Reputation: 61
I'm begining to use the OpenCL C++ API. I'm been using the C API for long time. The C++ API is a lot more elegant, simple, with less bloated code and less error prone, but I need the devices Ids. In the startup code I'm doing this:
vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
//example, get devices from first platform
vector<cl::Device> devices;
platforms[0].getDevices(CL_DEVICE_TYPE_ALL, &devices);
I need the devices IDs, but don't want to do this with C API:
cl_device_id *devicesIds = new cl_device_id[devices.size()];
clGetDeviceIDs(platformsIds[0], CL_DEVICE_TYPE_ALL, devices.size(), devicesIds, NULL);
How can I get de device_id ID from devs[0]
with the C++ API? Can't find it in the documentation. I see devices[0]
has the device_id
value, but I can't get it.
Upvotes: 2
Views: 3478
Reputation: 930
Any of the C++ wrapper objects can return the underlying OpenCL C object using operator().
In the original header the decision was made to make those objects directly convertible to the underlying C objects and I think this simple interface reflects that way of thinking. If you look through the header code of an old version there are many places were arrays of C++ objects are cast directly to arrays of C ids.
Upvotes: 3