且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

包括头文件到OpenCL .cl文件

更新时间:2023-09-19 23:20:22

OpenCL requires you use clCreateProgramWithSource() followed by clBuildProgram().

ClCreateProgramWithSource() creates and returns a cl_program object.

That cl_program object is input into clBuildProgram().

clBuildProgram() allows you to specify compiler options which include the include file directories. In your case, for header file includes, it will be something like the string:

-I myincludedir1 -I myincludedir2  ...

The compiler used is the internal OpenCL compiler in the OpenCL SDK you are using. So if you are using AMD's SDK, the AMD OpenCL compiler that is part of their OpenCL SDK will be used. Likewise for Nvidia or Intel.

Its important to check the OpenCL status code for ALL OpenCL function calls. This is mandatory for clCreateProgramWithSource() and clBuildProrgam() to get any compiler errors or messages. There is a whole other bit code to write to get the size of the messages and then retrieve the messages themselves.