我正在尝试为OpenCL做n身体练习。我为我的bodyForce函数使用一个结构,我需要给它一个实例作为该函数的参数。现在,我尝试在内核文件中声明该结构,因为我的内核不知道该结构(很明显),但是随后出现此OpenCL错误:
#define CL_INVALID_KERNEL_NAME -46
代码:
Opencl设置:
...
m_addKernel = clCreateKernel(m_program, "bodyForce", &err);
if (err != CL_SUCCESS)
{
cout << err << endl;
cout << "Error occured: clCreateKernel" << endl;
}
...
srcKernel.cl:
__kernel
typedef struct { float x, y, z, vx, vy, vz; } Body;
void bodyForce(__global Body *p, __global float *dtt, __global int *nn){
float dt = *dtt;
int n = *nn;
for (int i = 0; i < n; i++) {
float Fx = 0.0f; float Fy = 0.0f; float Fz = 0.0f;
for (int j = 0; j < n; j++) {
float dx = p[j].x - p[i].x;
float dy = p[j].y - p[i].y;
float dz = p[j].z - p[i].z;
float distSqr = dx * dx + dy * dy + dz * dz + 1e-9f;
float invDist = 1.0f / sqrtf(distSqr);
float invDist3 = invDist * invDist * invDist;
Fx += dx * invDist3;
Fy += dy * invDist3;
Fz += dz * invDist3;
}
p[i].vx += dt * Fx;
p[i].vy += dt * Fy;
p[i].vz += dt * Fz;
}
}
我认为其他事情不重要,但是如果我错过了一些事情,请告诉我!
谢谢。
更新:
如果我将结构像这样设置在__kernel之上:
typedef struct { float x, y, z, vx, vy, vz; } Body;
__kernel
void bodyForce(__global Body *p, __global float *dtt, __global int *nn){
...
}
然后我收到此错误消息:
ptxas application ptx input, line 94; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 135; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 176; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 222; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 259; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 296; error : Type of argument does not match formal parameter '%VAParam'
ptxas application ptx input, line 333; error : Type of argument does not match formal parameter '%VAParam'
ptxas fatal : Ptx assembly aborted due to errors
答案 0 :(得分:1)
您需要在函数定义之前放置__kernel
属性:
typedef struct { float x, y, z, vx, vy, vz; } Body;
__kernel
void bodyForce(__global Body *p, __global float *dtt, __global int *nn) {
}