OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1718 Discussions

How to link to OpenCL binary library created with clLinkProgram "-create-library"

Andy_R
Beginner
906 Views

Can someone please tell me how to link to the program library created in the following way:

lib = clLinkProgram(context, NULL, NULL, "-create-library ", 1, &prog, NULL, NULL, &err);

I can happily produce this object for our static OpenCL library functions at start up but there seems to be no way to link to it with our dynamically generated kernel program.

I'm not sure exactly how we are supposed to use the OpenCL binary library type created as above as it is rejected by any further attempts to link to compiled kernel programs with CL_LINK_FAILURE.

Any advice much appreciated - thanks!

0 Kudos
2 Replies
Robert_I_Intel
Employee
906 Views

Andy,

Note the signature for clLinkProgram:

cl_program clLinkProgram ( cl_context context,

 cl_uint num_devices,

 const cl_device_id *device_list,

 const char *options,

 cl_uint num_input_programs,

 const cl_program *input_programs,

 void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data),

 void *user_data,

 cl_int *errcode_ret)

Usually, when you call clLinkProgram without -create-library flag, your num_inputs_programs parameter will be equal to 2 or more, and your input_programs parameter will list your compiled program as the first program, and one ore more library programs as your second and subsequent parameters.

Here is a degenerate example:

   err = clCompileProgram(ocl->program, 1, &ocl->device, "", 0, nullptr, nullptr, nullptr, nullptr);
 cl_program foo = clLinkProgram(ocl->context, 1, &ocl->device, "-create-library", 1, &ocl->program, nullptr, nullptr, &err);
 cl_program linked = clLinkProgram(ocl->context, 1, &ocl->device, "", 1, &foo, nullptr, nullptr, &err);

Here we compile the program ocl-program, then create library out of it returning the program foo, then link foo (valid, if our original program contains all the kernels and has no dependencies) producing the program linked. Now use linked program to create your kernels.

 

 

0 Kudos
liang_p_
Beginner
906 Views

Hi Robert,

I have never had any luck linking a library and a compiled program or two compiled programs to create a kernel program. The attempt to do so always ended up in error -17, and no further error info could not be retrieved. In your example there was only one program involved. I am wondering if you have done anything that involved linking more than one compiled program. I need someone to instruct me on how to accomplish that. Any insight will be greatly appreciated.

Thanks,

Liang

0 Kudos
Reply