免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4056 | 回复: 7
打印 上一主题 下一主题

[技术动态] Linux 环境下 intel 核心显卡的 OpenCL 并行计算 [复制链接]

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-05-25 21:57 |只看该作者 |倒序浏览
  Intel CPU 内置的核心显卡也是可以做 OpenCL 并行计算的,虽然核心显卡的计算能力并不是很强. 

  Linux 环境下有 Beignet https://www.freedesktop.org/wiki/Software/Beignet/ 
Beignet is an open source implementation of the OpenCL specification - a generic compute oriented API. This code base contains the code to run OpenCL programs on Intel GPUs which basically defines and implements the OpenCL host functions required to initialize the device, create the command queues, the kernels and the programs and run them on the GPU. The code base also contains the compiler part of the stack which is included in backend ...


    配合 Boost.Compute https://github.com/boostorg/compute  和  OpenCV  可以处理图像,比如做一个边缘检测:

    参照  Boost.Compute 里这个例子 https://github.com/boostorg/comp ... cv_sobel_filter.cpp 效果大概是这样:



 下面的代码是在 GPU 平行的:

  1. // Create sobel filter program
  2. extern const std::string  str_cl_sobel = BOOST_COMPUTE_STRINGIZE_SOURCE
  3. (
  4.     //For out of boundary pixels, edge pixel
  5.     // value is returned
  6.     const sampler_t sampler = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
  7.    
  8.     kernel void cl_kernel(read_only image2d_t src, write_only image2d_t dst)
  9.     {
  10.         int x = (int)get_global_id(0);
  11.         int y = (int)get_global_id(1);

  12.         if (x >= get_image_width(src) || y >= get_image_height(src))
  13.                 return;

  14.         //  [(x-1, y+1), (x, y+1), (x+1, y+1)]
  15.         //  [(x-1, y  ), (x, y  ), (x+1, y  )]
  16.         //  [(x-1, y-1), (x, y-1), (x+1, y-1)]

  17.         //  [p02, p12,   p22]
  18.         //  [p01, pixel, p21]
  19.         //  [p00, p10,   p20]

  20.         //Basically finding influence of neighbour pixels on current pixel
  21.         float4 p00 = read_imagef(src, sampler, (int2)(x - 1, y - 1));
  22.         float4 p10 = read_imagef(src, sampler, (int2)(x,     y - 1));
  23.         float4 p20 = read_imagef(src, sampler, (int2)(x + 1, y - 1));

  24.         float4 p01 = read_imagef(src, sampler, (int2)(x - 1, y));
  25.         //pixel that we are working on
  26.         float4 p21 = read_imagef(src, sampler, (int2)(x + 1, y));

  27.         float4 p02 = read_imagef(src, sampler, (int2)(x - 1, y + 1));
  28.         float4 p12 = read_imagef(src, sampler, (int2)(x,     y + 1));
  29.         float4 p22 = read_imagef(src, sampler, (int2)(x + 1, y + 1));

  30.         //Find Gx = kernel + 3x3 around current pixel
  31.         //           Gx = [-1 0 +1]     [p02, p12,   p22]
  32.         //                [-2 0 +2]  +  [p01, pixel, p21]
  33.         //                [-1 0 +1]     [p00, p10,   p20]
  34.         float3 gx = -p00.xyz + p20.xyz +
  35.                     2.0f * (p21.xyz - p01.xyz)
  36.                     -p02.xyz + p22.xyz;

  37.         //Find Gy = kernel + 3x3 around current pixel
  38.         //           Gy = [-1 -2 -1]     [p02, p12,   p22]
  39.         //                [ 0  0  0]  +  [p01, pixel, p21]
  40.         //                [+1 +2 +1]     [p00, p10,   p20]
  41.         float3 gy = p00.xyz + p20.xyz +
  42.                     2.0f * (- p12.xyz + p10.xyz) -
  43.                     p02.xyz - p22.xyz;
  44.         //Find G
  45.         float3 g = native_sqrt(gx * gx + gy * gy);

  46.         // we could also approximate this as g = fabs(gx) + fabs(gy)
  47.         write_imagef(dst, (int2)(x, y), (float4)(g.x, g.y, g.z, 1.0f));
  48.     }
  49. );

复制代码

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
2 [报告]
发表于 2016-05-25 22:17 |只看该作者
我也想玩这个。

评分

参与人数 1信誉积分 +10 收起 理由
zhujiang73 + 10 赞一个!

查看全部评分

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
3 [报告]
发表于 2016-05-25 22:23 |只看该作者
回复 2# fender0107401


    把能用的计算能力都用上. 

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
4 [报告]
发表于 2016-05-25 22:38 |只看该作者
回复 3# zhujiang73

我经常要处理大量数据,一直都是靠多线程来实现并行,一直想弄这块。现在Boost里面有这个库了,应该能方便很多。

   

论坛徽章:
44
15-16赛季CBA联赛之浙江
日期:2021-10-11 02:03:59程序设计版块每日发帖之星
日期:2016-07-02 06:20:0015-16赛季CBA联赛之新疆
日期:2016-04-25 10:55:452016科比退役纪念章
日期:2016-04-23 00:51:2315-16赛季CBA联赛之山东
日期:2016-04-17 12:00:2815-16赛季CBA联赛之福建
日期:2016-04-12 15:21:2915-16赛季CBA联赛之辽宁
日期:2016-03-24 21:38:2715-16赛季CBA联赛之福建
日期:2016-03-18 12:13:4015-16赛季CBA联赛之佛山
日期:2016-02-05 00:55:2015-16赛季CBA联赛之佛山
日期:2016-02-04 21:11:3615-16赛季CBA联赛之天津
日期:2016-11-02 00:33:1215-16赛季CBA联赛之浙江
日期:2017-01-13 01:31:49
5 [报告]
发表于 2016-05-26 01:34 |只看该作者
这玩意貌似有bug,在我的mac上老崩……

论坛徽章:
12
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之同曦
日期:2017-03-17 19:13:162016科比退役纪念章
日期:2016-11-07 08:28:12luobin
日期:2016-06-17 17:46:36wusuopu
日期:2016-06-17 17:43:4515-16赛季CBA联赛之福建
日期:2016-01-14 12:49:22程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:002015年亚洲杯之科威特
日期:2015-03-24 14:21:272015年迎新春徽章
日期:2015-03-04 09:57:092016科比退役纪念章
日期:2018-04-10 16:20:18
6 [报告]
发表于 2016-05-26 09:10 |只看该作者
你们玩儿的东西真是高大上啊

论坛徽章:
208
巨蟹座
日期:2013-09-02 09:16:36卯兔
日期:2013-09-02 20:53:59酉鸡
日期:2013-09-05 21:21:45戌狗
日期:2013-10-15 20:51:17寅虎
日期:2013-10-18 21:13:16白羊座
日期:2013-10-23 21:15:19午马
日期:2013-10-25 21:22:48技术图书徽章
日期:2013-11-01 09:11:32双鱼座
日期:2013-11-01 20:29:44丑牛
日期:2013-11-01 20:40:00卯兔
日期:2013-11-11 09:21:32酉鸡
日期:2013-12-04 19:56:39
7 [报告]
发表于 2016-05-26 09:34 |只看该作者
都高大尚啊,怎么那么多时间research啊

论坛徽章:
9
程序设计版块每日发帖之星
日期:2015-10-18 06:20:00程序设计版块每日发帖之星
日期:2015-11-01 06:20:00程序设计版块每日发帖之星
日期:2015-11-02 06:20:00每日论坛发贴之星
日期:2015-11-02 06:20:00程序设计版块每日发帖之星
日期:2015-11-03 06:20:00程序设计版块每日发帖之星
日期:2015-11-04 06:20:00程序设计版块每日发帖之星
日期:2015-11-06 06:20:00数据库技术版块每周发帖之星
日期:2015-12-02 15:02:47数据库技术版块每日发帖之星
日期:2015-12-08 06:20:00
8 [报告]
发表于 2016-05-26 09:36 |只看该作者
不错, 有时间的话, 也学习一下.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP