opencl c file fails to compile
Question: What is missing from this function/kernel declaration that is keeping it from compiling?
Info:
__kernel void square(
__global float* input,
__global float* output,
const unsigned int count)
{
in开发者_C百科t i = get_global_id(0);
if(i < count)
output[i] = input[i] * input[i];
}
The code snippet above compiles on my graphics card. I've gotten this to work, but i decided for maintenance reasons it would be better to move the code from a string in my file to a separate file and simply read it in, nothing out of the ordinary. I figured that, in theory, i should be able to compile this code, whether or not it runs, but at least debug in gcc and command line then at run time with my gpu.
but the code above simply gives me the error:
GalGenCL.cl.c:51:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’
and that was the same error I got with the actual code I wanted to use:
__kernel void force(__global float* Galaxy, const unsigned int count)
{
int i = get_global_id(0);
float x,y,z,d,force;
int j;
for(j = 0; j < starc; j++)
{
if (j == i) continue;
//find relative distance
x = Galaxy[i][1] - Galaxy[j][1];
y = Galaxy[i][2] - Galaxy[j][2];
z = Galaxy[i][3] - Galaxy[j][3];
d = x*x+y*y+z*z;
if (d == 0) continue;
force = ((0.00000066742799999999995)*Galaxy[i][0]*Galaxy[j][0])/(d);
Galaxy[i][7] = (x*x)*force*(-1)/d;
Galaxy[i][8] = (y*y)*force*(-1)/d;
Galaxy[i][9] = (z*z)*force*(-1)/d;
}//end for loop
}
so i tried changing to this:
__kernel __attribute__((vec_type_hint(float)));
void force(__global float* Galaxy, const unsigned int count)
and got this:
GalGenCL.cl.c:8:1: warning: data definition has no type or storage class GalGenCL.cl.c:8:39: error: expected expression before ‘float’ GalGenCL.cl.c:8:45: error: expected ‘,’ or ‘;’ before ‘)’ token GalGenCL.cl.c:9:21: error: expected ‘)’ before ‘float’
so i changed again, taking the float out:
__kernel __attribute__((vec_type_hint()));
void force(__global float* Galaxy, const unsigned int count)
that made it a little happier:
GalGenCL.cl.c:8:1: warning: data definition has no type or storage class GalGenCL.cl.c:8:1: warning: ‘vec_type_hint’ attribute directive ignored GalGenCL.cl.c:9:21: error: expected ‘)’ before ‘float’
but still it wouldn't accept "float" from the function header, so i got ride of the semicolon. then it complained:
GalGenCL.cl.c:9:1: error: expected ‘,’ or ‘;’ before ‘void’
so now I'm just all kinds of clueless. what exactly it looking for?
OpenCL is a extension to C, and as such, a C compiler will not parse and compile it if any extensions are used.
It therefore does not make sense to have a GalGenCL.cl.c file to be processed by a C compiler, unless the extensions are explicitly accounted for - possibly via #define
to hide or remove them.
It would seem the the __kernel
modifier is being problematic in compilation.
What command line is being used to compile your program?
精彩评论