CUDA & VS C++ 2008 EXPRESS EDITION

Hi everybody,

This may seem as an easy question, but i am new to CUDA, I have downloaded all the drivers, the CUDA TOOLKIT 3.1 and the SDK and I would like to use Microsoft Visual Studio c++ 2008 express edition to wright my programms.
How can i do?

Thank you in advance.

Hi, I hope this would work

Have you installed the drivers, microsoft visual c++ express edition, cuda toolkit, dan cuda sdk?

If so you can check if it’s working or not. Find and run bandwidthTest .exe located in C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\bin\win32\Release. (I use win7 32bit)

To build cuda program in Visual C++, copy this Cuda.rules file located in C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common to VC\VCProjectDefaults in your Microsoft Visual Studio instalation folder.

Create New Project:

  1. Open Visual C++

  2. File > New > Project. Coose an empty project

  3. If the project has been created, right click on the project name in the solution explorer, choose Custom Build Rules

  4. If there’s CUDA Build Rule on the available rule, check it. If there isn’t just find existing rule, and browse CUDA bulid rule in VC\VCProjectDefaults.

  5. Add CUDA runtime library. right click on project, choose Properties → Linker → General, add $(CUDA_LIB_PATH) to Additional Library Directories. And then Linker → Input add cudart.lib to Additional Dependencies.

After that, try this one

/*

** Hello World using CUDA

**

** The string "Hello World!" is mangled then restored using a common CUDA idiom

**

** Byron Galbraith

** 2009-02-18

*/

#include <cuda.h>

#include <stdio.h>

// Prototypes

__global__ void helloWorld(char*);

// Host function

int

main(int argc, char** argv)

{

int i;

// desired output

char str[] = "Hello World Bapuk!";

// mangle contents of output

// the null character is left intact for simplicity

for(i = 0; i < 12; i++)

str[i] -= i;

// allocate memory on the device

char *d_str;

size_t size = sizeof(str);

cudaMalloc((void**)&d_str, size);

// copy the string to the device

cudaMemcpy(d_str, str, size, cudaMemcpyHostToDevice);

// set the grid and block sizes

dim3 dimGrid(2); // one block per word

dim3 dimBlock(6); // one thread per character

// invoke the kernel

helloWorld<<< dimGrid, dimBlock >>>(d_str);

// retrieve the results from the device

cudaMemcpy(str, d_str, size, cudaMemcpyDeviceToHost);

// free up the allocated memory on the device

cudaFree(d_str);

// everyone's favorite part

printf("%s\n", str);

return 0;

}

// Device kernel

__global__ void

helloWorld(char* str)

{

// determine where in the thread grid we are

int idx = blockIdx.x * blockDim.x + threadIdx.x;

// unmangle output

str[idx] += idx;

}

ps: Correct Me If I’m Wrong :rolleyes:

I hope this would also help

Thanks a lot this was very helpfull, the code works just fine !

hello ,

im new to cuda , too , and find this post very usefull , but its not worikng for me .

i`m using ms visual studio 2008 , installed the newest gpu driver (i ve got a nvidia gt 320 m) , downloaded and installed the latest versions of the cuda toolkit and sdk , ran the bandwidth test and also built and ran the bandwidth project , and they worked ok.

i followed the steps described here in the post , created a new empty C++ project , added the cuda rules , linked the libraries as you said ($(CUDA_LIB_PATH) & cudart.lib)
after that added a cpp file to the Source Files in the project , copy/paste the code you posted , but i get this error while building the project :

Error 1 fatal error C1083: Cannot open include file: ‘cuda.h’: No such file or directory c:\users\gogira\documents\visual studio 2008\projects\test2\test2\coco.cpp 9 test2

if you could point out for me what i`m missing or doing wrong , please do that .

thanks in advance.

//adrian

try to change your code file extension into coco.cu

i think that would work, hehe

try to change your code file extension into coco.cu

i think that would work, hehe

I’m having some issues with compilation. I’m always getting this error

I’m not sure what to do. I did manage to get intellisense and highlighting enabled though so if I can figure out how to get stuff to compile I can actually start practicing.

I’m having some issues with compilation. I’m always getting this error

I’m not sure what to do. I did manage to get intellisense and highlighting enabled though so if I can figure out how to get stuff to compile I can actually start practicing.