| 407 | } |
| 408 | |
| 409 | std::vector< cl_device_id > initializeCL( cl_device_type deviceType, |
| 410 | cl_int deviceId, |
| 411 | cl_int platformId, |
| 412 | cl_context& context, |
| 413 | bool printclInfo) |
| 414 | { |
| 415 | cl_int status = 0; |
| 416 | cl_platform_id platform = NULL; |
| 417 | std::vector< cl_device_id > devices(1); |
| 418 | devices[0] = NULL; |
| 419 | |
| 420 | // Have a look at all the available platforms on this system |
| 421 | std::vector< cl_platform_id > platformInfos; |
| 422 | std::vector< std::vector< cl_device_id > > deviceInfos; |
| 423 | discoverCLPlatforms( deviceType, platformInfos, deviceInfos ); |
| 424 | |
| 425 | |
| 426 | for (unsigned int i = 0; i < platformInfos.size(); ++i) |
| 427 | { |
| 428 | if(i == platformId) |
| 429 | { |
| 430 | for (unsigned int n = 0; n < deviceInfos[i].size(); ++n) |
| 431 | { |
| 432 | if (n == deviceId) |
| 433 | { |
| 434 | platform = platformInfos[i]; |
| 435 | devices[0] = deviceInfos[i][n]; |
| 436 | |
| 437 | if(printclInfo) |
| 438 | { |
| 439 | prettyPrintPlatformInfo(platform); |
| 440 | prettyPrintDeviceInfo(devices[0]); |
| 441 | } |
| 442 | |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | |
| 452 | |
| 453 | // Do some error checking if we really selected a valid platform and a valid device |
| 454 | if (NULL == devices[0]) |
| 455 | { |
| 456 | OPENCL_V_THROW(CLFFT_DEVICE_NOT_AVAILABLE, "No devices available"); |
| 457 | } |
| 458 | |
| 459 | if (NULL == platform) |
| 460 | { |
| 461 | throw std::runtime_error("No appropriate OpenCL platform could be found"); |
| 462 | } |
| 463 | |
| 464 | // Create an OpenCL context |
| 465 | cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties) platform, 0 }; |
| 466 | context = clCreateContext(cps, |
no test coverage detected