1.配置OpenCL
1.下载https://software.intel.com/en-us/intel-opencl
2.安装过程中会自动检查缺少的库。
2.CMakelists
include_directories(/opt/intel/opencl-sdk/include/CL)
target_link_libraries(untitled1 /opt/intel/opencl-sdk/lib64/libOpenCL.so)
3.获取平台和设备信息
#include <iostream>
#include <opencl.h>
#include <time.h>
using namespace std;
void show_platfor_device()
{
cl_platform_id *platform;
cl_uint num_platform;
cl_int error;
error = clGetPlatformIDs(0, NULL, &num_platform);
platform = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platform);
error = clGetPlatformIDs(num_platform, platform, NULL);
for (int i = 0; i < num_platform; ++i) {
size_t size_platform;
error = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, 0, NULL, &size_platform);
char *name;
name = (char *)malloc(sizeof(char) * size_platform);
error = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, size_platform, name, NULL);
cout << "platform:" << name << endl;
free(name);
cl_device_id *device_id;
cl_uint num_device;
error = clGetDeviceIDs(platform[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_device);
device_id = (cl_device_id *)malloc(sizeof(cl_device_id) * num_device);
error = clGetDeviceIDs(platform[i], CL_DEVICE_TYPE_ALL, num_device, device_id, NULL);
for (int j = 0; j < num_device; ++j) {
size_t size_device;
char *name_device;
error = clGetDeviceInfo(device_id[j], CL_DEVICE_NAME,0, NULL, &size_device);
name_device = (char *)malloc(sizeof(char) * size_device);
error = clGetDeviceInfo(device_id[j], CL_DEVICE_NAME, size_device, name_device, NULL);
cout << "device " << j << ":" <<name_device << endl;
free(name_device);
}
}
}
int main()
{
show_platfor_device();
return 0;
}