15#ifndef MAKEFILES_OPENCL_OBTAIN_PROGRAMH
16#define MAKEFILES_OPENCL_OBTAIN_PROGRAMH
22static int32_t _makefiles_opencl_obtain_program_helper(cl_context context, cl_uint num_devices, cl_device_id* devices, cl_program*
program,
char* binaries)
24 const char* magic_bytes =
"QOCLPB";
25 if (strncmp(magic_bytes, binaries, strlen(magic_bytes)) != 0) {
26 printf(
"Internal error accessing opencl program\n");
29 char* current_ptr = binaries + strlen(magic_bytes) + 1;
33 if (num_devices != pinfo->
count) {
34 printf(
"Number of devices differs from number of devices in opencl program\n");
39 std::vector<size_t> program_sizes(pinfo->
count);
40 std::vector<char*> program_binaries(pinfo->
count);
42 for (uint32_t
i = 0;
i < pinfo->
count;
i++) {
43 char device_name[64], device_vendor[64];
45 clGetDeviceInfo(devices[
i], CL_DEVICE_NAME, 64, device_name,
nullptr);
46 clGetDeviceInfo(devices[
i], CL_DEVICE_VENDOR, 64, device_vendor,
nullptr);
47 clGetDeviceInfo(devices[
i], CL_DEVICE_ADDRESS_BITS,
sizeof(nbits), &nbits,
nullptr);
50 printf(
"Device list is different to device list from opencl program (Device %d: '%s - %s' != '%s - %s')\n",
i, device_vendor, device_name, dinfo->
device_vendor, dinfo->
device_name);
53 if (nbits != dinfo->
nbits) {
54 printf(
"Pointer size of device and stored device binary differs\n");
60 program_binaries[
i] = current_ptr;
64 cl_int return_status[pinfo->
count];
66 *
program = clCreateProgramWithBinary(context, num_devices, devices, program_sizes.data(), (
const uint8_t**)program_binaries.data(), return_status, &ocl_error);
68 if (ocl_error != CL_SUCCESS) {
69 printf(
"Error loading program\n");
73 for (uint32_t
i = 0;
i < pinfo->
count;
i++) {
74 if (return_status[
i] != CL_SUCCESS) {
75 printf(
"Error loading program for device %d\n",
i);
81 ocl_error = clBuildProgram(*
program, num_devices, devices,
"",
nullptr,
nullptr);
82 if (ocl_error != CL_SUCCESS) {
83 printf(
"Error building program\n");
GLbitfield GLuint program