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

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

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!

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

 

 

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today