Computing apparatus and method, electronic device, and storage medium

By format conversion of the input parameters in the computing device, it supports multiplication and accumulation calculations of multiple floating point precision types, solving the problem that the existing technology cannot support BF16 and FP32 type operations, and improving the computing efficiency of AI accelerators and other equipment. and resource utilization.

WO2024212952A1PCT designated stage expired Publication Date: 2024-10-17BEIJING YOUZHUJU NETWORK TECH CO LTD +1

Patent Information

Application Number
PCT/CN2024/086776
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-11
Filing Date
2024-04-09
Publication Date
2024-10-17

AI Technical Summary

Technical Problem

Existing deep learning accelerators cannot support BF16 and FP32 type multiply-accumulate operations, resulting in poor computing efficiency and resource utilization in the fields of artificial intelligence and deep learning.

Method used

A computing device is designed, which uses the preprocessing module to convert input parameters into formats and convert floating-point numbers of different precision types into a unified format, so that it can reuse the multiplication calculation logic of the mantissa part and support multiple floating-point precision types. Multiply and accumulate calculations.

Benefits of technology

It implements multiplication-accumulation calculations in multiple precision formats on AI accelerators and other devices, saving hardware resources, improving computing performance, and reducing area and power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024086776_17102024_PF_FP_ABST
    Figure CN2024086776_17102024_PF_FP_ABST
Patent Text Reader

Abstract

A computing apparatus and method, an electronic device, and a storage medium. The computing apparatus comprises: a preprocessing module, configured for: receiving N pairs of input parameters, converting the format of each pair of input parameters in accordance with precision types of the N pairs of input parameters, and obtaining N pairs of converted processed input parameters; and an operation module, configured for: respectively calculating the product of an index part and a mantissa part of each pair of processed input parameters, and on the basis of said product, obtaining an output result; wherein the computing apparatus supports multiply and accumulation calculations of various floating-point number precision types. The computing apparatus can reuse a mantissa-part multiplication calculation and reuse a related hardware circuit structure, thereby saving hardware resources, reducing size and power consumption costs so as to allow the computing apparatus to support multiply and accumulation calculations of various precision types, and improving the performance of an electronic device utilizing the computing apparatus, such as an AI accelerator.
Need to check novelty before this filing date? Find Prior Art

Description

Computing device and method, electronic device and storage medium

[0001] This application claims priority to Chinese Patent Application No. 202310382667.1 filed on April 11, 2023, the entire text of which is incorporated by reference as a part of this application. Technical Field

[0002] Embodiments of the present disclosure relate to a computing device, a computing method, an electronic device, and a non-transitory computer-readable storage medium. Background Art

[0003] With the development of artificial intelligence and machine learning, new requirements have been put forward for many parallel processor devices represented by parallel processors (e.g., multi-core processors, digital signal processors, etc.). The computing operations of parallel processors can include general matrix multiplication (GEMM) or convolution multiplication operations. For example, in neural network processing frequently used in fields such as artificial intelligence, such as convolutional neural networks, it is often necessary to perform matrix multiplication and accumulation (MACC) calculations. The matrix multiplication and accumulation calculation includes multiplying the elements of corresponding positions in two matrices, and then accumulating the multiplication results to obtain a calculation result.

[0004] Summary of the Invention

[0005] This summary section is provided to briefly introduce concepts that will be described in detail in the detailed description section below. This summary section is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0006] At least one embodiment of the present disclosure provides a computing device, including: a preprocessing module, configured to: receive N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, N is a positive integer, and format conversion is performed on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of processed input parameters after conversion, wherein, during the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of the mantissa of the input parameter is expanded to a first value, and the exponent information of the input parameter is added. The processing module comprises: a first floating-point number inputting a mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; and a calculation module, configured to: respectively calculate the product of the exponent part and the mantissa part of each pair of processed input parameters, and obtain an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of N product results corresponding to the N pairs of input parameters in a one-to-one manner; wherein the calculation device supports multiplication and accumulation calculations of multiple floating-point number precision types.

[0007] At least one embodiment of the present disclosure provides a calculation method, comprising: receiving N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, N is a positive integer, performing format conversion on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of converted processed input parameters, wherein, during the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of a mantissa part of the input parameter is expanded to a first value, and exponent information of the input parameter is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; respectively calculating the product of the exponent part and the mantissa part of each pair of processed input parameters, and obtaining an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of the N product results corresponding to the N pairs of input parameters.

[0008] At least one embodiment of the present disclosure provides an electronic device, including: the computing device described in any embodiment of the present disclosure.

[0009] At least one embodiment of the present disclosure provides an electronic device, comprising: a memory, which non-transitorily stores computer-executable instructions; and a processor, configured to execute the computer-executable instructions, wherein the computer-executable instructions, when executed by the processor, implement the computing method according to any embodiment of the present disclosure.

[0010] At least one embodiment of the present disclosure provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the computing method according to any embodiment of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, rather than limiting the present disclosure.

[0012] FIG1 is a schematic block diagram of a computing device according to at least one embodiment of the present disclosure;

[0013] FIG2A is a schematic diagram of a format conversion process according to an embodiment of the present disclosure;

[0014] FIG2B is a schematic diagram of a format conversion process provided by another embodiment of the present disclosure;

[0015] FIG3 is a structural diagram of an index calculation unit provided by at least one embodiment of the present disclosure;

[0016] FIG4 is a schematic block diagram of a first-level unit provided by at least one embodiment of the present disclosure;

[0017] FIG5A is a schematic structural diagram of a first multiplication unit provided in at least one embodiment of the present disclosure.

[0018] FIG5B is a schematic structural diagram of a second multiplication unit provided in at least one embodiment of the present disclosure;

[0019] FIG6 is a schematic diagram of a compression process of a second-stage unit according to at least one embodiment of the present disclosure;

[0020] FIG7 is a schematic flow chart of a calculation method provided by at least one embodiment of the present disclosure;

[0021] FIG8 is a schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure;

[0022] FIG9 is a schematic block diagram of another electronic device provided by at least one embodiment of the present disclosure;

[0023] FIG10 is a schematic diagram of a non-transitory computer-readable storage medium provided by at least one embodiment of the present disclosure. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0025] Unless otherwise defined, the technical or scientific terms used in this disclosure should have the usual meanings understood by people with ordinary skills in the field to which this disclosure belongs. The "first", "second" and similar words used in this disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly. In order to keep the following description of the embodiments of the present disclosure clear and concise, the present disclosure omits detailed descriptions of some known functions and known components.

[0026] Floating point numbers (FP) are mainly used to represent decimals and usually consist of three parts: the sign bit, the exponent part, and the mantissa part. The exponent part can also be called the exponent part. For example, a floating point number V can usually be expressed as follows: V = (-1) s ×M×2 E

[0027] Among them, the sign bit s can be 1 bit, which determines whether the floating-point number V is negative or positive; M represents the mantissa part, which can include multiple bits, which is a binary decimal form and defines the precision of the floating-point number; E represents the exponent (also called the exponent value), which is used to weight the floating-point number, reflects the position of the decimal point in the floating-point number V, and defines the value range of the floating-point number.

[0028] For example, traditional floating-point numbers generally include three formats, namely, half-precision floating-point numbers (FP16), single-precision floating-point numbers (FP32), and double-precision floating-point numbers (FP64), and their exponent parts and mantissa parts have different numbers of bits.

[0029] AI accelerators and other devices are already widely used in deep learning model training. For convolution operations, common in deep learning models, special optimizations have been made in both software and hardware design to accelerate computation. For example, some AI accelerator vendors offer specialized data processing devices to optimize computation. For example, the Deep Learning Accelerator (DLA) provides hardware acceleration for convolutional neural networks; NVDLA utilizes a convolution pipeline in its Convolution Core engine to efficiently support parallel direct convolution operations.

[0030] For example, the data processing device taking DLA as an example supports a variety of computing processes, such as conventional numerical operations, matrix multiplication, convolution multiplication, etc. In addition, the data processing device has optimized and developed a variety of floating-point data formats for fields such as artificial intelligence / deep learning, such as BF16 (brain floating point 16, bit width is 16 bits), TF32 (Tensor Float 32, bit width is 19 bits), etc. These data formats can greatly reduce computing processes, especially the computing resources and power consumption required for matrix multiplication or convolution multiplication operations. In addition, the data processing device also supports some conventional floating-point types, such as half-precision floating point numbers (FP16, bit width is 16 bits) or double-precision floating point numbers (FP64, bit width is 64 bits), etc.

[0031] Table 1 shows the data formats of several floating-point precision types.

[0032] Table 1 Data format

[0033] As shown in Table 1, for the floating-point precision type FP32, the total number of bits is 32 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 8 bits, the mantissa part includes 23 bits, and the number of significant mantissa bits is 23+1=24 bits. For FP16, the total number of bits is 16 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 5 bits, the mantissa part includes 10 bits, and the number of significant mantissa bits is 10+1=11 bits. For BF16, the total number of bits is 16 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 8 bits, the mantissa part includes 7 bits, and the number of significant mantissa bits is 7+1=8 bits.

[0034] In order to represent the maximum number of significant digits in the mantissa and to ensure that floating-point numbers have a fixed representation, the encoding of floating-point numbers should adopt certain specifications, stipulating that the mantissa is given as a pure decimal, and the absolute value of the mantissa should be greater than or equal to 1 / R (usually 2) and less than or equal to 1, that is, the first digit after the decimal point is not zero. Floating-point numbers that do not meet this requirement can be made to meet this requirement by modifying the exponent and moving the mantissa at the same time. Therefore, for normalized floating-point numbers, the highest bit of its mantissa is 1, and the number of significant digits in its mantissa is the number of digits in the mantissa plus 1. For example, for a single-precision floating-point number, its mantissa includes 23 bits, its mantissa significant digits are 24 bits, and the highest bit is 1.

[0035] For common multiplication and accumulation operations in computing operations, for example, calculating the multiplication results of multiple pairs of input parameters and accumulating these multiplication results, the multiplication result of each pair of input parameters is the product of the two input parameters included in the pair of input parameters. Due to the different data formats of different floating-point numbers, as shown in Table 1, the total bit width, exponent bit width, and mantissa bit width of floating-point numbers of different precisions are all different. Therefore, the computing device used to perform multiplication and accumulation operations cannot universally support calculation operations of floating-point numbers of multiple different precision types; and with the evolution of deep learning algorithms, BF16 and FP32 have become the more mainstream precision types of algorithms in the reasoning and training process, while current deep learning accelerators and the like cannot support BF16 and FP32 types of multiplication and accumulation operations.

[0036] At least one embodiment of the present disclosure provides a computing device, a computing method, an electronic device, and a non-transitory computer-readable storage medium.

[0037] The computing device includes: a preprocessing module configured to: receive N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, N is a positive integer, and format each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of converted processed input parameters, wherein, during the conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of the mantissa part of the input parameter is expanded to a first value, and the exponent information of the input parameter is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; and an operation module configured to: respectively calculate the product of the exponent part and the mantissa part of each pair of processed input parameters, and obtain an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of the N product results corresponding to the N pairs of input parameters one by one; wherein the computing device supports multiplication and accumulation calculations of multiple floating-point number precision types.

[0038] In at least one embodiment, the computing device first performs format conversion on the input parameters through a preprocessing module, and expands the number of significant digits of the mantissa part of the input parameters whose significant digits of the mantissa part are less than the first value to the first value, so that the mantissa parts of all floating-point type input parameters whose significant digits of the mantissa part are less than the first value are processed into the same number of digits, thereby making it possible to reuse the multiplication calculation of the mantissa part and reuse the relevant hardware circuit structure, save hardware resources, and enable the computing device to support multiplication and accumulation calculations in multiple precision formats at a lower area and power consumption cost, thereby improving the performance of electronic devices using the computing device, such as AI accelerators.

[0039] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings, but the present disclosure is not limited to these specific embodiments.

[0040] FIG1 is a schematic block diagram of a computing device provided by at least one embodiment of the present disclosure.

[0041] As shown in FIG1 , the computing device 100 includes a pre-processing module 101 and a computing module 102 .

[0042] The preprocessing module 101 is configured to receive N pairs of input parameters, and perform format conversion on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of converted processed input parameters, where N is a positive integer.

[0043] The operation module 102 is configured to calculate the product of the exponent part and the mantissa part of each pair of processed input parameters, and to obtain an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters. For example, the output result is the cumulative sum of N product results corresponding to N pairs of input parameters.

[0044] For example, each pair of input parameters in the N pairs of input parameters may include two input parameters, and the N pairs of input parameters have the same precision type. For example, the product result corresponding to a pair of input parameters is the product of the two input parameters included in the pair of input parameters.

[0045] For example, N pairs of input parameters may include N first input parameters and N second input parameters, the first input parameter may be a weight, and the second input parameter may be input data. For example, in a convolutional neural network, the first input parameter may be the weight value of each convolution layer, and the second input parameter may be the input data input into each convolution layer.

[0046] For example, N can be determined based on the data line width and the precision type of the input parameter. Taking the data line width as 1024 bits as an example, when the precision type of the input parameter is INT8 (8-bit integer), N is a maximum of 128, that is, the computing device supports up to 128 pairs of INT8 input parameters for multiplication and accumulation calculations at the same time; when the precision type of the input parameter is FP16 or BF16 (16-bit floating point number), N is a maximum of 64, that is, the computing device supports up to 64 pairs of FP16 input parameters for multiplication and accumulation calculations at the same time; when the precision type of the input parameter is FP32 (32-bit floating point number), N is a maximum of 32, that is, the computing device supports up to 32 pairs of FP32 input parameters for multiplication and accumulation calculations at the same time. It is understandable that those skilled in the art can select the specific value of N according to actual needs.

[0047] For example, in some embodiments, a plurality of operation modules 102, such as 8 operation modules, may be set in parallel in the computing device. Each operation module 102 may simultaneously complete the multiplication and accumulation calculations of its own N pairs of input parameters. For example, the first input parameters input to each operation module 102 are different, and the second input parameters are the same. When the computing device receives the first input parameter, it caches it in a register (such as a shadow register) until all the first input parameters required to perform a calculation operation are obtained, and then it is assigned to the corresponding operation module; when the computing device receives the second input parameter, it broadcasts it to all operation modules, and each operation module performs the operation in parallel, and simultaneously completes and outputs the output results of the multiplication and accumulation calculations of its own N pairs of input parameters.

[0048] For example, during the format conversion process, for each input parameter whose precision type is the first floating-point type, the number of significant digits of the mantissa part of the input parameter is expanded to the first value, and the exponent information of the input parameter is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point type is less than or equal to the first value.

[0049] In this embodiment, the mantissa parts of input parameters of the first floating-point type whose number of significant digits of the mantissa part of the input parameter is less than or equal to the first value are all expanded to the first value, so that even if the types of the input parameters are different, the number of significant digits of the mantissa parts of the corresponding processed input parameters are the same, so that the same mantissa multiplication operation logic can be reused, the relevant hardware circuit structure can be reused, hardware resources can be saved, and the computing device can support multiplication and accumulation calculations in multiple precision formats at a lower area and power consumption cost, thereby improving the performance of electronic devices using the computing device, such as AI accelerators.

[0050] For example, when the preprocessing module 101 performs format conversion on each pair of input parameters according to the precision type of N pairs of input parameters, it includes the following operations: for each input parameter, in response to the precision type of the input parameter being the first floating-point type: discarding the lowest m bits of the exponent part of the input parameter, where m is a positive integer, performing a padding operation on the mantissa part of the input parameter, shifting the padded mantissa part by the value indicated by m bits to expand the number of valid digits of the mantissa part of the input parameter to the first value, and obtaining the processed input parameter corresponding to the input parameter.

[0051] For example, in some embodiments, the first value is 15, and the first floating-point number type may include BF16 and FP16. As shown in Table 1, the number of significant digits of the mantissa part thereof is different and both are less than the first value 15. Through format conversion, the number of significant digits of the mantissa part of the input parameter of type BF16 or FP16 is expanded to 15 bits, so that for the input parameters of type BF16 or FP16, the same hardware structure can be used to complete the product operation of the mantissa part.

[0052] Of course, the present disclosure is not limited thereto. Depending on the floating-point type of the input parameter to be processed, the first value and the range of the first floating-point type can be set as needed, and the present disclosure does not impose any specific restrictions on this.

[0053] For example, the padding operation includes adding a 1 before the most significant bit of the mantissa of the input parameter.

[0054] For normalized floating-point numbers, the highest bit of the mantissa is always 1, so in order to express the maximum number of significant digits in the mantissa, it is usually hidden, also called a hidden bit.

[0055] For example, for a normalized floating-point number, at least the hidden bit of the mantissa is filled in the padding operation, that is, a 1 is added before the highest bit of the mantissa of the input parameter.

[0056] For example, for denormalized floating-point numbers, a 0 may be added before the highest bit of the mantissa of the input parameter during the padding operation.

[0057] Of course, according to the number of bits required, if only the value indicated by shifting the mantissa part by m bits after padding the hidden bit cannot expand the mantissa part to the first value, the padding operation may also include continuing to pad at least one 0 in the higher bits of the hidden bit after padding the hidden bit until the mantissa part after performing the padding operation can be expanded to the first value after shifting the mantissa part by m bits.

[0058] Figure 2A is a schematic diagram of a format conversion process according to one embodiment of the present disclosure, and Figure 2B is a schematic diagram of a format conversion process according to another embodiment of the present disclosure. For example, Figure 2A illustrates the specific process of format conversion performed by the preprocessing module 101 on an FP16 type input parameter, and Figure 2B illustrates the specific process of format conversion performed by the preprocessing module 101 on a BF16 type input parameter.

[0059] 2A and 2B , the processing flow of the preprocessing module 101 provided in at least one embodiment of the present disclosure will be described in detail.

[0060] As shown in FIG2A , for an input parameter of FP16 type, the total number of bits is 16 bits, including 1 sign bit (the 15th bit in FIG2A ), the exponent part (i.e., the exponent code) includes 5 bits (the 10th to the 14th bits in FIG2A ), and the mantissa part includes 10 bits (the 0th to the 9th bits in FIG2A ).

[0061] During the format conversion process, the lowest two bits of the exponent of the input parameter are discarded. That is, for FP16, m = 2. In the processed input parameter, the three bits of the exponent are bits 12 to 14 of the original input parameter, thus compressing the exponent from 5 bits to 3 bits, saving logic for exponent processing.

[0062] For the mantissa part, as shown in the padding operation in Figure 2A, the hidden bits are first padded, and 1 is padded before the highest bit (9th bit) of the mantissa part of the input parameter, that is, 1 is padded to the 10th bit as shown in Figure 2A; and further, a 0 is padded before the padded hidden bit, and 0 is padded to the 11th bit as shown in Figure 2A, thereby obtaining the padded mantissa part. After the padding operation, the mantissa part is expanded to 12 bits.

[0063] Afterwards, the padded mantissa is shifted by the value indicated by the lowest two bits of the exponent part of the input parameter, up to three bits (the lowest two bits of the exponent part of the input parameter are "11" at this time), so that the input parameter can be expanded to 15 bits after processing. For example, if the two lowest-order bits of the exponent of the input parameter are "00", it indicates a shift of 0 bits, that is, after processing, the lower 12 bits of the mantissa of the input parameter are the padded mantissa, and the upper three bits are 0; if the two lowest-order bits of the exponent of the input parameter are "01", it indicates a shift of 1 bit, that is, after processing, the 1st to 12th bits of the mantissa of the input parameter are the padded mantissa, and the 13th, 14th, and 0th bits are 0; if the two lowest-order bits of the exponent of the input parameter are "10", it indicates a shift of 2 bits, that is, after processing, the 2nd to 13th bits of the mantissa of the input parameter are the padded mantissa, and the 14th, 0th, and 1st bits are 0; if the two lowest-order bits of the exponent of the input parameter are "11", it indicates a shift of 3 bits, that is, after processing, the 3rd to 14th bits of the mantissa of the input parameter are the padded mantissa, and the lower three bits are 0.

[0064] As shown in FIG2B , for a BF16 type input parameter, the total number of bits is 16 bits, including 1 sign bit (the 15th bit in FIG2B ), the exponent part (i.e., the exponent code) includes 8 bits (the 7th to the 14th bits in FIG2B ), and the mantissa part includes 7 bits (the 0th to the 6th bits in FIG2B ).

[0065] During the format conversion process, the lowest 3 bits of the exponent of the input parameter are discarded. That is, for BF16, m = 3. In the processed input parameter, the 5 bits of the exponent are bits 10 to 14 of the original input parameter, thus compressing the exponent from 8 bits to 5 bits, saving logic for exponent processing.

[0066] For the mantissa part, as shown in the padding operation in Figure 2A, the hidden bits are first padded, and 1 is padded before the highest bit (6th bit) of the mantissa part of the input parameter. As shown in Figure 2B, 1 is padded to the 7th bit, thereby obtaining the padded mantissa part. After the padding operation, the mantissa is expanded to 8 bits.

[0067] Afterwards, the padded mantissa is shifted by the value indicated by the lowest 3 bits of the exponent part of the input parameter, with a maximum shift of 7 bits (at this time, the lowest 3 bits of the exponent part of the input parameter are "111"), so that the input parameter can be expanded to 15 bits after processing. For example, if the lowest 3 bits of the exponent part of the input parameter are "101", it means a shift of 5 bits, that is, after processing, the mantissa part of the input parameter, the 5th to 12th bits are the padded mantissa part, and the 13th and 14th bits and the 0th to 4th bits are all 0; if the lowest 3 bits of the exponent part of the input parameter are "111", it means a shift of 7 bits, that is, after processing, the mantissa part of the input parameter, the 7th to 14th bits are the padded mantissa part, and the lower 7 bits are 0. The case where the lowest 3 bits of the exponent part of the input parameter are other values ​​is similar to the above process, and the repeated parts are not repeated.

[0068] It should be noted that since the sign bit also participates in the multiplication operation of the mantissa, the sign bit is set before the highest bit of the mantissa in the processed input parameter, that is, the 15th bit. In the following text, for FP16 and BF16, the mantissa part involved in the operation is 16 bits, including 15 bits of mantissa and 1 bit of sign.

[0069] For example, in the above embodiment, the lowest m bits of the exponent part of the input parameter are discarded to reduce the bit width of the exponent part and effectively simplify the operation logic of the exponent part; the padded mantissa part is shifted by the value indicated by m bits to add the exponent information of the input parameter to the mantissa part of the input parameter, reducing the impact on the accuracy of the calculation result; and, the preprocessing of the precision of the floating-point number can fully reuse the operation logic and hardware resources of the multiplication part. The above preprocessing can be performed on the input parameters of the first floating-point number type. The number of bits of the mantissa part of the input parameter after preprocessing is the same, and the same data processing path can be fully reused, thereby greatly saving hardware resources, minimizing the consumption of hardware resources, and enabling the computing device to support multiplication and accumulation calculations in multiple precision formats at a lower cost of area and power consumption.

[0070] For example, in response to the precision type of the input parameter being the second floating-point type, since the number of significant digits of the mantissa part of the input parameter is greater than the first value, the exponent part of the input parameter of the second floating-point type may not be subjected to the above-mentioned format conversion, and a hidden bit 1 is added before the highest bit of the mantissa part of the input parameter of the second floating-point type, thereby obtaining the processed input parameter corresponding to the input parameter of the second floating-point type.

[0071] For example, the second floating-point number type may include FP32, as shown in Table 1, the total number of bits is 32 bits, including 1 sign bit, the exponent part (i.e., the exponent code) includes 8 bits, the mantissa part includes 23 bits, and the number of significant mantissa bits is 23+1=24 bits. When performing a multiplication operation on the mantissa part, the mantissa part is 25 bits, including 1 sign bit, 1 padded hidden bit, and 23 bits of the original input parameter. For FP32, the exponent part is not specially processed in the preprocessing module, and the mantissa part is padded with hidden bits to obtain the processed input parameter and input it into the operation module 102.

[0072] As shown in FIG. 1 , the operation module 102 includes an exponent calculation unit 1021 and a mantissa calculation unit 1022 .

[0073] For example, the exponent calculation unit 1021 is configured to perform an operation on the exponent portion of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters. For example, the exponent shift value indicates the difference between the product result of the exponent portion of each pair of processed input parameters and a maximum exponent value, where the maximum exponent value is the maximum value among the product results of the exponent portions of N pairs of processed input parameters. For example, the exponent shift value is used to shift the mantissa product results so that the exponent values ​​of the product results of the N pairs of processed input parameters are the same, that is, all have the maximum exponent value, so that accumulation calculations can be performed directly without considering the different exponents.

[0074] For example, the mantissa calculation unit 1022 is configured to perform a multiplication operation on the mantissa part of each pair of processed input parameters in combination with the exponent shift value corresponding to each pair of processed input parameters to obtain an output result.

[0075] For example, the exponential calculation unit 1021 includes a first subunit, a second subunit, and an output subunit.

[0076] For example, the first subunit is configured to: parallelly calculate the sum of the exponential parts of N1 pairs of processed input parameters to obtain N1 exponential calculation results, and determine the maximum value of the N1 exponential calculation results as the first maximum value. For example, the N1 pairs of processed input parameters are obtained by formatting N1 pairs of input parameters of the first floating-point type, and each exponential calculation result is the sum of the exponential parts of the two processed input parameters included in each pair of processed input parameters. That is, in the present disclosure, when performing a multiplication calculation of the input parameters, the product of the exponential parts is actually the sum of the exponential parts, and the sum result is used as the exponential calculation result, that is, the product result of the exponential parts.

[0077] For example, the second subunit is configured to: calculate in parallel the sum of the exponential parts of N2 pairs of processed input parameters to obtain N2 exponential calculation results, and determine the maximum value of the N2 exponential calculation results as the second maximum value, wherein N1 and N2 are positive integers and N1+N2 equals N; or calculate in parallel the sum of the exponential parts of N pairs of processed input parameters to obtain N exponential calculation results, and determine the maximum value of the N exponential calculation results as the second maximum value. For example, the N2 pairs of processed input parameters are obtained by formatting the N2 pairs of input parameters of the first floating-point type.

[0078] For example, the output subunit is configured to: determine the larger value between the first maximum value and the second maximum value as the maximum exponent value; and calculate the difference between the product result of the exponential part of each pair of processed input parameters and the maximum exponent value to obtain the exponent shift value corresponding to each pair of processed input parameters.

[0079] For example, specific values ​​of N1 and N2 can be specified according to actual needs. For example, in one example, N1=N2=N / 2.

[0080] For example, if the processed input parameter is obtained by format conversion of the input parameter of the first floating-point type, the first subunit can simultaneously process the exponential partial products of N1 pairs of processed input parameters, and the second subunit can simultaneously process the exponential partial products of N2 pairs of processed input parameters, thereby simultaneously calculating the exponential partial products of N pairs of processed input parameters.

[0081] For example, if the processed input parameter is obtained by format conversion of the input parameter of the second floating point type, the second sub-unit simultaneously processes the exponential partial products of the N pairs of processed input parameters.

[0082] Thus, the computing device can simultaneously support the exponential calculation of input parameters of multiple floating-point types, and reuse as many hardware operation logics as possible, such as adders.

[0083] FIG3 is a structural diagram of an index calculation unit provided by at least one embodiment of the present disclosure.

[0084] As shown in FIG3 , the exponential calculation unit includes a first subunit, a second subunit, and an output subunit.

[0085] In Figure 3, a pair of processed input parameters includes a first processed input parameter and a second processed input parameter, N1 first exponents and N1 second exponents are the exponent parts of the processed input parameters obtained after format conversion of N1 pairs of input parameters of the first floating-point type, N2 first exponents and N2 second exponents are the exponent parts of the processed input parameters obtained after format conversion of N2 pairs of input parameters of the first floating-point type; the N first exponents and N second exponents in Figure 3 are the exponent parts of the processed input parameters obtained after format conversion of N pairs of input parameters of the second floating-point type.

[0086] For example, if the first floating-point number type includes BF16 and FP16, the second floating-point number type includes FP32, and the data line width is 1024 bits, then in Figure 3, N1=N2=N=32, indicating that the exponent calculation unit can simultaneously perform 64 operations on the exponential part of the input parameters of BF16 and FP16, or simultaneously perform 32 operations on the exponential part of the input parameters of FP32. It should be noted that when the types of input parameters are different, the specific values ​​of N1, N2 and N are also different. For the input parameters of BF16 and FP16, N is still the sum of N1 and N2, that is, 64, but for the input parameters of FP32, N=32, N1=N2=0, and in Figure 3, N1, N2 and N correspond to different types of floating-point numbers. For N1, N2 and N themselves in Figure 3, the relationship N1+N2=N is not satisfied.

[0087] For example, as shown in FIG3 , the first subunit includes N1 adders and a first comparator. The N1 adders are configured to concurrently calculate N1 sums of the exponential portions of the processed input parameters and output N1 exponential calculation results. The first comparator is configured to determine a maximum value among the N1 exponential calculation results as a first maximum value.

[0088] For example, as shown in FIG3 , the second subunit includes two multiplexers, N2 or N adders and a second comparator.

[0089] Two multiplexers are used to select one of the input parameters to be output to the adder based on the floating-point number type tag. For example, the floating-point number type tag includes a first tag (e.g., 0) indicating a first floating-point number type and a second tag (e.g., 1) indicating a second floating-point number type. If the floating-point number type tag is the first tag, both multiplexers select the 0-way output, thereby outputting N2 first exponents and N2 second exponents to the adder. If the floating-point number type tag is the second tag, both multiplexers select the 1-way output, thereby outputting N first exponents and N second exponents to the adder.

[0090] N2 adders are used to parallelly calculate the sum of the exponential parts of N2 pairs of processed input parameters, and output N2 exponential calculation results, where the N2 pairs of processed input parameters are obtained by formatting N2 pairs of input parameters of the first floating-point number type; or, N adders are used to parallelly calculate the sum of the exponential parts of N pairs of processed input parameters, and output N exponential calculation results, where the N pairs of processed input parameters are obtained by formatting N pairs of input parameters of the second floating-point number type.

[0091] The second comparator is used to determine the maximum value among the N2 or N exponential calculation results as the second maximum value.

[0092] The output subunit includes a third comparator and a plurality of subtractors.

[0093] The third comparator is used to determine the larger value of the first maximum value and the second maximum value as the maximum order value.

[0094] For example, if the input parameter is FP16 or BF16, it is divided into two paths through the first subunit and the second subunit, and the two paths each calculate the sum of the exponential parts of 32 pairs of processed input parameters to obtain 64 exponential calculation results at the same time, and then the maximum value of the 64 exponential calculation results is selected as the maximum exponent value through the third comparator.

[0095] For example, if the input parameter FP32, the output result of the first sub-unit is empty, that is, the first maximum value is empty, and the maximum value of the 32 exponent calculation results calculated by the second sub-unit is used as the maximum exponent value, that is, the maximum exponent value is the second maximum value.

[0096] The subtractor is used to calculate the difference between each exponential calculation result and the maximum exponent value, thereby obtaining the exponent shift value corresponding to each pair of processed input parameters.

[0097] For example, the data bit width processed by the first subunit is determined based on the largest number of significant digits in the exponent part of the processed input parameter corresponding to the input parameter of the first floating-point type. For example, the data bit width processed by the second subunit is determined based on the largest number of significant digits in the exponent part of the processed input parameter corresponding to the input parameter of the second floating-point type.

[0098] For example, taking the case where the first floating-point number type includes BF16 and FP16, and the second floating-point number type includes FP32, the data bit width processed by the first sub-unit is 6 bits. This is because the exponent part of BF16 has a bit width of 5 bits after preprocessing, and the exponent part product corresponding to two BF16 input parameters is 6 bits. The exponent part of FP16 has a bit width of 3 bits after preprocessing, and the exponent part product corresponding to two FP16 input parameters is 4 bits. To be able to simultaneously process BF16 and FP16 type input parameters, the largest number of exponent part significant digits is selected from the two to determine the data bit width processed by the first sub-unit, that is, the data bit width processed by the first sub-unit is determined to be 6 bits. Similarly, the data bit width processed by the second sub-unit is 9 bits. This is because the exponent part of FP32 has a bit width of 8 bits. To be able to simultaneously process BF16 and FP32 type input parameters, the largest number of exponent part significant digits is selected from the two to determine the data bit width processed by the second sub-unit, that is, the data bit width processed by the second sub-unit is determined to be 9 bits. The exponential calculation unit can also fully reuse circuit logic by adjusting the data bit width supported by hardware resources. For example, for input parameters of the first floating-point type, the exponential part can be calculated by the first subunit and the second subunit without data overflow.

[0099] In this embodiment, the first subunit can complete 32 pairs of exponential multiplications and find the maximum value therein as the first maximum value, and the second subunit can complete 32 pairs of exponential multiplications and find the maximum value therein as the second maximum value. After the output results of the first subunit and the second subunit are merged, the maximum exponent value is found. Thus, the circuit structure supports multiple precision types such as FP16, BF16, FP32, etc., while reducing hardware resources as much as possible and reusing more hardware circuit logic.

[0100] For example, the mantissa calculation unit 1022 includes multiplication units of at least two precision types, and the at least two precision types of multiplication units include a first multiplication unit and a second multiplication unit. The first multiplication unit and the second multiplication unit both support the mantissa part multiplication operation of the processed input parameters corresponding to the input parameters of the first floating-point type. In addition, the second multiplication unit also supports the mantissa part multiplication operation of the processed input parameters corresponding to the input parameters of the second floating-point type.

[0101] For example, the mantissa calculation unit includes a first-level unit, a second-level unit, and a third-level unit.

[0102] The first-level unit is configured to combine the exponent shift value corresponding to each pair of processed input parameters, use multiple multiplication units to parallelly calculate the products of the mantissa parts of N pairs of processed input parameters, and output N groups of intermediate results corresponding to the N pairs of processed input parameters, wherein each group of intermediate results includes two partial products and a sign compensation flag.

[0103] The second-level unit is configured to perform at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result.

[0104] The third-level unit is configured to combine the sign compensation flags and the compression results in the N groups of intermediate results and obtain the output result using an adder.

[0105] FIG4 is a schematic block diagram of a first-level unit provided by at least one embodiment of the present disclosure.

[0106] As shown in FIG4 , the first-stage unit includes a first pre-processing sub-unit, a plurality of first multiplication units, a plurality of second multiplication units, and a second pre-processing sub-unit.

[0107] For example, in order to reuse data paths as much as possible and improve transmission and processing efficiency, when transmitting data between modules, the data bit width can be set according to the input parameter of the second floating-point type, and multiple parameters of the first floating-point type can be spliced ​​so that their bit width can occupy the entire data bit width as much as possible. For example, taking the first floating-point type including FP16 and BF16, and the second floating-point type including FP32 as an example, the data bit width can be set to 32 bits, so that the mantissa part of the input parameter of the second floating-point type for mantissa multiplication calculation has a bit width of 25 bits, and the mantissa part of the input parameter of the first floating-point type has a bit width of 16 bits. The mantissa parts of the two first floating-point type input parameters can be spliced ​​to fully occupy the 32-bit data bit width.

[0108] The first preprocessing subunit is used to split the processed input parameters according to the floating-point number type tag and input them into the corresponding multiplication units. For example, when the floating-point number type tag indicates that the input mantissa portion is obtained by preprocessing the input parameter of the first floating-point number type, the input mantissa portion is split, for example, into two groups and input them into the first multiplication unit and the second multiplication unit respectively; for example, when the floating-point number type tag indicates that the input mantissa portion is obtained by preprocessing the input parameter of the second floating-point number type, the input mantissa portion is input into the corresponding second multiplication unit.

[0109] The plurality of first multiplication units and the plurality of second multiplication units are used to combine the exponent shift value and calculate the product of the mantissa part of the input processed parameter in parallel. The specific structure and calculation process are described below.

[0110] For example, the first floating-point number type includes FP16 and BF16, the second floating-point number type includes FP32, the first multiplication unit is a 16-bit multiplier, and the second multiplication unit is a 24-bit multiplier. Taking a data line width of 1024 bits as an example, the first-level unit can include 32 24-bit multipliers and 32 16-bit multipliers to complete 64 pairs of BF16 / FP16 mantissa multiplication operations in parallel, of which the 32 24-bit multipliers can also complete 32 pairs of FP32 mantissa multiplication operations in parallel.

[0111] The second preprocessing subunit corresponds to the first preprocessing subunit and is used to splice the calculation results of the multiplication unit according to the floating-point type tag. For example, if the floating-point type tag indicates that the mantissa portion of the input is obtained by preprocessing the input parameter of the first floating-point type, the intermediate results output by the multiplication unit are spliced ​​together, for example, every two partial products or every two sign flag bits are spliced ​​together. The specific process is the opposite of the splitting process of the first preprocessing subunit and is not further described here.

[0112] As shown in FIG4 , the second preprocessing subunit outputs the final N groups of intermediate results, each group of intermediate results including two partial products (partial product 1 and partial product 2 in FIG4 ) and a sign compensation flag.

[0113] Due to preprocessing, the significant bits of the mantissa part of the input parameters of BF16 and FP16 are both the first value, so the same calculation path can be reused; in addition, the structure of the 32 24-bit multipliers has been adjusted to support both the mantissa calculation of the first floating-point number type and the mantissa calculation of the second floating-point number type, so that the computing device can support the mantissa multiplication operations of floating-point numbers of different precision types, saving hardware resources on the data path, and maximizing the reuse of multiplier logic. At the cost of lower area and power consumption, it adds support for operations of more precision types, thereby improving the performance of the computing device in performing multiplication and accumulation calculations.

[0114] For example, when the first multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the first floating-point type, it includes performing the following operations: for the i-th pair of processed input parameters, obtaining L partial products corresponding to the i-th pair of processed input parameters through the Booth multiplier, where L is a positive integer; subjecting the L partial products to at least one Wallace tree compression to obtain a first intermediate compression result; shifting the first intermediate compression result according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; shifting the sign compensation reference constant according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0115] For example, each multiplication unit performs a multiplication operation on the mantissa portion of a pair of processed input parameters, so that multiple multiplication units can output the multiplication results of the mantissa portions of all processed input parameters in parallel. Instead of directly outputting the final result, the multiplication unit outputs an intermediate result consisting of two partial products and a sign compensation flag, thereby minimizing the number of adders used for accumulation calculations in the subsequent data path.

[0116] FIG5A is a schematic structural diagram of a first multiplication unit provided in at least one embodiment of the present disclosure.

[0117] For example, the first multiplication unit shown in FIG5A is configured to perform a multiplication operation on the mantissa portion of the i-th pair of processed input parameters, where the i-th pair of processed input parameters is obtained by format conversion of input parameters of a first floating-point type. The i-th pair of processed input parameters includes a first processed input parameter and a second processed input parameter. The first mantissa in FIG5A is the mantissa portion of the first processed input parameter, and the second mantissa is the mantissa portion of the second processed input parameter.

[0118] As shown in FIG5A , first, a Booth multiplier is used to obtain the product of the first mantissa and the second mantissa, ie, L partial products.

[0119] Afterwards, in order to save the number of adders on the subsequent path as much as possible, at least one Wallace tree compression is performed on the L partial products to obtain a first intermediate compression result.

[0120] Thereafter, the first intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters calculated by the exponent calculation unit to obtain partial product 1 and partial product 2. Due to the shifting, the partial products 1 (res_a) and 2 (res_b) obtained from the mantissas of all processed input parameters correspond to the same exponent value (exponent value), i.e., the maximum exponent value, so that direct addition operations can be performed during the summation process without considering the difference in exponents.

[0121] At the same time, the sign compensation reference constant is shifted according to the order shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag, which is used to calculate the sign compensation value when the product results of N pairs of input parameters are added.

[0122] For example, the product result of the first mantissa and the second mantissa can be represented by two partial products (res_a and res_b) in the intermediate result and a sign compensation value obtained based on the sign compensation flag.

[0123] For example, the sign compensation reference constant is related to the type of the processed input parameter. For example, in response to the first floating-point number type being BF16 or FP16, the sign compensation reference constant is 0xF0. Due to preprocessing, some exponent bits of the input parameter are discarded, and the exponent information of the input parameter is added to the mantissa of the input parameter. Therefore, for the processed input parameter, a shift of 1 bit in the exponent part can indicate a shift of multiple bits in the exponent part of the input parameter. A sign compensation parameter with fewer bits can be used to obtain the sign compensation flag, saving hardware resources.

[0124] In a specific example, for example, the first floating-point number type includes BF16 and FP16, and the first multiplication unit is a 16-bit multiplier. When the first multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the BF16 or FP16 input parameter, first, the product result of the first mantissa and the second mantissa is obtained by the Booth multiplier, that is, 10 partial products; then, the 10 partial products are compressed twice by the Wallace tree. In the first compression, the 10 partial products are compressed into 4 intermediate partial products, and in the second compression, the 10 partial products are compressed into 4 intermediate partial products. The four intermediate partial products are compressed again into two intermediate partial products during time compression, and the two intermediate partial products are used as a first intermediate compression result; thereafter, the first intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products (i.e., partial product 1 and partial product 2) in a set of intermediate results corresponding to the i-th pair of processed input parameters; at the same time, the sign compensation reference constant 0xF0 is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag.

[0125] In the above embodiment, using Booth multipliers can reduce the number of partial product terms as much as possible, while using Wallace tree compression can improve the parallelism of partial product addition, thereby improving the computational efficiency as much as possible.

[0126] The second multiplication unit can perform both multiplication operations of the first floating-point number type and multiplication operations of the second floating-point number type.

[0127] For example, when the second multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the second floating-point type, it includes performing the following operations: for the i-th pair of processed input parameters, obtaining L+O partial products corresponding to the i-th pair of processed input parameters through the Booth multiplier, where L and O are both positive integers; subjecting the L partial products to at least one Wallace tree compression to obtain a first intermediate compression result; subjecting the O partial products to at least one Wallace tree compression to obtain a second intermediate compression result; subjecting the first intermediate compression result and the second intermediate compression result to at least one Wallace tree compression to obtain a third intermediate compression result; shifting the third intermediate compression result according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; shifting the sign compensation reference constant according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0128] FIG5B is a schematic structural diagram of a second multiplication unit provided in at least one embodiment of the present disclosure.

[0129] For example, the second multiplication unit shown in FIG5B is configured to perform a multiplication operation on the mantissa portion of the i-th pair of processed input parameters, where the i-th pair of processed input parameters is obtained by format conversion of input parameters of the second floating-point type or the first floating-point type. The i-th pair of processed input parameters includes a first processed input parameter and a second processed input parameter, and the first mantissa in FIG5B is the mantissa portion of the first processed input parameter, and the second mantissa is the mantissa portion of the second processed input parameter.

[0130] As shown in FIG5B , first, the product result of the first mantissa and the second mantissa is obtained by a Booth multiplier. For example, if the first mantissa and the second mantissa are the mantissa parts obtained by format conversion of the input parameters of the first floating-point type, the product result is L partial products. If the first mantissa and the second mantissa are the mantissa parts obtained by format conversion of the input parameters of the second floating-point type, the product result is L+O partial products.

[0131] For example, if the first mantissa and the second mantissa are the mantissa parts obtained by format conversion of the input parameters of the first floating-point type, then for the L partial products, similar to the processing process of the first multiplication unit, as shown in Figure 5B, first, a first intermediate compression result is obtained by at least one Wallace tree compression, and then the first intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters, and then the output is selected by the selector according to the floating-point type mark to obtain two partial products in a set of intermediate results corresponding to the i-th pair of processed input parameters (partial product 1 and partial product 2 in Figure 5B).

[0132] At the same time, the sign compensation reference constant 1 (corresponding to the sign compensation parameter of the first floating-point type, for example, 0xF0) is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters, and then the output is selected through the selector according to the floating-point type mark to obtain the sign compensation flag in a set of intermediate results corresponding to the i-th pair of processed input parameters.

[0133] The specific process of the above process is similar to that of the first multiplication unit, and the specific process will not be repeated here.

[0134] For example, if the first mantissa and the second mantissa are mantissa parts obtained by format conversion of an input parameter of the second floating-point number type, the L+0 parts are integrated into two paths and processed separately.

[0135] For the L partial products, first, a first intermediate compression result is obtained by performing at least one Wallace tree compression, and for the O partial products, a second intermediate compression result is obtained by performing at least one Wallace tree compression; then, the first intermediate compression result and the second intermediate compression result are subjected to at least one Wallace tree compression to obtain a third intermediate compression result; then, the third intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters; then, the output is selected by the selector according to the floating-point type mark to obtain two partial products (partial product 1 and partial product 2 in FIG5B ) in a set of intermediate results corresponding to the i-th pair of processed input parameters. Similarly, due to the shifting, the partial products 1 (res_a) and 2 (res_b) obtained from the mantissa of all processed input parameters correspond to the same exponent value (exponent value), that is, the maximum exponent value, so that the addition operation can be performed directly during the addition process without considering the difference in exponents.

[0136] At the same time, the sign compensation reference constant 2 (corresponding to the sign compensation parameter of the second floating-point type, which is different from the sign compensation reference constant 1) is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters, and then the output is selected through the selector according to the floating-point type mark to obtain the sign compensation flag in a set of intermediate results corresponding to the i-th pair of processed input parameters.

[0137] For example, in other examples, the second multiplication unit may not be provided with a selector for selecting a sign compensation flag output, that is, the second multiplication unit may simultaneously output a sign compensation flag 1 for the first floating-point type (for example, obtained by shifting the sign compensation reference constant 1) and a sign compensation flag 2 for the second floating-point type (for example, obtained by shifting the sign compensation reference constant 2). When the sign compensation value is subsequently calculated, the corresponding sign compensation flag is selected according to the different floating-point types. For example, the sign compensation reference constant is related to the type of the input parameter being processed. For the second floating-point type, since part of the exponent bits are not discarded during the preprocessing process, its sign compensation parameter is different from that of the first floating-point type. For example, in response to the second floating-point type being FP32, the sign compensation reference constant is 0x2 aaaa aa00 0000.

[0138] In a specific example, for example, the second floating-point number type includes FP32, and the second multiplication unit is a 24-bit multiplier. When the second multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the FP32 input parameter, first, the product result of the first mantissa and the second mantissa is obtained by the Booth multiplier, that is, 10+6 partial products; then, 10 of the partial products are compressed by the Wallace tree twice, and the 10 partial products are compressed into 4 intermediate partial products in the first compression, and the 4 intermediate partial products are compressed again into 2 intermediate partial products in the second compression, and the 2 intermediate partial products are used as the first intermediate compression result; at the same time, The six partial products in the middle are subjected to one Wallace tree compression to be compressed into two intermediate partial products, and the two intermediate partial products are used as a second intermediate compression result; then, the first intermediate compression result and the second intermediate compression result are subjected to one Wallace tree compression to obtain two intermediate partial products as a third intermediate compression result; then, the third intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products (i.e., partial product 1 and partial product 2) in a group of intermediate results corresponding to the i-th pair of processed input parameters; at the same time, the sign compensation reference constant 0x2 aaaa aa00 0000 is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag.

[0139] In the above embodiment, since the number of partial products obtained by multiplying the mantissa parts of the input parameters of the second floating-point type is greater, the second multiplication unit divides the partial integrals obtained by the Booth multiplier into two different channels for separate processing. The L partial products can adopt the same structure as the first multiplication unit, and the O partial products are processed separately. This allows the second multiplication unit to support both mantissa partial multiplication operations of the first floating-point type and mantissa partial multiplication operations of the second floating-point type, thereby reusing hardware circuits as much as possible and minimizing the consumption of hardware resources.

[0140] For example, in some embodiments, the O partial products obtained in the second multiplication unit can be transmitted to the idle first multiplication unit to perform subsequent Wallace tree compression without setting up the hardware path for the O partial products in Figure 5B. In this case, the Wallace tree compression part in the first multiplication unit can be reused, saving hardware resources and improving computing efficiency.

[0141] The second-level unit is used to further compress the N groups of intermediate results output by the first-level unit. For example, the partial product 1 and partial product 2 in the N groups of intermediate results are further compressed using the Wallace tree, and the partial products in the N groups of intermediate results output by the multiplication unit are finally compressed into two intermediate numbers as the compressed results.

[0142] For example, for input parameters of the first floating-point precision type, such as FP16 or BF16, the input of the second-level unit is 64 pairs of partial products, each pair of partial products is two partial products (res_a and res_b) in a set of intermediate results corresponding to a pair of processed input parameters, and the output is two compressed intermediate numbers.

[0143] For example, for input parameters of the second floating-point precision type, such as FP32, the input of the second-level unit is 32 pairs of partial products, each pair of partial products is two partial products (res_a and res_b) in a set of intermediate results corresponding to a pair of processed input parameters, and the output is two compressed intermediate numbers.

[0144] For example, in the Wallace tree compression process, each Wallace tree compression is performed in the format of an operation result of at least one channel, and the operation result of each channel includes at least one product term.

[0145] FIG6 is a schematic diagram of the compression process of the second-stage unit provided by at least one embodiment of the present disclosure.

[0146] As shown in FIG6 , the input of the second-level unit is N pairs of partial products, which are N partial products res_a and N res_b in FIG6 .

[0147] First, N pairs of partial products are padded and truncated to convert them into operation results of N' channels, where the operation result of each channel includes the same number of multiple product terms.

[0148] Next, perform Wallace tree compression on the computation results of the N' channels to obtain the Wallace tree compressed result. The above padding and compression process is then repeated. After multiple padding and compression processes, two intermediate numbers are obtained as compressed results. Each intermediate number includes the computation results of the N" channels, and each computation result includes a product term.

[0149] For example, in some embodiments, in order to maximize the reuse of the Wallace tree logic, the precision with the largest input and output bit width is selected as the basic data path of the Wallace tree when performing Wallace tree compression. By reusing the circuit of this Wallace tree, compression of other precisions is supported while minimizing the consumption of hardware resources.

[0150] For example, during the Wallace tree compression process, for each product term in the result of operations with the same number of channels, the number of bits of the product term is a second value. Here, the second value is determined based on the maximum number of bits of the product terms with the same number of channels obtained through Wallace tree compression for all precision types supported by the computing device.

[0151] For example, in response to the bit number of the product term obtained by direct compression being smaller than the second value, 0 is added to the high order bits of the product term to expand the bit number of the product term to the second value.

[0152] For example, in one example, the computing device supports multiplication and accumulation calculations of multiple precision types such as FP16, FP32, and BF16, among which the bit width of input and output in the Wallace tree compression process required by FP32 is the largest. For example, when Wallace tree compression is performed for the first time, 16 channels of operation results are required in FP32, each operation result includes 4 product terms, and each product term requires 68 bits, that is, the second value is 68.

[0153] Therefore, the bit width of the product term in the calculation result of 16 channels in the Wallace number hardware circuit is 68 bits. If other precision types are compressed through the Wallace tree circuit and their product term width is less than 68 bits, at least one 0 is added to the high bit to expand the bit number of the product term to 68 bits.

[0154] For example, in a specific example, taking the second-level unit used by FP32 as an example, the input is 32 pairs of partial products, that is, 32 partial products res_a and 32 partial products res_b, and the bit width of each partial product is 64 bits.

[0155] After padding and truncating the 32 pairs of partial products, 16 channels of operation results are obtained. Each operation result includes 4 product terms, and each product term includes 68 bits, where 4 zeros are added to the high bits of each partial product as a product term.

[0156] Afterwards, the calculation results of the 16 channels are subjected to a Wallace tree compression to obtain an intermediate result; the intermediate result is then padded and truncated to convert it into the calculation results of 8 channels, each calculation result includes 4 product terms, each product term is 53 bits, including 2 high-order zeros; the calculation results of the 8 channels are then subjected to a Wallace tree compression again to obtain an intermediate result; the intermediate result is then truncated to convert it into the calculation results of 4 channels; finally, the calculation result is subjected to Wallace tree compression to obtain the final compressed result.

[0157] For FP16 or BF16, when Wallace tree compression is performed, if the number of bits of each product term in the 16-channel operation result is less than 68, 0 is padded to expand the number of bits of the product term to 68; similarly, for the 8-channel operation result, if the number of bits of the product term is less than 53, 0 is padded to expand it to 53.

[0158] In this embodiment, the Wallace tree used by FP32 is selected as the basic data path. By reusing the circuit of this Wallace tree, the product terms whose bit width does not meet the requirements are padded with zeros to support the compression of the remaining precisions while minimizing the consumption of hardware resources.

[0159] The third-level unit receives the compression result from the second-level unit, further fills it with 0 and compresses it, and then adds it to the sign compensation value obtained based on the sign compensation flag bit to output the final output result.

[0160] For example, in the computing device provided by at least one embodiment of the present disclosure, as shown in FIG1 , the operation module 102 further includes a not-a-number processing module 1023. The not-a-number processing module 1023 is configured to determine whether a not-a-number (NAN) exists in N pairs of input parameters based on the not-a-number flag corresponding to each input parameter provided by the preprocessing module 101; if so, the not-a-number flag is set to a first value (e.g., 1) to directly output a NAN result through the two-way selector in FIG1 ; if not, the not-a-number flag is set to a second value (e.g., 0) to output the calculation result of the mantissa calculation unit through the two-way selector in FIG1 .

[0161] For example, the non-number processing module 1023 includes a first path, a second path, and a selector.

[0162] For example, the first path is configured to receive N pairs of input parameters of a first floating point number type, determine whether there is a non-number in the N pairs of input parameters, and output the non-number in the N pairs of input parameters in response to the presence of a non-number.

[0163] For example, the second path is configured to receive N pairs of input parameters of the second floating point type, determine whether there is a non-number in the N pairs of input parameters, and output the non-number in the N pairs of input parameters in response to the presence of a non-number.

[0164] For example, the selector is configured to select an output value of one of the first path or the second path for output according to the floating-point number type flag.

[0165] For example, the first path and the second path include a multi-stage dual-input multiplexing tree, and each stage of the dual-input multiplexing tree includes a plurality of dual-input selectors.

[0166] For example, the first floating-point number type includes FP16 or BF16, the data line width is 1024 bits, N is 128, the first path includes a 7-level dual-input multiplexer tree, the first-level dual-input multiplexer tree includes 64 dual-input selectors, the second-level dual-input multiplexer tree includes 32 dual-input selectors, ..., the 7th-level dual-input multiplexer includes 1 dual-input selector, and the mantissa parts of the 128 input parameters together with the corresponding sign bits are propagated to the next level in pairs through the multi-level dual-input multiplexer tree, and finally N pairs of non-numbers in the input parameters are output. If there are multiple non-numbers, the non-number with the smallest subscript is output.

[0167] Since FP16 and BF16 reuse the same non-number processing module, the lowest three bits of the mantissa of BF16 can be padded with 0s to expand to 10 bits to use the same first path as FP16.

[0168] For example, the second floating-point number type includes FP32, N is 64, the second path includes a 6-level dual-input multiplexer tree, the first-level dual-input multiplexer tree includes 32 dual-input selectors, the second-level dual-input multiplexer includes 16 dual-input selectors, ..., the sixth-level dual-input multiplexer includes 1 dual-input selector, and the mantissa parts of the 64 input parameters together with the corresponding sign bits are propagated to the next level in pairs, and finally N pairs of non-numbers in the input parameters are output. If there are multiple non-numbers, the non-number with the smallest subscript is output.

[0169] It should be noted that for non-numeric processing modules, the parameters used for calculation should be input parameters. If the processed input parameters are input into the non-numeric processing module, the processed input parameters need to be restored to the input parameter format before calculation.

[0170] It should be noted that, in the present disclosure, a specific embodiment is described by taking the first floating-point number type as BF16 or FP16 and the second floating-point number type as FP32 as an example, but the present disclosure is not limited thereto. For example, the first floating-point number type may also be other floating-point number types that meet the definition of the first floating-point number type, such as TF32, and similarly, the second floating-point number type may also be other floating-point number types that meet the definition of the second floating-point number type, such as FP64, and the present disclosure does not impose specific limitations on this. Other floating-point number types may also be implemented in a similar manner to the embodiments provided in the present disclosure.

[0171] In addition, the computing device provided by at least one embodiment of the present disclosure can also support conventional integer type multiplication and accumulation operations in addition to floating-point types. For example, taking a data line width of 1024 bits as an example, the computing device supports 128 pairs of INT8 (8-bit integer) type multiplication and accumulation calculations, or 64 pairs of INT16 (16-bit integer) type multiplication and accumulation calculations. For example, for integer type multiplication and accumulation operations, no preprocessing is required, and no exponent calculation unit is required. The corresponding multiplication operation can be completed directly through the mantissa calculation unit, and the repeated parts will not be repeated.

[0172] At least one embodiment of the present disclosure provides a computing device capable of supporting multiplication-accumulation calculations of multiple precision types. A preprocessing module first performs format conversion on input parameters, and expands the number of significant digits of the mantissa portion of input parameters whose mantissa portion is less than a first value to the first value, so that the mantissa portions of all floating-point input parameters whose mantissa portion is less than the first value are processed to the same number of bits. This allows the multiplication calculation of the mantissa portion to be reused, and the related hardware circuit structure to be reused, saving hardware resources. Adders, subtractors, etc. in the exponent calculation unit are grouped and reused, saving hardware resources and overhead. Simultaneously, the multiplication units are modified so that some multiplication units can support mantissa multiplication operations of different precision types and reuse circuit structures such as Booth multipliers. Furthermore, the bit width of the product term is expanded by padding with zeros to reuse the Wallace tree circuit structure, further reducing hardware resource overhead. This enables the computing device to support multiplication-accumulation calculations of multiple precision formats at a lower cost in area and power consumption, thereby improving the performance of electronic devices using the computing device, such as AI accelerators.

[0173] At least one embodiment of the present disclosure further provides a calculation method. FIG7 is a schematic flow chart of a calculation method provided by at least one embodiment of the present disclosure.

[0174] As shown in FIG. 7 , the calculation method provided by at least one embodiment of the present disclosure includes steps S10 to S30 .

[0175] For example, in step S10, N pairs of input parameters are received.

[0176] For example, each pair of input parameters includes two input parameters, N pairs of input parameters have the same precision type, and N is a positive integer.

[0177] For example, each pair of input parameters in the N pairs of input parameters may include two input parameters, and the N pairs of input parameters have the same precision type. For example, the product result corresponding to a pair of input parameters is the product of the two input parameters included in the pair of input parameters.

[0178] For the description of N pairs of input parameters, please refer to the description of the aforementioned computing device, and the repeated parts will be omitted.

[0179] In step S20, format conversion is performed on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of converted processed input parameters.

[0180] For example, the number of significant digits of the mantissa of the input parameter of the first floating-point number type is less than or equal to the first value.

[0181] For example, during the conversion process, for each input parameter whose precision type is the first floating-point type, the number of significant digits of the mantissa part of the input parameter is expanded to the first value, and the exponent information of the input parameter is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter.

[0182] For example, format conversion is performed on each pair of input parameters according to the precision types of N pairs of input parameters, which may include: for each input parameter, in response to the precision type of the input parameter being the first floating-point number type: discarding the lowest m bits of the exponent part of the input parameter, where m is a positive integer, performing a padding operation on the mantissa part of the input parameter, shifting the padded mantissa part by the value indicated by m bits to expand the number of significant digits of the mantissa part of the input parameter to the first value, and obtaining a processed input parameter corresponding to the input parameter.

[0183] For example, the padding operation includes padding a 1 before the most significant bit of the mantissa of the input parameter. For example, in the padding operation, at least the hidden bit of the mantissa is padded, that is, a 1 is padded before the most significant bit of the mantissa of the input parameter.

[0184] Of course, according to the bit number requirement, if only shifting the mantissa part after padding the hidden bit by the value indicated by m bits cannot expand the mantissa part to the first value, the padding operation may also include continuing to pad at least one 0 in the higher bits of the hidden bit after padding the hidden bit, until the number of mantissa bits after the mantissa part after performing the padding operation is shifted by the value indicated by m bits can be expanded to the first value.

[0185] For the specific process of format conversion, please refer to the relevant description of the pre-processing module in the aforementioned computing device, and the repeated parts will be omitted.

[0186] For example, in the above embodiment, the lowest m bits of the exponent part of the input parameter are discarded to reduce the bit width of the exponent part and effectively simplify the operation logic of the exponent part; the padded mantissa part is shifted by the value indicated by m bits to add the exponent information of the input parameter to the mantissa part of the input parameter, reducing the impact on the accuracy of the calculation result; and, the preprocessing of the precision of the floating-point number can fully reuse the operation logic and hardware resources of the multiplication part. The above preprocessing can be performed on the input parameters of the first floating-point number type. The number of bits of the mantissa part of the input parameter after preprocessing is the same, and the same data processing path can be fully reused, thereby greatly saving hardware resources, minimizing the consumption of hardware resources, and enabling the computing device to support multiplication and accumulation calculations in multiple precision formats at a lower cost of area and power consumption.

[0187] In step S30, the product of the exponential part and the mantissa part of each pair of processed input parameters is calculated respectively, and an output result is obtained based on the product of the exponential part and the mantissa part of each pair of processed input parameters.

[0188] For example, the output result is the cumulative sum of N product results corresponding to N pairs of input parameters.

[0189] For example, respectively calculating the product of the exponential part and the mantissa part of each pair of processed input parameters, and obtaining an output result based on the product of the exponential part and the mantissa part of each pair of processed input parameters, can include: performing an operation on the exponential part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters; combining the exponent shift value corresponding to each pair of processed input parameters, using multiple multiplication units to calculate the product of the mantissa parts of N pairs of processed input parameters in parallel, and outputting N groups of intermediate results corresponding to the N pairs of processed input parameters, wherein each group of intermediate results includes two partial products and a sign compensation flag; performing at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result; combining the sign compensation flag and the compression result in the N groups of intermediate results, and obtaining the output result using an adder.

[0190] For example, the exponent shift value indicates the difference between the product result of the exponent portion of each pair of processed input parameters relative to a maximum exponent value, where the maximum exponent value is the maximum value among the product results of the exponent portions of N pairs of processed input parameters. For example, the exponent shift value is used to shift the mantissa product results so that the exponent values ​​of the product results of N pairs of processed input parameters are the same, that is, the maximum exponent value, so that accumulation calculation can be directly performed.

[0191] For example, performing an operation on the exponential part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters may include: if the processed input parameters are obtained by format conversion of input parameters of a first floating-point number type, calculating the sum of the exponential parts of N1 pairs of processed input parameters in parallel to obtain N1 exponential calculation results, and determining the maximum value of the N1 exponential calculation results as the first maximum value, calculating the sum of the exponential parts of N2 pairs of processed input parameters in parallel to obtain N2 exponential calculation results, and determining the maximum value of the N2 exponential calculation results as the second maximum value. two maximum values, where N1 and N2 are positive integers, and N1+N2 equals N; if the processed input parameter is obtained by format conversion of the input parameter of the second floating-point type, summing the exponential parts of N pairs of processed input parameters in parallel to obtain N exponential calculation results, and determining the maximum value of the N exponential calculation results as the second maximum value; determining the larger value of the first maximum value and the second maximum value as the maximum exponent value; and calculating the difference between the sum of the exponential parts of each pair of processed input parameters and the maximum exponent value to obtain the exponent shift value corresponding to each pair of processed input parameters.

[0192] Regarding the calculation process of N1 adding the exponential part of the processed input parameter, reference can be made to the relevant description of the first sub-unit mentioned above, which will not be repeated here.

[0193] Regarding the specific process of parallel calculation of N2 summing the exponential parts of the processed input parameters or N summing the exponential parts of the processed input parameters, please refer to the relevant description of the aforementioned second subunit and will not be repeated here.

[0194] Regarding the specific process of determining the maximum exponent value and the exponent shift value corresponding to each pair of processed input parameters, reference may be made to the relevant description of the aforementioned third subunit, which will not be repeated here.

[0195] In the above embodiment, the operation of the exponential part can simultaneously support multiple precision types such as FP16, BF16, FP32, etc., which reduces hardware resources as much as possible and reuses more hardware circuit logic.

[0196] For example, when performing a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the first floating-point type, in combination with the exponent shift value corresponding to each pair of processed input parameters, multiple multiplication units are used in parallel to calculate the products of the mantissa parts of N pairs of processed input parameters, and N groups of intermediate results corresponding to the N pairs of processed input parameters are output. This may include: for the i-th pair of processed input parameters, obtaining L partial products corresponding to the i-th pair of processed input parameters through a Booth multiplier, where L is a positive integer; compressing the L partial products through at least one Wallace tree to obtain a first intermediate compressed result; shifting the first intermediate compressed result according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; shifting the sign compensation reference constant according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0197] For example, the multiplication operation on the mantissa of the processed input parameter corresponding to the input parameter of the first floating-point type can be performed by the first multiplication unit or the second multiplication unit. For example, the first multiplication unit is the aforementioned 16-bit multiplier, and the second multiplication unit is the aforementioned 24-bit multiplier.

[0198] Regarding the multiplication operation of the mantissa of the processed input parameter corresponding to the input parameter of the first floating-point type, reference can be made to the relevant contents in the aforementioned computing device, such as the relevant description in the first multiplication unit or the second multiplication unit, and the repeated parts will be omitted.

[0199] For example, when performing a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the second floating-point type, combining the exponent shift value corresponding to each pair of processed input parameters, using multiple multiplication units to parallelly calculate the product of the mantissa parts of N pairs of processed input parameters, and outputting N groups of intermediate results corresponding to the N pairs of processed input parameters, respectively, may include: for the i-th pair of processed input parameters, obtaining L+O partial products corresponding to the i-th pair of processed input parameters by a Booth multiplier, where L and O are both positive integers; compressing the L partial products by at least one Wallace tree to obtain a first intermediate compression result; and compressing O The partial products are compressed by at least one Wallace tree to obtain a second intermediate compression result; the first intermediate compression result and the second intermediate compression result are compressed by at least one Wallace tree to obtain a third intermediate compression result; the third intermediate compression result is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; the sign compensation reference constant is shifted according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0200] For example, the multiplication operation on the mantissa of the processed input parameter corresponding to the input parameter of the second floating-point type may be performed by the second multiplication unit. For example, the second multiplication unit is the aforementioned 24-bit multiplier.

[0201] Regarding the multiplication operation of the mantissa of the processed input parameter corresponding to the input parameter of the second floating-point type, reference may be made to the relevant contents in the aforementioned computing device, such as the relevant description in the second multiplication unit, and the repeated parts will be omitted.

[0202] For example, in the above embodiment, since the number of partial products obtained by multiplying the mantissa parts of the input parameters of the second floating-point number type is greater, the partial integrals obtained by the Booth multiplier can be divided into two different channels for separate processing, wherein the processing of the L partial products is the same as that of the first floating-point number type, and the O partial products are processed separately. This allows the multiplication units to be reused, the hardware circuits to be reused as much as possible, and the consumption of hardware resources to be minimized.

[0203] For example, performing at least one Wallace tree compression on the partial products in N groups of intermediate results to obtain a compressed result may include: further compressing the partial products in the N groups of intermediate results using the Wallace tree, and finally compressing them into two intermediate numbers as the compressed result.

[0204] For example, in the Wallace tree compression process, each Wallace tree compression is performed in the format of an operation result of at least one channel, and the operation result of each channel includes at least one product term.

[0205] For example, during the Wallace tree compression process, for each product term in the result of operations with the same number of channels, the number of bits of the product term is a second value. Here, the second value is determined based on the maximum number of bits of the product terms with the same number of channels obtained through Wallace tree compression for all precision types supported by the computing device.

[0206] For example, in response to the bit number of the product term obtained by direct compression being smaller than the second value, 0 is added to the high order bits of the product term to expand the bit number of the product term to the second value.

[0207] Regarding the specific process of performing at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain the compressed results, reference can be made to the relevant description of the aforementioned second-level unit, and the repeated parts will be omitted.

[0208] For example, in the above embodiment, the logic of the Wallace tree can be reused to the maximum extent, and the precision with the largest input and output bit width is selected as the basic data path of the Wallace tree when performing Wallace tree compression. By reusing the circuit of this Wallace tree, compression of other precisions is supported while minimizing the consumption of hardware resources.

[0209] For example, combining the sign compensation flag and compression result in N groups of intermediate results, and using an adder to obtain the output result, can include: filling the compressed result with 0 and further compressing it, and then adding the compressed result with the sign compensation value obtained based on the sign compensation flag to obtain the final output result.

[0210] Regarding the specific process of combining the sign compensation flag and compression results in the N groups of intermediate results and using the adder to obtain the output result, please refer to the relevant description of the aforementioned third-level unit, and the repeated parts will not be repeated.

[0211] For example, in the calculation method provided in at least one embodiment of the present disclosure, the method further includes: determining whether there is a non-number (NAN, Not A Number) in the input parameter according to the non-number mark of each input parameter.

[0212] For example, if there is a non-number, the non-number flag is set to the first value (for example, 1) to directly output the NAN result; if there is no non-number, the non-number flag is set to the second value (for example, 0) to output the output result of the above calculation.

[0213] For the description related to non-number judgment, please refer to the description related to the non-number processing module mentioned above, and the repeated parts will not be repeated.

[0214] In the calculation method provided in at least one embodiment of the present disclosure, it is possible to support multiplication and accumulation calculations of multiple precision types. The input parameters are first format converted, and the significant digits of the mantissa part of the input parameters whose significant digits of the mantissa part are less than the first value are expanded to the first value, so that the mantissa parts of all floating-point type input parameters whose significant digits of the mantissa part are less than the first value are processed into the same number of bits, so that the multiplication calculation of the mantissa part can be reused, the relevant hardware circuit structure can be reused, and hardware resources can be saved; mantissa multiplication operations of different precision types can be supported, and circuit structures such as Booth multipliers can be reused; further, the bit width of the product term is expanded by filling 0 to reuse the Wallace tree circuit structure, further reducing hardware resource overhead, so that the computing device can support multiplication and accumulation calculations of multiple precision formats at a lower area and power consumption cost, thereby improving the performance of electronic devices using the computing device, such as AI accelerators.

[0215] Some embodiments of the present disclosure further provide an electronic device. FIG8 is a schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure.

[0216] As shown in Figure 8, the electronic device 200 includes a computing device 201. For example, the computing device 201 may be the aforementioned computing device 100, and the repeated parts are not repeated here.

[0217] For example, the electronic device may be a processor that needs to perform multiplication and accumulation calculations. For example, the electronic device may be a general-purpose processor such as a multi-core processor or a digital signal processor. The electronic device can use a computing device to perform multiplication and accumulation calculations such as matrix multiplication or convolution multiplication operations. For example, the electronic device may be a component specifically provided in some AI accelerators for optimizing calculations, such as a deep learning accelerator. Of course, the present disclosure is not limited to this, and the electronic device may be any device that needs to be loaded with the computing device provided by at least one embodiment of the present disclosure to perform corresponding multiplication and accumulation calculations of multiple precision types.

[0218] It should be noted that, in the embodiments of the present disclosure, the electronic device 200 may include more or fewer circuits or units, for example, it may also include other circuits or units that support the operation of the computing device 201, and the present disclosure does not impose specific limitations on this.

[0219] The connection relationship between each circuit or unit is not limited and can be determined according to actual needs. The specific configuration of each circuit or unit is not limited and can be composed of analog devices according to circuit principles, digital chips, or other applicable methods.

[0220] Some embodiments of the present disclosure also provide another electronic device. Figure 9 is a schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure.

[0221] For example, as shown in Figure 9, the electronic device 300 includes a processor 310 and a memory 320. It should be noted that the components of the electronic device 300 shown in Figure 9 are merely exemplary and non-limiting, and the electronic device 300 may also have other components according to actual application requirements.

[0222] For example, the processor 310 and the memory 320 may communicate with each other directly or indirectly.

[0223] For example, the processor 310 and the memory 320 may communicate via a network. The network may include a wireless network, a wired network, and / or any combination of a wireless network and a wired network. The processor 310 and the memory 320 may also communicate with each other via a system bus, which is not limited in this disclosure.

[0224] For example, in some embodiments, memory 320 is configured to non-transiently store computer-readable instructions. When processor 310 is configured to execute the computer-readable instructions, the computer-readable instructions, when executed by processor 310, implement the calculation method described in any of the above embodiments. The specific implementation and related explanations of each step of the calculation method can be found in the above-mentioned embodiments of the calculation method, and any repetitive details are not repeated here.

[0225] For example, the processor 310 can control other components in the electronic device 300 to perform desired functions. The processor 310 can be a network processor (NP), a neural network processing unit (NPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0226] For example, the memory 320 may include any combination of one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory. Non-volatile memory may include, for example, read-only memory (ROM), a hard disk, an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, a flash memory, etc. One or more computer-readable instructions may be stored on the computer-readable storage medium, and the processor 310 may execute the computer-readable instructions to implement various functions of the electronic device 300. Various applications and various data may also be stored in the storage medium.

[0227] For example, in some embodiments, the electronic device 300 may be a mobile phone, a tablet computer, an electronic paper, a television, a monitor, a laptop computer, a digital photo frame, a navigator, a wearable electronic device, a smart home device, etc.

[0228] For example, the electronic device 300 may include a display panel, which may be used to display interactive content, etc. For example, the display panel may be a rectangular panel, a circular panel, an elliptical panel, or a polygonal panel, etc. In addition, the display panel may be not only a flat panel, but also a curved panel or even a spherical panel.

[0229] For example, the electronic device 300 may have a touch function, that is, the electronic device 300 may be a touch device.

[0230] For example, for a detailed description of the process of the electronic device 300 executing the calculation method, reference may be made to the relevant description in the embodiment of the calculation method, and repeated parts will not be repeated.

[0231] Figure 10 is a schematic diagram of a non-transitory computer-readable storage medium provided by at least one embodiment of the present disclosure. For example, as shown in Figure 10 , one or more computer-readable instructions 410 may be non-transitory stored on storage medium 400. For example, when computer-readable instructions 410 are executed by a processor, one or more steps of the computing method described above may be performed.

[0232] For example, the storage medium 400 may be applied to the electronic device 300. For example, the storage medium 400 may include the memory 320 in the electronic device 300.

[0233] For example, the description of the storage medium 400 may refer to the description of the memory 320 in the embodiment of the electronic device 300, and the repeated parts will be omitted.

[0234] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0235] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit does not necessarily limit the unit itself.

[0236] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0237] According to one or more embodiments of the present disclosure, a computing device is provided, comprising: a preprocessing module configured to: receive N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, N is a positive integer, and format conversion is performed on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of processed input parameters after conversion, wherein, during the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of the mantissa of the input parameter is expanded to a first value, and the exponent of the input parameter is increased. The information is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point type is less than or equal to the first value; and an operation module is configured to: respectively calculate the product of the exponent part and the mantissa part of each pair of processed input parameters, and obtain an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of N product results corresponding to the N pairs of input parameters one by one; wherein the computing device supports multiplication and accumulation calculations of multiple floating-point precision types.

[0238] According to one or more embodiments of the present disclosure, when the preprocessing module performs format conversion on each pair of input parameters according to the precision type of the N pairs of input parameters, the following operations are performed: for each input parameter, in response to the precision type of the input parameter being the first floating-point number type: discarding the lowest m bits of the exponent part of the input parameter, where m is a positive integer, performing a padding operation on the mantissa part of the input parameter, shifting the padded mantissa part by the numerical value indicated by the m bits, so as to expand the number of significant digits of the mantissa part of the input parameter to the first value, and obtaining the processed input parameter corresponding to the input parameter.

[0239] According to one or more embodiments of the present disclosure, the padding operation includes adding a 1 before the most significant bit of the mantissa of the input parameter.

[0240] According to one or more embodiments of the present disclosure, the operation module includes an exponent calculation unit and a mantissa calculation unit, wherein the exponent calculation unit is configured to perform an operation on the exponent part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters, wherein the exponent shift value indicates the difference between the product result of the exponent part of each pair of processed input parameters and the maximum exponent value, and the maximum exponent value is the maximum value among the product results of the exponent part of the N pairs of processed input parameters; the mantissa calculation unit is configured to perform an operation on each pair of processed input parameters in combination with the exponent shift value corresponding to each pair of processed input parameters. The output result is obtained by performing a multiplication operation on the mantissa part of the number, wherein the mantissa calculation unit includes multiplication units of at least two precision types, and the at least two precision types of multiplication units include a first multiplication unit and a second multiplication unit, and the first multiplication unit and the second multiplication unit both support the mantissa part multiplication operation of the processed input parameter corresponding to the input parameter of the first floating-point number type, and the second multiplication unit supports the mantissa part multiplication operation of the processed input parameter corresponding to the input parameter of the second floating-point number type, wherein the input parameter of the second floating-point number type is an input parameter whose mantissa part has a significant number of digits greater than the first value.

[0241] According to one or more embodiments of the present disclosure, the exponential calculation unit includes a first subunit, a second subunit and an output subunit, the first subunit is configured to: parallelly calculate the sum of the exponential parts of N1 pairs of processed input parameters to obtain N1 exponential calculation results, wherein the N1 pairs of processed input parameters are obtained after format conversion of N1 pairs of input parameters of the first floating-point type; and determine the maximum value of the N1 exponential calculation results as the first maximum value; the second subunit is configured to: parallelly calculate the sum of the exponential parts of N2 pairs of processed input parameters to obtain N2 exponential calculation results, wherein the N2 pairs of processed input parameters are obtained after format conversion of N2 pairs of input parameters of the first floating-point type. Obtain; determine the maximum value among the N2 exponential calculation results as the second maximum value, wherein N1 and N2 are positive integers, and N1+N2 equals N; or calculate the sum of the exponential parts of the N pairs of processed input parameters in parallel to obtain N exponential calculation results, wherein the N pairs of processed input parameters are obtained after format conversion of N pairs of input parameters of the second floating-point type; determine the maximum value among the N exponential calculation results as the second maximum value; the output subunit is configured to: determine the larger value of the first maximum value and the second maximum value as the maximum exponent value; and calculate the difference between the product result of the exponential part of each pair of processed input parameters and the maximum exponent value to obtain the exponent shift value corresponding to each pair of processed input parameters.

[0242] According to one or more embodiments of the present disclosure, the data bit width processed by the first sub-unit is determined based on the largest number of significant digits of the exponent part among the significant digits of the exponent part of the processed input parameter corresponding to the input parameter of the first floating-point number type; the data bit width processed by the second sub-unit is determined based on the largest number of significant digits of the exponent part among the significant digits of the exponent part of the processed input parameter corresponding to the input parameter of the second floating-point number type.

[0243] According to one or more embodiments of the present disclosure, the mantissa calculation unit includes a first-level unit, a second-level unit and a third-level unit, the first-level unit is configured to combine the exponent shift value corresponding to each pair of processed input parameters, and use the multiple multiplication units to parallelly calculate the product of the mantissa parts of the N pairs of processed input parameters, and output N groups of intermediate results corresponding to the N pairs of processed input parameters, respectively, wherein each group of intermediate results includes two partial products and a sign compensation flag; the second-level unit is configured to perform at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result; the third-level unit is configured to combine the sign compensation flag in the N groups of intermediate results and the compressed result, and use an adder to obtain the output result.

[0244] According to one or more embodiments of the present disclosure, when the first multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the first floating-point type, it includes performing the following operations: for the i-th pair of processed input parameters, obtaining L partial products corresponding to the i-th pair of processed input parameters through the Booth multiplier, where L is a positive integer; subjecting the L partial products to at least one Wallace tree compression to obtain a first intermediate compression result; shifting the first intermediate compression result according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; shifting the sign compensation reference constant according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0245] According to one or more embodiments of the present disclosure, when the second multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the second floating-point type, it includes performing the following operations: for the i-th pair of processed input parameters, obtaining L+O partial products corresponding to the i-th pair of processed input parameters through the Booth multiplier, where L and O are both positive integers; subjecting the L partial products to at least one Wallace tree compression to obtain a first intermediate compression result; subjecting the O partial products to at least one Wallace tree compression to obtain a second intermediate compression result; subjecting the first intermediate compression result and the second intermediate compression result to at least one Wallace tree compression to obtain a third intermediate compression result; shifting the third intermediate compression result according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a group of intermediate results corresponding to the i-th pair of processed input parameters; shifting the sign compensation reference constant according to the exponent shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a group of intermediate results corresponding to the i-th pair of processed input parameters, where i is a positive integer.

[0246] According to one or more embodiments of the present disclosure, the O partial products obtained in the second multiplication unit are transmitted to an idle first multiplication unit to perform subsequent Wallace tree compression.

[0247] According to one or more embodiments of the present disclosure, in response to the first floating-point number type being BF16 or FP16, the sign compensation reference constant is 0xF0, and in response to the second floating-point number type being FP32, the sign compensation reference constant is 0x2 aaaa aa00 0000.

[0248] According to one or more embodiments of the present disclosure, during the Wallace tree compression process, each Wallace tree compression is performed in the format of the operation result of at least one channel, the operation result of each channel includes at least one product term, and for each product term in the operation results with the same number of channels, the bit number of the product term is a second value, wherein the second value is determined based on the maximum value of the bit number of the product terms with the same number of channels obtained by the Wallace tree compression in all precision types supported by the computing device. In response to the bit number of the product term being less than the second value, 0 is padded to the high bit of the product term to expand the bit number of the product term to the second value.

[0249] According to one or more embodiments of the present disclosure, the first floating-point number type is BF16 or FP16, the second floating-point number type is FP32, the first multiplication unit is a 16-bit multiplier, and the second multiplication unit is a 24-bit multiplier.

[0250] According to one or more embodiments of the present disclosure, a non-number processing module is further included, which is configured to determine whether there is a non-number in the N pairs of input parameters based on the non-number flag corresponding to each input parameter provided by the preprocessing module; wherein the non-number processing module includes a first path, a second path and a selector, the first path is configured to receive N pairs of input parameters of the first floating-point number type, determine whether there is a non-number in the N pairs of input parameters, and output the non-numbers in the N pairs of input parameters in response to the presence of a non-number; the second path is configured to receive N pairs of input parameters of the second floating-point number type, determine whether there is a non-number in the N pairs of input parameters, and output the non-numbers in the N pairs of input parameters in response to the presence of a non-number, wherein the input parameters of the second floating-point number type are input parameters whose number of significant digits in the mantissa is greater than the first value; the selector is configured to select the output value of one of the first path or the second path for output based on the floating-point number type flag.

[0251] According to one or more embodiments of the present disclosure, a calculation method is provided, comprising: receiving N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, N is a positive integer, performing format conversion on each pair of input parameters according to the precision type of the N pairs of input parameters to obtain N pairs of converted processed input parameters, wherein, during the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of a mantissa part of the input parameter is expanded to a first value, and exponent information of the input parameter is added to the mantissa part of the input parameter to obtain a processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; respectively calculating the product of the exponent part and the mantissa part of each pair of processed input parameters, and obtaining an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of the N product results corresponding to the N pairs of input parameters.

[0252] According to one or more embodiments of the present disclosure, each pair of input parameters is format converted according to the precision type of the N pairs of input parameters, including: for each input parameter, in response to the precision type of the input parameter being the first floating-point number type: discarding the lowest m bits of the exponent part of the input parameter, where m is a positive integer, performing a padding operation on the mantissa part of the input parameter, shifting the padded mantissa part by the numerical value indicated by the m bits to expand the number of significant digits of the mantissa part of the input parameter to the first value, and obtaining a processed input parameter corresponding to the input parameter.

[0253] According to one or more embodiments of the present disclosure, respectively calculating the product of the exponential part and the mantissa part of each pair of processed input parameters, and obtaining an output result based on the product of the exponential part and the mantissa part of each pair of processed input parameters, includes: performing an operation on the exponential part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters, wherein the exponent shift value indicates the difference between the product result of the exponential part of each pair of processed input parameters and the maximum exponent value, and the maximum exponent value is the exponent part of the N pairs of processed input parameters. the maximum value in the product result; combining the exponent shift value corresponding to each pair of processed input parameters, using multiple multiplication units to parallelly calculate the product of the mantissa parts of the N pairs of processed input parameters, and outputting N groups of intermediate results corresponding to the N pairs of processed input parameters, wherein each group of intermediate results includes two partial products and a sign compensation flag; performing at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result; combining the sign compensation flags in the N groups of intermediate results and the compressed result, and obtaining the output result by using an adder.

[0254] According to one or more embodiments of the present disclosure, an electronic device is provided, including the computing device as described in any embodiment of the present disclosure.

[0255] According to one or more embodiments of the present disclosure, an electronic device is provided, comprising: a memory, which non-transiently stores computer-executable instructions; and a processor, configured to execute the computer-executable instructions, wherein the computer-executable instructions, when executed by the processor, implement the computing method according to any embodiment of the present disclosure.

[0256] According to one or more embodiments of the present disclosure, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the computing method according to any embodiment of the present disclosure is implemented.

[0257] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also includes other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.

[0258] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details have been included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0259] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.

[0260] Regarding this disclosure, the following points need to be explained:

[0261] (1) The drawings of the embodiments of the present disclosure only relate to the structures related to the embodiments of the present disclosure. Other structures may refer to conventional designs.

[0262] (2) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to form new embodiments.

[0263] The above description is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. The protection scope of the present disclosure shall be based on the protection scope of the claims.

Claims

1. A computing device, comprising: Preprocessing module, configured as: Receive N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, and N is a positive integer, According to the precision types of the N pairs of input parameters, format conversion is performed on each pair of input parameters to obtain N pairs of processed input parameters after conversion, wherein in the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of the mantissa part of the input parameter is expanded to a first value, and the exponent information of the input parameter is added to the mantissa part of the input parameter to obtain the processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; and Operation module, configured as: Calculate the product of the exponent part and the mantissa part of each pair of processed input parameters respectively, and obtain an output result based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of N product results corresponding to the N pairs of input parameters one by one; The computing device supports multiplication and accumulation calculations of various floating point precision types.

2. The computing device according to claim 1, wherein: The preprocessing module performs format conversion on each pair of input parameters according to the precision type of the N pairs of input parameters, including the following operations: For each input parameter, in response to the precision type of the input parameter being the first floating point number type: The lowest m bits of the exponent part of the input parameter are discarded, where m is a positive integer. Perform padding operation on the mantissa of the input parameter, The padded mantissa is shifted by the value indicated by the m bits to expand the number of significant digits of the mantissa of the input parameter to the first value, thereby obtaining a processed input parameter corresponding to the input parameter.

3. The computing device according to claim 2, wherein: The padding operation includes adding a 1 before the most significant bit of the mantissa of the input parameter.

4. The computing device according to any one of claims 1 to 3, wherein: The operation module includes an exponent calculation unit and a mantissa calculation unit, wherein: The exponential calculation unit is configured to perform an operation on the exponential part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters, wherein the exponent shift value indicates a difference between a product result of the exponential part of each pair of processed input parameters and a maximum exponent value, and the maximum exponent value is a maximum value among the product results of the exponential parts of the N pairs of processed input parameters; The mantissa calculation unit is configured to perform a multiplication operation on the mantissa part of each pair of processed input parameters in combination with the exponent shift value corresponding to each pair of processed input parameters to obtain the output result. The mantissa calculation unit includes at least two types of multiplication units of precision, and the at least two types of multiplication units of precision include a first multiplication unit and a second multiplication unit. The first multiplication unit and the second multiplication unit both support the mantissa multiplication operation of the processed input parameter corresponding to the input parameter of the first floating-point number type, and the second multiplication unit supports the mantissa multiplication operation of the processed input parameter corresponding to the input parameter of the second floating-point number type, wherein the input parameter of the second floating-point number type is an input parameter whose number of significant digits of the mantissa part is greater than the first value.

5. The computing device according to claim 4, wherein: The exponential calculation unit includes a first subunit, a second subunit and an output subunit, The first subunit is configured as follows: Parallel calculation is performed to sum the exponential parts of N1 pairs of processed input parameters to obtain N1 exponential calculation results, wherein the N1 pairs of processed input parameters are obtained by format conversion of N1 pairs of input parameters of the first floating point number type; and Determine a maximum value among the N1 index calculation results as a first maximum value; The second subunit is configured as follows: Parallel calculation is performed to sum the exponential parts of N2 pairs of processed input parameters to obtain N2 exponential calculation results, wherein the N2 pairs of processed input parameters are obtained by format conversion of N2 pairs of input parameters of the first floating point type; and a maximum value among the N2 exponential calculation results is determined as a second maximum value, wherein N1 and N2 are positive integers, and N1+N2 equals N; or Calculating in parallel the sum of the exponential parts of the N pairs of processed input parameters to obtain N exponential calculation results, wherein the N pairs of processed input parameters are obtained by format conversion of N pairs of input parameters of the second floating point number type; determining a maximum value among the N exponential calculation results as a second maximum value; The output subunit is configured as follows: determining a larger value of the first maximum value and the second maximum value as the maximum order value; and The difference between the calculation result of the exponential part of each pair of processed input parameters and the maximum exponent value is calculated to obtain the exponent shift value corresponding to each pair of processed input parameters.

6. The computing device according to claim 5, wherein: The data bit width processed by the first subunit is determined based on the largest number of significant digits of the exponent part of the processed input parameter corresponding to the input parameter of the first floating point number type; The data bit width processed by the second subunit is determined based on the largest number of significant digits of the exponent part of the processed input parameter corresponding to the input parameter of the second floating point number type.

7. The computing device according to any one of claims 4 to 6, wherein: The mantissa calculation unit includes a first-level unit, a second-level unit and a third-level unit, The first-stage unit is configured to calculate the products of the mantissa parts of the N pairs of processed input parameters in parallel using a plurality of the multiplication units in combination with the exponent shift values ​​corresponding to each pair of processed input parameters, and output N groups of intermediate results corresponding to the N pairs of processed input parameters, respectively, wherein each group of intermediate results includes two partial products and a sign compensation flag bit; The second-level unit is configured to perform at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result; The third-level unit is configured to combine the sign compensation flag bits in the N groups of intermediate results and the compression results, and obtain the output result using an adder.

8. The computing device according to any one of claims 4 to 7, wherein: When the first multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the first floating-point number type, the following operations are performed: For the i-th pair of processed input parameters, obtaining L partial products corresponding to the i-th pair of processed input parameters through a Booth multiplier, where L is a positive integer; Compress the L partial products at least once using a Wallace tree to obtain a first intermediate compression result; Shifting the first intermediate compression result according to the order code shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a set of intermediate results corresponding to the i-th pair of processed input parameters; Compensate the sign reference constant according to the order shift value corresponding to the i-th pair of processed input parameters Shifting is performed to obtain a sign compensation flag bit in a set of intermediate results corresponding to the i-th pair of processed input parameters, Wherein, i is a positive integer.

9. The computing device according to any one of claims 4 to 8, wherein: When the second multiplication unit performs a multiplication operation on the mantissa part of the processed input parameter corresponding to the input parameter of the second floating-point number type, the following operations are performed: For the i-th pair of processed input parameters, obtain L+O partial products corresponding to the i-th pair of processed input parameters through a Booth multiplier, where L and O are both positive integers; Compress the L partial products at least once using a Wallace tree to obtain a first intermediate compression result; Compress the O partial products at least once using a Wallace tree to obtain a second intermediate compression result; Performing at least one Wallace tree compression on the first intermediate compression result and the second intermediate compression result to obtain a third intermediate compression result; Shifting the third intermediate compression result according to the order code shift value corresponding to the i-th pair of processed input parameters to obtain two partial products in a set of intermediate results corresponding to the i-th pair of processed input parameters; Shifting the sign compensation reference constant according to the order shift value corresponding to the i-th pair of processed input parameters to obtain a sign compensation flag bit in a set of intermediate results corresponding to the i-th pair of processed input parameters, Wherein, i is a positive integer.

10. The computing device according to claim 9, wherein: The O partial products obtained in the second multiplication unit are transmitted to the idle first multiplication unit to perform subsequent Wallace tree compression.

11. The computing device according to any one of claims 8 to 10, wherein: In response to the first floating point number type being BF16 or FP16, the sign compensation reference constant is 0xF0, In response to the second floating point number type being FP32, the sign compensation reference constant is 0x2 aaaa aa00 0000.

12. The computing device according to any one of claims 7 to 11, wherein: In the Wallace tree compression process, each Wallace tree compression is performed in the format of a calculation result of at least one channel, and the calculation result of each channel includes at least one product term. For each product term in the operation result with the same number of channels, the number of bits of the product term is a second value, wherein the second value is based on all precision types supported by the computing device. The maximum value of the number of bits in the product term of the same number of channels obtained by the Wallace tree compression is determined, In response to the number of bits of the product term being less than the second value, the high bits of the product term are padded with 0 to extend the number of bits of the product term to the second value.

13. The computing device according to any one of claims 4 to 12, wherein: The first floating point number type is BF16 or FP16, the second floating point number type is FP32, The first multiplication unit is a 16-bit multiplier, and the second multiplication unit is a 24-bit multiplier.

14. The computing device according to any one of claims 1 to 13, further comprising a non-number processing module configured to determine whether there is a non-number in the N pairs of input parameters according to the non-number mark corresponding to each input parameter provided by the pre-processing module; in, The non-number processing module includes a first path, a second path and a selector. The first path is configured to receive N pairs of input parameters of the first floating point number type, determine whether there is a non-number in the N pairs of input parameters, and in response to the presence of a non-number, output the non-number in the N pairs of input parameters; The second path is configured to receive N pairs of input parameters of a second floating point number type, determine whether there is a non-number in the N pairs of input parameters, and in response to the presence of a non-number, output the non-number in the N pairs of input parameters, wherein the input parameter of the second floating point number type is an input parameter with a mantissa part having a number of significant digits greater than the first value; The selector is configured to select an output value of one of the first path or the second path for output according to a floating point number type flag.

15. A calculation method comprising: Receive N pairs of input parameters, wherein each pair of input parameters includes two input parameters, the N pairs of input parameters have the same precision type, and N is a positive integer, According to the precision type of the N pairs of input parameters, format conversion is performed on each pair of input parameters to obtain N pairs of processed input parameters after conversion, wherein, in the format conversion process, for each input parameter whose precision type is a first floating-point number type, the number of significant digits of the mantissa part of the input parameter is expanded to a first value, and the exponent information of the input parameter is added to the mantissa part of the input parameter to obtain the processed input parameter corresponding to the input parameter, wherein the number of significant digits of the mantissa part of the input parameter of the first floating-point number type is less than or equal to the first value; The product of the exponent part and the mantissa part of each pair of processed input parameters is calculated respectively, and an output result is obtained based on the product of the exponent part and the mantissa part of each pair of processed input parameters, wherein the output result is the cumulative sum of the N product results corresponding to the N pairs of input parameters one by one.

16. The calculation method according to claim 15, wherein: According to the precision types of the N pairs of input parameters, format conversion is performed on each pair of input parameters, including: For each input parameter, in response to the precision type of the input parameter being the first floating point number type: The lowest m bits of the exponent part of the input parameter are discarded, where m is a positive integer. Perform padding operation on the mantissa of the input parameter, The padded mantissa is shifted by the value indicated by the m bits to expand the number of significant digits of the mantissa of the input parameter to the first value, thereby obtaining a processed input parameter corresponding to the input parameter.

17. The calculation method according to claim 15 or 16, wherein: The product of the exponential part and the mantissa part of each pair of processed input parameters is calculated respectively, and based on the product of the exponential part and the mantissa part of each pair of processed input parameters, an output result is obtained, including: Performing an operation on the exponential part of each pair of processed input parameters to obtain an exponent shift value corresponding to each pair of processed input parameters, wherein the exponent shift value indicates a difference between a sum of the exponential parts of each pair of processed input parameters and a maximum exponent value, and the maximum exponent value is a maximum value among the sum of the exponential parts of the N pairs of processed input parameters; In combination with the exponent shift value corresponding to each pair of processed input parameters, multiple multiplication units are used to calculate the products of the mantissa parts of the N pairs of processed input parameters in parallel, and N groups of intermediate results corresponding to the N pairs of processed input parameters are output, wherein each group of intermediate results includes two partial products and a sign compensation flag bit; Performing at least one Wallace tree compression on the partial products in the N groups of intermediate results to obtain a compressed result; The output result is obtained by combining the sign compensation flags in the N groups of intermediate results and the compression results using an adder.

18. An electronic device comprising the computing device according to any one of claims 1 to 14.

19. An electronic device comprising: A memory non-transitorily stores computer executable instructions; a processor configured to execute the computer executable instructions, Wherein, when the computer executable instructions are executed by the processor, the computing method according to any one of claims 15-17 is implemented.

20. A non-transitory computer-readable storage medium, wherein: The non-transitory computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, implement the computing method according to any one of claims 15 to 17.

Citation Information

Patent Citations

  • Multiplier, method, integrated circuit chip and computing device for floating point operation

    CN112732221A

  • Floating-point number multiplication calculation method and device and arithmetic logic unit

    CN113126954A

  • Arithmetic logic unit and floating-point number multiplication calculation method and device

    CN115934030A

  • Integrated circuits with machine learning extensions

    US20190155574A1

  • Numerical precision in digital multiplier circuitry

    WO2022150058A1

Cited By

  • Data processing method and device, electronic equipment, storage medium and program product

    CN121785563A