【问题标题】:C++ OpenCL only finding iGPU but not CPUC++ OpenCL 只找到 iGPU 而不是 CPU
【发布时间】:2022-12-03 15:59:21
【问题描述】:

正如标题所暗示的那样,OpenCL API 仅检测我的英特尔 iGPU 而不是 CPU 本身。关于为什么的任何想法?我已经通过包管理器安装了 Intel-opencl-icd,但它似乎还不足以找到 CPU。

对于上下文,这是我到目前为止的代码。

#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;
}

从技术上讲,不能在 CPU 内核上运行代码并不是什么大问题,但我想看看使用 CPU 内核和 GPU 内核之间的速度差异,因为我刚开始使用 OpenCL

谢谢

【问题讨论】:

  • 您的程序是 clinfo 所做工作的子集。我建议您安装 clinfo 并查看它是否检测到您的 CPU。并非所有 CPU 都支持 OpenCL。你检查过你的吗?有时您可能需要特殊的驱动程序才能将 OpenCL 与特定设备一起使用。
  • @SimonGoater 看来我的 CPU 确实不支持 OpenCL,因为 clinfo 也没有检测到它。我认为这是因为它是第 11 代 i7 移动芯片。谢谢您的回答
  • 您的 CPU 听起来并没有老到不支持 OpenCL 的地步。我建议您再看一下它需要与 OpenCL 一起使用的驱动程序。像 cpuworld 这样的网站列出了 CPU 的功能。

标签: c++ opencl cpu intel


【解决方案1】:

安装最新的英特尔 OprnCL CPU 运行时。这适用于 Intel 和 AMD CPU。 Linux:intel-opencl-icd_22.43.24558_amd64.deb 来自这里:https://github.com/intel/compute-runtime/releases/tag/22.43.24558 视窗:https://www.intel.com/content/www/us/en/developer/tools/opencl-cpu-runtime/overview.html

注意:请勿在 Windows 上使用旧的 16.1 或 18.1 版本。这些不能正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2013-09-18
    相关资源
    最近更新 更多