My setup for cuda
linux ubuntu 16.04+cuda 8.0+NIVIDIA GEFORCE GTX850M
My cuda code
#include <stdio.h>
#define N 64
#define TPB 32
_device_float scale(int i, int n)
{
return ((float)i)/(n - 1);
}
_device_float distance(float x1, float x2)
{
return sqrt((x2 - x1)*(x2 - x1));
}
_global_void distanceKernel(float d_out, float ref, int len)
{
const int i = blockIdx.xblockDim.x + threadIdx.x;
const float x = scale(i, len);
d_out[i] = distance(x, ref);
printf(“i = %2d: dist from %f to %f is %f.\n”, i, ref, x, d_out[i]);
}
int main()
{
const float ref = 0.5f;
float *d_out = 0;
cudaMalloc(&d_out, N*sizeof(float));
distanceKernel<<<N/TPB, TPB>>>(d_out, ref, N);
cudaFree(d_out);
return 0;
}
and Makefile code
NVCC = /usr/local/cuda/bin/nvcc
NVCC_FLAGS = -g -G -Xcompiler -Wall
main.exe: kernel.cu
$(NVCC) $(NVCC_FLAGS) $^ -o $@
When I was compiling cuda code , it awalys shows
kernel.cu(5): error: identifier “_device_float” is undefined
kernel.cu(10): error: identifier “_device_float” is undefined
kernel.cu(15): error: identifier “_global_void” is undefined
kernel.cu(31): error: a host function call cannot be configured
4 errors detected in the compilation of “/tmp/tmpxft_000011b9_00000000-9_kernel.cpp1.ii”.
How could I fix this problem? I will be very grateful if someone can help me !
(PS I just started learning cuda.)