In 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.
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:
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.
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
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 ==========
You can also review the XML changes in the project and solution files here and get a working copy of the project.