[英]Expression must have pointer-to-object type
I have the following code in CUDA我在 CUDA 中有以下代码
__global__ void matvec(int *MAT, int *VEC, int *SOL)
{
int bx = blockIdx.x;
int tx = threadIdx.x;
int i = 32*bx+tx;
for (int j = 0; j < X; j++){
SOL[i] = ((MAT[i][j] * VEC[j]) + SOL[i]) % 2;
}
}
My problem is that in line 6 I have an error.我的问题是在第 6 行我有一个错误。 It says that my expression must have a pointer-to-object type.
它说我的表达式必须有一个指向对象的类型。
The reason for the error is that you are treating a pointer as a 2D array.错误的原因是您将指针视为二维数组。 You define
MAT
as int *MAT
, but you access it as MAT[i][j]
.您将
MAT
定义为int *MAT
,但您将其作为MAT[i][j]
。
Assuming you have correctly allocated MAT
, I would change this to MAT[i*X + j]
.假设您已正确分配
MAT
,我会将其更改为MAT[i*X + j]
。 Alternatively, define MAT
as int **MAT
, again, assuming you have allocated it correctly.或者,再次将
MAT
定义为int **MAT
,假设您已正确分配它。
(BTW, this is not a CUDA problem, it is a simple C syntax error.) (顺便说一句,这不是 CUDA 问题,而是一个简单的 C 语法错误。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.