opencl - Is there a good way to choose the right platform on the fly? -
because computer using has amd, nvidea, , intel platforms. how can know right platform use on users computer? have loop tries create platform, device, context, , queue every platform. if fails @ point tries next platform.
readkernel(); numplatforms = getnumplatforms(); test platforms = getplatforms(); test for(int = 0; < numplatforms; i++) { numdevices = getnumdevices(platforms[i]); test_and_continue devices = getdevices(platforms[i], numdevices); test_and_continue context = createcontext(platforms[i], devices); test_and_continue queue = getcommandqueue(context, devices[0]); test_and_continue // setup. can post info here -> getdeviceinfo(devices[0]); break; } program = createprogram(context, source); test buildprogram(program); test kernel = buildkernel(program, appname); test
is way or there better way?
as usual kind of question, answer is: depends on need. or in other words, need define "the right platform".
here cases can think of (i'm sure can find others):
you developed kernel using features specific version of ocl. using
clgetplatforminfo
, query each platform present find 1 has proper ocl version.you optimized kernel specific type of device (cpu, gpu). filter devices interested in using appropriate flag (
cl_device_type_typename
)clgetdeviceids
.you want parallelized as possible computation, have move lot of data device. in case might have found out running kernel on igpu gives best performance. function
clgetdeviceinfo
, flagcl_device_host_unified_memory
can determine if have such device available.with
clgetdeviceinfo
function can query specific vendor extension want use (flag:cl_device_extensions
). noteclgetplatforminfo
provides list of extension supported platform.you have several gpus available , want 1 "best performance". still
clgetdeviceinfo
can query specifications of device. based on these specs can make choice. instance can found out if device has cache (cl_device_global_mem_cache_type
) , if yes how (cl_device_global_mem_cacheline_size
). can query clock frequency (cl_device_max_clock_frequency
) or how many compute units available on device (cl_device_max_compute_units
).
Comments
Post a Comment