bool load_binary(const string& kernel_path, const string& clbin) { /* read binary into memory */ vector<uint8_t> binary; if(!path_read_binary(clbin, binary)) { opencl_error(string_printf("OpenCL failed to read cached binary %s.", clbin.c_str())); return false; } /* create program */ cl_int status; size_t size = binary.size(); const uint8_t *bytes = &binary[0]; cpProgram = clCreateProgramWithBinary(cxContext, 1, &cdDevice, &size, &bytes, &status, &ciErr); if(opencl_error(status) || opencl_error(ciErr)) { opencl_error(string_printf("OpenCL failed create program from cached binary %s.", clbin.c_str())); return false; } if(!build_kernel(kernel_path)) return false; return true; }
bool path_read_text(const string& path, string& text) { vector<uint8_t> binary; if(!path_exists(path) || !path_read_binary(path, binary)) return false; const char *str = (const char*)&binary[0]; size_t size = binary.size(); text = string(str, size); return true; }