Data operation circuit, data processing device, chip, card board and electronic equipment

By designing a data operation circuit that can implement the ReLU function, Leaky ReLU function or PReLU function, the problem of increased power consumption and area of ​​existing chips when processing multiple data and flexible algorithms is solved, and efficient and low-cost data processing is achieved.

CN112667288BActive Publication Date: 2024-10-22STREAM COMPUTING INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201910979193.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-10-15
Publication Date
2024-10-22
Estimated Expiration
2039-10-15

AI Technical Summary

Technical Problem

When existing chips process a variety of data and flexible algorithms, they are unable to meet the needs of efficient calculations and lead to increased power consumption and area.

Method used

A data operation circuit is designed, including an operation unit, which can realize the operation of ReLU function, Leaky ReLU function or PReLU function. By integrating multiple operation unit arrays, the number of calls of individual functional units is reduced, and the power consumption and area are reduced.

Benefits of technology

It achieves data processing with high integration, low power consumption and fast calculation, is suitable for processing a variety of data and algorithms, and reduces calculation time and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112667288B_ABST
    Figure CN112667288B_ABST
Patent Text Reader

Abstract

The present invention discloses a data operation circuit, a data processing device, a chip, a card board and an electronic device. The data operation circuit includes: one or more operation units; the operation unit includes: an input variable register, a first constant register, a comparator, a switch, a second constant register, a multiplier and an output variable register. The data operation circuit provided in the embodiment of the present invention is provided with an operation unit, and the operation unit can realize the operation function of the ReLU function, the Leaky ReLU function or the PReLU function, and the data operation circuit has high integration, small area, high calculation efficiency and low power consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a data operation circuit, a data processing device, a chip, a card board and an electronic device. Background Art

[0002] With the development of science and technology, human society is rapidly entering the intelligent era. An important feature of the intelligent era is that people obtain more and more types of data, the amount of data they obtain is increasing, and the speed of processing data is getting higher and higher.

[0003] Chips are the cornerstone of data processing, and they fundamentally determine people's ability to process data. From the perspective of application fields, there are two main routes for chips: one is the general chip route, such as the central processing unit (CPU), which can provide great flexibility, but the effective computing power is relatively low when processing algorithms in specific fields; the other is the dedicated chip route, such as the tensor processing unit (TPU), which can exert high effective computing power in certain specific fields, but in the face of flexible and changeable more general fields, their processing capabilities are relatively poor or even unable to handle.

[0004] Since data in the intelligent era are of many types and huge amounts, chips are required to have both extremely high flexibility to handle ever-changing algorithms in different fields and extremely strong processing capabilities to quickly process huge and rapidly growing amounts of data. Summary of the invention

[0005] (I) Purpose of the invention

[0006] The object of the present invention is to provide a data operation circuit, a data processing device, a chip, a card board and an electronic device. The data operation circuit can realize the operation function of ReLU function, Leaky ReLU function or PReLU function, and the data operation circuit has high integration, small area, high calculation efficiency and low power consumption.

[0007] (II) Technical solution

[0008] To solve the above problems, the first aspect of the present invention provides a data operation circuit, comprising: one or more operation units; the operation units include: an input variable register, a first constant register, a comparator, a switch, a second constant register, a multiplier and an output variable register; the input variable register and the second constant register are respectively connected to the two input ends of the multiplier; the output end of the multiplier and the input variable register are respectively connected to the two input ends of the switch; the input variable register and the first constant register are respectively connected to the two input ends of the comparator; the output end of the comparator is connected to the control end of the switch; the output end of the switch is connected to the output variable register.

[0009] The data operation circuit provided by the embodiment of the present invention has an operation unit provided therein, and the operation unit can realize the operation function of the ReLU function, the Leaky ReLU function or the PReLU function. The data operation circuit has high integration, small area, high calculation efficiency and low power consumption.

[0010] Furthermore, there are multiple computing units, and the multiple computing units are arranged in an array.

[0011] According to a second aspect of the present invention, a data processing device is provided, comprising a storage module, a decoder, an instruction fetch module, a control module and the data operation circuit provided in the first aspect; the storage module is used to store instructions and data; the control module is used to instruct the instruction fetch module to extract instructions from the storage module; the decoder is used to decode the instructions and send the decoded instructions to the data operation circuit; the data operation circuit is used to perform data operations based on the decoded instructions, take the data out of the storage module, and store the data operation results in the storage module.

[0012] Furthermore, the data operation circuit is used to perform data operation based on the decoded instruction, take out the data from the storage module, and store the operation result of the data in the storage module, specifically including: each operation unit in the data operation circuit performs data operation based on the decoded instruction, takes out the data from the storage module, and stores the operation result of the data in the storage module.

[0013] Furthermore, the instructions are encoded using the standard RISC-V instruction encoding method.

[0014] Furthermore, the format of the instruction is the standard RISC-V instruction format.

[0015] Furthermore, the instruction is a matrix operation instruction, which includes an instruction name, a destination address register, a first source address register, and a second source address register; the first source address register is used to store source data, and the second source address register is used to store coefficients for operating on the source data.

[0016] The second source address register may be a matrix address register, a vector address register or a constant address register.

[0017] A third aspect of the present invention provides a chip, comprising one or more data processing devices provided by the second aspect.

[0018] A fourth aspect of the present invention provides a card board, comprising one or more chips provided by the third aspect.

[0019] A fifth aspect of the present invention provides an electronic device comprising one or more card boards as provided in the fourth aspect.

[0020] (III) Beneficial effects

[0021] The above technical solution of the present invention has the following beneficial technical effects:

[0022] The data operation circuit provided by the embodiment of the present invention has an operation unit provided therein, and the operation unit can realize the operation function of the ReLU function, the Leaky ReLU function or the PReLU function. The data operation circuit has high integration, small area, high calculation efficiency and low power consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 It is a schematic diagram of the ReLU function;

[0024] Figure 2 It is a schematic diagram of the Leaky ReLU function or PReLU function;

[0025] Figure 3 is a schematic structural diagram of a data operation circuit provided by one embodiment of the present invention;

[0026] Figure 4 is a simplified structural diagram of a computing unit in a data computing circuit according to an embodiment of the present invention;

[0027] Figure 5 is a schematic structural diagram of a data operation circuit provided by one embodiment of the present invention;

[0028] Figure 6 It is a schematic diagram of the structure of a data processing device provided by one embodiment of the present invention. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, the description of well-known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention.

[0030] In the description of the present invention, it should be noted that the terms “first”, “second” and “third” are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.

[0031] Figure 1 It is a schematic diagram of the ReLU function; Figure 2 It is a schematic diagram of the Leaky ReLU function or PReLU function.

[0032] like Figure 1 and Figure 2 As shown in the figure, the function Rectified Linear Unit (ReLU), also known as the rectified linear unit, is a commonly used activation function in artificial neural networks, usually referring to nonlinear functions represented by ramp functions and their variants. In neural networks, ReLU (Rectified Linear Unit) and its variants such as Leaky ReLU, PReLU, etc. are commonly used nonlinear activation functions.

[0033] exist Figure 1 In the ReLU function shown, when xi≥0, Yi=xi, and when xi<0, Yi=0. Therefore, the ReLU function can realize two calculation methods according to different values ​​of xi.

[0034] exist Figure 2 In the Leaky ReLU function or PReLU function shown, when xi≥0, Yi=xi, and when xi<0, Yi=aixi. Therefore, the Leaky ReLU function or PReLU function can realize two calculation functions according to different values ​​of xi.

[0035] Based on the characteristics of the above functions, it is necessary to combine multiple unit circuits with independent functions with computer programs for step-by-step processing to realize the calculation function of the above functions. Here, the multiple unit circuits with independent functions are, for example, multipliers and comparators.

[0036] As an example, the following is a computer software program that implements the functions of the ReLU function, the Leaky ReLU function or the PReLU function in the above scheme:

[0037]

[0038] It should be noted that the “If(X i >=0)C i =1; Else C i =0;" means that if X i ≥0, then assign 1 to C i , otherwise assign 0 to C i , in this part of the computer program, the first separate unit circuit is combined to realize the function of the comparator.

[0039] In the above computer code, "If(C i = =1) Y i =X i ;" means if C i =1, then X i Give Y i , this part of the computer program is the second separate unit circuit combined with the first separate unit circuit to once again realize the function of the comparator.

[0040] The "Else Y" in the above computer code i =a i *X i " means if Ci≠1, then a i *X i Give Y i ,This part is the third separate unit circuit combined with the second separate unit circuit and realizes the function of a multiplier.

[0041] It can be seen that in the above scheme, the computer software program needs to be combined with three separate unit circuits and called three times to realize the function of the ReLU function. If each element of a matrix needs to realize the function of the function, then during calculation, it is necessary to control the multiple calls of three separate unit circuits in sequence to realize the function operation of the matrix, which will lead to a complex operation sequence and a long calculation time. In addition, there are many independent unit circuits and many calls, which leads to high power consumption, large area of ​​the computing device and high cost.

[0042] The data operation circuit provided by the embodiment of the present invention will be described in detail below. In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0043] Figure 3 It is a schematic diagram of the structure of a data operation circuit provided by one embodiment of the present invention.

[0044] like Figure 3As shown, the data operation circuit includes an arithmetic operation unit, a logic operation unit, a data storage / access unit and a floating-point operation unit. The arithmetic operation unit implements arithmetic operations through a multiplier of the data operation circuit. The logic operation unit can be implemented by a comparator of the data operation circuit. The floating-point operation unit can be implemented by a multiplier. One or more data operation units PU are provided in the data operation circuit, and each data operation unit can implement comparison and multiplication functions, thereby implementing the functions of ReLU function, Leaky ReLU function or PReLU function.

[0045] Figure 4 It is a simplified structural diagram of a computing unit in a data computing circuit provided in one embodiment of the present invention.

[0046] like Figure 4 As shown, the data operation circuit includes: one or more operation units PU; the operation unit PU includes: an input variable register Rin1, a first constant register CO, a comparator CMP, a switch S0, a second constant register C1, a multiplier and an output variable register Rout.

[0047] The input variable register Rin1 and the second constant register C1 are respectively connected to the two input ends of the multiplier; the output end of the multiplier and the input variable register Rin1 are respectively connected to the two input ends of the switch S0; the input variable register Rin1 and the first constant register C0 are respectively connected to the two input ends of the comparator CMP; the output end of the comparator CMP is connected to the control end of the switch S0; the output end of the switch S0 is connected to the output variable register Rout.

[0048] Among them, the value at the input variable register Rin1 is equivalent to the variable xi in the ReLU function, the value at the output variable register Rout is equivalent to the yi in the ReLU function, the first constant register CO stores a first preset constant, the first preset constant is a comparison threshold, in the ReLU function, the Leaky ReLU function or the PReLU function, the preset constant is 0. The second constant register C1 stores a second preset constant, the second preset constant is the multiplication coefficient ai in the ReLU function, the Leaky ReLU function or the PReLU function.

[0049] It can be understood that in the ReLU function, the multiplication coefficient ai is equal to 0, and in the Leaky ReLU function or the PReLU function, the multiplication coefficient ai is equal to a specific coefficient value.

[0050] The operation process of this operation unit is:

[0051] The comparison result between the value xi at Rin1 and the comparison threshold C0 is used as the control signal of the switch S0 to control the port 1 or the port 0 of the switch S0 to be turned on.

[0052] Specifically, the first input terminal of the comparator receives the value xi at Rin1, and the second input terminal receives the comparison threshold at the first constant register C0.

[0053] If the data at the first input terminal of the comparator is greater than or equal to the data at the second input terminal, the generated control signal is used to control the connection of port 1 of switch S0. In this case, Rout outputs the value xi at the input variable register Rin1 obtained by switch S0. This is equivalent to implementing yi=xi in the ReLU function, Leaky ReLU function or PReLU function.

[0054] If the data at the first input terminal of the comparator is less than the data at the second input terminal, the generated control signal is used to control the connection of port 0 of switch S0. In this case, switch S0 obtains the product of xi at the variable register Rin1 obtained from the multiplier and the second preset constant ai stored in the second constant register C1, and Rout outputs the product obtained by switch S0. The output is equivalent to yi=ai*xi in the Leaky ReLU function or PReLU function. Of course, if ai is set to 0 in advance, the function of the ReLU function can be realized.

[0055] The data operation circuit provided in the embodiment of the present invention has an operation unit, which can realize the operation function of ReLU function, Leaky ReLU function or PReLU function. Compared with calling multiple independent unit circuits with different functions multiple times, the data operation circuit in the embodiment of the present invention has high integration, small area, high calculation efficiency and low power consumption.

[0056] Figure 5 It is a schematic diagram of the structure of a data operation circuit according to one embodiment of the present invention.

[0057] like Figure 5 As shown, the data operation circuit includes a plurality of the aforementioned data operation units (PUs), and the plurality of data operation units are arranged in an array. The data operation circuit can implement ReLU function, LeakyReLU function or PReLU function operation of a matrix.

[0058] exist Figure 5 In the example shown, the data operation circuit is provided with MxN operation units, that is, M rows and N columns of operation units, wherein M>=1, N>=2.

[0059] Among them, the operation unit PU is the basic unit for implementing the ReLU function, Leaky ReLU function or PReLU function operation, and multiple data operation PUs arranged in an array can realize the ReLU function, Leaky ReLU function or PReLU function operation for each element in the matrix.

[0060] The specific process of implementing the ReLU function operation for each element in the matrix is ​​as follows:

[0061] The data operation circuit reads the data xi of the input matrix from the storage module respectively, and distributes them to different operation units for ReLU function operation. Taking an input data x1 as an example, the data x1 is input into the first register of an operation unit, that is, as Rin1. The operation unit compares the data x1 with the comparison threshold at the first constant register C0 to obtain a comparison result, and controls the connection of port 1 or port 0 of switch S0 according to the comparison result, and then outputs the value obtained from switch S0 through the output register Rout of the operation unit to realize the operation of Relu function, Leaky ReLU function or PReLU function, that is, to realize the output of yi=xi or yi=ai*xi.

[0062] During the calculation process, one or more rows of data can be taken out at the same time and assigned to the corresponding operation units. At the same time, it is possible to continue reading data from the storage module while calculating and input the read data into the data operation unit array.

[0063] After the calculation is completed, the data operation circuit stores the calculation result in the storage module.

[0064] The following will be divided into different embodiments to illustrate the operation of the Relu function, Leaky ReLU function or PReLU function implemented by the data operation circuit provided in the above implementation.

[0065] Example 1

[0066] The first input matrix can be a 3x6 matrix, for example

[0067] The plurality of operation units of the data operation circuit are in an array of 3x6. The multiplication coefficient ai is preset to be 0.

[0068] When the instruction is to implement the ReLU function for each element of the first input matrix, the operation implemented by the data operation unit is: the data operation unit PU of the first row and the first column receives the data a11 (value is 0) of the first row and the first column of the first input matrix and stores it in Rin1, compares the data a11 with the first preset constant (which can be set to 0) stored in the first constant register CO, and according to the comparison result that the two are equal, controls the switch S0 to select port 1 to be connected, and Rout outputs Rin1, that is, 0. The data operation unit PU of the first row and the second column receives the data a12 (value is 7) of the first row and the second column of the first input matrix and stores it in Rin1, compares the data a12 with the first preset constant (which can be set to 0) stored in the first constant register CO, and according to the comparison result, controls the switch S0 to select port 1 to be connected, and Rout outputs Rin1, that is, 7.

[0069] By analogy, the output matrix is:

[0070] Example 2

[0071] The first input matrix can be a 3x6 matrix, for example

[0072] The plurality of operation units of the data operation circuit are in a 3x6 array. The pre-set multiplication coefficient ai is 2.

[0073] When the instruction is to implement the PReLU function for each element of the first input matrix, the operation implemented by the data operation unit is:

[0074] The data operation unit PU of the 1st row and the 1st column receives the data a11 (value is 0) of the 1st row and the 1st column of the first input matrix and stores it in Rin1, compares the data a11 with the first preset constant (which can be set to 0) stored in the first constant register CO, and according to the equal comparison result of the two, controls the switch S0 to select port 1 to be connected, and Rout outputs Rin1, that is, 0. The data operation unit PU of the 1st row and the 2nd column receives the data a12 (value is 7) of the 1st row and the 2nd column of the first input matrix and stores it in Rin1, compares the data a12 with the first preset constant (which can be set to 0) stored in the first constant register CO, and according to the equal comparison result of the two, controls the switch S0 to select port 1 to be connected, and Rout outputs Rin1, that is, 7.

[0075] By analogy, the output matrix is:

[0076] Example 3

[0077] The first input matrix can be a 3x6 matrix, for example

[0078] If the array of computing units in the data operation circuit is a 3x3 array, the matrix will be divided into two 3*3 groups for calculation.

[0079] When the instruction is to implement the ReLU function for each element of the first input matrix, the operation implemented by the data operation unit is: the data operation unit PU of the first row and the first column receives the data a11 (value is 0) of the first row and the first column of the first input matrix and stores it in Rin1, compares the data a11 with the first preset constant (which can be set to 0) stored in the first constant register CO, and according to the equal comparison result of the two, controls the switch S0 to select port 1 to be connected, and Rout outputs Rin1, that is, 0. By analogy, the operation unit of the third row and the third column obtains the data of the third row and the third column of the output matrix.

[0080] Then, the operation unit of the 1st row and the 1st column receives the 4th data a14 of the 1st row of the first input matrix, and compares the data a11 with the first preset constant (which can be set to 0) stored in the first constant register CO. Similarly, the operation unit of the 3rd row and the 3rd column obtains the data of the 3rd row and the 6th column of the output matrix. The results of the two operations are combined to form the final output matrix.

[0081] It is understandable that when there are multiple operation units in the data operation circuit, the data operation circuit can be suitable for implementing the functions of the ReLU function, the Leaky ReLU function or the PReLU function for the elements in the matrix. Of course, the above data operation circuit can be applied in neural network calculations.

[0082] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.

[0083] The data operation circuit provided by the embodiment of the present invention, the data operation unit can realize the calculation function of the ReLU function, Leaky ReLU function or PReLU function of a certain number or matrix through one instruction. Compared with the unit circuits with multiple independent functions combined with the step-by-step processing of the computer program to realize the calculation function of the above functions, on the first hand, there is no need to separately design multiple sets of control circuits, thereby reducing the area of ​​the device and reducing the cost. On the second hand, the operation of multiple sets of control circuits is reduced, thereby reducing power consumption. On the third hand, the operation unit of the embodiment of the present invention can realize the calculation function of the ReLU function, Leaky ReLU function or PReLU function, and one instruction can obtain the final result, without multiple calculations to obtain the result, saving calculation time. On the fourth hand, the operation unit of the embodiment of the present invention only needs to configure the corresponding registers to realize the ReLU function, Leaky ReLU function or PReLU function operation of the matrix, the combination is very flexible, and the device has strong versatility. The structure of the data operation circuit is small and the operation efficiency is high.

[0084] Figure 6 It is a schematic diagram of the structure of a data processing device provided by one embodiment of the present invention.

[0085] like Figure 6 As shown, the data processing device includes: a storage module 10, a decoder 20, an instruction fetch module 30, a control module 40 and a data operation circuit 50 provided by one or more of the above-mentioned embodiments.

[0086] The storage module 10 is used to store instructions and data.

[0087] The control module 40 is used to instruct the instruction fetching module 30 to fetch instructions from the storage module 10;

[0088] The decoder 20 is used to decode the instruction and send the decoded instruction to the data operation circuit 50;

[0089] The data operation circuit 50 performs data operation based on the decoded instruction, takes out the data from the storage module 10, and stores the data operation result in the storage module 10. The data operation circuit 50 includes a plurality of operation units.

[0090] The data operation circuit 50 can control the connection of different ports of the switch according to different instructions to realize the function of the instruction. Of course, the data operation circuit 50 can also realize the ReLU function, LeakyReLU function or PReLU function operation of the matrix according to the corresponding instruction.

[0091] In one embodiment, the data operation circuit 50 is used to perform data operation based on the decoded instruction, retrieve data from the storage module, and store the data operation result in the storage module, specifically including:

[0092] Each operation unit in the data operation circuit 50 performs data operation based on the decoded instruction, takes data out of the storage module 10 , and stores the operation result of the data in the storage module 10 .

[0093] In one embodiment, since a lot of data need to be operated on by ReLU function, Leaky ReLU function or PReLU function in the neural network calculation process, usually in the form of matrix. In order to facilitate the operation of the data operation circuit, the instructions are designed as matrix operation instructions in this embodiment, which can be processed in parallel by multiple operation units PU in the data operation circuit, thereby improving the efficiency of the operation.

[0094] In this embodiment, the ReLU instruction is encoded using RISC-V rules, using the custom part of the standard RISC-V main instruction code allocation table, namely the "Custom-3 (1111011)" part. The format of the instruction also follows the RISC-V instruction format, and the different instruction formats are as follows:

[0095]

[0096] In one embodiment, the format of the instruction may be: instruction name.destination address register.source matrix address register.second source address register. The destination address register is used to store the address of the destination matrix, for example, to store the data obtained after the source matrix operation; the first source address register is used to store the source data, for example, the source matrix; the second source address register is used to store the coefficients of the source data operation, for example, to store the multiplication coefficients ai for executing the ReLU function, the Leaky ReLU function or the PReLU function operation.

[0097] In one embodiment, the instruction is Velkrelu.mm(rd),(rs1),(rs2), where Velkrelu is an extension name, mm is a matrix-matrix operation, Velkrelu.mm is an instruction name, rd is a destination matrix address register, rs1 is a first source address register storing a source matrix, and rs2 is a second source address register, specifically a matrix address register storing a coefficient matrix for operating on the original data.

[0098] In one embodiment, the first source address register rs1 stores an active matrix, which is a 4*4 matrix a, the second source address register rs2 stores a 4*4 multiplication coefficient matrix v, and the data operation unit PU is a 4*4 array b.

[0099] The meaning of the matrix-matrix instruction is: take out the data of the source matrix from the first source address register rs1, and the number taking method is, for example, taking by row, then from element a11 to element a14, until element a41 to element a44 are taken out and allocated to each PU unit PU11, PU12... until PU44 in the data operation unit PU array b in turn; and take out the data of the multiplication coefficient matrix v from the second source address register rs2, and the number taking method is, for example, taking by row, then from element v11 to element v14, until element v41 to element v44 are taken out and allocated to each PU unit PU11, PU12... until PU44 in the data operation unit PU array b in the second constant register C1.

[0100] The comparator in each operation unit compares the data in Rin1 with the comparison threshold in the first constant register C0 respectively. If the data in Rin1 is greater than or equal to the comparison threshold in the first constant register C0, the processing unit uses the data in Rin1 as the operation result to perform the ReLU function, Leaky ReLU function or PReLU function on the element. If the data in Rin1 is less than the comparison threshold in the first constant register C0, the processing unit multiplies the data in Rin1 with the value of the second constant register C1 in the processing unit to obtain the operation result, and stores the operation result in the storage area specified by the destination matrix address register rd, thereby realizing the ReLU function, Leaky ReLU function or PReLU function of a single element and obtaining the result matrix.

[0101] In one embodiment, the instruction is Velkrelu.mv(rd),(rs1),(rs2), where Velkrelu is an extension name, mv is a matrix-vector, indicating the operation of a matrix and a vector, Velkrelu.mv is the instruction name, rd is the destination matrix address register, rs1 is the first source address register, storing the source matrix, and rs2 is the second source address register, specifically a vector address register, storing the coefficient vector of the source data operation.

[0102] In one embodiment, the first source address register rs1 stores an active matrix, which is a 4*4 matrix, the second source address register rs2 stores a 4*4 multiplication coefficient matrix v, and the data operation unit PU is a 4*4 array b.

[0103] The meaning of the matrix-vector instruction is: take out the data of the source matrix from the first source address register rs1, and the data acquisition method is, for example, row-based, then elements a11 to a14, until elements a41 to a44 are taken out and assigned to the PU units PU11, PU12... until PU44 in the data operation unit PU array b in turn; and take out the data of the multiplication coefficient vector v from the second source address register rs2, and the data acquisition method is, for example, row-based, then elements v1 to v4 are taken out and assigned to the PU units of each row in the data operation unit PU array b, and the first row element v1 is assigned to PU11 to PU14 respectively; until the fourth row element v4 is assigned to the second constant register C1 in PU41 to PU44 respectively.

[0104] The comparator in each operation unit compares the data in Rin1 with the comparison threshold in the first constant register C0 respectively. If the data in Rin1 is greater than or equal to the comparison threshold in the first constant register C0, the processing unit uses the data in Rin1 as the operation result to perform the ReLU function, Leaky ReLU function or PReLU function on the element. If the data in Rin1 is less than the comparison threshold in the first constant register C0, the processing unit multiplies the data in Rin1 with the value of the second constant register C1 in the processing unit to obtain the operation result, and stores the operation result in the storage area specified by the destination matrix address register rd, thereby realizing the ReLU function, Leaky ReLU function or PReLU function of a single element and obtaining the result matrix.

[0105] In one embodiment, the instruction is Velkrelu.mf(rd),(rs1),rs2, where Velkrelu is an extension name, mf is a matrix-constant, indicating the operation of a matrix and a constant, Velkrelu.mf is the instruction name, rd is the destination matrix address register, rs1 is the source matrix address register, and rs2 is the constant address register.

[0106] In one embodiment, the source matrix is ​​a 4*4 matrix a, stored in the source matrix address register rs1, the constant is d, stored in the constant register rs2, and the data processing unit PU is a 4*4 array b.

[0107] The meaning of the matrix-constant instruction is: take out the data of the source matrix from the source matrix address register rs1, and the data is taken in a row-by-row manner, for example, from element a11 to element a14, until element a41 to element a44 are taken out and allocated to Rin1 of each PU unit PU11, PU12... to PU44 in the data operation unit PU array b in turn; and take out the constant d from the constant register rs2, and allocate the constant d to the second constant register C1 in each PU unit PU11, PU12... to PU44.

[0108] The comparator in each data operation unit compares the data in Rin1 with the comparison threshold in the first constant register C0. If the data in Rin1 is greater than or equal to the comparison threshold in the first constant register C0, the processing unit uses the data in Rin1 as the operation result to perform the ReLU function, Leaky ReLU function or PReLU function on the element. If the data in Rin1 is less than the comparison threshold in the first constant register C0, the processing unit multiplies the data in Rin1 with the value of the second constant register C1 in the processing unit to obtain the operation result, and stores the operation result in the storage area specified by the destination matrix address register rd, thereby realizing the ReLU function, Leaky ReLU function or PReLU function of a single element and obtaining the result matrix.

[0109] In the above-mentioned embodiments of the present invention, the instructions adopt the standard RISC-V instruction encoding method and the standard RISC-V instruction format, which improves the versatility of the data operation circuit of the present invention.

[0110] An embodiment of the present invention further provides a chip, comprising one or more data processing devices of the above embodiments.

[0111] An embodiment of the present invention further provides a card board, comprising one or more chips of the above embodiments.

[0112] An embodiment of the present invention further provides an electronic device, comprising one or more chips of the above embodiments. The electronic device may be an electronic device such as a computer or a mobile phone.

[0113] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, and do not constitute a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modifications that fall within the scope and boundaries of the appended claims, or the equivalent forms of such scope and boundaries.

Claims

1. A data operation circuit for realizing the operation function of ReLU, Leaky or PReLU function, It is characterized in that include: one or more computing units; The operation unit includes: an input variable register, a first constant register, a comparator, a switch, a second constant register, a multiplier and an output variable register; The input variable register and the second constant register are connected to two input terminals of the multiplier respectively; The output terminal of the multiplier and the input variable register are connected to two input terminals of the switch respectively; The input variable register and the first constant register are connected to two input terminals of the comparator respectively; the output terminal of the comparator is connected to the control terminal of the switch; The output terminal of the switch is connected to the output variable register.

2. The data operation circuit according to claim 1, It is characterized in that There are multiple computing units, and the multiple computing units are arranged in an array.

3. A data processing device, It is characterized in that It comprises a storage module, a decoder, an instruction fetch module, a control module and a data operation circuit as claimed in claim 1 or 2; The storage module is used to store instructions and data; The control module is used to instruct the instruction fetching module to extract instructions from the storage module; The decoder is used to decode the instruction and send the decoded instruction to the data operation circuit; The data operation circuit is used to perform data operation based on the decoded instruction, take the data out of the storage module, and store the operation result of the data in the storage module.

4. The data processing device according to claim 3, It is characterized in that The data operation circuit is used to perform data operation based on the decoded instruction, take the data out of the storage module, and store the operation result of the data in the storage module, specifically including: Each of the operation units in the data operation circuit performs data operation based on the decoded instruction, takes the data out of the storage module, and stores the operation result of the data in the storage module.

5. The data processing device according to claim 3, It is characterized in that The instructions are encoded using standard RISC-V instruction encoding.

6. The data processing device according to claim 5, It is characterized in that The format of the instruction is the standard RISC-V instruction format.

7. The data processing device according to claim 3, It is characterized in that The instruction is a matrix operation instruction, which includes an instruction name, a destination address register, a first source address register, and a second source address register; the first source address register is used to store source data, and the second source address register is used to store coefficients for operating on the source data.

8. A chip, It is characterized in that Comprising one or more data processing devices as claimed in claim 3.

9. A pallet, It is characterized in that Comprising one or more chips as claimed in claim 8.

10. An electronic device, It is characterized in that Comprising one or more card boards as claimed in claim 9.

Citation Information

Patent Citations

  • Configurable processor

    CN102122275A

  • Constant voltage generating circuit and constant voltage generating method

    US20130249526A1