如何在opencl中创建脱机编译并创建其二进制文件? [英] how to create do offline compilation in opencl and create its binary?

查看:74
本文介绍了如何在opencl中创建脱机编译并创建其二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenCl的在线编译中,我们必须做...

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

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

但是,用于离线创建opencl程序.

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);

binary_buf是...

where binary_buf is...

fread(binary_buf, 1, MAX_BINARY_SIZE, fp);

因此,在脱机编译中,我们可以跳过clBuildProgram步骤,这会使该步骤更快. (这种方法正确吗,我们可以一次又一次地重复使用该二进制文件来运行程序?)

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?)

所以,我的问题是如何创建opencl二进制文件,以便跳过构建cl程序的步骤?

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

推荐答案

一旦创建了程序,就可以使用

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.

并非所有设备都支持二进制文件,因此您需要检查CL_PROGRAM_BINARY_SIZES结果(如果不支持二进制文件,则该设备的大小为零).

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).

要节省将来的时间(例如在应用程序的将来运行中),可以对返回的二进制文件使用clCreateProgramWithBinary.但是,您将永远只想使用完全相同的硬件来执行此操作.即使图形驱动程序针对相同的硬件进行了更改,您仍可能希望丢弃二进制文件并进行重建,因为新驱动程序中的OpenCL编译器可能会修正错误和/或改善性能.

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.

这篇关于如何在opencl中创建脱机编译并创建其二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆