Computing unit, related device and method
By using index and effective element loading instructions when multiplying the sparse matrix and the excitation vector, the number of loading instructions is reduced, the problem of high processing overhead in the existing technology is solved, and the computing efficiency is improved.
Patent Information
- Application Number
- CN202110231342.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-02
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2041-03-02
AI Technical Summary
The existing technology requires frequent instruction fetching and decoding when multiplying sparse matrices and excitation vectors, resulting in high processing overhead and slow speed, especially when the instruction fetch width is limited and the cache space is insufficient in low-power processing units.
An arithmetic unit is designed that simultaneously executes the unpruned element index in the sparse matrix and the loading of effective elements in the vector to be multiplied through index and valid element loading instructions, which reduces the number of loading instructions and thereby improves computing efficiency.
The efficiency of the multiplication operation of the sparse matrix and the vector to be multiplied is improved, the processing overhead is reduced, and it is suitable for modern low-power processing units.
Smart Images

Figure CN114996647B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of chips, and more specifically, to a computing unit, a related device and a method. Background Art
[0002] Deep neural networks (DNNs) use a large number of matrix and vector operations, such as matrix-matrix multiplication and matrix-vector multiplication. A deep neural network has multiple layers of nodes, each of which is connected to the nodes of the previous layer, which is equivalent to receiving the output of the nodes of the previous layer as input and performing operations (multiplication, convolution, etc.) with the weight matrix of the node. The output result of a deep neural network can be regarded as the product of the weight matrix and the input excitation vector or excitation matrix. Since the amount of matrix operation is very large, in order to reduce the computational intensity and memory overhead, pruning technology is proposed to remove redundant connections in DNNs, which is equivalent to turning a large number of elements in the weight matrix that have little effect on the result into 0. The elements that are 0 do not need to participate in the matrix multiplication operation, thereby reducing the computational intensity and memory overhead by increasing the sparsity. For example, 30% of the elements in a weight matrix with a sparsity of 30% are non-zero. As long as the product of these 30% elements and the corresponding elements in the excitation vector is calculated and accumulated, the final result can be obtained.
[0003] In the multiplication of a sparse matrix and an excitation vector (the multiplication of a sparse matrix and an excitation matrix can be transformed into the multiplication of a sparse matrix and one excitation vector), three loads are generally required. First, the unpruned weight values (weight values that are not 0) need to be loaded into the sparse matrix. For pruned element values that are 0, they do not need to participate in the operation. Then, the indexes of the unpruned weights (the indices of the weights that are not 0) need to be loaded into the sparse matrix. These indexes are the indices of the valid elements in the excitation vector that need to participate in the operation. The elements at the indices at other positions in the excitation vector correspond to a weight of 0, and the result of the multiplication is still equal to 0, which has no practical meaning. Next, the elements corresponding to these indices need to be loaded in the excitation vector according to these indices. After these three loads, the products of the elements selected by the index in the excitation vector and the unpruned weights in the sparse matrix are accumulated to obtain the multiplication result of the sparse matrix and the excitation vector.
[0004] Since the above three loads require three different instructions, the processing unit needs to frequently fetch and decode instructions, which results in high processing overhead and slow speed. Modern processing units, especially low-power processing units, usually have limited instruction fetch width, and insufficient cache space for loading. A large number of the above instructions seriously affects the computing efficiency and increases the processing overhead. Summary of the invention
[0005] In view of this, the present disclosure aims to improve the operational efficiency of the above-mentioned sparse matrix related operations and reduce their processing overhead.
[0006] According to one aspect of the present disclosure, there is provided a computing unit, comprising:
[0007] an instruction cache unit, configured to receive an index and valid element load instruction, wherein the index and valid element load instruction is used to obtain a valid element vector corresponding to an unpruned element in the sparse matrix from the vector to be multiplied in the multiplication of the sparse matrix and the vector to be multiplied, wherein the index and valid element load instruction comprises a first source address, a second source address and a destination address, wherein the first source address represents a starting storage address of an index of an unpruned element in the sparse matrix, the second source address represents a starting storage address of the vector to be multiplied, and the destination address represents an address to which the valid element vector is to be stored;
[0008] an unpruned element index reading unit, configured to read the unpruned element index according to the first source address;
[0009] an effective element reading unit, configured to read, in the vector to be multiplied, effective elements for multiplying with the unpruned elements in the sparse matrix according to the second source address and the read unpruned element index;
[0010] A storage unit is used to assemble the valid elements into a valid element vector and store it according to the destination address.
[0011] Optionally, the valid element reading unit adds the second source address and the read unpruned element index respectively to obtain the storage address of each valid element, and reads the valid element according to the storage address.
[0012] Optionally, the instruction cache unit is also used to receive an unpruned element value loading instruction, wherein the unpruned element value loading instruction obtains the unpruned element value in the sparse matrix during the multiplication of the sparse matrix and the vector to be multiplied, and the unpruned element value loading instruction includes a third source address, and the third source address represents the starting storage address of the unpruned element value; the operation unit also includes: an unpruned element value reading unit, which is used to read the unpruned element value according to the destination address.
[0013] Optionally, the instruction cache unit is also used to receive vector multiplication instructions, and the vector multiplication instructions obtain a multiplication result vector of the sparse matrix and the vector to be multiplied based on the unpruned element value and the effective element vector in the multiplication of the sparse matrix and the vector to be multiplied; the operation unit also includes: a multiplication result vector acquisition unit, which is used to obtain the multiplication result vector by multiplying the unpruned element value and the effective elements in the effective element vector.
[0014] Optionally, the first source address includes a first base source address, and the second source address includes a second base source address.
[0015] Optionally, the first source address includes a first base source address and a first immediate value, and the second source address includes a second base source address and a second immediate value; the unpruned element index reading unit reads the unpruned element index according to the address obtained by the sum of the first base source address and the first immediate value; the valid element reading unit reads the valid element in the vector to be multiplied according to the address obtained by the sum of the second base source address and the second immediate value, and the read unpruned element index.
[0016] Optionally, the first source address includes a first base source address and a first coefficient, and the second source address includes a second base source address and a second coefficient; the unpruned element index reading unit reads the unpruned element index according to the address obtained by the product of the first coefficient, the vector length and the element size in the vector, and the sum of the first base source address; the valid element reading unit reads the valid element in the vector to be multiplied according to the address obtained by the product of the second coefficient, the vector length and the element size in the vector, and the sum of the second base source address, and the read unpruned element index.
[0017] Optionally, the first source address includes a first base source address and a third coefficient, and the second source address includes a second base source address and a fourth coefficient; the unpruned element index reading unit reads the unpruned element index according to an address obtained by the product of the third coefficient and the size of the element in the vector, and the sum of the first base source address; the valid element reading unit reads the valid element in the vector to be multiplied according to an address obtained by the product of the fourth coefficient and the size of the element in the vector, and the sum of the second base source address, and the read unpruned element index.
[0018] Optionally, the elements of the vector to be multiplied are stored in multiple storage bodies in a tightly coupled memory, wherein parallel access to the elements in the multiple storage bodies is allowed; the indices of unpruned elements in the sparse matrix are stored in groups, a single group contains the index of an unpruned element taken from each of multiple rows in the sparse matrix, and different indexes in the same group correspond to different storage bodies of the tightly coupled memory.
[0019] Optionally, the multiple rows are rows of the number of storage bodies of the multiple storage bodies sequentially taken out from the sparse matrix according to row indices.
[0020] Optionally, the unpruned element index reading unit reads the unpruned element index of a group starting from the first source address, and updates the first source address with the sum of the first source address and the length of a group.
[0021] Optionally, the valid element vector is assembled in a cache and moved from the cache back to the processing unit where the operation unit is located according to the destination address.
[0022] Optionally, the valid element vector is assembled in the tightly coupled memory, and is moved from the tightly coupled memory back to the processing unit where the operation unit is located according to the destination address.
[0023] According to one aspect of the present disclosure, there is provided a processing unit, comprising:
[0024] An instruction fetch unit, used to fetch index and valid element load instructions from the memory;
[0025] An instruction decoding unit, used for decoding the retrieved index and valid element load instruction;
[0026] The arithmetic unit as described above is used to receive and execute the decoded index and valid element load instructions.
[0027] According to one aspect of the present disclosure, there is provided a computing device, comprising:
[0028] A memory, used to store the index and valid element loading instructions;
[0029] A processing unit as described above.
[0030] According to one aspect of the present disclosure, a system on chip is provided, comprising the processing unit as described above.
[0031] According to one aspect of the present disclosure, a data center is provided, comprising the computing device as described above.
[0032] According to one aspect of the present disclosure, a method for obtaining an effective element vector is provided, wherein the effective element vector is a vector consisting of effective elements corresponding to unpruned elements in a sparse matrix obtained from the vector to be multiplied in the multiplication of a sparse matrix and a vector to be multiplied, and the method comprises:
[0033] receiving an index and valid element load instruction, the index and valid element load instruction being used to obtain the valid element vector, the index and valid element load instruction comprising a first source address, a second source address and a destination address, the first source address representing a starting storage address of an unpruned element index in the sparse matrix, the second source address representing a starting storage address of the vector to be multiplied, and the destination address representing an address to which the valid element vector is to be stored;
[0034] Reading an unpruned element index according to the first source address;
[0035] Reading, according to the second source address and the read unpruned element index, a valid element in the vector to be multiplied for multiplication with the unpruned element in the sparse matrix;
[0036] The valid elements are assembled into a valid element vector and stored according to the destination address.
[0037] Optionally, reading, in the vector to be multiplied, valid elements for multiplying with unpruned elements in the sparse matrix according to the second source address and the read unpruned element index, comprises:
[0038] Adding the second source address and the read unpruned element index respectively to obtain the storage address of each valid element;
[0039] The valid element is read according to the storage address.
[0040] Optionally, the elements of the vector to be multiplied are stored in multiple storage bodies in a tightly coupled memory, wherein parallel access to the elements in the multiple storage bodies is allowed; the indices of unpruned elements in the sparse matrix are stored in groups, a single group contains the index of an unpruned element taken from each of multiple rows in the sparse matrix, and different indexes in the same group correspond to different storage bodies of the tightly coupled memory.
[0041] Optionally, the multiple rows are rows of the number of storage bodies of the multiple storage bodies sequentially taken out from the sparse matrix according to row indices.
[0042] Optionally, reading the unpruned element index according to the first source address includes: starting from the first source address, reading the unpruned element index of a group, and updating the first source address with the sum of the first source address and the length of a group.
[0043] In the embodiment of the present disclosure, the latter two of the three loads in the multiplication of the sparse matrix and the excitation vector (loading the index of the unpruned weights from the sparse matrix and loading the valid elements corresponding to these indexes from the excitation vector according to the index) are executed with one instruction. The instruction contains a first source address, a second source address, and a destination address. The first source address indicates the storage address of the unpruned element index, and the second source address indicates the storage address of the excitation vector. The index of the unpruned weights is loaded from the sparse matrix according to the first source address. The valid elements corresponding to the index are loaded from the excitation vector according to the second source address and the above index. Then the data is stored back according to the destination address. Through such an instruction, the purpose of executing the latter two of the three loads mentioned above at the same time is achieved. Compared with the prior art that executes three loads with three instructions, the embodiment of the present disclosure greatly improves the operational efficiency in the multiplication operation of the sparse matrix and the excitation vector, and reduces the processing overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The above and other objects, features and advantages of the present disclosure will become more apparent through the description of the embodiments of the present disclosure with reference to the following drawings, in which:
[0045] Figure 1 is a structural diagram of a data center to which an embodiment of the present disclosure is applied;
[0046] Figure 2 is an internal structure diagram of a server in a data center according to an embodiment of the present disclosure;
[0047] Figure 3 is an internal structure diagram of a computing unit as an instruction execution unit according to an embodiment of the present disclosure;
[0048] Figure 4 is a schematic diagram of a tightly coupled memory (TCM) storing elements in a vector to be multiplied by memory bank according to an embodiment of the present disclosure;
[0049] Figure 5A is a schematic diagram of loading valid elements from a vector to be multiplied according to an unpruned element index in a sparse matrix according to an embodiment of the present disclosure;
[0050] Figure 5B is a schematic diagram of loading valid elements from a vector to be multiplied according to an unpruned element index in a sparse matrix according to another embodiment of the present disclosure;
[0051] Fig. 6A is a schematic diagram of unpruned element values in a sparse matrix obtained according to an unpruned element value load instruction in one embodiment of the present disclosure;
[0052] Figure 6B is a schematic diagram of each group of unpruned element indexes read according to the index and the first source address of the valid element load instruction in one embodiment of the present disclosure;
[0053] Figure 6C is a second source address and Figure 6B The obtained index loads the valid elements from the vector to be multiplied;
[0054] Fig.6D is a schematic diagram of a valid element vector obtained in one embodiment of the present disclosure;
[0055] Fig. 6E In one embodiment of the present disclosure, Figure 6B A schematic diagram of the unpruned element values corresponding to the unpruned element indices;
[0056] Fig. 6F In one embodiment of the present disclosure Fig. 6EThe vector of unpruned elements shown is the same as
[0057] Fig.6D The schematic diagram of the result of multiplying the valid element vectors shown;
[0058] Figure 7 is a list of various addressing modes and corresponding operands of the embodiments of the present disclosure;
[0059] Figure 8 is a comparative histogram of the number of occupied clock cycles between the embodiment of the present disclosure and the prior art;
[0060] Fig. 9 is a flowchart of a method for obtaining a valid element vector according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0061] The present disclosure is described below based on embodiments, but the present disclosure is not limited to these embodiments. In the detailed description of the present disclosure below, some specific details are described in detail. It is possible for a person skilled in the art to fully understand the present disclosure without the description of these details. In order to avoid confusing the essence of the present disclosure, well-known methods, processes, and procedures are not described in detail. In addition, the drawings are not necessarily drawn to scale.
[0062] The following terms are used in this article.
[0063] Deep Neural Network (DNN): Deep neural network is a new research direction in the field of machine learning. It introduces machine learning to make it closer to its original goal - artificial intelligence (AI). Deep neural network learns the inherent rules and representation levels of sample data. The information obtained in the learning process is of great help in the interpretation of data such as text, images and sounds. Its ultimate goal is to enable machines to have analytical learning capabilities like humans and to recognize data such as text, images and sounds.
[0064] Weight: A deep neural network has multiple layers of nodes, each of which is connected to the nodes of the previous layer, which is equivalent to receiving the output of the nodes of the previous layer as input, and processing these inputs to generate outputs to the nodes of the next layer. Since its input includes the outputs of multiple nodes of the previous layer, and its output includes different outputs to multiple nodes of the next layer, its internal processing process can be regarded as the process of multiplying the output of the nodes of the previous layer by a certain value (possibly plus a certain offset) and outputting it to the nodes of the next layer. This value is called weight. Since the input and output are not single values, but in the form of vectors or matrices (receiving the outputs of multiple nodes of the previous layer at a single time point can be expressed as a vector, and multiple nodes of the previous layer have different outputs at different time points, so it can be expressed as a matrix), its output can also be expressed in the form of vectors or matrices (at a single time point, the outputs of multiple nodes of the next layer can be expressed as a vector, and these outputs are different at different time points, so it can be expressed as a matrix). Therefore, the weights of different nodes of the previous layer at different time points are often arranged in the form of a matrix, that is, a weight matrix.
[0065] Excitation: When the weights of each node of the deep neural network are trained, the real input of the node is called excitation. The multiple inputs from multiple previous layer nodes received at the same time point are reflected as excitation vectors, and the multiple inputs from multiple previous layer nodes received at different time points are reflected as excitation matrices.
[0066] Sparse matrix: judge the elements in the matrix. If the element has little effect on the entire matrix, it will be changed to 0, that is, pruned. Therefore, when multiplying with other vectors or matrices, the elements that are 0 do not actually participate in the multiplication operation, which greatly reduces the computational intensity and memory overhead. In practice, the above-mentioned weight matrix is often pruned, that is, the weights that have little effect on the operation results of the deep neural network are changed to 0 in the weight matrix. In this way, when the weight matrix as described above is multiplied with the excitation vector or excitation matrix, the weights that are 0 do not need to be multiplied, thereby reducing the computational intensity and memory overhead.
[0067] Pruning: The process in which an element in the matrix becomes 0 due to its unimportant nature during the above-mentioned sparsification process.
[0068] Sparsity: The ratio of unpruned elements to all elements in the matrix after pruning. For example, a sparsity of 10% means that 90% of the elements in the matrix become 0 and only 10% of the elements are non-zero.
[0069] Valid elements: Since the 0 elements in the sparse matrix do not participate in the multiplication process of the sparse matrix and the vector to be multiplied, the elements in the vector to be multiplied that correspond to the index of the 0 elements in the sparse matrix do not participate in the operation and are therefore considered invalid. Only the elements in the vector to be multiplied that correspond to the index of the non-0 elements in the sparse matrix participate in the operation, and these elements are called valid elements.
[0070] Element index: The number of an element. The element is uniquely identified by the element index, and is generally indexed as 0, 1, 2, etc.
[0071] Base address: The address used as the basis. In addressing, it is usually addressed according to the base address or, if there is an offset, according to the result of adding the base address to the offset.
[0072] Vector length: the number of elements in a vector. Generally, the system automatically configures it. Once configured, the number of elements in the row vector of the excitation vector and sparse matrix is the vector length.
[0073] Element size: Generally, it is the number of bytes that an element occupies. For example, if 2 bytes are used to represent an element in a vector, the element size is 2 bytes.
[0074] Tightly Coupled Memory (TCM): is a fixed-size random access memory (RAM) that is tightly coupled to the processor core and provides performance comparable to cache. Its advantage over cache is that the program code can precisely control what function or code is placed where in it, so it will have a performance preset by the user, rather than being affected by statistical performance like cache.
[0075] Bank: A portion of the storage space in a tightly coupled memory. A tightly coupled memory is divided into multiple banks, and different banks can be accessed in parallel, thereby improving access efficiency.
[0076] Processing unit: A unit that performs traditional processing (not for complex operations such as image processing and fully connected operations in various deep neural networks). The processing unit can take the form of a central processing unit (CPU), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), etc.
[0077] System-on-a-chip (SoC): A complete system integrated on a single chip, which packages all or part of the electronic circuits necessary to implement one or more functions. The so-called complete system generally includes a central processing unit (CPU), memory, and peripheral circuits.
[0078] Application environment of the present disclosure
[0079] The embodiment of the present disclosure proposes a method for obtaining a valid element vector corresponding to an unpruned element in a sparse matrix from the vector to be multiplied during the multiplication of a sparse matrix and a vector to be multiplied. The sparse matrix here can be a weight matrix. The vector to be multiplied can be an excitation vector. The whole scheme is relatively general. For example, data centers, ordinary computer embedded devices that need to multiply a sparse matrix and a vector to be multiplied, or Internet of Things (IOT) devices can all be applicable. The scheme is independent of the hardware environment in which it is ultimately deployed. However, for the sake of exemplary description, the following description will mainly be based on the data center as the application scenario. Those skilled in the art should understand that the embodiments of the present disclosure can also be applied to other application scenarios.
[0080] Data Center
[0081] Data centers are a globally collaborative network of specific devices used to transmit, accelerate, display, calculate, and store data information on the Internet network infrastructure. In the future, data centers will also become an asset for corporate competition. With the widespread application of data centers, artificial intelligence and other technologies are increasingly being applied to data centers. Deep learning, as an important technology of artificial intelligence, has been widely used in data center big data analysis operations. In deep learning, a large number of multiplication operations of weight matrices and incentive vectors are involved, among which the weight matrices are largely sparse to improve computing efficiency and reduce overhead.
[0082] In traditional large data centers, the network structure is usually as follows Figure 1 As shown in the figure, it is the hierarchical inter-networking model. This model includes the following parts:
[0083] Server 140 : Each server 140 is a processing and storage entity of the data center. The processing and storage of a large amount of data in the data center are completed by these servers 140 .
[0084] Access switch 130: Access switch 130 is used to connect servers 140 to the switch in the data center. One access switch 130 connects to multiple servers 140. Access switches 130 are usually located at the top of the rack, so they are also called top of rack switches, and they are physically connected to the servers.
[0085] Aggregation switch 120: Each aggregation switch 120 connects to multiple access switches 130 and provides other services, such as firewall, intrusion detection, network analysis, etc.
[0086] Core switch 110: The core switch 110 provides high-speed forwarding for packets entering and leaving the data center, and provides connectivity for the aggregation switch 120. The network of the entire data center is divided into an L3 layer routing network and an L2 layer routing network. The core switch 110 generally provides a flexible L3 layer routing network for the network of the entire data center.
[0087] Generally, the aggregation switch 120 is the demarcation point between the L2 and L3 layer routing networks. The network below the aggregation switch 120 is the L2 network, and the network above is the L3 network. Each group of aggregation switches manages a delivery point (POD), and each POD has an independent VLAN network. The server does not need to modify the IP address and default gateway when migrating within the POD, because one POD corresponds to one L2 broadcast domain.
[0088] The spanning tree protocol (STP) is usually used between the aggregation switch 120 and the access switch 130. STP makes only one aggregation layer switch 120 available for a VLAN network, and other aggregation switches 120 are used only when a failure occurs. In other words, horizontal expansion cannot be achieved at the aggregation switch 120 level, because even if multiple aggregation switches 120 are added, only one is still working.
[0089] server
[0090] Figure 2 Show Figure 1 A schematic block diagram of a server 140. Figure 2 As shown, the server 140 according to the embodiment of the present invention may include one or more processors 12 , a memory 14 , an L1 cache 16 , an L2 cache 15 , and a TCM 17 .
[0091] The memory 14 can be a main memory (abbreviated as main memory or internal memory), which is used to store instruction information and / or data information represented by data signals, such as storing data provided by the processor 12 (such as calculation results), and can also be used to realize data exchange between the processor 12 and an external storage device (or called auxiliary memory or external memory).
[0092] In some cases, the processor 12 may need to access the memory 14 to obtain data in the memory 14 or modify the data in the memory 14. Since the access speed of the memory 14 is slow, in order to alleviate the speed difference between the processor 12 and the memory 14, the computer system 10 also includes a cache coupled to the bus 18, namely, an L1 cache 16 and an L2 cache 15. The cache is used to cache some data such as program data or message data in the memory 14 that may be repeatedly called. The cache can be a storage device of the type of static random access memory (abbreviated as SRAM). Figure 2 The cache is divided into a hierarchical structure of L1 cache 16 and L2 cache 15, but in fact it can also be a cache structure of more than three levels or other types of cache structures. Figure 2 Although L1 cache 16 and L2 cache 15 are shown to be external to processor 12 , they may actually be internal to processor 12 .
[0093] The tightly coupled memory (TCM) 17 is tightly coupled to the processor core, providing a parallel access space. There are multiple banks in the tightly coupled memory (TCM) 17, and different banks can be accessed in parallel, thereby improving access efficiency. The L1 cache 16 and the L2 cache 15 cannot be accessed in parallel. Therefore, when storing data that needs to be accessed in parallel, it can be placed in the TCM 17. The excitation vector in the embodiment of the present disclosure needs to be accessed in parallel to improve the efficiency of multiplication operations with sparse matrices, so it is placed in the TCM 17.
[0094] The information exchange between the memory 14 and the cache (L1 cache 16 and L2 cache 15) is usually organized in blocks. In some embodiments, the cache and the memory 14 can be divided into data blocks according to the same spatial size, and the data block can be used as the minimum unit of data exchange between the cache and the memory 14 (including one or more data of a preset length). For the sake of simplicity and clarity, each data block in the cache is referred to as a cache block, and different cache blocks have different cache block addresses; each data block in the memory 14 is referred to as a memory block, and different memory blocks have different memory block addresses. The cache block address, for example, includes a physical address tag for locating the data block.
[0095] Due to space and resource limitations, the cache cannot cache all the contents in the memory 14, that is, the storage capacity of the cache is usually smaller than the memory 14, and the cache block addresses provided by the cache cannot correspond to all the memory block addresses provided by the memory 14. When the processor 12 needs to access the memory, it first accesses the cache via the bus 18 to determine whether the content to be accessed has been stored in the cache. If so, the cache hits, and the processor 12 directly calls the content to be accessed from the cache. If the content that the processor 12 needs to access is not in the cache, the processor 12 needs to access the memory 14 via the bus 11 to find the corresponding information in the memory 14. Because the access rate of the cache is very fast, when the cache hits, the efficiency of the processor 12 can be significantly improved, thereby improving the performance and efficiency of the entire server 140.
[0096] processor
[0097] like Figure 2 As shown, each processor 12 may include one or more processor cores 120 for processing instructions, and the processing and execution of instructions may be controlled by a user (e.g., through an application) and / or a system platform. In some embodiments, each processor core 120 may be used to process a specific instruction set. In some embodiments, the instruction set may support complex instruction set computing (CISC), reduced instruction set computing (RISC), or very long instruction word (VLIW)-based computing. Different processor cores 120 may each process different or the same instruction sets. In some embodiments, the processor core 120 may also include other processing modules, such as a digital signal processor (DSP), etc. As an example, Figure 2 , processor cores 1 to m are shown, where m is a non-zero natural number.
[0098] In some embodiments, Figure 2 As shown, the processor 12 may include a register file 126 (Register File), and the register file 126 may include multiple registers for storing different types of data and / or instructions, and these registers may be of different types. For example, the register file 126 may include: integer registers, floating point registers, status registers, instruction registers, and pointer registers. The registers in the register file 126 may be implemented by selecting general registers, or may adopt a specific design according to the actual needs of the processor 12.
[0099] The processor 12 may include a memory management unit (MMU) 122 for implementing the translation of virtual addresses to physical addresses. The memory management unit 122 caches some entries in the page table, and the memory management unit 122 may also obtain uncached entries from the memory. One or more memory management units 122 may be set in each processor core 120, and the memory management units 120 in different processor cores 120 may also be synchronized with the memory management units 120 in other processors or processor cores, so that each processor or processor core can share a unified virtual storage system.
[0100] The processor 12 is used to execute the instruction sequence (i.e., program). The process of the processor 12 executing each instruction includes: fetching the instruction from the memory storing the instruction, decoding the fetched instruction, executing the decoded instruction, saving the instruction execution result, etc., and the cycle continues until all the instructions in the instruction sequence are executed or a shutdown instruction is encountered.
[0101] To implement the above process, the processor 12 may include an instruction fetch unit 124 , an instruction decoding unit 125 , an instruction issuing unit (not shown), an instruction execution unit 121 , an instruction retirement unit (not shown), and the like.
[0102] The instruction fetch unit 124 acts as the startup engine of the processor 12 and is used to transfer instructions from the memory 14 to the instruction register (which may be Figure 2 A register in the register file 26 shown is used to store instructions) and receives the next instruction fetch address or calculates the next instruction fetch address according to an instruction fetch algorithm. The instruction fetch algorithm includes, for example, increasing or decreasing the address according to the instruction length.
[0103] After fetching the instruction, the processor 12 enters the instruction decoding stage, and the instruction decoding unit 125 decodes the fetched instruction according to the predetermined instruction format to obtain the operand acquisition information required by the fetched instruction, thereby preparing for the operation of the instruction execution unit 121. The operand acquisition information, for example, points to an immediate number, a register, or other software / hardware that can provide a source operand.
[0104] The instruction issuing unit is usually present in a high-performance processor 12, located between the instruction decoding unit 125 and the instruction execution unit 121, and is used for scheduling and controlling instructions to efficiently allocate each instruction to different instruction execution units 121, so that the parallel operation of multiple instructions becomes possible. After the instruction is fetched, decoded and scheduled to the corresponding instruction execution unit 121, the corresponding instruction execution unit 121 starts to execute the instruction, that is, to execute the operation indicated by the instruction and realize the corresponding function.
[0105] The instruction retirement unit (or instruction write back unit) is mainly responsible for writing the execution results generated by the instruction execution unit 121 back to the corresponding storage location (for example, the register inside the processor 12), so that subsequent instructions can quickly obtain the corresponding execution results from the storage location.
[0106] For different types of instructions, different instruction execution units 121 can be set accordingly in the processor 12. The instruction execution unit 121 can be an operation unit (for example, including an arithmetic logic unit, a vector operation unit, etc., for performing operations according to operands and outputting operation results, which is the execution subject of the multiplication of the sparse matrix and the vector to be multiplied in the embodiment of the present disclosure), a memory execution unit (for example, for accessing the memory according to the instruction to read the data in the memory or write the specified data to the memory, etc.) and a coprocessor, etc. In the processor 12, each instruction execution unit 121 can run in parallel and output the corresponding execution results.
[0107] When executing a certain type of instruction (eg, memory access instruction), the instruction execution unit 121 needs to access the memory 14 to obtain information stored in the memory 14 or provide data that needs to be written into the memory 14 .
[0108] The instruction execution unit 121 for executing memory access instructions may also be referred to as a memory execution unit, which may be, for example, a load store unit (LSU) and / or other units for memory access.
[0109] After the memory access instruction is fetched by the instruction fetch unit 124, the instruction decoding unit 125 can decode the memory access instruction so that the source operand of the memory access instruction can be obtained. The decoded memory access instruction is provided to the corresponding instruction execution unit 121, and the instruction execution unit 121 can perform corresponding operations on the source operand of the memory access instruction (for example, the arithmetic logic unit performs operations on the source operand stored in the register) to obtain the address information corresponding to the memory access instruction, and initiate corresponding requests according to the address information, such as address translation requests, write access requests, etc.
[0110] The source operand of the memory access instruction usually includes an address operand, and the instruction execution unit 121 operates on the address operand to obtain the virtual address or physical address corresponding to the memory access instruction. When the memory management unit 122 is disabled, the instruction execution unit 121 can directly obtain the physical address of the memory access instruction through logical operations. When the memory management unit 121 is enabled, the corresponding instruction execution unit 121 initiates an address translation request according to the virtual address corresponding to the memory access instruction, and the address translation request includes the virtual address corresponding to the address operand of the memory access instruction; the memory management unit 122 responds to the address translation request, and converts the virtual address in the address translation request into a physical address according to the table entry matching the virtual address, so that the instruction execution unit 121 can access the cache and / or memory 14 according to the translated physical address.
[0111] Depending on the function, the memory access instruction may include a load instruction and a store instruction. The execution process of the load instruction usually does not require modification of the information in the memory 14 or the cache. The instruction execution unit 121 only needs to read the data stored in the memory 14, the cache or the external storage device according to the address operand of the load instruction.
[0112] Different from the load instruction, the source operand of the store instruction includes not only the address operand but also the data information, and the execution process of the store instruction usually requires the memory 14 and / or the cache to be modified. The data information of the store instruction can point to the write data, and the source of the write data can be the execution result of the operation instruction, the load instruction and other instructions, or the data provided by the register or other storage unit in the processor 12, or the immediate value.
[0113] General Overview of the Disclosure
[0114] As mentioned above, the multiplication of weight matrix and excitation vector is often used in deep neural network (the multiplication of weight matrix and excitation matrix can be transformed into the multiplication of weight matrix and excitation vectors). Usually, the weight matrix is pruned to obtain a sparse matrix. In the prior art, in the process of multiplying the sparse weight matrix and the excitation vector, generally three loads are required, corresponding to three load instructions.
[0115] The first load instruction loads the unpruned weight values (weight values that are not 0) from the sparse weight matrix. For pruned element values of 0, they do not need to participate in the calculation and do not need to be loaded. Therefore, the first load instruction needs to include the starting storage address of the unpruned element value in the memory 14. After the instruction fetch unit 124 takes out the instruction from the memory 14, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121, which is the computing unit of the embodiment of the present disclosure, for execution. The instruction execution unit 121 loads the unpruned weight values in the sparse weight matrix from the memory 14 according to the address and places them in the cache (e.g., L2 cache 15).
[0116] The second load instruction loads the indices of the unpruned weights (the indices of the weights that are not 0) from the sparse weight matrix. These indices are the indices of the valid elements in the excitation vector that need to participate in the operation. The elements at the indices at other positions in the excitation vector need to be multiplied by the weight of 0, so it is meaningless. The second load instruction needs to include the starting storage address of the unpruned weight index in the sparse weight matrix in the memory 14. After the instruction fetch unit 124 takes out the instruction from the memory 14, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction execution unit 121 loads the unpruned weight index in the sparse weight matrix from the memory 14 according to the address and places it in the cache (for example, the L2 cache 15).
[0117] The third load instruction loads the elements corresponding to these indexes in the excitation vector according to the unpruned weight indexes in the cache (e.g., L2 cache 15), and the loaded elements are the elements in the excitation vector to be multiplied by the weights loaded by the first load instruction. The third load instruction needs to include the starting storage address of the excitation vector and the address of the register in the processor 12 (e.g., a register in the register file 126) where the elements loaded from the excitation vector need to be stored back. After the instruction fetch unit 124 fetches the instruction from the memory 14, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction execution unit 121 accumulates the starting storage address of the excitation vector and the unpruned weight index to obtain the addresses of the valid elements in the excitation vector, loads the valid elements from these addresses, and stores these valid elements back to the addresses of the registers in the processor 12 specified in the instruction.
[0118] Then, the instruction execution unit 121 multiplies the unpruned weight value obtained by executing the first load instruction and the valid element obtained by the third load instruction and accumulates them to obtain the multiplication result of the sparse weight matrix and the excitation vector.
[0119] Since the above three loads require three different instructions, frequent instruction fetching and decoding are required, which results in high processing overhead and slow speed. However, modern processing units, especially low-power processing units, usually have limited instruction fetch width, and the cache space used for loading is insufficient. In the disclosed embodiment, for the above last two load instructions, an index and valid element load instruction are used to execute. The following is an example of the instruction:
[0120] LoadGatherFused pg,Destaddr,Addr 1,Addr 2
[0121] The above-mentioned Addr 1 is the first source address, which is used to indicate the storage address of the index of the unpruned element (such as the weight in the weight matrix); Addr 2 is the second source address, which is used to indicate the storage address of the vector to be multiplied (such as the excitation vector); Destaddr is the destination address, which is used to indicate the address of the vector back to which the valid elements loaded from the vector to be multiplied (such as the excitation vector) are stored. Pg is a control parameter used to indicate how many bits in the vector used in the embodiment of the present disclosure are valid. For example, the excitation vector has 24 bits, and only the first 16 bits may be valid, indicating the excitation value. The last 8 bits may be invalid, do not represent the excitation value, and can be set to 0, etc. The administrator can intervene in the number of valid bits of the vector through pg.
[0122] After the instruction fetching unit 124 fetches the instruction from the memory 14, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction execution unit 121 loads the index of the unpruned elements in the sparse matrix from the memory 14 according to the first source address Addr 1, and loads the valid elements corresponding to the index of these unpruned elements from the vector to be multiplied according to the second source address Addr 2 and the sum address of the above index, and then stores the obtained vector of valid elements back according to the destination address Destaddr. Through such an instruction, the purpose of executing the latter two of the three loads mentioned above at the same time is achieved. Compared with the prior art that performs loading with three instructions, the embodiment disclosed in the present invention uses two instructions to perform loading, which improves the operation efficiency of the multiplication operation of the sparse matrix and the vector to be multiplied and reduces the operation overhead.
[0123] Detailed implementation process of the basic embodiment of the present disclosure
[0124] like Figure 3 As shown, the instruction execution unit 121, which is a computing unit of an embodiment of the present disclosure, includes an instruction cache unit 210, an unpruned element index reading unit 220, a valid element reading unit 230, a storage back unit 240, an unpruned element value reading unit 250, and a multiplication result vector acquisition unit 260.
[0125] Combine the following Figure 5AThe implementation process according to a basic embodiment of the present disclosure is described.
[0126] Figure 5A In the example, the sparse matrix can be a sparse weight matrix, and the vector to be multiplied is an excitation vector. The sparse weight matrix is a matrix with several rows and 24 columns, each row has 24 elements, and its indexes are represented by indexes 0, 1, 2...23, respectively. The thick-lined frame represents the unpruned elements, that is, the elements that are not 0, and the thin-lined frame represents the pruned elements, that is, the elements that are 0. The vector to be multiplied is a vector of 24 elements, and its indexes are also 0, 1, 2...23, which correspond one to one with the row index of the sparse weight matrix. Multiply the vector to be multiplied with the row vector of the first row of the sparse weight matrix to obtain the first element of the multiplication result vector, that is, the element with index 0. Since only 4 elements in the first row of the sparse weight matrix are not 0, as long as these 4 elements are multiplied and accumulated with the elements at the corresponding index positions in the vector to be multiplied, the element with index 0 of the multiplication result vector is obtained. The elements in the first row that are 0 are multiplied by the elements at the corresponding index position in the vector to be multiplied, which still equals 0, and has no effect on the result. Similarly, the 4 non-0 elements in the second row of the sparse weight matrix are multiplied and accumulated by the elements at the corresponding index position in the vector to be multiplied, and the element at index 1 of the multiplication result vector is obtained. And so on, the final multiplication result vector is obtained.
[0127] In this basic embodiment, first, the instruction fetch unit 124 fetches an unpruned element value load instruction from the memory 14. The unpruned element value load instruction is an instruction for obtaining the unpruned element value in the sparse matrix. Figure 5A As shown, in the first row of the sparse matrix, the element values of indexes 0, 2, 4, and 9 are not pruned, that is, not 0, and the unpruned element value load instruction obtains the element values of these elements. The unpruned element value load instruction includes a third source address, and the third source address represents the starting storage address of the unpruned element value. In the memory 14, the element values of 0, 2, 4, and 9 are stored continuously. When the third source address, that is, the starting address at which they are stored in the memory 14, is obtained, they can be loaded sequentially. After the instruction fetch unit 124 fetches the unpruned element value load instruction, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction cache unit 210 of the instruction execution unit 121 receives the unpruned element value load instruction. The unpruned element value reading unit 220 reads the unpruned element value from the memory 14 according to the third source address in the unpruned element value load instruction and places it in the cache (e.g., L2 cache 15).
[0128] Then, the instruction fetch unit 124 fetches the index and valid element load instruction from the memory 14. The index and valid element load instruction is an instruction to obtain the valid element vector corresponding to the unpruned element in the sparse matrix from the vector to be multiplied. In this embodiment, the vector to be multiplied is stored in the memory 14. Figure 5A As shown, in the first row of the sparse matrix, the element values of indexes 0, 2, 4, and 9 are not pruned, so in the vector to be multiplied, the elements of indexes 0, 2, 4, and 9 must also be taken out as valid element vectors. As shown above, the index and valid element loading instructions are LoadGatherFused pg, Destaddr, Addr 1, Addr2. The first source address Addr 1 represents the starting storage address of the unpruned element index in the sparse matrix. Figure 5A In the first row of the sparse matrix, the unpruned element indexes are indexes 0, 2, 4, and 9. They are stored in consecutive locations in the memory 14, but the locations are different from the locations where the unpruned element values are stored. The first source address Addr 1 represents their starting storage address. The second source address Addr 2 represents the starting storage address of the vector to be multiplied on the memory 14. The destination address Destaddr represents the address in the register file 126 of the processor 12 where the valid element vector is to be stored back.
[0129] After the instruction fetch unit 124 fetches the index and the valid element load instruction, the instruction decoding unit 125 decodes the instruction and sends it to the instruction execution unit 121 for execution. The instruction cache unit 210 of the instruction execution unit 121 receives the index and the valid element load instruction. The unpruned element index reading unit 220 reads the unpruned element index according to the index and the first source address in the valid element load instruction, for example Figure 5A The unpruned element indices 0, 2, 4, 9 in the first row of the sparse matrix are placed in a cache (e.g., L2 cache 15). Then, the valid element reading unit 230 adds the second source address placed in the cache and the read unpruned element index (e.g., 0, 2, 4, 9 in the above example) to obtain the specific address of the valid element to be loaded and multiplied with the unpruned element in the sparse matrix, wherein the second source address reflects the address of the first element of the vector to be multiplied, and the above index is equivalent to the offset on this basis, and the two are added to obtain the specific address of each valid element. Then, the valid element reading unit 230 reads the valid element to be multiplied with the unpruned element according to the sum address, such as Figure 5A The storage unit 240 assembles the valid elements (e.g., the elements of indexes 0, 2, 4, 9 of the vector to be multiplied in the above example) into a valid element vector and stores it in the register file 126 of the processor 12 according to the destination address.
[0130] Then, the instruction fetch unit 124 fetches the vector multiplication instruction from the memory 14. The vector multiplication instruction is used to obtain a multiplication result vector of the sparse matrix and the vector to be multiplied based on the unpruned element value obtained by the unpruned element value load instruction and the effective element vector obtained by the second instruction. The multiplication result vector acquisition unit 260 executes the above-mentioned vector multiplication instruction. The specific method can be to synthesize the unpruned element value obtained by the unpruned element value load instruction into an unpruned element value vector, and multiply it with the effective element vector to obtain an element of the multiplication result vector. For example, assuming that in the above example, the element values of the indexes 0, 2, 4, and 9 of the first row of the sparse matrix are 0.5, 1, 2, and 3 respectively, and the effective element vector is (2, 2, 1, 4), then the first element of the multiplication result vector is 0.5×2+1×2+2×1+3×4=1+2+2+12=17. The vector of the unpruned element values of the second row of the sparse matrix is multiplied by the valid element vector extracted according to the unpruned element index of the second row of the sparse matrix to obtain the second element of the multiplication result vector, and so on.
[0131] Through the above process, the multiplication of the sparse matrix and the vector to be multiplied is completed. In addition to the last vector multiplication instruction, two load instructions are used, which improves the operation efficiency and reduces the processing overhead compared with the prior art that uses three load instructions.
[0132] The present disclosure is combined with a detailed description of an embodiment of the TCM 17
[0133] Figure 5A In the embodiment of , when loading valid elements from the vector to be multiplied according to the unpruned element index of the sparse matrix, only one valid element can be loaded per clock cycle. Figure 5A In cycle 1, the element of index 0 of the vector to be multiplied is loaded according to index 0, the element of index 2 of the vector to be multiplied is loaded according to index 2 in cycle 2, the element of index 4 of the vector to be multiplied is loaded according to index 4 in cycle 3, and the element of index 9 of the vector to be multiplied is loaded according to index 9 in cycle 4. This is because the vector to be multiplied is stored in the memory 14, which does not support simultaneous access to multiple elements in the vector.
[0134] Tightly coupled memory (TCM) 17 can support simultaneous access to multiple elements in a vector. TCM 17 is divided into multiple memory banks, and different memory banks can be accessed in parallel, thereby improving access efficiency. Figure 5B In the embodiment of FIG. 1 , the vector to be multiplied is stored in TCM 17. The elements of the vector to be multiplied may be stored in a plurality of memory banks 171 in a dispersed manner, such as Figure 4 In this case, if multiple elements to be accessed simultaneously are in different storage bodies 171, these multiple elements can be loaded simultaneously.
[0135] exist Figure 4In the example, the elements A[0], A[4], A[8], A
[12] of the indexes 0, 4, 8, 12 of the vectors to be multiplied are stored in memory bank 0, and their indexes are characterized by a remainder modulo 4 of 0. The elements A[1], A[5], A[9], A
[13] of the indexes 1, 5, 9, 13 of the vectors to be multiplied are stored in memory bank 1, and their indexes are characterized by a remainder modulo 4 of 1. The elements A[2], A[6], A
[10] , A
[14] of the indexes 2, 6, 10, 14 of the vectors to be multiplied are stored in memory bank 2, and their indexes are characterized by a remainder modulo 4 of 2. The elements A[3], A[7], A
[11] , A
[15] of the indexes 3, 7, 11, 15 of the vectors to be multiplied are stored in memory bank 3, and their indexes are characterized by a remainder modulo 4 of 3. It can be seen that in this embodiment, the remainder after the index of the element is modulo the total number of memory banks 171 is the index of the memory bank 171 where the element is stored. The above distribution of the elements of the vector to be multiplied in each memory bank is only an example, and there may be other distribution methods.
[0136] Correspondingly, the unpruned element indexes in the sparse matrix can be stored in groups, and the number of indexes in the group is less than or equal to the total number of storage bodies 171 in TCM 17, and it is ensured that different indexes in the same group correspond to different storage bodies 171 of TCM 17. Figure 5B The group 0 of contains 4 indexes 0, 2, 5, 7, whose modulo 4 remainders are 0, 2, 1, 3, respectively, corresponding to four different storage banks 171. In this way, when loading valid elements from the vector to be multiplied according to these 4 indexes, the corresponding 4 valid elements are located in 4 different storage banks 171, and valid elements can be taken from the 4 storage banks 171 in parallel to form a valid element vector. Similarly, the group 1 contains 4 indexes 2, 3, 0, 5, whose modulo 4 remainders are 2, 3, 0, 1, respectively, corresponding to four different storage banks 171, and so on.
[0137] In addition, a single group may contain the index of an unpruned element taken from each of a plurality of rows in the sparse matrix, the number of rows of the plurality of rows being equal to the total number of memory banks 171 in TCM 17. For example, in the above example, the total number of memory banks 171 in TCM 17 is 4, so the index of an unpruned element may be taken from each of the 4 rows in the sparse matrix, and when taking the indexes, it is important to make sure that the indexes correspond to different memory banks 171 in TCM 17. For example, in Figure 5B In the sparse matrix, the first row takes index 0, the second row takes index 2, the third row takes index 5, and the fourth row takes index 7. Their remainders modulo 4 are different, corresponding to the indices of four different storage bodies 171, and so on.
[0138] In this way, Figure 5BAs shown, when loading the index of the unpruned element from the sparse matrix, the index of the unpruned element of a row is no longer loaded, but the group of indexes formed as above is loaded. After loading the valid elements from the vector to be multiplied according to the group of indexes, the unpruned element values corresponding to each index are multiplied with the corresponding valid elements, and the accumulated product obtained is in the element corresponding to the index of the multiplication result vector. As the above operation proceeds, each element of the multiplication result vector continuously adds the accumulated product of the corresponding row to the corresponding element, that is, each element of the multiplication result vector continuously accumulates the newly generated product as the above operation proceeds. The accumulated product of the unpruned element taken from the first row of the sparse array and the corresponding valid element is in the first element of the multiplication result vector. The accumulated product of the unpruned element taken from the second row of the sparse array and the corresponding valid element is in the second element of the multiplication result vector, and so on.
[0139] Combine the following Fig. 6A -F describes the specific implementation process of the above embodiment.
[0140] Figure 5B In the embodiment of, first, the instruction fetch unit 124 fetches an unpruned element value load instruction from the memory 14. The unpruned element value load instruction is an instruction for obtaining the unpruned element value in the sparse matrix. The unpruned element value load instruction includes a third source address, and the third source address represents the starting storage address of the unpruned element value in the memory 14. Figure 5B In the example, since the index 0 of the first row, the index 2 of the second row, the index 5 of the third row, and the index 7 of the fourth row of the sparse matrix together form group 0, the element value of index 0 of the first row, the element value of index 2 of the second row, the element value of index 5 of the third row, and the element value of index 7 of the fourth row are also stored together continuously; similarly, corresponding to group 2, the element value of index 2 of the first row, the element value of index 3 of the second row, the element value of index 0 of the third row, and the element value of index 5 of the fourth row are also stored together continuously, and so on. In the above example, the third source address represents the address of index 0 of the first row in memory 14.
[0141] After the instruction fetching unit 124 fetches the unpruned element value load instruction, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction cache unit 210 of the instruction execution unit 121 receives the unpruned element value load instruction. The unpruned element value reading unit 220 sequentially fetches multiple rows of unpruned element values according to the row index according to the third source address in the unpruned element value load instruction, and the number of the multiple rows is equal to the number of storage banks in the TCM 17. Figure 5B In the embodiment of FIG. 1 , the number of memory banks in TCM 17 is 4, so 4 rows of unpruned element values can be fetched each time. The first time, the unpruned element values of rows 0-3 are fetched. The second time, the unpruned element values of rows 4-7 are fetched, and so on. Fig. 6AThe unpruned element values of the first four rows taken out are shown, where the boxes with values represent unpruned elements, and the blank boxes represent pruned elements, that is, elements with a value of 0. In fact, the order in which they are stored in the memory 14 is not row by row, but is stored in the order of index groups as described above. The element value of index 0 of the first row, the element value of index 2 of the second row, the element value of index 5 of the third row, and the element value of index 7 of the fourth row are stored in the first row, followed by the element value of index 2 of the first row, the element value of index 3 of the second row, the element value of index 0 of the third row, the element value of index 5 of the fourth row, and so on. The unpruned element value reading unit 220 determines the first unpruned element value to be read according to the third source address, and then sequentially reads the element values of each index of each index group of the number of rows of the storage body.
[0142] Then, the instruction fetch unit 124 fetches the index and valid element load instruction from the memory 14. The index and valid element load instruction is an instruction to obtain the valid element vector corresponding to the unpruned element in the sparse matrix from the vector to be multiplied, that is, the above-mentioned LoadGatherFused pg, Destaddr, Addr 1, Addr 2. The first source address Addr 1 represents the starting storage address of the unpruned element index in the sparse matrix. The unpruned element index is based on Figure 6B The first source address is the address of the first index of group 0. Since the indexes of these groups are stored in sequence, the subsequent indexes can be obtained in sequence according to the first source address Address 1. The second source address Addr 2 represents the starting storage address of the vector to be multiplied on the memory 14. The destination address Destaddr represents the address in the register stack 126 of the processor 12 where the valid element vector is to be stored back.
[0143] After the instruction fetch unit 124 fetches the index and valid element load instruction, it is decoded by the instruction decoding unit 125 and handed over to the instruction execution unit 121 for execution. The instruction cache unit 210 of the instruction execution unit 121 receives the index and valid element load instruction. The unpruned element index reading unit 220 starts from the first source address in the index and valid element load instruction, reads a group of unpruned element indexes, and updates the first source address with the sum of the first source address and the length of a group. In this way, when the second instruction is executed next time, the unpruned element index of the next group is read until all groups are read. For example, in Figure 6B In the process, the index of group 0 is first read and placed in the cache (eg, L2 cache 15).
[0144] Then, the effective element reading unit 230 adds the second source address placed in the cache and the read unpruned element index (such as index 0, 2, 5, 7 in group 0) to obtain the specific address of the effective element to be loaded and multiplied with the unpruned element in the sparse matrix. Figure 6C As shown, the effective element reading unit 230 reads the effective element multiplied with the unpruned element according to the sum address, such as Figure 6C The elements of index 0, 2, 5, 7 of the vector to be multiplied are 1.5, 0.4, 0.8, 3.0.
[0145] The storage unit 240 assembles the valid elements (such as the elements of indexes 0, 2, 5, and 7 of the vector to be multiplied in the above example) into a valid element vector, such as Fig.6D The vector is stored in the register file 126 of the processor 12 according to the destination address. The storage back unit 240 can assemble the valid elements into a vector in a cache (such as an L2 cache 15), and move them back from the cache according to the destination address to the register of the processor 12 where the instruction execution unit 121 is located. The storage back unit 240 can also assemble the valid elements into a vector in the TCM 17, and move them back from the TCM17 according to the destination address to the register of the processor 12 where the instruction execution unit 121 is located.
[0146] Then, the instruction fetch unit 124 fetches a vector multiplication instruction from the memory 14. The vector multiplication instruction is used to obtain a multiplication result vector of the sparse matrix and the vector to be multiplied based on the unpruned element value obtained by the unpruned element value load instruction and the index and the effective element vector obtained by the effective element load instruction. The multiplication result vector acquisition unit 260 executes the above-mentioned vector multiplication instruction. Specifically, the unpruned element value and index obtained by the unpruned element value load instruction and the effective element corresponding to the unpruned element index obtained by the effective element load instruction are multiplied, and the resultant accumulation is accumulated on the element corresponding to the sparse matrix row from which the unpruned element comes in the multiplication result vector. For example, the accumulation of the unpruned element taken from the first row of the sparse array and the corresponding effective element is accumulated on the first element of the multiplication result vector. The accumulation of the unpruned element taken from the second row of the sparse array and the corresponding effective element is accumulated on the second element of the multiplication result vector, and so on. For example, Fig. 6E The unpruned element values of index group 0 obtained by the unpruned element value load instruction are 0.5, 0.3, 1.6, and 1.9. Fig. 6E The first element of 0.5 is multiplied by Fig.6D The first element of 1.5 is 0.75, which is accumulated to Fig. 6F The first element of the multiplication result vector (this is due to Fig. 6E The first element 0.5 is taken from the first row of the sparse matrix). Fig. 6EThe second element of 0.3 is multiplied by Fig.6D The second element of 0.4 is 0.12, which is accumulated to Fig. 6F The second element of the multiplication result vector (this is due to Fig. 6E The second element 0.3 is taken from the second row of the sparse matrix), and so on.
[0147] Through the above process, the multiplication of the sparse matrix and the vector to be multiplied is completed. In addition to the last vector multiplication instruction, the above process uses two load instructions, which improves the operation efficiency and reduces the processing overhead compared with the three load instructions in the prior art. At the same time, since the vector to be multiplied is stored in multiple storage bodies 171 of TCM 17, and the unpruned element indexes in the sparse matrix are stored in groups, the indexes in each group correspond to different storage bodies of TCM 17. In this way, when loading the corresponding valid elements in the vector to be multiplied according to the multiple indexes in each group, it can be executed in parallel in one cycle (such as Figure 5B , loading valid elements according to index 0, 2, 5, and 7 can all be executed in cycle 1), further improving the computational efficiency.
[0148] The addressing mode that can be adopted by the embodiment of the present disclosure
[0149] like Figure 7 As shown, the above index and valid element loading instruction LoadGatherFused pg,Destaddr,Addr1,Addr2 can have different transformations.
[0150] In one embodiment, the above-mentioned index and valid element loading instruction can be written as LoadGatherFused pg, Destaddr, Base 1, Base 2. That is, the first source address is represented by the first base source address Base1, and the second source address is represented by the second base source address Base 2. The base address is the address used as the basis. In addressing, a certain address to be found may differ from the base address by an offset, so it can be addressed in the manner of adding the base address to the offset. In the absence of an offset, it can be addressed only according to the base address. For LoadGatherFused pg, Destaddr, Base 1, Base 2, the unpruned element index reading unit 220 reads the unpruned element index according to the first base source address Base 1, and the valid element reading unit 230 reads the valid element according to the sum address of the second base source address Base 2 and the read unpruned element index.
[0151] In one embodiment, the above-mentioned index and valid element loading instruction can be written as LoadGatherFused pg, Destaddr, Base 1, Imm 1, Base 2, Imm 2. That is, the address to be addressed is represented by the base address and the offset represented by the immediate number. The first source address is represented by the sum address of the first base source address Base 1 plus the first immediate number Imm 1, and the second source address is represented by the sum address of the second base source address Base 2 plus the second immediate number Imm 2. For LoadGatherFusedpg, Destaddr, Base 1, Imm 1, Base 2, Imm 2, the unpruned element index reading unit 220 reads the unpruned element index according to the sum address of the first base source address Base 1 plus the first immediate number Imm 1, and the valid element reading unit 230 reads the valid element according to the sum address of the second base source address Base 2, the second immediate number Imm 2 and the read unpruned element index.
[0152] In one embodiment, the above index and valid element load instruction can be written as LoadGatherFused pg, Destaddr, Base 1, N1, Base 2, N2. It still uses the base address and offset to represent the address to be addressed, but it determines the offset by multiplying the first coefficient by the vector length by the element size. The vector length is the number of elements included in the vector. Generally, the system automatically configures it. After configuration, the number of elements in the row vector of the excitation vector and the sparse matrix is the vector length. Figure 5A In the example, the vector length is 24 elements. The element size generally refers to the number of bytes occupied by an element. In most cases, the element size is 2 bytes. In this embodiment, the first source address is equal to Base 1+N1*Wlength*Elesize, where Base 1 is the first base source address, N1 is the first coefficient, Wlength is the vector length, and Elesize is the element size. The second source address is equal to Base 2+N2*Wlength*Elesize, where Base 2 is the second base source address and N2 is the second coefficient. For the above-mentioned index and valid element load instructions, the unpruned element index reading unit 220 reads the unpruned element index according to the address of Base 1+N1*Wlength*Elesize, and the valid element reading unit 230 reads the valid element according to the sum address of Base 2+N2*Wlength*Elesize and the read unpruned element index.
[0153] In one embodiment, the above-mentioned index and valid element loading instruction can be written as LoadGatherFused pg, Destaddr, Base 1, N3, Base 2, N4. It also uses the base address and the offset to represent the address to be addressed. It determines the offset by multiplying the first coefficient by the element size. In this embodiment, the first source address is equal to Base 1+N3*Elesize, where Base 1 is the first base source address, N3 is the third coefficient, and Elesize is the element size. The second source address is equal to Base 2+N4*Elesize, where Base 2 is the second base source address, and N4 is the fourth coefficient. For the above-mentioned second instruction, the unpruned element index reading unit 220 reads the unpruned element index according to the address of Base 1+N3*Elesize, and the valid element reading unit 230 reads the valid element according to the sum address of Base 2+N4*Elesize and the read unpruned element index.
[0154] The design of the above-mentioned multiple indexes and valid element load instructions improves the flexibility of addressing according to the indexes and valid element load instructions in the embodiments of the present disclosure.
[0155] Effect evaluation data and commercial value
[0156] In order to evaluate the effect of the embodiment of the present disclosure, the simulator GEM 5 with ARM SVE SIMD extension is used for simulation, where SIMD refers to single instruction multiple data stream, that is, a set of instruction sets that can copy multiple operands and pack them in large registers. The second instruction proposed in the embodiment of the present disclosure runs in the environment of the above-mentioned GEM 5 and GCC compiler. The embodiment of the present disclosure is configured according to the vector length of ARM v8.2a, with 8 elements per vector and 2 bytes (16 bits) per element. Two CPU models are used in the experiment, one is the MINOR model, which has low power consumption but relatively poor performance; the other is the O3 model, which has high performance but high power consumption. TCM with 8 storage bodies is used. On the one hand, the sparse matrix uses sparse matrices of synthetic data with sparsity of 0, 0.25, and 0.5 respectively, and on the other hand, the sparse matrix uses sparse matrices of real data. In real data, the probability of weight being 0 is 10%, so the sparsity is 0.9.
[0157] The final experimental results are as follows Figure 8 shown. Figure 88 histograms are shown respectively when the CPU adopts the MINOR model and the O3 model in four cases of sparsity of 0, 0.25, 0.5, and 0.9 (real data). Each group of histograms includes 2 histograms. The histogram on the left represents the number of clock cycles used to calculate the product of the sparse matrix and the vector to be multiplied in the prior art, and the histogram on the right represents the number of clock cycles used to calculate the product of the sparse matrix and the vector to be multiplied in the embodiment of the present disclosure. It can be seen that in the embodiment of the present disclosure, the number of clock cycles used to calculate the product of the sparse matrix and the vector to be multiplied is reduced, so the operation speed is faster, and the operation speed is 1.16 times (CPU adopts O3 model) to 1.39 times (CPU adopts MINOR model) of the existing method. When real data (sparseness = 0.9) is used, the operation speed reaches 1.2 times (CPU adopts O3 model) to 1.47 times (CPU adopts MINOR model) of the existing method. In the process of multiplying a sparse matrix and a vector to be multiplied, three load instructions are compressed into two, which greatly reduces the pressure of instruction fetching and decoding in the process of calculating the product of the sparse matrix and the vector to be multiplied, and is particularly applicable to modern low-power processors with limited instruction fetch width. By applying the embodiments of the present disclosure, it is expected that the market share of low-power processors will be expanded by more than 20%, which has a good market prospect.
[0158] A deep neural network operation method according to an embodiment of the present disclosure
[0159] like Fig. 9 As shown, according to an embodiment of the present disclosure, a method for obtaining a valid element vector is also provided, the method comprising:
[0160] Step 910: receiving an index and valid element load instruction, the index and valid element load instruction is used to obtain the valid element vector, the index and valid element load instruction includes a first source address, a second source address and a destination address, the first source address represents the starting storage address of the unpruned element index in the sparse matrix, the second source address represents the starting storage address of the vector to be multiplied, and the destination address represents the address to which the valid element vector is to be stored back;
[0161] Step 920: read the unpruned element index according to the first source address;
[0162] Step 930: read, according to the second source address and the read unpruned element index, a valid element in the vector to be multiplied for multiplication with the unpruned element in the sparse matrix;
[0163] Step 940: Assemble the valid elements into a valid element vector and store it according to the destination address.
[0164] Optionally, step 930 includes:
[0165] Adding the second source address and the read unpruned element index respectively to obtain the storage address of each valid element;
[0166] The valid element is read according to the storage address.
[0167] Optionally, the elements of the vector to be multiplied are stored in multiple storage bodies in a tightly coupled memory, wherein parallel access to the elements in the multiple storage bodies is allowed; the indices of unpruned elements in the sparse matrix are stored in groups, a single group contains the index of an unpruned element taken from each of multiple rows in the sparse matrix, and different indexes in the same group correspond to different storage bodies of the tightly coupled memory.
[0168] Optionally, the multiple rows are rows of the number of storage bodies of the multiple storage bodies sequentially taken out from the sparse matrix according to row indices.
[0169] Optionally, step 920 includes: starting from the first source address, reading an unpruned element index of a group, and updating the first source address with the sum of the first source address and a length of a group.
[0170] Since the implementation details of the above process have been described in detail in the description of the above device embodiment, they will not be repeated here.
[0171] It should be understood that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the method embodiment, since it is basically similar to the method described in the device and system embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of other embodiments.
[0172] It should be understood that the above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0173] It should be understood that an element described in singular form herein or shown in the drawings as only one does not limit the number of the element to one. In addition, modules or elements described or shown as separate herein may be combined into a single module or element, and modules or elements described or shown as single herein may be split into multiple modules or elements.
[0174] It should also be understood that the terms and expressions used herein are for description only, and one or more embodiments of this specification should not be limited to these terms and expressions. The use of these terms and expressions does not mean to exclude any equivalent features of the illustrations and descriptions (or parts thereof), and it should be recognized that various modifications that may exist should also be included in the scope of the claims. Other modifications, changes and substitutions may also exist. Accordingly, the claims should be deemed to cover all such equivalents.
Claims
1. A computing unit, include: an instruction cache unit, configured to receive an index and valid element load instruction, wherein the index and valid element load instruction is used to obtain a valid element vector corresponding to an unpruned element in the sparse matrix from the vector to be multiplied in the multiplication of the sparse matrix and the vector to be multiplied, wherein the index and valid element load instruction comprises a first source address, a second source address and a destination address, wherein the first source address represents a starting storage address of an index of an unpruned element in the sparse matrix, the second source address represents a starting storage address of the vector to be multiplied, and the destination address represents an address to which the valid element vector is to be stored; an unpruned element index reading unit, configured to read the unpruned element index according to the first source address; An effective element reading unit, configured to read, in the vector to be multiplied, effective elements for multiplying with the unpruned elements in the sparse matrix according to the second source address and the read unpruned element index; The storage unit is used to assemble the valid elements into a valid element vector and store it according to the destination address.
2. The computing unit according to claim 1, in, The valid element reading unit adds the second source address and the read unpruned element index respectively to obtain the storage address of each valid element, and reads the valid element according to the storage address.
3. The computing unit according to claim 1, in, The instruction cache unit is further used to receive an unpruned element value load instruction, wherein the unpruned element value load instruction obtains an unpruned element value in the sparse matrix in the multiplication of the sparse matrix and the vector to be multiplied, and the unpruned element value load instruction includes a third source address, and the third source address represents a starting storage address of the unpruned element value; The computing unit also includes: An unpruned element value reading unit is used to read the unpruned element value according to the third source address.
4. The computing unit according to claim 2, in, The instruction cache unit is further used to receive a vector multiplication instruction, wherein the vector multiplication instruction obtains a multiplication result vector of the sparse matrix and the vector to be multiplied based on the unpruned element value and the valid element vector in the multiplication of the sparse matrix and the vector to be multiplied; The computing unit also includes: A multiplication result vector acquisition unit is used to obtain the multiplication result vector by multiplying the unpruned element value with the valid elements in the valid element vector.
5. The computing unit according to claim 1, in, The first source address includes a first base source address, and the second source address includes a second base source address.
6. The computing unit according to claim 1, in, The first source address includes a first base source address and a first immediate value, the second source address includes a second base source address and a second immediate value, The unpruned element index reading unit reads the unpruned element index according to an address obtained by the sum of the first base source address and the first immediate value; The valid element reading unit reads the valid element in the to-be-multiplied vector according to an address obtained by summing the second base source address and the second immediate value and the read unpruned element index.
7. The computing unit according to claim 1, in, The first source address includes a first base source address and a first coefficient, the second source address includes a second base source address and a second coefficient, The unpruned element index reading unit reads the unpruned element index according to an address obtained by summing the first coefficient, the product of the vector length and the element size in the vector, and the first base source address; The effective element reading unit reads the effective element in the vector to be multiplied according to the address obtained by summing the second coefficient, the product of the vector length and the element size in the vector, and the second base source address, and the read unpruned element index.
8. The computing unit according to claim 1, in, The first source address includes a first base source address and a third coefficient, the second source address includes a second base source address and a fourth coefficient, The unpruned element index reading unit reads the unpruned element index according to an address obtained by summing the product of the third coefficient and the element size in the vector and the first base source address; The effective element reading unit reads the effective element in the to-be-multiplied vector according to an address obtained by summing the product of the fourth coefficient and the element size in the vector and the second base source address, and the read unpruned element index.
9. The computing unit according to claim 1, in, The elements of the vector to be multiplied are stored in a plurality of memory banks in a tightly coupled memory, wherein parallel access to the elements in the plurality of memory banks is allowed; The unpruned element indices in the sparse matrix are stored in groups, a single group contains an index of an unpruned element taken from each of a plurality of rows in the sparse matrix, and different indices in the same group correspond to different storage bodies of the tightly coupled memory.
10. The computing unit according to claim 9, in, The multiple rows are rows of the number of memory banks of the multiple memory banks sequentially taken out from the sparse matrix according to row indices.
11. The computing unit according to claim 9, in, The unpruned element index reading unit reads the unpruned element index of a group starting from the first source address, and updates the first source address by adding the first source address to the length of a group.
12. The computing unit according to claim 1, in, The valid element vector is assembled in a cache and moved from the cache back to the processing unit where the operation unit is located according to the destination address.
13. The computing unit according to claim 9, in, The valid element vector is assembled in the tightly coupled memory, and is moved from the tightly coupled memory back to the processing unit where the operation unit is located according to the destination address.
14. A processing unit, include: An instruction fetch unit, used to fetch index and valid element load instructions from the memory; An instruction decoding unit, used for decoding the retrieved index and valid element load instruction; An arithmetic unit according to any one of claims 1 to 13, configured to receive and execute decoded index and valid element load instructions.
15. A computing device, include: A memory, used to store the index and valid element loading instructions; A processing unit according to claim 14.
16. A system on chip comprising the processing unit according to claim 14.
17. A data center comprising the computing device according to claim 15.
18. A method for obtaining a valid element vector, wherein the valid element vector is a vector consisting of valid elements corresponding to unpruned elements in the sparse matrix obtained from the vector to be multiplied in the multiplication of the sparse matrix and the vector to be multiplied, wherein the method include: receiving an index and valid element load instruction, the index and valid element load instruction being used to obtain the valid element vector, the index and valid element load instruction comprising a first source address, a second source address and a destination address, the first source address representing a starting storage address of an unpruned element index in the sparse matrix, the second source address representing a starting storage address of the vector to be multiplied, and the destination address representing an address to which the valid element vector is to be stored; Reading an unpruned element index according to the first source address; Reading, according to the second source address and the read unpruned element index, a valid element in the vector to be multiplied for multiplication with the unpruned element in the sparse matrix; The valid elements are assembled into a valid element vector and stored according to the destination address.
19. The method according to claim 18, in, The step of reading, in the vector to be multiplied, valid elements for multiplying the unpruned elements in the sparse matrix according to the second source address and the read unpruned element index, comprises: Adding the second source address and the read unpruned element index respectively to obtain the storage address of each valid element; The valid element is read according to the storage address.
20. The method according to claim 18, in, The elements of the vector to be multiplied are stored in a plurality of memory banks in a tightly coupled memory, wherein parallel access to the elements in the plurality of memory banks is allowed; The unpruned element indices in the sparse matrix are stored in groups, a single group contains an index of an unpruned element taken from each of a plurality of rows in the sparse matrix, and different indices in the same group correspond to different storage bodies of the tightly coupled memory.
21. The method according to claim 20, in, The multiple rows are rows of the number of memory banks of the multiple memory banks sequentially taken out from the sparse matrix according to row indices.
22. The method according to claim 20, in, The reading of the unpruned element index according to the first source address includes: starting from the first source address, reading the unpruned element index of a group, and updating the first source address with the sum of the first source address and the length of a group.
