I am trying to get started with CUDA programming on Windows using Visual Studio 2010 Express on a 64 bit Windows 7. It took me a while setting up the environment, and I just wrote my first program, helloWorld.cu :)
Currently I am working with the following program:
#include <stdio.h>
__global__ void add(int a, int b, int *c){
*c = a + b;
}
int main(void){
int c;
int *dev_c;
HANDLE_ERROR( cudaMalloc( (void**)&dev_c, sizeof(int) ) );
add<<<1,1>>>(2, 7, dev_c);
HANDLE_ERROR( cudaMemcpy( &c, dev_c, sizeof(int), cudaMemcpyDeviceToHost ) );
printf("2 + 7 = %d\n", c);
cudaFree( dev_c );
return 0;
}
And here is the output of build with Windows7.1SDK platform toolset:
1> C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G --keep-dir "x64\Debug" -maxrregcount=0 --machine 64 --compile -g -Xcompiler "/EHsc /W1 /nologo /O2 /Zi /MD " -o "x64\Debug\hello.cu.obj" "C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2\hello.cu"
1>nvcc : fatal error : '-ccbin': expected a number
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G --keep-dir "x64\Debug" -maxrregcount=0 --machine 64 --compile -g -Xcompiler "/EHsc /W1 /nologo /O2 /Zi /MD " -o "x64\Debug\hello.cu.obj" "C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2\hello.cu"" exited with code -1.
However, with v100 platform toolset I am getting this error:
C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G --keep-dir "x64\Debug" -maxrregcount=0 --machine 64 --compile -g -Xcompiler "/EHsc /W1 /nologo /O2 /Zi /MD " -o "x64\Debug\hello.cu.obj" "C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2\hello.cu"
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\math.h(455): error : dllexport/dllimport requires external linkage
1>C:/Users/User/documents/visual studio 2010/Projects/CudaTest2/CudaTest2/hello.cu(12): error : identifier "HANDLE_ERROR" is undefined
1>c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h(2900): error : function "hypotf" was referenced but not defined
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G --keep-dir "x64\Debug" -maxrregcount=0 --machine 64 --compile -g -Xcompiler "/EHsc /W1 /nologo /O2 /Zi /MD " -o "x64\Debug\hello.cu.obj" "C:\Users\User\documents\visual studio 2010\Projects\CudaTest2\CudaTest2\hello.cu"" exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Could anyone point me in right direction? I have been reading almost all posts about related issues, installed and uninstalled tools couple of times and still can't get a proper build.
This is because visual studio doesn't have the privilege to access the Temp folder.
navigate to C:\Users\userName\AppData\Local\Temp and change the access security rules of the current user (in this case it is userName) to full control
The answer is two-fold. The HANDLE_ERROR build error you're getting using the v100 platform is related to the HANDLE_ERROR function being defined in the additional headers for the book "Cuda By Example" - I recognize the example, so I assume that's the code you're trying to compile. You haven't included this filem because it's not listed in the book code listings ... a small oversight from the author(s), imho.
You can download the code examples, and the additional header "book.h" you need from the book page:https://developer.nvidia.com/content/cuda-example-introduction-general-purpose-gpu-programming-0
For reference, this is the HANDLE_ERROR code from book.h:
The following worked for me. Edit the file *C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.prop*s. Search for PlatformToolset and add an entry for Windows7.1SDK. Set the value to 2010.