Data processing method and device, electronic equipment and storage medium

By converting the data format and adjusting the precision bits of the element values ​​of the matrix to be processed, the problem of increased data bit width and reduced precision in matrix operations is solved, and storage space is saved and the accuracy of the operation results is achieved.

CN118535844APending Publication Date: 2024-08-23SHANGHAI POWERTENSORS INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410295201.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-14
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

During the matrix operation process, the data bit width of the intermediate data continues to increase, resulting in problems such as high storage space usage and reduced accuracy of operation results.

Method used

By converting the data format of the element values ​​of the matrix to be processed, adding precision bits to control the data bit width of the intermediate data, and retaining data precision by adjusting the precision unit to ensure the accuracy of the operation results.

Benefits of technology

It effectively reduces the storage space occupied, improves the accuracy of intermediate data, and ensures the accuracy of operation results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535844A
    Figure CN118535844A
Patent Text Reader

Abstract

The invention provides a data processing method and device, electronic equipment and a storage medium. The method comprises the steps that a to-be-processed matrix pair is acquired; performing data format conversion on each first element value of a first to-be-processed matrix and each second element value of a second to-be-processed matrix in the to-be-processed matrix pair to obtain a first target matrix comprising the converted first element values and a second target matrix comprising the converted second element values; wherein the data format of the converted first element value and the converted second element value comprises a precision bit and a data bit, a numerical value located on the precision bit represents a precision unit corresponding to the converted element value, and a numerical value located on the data bit represents a target value of the converted element value under the precision unit; and performing matrix operation on the first target matrix and the second target matrix to obtain an operation result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a data processing method, device, electronic device and storage medium. Background Art

[0002] Matrix operations are often required in applications such as neural networks or two-dimensional image transformation. For example, when performing convolution operations in neural networks, matrix operations need to be performed on the input feature data and the convolution kernel. In the transformation of two-dimensional images, the homography matrix needs to be determined, and the homography matrix is ​​calculated from multiple matching pairs, and matrix operations are involved in the calculation process.

[0003] Generally, the data bit width of the intermediate data generated during the matrix operation will continue to increase, and the storage space capacity required will also increase; therefore, the obtained operation results need to be embedded before they can be used. However, the embedding operation will cause the accuracy of the matrix operation results to decrease. Summary of the invention

[0004] In view of this, the present disclosure at least provides a data processing method, device, electronic device and storage medium.

[0005] In a first aspect, the present disclosure provides a data processing method, comprising:

[0006] Get the matrix pair to be processed;

[0007] Performing data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical values ​​located at the precision bits represent the precision units corresponding to the converted element values, and the numerical values ​​located at the data bits represent the target values ​​of the converted element values ​​under the precision units;

[0008] A matrix operation is performed on the first target matrix and the second target matrix to obtain an operation result.

[0009] In the above method, data format conversion is performed on each first element value of the first matrix to be processed to obtain a first target matrix including the converted first element value, and data format conversion is performed on each second element value of the second matrix to be processed to obtain a second target matrix including the converted second element value; wherein the data format of the converted first element value and the converted second element value includes precision bits and data bits, the numerical value located on the precision bits represents the precision unit corresponding to the converted element value, and the numerical value located on the data bits is the target value of the converted element value under the precision unit; by increasing the precision bits, the data bits and precision bits can be used to more accurately represent the element value.

[0010] Furthermore, when performing matrix operations on the first target matrix and the second target matrix, the data bit width of the intermediate data generated during the operation can be controlled within the preset data bit width to reduce the storage space capacity; at the same time, the data precision of the intermediate data can be retained by adjusting the precision unit, so that the data precision of the intermediate data obtained is more accurate, thereby ensuring that the accuracy of the obtained operation results is more accurate.

[0011] In a possible implementation manner, performing a matrix operation on the first target matrix and the second target matrix to obtain an operation result includes:

[0012] For each of the converted first element values ​​in the first target matrix, based on the operation logic corresponding to the matrix operation, determine a target second element value matching the converted first element value from the converted second element values ​​included in the second target matrix; and

[0013] Based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, a target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result;

[0014] The operation result is determined based on the intermediate results respectively corresponding to the converted first element values.

[0015] Here, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, target operations are performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value, so that the accuracy of the intermediate result can be more accurate; and further, based on the intermediate results corresponding to each converted first element value, the accuracy of the determined operation result can be made more accurate.

[0016] In a possible implementation, the target operation includes a multiplication operation; and the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result, including:

[0017] Determining a target precision unit corresponding to the target operation based on the first precision unit and the second precision unit;

[0018] Performing a multiplication operation on the first target value and the second target value to obtain a product result in the target precision unit; wherein the product result includes a value located at a preset number of data bits, and the data bits include a high-order data bit and a low-order data bit;

[0019] Based on the first precision unit and the second precision unit, a precision preserving operation is performed on the product result in the target precision unit to obtain an intermediate result.

[0020] Here, based on the first precision unit and the second precision unit, the target precision unit corresponding to the target operation can be determined more quickly; and the first target value and the second target value can be multiplied to obtain the product result in the target precision unit; then, based on the first precision unit and the second precision unit, the product result in the target precision unit can be subjected to precision preservation operation to obtain an intermediate result, thereby improving chip performance while ensuring that the accuracy of the intermediate result is more accurate.

[0021] In a possible implementation, performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes:

[0022] When it is determined that the first precision unit is the same as the second precision unit and the first precision unit is less than a first preset value, determining whether a second preset value exists in the numerical value located at the high-order data bit in the multiplication result;

[0023] If it exists, retain the value of the high-order data bit in the product result, and generate an intermediate result based on the value of the high-order data bit and the target precision unit;

[0024] If not, retaining the value located at the low-order data bit in the product result; and adjusting the target precision unit to obtain a first adjusted precision unit, wherein the first adjusted precision unit is smaller than the target precision unit; and generating an intermediate result based on the value located at the low-order data bit and the first adjusted precision unit;

[0025] Alternatively, if it does not exist, the values ​​of the low-order data bits in the product result are adjusted to the second preset value that does not exist, so as to obtain the adjusted values ​​of the low-order data bits; and based on the adjusted values ​​of the low-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the minimum precision unit.

[0026] In the disclosed embodiment, the precision-preserving operation can be performed on the product result more quickly based on the first precision unit and the second precision unit to obtain an intermediate result, thereby reducing the complexity of the operation and improving the operation speed. At the same time, the precision unit can be used to ensure the accuracy of the intermediate result.

[0027] In a possible implementation, performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes:

[0028] In the case where it is determined that the first precision unit is the same as the second precision unit and the first precision unit is greater than or equal to a first preset value, determining whether a value located at the high-order data bit in the product result has a second preset value;

[0029] If not, retaining the value located at the low-order data bit in the product result, and generating an intermediate result based on the value located at the low-order data bit and the target precision unit;

[0030] If it exists, retaining the value located at the high-order data bit in the product result; and adjusting the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generating an intermediate result based on the value located at the high-order data bit and the second adjusted precision unit;

[0031] Alternatively, if it exists, the values ​​of the high-order data bits in the product result are all adjusted to the second preset value to obtain the adjusted values ​​of the high-order data bits; and based on the adjusted values ​​of the high-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the maximum precision unit.

[0032] In a possible implementation, performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes:

[0033] In the case where it is determined that the first precision unit and the second precision unit are different, determining whether a second preset value exists in the numerical value located at the high-order data bit in the multiplication result;

[0034] If not, retaining the value located at the low-order data bit in the product result, and generating an intermediate result based on the value located at the low-order data bit and the target precision unit;

[0035] If it exists, retain the numerical value located at the high data bit in the product result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the numerical value located at the high data bit and the second adjusted precision unit.

[0036] In a possible implementation manner, the performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result further includes:

[0037] When it is determined that the first precision unit and the second precision unit are different, and both the first precision unit and the second precision unit are smaller than a first preset value, the values ​​of the low-order data bits in the multiplication result are adjusted so that the second preset value does not exist, and the values ​​of the low-order data bits after adjustment are obtained;

[0038] An intermediate result is generated based on the value of the adjusted low-order data bit and the target precision unit, wherein the target precision unit and the first precision unit are minimum precision units.

[0039] In a possible implementation manner, the target operation includes an addition operation; and the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result, including:

[0040] When it is determined that the first precision unit and the second precision unit are the same, adding the first target value and the second target value to obtain an addition result in the first precision unit;

[0041] When the number of bits of the data bits of the addition result is the same as the number of bits of the data bits of the first target value, determining the addition result as the intermediate result;

[0042] When the number of bits of the data bits of the addition result is different from the number of bits of the data bits of the first target value, the first precision unit is adjusted to obtain a third adjusted precision unit; and the value of the highest data bit is selected from the addition result; and an intermediate result is generated based on the third adjusted precision unit and the value of the highest data bit.

[0043] In the above method, when it is determined that the first precision unit and the second precision unit are the same, the first target value and the second target value are added to obtain the addition result in the first precision unit; then, based on the number of bits of the data bits of the addition result and the number of bits of the data bits of the first target value, it is determined whether data overflow occurs in the addition result, so that the intermediate result can be determined more accurately according to different methods.

[0044] In a possible implementation manner, the performing a target operation on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result further includes:

[0045] In the case where the first precision unit is smaller than the second precision unit, adjusting the first precision unit and the first target value of the converted first element value to obtain an adjusted element value; wherein the adjusted element value includes an adjusted precision unit and an adjusted target value, and the adjusted precision unit is one level larger than the first precision unit;

[0046] When it is determined that the adjusted precision unit is different from the second precision unit, the converted second element value is determined as the intermediate result.

[0047] In the above method, when the first precision unit is smaller than the second precision unit, the first precision unit and the first target value of the converted first element value are adjusted, and the adjusted precision unit of the obtained adjusted element value is larger than the first precision unit; when it is determined that the adjusted precision unit is different from the second precision unit, it means that the difference between the converted first element value and the converted second element value is large, so the converted second element value can be directly determined as the intermediate result, which can reduce the complexity of the calculation and improve the calculation speed.

[0048] The effects of the following devices, electronic devices, etc. are described in the description of the above method and will not be repeated here.

[0049] In a second aspect, the present disclosure provides a data processing device, including:

[0050] An acquisition module, used for acquiring a matrix pair to be processed;

[0051] A conversion module, used for performing data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical value located on the precision bits represents the precision unit corresponding to the converted element values, and the numerical value located on the data bits represents the target value of the converted element values ​​under the precision unit;

[0052] An operation module is used to perform matrix operation on the first target matrix and the second target matrix to obtain an operation result.

[0053] In a third aspect, the present disclosure provides an electronic device comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the data processing method described in the first aspect or any one of the embodiments are performed.

[0054] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the data processing method as described in the first aspect or any one of the embodiments are executed.

[0055] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.

[0057] Figure 1 A schematic diagram showing a flow chart of a data processing method provided by an embodiment of the present disclosure;

[0058] Figure 2 A schematic diagram of the architecture of a data processing device provided by an embodiment of the present disclosure is shown;

[0059] Figure 3 A schematic structural diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0060] 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. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.

[0061] Matrix operations are often required in applications such as neural networks or two-dimensional image transformation. For example, when performing convolution operations in neural networks, matrix operations need to be performed on the input feature data and the convolution kernel. In the transformation of two-dimensional images, the homography matrix needs to be determined, and the homography matrix is ​​calculated from multiple matching pairs, and matrix operations are involved in the calculation process.

[0062] During the matrix operation, the data width of the generated intermediate data will continue to increase. For example, when performing matrix multiplication operation on an MxN matrix and an NxM matrix, if the data width of each element value of the matrix is ​​32 bits, the value on the 16 high-order data bits represents the value of the integer part, and the value on the 16 low-order data bits represents the value of the decimal part, then the minimum element value can be 1 / 65536 and the maximum can be 65535; and the data width of the product obtained by multiplying two element values ​​is 64 bits, so the data width of the intermediate data generated during the matrix operation will continue to increase. Generally, the chip needs to design the storage space capacity according to the maximum data width, which makes the hardware cost higher. At the same time, due to the increase in the data width of the intermediate data, the obtained operation result needs to be used after bit embedding, but the bit embedding operation will reduce the accuracy of the operation result.

[0063] In order to alleviate the above problems, the embodiments of the present disclosure provide a data processing method, device, electronic device and storage medium.

[0064] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0065] To facilitate understanding of the embodiments of the present disclosure, a data processing method disclosed in the embodiments of the present disclosure is first introduced in detail. The execution subject of the data processing method provided in the embodiments of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example, a terminal device or a server. In some possible implementations, the data processing method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0066] See also Figure 1 FIG. 1 is a flow chart of a data processing method provided by an embodiment of the present disclosure, the method comprising: S101-S103, specifically:

[0067] S101, obtaining a matrix pair to be processed.

[0068] S102, respectively converting the data format of each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical value located on the precision bits represents the precision unit corresponding to the converted element values, and the numerical value located on the data bits represents the target value of the converted element values ​​under the precision unit.

[0069] S103, performing matrix operation on the first target matrix and the second target matrix to obtain operation results.

[0070] In the above method, data format conversion is performed on each first element value of the first matrix to be processed to obtain a first target matrix including the converted first element value, and data format conversion is performed on each second element value of the second matrix to be processed to obtain a second target matrix including the converted second element value; wherein the data format of the converted first element value and the converted second element value includes precision bits and data bits, the numerical value located on the precision bits represents the precision unit corresponding to the converted element value, and the numerical value located on the data bits is the target value of the converted element value under the precision unit; by increasing the precision bits, the data bits and precision bits can be used to more accurately represent the element value.

[0071] Furthermore, when performing matrix operations on the first target matrix and the second target matrix, the data bit width of the intermediate data generated during the operation can be controlled within the preset data bit width to reduce the storage space capacity; at the same time, the data precision of the intermediate data can be retained by adjusting the precision unit, so that the data precision of the intermediate data obtained is more accurate, thereby ensuring that the accuracy of the obtained operation results is more accurate.

[0072] S101 to S103 are described in detail below.

[0073] For S101 and S102:

[0074] The matrix pair to be processed may include any two matrix pairs that need to perform matrix operations. For example, in the neural network application scenario, the matrix pair to be processed may be the feature data input to the convolution layer in the neural network, and the matrix pair to be processed may include the input feature data and the weight feature data; in the image transformation application scenario, the matrix pair to be processed may also be the data to be processed when performing a two-dimensional image transformation, and the matrix pair to be processed may include the matrix data corresponding to the image to be processed and the transformation matrix, etc.

[0075] After obtaining the matrix to be processed, the first matrix to be processed and the second matrix to be processed in the matrix pair to be processed can be preprocessed first, that is, based on the mapping relationship between the numerical range and the precision bit value, each first element value of the first matrix to be processed can be converted into a data format to obtain a first target matrix including the converted first element value; and each second element value of the second matrix to be processed can be converted into a data format to obtain a second target matrix including the converted second element value; wherein the data format of the converted first element value and the converted second element value includes a precision bit and a data bit, the value located on the precision bit represents the precision unit corresponding to the converted element value (that is, the minimum extreme value of the numerical range), and the value located on the data bit is the target value of the converted element value under the precision unit.

[0076] Exemplarily, for binary data, the data bit width is set to 10 bits, including 2 precision bits and 8 data bits; therefore, the precision bit values ​​may include 00, 01, 10, and 11, and the mapping relationship between the set numerical range and the precision bit value may be: the precision bit value corresponding to the value between [1 / 65536, 1 / 256) is 00, the precision bit value corresponding to the value between [1 / 256, 1) is 01, the precision bit value corresponding to the value between [1, 256) is 10, and the precision bit value corresponding to the value between [256, 65536) is 11; then the precision unit corresponding to the precision bit value 00 is 1 / 65536, the precision unit corresponding to the precision bit value 01 is 1 / 256, the precision unit corresponding to the precision bit value 10 is 1, and the precision unit corresponding to the precision bit value 11 is 256.

[0077] If the first element value is 167, it can be determined that the precision unit of the first element value is 1, and the corresponding precision bit value is 10, and the first element value is converted to binary form, so the converted first element value is 10_10100111, that is, the result of multiplying the precision unit of the converted first element by the first target value is equal to the first element value. Among them, the set data bit width can be determined according to the storage space capacity of the actual chip, the mapping relationship between the value range and the precision bit value can be determined according to actual needs, and the precision unit can be flexibly set according to needs, which is only an exemplary description here.

[0078] Therefore, based on the mapping relationship between the numerical range and the precision bit value, the above process can be used to perform data format conversion on the first element value and the second element value to obtain the converted first element value and the converted second element value; and to obtain a first target matrix including the converted first element value, and a second target matrix including the converted second element value.

[0079] For S103:

[0080] After obtaining the first target matrix and the second target matrix, a matrix operation may be performed on the first target matrix and the second target matrix to obtain an operation result; for example, the matrix operation may be a matrix multiplication operation, a matrix addition operation, or a dot product operation.

[0081] In a possible implementation, performing a matrix operation on the first target matrix and the second target matrix to obtain an operation result includes:

[0082] Step A1, for each converted first element value in the first target matrix, based on the operation logic corresponding to the matrix operation, determine the target second element value that matches the converted first element value from the converted second element values ​​included in the second target matrix.

[0083] Step A2, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, perform target operation on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result.

[0084] Step A3, determining the operation result based on the intermediate results corresponding to the first element values ​​after each conversion.

[0085] During implementation, for each converted first element value in the first target matrix, a target second element value matching the converted first element value can be determined from the converted second element values ​​included in the second target matrix based on the operation logic corresponding to the matrix operation.

[0086] For example, the first target matrix includes first element values ​​[A00, A01; A10, A11], and the second target matrix includes second element values ​​[B00, B01; B10, B11]. If the matrix operation is a matrix addition operation, for the first element value A00, the target second element value that matches the first element value A00 can be determined to be B00; for the first element value A01, the target second element value that matches the first element value A01 can be determined to be B01. If the matrix operation is a matrix multiplication operation, for the first element value A00, the target second element values ​​that match the first element value A00 can be determined to be B00 and B10; for the first element value A01, the target second element values ​​that match the first element value A01 can be determined to be B01 and B11.

[0087] Then, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, a target operation can be performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result. The target operation includes addition operation, multiplication operation, etc.

[0088] For example, if the matrix operation is a matrix addition operation, the target operation includes an addition operation, and the first target value and the second target value can be added to obtain an intermediate result; if the matrix operation is a matrix multiplication operation or a dot product operation, the target operation includes a multiplication operation and an addition operation, and the first target value and the second target value can be multiplied first to obtain intermediate data corresponding to each converted first element value, and then, according to the operation logic, the matching first intermediate data and second intermediate data can be added to obtain an intermediate result; and then, based on the intermediate results corresponding to each converted first element value, the operation result can be determined.

[0089] Here, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, target operations are performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value, so that the accuracy of the intermediate result can be more accurate; and further, based on the intermediate results corresponding to each converted first element value, the accuracy of the determined operation result can be made more accurate.

[0090] In one possible implementation, the target operation includes a multiplication operation; based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, including:

[0091] Step B1, determining a target precision unit corresponding to a target operation based on a first precision unit and a second precision unit.

[0092] Step B2, multiplying the first target value and the second target value to obtain a product result in a target precision unit; wherein the product result includes a value located at a preset number of data bits, and the data bits include high-order data bits and low-order data bits.

[0093] Step B3, based on the first precision unit and the second precision unit, perform a precision preservation operation on the product result in the target precision unit to obtain an intermediate result.

[0094] During implementation, the target operation includes a multiplication operation, and the target precision unit corresponding to the target operation can be determined based on the first precision unit and the second precision unit. Specifically, if the first precision unit and the second precision unit are the same, the first precision unit or the second precision unit is determined as the target precision unit; if the first precision unit and the second precision unit are different, the result of multiplying the first precision unit and the second precision unit can be determined as the target precision unit.

[0095] The first target value and the second target value are multiplied to obtain a product result in a target precision unit; wherein the product result includes a value located at a preset number of data bits, and the data bits include high-order data bits and low-order data bits. For example, if the data bit width of the first target value and the second target value is set to 8 bits, the preset number of data bits is 16 bits, including 8 high-order data bits and 8 low-order data bits. Furthermore, based on the first precision unit and the second precision unit, the product result in the target precision unit can be subjected to a precision preservation operation to obtain an intermediate result.

[0096] Exemplarily, the precision unit corresponding to the precision bit value 00 is 1 / 65536, the precision unit corresponding to the precision bit value 01 is 1 / 256, the precision unit corresponding to the precision bit value 10 is 1, and the precision unit corresponding to the precision bit value 11 is 256. If the converted first element value is 01_10000000, the first precision unit is 1 / 256, and the first target value is 10000000; the converted second element value is 01_01000000, the second precision unit is 1 / 256, and the second target value is 01000000; if the first precision unit and the second precision unit are both 1 / 256, the target precision unit is 1 / 256; the product result under the target precision unit is 001000000000000, including the value 00100000 located in the high data bit and the value 00000000 located in the low data bit.

[0097] If the converted first element value is 11_00000010, the first precision unit is 256 and the first target value is 00000010; if the converted second element value is 00_01000000, the second precision unit is 1 / 65536 and the second target value is 01000000; if the first precision unit is 256 and the second precision unit is 1 / 65536, the target precision unit is 1 / 256, that is, 256×(1 / 65536)).

[0098] Among them, if the product result obtained in the target precision unit is smaller than the set minimum precision unit, the minimum precision unit can be determined as the target precision unit of the intermediate result, and the target value of the intermediate result can be determined as 00000000; if the product result obtained in the target precision unit is greater than the set maximum precision unit, the maximum precision unit can be determined as the target precision unit of the intermediate result, and the target value of the intermediate result can be determined as 11111111.

[0099] During implementation, if the precision unit corresponding to the precision digit value 00 is 1 / 65536, the precision unit corresponding to the precision digit value 01 is 1 / 1024, the precision unit corresponding to the precision digit value 10 is 1, and the precision unit corresponding to the precision digit value 11 is 256. When the first precision unit is 256 and the second precision unit is 1 / 1024, the result of multiplying the first precision unit and the second precision unit is 1 / 4, and the precision unit with the smaller difference from the precision unit 1 / 4 can be determined from the precision units 1 / 65536, 1 / 1024, 1, and 256 as the target precision unit. Here, the target precision unit is determined to be 1.

[0100] Here, based on the first precision unit and the second precision unit, the target precision unit corresponding to the target operation can be determined more quickly; and the first target value and the second target value can be multiplied to obtain the product result in the target precision unit; then, based on the first precision unit and the second precision unit, the product result in the target precision unit can be subjected to precision preservation operation to obtain an intermediate result, thereby improving chip performance while ensuring that the accuracy of the intermediate result is more accurate.

[0101] In a possible implementation, based on the first precision unit and the second precision unit, a precision preservation operation is performed on the product result in the target precision unit to obtain an intermediate result, including:

[0102] Step C1, when it is determined that the first precision unit and the second precision unit are the same and the first precision unit is less than the first preset value, determine whether the value located at the high-order data bit in the product result has a second preset value.

[0103] Step C2: if it exists, retain the value of the high-order data bit in the product result, and generate an intermediate result based on the value of the high-order data bit and the target precision unit.

[0104] Step C3: if it does not exist, retain the value located at the low data bit in the product result; and adjust the target precision unit to obtain a first adjusted precision unit, wherein the first adjusted precision unit is smaller than the target precision unit; and generate an intermediate result based on the value located at the low data bit and the first adjusted precision unit;

[0105] Alternatively, if it does not exist, the values ​​of the low-order data bits in the product result are adjusted to the second preset value that does not exist, so as to obtain the adjusted values ​​of the low-order data bits; and based on the adjusted values ​​of the low-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the minimum precision unit.

[0106] During implementation, when it is determined that the first precision unit and the second precision unit are the same and the first precision unit is less than the first preset value, it can be determined whether the value located at the high-order data bit in the product result has the second preset value. The first preset value can be 1, and the second preset value can be 1; if it exists, the value located at the high-order data bit in the product result can be retained, and an intermediate result can be generated based on the value located at the high-order data bit and the target precision unit.

[0107] Exemplarily, if the converted first element value is 01_10000000, the first precision unit is 1 / 256 and the first target value is 10000000; if the converted second element value is 01_01000000, the second precision unit is 1 / 256 and the second target value is 01000000; if both the first precision unit and the second precision unit are 1 / 256, the target precision unit is 1 / 256. The product result in the target precision unit is 0010000000000000, including the value 00100000 located in the high data bit, and the value 00000000 located in the low data bit; when the first precision unit and the second precision unit are the same, and the first precision unit is less than the first preset value (1 / 256<1), if the value 00100000 located in the high data bit in the product result has the second preset value (1), the value 00100000 can be retained; and the intermediate result 01_00100000 can be generated.

[0108] If it does not exist, the value at the low data bit in the product result can be retained; and the target precision unit can be adjusted, such as jumping down one level to obtain a first adjusted precision unit, wherein the first adjusted precision unit is smaller than the target precision unit, such as if the target precision unit is 1, then the first adjusted precision unit is 1 / 256; and an intermediate result can be generated based on the value at the low data bit and the first adjusted precision unit.

[0109] Alternatively, if it does not exist, the values ​​of the low-order data bits in the product result are adjusted to the second preset value that does not exist, and the adjusted value of the low-order data bits is obtained, that is, the adjusted value of the low-order data bits is 00000000; and based on the adjusted value of the low-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the minimum precision unit, and the minimum precision unit can be 1 / 65536.

[0110] If the converted first element value is 01_00010000, the first precision unit is 1 / 256 and the first target value is 00010000; the converted second element value is 01_00001000, the second precision unit is 1 / 256 and the second target value is 00001000; if both the first precision unit and the second precision unit are 1 / 256, the target precision unit is 1 / 256; the product result in the target precision unit is 0000000010000000, including the value 0 in the high-order data bit 0000000, and the value 10000000 located in the low data bit; when the first precision unit and the second precision unit are the same, and the first precision unit is less than the first preset value (1 / 256<1), if the value 00000000 located in the high data bit in the product result does not have the second preset value (does not exist 1), then the value 10000000 located in the low data bit can be retained, and the first adjusted precision unit can be 1 / 65536; and the intermediate result 00_10000000 can be generated. If the converted first element value is 00_00010000, the first precision unit is 1 / 65536, and the first target value is 00010000; the converted second element value is 00_00001000, the second precision unit is 1 / 65536, and the second target value is 00001000; if the first precision unit and the second precision unit are both 1 / 65536, the target precision unit is 1 / 65536 (the target precision unit is the minimum precision unit); the product result under the target precision unit is 0000000010000000, including the value 0000 located in the high-order data bit 0000, and the value 10000000 located in the low data bit; when the first precision unit and the second precision unit are the same, and the converted first precision unit is less than the first preset value (1 / 65536<1), if the value 00000000 located in the high data bit in the product result does not have the second preset value (does not exist 1), then the 1 in the value 10000000 located in the low data bit can be adjusted to 0, and the adjusted low data bit value is 00000000, then the intermediate result 00_00000000 can be generated based on the target precision unit and the adjusted low data bit value.

[0111] During implementation, if the precision unit corresponding to the precision bit value 00 is 1 / 65536, the precision unit corresponding to the precision bit value 01 is 1 / 256, the precision unit corresponding to the precision bit value 10 is 1, and the precision unit corresponding to the precision bit value 11 is 256; when the first precision unit and the second precision unit are the same and the first precision unit is 1 / 65536 (minimum precision unit), if the value located in the high data bit in the product result does not have a second preset value (does not exist 1), the intermediate result can be determined to be 00_00000000; when the first precision unit and the second precision unit are the same and the first precision unit is 256 (maximum precision unit), if the value located in the high data bit in the product result does have a second preset value (does not exist 1), the intermediate result can be determined to be 11_111111111.

[0112] In the disclosed embodiment, the precision-preserving operation can be performed on the product result more quickly based on the first precision unit and the second precision unit to obtain an intermediate result, thereby reducing the complexity of the operation and improving the operation speed. At the same time, the precision unit can be used to ensure the accuracy of the intermediate result.

[0113] In a possible implementation, based on the first precision unit and the second precision unit, a precision preservation operation is performed on the product result in the target precision unit to obtain an intermediate result, including:

[0114] Step D1, when it is determined that the first precision unit and the second precision unit are the same and the first precision unit is greater than or equal to the first preset value, determining whether the value located at the high-order data bit in the product result has a second preset value;

[0115] Step D2: if it does not exist, retain the value of the low-order data bit in the product result, and generate an intermediate result based on the value of the low-order data bit and the target precision unit;

[0116] Step D3, if it exists, retain the value located at the high data bit in the product result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the value located at the high data bit and the second adjusted precision unit;

[0117] Alternatively, if it exists, the values ​​of the high-order data bits in the product result are all adjusted to the second preset value to obtain the adjusted value of the high-order data bits; and based on the adjusted value of the high-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the maximum precision unit.

[0118] During implementation, when it is determined that the first precision unit and the second precision unit are the same, and the first precision unit is greater than or equal to a first preset value (the first preset value is 1), it can be determined whether the numerical value located in the high-order data bit in the product result has a second preset value (the second preset value is 1); if not, the numerical value located in the low-order data bit in the product result can be retained, and an intermediate result can be generated based on the numerical value located in the low-order data bit and the target precision unit.

[0119] Exemplarily, the converted first element value is 10_00010000, the first precision unit is 1, and the first target value is 00010000; the converted second element value is 10_00001000, the second precision unit is 1, and the second target value is 00001000; the first precision unit and the second precision unit are both 1, and the target precision unit is 1; the product result under the target precision unit is 0000000010000000, including the value 000 located in the high data bit 00000, and the value 10000000 located in the low data bit; when the first precision unit and the second precision unit are the same, and the first precision unit is greater than the first preset value (16>1), if the value 00000000 located in the high data bit in the product result does not have the second preset value (does not exist 1), the value 10000000 located in the low data bit can be retained; and based on the value located in the low data bit and the target precision unit, an intermediate result of 10_10000000 can be generated.

[0120] If there is a second preset value for the numerical value located in the high-order data bit in the product result, the numerical value located in the high-order data bit in the product result can be retained; and the target precision unit can be adjusted, such as jumping up one level to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit, for example, if the target precision unit is 1, then the second adjusted precision unit is 256; and an intermediate result can be generated based on the numerical value located in the high-order data bit and the second adjusted precision unit.

[0121] If the converted first element value is 10_00010000, the first precision unit is 1 and the first target value is 00010000; if the converted second element value is 10_00100000, the second precision unit is 1 and the second target value is 00100000; if both the first precision unit and the second precision unit are 1, the target precision unit is 1; the product result under the target precision unit is 000000100000000, including the value 00000010 at the high data bit and the value 00000010 at the low data bit. The value of the first precision unit is 00000000; when the first precision unit and the second precision unit are the same and the first precision unit is greater than the first preset value (16>1), if the value 00000010 located in the high data bit in the product result has the second preset value (1), the value 00000010 located in the high data bit can be retained, and the second adjusted precision unit can be 256; and based on the value located in the high data bit and the second adjusted precision unit, an intermediate result of 11_00000010 can be generated.

[0122] If the converted first element value is 11_00010000, the first precision unit is 256 and the first target value is 00010000; the converted second element value is 11_00100000, the second precision unit is 256 and the second target value is 00100000; if the first precision unit and the second precision unit are both 256, the target precision unit is 256 (the target precision unit is the maximum precision unit); the product result under the target precision unit is 000000100000000, including the value 00 located in the high data bit 000010, and the value 00000000 located in the low data bit; when the first precision unit and the second precision unit are the same, and the first precision unit is greater than the first preset value (256>1), if the value 00000010 located in the high data bit in the product result has the second preset value (1), then the value 00000010 located in the high data bit is adjusted to the second preset value, that is, 11111111, and then the intermediate result 11_11111111 can be generated based on the target precision unit and the adjusted value of the high data bit.

[0123] In a possible implementation, based on the first precision unit and the second precision unit, a precision preservation operation is performed on the product result in the target precision unit to obtain an intermediate result, including:

[0124] Step D4, when it is determined that the first precision unit and the second precision unit are different, determining whether the numerical value located at the high-order data bit in the product result has a second preset value.

[0125] Step D5: If it does not exist, retain the value located at the low-order data bit in the product result, and generate an intermediate result based on the value located at the low-order data bit and the target precision unit.

[0126] Step D6, if it exists, retain the numerical value located in the high-order data bit in the product result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the numerical value located in the high-order data bit and the second adjusted precision unit.

[0127] During implementation, when it is determined that the first precision unit and the second precision unit are different, if it is determined that the numerical value located in the high-order data bit in the product result does not have a second preset value (that is, there is no 1), the numerical value located in the low-order data bit in the product result can be retained, and an intermediate result can be generated based on the numerical value located in the low-order data bit and the target precision unit; if it is determined that the numerical value located in the high-order data bit in the product result does have a second preset value (that is, there is 1), the numerical value located in the high-order data bit in the product result can be retained; and the target precision unit can be adjusted to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit, for example, if the target precision unit is 1, then the first adjusted precision unit is 256; and an intermediate result can be generated based on the numerical value located in the high-order data bit and the second adjusted precision unit.

[0128] For example, the converted first element value is 11_00010000, the first precision unit is 256, and the first target value is 00010000; the converted second element value is 00_00001000, the second precision unit is 1 / 65536, and the second target value is 00001000; the product of the first precision unit and the second precision unit is 1 / 256, and the target precision unit is 1 / 256; the product result under the target precision unit is 0000000010000 000, including the numerical value 00000000 located in the high data bit, and the numerical value 10000000 located in the low data bit; when the first precision unit and the second precision unit are different, if the numerical value 00000000 located in the high data bit in the product result does not have the second preset value (does not have 1), the numerical value 10000000 located in the low data bit can be retained; and based on the numerical value located in the low data bit and the target precision unit, an intermediate result of 01_10000000 can be generated.

[0129] If the converted first element value is 11_00010000, the first precision unit is 256 and the first target value is 00010000; the converted second element value is 00_00100000, the second precision unit is 1 / 65536 and the second target value is 00100000; the product of the first precision unit and the second precision unit is 1 / 256, and the target precision unit is 1 / 256; the product result under the target precision unit is 000000100000000, including the high-order data The value 00000010 at the high data bit and the value 00000000 at the low data bit; when the first precision unit and the second precision unit are different, if the value 00000010 at the high data bit in the product result has a second preset value (1), the value 00000010 at the high data bit can be retained, and the second adjusted precision unit can be 1; and based on the value at the high data bit and the second adjusted precision unit, an intermediate result 10_00000010 can be generated.

[0130] In a possible implementation, based on the first precision unit and the second precision unit, performing a precision preservation operation on the product result in the target precision unit to obtain an intermediate result further includes:

[0131] Step D7, when it is determined that the first precision unit and the second precision unit are different, and the first precision unit and the second precision unit are both smaller than a first preset value, the values ​​of the low-order data bits in the multiplication result are adjusted so that the second preset value does not exist, and the adjusted values ​​of the low-order data bits are obtained.

[0132] Step D8, generating an intermediate result based on the adjusted value of the low-order data bit and the target precision unit, wherein the target precision unit and the first precision unit are minimum precision units.

[0133] During implementation, if the precision unit corresponding to the precision bit value 00 is 1 / 65536, the precision unit corresponding to the precision bit value 01 is 1 / 256, the precision unit corresponding to the precision bit value 10 is 1, and the precision unit corresponding to the precision bit value 11 is 256; when the first precision unit and the second precision unit are different, and the first precision unit is 1 / 65536 (the smallest precision unit) and the second precision unit is 1 / 256, which are both less than 1, the target precision unit is determined to be 1 / 65536, then the values ​​of the low-order data bits in the product result are adjusted to a second preset value of 00000000, to obtain the adjusted value of the low-order data bits, and based on the adjusted value of the low-order data bits and the target precision unit, an intermediate result of 00_00000000 is generated.

[0134] For example, if the converted first element value is 01_00010000, the first precision unit is 1 / 256, and the first target value is 00010000; if the converted second element value is 00_00001000, the second precision unit is 1 / 65536, and the second target value is 00001000; if the first precision unit precision unit 1 / 256<1, and the second precision unit precision unit 1 / 65536<1, the target precision unit is 1 / 65536 (minimum precision unit); the product result under the target precision unit is 00000000100000 00, including the numerical value 00000000 located in the high-order data bit, and the numerical value 10000000 located in the low-order data bit; when the first precision unit and the second precision unit are different, and the first precision unit and the second precision unit are both less than 1, the numerical value 10000000 located in the low-order data bit in the product result is adjusted to 00000000 when there is no second preset value, and the numerical value of the low-order data bit after adjustment is obtained, and based on the numerical value of the low-order data bit after adjustment and the target precision unit, an intermediate result of 00_00000000 is generated.

[0135] In one possible implementation, the target operation includes an addition operation; based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, including:

[0136] Step E1, when it is determined that the first precision unit and the second precision unit are the same, the first target value and the second target value are added to obtain an addition result in the first precision unit.

[0137] Step E2: when the number of data bits of the addition result is the same as the number of data bits of the first target value, the addition result is determined as an intermediate result.

[0138] Step E3, when the number of bits of the data bits of the addition result is different from the number of bits of the data bits of the first target value, adjust the first precision unit to obtain a third adjusted precision unit; and select the value of the highest data bit from the addition result; and generate an intermediate result based on the third adjusted precision unit and the value of the highest data bit.

[0139] During implementation, the target operation includes an addition operation. When it is determined that the first precision unit and the second precision unit are the same, the first target value and the second target value can be added to obtain an addition result in the first precision unit; and when the number of data bits of the addition result is the same as the number of data bits of the first target value, that is, no data overflow occurs in the addition result, the addition result can be determined as an intermediate result.

[0140] Exemplarily, if the converted first element value is 01_10000000, the first precision unit is 1 / 256, and the first target value is 10000000; the converted second element value is 01_01000000, the first precision unit is 1 / 256, and the first target value is 01000000; the first precision unit and the second precision unit are both 1 / 256, and the addition result of the first target value and the second target value is 11000000; the number of bits of the data bits of the addition result (for example, the number of bits is 8 bits) is the same as the number of bits of the data bits of the first target value (for example, the number of bits is 8 bits), then the intermediate result is 01_11000000.

[0141] When the number of data bits of the addition result is different from the number of data bits of the first target value, the first precision unit can be adjusted to obtain a third adjusted precision unit; and the value of the highest data bit can be selected from the intermediate result; and the intermediate result can be generated based on the third adjusted precision unit and the value of the highest data bit.

[0142] Exemplarily, if the converted first element value is 01_10000000, the first precision unit is 1 / 256, and the first target value is 10000000; the converted second element value is 01_10000000, the second precision unit is 1 / 256, and the second target value is 10000000; the first precision unit is 1 / 256, the second precision unit is 1 / 256, and the addition result obtained by adding the first target value and the second target value is 100000000; the number of bits of the data bits of the addition result (for example, the number of bits is 9 bits) is different from the number of bits of the data bits of the first target value (for example, the number of bits is 8 bits), which indicates that the addition result of the addition operation overflows, so the third adjusted precision unit is greater than the first precision unit, and the third adjusted precision unit is 1; and the value of the highest data bit is selected from the addition result, that is, 1; and based on the third adjusted precision unit and the value of the highest data bit, the intermediate result generated is 10_00000001.

[0143] In the above method, when it is determined that the first precision unit and the second precision unit are the same, the first target value and the second target value are added to obtain the addition result in the first precision unit; then, based on the number of bits of the data bits of the addition result and the number of bits of the data bits of the first target value, it is determined whether data overflow occurs in the addition result, so that the intermediate result can be determined more accurately according to different methods.

[0144] In a possible implementation, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, a target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, further comprising:

[0145] Step F1, when the first precision unit is smaller than the second precision unit, adjust the first precision unit and the first target value of the converted first element value to obtain an adjusted element value; wherein the adjusted element value includes the adjusted precision unit and the adjusted target value, and the adjusted precision unit is one level larger than the first precision unit.

[0146] Step F2: when it is determined that the adjusted precision unit is different from the second precision unit, the converted second element value is determined as the intermediate result.

[0147] During implementation, when the first precision unit is smaller than the second precision unit, the first precision unit and the first target value of the converted first element value may be adjusted to obtain an adjusted element value.

[0148] Specifically, when the value of the highest data bit located at the first target value is 1, the adjusted precision unit of the obtained adjusted element value is greater than the first precision unit (that is, the adjusted precision unit is one level larger than the first precision unit), and the adjusted target value of the adjusted element value is 00000001. When the value of the highest data bit located at the first target value is 0, the adjusted precision unit of the obtained adjusted element value is greater than the first precision unit (that is, the adjusted precision unit is one level larger than the first precision unit), and the adjusted target value of the adjusted element value is 00000000.

[0149] For example, the first element value after conversion is 01_00001000, the first precision unit is 1 / 256, the adjusted precision unit of the adjusted element value is 1, and the adjusted element value is 10_00000000; the first element value after conversion is 10_10001000, the first precision unit is 1, the adjusted precision unit of the adjusted element value is 256, and the adjusted element value is 11_00000001.

[0150] Since the first precision unit is smaller than the second precision unit, and the adjusted precision unit is larger than the first precision unit, when it is determined that the adjusted precision unit is different from the second precision unit, it is determined that the difference between the converted first element value and the converted second element value is large, and the converted second element value can be determined as the intermediate result. When it is determined that the adjusted precision unit is the same as the second precision unit, the intermediate result can be obtained according to the process of step E1 to step E3, which will not be described in detail here.

[0151] When the first precision unit is greater than the second precision unit, the second precision unit and the second target value of the converted second element value are adjusted to obtain the adjusted element value; when it is determined that the adjusted precision unit is different from the first precision unit, the converted first element value is determined as the intermediate result. The specific execution process is similar to the execution process when the first precision unit is less than the second precision unit, and will not be repeated here.

[0152] In the above method, when the first precision unit is smaller than the second precision unit, the first precision unit and the first target value of the converted first element value are adjusted, and the adjusted precision unit of the obtained adjusted element value is larger than the first precision unit; when it is determined that the adjusted precision unit is different from the second precision unit, it means that the difference between the converted first element value and the converted second element value is large, so the converted second element value can be directly determined as the intermediate result, which can reduce the complexity of the calculation and improve the calculation speed.

[0153] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.

[0154] Based on the same concept, the present disclosure also provides a data processing device, see Figure 2 As shown, it is a schematic diagram of the architecture of the data processing device provided by the embodiment of the present disclosure, including an acquisition module 201, a conversion module 202, and a calculation module 203. Specifically:

[0155] An acquisition module 201 is used to acquire a matrix pair to be processed;

[0156] The conversion module 202 is used to perform data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical value located at the precision bits represents the precision unit corresponding to the converted element values, and the numerical value located at the data bits represents the target value of the converted element values ​​under the precision unit;

[0157] The operation module 203 is used to perform matrix operation on the first target matrix and the second target matrix to obtain an operation result.

[0158] In a possible implementation, the operation module 203, when performing matrix operations on the first target matrix and the second target matrix to obtain operation results, is used to: determine, for each of the converted first element values ​​in the first target matrix, from the converted second element values ​​included in the second target matrix based on the operation logic corresponding to the matrix operation, a target second element value that matches the converted first element value; and perform target operations on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result; and determine the operation result based on the intermediate results corresponding to each of the converted first element values.

[0159] In a possible implementation, the target operation includes a multiplication operation; the operation module 203, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, performs a target operation on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, is used to: determine the target precision unit corresponding to the target operation based on the first precision unit and the second precision unit; perform a multiplication operation on the first target value and the second target value to obtain a product result under the target precision unit; wherein the product result includes a numerical value located at a preset number of data bits, and the data bits include high-order data bits and low-order data bits; based on the first precision unit and the second precision unit, perform a precision preservation operation on the product result under the target precision unit to obtain an intermediate result.

[0160] In a possible implementation manner, the operation module 203, when performing a precision retention operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result, is used to: when it is determined that the first precision unit and the second precision unit are the same and the first precision unit is less than a first preset value, determine whether the value located in the high-order data bit in the product result has a second preset value; if so, retain the value located in the high-order data bit in the product result, and generate an intermediate result based on the value located in the high-order data bit and the target precision unit; if not, Then retain the numerical value of the low-order data bit in the multiplication result; and adjust the target precision unit to obtain a first adjusted precision unit, wherein the first adjusted precision unit is smaller than the target precision unit; and generate an intermediate result based on the numerical value of the low-order data bit and the first adjusted precision unit; or, if it does not exist, adjust the numerical values ​​of the low-order data bits in the multiplication result to a second preset value that does not exist, to obtain the numerical value of the adjusted low-order data bit; and generate an intermediate result based on the numerical value of the adjusted low-order data bit and the target precision unit, wherein the target precision unit is the minimum precision unit.

[0161] In a possible implementation manner, the operation module 203, when performing a precision retention operation on the product result under the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result, is used to: when it is determined that the first precision unit and the second precision unit are the same and the first precision is greater than or equal to a first preset value, determine whether the value located at the high-order data bit in the product result has a second preset value; if not, retain the value located at the low-order data bit in the product result, and generate an intermediate result based on the value located at the low-order data bit and the target precision unit; If it exists, retain the numerical value of the high-order data bit in the product result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the numerical value of the high-order data bit and the second adjusted precision unit; or, if it exists, adjust the numerical values ​​of the high-order data bits in the product result to second preset values ​​to obtain the adjusted numerical values ​​of the high-order data bits; and generate an intermediate result based on the numerical value of the adjusted high-order data bits and the target precision unit, wherein the target precision unit is the maximum precision unit.

[0162] In a possible implementation, the operation module 203, when performing a precision retention operation on the product result under the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result, is used to: when it is determined that the first precision unit and the second precision unit are different, determine whether the numerical value located at the high data bit in the multiplication result has a second preset value; if not, retain the numerical value located at the low data bit in the multiplication result, and generate an intermediate result based on the numerical value located at the low data bit and the target precision unit; if so, retain the numerical value located at the high data bit in the multiplication result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the numerical value located at the high data bit and the second adjusted precision unit.

[0163] In a possible implementation, the operation module 203, when performing a precision-retaining operation on the multiplication result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result, is also used to: when it is determined that the first precision unit and the second precision unit are not the same, and both the first precision unit and the second precision unit are less than a first preset value, adjust the values ​​of the low-order data bits in the multiplication result to a value in which the second preset value does not exist, to obtain the adjusted values ​​of the low-order data bits; generate an intermediate result based on the adjusted values ​​of the low-order data bits and the target precision unit, wherein the target precision unit and the first precision unit are the minimum precision units.

[0164] In a possible implementation manner, the target operation includes an addition operation; the operation module 203, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, performs a target operation on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, is used to: when it is determined that the first precision unit and the second precision unit are the same, add the first target value and the second target value to obtain an addition result under the first precision unit; when the number of bits of the data bits of the addition result is the same as the number of bits of the data bits of the first target value, determine the addition result as the intermediate result; when the number of bits of the data bits of the addition result is different from the number of bits of the data bits of the first target value, adjust the first precision unit to obtain a third adjusted precision unit; and select the value of the highest data bit from the addition result; and generate an intermediate result based on the third adjusted precision unit and the value of the highest data bit.

[0165] In a possible implementation, the operation module 203, based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, performs a target operation on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result, and is also used to: when the first precision unit is smaller than the second precision unit, adjust the first precision unit and the first target value of the converted first element value to obtain an adjusted element value; wherein the adjusted element value includes an adjusted precision unit and an adjusted target value, and the adjusted precision unit is one level larger than the first precision unit; when it is determined that the adjusted precision unit is different from the second precision unit, determine the converted second element value as the intermediate result.

[0166] In some embodiments, the functions or templates contained in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0167] Based on the same technical concept, the embodiment of the present disclosure also provides an electronic device. Figure 3As shown, it is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure, including a processor 301, a memory 302, and a bus 303. Among them, the memory 302 is used to store execution instructions, including a memory 3021 and an external memory 3022; the memory 3021 here is also called an internal memory, which is used to temporarily store the operation data in the processor 301, and the data exchanged with the external memory 3022 such as a hard disk. The processor 301 exchanges data with the external memory 3022 through the memory 3021. When the electronic device 300 is running, the processor 301 communicates with the memory 302 through the bus 303, so that the processor 301 executes the following instructions:

[0168] Get the matrix pair to be processed;

[0169] Performing data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical values ​​located at the precision bits represent the precision units corresponding to the converted element values, and the numerical values ​​located at the data bits represent the target values ​​of the converted element values ​​under the precision units;

[0170] A matrix operation is performed on the first target matrix and the second target matrix to obtain an operation result.

[0171] The specific processing flow of the processor 301 may refer to the description of the above method embodiment, which will not be repeated here.

[0172] In addition, the embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the data processing method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.

[0173] The embodiments of the present disclosure also provide a computer program product, which carries a program code. 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 embodiment, which will not be repeated here.

[0174] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0175] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.

[0176] 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 distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0177] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0178] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, 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, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0179] The above are only specific embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.

Claims

1. A data processing method, It is characterized in that include: Get the matrix pair to be processed; Performing data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical values ​​located at the precision bits represent the precision units corresponding to the converted element values, and the numerical values ​​located at the data bits represent the target values ​​of the converted element values ​​under the precision units; A matrix operation is performed on the first target matrix and the second target matrix to obtain an operation result.

2. The method according to claim 1, It is characterized in that The performing a matrix operation on the first target matrix and the second target matrix to obtain an operation result includes: For each of the converted first element values ​​in the first target matrix, based on the operation logic corresponding to the matrix operation, determine a target second element value matching the converted first element value from the converted second element values ​​included in the second target matrix; and Based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value, a target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value to obtain an intermediate result; The operation result is determined based on the intermediate results respectively corresponding to the converted first element values.

3. The method according to claim 2, It is characterized in that The target operation includes a multiplication operation; the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result, including: Determining a target precision unit corresponding to the target operation based on the first precision unit and the second precision unit; Performing a multiplication operation on the first target value and the second target value to obtain a product result in the target precision unit; wherein the product result includes a value located at a preset number of data bits, and the data bits include a high-order data bit and a low-order data bit; Based on the first precision unit and the second precision unit, a precision preserving operation is performed on the product result in the target precision unit to obtain an intermediate result.

4. The method according to claim 3, It is characterized in that The step of performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes: When it is determined that the first precision unit is the same as the second precision unit and the first precision unit is less than a first preset value, determining whether a second preset value exists in the numerical value located at the high-order data bit in the multiplication result; If it exists, retain the value of the high-order data bit in the product result, and generate an intermediate result based on the value of the high-order data bit and the target precision unit; If not, retaining the value located at the low-order data bit in the product result; and adjusting the target precision unit to obtain a first adjusted precision unit, wherein the first adjusted precision unit is smaller than the target precision unit; and generating an intermediate result based on the value located at the low-order data bit and the first adjusted precision unit; Alternatively, if it does not exist, the values ​​of the low-order data bits in the product result are adjusted to the second preset value that does not exist, so as to obtain the adjusted values ​​of the low-order data bits; and based on the adjusted values ​​of the low-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the minimum precision unit.

5. The method according to claim 3, It is characterized in that The step of performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes: In the case where it is determined that the first precision unit is the same as the second precision unit and the first precision unit is greater than or equal to a first preset value, determining whether a value located at the high-order data bit in the product result has a second preset value; If not, retaining the value located at the low-order data bit in the product result, and generating an intermediate result based on the value located at the low-order data bit and the target precision unit; If it exists, retaining the value located at the high-order data bit in the product result; and adjusting the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generating an intermediate result based on the value located at the high-order data bit and the second adjusted precision unit; Alternatively, if it exists, the values ​​of the high-order data bits in the product result are all adjusted to the second preset value to obtain the adjusted values ​​of the high-order data bits; and based on the adjusted values ​​of the high-order data bits and the target precision unit, an intermediate result is generated, wherein the target precision unit is the maximum precision unit.

6. The method according to claim 3, It is characterized in that The step of performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result includes: In the case where it is determined that the first precision unit and the second precision unit are different, determining whether a second preset value exists in the numerical value located at the high-order data bit in the multiplication result; If not, retaining the value located at the low-order data bit in the product result, and generating an intermediate result based on the value located at the low-order data bit and the target precision unit; If it exists, retain the numerical value located at the high data bit in the product result; and adjust the target precision unit to obtain a second adjusted precision unit, wherein the second adjusted precision unit is greater than the target precision unit; and generate an intermediate result based on the numerical value located at the high data bit and the second adjusted precision unit.

7. The method according to claim 6, It is characterized in that The method further comprises: performing a precision preservation operation on the product result in the target precision unit based on the first precision unit and the second precision unit to obtain an intermediate result. When it is determined that the first precision unit and the second precision unit are different, and both the first precision unit and the second precision unit are smaller than a first preset value, the values ​​of the low-order data bits in the multiplication result are adjusted so that the second preset value does not exist, and the values ​​of the low-order data bits after adjustment are obtained; An intermediate result is generated based on the value of the adjusted low-order data bit and the target precision unit, wherein the target precision unit and the first precision unit are minimum precision units.

8. The method according to any one of claims 2 to 7, It is characterized in that The target operation includes an addition operation; the target operation is performed on the first target value located at the data bit in the converted first element value and the second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result, including: When it is determined that the first precision unit and the second precision unit are the same, adding the first target value and the second target value to obtain an addition result in the first precision unit; When the number of bits of the data bits of the addition result is the same as the number of bits of the data bits of the first target value, determining the addition result as the intermediate result; When the number of bits of the data bits of the addition result is different from the number of bits of the data bits of the first target value, the first precision unit is adjusted to obtain a third adjusted precision unit; and the value of the highest data bit is selected from the addition result; and an intermediate result is generated based on the third adjusted precision unit and the value of the highest data bit.

9. The method according to claim 8, It is characterized in that The method further comprises: performing a target operation on a first target value located at the data bit in the converted first element value and a second target value located at the data bit in the target second element value based on the first precision unit located at the precision bit in the converted first element value and the second precision unit located at the precision bit in the target second element value to obtain an intermediate result, further comprising: In the case where the first precision unit is smaller than the second precision unit, adjusting the first precision unit and the first target value of the converted first element value to obtain an adjusted element value; wherein the adjusted element value includes an adjusted precision unit and an adjusted target value, and the adjusted precision unit is one level larger than the first precision unit; When it is determined that the adjusted precision unit is different from the second precision unit, the converted second element value is determined as the intermediate result.

10. A data processing device, It is characterized in that include: An acquisition module, used for acquiring a matrix pair to be processed; A conversion module, used for performing data format conversion on each first element value of the first matrix to be processed and each second element value of the second matrix to be processed in the matrix pair to be processed, respectively, to obtain a first target matrix including the converted first element values ​​and a second target matrix including the converted second element values; wherein the data formats of the converted first element values ​​and the converted second element values ​​include precision bits and data bits, the numerical value located on the precision bits represents the precision unit corresponding to the converted element values, and the numerical value located on the data bits represents the target value of the converted element values ​​under the precision unit; An operation module is used to perform matrix operation on the first target matrix and the second target matrix to obtain an operation result.

11. An electronic device, It is characterized in that include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the data processing method as described in any one of claims 1 to 9 are performed.

12. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 9 are executed.