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); }
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); }
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); }