| 180 | }; |
| 181 | |
| 182 | DeviceManager::DeviceManager() |
| 183 | : logger(common::loggerFactory("platform")) |
| 184 | , mUserDeviceOffset(0) |
| 185 | , fgMngr(nullptr) |
| 186 | , mFFTSetup(new clfftSetupData) { |
| 187 | vector<Platform> platforms; |
| 188 | try { |
| 189 | Platform::get(&platforms); |
| 190 | } catch (const cl::Error& err) { |
| 191 | #if !defined(OS_MAC) |
| 192 | // CL_PLATFORM_NOT_FOUND_KHR is not defined in Apple's OpenCL |
| 193 | // implementation. Thus, it requires this ugly check. |
| 194 | if (err.err() == CL_PLATFORM_NOT_FOUND_KHR) { |
| 195 | #endif |
| 196 | AF_ERROR( |
| 197 | "No OpenCL platforms found on this system. Ensure you have " |
| 198 | "installed the device driver as well as the OpenCL runtime and " |
| 199 | "ICD from your device vendor. You can use the clinfo utility " |
| 200 | "to debug OpenCL installation issues.", |
| 201 | AF_ERR_RUNTIME); |
| 202 | #if !defined(OS_MAC) |
| 203 | } |
| 204 | #endif |
| 205 | } |
| 206 | fgMngr = std::make_unique<arrayfire::common::ForgeManager>(); |
| 207 | |
| 208 | // This is all we need because the sort takes care of the order of devices |
| 209 | #ifdef OS_MAC |
| 210 | cl_device_type DEVICE_TYPES = CL_DEVICE_TYPE_GPU; |
| 211 | #else |
| 212 | cl_device_type DEVICE_TYPES = CL_DEVICE_TYPE_ALL; |
| 213 | #endif |
| 214 | |
| 215 | string deviceENV = getEnvVar("AF_OPENCL_DEVICE_TYPE"); |
| 216 | |
| 217 | if (deviceENV == "GPU") { |
| 218 | DEVICE_TYPES = CL_DEVICE_TYPE_GPU; |
| 219 | } else if (deviceENV == "CPU") { |
| 220 | DEVICE_TYPES = CL_DEVICE_TYPE_CPU; |
| 221 | } else if (deviceENV.compare("ACC") >= 0) { |
| 222 | DEVICE_TYPES = CL_DEVICE_TYPE_ACCELERATOR; |
| 223 | } |
| 224 | |
| 225 | AF_TRACE("Found {} OpenCL platforms", platforms.size()); |
| 226 | |
| 227 | std::map<cl::Device, cl::Context, deviceLess> mDeviceContextMap; |
| 228 | // Iterate through platforms, get all available devices and store them |
| 229 | for (auto& platform : platforms) { |
| 230 | vector<Device> current_devices; |
| 231 | |
| 232 | try { |
| 233 | platform.getDevices(DEVICE_TYPES, ¤t_devices); |
| 234 | } catch (const cl::Error& err) { |
| 235 | if (err.err() != CL_DEVICE_NOT_FOUND) { throw; } |
| 236 | } |
| 237 | AF_TRACE("Found {} devices on platform {}", current_devices.size(), |
| 238 | platform.getInfo<CL_PLATFORM_NAME>()); |
| 239 | if (!current_devices.empty()) { |
nothing calls this directly
no test coverage detected