| 371 | } |
| 372 | |
| 373 | Status CreateDefaultGPUDevice(CLDevice* result) { |
| 374 | cl_uint num_platforms; |
| 375 | clGetPlatformIDs(0, nullptr, &num_platforms); |
| 376 | if (num_platforms == 0) { |
| 377 | return UnknownError("No supported OpenCL platform."); |
| 378 | } |
| 379 | std::vector<cl_platform_id> platforms(num_platforms); |
| 380 | clGetPlatformIDs(num_platforms, platforms.data(), nullptr); |
| 381 | |
| 382 | cl_uint num_devices; |
| 383 | clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, nullptr, &num_devices); |
| 384 | if (num_devices == 0) { |
| 385 | return UnknownError("No GPU on current platform."); |
| 386 | } |
| 387 | |
| 388 | std::vector<cl_device_id> devices(num_devices); |
| 389 | clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, num_devices, devices.data(), |
| 390 | nullptr); |
| 391 | |
| 392 | *result = CLDevice(devices[0], platforms[0]); |
| 393 | return OkStatus(); |
| 394 | } |
| 395 | |
| 396 | } // namespace cl |
| 397 | } // namespace gpu |
no test coverage detected