AnsweredAssumed Answered

include headers into opencl kernels

Question asked by shawnccx on Apr 18, 2013
Latest reply on Sep 28, 2013 by krunalpatelamd

Hi all,

 

I need to include some .h files into .cl OpenCL kernels but I haven't found a way to solve it.

 

My problem is described as follows:

1.

(1) a kernel in example.cl file:

 

__kernel void example_kernel(length m, length n){

    ....

}

 

(2) type length is defined in test_header.h (in the same directory of all the other files)

 

typedef int length;

 

(3) According to OpenCL Spec, adding -I when building program

 

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-I ./", NULL, NULL);

 

But this doesn't work, the program got crashed at this line, the log of building program showed:

 

"/tmp/OCLkQF3NK.cl", line 2: error: overloaded function "length" is not a type

          name

  __kernel void example_kernel(length m, length n)

                             ^

 

"/tmp/OCLkQF3NK.cl", line 2: error: overloaded function "length" is not a type

          name

  __kernel void example_kernel(length m, length n)

                                       ^

 

2 errors detected in the compilation of "/tmp/OCLkQF3NK.cl".

 

Internal error: clc compiler invocation failed.

 

2. I tried again to include test_header.h in .cl file (I know this is forbidden in OpenCL Spec)

The program still got crashed when building, and the log became:

 

"./test_header.h", line 2: error: "length" has already been declared in the

          current scope

  typedef int length;

              ^

 

1 error detected in the compilation of "/tmp/OCLmy1VZ1.cl".

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Previously I just redefined them as Macros in the kernels to avoid including headers. But now, too many functions from the headers are needed, so I need to find a way to import the headers for kernel.

 

Is anyone seeing what could be the problem? I really need help with this.

 

thanks

 

Chongxiao

Outcomes