Я получаю сообщение об ошибке при попытке использовать printf () в ядре
Я использую Visual Studio 2010 и GTX480 с возможностью вычислений 2.0.
Я попытался установить sm на 2.0, но когда я пытаюсь использовать printf () в ядре, я получаю:
ошибка: вызов функции хоста ("printf") из функции __device __ / __ global__ ("test") недопустим
Это мой код:
#include "util\cuPrintf.cu"
#include <cuda.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <cuda_runtime.h>
__global__ void test (void)
{
printf("Hello, world from the device!\n");
}
void main(void)
{
test<<<1,1>>>();
getch();
}
Я нахожу здесь пример: "CUDA_C_Programming_Guide" 'страница _106' "B.16.4 Примеры", наконец, это работа для меня: D спасибо.
#include "stdio.h"
#include <conio.h>
// printf() is only supported
// for devices of compute capability 2.0 and higher
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 200)
#define printf(f, ...) ((void)(f, __VA_ARGS__),0)
#endif
__global__ void helloCUDA(float f)
{
printf("Hello thread %d, f=%f\n", threadIdx.x, f);
}
int main()
{
helloCUDA<<<1, 5>>>(1.2345f);
cudaDeviceSynchronize();
getch();
return 0;
}