2

What is a good way to compile CUDA code in Windows?

I tried in different ways, linking with Visual Studio and compiling from command line using nvcc command.

Issues with visual studio. I followed most of the links for compiling, found in internet, but still I am not able to compile simple program.

Issues with nvcc. Cannot find path windows.h. I tried adding include path of Visual Studio in nvcc.profile but it is not working?

Does anyone have a good solution for this?

I am using CUDA 4.2 and visual studio 2010.

Bart
  • 19,692
  • 7
  • 68
  • 77
Kalyan
  • 477
  • 2
  • 6
  • 12
  • http://stackoverflow.com/questions/3778799/how-do-i-start-a-cuda-app-in-visual-studio-2010 – Martin Beckett Jul 25 '12 at 16:58
  • It is not working after setting up cuda compilation..Showing an error in kernel function "third < "with error "expecting an expression" and "intellicense error".... and in device_functions.h and sm_11_atomic_functions.h exit() identifier is not defined... – Kalyan Jul 25 '12 at 20:57
  • If you simply set up the Visual Studio integration that is now part of each CUDA release, you should really have no problem. If you're using Visual Studio anyway, that's by far the easiest method. Have you tried? – Bart Jul 26 '12 at 17:59

2 Answers2

4

Here is my advice. You can get other people's recipes for setting up CUDA with Visual Studio. But every time nVidia releases a new kit or you update to the next Visual Studio, you're going to go through it all over again. Almost always it is because one of those vendors could not leave well enough alone (or maybe they really did have a good reason; it could happen) decided to change paths.

So my advice is to use nvcc from the command line until you understand all the dependencies. Then you will have no trouble setting up your IDE. Each time a new CUDA comes out, I go back to the command line and make sure I can still build, discover any path changes, tool changes, etc. Once I understand, then I update my IDE settings.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Carlos
  • 1,470
  • 10
  • 18
0

I had the same problem. Here is the easy solution.

The examples of CUDA (GPU Computing SDK) run correctly (You should have installed Nvidia GPU Computing SDK). Open the start menu and type "Browse CUDA SDK" in the text box (Hope you use win vista or seven).

The examples are in the src folder. The examples in this folder have solution in VS 2005, VS 2008 and VS 2010. They have all the initial settings set in this solution and projects and you can copy one of the examples and clean the code and run your own code. The only Problem is that their settings files are addressed locally (for example ../../common/lib/). So you should run your project in exactly that src folder.

Also CUDA 4.0 and 4.1 had a CUDA Runtime option on Visual Studio's New project wizard. That was great and I don't know why did they eliminated this option on 4.2. If you couldn't run CUDA 4.2, CUDA 4.1 is a good option. (You can install Nvidia GPU SDK 4.1 and then uninstall it the Visual Studio optin will remain and work correctly)

Another option is to make a blank project and use this configuration (It is for CUDA 4.0 and the addresses in your computer may be different):

New -> Project -> Win32 Console Application

Name: "HelloCuda" -> OK -> Next -> Empty project -> Finish

Right Click the project HelloCuda -> Build Customizations

Click Find Existing and Navigate to CUDA 4.0.targets

C:\ProgramFiles\MSBuild\Microsoft.Cpp\v4. 0\BuildCustomizations\CUDA 4.0.targets

Now create a textfile and save it as HelloWorld with .cu Extension

Now you will have a file HelloWorld.cu

Add this file to the project HelloCuda

Right Click HelloWorld.cu -> Configuration Properties -> General -> Item Type -> CUDA C/C++

Now right click project HelloCuda -> Configuration Properties -> CUDA C/C++ -> Common -> Additional Include Directories

Add C:\Users\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\inc;

Now right click project HelloCuda -> Configuration Properties -> Linker -> General -> Additional Library Directories

Add C:\Users\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\lib;

Linker -> Input -> Additional Dependencies -> cudart.lib

Now write a sample CUDA C Program inside HelloWorld.cu and Compile.

Bardia
  • 393
  • 4
  • 11