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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With