Get All CPU/GPU Devices

66 views
Skip to first unread message

Christian LeMoussel

unread,
Apr 8, 2018, 11:08:47 AM4/8/18
to boost-compute
To get all CPU/GPU OpenCL devices, I do this

const std::vector<boost::compute::device> openCLdevices = boost::compute::system::devices();
if(openCLdevices.empty()){
BOOST_THROW_EXCEPTION(boost::compute::no_device_found());
    }

    for(size_t i = 0; i < openCLdevices.size(); i++) {
        if (openCLdevices[i].type() & boost::compute::device::gpu) { std::cout << "GPU: " << openCLdevices[i].name() << std::endl; }
        if (openCLdevices[i].type() & boost::compute::device::cpu) { std::cout << "CPU: " << openCLdevices[i].name() << std::endl; }
    }

In result I got

GPU: Caicos => OK AMD GPU
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz

I do not understand why there are three times "CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz"
I should only have "CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz" once

Thank you for your support.

Jakub Szuppe

unread,
Apr 8, 2018, 11:14:57 AM4/8/18
to boost-compute
I'd recommend printing name of the platform for each device. It's possible that one CPU is from AMD platform, one from Intel Experimental platform, one from Intel "stable" platform etc. Same
hardware device can be recognised/found and used by multiple OpenCL platforms. 

Christian LeMoussel

unread,
Apr 8, 2018, 12:43:00 PM4/8/18
to boost-compute
How can I printing name of the platform for each device?

Another solution may be to to get all prlatorm with compute::system::platforms() and for each plateform get all devices like platform.devices()

Christian LeMoussel

unread,
Apr 8, 2018, 1:00:45 PM4/8/18
to boost-compute
I find it :)  and you are right. For CPUs three different platform.

    for(size_t i = 0; i < openCLdevices.size(); i++) {
        if (openCLdevices[i].type() & boost::compute::device::gpu) {
             std::cout << "GPU: " << openCLdevices[i].name() << " Plateform: " << openCLdevices[i].platform().name() << std::endl; }
        if (openCLdevices[i].type() & boost::compute::device::cpu) {
            std::cout << "CPU: " << openCLdevices[i].name() << " Plateform: " << openCLdevices[i].platform().name() << std::endl; }
    }


GPU: Caicos Plateform: AMD Accelerated Parallel Processing
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz Plateform: AMD Accelerated Parallel Processing
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz Plateform: Intel(R) OpenCL
CPU:         Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz Plateform: Experimental OpenCL 2.1 CPU Only Platform


But with these 3 platforms, which one to choose?

Jakub Szuppe

unread,
Apr 8, 2018, 1:28:24 PM4/8/18
to boost-compute
If you want to use Intel CPU separately, that is you don't need GPU and CPU to be on the same platform and  (potentially) in the same context, then stable Intel platform seems the best, but you
can try every platform when you have your program/kernel done. If you need to use GPU then obviously - AMD platform. 
Reply all
Reply to author
Forward
0 new messages