How to build CUDA 4.0 samples with Visual Studio? - visual-studio

I'm using Visual Studio 2010 and want to build the examples under C:\ProgramData\NVIDIA Corporation\NVIDIA 4.0 GPU Computing Toolkit\C\src.
I had lots of problems regarding include files, but they are partly solved by building the cutil project under C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common using Visual Studio.
But when I try to compile the nbody example, I get an error message which implies a conflict with previously installed 3.2 GPU Computing Toolkit.
How can I fix this "exit with -1" error?
C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA
4.0.targets(357,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin\nvcc.exe"
-gencode=arch=compute_10,code=\"sm_10,compute_10\" -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"./" -I"../../common/inc"
-I"../../../shared/inc" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\include" -G0 --keep-dir "Debug" -maxrregcount=0
--machine 32 --compile -D_NEXUS_DEBUG -g -Xcompiler "/EHsc /nologo /Od /Zi /MTd " -o "Win32/Debug/bodysystemcuda.cu.obj"
"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK
4.0\C\src\nbody\bodysystemcuda.cu"" exited with code -1.

You appear to have the 3.2 include directory in the path instead of the 4.0 what is CUDA_INC_PATH set to ?

Related

Can't find neither .cubin nor .ptx file compiling CUDA

I am working on CUDA (7.0) project using Visual Studio 2013. The project is 64bit.
I am using driver API and need to load module from ptx or cubin file.But I can't find the file.
In VS I go Properties->CUDA C/C++ ->Common->NVCC Compilation Type ,change it to -cubin or ptx .the compiler finishes ok but I can't find that file.I only can see kernel.cu.obj and kernel.cu.cache files in output debug directory.What can be wrong here?
UPDATE:
If I go to Properties->CUDA C/C++ ->Common->Keep Preprocessed Files and set YES.Then I see .ptx,and other intermediate stuff.But as far as I understand this option is not mandatory to get .ptx?Also demo CUDA SDK projects like "matrixMulDrv" spitr ptx with that option off.I can't figure out where is the difference.
Here is matrixMulDrv project compile command:
C:\ProgramData\NVIDIA Corporation\CUDA
Samples\v7.0\0_Simple\matrixMulDrv>"C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v7.0\bin\nvcc.exe"
-gencode=arch=compute_20,code=\"compute_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64" -I./
-I../../common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0/include" -I../../common/inc -I"C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -G --keep-dir
x64\Debug -maxrregcount=0 --machine 64 -ptx -cudart static -Xcompiler
"/wd 4819" -o data/matrixMul_kernel64.ptx "C:\ProgramData\NVIDIA
Corporation\CUDA
Samples\v7.0\0_Simple\matrixMulDrv\matrixMul_kernel.cu"
And here is my project CUDA kernel compile command:
E:\Documents\visual studio
2012\Projects\ProjectName\ProjectName>"C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v7.0\bin\nvcc.exe"
-gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64" -I"E:\Documents\visual studio
2012\Projects\XXXXXX\XXXXX\XXXXX\include" -I"E:\Documents\visual
studio 2012\Projects\XXXXX\XXXXX\XXXXX\include" -I"E:\Documents\visual
studio 2012\Projects\XXXXXXXX\XXXXXXX\XXXXXX\include"
-I"E:\Documents\visual studio 2012\Projects\XXXXXXX\XXXXXX\XXXXXXX\include" -I"E:\Documents\visual
studio 2012\Projects\ProjectName\ProjectName\include"
-I"E:\Documents\visual studio 2012\Projects\XXXXXXX\XXXXXX\XXXXXX\include" -I"E:\Documents\visual
studio 2012\Projects\XXXXXX\XXXXXX\XXXXXX\include"
-I"E:\Documents\visual studio 2012\Projects\XXXXXXX\XXXXXX\XXXXXX\include" -I"E:\Documents\visual
studio 2012\Projects\XXXXXX\XXXXXX\XXXXXX\include" -I"C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0/include"
-I"C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.0\common\inc" -I"E:\Documents\visual studio 2012\Projects\ProjectName\ProjectName\include" -I"C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -I"C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -G --keep-dir
x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g
-DWIN32 -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " -o x64\Debug\skernel.cu.obj "E:\Documents\visual studio
2012\Projects\ProjectName\ProjectName\src\skernel.cu"
It is possible to see that matrixMulDrv project is set to compile .ptx with this line data/matrixMul_kernel64.ptx while in my project I have -o x64\Debug\skernel.cu.obj .But I have the same CUDA compiler settings on both projects.
CUDA projects in Visual Studio can inherit compile settings both at the project level (in which case they are defined in Project Properties...CUDA...Device) and at the file level (in which case you can right click on the file to bring up its properties and find them in a similar location).
The file can inherit its settings from the global project settings, or it can replace them (if you so select at the file level).
Some of those settings will determine what type of output will be generated (and therefore effectively what compile switches are needed) when that file is compiled by nvcc. Ordinary CUDA runtime API projects need their modules compiled into ("hybrid") object files (i.e. .o), but CUDA driver API projects will typically need cuda "objects" in the form of a .cubin file or a .ptx file.
There are settings to modify this generation, and for example to switch a file from typical CUDA runtime API compilation to typical driver API compilation, you could change the "NVCC Compilation Type" option from "Generate hybrid object file (--compile)" to "Generate .ptx file (-ptx)"
If you do this at the file level, it will need to be done for each file that needs its settings changed.

Compiling cuda from command line - win32

I don't want the whole VS install, especially since it would eat up most of my C space, so I grabbed the SDK. I've also installed the cuda SDK. I'm running into a rather absurd problem though:
d:\cuda\class>nvcc --cubin unit1-1.cu
unit1-1.cu
unit1-1.cu
tmpxft_00001224_00000000-5_unit1-1.cudafe1.gpu
tmpxft_00001224_00000000-11_unit1-1.cudafe2.gpu
'nvopencc' is not recognized as an internal or external command,
operable program or batch file.
d:\cuda\class>nvopencc
nvopencc: no input files
For general help: nvopencc --help
To search help: nvopencc -help:<string>
It's saying that nvopencc isn't a valid command and yet I can run it! Anyone have any idea at all how to fix this?? I found --cubin on a command somewhere and hoped it would work...I have no idea if it's supposed to be there. At any rate, with or without I get the same error.
Here's a typical call to nvcc.exe, generated by Visual Studio 2010. Looks like you need to specify the location of the compiler binaries.
nvcc.exe -gencode=arch=compute_30,code=\"sm_30,compute_30\"
--use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"
-I"\C\common\inc" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v5.0\include" --keep --keep-dir "Release" -maxrregcount=0
--machine 32 --compile -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MD " -o "Release\kernel.cu.obj" "c:\test_cuda\test_cuda\kernel.cu"

CUDA 4.2. toolbox & VS2010

I am trying to compile Cuda SDK examples but I am getting "MSB3721 error" since "nvcc" is "exited with code 1". Complete output:
"C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA
4.2.targets(361,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe"
-gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64" -I"./" -I"../../common/inc"
-I"../../../shared/inc" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -G --keep-dir "x64\Debug" -maxrregcount=0
--machine 64 --compile -g -Xcompiler "/EHsc /nologo /Od /Zi /MTd " -o "x64/Debug/bandwidthTest.cu.obj" "C:\ProgramData\NVIDIA
Corporation\NVIDIA GPU Computing SDK
4.2\C\src\bandwidthTest\bandwidthTest.cu"" exited with code 1."
Cuda toolkit 4.2 is used on Win7 x64 Ultimate system with VS2010 Ultimate.
The error remains when the "win32" option in "Configuration management" is used.
Are there any suggestions?
!!!!! Finally after reading all available NVIDIA manuals about "Getting started with CUDA" after reinstalling Win7+VS2010+CUDA drivers more than 10 times after building a new computer (Z77 mobo + i7 + GTX550Ti) and after waiting for months the NVIDIA forum resurrection I found out that the problem with the nvcc build error "exited with code 1" was disappeared when the "Run as administrator" option was selected on the VS2010 shortcut on my desktop!!!!!!
Although I was using an administrator account (the only account on the PC) it was impossible to build any of the CUDA Examples. The executables were running without any problem but I couldn't build the source code using VS2010!
!!!!!Thank you all for your support!!!!!
I would try to start from scratch. Remove CUDA, Nsight, and Visual Studio. Reboot. Manually remove any program folders that might be left. I can't guarantee that it's safe to remove these, but if any other NVIDIA or Microsoft products break because of this, I'd just fix those after having fixed CUDA:
C:\Program Files (x86)\Microsoft Visual Studio 10.0
C:\Program Files (x86)\Microsoft Visual Studio 9.0
C:\Program Files (x86)\NVIDIA Parallel Nsight 2.1
C:\Program Files (x86)\NVIDIA Parallel Nsight Monitor 2.1
C:\Program Files\Microsoft Visual Studio 10.0
C:\Program Files\NVIDIA GPU Computing Toolkit
Manually remove any left over app data folders:
C:\Users\<your user folder>\AppData\Roaming\NVIDIA
C:\Users\<your user folder>\AppData\Roaming\NVIDIA Corporation
You might want to look for registry keys as well.
Then reinstall everything. Nsight comes with CUDA, so I'd first install VS then Nsight. That should be all that is required. Then, create a CUDA project from scratch.
You might want to look at this thread, maybe it helps you with your problem:
How to Compile CUDA App is Visual Studio 2010?

'X86' conflicts with target machine type 'x64'

I'm getting the following error:
LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
I'm working on a 64 bit machine (VS2008) and I have the x64 compiler. I checked that the build is on x64.
Why isn't it compiling? Here's the build log:
echo "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include" -maxrregcount=0 --compile -o "x64\Debug/lowWrappers.cu.obj" lowWrappers.cu
In the top of the properties dialogue, there's a Platform dropdown. That should say "Active(x64)". If it says "Active(Win32)", that's your problem. Click "Configuration Manager..." in the top right, select the platform for your project, select "" and find x64. You can then delete the Win32 platform if you like.
(this might be a bit out of date...but I found a fix, since I just ran into this problem).
The short answer, in your Project Properties->Configuration Properties->CUDA RuntimeAPI->Host
set the "Target Machine Platform" to x64. (mine was at x86 despite having the platform at x64).
Make sure that any libraries you are using have also been compiled on 64 bit.

Cuda 4.0 with Visual Studio 2010 cl compiler error

As I did not get any help in the Nvidia forums (see my post at the bottom of the thread), and it seems I am not the only one struggeling with similar problems, I will give it a try here.
I tried to compile the Cuda SDK 4.0 examples as well as following the very nice tutorial by Ade Miller. But compiling the ".cu" file won't work.
This is the (exemplary) command the compiler invokes:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.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\v4.0\include" -G0
--keep-dir "x64\Debug" -maxrregcount=0 --machine 64 --compile -D_NEXUS_DEBUG
-g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "x64\Debug\Hello.cu.obj"
"D:\Code\CUDA\Test_Cuda_4_0\Test_Cuda_4_0\Hello.cu"
And this is the strange error message I always get.
nvcc fatal : Compiler 'cl' in PATH different than the one specified with -ccbin
EDIT: To be a bit more precise: Visual Studio just tells me the command did not succeed ("exit code -1") -> to see this error message I have to invoke the command by myself in the command line.
1) Why should nvcc care about the path in the environment variable differing from the one specified with the command line option? If it would care, wouldn't this make the command line option completely useless?
2) How to fix ;) ?
I use Win7 64Bit, VS2010 Prof SP1, and the following nvidia versions:
cudatoolkit_4.0.17_win_64
devdriver_4.0_winvista-win7_64_270.81_general
gpucomputingsdk_4.0.19_win_64
Many thanks for your help!
try using the conventional method to start writing a CUDA program, as given in Getting Started guide(Copy the sample). To solve the above problem you have to add it as an environment variable. But since the SDK samples are already linked, they don't give problems.
I had a similar problem. previously i copied cl.exe in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin for test several parameters with nvcc.exe and forget delete this file from this directory. i removed this file and everything is OK. purpose of PATH for my problem in really was for this path: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin and wasn't PATH in Environment variables.

Resources