怎么配置opencl
用a卡的能配置opencl : (windows下)
#include <CL/cl.h>
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
char main(void)
{
cl_uint num_platforms;
char err;
//get platform numbers
err = clGetPlatformIDs(0, 0, &num_platforms); //返回值如果为-1就说明调用函数失败,如果为0标明成功
cout << "get platform numbers:" << endl;
cout << err << "," << num_platforms << endl; //计算机上显示为2,有intel和AMD两个平台
//get all platforms[ID]
vector<cl_platform_id> platforms(num_platforms);
err = clGetPlatformIDs(num_platforms, &platforms[0], &num_platforms);
cout << "get all platforms ID:" << endl;
cout << platforms[0] << endl;
cout << platforms[1] << endl;
// Find extensions of all platforms //
//获取额外的平台信息。上面已经取得了平台id了,那么就可以进一步获取更加详细的信息了。
//一个for循环获取所有的主机上的platforms信息
size_t ext_size;
char* ext_data;
for (char i = 0; i < num_platforms; i++)
{
/* Find size of extension data */
//也是和前面一样,先设置第三和第四个参数为0和NULL,然后就可以用第五个参数ext_size获取额外信息的长度了。
err = clGetPlatformInfo(platforms[i],
CL_PLATFORM_EXTENSIONS, 0, NULL, &ext_size);
if (err < 0)
{
perror("Couldn't read extension data.");
return 0;
}
cout << "The size of extension data is:"<<ext_size << endl;
/* Access extension data */
//这里的ext_data相当于一个缓存,存储相关信息。
ext_data = (char*)malloc(ext_size);
//这个函数就是获取相关信息的函数,第二个参数指明了需要什么样的信息,如这里的CL_PLATFORM_EXTENSIONS表示是opencl支持的扩展功能信息。
//我计算机输出一大串,机器比较新(专门为了学图形学而购置的电脑),支持的东西比较多。
//cl_khr_icd
clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS,
ext_size, ext_data, NULL);
cout << "Platform" << i <<" name:" << ext_data << endl;
//这里是输出生产商的名字,比如我显卡信息是:AMD Accelerated parallel Processing;另一个是Intel<R> OpenCL
char *name = (char*)malloc(ext_size);
clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME,
ext_size, name, NULL);
printf("Platform %d name: %s\n", i, name);
//这里是供应商信息,我显卡信息:AMD ,Inc
char *vendor = (char*)malloc(ext_size);
clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR,
ext_size, vendor, NULL);
printf("Platform %d vendor: %s\n", i, vendor);
//最高支持的OpenCL版本,本机显示:OpenCL2.0 AMD-APP <1800.5> 另一个是 OpenCL1.2
char *version = (char*)malloc(ext_size);
clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION,
ext_size, version, NULL);
printf("Platform %d version: %s\n", i, version);
//释放空间
free(ext_data);
free(name);
free(vendor);
free(version);
}
system("pause");
return 1;
}

浙公网安备 33010602011771号