1

以下代码给出了一个错误,我看不出有任何原因。有人可以让我知道我做错了什么。

__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

4

1 回答 1

1

将幂函数转换为int类型有效。

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

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

于 2013-06-02T21:52:51.080 回答