Tell you what is CPU/GPU in plain language?

CPU

The CPU (Central Processing Unit, Central Processing Unit) is the "brain" of the machine, and the "commander-in-chief" who lays out strategies, issues orders, and controls actions.

The structure of the CPU mainly includes arithmetic unit (ALU, Arithmetic and Logic Unit), control unit (CU, Control Unit), register (Register), cache (Cache) and the bus for data, control and status communication between them.

In simple terms: the computing unit, control unit and storage unit, the architecture is shown in the following figure:

Figure: Schematic diagram of CPU microarchitecture

what? Can't remember the architecture? Let's change the way of expression:

Figure: Schematic diagram of CPU micro-architecture (modified)

Well, it probably means that.

Literally, we also understand very well that the calculation unit mainly performs arithmetic operations, shifts and other operations, as well as address operations and conversion; the storage unit is mainly used to store the data and instructions generated in the operation; the control unit decodes the instructions, and Send out the control signal for each operation to be performed to complete each instruction.

Therefore, the process of an instruction executed in the CPU is as follows: After the instruction is read, it is sent to the controller (yellow area) through the instruction bus for decoding, and the corresponding operation control signal is issued; then the arithmetic unit (green area) Calculate the data according to the operating instructions, and store the obtained data into the data buffer (large orange area) through the data bus. The process is shown in the figure below:

Figure: CPU execution instruction diagram

Is it a bit complicated? It doesn't matter, this picture does not need to be remembered at all, we just need to know that the CPU follows the Von Neumann architecture, and its core is: stored programs and executed sequentially.

Speaking of this, have you seen the problem? That's right-in this structure diagram, the area of ​​the green area responsible for calculation seems to be too small, while the cache in the orange area and the control unit in the yellow area occupy a lot of space.

There is a common saying in high school chemistry: structure determines properties, which is also very applicable here.

Because the CPU architecture requires a lot of space to place the storage unit (orange part) and control unit (yellow part), in contrast, the computing unit (green part) occupies only a small part, so it is in massively parallel computing Extremely limited in ability, and better at logic control.

In addition, because it follows the von Neumann architecture (stored programs, sequential execution), the CPU is like a steward of everything, and it always does everything that people order. But as people's demand for larger scales and faster processing speeds increased, the housekeeper gradually became a little weak.

So everyone thought, can we put multiple processors on the same chip and let them do things together, so that the efficiency will not be improved?

That's right, the GPU was born.

GPU

Before officially explaining the GPU, let's talk about a concept mentioned above-parallel computing.

Parallel computing refers to the process of using multiple computing resources to solve computing problems at the same time. It is an effective means to improve the computing speed and processing capacity of a computer system. Its basic idea is to use multiple processors to solve the same problem together, that is, to decompose the solved problem into several parts, and each part is calculated in parallel by an independent processor.

Parallel computing can be divided into parallel in time and parallel in space.

Parallelism in time refers to assembly line technology. For example, when a factory produces food, it is divided into four steps: cleaning-disinfection-cutting-packaging.

If the assembly line is not used, after one food completes the above four steps, the next food will be processed, which is time-consuming and affects efficiency. But with assembly line technology, four foods can be processed simultaneously. This is the time parallelism in parallel algorithms. Two or more operations are started at the same time, which greatly improves computing performance.

Figure: Schematic diagram of the pipeline

Spatial parallelism refers to the concurrent execution of calculations by multiple processors, that is, connecting two or more processors through a network to simultaneously calculate different parts of the same task, or large-scale problems that a single processor cannot solve.

For example, Xiao Li plans to plant three trees on the Arbor Day. If Xiao Li takes 6 hours to complete the task by one person, on the day of the Arbor Day, he called good friends Xiao Hong and Xiao Wang, and the three began to dig holes and plant trees at the same time. After hours, everyone completed a tree planting task. This is the spatial parallelism in the parallel algorithm, which divides a large task into multiple identical subtasks to speed up problem solving.

Therefore, if the CPU is allowed to perform this tree planting task, it will be planted one by one, which takes 6 hours, but letting the GPU plant the tree is equivalent to several people planting it at the same time.

The full name of GPU is Graphics Processing Unit, and Chinese means graphics processor. Just like its name, GPU was originally used on personal computers, workstations, game consoles and some mobile devices (such as tablets, smartphones, etc.) to run graphics operations. Microprocessor.

Why is GPU so good at processing image data? This is because every pixel on the image needs to be processed, and the process and method of processing each pixel are very similar, which has become a natural hotbed of GPU.

The simple GPU architecture is shown in the figure below:

Figure: Schematic diagram of GPU micro-architecture

From the architecture diagram, we can clearly see that the structure of the GPU is relatively simple, with a large number of computing units and an ultra-long pipeline, which is particularly suitable for processing a large amount of uniform data.

But the GPU cannot work alone, it must be controlled by the CPU to work. The CPU can act alone to process complex logical operations and different data types, but when a large amount of data with a uniform processing type is required, the GPU can be called for parallel computing.

Note: There are many arithmetic units ALU and few caches in the GPU. The purpose of the cache is not to save the data that needs to be accessed later. This is different from the CPU, but to improve services for the thread. If there are many threads that need to access the same data, the cache will merge these accesses and then access the dram.

Then put the CPU and GPU on a picture to see the comparison, it is very clear.

Most of the GPU's work is computationally intensive, but it has no technical content and has to be repeated many, many times.

To borrow from the saying of a great god on Zhihu, just like you have a job that needs to calculate hundreds of millions of times plus, subtract, multiply and divide within 100, the best way is to hire dozens of elementary school students to do the calculation together, and one person counts as part. Anyway, these calculations are also There is no technical content, it is purely physical work; and the CPU is like an old professor, integral and differential will be counted, that is, the salary is high, an old professor is worth 20 elementary school students, if you are Foxconn, which one would you hire?

GPU is to use a lot of simple computing units to complete a large number of computing tasks, purely crowded tactics. This strategy is based on the premise that the work of elementary student A and elementary student B are independent of each other.

But one thing needs to be emphasized. Although the GPU is born for image processing, we can find from the previous introduction that it does not have special image service components in structure, but optimizes and adjusts the structure of the CPU, so Now GPUs can not only show their talents in the field of image processing, it is also used in scientific computing, password cracking, numerical analysis, massive data processing (sorting, Map-Reduce, etc.), financial analysis and other fields that require large-scale parallel computing.

So GPU can also be considered as a more general chip.

Guess you like

Origin blog.csdn.net/l1509214729/article/details/109157349