Bibrak
Bibrak

Reputation: 554

How to preprocess OpenCL kernel?

Its simple to call the preprocessor on a c/c++ code:

g++ -E <file>.cpp 

And it passes through the preprocessor and generates the preprocessed code.

I have OpenCL kernel in .cl how to achieve the same?

This is what I did and failed:

g++ -E -I. -std=c++11 -g -O3 -march=native -I/path/to/opencl/include/  -Wno-unused-result kernel.cl -L/path/to/opencl/lib/x86_64/ -lOpenCL -lquadmath
g++: warning: kernel.cl: linker input file unused because linking not done

Thanks

Upvotes: 1

Views: 536

Answers (1)

user6409506
user6409506

Reputation:

OpenCL code can run on a different architecture to the one that you are using to compile this on. You might find that there are differences depending on the complile time settings in the code that depend on the physical configuration of the target.

The most reliable method for generation of the postprocessed code for AMD devices is to ask the framework to save the temporary files, including the postprocessed output files.

On linux all you need to do for AMD is set an environment varisable. ie:

 export AMD_OCL_BUILD_OPTIONS_APPEND="-save-temps"

When you compile you opencl program you will see a few files in /tmp. The one with the .i extension is the postprocessed file. This might be different to the one that you will get using cpp on the host architecture.

Upvotes: 1

Related Questions