简体   繁体   English

使用CUDA和犰狳

[英]Using CUDA and Armadillo

I have a .cu file in a 64x VS2010 project. 我在64x VS2010项目中有一个.cu文件。 This project is configured to extract a .mexw64 file. 该项目配置为提取.mexw64文件。 Bellow there is the example I run. 贝娄有我运行的例子。 Inside the mex function I want to use some functions of the Armadillo linear algebra library. 在mex函数内部,我想使用Armadillo线性代数库的某些函数。 So When the #include "armaMex.hpp" is used the compiler return some errors: 因此,当使用#include "armaMex.hpp" ,编译器将返回一些错误:

  1. error C3203: 'fixed' : unspecialized class template can't be used as a template argument for template parameter 'T1', expected a real type c:....\\armadillo-4.200.0\\include\\armadillo_bits\\Mat_meat.hpp 错误C3203:“已修复”:非专业类模板不能用作模板参数“ T1”的模板参数,应为实型c:.... \\ armadillo-4.200.0 \\ include \\ armadillo_bits \\ Mat_meat.hpp
  2. error C2955: 'arma::Mat::fixed' : use of class template requires template argument list c:\\ ....\\armadillo-4.200.0\\include\\armadillo_bits\\Mat_meat.hpp 错误C2955:'arma :: Mat :: fixed':使用类模板需要模板参数列表c:\\ ..... \\ armadillo-4.200.0 \\ include \\ armadillo_bits \\ Mat_meat.hpp
  3. error C1903: unable to recover from previous error(s); 错误C1903:无法从以前的错误中恢复; stopping compilation c:\\ ....\\armadillo-4.200.0\\include\\armadillo_bits\\Mat_meat.hpp 停止编译c:\\ ..... \\ armadillo-4.200.0 \\ include \\ armadillo_bits \\ Mat_meat.hpp

I can not figure out what is causing these errors. 我不知道是什么导致这些错误。 Could you please give an explanation? 你能解释一下吗?

#include "mex.h" 
#include "armaMex.hpp"
void
    mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    mexPrintf("hello!\n");
}

PS: CUDA SDK 5.5 64x, VS2010 PS:CUDA SDK 5.5 64x,VS2010

This is a known limitation of nvcc (technically cudafe++, I think). 这是nvcc的已知限制(我认为技术上是cudafe ++)。 nvcc uses file extension to determine whether a given source file should be processed for device code or passed to the CUDA preprocessors and then the device compiler. nvcc使用文件扩展名来确定应处理给定的源文件以获取设备代码还是将其传递给CUDA预处理器,然后传递给设备编译器。 It looks like that compilation trajectory can't correctly parse some of the very complex declarations that Armadillo contains, and the compile fails. 看来编译轨迹无法正确解析Armadillo包含的某些非常复杂的声明,并且编译失败。 This is known to happen with Boost, Eigen and QT. 众所周知,Boost,Eigen和QT会发生这种情况。 I guess Armadillo is in the same boat. 我猜犰狳在同一条船上。

The solution is to not import Armadillo headers inside a .cu file. 解决方案是不要在.cu文件中导入Armadillo标头。 Put your host boost code in a .cc file, device code and kernel launches in a separate .cu file and make some thin wrappers to access the kernel calls from the .cc file. 将主机增强代码放在.cc文件中,将设备代码和内核启动放在单独的.cu文件中,并进行一些精简包装,以访问.cc文件中的内核调用。 You can still pass all the source to nvcc to compile into a single object file, but separating the Armadillo imports from the device code eliminates the problem of the front end choking on the complex template declarations Armadillo contains. 您仍然可以将所有源代码传递给nvcc以编译成单个目标文件,但是将Armadillo导入与设备代码分开可以避免前端阻塞导致Armadillo包含的复杂模板声明的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM