1
votes

I am trying to do the n-Body excercise for OpenCL. I use a struct for my bodyForce function and I need to give an instance of it as an argument to the function. Now I am trying to declare the struct in my kernel file because my kernel doesn't know the struct (Obviously) but Then I get this OpenCL error:

#define CL_INVALID_KERNEL_NAME                      -46
  • I checked the kernel name and it matches
  • I changed the name of my kernel to something else
  • I used a header file, const char pointer and just implemented the struct in my kernel file

CODE:

Opencl setup:

...
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;
}

}

I don't think something else is important but if i missed something then let me know!

Thanks in advance.


Update:

If I set my struct above my __kernel like this:

typedef struct { float x, y, z, vx, vy, vz; } Body;
__kernel
void bodyForce(__global Body *p, __global float *dtt, __global int *nn){
...
}

Then I get this error message:

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
1
This does seem like a compiler bug. I suggest to get a minimal reproducer and contact Nvidia support.Andrew Savonichev
I'd probably run it through a different OpenCL implementation first (Intel, AMD, whatever) and check if there's anything any of us have missed, but if the code compiles fine there, I'd agree with @AndrewSavonichev that the output suggests a compiler bug.pmdj

1 Answers

1
votes

You need to put __kernel attribute before function definition:

typedef struct { float x, y, z, vx, vy, vz; } Body;

__kernel
void bodyForce(__global Body *p, __global float *dtt, __global int *nn) {
}