CUDA 5.0,编译错误

时间:2013-06-02 21:22:38

标签: compiler-construction cuda compiler-errors

以下代码出错,我看不出任何理由。有人能让我知道我做错了什么。

__global__ void thekernel(float *device_a, int CELLS, int LVLS) {

   int t_id = threadIdx.x + blockDim.x * blockIdx.x;

   int INR = CELLS - 1;
   int col = INR - (threadIdx.x % CELLS);
   int row = t_id / CELLS;
   float power = (row / pow((float)LVLS, col)) % LVLS;
   device_a[t_id] = power;
 }

编译错误说明:

cudaMain.cu(11): error: expression must have integral or enum type

表达式:

float power = (row / pow((float)LVLS, col)) % LVLS;

如果我从此表达式中删除“%LVLS”,则代码会编译而不会出现任何错误。 编译字符串是:

nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "" -M -o "cudaMain.d" "../cudaMain.cu"
nvcc --compile -G -O0 -g -gencode arch=compute_20,code=compute_20 -gencode arch=compute_20,code=sm_20  -x cu -o  "cudaMain.o" "../cudaMain.cu"

硬件

我的GPU卡是:具有计算能力2.0的Quadro 6000

1 个答案:

答案 0 :(得分:1)

将幂函数转换为输入 int

int denom = (int)pow((float)LVLS, (float)col);
int power = (row / denom) % LVLS;

执行时没有任何编译错误。有趣的是,在cuda中,模数运算符仅限于整数。 (我对此不太确定)