Data conversion method, conversion device, conversion circuit and computing and storage integrated device
By truncating the mantissa of the target scaling factor, the problems of computational complexity and hardware resource occupation when converting integer data into floating-point data are solved, and efficient data format conversion is achieved.
Patent Information
- Application Number
- CN202411310094.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-09-19
AI Technical Summary
In the process of converting integer data into floating-point data, existing technologies require the use of FP16, FP32, or FP64 multipliers, resulting in large amounts of computation, high hardware resource usage, and high energy consumption.
By truncating the mantissa of the target scaling factor to obtain the effective mantissa, and performing format conversion based on the sign, exponent and effective mantissa, the amount of calculation and hardware resource usage are reduced.
It greatly reduces the amount of data conversion calculations, reduces hardware resource usage and energy consumption, and at the same time ensures calculation accuracy.
Smart Images

Figure CN119276270B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data conversion, and in particular to a data conversion method, a computer readable storage medium, a data conversion device, a data conversion circuit and an integrated computing device. BACKGROUND
[0002] In the technical scheme of converting integer data into floating point data, the INT (Integer) data (such as INT8, INT16) is multiplied by a corresponding scaling factor through a peripheral digital circuit to restore the FP (Floating Point) data (such as FP16, FP32 or FP64). This process usually requires the use of a multiplier of FP16, FP32 or FP64 to multiply the INT data with the FP data to obtain the restored FP data, thereby resulting in a large amount of calculation required for the process, occupying a large amount of hardware resources and causing a large energy consumption overhead. SUMMARY
[0003] The present application aims to at least solve one of the technical problems in the related art. To this end, the first object of the present application is to provide a data conversion method, which first truncates the mantissa of a target scaling factor based on the data bit number of the integer data to be converted, and then calculates the integer data to be converted through the target scaling factor after the truncation processing to complete the data format conversion, greatly reducing the data conversion calculation amount, reducing the occupation of hardware resources and energy consumption overhead.
[0004] The second object of the present application is to provide a computer readable storage medium.
[0005] The third object of the present application is to provide a data conversion device.
[0006] The fourth object of the present application is to provide a data conversion circuit.
[0007] The fifth object of the present application is to provide an integrated computing device.
[0008] To achieve the above objects, the first aspect of the present application provides a data conversion method, which comprises: obtaining integer data to be converted and a target scaling factor; truncating the mantissa of the target scaling factor to obtain the effective mantissa of the target scaling factor according to the data bit number of the integer data to be converted; and 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 the target floating point data corresponding to the integer data to be converted.
[0009] According to the data conversion method provided in the embodiments of the present application, the integer type data to be converted and the target scaling coefficient are first obtained, then the mantissa of the target scaling coefficient is truncated according to the data bit number of the integer type data to be converted to obtain the effective mantissa of the target scaling coefficient, and the integer type data to be converted is format-converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient to obtain the target floating point type data corresponding to the integer type data to be converted. Thus, the mantissa of the target scaling coefficient is first truncated according to the data bit number of the integer type data to be converted, and then the integer type data to be converted is calculated by using the target scaling coefficient after the truncation, so as to complete the data format conversion, which greatly reduces the calculation amount and reduces the occupation of hardware resources and energy consumption.
[0010] In addition, the data conversion method provided in the embodiments of the present application can further have the following additional technical features:
[0011] According to one embodiment of the present application, the mantissa of the target scaling coefficient is truncated according to the data bit number of the integer type data to be converted to obtain the effective mantissa of the target scaling coefficient, including: determining the high-bit reserved mantissa of the target scaling coefficient based on the data bit number of the integer type data to be converted, and rounding the remaining mantissa of the target scaling coefficient to obtain the effective mantissa of the target scaling coefficient.
[0012] According to one embodiment of the present application, the integer type data to be converted is format-converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient to obtain the target floating point type data corresponding to the integer type data to be converted, including: determining the sign of the target floating point type data corresponding to the integer type data to be converted based on the sign of the target scaling coefficient and the sign of the integer type data to be converted; determining the mantissa of the target floating point type data corresponding to the integer type data to be converted and the decimal point shift number based on the effective mantissa of the target scaling coefficient and the data of the integer type data to be converted; determining the exponent of the target floating point type data corresponding to the integer type data to be converted based on the exponent of the target scaling coefficient and the decimal point shift number; and outputting the target floating point type data corresponding to the integer type data to be converted according to the sign of the target floating point type data corresponding to the integer type data to be converted, the exponent of the target floating point type data corresponding to the integer type data to be converted and the mantissa of the target floating point type data corresponding to the integer type data to be converted.
[0013] According to one embodiment of the present application, the sign of the target floating point type data corresponding to the integer type data to be converted is determined based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, including: performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted; or, the sign of the target floating point type data corresponding to the integer type data to be converted is determined based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, including: when the sign of the target scaling coefficient is negative, performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted, and when the sign of the target scaling coefficient is positive, taking the sign of the integer type data to be converted as the sign of the target floating point type data corresponding to the integer type data to be converted.
[0014] According to one embodiment of the present application, the exponent and the decimal point shift quantity of the target floating point type data corresponding to the integer type data to be converted are determined based on the effective mantissa of the target scaling coefficient and the data of the integer type data to be converted, including: performing high-bit padding on the effective mantissa of the target scaling coefficient to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the data bit number of the integer type data to be converted; obtaining the product between the target effective mantissa and the data of the integer type data to be converted to obtain first data, and determining the decimal point shift quantity and the effective mantissa of the target floating point type data corresponding to the integer type data to be converted based on the leading zero number of the first data; taking the effective mantissa of the target floating point type data corresponding to the integer type data to be converted as the high-bit mantissa of the target floating point type data corresponding to the integer type data to be converted, and performing zero padding on the remaining mantissa of the target floating point type data to obtain the mantissa of the target floating point type data corresponding to the integer type data to be converted.
[0015] According to one embodiment of the present application, the exponent of the target floating point type data corresponding to the integer type data to be converted is determined based on the index of the target scaling coefficient and the decimal point shift quantity, including: obtaining the sum of the index of the target scaling coefficient and the decimal point shift quantity to obtain the exponent of the target floating point type data corresponding to the integer type data to be converted.
[0016] To achieve the above object, the second aspect of the present application provides a computer readable storage medium having a data conversion program stored thereon, which is executed by a processor to implement the above data conversion method.
[0017] The computer readable storage medium according to the embodiment of the present application, when the data conversion program is executed by the processor, implements the above data conversion method. Based on the above data conversion method, the data conversion calculation amount is greatly reduced, and the occupation of hardware resources and energy consumption overhead are reduced.
[0018] To achieve the above object, the third aspect of the present application provides a data conversion device, comprising: a data input module, configured to receive an integer data to be converted and a target scaling coefficient; a preprocessing module, configured to obtain an effective mantissa of the target scaling coefficient by truncating a mantissa of the target scaling coefficient according to a data bit number of the integer data to be converted; and a conversion module, configured to perform format conversion on the integer data to be converted based on a sign of the target scaling coefficient, an exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient, so as to obtain a target floating point data corresponding to the integer data to be converted.
[0019] According to the data conversion device provided by the embodiment of the present application, the data input module receives the integer data to be converted and the target scaling coefficient, the preprocessing module obtains the effective mantissa of the target scaling coefficient by truncating the mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted, and the conversion module performs format conversion on the integer data to be converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient, so as 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 coefficient according to the data bit number of the integer data to be converted, and then performs calculation on the integer data to be converted by using the target scaling coefficient after the truncation, so as to complete the data format conversion, thereby greatly reducing the data conversion calculation amount and reducing the occupation of hardware resources and energy consumption.
[0020] To achieve the above object, the fourth aspect of the present application provides a data conversion circuit, comprising: a preprocessing unit, configured to obtain an effective mantissa of a target scaling coefficient by truncating a mantissa of the target scaling coefficient according to a data bit number of an integer data to be converted; and a data conversion unit, configured to perform format conversion on the integer data to be converted based on a sign of the target scaling coefficient, an exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient, so as to obtain a target floating point data corresponding to the integer data to be converted.
[0021] According to the data conversion circuit provided by the embodiment of the present application, the preprocessing unit obtains the effective mantissa of the target scaling coefficient by truncating the mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted, and the data conversion unit performs format conversion on the integer data to be converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient, so as to obtain the target floating point data corresponding to the integer data to be converted. Thus, the circuit performs calculation on the integer data to be converted by using the target scaling coefficient after the truncation, so as to complete the data format conversion, thereby greatly reducing the data conversion calculation amount and reducing the occupation of hardware resources and energy consumption.
[0022] In addition, the data conversion circuit according to the above embodiments of the present application can have the following additional technical features:
[0023] According to one embodiment of the present application, the preprocessing unit comprises: a rounding processing module configured to determine a high bit reserved mantissa of a target scaling coefficient based on a data bit number of the integer type data to be converted, and round a remaining mantissa of the target scaling coefficient to obtain an effective mantissa of the target scaling coefficient.
[0024] According to one embodiment of the present application, the data conversion unit comprises: an exclusive OR module configured to perform an exclusive OR logical operation on a sign of the target scaling coefficient and a sign of the integer type data to be converted to obtain a sign of the target floating point type data corresponding to the integer type data to be converted; a one supplement processing module configured to supplement one to a high bit of the effective mantissa of the target scaling coefficient to obtain a target effective mantissa of the target scaling coefficient, wherein a mantissa of the target effective mantissa is equal to the data bit number of the integer type data to be converted; a multiplier configured to obtain a product between the target effective mantissa and the data of the integer type data to be converted to obtain a first data; a leading zero counter configured to determine a decimal point displacement number and an effective mantissa of the target floating point type data corresponding to the integer type data to be converted based on a number of leading zeros of the first data; an adder configured to obtain a sum of an index of the target scaling coefficient and the decimal point displacement number to obtain an index of the target floating point type data corresponding to the integer type data to be converted; and a bit supplement processing module configured to take the effective mantissa of the target floating point type data corresponding to the integer type data to be converted as a high bit mantissa of the target floating point type data corresponding to the integer type data to be converted, and supplement zeros to a remaining mantissa of the target floating point type data to obtain a mantissa of the target floating point type data corresponding to the integer type data to be converted; wherein the target floating point type data corresponding to the integer type data to be converted is composed of the sign of the target floating point type data corresponding to the integer type data to be converted, the index of the target floating point type data corresponding to the integer type data to be converted, and the mantissa of the target floating point type data corresponding to the integer type data to be converted.
[0025] To achieve the above object, the fifth aspect embodiment of the present application provides a data conversion circuit.
[0026] The data conversion circuit according to the embodiment of the present application greatly reduces the data conversion calculation amount and reduces the occupation of hardware resources and energy consumption.
[0027] Additional aspects and advantages of the present application will be made apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 A flowchart of the data conversion method according to one embodiment of the present application;
[0029] Figure 2 A flowchart of the data conversion method according to one embodiment of the present application;
[0030] Figure 3 Connection diagram of a data conversion device according to an embodiment of the present application;
[0031] Figure 4 Connection diagram of a data conversion circuit according to an embodiment of the present application;
[0032] Figure 5 Connection diagram of a data conversion circuit according to a specific embodiment of the present application;
[0033] Figure 6 Block diagram of an in-memory computing device according to an embodiment of the present application. DETAILED DESCRIPTION
[0034] Embodiments of the present application are described in detail below with reference to the accompanying drawings, in which the same or like reference numerals in different drawings denote the same or like elements or elements having the same or similar functions. The embodiments described below by reference to the accompanying drawings are exemplary and are intended to explain the present application, and cannot be understood as limiting the present application.
[0035] The data conversion method, computer readable storage medium, data conversion device, data conversion circuit and in-memory computing device according to the embodiments of the present application are described below with reference to the accompanying drawings.
[0036] Figure 1 Flowchart of a data conversion method according to an embodiment of the present application.
[0037] As shown in Figure 1 , the data conversion method according to the embodiments of the present application can include:
[0038] S1, obtaining an integer type data to be converted and a target scaling factor;
[0039] S2, performing bit truncation on the mantissa of the target scaling factor according to the data bit number of the integer type data to be converted to obtain the effective mantissa of the target scaling factor;
[0040] S3, performing format conversion on the integer type 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 type data corresponding to the integer type data to be converted.
[0041] Specifically, taking the integer type data to be converted as INT8 and the target floating point type data as FP32 as an example, the data conversion method of the present application is described in detail. Then, the target scaling factor is an FP32 scaling factor. As shown in Figure 5 , the INT8 includes 1 bit sign + 7 bit data, and the FP32 and the FP32 scaling factor include 1 bit sign + 8 bit exponent + 23 bit mantissa.
[0042] The 23-bit mantissa of the FP32 scaling coefficient is truncated based on the 7-bit data of INT8, and the relationship between the number of effective mantissa bits of the FP32 scaling coefficient and the number of data bits of INT8 can be set according to actual conditions to achieve the truncation and shortening of the 23-bit mantissa of the FP32 scaling coefficient. At this time, the number of effective mantissa bits of the FP32 scaling coefficient is one bit less than the number of data bits of INT8, that is, the mantissa of the FP32 scaling coefficient is truncated from the high bit, and the 6-bit high bit mantissa is obtained as the effective mantissa of the FP32 scaling coefficient. After the mantissa truncation, the FP32 scaling coefficient used for calculation includes 1-bit sign + 8-bit exponent + 6-bit effective mantissa, and then the INT8 to be converted is format-converted based on the FP32 scaling coefficient after the truncation processing to convert the INT8 to be converted into the data format of FP32.
[0043] In the format conversion process of the INT8 to be converted based on the FP32 scaling coefficient after the truncation processing, the sign of the FP32 can be obtained by calculating the sign of the INT8 to be converted and the sign of the FP32 scaling coefficient after the truncation processing, and the exponent and the mantissa of the FP32 can be obtained by calculating the data of the INT8 to be converted and the exponent and the effective mantissa of the FP32 scaling coefficient after the truncation processing, so as to convert the INT8 to be converted into FP32. In addition, the scaling coefficient is usually positive, so when the scaling coefficient is positive, the sign of the target floating point data corresponding to the integer data to be converted can also be directly taken as the sign of the integer data to be converted, for example, after the mantissa truncation, 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 taken as the sign of the 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 processing to obtain the exponent and the mantissa of the FP32. Therefore, this embodiment first truncates the mantissa of the target scaling coefficient based on the data bit number of the integer data to be converted, and then calculates the integer data to be converted by the target scaling coefficient after the truncation to complete the data format conversion, which greatly reduces the calculation amount of data conversion and reduces the occupation of hardware resources and energy consumption.
[0044] In an embodiment of the present application, the mantissa of the target scaling coefficient is truncated based on the data bit number of the integer data to be converted to obtain the effective mantissa of the target scaling coefficient, including: determining the high-bit reserved mantissa of the target scaling coefficient based on the data bit number of the integer data to be converted, and rounding the remaining mantissa of the target scaling coefficient to obtain the effective mantissa of the target scaling coefficient.
[0045] Specifically, first, the high 6-bit mantissa of the FP32 scale coefficient is determined according to the 7-bit data of the INT8 as the high-bit reserved mantissa, and the low 17-bit mantissa of the FP32 scale coefficient is rounded off, and the first 6 bits of the rounded-off mantissa are taken as the significant bits, so as to obtain the 6-bit significant mantissa of the FP32 scale coefficient.
[0046] In an embodiment of the present application, the format conversion of the to-be-converted integer type data based on the sign of the target scale coefficient, the exponent of the target scale coefficient and the significant mantissa of the target scale coefficient is to obtain the target floating point type data corresponding to the to-be-converted integer type data, which includes: determining the sign of the target floating point type data corresponding to the to-be-converted integer type data based on the sign of the target scale coefficient and the sign of the to-be-converted integer type data; determining the mantissa of the target floating point type data corresponding to the to-be-converted integer type data and the number of decimal point shifts based on the significant mantissa of the target scale coefficient and the data of the to-be-converted integer type data; determining the exponent of the target floating point type data corresponding to the to-be-converted integer type data based on the exponent of the target scale coefficient and the number of decimal point shifts; and outputting the target floating point type data corresponding to the to-be-converted integer type data according to the sign of the target floating point type data corresponding to the to-be-converted integer type data, the exponent of the target floating point type data corresponding to the to-be-converted integer type data and the mantissa of the target floating point type data corresponding to the to-be-converted integer type data.
[0047] That is, the 1-bit sign of the FP32 is determined according to the sign of the FP32 scale coefficient and the sign of the INT8, the 23-bit mantissa of the FP32 and the number of decimal point shifts are calculated according to the 6-bit significant mantissa of the FP32 scale coefficient and the 7-bit data of the INT8, the 8-bit exponent of the FP32 is calculated according to the number of decimal point shifts and the 8-bit exponent of the FP32 scale coefficient, and the FP32 is obtained according to the 1-bit sign of the FP32, the 23-bit mantissa of the FP32 and the 8-bit exponent of the FP32 scale coefficient, that is, the FP32 is 1-bit sign + 8-bit exponent + 23-bit mantissa.
[0048] In an embodiment of the present application, the sign of the target floating point type data corresponding to the integer type data to be converted is determined based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, including: performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted; or, the sign of the target floating point type data corresponding to the integer type data to be converted is determined based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, including: when the sign of the target scaling coefficient is negative, performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted, and when the sign of the target scaling coefficient is positive, taking the sign of the integer type data to be converted as the sign of the target floating point type data corresponding to the integer type data to be converted.
[0049] That is, in the case that one of the sign of the FP32 scaling coefficient and the sign of the INT8 to be converted is 0 and the other is 1, the sign of the converted FP32 is 1; in the case that both of the sign of the FP32 scaling coefficient and the sign of the INT8 to be converted are 0 or 1, the sign of the converted FP32 is 0. Wherein, 0 represents positive number and 1 represents negative number.
[0050] In addition, the sign of the target scaling coefficient can be first judged, for example, when the sign of the FP32 scaling coefficient is positive, i.e. 0, the sign of the converted FP32 is directly taken as the sign of the INT8 to be converted without logical operation; when the sign of the FP32 scaling coefficient is negative, i.e. 1, exclusive-OR logical operation is performed on the sign of the FP32 scaling coefficient and the sign of the INT8 to be converted to obtain the sign of the FP32.
[0051] In an embodiment of the present application, the mantissa of the target floating point type data corresponding to the integer type data to be converted and the number of decimal point shifts are determined based on the effective mantissa of the target scaling coefficient and the data of the integer type data to be converted, including: performing high-bit padding on the effective mantissa of the target scaling coefficient to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the data bit number of the integer type data to be converted; obtaining the product between the target effective mantissa and the data of the integer type data to be converted to obtain first data, and determining the number of decimal point shifts and the effective mantissa of the target floating point type data corresponding to the integer type data to be converted based on the number of leading zeros of the first data; taking the effective mantissa of the target floating point type data corresponding to the integer type data to be converted as the high-order mantissa of the target floating point type data corresponding to the integer type data to be converted, and performing zero padding on the remaining mantissa of the target floating point type data to obtain the mantissa of the target floating point type data corresponding to the integer type data to be converted.
[0052] That is, the first bit of the 6-bit effective mantissa of the FP32 scaling coefficient is filled with 1 to obtain a 7-bit target effective mantissa. The 7-bit target effective mantissa is multiplied with the 7-bit data in the INT8 to be converted using a 7-bit multiplier to obtain first data. The first 1 in the first data is found using a leading zero counter, and the number of 0s in front of the first 1 is used to obtain a decimal point shift number, and the first 1 and the 0s in front of the first 1 are deleted to obtain the effective mantissa of the FP32.
[0053] The calculated effective mantissa of the FP32 can be 7 bits, 9 bits, etc. Since the mantissa of the data format of the FP32 is 23 bits, the calculated effective mantissa of the FP32 is used as a high-bit mantissa, and the remaining low-bit mantissa is filled with 0s to obtain the 23-bit mantissa corresponding to the FP32.
[0054] In an embodiment of the present application, 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 coefficient and the decimal point shift number, and includes: obtaining the sum of the exponent of the target scaling coefficient and the decimal point shift number 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 number output by the leading zero counter is added to the 8-bit exponent of the FP32 scaling coefficient to obtain the 8-bit exponent of the FP32.
[0056] As a specific embodiment of the present application, taking the integer data to be converted as INT8, the target floating-point data as FP32, and the target scaling coefficient as the FP32 scaling coefficient as an example, as shown in the following table, the data conversion method can include the following steps: Figure 2
[0057] S101, obtaining the INT8 to be converted and the FP32 scaling coefficient.
[0058] S102, determining the high-bit reserved mantissa of the FP32 scaling coefficient based on the data bit number of the INT8 to be converted.
[0059] S103, rounding the remaining mantissa of the FP32 scaling coefficient to obtain a 6-bit effective mantissa of the FP32 scaling coefficient.
[0060] S104, performing an exclusive-OR logical operation on the sign of the FP32 scaling coefficient and the sign of the INT8 to be converted to obtain a 1-bit sign of the FP32.
[0061] S105, filling the high bit of the 6-bit effective mantissa of the FP32 scaling coefficient with 1 to obtain a 7-bit target effective mantissa of the FP32 scaling coefficient.
[0062] S106, obtain a product between the 7-bit target effective mantissa and the 7-bit data of the INT8 to be converted, to obtain first data.
[0063] S107, determine the number of decimal point shifts and the effective mantissa of the FP32 based on the number of leading zeros of the first data.
[0064] S108, take the effective mantissa of the FP32 as the high-order mantissa of the FP32, and pad zeros to the remaining mantissa of the FP32 to obtain the 23-bit mantissa of the FP32.
[0065] S109, obtain a sum of the 8-bit exponent of the FP32 scaling coefficient and the number of decimal point shifts to obtain the 8-bit exponent of the FP32.
[0066] S110, output the FP32 according to the 1-bit sign of the FP32, the 8-bit exponent of the FP32, and the 23-bit mantissa of the FP32.
[0067] Therefore, the embodiment can realize the data type conversion from the integer data to the floating-point data mainly based on an 8-bit adder and a 7-bit multiplier, and can greatly reduce the energy consumption, area, and delay overhead of the circuit relative to the multiplier of the FP32 in the related art. Meanwhile, since the mantissa of the FP32 scaling coefficient is truncated by 6 bits, the 7-bit input data, i.e., the target effective mantissa, is obtained after padding 1, the input data and the 7-bit data in the INT8 have the same resolution, the calculation precision loss can be effectively guaranteed, the precision of the INT8 itself is maintained, and the additional precision loss is not introduced, so that the circuit overhead is greatly reduced.
[0068] In summary, according to the data conversion method of the embodiment of the present application, the integer data to be converted and the target scaling coefficient are first obtained, then the effective mantissa of the target scaling coefficient is obtained by truncating the mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted, and the integer data to be converted is format-converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient, and the effective mantissa of the target scaling coefficient, 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 coefficient based on the data bit number of the integer data to be converted, and then calculates the integer data to be converted by using the target scaling coefficient after the truncation, to complete the data format conversion, so that the calculation amount is greatly reduced, and the occupation of hardware resources and the energy consumption overhead are reduced.
[0069] Corresponding to the above embodiment, the present application further provides a computer readable storage medium.
[0070] The computer readable storage medium of the embodiment of the present application has a data conversion program stored thereon, and the data conversion program, when executed by a processor, implements the data conversion method.
[0071] The computer readable storage medium of the embodiment of the present application has a data conversion program stored thereon, and the data conversion program, when executed by a processor, implements the data conversion method.
[0072] Corresponding to the above embodiment, the present application also provides a data conversion device.
[0073] As shown in Figure 3 The data conversion device of the embodiment of the present application can include a data input module 10, a preprocessing module 20 and a conversion module 30.
[0074] The data input module 10 is configured to receive the integer data to be converted and a target scaling factor. The preprocessing module 20 is configured to obtain the significant digits of the target scaling factor by truncating the mantissa of the target scaling factor according to the data bit number of the integer data to be converted. The conversion module 30 is configured 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 significant digits of the target scaling factor, so as to obtain the target floating point data corresponding to the integer data to be converted.
[0075] According to an embodiment of the present application, the preprocessing module 20 obtains the significant digits of the target scaling factor by truncating the mantissa of the target scaling factor according to the data bit number of the integer data to be converted, specifically by determining the high-order reserved mantissa of the target scaling factor based on the data bit number of the integer data to be converted, and rounding the remaining mantissa of the target scaling factor to obtain the significant digits of the target scaling factor.
[0076] According to an embodiment of the present application, 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 significant digits of the target scaling factor, so as to obtain the target floating point data corresponding to the integer data to be converted, specifically by 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 of the target floating point data corresponding to the integer data to be converted and the number of decimal point shifts based on the significant digits 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 number of decimal point shifts; 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 application, the conversion module 30 converts the sign of the target floating point type data corresponding to the integer type data to be converted based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, specifically for: performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted; or, the conversion module 30 converts the sign of the target floating point type data corresponding to the integer type data to be converted based on the sign of the target scaling coefficient and the sign of the integer type data to be converted, specifically for: when the sign of the target scaling coefficient is negative, performing exclusive-OR logical operation on the sign of the target scaling coefficient and the sign of the integer type data to be converted to obtain the sign of the target floating point type data corresponding to the integer type data to be converted, and when the sign of the target scaling coefficient is positive, taking the sign of the integer type data to be converted as the sign of the target floating point type data corresponding to the integer type data to be converted.
[0078] According to one embodiment of the present application, the conversion module 30 determines the tail of the target floating point type data corresponding to the integer type data to be converted and the number of decimal point shifts based on the effective tail of the target scaling coefficient and the data of the integer type data to be converted, specifically for: padding the effective tail of the target scaling coefficient with one to obtain the target effective tail of the target scaling coefficient, wherein the tail of the target effective tail is equal to the number of data bits of the integer type data to be converted; obtaining the product between the target effective tail and the data of the integer type data to be converted to obtain the first data, and determining the number of decimal point shifts and the effective tail of the target floating point type data corresponding to the integer type data to be converted based on the number of leading zeros of the first data; taking the effective tail of the target floating point type data corresponding to the integer type data to be converted as the high tail of the target floating point type data corresponding to the integer type data to be converted, and padding the remaining tail of the target floating point type data with zeros to obtain the tail of the target floating point type data corresponding to the integer type data to be converted.
[0079] According to one embodiment of the present application, the conversion module 30 determines the exponent of the target floating point type data corresponding to the integer type data to be converted based on the exponent of the target scaling coefficient and the number of decimal point shifts, specifically for: obtaining the sum of the exponent of the target scaling coefficient and the number of decimal point shifts to obtain the exponent of the target floating point type data corresponding to the integer type data to be converted.
[0080] It should be noted that the details of the data conversion device not disclosed in the embodiments of the present application are referred to the details disclosed in the data conversion method of the above-mentioned embodiments of the present application, which will not be described here in detail.
[0081] According to the data conversion device, the data input module receives the integer data to be converted and the target scaling coefficient, the preprocessing module performs bit truncation on the mantissa of the target scaling coefficient to obtain the effective mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted, and the conversion module performs format conversion on the integer data to be converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient to obtain the target floating-point data corresponding to the integer data to be converted. Thus, the device first performs bit truncation on the mantissa of the target scaling coefficient based on the data bit number of the integer data to be converted, and then performs calculation on the integer data to be converted by using the target scaling coefficient after the bit truncation to complete the data format conversion, thereby greatly reducing the calculation amount and reducing the occupation of hardware resources and energy consumption.
[0082] According to the above embodiment, the application further provides a data conversion circuit.
[0083] As shown in Figure 4 The data conversion circuit 100 according to an embodiment of the application can include a preprocessing unit 110 and a data conversion unit 120.
[0084] The preprocessing unit 110 is configured to perform bit truncation on the mantissa of the target scaling coefficient to obtain the effective mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted. The data conversion unit 120 is configured to perform format conversion on the integer data to be converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the effective mantissa of the target scaling coefficient to obtain the target floating-point data corresponding to the integer data to be converted.
[0085] As shown in Figure 5 According to an embodiment of the application, the preprocessing unit 110 includes a rounding processing module 111 configured to determine the high-bit reserved mantissa of the target scaling coefficient based on the data bit number 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.
[0086] According to one embodiment of the present application, the data conversion unit 120 comprises: an exclusive or module 121, configured to perform exclusive or logical 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; a one-complement processing module 122, configured to perform high-bit one-complement on the effective mantissa of the target scaling coefficient, to obtain the target effective mantissa of the target scaling coefficient, wherein the mantissa of the target effective mantissa is equal to the data bit number of the integer data to be converted; a multiplier 123, configured to obtain 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 124, configured 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, configured to obtain the sum of the exponent of the target scaling coefficient and the number of decimal point shifts, to obtain the exponent of the target floating point data corresponding to the integer data to be converted; and a bit-complement processing module 126, configured to take 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 perform zero-complement on the remaining mantissa of the target floating point data, 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 coefficient as FP32 scaling coefficient as an example, the data conversion unit 120 mainly comprises 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 coefficient is truncated by 6 bits, the input data is obtained after 1 is added, and the resolution of the input data and the INT8 output data remains consistent, so that the circuit overhead is greatly reduced without introducing additional precision loss. In addition, the floating point multiplier in the CPU (Central Processing Unit, central processor) or other digital circuits can also be used for calculation, and rounding is performed, but the circuit overhead is large.
[0088] According to the data conversion circuit, the pre-processing unit obtains the significant mantissa of the target scaling coefficient by truncating the mantissa of the target scaling coefficient according to the data bit number of the integer data to be converted, and the data conversion unit performs format conversion on the integer data to be converted based on the sign of the target scaling coefficient, the exponent of the target scaling coefficient and the significant mantissa of the target scaling coefficient, 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 using the target scaling coefficient after the truncation processing to complete the data format conversion, greatly reduces the calculation amount, reduces the energy consumption, area and overhead of the circuit while ensuring the data conversion accuracy, and reduces the occupation and energy consumption of the hardware resources.
[0089] Corresponding to the above-mentioned embodiments, the application further provides a compute-in-memory device.
[0090] The compute-in-memory (CIM) cross array (referred to as compute-in-memory array) is a high-efficiency analog operation device, which can be used to implement large-scale matrix-vector multiplication and addition operations, and is usually applied in a large number of calculations of artificial intelligence and neural networks. The basic operation unit of the circuit is usually an electric conductance or charge modulatable circuit device, such as a memristor, a resistive random access memory, a phase change memory, a magnetic memory, a floating gate transistor, a dynamic random access memory and a static random access memory. Through the gating of row and column switches, the current is accumulated and sampled in the analog domain, and high-efficiency matrix multiplication operation is realized.
[0091] Since the CIM device adopts DAC (Digital to Analog Converter) and ADC (Analog to Digital Converter) for data acquisition and quantization, only linear calculation data can be represented, and therefore the CIM device cannot be compatible with floating-point number format data (such as FP32), and usually adopts integer data for calculation (such as INT8), and scaling of the data is generated. Taking the INT8 and FP32 data types as examples, for a neural network or a task type requiring FP calculation result, the INT8 result obtained by the CIM calculation needs to be converted into the FP32 result. This process will involve additional circuit overhead, energy consumption overhead and delay overhead.
[0092] In the related art, INT data calculated by a CIM device is transmitted to a peripheral digital circuit such as a CPU, and then multiplied by a corresponding scaling factor to restore the INT data (such as INT8, INT16) to FP data (such as FP16, FP32, or FP64). This process usually requires the use of an FP16, FP32, or FP64 multiplier to multiply the INT data with the FP scaling data to obtain the restored FP data. This process occupies a large amount of hardware resources and energy consumption, and has high latency.
[0093] To solve the above technical problems, as shown in Figure 6 The storage-computing integrated device 1000 according to an embodiment of the present application includes the data conversion circuit 100 described above.
[0094] For example, the data conversion circuit 100 is designed in combination with the INT8 data type commonly used in a CIM computing array and another FP32 data type commonly used in a digital circuit. Compared with a conventional FP32 multiplier, 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 latency overhead of the circuit. At the same time, since the 7-bit target effective mantissa and the 7-bit data in the INT8 have the same resolution, the calculation accuracy can be effectively guaranteed without loss, and the accuracy is consistent with that of the INT8 itself.
[0095] According to the storage-computing integrated device according to an embodiment of the present application, based on the data conversion circuit described above, the data conversion calculation amount is greatly reduced, the calculation amount is greatly reduced, and the occupation of hardware resources and energy consumption are reduced.
[0096] It is to be appreciated that the above description and the examples that follow are intended to be illustrative only and that changes can be made to the description, as represented by the above listed elements, by the steps recited in the flow charts, and by the examples that follow, without departing from the spirit of the application. Accordingly, the scope of the present application is intended to be defined only by the appended claims.
[0097] It should be understood that aspects of the application can be implemented in hardware, software, firmware or a combination thereof. In the above embodiments, various steps or methods can be implemented in software or firmware that is stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any of the following techniques, which are well known in the art of hardware implementation, can be used: a hybrid of the above techniques, a mixture of two or more of the above techniques, or a combination of the above techniques with other techniques not listed above.
[0098] In the description of the present application, the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" are intended to mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. The illustrative appearances of the above-mentioned terms in various places in the specification are not intended to exclude that the terms in the specification can refer to the same or similar features, structures, materials, or characteristics. Furthermore, it is to be understood that the particular feature, structure, material, or characteristic can be combined in any one or more embodiments or examples.
[0099] In addition, the terms "first", "second", etc. are used only for the purpose of description, and should not be understood as indicating or implying relative importance or implying a number of the technical features indicated. Therefore, the features defined as "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present application, the meaning of "a plurality of" is at least two, for example, two, three, etc., unless otherwise explicitly specified and limited.
[0100] In the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connecting", "connecting", "fixing" and the like should be understood broadly, for example, it can be fixedly connected, or it can be detachably connected, or it can be integrated; it can be mechanically connected, or it can be electrically connected; it can be directly connected, or it can be indirectly connected through an intermediate medium; it can be the internal communication of two elements or the interaction relationship between two elements, unless otherwise explicitly limited. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0101] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application, and those skilled in the art can make changes, modifications, replacements and variations to the above embodiments within the scope of the present application.
Claims
1. A data conversion method, characterized in that: The method comprises: Get the integer data to be converted and the 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 a valid mantissa of the target scaling factor; performing 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 significant mantissa of the target scaling factor to obtain target floating-point data corresponding to the to-be-converted integer data; The step of 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 includes: determining a 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 a valid mantissa of the target scaling factor; 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; Determining an 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; 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.
2. The data conversion method according to claim 1, wherein: 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 exclusive OR 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 exclusive OR 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.
3. The data conversion method according to claim 1, wherein: 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 coefficient and the data of the integer data to be converted comprises: Filling the high-order bits of the effective mantissa of the target scaling coefficient with one to obtain a 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 significant mantissa and the data of the to-be-converted integer data to obtain first data, and determining the decimal point shift amount and the significant mantissa of the target floating-point data corresponding to the to-be-converted integer data 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.
4. The data conversion method according to claim 1, wherein: The determining, based on the exponent of the target scaling factor and the decimal point shift amount, the exponent of the target floating-point data corresponding to the integer data to be converted comprises: 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.
5. 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 to 4 is implemented.
6. 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; A conversion module is configured 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 target floating-point data corresponding to the integer data to be converted; wherein, The preprocessing module is specifically used for: determining a 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 a valid mantissa of the target scaling factor; The conversion module 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; 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; Determining an 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; 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.
7. 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; a data conversion unit, configured 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, so as to obtain target floating-point data corresponding to the to-be-converted integer data; Wherein, the pre-processing unit includes: a rounding processing module, configured to determine a 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 a valid mantissa of the target scaling factor; The data conversion unit includes: an XOR module, configured to perform 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; a one-padding processing module, configured to pad the high-order 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; a multiplier, configured to obtain a product of the target significant mantissa and the integer data to be converted to obtain first data; a leading zero counter, configured to determine, based on the number of leading zeros in the first data, a decimal point shift amount and a valid mantissa of the target floating-point data corresponding to the integer data to be converted; an adder, configured to obtain a sum of an exponent of the target scaling factor and the decimal point shift quantity, and obtain an exponent of the target floating-point data corresponding to the integer data to be converted; a padding processing module, configured 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 pad 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.
8. A storage and computing integrated device, characterized in that: Comprising the data conversion circuit according to claim 7.
Citation Information
Patent Citations
Data processing method and device, processor, electronic equipment and storage medium
CN118312130A
Preparation and execution of quantized scaling on integrated circuitry
US11188300B1