C++ OpenCL仅查找iGPU而非CPU

ylamdve6  于 2022-12-05  发布在  其他
关注(0)|答案(1)|浏览(158)

As the title suggests, the OpenCL API only detects my Intel iGPU but not the CPU itself. any ideas on why ? I have installed the Intel-opencl-icd via the package manager but it doesn't seem to be enough to find the CPU.
For context this is the code I have so far.

#include <iostream>
#include <vector>

#include <CL/opencl.hpp>

int main(int argc, char const *argv[])
{
    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    std::cout << "Numbers of platforms : " << platforms.size() << std::endl;

    int platform_id = 0;
    int device_id = 0;

    for(cl::vector<cl::Platform>::iterator it = platforms.begin(); it != platforms.end(); ++it){
        cl::Platform platform(*it);

        std::cout << "Platform ID: " << platform_id++ << std::endl;  
        std::cout << "Platform Name: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl;  
        std::cout << "Platform Vendor: " << platform.getInfo<CL_PLATFORM_VENDOR>() << std::endl;  

        cl::vector<cl::Device> devices;  
        platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);  

        for(cl::vector<cl::Device>::iterator it2 = devices.begin(); it2 != devices.end(); ++it2){
            cl::Device device(*it2);

            std::cout << "\tDevice " << device_id++ << ": " << std::endl;
            std::cout << "\t\tDevice Name: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;  
            std::cout << "\t\tDevice Type: " << device.getInfo<CL_DEVICE_TYPE>();
            std::cout << " (GPU: " << CL_DEVICE_TYPE_GPU << ", CPU: " << CL_DEVICE_TYPE_CPU << ")" << std::endl;  
            std::cout << "\t\tDevice Vendor: " << device.getInfo<CL_DEVICE_VENDOR>() << std::endl;
            std::cout << "\t\tDevice Max Compute Units: " << device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>() << std::endl;
            std::cout << "\t\tDevice Global Memory: " << device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>() << std::endl;
            std::cout << "\t\tDevice Max Clock Frequency: " << device.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>() << std::endl;
            std::cout << "\t\tDevice Max Allocateable Memory: " << device.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>() << std::endl;
            std::cout << "\t\tDevice Local Memory: " << device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>() << std::endl;
            std::cout << "\t\tDevice Available: " << device.getInfo< CL_DEVICE_AVAILABLE>() << std::endl;
        }  
        std::cout<< std::endl;
    } 

    return 0;
}

It technically wouldn't be too much of an issue not being able to run the code on the CPU cores but I wanted to see the difference in speed between using the CPU cores and GPU cores as I'm just starting in OpenCL
Thanks

ycl3bljg

ycl3bljg1#

安装最新的Intel OpenCL CPU Runtime。这适用于Intel和AMD CPU。
windows :win-oclcpuexp-2022.14.8.0.04_rel.zip
Linux系统:oclcpuexp-2022.14.8.0.04_rel.tar.gz
注意:不要在Windows上使用旧的16.1或18.1版本(Google搜索的第一个结果)。这些版本无法正常工作。

相关问题