Threads are executed in warps of 32, with all threads in the warp executing the same instruction at the same time What happens if different threads in a warp need to do different things?
if (x<0.0)
  z = x-2.0;
else
  z = sqrt(x);

This is called warp divergence – CUDA will generate correct code to handle this, but to understand the performance you need to understand what CUDA does with it, all threads execute both conditional branches, so execution cost is sum of both branches ⇒ potentially large loss of performance

cuda 的实现是将两条路径的代码都运行了,只是让那个不符合的路径返回一个奇怪的值。原因在于在同一时间,所有的thread必须执行相同的instruction(指令),这里的thread是所有的thread,不只是同一个block中的。所以即使你让thread分开执行if和else语句,那也是一部分thread执行if的语句,其他的thread要执行else的语句要等待他执行完,然后这些执行else的语句。这与所有的thread同时执行if和else的代码是一样的,因此两个都执行,这是CUDA的实现方法。部分thread不能工作,造成闲置而降低了效率,成为divergence。

如果对thread进行if statement判断,就会出现warp divergence。

最新文章

  1. 谷歌大牛 Rob Pike 的 5 个编程原则
  2. 认识html文件基本结构
  3. jQuery入门第三
  4. 一个通用onReady函数的实现
  5. PHP操作mysql类
  6. esri-leaflet入门教程(4)-加载各类图层
  7. 跟着刚哥梳理java知识点——包装类(十)
  8. Ubuntu16.04解决无法切换root权限的问题
  9. TypeError:Error #1009
  10. 配置文件properties读取使用的好方法
  11. 419 JQuery and BootStrap
  12. 基于LinkedList实现桶排序
  13. spring cloud学习(五) 配置中心
  14. scp机器间远程拷贝
  15. Kubernetes学习之路(二十五)之Helm程序包管理器
  16. 在Linux下如何限制命令执行的时间?
  17. 墨菲定律:当你觉得一个地方可能有bug,那么这个地方就会有bug----顺带了解下Tomcat那少有人注意的localhost.log
  18. Power OJ 2605 SPFA+dp思想
  19. JS 中div内容的显示和隐藏
  20. echarts实现动态传入数据刷新【可执行】

热门文章

  1. spring框架搭建url
  2. CentOS7.0安装Nginx 1.7.9
  3. MongoDB—— 写操作 Core MongoDB Operations (CRUD)
  4. C语言的源程序字符集与执行字符集
  5. 01WebApi防篡改机制---HMAC机制
  6. 免费的Android UI库及组件推荐
  7. 实战CentOS系统部署Hadoop集群服务
  8. Unity手游之路&lt;四&gt;3d旋转-四元数,欧拉角和变幻矩阵
  9. Two Strings Are Anagrams
  10. All Kind Of Conference(随时更新...)