PUBLIC cl_int clGetProgramBuildInfo(cl_program prog, cl_device_id dev, cl_program_build_info param, size_t size, void *buf, size_t *size_ret) { if (!prog) return CL_INVALID_PROGRAM; if (!prog->ctx.has_device(dev)) return CL_INVALID_DEVICE; switch (param) { case CL_PROGRAM_BUILD_STATUS: return scalar_property<cl_build_status>(buf, size, size_ret, prog->build_status(dev)); case CL_PROGRAM_BUILD_OPTIONS: return string_property(buf, size, size_ret, prog->build_opts(dev)); case CL_PROGRAM_BUILD_LOG: return string_property(buf, size, size_ret, prog->build_log(dev)); default: return CL_INVALID_VALUE; } }
PUBLIC cl_int clBuildProgram(cl_program prog, cl_uint count, const cl_device_id *devs, const char *opts, void (*pfn_notify)(cl_program, void *), void *user_data) try { if (!prog) throw error(CL_INVALID_PROGRAM); if (bool(count) != bool(devs) || (!pfn_notify && user_data)) throw error(CL_INVALID_VALUE); if (devs) { if (any_of([&](const cl_device_id dev) { return !prog->ctx.has_device(dev); }, devs, devs + count)) throw error(CL_INVALID_DEVICE); prog->build({ devs, devs + count }); } else { prog->build(prog->ctx.devs); } return CL_SUCCESS; } catch (error &e) { return e.get(); }
bool is_valid(cl_program p) { global_mutex.lock(); const bool r = valid_programs.count(p) != 0 && p->valid(); if (r) p->lock(); global_mutex.unlock(); return r; }
cl_int clRetainProgram(cl_program program) { if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; program->reference(); return CL_SUCCESS; }
cl_int clReleaseProgram(cl_program program) { if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; if (program->dereference()) delete program; return CL_SUCCESS; }
cl_int clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; return program->info(param_name, param_value_size, param_value, param_value_size_ret); }
PUBLIC cl_int clGetProgramInfo(cl_program prog, cl_program_info param, size_t size, void *buf, size_t *size_ret) { if (!prog) return CL_INVALID_PROGRAM; switch (param) { case CL_PROGRAM_REFERENCE_COUNT: return scalar_property<cl_uint>(buf, size, size_ret, prog->ref_count()); case CL_PROGRAM_CONTEXT: return scalar_property<cl_context>(buf, size, size_ret, &prog->ctx); case CL_PROGRAM_NUM_DEVICES: return scalar_property<cl_uint>(buf, size, size_ret, prog->binaries().size()); case CL_PROGRAM_DEVICES: return vector_property<cl_device_id>( buf, size, size_ret, map(keys<device *, module>, prog->binaries().begin(), prog->binaries().end())); case CL_PROGRAM_SOURCE: return string_property(buf, size, size_ret, prog->source()); case CL_PROGRAM_BINARY_SIZES: return vector_property<size_t>( buf, size, size_ret, map([](const std::pair<device *, module> &ent) { compat::ostream::buffer_t bin; compat::ostream s(bin); ent.second.serialize(s); return bin.size(); }, prog->binaries().begin(), prog->binaries().end())); case CL_PROGRAM_BINARIES: return matrix_property<unsigned char>( buf, size, size_ret, map([](const std::pair<device *, module> &ent) { compat::ostream::buffer_t bin; compat::ostream s(bin); ent.second.serialize(s); return bin; }, prog->binaries().begin(), prog->binaries().end())); default: return CL_INVALID_VALUE; } }
cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; return program->buildInfo((Coal::DeviceInterface *)device, param_name, param_value_size, param_value, param_value_size_ret); }
cl_int clReleaseProgram(cl_program program) { #ifdef DBG_API std::cerr << "Entering clReleaseProgram\n"; #endif if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; if (program->dereference()) delete program; #ifdef DBG_API std::cerr << "Leaving clReleaseProgram\n"; #endif return CL_SUCCESS; }
cl_int clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { #ifdef DBG_API std::cerr << "clGetProgramInfo\n"; #endif if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; return program->info(param_name, param_value_size, param_value, param_value_size_ret); }
PUBLIC cl_int clRetainProgram(cl_program prog) { if (!prog) return CL_INVALID_PROGRAM; prog->retain(); return CL_SUCCESS; }
PUBLIC cl_int clReleaseProgram(cl_program prog) { if (!prog) return CL_INVALID_PROGRAM; if (prog->release()) delete prog; return CL_SUCCESS; }
cl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id * device_list, const char * options, void (*pfn_notify)(cl_program program, void * user_data), void * user_data) { #ifdef DBG_API std::cerr << "Entering clBuildProgram. Building for " << num_devices << " devices\n"; #endif if (!program->isA(Coal::Object::T_Program)) { std::cerr << "INVALID_PROGRAM\n"; return CL_INVALID_PROGRAM; } if (!device_list && num_devices > 0) { std::cerr << "!device_list : INVALID_VALUE\n"; return CL_INVALID_VALUE; } if (!num_devices && device_list) { std::cerr << "!num_devices : INVALID_VALUE\n"; return CL_INVALID_VALUE; } if (!pfn_notify && user_data) { std::cerr << "!pfn_notify : INVALID_VALUE\n"; return CL_INVALID_VALUE; } // We cannot try to build a previously-failed program if (program->state() != Coal::Program::Loaded) return CL_INVALID_OPERATION; #ifdef DBG_API std::cerr << "Checking " << num_devices << " devices\n"; #endif // Check the devices for compliance //if (num_devices) //{ cl_uint context_num_devices = 0; cl_device_id *context_devices; Coal::Context *context = (Coal::Context *)program->parent(); cl_int result; result = context->info(CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), &context_num_devices, 0); if (result != CL_SUCCESS) return result; context_devices = (cl_device_id *)std::malloc(context_num_devices * sizeof(cl_device_id)); result = context->info(CL_CONTEXT_DEVICES, context_num_devices * sizeof(cl_device_id), context_devices, 0); if (result != CL_SUCCESS) { #ifdef DBG_API std::cerr << "context->info != CL_SUCCESS\n"; #endif return result; } #ifdef DBG_API std::cerr << "Checking " << context_num_devices << " context devices\n"; #endif if (num_devices) { for (cl_uint i=0; i < num_devices; ++i) { bool found = false; #ifdef DBG_API std::cerr << "device_list[" << i << "] addr = " << device_list[i] << std::endl; #endif for (cl_uint j=0; j<context_num_devices; ++j) { #ifdef DBG_API std::cerr << "context_device [" << j << "] addr = " << context_devices[j] << std::endl; #endif if (device_list[i] == context_devices[j]) { found = true; #ifdef DBG_API std::cerr << "Found device, break out\n"; #endif break; } } if (!found) { std::cerr << "INVALID_DEVICE\n"; return CL_INVALID_DEVICE; } } #ifdef DEBUCL std::cerr << "Leaving clBuildProgram after program->build\n"; #endif // Build program return program->build(options, pfn_notify, user_data, num_devices, (Coal::DeviceInterface * const*)device_list); } // num devices wasn't specified and device_list is probably null, so // build for all associated devices else { #ifdef DEBUCL std::cerr << "Leaving clBuildProgram after program->build\n"; #endif return program->build(options, pfn_notify, user_data, context_num_devices, context->getAllDevices()); } return NULL; }
cl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id * device_list, const char * options, void (*pfn_notify)(cl_program program, void * user_data), void * user_data) { if (!program->isA(Coal::Object::T_Program)) return CL_INVALID_PROGRAM; if (!device_list && num_devices > 0) return CL_INVALID_VALUE; if (!num_devices && device_list) return CL_INVALID_VALUE; if (!pfn_notify && user_data) return CL_INVALID_VALUE; // Check the devices for compliance if (num_devices) { cl_uint context_num_devices = 0; cl_device_id *context_devices; Coal::Context *context = (Coal::Context *)program->parent(); cl_int result; result = context->info(CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), &context_num_devices, 0); if (result != CL_SUCCESS) return result; context_devices = (cl_device_id *)std::malloc(context_num_devices * sizeof(cl_device_id)); result = context->info(CL_CONTEXT_DEVICES, context_num_devices * sizeof(cl_device_id), context_devices, 0); if (result != CL_SUCCESS) return result; for (cl_uint i=0; i<num_devices; ++i) { bool found = false; for (cl_uint j=0; j<context_num_devices; ++j) { if (device_list[i] == context_devices[j]) { found = true; break; } } if (!found) return CL_INVALID_DEVICE; } } // We cannot try to build a previously-failed program if (program->state() != Coal::Program::Loaded) return CL_INVALID_OPERATION; // Build program return program->build(options, pfn_notify, user_data, num_devices, (Coal::DeviceInterface * const*)device_list); }