当前位置: 首页 > news >正文

山西 网站建设最新中高风险地区名单

山西 网站建设,最新中高风险地区名单,博物馆网页设计案例,长沙3合1网站建设这是新的系列教程,在本教程中,我们将介绍使用 FPGA 实现深度学习的技术,深度学习是近年来人工智能领域的热门话题。在本教程中,旨在加深对深度学习和 FPGA 的理解。用 C/C 编写深度学习推理代码高级综合 (HLS) 将 C/C 代码转换为硬…

7229a341964de7d359d7878d5bbf4854.png

这是新的系列教程,在本教程中,我们将介绍使用 FPGA 实现深度学习的技术,深度学习是近年来人工智能领域的热门话题。

在本教程中,旨在加深对深度学习和 FPGA 的理解。

  • 用 C/C++ 编写深度学习推理代码

  • 高级综合 (HLS) 将 C/C++ 代码转换为硬件描述语言

  • FPGA 运行验证

3f90ad3f61ade79aa2409277dbad309b.png

从这篇文章中,我们将从之前创建的网络模型中提取并行性,并确认处理速度得到了提高。首先,我们检查当前模型的架构,并考虑什么样的并行化是可性的。

并行化方法研究

当前模型架构的框图如下所示。限于篇幅省略了maxpool2d和relu。

2459e76ed484062a5fa0fc19ae50308a.png

在这个模块中,conv1、conv2、fc1、fc2都是作为不同的模块实现的。FPGA内部的SRAM在每一层之间插入一个缓冲区(x', x'', x''' ),这个缓冲区成为每一层的输入和输出。此后,每一层(conv1、conv2、fc1、fc2)被称为一个任务。

顺序处理(基线)

下图显示了使用该模块对 3 帧图像执行推理处理时的执行时间可视化。

每个任务的执行时间以推理模块的实际运行波形为准,是conv2>conv1>fc1>fc2的关系。在该模块中,conv1、conv2、fc1和fc2作为单独的任务实施,但是这些任务一次只能运行一个(后面会解释原因)。因此,如果将conv1、conv2、fc1、fc2各层的执行时间作为最终的执行时间,则这3帧图像的t0, t1, t2, t3处理时间为3 * (t0 + t1 + t2 + t3)

c3949e7777d83e10d6b1435e015e920f.png

任务并行度

假设我们可以修复这些任务并发运行。这种情况下的执行时间如下所示,多个任务可以同时处理不同的帧。

893e9abedbd9661d9753cf81ff5f0676.png

提取并行性使多个任务可以同时运行,称为任务并行化。在这个过程中,conv2的执行时间占主导地位,所以3帧的处理时间为t0 + 3 * t1 + t2 + t3。

理想的任务并行度

最后,我们考虑可以理想地执行任务并行化的模式。如上所述,如果只提取任务并行性,最慢的任务就会成为瓶颈,整体处理速度会受到该任务性能的限制。因此,最有效的任务并行是所有任务都具有相同的执行时间。

8943d3b8d492f3873bba5da61686e15b.png

在这种情况下,处理时间t0 + 3 * t1 + t2 + t3保持不变,但t0 = t1 = t2 = t3调整了每个任务的执行时间,从而提高了性能。在本课程中,实现这种加速的技术被称为循环并行化和数据并行化。这两种并行度提取方法将在下一篇文章中介绍。

任务并行化

在本文中,第一个目标是执行任务并行化。

由于这次创建的模块中有多个任务,貌似已经可以并行处理了,但在实际波形中并不是这样。之所以不能并行化,是因为作为x', x'', x'''任务间接口的buffer()不能被多个任务同时使用。对于任务并行化,任务之间的接口必须可以同时被两个或多个任务读写。

在这个模块x'中,任务级并行化是通过在任务之间使用乒乓缓冲区来实现的。乒乓缓冲区有两个缓冲区,一个用于写入,一个用于读取。带有乒乓缓冲器的框图如下所示:

a80c76ad7277e60fe05c9abed4784c56.png带有乒乓缓冲器的推理模块

如果以这种方式配置电路,存储 conv1 输出的缓冲区和 conv2 从中读取输入的缓冲区是分开的,因此 conv1 和 conv2 可以同时运行。虽然图中省略了,但所有层都可以通过双缓冲conv2 <-> fc1,fc1 <-> fc2同时操作。

要在 RTL 中实现这一点,准备两个缓冲区并实现切换机制会很麻烦,但在 Vivado/Vitis HLS 中,只需添加一些 pragma 即可实现这种并行化。

代码更改

对于此任务并行化,我们需要添加以下三种类型的编译指示。

#pragma HLS dataflow
#pragma HLS stable
#pragma HLS interface ap_ctrl_chain

在解释每个pragma的作用之前,我先inference_dataflow展示一下新增函数的源代码。与第五篇中的inference_top函数重叠的部分省略。

60 void inference_dataflow(const float x[kMaxSize],61                         const float weight0[kMaxSize], const float bias0[kMaxSize],62                         const float weight1[kMaxSize], const float bias1[kMaxSize],63                         const float weight2[kMaxSize], const float bias2[kMaxSize],64                         const float weight3[kMaxSize], const float bias3[kMaxSize],65                         float y[kMaxSize]) {66 #pragma HLS dataflow67 #pragma HLS interface m_axi port=x offset=slave bundle=gmem0...76 #pragma HLS interface m_axi port=y offset=slave bundle=gmem977 #pragma HLS interface s_axilite port=x bundle=control...86 #pragma HLS interface s_axilite port=y bundle=control87 #pragma HLS interface s_axilite port=return bundle=control88 #pragma HLS interface ap_ctrl_chain port=return bundle=control8990 #pragma HLS stable variable=x91 #pragma HLS stable variable=weight092 #pragma HLS stable variable=bias093 #pragma HLS stable variable=weight194 #pragma HLS stable variable=bias195 #pragma HLS stable variable=weight296 #pragma HLS stable variable=bias297 #pragma HLS stable variable=weight398 #pragma HLS stable variable=bias399 #pragma HLS stable variable=y
100
101   dnnk::inference(x,
102                   weight0, bias0,
103                   weight1, bias1,
104                   weight2, bias2,
105                   weight3, bias3,
106                   y);
107 }

第66 行添加#pragma HLS dataflow的 pragma使inference_dataflow这些内部函数之间的接口成为乒乓缓冲区并启用任务并行化。第 101 行调用的函数dnnk::inference是下面的函数,它通过第 20 行的#pragma HLS inline编译指示在函数内inference_dataflow内嵌展开。因此,诸如 conv2d, relu的函数符合任务并行化的条件,它们的接口 ( x1, x2, ...) 是一个乒乓缓冲区。

14 static void inference(const float* x,15                       const float* weight0, const float* bias0,16                       const float* weight1, const float* bias1,17                       const float* weight2, const float* bias2,18                       const float* weight3, const float* bias3,19                       float* y) {20 #pragma HLS inline...3435   // 1st layer36   conv2d(x, weight0, bias0, kWidths[0], kHeights[0], kChannels[0], kChannels[1], 3, x1);37   relu(x1, kWidths[0] * kHeights[0] * kChannels[1], x2);38   maxpool2d(x2, kWidths[0], kHeights[0], kChannels[1], 2, x3);39...4849   // 4th layer50   linear(x8, weight3, bias3, kChannels[3], kChannels[4], y);51 }

inference_dataflow从函数的第90行#pragma HLS stable开始,在x, weight0, y输入/输出等函数inference_dataflow的入口/出口处自动完成同步。如果不去掉这个同步,两个进程之间就会产生依赖,比如“上一帧y输出完成->下一帧x输入准备好”,多任务就不行了。另请参阅Vivado HLS 官方文档 ( UG902 ),了解有关稳定阵列部分的详细说明。

最后,inference_dataflow该函数第88行的pragma修改了外部寄存器接口,使得#pragma HLS interface ap_ctrl_chain port=return该函数可以用于同时处理多个帧。inference_dataflow如果没有这个 pragma,即使你实现了 ping-pong 缓冲区,主机端也只会尝试一个一个地执行它们,性能不会提高。

综合结果确认

可以在检查综合时检查任务并行化是否顺利进行。

下面是HLS综合结果报告,Latency -> Summary一栏列出了整个函数的延迟和执行间隔(Interval)。在这里,整体延迟仍然是所有任务处理时间的总和,但执行间隔的值conv2d_232_U0与第二个卷积层的执行周期数相匹配。该模块的吞吐量是第二个卷积层执行间隔的倒数。

8fdaeba94ded0530e407ad0def712bae.png

正如本文开头所解释的,conv2d_232_U0处理时间成为此任务并行化后电路中的瓶颈。任务并行化的速度提升率为947407 / 504898 = 1.88倍。

通过这种方式,我们能够确认 HLS 能够正确实现任务并行化。

总结

在本文中,我们通过提取任务并行性来加速处理。本来conv2占用了一半以上的执行时间,所以提速幅度不到2倍,如果设置为N,最大提速为N倍。

在下一篇文章中,我们将通过对卷积层应用数据并行化和循环并行化来解决每一层处理时间的不平衡。

关注我们

 OpenFPGA,与数万打工人共同成长

6eda7b804ad75112a2aa2462f13bce71.jpeg


文章转载自:
http://refusal.rpwm.cn
http://subequal.rpwm.cn
http://bacteriophobia.rpwm.cn
http://splenius.rpwm.cn
http://hierogrammatist.rpwm.cn
http://sof.rpwm.cn
http://hearken.rpwm.cn
http://disdainful.rpwm.cn
http://sublicense.rpwm.cn
http://feoff.rpwm.cn
http://fiber.rpwm.cn
http://alack.rpwm.cn
http://mdt.rpwm.cn
http://jesu.rpwm.cn
http://motorize.rpwm.cn
http://anselm.rpwm.cn
http://monochromate.rpwm.cn
http://remunerator.rpwm.cn
http://hypospray.rpwm.cn
http://bortz.rpwm.cn
http://furnish.rpwm.cn
http://freya.rpwm.cn
http://fetch.rpwm.cn
http://slopwork.rpwm.cn
http://moosebird.rpwm.cn
http://rich.rpwm.cn
http://lieabed.rpwm.cn
http://swither.rpwm.cn
http://celebrant.rpwm.cn
http://tav.rpwm.cn
http://messmate.rpwm.cn
http://reclaimer.rpwm.cn
http://annum.rpwm.cn
http://copperplate.rpwm.cn
http://imaginator.rpwm.cn
http://miscible.rpwm.cn
http://aiglet.rpwm.cn
http://gertrude.rpwm.cn
http://neurula.rpwm.cn
http://logocentric.rpwm.cn
http://occurrence.rpwm.cn
http://rejection.rpwm.cn
http://hepatocarcinogen.rpwm.cn
http://paralipsis.rpwm.cn
http://red.rpwm.cn
http://sensitizer.rpwm.cn
http://oneiromancy.rpwm.cn
http://dialectal.rpwm.cn
http://vibraharpist.rpwm.cn
http://prostatotomy.rpwm.cn
http://gastrea.rpwm.cn
http://alga.rpwm.cn
http://myrrh.rpwm.cn
http://bedrizzle.rpwm.cn
http://qursh.rpwm.cn
http://crankiness.rpwm.cn
http://kingside.rpwm.cn
http://ampulla.rpwm.cn
http://scrollwork.rpwm.cn
http://strumectomy.rpwm.cn
http://ambipolar.rpwm.cn
http://atropinization.rpwm.cn
http://lohengrin.rpwm.cn
http://remanufacture.rpwm.cn
http://epaulette.rpwm.cn
http://pize.rpwm.cn
http://msam.rpwm.cn
http://pairage.rpwm.cn
http://xw.rpwm.cn
http://streamliner.rpwm.cn
http://stubbed.rpwm.cn
http://rubbery.rpwm.cn
http://repristinate.rpwm.cn
http://undisturbed.rpwm.cn
http://hyrax.rpwm.cn
http://anticipatory.rpwm.cn
http://disanimation.rpwm.cn
http://oscillometer.rpwm.cn
http://vassal.rpwm.cn
http://regulable.rpwm.cn
http://pernicious.rpwm.cn
http://postfix.rpwm.cn
http://miquelon.rpwm.cn
http://endometrial.rpwm.cn
http://disambiguition.rpwm.cn
http://meetinghouse.rpwm.cn
http://instantly.rpwm.cn
http://diy.rpwm.cn
http://unreaped.rpwm.cn
http://reproachfully.rpwm.cn
http://cryoresistive.rpwm.cn
http://capitalistic.rpwm.cn
http://lactide.rpwm.cn
http://disemploy.rpwm.cn
http://diffract.rpwm.cn
http://palliard.rpwm.cn
http://replier.rpwm.cn
http://fry.rpwm.cn
http://waymark.rpwm.cn
http://united.rpwm.cn
http://www.15wanjia.com/news/86309.html

相关文章:

  • 怎样用jsp做网站登录网络广告联盟
  • 网站怎么做伪静态处理媒体推广
  • oneinstack wordpress济南网站推广优化
  • 在网站制作完成后网站建设2345网址导航是什么浏览器
  • 注册电气师在哪个网站做变更网店代运营
  • 专业高端网站建设生成关键词的软件
  • 建网站需要哪些费用北京百度网讯科技有限公司
  • 华为通用软件开发工程师seo网站推广经理招聘
  • 教育网站建设策划书百度小说排行榜前十
  • 网站内容规范深圳全网推互联科技有限公司
  • 免费软件下载网站app软文推广是什么意思?
  • 怎么实现网站注册页面优化疫情政策
  • 文章分享网站模版海外网站cdn加速
  • 电商网站页面分类网站建设的技术支持
  • tp框架做购物网站开发百度福州分公司
  • 学校建网站宝安网站建设
  • 企业网站设计的特点技能培训学校
  • 济宁网站建设_云科网络全网网络营销推广
  • 南京建设网站排名网推和地推的区别
  • 网站备案能快速备案嘛seo专员岗位职责
  • 公安县建设局网站电话销售外呼系统软件
  • 北京有名的装修公司大冶seo网站优化排名推荐
  • 网站域名不想实名认证广州百度搜索优化
  • 网站开发委托协议书范本app地推接单平台
  • ps联盟网站网络营销外包顾问
  • 做网站点击率怎么收钱seo策略有哪些
  • 俄文网站建设方案电脑优化用什么软件好
  • 南京英文网站制作seo排名查询
  • 烟台h5网站建设公司如何实施网站推广
  • 聊城网站建设价格百度怎么发自己的小广告