What is the difference between CPU and GPU

Author: know almost Users
link: https: //www.zhihu.com/question/19903344/answer/96081382
Source: know almost
 

CPU and GPU very different reason, because of their different design goals, which are for two different scenarios. CPU needs very versatile to handle a variety of data types, while also determining logic will introduce a large amount of jump and branch processing interrupts. These are made extremely complicated internal structure of the CPU. The GPU is the face of the type of highly uniform, no mutual dependence of large-scale data and does not need to be interrupted pure computing environment.

  So the CPU and GPU on the show a very different architectures (schematic):

  Pictures from nVidia CUDA documentation. Wherein the calculation unit is green, orange-red is a storage unit, the control unit is orange.

GPU uses a large number of computing units and long lines, but only a very simple control logic and eliminates the Cache. Cache while the CPU is not only occupy a lot of space, but also has many and complex control logic circuit optimization, computing power compared to only a small portion of the CPU

 

  As can be seen from the figure:

Cache, local memory: CPU > GPU

Threads (threads): GPU> CPU

Registers: GPU> CPU registers can support more than a lot of Thread, thread need to use the register, a large number of thread, register also have to follow a great job.

SIMD Unit (single instruction multiple data stream, in a synchronous manner, execute the same instruction at the same time): GPU> CPU.

CPU-based low-latency design:

 

The ALU has a powerful CPU (arithmetic means), it can be done in a few clock cycles arithmetic.

Today's CPU can reach 64bit double precision. Source operator performing double precision floating point addition and multiplication only requires one to three clock cycles.

Frequency of the clock cycle of the CPU is very high, reaching 1.532 ~ 3gigahertz (Gigabit HZ, 9 th 10).

大的缓存也可以降低延时。保存很多的数据放在缓存里面,当需要访问的这些数据,只要在之前访问过的,如今直接在缓存里面取即可。

复杂的逻辑控制单元。当程序含有多个分支的时候,它通过提供分支预测的能力来降低延时。

数据转发。 当一些指令依赖前面的指令结果时,数据转发的逻辑控制单元决定这些指令在pipeline中的位置并且尽可能快的转发一个指令的结果给后续的指令。这些动作需要很多的对比电路单元和转发电路单元。

 

GPU是基于大的吞吐量设计。

GPU的特点是有很多的ALU和很少的cache. 缓存的目的不是保存后面需要访问的数据的,这点和CPU不同,而是为thread提高服务的。如果有很多线程需要访问同一个相同的数据,缓存会合并这些访问,然后再去访问dram(因为需要访问的数据保存在dram中而不是cache里面),获取数据后cache会转发这个数据给对应的线程,这个时候是数据转发的角色。但是由于需要访问dram,自然会带来延时的问题。

GPU的控制单元(左边黄色区域块)可以把多个的访问合并成少的访问。

GPU的虽然有dram延时,却有非常多的ALU和非常多的thread. 为啦平衡内存延时的问题,我们可以中充分利用多的ALU的特性达到一个非常大的吞吐量的效果。尽可能多的分配多的Threads.通常来看GPU ALU会有非常重的pipeline就是因为这样。

所以与CPU擅长逻辑控制,串行的运算。和通用类型数据运算不同,GPU擅长的是大规模并发计算,这也正是密码破解等所需要的。所以GPU除了图像处理,也越来越多的参与到计算当中来。

GPU的工作大部分就是这样,计算量大,但没什么技术含量,而且要重复很多很多次。就像你有个工作需要算几亿次一百以内加减乘除一样,最好的办法就是雇上几十个小学生一起算,一人算一部分,反正这些计算也没什么技术含量,纯粹体力活而已。而CPU就像老教授,积分微分都会算,就是工资高,一个老教授资顶二十个小学生,你要是富士康你雇哪个?GPU就是这样,用很多简单的计算单元去完成大量的计算任务,纯粹的人海战术。这种策略基于一个前提,就是小学生A和小学生B的工作没有什么依赖性,是互相独立的。很多涉及到大量计算的问题基本都有这种特性,比如你说的破解密码,挖矿和很多图形学的计算。这些计算可以分解为多个相同的简单小任务,每个任务就可以分给一个小学生去做。但还有一些任务涉及到“流”的问题。比如你去相亲,双方看着顺眼才能继续发展。总不能你这边还没见面呢,那边找人把证都给领了。这种比较复杂的问题都是CPU来做的。

  总而言之,CPU和GPU因为最初用来处理的任务就不同,所以设计上有不小的区别。而某些任务和GPU最初用来解决的问题比较相似,所以用GPU来算了。GPU的运算速度取决于雇了多少小学生,CPU的运算速度取决于请了多么厉害的教授。教授处理复杂任务的能力是碾压小学生的,但是对于没那么复杂的任务,还是顶不住人多。当然现在的GPU也能做一些稍微复杂的工作了,相当于升级成初中生高中生的水平。但还需要CPU来把数据喂到嘴边才能开始干活,究竟还是靠CPU来管的。

什么类型的程序适合在GPU上运行?

  (1)计算密集型的程序。所谓计算密集型(Compute-intensive)的程序,就是其大部分运行时间花在了寄存器运算上,寄存器的速度和处理器的速度相当,从寄存器读写数据几乎没有延时。可以做一下对比,读内存的延迟大概是几百个时钟周期;读硬盘的速度就不说了,即便是SSD, 也实在是太慢了。

  (2)易于并行的程序。GPU其实是一种SIMD(Single Instruction Multiple Data)架构, 他有成百上千个核,每一个核在同一时间最好能做同样的事情。

Guess you like

Origin blog.csdn.net/luoyajingfeng2/article/details/90752019