Using CUDA and Thrust with VS 2010 Part 2: x64 Builds
Saturday, April 9, 2011 – 8:22 AMIn the first part of this tutorial I covered getting started with CUDA on Visual Studio 2010. The post didn’t talk about building x64 targets. A couple of people asked about this so I’ve upgraded the example to build both x86 and x64. This is very easy to do provided you know what levers to throw in Visual Studio.
Using CUDA 4.0 RC2? Read the update post here.
Here’s a brief step-by-step guide to show you how.
Adding x64 to the configuration
The first thing to do is add x64 builds to the configuration. Each project in the solution needs an x64 platform target.
1) Open the Build | Configuration Manager…
2) For the HelloWorld project use the platform dropdown and select <New…> to bring up the New Project Platform dialog.
3) Use the dialog to create a new platform and copy the settings from the existing Win32 platform and check the box to create a new solution platform.
4) Make sure that the build checkboxes are checked for both Debug and Release configurations of x64.
Repeat steps 2, 3 and 4 for the HelloWorldCuda project but don’t check the “Create new solution platforms”, you only have to create a solution platform once per solution.
The next thing to do is to fix up the output and intermediate directories for both projects. Your life will be much easier if these are consistent (trust me on this).
For each project open the property pages. A useful shortcut for this is to select the project in the solution explorer and press ALT-ENTER. Next select All Configurations and All Platforms then set the following properties to as shown below.
Output Directory: $(SolutionDir)$(Platform)\$(Configuration)\
Intermediate Directory: $(Platform)\$(Configuration)\
This is shown below:
Now build output from both your projects will end up in a x64\Debug or x64\Release folder within the solution.
Building x64 CUDA
That’s the basics. Now let’s configure the CUDA project to use x64 too. Open the HelloWorldCuda project’s property pages and select the Configuration Properties | CUDA C/C++ node. For all configurations set the following property:
Target Machine Platform: 64-bit (—machine 64)
The properties page should look like this:
Finishup up
Finally we need to make sure that the HelloWorld project can find the output of the HelloWorldCuda project that we configured when we set the project output directories. Open the HelloWorld project’s property pages and select the Configuration Properties | Linker |General node. For all configurations and platforms set the following property:
Additional Library Directories: $(SolutionDir)$(Platform)\$(Configuration)\;$(CUDA_PATH_V4_0)\lib\$(Platform);%(AdditionalLibraryDirectories)
Note how I’ve selected All Configurations so that this gets set for both Debug and Release builds.
Building
Use the Build | Configuration Manager… menu item to open the Configuration Manager dialog and set the active configuration and platform to Debug / x64. Close the dialog and rebuild the solution.
You’ll see a lot of warnings like:
1> “c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\math_functions.h(369): warning: dllexport/dllimport conflict with “fmodf”
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\math.h(238): here; dllimport/dllexport dropped
and
1>c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\math_functions.h(369): warning C4273: ‘fmodf’ : inconsistent dll linkage
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\math.h(238) : see previous definition of ‘fmodf’
These are expected. I’m hoping they’ll be fixed in a updated CUDA 4.0 RC. If I come up with a workaround I’ll update this post.
That was a lost of setting changes and you’ve now increased the number of project configurations from four to eight. How do I make sure all the possible builds work?
Open the Build | Batch Build… menu item and in the Batch Build dialog check all the configurations.
Next click the Rebuild button. You should see the following final output
========== Rebuild All: 8 succeeded, 0 failed, 0 skipped ==========
We’re done!
You can also review the XML changes in the project and solution files here and get a working copy of the project.
2 Responses to “Using CUDA and Thrust with VS 2010 Part 2: x64 Builds”
Hi Ade,
First I want to thank you for sharing. I have red and followed the instructions of both part 1 and this (part 2) articles. Part 1 worked just as you said and has helped me understand the workings of VS2010+CUDA+Thrust much better.
When I try this part (part 2) using the previous project of part 1 as the basis I cannot build the solution. I have done it twice just to be sure I did not screw up any of the steps, but my final result is that the solution does not build.
The errors I get in the output from Build are:
****Quote
1>—— Rebuild All started: Project: HelloWorldCuda, Configuration: Debug x64 ——
1>
1> c:\Users\dam\Documents\Visual Studio 2010\Projects\HelloWorld\HelloWorldCuda>”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -ccbin “c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64″ -I”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\\include” -I”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include” -G0 –keep-dir “x64\Debug” -maxrregcount=32 –machine 64 –compile -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MDd ” -o “x64\Debug\Hello.cu.obj” “c:\Users\dam\Documents\Visual Studio 2010\Projects\HelloWorld\HelloWorldCuda\Hello.cu” -clean
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.0.targets(347,3): error MSB3721: The command “”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -ccbin “c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64″ -I”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\\include” -I”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include” -G0 –keep-dir “x64\Debug” -maxrregcount=32 –machine 64 –compile -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MDd ” -o “x64\Debug\Hello.cu.obj” “c:\Users\dam\Documents\Visual Studio 2010\Projects\HelloWorld\HelloWorldCuda\Hello.cu” -clean” exited with code -1.
2>—— Rebuild All started: Project: HelloWorld, Configuration: Debug x64 ——
2> stdafx.cpp
2> HelloWorld.cpp
2>LINK : fatal error LNK1104: cannot open file ‘HelloWorldCuda.lib’
========== Rebuild All: 0 succeeded, 2 failed, 0 skipped ==========
****Unquote
I have checked the paths and cannot find the faulty line, and thought you might have an idea.
Regards,
Didac
By Didac Artes on Apr 12, 2011
Didac,
It looks like the solution is trying to build the HelloWorld project first. Right click on the HelloWorld project and select Project Dependencies. Check the box next to HelloWorldCuda. This will force this project to build first.
Ade
By Ade Miller on Apr 22, 2011