Problems starting nvcc from the command line

I need to compile a cuda cc file using nvcc from the command line. The file is "vectorAdd_kernel.cu" and contains the following code fragment:

extern "C" __global__ void VecAdd_kernel(const float* A, const float* B, float* C, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) C[i] = A[i] + B[i]; } 

I used the following command (I need to get the .cubin file):

 nvcc --cubin --use-local-env --cl-version 2010 -keep -I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" vectorAdd_kernel.cu 

The compiler creates the files vectorAdd_kernel.cpp4.ii and vectorAdd_kernel.cpp1.ii, then stops with the following output:

 C:\Users\Massimo\Desktop\Pluto>nvcc --cubin --use-local-env --cl-version 2010 vectorAdd_kernel.cu -keep -I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" vectorAdd_kernel.cu vectorAdd_kernel.cu c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error: invalid redeclaration of type name "size_t" C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include\new(51): error: first parameter of allocation function must be of type "size_t" C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include\new(55): error: first parameter of allocation function must be of type "size_t" 

Could you help me in solving this problem?

Greetings

Massimo

+4
source share
2 answers

I had a similar problem.

Code where assembly breaks in SourceAnnotations.h:

 #ifdef _WIN64 typedef unsigned __int64 size_t; #else typedef _W64 unsigned int size_t; #endif 

I added the _WIN64 symbol of the compiler with this --compiler-options "-D _WIN64" . The nvcc build line looked like this:

 nvcc kernel.cu --cubin --compiler-options "-D _WIN64" 
+2
source

I just ran into this in Visual Studio 2017 and Cuda v9.0, trying to compile from the command line using nvcc . After a lengthy session, I realized that my Visual Studio command-line tools were configured to use cl.exe from the x86 director instead of x64 . There are several ways to solve it, one way is to override the directory in which it searches for its compiler tools, for example, for example:

 nvcc -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\bin\HostX86\x64" -o add_cuda add_cuda.cu 

Then it worked fine.

I also mentioned that I used which.exe utility from git tools to find out which version of cl.exe it was cl.exe , but the where command, which is native to windows, works.

Update:

Another way — perhaps the best way — is to simply set the Visual Studio environment variables correctly to 64 bits, as is the case for the Enterprise version:

 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 

For the community version, replace "Community" with "Enterprise" along the way.

You can also select a toolbox with (for example) --vcvars_ver=14.0 , which selects the toolbox 14.0 needed to compile CUDA 9.1 with Visual Studio version 15.5.

Then you can simply create this:

 nvcc -o add_cuda add_cuda.cu 
+1
source

Source: https://habr.com/ru/post/1439208/


All Articles