WO2023124371A1 - Data processing apparatus and method, and chip, computer device and storage medium - Google Patents

Data processing apparatus and method, and chip, computer device and storage medium Download PDF

Info

Publication number
WO2023124371A1
WO2023124371A1 PCT/CN2022/124516 CN2022124516W WO2023124371A1 WO 2023124371 A1 WO2023124371 A1 WO 2023124371A1 CN 2022124516 W CN2022124516 W CN 2022124516W WO 2023124371 A1 WO2023124371 A1 WO 2023124371A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
circuit
value
sub
processed
Prior art date
Application number
PCT/CN2022/124516
Other languages
French (fr)
Chinese (zh)
Inventor
霍冠廷
王文强
徐宁仪
Original Assignee
上海商汤智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 上海商汤智能科技有限公司 filed Critical 上海商汤智能科技有限公司
Publication of WO2023124371A1 publication Critical patent/WO2023124371A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/52Multiplying; Dividing
    • G06F7/523Multiplying only

Definitions

  • the present disclosure relates to the field of computer technology, and in particular, to a data processing device, method, chip, computer equipment, and computer-readable storage medium.
  • Matrix multiplication is one of the most important operations in data calculations performed by artificial intelligence (AI) chips.
  • AI artificial intelligence
  • convolution calculations can be converted into matrix multiplication calculations.
  • Embodiments of the present disclosure at least provide a data processing device, method, chip, computer equipment, and computer-readable storage medium.
  • an embodiment of the present disclosure provides a data processing device, including a data conversion circuit and a calculation circuit.
  • the data conversion circuit is used to receive the data to be processed, and convert the data to be processed into first symbol data and absolute value data; transmit the first symbol data and the absolute value data to the calculation circuit.
  • the first sign data indicates that the corresponding data to be processed is a positive value or a negative value.
  • the calculation circuit is used to obtain the first symbol data and the absolute value data generated by the data conversion circuit, perform a first operation on the absolute value data, and obtain a first intermediate calculation result; and based on the The first symbol data determines the second symbol data of the first intermediate calculation result; and performs a second operation process based on the second symbol data and the first intermediate calculation result to obtain a target processing result of the data to be processed.
  • an embodiment of the present disclosure further provides a data processing method applied to a data processing device, where the data processing device includes a data conversion circuit and a calculation circuit.
  • the method includes: the data conversion circuit receives the data to be processed, and converts the data to be processed into first symbol data and absolute value data; the data conversion circuit transmits the first symbol data to the calculation circuit And the absolute value data, wherein the first symbol data indicates that the corresponding data to be processed is a positive value or a negative value; the calculation circuit obtains the first symbol data generated by the data conversion circuit and the The absolute value data, performing first arithmetic processing on the absolute value data to obtain a first intermediate calculation result; the calculation circuit determines second sign data of the first intermediate calculation result based on the first sign data; and The calculation circuit performs a second calculation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed.
  • an optional implementation manner of the present disclosure further provides a chip, including the data processing device as described in the first aspect or any embodiment of the first aspect.
  • an optional implementation manner of the present disclosure further provides a computer device, including a memory and the data processing apparatus as described in the first aspect or any embodiment of the first aspect.
  • an optional implementation manner of the present disclosure further provides a computer device, including the chip described in the third aspect above.
  • an optional implementation manner of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by a computer device, the computer device executes the above-mentioned second aspect The steps of the data processing method.
  • FIG. 1 shows a schematic diagram of a data processing device provided by an embodiment of the present disclosure
  • Fig. 2a shows a schematic structural diagram of a specific example when the data processing apparatus provided by an embodiment of the present disclosure processes data to be processed
  • Fig. 2b shows a schematic structural diagram of another specific example of processing data to be processed by a data processing device provided by an embodiment of the present disclosure
  • FIG. 3 shows a schematic diagram of another data processing device provided by an embodiment of the present disclosure
  • Fig. 4a shows a schematic structural diagram of a specific example of another data processing apparatus provided by an embodiment of the present disclosure when processing data to be processed;
  • Fig. 4b shows a schematic structural diagram of another specific example of another data processing apparatus provided by an embodiment of the present disclosure when processing data to be processed;
  • FIG. 5 shows a specific circuit structure diagram of a data conversion circuit provided by an embodiment of the present disclosure
  • FIG. 6 shows a specific circuit structure diagram of another data conversion circuit provided by an embodiment of the present disclosure
  • FIG. 7 shows a schematic structural diagram of a second numerical operation circuit provided by an embodiment of the present disclosure
  • FIG. 8 shows a schematic structural diagram of a data processing device for multiplying the first matrix C to be processed and the second matrix D to be processed provided by an embodiment of the present disclosure
  • Fig. 9 shows a schematic flowchart of a data processing method provided by an embodiment of the present disclosure.
  • Matrix multiplication is one of the most important operations in the data calculation of AI chips.
  • the convolution calculation can be converted into matrix multiplication calculation; the calculation rule of matrix multiplication calculation is, as the multiplier
  • the matrix elements in the i-th row of the matrix are multiplied by the corresponding matrix elements in the corresponding position of the j-th column as the multiplicand, and then the product results are added to obtain the position in the i-th row and j-th column in the result matrix matrix elements.
  • the circuit that realizes matrix operation In order to realize the multiplication operation between matrices, in the AI chip, it is necessary to deploy a circuit that realizes matrix operation, and the circuit that realizes matrix operation usually occupies a large amount of chip space and consumes most of the power consumption.
  • the power consumption is usually positively correlated with the bit width of the data to be processed; the current matrix operation circuit directly processes the signed data, and because the bit width occupied by the signed data is large, it needs to consume a lot of power during the matrix multiplication operation. power consumption.
  • the present disclosure provides a data processing device, method, chip, computer equipment, and computer-readable storage medium, by converting the multiplication between signed data to be processed into the multiplication between unsigned data to be processed
  • the multiplication operation can reduce the data bit width during the multiplication operation, and reduce the chip volume and power consumption required for the matrix multiplication calculation.
  • connection described in the embodiments of the present disclosure refers to the connection between hardware circuits, such as connecting different circuit modules (such as data conversion circuits and computing circuits) through lines.
  • circuit modules such as data conversion circuits and computing circuits
  • a data processing device disclosed in this example is introduced in detail, taking the application of the data processing device provided by the embodiment of the present disclosure in matrix operation as an example.
  • FIG. 1 it is a schematic diagram of a data processing device 10 provided by an embodiment of the present disclosure.
  • the data processing device 10 includes a data conversion circuit 11 and a calculation circuit 12 .
  • the data conversion circuit 11 is used to receive data to be processed, and convert the data to be processed into first symbol data and absolute value data; transmit the first symbol data and the absolute value data to the calculation circuit 12 ; Wherein, the first sign data indicates that the corresponding data to be processed is a positive value or a negative value.
  • the calculation circuit 12 is used to obtain the first symbol data and the absolute value data generated by the data conversion circuit 11, and perform a first calculation process on the absolute value data to obtain a first intermediate calculation result; based on the The first symbol data determines the second symbol data of the first intermediate calculation result; and performs a second operation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed.
  • the input end of the data conversion circuit 11 can be connected to the output end of other processing circuits or registers to receive the data to be processed transmitted by other processing circuits, or to read the data to be processed from the register to convert the data to be processed converted into first symbol data and absolute value data.
  • the output terminal of the data conversion circuit 11 can be connected with the input terminal of the calculation circuit 12, and the data conversion circuit 11 can directly transmit the first symbol data and the absolute value data obtained after data conversion to the data to be processed to the calculation circuit 12; the calculation circuit 12 , for receiving the first sign data and absolute value data transmitted by the data conversion circuit 11 when acquiring the first sign data and absolute value data generated by the data conversion circuit 11 .
  • the data to be processed includes multiple data
  • the data to be processed includes first data to be processed and second data to be processed
  • the first data to be processed includes a plurality of first sub-data
  • the second data to be processed includes a plurality of second sub-data
  • a data conversion circuit 11 can be used to receive the first data to be processed and the second data to be processed respectively, and convert a plurality of first sub-data in the first data to be processed converting the sub-data into first symbol data and absolute value data corresponding to each first sub-data; and converting a plurality of second sub-data in the second data to be processed into corresponding to each second sub-data Second sign data and absolute value data.
  • the data processing device 10 provided by the embodiment of the present disclosure can be applied in matrix multiplication operations.
  • the data to be processed includes, for example, matrix A and matrix B to be multiplied, and the matrix elements in matrix A and matrix B are both Signed value; matrix A and matrix B are both 3*3 matrices, and the number system is int8, the first sub-data includes the matrix elements of each row in matrix A, and the second sub-data includes the matrix elements of each column in matrix B;
  • Each matrix element in the matrix A and the matrix B with a relatively wide bit width can be converted into a symbol matrix and an absolute value matrix with a relatively small bit width through the data conversion circuit 11;
  • the matrix A satisfies
  • the symbol matrix includes first symbol data corresponding to each matrix element of matrix A;
  • the symbol matrix includes first symbol data corresponding to each matrix element of matrix B;
  • the absolute value matrix includes absolute value data corresponding to each matrix element of matrix A;
  • the absolute value matrix corresponding to matrix B is
  • the absolute value matrix includes absolute value data corresponding to each matrix element of the matrix B.
  • the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; the second data to be processed includes a plurality of second sub-data; the data conversion circuit 11 It includes a first data conversion circuit 11-1 and a second data conversion circuit 11-2; wherein, the first data conversion circuit 11-1 is used to receive the first data to be processed, and convert multiple first data in the first data to be processed A sub-data is respectively converted into first symbol data and absolute value data corresponding to each first sub-data; the second data conversion circuit 11-2 is used to receive the second data to be processed, and convert the data in the second data to be processed The plurality of second sub-data are respectively converted into first sign data and absolute value data corresponding to each second sub-data.
  • the data processing device 10 can be applied in matrix multiplication operations, and the data to be processed includes matrix A and matrix B, where both matrix A and matrix B are 3*3 int8 matrices, and the first One sub-data includes each matrix element in the matrix A, and the second sub-data includes each matrix element in the matrix B; through the first data conversion circuit 11-1, each of the matrix A that occupies a relatively wide bit width The matrix elements are respectively converted into the first symbol data and absolute value data occupying a relatively small bit width; through the second data conversion circuit 11-2, each matrix element in the matrix B occupying a relatively wide bit width is respectively It is transformed into first symbol data and absolute value data occupying a relatively small bit width.
  • Data conversion circuit 11 converts each matrix element in matrix A into corresponding first symbol matrix and absolute value data; and after converting each matrix element in matrix B into corresponding first symbol matrix and absolute value data, it can be sent to Calculation circuit 12 transmits the first symbol matrix and absolute value data.
  • the data processing device 10 may include a plurality of calculation circuits 12, wherein the number of calculation circuits 12 is related to the number of rows and columns of the matrix involved in the matrix multiplication operation, For example, if two 3*3 (that is, 3 rows and 3 columns) matrices are multiplied, 9 computing circuits are required to calculate each matrix element in the result matrix.
  • each calculation circuit 12 is used to receive the matrix
  • the processing result of the data to be processed that is, after multiplying matrix A and matrix B, the matrix element in the position of row i and column j in the obtained result matrix; where, i ⁇ [1,3]; j ⁇ [1 ,3].
  • FIG. 2a shows a schematic structural diagram of a specific example of using a data conversion circuit 11 to process data to be processed in the data processing device 10 of the embodiment of the present disclosure.
  • Fig. 2b shows a schematic structural diagram of a specific example of using two data conversion circuits 11 (ie, a first data conversion circuit 11-1 and a second data conversion circuit 11-2) to respectively process corresponding data to be processed.
  • the data processing device 10 includes a first data conversion circuit 11-1, a second data conversion circuit 11-2, and a plurality of calculation circuits 12; here, since matrix A and matrix B are multiplied, the calculation circuit 12 Quantity is 9 (namely calculation circuit 12-1, calculation circuit 12-2, calculation circuit 12-3, ..., calculation circuit 12-9);
  • the first data conversion circuit 11-1 is used for receiving matrix A, and convert each matrix element in the matrix A into the first symbol data and absolute value data respectively
  • the second data conversion circuit 11-2 is used to receive the matrix B, and convert each matrix element in the matrix B into the first symbol data respectively A symbol data and absolute value data
  • the first data conversion circuit 11-1 transmits the first symbol data and absolute value data corresponding to each matrix element in the matrix A to the corresponding computing circuit
  • the second data conversion circuit 11-2
  • FIG. 3 provides a schematic diagram of another data processing apparatus 10 for the embodiment of the present disclosure.
  • the data processing device 10 also includes a first register 13 and a second register 14 , wherein both the first register 13 and the second register 14 are connected to the output end of the data conversion circuit 11 and the input end of the calculation circuit 12 .
  • the data conversion circuit 11 is also used to store the first sign data into the first register 13 and store the absolute value data into the second register 14 .
  • the calculation circuit 12 is used to read the first sign data from the first register 13 and the absolute value data from the second register 14 when acquiring the first sign data and absolute value data generated by the data conversion circuit 11 .
  • the data processing device 10 further includes a first register 13 for storing first sign data and a second register 14 for storing absolute value data.
  • the data conversion circuit 11 transmits each matrix element of matrix A to the first register 13-1 after converting the data to be processed into first symbol data and absolute value data
  • the corresponding first symbol data, the first symbol data corresponding to each matrix element of matrix B is transmitted to the first register 13-2, and the absolute value data corresponding to each matrix element of matrix A is transmitted to the second register 14-1, And the absolute value data corresponding to each matrix element of the matrix B is transmitted to the second register 14-2; or, the first data conversion circuit 11-1 converts each first data in the first data to be processed (ie matrix A) After the sub-data (i.e.
  • the first symbol data corresponding to each matrix element of matrix A is transmitted to the first register 13-1, and sent to the second register 14 -1
  • the absolute value data corresponding to each matrix element of the transmission matrix A; the second data conversion circuit 11-2 converts each second sub-data (ie matrix element) in the second data to be processed (ie matrix B)
  • the first symbol data corresponding to each matrix element of matrix B is transmitted to the first register 13-2, and each matrix of matrix B is transmitted to the second register 14-2
  • the first register 13-1 and the first register 13-2 respectively store the obtained first symbol data
  • the second register 14-1 and the second register 14-2 respectively store the obtained absolute value data
  • the data processing device 10 includes a plurality of calculation circuits 12, and each calculation circuit 12 can read from the first register 13-1 that each matrix element in the i-th row in the matrix A corresponds to The first symbol data, read from the second register 14-1 the absolute value data corresponding to the matrix elements in the i-th row in the matrix A, and read the j-th column in the matrix B from the first register 13-2
  • the first symbol data respectively corresponding to the matrix elements of the matrix B and the absolute value data corresponding to the matrix elements in the jth column in the matrix B read from the second register 14-2, and the first operation is performed on the absolute value data to obtain a first intermediate calculation result; and determining second symbol data of the first intermediate calculation result based on the first symbol data, and performing a second operation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed, That is, after matrix A is multiplied by matrix B, the matrix element at the i-th row and j-th column in the resulting matrix is obtained
  • FIG. 4a shows a schematic diagram of another specific example when a data conversion circuit 11 is used to process data to be processed in the data processing device 10 of the embodiment of the present disclosure.
  • the data processing device 10 includes a data conversion circuit 11 , a first register 13 , a second register 14 and a plurality of calculation circuits 12 .
  • the number of calculation circuits 12 is 9 (i.e.
  • the calculation circuit 12-1 After the enable signal, it obtains the first sign data (ie, a_sign 00 , a_sign 01 a_sign 02 ) and matrix Each matrix element in the first column in B corresponds to the first symbol data (ie b_sign 00 , b_sign 10 , b_sign 20 ), and obtains from the second register 14 the matrix elements in the first row in matrix A corresponding to Absolute value data (ie a_cvt 00 , a_cvt 01 , a_cvt 02 ) and the absolute value data corresponding to each matrix element in the first column of matrix B (ie b_cvt 00 , b_cvt 10 , b_cvt 20 ), to calculate the result matrix The matrix element at the first row and first column position in .
  • the calculation circuit 12-2 obtains the first symbol data corresponding to each matrix element in the first row in the matrix A (that is, a_sign 00 , a_sign 01 a_sign 02 , respectively) from the first register 13 ) and the first symbol data corresponding to each matrix element in the second column in matrix B (ie b_sign 01 , b_sign 11 , b_sign 21 ), and obtain each matrix in the first row in matrix A from the second register 14
  • the absolute value data corresponding to the elements ie a_cvt 00 , a_cvt 01 , a_cvt 02
  • the absolute value data corresponding to each matrix element in the second column in matrix B ie b_cvt 01 , b_cvt 11 , b_cvt 21 ), to calculate Get the matrix element at the position of the first row and second column in the result matrix.
  • the calculation circuit 12-9 receives the enable signal, it obtains the first sign data corresponding to each matrix element in the third row in the matrix A (that is, a_sign 20 , a_sign 21 , a_sign 22 ) and the first sign data (ie b_sign 02 , b_sign 12 , b_sign 22 ) corresponding to each matrix element in the third column in matrix B, and obtain the data in the third row in matrix A from the second register 14
  • the absolute value data corresponding to each matrix element ie a_cvt 20 , a_cvt 21 , a_cvt 22
  • the absolute value data corresponding to each matrix element in the third column in matrix B ie b_cvt 02 , b_cvt 12 , b_cvt 22 ), To calculate the matrix element at the position of the third row and third column in the result matrix.
  • FIG. 4b shows a schematic diagram of another specific example of using two data conversion circuits 11 (ie, a first data conversion circuit 11-1 and a second data conversion circuit 11-2) to respectively process corresponding data to be processed.
  • a first data conversion circuit 11-1 and a second data conversion circuit 11-2 are respectively processed corresponding data to be processed.
  • FIG. 4b also includes a first data conversion circuit 11-1 and a second data conversion circuit 11-2.
  • the first data conversion circuit 11-1 is used to receive the matrix A, and convert each matrix element in the matrix A into the first symbol data and absolute value data respectively;
  • the second data conversion circuit 11-2 is used to receive the matrix B, and Each matrix element in the matrix B is respectively converted into first symbol data and absolute value data;
  • the first data conversion circuit 11-1 transmits the first symbol data corresponding to each matrix element in the matrix A to the first register 13, and sends the first symbol data to the first register 13
  • the absolute value data corresponding to each matrix element in the second register 14 transfer matrix A;
  • the second data conversion circuit 11-2 transfers the first symbol data corresponding to each matrix element in the matrix B to the first register 13, and sends to the second register 14 Absolute value data corresponding to each matrix element in the transfer matrix B.
  • the functions and data processing flow of each calculation circuit 12 in FIG. 4b are similar to the specific implementation manner shown in FIG. 4a, and repeated descriptions will not be repeated.
  • the data conversion circuit 11 includes a first conversion circuit and a second conversion circuit; wherein, the first conversion circuit is used to receive the first numerical value of the preset first bit in the data to be processed; the received first The value is used as the first symbol data; and the first value is transmitted to the second conversion circuit; the second conversion circuit is used to receive the second value of the preset second bit in the data to be processed, and based on the first value transmitted by the first conversion circuit Value, convert the second value to obtain absolute value data.
  • the preset first bit represents the sign bit, for example, the bit width of each matrix element in the matrix is n, then the preset first bit can be, for example, the n-1th bit; the preset second bit represents the value bit , for example, bits 0 to n-2 in a matrix element with a bit width of n; for example, the first value of the preset first bit may include 0 and 1, where 0 means positive, that is, the value of the data to be processed When the first value of the preset first bit includes 0, the data to be processed is a positive value; 1 means negative, that is, when the first value of the preset first bit of the data to be processed includes 1, the data to be processed is a negative value .
  • the data conversion circuit 11 converts the data to be processed into the first symbol data and absolute value data
  • the second conversion circuit includes a first adder, a first negation circuit and a first selector connected in sequence; the input terminal of the first selector is connected to the first
  • the output end of the conversion circuit is connected to the output end of the first inversion circuit; the input end of the first inversion circuit is connected to the output end of the first adder.
  • the first adder is used to respond to receiving the second value of the preset second bit in the data to be processed, sum the second value and the preset value to obtain the first intermediate value; transmit to the first negation circuit first intermediate value.
  • the preset numerical value may include 1 or -1, for example.
  • the complement of the second value is calculated by first adding the second value to the preset value, and then inverting the addition result bit by bit.
  • the preset value includes 1, use the method of inverting the second value by bit first, and then add it to the preset value to find the complement of the second value; the above two methods can be calculated to obtain the first
  • the absolute value of the binary value the specific implementation method can be selected according to the actual circuit design requirements, so as to achieve the relevant purpose. The above two methods of calculating the complement of the second value, that is, calculating the absolute value of the second value, will be described in detail below.
  • the first inverting circuit is configured to perform a bitwise inversion operation on the first intermediate value in response to receiving the first intermediate value transmitted by the first adder to obtain a second intermediate value ;Transfer the second intermediate value to the first selector.
  • the first selector is used to convert the first value to the first value in response to receiving the second value of the preset second bit in the data to be processed, the second intermediate value transmitted by the first negation circuit, and the first value transmitted by the first conversion circuit
  • the selection control signal it controls to output the second numerical value as absolute value data, or controls to output the second intermediate numerical value as absolute value data.
  • the control when the first numerical value is 0, the control outputs the second numerical value as absolute value data; when the first numerical value is 1, the control outputs the second intermediate numerical value as absolute value data.
  • FIG. 11 An inverse circuit and a first selector; the first conversion circuit is used to receive the first value of the n-1th bit in the data to be processed (ie val[n-1], where n represents the bit width occupied by the data to be processed), Output the first numerical value of the n-1th bit as the first symbol data (i.e.
  • the first adder in the second conversion circuit is used for Receive the second value (ie val[n-1:0]) of the n-2th to the 0th bit in the data to be processed, and add the second value and the preset value (for example, -1) and sum them, Obtain the first intermediate value; transmit the first intermediate value to the first negation circuit in the second conversion circuit and transmit the second value to the first selector; the first negation circuit bitwise Inverting to obtain the second intermediate value, and transmitting the second intermediate value to the first selector; the first selector is used to use the first value as Select the control signal to control the output of the second value as absolute value data (ie abs), or to control the output of the second intermediate value as absolute value data (ie abs).
  • the specific process of converting the data to be processed by the data conversion circuit 11 shown in FIG. Receive the first value 0 of the seventh bit in a 00 , use the received first value as the first symbol data, and transmit the first value to the second conversion circuit.
  • the first adder in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a 00 , sums the second value and the preset value -1 to obtain the first intermediate value 1000100;
  • the first inverting circuit in the second conversion circuit transmits the first intermediate value.
  • the first inversion circuit In response to receiving the first intermediate value, the first inversion circuit performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value 0111011; and transmits the second intermediate value to the first selector.
  • the first selector uses the first value 0 as a selection control signal. Since the first value is 0, the data to be processed itself is a positive value. Then, the second numerical value of the preset second bit itself is an absolute value, therefore, the control outputs the second numerical value 1000101 as absolute value data.
  • the first conversion circuit in the data conversion circuit 11 receives the first numerical value 1 of the 7th bit in a 01 , and uses the received first numerical value as The first symbol data, and transmit the first value to the second conversion circuit.
  • the first adder in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a01 , sums the second value and the preset value -1 to obtain the first intermediate value 1000100;
  • the first inverting circuit in the second conversion circuit transmits the first intermediate value.
  • the first inversion circuit In response to receiving the first intermediate value, the first inversion circuit performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value 0111011; and transmits the second intermediate value to the first selector.
  • the first selector uses the first value 1 as a selection control signal. Since the first value is 1, the data to be processed itself is a negative value. Therefore, the control outputs the second intermediate value 0111011 as absolute value data.
  • the second conversion circuit may further include a first negation circuit, a first adder, and a first selector connected in sequence; wherein, the first The output end of the negation circuit is connected to the input end of the first adder, and the output end of the first adder is connected to the input end of the first selector.
  • the first inversion circuit is configured to perform a bitwise inversion operation on the second value to obtain a first intermediate value in response to receiving a second value preset in a second bit in the data to be processed; and transmit the second value to the first adder. an intermediate value.
  • the first adder is used for receiving the first intermediate value transmitted by the first negation circuit, summing the first intermediate value and the preset value 1 to obtain a second intermediate value; and transmitting the second intermediate value to the first selector.
  • the first selector is configured to take the first value as The control signal is selected to control the output of the second value as absolute value data, or to control the output of the second intermediate value as absolute value data. Specifically, when the first numerical value is 0, the control outputs the second numerical value as absolute value data; when the first numerical value is 1, the control outputs the second intermediate numerical value as absolute value data.
  • the specific circuit structure diagram of the data conversion circuit 11 can be shown in Figure 6, the data conversion circuit 11 includes a first conversion circuit and a second conversion circuit, and the second conversion circuit includes sequentially connecting the first inverting circuit, the first An adder and a first selector; the first conversion circuit is used to receive the first numerical value of the n-1th bit in the data to be processed (ie val[n-1], wherein n represents the bit width occupied by the data to be processed), Output the first numerical value of the n-1th bit as the first symbol data (i.e.
  • the first negation circuit in the second conversion circuit Receive the second numerical value (ie val[n-1:0]) of the n-2th bit to the 0th bit in the data to be processed, and perform bitwise inversion on the second numerical value to obtain the first intermediate value;
  • the adder transmits the first intermediate value and transmits the second value to the first selector; after the first adder receives the first intermediate value, it adds and sums the first intermediate value and a preset value (for example: 1), Obtain the second intermediate value; transmit the second intermediate value to the first selector; the first selector is used to use the first value as a selection control signal after receiving the first value, the second value and the second intermediate value, and the control will
  • the second numerical value is output as absolute value data (ie, abs), or the second intermediate value is output as absolute value data (ie, abs).
  • the first inversion circuit in the second conversion circuit in response to receiving the second value 1000101 of the 6th to 0th bits in a 00 , performs a bitwise inversion operation on the second value to obtain the first intermediate value 0111010;
  • the first adder in the second conversion circuit transmits the first intermediate value.
  • the first adder In response to receiving the first intermediate value, the first adder adds the first intermediate value to a preset value 1 to obtain a second intermediate value 0111011; transmits the second intermediate value to the first selector.
  • the first selector in response to receiving the first value 0, the second value 1000101 and the second intermediate value 0111011, uses the first value 0 as a selection control signal, because when the first value is 0, the data to be processed itself is a positive value , then the second value of the preset second bit itself is an absolute value, therefore, the control outputs the second value 1000101 as absolute value data.
  • the first conversion circuit in the data conversion circuit 11 receives the first numerical value 1 of the 7th bit in a 01 , and uses the received first numerical value as The first symbol data, and transmit the first value to the second converting circuit.
  • the first inversion circuit in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a 01 , and performs a bitwise inversion operation on the second value to obtain the first intermediate value 0111010;
  • the first adder in the conversion circuit transmits the first intermediate value.
  • the first adder In response to receiving the first intermediate value, the first adder adds the first intermediate value to a preset value 1 to obtain a second intermediate value 0111011; transmits the second intermediate value to the first selector.
  • the first selector in response to receiving the first value 1, the second value 1000101 and the second intermediate value 0111011, uses the first value 1 as a selection control signal, because when the first value is 1, the data to be processed itself is a negative value , therefore, the control outputs the second intermediate value 0111011 as absolute value data.
  • the first sign data and absolute value data may be transmitted to the calculation circuit 12 for processing the data to be processed.
  • the calculation circuit 12 may include a symbolic operation circuit, a first numerical operation circuit, and a second numerical operation circuit; wherein, the output terminal of the symbolic operation circuit is connected to the input end of the second numerical operation circuit; the output of the first numerical operation circuit The terminal is connected to the input terminal of the second numerical operation circuit; the symbolic operation circuit is used to respond to the acquisition of the first symbolic data, and based on the first symbolic data, determine the second symbolic data of the first intermediate calculation result; The operation circuit transmits the second symbol data.
  • the first numerical operation circuit is used for performing first operation processing on the absolute value data in response to the acquired absolute value data to obtain a first intermediate calculation result; and transmitting the first intermediate calculation result to the second numerical operation circuit.
  • the second numerical operation circuit is configured to perform a second operation based on the second symbolic data and the first intermediate calculation result in response to receiving the second symbol data transmitted by the symbol operation circuit and the first intermediate calculation result transmitted by the first numerical operation circuit Processing to obtain the target processing result of the data to be processed.
  • the first operation processing includes multiplication processing; the second operation processing includes addition processing; the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; The processed data includes a plurality of second sub-data respectively corresponding to the first sub-data; the first symbol data includes first symbol data of the first sub-data and first symbol data of the second sub-data respectively corresponding to the first sub-data .
  • the symbol operation circuit includes an XOR gate circuit; the XOR gate circuit is used for performing exclusive OR gates on the first symbol data of each first sub-data and the first symbol data of the corresponding second sub-data for each first sub-data. or processing to obtain the second sign data of the first intermediate calculation result obtained by multiplying each first sub-data and the corresponding second sub-data.
  • the first data to be processed includes matrix
  • the first sub-data includes each matrix element in matrix A, namely a 00 , a 01 , a 02 , a 10 , a 11 , a 12 , a 20 , a 21 , a 22 ;
  • the sign data includes a_sign 00 , a_sign 01 , a_sign 02 , a_sign 10 , a_sign 11 , a_sign 12 , a_sign 20 , a_sign 21 , a_sign 22 .
  • the second pending data includes matrix
  • the second sub-data includes each matrix element in the matrix B, namely b 00 , b 01 , b 02 , b 10 , b 11 , b 12 , b 20 , b 21 , b 22 ; the multiple first sub-data are respectively The corresponding first sign data of each second sub-data is b_sign 00 , b_sign 01 , b_sign 02 , b_sign 10 , b_sign 11 , b_sign 12 , b_sign 20 , b_sign 21 , b_sign 22 .
  • the embodiment of the present disclosure is applied to perform matrix multiplication operation on matrix A and matrix B.
  • the XOR gate circuit in the symbol operation circuit is used to, for each first sub-data in matrix A, convert the first The first symbol data of the sub-data and the first symbol data of the second sub-data multiplied by the first sub-data in matrix B are subjected to XOR processing to obtain the first sub-data and the corresponding second sub-data The second sign data of the first intermediate calculation result obtained after the multiplication process.
  • the symbol operation circuit can combine the first symbol data of each first sub-data in the first row in matrix A with the corresponding second sub-data in the first column in matrix B Exclusive OR processing is performed on the second symbol data to obtain the second symbol data of the first intermediate calculation result obtained after the first sub-data and the corresponding second sub-data are multiplied; Determined as the second symbol data of the first intermediate calculation result obtained after multiplication of a 00 and b 00 ; Determined as the second symbol data of the first intermediate calculation result obtained after multiplication of a 01 and b 10 ; It is determined as the second sign data of the first intermediate calculation result obtained by multiplying a 02 and b 20 .
  • the absolute value data includes the first absolute value data corresponding to each first sub-data in the first data to be processed and the first absolute value data corresponding to the second Second absolute value data corresponding to the second sub-data corresponding to each first sub-data in the data to be processed;
  • the first numerical operation circuit includes a multiplier, and the multiplier is used for each first sub-data, each A product operation is performed on the first absolute value data of the first sub-data and the second absolute value data corresponding to the second sub-data to obtain a first intermediate calculation result corresponding to each first sub-data.
  • the first data to be processed includes matrix
  • the first sub-data includes each matrix element in the matrix A, namely
  • the first absolute value data of each first sub-data includes a_ctv 00 , a_ctv 01 , a_ctv 02 , a_ctv 10 , a_ctv 11 , a_ctv 12 , a_ctv 20 , a_ctv 21 , a_ctv 22 .
  • the second pending data includes matrix
  • the second sub-data includes each matrix element in the matrix B, namely b 00 , b 01 , b 02 , b 10 , b 11 , b 12 , b 20 , b 21 , b 22 ;
  • the two absolute value data include b_ctv 00 , b_ctv 01 , b_ctv 02 , b_ctv 10 , b_ctv 11 , b_ctv 12 , b_ctv 20 , b_ctv 21 , b_ctv 22 .
  • the embodiment of the present disclosure is applied to perform matrix multiplication operation on matrix A and matrix B.
  • the multiplier in the first numerical operation circuit is used for each first sub-data in matrix A, and the first sub-data
  • the first absolute value data of the matrix B is multiplied with the second absolute value data of the second sub-data multiplied by the first sub-data to obtain the multiplication process of the first sub-data and the corresponding second sub-data
  • the multiplier in the first numerical operation circuit can be used to combine the first absolute value data of each first sub-data in the first row in matrix A with the first absolute value data in the first column in matrix B
  • the second absolute value data of the corresponding second sub-data is multiplied to obtain the first intermediate calculation result obtained after the first sub-data and the corresponding second sub-data are multiplied; that is, a_ctv 00 ⁇ b_ctv 00 is determined as The first intermediate calculation result after multiplying a 00 and b 00 ; determine a_ctv 01 ⁇ b_ctv 10 as the first intermediate calculation result after multiplying a 01 and b 10 ; set a_ctv 02 ⁇ b_ctv 20 It is determined as the first intermediate calculation result obtained after multiplying a 02 and b 20 .
  • the second numerical operation circuit includes a second negation circuit, a second selector, a second adder, and a third adder; wherein, the input terminal of the second inversion circuit is connected to the output of the first numerical operation circuit The input end of the second selector is respectively connected with the output end of the second negation circuit, the output end of the sign operation circuit and the output end of the first numerical operation circuit; the input end of the second adder is connected with the output end of the sign operation circuit The output terminal is connected; the input terminal of the third adder is respectively connected with the output terminal of the second selector and the output terminal of the second adder.
  • the second negation circuit is used to receive the first intermediate calculation result corresponding to each first sub-data transmitted by the first numerical operation circuit, and perform bitwise fetching on the first intermediate calculation result corresponding to each first sub-data
  • the reverse operation is performed to obtain the second intermediate calculation result corresponding to each first sub-data, and transmit the second intermediate calculation result corresponding to each first sub-data to the second selector.
  • the second selector is used to respond to receiving the second symbol data of the first intermediate calculation result corresponding to each first sub-data transmitted by the symbol operation circuit, and the second symbol data corresponding to each first sub-data transmitted by the second negation circuit.
  • the intermediate calculation results and the first intermediate calculation results corresponding to each first sub-data transmitted by the first numerical operation circuit use the second symbol data as a selection control signal to control the first intermediate calculation results corresponding to each first sub-data Output as the third intermediate calculation result corresponding to the first sub-data, or control to output the second intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data; to the third
  • the adder transmits the third intermediate calculation result corresponding to each first sub-data.
  • the control when the second symbol data is 0, the control outputs the first intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data; when the second symbol data is In the case of 1, the control outputs the second intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data.
  • the second adder is configured to respond to the second symbol data of the first intermediate calculation result corresponding to each first sub-data transmitted by the receiving symbol operation circuit, and calculate the second symbol of the first intermediate calculation result corresponding to each first sub-data The data are summed to obtain a fourth intermediate calculation result; and the fourth intermediate calculation result is transmitted to the third adder.
  • the third adder is configured to calculate the third intermediate calculation result and the fourth intermediate calculation result corresponding to each first sub-data in response to receiving the third intermediate calculation result and the fourth intermediate calculation result corresponding to each first sub-data. And, get the target processing result.
  • the second numerical operation circuit includes a second adder, a second inverting circuit, a second selector, and a third adder; wherein, the second adder is used to receive each first sub-data and the corresponding The second sign data (i.e.
  • res_sign of the first intermediate calculation result obtained after the second sub-data is multiplied, for example, may include res_sign0, res_sign1, ..., res_signm, where m represents the result matrix in the matrix multiplication operation process The number of matrix elements in the middle), and the second symbol data corresponding to each matrix element in the i-th row in the matrix as the multiplier is added to obtain the fourth intermediate calculation result (i.e.
  • the second negation circuit is used to receive the first intermediate calculation obtained by multiplying each first sub-data and the corresponding second sub-data transmitted by the first numerical operation circuit (such as a multiplier) Result (that is, res_val, such as may include res_val0, res_val1, ..., res_valm, wherein m represents the number of matrix elements in the result matrix during the matrix multiplication operation), and perform bitwise fetching of the first intermediate calculation result
  • the second intermediate calculation result is obtained; the second intermediate calculation result is transmitted to the second selector; after the second selector receives the second symbol data, the first intermediate calculation result and the second intermediate calculation result, the second symbol
  • the data is used as a selection control signal to control the output of the first intermediate calculation result or the second intermediate calculation result as the third intermediate calculation result; transmit the third intermediate calculation result to the third adder; the third adder receives the third intermediate calculation result After the calculation result and the fourth intermediate calculation result, add the
  • the specific numerical operation process of the second numerical operation circuit can be shown as follows: take the first data to be processed as matrix A and the second data to be processed as matrix B, calculate the matrix A in the first row Each matrix element of is multiplied with each corresponding matrix element in the first column in the corresponding matrix B to obtain the operation process of the matrix element at the first row and first column position in the result matrix as an example; if through the multiplier, After the determined a 00 and b 00 are multiplied, the first intermediate calculation result obtained is 1000111, and the second inversion circuit performs a bitwise inversion operation on the first intermediate calculation result after receiving the first intermediate calculation result , to obtain the second intermediate calculation result 0111000 corresponding to a 00 ; if through the multiplier, the first intermediate calculation result obtained after the multiplication of a 01 and b 10 determined is 0100011, the second negation circuit receives the first After the intermediate calculation result, the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1011100 corresponding to
  • the sign bit of b 00 corresponds to The first sign data includes 1, the first sign data corresponding to the sign bit of b 10 includes 1, and the first sign data corresponding to the sign bit of b 20 includes 0.
  • the sign operation circuit performs XOR processing on the first sign data of a 00 and the first sign data of b 00 to obtain the second sign data 1 of the first intermediate calculation result obtained by multiplying a 00 and the corresponding b 00 ; Similarly, the sign operation circuit performs XOR processing on the first sign data of a 01 and the first sign data of b 10 , and obtains the first intermediate calculation result obtained after multiplying a 01 and the corresponding b 10 Two symbol data 0; similarly, the symbol operation circuit performs XOR processing on the first symbol data of a 02 and the first symbol data of b 20 , and obtains the first intermediate calculation result obtained after the multiplication processing of a 02 and b 20
  • the second sign data 0; the sign operation circuit transmits the second sign data respectively corresponding to the three first intermediate calculation results to the second adder and the second selector.
  • the second selector receives the first intermediate calculation result 1000111 obtained after multiplying a 00 and b 00 , the second intermediate calculation result 0111000 obtained after bitwise inversion of the first intermediate calculation result, and a 00 and the corresponding b 00 are multiplied by the second symbol data 1 of the first intermediate calculation result, and the second symbol data 1 is used as the selection control signal. Since the second symbol data is 1, the representation will be a 00 and The first intermediate calculation result obtained after the multiplication of b 00 is a negative value, therefore, the control outputs the second intermediate calculation result 0111000 obtained after bitwise inversion of the first intermediate result as the third intermediate calculation result.
  • the second selector receives the first intermediate calculation result 0100011 obtained after multiplying a 01 and b 10 , and the second intermediate calculation result 1011100 obtained after bitwise inversion of the first intermediate calculation result
  • the second sign data 0 is used as the selection control signal, because when the second sign data is 0, the representation will be
  • the first intermediate calculation result obtained after the multiplication of a 01 and b 10 is a positive value, therefore, the control outputs the first intermediate calculation result 0100011 as the third intermediate result.
  • the second selector receives the first intermediate calculation result 0100011 obtained after multiplying a 02 and b 20 , and the second intermediate calculation result 1011100 obtained after bitwise inversion of the first intermediate calculation result
  • the second symbol data 0 is used as the selection control information, because when the second symbol data is 0, the representation will be a 02
  • the first intermediate calculation result obtained after multiplication with b 20 is a positive value, therefore, the control outputs the first intermediate calculation result 0100011 as the third intermediate result.
  • the second selector transmits the third intermediate calculation result to the third adder.
  • the second adder receives the second symbol data 1 of the first intermediate calculation result obtained after multiplying a 00 and the corresponding b 00 , and the first intermediate calculation result obtained after multiplying a 01 and the corresponding b 10
  • the above three second symbol data are added and summed to obtain the fourth an intermediate calculation result 1; and transmitting the fourth intermediate calculation result to the third adder.
  • the third adder After receiving the third intermediate calculation result and the fourth intermediate calculation result transmitted by the second selector, the third adder adds and sums the third intermediate calculation result and the fourth intermediate calculation result to obtain the target processing of the data to be processed As a result, add 0111000, 0100011, 0100011, and 1 to obtain the first row of the matrix obtained by multiplying each matrix element in the first row of matrix A by the corresponding matrix element in the first column of matrix B. A column of matrix elements.
  • the data processing device can be applied in the process of multiplication of signed matrices with multiple N rows and M columns.
  • the first data to be processed includes The first matrix to be processed
  • the second data to be processed includes the second matrix to be processed
  • a plurality of first sub-data in the first data to be processed includes a plurality of matrix elements located in row i in the first matrix to be processed
  • a plurality of The second sub-data includes a plurality of matrix elements positioned at the jth column in the second matrix to be processed
  • i ⁇ [1, N] N is a positive integer greater than or equal to 2, representing the total number of rows of the first matrix to be processed
  • j ⁇ [1, M] M is a positive integer greater than or equal to 2, indicating the total number of columns of the second matrix to be processed.
  • the second data to be processed includes the second matrix to be processed
  • the 7th characterizes the first numerical value of the sign bit of the matrix element), and uses the first numerical value as the first sign data of each matrix element, that is, receives c 00
  • the first value 1 of the 7th bit of c 01 the first value 1 is used as the first symbol data of c 00 ; and the first value 1 of the 7th bit of c 01 is received, and the first value 1 is used as the first symbol data of c 01 data; and receive the first numerical value 0 of the 7th bit of c 10 , and use the first numerical value 0 as the first symbol data of c 10 ; and receive the first numerical value 0 of the 7th bit of c 11 , and use the first numerical value 0 as the first symbol data for c 11 .
  • the first conversion circuit in the first data conversion circuit 11-1 after receiving the first value corresponding to each matrix element in the first data to be processed, can transmit the first value corresponding to each matrix element to the first data conversion circuit
  • the second selector in the second conversion circuit in 11-1 after receiving the first value corresponding to each matrix element in the first data to be processed, can transmit the first value corresponding to each matrix element to the first data conversion circuit
  • the second selector in the second conversion circuit in 11-1 after receiving the first value corresponding to each matrix element in the first data to be processed, can transmit the first value corresponding to each matrix element to the first data conversion circuit
  • the second selector in the second conversion circuit in 11-1 after receiving the first value corresponding to each matrix element in the first data to be processed, can transmit the first value corresponding to each matrix element to the first data conversion circuit
  • the second selector in the second conversion circuit in 11-1 after receiving the first value corresponding to each matrix element in the first data to be processed.
  • the second conversion circuit includes a first adder, a first inverting circuit, and a first selector connected in sequence; wherein, the first adder receives the second value 1111110 of the 6th to 0th bits of c 00 , the second value and the preset value (-1) are summed to obtain the first intermediate value 1111101 corresponding to c 00 ; and the first intermediate value is transmitted to the first inverting circuit; the first inverting circuit receives the first After the intermediate value, perform bitwise inversion on the first intermediate value to obtain the second intermediate value 0000010 corresponding to c 00 ; transmit the second intermediate value to the first selector; the first selector receives the second intermediate value corresponding to c 00 value, the second intermediate value corresponding to c 00 , and the first value corresponding to c 00 (that is, the first symbol data corresponding to c 00 ), the first value is used as the selection control signal, since the first value is 1, that is, c 00 itself is a negative value
  • the first adder receives the second value 1111010 of the 6th to 0th digits of c 01 , and sums the second value with the preset value (-1) to obtain the first intermediate value 1111001 corresponding to c 01 ; and transmit the first intermediate value to the first inversion circuit; after the first inversion circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 0000110 corresponding to c 01 ;
  • the first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 01 , the second intermediate value corresponding to c 01 , and the first value corresponding to c 01 (that is, the first symbol corresponding to c 01 data), the first value is used as the selection control signal, since the first value is 1, that is, c 01 itself is a negative value, therefore, the second intermediate value 0000110 corresponding to c 01 needs to be output as the absolute value data corresponding to c 01 .
  • the first adder receives the second value 0000001 of the 6th to 0th digits of c 10 , sums the second value with the preset value (-1), and obtains the first intermediate value 0000000 corresponding to c 10 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 1111111 corresponding to c 10 ;
  • the first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 10 , the second intermediate value corresponding to c 10 , and the first value corresponding to c 10 (that is, the first symbol corresponding to c 10 data), the first value is used as the selection control signal, since the first value is 0, that is, c10 itself is a positive value, therefore, the second value 0000001 corresponding to c10 can be output as the absolute value data corresponding to c10 .
  • the first adder receives the second value 0000000 from the 6th bit to the 0th bit of c 11 , sums the second value with the preset value (-1), and obtains the first intermediate value 10000001 corresponding to c 11 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 01111110 corresponding to c 11 ;
  • the first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 11 , the second intermediate value corresponding to c 11 and the first value corresponding to c 11 (that is, the first symbol corresponding to c 11 data), the first numerical value is used as the selection control signal, since the first numerical value is 0, that is, c 11 itself is a positive value, therefore, the second numerical value 0000000 corresponding to c 11 can be output as the absolute value data corresponding to c 11 .
  • the second data conversion circuit 11-2 is used to receive the second matrix D to be processed, and convert each matrix element (that is, d 00 , d 10 ) in the second matrix D to be processed into the first symbol data and the absolute value data.
  • the 7th bit characterizes the first numerical value of the sign bit of the matrix element), and the first numerical value is used as the first sign data of each matrix element, that is, receiving
  • the first value 0 of the 7th bit of d 00 is 0, and the first value 0 is used as the first symbol data of d 00 ; and the first value 0 of the 7th bit of d 10 is received, and the first value 0 is used as the first symbol data of d 10 A symbolic data.
  • the first conversion circuit in the second data conversion circuit 11-2 after receiving the first value corresponding to each matrix element in the second data to be processed, can transmit the first value corresponding to each matrix element to the second data conversion circuit
  • the second selector in the second conversion circuit in 11-2 after receiving the first value corresponding to each matrix element in the second data to be processed, can transmit the first value corresponding to each matrix element to the second data conversion circuit
  • the second selector in the second conversion circuit in 11-2 after receiving the first value corresponding to each matrix element in the second data to be processed, can transmit the first value corresponding to each matrix element to the second data conversion circuit
  • the second selector in the second conversion circuit in 11-2 after receiving the first value corresponding to each matrix element in the second data to be processed, can transmit the first value corresponding to each matrix element to the second data conversion circuit
  • the second selector in the second conversion circuit in 11-2 after receiving the first value corresponding to each matrix element in the second data to be processed.
  • the second conversion circuit includes a first adder, a first inverting circuit, and a first selector connected in sequence; wherein, the first adder receives the second value 0000001 of the 6th to 0th bits of d 00 , sum the second value with the preset value (-1) to obtain the first intermediate value 0000000 corresponding to d 00 ; and transmit the first intermediate value to the first negation circuit; the first negation circuit receives the first After the intermediate value, perform bitwise inversion on the first intermediate value to obtain the second intermediate value 1111111 corresponding to d 00 ; transmit the second intermediate value to the first selector; the first selector receives the second intermediate value corresponding to d 00 value, the second intermediate value corresponding to d 00 , and the first value corresponding to d 00 (that is, the first symbol data corresponding to d 00 ), the first value is used as the selection control signal, since the first value is 0, that is, d 00 itself is a positive value, therefore, the second value 0000001
  • the first adder receives the second value 0000010 of the 6th to 0th digit of d 10 , sums the second value with the preset value (-1), and obtains the first intermediate value 0000001 corresponding to d 10 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 1111110 corresponding to d 10 ;
  • the first selector transmits the second intermediate value; the first selector receives the second value corresponding to d 10 , the second intermediate value corresponding to d 10 , and the first value corresponding to d 10 (that is, the first symbol corresponding to d 10 data), the first numerical value is used as the selection control signal, since the first numerical value is 0, that is, d10 itself is a positive value, therefore, the second numerical value 0000010 corresponding to d10 can be output as the absolute value data corresponding to d10 .
  • each matrix element in the first matrix C to be processed is converted into corresponding first sign data and absolute value data and the second data conversion circuit 11-2 converts the second matrix D to be processed After each matrix element in is converted into the corresponding first symbol data and absolute value data, the first data conversion circuit 11-1 can convert the matrix elements in the first row in the first matrix C to be processed (i.e.
  • the second data conversion circuit 11-2 can convert the matrix elements (ie, d 00 , d 10 ) respectively corresponding to the first symbol data and absolute value data are transmitted to the calculation circuit 12-1, so that the calculation circuit 12-1, based on the first symbols corresponding to c 00 , c 01 , d 00 , d 10 data and absolute value data, and calculate e 00 in the result matrix E; similarly, the first data conversion circuit 11-1 can convert the matrix elements (ie, c 10 , c 11 ) respectively corresponding to the first sign data and absolute value data to the calculation circuit 12-2, and at the same time, the second data conversion circuit 11-2 can place the matrix elements in the first column in the second matrix D to be processed (ie d 00 , d 10 ) respectively corresponding first sign data and absolute value data are transmitted to the calculation circuit 12-2, so that the calculation circuit 12-2, based
  • the sign operation circuit includes an exclusive OR gate circuit for receiving the first symbol data corresponding to
  • the exclusive OR gate circuit in the calculation circuit 12-1 multiplies c 00 and the corresponding d 00 to obtain the second symbol data 1 of the first intermediate calculation result, and multiplies c 01 and the corresponding d 10 to obtain The second sign data 1 of the first intermediate calculation result is transmitted to the second selector and the second adder in the second numerical operation circuit in the calculation circuit 12-1 respectively.
  • the first numerical calculation circuit in the calculation circuit 12-1 includes a multiplier for receiving absolute value data corresponding to c 00 , absolute value data corresponding to c 01 , absolute value data corresponding to d 00 , and absolute value data corresponding to d 10 ; and multiply the absolute value data corresponding to c 00 and the absolute value data corresponding to d 00 to obtain the first intermediate calculation result 0000010 obtained after multiplying c 00 and the corresponding d 00 ; and the absolute value data corresponding to c 01 The value data and the absolute value data corresponding to d 10 are multiplied to obtain the first intermediate calculation result 0001100 obtained by multiplying c 01 and the corresponding d 10 .
  • the multiplier in the calculation circuit 12-1 multiplies c 00 and the corresponding d 00 to obtain the first intermediate calculation result 0000010, and c 01 and the corresponding d 10 to obtain the first intermediate calculation result 0001100 , respectively transmitted to the second selector and the second negation circuit in the second numerical operation circuit in the calculation circuit 12-1.
  • the second numerical calculation circuit in the calculation circuit 12-1 includes a second inversion circuit, a second selector, a second adder and a third adder, wherein the second inversion circuit is used to receive c 00 and the corresponding The first intermediate calculation result obtained after the multiplication of d 00 is 0000010, and the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1111101; the second intermediate calculation result is transmitted to the second selector ;
  • the second selector is used to receive the second symbol data 1 of the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 , and the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00
  • the second inversion circuit is also used to receive the first intermediate calculation result 0001100 obtained after multiplying c 01 and the corresponding d 10 , and perform a bitwise inversion operation on the first intermediate calculation result to obtain the second Intermediate calculation result: 1110011; transmit the second intermediate calculation result to the second selector; the second selector is also used to receive the first intermediate calculation result obtained after multiplying c 01 and corresponding d 10
  • Two-symbol data 1 the first intermediate calculation result 0001100 obtained after multiplying c 01 and the corresponding d 10 and the second intermediate calculation result 1110011, the first intermediate calculation result obtained after multiplying c 01 and the corresponding d 10
  • the second symbol data 1 of the intermediate calculation result is used as the selection control signal. Since the second symbol data is 1, the second intermediate calculation result 1110011 after bitwise inversion of the first intermediate calculation result needs to be used as the third intermediate calculation result .
  • the third intermediate calculation result may be transmitted to the third adder in the calculation circuit 12-1.
  • the second adder in the calculation circuit 12-1 is used to receive the second symbol data 1 of the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 , and multiply c 01 and the corresponding d 10 Then obtain the second symbol data 1 of the first intermediate calculation result, and calculate its sum value to obtain the fourth intermediate calculation result, namely 2 (ie 00000010).
  • the third adder in the calculation circuit 12-1 is used to receive the above-mentioned third intermediate calculation results and the fourth intermediate calculation results, and sum them to obtain e 00 in the result matrix E (that is, to sum 1111101, 1110011, 00000010 , to get 11110010).
  • the sign operation circuit includes an exclusive OR gate circuit for receiving the first symbol data corresponding to c10
  • the exclusive OR gate circuit in the calculation circuit 12-2 multiplies c 10 and the corresponding d 00 to obtain the second symbol data 0 of the first intermediate calculation result, and multiplies c 11 and the corresponding d 10 to obtain The second sign data 0 of the first intermediate calculation result is transmitted to the second selector and the second adder in the second numerical operation circuit in the calculation circuit 12-2 respectively.
  • the first numerical operation circuit in the calculation circuit 12-2 includes a multiplier for receiving absolute value data corresponding to c 10 , absolute value data corresponding to c 11 , absolute value data corresponding to d 00 , and absolute value data corresponding to d 10 ; and The absolute value data corresponding to c 10 and the absolute value data corresponding to d 00 are multiplied to obtain the first intermediate calculation result 0000001 obtained after multiplying c 10 and the corresponding d 00 ; and the absolute value data corresponding to c 11 and the absolute value data corresponding to d 10 are multiplied to obtain the first intermediate calculation result 0000000 obtained by multiplying c 11 and the corresponding d 10 .
  • the multiplier in the calculation circuit 12-2 multiplies c 10 and the corresponding d 00 to obtain the first intermediate calculation result 0000001 and c 11 and the corresponding d 10 to obtain the first intermediate calculation result 0000000 , respectively transmitted to the second selector and the second negation circuit in the second numerical operation circuit in the calculation circuit 12-2.
  • the second numerical calculation circuit in the calculation circuit 12-2 includes a second negation circuit, a second selector, a second adder, and a third adder, wherein the second negation circuit is used to receive c 10 and the corresponding
  • the first intermediate calculation result obtained after the multiplication of d 00 is 0000001, and the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1111110; the second intermediate calculation result is transmitted to the second selector ;
  • the second selector is used to receive the second symbol data 0 of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 , obtained after multiplying c 10 and the corresponding d 00
  • the second inversion circuit is also used to receive the first intermediate calculation result 0000000 obtained after multiplying c 11 and the corresponding d 10 , and perform a bitwise inversion operation on the first intermediate calculation result to obtain the second The intermediate calculation result 1111111; transmit the second intermediate calculation result to the second selector; the second selector is also used for receiving the second intermediate calculation result of the first intermediate calculation result obtained after multiplying c 11 and the corresponding d 10 Symbol data 0, the first intermediate calculation result 0000000 obtained by multiplying c 11 and the corresponding d 10 , and the second intermediate calculation result 1111111, the first intermediate obtained by multiplying c 11 and the corresponding d 10
  • the second symbol data 0 of the calculation result is used as the selection control signal, and since the second symbol data is 0, the first intermediate calculation result 0000000 can be used as the third intermediate calculation result.
  • the third intermediate calculation result may be transmitted to the third adder in the calculation circuit 12-2.
  • the second adder in the calculation circuit 12-2 is used to receive the second symbol data 0 of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 and multiply c 11 and the corresponding d 10 Then obtain the second symbol data 0 of the first intermediate calculation result, and calculate its sum value to obtain the fourth intermediate calculation result, namely 0 (ie 00000000).
  • the third adder in the calculation circuit 12-2 is used to receive the above-mentioned third intermediate calculation results and the fourth intermediate calculation results, and sum them to obtain e 10 in the result matrix E (to sum 0000001, 0000000, 00000000 to obtain 00000001).
  • FIG. 8 A specific structural diagram of a data processing device for performing multiplication operations on the first matrix C to be processed and the second matrix D to be processed may be shown in FIG. 8 .
  • the multiplication operation between the signed data to be processed is converted into the multiplication operation between the unsigned data to be processed, which can reduce the multiplication rate.
  • the data bit width during operation reduces the chip size and power consumption required for matrix multiplication calculations.
  • the layout of the adder in the data processing device is reduced, the structure of the data processing device is simplified, and the volume of the data processing device can be effectively reduced, thereby reducing the number of components of the data processing device in the AI chip.
  • the occupied space can reduce the volume of the AI chip and increase the application range of the AI chip, that is, the AI chip can be applied to scenarios with limited volume.
  • the writing order of each step does not mean a strict execution order and constitutes any limitation on the implementation process.
  • the specific execution order of each step should be based on its function and possible
  • the inner logic is OK.
  • the embodiments of the present disclosure also provide a data processing method corresponding to the data processing device. Since the problem-solving principle of the method in the embodiments of the present disclosure is similar to that of the above-mentioned data processing device in the embodiments of the present disclosure, the implementation of the method Reference can be made to the implementation of the device, and repeated descriptions will not be repeated.
  • the execution subject of the data processing method provided by the embodiments of the present disclosure is generally a computer device with a certain computing capability, and the computer device includes, for example, a data processing device, a server, or other processing devices.
  • the data processing method may be implemented by a processor invoking computer-readable instructions stored in a memory.
  • FIG. 9 it is a schematic flowchart of a data processing method provided by an embodiment of the present disclosure.
  • the method is applied to a data processing device, and the data processing device includes a data conversion circuit and a calculation circuit; the method includes:
  • the data conversion circuit receives the data to be processed, and converts the data to be processed into first symbol data and absolute value data; transmits the first symbol data and absolute value data to the calculation circuit; wherein, the first symbol data represents the corresponding to-be-processed data Data is positive or negative.
  • the calculation circuit acquires the first symbol data and the absolute value data generated by the data conversion circuit, and performs a first calculation process on the absolute value data to obtain a first intermediate calculation result; determine a second value of the first intermediate calculation result based on the first symbol data Symbolic data: performing a second calculation process based on the second symbolic data and the first intermediate calculation result to obtain a processing result of the data to be processed.
  • the data conversion circuit transmits the first symbol data and the absolute value data to the input terminal of the calculation circuit through its output terminal.
  • the data processing device further includes a first register and a second register.
  • the method further includes: the data conversion circuit storing the first symbol data into the first register, and storing the absolute value data into the second register; reading the first sign data from the first register, and reading the absolute value data from the second register.
  • the data conversion circuit includes a first conversion circuit and a second conversion circuit
  • the method further includes: the first conversion circuit receives a preset first bit in the data to be processed The first value of the bit, using the received first value as the first symbol data and transmitting the first value to the second conversion circuit; the second conversion circuit receives the data to be processed A second value of the second bit is preset, and based on the first value transmitted by the first conversion circuit, the second value is converted to obtain the absolute value data.
  • the second conversion circuit includes a first adder, a first negation circuit, and a first selector connected in sequence
  • the method further includes: the first adder responds to receiving the second value of the preset second bit in the data to be processed, summing the second value and the preset value to obtain a first intermediate value; transmitting the first intermediate value to the first inverting circuit an intermediate value; the first inversion circuit responds to receiving the first intermediate value transmitted by the first adder, and performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value, transmit the second intermediate value to the first selector; the first selector responds to receiving the second value of the preset second bit in the data to be processed, and the first inverting circuit transmits The second intermediate value and the first value transmitted by the first conversion circuit, using the first value as a selection control signal, control the output of the second value as the absolute value data, or control The second intermediate value is output as the absolute value data.
  • the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; the second data to be processed It includes a plurality of second sub-data; the data conversion circuit includes a first data conversion circuit and a second data conversion circuit.
  • the method further includes: the first data conversion circuit receives the first data to be processed, and converts a plurality of first sub-data in the first data to be processed into The first symbol data and absolute value data corresponding to the first sub-data; the second data conversion circuit receives the second data to be processed, and converts a plurality of second sub-data in the second data to be processed respectively are first sign data and absolute value data corresponding to each of the second sub-data.
  • the calculation circuit includes a symbolic operation circuit, a first numerical operation circuit and a second numerical operation circuit.
  • the method further includes: the symbolic operation circuit responds to the acquisition of the first symbolic data, and based on the first symbolic data, determines the second symbolic data of the first intermediate calculation result, and sends to the The second numerical operation circuit transmits the second symbol data; the first numerical operation circuit performs a first operation on the absolute value data in response to obtaining the absolute value data to obtain the first intermediate calculation Result; transmit the first intermediate calculation result to the second numerical operation circuit; the second numerical operation circuit responds to receiving the second symbol data transmitted by the symbol operation circuit and the first numerical operation The first intermediate calculation result transmitted by the circuit, based on the second symbol data and the first intermediate calculation result, performs a second calculation process to obtain a target processing result of the data to be processed.
  • the first operation processing includes multiplication processing; the second operation processing includes addition processing; the data to be processed includes first data to be processed and second data to be processed; The first data to be processed includes a plurality of first sub-data; the second data to be processed includes a plurality of second sub-data respectively corresponding to the first sub-data; the first symbol data includes the first The first symbol data of the sub-data and the first symbol data of the second sub-data respectively corresponding to the first sub-data; the symbol operation circuit includes an exclusive OR gate circuit.
  • the method further includes: for each of the first sub-data, the XOR gate circuit combines the first symbol data of each of the first sub-data with the first symbol data of the corresponding second sub-data Exclusive OR processing is performed to obtain second sign data of the first intermediate calculation result obtained by multiplying each of the first sub-data and the corresponding second sub-data.
  • the absolute value data includes the first absolute value data corresponding to each of the first sub-data and the first absolute value data corresponding to each of the first sub-data
  • the method further includes: for each of the first sub-data, the multiplier combines the first absolute value data of each of the first sub-data with the second absolute value data of the corresponding second sub-data Performing a product operation to obtain a first intermediate calculation result corresponding to each of the first sub-data.
  • the second numerical operation circuit includes a second negation circuit, a second selector, a second adder, and a third adder.
  • the second negation circuit receives the first intermediate calculation result corresponding to each of the first sub-data transmitted by the first numerical operation circuit, and calculates the first intermediate calculation result corresponding to each of the first sub-data performing a bitwise inversion operation on the calculation result to obtain a second intermediate calculation result corresponding to each of the first sub-data, and transmitting the second intermediate calculation result corresponding to each of the first sub-data to the second selector .
  • the second selector responds to receiving the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data transmitted by the symbol operation circuit, and each of the first intermediate calculation results transmitted by the second negation circuit.
  • the second intermediate calculation result corresponding to the first sub-data and the first intermediate calculation result corresponding to each of the first sub-data transmitted by the first numerical operation circuit using the second symbol data as a selection control signal , control to output the first intermediate calculation result corresponding to each of the first sub-data as the third intermediate calculation result corresponding to the first sub-data, or control to output the second intermediate calculation result corresponding to each of the first sub-data
  • the result is output as a third intermediate calculation result corresponding to the first sub-data; and the third intermediate calculation result corresponding to each of the first sub-data is transmitted to the third adder.
  • the second adder responds to receiving the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data transmitted by the symbol operation circuit, and for each of the first sub-data corresponding to Summing the second sign data of the first intermediate calculation result to obtain a fourth intermediate calculation result; transmitting the fourth intermediate calculation result to the third adder.
  • the third adder calculates the third intermediate calculation result corresponding to each of the first sub-data summing the fourth intermediate calculation result to obtain the target processing result.
  • the first data to be processed includes a first matrix to be processed;
  • the second data to be processed includes a second matrix to be processed;
  • the plurality of first sub-data includes the first A plurality of matrix elements located in row i in a matrix to be processed;
  • a plurality of the second sub-data includes a plurality of matrix elements located in column j in the second matrix to be processed;
  • i ⁇ [1,N] N is a positive integer greater than or equal to 2, representing the total number of rows of the first matrix to be processed;
  • the implementation of the method can refer to the implementation of the above-mentioned data processing device, repeat The place will not be repeated.
  • the writing order of each step does not mean a strict execution order and constitutes any limitation on the implementation process.
  • the specific execution order of each step should be based on its function and possible
  • the inner logic is OK.
  • the embodiment of the present disclosure also provides a chip, including the data processing device as provided in the embodiment of the present disclosure.
  • the embodiment of the present disclosure also provides a computer device, including: a memory and the data processing apparatus provided in the embodiment of the present disclosure.
  • the embodiment of the present disclosure also provides a computer device, including a chip.
  • the data processing apparatus may include a chip, an AI chip, and the like.
  • the computer device provided in the embodiment of the present disclosure may include a smart terminal such as a mobile phone, or may also be other devices, servers, etc. that can be used for data processing, which is not limited here.
  • Embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored.
  • the computer program When the computer program is run by a computer device, the computer device executes the data processing described in the foregoing method embodiments. method steps.
  • the storage medium may be a volatile or non-volatile computer-readable storage medium.
  • Embodiments of the present disclosure also provide a computer program product, the computer program product carries a program code, and the instructions included in the program code can be used to execute the steps of the data processing method described in the above method embodiment, for details, please refer to the above method The embodiment will not be repeated here.
  • the above-mentioned computer program product may be specifically implemented by means of hardware, software or a combination thereof.
  • the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK) etc. wait.
  • a software development kit Software Development Kit, SDK
  • the specific working process of the above-described system and device can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
  • the disclosed systems, devices and methods may be implemented in other ways. The device embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor.
  • the technical solution of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present disclosure.
  • the aforementioned storage medium includes various media that can store program codes such as U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk.

Abstract

Provided in the present disclosure are a data processing apparatus and method, and a chip, a computer device and a storage medium. The data processing apparatus comprises: a data conversion circuit, which is used for receiving data to be processed, and converting, into first symbol data and absolute value data, the data to be processed, wherein the first symbol data represents that corresponding data to be processed is a positive value or a negative value; and a calculation circuit, which is used for acquiring the first symbol data and the absolute value data that are generated by the data conversion circuit, performing first operation processing on the absolute value data, so as to obtain a first intermediate calculation result, determining second symbol data of the first intermediate calculation result on the basis of the first symbol data, and performing second operation processing on the basis of the second symbol data and the first intermediate calculation result, so as to obtain a target processing result of the data to be processed.

Description

数据处理装置、方法、芯片、计算机设备及存储介质Data processing device, method, chip, computer equipment and storage medium
交叉引用声明cross-reference statement
本申请要求于2021年12月31日提交中国专利局的申请号为202111666460.4的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of Chinese Patent Application No. 202111666460.4 filed with the China Patent Office on December 31, 2021, the entire contents of which are incorporated herein by reference.
技术领域technical field
本公开涉及计算机技术领域,具体而言,涉及一种数据处理装置、方法、芯片、计算机设备及计算机可读存储介质。The present disclosure relates to the field of computer technology, and in particular, to a data processing device, method, chip, computer equipment, and computer-readable storage medium.
背景技术Background technique
矩阵乘法是人工智能(Artificial Intelligence,AI)芯片进行数据计算中最重要的操作之一,例如,在卷积神经网络的实现过程中,可以将卷积计算转化为矩阵乘法计算。当前的矩阵乘法计算中存在功耗大的问题。Matrix multiplication is one of the most important operations in data calculations performed by artificial intelligence (AI) chips. For example, in the implementation of convolutional neural networks, convolution calculations can be converted into matrix multiplication calculations. There is a problem of high power consumption in the current matrix multiplication calculation.
发明内容Contents of the invention
本公开实施例至少提供一种数据处理装置、方法、芯片、计算机设备及计算机可读存储介质。Embodiments of the present disclosure at least provide a data processing device, method, chip, computer equipment, and computer-readable storage medium.
第一方面,本公开实施例提供了一种数据处理装置,包括数据转化电路以及计算电路。所述数据转化电路用于接收待处理数据,并将所述待处理数据转化为第一符号数据以及绝对值数据;向所述计算电路传输所述第一符号数据以及所述绝对值数据。其中,所述第一符号数据表征对应的所述待处理数据为正值或者负值。所述计算电路用于获取所述数据转化电路生成的所述第一符号数据以及所述绝对值数据,对所述绝对值数据进行第一运算处理,得到第一中间计算结果;以及基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的目标处理结果。In a first aspect, an embodiment of the present disclosure provides a data processing device, including a data conversion circuit and a calculation circuit. The data conversion circuit is used to receive the data to be processed, and convert the data to be processed into first symbol data and absolute value data; transmit the first symbol data and the absolute value data to the calculation circuit. Wherein, the first sign data indicates that the corresponding data to be processed is a positive value or a negative value. The calculation circuit is used to obtain the first symbol data and the absolute value data generated by the data conversion circuit, perform a first operation on the absolute value data, and obtain a first intermediate calculation result; and based on the The first symbol data determines the second symbol data of the first intermediate calculation result; and performs a second operation process based on the second symbol data and the first intermediate calculation result to obtain a target processing result of the data to be processed.
第二方面,本公开实施例还提供一种数据处理方法,应用于数据处理装置,所述数据处理装置包括数据转化电路以及计算电路。所述方法包括:所述数据转化电路接收待处理数据,并将所述待处理数据转化为第一符号数据以及绝对值数据;所述数据转化电路向所述计算电路传输所述第一符号数据以及所述绝对值数据,其中,所述第一符号数据表征对应的所述待处理数据为正值或者负值;所述计算电路获取所述数据转化电路生成的所述第一符号数据以及所述绝对值数据,对所述绝对值数据进行第一运算处理,得到第一中间计算结果;所述计算电路基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;以及所述计算电路基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的处理结果。In a second aspect, an embodiment of the present disclosure further provides a data processing method applied to a data processing device, where the data processing device includes a data conversion circuit and a calculation circuit. The method includes: the data conversion circuit receives the data to be processed, and converts the data to be processed into first symbol data and absolute value data; the data conversion circuit transmits the first symbol data to the calculation circuit And the absolute value data, wherein the first symbol data indicates that the corresponding data to be processed is a positive value or a negative value; the calculation circuit obtains the first symbol data generated by the data conversion circuit and the The absolute value data, performing first arithmetic processing on the absolute value data to obtain a first intermediate calculation result; the calculation circuit determines second sign data of the first intermediate calculation result based on the first sign data; and The calculation circuit performs a second calculation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed.
第三方面,本公开可选实施方式还提供一种芯片,包括如上述第一方面或第一方面中任一实施例所述的数据处理装置。In a third aspect, an optional implementation manner of the present disclosure further provides a chip, including the data processing device as described in the first aspect or any embodiment of the first aspect.
第四方面,本公开可选实现方式还提供一种计算机设备,包括存储器和如上述第一方面或第一方面中任一实施例所述的数据处理装置。In a fourth aspect, an optional implementation manner of the present disclosure further provides a computer device, including a memory and the data processing apparatus as described in the first aspect or any embodiment of the first aspect.
第五方面,本公开可选实现方式还提供一种计算机设备,包括如上述第三方面所述的芯片。In a fifth aspect, an optional implementation manner of the present disclosure further provides a computer device, including the chip described in the third aspect above.
第五方面,本公开可选实现方式还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被计算机设备运行时,所述计算机设备执行上述第二方面所述的数据处理方法的步骤。In the fifth aspect, an optional implementation manner of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by a computer device, the computer device executes the above-mentioned second aspect The steps of the data processing method.
关于上述数据处理方法、芯片、计算机设备、及计算机可读存储介质的效果描述参见上述数据处理装置的说明,这里不再赘述。For the effect description of the above data processing method, chip, computer equipment, and computer-readable storage medium, please refer to the description of the above data processing device, which will not be repeated here.
为使本公开的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图,作详细说明如下。In order to make the above-mentioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments will be described in detail below together with the accompanying drawings.
附图说明Description of drawings
为了更清楚地说明本公开实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍。这些附图示出了符合本公开的实施例,并与说明书一起用于说明本公开的技术方案。应当理解,以下附图仅示出了本公开的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings required in the embodiments. These drawings show embodiments consistent with the present disclosure, and are used together with the description to explain the technical solution of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be regarded as limiting the scope. For those skilled in the art, they can also make From these drawings other related drawings are obtained.
图1示出了本公开实施例所提供的一种数据处理装置的示意图;FIG. 1 shows a schematic diagram of a data processing device provided by an embodiment of the present disclosure;
图2a示出了本公开实施例所提供的数据处理装置对待处理数据进行处理时的一种具体示例的结构示意图;Fig. 2a shows a schematic structural diagram of a specific example when the data processing apparatus provided by an embodiment of the present disclosure processes data to be processed;
图2b示出了本公开实施例所提供的数据处理装置对待处理数据进行处理时的另一种具体示例的结构示意图;Fig. 2b shows a schematic structural diagram of another specific example of processing data to be processed by a data processing device provided by an embodiment of the present disclosure;
图3示出了本公开实施例所提供的另一种数据处理装置的示意图;FIG. 3 shows a schematic diagram of another data processing device provided by an embodiment of the present disclosure;
图4a示出了本公开实施例所提供的另一种数据处理装置对待处理数据进行处理时的一种具体示例的结构示意图;Fig. 4a shows a schematic structural diagram of a specific example of another data processing apparatus provided by an embodiment of the present disclosure when processing data to be processed;
图4b示出了本公开实施例所提供的另一种数据处理装置对待处理数据进行处理时的另一种具体示例的结构示意图;Fig. 4b shows a schematic structural diagram of another specific example of another data processing apparatus provided by an embodiment of the present disclosure when processing data to be processed;
图5示出了本公开实施例提供的一种数据转化电路的具体电路结构图;FIG. 5 shows a specific circuit structure diagram of a data conversion circuit provided by an embodiment of the present disclosure;
图6示出了本公开实施例提供的另一种数据转化电路的具体电路结构图;FIG. 6 shows a specific circuit structure diagram of another data conversion circuit provided by an embodiment of the present disclosure;
图7示出了本公开实施例提供的一种第二数值运算电路的结构示意图图;FIG. 7 shows a schematic structural diagram of a second numerical operation circuit provided by an embodiment of the present disclosure;
图8示出了本公开实施例提供的一种对第一待处理矩阵C和第二待处理矩阵D进行乘法运算的数据处理装置的结构示意图;FIG. 8 shows a schematic structural diagram of a data processing device for multiplying the first matrix C to be processed and the second matrix D to be processed provided by an embodiment of the present disclosure;
图9示出了本公开实施例所提供的一种数据处理方法的流程示意图。Fig. 9 shows a schematic flowchart of a data processing method provided by an embodiment of the present disclosure.
具体实施方式Detailed ways
为使本公开实施例的目的、技术方案和优点更加清楚,下面将结合本公开实施例中附图,对本公开实施例中的技术方案进行清楚、完整地描述。所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。通常在此处描述和示出的本公开实施例的组件可以以各种不同的配置来布置和设计。因此,以下对本公开的实施例的详细描述无意限制要求保护的本公开的范围。基于本公开的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本公开保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. The described embodiments are only some of the embodiments of the present disclosure, not all of them. The components of the disclosed embodiments generally described and illustrated herein may be arranged and designed in a variety of different configurations. Accordingly, the following detailed description of embodiments of the present disclosure is not intended to limit the scope of the claimed disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative effort shall fall within the protection scope of the present disclosure.
矩阵乘法是AI芯片进行数据计算中最重要的操作之一,例如,在卷积神经网络的实现过程中,可以将卷积计算转化为矩阵乘法计算;矩阵乘法计算的计算规则是,作为乘数的矩阵第i行的各矩阵元素,分别与对应的作为被乘数的第j列对应位置的各矩阵元素相乘,然后将乘积结果相加,得到结果矩阵中位于第i行第j列位置的矩阵元素。为了实现矩阵之间的乘法运算,在AI芯片中,需要部署实现矩阵运算的电路,而实现矩阵运算的电路通常占用大量的芯片空间,并消耗了大部分的功耗,其占用的空间与消耗的功耗通常与待处理数据位宽呈正相关;当前的矩阵运算电路直接对有符号数据进行运算处理,由于有符号数据占据的位宽较大,导致在进行矩阵乘法运算过程中,需要消耗大量的功耗。Matrix multiplication is one of the most important operations in the data calculation of AI chips. For example, in the implementation process of convolutional neural network, the convolution calculation can be converted into matrix multiplication calculation; the calculation rule of matrix multiplication calculation is, as the multiplier The matrix elements in the i-th row of the matrix are multiplied by the corresponding matrix elements in the corresponding position of the j-th column as the multiplicand, and then the product results are added to obtain the position in the i-th row and j-th column in the result matrix matrix elements. In order to realize the multiplication operation between matrices, in the AI chip, it is necessary to deploy a circuit that realizes matrix operation, and the circuit that realizes matrix operation usually occupies a large amount of chip space and consumes most of the power consumption. The power consumption is usually positively correlated with the bit width of the data to be processed; the current matrix operation circuit directly processes the signed data, and because the bit width occupied by the signed data is large, it needs to consume a lot of power during the matrix multiplication operation. power consumption.
基于上述研究,本公开提供了一种数据处理装置、方法、芯片、计算机设备及计算 机可读存储介质,通过将有符号待处理数据之间的乘法运算转换为无符号的待处理数据之间的乘法运算,能够降低乘法运算时的数据位宽,减少矩阵乘法计算时所需要的芯片体积以及功耗。Based on the above research, the present disclosure provides a data processing device, method, chip, computer equipment, and computer-readable storage medium, by converting the multiplication between signed data to be processed into the multiplication between unsigned data to be processed The multiplication operation can reduce the data bit width during the multiplication operation, and reduce the chip volume and power consumption required for the matrix multiplication calculation.
针对现有方案所存在的缺陷以及本公开所提出的解决方案,均是发明人在经过实践并仔细研究后得出的结果,因此,上述问题的发现过程以及文中本公开针对上述问题所提出的解决方案,都应该是发明人在本公开过程中对本公开做出的贡献。The defects in the existing solutions and the solutions proposed by the present disclosure are the results obtained by the inventor after practice and careful research. The solution should be the inventor's contribution to the disclosure during the disclosure process.
应注意到,相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。It should be noted that like numerals and letters denote similar items in the following figures, therefore, once an item is defined in one figure, it does not require further definition and explanation in subsequent figures.
本公开实施例所述的连接是指的硬件电路之间的连接,例如通过线路将不同的电路模块(例如数据转化电路和计算电路)接通,为便于对本实施例进行理解,首先对本公开实施例所公开的一种数据处理装置进行详细介绍,以本公开实施例提供的数据处理装置应用在矩阵运算为例。The connection described in the embodiments of the present disclosure refers to the connection between hardware circuits, such as connecting different circuit modules (such as data conversion circuits and computing circuits) through lines. To facilitate the understanding of this embodiment, first implement the present disclosure A data processing device disclosed in this example is introduced in detail, taking the application of the data processing device provided by the embodiment of the present disclosure in matrix operation as an example.
参见图1所示,为本公开实施例提供的一种数据处理装置10的示意图。所述数据处理装置10包括数据转化电路11以及计算电路12。Referring to FIG. 1 , it is a schematic diagram of a data processing device 10 provided by an embodiment of the present disclosure. The data processing device 10 includes a data conversion circuit 11 and a calculation circuit 12 .
所述数据转化电路11用于接收待处理数据,并将所述待处理数据转化为第一符号数据以及绝对值数据;向所述计算电路12传输所述第一符号数据以及所述绝对值数据;其中,所述第一符号数据表征对应的所述待处理数据为正值或者负值。The data conversion circuit 11 is used to receive data to be processed, and convert the data to be processed into first symbol data and absolute value data; transmit the first symbol data and the absolute value data to the calculation circuit 12 ; Wherein, the first sign data indicates that the corresponding data to be processed is a positive value or a negative value.
所述计算电路12用于获取所述数据转化电路11生成的所述第一符号数据以及所述绝对值数据,对所述绝对值数据进行第一运算处理,得到第一中间计算结果;基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的处理结果。The calculation circuit 12 is used to obtain the first symbol data and the absolute value data generated by the data conversion circuit 11, and perform a first calculation process on the absolute value data to obtain a first intermediate calculation result; based on the The first symbol data determines the second symbol data of the first intermediate calculation result; and performs a second operation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed.
在具体实施中,数据转化电路11的输入端可以与其它处理电路或寄存器的输出端相连,以接收其它处理电路传输的待处理数据,或者从寄存器中读取待处理数据,以将待处理数据转化为第一符号数据和绝对值数据。In a specific implementation, the input end of the data conversion circuit 11 can be connected to the output end of other processing circuits or registers to receive the data to be processed transmitted by other processing circuits, or to read the data to be processed from the register to convert the data to be processed converted into first symbol data and absolute value data.
数据转化电路11的输出端可以和计算电路12的输入端连接,数据转化电路11可以将对待处理数据进行数据转化后得到的第一符号数据以及绝对值数据直接传输至计算电路12;计算电路12,在获取数据转化电路11生成的第一符号数据以及绝对值数据时,用于接收数据转化电路11传输的第一符号数据以及绝对值数据。The output terminal of the data conversion circuit 11 can be connected with the input terminal of the calculation circuit 12, and the data conversion circuit 11 can directly transmit the first symbol data and the absolute value data obtained after data conversion to the data to be processed to the calculation circuit 12; the calculation circuit 12 , for receiving the first sign data and absolute value data transmitted by the data conversion circuit 11 when acquiring the first sign data and absolute value data generated by the data conversion circuit 11 .
在一种可能的实施方式中,在待处理数据包括多个的情况下,例如,待处理数据包括第一待处理数据和第二待处理数据;第一待处理数据包括多个第一子数据;第二待处理数据包括多个第二子数据;则可以通过一个数据转化电路11,分别接收第一待处理数据以及第二待处理数据,并将第一待处理数据中的多个第一子数据分别转化为与每个第一子数据对应的第一符号数据以及绝对值数据;以及将第二待处理数据中的多个第二子数据分别转化为与每个第二子数据对应的第二符号数据以及绝对值数据。In a possible implementation manner, when the data to be processed includes multiple data, for example, the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data The second data to be processed includes a plurality of second sub-data; then a data conversion circuit 11 can be used to receive the first data to be processed and the second data to be processed respectively, and convert a plurality of first sub-data in the first data to be processed converting the sub-data into first symbol data and absolute value data corresponding to each first sub-data; and converting a plurality of second sub-data in the second data to be processed into corresponding to each second sub-data Second sign data and absolute value data.
示例性的,本公开实施例提供的数据处理装置10可以应用在矩阵乘法运算中,待处理数据例如包括要进行乘法运算的矩阵A和矩阵B,且矩阵A和矩阵B中的矩阵元素均为有符号数值;矩阵A和矩阵B均为3*3、且数制为int8的矩阵,第一子数据包括矩阵A中的各行矩阵元素,第二子数据包括矩阵B中的各列矩阵元素;可以通过数据转化电路11,将位宽相对较宽的矩阵A和矩阵B中的各矩阵元素,分别转化为位宽相对较小的符号矩阵以及绝对值矩阵;Exemplarily, the data processing device 10 provided by the embodiment of the present disclosure can be applied in matrix multiplication operations. The data to be processed includes, for example, matrix A and matrix B to be multiplied, and the matrix elements in matrix A and matrix B are both Signed value; matrix A and matrix B are both 3*3 matrices, and the number system is int8, the first sub-data includes the matrix elements of each row in matrix A, and the second sub-data includes the matrix elements of each column in matrix B; Each matrix element in the matrix A and the matrix B with a relatively wide bit width can be converted into a symbol matrix and an absolute value matrix with a relatively small bit width through the data conversion circuit 11;
其中,矩阵A满足Among them, the matrix A satisfies
Figure PCTCN2022124516-appb-000001
Figure PCTCN2022124516-appb-000001
矩阵B满足Matrix B satisfies
Figure PCTCN2022124516-appb-000002
Figure PCTCN2022124516-appb-000002
矩阵A对应的符号矩阵为The symbol matrix corresponding to matrix A is
Figure PCTCN2022124516-appb-000003
Figure PCTCN2022124516-appb-000003
该符号矩阵中包括矩阵A的每个矩阵元素对应的第一符号数据;The symbol matrix includes first symbol data corresponding to each matrix element of matrix A;
矩阵B对应的符号矩阵为The symbol matrix corresponding to matrix B is
Figure PCTCN2022124516-appb-000004
Figure PCTCN2022124516-appb-000004
该符号矩阵中包括矩阵B的每个矩阵元素对应的第一符号数据;The symbol matrix includes first symbol data corresponding to each matrix element of matrix B;
此外,矩阵A对应的绝对值矩阵为In addition, the absolute value matrix corresponding to matrix A is
Figure PCTCN2022124516-appb-000005
Figure PCTCN2022124516-appb-000005
该绝对值矩阵中包括矩阵A的每个矩阵元素对应的绝对值数据;The absolute value matrix includes absolute value data corresponding to each matrix element of matrix A;
矩阵B对应的绝对值矩阵为The absolute value matrix corresponding to matrix B is
Figure PCTCN2022124516-appb-000006
Figure PCTCN2022124516-appb-000006
该绝对值矩阵中包括矩阵B的每个矩阵元素对应的绝对值数据。The absolute value matrix includes absolute value data corresponding to each matrix element of the matrix B.
在另一种可能的实施方式中,待处理数据包括多个的情况下,可以通过与待处理数据数量相同的数据转化电路11,分别对对应的待处理数据进行数据转化。示例性的,待处理数据包括第一待处理数据和第二待处理数据;第一待处理数据包括多个第一子数据;第二待处理数据包括多个第二子数据;数据转化电路11包括第一数据转化电路11-1以及第二数据转化电路11-2;其中,第一数据转化电路11-1用于接收第一待处理数据,并将第一待处理数据中的多个第一子数据分别转化为与每个第一子数据对应的第一符号数据以及绝对值数据;第二数据转化电路11-2用于接收第二待处理数据,并将第二待处理数据中的多个第二子数据分别转化为与每个第二子数据对应的第一符号数据以及绝对值数据。In another possible implementation manner, when there are multiple pieces of data to be processed, data conversion can be performed on the corresponding data to be processed through the data conversion circuits 11 having the same quantity as the data to be processed. Exemplarily, the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; the second data to be processed includes a plurality of second sub-data; the data conversion circuit 11 It includes a first data conversion circuit 11-1 and a second data conversion circuit 11-2; wherein, the first data conversion circuit 11-1 is used to receive the first data to be processed, and convert multiple first data in the first data to be processed A sub-data is respectively converted into first symbol data and absolute value data corresponding to each first sub-data; the second data conversion circuit 11-2 is used to receive the second data to be processed, and convert the data in the second data to be processed The plurality of second sub-data are respectively converted into first sign data and absolute value data corresponding to each second sub-data.
示例性的,本公开实施例提供的数据处理装置10可以应用在矩阵乘法运算中,待处理数据包括矩阵A和矩阵B,其中,矩阵A和矩阵B均为3*3的int8的矩阵,第一子数据包括矩阵A中的各矩阵元素,第二子数据包括矩阵B中的各矩阵元素;可以通过第一数据转化电路11-1,将占用位宽相对较宽的矩阵A中的每个矩阵元素,分别转化为占用位宽相对较小的第一符号数据以及绝对值数据;通过第二数据转化电路11-2,将占用位宽相对较宽的矩阵B中的每个矩阵元素,分别转化为占用位宽相对较小的第一符号数据以及绝对值数据。Exemplarily, the data processing device 10 provided by the embodiment of the present disclosure can be applied in matrix multiplication operations, and the data to be processed includes matrix A and matrix B, where both matrix A and matrix B are 3*3 int8 matrices, and the first One sub-data includes each matrix element in the matrix A, and the second sub-data includes each matrix element in the matrix B; through the first data conversion circuit 11-1, each of the matrix A that occupies a relatively wide bit width The matrix elements are respectively converted into the first symbol data and absolute value data occupying a relatively small bit width; through the second data conversion circuit 11-2, each matrix element in the matrix B occupying a relatively wide bit width is respectively It is transformed into first symbol data and absolute value data occupying a relatively small bit width.
数据转化电路11将矩阵A中每个矩阵元素转化为对应的第一符号矩阵以及绝对值数据;并将矩阵B中每个矩阵元素转化为对应的第一符号矩阵以及绝对值数据后,可以向计算电路12传输第一符号矩阵和绝对值数据。 Data conversion circuit 11 converts each matrix element in matrix A into corresponding first symbol matrix and absolute value data; and after converting each matrix element in matrix B into corresponding first symbol matrix and absolute value data, it can be sent to Calculation circuit 12 transmits the first symbol matrix and absolute value data.
由于矩阵运算的规则为作为乘数的矩阵的第i行的每个矩阵元素,分别乘以作为被乘数的矩阵的第j列对应位置的矩阵元素,然后将乘积相加,作为结果矩阵中位于第i行第j列位置处的矩阵元素,因此,数据处理装置10可以包括多个计算电路12,其中,计算电路12的数量与矩阵乘法运算涉及到的矩阵的行数和列数相关,比如两个3*3(即3行3列)的矩阵进行乘法运算,则需要9个计算电路,以计算得到结果矩阵中每个矩阵元素,再比如,一个5*4(即5行4列)的矩阵与一个4*6(即4行6列)的矩阵进行乘法运算,则需要30个计算电路,以计算得到结果矩阵中每个矩阵元素;其中,每个计算电路12用于接收矩阵A的位于第i行的各矩阵元素分别对应的第一符号数据和绝对值数据以及矩阵B的位于第j列的各矩阵元素分别对应的第一符号数据和绝对值数据,并对绝对值数据进行第一运算处理,得到第一中间计算结果;以及基于第一符号数据确定第一中间计算结果的第二符号数据,并基于第二符号数据以及第一中间计算结果进行第二运算处理,得到待处理数据的处理结果,即得到矩阵A和矩阵B相乘后,得到的结果矩阵中位于第i行第j列位置处的矩阵元素;其中,i∈[1,3];j∈[1,3]。Since the rule of matrix operation is that each matrix element in the i-th row of the matrix as a multiplier is multiplied by the matrix element in the corresponding position of the j-th column of the matrix as a multiplicand, and then the products are added together as the result matrix The matrix element located at the i-th row and the jth column position, therefore, the data processing device 10 may include a plurality of calculation circuits 12, wherein the number of calculation circuits 12 is related to the number of rows and columns of the matrix involved in the matrix multiplication operation, For example, if two 3*3 (that is, 3 rows and 3 columns) matrices are multiplied, 9 computing circuits are required to calculate each matrix element in the result matrix. For example, a 5*4 (that is, 5 rows and 4 columns ) matrix and a matrix of 4*6 (that is, 4 rows and 6 columns) are multiplied, and 30 calculation circuits are needed to calculate each matrix element in the result matrix; wherein, each calculation circuit 12 is used to receive the matrix The first symbol data and absolute value data corresponding to each matrix element in the i-th row of A and the first symbol data and absolute value data corresponding to each matrix element in the j-th column of matrix B respectively, and the absolute value data performing a first calculation process to obtain a first intermediate calculation result; and determining second symbol data of the first intermediate calculation result based on the first symbol data, and performing a second calculation process based on the second symbol data and the first intermediate calculation result to obtain The processing result of the data to be processed, that is, after multiplying matrix A and matrix B, the matrix element in the position of row i and column j in the obtained result matrix; where, i∈[1,3]; j∈[1 ,3].
具体的,图2a示出本公开实施例数据处理装置10中利用一个数据转化电路11对待处理数据进行处理时的具体示例的结构示意图。该数据处理装置10中包括数据转化电路11以及多个计算电路12,这里,由于是对矩阵A和矩阵B进行乘法运算,因此计算电路12的数量为9个(即计算电路12-1、计算电路12-2、计算电路12-3、....、计算电路12-9);其中,数据转化电路11用于接收矩阵A和矩阵B,并将矩阵A中的各矩阵元素以及矩阵B中的各矩阵元素分别转化为第一符号数据以及绝对值数据;数据转化电路11向相应的计算电路传输矩阵A中各矩阵元素对应的第一符号数据和绝对值数据以及矩阵B中各矩阵元素对应的第一符号数据和绝对值数据;其中,数据转化电路11将矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 00、a_sign 01、a_sign 02和a_cvt 00、a_cvt 01、a_cvt 02)以及矩阵B中位于第一列的各矩阵元素分别对应的第一符号数据和绝对值数据(即b_sign 00、b_sign 10、b_sign 20和b_cvt 00、b_cvt 10、b_cvt 20)传输至计算电路12-1,以计算得到结果矩阵中位于第一行第一列位置处的矩阵元素;同理,数据转化电路11将矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 00、a_sign 01、a_sign 02和a_cvt 00、a_cvt 01、a_cvt 02)以及矩阵B中位于第二列的各矩阵元素分别对应的第一符号数据和绝对值数据(即b_sign 01、b_sign 11、b_sign 21和b_cvt 01、b_cvt 11、b_cvt 21)传输至计算电路12-2,以计算得到结果矩阵中位于第一行第二列的位置处的矩阵元素;以此类推,数据转化电路11将矩阵A中位于第三行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 20、a_sign 21、a_sign 22和a_cvt 20、a_cvt 21、a_cvt 22)以及矩阵B中位于第三列的各矩阵元素分别对应的第一符号数据和绝对值数据(即 b_sign 02、b_sign 12、b_sign 22和b_cvt 02、b_cvt 12、b_cvt 22)传输至计算电路12-9,以计算得到结果矩阵中位于第三行第三列位置处的矩阵元素。 Specifically, FIG. 2a shows a schematic structural diagram of a specific example of using a data conversion circuit 11 to process data to be processed in the data processing device 10 of the embodiment of the present disclosure. Comprise data conversion circuit 11 and a plurality of calculation circuits 12 in this data processing device 10, here, because be to carry out multiplication operation to matrix A and matrix B, so the quantity of calculation circuit 12 is 9 (namely calculation circuit 12-1, calculating circuit 12-2, calculation circuit 12-3, ..., calculation circuit 12-9); wherein, data conversion circuit 11 is used to receive matrix A and matrix B, and each matrix element in matrix A and matrix B Each matrix element in is converted into first symbol data and absolute value data respectively; Data conversion circuit 11 transmits the first symbol data and absolute value data corresponding to each matrix element in matrix A and each matrix element in matrix B to corresponding computing circuit Corresponding first sign data and absolute value data; Wherein, data conversion circuit 11 will be positioned at the first sign data and absolute value data (namely a_sign 00 , a_sign 01 , a_sign 02 respectively corresponding to each matrix element in the first row in matrix A and a_cvt 00 , a_cvt 01 , a_cvt 02 ) and the first sign data and absolute value data corresponding to each matrix element in the first column in matrix B (ie b_sign 00 , b_sign 10 , b_sign 20 and b_cvt 00 , b_cvt 10 , b_cvt 20 ) is transmitted to the calculation circuit 12-1 to calculate the matrix elements at the position of the first row and the first column in the result matrix; similarly, the data conversion circuit 11 converts each matrix element at the first row in the matrix A to The corresponding first sign data and absolute value data (that is, a_sign 00 , a_sign 01 , a_sign 02 and a_cvt 00 , a_cvt 01 , a_cvt 02 ) and the matrix elements in the second column in matrix B respectively correspond to the first sign data and Absolute value data (ie b_sign 01 , b_sign 11 , b_sign 21 and b_cvt 01 , b_cvt 11 , b_cvt 21 ) are transmitted to the calculation circuit 12-2 to calculate the matrix element at the position of the first row and second column in the result matrix ; By analogy, the data conversion circuit 11 is positioned at the first symbol data and the absolute value data corresponding to each matrix element of the third row in the matrix A (i.e. a_sign 20 , a_sign 21 , a_sign 22 and a_cvt 20 , a_cvt 21 , a_cvt 22 ) and the first sign data and absolute value data (ie b_sign 02 , b_sign 12 , b_sign 22 and b_cvt 02 , b_cvt 12 , b_cvt 22 ) corresponding to each matrix element in the third column of the matrix B are transmitted to the calculation circuit 12 -9, to calculate the matrix element at the position of the third row and third column in the result matrix.
图2b示出利用两个数据转化电路11(即第一数据转化电路11-1和第二数据转化电路11-2)分别对对应的待处理数据进行处理时的具体示例的结构示意图。该数据处理装置10中包括第一数据转化电路11-1、第二数据转化电路11-2以及多个计算电路12;这里,由于是对矩阵A和矩阵B进行乘法运算,因此计算电路12的数量为9个(即计算电路12-1、计算电路12-2、计算电路12-3、....、计算电路12-9);其中,第一数据转化电路11-1用于接收矩阵A,并将矩阵A中的各矩阵元素分别转化为第一符号数据以及绝对值数据;第二数据转化电路11-2用于接收矩阵B,并将矩阵B中的各矩阵元素分别转化为第一符号数据以及绝对值数据;第一数据转化电路11-1向相应的计算电路传输矩阵A中各矩阵元素对应的第一符号数据和绝对值数据,第二数据转化电路11-2向相应的计算电路传输矩阵B中各矩阵元素对应的第一符号数据和绝对值数据;其中,第一数据转化电路11-1将矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 00、a_sign 01、a_sign 02和a_cvt 00、a_cvt 01、a_cvt 02)传输至计算电路12-1,第二数据转化电路11-2将矩阵B中位于第一列的各矩阵元素分别对应的第一符号数据和绝对值数据(即b_sign 00、b_sign 10、b_sign 20和b_cvt 00、b_cvt 10、b_cvt 20)传输至计算电路12-1,以使计算电路12-1计算得到结果矩阵中位于第一行第一列位置处的矩阵元素;同理,第一数据转化电路11-1将矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 00、a_sign 01、a_sign 02和a_cvt 00、a_cvt 01、a_cvt 02)传输至计算电路12-2,第二数据转化电路11-2将矩阵B中位于第二列的各矩阵元素分别对应的第一符号数据和绝对值数据(即b_sign 01、b_sign 11、b_sign 21和b_cvt 01、b_cvt 11、b_cvt 21)传输至计算电路12-2,以使计算电路12-2计算得到结果矩阵中位于第一行第二列位置处的矩阵元素;以此类推,第一数据转化电路11-1将矩阵A中位于第三行的各矩阵元素分别对应的第一符号数据和绝对值数据(即a_sign 20、a_sign 21、a_sign 22和a_cvt 20、a_cvt 21、a_cvt 22)传输至计算电路12-9,第二数据转化电路11-2将矩阵B中位于第三列的各矩阵元素分别对应的第一符号数据和绝对值数据(即b_sign 02、b_sign 12、b_sign 22和b_cvt 02、b_cvt 12、b_cvt 22)传输至计算电路12-9,以使计算电路12-9计算得到结果矩阵中位于第三行第三列位置处的矩阵元素。 Fig. 2b shows a schematic structural diagram of a specific example of using two data conversion circuits 11 (ie, a first data conversion circuit 11-1 and a second data conversion circuit 11-2) to respectively process corresponding data to be processed. The data processing device 10 includes a first data conversion circuit 11-1, a second data conversion circuit 11-2, and a plurality of calculation circuits 12; here, since matrix A and matrix B are multiplied, the calculation circuit 12 Quantity is 9 (namely calculation circuit 12-1, calculation circuit 12-2, calculation circuit 12-3, ..., calculation circuit 12-9); Wherein, the first data conversion circuit 11-1 is used for receiving matrix A, and convert each matrix element in the matrix A into the first symbol data and absolute value data respectively; the second data conversion circuit 11-2 is used to receive the matrix B, and convert each matrix element in the matrix B into the first symbol data respectively A symbol data and absolute value data; the first data conversion circuit 11-1 transmits the first symbol data and absolute value data corresponding to each matrix element in the matrix A to the corresponding computing circuit, and the second data conversion circuit 11-2 sends the corresponding calculation circuit The calculation circuit transfers the first symbol data and absolute value data corresponding to each matrix element in the matrix B; wherein, the first data conversion circuit 11-1 converts the first symbol data and the absolute value data corresponding to each matrix element in the first row in the matrix A respectively Absolute value data (that is, a_sign 00 , a_sign 01 , a_sign 02 and a_cvt 00 , a_cvt 01 , a_cvt 02 ) are transmitted to the calculation circuit 12-1, and the second data conversion circuit 11-2 converts each matrix in the first column of the matrix B to The first sign data and absolute value data corresponding to the elements (ie b_sign 00 , b_sign 10 , b_sign 20 and b_cvt 00 , b_cvt 10 , b_cvt 20 ) are transmitted to the calculation circuit 12-1, so that the calculation circuit 12-1 calculates the result Matrix elements at the first row and first column position in the matrix; similarly, the first data conversion circuit 11-1 converts the first symbol data and absolute value data corresponding to each matrix element at the first row in the matrix A ( That is, a_sign 00 , a_sign 01 , a_sign 02 and a_cvt 00 , a_cvt 01 , a_cvt 02 ) are transmitted to the calculation circuit 12-2, and the second data conversion circuit 11-2 converts the matrix elements in the second column in the matrix B to corresponding The first sign data and absolute value data (that is, b_sign 01 , b_sign 11 , b_sign 21 and b_cvt 01 , b_cvt 11 , b_cvt 21 ) are transmitted to the calculation circuit 12-2, so that the calculation circuit 12-2 calculates the position in the result matrix The matrix element at the second column position of a row; By analogy, the first data conversion circuit 11-1 is positioned at the first sign data and the absolute value data corresponding to each matrix element in the third row in matrix A respectively (being a_sign 20 , a_sign 21 , a_sign 22 and a_cvt 20 , a_cvt 21 , a_cvt 22 ) are transmitted to the calculation circuit 12-9, and the second data conversion circuit 11-2 converts the first symbols corresponding to the matrix elements in the third column in the matrix B Data and absolute value data (that is, b_sign 02 , b_sign 12 , b_sign 22 and b_cvt 02 , b_cvt 12 , b_cvt 22 ) are transmitted to the calculation circuit 12-9, so that the calculation circuit 12-9 calculates the result matrix located in the third row No. Matrix elements at three column positions.
在一种可能的实施方式中,如图3所示为本公开实施例提供了另一种数据处理装置10的示意图。该数据处理装置10还包括第一寄存器13和第二寄存器14,其中,第一寄存器13和第二寄存器14均与数据转化电路11的输出端以及计算电路12的输入端连接。In a possible implementation manner, FIG. 3 provides a schematic diagram of another data processing apparatus 10 for the embodiment of the present disclosure. The data processing device 10 also includes a first register 13 and a second register 14 , wherein both the first register 13 and the second register 14 are connected to the output end of the data conversion circuit 11 and the input end of the calculation circuit 12 .
数据转化电路11还用于将第一符号数据存储至第一寄存器13,以及将绝对值数据存储至第二寄存器14中。The data conversion circuit 11 is also used to store the first sign data into the first register 13 and store the absolute value data into the second register 14 .
计算电路12,在获取数据转化电路11生成的第一符号数据以及绝对值数据时,用于从第一寄存器13中读取第一符号数据以及从第二寄存器14中读取绝对值数据。The calculation circuit 12 is used to read the first sign data from the first register 13 and the absolute value data from the second register 14 when acquiring the first sign data and absolute value data generated by the data conversion circuit 11 .
示例性的,本公开实施例提供的数据处理装置10还包括用于存储第一符号数据的第一寄存器13以及用于存储绝对值数据的第二寄存器14。以待处理数据包括矩阵A和矩阵B为例,则数据转化电路11在将待处理数据转化为第一符号数据和绝对值数据后,向第一寄存器13-1传输矩阵A的每个矩阵元素对应的第一符号数据,向第一寄存器13-2传输矩阵B的每个矩阵元素对应的第一符号数据,向第二寄存器14-1传输矩阵A的每 个矩阵元素对应的绝对值数据,以及向第二寄存器14-2传输矩阵B的每个矩阵元素对应的绝对值数据;或者,第一数据转化电路11-1在将第一待处理数据(即矩阵A)中的每个第一子数据(即矩阵元素)转化为对应的第一符号数据、以及绝对值数据后,向第一寄存器13-1传输矩阵A的每个矩阵元素对应的第一符号数据,并向第二寄存器14-1传输矩阵A的每个矩阵元素对应的绝对值数据;第二数据转化电路11-2在将第二待处理数据(即矩阵B)中的每个第二子数据(即矩阵元素)转化为对应的第一符号数据以及绝对值数据后,向第一寄存器13-2传输矩阵B的每个矩阵元素对应的第一符号数据,并向第二寄存器14-2传输矩阵B的每个矩阵元素对应的绝对值数据。Exemplarily, the data processing device 10 provided by the embodiment of the present disclosure further includes a first register 13 for storing first sign data and a second register 14 for storing absolute value data. Taking the data to be processed including matrix A and matrix B as an example, the data conversion circuit 11 transmits each matrix element of matrix A to the first register 13-1 after converting the data to be processed into first symbol data and absolute value data The corresponding first symbol data, the first symbol data corresponding to each matrix element of matrix B is transmitted to the first register 13-2, and the absolute value data corresponding to each matrix element of matrix A is transmitted to the second register 14-1, And the absolute value data corresponding to each matrix element of the matrix B is transmitted to the second register 14-2; or, the first data conversion circuit 11-1 converts each first data in the first data to be processed (ie matrix A) After the sub-data (i.e. matrix elements) are converted into corresponding first symbol data and absolute value data, the first symbol data corresponding to each matrix element of matrix A is transmitted to the first register 13-1, and sent to the second register 14 -1 The absolute value data corresponding to each matrix element of the transmission matrix A; the second data conversion circuit 11-2 converts each second sub-data (ie matrix element) in the second data to be processed (ie matrix B) After the corresponding first symbol data and absolute value data, the first symbol data corresponding to each matrix element of matrix B is transmitted to the first register 13-2, and each matrix of matrix B is transmitted to the second register 14-2 The absolute value data corresponding to the element.
第一寄存器13-1和第一寄存器13-2分别对获取到的第一符号数据进行存储,第二寄存器14-1和第二寄存器14-2分别对获取到的绝对值数据进行存储。The first register 13-1 and the first register 13-2 respectively store the obtained first symbol data, and the second register 14-1 and the second register 14-2 respectively store the obtained absolute value data.
数据处理装置10中包括多个计算电路12,每个计算电路12在接收到使能控制信号后,可以从第一寄存器13-1中读取矩阵A中位于第i行的各矩阵元素分别对应的第一符号数据、从第二寄存器14-1中读取矩阵A中位于第i行的矩阵元素分别对应的绝对值数据、从第一寄存器13-2中读取矩阵B中位于第j列的矩阵元素分别对应的第一符号数据以及从第二寄存器14-2中读取矩阵B中位于第j列的矩阵元素分别对应的绝对值数据,并对绝对值数据进行第一运算处理,得到第一中间计算结果;以及基于第一符号数据确定第一中间计算结果的第二符号数据,并基于第二符号数据以及第一中间计算结果进行第二运算处理,得到待处理数据的处理结果,即得到矩阵A和矩阵B相乘后,得到的结果矩阵中位于第i行第j列位置处的矩阵元素。The data processing device 10 includes a plurality of calculation circuits 12, and each calculation circuit 12 can read from the first register 13-1 that each matrix element in the i-th row in the matrix A corresponds to The first symbol data, read from the second register 14-1 the absolute value data corresponding to the matrix elements in the i-th row in the matrix A, and read the j-th column in the matrix B from the first register 13-2 The first symbol data respectively corresponding to the matrix elements of the matrix B and the absolute value data corresponding to the matrix elements in the jth column in the matrix B read from the second register 14-2, and the first operation is performed on the absolute value data to obtain a first intermediate calculation result; and determining second symbol data of the first intermediate calculation result based on the first symbol data, and performing a second operation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed, That is, after matrix A is multiplied by matrix B, the matrix element at the i-th row and j-th column in the resulting matrix is obtained.
具体的,图4a示出本公开实施例数据处理装置10中在利用一个数据转化电路11对待处理数据进行处理时的另一种具体示例的示意图。该数据处理装置10中包括数据转化电路11、第一寄存器13、第二寄存器14以及多个计算电路12。这里,由于是对矩阵A和矩阵B进行乘法运算,因此,计算电路12的数量为9个(即计算电路12-1、计算电路12-2、计算电路12-3、....、计算电路12-9);其中,数据转化电路11用于接收矩阵A和矩阵B,并将矩阵A中的各矩阵元素、矩阵B中的各矩阵元素分别转化为第一符号数据以及绝对值数据;数据转化电路11向第一寄存器13传输矩阵A中各矩阵元素对应的第一符号数据以及矩阵B中各矩阵元素对应的第一符号数据,以使第一寄存器13存储矩阵A中各矩阵元素对应的第一符号数据以及矩阵B中各矩阵元素对应的第一符号数据;数据转化电路11向第二寄存器14传输矩阵A中各矩阵元素对应的绝对值数据以及矩阵B中各矩阵元素对应的绝对值数据,以使第二寄存器14存储矩阵A中各矩阵元素对应的绝对值数据以及矩阵B中各矩阵元素对应的绝对值数据。Specifically, FIG. 4a shows a schematic diagram of another specific example when a data conversion circuit 11 is used to process data to be processed in the data processing device 10 of the embodiment of the present disclosure. The data processing device 10 includes a data conversion circuit 11 , a first register 13 , a second register 14 and a plurality of calculation circuits 12 . Here, since matrix A and matrix B are multiplied, therefore, the number of calculation circuits 12 is 9 (i.e. calculation circuit 12-1, calculation circuit 12-2, calculation circuit 12-3, ..., calculation Circuit 12-9); wherein, the data conversion circuit 11 is used to receive the matrix A and the matrix B, and convert each matrix element in the matrix A and each matrix element in the matrix B into first symbol data and absolute value data respectively; The data conversion circuit 11 transmits to the first register 13 the first symbol data corresponding to each matrix element in the matrix A and the first symbol data corresponding to each matrix element in the matrix B, so that the first register 13 stores the corresponding matrix elements in the matrix A. The first symbol data corresponding to each matrix element in matrix B and the first symbol data corresponding to each matrix element in matrix B; the data conversion circuit 11 transmits to the second register 14 the absolute value data corresponding to each matrix element in matrix A and the absolute Value data, so that the second register 14 stores the absolute value data corresponding to each matrix element in matrix A and the absolute value data corresponding to each matrix element in matrix B.
计算电路12-1在接收到使能信号后,从第一寄存器13中获取矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据(即a_sign 00、a_sign 01a_sign 02)以及矩阵B中位于第一列的各矩阵元素分别对应的第一符号数据(即b_sign 00、b_sign 10、b_sign 20),并从第二寄存器14中获取矩阵A中位于第一行的各矩阵元素分别对应的绝对值数据(即a_cvt 00、a_cvt 01、a_cvt 02)以及矩阵B中位于第一列的各矩阵元素分别对应的绝对值数据(即b_cvt 00、b_cvt 10、b_cvt 20),以计算得到结果矩阵中位于第一行第一列位置处的矩阵元素。 After the calculation circuit 12-1 receives the enable signal, it obtains the first sign data (ie, a_sign 00 , a_sign 01 a_sign 02 ) and matrix Each matrix element in the first column in B corresponds to the first symbol data (ie b_sign 00 , b_sign 10 , b_sign 20 ), and obtains from the second register 14 the matrix elements in the first row in matrix A corresponding to Absolute value data (ie a_cvt 00 , a_cvt 01 , a_cvt 02 ) and the absolute value data corresponding to each matrix element in the first column of matrix B (ie b_cvt 00 , b_cvt 10 , b_cvt 20 ), to calculate the result matrix The matrix element at the first row and first column position in .
同理,计算电路12-2在接收到使能信号后,从第一寄存器13中获取矩阵A中位于第一行的各矩阵元素分别对应的第一符号数据(即a_sign 00、a_sign 01a_sign 02)以及矩阵B中位于第二列的各矩阵元素分别对应的第一符号数据(即b_sign 01、b_sign 11、b_sign 21),并从第二寄存器14中获取矩阵A中位于第一行的各矩阵元素分别对应的绝对值数据(即a_cvt 00、a_cvt 01、a_cvt 02)以及矩阵B中位于第二列的各矩阵元素 分别对应的绝对值数据(即b_cvt 01、b_cvt 11、b_cvt 21),以计算得到结果矩阵中位于第一行第二列的位置处的矩阵元素。 Similarly, after receiving the enable signal, the calculation circuit 12-2 obtains the first symbol data corresponding to each matrix element in the first row in the matrix A (that is, a_sign 00 , a_sign 01 a_sign 02 , respectively) from the first register 13 ) and the first symbol data corresponding to each matrix element in the second column in matrix B (ie b_sign 01 , b_sign 11 , b_sign 21 ), and obtain each matrix in the first row in matrix A from the second register 14 The absolute value data corresponding to the elements (ie a_cvt 00 , a_cvt 01 , a_cvt 02 ) and the absolute value data corresponding to each matrix element in the second column in matrix B (ie b_cvt 01 , b_cvt 11 , b_cvt 21 ), to calculate Get the matrix element at the position of the first row and second column in the result matrix.
以此类推,计算电路12-9在接收到使能信号后,从第一寄存器13中获取矩阵A中位于第三行的各矩阵元素分别对应的第一符号数据(即a_sign 20、a_sign 21、a_sign 22)以及矩阵B中位于第三列的各矩阵元素分别对应的第一符号数据(即b_sign 02、b_sign 12、b_sign 22),并从第二寄存器14中获取矩阵A中位于第三行的各矩阵元素分别对应的绝对值数据(即a_cvt 20、a_cvt 21、a_cvt 22)以及矩阵B中位于第三列的各矩阵元素分别对应的绝对值数据(即b_cvt 02、b_cvt 12、b_cvt 22),以计算得到结果矩阵中位于第三行第三列位置处的矩阵元素。 By analogy, after the calculation circuit 12-9 receives the enable signal, it obtains the first sign data corresponding to each matrix element in the third row in the matrix A (that is, a_sign 20 , a_sign 21 , a_sign 22 ) and the first sign data (ie b_sign 02 , b_sign 12 , b_sign 22 ) corresponding to each matrix element in the third column in matrix B, and obtain the data in the third row in matrix A from the second register 14 The absolute value data corresponding to each matrix element (ie a_cvt 20 , a_cvt 21 , a_cvt 22 ) and the absolute value data corresponding to each matrix element in the third column in matrix B (ie b_cvt 02 , b_cvt 12 , b_cvt 22 ), To calculate the matrix element at the position of the third row and third column in the result matrix.
图4b示出利用两个数据转化电路11(即第一数据转化电路11-1和第二数据转化电路11-2)分别对对应的待处理数据进行处理时的另一种具体示例的示意图。图4b中除了包含图4a中的多个计算电路12、第一寄存器13和第二寄存器14外,还包括第一数据转化电路11-1以及第二数据转化电路11-2。第一数据转化电路11-1用于接收矩阵A,并将矩阵A中的各矩阵元素分别转化为第一符号数据以及绝对值数据;第二数据转化电路11-2用于接收矩阵B,并将矩阵B中的各矩阵元素分别转化为第一符号数据以及绝对值数据;第一数据转化电路11-1向第一寄存器13传输矩阵A中各矩阵元素对应的第一符号数据,并向第二寄存器14传输矩阵A中各矩阵元素分别对应的绝对值数据;第二数据转化电路11-2向第一寄存器13传输矩阵B中各矩阵元素对应的第一符号数据,并向第二寄存器14传输矩阵B中各矩阵元素分别对应的绝对值数据。图4b中各计算电路12的功能及数据处理流程与图4a中所示的具体实施方式类似,重复之处不再赘述。Fig. 4b shows a schematic diagram of another specific example of using two data conversion circuits 11 (ie, a first data conversion circuit 11-1 and a second data conversion circuit 11-2) to respectively process corresponding data to be processed. In addition to the calculation circuits 12, the first register 13 and the second register 14 in FIG. 4a, FIG. 4b also includes a first data conversion circuit 11-1 and a second data conversion circuit 11-2. The first data conversion circuit 11-1 is used to receive the matrix A, and convert each matrix element in the matrix A into the first symbol data and absolute value data respectively; the second data conversion circuit 11-2 is used to receive the matrix B, and Each matrix element in the matrix B is respectively converted into first symbol data and absolute value data; the first data conversion circuit 11-1 transmits the first symbol data corresponding to each matrix element in the matrix A to the first register 13, and sends the first symbol data to the first register 13 The absolute value data corresponding to each matrix element in the second register 14 transfer matrix A; The second data conversion circuit 11-2 transfers the first symbol data corresponding to each matrix element in the matrix B to the first register 13, and sends to the second register 14 Absolute value data corresponding to each matrix element in the transfer matrix B. The functions and data processing flow of each calculation circuit 12 in FIG. 4b are similar to the specific implementation manner shown in FIG. 4a, and repeated descriptions will not be repeated.
在具体实施中,数据转化电路11包括第一转化电路以及第二转化电路;其中,第一转化电路用于接收待处理数据中预设第一比特位的第一数值;将接收到的第一数值作为第一符号数据;以及向第二转化电路传输第一数值;第二转化电路用于接收待处理数据中预设第二比特位的第二数值,并基于第一转化电路传输的第一数值,对第二数值进行转化处理,得到绝对值数据。In a specific implementation, the data conversion circuit 11 includes a first conversion circuit and a second conversion circuit; wherein, the first conversion circuit is used to receive the first numerical value of the preset first bit in the data to be processed; the received first The value is used as the first symbol data; and the first value is transmitted to the second conversion circuit; the second conversion circuit is used to receive the second value of the preset second bit in the data to be processed, and based on the first value transmitted by the first conversion circuit Value, convert the second value to obtain absolute value data.
其中,预设第一比特位表示符号位,例如矩阵中每个矩阵元素的位宽为n,则预设第一比特位比如可以为第n-1位;预设第二比特位表示数值位,例如位宽为n的矩阵元素中第0~n-2位;示例性的,预设第一比特位的第一数值例如可以包括0和1,其中,0表示正,即待处理数据的预设第一比特位的第一数值包括0时,待处理数据为正值;1表示负,即待处理数据的预设第一比特位的第一数值包括1时,待处理数据为负值。Wherein, the preset first bit represents the sign bit, for example, the bit width of each matrix element in the matrix is n, then the preset first bit can be, for example, the n-1th bit; the preset second bit represents the value bit , for example, bits 0 to n-2 in a matrix element with a bit width of n; for example, the first value of the preset first bit may include 0 and 1, where 0 means positive, that is, the value of the data to be processed When the first value of the preset first bit includes 0, the data to be processed is a positive value; 1 means negative, that is, when the first value of the preset first bit of the data to be processed includes 1, the data to be processed is a negative value .
具体的,数据转化电路11在将待处理数据转化为第一符号数据以及绝对值数据时,为了保证不改变待处理数据在数据转化前后的数值,则需要将为负值的待处理数据中预设第二比特位的第二数值,转化为绝对值数据;第二转化电路包括依次连接的第一加法器、第一取反电路以及第一选择器;第一选择器的输入端与第一转化电路的输出端以及第一取反电路的输出端连接;第一取反电路的输入端与第一加法器的输出端连接。Specifically, when the data conversion circuit 11 converts the data to be processed into the first symbol data and absolute value data, in order to ensure that the values of the data to be processed before and after data conversion are not changed, it is necessary to pre-set The second numerical value of the second bit is set to be converted into absolute value data; the second conversion circuit includes a first adder, a first negation circuit and a first selector connected in sequence; the input terminal of the first selector is connected to the first The output end of the conversion circuit is connected to the output end of the first inversion circuit; the input end of the first inversion circuit is connected to the output end of the first adder.
其中,第一加法器用于响应于接收到待处理数据中预设第二比特位的第二数值,将第二数值和预设数值求和,得到第一中间数值;向第一取反电路传输第一中间数值。Wherein, the first adder is used to respond to receiving the second value of the preset second bit in the data to be processed, sum the second value and the preset value to obtain the first intermediate value; transmit to the first negation circuit first intermediate value.
其中,预设数值例如可以包括1或-1。本公开实施例中,在预设数值包括-1的情况下,利用先将第二数值与预设数值相加,再对相加结果进行按位取反的方式,求第二数值的补码;在预设数值包括1的情况下,利用先将第二数值按位取反,再与预设数值相加的方式,求第二数值的补码;上述两种方式,均可以计算得到第二数值的绝对值,具体的实现方式可以根据实际电路设计需求进行选择,以达到相关目的。下面分别对上述 两种计算第二数值的补码,即计算第二数值的绝对值的方式进行详细描述。Wherein, the preset numerical value may include 1 or -1, for example. In the embodiment of the present disclosure, when the preset value includes -1, the complement of the second value is calculated by first adding the second value to the preset value, and then inverting the addition result bit by bit. ; In the case that the preset value includes 1, use the method of inverting the second value by bit first, and then add it to the preset value to find the complement of the second value; the above two methods can be calculated to obtain the first The absolute value of the binary value, the specific implementation method can be selected according to the actual circuit design requirements, so as to achieve the relevant purpose. The above two methods of calculating the complement of the second value, that is, calculating the absolute value of the second value, will be described in detail below.
在预设数值包括-1的情况下,第一取反电路用于响应于接收到第一加法器传输的第一中间数值,对第一中间数值进行按位取反操作,得到第二中间数值;向第一选择器传输第二中间数值。In the case where the preset value includes -1, the first inverting circuit is configured to perform a bitwise inversion operation on the first intermediate value in response to receiving the first intermediate value transmitted by the first adder to obtain a second intermediate value ;Transfer the second intermediate value to the first selector.
第一选择器用于响应于接收到待处理数据中预设第二比特位的第二数值、第一取反电路传输的第二中间数值以及第一转化电路传输的第一数值,将第一数值作为选择控制信号,控制将第二数值作为绝对值数据输出、或者控制将第二中间数值作为绝对值数据输出。具体的,在第一数值为0的情况下,控制将第二数值作为绝对值数据输出;在第一数值为1的情况下,控制将第二中间数值作为绝对值数据输出。The first selector is used to convert the first value to the first value in response to receiving the second value of the preset second bit in the data to be processed, the second intermediate value transmitted by the first negation circuit, and the first value transmitted by the first conversion circuit As the selection control signal, it controls to output the second numerical value as absolute value data, or controls to output the second intermediate numerical value as absolute value data. Specifically, when the first numerical value is 0, the control outputs the second numerical value as absolute value data; when the first numerical value is 1, the control outputs the second intermediate numerical value as absolute value data.
示例性的,数据转化电路11的具体电路结构图可以如图5所示,数据转化电路11包括第一转化电路和第二转化电路,第二转化电路包括依次连接第一加法器、第一取反电路以及第一选择器;第一转化电路用于接收待处理数据中第n-1位的第一数值(即val[n-1],其中n表征待处理数据所占的位宽),将第n-1位的第一数值作为第一符号数据(即sign)输出,并向第二转化电路中的第一选择器传输该第一数值;第二转化电路中的第一加法器用于接收待处理数据中第n-2位~第0位的第二数值(即val[n-1:0]),并将第二数值和预设数值(比如,-1)相加求和,得到第一中间数值;向第二转化电路中的第一取反电路传输第一中间数值以及向第一选择器传输第二数值;第一取反电路对接收到的第一中间数值进行按位取反,得到第二中间数值,并将该第二中间数值传输至第一选择器;第一选择器用于在接收到第一数值、第二数值以及第二中间数值后,将第一数值作为选择控制信号,控制将第二数值作为绝对值数据(即abs)输出,或控制将第二中间数值作为绝对值数据(即abs)输出。Exemplarily, a specific circuit structure diagram of the data conversion circuit 11 can be shown in FIG. An inverse circuit and a first selector; the first conversion circuit is used to receive the first value of the n-1th bit in the data to be processed (ie val[n-1], where n represents the bit width occupied by the data to be processed), Output the first numerical value of the n-1th bit as the first symbol data (i.e. sign), and transmit the first numerical value to the first selector in the second conversion circuit; the first adder in the second conversion circuit is used for Receive the second value (ie val[n-1:0]) of the n-2th to the 0th bit in the data to be processed, and add the second value and the preset value (for example, -1) and sum them, Obtain the first intermediate value; transmit the first intermediate value to the first negation circuit in the second conversion circuit and transmit the second value to the first selector; the first negation circuit bitwise Inverting to obtain the second intermediate value, and transmitting the second intermediate value to the first selector; the first selector is used to use the first value as Select the control signal to control the output of the second value as absolute value data (ie abs), or to control the output of the second intermediate value as absolute value data (ie abs).
示例性的,图5所示的数据转化电路11对待处理数据进行转化的具体流程如下:若待处理数据包括矩阵A中的矩阵元素a 00=01000101,数据转化电路11中的第一转化电路,接收a 00中第7位的第一数值0,将接收到的第一数值作为第一符号数据,并向第二转化电路传输第一数值。 Exemplarily, the specific process of converting the data to be processed by the data conversion circuit 11 shown in FIG. Receive the first value 0 of the seventh bit in a 00 , use the received first value as the first symbol data, and transmit the first value to the second conversion circuit.
第二转化电路中的第一加法器响应于接收到a 00中的第6~0位的第二数值1000101,将第二数值和预设数值-1求和,得到第一中间数值1000100;向第二转化电路中的第一取反电路传输该第一中间数值。 The first adder in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a 00 , sums the second value and the preset value -1 to obtain the first intermediate value 1000100; The first inverting circuit in the second conversion circuit transmits the first intermediate value.
第一取反电路响应于接收到第一中间数值,对第一中间数值进行按位取反操作,得到第二中间数值0111011;向第一选择器传输该第二中间数值。In response to receiving the first intermediate value, the first inversion circuit performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value 0111011; and transmits the second intermediate value to the first selector.
第一选择器响应于接收到第一数值0、第二数值1000101以及第二中间数值0111011,将第一数值0作为选择控制信号,由于第一数值为0时,待处理数据本身为正值,则其预设第二比特位的第二数值本身即为绝对值,因此,控制将第二数值1000101作为绝对值数据输出。In response to receiving the first value 0, the second value 1000101, and the second intermediate value 0111011, the first selector uses the first value 0 as a selection control signal. Since the first value is 0, the data to be processed itself is a positive value. Then, the second numerical value of the preset second bit itself is an absolute value, therefore, the control outputs the second numerical value 1000101 as absolute value data.
另外,若待处理数据包括矩阵A中的矩阵元素a 01=11000101,数据转化电路11中的第一转化电路,接收a 01中第7位的第一数值1,将接收到的第一数值作为第一符号数据,并向第二转化电路传输第一数值。 In addition, if the data to be processed includes the matrix element a 01 =11000101 in the matrix A, the first conversion circuit in the data conversion circuit 11 receives the first numerical value 1 of the 7th bit in a 01 , and uses the received first numerical value as The first symbol data, and transmit the first value to the second conversion circuit.
第二转化电路中的第一加法器响应于接收到a 01中的第6~0位的第二数值1000101,将第二数值和预设数值-1求和,得到第一中间数值1000100;向第二转化电路中的第一取反电路传输该第一中间数值。 The first adder in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a01 , sums the second value and the preset value -1 to obtain the first intermediate value 1000100; The first inverting circuit in the second conversion circuit transmits the first intermediate value.
第一取反电路响应于接收到第一中间数值,对第一中间数值进行按位取反操作,得 到第二中间数值0111011;向第一选择器传输该第二中间数值。In response to receiving the first intermediate value, the first inversion circuit performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value 0111011; and transmits the second intermediate value to the first selector.
第一选择器响应于接收到第一数值1、第二数值1000101以及第二中间数值0111011,将第一数值1作为选择控制信号,由于第一数值为1时,待处理数据本身为负值,因此,控制将第二中间数值0111011作为绝对值数据输出。In response to receiving the first value 1, the second value 1000101 and the second intermediate value 0111011, the first selector uses the first value 1 as a selection control signal. Since the first value is 1, the data to be processed itself is a negative value. Therefore, the control outputs the second intermediate value 0111011 as absolute value data.
在另一种可能的实施方式中,在预设数值包括1的情况下,第二转化电路还可以包括依次连接的第一取反电路、第一加法器以及第一选择器;其中,第一取反电路的输出端与第一加法器的输入端连接,第一加法器的输出端与第一选择器的输入端连接。In another possible implementation manner, when the preset value includes 1, the second conversion circuit may further include a first negation circuit, a first adder, and a first selector connected in sequence; wherein, the first The output end of the negation circuit is connected to the input end of the first adder, and the output end of the first adder is connected to the input end of the first selector.
第一取反电路用于响应于接收到待处理数据中预设第二比特位的第二数值,将第二数值进行按位取反操作,得到第一中间数值;向第一加法器传输第一中间数值。The first inversion circuit is configured to perform a bitwise inversion operation on the second value to obtain a first intermediate value in response to receiving a second value preset in a second bit in the data to be processed; and transmit the second value to the first adder. an intermediate value.
第一加法器用于响应于接收第一取反电路传输的第一中间数值,将第一中间数值与预设数值1求和,得到第二中间数值;向第一选择器传输第二中间数值。The first adder is used for receiving the first intermediate value transmitted by the first negation circuit, summing the first intermediate value and the preset value 1 to obtain a second intermediate value; and transmitting the second intermediate value to the first selector.
第一选择器用于响应于接收到待处理数据中预设第二比特位的第二数值、第一加法器传输的第二中间数值以及第一转化电路传输的第一数值,将第一数值作为选择控制信号,控制将第二数值作为绝对值数据输出、或者控制将第二中间数值作为绝对值数据输出。具体的,在第一数值为0的情况下,控制将第二数值作为绝对值数据输出;在第一数值为1的情况下,控制将第二中间数值作为绝对值数据输出。The first selector is configured to take the first value as The control signal is selected to control the output of the second value as absolute value data, or to control the output of the second intermediate value as absolute value data. Specifically, when the first numerical value is 0, the control outputs the second numerical value as absolute value data; when the first numerical value is 1, the control outputs the second intermediate numerical value as absolute value data.
示例性的,数据转化电路11的具体电路结构图可以如图6所示,数据转化电路11包括第一转化电路和第二转化电路,第二转化电路包括依次连接第一取反电路、第一加法器和第一选择器;第一转化电路用于接收待处理数据中第n-1位的第一数值(即val[n-1],其中n表征待处理数据所占的位宽),将第n-1位的第一数值作为第一符号数据(即sign)输出,并向第二转化电路中的第一选择器传输该第一数值;第二转化电路中的第一取反电路接收待处理数据中第n-2位~第0位的第二数值(即val[n-1:0]),并对第二数值进行按位取反,得到第一中间数值;向第一加法器传输该第一中间数值以及向第一选择器传输第二数值;第一加法器接收到第一中间数值后,将第一中间数值和预设数值(比如:1)相加求和,得到第二中间数值;向第一选择器传输第二中间数值;第一选择器用于在接收到第一数值、第二数值以及第二中间数值后,将第一数值作为选择控制信号,控制将第二数值作为绝对值数据(即abs)输出,或控制将第二中间数值作为绝对值数据(即abs)输出。Exemplarily, the specific circuit structure diagram of the data conversion circuit 11 can be shown in Figure 6, the data conversion circuit 11 includes a first conversion circuit and a second conversion circuit, and the second conversion circuit includes sequentially connecting the first inverting circuit, the first An adder and a first selector; the first conversion circuit is used to receive the first numerical value of the n-1th bit in the data to be processed (ie val[n-1], wherein n represents the bit width occupied by the data to be processed), Output the first numerical value of the n-1th bit as the first symbol data (i.e. sign), and transmit the first numerical value to the first selector in the second conversion circuit; the first negation circuit in the second conversion circuit Receive the second numerical value (ie val[n-1:0]) of the n-2th bit to the 0th bit in the data to be processed, and perform bitwise inversion on the second numerical value to obtain the first intermediate value; The adder transmits the first intermediate value and transmits the second value to the first selector; after the first adder receives the first intermediate value, it adds and sums the first intermediate value and a preset value (for example: 1), Obtain the second intermediate value; transmit the second intermediate value to the first selector; the first selector is used to use the first value as a selection control signal after receiving the first value, the second value and the second intermediate value, and the control will The second numerical value is output as absolute value data (ie, abs), or the second intermediate value is output as absolute value data (ie, abs).
数据转化电路11对待处理数据进行转化的具体流程如下:若待处理数据包括矩阵A中的矩阵元素a 00=01000101,数据转化电路11中的第一转化电路,接收a 00中第7位的第一数值0,将接收到的第一数值作为第一符号数据,并向第二转化电路传输第一数值。 The concrete process that data conversion circuit 11 converts data to be processed is as follows: if data to be processed comprises matrix element a00 =01000101 in matrix A, the first conversion circuit in data conversion circuit 11 receives the 7th bit in a00 A value of 0, the received first value is used as the first symbol data, and the first value is transmitted to the second conversion circuit.
第二转化电路中的第一取反电路,响应于接收到a 00中的第6~0位的第二数值1000101,将第二数值进行按位取反操作,得到第一中间数值0111010;向第二转化电路中的第一加法器传输该第一中间数值。 The first inversion circuit in the second conversion circuit, in response to receiving the second value 1000101 of the 6th to 0th bits in a 00 , performs a bitwise inversion operation on the second value to obtain the first intermediate value 0111010; The first adder in the second conversion circuit transmits the first intermediate value.
第一加法器响应于接收到第一中间数值,将第一中间数值与预设数值1相加,得到第二中间数值0111011;向第一选择器传输该第二中间数值。In response to receiving the first intermediate value, the first adder adds the first intermediate value to a preset value 1 to obtain a second intermediate value 0111011; transmits the second intermediate value to the first selector.
第一选择器,响应于接收到第一数值0、第二数值1000101以及第二中间数值0111011,将第一数值0作为选择控制信号,由于第一数值为0时,待处理数据本身为正值,则其预设第二比特位的第二数值本身即为绝对值,因此,控制将第二数值1000101作为绝对值数据输出。The first selector, in response to receiving the first value 0, the second value 1000101 and the second intermediate value 0111011, uses the first value 0 as a selection control signal, because when the first value is 0, the data to be processed itself is a positive value , then the second value of the preset second bit itself is an absolute value, therefore, the control outputs the second value 1000101 as absolute value data.
另外,若待处理数据包括矩阵A中的矩阵元素a 01=11000101,数据转化电路11中 的第一转化电路,接收a 01中第7位的第一数值1,将接收到的第一数值作为第一符号数据,并向第二转化电路传输第一数值。 In addition, if the data to be processed includes the matrix element a 01 =11000101 in the matrix A, the first conversion circuit in the data conversion circuit 11 receives the first numerical value 1 of the 7th bit in a 01 , and uses the received first numerical value as The first symbol data, and transmit the first value to the second converting circuit.
第二转化电路中的第一取反电路响应于接收到a 01中的第6~0位的第二数值1000101,将第二数值进行按位取反操作,得到第一中间数值0111010;向第二转化电路中的第一加法器传输该第一中间数值。 The first inversion circuit in the second conversion circuit responds to receiving the second value 1000101 of the 6th to 0th bits in a 01 , and performs a bitwise inversion operation on the second value to obtain the first intermediate value 0111010; The first adder in the conversion circuit transmits the first intermediate value.
第一加法器响应于接收到第一中间数值,对第一中间数值与预设数值1相加,得到第二中间数值0111011;向第一选择器传输该第二中间数值。In response to receiving the first intermediate value, the first adder adds the first intermediate value to a preset value 1 to obtain a second intermediate value 0111011; transmits the second intermediate value to the first selector.
第一选择器,响应于接收到第一数值1、第二数值1000101以及第二中间数值0111011,将第一数值1作为选择控制信号,由于第一数值为1时,待处理数据本身为负值,因此,控制将第二中间数值0111011作为绝对值数据输出。The first selector, in response to receiving the first value 1, the second value 1000101 and the second intermediate value 0111011, uses the first value 1 as a selection control signal, because when the first value is 1, the data to be processed itself is a negative value , therefore, the control outputs the second intermediate value 0111011 as absolute value data.
在具体实施中,数据转化电路11将待处理数据转化为第一符号数据和绝对值数据后,可以将第一符号数据和绝对值数据传输至计算电路12,以对待处理数据进行处理。In a specific implementation, after the data conversion circuit 11 converts the data to be processed into first sign data and absolute value data, the first sign data and absolute value data may be transmitted to the calculation circuit 12 for processing the data to be processed.
具体的,计算电路12可以包括符号运算电路、第一数值运算电路以及第二数值运算电路;其中,符号运算电路的输出端与第二数值运算电路的输入端连接;第一数值运算电路的输出端与第二数值运算电路的输入端连接;符号运算电路,用于响应于获取到第一符号数据,并基于第一符号数据,确定第一中间计算结果的第二符号数据;向第二数值运算电路传输第二符号数据。Specifically, the calculation circuit 12 may include a symbolic operation circuit, a first numerical operation circuit, and a second numerical operation circuit; wherein, the output terminal of the symbolic operation circuit is connected to the input end of the second numerical operation circuit; the output of the first numerical operation circuit The terminal is connected to the input terminal of the second numerical operation circuit; the symbolic operation circuit is used to respond to the acquisition of the first symbolic data, and based on the first symbolic data, determine the second symbolic data of the first intermediate calculation result; The operation circuit transmits the second symbol data.
第一数值运算电路用于响应于获取到绝对值数据,对绝对值数据进行第一运算处理,得到第一中间计算结果;向第二数值运算电路传输第一中间计算结果。The first numerical operation circuit is used for performing first operation processing on the absolute value data in response to the acquired absolute value data to obtain a first intermediate calculation result; and transmitting the first intermediate calculation result to the second numerical operation circuit.
第二数值运算电路用于响应于接收到符号运算电路传输的第二符号数据以及第一数值运算电路传输的第一中间计算结果,基于第二符号数据以及第一中间计算结果,进行第二运算处理,得到待处理数据的目标处理结果。The second numerical operation circuit is configured to perform a second operation based on the second symbolic data and the first intermediate calculation result in response to receiving the second symbol data transmitted by the symbol operation circuit and the first intermediate calculation result transmitted by the first numerical operation circuit Processing to obtain the target processing result of the data to be processed.
其中,第一运算处理包括乘法处理;第二运算处理包括加法处理;待处理数据包括第一待处理数据和第二待处理数据;第一待处理数据包括多个第一子数据;第二待处理数据包括多个与第一子数据分别对应的第二子数据;第一符号数据包括第一子数据的第一符号数据以及与第一子数据分别对应的第二子数据的第一符号数据。Wherein, the first operation processing includes multiplication processing; the second operation processing includes addition processing; the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; The processed data includes a plurality of second sub-data respectively corresponding to the first sub-data; the first symbol data includes first symbol data of the first sub-data and first symbol data of the second sub-data respectively corresponding to the first sub-data .
符号运算电路包括异或门电路;该异或门电路用于针对每个第一子数据,将每个第一子数据的第一符号数据和对应的第二子数据的第一符号数据进行异或处理,得到将每个第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果的第二符号数据。The symbol operation circuit includes an XOR gate circuit; the XOR gate circuit is used for performing exclusive OR gates on the first symbol data of each first sub-data and the first symbol data of the corresponding second sub-data for each first sub-data. or processing to obtain the second sign data of the first intermediate calculation result obtained by multiplying each first sub-data and the corresponding second sub-data.
示例性的,第一待处理数据包括矩阵Exemplarily, the first data to be processed includes matrix
Figure PCTCN2022124516-appb-000007
Figure PCTCN2022124516-appb-000007
其中第一子数据包括矩阵A中的各个矩阵元素,即a 00、a 01、a 02、a 10、a 11、a 12、a 20、a 21、a 22;各第一子数据的第一符号数据包括a_sign 00、a_sign 01、a_sign 02、a_sign 10、a_sign 11、a_sign 12、a_sign 20、a_sign 21、a_sign 22Wherein the first sub-data includes each matrix element in matrix A, namely a 00 , a 01 , a 02 , a 10 , a 11 , a 12 , a 20 , a 21 , a 22 ; The sign data includes a_sign 00 , a_sign 01 , a_sign 02 , a_sign 10 , a_sign 11 , a_sign 12 , a_sign 20 , a_sign 21 , a_sign 22 .
第二待处理数据包括矩阵The second pending data includes matrix
Figure PCTCN2022124516-appb-000008
Figure PCTCN2022124516-appb-000008
其中,第二子数据包括矩阵B中的各个矩阵元素,即b 00、b 01、b 02、b 10、b 11、b 12、b 20、b 21、b 22;多个第一子数据分别对应的各第二子数据的第一符号数据为b_sign 00、b_sign 01、b_sign 02、b_sign 10、b_sign 11、b_sign 12、b_sign 20、b_sign 21、b_sign 22Wherein, the second sub-data includes each matrix element in the matrix B, namely b 00 , b 01 , b 02 , b 10 , b 11 , b 12 , b 20 , b 21 , b 22 ; the multiple first sub-data are respectively The corresponding first sign data of each second sub-data is b_sign 00 , b_sign 01 , b_sign 02 , b_sign 10 , b_sign 11 , b_sign 12 , b_sign 20 , b_sign 21 , b_sign 22 .
本公开实施例应用在对矩阵A和矩阵B进行矩阵乘法运算,在运算过程中,符号运算电路中的异或门电路,用于针对矩阵A中的每个第一子数据,将该第一子数据的第一符号数据、与矩阵B中与该第一子数据相乘的第二子数据的第一符号数据进行异或处理,得到将该第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果的第二符号数据。The embodiment of the present disclosure is applied to perform matrix multiplication operation on matrix A and matrix B. During the operation process, the XOR gate circuit in the symbol operation circuit is used to, for each first sub-data in matrix A, convert the first The first symbol data of the sub-data and the first symbol data of the second sub-data multiplied by the first sub-data in matrix B are subjected to XOR processing to obtain the first sub-data and the corresponding second sub-data The second sign data of the first intermediate calculation result obtained after the multiplication process.
比如,在矩阵乘法运算过程中,符号运算电路可以将矩阵A中位于第一行的各第一子数据的第一符号数据与矩阵B中的位于第一列的对应的各第二子数据的第二符号数据进行异或处理,得到第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果的第二符号数据;即将
Figure PCTCN2022124516-appb-000009
确定为将a 00和b 00进行乘法处理后得到的第一中间计算结果的第二符号数据;将
Figure PCTCN2022124516-appb-000010
确定为将a 01和b 10进行乘法处理后得到的第一中间计算结果的第二符号数据;将
Figure PCTCN2022124516-appb-000011
确定为将a 02和b 20进行乘法处理后得到的第一中间计算结果的第二符号数据。
For example, during the matrix multiplication operation, the symbol operation circuit can combine the first symbol data of each first sub-data in the first row in matrix A with the corresponding second sub-data in the first column in matrix B Exclusive OR processing is performed on the second symbol data to obtain the second symbol data of the first intermediate calculation result obtained after the first sub-data and the corresponding second sub-data are multiplied;
Figure PCTCN2022124516-appb-000009
Determined as the second symbol data of the first intermediate calculation result obtained after multiplication of a 00 and b 00 ;
Figure PCTCN2022124516-appb-000010
Determined as the second symbol data of the first intermediate calculation result obtained after multiplication of a 01 and b 10 ;
Figure PCTCN2022124516-appb-000011
It is determined as the second sign data of the first intermediate calculation result obtained by multiplying a 02 and b 20 .
在具体实施中,在待处理数据包括第一待处理数据和第二待处理数据的情况下,绝对值数据包括第一待处理数据中每个第一子数据对应的第一绝对值数据以及第二待处理数据中与每个第一子数据对应的第二子数据对应的第二绝对值数据;第一数值运算电路包括乘法器,该乘法器用于针对每个第一子数据,将每个第一子数据的第一绝对值数据和对应第二子数据的第二绝对值数据进行乘积运算,得到每个第一子数据对应的第一中间计算结果。In a specific implementation, when the data to be processed includes the first data to be processed and the second data to be processed, the absolute value data includes the first absolute value data corresponding to each first sub-data in the first data to be processed and the first absolute value data corresponding to the second Second absolute value data corresponding to the second sub-data corresponding to each first sub-data in the data to be processed; the first numerical operation circuit includes a multiplier, and the multiplier is used for each first sub-data, each A product operation is performed on the first absolute value data of the first sub-data and the second absolute value data corresponding to the second sub-data to obtain a first intermediate calculation result corresponding to each first sub-data.
示例性的,第一待处理数据包括矩阵Exemplarily, the first data to be processed includes matrix
Figure PCTCN2022124516-appb-000012
Figure PCTCN2022124516-appb-000012
其中第一子数据包括矩阵A中的各个矩阵元素,即
Figure PCTCN2022124516-appb-000013
各第一子数据的第一绝对值数据包括a_ctv 00、a_ctv 01、a_ctv 02、a_ctv 10、a_ctv 11、a_ctv 12、a_ctv 20、a_ctv 21、a_ctv 22
Wherein the first sub-data includes each matrix element in the matrix A, namely
Figure PCTCN2022124516-appb-000013
The first absolute value data of each first sub-data includes a_ctv 00 , a_ctv 01 , a_ctv 02 , a_ctv 10 , a_ctv 11 , a_ctv 12 , a_ctv 20 , a_ctv 21 , a_ctv 22 .
第二待处理数据包括矩阵The second pending data includes matrix
Figure PCTCN2022124516-appb-000014
Figure PCTCN2022124516-appb-000014
其中,第二子数据包括矩阵B中的各个矩阵元素,即b 00、b 01、b 02、b 10、b 11、b 12、b 20、b 21、b 22;各第二子数据的第二绝对值数据包括b_ctv 00、b_ctv 01、b_ctv 02、b_ctv 10、b_ctv 11、b_ctv 12、b_ctv 20、b_ctv 21、b_ctv 22Wherein, the second sub-data includes each matrix element in the matrix B, namely b 00 , b 01 , b 02 , b 10 , b 11 , b 12 , b 20 , b 21 , b 22 ; The two absolute value data include b_ctv 00 , b_ctv 01 , b_ctv 02 , b_ctv 10 , b_ctv 11 , b_ctv 12 , b_ctv 20 , b_ctv 21 , b_ctv 22 .
本公开实施例应用在对矩阵A和矩阵B进行矩阵乘法运算,在运算过程中,第一数值运算电路中的乘法器用于针对矩阵A中的每个第一子数据,将该第一子数据的第一 绝对值数据与矩阵B中与该第一子数据相乘的第二子数据的第二绝对值数据进行乘积运算,得到将该第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果。The embodiment of the present disclosure is applied to perform matrix multiplication operation on matrix A and matrix B. During the operation, the multiplier in the first numerical operation circuit is used for each first sub-data in matrix A, and the first sub-data The first absolute value data of the matrix B is multiplied with the second absolute value data of the second sub-data multiplied by the first sub-data to obtain the multiplication process of the first sub-data and the corresponding second sub-data The first intermediate calculation result obtained after.
比如,在矩阵乘法运算过程中,第一数值运算电路中的乘法器可以用于将矩阵A中位于第一行的各第一子数据的第一绝对值数据、与矩阵B中位于第一列的对应的各第二子数据的第二绝对值数据进行乘积运算,得到第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果;即将a_ctv 00×b_ctv 00确定为将a 00和b 00进行乘法处理后得到的第一中间计算结果;将a_ctv 01×b_ctv 10确定为将a 01和b 10进行乘法处理后得到的第一中间计算结果;将a_ctv 02×b_ctv 20确定为将a 02和b 20进行乘法处理后得到的第一中间计算结果。 For example, in the process of matrix multiplication, the multiplier in the first numerical operation circuit can be used to combine the first absolute value data of each first sub-data in the first row in matrix A with the first absolute value data in the first column in matrix B The second absolute value data of the corresponding second sub-data is multiplied to obtain the first intermediate calculation result obtained after the first sub-data and the corresponding second sub-data are multiplied; that is, a_ctv 00 × b_ctv 00 is determined as The first intermediate calculation result after multiplying a 00 and b 00 ; determine a_ctv 01 × b_ctv 10 as the first intermediate calculation result after multiplying a 01 and b 10 ; set a_ctv 02 × b_ctv 20 It is determined as the first intermediate calculation result obtained after multiplying a 02 and b 20 .
在具体实施中,第二数值运算电路包括第二取反电路、第二选择器、第二加法器以及第三加法器;其中,第二取反电路的输入端与第一数值运算电路的输出端连接;第二选择器的输入端分别与第二取反电路的输出端、符号运算电路的输出端以及第一数值运算电路的输出端连接;第二加法器的输入端与符号运算电路的输出端连接;第三加法器的输入端分别与第二选择器的输出端以及第二加法器的输出端连接。In a specific implementation, the second numerical operation circuit includes a second negation circuit, a second selector, a second adder, and a third adder; wherein, the input terminal of the second inversion circuit is connected to the output of the first numerical operation circuit The input end of the second selector is respectively connected with the output end of the second negation circuit, the output end of the sign operation circuit and the output end of the first numerical operation circuit; the input end of the second adder is connected with the output end of the sign operation circuit The output terminal is connected; the input terminal of the third adder is respectively connected with the output terminal of the second selector and the output terminal of the second adder.
其中,第二取反电路用于接收第一数值运算电路传输的每个第一子数据对应的第一中间计算结果,并对每个第一子数据对应的第一中间计算结果进行按位取反操作,得到每个第一子数据对应的第二中间计算结果,并向第二选择器传输每个第一子数据对应的第二中间计算结果。Wherein, the second negation circuit is used to receive the first intermediate calculation result corresponding to each first sub-data transmitted by the first numerical operation circuit, and perform bitwise fetching on the first intermediate calculation result corresponding to each first sub-data The reverse operation is performed to obtain the second intermediate calculation result corresponding to each first sub-data, and transmit the second intermediate calculation result corresponding to each first sub-data to the second selector.
第二选择器用于响应于接收到符号运算电路传输的每个第一子数据对应的第一中间计算结果的第二符号数据、第二取反电路传输的每个第一子数据对应的第二中间计算结果以及第一数值运算电路传输的每个第一子数据对应的第一中间计算结果,将第二符号数据作为选择控制信号,控制将每个第一子数据对应的第一中间计算结果作为该第一子数据对应的第三中间计算结果输出,或者,控制将每个第一子数据对应的第二中间计算结果作为该第一子数据对应的第三中间计算结果输出;向第三加法器传输每个第一子数据对应的第三中间计算结果。具体的,在第二符号数据为0的情况下,控制将每个第一子数据对应的第一中间计算结果作为该第一子数据对应的第三中间计算结果输出;在第二符号数据为1的情况下,控制将每个第一子数据对应的第二中间计算结果作为该第一子数据对应的第三中间计算结果输出。The second selector is used to respond to receiving the second symbol data of the first intermediate calculation result corresponding to each first sub-data transmitted by the symbol operation circuit, and the second symbol data corresponding to each first sub-data transmitted by the second negation circuit. The intermediate calculation results and the first intermediate calculation results corresponding to each first sub-data transmitted by the first numerical operation circuit use the second symbol data as a selection control signal to control the first intermediate calculation results corresponding to each first sub-data Output as the third intermediate calculation result corresponding to the first sub-data, or control to output the second intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data; to the third The adder transmits the third intermediate calculation result corresponding to each first sub-data. Specifically, when the second symbol data is 0, the control outputs the first intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data; when the second symbol data is In the case of 1, the control outputs the second intermediate calculation result corresponding to each first sub-data as the third intermediate calculation result corresponding to the first sub-data.
第二加法器用于响应于接收符号运算电路传输的每个第一子数据对应的第一中间计算结果的第二符号数据,对每个第一子数据对应的第一中间计算结果的第二符号数据进行求和,得到第四中间计算结果;向第三加法器传输第四中间计算结果。The second adder is configured to respond to the second symbol data of the first intermediate calculation result corresponding to each first sub-data transmitted by the receiving symbol operation circuit, and calculate the second symbol of the first intermediate calculation result corresponding to each first sub-data The data are summed to obtain a fourth intermediate calculation result; and the fourth intermediate calculation result is transmitted to the third adder.
第三加法器用于响应于接收到每个第一子数据对应的第三中间计算结果以及第四中间计算结果,对每个第一子数据对应的第三中间计算结果和第四中间计算结果求和,得到目标处理结果。The third adder is configured to calculate the third intermediate calculation result and the fourth intermediate calculation result corresponding to each first sub-data in response to receiving the third intermediate calculation result and the fourth intermediate calculation result corresponding to each first sub-data. And, get the target processing result.
这样,无需将每个第一子数据和对应的第二子数据进行乘法处理后得到的为负值的计算结果分别与预设数值(即1)之间的加法处理操作,仅需要通过将每个第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果对应的第二符号数据相加,得到第四中间计算结果;并将第四中间计算结果与每个第一子数据和对应的第二子数据进行乘法处理后得到的第三中间计算结果相加,即可得到待处理数据的目标处理结果;可见,该过程减少了加法运算的次数,减少了电路中加法器的部署,进一步简化了电路结构,从而减少了矩阵乘法运算电路在芯片中占据的空间。In this way, there is no need to perform addition processing operations between the negative calculation results obtained after multiplying each first sub-data and the corresponding second sub-data and the preset value (ie 1), only by multiplying each Add the second symbol data corresponding to the first intermediate calculation result obtained after multiplying the first sub-data and the corresponding second sub-data to obtain the fourth intermediate calculation result; and combine the fourth intermediate calculation result with each of the first intermediate calculation results The third intermediate calculation result obtained after the multiplication of the first sub-data and the corresponding second sub-data is added, and the target processing result of the data to be processed can be obtained; it can be seen that this process reduces the number of addition operations and reduces the number of calculations in the circuit. The deployment of the adder further simplifies the circuit structure, thereby reducing the space occupied by the matrix multiplication operation circuit in the chip.
示例性的,第二数值运算电路的结构示意图可以如图7所示。第二数值运算电路包 括第二加法器、第二取反电路、第二选择器以及第三加法器;其中,第二加法器用于接收符号运算电路传输的将每个第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果的第二符号数据(即res_sign,比如可以包括res_sign0、res_sign1、...、res_signm,其中,m表示在矩阵乘法运算过程中,结果矩阵中矩阵元素的个数),并将作为乘数的矩阵中第i行的各矩阵元素对应的第二符号数据相加,得到第四中间计算结果(即add_sign);向第三加法器传输该第四中间计算结果;第二取反电路用于接收第一数值运算电路(比如乘法器)传输的将每个第一子数据和对应的第二子数据进行乘法处理后得到的第一中间计算结果(即res_val,比如可以包括res_val0、res_val1、...、res_valm,其中,m表示在矩阵乘法运算过程中,结果矩阵中矩阵元素的个数),并对第一中间计算结果进行按位取反,得到第二中间计算结果;向第二选择器传输第二中间计算结果;第二选择器在接收到第二符号数据、第一中间计算结果以及第二中间计算结果后,将第二符号数据作为选择控制信号,控制将第一中间计算结果或者第二中间计算结果作为第三中间计算结果输出;向第三加法器传输该第三中间计算结果;第三加法器在接收到第三中间计算结果、第四中间计算结果之后,将第三中间计算结果、与第四中间计算结果相加,得到结果矩阵中矩阵元素(即mul_val,比如可以包括mul_val00、mul_val01、...、mul_valNM,其中,N表示在矩阵乘法运算过程中,作为乘数的矩阵的行数,M表示在矩阵乘法运算过程中,作为被乘数的矩阵的列数)。Exemplarily, a schematic structural diagram of the second numerical operation circuit may be shown in FIG. 7 . The second numerical operation circuit includes a second adder, a second inverting circuit, a second selector, and a third adder; wherein, the second adder is used to receive each first sub-data and the corresponding The second sign data (i.e. res_sign) of the first intermediate calculation result obtained after the second sub-data is multiplied, for example, may include res_sign0, res_sign1, ..., res_signm, where m represents the result matrix in the matrix multiplication operation process The number of matrix elements in the middle), and the second symbol data corresponding to each matrix element in the i-th row in the matrix as the multiplier is added to obtain the fourth intermediate calculation result (i.e. add_sign); transmit this to the third adder The fourth intermediate calculation result; the second negation circuit is used to receive the first intermediate calculation obtained by multiplying each first sub-data and the corresponding second sub-data transmitted by the first numerical operation circuit (such as a multiplier) Result (that is, res_val, such as may include res_val0, res_val1, ..., res_valm, wherein m represents the number of matrix elements in the result matrix during the matrix multiplication operation), and perform bitwise fetching of the first intermediate calculation result On the contrary, the second intermediate calculation result is obtained; the second intermediate calculation result is transmitted to the second selector; after the second selector receives the second symbol data, the first intermediate calculation result and the second intermediate calculation result, the second symbol The data is used as a selection control signal to control the output of the first intermediate calculation result or the second intermediate calculation result as the third intermediate calculation result; transmit the third intermediate calculation result to the third adder; the third adder receives the third intermediate calculation result After the calculation result and the fourth intermediate calculation result, add the third intermediate calculation result and the fourth intermediate calculation result to obtain the matrix elements in the result matrix (ie mul_val, for example, may include mul_val00, mul_val01, ..., mul_valNM, where , N represents the number of rows of the matrix as the multiplier during the matrix multiplication operation, and M represents the number of columns of the matrix as the multiplicand during the matrix multiplication operation).
示例性的,具体的第二数值运算电路进行数值运算的过程可以如下所示:以对第一待处理数据为矩阵A和第二待处理数据为矩阵B,计算将矩阵A中位于第一行的各个矩阵元素与对应的矩阵B中位于第一列的对应的各个矩阵元素相乘,得到结果矩阵中位于第一行第一列位置处的矩阵元素的运算过程为例;若通过乘法器,确定的a 00和b 00进行乘法处理后得到的第一中间计算结果为1000111,第二取反电路在接收到该第一中间计算结果后,对该第一中间计算结果进行按位取反操作,得到a 00对应的第二中间计算结果0111000;若通过乘法器,确定的a 01和b 10进行乘法处理后得到的第一中间计算结果为0100011,第二取反电路在接收到该第一中间计算结果后,对该第一中间计算结果进行按位取反操作,得到a 01对应的第二中间计算结果1011100;若通过乘法器,确定的a 02和b 20进行乘法处理后得到的第一中间计算结果为0100011,第二取反电路在接收到该第一中间计算结果后,对该第一中间计算结果进行按位取反操作,得到a 02对应的第二中间计算结果1011100。 Exemplarily, the specific numerical operation process of the second numerical operation circuit can be shown as follows: take the first data to be processed as matrix A and the second data to be processed as matrix B, calculate the matrix A in the first row Each matrix element of is multiplied with each corresponding matrix element in the first column in the corresponding matrix B to obtain the operation process of the matrix element at the first row and first column position in the result matrix as an example; if through the multiplier, After the determined a 00 and b 00 are multiplied, the first intermediate calculation result obtained is 1000111, and the second inversion circuit performs a bitwise inversion operation on the first intermediate calculation result after receiving the first intermediate calculation result , to obtain the second intermediate calculation result 0111000 corresponding to a 00 ; if through the multiplier, the first intermediate calculation result obtained after the multiplication of a 01 and b 10 determined is 0100011, the second negation circuit receives the first After the intermediate calculation result, the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1011100 corresponding to a 01 ; if the multiplier is used, the determined a 02 and b 20 are multiplied to obtain the first An intermediate calculation result is 0100011. After receiving the first intermediate calculation result, the second inversion circuit performs a bitwise inversion operation on the first intermediate calculation result to obtain a second intermediate calculation result 1011100 corresponding to a 02 .
若a 00的符号位对应的第一符号数据包括0,a 01的符号位对应的第一符号数据包括1,a 02的符号位对应的第一符号数据包括0;b 00的符号位对应的第一符号数据包括1,b 10的符号位对应的第一符号数据包括1,b 20的符号位对应的第一符号数据包括0。 If the first sign data corresponding to the sign bit of a 00 includes 0, the first sign data corresponding to the sign bit of a 01 includes 1, the first sign data corresponding to the sign bit of a 02 includes 0; the sign bit of b 00 corresponds to The first sign data includes 1, the first sign data corresponding to the sign bit of b 10 includes 1, and the first sign data corresponding to the sign bit of b 20 includes 0.
符号运算电路将a 00的第一符号数据和b 00的第一符号数据进行异或处理,得到将a 00和对应的b 00进行乘法处理后得到的第一中间计算结果的第二符号数据1;同理,符号运算电路将a 01的第一符号数据和b 10的第一符号数据进行异或处理,得到将a 01和对应的b 10进行乘法处理后得到的第一中间计算结果的第二符号数据0;同理,符号运算电路将a 02的第一符号数据和b 20的第一符号数据进行异或处理,得到a 02和b 20进行乘法处理后得到的第一中间计算结果的第二符号数据0;符号运算电路将上述三个第一中间计算结果分别对应的第二符号数据传输至第二加法器以及第二选择器。 The sign operation circuit performs XOR processing on the first sign data of a 00 and the first sign data of b 00 to obtain the second sign data 1 of the first intermediate calculation result obtained by multiplying a 00 and the corresponding b 00 ; Similarly, the sign operation circuit performs XOR processing on the first sign data of a 01 and the first sign data of b 10 , and obtains the first intermediate calculation result obtained after multiplying a 01 and the corresponding b 10 Two symbol data 0; similarly, the symbol operation circuit performs XOR processing on the first symbol data of a 02 and the first symbol data of b 20 , and obtains the first intermediate calculation result obtained after the multiplication processing of a 02 and b 20 The second sign data 0; the sign operation circuit transmits the second sign data respectively corresponding to the three first intermediate calculation results to the second adder and the second selector.
第二选择器在接收到将a 00和b 00进行乘法处理后得到的第一中间计算结果1000111、对该第一中间计算结果进行按位取反后得到的第二中间计算结果0111000以及将a 00和 对应的b 00进行乘法处理后得到的第一中间计算结果的第二符号数据1后,将第二符号数据1作为选择控制信号,由于第二符号数据为1时,表征将a 00和b 00进行乘法处理后得到的第一中间计算结果为负值,因此,控制将对第一中间结果进行按位取反后得到的第二中间计算结果0111000作为第三中间计算结果输出。 The second selector receives the first intermediate calculation result 1000111 obtained after multiplying a 00 and b 00 , the second intermediate calculation result 0111000 obtained after bitwise inversion of the first intermediate calculation result, and a 00 and the corresponding b 00 are multiplied by the second symbol data 1 of the first intermediate calculation result, and the second symbol data 1 is used as the selection control signal. Since the second symbol data is 1, the representation will be a 00 and The first intermediate calculation result obtained after the multiplication of b 00 is a negative value, therefore, the control outputs the second intermediate calculation result 0111000 obtained after bitwise inversion of the first intermediate result as the third intermediate calculation result.
同理,第二选择器在接收到将a 01和b 10进行乘法处理后得到的第一中间计算结果0100011、对该第一中间计算结果进行按位取反后得到的第二中间计算结果1011100以及将a 01和对应的b 10进行乘法处理后得到的第一中间计算结果的第二符号数据0后,将第二符号数据0作为选择控制信号,由于第二符号数据为0时,表征将a 01和b 10进行乘法处理后得到的第一中间计算结果为正值,因此,控制将第一中间计算结果0100011作为第三中间结果输出。 Similarly, the second selector receives the first intermediate calculation result 0100011 obtained after multiplying a 01 and b 10 , and the second intermediate calculation result 1011100 obtained after bitwise inversion of the first intermediate calculation result And after the second sign data 0 of the first intermediate calculation result obtained after multiplying a 01 and the corresponding b 10 , the second sign data 0 is used as the selection control signal, because when the second sign data is 0, the representation will be The first intermediate calculation result obtained after the multiplication of a 01 and b 10 is a positive value, therefore, the control outputs the first intermediate calculation result 0100011 as the third intermediate result.
同理,第二选择器在接收到将a 02和b 20进行乘法处理后得到的第一中间计算结果0100011、对该第一中间计算结果进行按位取反后得到的第二中间计算结果1011100以及将a 02和b 20进行乘法处理后得到的第一中间计算结果的第二符号数据0后,将第二符号数据0作为选择控制信息,由于第二符号数据为0时,表征将a 02和b 20进行乘法处理后得到的第一中间计算结果为正值,因此,控制将第一中间计算结果0100011作为第三中间结果输出。 Similarly, the second selector receives the first intermediate calculation result 0100011 obtained after multiplying a 02 and b 20 , and the second intermediate calculation result 1011100 obtained after bitwise inversion of the first intermediate calculation result And after the second symbol data 0 of the first intermediate calculation result obtained after the multiplication of a 02 and b 20 , the second symbol data 0 is used as the selection control information, because when the second symbol data is 0, the representation will be a 02 The first intermediate calculation result obtained after multiplication with b 20 is a positive value, therefore, the control outputs the first intermediate calculation result 0100011 as the third intermediate result.
第二选择器将第三中间计算结果传输至第三加法器。The second selector transmits the third intermediate calculation result to the third adder.
第二加法器在接收到将a 00和对应的b 00进行乘法处理后得到的第一中间计算结果的第二符号数据1、将a 01和对应的b 10进行乘法处理后得到的第一中间计算结果的第二符号数据0以及将a 02和b 20进行乘法处理后得到的第一中间计算结果的第二符号数据0后,将上述三个第二符号数据相加求和,得到第四中间计算结果1;并将该第四中间计算结果传输至第三加法器。 The second adder receives the second symbol data 1 of the first intermediate calculation result obtained after multiplying a 00 and the corresponding b 00 , and the first intermediate calculation result obtained after multiplying a 01 and the corresponding b 10 After the second symbol data 0 of the calculation result and the second symbol data 0 of the first intermediate calculation result obtained after multiplying a 02 and b 20 , the above three second symbol data are added and summed to obtain the fourth an intermediate calculation result 1; and transmitting the fourth intermediate calculation result to the third adder.
第三加法器在接收到第二选择器传输的第三中间计算结果以及第四中间计算结果后,将第三中间计算结果与第四中间计算结果相加求和,得到待处理数据的目标处理结果,即将0111000、0100011、0100011以及1相加,得到将矩阵A中位于第一行的各矩阵元素、与矩阵B中位于第一列的对应矩阵元素相乘后的结果矩阵中第一行第一列的矩阵元素。After receiving the third intermediate calculation result and the fourth intermediate calculation result transmitted by the second selector, the third adder adds and sums the third intermediate calculation result and the fourth intermediate calculation result to obtain the target processing of the data to be processed As a result, add 0111000, 0100011, 0100011, and 1 to obtain the first row of the matrix obtained by multiplying each matrix element in the first row of matrix A by the corresponding matrix element in the first column of matrix B. A column of matrix elements.
本公开提供的数据处理装置可以应用在多个N行M列的有符号矩阵乘法运算的过程中,以应用在两个有符号矩阵乘法运算中为例,其中的第一待处理数据中包括的第一待处理矩阵,第二待处理数据包括第二待处理矩阵;第一待处理数据中的多个第一子数据包括第一待处理矩阵中位于第i行的多个矩阵元素;多个第二子数据包括第二待处理矩阵中位于第j列的多个矩阵元素;i∈[1,N],N为大于等于2的正整数,表示第一待处理矩阵的总行数;j∈[1,M],M为大于等于2的正整数,表示第二待处理矩阵的总列数。The data processing device provided by the present disclosure can be applied in the process of multiplication of signed matrices with multiple N rows and M columns. Taking the application in two signed matrix multiplication operations as an example, the first data to be processed includes The first matrix to be processed, the second data to be processed includes the second matrix to be processed; a plurality of first sub-data in the first data to be processed includes a plurality of matrix elements located in row i in the first matrix to be processed; a plurality of The second sub-data includes a plurality of matrix elements positioned at the jth column in the second matrix to be processed; i∈[1, N], N is a positive integer greater than or equal to 2, representing the total number of rows of the first matrix to be processed; j∈ [1, M], M is a positive integer greater than or equal to 2, indicating the total number of columns of the second matrix to be processed.
示例性的,以将本公开提供的数据处理装置应用在对两个有符号矩阵进行乘法运算为例,若第一待处理数据包括第一待处理矩阵Exemplarily, taking the application of the data processing device provided by the present disclosure in multiplying two signed matrices as an example, if the first data to be processed includes the first matrix to be processed
Figure PCTCN2022124516-appb-000015
Figure PCTCN2022124516-appb-000015
且由于第一待处理矩阵C中每个矩阵元素的类型为int型、且占据8位空间,则And since the type of each matrix element in the first matrix C to be processed is int type and occupies 8-bit space, then
Figure PCTCN2022124516-appb-000016
Figure PCTCN2022124516-appb-000016
第二待处理数据包括第二待处理矩阵The second data to be processed includes the second matrix to be processed
Figure PCTCN2022124516-appb-000017
Figure PCTCN2022124516-appb-000017
且由于第二待处理矩阵D中每个矩阵元素的类型为int型、且占据8位空间,则And since the type of each matrix element in the second matrix D to be processed is an int type and occupies 8 bits of space, then
Figure PCTCN2022124516-appb-000018
Figure PCTCN2022124516-appb-000018
接下来,将介绍利用数据处理装置如下计算第一待处理矩阵C乘以第二待处理矩阵D的过程:Next, the process of multiplying the first matrix C to be processed by the second matrix D to be processed by the data processing device as follows will be introduced:
Figure PCTCN2022124516-appb-000019
Figure PCTCN2022124516-appb-000019
利用第一数据转化电路11-1,接收第一待处理矩阵C,并将第一待处理矩阵C中每个矩阵元素(即c 00、c 01、c 10、c 11)分别转化为第一符号数据以及绝对值数据。 Utilize the first data conversion circuit 11-1 to receive the first matrix C to be processed, and convert each matrix element (ie c 00 , c 01 , c 10 , c 11 ) in the first matrix C to be processed into the first Symbolic data as well as absolute value data.
具体的,第一数据转化电路11-1中的第一转化电路,接收第一待处理矩阵C中各矩阵元素对应的第n-1位(由于每个矩阵元素为int8,即占据8位空间,即n=8,因此第n-1位(即第7位)表征矩阵元素的符号位)的第一数值,并将该第一数值作为各矩阵元素的第一符号数据,即接收c 00的第7位的第一数值1,将第一数值1作为c 00的第一符号数据;并接收c 01的第7位的第一数值1,将第一数值1作为c 01的第一符号数据;并接收c 10的第7位的第一数值0,将该第一数值0作为c 10的第一符号数据;并接收c 11的第7位的第一数值0,将该第一数值0作为c 11的第一符号数据。 Specifically, the first conversion circuit in the first data conversion circuit 11-1 receives the n-1th bit corresponding to each matrix element in the first matrix C to be processed (because each matrix element is int8, it occupies 8 bits of space , ie n=8, so the n-1th (i.e. the 7th) characterizes the first numerical value of the sign bit of the matrix element), and uses the first numerical value as the first sign data of each matrix element, that is, receives c 00 The first value 1 of the 7th bit of c 01, the first value 1 is used as the first symbol data of c 00 ; and the first value 1 of the 7th bit of c 01 is received, and the first value 1 is used as the first symbol data of c 01 data; and receive the first numerical value 0 of the 7th bit of c 10 , and use the first numerical value 0 as the first symbol data of c 10 ; and receive the first numerical value 0 of the 7th bit of c 11 , and use the first numerical value 0 as the first symbol data for c 11 .
第一数据转化电路11-1中第一转化电路,在接收到第一待处理数据中各矩阵元素对应的第一数值后,可以将各矩阵元素对应的第一数值传输至第一数据转化电路11-1中的第二转化电路中的第二选择器。The first conversion circuit in the first data conversion circuit 11-1, after receiving the first value corresponding to each matrix element in the first data to be processed, can transmit the first value corresponding to each matrix element to the first data conversion circuit The second selector in the second conversion circuit in 11-1.
另外,第一数据转化电路11-1中的第二转化电路,接收第一待处理矩阵C中各矩阵元素对应的第n-2位~第0位(由于每个矩阵元素为int8,即占据8位空间,即n=8,因此第n-2位~第0位(即第6位~第0位)表征矩阵元素的数值位)的第二数值,并基于接收到各矩阵元素对应的第一数值,对对应矩阵元素的第二数值进行转化处理,得到该矩阵元素对应的绝对值数据。In addition, the second conversion circuit in the first data conversion circuit 11-1 receives the n-2th to 0th bits corresponding to each matrix element in the first matrix C to be processed (because each matrix element is int8, that is, it occupies 8-bit space, that is, n=8, so the n-2th bit to the 0th bit (ie the 6th bit to the 0th bit) represents the second value of the value of the matrix element), and based on receiving the corresponding value of each matrix element The first numerical value is converted to the second numerical value corresponding to the matrix element to obtain the absolute value data corresponding to the matrix element.
具体的,第二转化电路中包括依次连接的第一加法器、第一取反电路以及第一选择器;其中,第一加法器接收c 00的第6位~第0位的第二数值1111110,将该第二数值与预设数值(-1)求和,得到c 00对应的第一中间数值1111101;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得到c 00对应的第二中间数值0000010;向第一选择器传输该第二中间数值;第一选择器接收到c 00对应的第二数值、c 00对应的第二中间数值以及c 00对应的第一数值(即c 00对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为1,即c 00本身为负值,因此,需要将c 00对应的第二中间数值0000010作为c 00对应的绝对值数据输出。 Specifically, the second conversion circuit includes a first adder, a first inverting circuit, and a first selector connected in sequence; wherein, the first adder receives the second value 1111110 of the 6th to 0th bits of c 00 , the second value and the preset value (-1) are summed to obtain the first intermediate value 1111101 corresponding to c 00 ; and the first intermediate value is transmitted to the first inverting circuit; the first inverting circuit receives the first After the intermediate value, perform bitwise inversion on the first intermediate value to obtain the second intermediate value 0000010 corresponding to c 00 ; transmit the second intermediate value to the first selector; the first selector receives the second intermediate value corresponding to c 00 value, the second intermediate value corresponding to c 00 , and the first value corresponding to c 00 (that is, the first symbol data corresponding to c 00 ), the first value is used as the selection control signal, since the first value is 1, that is, c 00 itself is a negative value, therefore, the second intermediate value 0000010 corresponding to c 00 needs to be output as the absolute value data corresponding to c 00 .
同理,第一加法器接收c 01的第6位~第0位的第二数值1111010,将该第二数值与 预设数值(-1)求和,得到c 01对应的第一中间数值1111001;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得到c 01对应的第二中间数值0000110;向第一选择器传输该第二中间数值;第一选择器接收到c 01对应的第二数值、c 01对应的第二中间数值以及c 01对应的第一数值(即c 01对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为1,即c 01本身为负值,因此,需要将c 01对应的第二中间数值0000110作为c 01对应的绝对值数据输出。 Similarly, the first adder receives the second value 1111010 of the 6th to 0th digits of c 01 , and sums the second value with the preset value (-1) to obtain the first intermediate value 1111001 corresponding to c 01 ; and transmit the first intermediate value to the first inversion circuit; after the first inversion circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 0000110 corresponding to c 01 ; The first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 01 , the second intermediate value corresponding to c 01 , and the first value corresponding to c 01 (that is, the first symbol corresponding to c 01 data), the first value is used as the selection control signal, since the first value is 1, that is, c 01 itself is a negative value, therefore, the second intermediate value 0000110 corresponding to c 01 needs to be output as the absolute value data corresponding to c 01 .
同理,第一加法器接收c 10的第6位~第0位的第二数值0000001,将该第二数值与预设数值(-1)求和,得到c 10对应的第一中间数值0000000;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得到c 10对应的第二中间数值1111111;向第一选择器传输该第二中间数值;第一选择器接收到c 10对应的第二数值、c 10对应的第二中间数值以及c 10对应的第一数值(即c 10对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为0,即c 10本身为正值,因此,可以将c 10对应的第二数值0000001作为c 10对应的绝对值数据输出。 Similarly, the first adder receives the second value 0000001 of the 6th to 0th digits of c 10 , sums the second value with the preset value (-1), and obtains the first intermediate value 0000000 corresponding to c 10 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 1111111 corresponding to c 10 ; The first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 10 , the second intermediate value corresponding to c 10 , and the first value corresponding to c 10 (that is, the first symbol corresponding to c 10 data), the first value is used as the selection control signal, since the first value is 0, that is, c10 itself is a positive value, therefore, the second value 0000001 corresponding to c10 can be output as the absolute value data corresponding to c10 .
同理,第一加法器接收c 11的第6位~第0位的第二数值0000000,将该第二数值与预设数值(-1)求和,得到c 11对应的第一中间数值10000001;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得到c 11对应的第二中间数值01111110;向第一选择器传输该第二中间数值;第一选择器接收到c 11对应的第二数值、c 11对应的第二中间数值以及c 11对应的第一数值(即c 11对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为0,即c 11本身为正值,因此,可以将c 11对应的第二数值0000000作为c 11对应的绝对值数据输出。 Similarly, the first adder receives the second value 0000000 from the 6th bit to the 0th bit of c 11 , sums the second value with the preset value (-1), and obtains the first intermediate value 10000001 corresponding to c 11 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 01111110 corresponding to c 11 ; The first selector transmits the second intermediate value; the first selector receives the second value corresponding to c 11 , the second intermediate value corresponding to c 11 and the first value corresponding to c 11 (that is, the first symbol corresponding to c 11 data), the first numerical value is used as the selection control signal, since the first numerical value is 0, that is, c 11 itself is a positive value, therefore, the second numerical value 0000000 corresponding to c 11 can be output as the absolute value data corresponding to c 11 .
另外,利用第二数据转化电路11-2,接收第二待处理矩阵D,并将第二待处理矩阵D中每个矩阵元素(即d 00、d 10)分别转化为第一符号数据和绝对值数据。 In addition, the second data conversion circuit 11-2 is used to receive the second matrix D to be processed, and convert each matrix element (that is, d 00 , d 10 ) in the second matrix D to be processed into the first symbol data and the absolute value data.
具体的,第二数据转化电路11-2中的第一转化电路,接收第二待处理绝镇D中各矩阵元素对应的第n-1位(由于每个矩阵元素为int8,即占据8位空间,即n=8,因此,第n-1位(即第7位)表征矩阵元素的符号位)的第一数值,并将该第一数值作为各矩阵元素的第一符号数据,即接收d 00的第7位的第一数值0,将第一数值0作为d 00的第一符号数据;并接收d 10的第7位的第一数值0,将第一数值0作为d 10的第一符号数据。 Specifically, the first conversion circuit in the second data conversion circuit 11-2 receives the n-1th bit corresponding to each matrix element in the second to-be-processed column D (because each matrix element is int8, it occupies 8 bits space, i.e. n=8, therefore, the n-1th (i.e. the 7th bit) characterizes the first numerical value of the sign bit of the matrix element), and the first numerical value is used as the first sign data of each matrix element, that is, receiving The first value 0 of the 7th bit of d 00 is 0, and the first value 0 is used as the first symbol data of d 00 ; and the first value 0 of the 7th bit of d 10 is received, and the first value 0 is used as the first symbol data of d 10 A symbolic data.
第二数据转化电路11-2中第一转化电路,在接收到第二待处理数据中各矩阵元素对应的第一数值后,可以将各矩阵元素对应的第一数值传输至第二数据转化电路11-2中的第二转化电路中的第二选择器。The first conversion circuit in the second data conversion circuit 11-2, after receiving the first value corresponding to each matrix element in the second data to be processed, can transmit the first value corresponding to each matrix element to the second data conversion circuit The second selector in the second conversion circuit in 11-2.
另外,第二数据转化电路11-2中的第二转化电路,接收第二待处理矩阵D中各矩阵元素对应的第n-2位~第0位(由于每个矩阵元素为int8,即占据8位空间,即n=8,因此第n-2位~第0位(即第6位~第0位)表征矩阵元素的数值位)的第二数值,并基于接收到各矩阵元素对应的第一数值,对对应矩阵元素的第二数值进行转化处理,得到该矩阵元素对应的绝对值数据。In addition, the second conversion circuit in the second data conversion circuit 11-2 receives the n-2th to 0th bits corresponding to each matrix element in the second to-be-processed matrix D (because each matrix element is int8, i.e. occupies 8-bit space, that is, n=8, so the n-2th bit to the 0th bit (ie the 6th bit to the 0th bit) represents the second value of the value of the matrix element), and based on receiving the corresponding value of each matrix element The first numerical value is converted to the second numerical value corresponding to the matrix element to obtain the absolute value data corresponding to the matrix element.
具体的,第二转化电路中包括依次连接的第一加法器、第一取反电路以及第一选择器;其中,第一加法器接收d 00的第6位~第0位的第二数值0000001,将该第二数值与预设数值(-1)求和,得到d 00对应的第一中间数值0000000;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得 到d 00对应的第二中间数值1111111;向第一选择器传输该第二中间数值;第一选择器接收到d 00对应的第二数值、d 00对应的第二中间数值以及d 00对应的第一数值(即d 00对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为0,即d 00本身为正值,因此,可以将d 00对应的第二数值0000001作为d 00对应的绝对值数据输出。 Specifically, the second conversion circuit includes a first adder, a first inverting circuit, and a first selector connected in sequence; wherein, the first adder receives the second value 0000001 of the 6th to 0th bits of d 00 , sum the second value with the preset value (-1) to obtain the first intermediate value 0000000 corresponding to d 00 ; and transmit the first intermediate value to the first negation circuit; the first negation circuit receives the first After the intermediate value, perform bitwise inversion on the first intermediate value to obtain the second intermediate value 1111111 corresponding to d 00 ; transmit the second intermediate value to the first selector; the first selector receives the second intermediate value corresponding to d 00 value, the second intermediate value corresponding to d 00 , and the first value corresponding to d 00 (that is, the first symbol data corresponding to d 00 ), the first value is used as the selection control signal, since the first value is 0, that is, d 00 itself is a positive value, therefore, the second value 0000001 corresponding to d 00 can be output as the absolute value data corresponding to d 00 .
同理,第一加法器接收d 10的第6位~第0位的第二数值0000010,将该第二数值与预设数值(-1)求和,得到d 10对应的第一中间数值0000001;并向第一取反电路传输第一中间数值;第一取反电路接收到第一中间数值后,对第一中间数值进行按位取反,得到d 10对应的第二中间数值1111110;向第一选择器传输该第二中间数值;第一选择器接收到d 10对应的第二数值、d 10对应的第二中间数值以及d 10对应的第一数值(即d 10对应的第一符号数据),将第一数值作为选择控制信号,由于第一数值为0,即d 10本身为正值,因此,可以将d 10对应的第二数值0000010作为d 10对应的绝对值数据输出。 Similarly, the first adder receives the second value 0000010 of the 6th to 0th digit of d 10 , sums the second value with the preset value (-1), and obtains the first intermediate value 0000001 corresponding to d 10 ; and transmit the first intermediate value to the first inverting circuit; after the first inverting circuit receives the first intermediate value, the first intermediate value is bitwise inverted to obtain the second intermediate value 1111110 corresponding to d 10 ; The first selector transmits the second intermediate value; the first selector receives the second value corresponding to d 10 , the second intermediate value corresponding to d 10 , and the first value corresponding to d 10 (that is, the first symbol corresponding to d 10 data), the first numerical value is used as the selection control signal, since the first numerical value is 0, that is, d10 itself is a positive value, therefore, the second numerical value 0000010 corresponding to d10 can be output as the absolute value data corresponding to d10 .
由于对矩阵C和矩阵D进行乘法运算时,本质上是将矩阵C中位于第一行的各矩阵元素、与矩阵D中位于第一列对应的各矩阵元素进行乘法运算,并求和,得到结果矩阵E第一行第一列的矩阵元素,即结果矩阵E的e 00=c 00×d 00+c 01×d 10;并将矩阵C中位于第二行的各矩阵元素、与矩阵D中位于第一列对应的各矩阵元素进行乘法运算,并求和,得到结果矩阵E中位于第二行第一列位置处的矩阵元素,即结果矩阵E的e 10=c 10×d 00+c 11×d 10;因此,需要两个计算电路,即计算电路12-1和计算电路12-2,以分别计算得到结果矩阵E中各矩阵元素。 Since the multiplication operation of matrix C and matrix D is essentially to multiply the matrix elements in the first row of matrix C and the corresponding matrix elements in the first column of matrix D, and sum them up to obtain The matrix elements of the first row and the first column of the result matrix E, that is, e 00 =c 00 ×d 00 +c 01 ×d 10 of the result matrix E; The matrix elements corresponding to the first column in E are multiplied and summed to obtain the matrix elements located in the first column of the second row in the result matrix E, that is, e 10 =c 10 ×d 00 of the result matrix E c 11 ×d 10 ; therefore, two calculation circuits, ie, the calculation circuit 12-1 and the calculation circuit 12-2, are required to calculate and obtain each matrix element in the result matrix E respectively.
在第一数据转化电路11-1将第一待处理矩阵C中的各矩阵元素,转化为对应的第一符号数据和绝对值数据以及第二数据转化电路11-2将第二待处理矩阵D中的各矩阵元素,转化为对应的第一符号数据和绝对值数据后,第一数据转化电路11-1可以将第一待处理矩阵C中位于第一行的矩阵元素(即c 00、c 01)分别对应的第一符号数据和绝对值数据传输至计算电路12-1,同时,第二数据转化电路11-2可以将第二待处理矩阵D中位于第一列的矩阵元素(即d 00、d 10)分别对应的第一符号数据和绝对值数据传输至计算电路12-1,以使计算电路12-1,基于c 00、c 01、d 00、d 10分别对应的第一符号数据和绝对值数据,计算得到结果矩阵E中的e 00;同理,第一数据转化电路11-1可以将第一待处理矩阵C中位于第二行的矩阵元素(即c 10、c 11)分别对应的第一符号数据和绝对值数据传输至计算电路12-2,同时,第二数据转化电路11-2可以将第二待处理矩阵D中位于第一列的矩阵元素(即d 00、d 10)分别对应的第一符号数据和绝对值数据传输至计算电路12-2,以使计算电路12-2,基于c 00、c 01、d 00、d 10分别对应的第一符号数据和绝对值数据,计算得到结果矩阵E中的e 10In the first data conversion circuit 11-1, each matrix element in the first matrix C to be processed is converted into corresponding first sign data and absolute value data and the second data conversion circuit 11-2 converts the second matrix D to be processed After each matrix element in is converted into the corresponding first symbol data and absolute value data, the first data conversion circuit 11-1 can convert the matrix elements in the first row in the first matrix C to be processed (i.e. c 00 , c 01 ) respectively corresponding to the first sign data and absolute value data are transmitted to the calculation circuit 12-1, and at the same time, the second data conversion circuit 11-2 can convert the matrix elements (ie, d 00 , d 10 ) respectively corresponding to the first symbol data and absolute value data are transmitted to the calculation circuit 12-1, so that the calculation circuit 12-1, based on the first symbols corresponding to c 00 , c 01 , d 00 , d 10 data and absolute value data, and calculate e 00 in the result matrix E; similarly, the first data conversion circuit 11-1 can convert the matrix elements (ie, c 10 , c 11 ) respectively corresponding to the first sign data and absolute value data to the calculation circuit 12-2, and at the same time, the second data conversion circuit 11-2 can place the matrix elements in the first column in the second matrix D to be processed (ie d 00 , d 10 ) respectively corresponding first sign data and absolute value data are transmitted to the calculation circuit 12-2, so that the calculation circuit 12-2, based on the first sign data corresponding to c 00 , c 01 , d 00 , d 10 respectively and the absolute value data, and calculate e 10 in the result matrix E.
在具体实施中,计算电路12-1包括符号运算电路、第一数值运算电路以及第二数值运算电路;其中,符号运算电路包括异或门电路,用于接收c 00对应的第一符号数据、c 01对应的第一符号数据、d 00对应的第一符号数据以及d 10对应的第一符号数据;并将c 00对应的第一符号数据以及d 00对应的第一符号数据进行异或处理,得到将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据(即1^0=1);并对c 01对应的第一符号数据以及d 10对应的第一符号数据进行异或处理,得到将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据(即1^0=1)。 In a specific implementation, the calculation circuit 12-1 includes a symbol operation circuit, a first value operation circuit, and a second value operation circuit; wherein, the sign operation circuit includes an exclusive OR gate circuit for receiving the first symbol data corresponding to c 00 , The first symbol data corresponding to c 01 , the first symbol data corresponding to d 00 , and the first symbol data corresponding to d 10 ; and the first symbol data corresponding to c 00 and the first symbol data corresponding to d 00 are subjected to XOR processing , obtain the second symbol data (that is, 1^0=1) of the first intermediate calculation result obtained after c 00 and the corresponding d 00 are multiplied; and the first symbol data corresponding to c 01 and the corresponding d 10 Exclusive OR processing is performed on the first symbol data to obtain the second symbol data (that is, 1^0=1) of the first intermediate calculation result obtained by multiplying c 01 and the corresponding d 10 .
计算电路12-1中的异或门电路将c 00和对应的d 00进行乘法处理后得到的第一中间 计算结果的第二符号数据1以及将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据1,分别传输至计算电路12-1中第二数值运算电路中的第二选择器和第二加法器。 The exclusive OR gate circuit in the calculation circuit 12-1 multiplies c 00 and the corresponding d 00 to obtain the second symbol data 1 of the first intermediate calculation result, and multiplies c 01 and the corresponding d 10 to obtain The second sign data 1 of the first intermediate calculation result is transmitted to the second selector and the second adder in the second numerical operation circuit in the calculation circuit 12-1 respectively.
计算电路12-1中第一数值运算电路包括乘法器,用于接收c 00对应的绝对值数据、c 01对应的绝对值数据、d 00对应的绝对值数据以及d 10对应的绝对值数据;并将c 00对应的绝对值数据和d 00对应的绝对值数据进行乘积运算,得到将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果0000010;并对c 01对应的绝对值数据以及d 10对应的绝对值数据进行乘积运算,得到将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果0001100。 The first numerical calculation circuit in the calculation circuit 12-1 includes a multiplier for receiving absolute value data corresponding to c 00 , absolute value data corresponding to c 01 , absolute value data corresponding to d 00 , and absolute value data corresponding to d 10 ; and multiply the absolute value data corresponding to c 00 and the absolute value data corresponding to d 00 to obtain the first intermediate calculation result 0000010 obtained after multiplying c 00 and the corresponding d 00 ; and the absolute value data corresponding to c 01 The value data and the absolute value data corresponding to d 10 are multiplied to obtain the first intermediate calculation result 0001100 obtained by multiplying c 01 and the corresponding d 10 .
计算电路12-1中的乘法器将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果0000010以及将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果0001100,分别传输至计算电路12-1中第二数值运算电路中的第二选择器以及第二取反电路。 The multiplier in the calculation circuit 12-1 multiplies c 00 and the corresponding d 00 to obtain the first intermediate calculation result 0000010, and c 01 and the corresponding d 10 to obtain the first intermediate calculation result 0001100 , respectively transmitted to the second selector and the second negation circuit in the second numerical operation circuit in the calculation circuit 12-1.
计算电路12-1中的第二数值运算电路包括第二取反电路、第二选择器、第二加法器以及第三加法器,其中,第二取反电路用于接收将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果0000010,并对该第一中间计算结果进行按位取反操作,得到第二中间计算结果1111101;向第二选择器传输该第二中间计算结果;第二选择器用于接收到将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据1、将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果0000010以及第二中间计算结果1111101,并将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据1作为选择控制信号,由于第二符号数据为1,则需要将对第一中间计算结果进行按位取反后的第二中间计算结果1111101作为第三中间计算结果。 The second numerical calculation circuit in the calculation circuit 12-1 includes a second inversion circuit, a second selector, a second adder and a third adder, wherein the second inversion circuit is used to receive c 00 and the corresponding The first intermediate calculation result obtained after the multiplication of d 00 is 0000010, and the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1111101; the second intermediate calculation result is transmitted to the second selector ; The second selector is used to receive the second symbol data 1 of the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 , and the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 The intermediate calculation result 0000010 and the second intermediate calculation result 1111101, and the second symbol data 1 of the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 as the selection control signal, because the second symbol data is 1 , then the second intermediate calculation result 1111101 after bitwise inversion of the first intermediate calculation result needs to be used as the third intermediate calculation result.
另外,第二取反电路还用于接收将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果0001100,并对该第一中间计算结果进行按位取反操作,得到第二中间计算结果:1110011;向第二选择器传输该第二中间计算结果;第二选择器还用于在接收到将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据1、将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果0001100以及第二中间计算结果1110011后,将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据1作为选择控制信号,由于第二符号数据为1,则需要将对第一中间计算结果进行按位取反后的第二中间计算结果1110011作为第三中间计算结果。 In addition, the second inversion circuit is also used to receive the first intermediate calculation result 0001100 obtained after multiplying c 01 and the corresponding d 10 , and perform a bitwise inversion operation on the first intermediate calculation result to obtain the second Intermediate calculation result: 1110011; transmit the second intermediate calculation result to the second selector; the second selector is also used to receive the first intermediate calculation result obtained after multiplying c 01 and corresponding d 10 Two-symbol data 1, the first intermediate calculation result 0001100 obtained after multiplying c 01 and the corresponding d 10 and the second intermediate calculation result 1110011, the first intermediate calculation result obtained after multiplying c 01 and the corresponding d 10 The second symbol data 1 of the intermediate calculation result is used as the selection control signal. Since the second symbol data is 1, the second intermediate calculation result 1110011 after bitwise inversion of the first intermediate calculation result needs to be used as the third intermediate calculation result .
计算电路12-1中的第二选择器确定各第三中间计算结果后,可以将第三中间计算结果传输至计算电路12-1中的第三加法器。计算电路12-1中的第二加法器用于接收将c 00和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据1、将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据1、并计算其和值,得到第四中间计算结果,即2(即00000010)。 After the second selector in the calculation circuit 12-1 determines each third intermediate calculation result, the third intermediate calculation result may be transmitted to the third adder in the calculation circuit 12-1. The second adder in the calculation circuit 12-1 is used to receive the second symbol data 1 of the first intermediate calculation result obtained after multiplying c 00 and the corresponding d 00 , and multiply c 01 and the corresponding d 10 Then obtain the second symbol data 1 of the first intermediate calculation result, and calculate its sum value to obtain the fourth intermediate calculation result, namely 2 (ie 00000010).
计算电路12-1中的第三加法器,用于接收上述各第三中间计算结果以及第四中间计算结果,并求和,得到结果矩阵E中的e 00(即将1111101、1110011、00000010求和,得到11110010)。 The third adder in the calculation circuit 12-1 is used to receive the above-mentioned third intermediate calculation results and the fourth intermediate calculation results, and sum them to obtain e 00 in the result matrix E (that is, to sum 1111101, 1110011, 00000010 , to get 11110010).
同理,计算电路12-2包括符号运算电路、第一数值运算电路以及第二数值运算电路;其中,符号运算电路包括异或门电路,用于接收c 10对应的第一符号数据、c 11对应 的第一符号数据、d 00对应的第一符号数据以及d 10对应的第一符号数据;并将c 10对应的第一符号数据以及d 00对应的第一符号数据进行异或处理,得到将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据(即0^0=0);并对c 11对应的第一符号数据以及d 10对应的第一符号数据进行异或处理,得到将c 01和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据(即0^0=1)。 Similarly, the calculation circuit 12-2 includes a symbol operation circuit, a first value operation circuit and a second value operation circuit; wherein, the sign operation circuit includes an exclusive OR gate circuit for receiving the first symbol data corresponding to c10 , c11 The corresponding first symbol data, the first symbol data corresponding to d 00 , and the first symbol data corresponding to d 10 ; and the first symbol data corresponding to c 10 and the first symbol data corresponding to d 00 are subjected to XOR processing to obtain The second symbol data (ie 0^0=0) of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 ; and the first symbol data corresponding to c 11 and the first symbol data corresponding to d 10 Exclusive OR processing is performed on the sign data to obtain the second sign data (that is, 0^0=1) of the first intermediate calculation result obtained by multiplying c 01 and the corresponding d 10 .
计算电路12-2中的异或门电路将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据0以及将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据0,分别传输至计算电路12-2中第二数值运算电路中的第二选择器、第二加法器。 The exclusive OR gate circuit in the calculation circuit 12-2 multiplies c 10 and the corresponding d 00 to obtain the second symbol data 0 of the first intermediate calculation result, and multiplies c 11 and the corresponding d 10 to obtain The second sign data 0 of the first intermediate calculation result is transmitted to the second selector and the second adder in the second numerical operation circuit in the calculation circuit 12-2 respectively.
计算电路12-2中第一数值运算电路包括乘法器用于接收c 10对应的绝对值数据、c 11对应的绝对值数据、d 00对应的绝对值数据以及d 10对应的绝对值数据;并将c 10对应的绝对值数据和d 00对应的绝对值数据进行乘积运算,得到将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果0000001;并对c 11对应的绝对值数据以及d 10对应的绝对值数据进行乘积运算,得到将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果0000000。 The first numerical operation circuit in the calculation circuit 12-2 includes a multiplier for receiving absolute value data corresponding to c 10 , absolute value data corresponding to c 11 , absolute value data corresponding to d 00 , and absolute value data corresponding to d 10 ; and The absolute value data corresponding to c 10 and the absolute value data corresponding to d 00 are multiplied to obtain the first intermediate calculation result 0000001 obtained after multiplying c 10 and the corresponding d 00 ; and the absolute value data corresponding to c 11 and the absolute value data corresponding to d 10 are multiplied to obtain the first intermediate calculation result 0000000 obtained by multiplying c 11 and the corresponding d 10 .
计算电路12-2中的乘法器将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果0000001以及将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果0000000,分别传输至计算电路12-2中第二数值运算电路中的第二选择器以及第二取反电路。 The multiplier in the calculation circuit 12-2 multiplies c 10 and the corresponding d 00 to obtain the first intermediate calculation result 0000001 and c 11 and the corresponding d 10 to obtain the first intermediate calculation result 0000000 , respectively transmitted to the second selector and the second negation circuit in the second numerical operation circuit in the calculation circuit 12-2.
计算电路12-2中的第二数值运算电路包括第二取反电路、第二选择器、第二加法器以及第三加法器,其中,第二取反电路用于接收将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果0000001,并对该第一中间计算结果进行按位取反操作,得到第二中间计算结果1111110;向第二选择器传输该第二中间计算结果;第二选择器,用于接收到将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据0、将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果0000001以及第二中间计算结果1111110,并将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据0作为选择控制信号,由于第二符号数据为0,则可以将第一中间计算结果0000001作为第三中间计算结果。 The second numerical calculation circuit in the calculation circuit 12-2 includes a second negation circuit, a second selector, a second adder, and a third adder, wherein the second negation circuit is used to receive c 10 and the corresponding The first intermediate calculation result obtained after the multiplication of d 00 is 0000001, and the bitwise inversion operation is performed on the first intermediate calculation result to obtain the second intermediate calculation result 1111110; the second intermediate calculation result is transmitted to the second selector ; The second selector is used to receive the second symbol data 0 of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 , obtained after multiplying c 10 and the corresponding d 00 The first intermediate calculation result 0000001 and the second intermediate calculation result 1111110, and the second symbol data 0 of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 as the selection control signal, because the second symbol data is 0, the first intermediate calculation result 0000001 can be used as the third intermediate calculation result.
另外,第二取反电路还用于接收将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果0000000,并对该第一中间计算结果进行按位取反操作,得到第二中间计算结果1111111;向第二选择器传输该第二中间计算结果;第二选择器还用于在接收到将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据0、将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果0000000以及第二中间计算结果1111111后,将c 11和对应的d 10进行乘法处理后得到的第一中间计算结果的第二符号数据0作为选择控制信号,由于第二符号数据为0,则可以将第一中间计算结果0000000作为第三中间计算结果。 In addition, the second inversion circuit is also used to receive the first intermediate calculation result 0000000 obtained after multiplying c 11 and the corresponding d 10 , and perform a bitwise inversion operation on the first intermediate calculation result to obtain the second The intermediate calculation result 1111111; transmit the second intermediate calculation result to the second selector; the second selector is also used for receiving the second intermediate calculation result of the first intermediate calculation result obtained after multiplying c 11 and the corresponding d 10 Symbol data 0, the first intermediate calculation result 0000000 obtained by multiplying c 11 and the corresponding d 10 , and the second intermediate calculation result 1111111, the first intermediate obtained by multiplying c 11 and the corresponding d 10 The second symbol data 0 of the calculation result is used as the selection control signal, and since the second symbol data is 0, the first intermediate calculation result 0000000 can be used as the third intermediate calculation result.
计算电路12-2中的第二选择器确定各第三中间计算结果后,可以将第三中间计算结果传输至计算电路12-2中的第三加法器。After the second selector in the calculation circuit 12-2 determines each third intermediate calculation result, the third intermediate calculation result may be transmitted to the third adder in the calculation circuit 12-2.
计算电路12-2中的第二加法器用于接收将c 10和对应的d 00进行乘法处理后得到的第一中间计算结果的第二符号数据0以及将c 11和对应的d 10进行乘法处理后得到的第一 中间计算结果的第二符号数据0,并计算其和值,得到第四中间计算结果,即0(即00000000)。 The second adder in the calculation circuit 12-2 is used to receive the second symbol data 0 of the first intermediate calculation result obtained after multiplying c 10 and the corresponding d 00 and multiply c 11 and the corresponding d 10 Then obtain the second symbol data 0 of the first intermediate calculation result, and calculate its sum value to obtain the fourth intermediate calculation result, namely 0 (ie 00000000).
计算电路12-2中的第三加法器用于接收上述各第三中间计算结果以及第四中间计算结果,并求和,得到结果矩阵E中的e 10(即将0000001、0000000、00000000求和,得到00000001)。 The third adder in the calculation circuit 12-2 is used to receive the above-mentioned third intermediate calculation results and the fourth intermediate calculation results, and sum them to obtain e 10 in the result matrix E (to sum 0000001, 0000000, 00000000 to obtain 00000001).
具体的对第一待处理矩阵C和第二待处理矩阵D进行乘法运算的数据处理装置的结构示意图可以如图8所示。A specific structural diagram of a data processing device for performing multiplication operations on the first matrix C to be processed and the second matrix D to be processed may be shown in FIG. 8 .
本公开实施例中,通过数据处理装置中的数据转化电路和计算电路的协同工作,将有符号待处理数据之间的乘法运算转换为无符号的待处理数据之间的乘法运算,能够降低乘法运算时的数据位宽,减少矩阵乘法计算时所需要的芯片体积以及功耗。In the embodiment of the present disclosure, through the cooperative work of the data conversion circuit and the calculation circuit in the data processing device, the multiplication operation between the signed data to be processed is converted into the multiplication operation between the unsigned data to be processed, which can reduce the multiplication rate. The data bit width during operation reduces the chip size and power consumption required for matrix multiplication calculations.
另外,在计算电路执行乘加运算的过程中,减少了数据处理装置中加法器的布局,简化了数据处理装置结构,能够有效减少数据处理装置的体积,进而减少了数据处理装置在AI芯片中占据的空间,从而能够减少AI芯片的体积,增加了AI芯片的应用范围,即使得AI芯片可以应用到对体积有限制的场景下。In addition, in the process of performing multiplication and addition operations by the calculation circuit, the layout of the adder in the data processing device is reduced, the structure of the data processing device is simplified, and the volume of the data processing device can be effectively reduced, thereby reducing the number of components of the data processing device in the AI chip. The occupied space can reduce the volume of the AI chip and increase the application range of the AI chip, that is, the AI chip can be applied to scenarios with limited volume.
本领域技术人员可以理解,在具体实施方式的上述装置中,各步骤的撰写顺序并不意味着严格的执行顺序而对实施过程构成任何限定,各步骤的具体执行顺序应当以其功能和可能的内在逻辑确定。Those skilled in the art can understand that in the above-mentioned device in the specific implementation mode, the writing order of each step does not mean a strict execution order and constitutes any limitation on the implementation process. The specific execution order of each step should be based on its function and possible The inner logic is OK.
基于同一发明构思,本公开实施例中还提供了与数据处理装置对应的数据处理方法,由于本公开实施例中的方法解决问题的原理与本公开实施例上述数据处理装置相似,因此方法的实施可以参见装置的实施,重复之处不再赘述。Based on the same inventive concept, the embodiments of the present disclosure also provide a data processing method corresponding to the data processing device. Since the problem-solving principle of the method in the embodiments of the present disclosure is similar to that of the above-mentioned data processing device in the embodiments of the present disclosure, the implementation of the method Reference can be made to the implementation of the device, and repeated descriptions will not be repeated.
本公开实施例所提供的数据处理方法的执行主体一般为具有一定计算能力的计算机设备,该计算机设备例如包括数据处理装置、服务器或其它处理设备。在一些可能的实现方式中,该数据处理方法可以通过处理器调用存储器中存储的计算机可读指令的方式来实现。The execution subject of the data processing method provided by the embodiments of the present disclosure is generally a computer device with a certain computing capability, and the computer device includes, for example, a data processing device, a server, or other processing devices. In some possible implementation manners, the data processing method may be implemented by a processor invoking computer-readable instructions stored in a memory.
参照图9所示,为本公开实施例提供的一种数据处理方法的流程示意图,所述方法应用于数据处理装置,数据处理装置包括数据转化电路以及计算电路;所述方法包括:Referring to FIG. 9 , it is a schematic flowchart of a data processing method provided by an embodiment of the present disclosure. The method is applied to a data processing device, and the data processing device includes a data conversion circuit and a calculation circuit; the method includes:
S901、数据转化电路接收待处理数据,并将待处理数据转化为第一符号数据以及绝对值数据;向计算电路传输第一符号数据以及绝对值数据;其中,第一符号数据表征对应的待处理数据为正值或者负值。S901. The data conversion circuit receives the data to be processed, and converts the data to be processed into first symbol data and absolute value data; transmits the first symbol data and absolute value data to the calculation circuit; wherein, the first symbol data represents the corresponding to-be-processed data Data is positive or negative.
S902、计算电路获取数据转化电路生成的第一符号数据以及绝对值数据,对绝对值数据进行第一运算处理,得到第一中间计算结果;基于第一符号数据确定第一中间计算结果的第二符号数据;基于第二符号数据以及第一中间计算结果进行第二运算处理,得到待处理数据的处理结果。S902. The calculation circuit acquires the first symbol data and the absolute value data generated by the data conversion circuit, and performs a first calculation process on the absolute value data to obtain a first intermediate calculation result; determine a second value of the first intermediate calculation result based on the first symbol data Symbolic data: performing a second calculation process based on the second symbolic data and the first intermediate calculation result to obtain a processing result of the data to be processed.
在一种可选的实施方式中,所述数据转化电路通过其输出端向计算电路的输入端传输第一符号数据以及绝对值数据。In an optional implementation manner, the data conversion circuit transmits the first symbol data and the absolute value data to the input terminal of the calculation circuit through its output terminal.
在一种可选的实施方式中,所述数据处理装置还包括第一寄存器以及第二寄存器。相应地,所述方法还包括:所述数据转化电路将所述第一符号数据存储至所述第一寄存器,以及将所述绝对值数据存储至所述第二寄存器;所述计算电路从所述第一寄存器中读取所述第一符号数据,以及从所述第二寄存器中读取所述绝对值数据。In an optional implementation manner, the data processing device further includes a first register and a second register. Correspondingly, the method further includes: the data conversion circuit storing the first symbol data into the first register, and storing the absolute value data into the second register; reading the first sign data from the first register, and reading the absolute value data from the second register.
在一种可选的实施方式中,所述数据转化电路包括第一转化电路以及第二转化电路,所述方法还包括:所述第一转化电路接收所述待处理数据中预设第一比特位的第一数值, 将接收到的所述第一数值作为所述第一符号数据以及向所述第二转化电路传输所述第一数值;所述第二转化电路接收所述待处理数据中预设第二比特位的第二数值,并基于所述第一转化电路传输的所述第一数值,对所述第二数值进行转化处理,得到所述绝对值数据。In an optional implementation manner, the data conversion circuit includes a first conversion circuit and a second conversion circuit, and the method further includes: the first conversion circuit receives a preset first bit in the data to be processed The first value of the bit, using the received first value as the first symbol data and transmitting the first value to the second conversion circuit; the second conversion circuit receives the data to be processed A second value of the second bit is preset, and based on the first value transmitted by the first conversion circuit, the second value is converted to obtain the absolute value data.
在一种可选的实施方式中,所述第二转化电路包括依次连接的第一加法器、第一取反电路以及第一选择器,所述方法还包括:所述第一加法器响应于接收到所述待处理数据中预设第二比特位的第二数值,将所述第二数值和预设数值求和,得到第一中间数值;向所述第一取反电路传输所述第一中间数值;所述第一取反电路响应于接收到所述第一加法器传输的所述第一中间数值,对所述第一中间数值进行按位取反操作,得到第二中间数值,向所述第一选择器传输所述第二中间数值;所述第一选择器响应于接收到所述待处理数据中预设第二比特位的第二数值、所述第一取反电路传输的所述第二中间数值以及所述第一转化电路传输的所述第一数值,将所述第一数值作为选择控制信号,控制将所述第二数值作为所述绝对值数据输出、或者控制将所述第二中间数值作为所述绝对值数据输出。In an optional implementation manner, the second conversion circuit includes a first adder, a first negation circuit, and a first selector connected in sequence, and the method further includes: the first adder responds to receiving the second value of the preset second bit in the data to be processed, summing the second value and the preset value to obtain a first intermediate value; transmitting the first intermediate value to the first inverting circuit an intermediate value; the first inversion circuit responds to receiving the first intermediate value transmitted by the first adder, and performs a bitwise inversion operation on the first intermediate value to obtain a second intermediate value, transmit the second intermediate value to the first selector; the first selector responds to receiving the second value of the preset second bit in the data to be processed, and the first inverting circuit transmits The second intermediate value and the first value transmitted by the first conversion circuit, using the first value as a selection control signal, control the output of the second value as the absolute value data, or control The second intermediate value is output as the absolute value data.
在一种可选的实施方式中,所述待处理数据包括第一待处理数据和第二待处理数据;所述第一待处理数据包括多个第一子数据;所述第二待处理数据包括多个第二子数据;所述数据转化电路包括第一数据转化电路以及第二数据转化电路。相应地,所述方法还包括:所述第一数据转化电路接收所述第一待处理数据,并将所述第一待处理数据中的多个第一子数据分别转化为与每个所述第一子数据对应的第一符号数据以及绝对值数据;所述第二数据转化电路接收所述第二待处理数据,并将所述第二待处理数据中的多个第二子数据分别转化为与每个所述第二子数据对应的第一符号数据以及绝对值数据。In an optional implementation manner, the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data; the second data to be processed It includes a plurality of second sub-data; the data conversion circuit includes a first data conversion circuit and a second data conversion circuit. Correspondingly, the method further includes: the first data conversion circuit receives the first data to be processed, and converts a plurality of first sub-data in the first data to be processed into The first symbol data and absolute value data corresponding to the first sub-data; the second data conversion circuit receives the second data to be processed, and converts a plurality of second sub-data in the second data to be processed respectively are first sign data and absolute value data corresponding to each of the second sub-data.
在一种可选的实施方式中,所述计算电路包括符号运算电路、第一数值运算电路以及第二数值运算电路。相应地,所述方法还包括:所述符号运算电路响应于获取到所述第一符号数据,并基于所述第一符号数据,确定所述第一中间计算结果的第二符号数据,向所述第二数值运算电路传输所述第二符号数据;所述第一数值运算电路响应于获取到所述绝对值数据,对所述绝对值数据进行第一运算处理,得到所述第一中间计算结果;向所述第二数值运算电路传输所述第一中间计算结果;所述第二数值运算电路响应于接收到所述符号运算电路传输的所述第二符号数据以及所述第一数值运算电路传输的所述第一中间计算结果,基于所述第二符号数据以及所述第一中间计算结果,进行第二运算处理,得到所述待处理数据的目标处理结果。In an optional implementation manner, the calculation circuit includes a symbolic operation circuit, a first numerical operation circuit and a second numerical operation circuit. Correspondingly, the method further includes: the symbolic operation circuit responds to the acquisition of the first symbolic data, and based on the first symbolic data, determines the second symbolic data of the first intermediate calculation result, and sends to the The second numerical operation circuit transmits the second symbol data; the first numerical operation circuit performs a first operation on the absolute value data in response to obtaining the absolute value data to obtain the first intermediate calculation Result; transmit the first intermediate calculation result to the second numerical operation circuit; the second numerical operation circuit responds to receiving the second symbol data transmitted by the symbol operation circuit and the first numerical operation The first intermediate calculation result transmitted by the circuit, based on the second symbol data and the first intermediate calculation result, performs a second calculation process to obtain a target processing result of the data to be processed.
在一种可选的实施方式中,所述第一运算处理包括乘法处理;所述第二运算处理包括加法处理;所述待处理数据包括第一待处理数据和第二待处理数据;所述第一待处理数据包括多个第一子数据;所述第二待处理数据包括多个与所述第一子数据分别对应的第二子数据;所述第一符号数据,包括所述第一子数据的第一符号数据以及与所述第一子数据分别对应的所述第二子数据的第一符号数据;所述符号运算电路,包括异或门电路。相应地,所述方法还包括:所述异或门电路针对每个所述第一子数据,将每个所述第一子数据的第一符号数据和对应第二子数据的第一符号数据进行异或处理,得到将每个所述第一子数据和对应的第二子数据进行乘法处理后得到的所述第一中间计算结果的第二符号数据。In an optional implementation manner, the first operation processing includes multiplication processing; the second operation processing includes addition processing; the data to be processed includes first data to be processed and second data to be processed; The first data to be processed includes a plurality of first sub-data; the second data to be processed includes a plurality of second sub-data respectively corresponding to the first sub-data; the first symbol data includes the first The first symbol data of the sub-data and the first symbol data of the second sub-data respectively corresponding to the first sub-data; the symbol operation circuit includes an exclusive OR gate circuit. Correspondingly, the method further includes: for each of the first sub-data, the XOR gate circuit combines the first symbol data of each of the first sub-data with the first symbol data of the corresponding second sub-data Exclusive OR processing is performed to obtain second sign data of the first intermediate calculation result obtained by multiplying each of the first sub-data and the corresponding second sub-data.
在一种可选的实施方式中,所述绝对值数据包括每个所述第一子数据对应的第一绝对值数据以及每个所述第一子数据对应的所述第二子数据对应的第二绝对值数据;所述第一数值运算电路包括乘法器。相应地,所述方法还包括:所述乘法器针对每个所述第一子数据,将每个所述第一子数据的第一绝对值数据和对应第二子数据的第二绝对值数据进行乘积运算,得到每个所述第一子数据对应的第一中间计算结果。In an optional implementation manner, the absolute value data includes the first absolute value data corresponding to each of the first sub-data and the first absolute value data corresponding to each of the first sub-data The second absolute value data; the first numerical operation circuit includes a multiplier. Correspondingly, the method further includes: for each of the first sub-data, the multiplier combines the first absolute value data of each of the first sub-data with the second absolute value data of the corresponding second sub-data Performing a product operation to obtain a first intermediate calculation result corresponding to each of the first sub-data.
在一种可选的实施方式中,所述第二数值运算电路包括第二取反电路、第二选择器、第二加法器以及第三加法器。其中,所述第二取反电路接收所述第一数值运算电路传输的每个所述第一子数据对应的第一中间计算结果,并对每个所述第一子数据对应的第一中间计算结果进行按位取反操作,得到每个所述第一子数据对应的第二中间计算结果,并向所述第二选择器传输每个所述第一子数据对应的第二中间计算结果。所述第二选择器响应于接收所述符号运算电路传输的每个所述第一子数据对应的第一中间计算结果的所述第二符号数据、所述第二取反电路传输的每个所述第一子数据对应的第二中间计算结果以及所述第一数值运算电路传输的每个所述第一子数据对应的第一中间计算结果,将所述第二符号数据作为选择控制信号,控制将每个所述第一子数据对应的第一中间计算结果作为该第一子数据对应的第三中间计算结果输出,或者控制将每个所述第一子数据对应的第二中间计算结果作为该第一子数据对应的第三中间计算结果输出;向所述第三加法器传输每个所述第一子数据对应的第三中间计算结果。所述第二加法器响应于接收所述符号运算电路传输的每个所述第一子数据对应的第一中间计算结果的所述第二符号数据,对每个所述第一子数据对应的第一中间计算结果的所述第二符号数据进行求和,得到第四中间计算结果;向所述第三加法器传输所述第四中间计算结果。所述第三加法器响应于接收到每个所述第一子数据对应的第三中间计算结果以及所述第四中间计算结果,对每个所述第一子数据对应的第三中间计算结果和所述第四中间计算结果求和,得到所述目标处理结果。In an optional implementation manner, the second numerical operation circuit includes a second negation circuit, a second selector, a second adder, and a third adder. Wherein, the second negation circuit receives the first intermediate calculation result corresponding to each of the first sub-data transmitted by the first numerical operation circuit, and calculates the first intermediate calculation result corresponding to each of the first sub-data performing a bitwise inversion operation on the calculation result to obtain a second intermediate calculation result corresponding to each of the first sub-data, and transmitting the second intermediate calculation result corresponding to each of the first sub-data to the second selector . The second selector responds to receiving the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data transmitted by the symbol operation circuit, and each of the first intermediate calculation results transmitted by the second negation circuit. The second intermediate calculation result corresponding to the first sub-data and the first intermediate calculation result corresponding to each of the first sub-data transmitted by the first numerical operation circuit, using the second symbol data as a selection control signal , control to output the first intermediate calculation result corresponding to each of the first sub-data as the third intermediate calculation result corresponding to the first sub-data, or control to output the second intermediate calculation result corresponding to each of the first sub-data The result is output as a third intermediate calculation result corresponding to the first sub-data; and the third intermediate calculation result corresponding to each of the first sub-data is transmitted to the third adder. The second adder responds to receiving the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data transmitted by the symbol operation circuit, and for each of the first sub-data corresponding to Summing the second sign data of the first intermediate calculation result to obtain a fourth intermediate calculation result; transmitting the fourth intermediate calculation result to the third adder. In response to receiving the third intermediate calculation result and the fourth intermediate calculation result corresponding to each of the first sub-data, the third adder calculates the third intermediate calculation result corresponding to each of the first sub-data summing the fourth intermediate calculation result to obtain the target processing result.
在一种可选的实施方式中,所述第一待处理数据包括第一待处理矩阵;所述第二待处理数据包括第二待处理矩阵;多个所述第一子数据包括所述第一待处理矩阵中位于第i行的多个矩阵元素;多个所述第二子数据包括所述第二待处理矩阵中位于第j列的多个矩阵元素;i∈[1,N],N为大于或者等于2的正整数,表示第一待处理矩阵的总行数;j∈[1,M],M为大于或者等于2的正整数,表示第二待处理矩阵的总列数。In an optional implementation manner, the first data to be processed includes a first matrix to be processed; the second data to be processed includes a second matrix to be processed; the plurality of first sub-data includes the first A plurality of matrix elements located in row i in a matrix to be processed; a plurality of the second sub-data includes a plurality of matrix elements located in column j in the second matrix to be processed; i∈[1,N], N is a positive integer greater than or equal to 2, representing the total number of rows of the first matrix to be processed; j∈[1, M], M being a positive integer greater than or equal to 2, representing the total number of columns of the second matrix to be processed.
由于本公开实施例中的方法解决问题的原理、以及关于方法处理流程与本公开实施例对应的数据处理装置实施例中的相关说明相似,因此方法的实施可以参见上述数据处理装置的实施,重复之处不再赘述。Since the problem-solving principle of the method in the embodiment of the present disclosure is similar to the relevant description in the embodiment of the data processing device corresponding to the embodiment of the present disclosure, the implementation of the method can refer to the implementation of the above-mentioned data processing device, repeat The place will not be repeated.
本领域技术人员可以理解,在具体实施方式的上述方法中,各步骤的撰写顺序并不意味着严格的执行顺序而对实施过程构成任何限定,各步骤的具体执行顺序应当以其功能和可能的内在逻辑确定。Those skilled in the art can understand that in the above method of specific implementation, the writing order of each step does not mean a strict execution order and constitutes any limitation on the implementation process. The specific execution order of each step should be based on its function and possible The inner logic is OK.
本公开实施例还提供了一种芯片,包括如本公开实施例提供的数据处理装置。The embodiment of the present disclosure also provides a chip, including the data processing device as provided in the embodiment of the present disclosure.
本公开实施例还提供一种计算机设备,包括:存储器和本公开实施例提供的数据处理装置。The embodiment of the present disclosure also provides a computer device, including: a memory and the data processing apparatus provided in the embodiment of the present disclosure.
本公开实施例还提供一种计算机设备,包括芯片。The embodiment of the present disclosure also provides a computer device, including a chip.
本公开实施例提供的数据处理装置可以包括芯片、AI芯片等。本公开实施例提供的计算机设备可以包括手机等智能终端,或者也可以是其他可以用于进行数据处理的设备、服务器等,这里并不限制。The data processing apparatus provided by the embodiments of the present disclosure may include a chip, an AI chip, and the like. The computer device provided in the embodiment of the present disclosure may include a smart terminal such as a mobile phone, or may also be other devices, servers, etc. that can be used for data processing, which is not limited here.
本公开实施例还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被计算机设备运行时,所述计算机设备执行上述方法实施例中所述的数据处理方法的步骤。其中,该存储介质可以是易失性或非易失的计算机可读取存储介质。Embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a computer device, the computer device executes the data processing described in the foregoing method embodiments. method steps. Wherein, the storage medium may be a volatile or non-volatile computer-readable storage medium.
本公开实施例还提供一种计算机程序产品,该计算机程序产品承载有程序代码,所述程序代码包括的指令可用于执行上述方法实施例中所述的数据处理方法的步骤,具体 可参见上述方法实施例,在此不再赘述。Embodiments of the present disclosure also provide a computer program product, the computer program product carries a program code, and the instructions included in the program code can be used to execute the steps of the data processing method described in the above method embodiment, for details, please refer to the above method The embodiment will not be repeated here.
其中,上述计算机程序产品可以具体通过硬件、软件或其结合的方式实现。在一个可选实施例中,所述计算机程序产品具体体现为计算机存储介质,在另一个可选实施例中,计算机程序产品具体体现为软件产品,例如软件开发包(Software Development Kit,SDK)等等。所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统和装置的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。在本公开所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。Wherein, the above-mentioned computer program product may be specifically implemented by means of hardware, software or a combination thereof. In an optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK) etc. wait. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the above-described system and device can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods may be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个处理器可执行的非易失的计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present disclosure. The aforementioned storage medium includes various media that can store program codes such as U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk.
最后应说明的是,以上所述实施例,仅为本公开的具体实施方式,用以说明本公开的技术方案,而非对其限制,本公开的保护范围并不局限于此,尽管参照前述实施例对本公开进行了详细的说明,本领域的普通技术人员应当理解,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,其依然可以对前述实施例所记载的技术方案进行修改或可轻易想到变化,或者对其中部分技术特征进行等同替换;而这些修改、变化或者替换,并不使相应技术方案的本质脱离本公开实施例技术方案的精神和范围,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应所述以权利要求的保护范围为准。Finally, it should be noted that the above-described embodiments are only specific implementations of the present disclosure, and are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto, although referring to the aforementioned The embodiments have described the present disclosure in detail, and those skilled in the art should understand that any person familiar with the technical field can still modify the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present disclosure Changes can be easily imagined, or equivalent replacements can be made to some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in this disclosure. within the scope of protection. Therefore, the protection scope of the present disclosure should be defined by the protection scope of the claims.

Claims (16)

  1. 一种数据处理装置,其特征在于,包括:A data processing device, characterized in that it comprises:
    数据转化电路,用于接收待处理数据,并将所述待处理数据转化为第一符号数据以及绝对值数据,其中,所述第一符号数据表征对应的所述待处理数据为正值或者负值;A data conversion circuit, configured to receive data to be processed, and convert the data to be processed into first symbol data and absolute value data, wherein the first symbol data indicates that the corresponding data to be processed is positive or negative value;
    计算电路,用于:Calculation circuit for:
    获取所述数据转化电路生成的所述第一符号数据以及所述绝对值数据;Acquiring the first symbol data and the absolute value data generated by the data conversion circuit;
    对所述绝对值数据进行第一运算处理,得到第一中间计算结果;performing a first calculation process on the absolute value data to obtain a first intermediate calculation result;
    基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;determining second sign data of the first intermediate calculation result based on the first sign data;
    基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的目标处理结果。Performing a second calculation process based on the second symbol data and the first intermediate calculation result to obtain a target processing result of the data to be processed.
  2. 根据权利要求1所述的装置,其特征在于,The device according to claim 1, characterized in that,
    所述数据转化电路的输出端和所述计算电路的输入端连接;The output end of the data conversion circuit is connected to the input end of the calculation circuit;
    所述数据转化电路还用于通过所述数据转化电路的输出端向所述计算电路的输入端传输所述第一符号数据以及所述绝对值数据。The data conversion circuit is further configured to transmit the first symbol data and the absolute value data to the input terminal of the calculation circuit through the output terminal of the data conversion circuit.
  3. 根据权利要求1所述的装置,其特征在于,The device according to claim 1, characterized in that,
    所述装置还包括第一寄存器以及第二寄存器;The device also includes a first register and a second register;
    所述数据转化电路还用于将所述第一符号数据存储至所述第一寄存器,以及将所述绝对值数据存储至所述第二寄存器;The data conversion circuit is further configured to store the first sign data into the first register, and store the absolute value data into the second register;
    所述计算电路还用于从所述第一寄存器中读取所述第一符号数据,以及从所述第二寄存器中读取所述绝对值数据。The calculation circuit is also used to read the first sign data from the first register, and read the absolute value data from the second register.
  4. 根据权利要求1-3任一项所述的装置,其特征在于,所述数据转化电路包括:The device according to any one of claims 1-3, wherein the data conversion circuit comprises:
    第一转化电路,用于接收所述待处理数据中预设第一比特位的第一数值,并将接收到的所述第一数值作为所述第一符号数据;A first conversion circuit, configured to receive a first numerical value of a preset first bit in the data to be processed, and use the received first numerical value as the first symbol data;
    第二转化电路,用于接收所述待处理数据中预设第二比特位的第二数值,并基于所述第一转化电路传输的所述第一数值,对所述第二数值进行转化处理,得到所述绝对值数据。A second conversion circuit, configured to receive a second value preset in a second bit in the data to be processed, and perform conversion processing on the second value based on the first value transmitted by the first conversion circuit , to obtain the absolute value data.
  5. 根据权利要求4所述的装置,其特征在于,所述第二转化电路包括:The device according to claim 4, wherein the second converting circuit comprises:
    第一加法器,用于响应于接收到所述待处理数据中预设第二比特位的第二数值,将所述第二数值和预设数值求和,得到第一中间数值;A first adder, configured to sum the second value and the preset value to obtain a first intermediate value in response to receiving a second value of a preset second bit in the data to be processed;
    第一取反电路,所述第一取反电路的输入端与所述第一加法器的输出端连接,用于响应于接收到所述第一加法器传输的所述第一中间数值,对所述第一中间数值进行按位取反操作,得到第二中间数值;A first inversion circuit, the input end of the first inversion circuit is connected to the output end of the first adder, and is used for responding to receiving the first intermediate value transmitted by the first adder, for performing a bitwise inversion operation on the first intermediate value to obtain a second intermediate value;
    第一选择器,所述第一选择器的输入端与所述第一转换电路的输出端以及所述第一取反电路的输出端连接,用于响应于接收到所述待处理数据中预设第二比特位的第二数值、所述第一取反电路传输的所述第二中间数值、以及所述第一转化电路传输的所述第一数值,将所述第一数值作为选择控制信号,控制将所述第二数值作为所述绝对值数据输出、或者控制将所述第二中间数值作为所述绝对值数据输出。A first selector, the input end of the first selector is connected to the output end of the first conversion circuit and the output end of the first inverting circuit, and is used for responding to receiving the preset in the data to be processed Set the second value of the second bit, the second intermediate value transmitted by the first negation circuit, and the first value transmitted by the first conversion circuit, and use the first value as a selection control signal, control to output the second value as the absolute value data, or control to output the second intermediate value as the absolute value data.
  6. 根据权利要求1-5任一项所述的装置,其特征在于,所述待处理数据包括第一 待处理数据和第二待处理数据;所述第一待处理数据包括多个第一子数据;所述第二待处理数据包括多个第二子数据;所述数据转化电路包括:The device according to any one of claims 1-5, wherein the data to be processed includes first data to be processed and second data to be processed; the first data to be processed includes a plurality of first sub-data ; The second data to be processed includes a plurality of second sub-data; the data conversion circuit includes:
    第一数据转化电路,用于接收所述第一待处理数据,并将所述第一待处理数据中的多个第一子数据分别转化为与每个所述第一子数据对应的第一符号数据以及绝对值数据;A first data conversion circuit, configured to receive the first data to be processed, and convert a plurality of first sub-data in the first data to be processed into first data corresponding to each of the first sub-data symbolic data as well as absolute value data;
    第二数据转化电路,用于接收所述第二待处理数据,并将所述第二待处理数据中的多个第二子数据分别转化为与每个所述第二子数据对应的第一符号数据以及绝对值数据。The second data conversion circuit is configured to receive the second data to be processed, and convert a plurality of second sub-data in the second data to be processed into first data corresponding to each of the second sub-data Symbolic data as well as absolute value data.
  7. 根据权利要求1-6任一项所述的装置,其特征在于,所述计算电路包括:The device according to any one of claims 1-6, wherein the computing circuit comprises:
    符号运算电路,用于响应于获取到所述第一符号数据,基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;a sign operation circuit, configured to determine second sign data of the first intermediate calculation result based on the first sign data in response to acquiring the first sign data;
    第一数值运算电路,用于响应于获取到所述绝对值数据,对所述绝对值数据进行第一运算处理,得到所述第一中间计算结果;A first numerical operation circuit, configured to, in response to acquiring the absolute value data, perform a first operation on the absolute value data to obtain the first intermediate calculation result;
    第二数值运算电路,所述第二数值运算电路的输入端与所述符号运算电路的输出端以及所述第一数值运算电路的输出端连接,用于响应于接收到所述符号运算电路传输的所述第二符号数据、以及所述第一数值运算电路传输的所述第一中间计算结果,基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的目标处理结果。The second numerical operation circuit, the input end of the second numerical operation circuit is connected to the output end of the symbolic operation circuit and the output end of the first numerical operation circuit, and is used to respond to receiving the transmission from the symbolic operation circuit The second symbol data and the first intermediate calculation result transmitted by the first numerical operation circuit, based on the second symbol data and the first intermediate calculation result, a second calculation process is performed to obtain the The target processing result for the data to be processed.
  8. 根据权利要求7所述的装置,其特征在于,The device according to claim 7, characterized in that,
    所述第一运算处理包括乘法处理;The first arithmetic processing includes multiplication processing;
    所述第二运算处理包括加法处理;The second arithmetic processing includes addition processing;
    所述待处理数据包括第一待处理数据和第二待处理数据;The data to be processed includes first data to be processed and second data to be processed;
    所述第一待处理数据包括多个第一子数据;The first data to be processed includes a plurality of first sub-data;
    所述第二待处理数据包括多个与所述第一子数据分别对应的第二子数据;The second data to be processed includes a plurality of second sub-data respectively corresponding to the first sub-data;
    所述第一符号数据包括所述第一子数据的第一符号数据以及与所述第一子数据分别对应的所述第二子数据的第一符号数据;The first symbol data includes first symbol data of the first sub-data and first symbol data of the second sub-data respectively corresponding to the first sub-data;
    所述符号运算电路包括异或门电路;The symbol operation circuit includes an exclusive OR gate circuit;
    所述异或门电路用于针对每个所述第一子数据,将每个所述第一子数据的第一符号数据和对应第二子数据的第一符号数据进行异或处理,得到将每个所述第一子数据和对应的第二子数据进行乘法处理后得到的所述第一中间计算结果的第二符号数据。The XOR gate circuit is used to perform XOR processing on the first symbol data of each of the first sub-data and the first symbol data corresponding to the second sub-data for each of the first sub-data, to obtain The second symbol data of the first intermediate calculation result obtained after each of the first sub-data and the corresponding second sub-data is multiplied.
  9. 根据权利要求8所述的装置,其特征在于,所述绝对值数据包括每个所述第一子数据对应的第一绝对值数据以及每个所述第一子数据对应的所述第二子数据对应的第二绝对值数据;The device according to claim 8, wherein the absolute value data includes first absolute value data corresponding to each of the first sub-data and the second sub-data corresponding to each of the first sub-data The second absolute value data corresponding to the data;
    所述第一数值运算电路包括乘法器;The first numerical operation circuit includes a multiplier;
    所述乘法器用于针对每个所述第一子数据,将每个所述第一子数据的第一绝对值数据和对应第二子数据的第二绝对值数据进行乘积运算,得到每个所述第一子数据对应的第一中间计算结果。The multiplier is configured to, for each of the first sub-data, perform a product operation on the first absolute value data of each of the first sub-data and the second absolute value data corresponding to the second sub-data to obtain each of the first sub-data The first intermediate calculation result corresponding to the first sub-data.
  10. 根据权利要求8或9所述的装置,其特征在于,所述第二数值运算电路包括:The device according to claim 8 or 9, wherein the second numerical operation circuit comprises:
    第二取反电路,所述第二取反电路的输入端与所述第一数值运算电路的输出端连接, 用于接收所述第一数值运算电路传输的每个所述第一子数据对应的第一中间计算结果,并对每个所述第一子数据对应的第一中间计算结果进行按位取反操作,得到每个所述第一子数据对应的第二中间计算结果;A second inversion circuit, the input end of the second inversion circuit is connected to the output end of the first numerical operation circuit, and is used to receive each of the first sub-data corresponding to the transmission of the first numerical operation circuit and performing a bitwise inversion operation on the first intermediate calculation result corresponding to each of the first sub-data to obtain a second intermediate calculation result corresponding to each of the first sub-data;
    第二选择器,所述第二选择器的输入端分别与所述第二取反电路的输出端、以及所述符号运算电路的输出端、以及所述第一数值运算电路的输出端连接,用于响应于接收所述符号运算电路传输的每个所述第一子数据对应的第一中间计算结果的所述第二符号数据、所述第二取反电路传输的每个所述第一子数据对应的第二中间计算结果、以及所述第一数值运算电路传输的每个所述第一子数据对应的第一中间计算结果,将所述第二符号数据作为选择控制信号,控制将每个所述第一子数据对应的第一中间计算结果作为该第一子数据对应的第三中间计算结果输出,或者控制将每个所述第一子数据对应的第二中间计算结果作为该第一子数据对应的第三中间计算结果输出;a second selector, the input end of the second selector is respectively connected to the output end of the second negation circuit, the output end of the symbol operation circuit, and the output end of the first numerical operation circuit, In response to receiving the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data transmitted by the symbol operation circuit, each of the first sub-data transmitted by the second inverting circuit The second intermediate calculation result corresponding to the sub-data, and the first intermediate calculation result corresponding to each of the first sub-data transmitted by the first numerical operation circuit, the second symbol data is used as a selection control signal, and the control will The first intermediate calculation result corresponding to each of the first sub-data is output as the third intermediate calculation result corresponding to the first sub-data, or control the second intermediate calculation result corresponding to each of the first sub-data as the output outputting the third intermediate calculation result corresponding to the first sub-data;
    第二加法器,所述第二加法器的输入端与所述符号运算电路的输出端连接,用于响应于接收所述符号运算电路传输的每个所述第一子数据对应的第一中间计算结果的所述第二符号数据,对每个所述第一子数据对应的第一中间计算结果的所述第二符号数据进行求和,得到第四中间计算结果;The second adder, the input terminal of the second adder is connected to the output terminal of the symbol operation circuit, and is used to respond to receiving the first intermediate corresponding to each of the first sub-data transmitted by the symbol operation circuit For the second symbol data of the calculation result, sum the second symbol data of the first intermediate calculation result corresponding to each of the first sub-data to obtain a fourth intermediate calculation result;
    第三加法器,所述第三加法器的输入端分别与所述第二选择器的输出端、以及所述第二加法器的输出端连接,用于响应于接收到每个所述第一子数据对应的第三中间计算结果、以及所述第四中间计算结果,对每个所述第一子数据对应的第三中间计算结果、和所述第四中间计算结果求和,得到所述目标处理结果。A third adder, the input end of the third adder is respectively connected to the output end of the second selector and the output end of the second adder, for responding to receiving each of the first The third intermediate calculation result corresponding to the sub-data and the fourth intermediate calculation result are summed to the third intermediate calculation result corresponding to each of the first sub-data and the fourth intermediate calculation result to obtain the Target processing result.
  11. 根据权利要求8-10任一项所述的装置,其特征在于,The device according to any one of claims 8-10, characterized in that,
    所述第一待处理数据包括第一待处理矩阵;The first data to be processed includes a first matrix to be processed;
    所述第二待处理数据包括第二待处理矩阵;The second data to be processed includes a second matrix to be processed;
    多个所述第一子数据包括所述第一待处理矩阵中位于第i行的多个矩阵元素,i∈[1,N];The plurality of first sub-data includes a plurality of matrix elements located in row i in the first matrix to be processed, i∈[1,N];
    多个所述第二子数据包括所述第二待处理矩阵中位于第j列的多个矩阵元素,j∈[1,M];The plurality of second sub-data includes a plurality of matrix elements located in column j in the second matrix to be processed, j∈[1,M];
    N为大于或者等于2的正整数,表示所述第一待处理矩阵的总行数;N is a positive integer greater than or equal to 2, representing the total number of rows of the first matrix to be processed;
    M为大于或者等于2的正整数,表示所述第二待处理矩阵的总列数。M is a positive integer greater than or equal to 2, and represents the total number of columns of the second matrix to be processed.
  12. 一种数据处理方法,其特征在于,应用于数据处理装置,所述数据处理装置包括数据转化电路以及计算电路;所述方法包括:A data processing method, characterized in that it is applied to a data processing device, and the data processing device includes a data conversion circuit and a calculation circuit; the method includes:
    所述数据转化电路接收待处理数据,并将所述待处理数据转化为第一符号数据以及绝对值数据;The data conversion circuit receives the data to be processed, and converts the data to be processed into first symbol data and absolute value data;
    所述数据转化电路向所述计算电路传输所述第一符号数据以及所述绝对值数据;其中,所述第一符号数据表征对应的所述待处理数据为正值或者负值;The data conversion circuit transmits the first symbol data and the absolute value data to the calculation circuit; wherein, the first symbol data indicates that the corresponding data to be processed is a positive value or a negative value;
    所述计算电路获取所述数据转化电路生成的所述第一符号数据以及所述绝对值数据,对所述绝对值数据进行第一运算处理,得到第一中间计算结果;The calculation circuit acquires the first symbol data and the absolute value data generated by the data conversion circuit, performs a first calculation process on the absolute value data, and obtains a first intermediate calculation result;
    所述计算电路基于所述第一符号数据确定所述第一中间计算结果的第二符号数据;the calculation circuit determines second sign data of the first intermediate calculation result based on the first sign data;
    所述计算电路基于所述第二符号数据以及所述第一中间计算结果进行第二运算处理,得到所述待处理数据的处理结果。The calculation circuit performs a second calculation process based on the second symbol data and the first intermediate calculation result to obtain a processing result of the data to be processed.
  13. 一种芯片,其特征在于,包括如权利要求1-11任一项所述的数据处理装置。A chip, characterized by comprising the data processing device according to any one of claims 1-11.
  14. 一种计算机设备,其特征在于,包括:A computer device, characterized in that it includes:
    存储器;和memory; and
    如权利要求1-11任一项所述的数据处理装置。The data processing device according to any one of claims 1-11.
  15. 一种计算机设备,其特征在于,包括如权利要求13所述的芯片。A computer device, characterized by comprising the chip as claimed in claim 13.
  16. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被计算机设备运行时,所述计算机设备执行如权利要求12所述的数据处理方法的步骤。A computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is run by a computer device, the computer device executes the data processing method according to claim 12 A step of.
PCT/CN2022/124516 2021-12-31 2022-10-11 Data processing apparatus and method, and chip, computer device and storage medium WO2023124371A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111666460.4A CN114329330A (en) 2021-12-31 2021-12-31 Data processing device, method, chip, computer equipment and storage medium
CN202111666460.4 2021-12-31

Publications (1)

Publication Number Publication Date
WO2023124371A1 true WO2023124371A1 (en) 2023-07-06

Family

ID=81020407

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/124516 WO2023124371A1 (en) 2021-12-31 2022-10-11 Data processing apparatus and method, and chip, computer device and storage medium

Country Status (2)

Country Link
CN (1) CN114329330A (en)
WO (1) WO2023124371A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114329330A (en) * 2021-12-31 2022-04-12 上海阵量智能科技有限公司 Data processing device, method, chip, computer equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5148386A (en) * 1989-06-06 1992-09-15 Kabushiki Kaisha Toshiba Adder-subtracter for signed absolute values
JPH09319732A (en) * 1996-05-28 1997-12-12 Sony Corp Discrete cosine transforming device
JP2009267606A (en) * 2008-04-23 2009-11-12 Toshiba Corp Computing unit
WO2019057093A1 (en) * 2017-09-19 2019-03-28 华为技术有限公司 Multiplication circuit, system on chip, and electronic device
CN113222132A (en) * 2021-05-22 2021-08-06 上海阵量智能科技有限公司 Multiplier, data processing method, chip, computer device and storage medium
CN114329330A (en) * 2021-12-31 2022-04-12 上海阵量智能科技有限公司 Data processing device, method, chip, computer equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5148386A (en) * 1989-06-06 1992-09-15 Kabushiki Kaisha Toshiba Adder-subtracter for signed absolute values
JPH09319732A (en) * 1996-05-28 1997-12-12 Sony Corp Discrete cosine transforming device
JP2009267606A (en) * 2008-04-23 2009-11-12 Toshiba Corp Computing unit
WO2019057093A1 (en) * 2017-09-19 2019-03-28 华为技术有限公司 Multiplication circuit, system on chip, and electronic device
CN113222132A (en) * 2021-05-22 2021-08-06 上海阵量智能科技有限公司 Multiplier, data processing method, chip, computer device and storage medium
CN114329330A (en) * 2021-12-31 2022-04-12 上海阵量智能科技有限公司 Data processing device, method, chip, computer equipment and storage medium

Also Published As

Publication number Publication date
CN114329330A (en) 2022-04-12

Similar Documents

Publication Publication Date Title
CN107729989B (en) Device and method for executing artificial neural network forward operation
CN110447010B (en) Performing matrix multiplication in hardware
US11507350B2 (en) Processing apparatus and processing method
US11599773B2 (en) Neural networks and systems for decoding encoded data
JP2018055677A (en) Processor and method for outer product accumulate operations
CN107256424B (en) Three-value weight convolution network processing system and method
US11424764B2 (en) Recurrent neural networks and systems for decoding encoded data
CN107944545B (en) Computing method and computing device applied to neural network
CN110163360B (en) Computing device and method
CN111008003B (en) Data processor, method, chip and electronic equipment
KR20190107766A (en) Computing device and method
CN110109646B (en) Data processing method, data processing device, multiplier-adder and storage medium
WO2022247194A1 (en) Multiplier, data processing method, chip, computer device and storage medium
CN112114776A (en) Quantum multiplication method and device, electronic device and storage medium
WO2023124371A1 (en) Data processing apparatus and method, and chip, computer device and storage medium
Tsmots et al. Neural-like means for data streams encryption and decryption in real time
CN111045728A (en) Computing device and related product
CN111353598A (en) Neural network compression method, electronic device and computer readable medium
CN110515587B (en) Multiplier, data processing method, chip and electronic equipment
CN111914987A (en) Data processing method and device based on neural network, equipment and readable medium
CN113986194A (en) Neural network approximate multiplier implementation method and device based on preprocessing
CN113504892A (en) Method, system, equipment and medium for designing multiplier lookup table
KR102482300B1 (en) Bit serial computation method and apparatus including modified harley-seal popcount
CN112132272A (en) Computing device, processor and electronic equipment of neural network
CN111047024A (en) Computing device and related product

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22913635

Country of ref document: EP

Kind code of ref document: A1