访问AMD OpenCL平台中的平台和设备

访问AMD OpenCL平台中的平台和设备,opencl,Opencl,我正在尝试运行OpenCL中的第一个代码。我编写了以下程序来检测计算机中可用的平台和设备。这段代码在我的电脑上运行良好,它有英特尔CPU和NVIDIA GPU。它能正确检测每个平台和设备。但是,当我在装有AMD-FX 770K和Radeon R7 240的计算机上运行它时,输出如下图所示。至少,它必须将Radeon R7 240 GPU显示为此平台中的一个设备,但它没有。你知道为什么代码在AMD平台上不能正常工作吗 代码如下: #include <stdio.h> #include

我正在尝试运行OpenCL中的第一个代码。我编写了以下程序来检测计算机中可用的平台和设备。这段代码在我的电脑上运行良好,它有英特尔CPU和NVIDIA GPU。它能正确检测每个平台和设备。但是,当我在装有AMD-FX 770K和Radeon R7 240的计算机上运行它时,输出如下图所示。至少,它必须将Radeon R7 240 GPU显示为此平台中的一个设备,但它没有。你知道为什么代码在AMD平台上不能正常工作吗

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>

int main(){

cl_int err, i, j;
cl_platform_id *platforms;
cl_device_id *devices;
cl_uint num_platforms, num_devices;
size_t plat_name_size, devi_name_size;
char *plat_name_data, *devi_name_data;

err = clGetPlatformIDs(1, NULL, &num_platforms);
if (err < 0){
    perror("No platform is found");
    exit(1);
}
platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id)*num_platforms);
clGetPlatformIDs(num_platforms, platforms, NULL);

printf("Number of found platforms is %d\n ", num_platforms);

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

    err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 0, NULL, &plat_name_size);
    if (err < 0){
        perror("Couldn't read platform name.");
        exit(1);
    }
    plat_name_data = (char*)malloc(plat_name_size);
    clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, plat_name_size, plat_name_data, NULL);
    printf("Platform No.%d is: %s\n", i, plat_name_data);
    free(plat_name_data);

    err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 1, NULL, &num_devices);
    if (err < 0){
        perror("No device is found in this platform");
        exit(1);
    }
    devices = (cl_device_id*)malloc(sizeof(cl_device_id)*(num_devices));
    clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
    printf("Number of devices found in this platform is: %d\n", num_devices);
    for (j = 0; j < num_devices; j++){
        err = clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &devi_name_size);
        if (err < 0){
            perror("Couldn't read the device name.");
            exit(1);
        }
        devi_name_data = (char*)malloc(devi_name_size);
        clGetDeviceInfo(devices[j], CL_DEVICE_NAME, devi_name_size, devi_name_data, NULL);
        printf("Device No.%d name is: %s\n", j, devi_name_data);
        free(devi_name_data);
    }

}
return 0;
#包括
#包括
#包括
#包括
int main(){
cl_int err,i,j;
cl_平台_id*平台;
cl_设备\u id*设备;
cl_uint num_平台、num_设备;
尺寸、平台名称、设备名称、尺寸;
字符*平台名称数据,*设备名称数据;
err=clGetPlatformIDs(1、NULL和num_平台);
如果(误差<0){
perror(“未找到平台”);
出口(1);
}
平台=(cl_平台id*)malloc(sizeof(cl_平台id)*num_平台);
clGetPlatformIDs(num_平台,platforms,NULL);
printf(“找到的平台数为%d\n”,num_platforms);
对于(i=0;i
}

请在以下两个调用中将num\u条目设置为“0”:

clGetPlatformIDs(0/*num\u条目*/\u、NULL和num\u平台)

CLGetDeviceID(平台[i]、CLU设备类型所有、0/*num\u条目*/、NULL和num\u设备)