Yogeesh Agarwal
Yogeesh Agarwal

Reputation: 51

how to get default device id for calling host thread in opencl

i am working with opencl "c" in a multi gpu scenario, where for various calls i have to get the default device id for the current calling host thread in opencl. unfortunately i am not able to figure it out and internet hasnt been kind in this aspect.
in HIP, one would call hipGetDevice(&device_id) and get the device id for current calling host thread. If someone can help me figure out something similar to what hipGetDevice does in opencl it would be highly appreciated.

Upvotes: 1

Views: 135

Answers (1)

ProjectPhysX
ProjectPhysX

Reputation: 5746

OpenCL always requires you to manually select a device, so you alwayws know which device you have used by keeping track of its ID/context. There is no "default" device selection, although some codes just use device #0 from platform #0 - but on some systems that gives you the CPU/iGPU and not the fast dedicated GPU.

A better solution to pick a default device is to first make a list of all avaliable devices, then query/estimate their specs (FLOPs and memory capacity) and select the fastest device or device with most memory from that list.

More details how that works in code are in this answer.

Upvotes: 1

Related Questions