How to compile 64-bit using nvcc?

Hi, I’d like to know how to compile 64-bit binaries using nvcc.exe on my 32-bit machine.

Right now to compile the 32-bit binary I’m using:
…\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat
nvcc -o main.exe main.cu

To compile a 64-bit binary I use the cross compiler with:
…\Microsoft Visual Studio 9.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat

I can compile 64-bit apps with cl.exe but nvcc says “nvcc fatal : nvcc cannot find a supported cl version. Only MSVC 8.0 and MSVC 9.0 are supported”

Thank you.

You have to use the 64-bit toolkit. Not sure if that’s a 64-bit binary or not. We’re aware that this limitation is very lame and are working to correct it.

Thanks for the quick reply. I guess I’ll stay tuned :)

I am using Vista 64-bit. I have downloaded and installed all the CUDA stuff (SDK, Toolkit, Drivers – all installers had ‘win_64’ in the filename). I am trying to build at the command line, and here’s what I get:

64-bit version of “cl.exe”

Run command: nvcc --compiler-bindir “C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin<b>amd64”

-c -D_DEBUG -DWIN64 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/MTd

-I “C:\Users\shep\AppData\local\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc” -I./ -o BlackScholes.exe BlackScholes.cu

nvcc output: nvcc fatal : nvcc cannot find a supported cl version. Only MSVC 8.0 and MSVC 9.0 are supported

32-bit version of “cl.exe”

Run command: nvcc --compiler-bindir “C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin”

-c -D_DEBUG -DWIN64 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/MTd -I

“C:\Users\shep\AppData\local\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc” -I./ -o BlackScholes.exe BlackScholes.cu

nvcc output: nvcc fatal : Visual Studio configuration file ‘(null)’ could not be found for

installation at ‘C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/…/…’

Note the differences in the error message output from nvcc. 64-bits reports that “cl.exe” is not a supported compiler. 32-bits that the compiler is OK, but the configuration file isn’t there.

It seems that nvcc has all sorts of stuff ‘hard wired’ into it. Isn’t there some way to simply specify the compiler to nvcc and force it to use it? nvcc does it’s thing, and then passes the resulting files to whatever compiler you have chosen? I’m guessing the 64-bit cl.exe from Visual Studio Express, or the cl.exe from the 64-bit Windows SDK (a free download), would work … if only they were allowed to by nvcc.

Pointing 64-bit nvcc’s -ccbin at the 32-bit cl.exe is correct for now (don’t worry, this is being fixed). The configuration (null) issue is something I’ve seen when the 64-bit cl.exe isn’t installed. Are you sure you actually did the custom installation and selected the x64 compilers? (sorry if it seems like a dumb question, but I’ve seen people do that a million times)

OK but I really need to be able to build 64bit binaries on a 32bit machine to integrate with our build system. This should simpy be a matter of setting some flags. Clearly since the 64bit version of nvcc is already using the 32 bit version of cl it should be no big deal to have the 32 bit version of nvcc use the the 32bit version of cl to generate 64bit code… please!

It’s not using the 32-bit version of cl, that’s the thing.

Supporting 32-bit compilation on 64-bit toolkits is a big deal for me; the opposite isn’t really something I’m concerned about at the moment.

I am having the same problems but with the windows7 x64 toolkit and drivers… please help!

I had this problem as well. This worked for me:

“F:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat” ← sets the C compiler to x64.

nvcc -ccbin “\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin” -o foo.exe foo.cu

That is a gem right there. I spent the last couple of hours trying to track down how to compile using nvcc on the command line. I wonder if you might have any words of wisdom on using nvcc from the command line to produce a DLL? A project I’m working on is forcing me to use C# (I’m normally just a C dev), and I need to write a CUDA DLL in order to access the GPU from within C#…

Well here it is March 2010 and as of nvcc version 2.3 V0.2.1221 it’s still a bit tricky to get nvcc to play nicely with the 64 bit MS Visual Studio compiler. If you don’t use the -ccbin option it still chokes by complaining you don’t have the right MS visual studio version number. However using -ccbin seems to be a bit tricky when the path to your cl.exe contains spaces (as it would if installed to the default path), I can’t seem to get the ccbin option to work properly.

I tried for example double quotes around the cl.exe directory as below:

nvcc.exe -O2 -o MatrixTest.exe -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe” -IC:\CUDA\include -IC:\Cuda\SDK\C\common\inc MatrixTest.cpp mempool.c cmatrix.cu -L C:\CUDA\lib64\ -l cuda -l cublas -l cufft -L C:\Cuda\SDK\C\common\lib -l cutil64

I get the error:

‘C:\Program’ is not recognized as an internal or external command,

operable program or batch file.

The only way I could get it to work was using MS windows 7 new symbolic link facility mklink, to create a no spaces hard link to the visual studio directory.

In general it would be nice to be able to retarget the compiler to other versions of microsofts products, such as their sdk compiler or the visual studio express compiler.