2011-05-17 80 views
0

一直在試圖編寫一個並行版本的AES來處理CUDA。 在最後完成了最後幾個CUDA問題後,我開始編譯測試以確保事情能夠正常工作。不過,我打了一個大彎路。CUDA + C++不能很好地協同工作

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 ========== 

我附上正確的CUDA 4.0構建定製到我的VS項目,你可以從構建日誌中看到。然而,C++編譯器正在重新解釋CUDA源文件。任何想法都表示讚賞。

回答

3

看起來你是從main.cpp中包含aes.cu,這通常不是一個好主意。如果你需要混合主機和設備代碼,你通常應該在.cu文件中使用nvcc編譯。如果有應該從主機和設備代碼中調用的函數,你可以聲明它們的方式:

__host__ __device__ int foo() { return do_something(); } 

但是請注意,在這些功能不能使用設備特定的結構,如threadIdx.x。如果你有一個__device__ __host__功能需要使用的設備上運行時設備特定的結構,你可以用這些代碼在#ifdef __CUDA_ARCH__

__host__ __device__ int sharedFunction { 
#ifdef __CUDA_ARCH__ 
    return threadIdx.x * do_something(); 
#else 
    return do_something_on_the_cpu(); 
#endif 
} 
+0

我有.CU文件中的所有CUDA代碼。 標題中的AES代碼,其中包含CUDA代碼。主C++文件包含寫入標題的AES代碼。 – Nocturnal 2011-05-17 02:54:28

+0

這是你的問題。 C++編譯器試圖編譯你的AES頭文件中包含的CUDA代碼,並且它正在扼殺C++中一般C++一無所知的特定CUDA關鍵字。爲了解決這個問題,你需要將CUDA代碼分離出來,或者在不編譯GPU時用'#ifdef __CUDA_ARCH__'註釋掉它。 – harrism 2011-05-17 03:12:04

+0

nVidia GPU Computing SDK具有相同的文件結構,雖然我從未編譯過它並且缺少一個文件。然而,他們有一些解決方法,允許他們編譯與CUDA集成的Cpp版本。 – Nocturnal 2011-05-17 09:26:09

相關問題