我正在尝试使用clCreateProgramWithBinary获得一个基本程序.这是我知道如何使用它而不是"真正的"应用程序.
我看到其中一个参数是二进制文件列表.我究竟要如何创建一个二进制文件来测试?我有一些测试代码,它从源代码创建程序,构建和排队.在这个过程中的某个时刻是否有一个二进制文件可以输入clCreateProgramWithBinary?
这是我的一些代码,只是为了了解我的整体流程.为简单起见,我省略了注释和错误检查.
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);
Run Code Online (Sandbox Code Playgroud)
编译程序后,您可以使用clGetProgramInfo获取其二进制代码,然后将其保存到文件中。
示例代码(未尝试编译,但应该是这样的):
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6219 次 |
| 最近记录: |