MCPcopy Create free account
hub / github.com/clMathLibraries/clFFT / discoverCLPlatforms

Function discoverCLPlatforms

src/callback-client/openCL.misc.cpp:357–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355
356
357int discoverCLPlatforms( cl_device_type deviceType,
358 std::vector< cl_platform_id >& platforms,
359 std::vector< std::vector< cl_device_id > >& devices )
360{
361 cl_int status = 0;
362
363 /*
364 * Find all OpenCL platforms this system has to offer.
365 */
366
367 cl_uint numPlatforms = 0;
368 cl_platform_id platform = NULL;
369 OPENCL_V_THROW(::clGetPlatformIDs(0, NULL, &numPlatforms),
370 "Getting number of platforms( ::clGetPlatformsIDs() )");
371
372 if (numPlatforms > 0)
373 {
374 platforms.resize( numPlatforms );
375 devices.resize( numPlatforms );
376 OPENCL_V_THROW(::clGetPlatformIDs(numPlatforms, &platforms[0], NULL),
377 "Getting Platform Id's ( ::clGetPlatformsIDs() )");
378
379 if (NULL == platforms[0])
380 {
381 throw std::runtime_error("No appropriate OpenCL platform could be found");
382 }
383
384 /*
385 * Now, for each platform get all available devices matching deviceType.
386 */
387 for (unsigned int i = 0; i < numPlatforms; ++i)
388 {
389 // Get the device list for deviceType.
390 //
391 cl_uint numDevices = 0;
392 OPENCL_V_WARN(::clGetDeviceIDs(platforms[i], deviceType, 0, NULL, &numDevices),
393 "Getting OpenCL devices ( ::clGetDeviceIDs() )");
394 if (0 == numDevices)
395 {
396 // OPENCL_V_WARN(CLFFT_DEVICE_NOT_AVAILABLE, "No devices available");
397 continue;
398 }
399
400 devices[i].resize(numDevices);
401 OPENCL_V_THROW(::clGetDeviceIDs(platforms[i], deviceType, numDevices, &(devices[i])[0], NULL),
402 "Getting OpenCL deviceIDs ( ::clGetDeviceIDs() )");
403 }
404 }
405
406 return 0;
407}
408
409std::vector< cl_device_id > initializeCL( cl_device_type deviceType,
410 cl_int deviceId,

Callers 1

initializeCLFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected