Monday, 3 June 2013

CUDA 5.0 Hello World

Time for my first CUDA 'Hello World' program. Well, there won't be any GPU processing in it, but at least I'll prove that my environment is fully operational. Let's get to work!

I'll start by creating new Win32 Console Application (selecting 'Empty Project' option). Although it is a Visual C++ project, I will try to stick to C as I simply feel more confident using this language and don't want the OOP getting in my way.

First of all, since I use 64-bit windows, I changed my program to target the x64 platform.

Next, I selected CUDA 5.0 targets in my project's build customization options.

And I modify my project's Include and Library directories adding $(CUDA_INC_PATH) and $(CUDA_LIB_PATH) respectively (these settings can be located in project's properties menu -> Configuration Properties -> VC++ Directories).

Next thing is to change the nvcc parameters (by default they are set to compute_10,sm_10 which you probably don't want). To utilise full potential of your GPU, please adjust these parameters according to CUDA wiki. In my case it is compute_30,sm_30.

Last thing to do before I started writing code was to change CUDA/C++ target machine platform, which was still 32-bit.

And finally, my project nicely compiles (Intellisense complains about the angle brackets though, but I have yet to find an answer for this one).

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <stdio.h>

#pragma comment(lib, "cudart") 

__global__ void mykernel(void)

int main(void)
 printf("Hello World!\n");
 return 0;

No comments:

Post a Comment