gpt4 book ai didi

c++ - clGetPlatformIDs 返回两个平台,但它们是相同的

转载 作者:行者123 更新时间:2023-11-30 00:39:23 25 4
gpt4 key购买 nike

要创建 opencl 应用程序,第一步是通过使用获取平台

clGetPlatformIDs 

我对从函数返回的平台有问题;函数返回我有 2 个平台,但当我检查它们时,我发现我有一个平台,但它是重复的!!

源代码

struct PLATFORM
{
cl_platform_id _Platforms ;
map <cl_platform_info , char*> _Platforms_info ;
};

cl_int error ;
cl_uint temp_num_platforms ;

error = clGetPlatformIDs (NULL , NULL , &temp_num_platforms );

if ( error != CL_SUCCESS )
{
/* create error and debug function*/
cout << " error detect platforms " << endl << endl ;
}
else
{
cout << " we detect " << temp_num_platforms << " platforms " << endl << endl ;

_Platforms = std::unique_ptr < PLATFORM [] > ( new PLATFORM [temp_num_platforms] ) ;

for ( unsigned int num_platforms = 1 ; num_platforms <= temp_num_platforms ; num_platforms++ )
{
// get platforms
error = clGetPlatformIDs (num_platforms ,&_Platforms[num_platforms-1]._Platforms , NULL );

if ( error != CL_SUCCESS || _Platforms[num_platforms-1]._Platforms == NULL )
{
cout << " error get platform " << num_platforms - 1 << endl << endl;
}
else
{
cout << " OK ! we detect "<< num_platforms << " platform " << endl << endl ;
}
}
}

if ( _Platforms[0]._Platforms == _Platforms[1]._Platforms )
{
cout << " we have two platforms" << endl << endl ;
}

最佳答案

您没有说太多关于您的安装平台。我的猜测是您安装了来自某个供应商的多个版本的 OpenCL SDK。那,或者你遇到了一个错误。试试下面的程序,它会打印出系统上报告的所有平台的供应商、名称和版本。它可能会帮助您更好地理解您的问题。

// You might need to change this header based on your install:
#include <OpenCL/cl.h>
#include <stdio.h>
#include <stdlib.h>

static void check_error(cl_int error, char* name) {
if (error != CL_SUCCESS) {
fprintf(stderr, "Non-successful return code %d for %s. Exiting.\n", error, name);
exit(1);
}
}

int main (int argc, char const *argv[])
{
cl_uint i;
cl_int err;

// Discover the number of platforms:
cl_uint nplatforms;
err = clGetPlatformIDs(0, NULL, &nplatforms);
check_error(err, "clGetPlatformIds");

// Now ask OpenCL for the platform IDs:
cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * nplatforms);
err = clGetPlatformIDs(nplatforms, platforms, NULL);
check_error(err, "clGetPlatformIds");

// Ask OpenCL about each platform to understand the problem:
char name[128];
char vendor[128];
char version[128];

fprintf(stdout, "OpenCL reports %d platforms.\n\n", nplatforms);

for (i = 0; i < nplatforms; i++) {
err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, 128, vendor, NULL);
err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL);
err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION, 128, version, NULL);
check_error(err, "clGetPlatformInfo");

fprintf(stdout, "Platform %d: %s %s %s\n", i, vendor, name, version);
}

free(platforms);
return 0;
}

如果您看到两个相同的 vendor-name-versions 字符串,那么这是一个错误。将它提交给您的 OpenCL 供应商,他们会感谢您!

关于c++ - clGetPlatformIDs 返回两个平台,但它们是相同的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8969709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com