试着用纹理存储器,编译器报出了很多错误。不知道是需要加一些头文件还是什么问题,sample里面有没有例程。
cudaArray m_alphax;
c:\users\administrator\desktop\reforward\reforward\WaveR.h(112): error C2143: 语法错误 : 缺少“;”(在“”的前面)
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(112): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(112): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc();
c:\users\administrator\desktop\reforward\reforward\WaveR.h(132): error C2065: “cudaCreateChannelDesc”: 未声明的标识符
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(132): error C2062: 意外的类型“float”
texture<float,1,cudaReadModeElementType> texRefm_alphax;
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(170): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(170): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\reforward\reforward\WaveR.h(171): error C2086: “int texture”: 重定义
········
楼主您好,
如果只是一个简单的:
cudaArray *m_alphax;(或者cudaArray_t m_alphax;)都能报错的话,
请确保您的当前文件是作为.cu编译的(如果是.h文件,请确保#include它的是一个.cu文件)。
并请确保.cu文件的编译类型是CUDA C/C++
您的错误看上去是没有作为CUDA C/C++编译导致的。
谢谢版主指导。我果然是放错地方了。改完以后错误少了很多,但是纹理引用和绑定还是有问题。
texture<float,1,cudaReadModeElementType> texRefm_alphax;
cudaBindTextureToArray(texRefm_alphax,m_alphax);
c:\users\administrator\desktop\reforward\reforward\kernel.cuh(57): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(57): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(58): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(58): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(58): error C2086: “int texture”: 重定义
1> c:\users\administrator\desktop\reforward\reforward\kernel.cuh(57) : 参见“texture”的声明
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(59): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(59): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\reforward\reforward\kernel.cuh(59): error C2086: “int texture”: 重定义
texture<float,1,cudaReadModeElementType> texRefm_alphax;
texture<float,1,cudaReadModeElementType> texRefm_alphaz;
texture<float,1,cudaReadModeElementType> texRefm_vecVelocity;
cudaBindTextureToArray(texRefm_alphax,m_alphax,channelDesc);
cudaBindTextureToArray(texRefm_alphaz,m_alphaz,channelDesc);
cudaBindTextureToArray(texRefm_vecVelocity,m_vecVelocity,channelDesc);
楼主你好,
类似前文说法,您含有cuda代码的头文件必须只在.cu里被引用。任何在.c/.cpp中的使用都将导致大量的语法错误。
以及,不建议在头文件中防止实际可执行的代码。
(例如您给的cudaBindTextureToArray()之类的)
感谢来访。
版主您好:
我把
texture<float,1,cudaReadModeElementType> texRefm_alphax;
texture<float,1,cudaReadModeElementType> texRefm_alphaz;
texture<float,1,cudaReadModeElementType> texRefm_vecVelocity;定义在kernel.cuh里面。然后把涉及cudaBindTextureToArray()的函数都写在.cu里面。还是出现了如上的错误。不知道怎么解决。
楼主您好 我想把 cudaArray * 当作类的成员对象。可是在.h里面声明时不识别。我需要在类函数中调用cudaArray * 对象,就是说我需要cudaArray * 对象在类函数中可见。 如果我把cudaArray * 定义在.cuh中,好像不能对类的成员函数可见。 不知道怎么做了。
我已经说过多遍了,
包含cuda特定内容的头文件必须被一个.cu来引用,并且编译。
您不能试图将这种头文件给普通的.cpp/.c用的(例如你想将一些操作/函数导出),
这是不行的。
这个以及强调第三遍对您了。请问您看到了么?
以及,如果需要将CUDA操作导出,建议封装在一个普通的C函数里然后导出此普通函数(或者一个普通的C++类也行),但此类所在的头文件如果要给普通.cpp用,不能包含任何CUDA特定内容(例如<<<>>>)。
这是常见变通做法。