如何在OpenCL中使用clCreateProgramWithBinary? [英] How to use clCreateProgramWithBinary in OpenCL?

查看:426
本文介绍了如何在OpenCL中使用clCreateProgramWithBinary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用clCreateProgramWithBinary使一个基本程序正常工作.这样我就知道如何使用它,而不是一个真正的"应用程序.

I'm trying to just get a basic program to work using clCreateProgramWithBinary. This is so I know how to use it rather than a "true" application.

我看到参数之一是二进制列表.我将如何精确地创建一个二进制文件进行测试?我有一些测试代码,这些代码可以从源代码创建程序,并对其进行排队和入队.在此过程中的某个时刻是否创建了二进制文件,可以将其输入clCreateProgramWithBinary?

I see that one of the parameters is a list of binaries. How exactly would I go about creating a binary to test with? I have some test code which creates a program from source, builds and enqueues it. Is there a binary created at some point during this process which I can feed into clCreateProgramWithBinary?

这是我的一些代码,目的只是为了让我了解我的整体流程.为了简单起见,我省略了注释和错误检查.

Here is some of my code, just to give an idea of my overall flow. I've omitted comments and error checks for simplicity.

program = clCreateProgramWithSource(clctx, 1, &dumbkernelsource, NULL, &errcode);
errcode = clBuildProgram(program, env->num_devices, env->device, NULL, NULL, NULL);
mykernel = clCreateKernel(program, "flops", &errcode);
errcode = clGetKernelWorkGroupInfo(mykernel, *(env->device), CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL);
global = num_workgroups * local;
errcode = clEnqueueNDRangeKernel(commands, mykernel, 1, NULL, &global, &local, 0, NULL, NULL);

推荐答案

编译程序后,您可以使用

After you compile your program, you can get its binary code with clGetProgramInfo, and then save it to a file.

示例代码(未尝试编译,但应遵循以下原则):

Example code (not tried to compile, but should be something along these lines):

program = clCreateProgramWithSource(clctx, 1, &dumbkernelsource, NULL, &errcode);
errcode = clBuildProgram(program, env->num_devices, env->device, NULL, NULL, NULL);
int number_of_binaries;
char **binary;
int *binary_sizes;
errcode = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, NULL, 0, &number_of_binaries);
binary_sizes = new int[number_of_binaries];
binary = new char*[number_of_binaries];
errcode = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, binary_sizes, number_of_binaries*sizeof(int), &number_of_binaries);
for (int i = 0; i < number_of_binaries; ++i) binary[i] = new char[binary_sizes[i]];
errcode = clGetProgramInfo(program, CL_PROGRAM_BINARIES, binary, number_of_binaries*sizeof(char*), &number_of_binaries);

这篇关于如何在OpenCL中使用clCreateProgramWithBinary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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