problems running code


I am trying to run a small test on my graphics card using cuda, though it seems I dont get any data returned from a kernel.

Here is the code of “”:

#include <iostream>

__global__ void cudaTest (int* C)


	*C = 20;


int main ()


	int C = 12;


	cudaTest<<<1, 1>>>(&C);


	std::cout << C << "\n";


I expect the last line to print “20” on my screen, but i just get the declared “12”;

Compiling with “nvcc” doesnt show any error (Doesnt give any output at all - but thats good for a compiler i guess :D).

I am running an Ubuntu 9.04 with nvidia cuda drivers installed succesfully and a 9600 GT. I got those lines in my “~/.bashrc” as mentioned in the programmers guide:


export PATH



Checking dmesg after executing the compiled code i get:

NVRM: Xid (0004:00): 13, 0004 00000000 000050c0 00000368 00000000 00000100

Can anyone explain what I am doing wrong?

Thanks and greetings.

You kernel is never running because you are trying to pass a host pointer, which is illegal. The GPU and host CPU have separate memory spaces, and you must declare and allocate memory in each separately and explicitly copy from one to the other. Pointers in each memory space are not interchangeable. How to do this is covered in Chapter 3 of the Programming Guide.

What he said ^

The general procedure is

  1. Allocate GPU-memory
  2. Allocate Host-memory
  3. Run Kernel, passing GPU-pointer
  4. Copy data from GPU-memory to Host-memory
  5. Print