| 74 | cl_program get_program() const { return m_program; } |
| 75 | |
| 76 | bool init(bool force_serialization) |
| 77 | { |
| 78 | deinit(); |
| 79 | |
| 80 | interval_timer tm; |
| 81 | tm.start(); |
| 82 | |
| 83 | cl_uint num_platforms = 0; |
| 84 | cl_int ret = clGetPlatformIDs(0, NULL, &num_platforms); |
| 85 | if (ret != CL_SUCCESS) |
| 86 | { |
| 87 | ocl_error_printf("ocl::init: clGetPlatformIDs() failed with %i\n", ret); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | if ((!num_platforms) || (num_platforms > INT_MAX)) |
| 92 | { |
| 93 | ocl_error_printf("ocl::init: clGetPlatformIDs() returned an invalid number of num_platforms\n"); |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | std::vector<cl_platform_id> platforms(num_platforms); |
| 98 | |
| 99 | ret = clGetPlatformIDs(num_platforms, platforms.data(), NULL); |
| 100 | if (ret != CL_SUCCESS) |
| 101 | { |
| 102 | ocl_error_printf("ocl::init: clGetPlatformIDs() failed\n"); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | cl_uint num_devices = 0; |
| 107 | ret = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 1, &m_device_id, &num_devices); |
| 108 | |
| 109 | if (ret == CL_DEVICE_NOT_FOUND) |
| 110 | { |
| 111 | ocl_error_printf("ocl::init: Couldn't get any GPU device ID's, trying CL_DEVICE_TYPE_CPU\n"); |
| 112 | |
| 113 | ret = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_CPU, 1, &m_device_id, &num_devices); |
| 114 | } |
| 115 | |
| 116 | if (ret != CL_SUCCESS) |
| 117 | { |
| 118 | ocl_error_printf("ocl::init: Unable to get any device ID's\n"); |
| 119 | |
| 120 | m_device_id = nullptr; |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | ret = clGetDeviceInfo(m_device_id, |
| 125 | CL_DEVICE_SINGLE_FP_CONFIG, |
| 126 | sizeof(m_dev_fp_config), |
| 127 | &m_dev_fp_config, |
| 128 | nullptr); |
| 129 | if (ret != CL_SUCCESS) |
| 130 | { |
| 131 | ocl_error_printf("ocl::init: clGetDeviceInfo() failed\n"); |
| 132 | return false; |
| 133 | } |
nothing calls this directly
no test coverage detected