由于我的电脑是windows10,显卡是集显Intel® UHD Graphics 630。
下载Intel的SDK for OpenCL,下载地址https://software.intel.com/en-us/opencl-sdk/choose-download,也可以在我的资源里面直接下载
http://xiazai.jb51.net/202305/yuanma/intel_sdk_for_opencl_applications_283428.rar
运行install.exe,装置
运行后,假设vs翻开了需要关闭。
默认装置途径在C:\Program Files (x86)\IntelSWTools,找到OpenCL装置位置在C:\Program Files (x86)\IntelSWTools\system_studio_2020\OpenCL
配置环境变量,发现以及自动配置到里面了
下载intel提供测试工具,下载地址:https://download.csdn.net/download/qq_36314864/87756581然后下载了直接运行,打印如下表示装置胜利。
自己搭建一个OpenCL工程,创建一个C++控制台工程
翻开配置属性,包含OpenCL的头文件,即将C:\Program Files (x86)\IntelSWTools\system_studio_2020\OpenCL\sdk\include
添加依赖项,假设工程是x64,就在C:\Program Files (x86)\IntelSWTools\system_studio_2020\OpenCL\sdk\lib\x64下面,假设x86就依赖x86下面的
拷贝下面测试代码交换helloword
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cassert>
#include <CL/cl.h>
/*
* 修改自官方示例intel_ocl_caps_basic_win,用于测试手工配置项目
*/
int main()
{
using namespace std;
const char* required_platform_subname = "Intel";
//函数返回值,CL_SUCCESS表示胜利
cl_int err = CL_SUCCESS;
// 判断返回值是否正确的宏
#define CAPSBASIC_CHECK_ERRORS(ERR) \
if(ERR != CL_SUCCESS) \
{ \
cerr \
<< "OpenCL error with code " << ERR \
<< " happened in file " << __FILE__ \
<< " at line " << __LINE__ \
<< ". Exiting...\n"; \
exit(1); \
}
// 遍历系统中所有OpenCL平台
cl_uint num_of_platforms = 0;
// 得到平台数目
err = clGetPlatformIDs(0, 0, &num_of_platforms);
CAPSBASIC_CHECK_ERRORS(err);
cout << "Number of available platforms: " << num_of_platforms << endl;
cl_platform_id* platforms = new cl_platform_id[num_of_platforms];
// 得到所有平台的ID
err = clGetPlatformIDs(num_of_platforms, platforms, 0);
CAPSBASIC_CHECK_ERRORS(err);
//列出所有平台
cl_uint selected_platform_index = num_of_platforms;
cout << "Platform names:\n";
for (cl_uint i = 0; i < num_of_platforms; ++i)
{
size_t platform_name_length = 0;
err = clGetPlatformInfo(
platforms,
CL_PLATFORM_NAME,
0,
0,
&platform_name_length
);
CAPSBASIC_CHECK_ERRORS(err);
// 调用两次,第一次是得到名称的长度
char* platform_name = new char[platform_name_length];
err = clGetPlatformInfo(
platforms,
CL_PLATFORM_NAME,
platform_name_length,
platform_name,
NULL
);
CAPSBASIC_CHECK_ERRORS(err);
cout << " [" << i << "] " << platform_name;
if (
strstr(platform_name, required_platform_subname) &&
selected_platform_index == num_of_platforms // have not selected yet
)
{
cout << " [Selected]";
selected_platform_index = i;
}
cout << endl;
delete[] platform_name;
}
delete[] platforms;
return 0;
}
到此这篇关于windows下如何装置OpenCL的文章就介绍到这了,更多相关windows装置OpenCL内容请搜索网站以前的文章或继续阅读下面的相关文章希望大家以后多多支持网站! |