win10-opencl-intel集显GPU开发环境搭建

设备参数:

windows10专业版 i5-4210m 8GB内存 64位操作系统
显卡:intel(R)HD 4600 NVIDIA GT 730M

搭建opencl开发环境的必要条件:

  1. 显卡
    电脑带有集成显卡或者独立显卡
  2. 驱动
    更新显卡驱动以适配最新opencl库,windows自带opencl驱动
  3. 安装SDK
    在intel官网下载Intel SDK for OpenCL applications,这一步有点坑,一定要先去注册和验证,然后再转到这个页面点击下载 然后会跳到这里点击下载合适平台版本的SDK

搭建你的第一个hello GPU for openCL工程

  1. 创建一个c++控制台工程

  2. 打开项目属性配置,在C/C++z中找到附加包含目录,添加D:\opencl-intel\OpenCL\sdk\include目录(包含CL文件夹)

  3. 在链接器、常规、附加库目录中添加D:\opencl-intel\OpenCL\sdk\lib\x64(自己选择工程为64位或者32位)

  4. 在链接器、输入、附加依赖项中添加D:\opencl-intel\OpenCL\sdk\lib\x64下的OpenCL.lib库

  5. 打开项目中任意cpp文件写入以下代码:

#include 
#include 
#include 
#include 
#include 

#include 

/*
 * 修改自官方示例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[i],
            CL_PLATFORM_NAME,
            0,
            0,
            &platform_name_length
        );
        CAPSBASIC_CHECK_ERRORS(err);

        // 调用两次,第一次是得到名称的长度
        char* platform_name = new char[platform_name_length];
        err = clGetPlatformInfo(
            platforms[i],
            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;
}
  1. 输出结果


    调试控制台

你可能感兴趣的:(win10-opencl-intel集显GPU开发环境搭建)