ubuntu intel OpenCL

匿名 (未验证) 提交于 2019-12-03 00:41:02

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; }
文章来源: ubuntu intel OpenCL
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!