hughperkins / EasyCL

Easy to run kernels using OpenCL
Other
183 stars 52 forks source link

Feature Request: Simple check to see which vendor we're on #22

Closed merceyz closed 7 years ago

merceyz commented 7 years ago

A simple function to see if we're on AMD, Nvidia, Intel, or other. (To use with DeepCL)

Reason: Nvidia prefers workgroupsizes to be a multiple of 32, AMD prefers 64 and Intel (CPU) 8 So it would be nice to easily see which platform we're currently on

hughperkins commented 7 years ago

Hi Chris,

Cool :-) . Actually, you can get this as follows:

    int numGpus = DevicesInfo::getNumGpus();
    for(int i = 0; i < numGpus; i++) {
        cout << DevicesInfo::getGpuInfo(i).toString() << endl;
    }

Or, this will print:

... stuff...
platformVendor: Apple
platformName: Apple
...
deviceName: AMD Radeon Pro 450 Compute Engine
... 

To get the value of platformVendor:

        cout << DevicesInfo::getGpuInfo(i).platformVendor << endl;

You can take a look at:

merceyz commented 7 years ago

How would that work if I only have a EasyCL and CLKernel https://github.com/hughperkins/DeepCL/blob/master/src/conv/BackpropWeightsScratch.cpp#L56

And it can't be specific to GPU as it can be a CPU as well

hughperkins commented 7 years ago

The methods above are static. Global. Dont need any EasyCL or CLKernel objects. Just call these global methods directly.

hughperkins commented 7 years ago

(though you probably want to cache the result, if you're going to be checking this value thousands of times a second)

merceyz commented 7 years ago

Yes, that was the plan.

Though I want to know it for the specific device the kernel will be run on (the line I linked to). So I either need to get the device ID from the CL object or easycl::DevicesInfo::getDeviceInfo needs to accept a cl_device_id object

hughperkins commented 7 years ago

Seems you can get the DeviceInfo from the cl like this: https://github.com/hughperkins/clnn/blob/master/lib/THCLNN/im2col.cpp#L19

  int maxWorkgroupSize = ((easycl::DeviceInfo *)state->deviceInfoByDevice[state->currentDevice])->maxWorkGroupSize;
hughperkins commented 7 years ago

oh wait, thats torch specific. hmmm

hughperkins commented 7 years ago

Hmmm, ok I see. So, getting the device_id and platform_id from the EasyCL object is already possible:

https://github.com/hughperkins/EasyCL/blob/master/EasyCL.h#L65-L66

    cl_platform_id platform_id;
    cl_device_id device;

But there's no obvious existing method to then retrieve a DeviceInfo object given those.

merceyz commented 7 years ago

It can be done like this:

easycl::DeviceInfo info;
info.populate(cl->platform_id, cl->device);

cout << info.platformVendor << endl;

Thanks for pointing me in the right direction

hughperkins commented 7 years ago

Cool :-)