Data conversion method, data conversion device, data conversion circuit and storage and calculation integrated equipment
By processing the mantissa cutoff, symbol and exponent of the scaling coefficient, efficient conversion from integer data to floating point data is achieved, solving the problems of large calculation volume and high energy consumption in the existing technology, and reducing the consumption of hardware resources .
Patent Information
- Application Number
- CN202411310094.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-09-19
AI Technical Summary
In the process of converting integer data into floating-point data, the prior art requires the use of multipliers of FP16, FP32 or FP64, resulting in large amounts of calculation, large hardware resource utilization and high energy consumption.
By obtaining the integer data to be converted and the target scaling coefficient, the mantissa of the scaling coefficient is cut off according to the number of data bits, the effective mantissa is obtained, and the format conversion is performed based on the symbol, exponent and effective mantissa is reduced to reduce the calculation amount and hardware resource usage.
It greatly reduces the amount of data conversion calculation, reduces the consumption of hardware resources and energy consumption, and ensures calculation accuracy.
Smart Images

Figure CN119276270A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data conversion technology, and in particular to a data conversion method, a computer-readable storage medium, a data conversion device, a data conversion circuit and a storage-computing integrated device. Background Art
[0002] In the technical solution for converting integer data to floating-point data, the INT (Integer) data (such as INT8, INT16) is multiplied by the corresponding scaling factor through the peripheral digital circuit to restore it to FP (Floating Point) data (such as FP16, FP32, or FP64). This process usually requires the use of FP16, FP32 or FP64 multipliers to multiply the INT data with the FP data to obtain the restored FP data, which results in a large amount of calculation required for the process, which will occupy a large amount of hardware resources and bring about a large energy consumption overhead. Summary of the invention
[0003] The present invention aims to solve at least one of the technical problems in the related art to a certain extent. To this end, the first purpose of the present invention is to propose a data conversion method, firstly truncating the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculating the integer data to be converted by the truncated target scaling factor to complete the data format conversion, which greatly reduces the amount of data conversion calculation, reduces the occupation of hardware resources and energy consumption.
[0004] A second object of the present invention is to provide a computer-readable storage medium.
[0005] The third objective of the present invention is to provide a data conversion device.
[0006] A fourth objective of the present invention is to provide a data conversion circuit.
[0007] The fifth objective of the present invention is to provide a storage and computing integrated device.
[0008] To achieve the above-mentioned purpose, the first aspect of the present invention proposes a data conversion method, which includes: obtaining integer data to be converted and a target scaling factor; truncating the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor; and formatting the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted.
[0009] According to the data conversion method of the embodiment of the present invention, firstly, the integer data to be converted and the target scaling factor are obtained, and then the mantissa of the target scaling factor is truncated according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the format of the integer data to be converted is converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the method first truncates the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of calculation, reduces the occupation of hardware resources and energy consumption.
[0010] In addition, the data conversion method according to the above embodiment of the present invention may also have the following additional technical features:
[0011] According to one embodiment of the present invention, the mantissa of the target scaling factor is truncated according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, including: determining the high-order retained mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and rounding the remaining mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor.
[0012] According to one embodiment of the present invention, the format of the integer data to be converted is converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted, including: determining the sign of the target floating-point data corresponding to the integer data to be converted based on the sign of the target scaling factor and the sign of the integer data to be converted; determining the mantissa and the decimal point shift amount of the target floating-point data corresponding to the integer data to be converted based on the effective mantissa of the target scaling factor and the data of the integer data to be converted; determining the exponent of the target floating-point data corresponding to the integer data to be converted based on the exponent of the target scaling factor and the decimal point shift amount; and outputting the target floating-point data corresponding to the integer data to be converted according to the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted and the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0013] According to one embodiment of the present invention, converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted includes: performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted; or converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, including: when the sign of the target scaling factor is negative, performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, and when the sign of the target scaling factor is positive, using the sign of the integer data to be converted as the sign of the target floating-point data corresponding to the integer data to be converted.
[0014] According to one embodiment of the present invention, the mantissa of target floating-point data corresponding to the integer data to be converted and the amount of decimal point shift are determined based on the effective mantissa of the target scaling coefficient and the data of the integer data to be converted, including: filling the high-order bits of the effective mantissa of the target scaling coefficient with one to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; obtaining the product between the target effective mantissa and the data of the integer data to be converted to obtain first data, and determining the amount of decimal point shift and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data; using the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and filling the remaining mantissa of the target floating-point data with zero to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0015] According to one embodiment of the present invention, the exponent of the target floating-point data corresponding to the integer data to be converted is determined based on the exponent of the target scaling factor and the decimal point shift amount, including: obtaining the sum of the exponent of the target scaling factor and the decimal point shift amount to obtain the exponent of the target floating-point data corresponding to the integer data to be converted.
[0016] To achieve the above-mentioned purpose, a second embodiment of the present invention proposes a computer-readable storage medium on which a data conversion program is stored. When the data conversion program is executed by a processor, the above-mentioned data conversion method is implemented.
[0017] According to the computer-readable storage medium of an embodiment of the present invention, the above-mentioned data conversion method is implemented when the data conversion program is executed by the processor. Based on the above-mentioned data conversion method, the amount of data conversion calculation is greatly reduced, and the occupation of hardware resources and energy consumption overhead are reduced.
[0018] To achieve the above-mentioned purpose, the third aspect of the present invention proposes a data conversion device, which includes: a data input module, used to receive integer data to be converted and a target scaling factor; a preprocessing module, used to truncate the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor; a conversion module, used to perform format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted.
[0019] According to the data conversion device of the embodiment of the present invention, the data input module receives the integer data to be converted and the target scaling factor, the preprocessing module truncates the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the conversion module performs format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the device first truncates the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of data conversion calculations and reduces the occupation of hardware resources and energy consumption.
[0020] To achieve the above-mentioned purpose, the fourth aspect of the present invention proposes a data conversion circuit, including: a preprocessing unit, used to truncate the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor; a data conversion unit, used to perform format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted.
[0021] According to the data conversion circuit of the embodiment of the present invention, the preprocessing unit truncates the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the data conversion unit performs format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the circuit calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of data conversion calculation and reduces the occupation of hardware resources and energy consumption.
[0022] In addition, the data conversion circuit according to the above embodiment of the present invention may also have the following additional technical features:
[0023] According to one embodiment of the present invention, the preprocessing unit includes: a rounding processing module, which is used to determine the high-order retained mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and round the remaining mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor.
[0024] According to one embodiment of the present invention, the data conversion unit includes: an XOR module, which is used to perform an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted, so as to obtain the sign of the target floating-point data corresponding to the integer data to be converted; a one-complement processing module, which is used to perform one-complement on the high-bit of the effective mantissa of the target scaling factor, so as to obtain the target effective mantissa of the target scaling factor, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; a multiplier, which is used to obtain the product between the target effective mantissa and the data of the integer data to be converted, so as to obtain the first data; a leading zero counter, which is used to determine the decimal point displacement amount and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data ; an adder, used to obtain the sum of the exponent of the target scaling factor and the decimal point shift quantity, and obtain the exponent of the target floating-point data corresponding to the integer data to be converted; a padding processing module, used to use the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and to pad the remaining mantissa of the target floating-point data with zeros, and obtain the mantissa of the target floating-point data corresponding to the integer data to be converted; wherein the target floating-point data corresponding to the integer data to be converted is composed of the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted, and the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0025] In order to achieve the above-mentioned purpose, the fifth aspect of the present invention proposes a storage and computing integrated device, including the above-mentioned data conversion circuit.
[0026] According to the storage and computing integrated device of the embodiment of the present invention, based on the above-mentioned data conversion circuit, the amount of data conversion calculation is greatly reduced, and the occupation of hardware resources and energy consumption are reduced.
[0027] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 is a flow chart of a data conversion method according to an embodiment of the present invention;
[0029] Figure 2 is a flow chart of a data conversion method according to a specific embodiment of the present invention;
[0030] Figure 3 A connection diagram of a data conversion device according to an embodiment of the present invention;
[0031] Figure 4 is a connection diagram of a data conversion circuit according to an embodiment of the present invention;
[0032] Figure 5 is a connection diagram of a data conversion circuit according to a specific embodiment of the present invention;
[0033] Figure 6 A block diagram of a storage-computing integrated device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0034] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.
[0035] The following describes the data conversion method, computer-readable storage medium, data conversion device, data conversion circuit and storage-computing integrated device proposed in the embodiments of the present invention with reference to the accompanying drawings.
[0036] Figure 1 4 is a flow chart of a data conversion method according to an embodiment of the present invention.
[0037] like Figure 1 As shown, the data conversion method of the embodiment of the present invention may include:
[0038] S1, obtain the integer data to be converted and the target scaling factor;
[0039] S2, truncating the mantissa of the target scaling factor according to the number of bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor;
[0040] S3, performing format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor, and the effective mantissa of the target scaling factor to obtain target floating-point data corresponding to the integer data to be converted.
[0041] Specifically, taking the integer data to be converted as INT8 and the target floating point data as FP32 as an example, the data conversion method of the present application is described in detail. Then, the target scaling factor is the FP32 scaling factor. Among them, INT8 includes 1 bit symbol + 7 bit data, FP32, FP32 scaling factor includes 1 bit symbol + 8 bit exponent + 23 bit mantissa, such as Figure 5 shown.
[0042] The 23-bit mantissa of the FP32 scaling factor is truncated based on the 7-bit data of INT8, wherein the relationship between the number of bits of the effective mantissa of the FP32 scaling factor and the number of bits of the data of INT8 can be set according to the actual situation to achieve truncation and shortening of the 23-bit mantissa of the FP32 scaling factor. Among them, the number of bits of data of INT8 is 7 bits, and at this time, the number of bits of the effective mantissa of the FP32 scaling factor can be set to be one bit less than the number of bits of data of INT8, that is, the mantissa of the FP32 scaling factor is truncated from the high bit, and the high 6-bit mantissa is obtained as the effective mantissa of the FP32 scaling factor. After the mantissa is truncated, the FP32 scaling factor used for calculation includes 1-bit sign + 8-bit exponent + 6-bit effective mantissa, and then the format of the INT8 to be converted is converted based on the truncated FP32 scaling factor to convert the INT8 to be converted into the data format of FP32.
[0043] In the process of format conversion of the INT8 to be converted based on the truncated FP32 scaling coefficient, the sign of the FP32 scaling coefficient after the truncation process and the sign of the INT8 to be converted can be calculated to obtain the sign of FP32, and the exponent and effective mantissa of the FP32 scaling coefficient after the truncation process and the data of the INT8 to be converted can be calculated to obtain the exponent and mantissa of FP32, thereby converting the INT8 to be converted into FP32. In addition, the scaling coefficient is usually a positive number. Then, when the scaling coefficient is a positive number, the sign of the integer data to be converted can also be directly used as the sign of the target floating-point data corresponding to the integer data to be converted. For example, after the mantissa is truncated, the FP32 scaling coefficient used for calculation includes 1-bit sign + 8-bit exponent + 6-bit effective mantissa, and then the sign of the INT8 to be converted is directly used as the sign of FP32, and the data of the INT8 to be converted is calculated based on the 8-bit exponent + 6-bit effective mantissa of the FP32 scaling coefficient after the truncation process to obtain the exponent and mantissa of FP32. Therefore, this embodiment first truncates the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculates the integer data to be converted using the truncated target scaling factor to complete the data format conversion, which greatly reduces the amount of calculation for data conversion and reduces the occupancy of hardware resources and energy consumption.
[0044] In one embodiment of the present invention, the mantissa of the target scaling factor is truncated according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, including: determining the high-order retained mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and rounding the remaining mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor.
[0045] Specifically, first, the high 6-bit mantissa of the FP32 scaling factor is determined as the high-order reserved mantissa according to the 7-bit data of INT8, and the low 17-bit mantissa of the FP32 scaling factor is rounded, and the first 6 bits after rounding are taken as the valid bits, thereby obtaining a 6-bit valid mantissa of the FP32 scaling factor.
[0046] In one embodiment of the present invention, the format of the integer data to be converted is converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted, including: determining the sign of the target floating-point data corresponding to the integer data to be converted based on the sign of the target scaling factor and the sign of the integer data to be converted; determining the mantissa and the decimal point shift amount of the target floating-point data corresponding to the integer data to be converted based on the effective mantissa of the target scaling factor and the data of the integer data to be converted; determining the exponent of the target floating-point data corresponding to the integer data to be converted based on the exponent of the target scaling factor and the decimal point shift amount; and outputting the target floating-point data corresponding to the integer data to be converted according to the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted and the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0047] That is to say, the 1-bit sign of FP32 is determined according to the sign of the FP32 scaling factor and the sign of INT8, the 23-bit mantissa of FP32 and the number of decimal point shifts are calculated according to the 6-bit significant mantissa of the FP32 scaling factor and the 7-bit data of INT8, the 8-bit exponent of FP32 is calculated according to the number of decimal point shifts and the 8-bit exponent of the FP32 scaling factor, and FP32 is obtained according to the 1-bit sign of FP32, the 23-bit mantissa of FP32 and the 8-bit exponent of the FP32 scaling factor, that is, FP32 is 1-bit sign + 8-bit exponent + 23-bit mantissa.
[0048] In one embodiment of the present invention, converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted includes: performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted; or converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted includes: when the sign of the target scaling factor is negative, performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, and when the sign of the target scaling factor is positive, using the sign of the integer data to be converted as the sign of the target floating-point data corresponding to the integer data to be converted.
[0049] That is, when one of the sign of the FP32 scaling factor and the sign of the INT8 to be converted is 0 and the other is 1, the sign of the converted FP32 is 1; when the sign of the FP32 scaling factor and the sign of the INT8 to be converted are both 0 or both 1, the sign of the converted FP32 is 0. 0 represents a positive number and 1 represents a negative number.
[0050] In addition, the sign of the target scaling factor may be determined first. For example, when the sign of the FP32 scaling factor is positive, that is, 0, the sign of the INT8 to be converted is directly used as the sign of the FP32 without logical operation. When the sign of the FP32 scaling factor is negative, that is, 1, an XOR logical operation is performed on the sign of the FP32 scaling factor and the sign of the INT8 to be converted to obtain the sign of the FP32.
[0051] In one embodiment of the present invention, the mantissa of target floating-point data corresponding to the integer data to be converted and the amount of decimal point shift are determined based on the effective mantissa of the target scaling coefficient and the data of the integer data to be converted, including: filling the high-order bits of the effective mantissa of the target scaling coefficient with one to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; obtaining the product of the target effective mantissa and the data of the integer data to be converted to obtain first data, and determining the amount of decimal point shift and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data; using the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and filling the remaining mantissa of the target floating-point data with zero to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0052] That is, the first digit of the 6-bit effective mantissa of the FP32 scaling factor is padded with 1 to obtain a 7-bit target effective mantissa. The 7-bit target effective mantissa is multiplied by the 7-bit data in the INT8 to be converted using a 7-bit multiplier to obtain the first data. The leading zero counter is used to find the position of the first 1 in the first data, and the decimal point shift amount is obtained accordingly according to the number of 0s before the position of the first 1, and the first 1 and the 0 before the first 1 are deleted to obtain the effective mantissa of FP32.
[0053] Among them, the calculated effective mantissa of FP32 may be 7 bits, 9 bits, etc. Since the mantissa of the FP32 data format is 23 bits, the calculated effective mantissa of FP32 is used as the high-order mantissa, and the remaining low-order mantissa is padded with zeros to obtain the 23-bit mantissa corresponding to FP32.
[0054] In one embodiment of the present invention, the exponent of the target floating-point data corresponding to the integer data to be converted is determined based on the exponent of the target scaling factor and the decimal point shift amount, including: obtaining the sum of the exponent of the target scaling factor and the decimal point shift amount to obtain the exponent of the target floating-point data corresponding to the integer data to be converted.
[0055] That is, the decimal point shift amount output by the leading zero counter is added to the 8-bit exponent of the FP32 scaling factor to obtain the 8-bit exponent of FP32.
[0056] As a specific embodiment of the present invention, the integer data to be converted is INT8, the target floating point data is FP32, and the target scaling factor is the FP32 scaling factor. Figure 2 As shown, the data conversion method may include the following steps:
[0057] S101, obtaining INT8 and FP32 scaling factors to be converted.
[0058] S102, determining the high-order reserved mantissa of the FP32 scaling coefficient based on the number of INT8 data bits to be converted.
[0059] S103, rounding the remaining mantissa of the FP32 scaling factor to obtain a 6-bit effective mantissa of the FP32 scaling factor.
[0060] S104, performing an XOR logic operation on the sign of the FP32 scaling factor and the sign of the INT8 to be converted to obtain a 1-bit sign of FP32.
[0061] S105 , padding the high-order bits of the 6-bit effective mantissa of the FP32 scaling factor with one to obtain a 7-bit target effective mantissa of the FP32 scaling factor.
[0062] S106, obtain the product of the 7-bit target effective mantissa and the 7-bit data of INT8 to be converted to obtain the first data.
[0063] S107, determining the decimal point shift amount and the effective mantissa of FP32 based on the leading zero amount of the first data.
[0064] S108, taking the effective mantissa of FP32 as the high-order mantissa of FP32, and padding the remaining mantissa of FP32 with zeros to obtain a 23-bit mantissa of FP32.
[0065] S109, obtaining the sum of the 8-bit exponent of the FP32 scaling factor and the decimal point shift quantity to obtain the 8-bit exponent of FP32.
[0066] S110, output FP32 according to the 1-bit sign of FP32, the 8-bit exponent of FP32, and the 23-bit mantissa of FP32.
[0067] Therefore, this embodiment is mainly based on an 8-bit adder and a 7-bit multiplier, which can realize the data type conversion from integer data to floating-point data. Compared with the FP32 multiplier in the related art, it can greatly reduce the energy consumption, area, and delay overhead of the circuit. At the same time, since the mantissa of the FP32 scaling factor is truncated by 6 bits and supplemented with 1 to obtain the 7-bit input data, that is, the target effective mantissa, the input data has the same resolution as the 7-bit data in INT8, which can effectively ensure the lossless calculation accuracy and keep consistent with the accuracy of INT8 itself, thereby achieving a significant reduction in circuit overhead without introducing additional precision loss.
[0068] In summary, according to the data conversion method of the embodiment of the present invention, firstly, the integer data to be converted and the target scaling factor are obtained, and then the mantissa of the target scaling factor is truncated according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the format of the integer data to be converted is converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Therefore, the method first truncates the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of calculation, reduces the occupation of hardware resources and energy consumption.
[0069] Corresponding to the above embodiment, the present invention also proposes a computer-readable storage medium.
[0070] The computer-readable storage medium of the embodiment of the present invention stores a data conversion program, and the data conversion program implements the above-mentioned data conversion method when executed by a processor.
[0071] According to the computer-readable storage medium of an embodiment of the present invention, the above-mentioned data conversion method is implemented when the data conversion program is executed by the processor. Based on the above-mentioned data conversion method, the amount of calculation is greatly reduced, and the occupation of hardware resources and energy consumption are reduced.
[0072] Corresponding to the above embodiment, the present invention also proposes a data conversion device.
[0073] like Figure 3 As shown, the data conversion device of the embodiment of the present invention may include: a data input module 10, a preprocessing module 20 and a conversion module 30.
[0074] The data input module 10 is used to receive the integer data to be converted and the target scaling factor. The preprocessing module 20 is used to truncate the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor. The conversion module 30 is used to perform format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted.
[0075] According to one embodiment of the present invention, the preprocessing module 20 truncates the mantissa of the target scaling coefficient according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling coefficient, and is specifically used to: determine the high-order retained mantissa of the target scaling coefficient based on the number of data bits of the integer data to be converted, and round the remaining mantissa of the target scaling coefficient to obtain the effective mantissa of the target scaling coefficient.
[0076] According to one embodiment of the present invention, the conversion module 30 performs format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted, and is specifically used for: determining the sign of the target floating-point data corresponding to the integer data to be converted based on the sign of the target scaling factor and the sign of the integer data to be converted; determining the mantissa and the decimal point shift amount of the target floating-point data corresponding to the integer data to be converted based on the effective mantissa of the target scaling factor and the data of the integer data to be converted; determining the exponent of the target floating-point data corresponding to the integer data to be converted based on the exponent of the target scaling factor and the decimal point shift amount; and outputting the target floating-point data corresponding to the integer data to be converted according to the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted and the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0077] According to one embodiment of the present invention, the conversion module 30 performs conversion based on the sign of the target scaling coefficient and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, and is specifically used for: performing an XOR logic operation on the sign of the target scaling coefficient and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted; or, the conversion module 30 performs conversion based on the sign of the target scaling coefficient and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, and is specifically used for: when the sign of the target scaling coefficient is negative, performing an XOR logic operation on the sign of the target scaling coefficient and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted, and when the sign of the target scaling coefficient is positive, using the sign of the integer data to be converted as the sign of the target floating-point data corresponding to the integer data to be converted.
[0078] According to one embodiment of the present invention, the conversion module 30 determines the mantissa of the target floating-point data corresponding to the integer data to be converted and the amount of decimal point shift based on the effective mantissa of the target scaling coefficient and the data of the integer data to be converted, and is specifically used to: fill the high-order mantissa of the effective mantissa of the target scaling coefficient with one to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; obtain the product between the target effective mantissa and the data of the integer data to be converted to obtain the first data, and determine the amount of decimal point shift and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data; use the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and fill the remaining mantissa of the target floating-point data with zero to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0079] According to one embodiment of the present invention, the conversion module 30 determines the exponent of the target floating-point data corresponding to the integer data to be converted based on the exponent of the target scaling factor and the decimal point shift amount, and is specifically used to: obtain the sum of the exponent of the target scaling factor and the decimal point shift amount, and obtain the exponent of the target floating-point data corresponding to the integer data to be converted.
[0080] It should be noted that for details not disclosed in the data conversion device of the embodiment of the present invention, please refer to the details disclosed in the data conversion method of the above embodiment of the present invention, and the details will not be repeated here.
[0081] According to the data conversion device of the embodiment of the present invention, the data input module receives the integer data to be converted and the target scaling factor, the preprocessing module truncates the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the conversion module performs format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the device first truncates the mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and then calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of calculation, reduces the occupation of hardware resources and energy consumption.
[0082] Corresponding to the above embodiment, the present invention further proposes a data conversion circuit.
[0083] like Figure 4 As shown, the data conversion circuit 100 according to the embodiment of the present invention may include: a pre-processing unit 110 and a data conversion unit 120 .
[0084] The preprocessing unit 110 is used to truncate the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor. The data conversion unit 120 is used to perform format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted.
[0085] Combination Figure 5 As shown, according to one embodiment of the present invention, the preprocessing unit 110 includes: a rounding processing module 111, which is used to determine the high-order retained mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and round the remaining mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor.
[0086] According to one embodiment of the present invention, the data conversion unit 120 includes: an XOR module 121, which is used to perform an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted, so as to obtain the sign of the target floating-point data corresponding to the integer data to be converted. A one-complement processing module 122, which is used to perform one-complement on the high-order effective mantissa of the target scaling factor to obtain the target effective mantissa of the target scaling factor, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted. A multiplier 123, which is used to obtain the product between the target effective mantissa and the data of the integer data to be converted, so as to obtain the first data. A leading zero counter 124, which is used to determine the number of decimal point shifts and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data. An adder 125, which is used to obtain the sum of the exponent of the target scaling factor and the number of decimal point shifts, so as to obtain the exponent of the target floating-point data corresponding to the integer data to be converted. The padding processing module 126 takes the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the target floating-point data corresponding to the integer data to be converted, and pads the remaining mantissa of the target floating-point data with zeros to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted; wherein the target floating-point data corresponding to the integer data to be converted is composed of the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted, and the mantissa of the target floating-point data corresponding to the integer data to be converted.
[0087] Specifically, taking the integer data to be converted as INT8, the target floating-point data as FP32, and the target scaling factor as the FP32 scaling factor as an example, the data conversion unit 120 mainly includes an 8-bit adder and a 7-bit multiplier, so compared with the FP32 multiplier, the circuit area, energy consumption, and delay overhead can be greatly reduced. In addition, since the data mantissa of the FP32 scaling factor is truncated by 6 bits and 1 is added to obtain 7-bit input data, the resolution of the input data is consistent with that of the INT8 output data, which greatly reduces the circuit overhead without introducing additional precision loss. In addition, the floating-point multiplier built into the CPU (Central Processing Unit) or other digital circuits can also be used for calculations and rounded, but the circuit overhead is large.
[0088] According to the data conversion circuit of the embodiment of the present invention, the preprocessing unit truncates the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain the effective mantissa of the target scaling factor, and the data conversion unit performs format conversion on the integer data to be converted based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the circuit calculates the integer data to be converted by the target scaling factor after truncation to complete the data format conversion, which greatly reduces the amount of calculation, reduces the energy consumption, area and overhead of the circuit while ensuring the accuracy of data conversion, and reduces the occupation of hardware resources and energy consumption overhead.
[0089] Corresponding to the above-mentioned embodiment, the present invention also proposes a storage and computing integrated device.
[0090] The Compute-In-Memory (CIM) crossbar array (abbreviated as CIM) is an efficient analog computing device that can be used to implement large-scale matrix-vector multiplication and addition operations, and is often widely used in artificial intelligence and neural network calculations. The basic computing unit of its circuit is usually a conductance or charge modulated circuit device, such as a memristor, resistive random access memory, phase change memory, magnetic memory, floating gate transistor, dynamic random access memory, static random access memory, etc. By gating the row and column switches, the current is accumulated and sampled in the analog domain to achieve efficient matrix multiplication operations.
[0091] Since CIM devices use DAC (Digital to Analog Converter) and ADC (Analog to Digital Converter) for data acquisition and quantization, they can only represent calculated data linearly, so they are not compatible with floating-point data (such as FP32). Instead, they usually use integer data for calculations (such as INT8), which will result in data scaling. Taking INT8 and FP32 data types as an example, for neural networks or task types that require FP calculation results, the INT8 results calculated by CIM need to be converted to FP32 results. This process involves additional circuit overhead, energy consumption overhead, and delay overhead.
[0092] In the related art, the INT data calculated by the CIM device is transmitted to the peripheral digital circuit, such as the CPU and other digital computing cores, and then the INT data (such as INT8, INT16) is multiplied by the corresponding scaling factor to restore it to FP data (such as FP16, FP32, or FP64). This process usually requires the use of FP16, FP32, or FP64 multipliers to multiply the INT data with the FP scaling data to obtain the restored FP data. This process will occupy a lot of hardware resources and energy consumption, and the delay is high.
[0093] To solve the above technical problems, Figure 6 As shown, the storage and computing integrated device 1000 of an embodiment of the present invention includes the above-mentioned data conversion circuit 100.
[0094] For example, the data conversion circuit 100 is designed by combining the INT8 data type commonly used in CIM computing arrays with other FP32 data types commonly used in digital circuits. Compared with conventional FP32 multipliers, the data conversion circuit 100 only includes a 7-bit mantissa multiplier instead of a 24-bit multiplier, which can greatly reduce the energy consumption, area, and delay overhead of the circuit. At the same time, since the 7-bit target effective mantissa has the same resolution as the 7-bit data in INT8, the calculation accuracy can be effectively guaranteed to be lossless and consistent with the accuracy of INT8 itself.
[0095] According to the storage and computing integrated device of the embodiment of the present invention, based on the above-mentioned data conversion circuit, the amount of data conversion calculation is greatly reduced, the amount of calculation is greatly reduced, and the occupation of hardware resources and energy consumption are reduced.
[0096] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0097] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0098] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0099] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0100] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0101] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A data conversion method, characterized in that: The method comprises: Get the integer data to be converted and the target scaling factor; According to the number of data bits of the to-be-converted integer data, the mantissa of the target scaling factor is truncated to obtain the effective mantissa of the target scaling factor; The to-be-converted integer data is format-converted based on the sign of the target scaling factor, the exponent of the target scaling factor, and the effective mantissa of the target scaling factor to obtain target floating-point data corresponding to the to-be-converted integer data.
2. The data conversion method according to claim 1, characterized in that: The step of truncating the mantissa of the target scaling factor according to the number of data bits of the to-be-converted integer data to obtain the effective mantissa of the target scaling factor comprises: The high-order reserved mantissa of the target scaling factor is determined based on the number of data bits of the to-be-converted integer data, and the remaining mantissa of the target scaling factor is rounded to obtain the effective mantissa of the target scaling factor.
3. The data conversion method according to claim 2, characterized in that: The format conversion of the to-be-converted integer data based on the sign of the target scaling factor, the exponent of the target scaling factor, and the effective mantissa of the target scaling factor to obtain target floating-point data corresponding to the to-be-converted integer data includes: Determining the sign of the target floating-point data corresponding to the integer data to be converted based on the sign of the target scaling factor and the sign of the integer data to be converted; Determine the mantissa of the target floating-point data corresponding to the integer data to be converted and the decimal point shift amount based on the effective mantissa of the target scaling factor and the data of the integer data to be converted; Determine the exponent of the target floating-point data corresponding to the to-be-converted integer data based on the exponent of the target scaling factor and the decimal point shift amount; Output the target floating-point data corresponding to the integer data to be converted according to the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted, and the mantissa of the target floating-point data corresponding to the integer data to be converted.
4. The data conversion method according to claim 3, characterized in that: The converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted includes: Performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted; or The converting based on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted includes: When the sign of the target scaling factor is negative, an XOR logic operation is performed on the sign of the target scaling factor and the sign of the integer data to be converted to obtain the sign of the target floating-point data corresponding to the integer data to be converted; and when the sign of the target scaling factor is positive, the sign of the integer data to be converted is used as the sign of the target floating-point data corresponding to the integer data to be converted.
5. The data conversion method according to claim 3, characterized in that: The determining the mantissa of the target floating-point data corresponding to the integer data to be converted and the decimal point shift amount based on the effective mantissa of the target scaling factor and the data of the integer data to be converted comprises: Filling the high bits of the effective mantissa of the target scaling factor with one to obtain a target effective mantissa of the target scaling factor, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; Obtain the product of the target effective mantissa and the data of the integer data to be converted to obtain first data, and determine the decimal point shift amount and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data; The effective mantissa of the target floating-point data corresponding to the integer data to be converted is used as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and the remaining mantissa of the target floating-point data is padded with zeros to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted.
6. The data conversion method according to claim 3, characterized in that: The step of determining the exponent of the target floating-point data corresponding to the integer data to be converted based on the exponent of the target scaling factor and the decimal point shift amount includes: The sum of the exponent of the target scaling factor and the decimal point shift quantity is obtained to obtain the exponent of the target floating-point data corresponding to the integer data to be converted.
7. A computer-readable storage medium, characterized in that: A data conversion program is stored thereon, and when the data conversion program is executed by a processor, the data conversion method according to any one of claims 1-6 is implemented.
8. A data conversion device, characterized in that: The device comprises: A data input module, for receiving integer data to be converted and a target scaling factor; A preprocessing module, configured to truncate the mantissa of the target scaling factor according to the number of data bits of the integer data to be converted to obtain a valid mantissa of the target scaling factor; The conversion module is used to perform format conversion on the to-be-converted integer data based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain target floating-point data corresponding to the to-be-converted integer data.
9. A data conversion circuit, characterized in that: include: A preprocessing unit, configured to truncate the mantissa of the target scaling factor according to the number of bits of the integer data to be converted to obtain a valid mantissa of the target scaling factor; The data conversion unit is used to perform format conversion on the to-be-converted integer data based on the sign of the target scaling factor, the exponent of the target scaling factor and the effective mantissa of the target scaling factor to obtain target floating-point data corresponding to the to-be-converted integer data.
10. The data conversion circuit according to claim 9, characterized in that: The pre-processing unit comprises: The rounding processing module is used to determine the high-order retained mantissa of the target scaling factor based on the number of data bits of the integer data to be converted, and round off the remaining mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor.
11. The data conversion circuit according to claim 10, characterized in that: The data conversion unit comprises: An XOR module, used for performing an XOR logic operation on the sign of the target scaling factor and the sign of the integer data to be converted, so as to obtain the sign of the target floating-point data corresponding to the integer data to be converted; a one-fill processing module, used for filling the high-order bits of the effective mantissa of the target scaling factor with one to obtain the target effective mantissa of the target scaling factor, wherein the mantissa of the target effective mantissa is equal to the number of data bits of the integer data to be converted; A multiplier, used for obtaining the product of the target effective mantissa and the data of the integer data to be converted to obtain first data; A leading zero counter, used for determining the number of decimal point shifts and the effective mantissa of the target floating-point data corresponding to the integer data to be converted based on the number of leading zeros of the first data; An adder, used for obtaining the sum of the exponent of the target scaling factor and the decimal point shift quantity, and obtaining the exponent of the target floating-point data corresponding to the integer data to be converted; a padding processing module, used for taking the effective mantissa of the target floating-point data corresponding to the integer data to be converted as the high-order mantissa of the target floating-point data corresponding to the integer data to be converted, and padding the remaining mantissa of the target floating-point data with zeros to obtain the mantissa of the target floating-point data corresponding to the integer data to be converted; The target floating-point data corresponding to the integer data to be converted is composed of the sign of the target floating-point data corresponding to the integer data to be converted, the exponent of the target floating-point data corresponding to the integer data to be converted, and the mantissa of the target floating-point data corresponding to the integer data to be converted.
12. A storage and computing integrated device, characterized in that: Comprising the data conversion circuit according to any one of claims 9-11.
Citation Information
Patent Citations
Floating-point-type data lossless compression method for scientific calculation
CN105024702A
Data conversion method based on new short floating point type data
CN105634499A
Data format conversion device and method, electronic equipment and computer storage medium
CN118051200A
Data processing method and device, processor, electronic equipment and storage medium
CN118312130A
Preparation and execution of quantized scaling on integrated circuitry
US11188300B1