OpenCL 找不到 GPU 设备

时间:2021-07-14 13:19:19

标签: opencl

我会尽力向您解释我的问题。 我正在尝试将 OpenCL 用于项目并使用我的 RTX 2070 显卡

My graphic card

但是,安装OpenCL之后,把它放在我的环境变量中并安装驱动程序。我无法检测到我的 GPU 设备。 这是我正在运行的代码:

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <inttypes.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#define CL_TARGET_OPENCL_VERSION 220
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>


/// Print device info to see the different information about the device
    if (device_info==true){
        cl_uint max_device_ids = 32;
        cl_uint num_device_ids=0;
        cl_device_id device_ids[max_device_ids];
        int rep;
        rep = clGetDeviceIDs(0, CL_DEVICE_TYPE_ALL, max_device_ids, device_ids, &num_device_ids);
        printf("rep %d\n\n", rep);

        printf("clGetDeviceIDs returned %d devices\n\n", num_device_ids);

        for(cl_uint idx=0; idx<num_device_ids; ++idx)
        {
            printf("Device %d\n\n", idx);

            printClDeviceInfoString (device_ids[idx], P(CL_DEVICE_NAME));
            printClDeviceInfoString (device_ids[idx], P(CL_DEVICE_VENDOR));
            printClDeviceInfoString (device_ids[idx], P(CL_DEVICE_VERSION));
            printClDeviceInfoString (device_ids[idx], P(CL_DRIVER_VERSION));
            printClDeviceInfoString (device_ids[idx], P(CL_DEVICE_PROFILE));
            printClDeviceInfoBool   (device_ids[idx], P(CL_DEVICE_AVAILABLE));
            printClDeviceInfoBool   (device_ids[idx], P(CL_DEVICE_COMPILER_AVAILABLE));
            printClDeviceInfoUlong  (device_ids[idx], P(CL_DEVICE_GLOBAL_MEM_SIZE));
            printClDeviceInfoUlong  (device_ids[idx], P(CL_DEVICE_LOCAL_MEM_SIZE));
            printClDeviceInfoBool   (device_ids[idx], P(CL_DEVICE_IMAGE_SUPPORT));

            printf("\n");
        }
    }

输出:

rep 0

clGetDeviceIDs returned 1 devices

Device 0

CL_DEVICE_NAME: pthread-Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
CL_DEVICE_VENDOR: GenuineIntel
CL_DEVICE_VERSION: OpenCL 1.2 pocl HSTR: pthread-x86_64-unknown-windows-cygnus-bdver2
CL_DRIVER_VERSION: 1.3
CL_DEVICE_PROFILE: FULL_PROFILE
CL_DEVICE_AVAILABLE: 1
CL_DEVICE_COMPILER_AVAILABLE: 1
CL_DEVICE_GLOBAL_MEM_SIZE: 8051892224
CL_DEVICE_LOCAL_MEM_SIZE: 8388608
CL_DEVICE_IMAGE_SUPPORT: 1

-1Error: Failed to create a device group!: -1

Process finished with exit code 1

我正在使用 Cygwin 在 Windows 上运行它。 奇怪的是,我可以毫无问题地使用 CUDA。我的错误来自哪里?

如果我使用:

clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);

什么都没找到

编辑 1 : 为了回答 Jan Gerd,我尝试查看此代码可用的不同平台:

int i, j;
    char* value;
    size_t valueSize;
    cl_uint platformCount;
    cl_platform_id* platforms;
    cl_uint deviceCount;
    cl_device_id* devices;
    cl_uint maxComputeUnits;

    // get all platforms
    clGetPlatformIDs(0, NULL, &platformCount);
    platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
    clGetPlatformIDs(platformCount, platforms, NULL);

    for (i = 0; i < platformCount; i++) {

        // get all devices
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
        devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);

        // for each device print critical attributes
        for (j = 0; j < deviceCount; j++) {

            // print device name
            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
            value = (char*) malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
            printf("%d. Device: %s\n", j+1, value);
            free(value);

            // print hardware device version
            clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize);
            value = (char*) malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL);
            printf(" %d.%d Hardware version: %s\n", j+1, 1, value);
            free(value);

            // print software driver version
            clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
            value = (char*) malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
            printf(" %d.%d Software version: %s\n", j+1, 2, value);
            free(value);

            // print c version supported by compiler for device
            clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
            value = (char*) malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL);
            printf(" %d.%d OpenCL C version: %s\n", j+1, 3, value);
            free(value);

            // print parallel compute units
            clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
                            sizeof(maxComputeUnits), &maxComputeUnits, NULL);
            printf(" %d.%d Parallel compute units: %d\n", j+1, 4, maxComputeUnits);

        }

        free(devices);

    }

    free(platforms);

但不幸的是我没有与 CUDA 或显卡相关的平台

输出:

1. Device: pthread-Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
 1.1 Hardware version: OpenCL 1.2 pocl HSTR: pthread-x86_64-unknown-windows-cygnus-bdver2
 1.2 Software version: 1.3
 1.3 OpenCL C version: OpenCL C 1.2 pocl
 1.4 Parallel compute units: 12

编辑 2:

enter image description here

根据这个soft,OpenCL有2个平台。 我会尝试安装另一个版本的 OpenCL

0 个答案:

没有答案