Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA 4.1 printf() Error

Tags:

cuda

Even though I have a fermi card(gtx 560) I get this error on VS2010:

error : calling a host function("printf") from a __device__/__global__ function("kernel") is not allowed

Code:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>

__global__ void kernel()
{
  printf("hello");
}

int main()
{
  kernel<<<1, 1>>>();
  return 0;
}

Am I missing something here?

like image 938
dvgvrco Avatar asked Mar 17 '12 11:03

dvgvrco


1 Answers

You need to make sure you are compiling for the correct architecture. Only Fermi and Kepler cards (so compute capability 2.0, 2.1, 3.0 and 3.5 devices) support printf in kernels. If you compile your code like this:

nvcc -arch=sm_21 [other options] .....

the code should build correctly. The default architecture is compute 1.0, which is why you are getting the error. If you use Visual studio, there should be a project option to select the target architecture, although I can't tell you precisely where to find that as I don't use it with CUDA.

like image 65
talonmies Avatar answered Oct 25 '22 04:10

talonmies