| 29 | #include <vector> |
| 30 | |
| 31 | static amd::Program* createProgram(cl_context context, cl_uint num_devices, |
| 32 | const cl_device_id* device_list, cl_int* errcode_ret) { |
| 33 | // Create the program |
| 34 | amd::Program* program = new amd::Program(*as_amd(context)); |
| 35 | if (program == NULL) { |
| 36 | *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; |
| 37 | return NULL; |
| 38 | } |
| 39 | |
| 40 | // Add programs for all devices in the context. |
| 41 | if (device_list == NULL) { |
| 42 | const std::vector<amd::Device*>& devices = as_amd(context)->devices(); |
| 43 | for (const auto& it : devices) { |
| 44 | if (program->addDeviceProgram(*it) == CL_OUT_OF_HOST_MEMORY) { |
| 45 | *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; |
| 46 | program->release(); |
| 47 | return NULL; |
| 48 | } |
| 49 | } |
| 50 | return program; |
| 51 | } |
| 52 | |
| 53 | *not_null(errcode_ret) = CL_SUCCESS; |
| 54 | for (cl_uint i = 0; i < num_devices; ++i) { |
| 55 | cl_device_id device = device_list[i]; |
| 56 | |
| 57 | if (!is_valid(device) || !as_amd(context)->containsDevice(as_amd(device))) { |
| 58 | *not_null(errcode_ret) = CL_INVALID_DEVICE; |
| 59 | program->release(); |
| 60 | return NULL; |
| 61 | } |
| 62 | |
| 63 | cl_int status = program->addDeviceProgram(*as_amd(device)); |
| 64 | if (status == CL_OUT_OF_HOST_MEMORY) { |
| 65 | *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; |
| 66 | program->release(); |
| 67 | return NULL; |
| 68 | } |
| 69 | } |
| 70 | return program; |
| 71 | } |
| 72 | |
| 73 | /*! \addtogroup API |
| 74 | * @{ |
no test coverage detected