how to create do offline compilation in opencl and create its binary?

白昼怎懂夜的黑 提交于 2019-12-01 06:34:43

问题


In online compilation of OpenCl, we have to do...

program = clCreateProgramWithSource(context, 1, (const char **)&source_str, (const size_t *)&source_size, &ret);

But, for offline creation of program for opencl..

program = clCreateProgramWithBinary(context, 1, &device_id, (const size_t *)&binary_size, (const unsigned char **)&binary_buf, &binary_status, &ret);

where binary_buf is...

fread(binary_buf, 1, MAX_BINARY_SIZE, fp);

Hence in offline compilation, we can skip the clBuildProgram step, which makes this step faster. (Is this approach correct, that we can re-use again and again that binary for running the program?)

So, my question is how to create opencl binary file so i can skip the step of building cl program?


回答1:


Once the program has been created you can use clGetProgramInfo with CL_PROGRAM_BINARY_SIZES and then CL_PROGRAM_BINARIES, storing the resulting binary programs (one for each device of the context) into a buffer you supply. You can then save this binary data to disk for use in later runs.

Not all devices might support binaries, so you will need to check the CL_PROGRAM_BINARY_SIZES result (it returns a zero size for that device if binaries are not supported).

To save time in the future (say in future runs of your application), you can use clCreateProgramWithBinary with the returned binaries. However, you will only ever want to do this with exactly the same hardware. Even when the graphics driver changes for the same hardware, you might want to throw the binary away and rebuild since there is potential the OpenCL compiler in the new driver has bugfixes and/or performance improvements.



来源:https://stackoverflow.com/questions/23601058/how-to-create-do-offline-compilation-in-opencl-and-create-its-binary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!