cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Raistmer
Adept II

Device <-> cl_device_id

How to get device pointer (of type cl_device_id ) for given object of class Device?
I need to know if particular Device is the same as particular cl_device_id object or not.

Device constructor saves cl_device_id device in _object member - is it possible to read this member?
0 Likes
6 Replies
himanshu_gautam
Grandmaster

Device <-> cl_device_id

Can you explain what you want to do.

I don't think there would be any way to access a private class member without a member function.

0 Likes
rick_weber
Adept II

Device <-> cl_device_id

With clever pointer arithmetic, you can read private members of classes. Just watch out for _vtable stuff if the class has virtual members.

Note that this completely violates virtually every rule and best practice of object oriented design.

Example:

 

class foo { private: int foo1; int foo2; } void bar(foo* theClass) { printf("foo.foo2 = %d", ((int*)theClass)[1]); }

0 Likes
nou
Exemplar

Device <-> cl_device_id

IMHO cleanest solution will be patch cl.hpp so Device class will have method which return cl_device_id

0 Likes
Raistmer
Adept II

Device <-> cl_device_id

yes, it can be patched, and private member can be accessed... but I though there is some "proper" way to get it.
IMHO to be useful any wrapper including this one should provide access to original object it wraps. I need to know what Device object belongs to what GPU device in heterogeneous host (NV/ATi platforms mixed).
Cause rest of code uses cl_device_id based device descriptor (to select appropriate device) and enumerating part of code uses CLinfo(i.e. Device) based device descriptor I need way to compare they for equality.
Now I think it's better to re-write device quering in "plain OpenCL" and forget AMD OpenCL-C++ attempt as too incomplete to be useful... It will be better than hacking private class members....
0 Likes
himanshu_gautam
Grandmaster

Device <-> cl_device_id

If i am understanding it correctly, we select the device based on its properties(device name or vendor name or whether it supports some extension).

 

0 Likes
nou
Exemplar

Device <-> cl_device_id

IMHO he just copy pasted code from CLInfo example into his own program which use C interface.

but you can be pretty sure that device which return C++ binding will be in the same order as from C API.

0 Likes