CUDA + C++ don't play well together
Have been attempting to code a parallel version of AES to work on CUDA. After finally finishing off the last few CUDA problems, so I started a compilation test to ensure if things would be working. However I hit a major detour.
1>------ 开发者_如何学运维Build started: Project: AES-CUDA, Configuration: Debug Win32 ------
1>Build started 05/17/2011 3:53:27 AM.
1>InitializeBuildStatus:
1> Touching "Debug\AES-CUDA.unsuccessfulbuild".
1>CudaBuild:
1> Compiling CUDA source file AES.cu...
1>
1> C:\Users\*\Documents\Visual Studio 2010\Projects\AES-CUDA\AES-CUDA>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -G0 --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -D_NEXUS_DEBUG -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\AES.cu.obj" "C:\Users\*\Documents\Visual Studio 2010\Projects\AES-CUDA\AES-CUDA\AES.cu"
1> AES.cu
1> tmpxft_00001bd8_00000000-0_AES.cudafe1.gpu
1> tmpxft_00001bd8_00000000-5_AES.cudafe2.gpu
1> AES.cu
1> tmpxft_00001bd8_00000000-0_AES.cudafe1.cpp
1> tmpxft_00001bd8_00000000-11_AES.ii
1> Deleting file "tmpxft_00001bd8_00000000-6_AES.cpp3.o".
1>ClCompile:
1> main.cpp
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(12): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(55): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(60): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(60): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(64): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(64): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(66): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(66): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(66): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(66): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(67): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(67): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(67): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(67): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(68): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(68): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(68): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(68): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(69): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(69): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(79): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(79): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(80): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(80): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(81): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(81): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(82): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(82): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(84): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(84): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(85): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(85): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(86): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(86): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(87): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(87): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(93): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(98): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(98): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(102): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(102): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(104): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(104): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(104): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(104): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(105): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(105): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(105): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(105): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(106): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(106): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(106): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(106): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(107): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(107): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(117): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(117): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(118): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(118): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(119): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(119): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(120): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(120): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(122): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(122): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(123): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(123): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(124): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(124): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(125): error C2065: 'threadIdx' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(125): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(136): error C2664: 'cudaMallocPitch' : cannot convert parameter 1 from 'unsigned char **' to 'void **'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(142): error C2664: 'cudaMallocPitch' : cannot convert parameter 1 from 'unsigned char **' to 'void **'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(147): error C2664: 'cudaMalloc' : cannot convert parameter 1 from 'unsigned char **' to 'void **'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(170): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(175): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(176): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(177): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(178): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(182): error C2059: syntax error : '<'
1>c:\users\*\documents\visual studio 2010\projects\aes-cuda\aes-cuda\aes.cu(182): fatal error C1003: error count exceeds 100; stopping compilation
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.56
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have attached the proper CUDA 4.0 build customizations to my VS project as you can see from the build log. However the C++ compiler is re-interpreting the CUDA source file. Any ideas are appreciated.
It appears you are including aes.cu from main.cpp, which is generally not a good idea. If you need to mix host and device code, you should generally do it in .cu files, compiled using nvcc. If you have functions that should be called from both host and device code, you can declare them as such:
__host__ __device__ int foo() { return do_something(); }
However note that in these functions you can't use device-specific constructs like threadIdx.x
. If you have a __device__ __host__
function that needs to use device-specific constructs when running on the device, you can wrap that code in #ifdef __CUDA_ARCH__
:
__host__ __device__ int sharedFunction {
#ifdef __CUDA_ARCH__
return threadIdx.x * do_something();
#else
return do_something_on_the_cpu();
#endif
}
精彩评论