Accumulator, method for accumulator, and computing device
By introducing an addition processing unit, a cache comparison unit and an accumulation feedback unit into the accumulator, the addend is dynamically adjusted and the data format is corrected, which solves the error problem caused by data format limitations in the accumulation of floating point numbers and improves calculation accuracy.
Patent Information
- Application Number
- CN202410877073.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-02
AI Technical Summary
In the existing technology, calculation errors due to data format limitations during the accumulation process of floating point numbers are large, especially when the data exceeds the range, the calculation results are unreliable.
An accumulator is designed, including an addition processing unit, a cache comparison unit and an accumulation feedback unit. By comparing and judging the accumulation results and using feedback control signals, the addend is dynamically selected and the data format range is corrected to ensure that the final result is within Within the scope of the data format, errors are reduced.
It effectively reduces calculation errors caused by data format limitations and improves the accuracy of accumulation calculations, especially when accumulating floating point numbers to maintain the accuracy of the results.
Smart Images

Figure CN118426734B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of integrated circuit accumulators, and in particular to an accumulator and a method and a computing device for the accumulator. Background Art
[0002] The accumulator is a common digital logic circuit design used to accumulate input data. The core is an adder that returns the output to the input to accumulate the input. Figure 1 The simple accumulator in the figure, where the first input data of A is added to 0 to get B. Obviously, B=A at this time, and then switch, and select B to add to A until the accumulation stops. As the input A is continuously updated, B is also continuously updated by addition, and B returns to add to the input A, thus realizing the function of accumulating the input A, and finally obtaining the accumulated result B.
[0003] Assumptions Figure 1 In the example, A is 8-bit data, and the maximum number of consecutive accumulations is 2^10 (2 to the 10th power) = 1024. Therefore, setting the bit width of B signal to 18 is sufficient to ensure accurate results. However, for designs with limited bit widths, direct hard accumulation like this may cause calculation errors, which is particularly typical in the process of floating-point accumulation.
[0004] See also Figure 2 The figure shows some commonly used floating point formats, where sign is the sign bit, indicating the positive or negative of the data, range is the integer range, and precision can be considered as the decimal part. The three together can represent a positive or negative decimal, and obviously can also represent a positive or negative integer. The floating point format is widely used in computer systems and is a universal standard.
[0005] However, due to the fixed floating-point format, especially the fixed bit width of the range, the floating-point format can only accurately represent a limited range of numbers. Once the data is too large and exceeds the range, it cannot be accurately represented. Moreover, if the calculation continues after exceeding the range of the data format, the calculation result is unreliable, which will lead to increasing calculation errors.
[0006] For ease of understanding, let's take a simple example. Suppose there is a floating point number that can only represent the range of -10 to +10. Any number greater than +10 can only be represented by +11 (in the real floating point representation, it is +∞, positive infinity. To facilitate understanding of the error, this example uses +11 instead). Any number less than -10 can only be represented by -11 (in the real floating point representation, it is -∞, negative infinity). Suppose +5, +6 and +7 are added, theoretically we can get +18, but the computer can only get +11 using this floating point representation. At this time, if we do addition again, even if we add -9, we can theoretically get +18+(-9)=+9, but the computer result is +11+(-9)=+2.
[0007] Therefore, a technical solution is needed to reduce the calculation error caused by data format limitations and improve the accuracy of the accumulation calculation during the data accumulation process. Summary of the invention
[0008] The present invention aims to provide an accumulator and a method and a computing device for the accumulator, which can reduce the calculation error caused by data format restrictions and improve the accumulation calculation accuracy during the data accumulation process.
[0009] According to one aspect of the present invention, an accumulator is provided, comprising: an addition operation processing unit, a cache comparison unit, and an accumulation feedback unit, wherein:
[0010] The addition operation processing unit receives external input data, first accumulated result data from the cache comparison unit, and second accumulated result data from the accumulated feedback unit, and selects to perform an addition operation on the external input data or the first accumulated result data and the second accumulated result data according to a first feedback control signal from the cache comparison unit, and outputs the updated second accumulated result data to the cache comparison unit and the accumulated feedback unit;
[0011] The cache comparison unit receives the updated second accumulation result data from the addition operation processing unit, and performs comparison and judgment according to the internal logic, and according to the comparison and judgment result, caches the updated second accumulation result data as the first accumulation result data and outputs a first feedback control signal, and the first accumulation result data and the first feedback control signal are transmitted to the addition operation processing unit;
[0012] The accumulation feedback unit receives the updated second accumulation result data from the addition processing unit, and feeds back the updated second accumulation result data to the addition processing unit and the cache comparison unit.
[0013] According to some embodiments, the addition operation processing unit includes a first multiplexer and an adder, wherein:
[0014] The first multiplexer is used to receive the external input data and the first accumulated result data, and select the external input data or the first accumulated result data as the first addend according to the first feedback control signal, and output it to the adder;
[0015] The adder receives the first addend from the first multiplexer and the second accumulation result data from the accumulation feedback unit, performs an addition operation, and outputs the updated second accumulation result data.
[0016] According to some embodiments, the cache comparison unit includes a comparator, a first counter, a second counter, and a register, wherein:
[0017] The comparator is used for comparing the first accumulation result data with the updated second accumulation result when the second counter is updated, and outputting a first feedback control signal to the addition operation processing unit according to the comparison result;
[0018] The first counter, the second counter and the register are used to perform beat registering on the updated second accumulated data, and the updated second accumulated result data is cached in the register as the first accumulated result data according to the comparison and judgment result of the comparator.
[0019] According to some embodiments, the cache comparison unit is configured to:
[0020] When the second counter is updated for the first time, the updated second accumulation result data is received from the addition operation processing unit and cached in the register, and output as the first accumulation result data.
[0021] According to some embodiments, the cache comparison unit is further configured to:
[0022] When the second counter is subsequently updated, comparing the first accumulation result data with the updated second accumulation result data;
[0023] If the first accumulation result data and the updated second accumulation result data have the same sign and the first accumulation result data is not zero, then perform accumulation of the next group of accumulation data and continue to update the second accumulation result data;
[0024] Otherwise, the first accumulated result is added to the second accumulated result, and the calculation result is applied to update the first accumulated result data in the register, and the first feedback control signal is output.
[0025] According to some embodiments, the accumulation feedback unit includes: a second multiplexer, configured to send the updated second accumulation result data to the addition operation processing unit.
[0026] According to another aspect of the present invention, there is provided a method for an accumulator, comprising:
[0027] Obtaining a total amount of external input data and dividing it into at least three groups, each group including a specific amount of input data, and sequentially inputting the groups into the accumulator as described above;
[0028] Performing an accumulation operation on the first group of input data, and saving the accumulation result of the first group as first accumulation result data;
[0029] Performing an accumulation operation on the second group of input data, and using the accumulation result of the second group as the updated second accumulation result data;
[0030] Comparing the first accumulated result data with the updated second accumulated result data, if the two have the same sign and the first accumulated result data is not zero, accumulating a third group of accumulated data and continuing to update the second accumulated result data, otherwise adding the first accumulated result data with the updated second accumulated result data, and applying the calculation result to save and update the first accumulated result data;
[0031] According to the above method, input the last group of data to be accumulated in sequence to complete the accumulation;
[0032] The updated second accumulation result data after the accumulation is completed is output as the final result of the accumulation calculation.
[0033] According to some embodiments, when the total amount of the external input data does not meet the grouping requirement, zeros are added after the external input data to make up the amount.
[0034] According to some embodiments, when the total amount of the external input data is constant, increasing the number of groups can improve the accuracy of the accumulation result.
[0035] According to some embodiments, each time the first accumulated result data is updated and saved, the updated second accumulated result data is cleared.
[0036] According to another aspect of the present invention, there is provided a computing device, comprising:
[0037] Processor; and
[0038] A memory storing a computer program, which, when executed by the processor, enables the processor to execute any of the methods described above.
[0039] According to another aspect of the present invention, there is provided a non-transitory computer-readable storage medium having computer-readable instructions stored thereon, and when the instructions are executed by a processor, the processor is caused to execute any of the above methods.
[0040] According to an embodiment of the present invention, by comparing and judging the second accumulated result data with the first accumulated result number, and cooperating with the first feedback control signal to correct the data format range of the accumulated data result of the external input data, the error accumulation in the accumulation process is reduced, so that the final accumulated result is kept within the data format range, the error caused by exceeding the data format range during the calculation process is reduced, and the accuracy of the accumulated calculation is improved.
[0041] According to some embodiments, by grouping and accumulating all external input data, the probability of intermediate accumulation result data exceeding the valid range is reduced, thereby reducing calculation errors caused by exceeding the digital format range.
[0042] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for describing the embodiments are briefly introduced below.
[0044] Figure 1 A schematic diagram of a conventional simple accumulator is shown.
[0045] Figure 2 Shows some common floating-point number formats.
[0046] Figure 3 A device architecture diagram of an accumulator according to an example is shown.
[0047] Figure 4 A schematic diagram of an accumulator according to an example is shown.
[0048] Figure 5 A flow chart of a method for an accumulator according to an example is shown.
[0049] Figure 6 A detailed step diagram of a method for an accumulator according to an example is shown.
[0050] Figure 7 A block diagram of a computing device is shown according to an exemplary embodiment. DETAILED DESCRIPTION
[0051] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that the present invention will be comprehensive and complete and fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0052] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solution of the present invention can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring various aspects of the present invention.
[0053] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0054] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0055] It should be understood that although the terms first, second, third, etc. may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another component. Therefore, the first component discussed below can be referred to as the second component without departing from the teachings of the present inventive concept. As used herein, the term "and / or" includes any one of the associated listed items and all combinations of one or more.
[0056] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0057] Those skilled in the art will appreciate that the drawings are merely schematic diagrams of example embodiments, and the modules or processes in the drawings are not necessarily necessary for implementing the present invention, and therefore cannot be used to limit the protection scope of the present invention.
[0058] During the accumulation process, if the result of the data accumulation exceeds the range that can be represented by its data format, an overflow error will occur, which is a typical numerical error. Different data formats (such as unsigned integers, signed integers, floating-point numbers, etc.) handle overflow in different ways, but they all affect the accuracy of the calculation.
[0059] To this end, the present invention provides an accumulator and a method and computing device for the accumulator, which reduce the calculation error caused by data format restrictions and improve the accuracy of the accumulation calculation during the data accumulation process. According to an embodiment, by comparing and judging the second accumulation result data with the first accumulation result number, and coordinating the first feedback control signal to correct the data format range of the accumulation data result of the external input data, the final accumulation result is kept within the data format range, reducing the error caused by exceeding the data format range during the calculation process.
[0060] Exemplary embodiments of the present invention are described below with reference to the accompanying drawings.
[0061] Figure 3 A device architecture diagram of an accumulator according to an example is shown.
[0062] See also Figure 3 According to an exemplary embodiment, an accumulator includes: an addition operation processing unit 01, a cache comparison unit 02, and an accumulation feedback unit 03, wherein:
[0063] The addition operation processing unit 01 receives external input data, first accumulated result data from the cache comparison unit 02, and second accumulated result data from the accumulated feedback unit 03, and selects to perform addition operation on the external input data or the first accumulated result data and the second accumulated result data according to the first feedback control signal from the cache comparison unit 02, and outputs the updated second accumulated result data to the cache output unit 02 and the accumulated feedback unit 03.
[0064] According to some embodiments, the addition operation processing unit 01 implements the accumulation calculation function, and the addition operation processing unit 01 receives external input data, first accumulation result data cached by the cache comparison unit 02, and second accumulation result data from the accumulation feedback unit 03. According to the first feedback control signal from the cache comparison unit 02, the addition operation processing unit 01 selects the external input data or the first accumulation result data as one of the addends to perform an addition operation with the second accumulation result data.
[0065] According to some embodiments, the addition operation processing unit 01 uses the external input data or the first accumulation result data to add the second accumulation result data, and outputs the updated second accumulation result data to the accumulation feedback unit 03, which is then fed back to the addition operation processing unit 01 by the accumulation feedback unit 03 to perform the next accumulation operation.
[0066] According to some embodiments, the addition operation processing unit 01 transmits the updated second accumulation result data to the cache comparison unit 02, and the internal logic of the cache comparison unit 02 determines whether to save the updated second accumulation result data.
[0067] The cache comparison unit 02 receives the updated second accumulation result data from the addition operation processing unit 01, and performs comparison and judgment according to the internal logic. According to the comparison and judgment result, the updated second accumulation result data is cached as the first accumulation result data and a first feedback control signal is output. The first accumulation result data and the first feedback control signal are transmitted to the addition operation processing unit 01.
[0068] According to some embodiments, the cache comparison unit 02 receives the updated second accumulation result data from the addition operation processing unit 01, and compares and judges with the first accumulation result data according to internal logic to determine whether the second accumulation result data has the same sign as the first accumulation data, and the first accumulation data is not 0.
[0069] According to some embodiments, if the second accumulated result data has the same sign as the first accumulated data, and the first accumulated data is not 0, then the accumulation operation of the external data is continued, and the second accumulated result is continued to be updated. If the second accumulated result data has a different sign from the first accumulated data, or the first accumulated data is 0, then the updated second accumulated result data is cached as the first accumulated result data and a first feedback control signal is output, and the first accumulated result data and the first feedback control signal are transmitted to the addition operation processing unit 01.
[0070] According to some embodiments, the first feedback control signal is fed back to the addition operation control unit 01. Under the control of the first feedback control signal, the addition operation unit 01 selects the first accumulation result data in the next cycle signal and sends it to the internal adder.
[0071] The accumulation feedback unit 03 receives the updated second accumulation result data from the addition processing unit 01 , and feeds back the updated second accumulation result data to the addition processing unit 01 and the cache comparison unit 02 .
[0072] According to some embodiments, the accumulation feedback unit 03 receives the updated second accumulation result data from the addition operation processing unit 01, and feeds back the updated second accumulation result data to the addition operation processing unit 01 and the cache comparison unit 02 for cyclic accumulation. The accumulation feedback unit 03 receives the updated second accumulation result data from the addition operation processing unit 01, transmits it to the cache comparison unit 02, and completes the comparison judgment inside the cache comparison unit 02.
[0073] According to some embodiments, after the last external input data is accumulated, the accumulation feedback unit outputs a final accumulation operation result.
[0074] Figure 4 A schematic diagram of an accumulator according to an example is shown.
[0075] See also Figure 4 , according to an example embodiment, an accumulator device, wherein the addition operation processing unit 01 includes a first multiplexer 0101 and an adder 0103, wherein the first multiplexer 0101 is used to receive the external input data and the first accumulation result data, and select the external input data or the first accumulation result data as the first addend according to the first feedback control signal, and output it to the adder 0103; the adder 0103 receives the first addend from the first multiplexer 0101 and the second accumulation result data from the accumulation feedback unit 02, performs an addition operation, and outputs the updated second accumulation result data.
[0076] According to some embodiments, the first multiplexer 0101 receives external input data and first accumulated result data from the cache comparison unit. According to the received first feedback control signal (generated by the cache comparison unit 02), the first multiplexer 0101 selects the external input data or the first accumulated result data as the first addend (i.e., the first addend) in the addition operation. The selected first addend is output to the adder 0103 for the next operation.
[0077] According to some embodiments, the adder 0103 receives the first addend output from the first multiplexer 0101 and the second accumulated result data directly from the accumulated feedback unit 03, and performs an addition operation, and the output is the updated second accumulated result data, which will be sent back to the cache comparison unit 02 and the accumulated feedback unit 03 to form a closed feedback loop, ensuring that the accumulation process can be dynamically adjusted according to the control signal and the previous operation results. Such a design cleverly combines data selection logic with basic arithmetic operations, allowing the accumulator to dynamically select the input source according to real-time needs or the status of previous operations, thereby improving its processing flexibility and adaptability.
[0078] The cache comparison unit includes a comparator, a first counter, a second counter, and a register, wherein the comparator is used to compare the first accumulation result data with the updated second accumulation result when the second counter is updated, and output a first feedback control signal to the addition operation processing unit according to the comparison result;
[0079] The first counter, the second counter and the register are used to perform beat registering on the updated second accumulated data, and the updated second accumulated result data is cached in the register as the first accumulated result data according to the comparison and judgment result of the comparator.
[0080] According to some embodiments, the cache comparison unit 02 includes a comparator 0201, and when the second counter is updated, the comparator 0201 compares two key data items, namely, the current first accumulation result data and the updated second accumulation result data just obtained from the adder 0103. According to the comparison result, the comparator 0201 outputs a first feedback control signal to control the data path selection in the addition operation unit 01.
[0081] According to some embodiments, the cache comparison unit 02 includes a first counter 0203, a second counter 0204, and a register 0202, wherein the first counter works in conjunction with the second counter to count the updated second accumulated result data, and when the second counter is updated, the comparator is triggered to perform a comparison operation. The register 0202 stores the updated second accumulated result data as new first accumulated result data according to the judgment result of the comparator, thereby ensuring the stability and reliability of data flow.
[0082] According to some embodiments, the cache comparison unit 02 provides a flexible and efficient control means for the entire operation processing unit by integrating comparison logic, count control and data cache functions, thereby ensuring the accuracy of data processing and the dynamic response capability of the system.
[0083] According to some embodiments, the cache comparison unit is configured to: when the second counter is updated for the first time, receive the updated second accumulation result data from the addition operation processing unit and cache it to the register 0202, and output it as the first accumulation result data.
[0084] According to some embodiments, before the external input data begins to be accumulated, it is necessary to first divide the external input data into at least three groups according to the total amount of the external input data, each group containing a specific amount of data. Afterwards, according to the amount of each group of data and the total number of groups, a first counter and a second counter are configured, the upper limit value of the first counter is configured to be the number of the specific amount of data in each group minus 1, and the upper limit value of the second counter is configured to be the number of groups minus 1.
[0085] According to some embodiments, when the second counter is updated for the first time, it indicates that the first group of external input data has completed accumulation. At this time, the cache comparison unit 02 will receive the updated second accumulation result data from the addition operation processing unit 01. The updated second accumulation result data will be cached in the register 0202, ensuring the continuity of the data flow and the iteration of the accumulation process. After each group of data is processed, it can continue to accumulate based on the accumulation result of the previous group. Such a configuration enables the cache comparison unit 02 to not only effectively manage the data flow and process in groups on demand, but also accurately control the rhythm of the accumulation operation and the timing of data update, ensuring the efficiency and accuracy of the accumulation process, and is particularly suitable for complex application environments that require detailed control of the data processing process.
[0086] According to some embodiments, the cache comparison unit is further configured to: when the second counter is subsequently updated, compare the first accumulation result data with the updated second accumulation result data; if the first accumulation result data and the updated second accumulation result data have the same sign and the first accumulation result data is not zero, then accumulate the next set of accumulation data and continue to update the second accumulation result data; otherwise, add the first accumulation result and the second accumulation result, and apply the calculation result to update the first accumulation result data in the register 0202, and output the first feedback control signal.
[0087] For example, when the second counter is updated again after the first update, the comparator will compare the value of the first cumulative result data currently stored in 0202 with the updated second cumulative result transmitted from the addition operation processing unit. If the first cumulative result data has the same sign as the updated second cumulative result (i.e., both are positive or both are negative) and the first cumulative result is not zero, then the accumulation of the next set of cumulative data will continue, i.e., more data will continue to be accumulated on the current second cumulative result to maintain the accumulation trend. On the contrary, if the first cumulative result data has a different sign from the updated second cumulative result, or the first cumulative result is zero, then the first cumulative result is added to the second cumulative result, and the newly calculated cumulative result is applied to update the first cumulative result data stored in register 0202 to ensure the continuity and accuracy of the data. At the same time, the first feedback control signal is output to the addition operation processing unit to control the next addition operation processing unit 02 to select the correct data as the first addend. Such a configuration can dynamically adjust the accumulation strategy according to the trend and characteristics of the accumulated data, and adjust the data range of the accumulated intermediate results, which can minimize the errors caused by the calculation results exceeding the data format range.
[0088] According to some embodiments, the accumulation feedback unit 03 includes: a second multiplexer 0301, the second multiplexer 0301 receiving the updated second accumulation result data and a specific low-level control signal from the addition operation processing unit. When the second counter is updated, the second multiplexer 0301 selects a low-level input to clear the second accumulation result data to start the accumulation of the next set of external input data.
[0089] Figure 5 A flow chart of a method for an accumulator according to an example is shown.
[0090] See also Figure 5 , according to an example embodiment a method for an accumulator, comprising:
[0091] In S501, the total amount of external input data is obtained and divided into at least three groups, each group including a specific amount of data, and the data is sequentially input into the accumulator as described above in groups.
[0092] According to some embodiments, before accumulation is performed, the total amount of external input data is first obtained. Based on the total amount of data, the data is divided into at least three groups, each of which contains a specific amount of data, which may be determined based on factors such as memory capacity, processing speed, and algorithm requirements. A reasonable grouping strategy can avoid the problem of memory overflow caused by excessive data processing at a single time. After grouping is completed, the data is input into the accumulator having the functional structure as described above in order and the accumulation operation is performed.
[0093] In S503, an accumulation operation is performed on the first group of accumulated data, and the accumulated result of the first group is saved as first accumulated result data.
[0094] According to some embodiments, an accumulation operation is performed on the first group of data, and the external input data in the first group are accumulated one by one until the last data in the group is input into the above-mentioned accumulator. At this time, the corresponding accumulation result of the first group is obtained, that is, the updated second accumulation result data output by the adder in the accumulator at this time, and it is saved as the first accumulation result data.
[0095] In S505, an accumulation operation is performed on the second group of accumulated data, and the accumulated result of the second group is the updated second accumulated result data.
[0096] According to some embodiments, an accumulation operation is performed on the second group of data, which is the same as the accumulation operation of the first group of accumulated data, and the second group of accumulated data is directly sent to the accumulator to obtain the accumulation result of the second group of data, that is, the updated second accumulation result data output by the adder in the accumulator at this time.
[0097] According to some embodiments, when a first group of accumulated data is input into the accumulator, a first counter and a second counter in the accumulator begin to count the input data, wherein the first counter is used to count the number of data in each group, and the second counter is used to count how many groups of data are currently input. When the second counter is updated, it is selected to save the updated second accumulated result data as the first accumulated result data or to compare the updated second accumulated result data with the first accumulated result data. Based on the comparison result, it is determined whether to add the updated second accumulated result data to the first accumulated result data, and the calculation result is applied to update the first accumulated result data.
[0098] In S507, the first cumulative result data is compared with the updated second cumulative result data. If the two have the same sign and the first cumulative result data is not zero, a third set of cumulative data is accumulated and the second cumulative result data is continued to be updated. Otherwise, the first cumulative result data is added to the updated second cumulative result data, and the calculation result is applied to save and update the first cumulative result data.
[0099] According to some embodiments, the first cumulative result data and the updated second cumulative result data are compared to see whether their signs are the same (positive or negative) and whether the first cumulative result data is not zero. If the two have the same signs and the first cumulative result is not zero, this means that the accumulation process maintains the original increase or decrease trend. In this case, the system directly accumulates the third set of data without immediately adding the first cumulative result data and the second cumulative result data. This may be done to keep the cumulative data result within the current digital format range and not to increase suddenly and exceed the current digital format position. Especially when processing a data sequence with an obvious trend, this approach can reduce the error caused by the cumulative result exceeding the current digital format range.
[0100] According to some embodiments, if the first cumulative result data and the updated second cumulative result data have different signs, or the first cumulative result is zero, this usually indicates that the data trend has changed. At this time, the cumulative result needs to be integrated so that the final cumulative result can be offset within the digital format range. At this time, the accumulator will add the first cumulative result data and the updated second cumulative result data, and then use this new cumulative result to update the first cumulative result data. In this way, the digital format range of the intermediate result of the accumulation process is adjusted to adapt to data changes, reduce the cumulative calculation error, and ensure the accuracy of the cumulative result.
[0101] According to some embodiments, the method of the present invention improves the ability of the accumulator to process complex data sequences and reduces the accumulation calculation error by intelligently controlling the accumulation process, monitoring and analyzing data trends, and adjusting the accumulation strategy in a timely manner.
[0102] In S509, the last group of data to be accumulated is sequentially input according to the above method to complete the accumulation.
[0103] According to some embodiments, according to the above method, the accumulator will continue to perform the accumulation operation until all data groups are processed in sequence, completing the entire accumulation process.
[0104] According to some embodiments, after completing the accumulation of the second group of data and the corresponding logic processing, the accumulator will enter a loop or iteration phase, and perform accumulation operations on each of the remaining groups of data in turn according to the established grouping order. Before each accumulation, the comparison logic will be repeatedly executed, that is, the sign of the current accumulation result and the new group of accumulation results (that is, the updated first accumulation result data or the updated second accumulation result data) will be compared, and whether the accumulation result is zero will be checked, that is, after each group of data is accumulated, it will be decided based on the sign and non-zeroness of the accumulation result whether to directly accumulate the next group of data (maintain the accumulation trend) or to add the current accumulation result to the new accumulation result and then update the accumulation base value (adjust the accumulation trend or process the turning point) until the last data group is processed. The result of each accumulation will be properly processed and updated according to the comparison logic to ensure that the accumulation process can be carried out efficiently and accurately reflect the overall trend of the data.
[0105] In S511, the updated second accumulation result data after the accumulation is completed is output as the final result of the accumulation calculation.
[0106] According to some embodiments, when all data groups are accumulated, the final accumulation result, that is, the updated second accumulation result data obtained after the last accumulation, will be output as the final result of the accumulation calculation of the entire data set.
[0107] Based on the accumulator and the method for the accumulator as described above, the specific solution of the present invention is further explained by example. Assume that there are 15 external input data in total, named A1, A2, A3, ..., A15 respectively. According to the solution of the present invention, the 15 data are divided into 3 batches, each batch of 5 data. Figure 4 The accumulator structure example in , where the first counter is responsible for counting the number of each batch of data, with a value range of 0 to 4 (the maximum value is configurable, and can be configured as the amount of data in each batch - 1). The second counter is responsible for counting the data batches, with a value range of 0 to 2 (the maximum value is configurable, and can be configured as the total batches - 1). Assuming that the addition calculation takes 1 clock cycle, the entire calculation process can be seen in Table 1 below.
[0108] Table 1 Accumulator accumulation process table according to an example embodiment
[0109]
[0110] In the 11th clock cycle, the accumulated result B of the second batch of data is obtained, and B and C are compared. If they have the same sign and C is not equal to 0, B and C are not added, C is kept unchanged, B continues to be accumulated with A, and the calculation process is then carried out according to branch a (11a~17a); otherwise, B and C are added, and the calculation process is then carried out according to branch b (11b~18b).
[0111] As can be seen from Table 1, no matter whether branch a or branch b is taken, the final cumulative result is in the form of A1+A2+A3+A4+A5+A6+A7+A8+A9+A10+A11+A12+A13+A14+A15, which is consistent with the hard accumulation expression, so it is equivalent from a mathematical point of view. However, due to the batch and deferred accumulation, the result value of this design and the hard accumulation may not be equal.
[0112] Among them, branch a chooses to keep C and add it later. The complete calculation is equivalent to calculating ①A1+A2+A3+A4+A5 first, then calculating ②A6+A7+A8+A9+A10+A11+A12+A13+A14+A15, and finally calculating ③(A1+A2+A3+A4+A5)+(A6+A7+A8+A9+A10+A11+A12+A13+A14+A15). The hard calculation is to calculate ①A1+A2+A3+A4+A5 first, and then calculate ②(A1+A2+A3+A4+A5)+A6+A7+A8
[0113] +A9+A10, and finally calculate ③((A1+A2+A3+A4+A5)+A6+A7+A8+A9+A10)+A11+A12+A13
[0114] +A14+A15.
[0115] The difference in the calculation results of the two can be illustrated with an example. Suppose there is a floating-point number that can only represent a maximum range of -10 to +10. Any number greater than +10 can only be represented by +11 (in the real floating-point representation, it is +∞, positive infinity. To facilitate understanding of the error, this example uses +11 instead), and any number less than -10 can only be represented by -11 (in the real floating-point representation, it is -∞, negative infinity). Suppose A1~A10 are all +2, and A11~A15 are all -2. The new design is to first calculate ①A1+A2+A3+A4+A5=+10, then calculate ②A6+A7+A8+A9+A10+A11+A12+A13+A14+A15=0, and finally calculate ③(A1+A2+A3+A4+A5)
[0116] +(A6+A7+A8+A9+A10+A11+A12+A13+A14+A15)=+10+0=+10, which is within the reasonable numerical range and consistent with the theoretical calculation results. However, the hard calculation is to first calculate ①A1+A2+A3+A4+A5=+10, then calculate ②(A1+A2+A3+A4+A5)+A6=+10+2=+11, and it is still +11 when added to A10, and finally calculate ③((A1+A2+A3+A4+A5)+A6+A7+A8+A9+A10)+A11+A12+A13+A14+A15=+11+A11+A12+A13+A14+A15=+1, which has a large error with the theoretical result.
[0117] Branch b chooses to add B and C first, that is, to add a positive number and a negative number or to add B to 0 (because any number added to 0 is itself, so there is no need to keep 0 until later like branch a). If B is a positive number and C is a negative number, obviously B+C will become smaller and will not make the result B bigger and bigger, that is, B will be further away from +∞. Similarly, if B is a negative number and C is a positive number, the result B will be further away from -∞. If C is 0, B+C is still B, no effect. Like the purpose of branch a, branch b is also to reduce the probability of the result being close to the boundary of valid data during the calculation process and reduce the final error.
[0118] In summary, no matter branch a or branch b, once an intermediate result exceeds the valid range, the final result will be inaccurate. Obviously, hard calculation is definitely inaccurate at this time. In this case, if you want to reduce the error, you can increase the data batches, divide the total data into more batches, and reduce the probability of exceeding the valid range. You can even increase the number of registers to store more previous results, which makes the design more flexible, the final result more accurate, and the calculation error smaller.
[0119] To summarize, the data to be accumulated is divided into multiple batches, and two accumulated results are obtained by accumulating in batch order, one is the previous result and the other is the current result. By comparing the two results, two branches can be obtained. Branch a, if the previous result and the current result have the same sign and the previous result is not 0, the previous result is retained, and the current result is continued to be accumulated with the input. After the next batch of data is accumulated, the current result is compared with the previous result again. Branch b, if the previous result and the current result have different signs or the previous result is 0, the previous result and the current result are immediately added, and updated to the latest current result, and then the current result is saved as the previous result, and the input is accumulated again. After the next batch of data is accumulated, the current result is compared with the previous result again. No matter which branch is taken, the calculation can be looped to complete the accumulation of all data. Moreover, compared with hard calculation, batch calculation can reduce the probability of a small amount of data being added beyond the valid range. Delaying the accumulation of previous results can also reduce the probability of addition exceeding the valid range and reduce calculation errors.
[0120] When the total amount of the external input data does not meet the grouping requirement, zeros are added after the external input data to make up the total amount.
[0121] According to some embodiments, if the total amount of external input data cannot divide the predetermined grouping size, resulting in the last group of data being less than the required number of groupings, the grouping can be completed by padding zeros at the end of the last group of data. This allows the data amount of all groups to be consistent, facilitating subsequent parallel processing or the application of algorithms in a unified format. For example, if the grouping requirement is that each group has 5 data, and there are 23 data in total, then the last group will only have 3 data. In order to meet the grouping requirement, we will add 2 zeros at the end so that the last group also reaches 5 data.
[0122] When the external input data is constant, increasing the number of groups can improve the accuracy of the accumulation result.
[0123] According to some embodiments, when the total amount of the external input data is constant, increasing the number of groups can improve the accuracy of the accumulated result, especially in floating-point operations, where conventional accumulation methods may introduce tiny rounding errors in each operation. When the amount of data is large, these small errors may accumulate, causing the final result to deviate from the true value. By applying the method and the accumulator of the present invention, the data is divided into more groups for accumulation, and the amount of data accumulated each time is reduced, which can minimize the error margin of a single accumulation, thereby reducing the cumulative error.
[0124] Each time the first accumulated result data is updated and saved, the updated second accumulated data is cleared.
[0125] According to some embodiments, each time the first accumulated result data is updated and saved, the updated second accumulated data is cleared to set a new starting point for the next set of data accumulation (i.e., accumulation starts from zero). In the accumulation process of the scheme of the present invention, each time the first accumulated result data is updated, the updated second accumulated data is reset to ensure the independence of each set of accumulated data and avoid direct accumulation interference between different sets of data. This mechanism can simplify the control logic, allowing the system to focus more on the processing of the current data segment without the need to continuously track the data accumulation status across segments.
[0126] According to some embodiments, clearing the updated second accumulated data can limit the accumulation of digital format range errors and avoid potential digital format range accumulation caused by the accumulation of a large amount of data.
[0127] Figure 6 A detailed step diagram of a method for an accumulator according to an example is shown.
[0128] See also Figure 6 , according to the example, the detailed step diagram of the method for the accumulator includes: in S1, the total amount of external input data is determined and divided into N batches, N≥3, and each batch has M data. Obviously, it should be divided into at least 3 batches, because only 1 batch becomes a hard calculation, and there is no difference between dividing into 2 batches and dividing into 1 batch. If the actual total amount of data is less than N*M, you can continue to input multiple 0s after the last data to make up N*M, or count the amount of input data in the accumulator, and after the actual amount is reached, the accumulator accumulates multiple 0s to make up N*M.
[0129] In S2, the software configures the maximum count value of counter1 to M-1 and the maximum count value of counter2 to N-1. After that, the data to be accumulated are input one by one in batch order and accumulated with the current result. The first input data of this batch is added with 0. Other subsequent detailed steps have been described in the above method and will not be repeated here.
[0130] According to some embodiments, in the solution of the present invention, all external input data are grouped and accumulated. Group calculation can reduce the probability that the intermediate accumulation result data exceeds the valid range and reduce the calculation error caused by exceeding the digital format range.
[0131] According to some embodiments, in the solution of the present invention, by comparing and judging the second accumulated result data with the first accumulated result number, and coordinating the first feedback control signal to correct the data format range of the accumulated data result of the external input data, the probability of the addition result exceeding the valid range can be reduced, and the calculation error can be reduced. In addition, the solution of the present invention only adds a small number of new components, consumes less hardware resources, and has low improvement costs.
[0132] Figure 7A block diagram of a computing device according to an example embodiment of the invention is shown.
[0133] like Figure 7 As shown, computing device 30 includes processor 12 and memory 14. Computing device 30 may also include bus 22, network interface 16, and I / O interface 18. Processor 12, memory 14, network interface 16, and I / O interface 18 may communicate with each other via bus 22.
[0134] The processor 12 may include one or more general-purpose CPUs (Central Processing Units, processors), microprocessors, or application-specific integrated circuits, etc., for executing relevant program instructions. According to some embodiments, the computing device 30 may also include a high-performance graphics card (GPU) 20 for accelerating the processor 12.
[0135] The memory 14 may include a machine system readable medium in the form of a volatile memory, such as a random access memory (RAM), a read-only memory (ROM) and / or a cache memory. The memory 14 is used to store one or more programs including instructions and data. The processor 12 may read the instructions stored in the memory 14 to execute the above-mentioned method according to the embodiment of the present invention.
[0136] The computing device 30 may also communicate with one or more networks via the network interface 16. The network interface 16 may be a wireless network interface.
[0137] The bus 22 may include an address bus, a data bus, a control bus, etc. The bus 22 provides a path for exchanging information between components.
[0138] It should be noted that, in the specific implementation process, the computing device 30 may also include other components necessary for normal operation. In addition, those skilled in the art may understand that the above device may only include components necessary for implementing the embodiments of this specification, and need not include all components shown in the figure.
[0139] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above method when the program is executed by a processor. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), a network storage device, a cloud storage device, or any type of medium or device suitable for storing instructions and / or data.
[0140] An embodiment of the present invention also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute part or all of the steps of any method recorded in the above method embodiments.
[0141] Those skilled in the art can clearly understand that the technical solution of the present invention can be implemented with the help of software and / or hardware. "Unit" and "module" in this specification refer to software and / or hardware that can independently complete or cooperate with other components to complete specific functions, where the hardware can be, for example, a field programmable gate array, an integrated circuit, etc.
[0142] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described order of actions, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0143] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0144] In the several embodiments provided by the present invention, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0145] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0146] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0147] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention.
[0148] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0149] The exemplary embodiments of the present invention are specifically shown and described above. It should be understood that the present invention is not limited to the detailed structure, configuration or implementation method described herein; on the contrary, the present invention is intended to cover various modifications and equivalent configurations included in the spirit and scope of the attached clauses.
Claims
1. An accumulator, characterized in that: include: Addition processing unit, cache comparison unit, accumulation feedback unit, wherein, The addition operation processing unit receives external input data, first accumulated result data from the cache comparison unit cache, and second accumulated result data from the accumulated feedback unit, and selects to perform an addition operation on the external input data or the first accumulated result data and the second accumulated result data according to a first feedback control signal from the cache comparison unit, and outputs the updated second accumulated result data to the cache comparison unit and the accumulated feedback unit; The cache comparison unit receives the updated second accumulation result data from the addition operation processing unit, and performs comparison and judgment according to the internal logic. According to the comparison and judgment result, the updated second accumulation result data is cached as the updated first accumulation result data and outputs the first feedback control signal. The first accumulation result data and the first feedback control signal are transmitted to the addition operation processing unit. The cache comparison unit includes a first counter, a second counter and a comparator, the first counter and the second counter are used to count the external input data in groups, the first counter is used to count the number of data in each group, and the second counter is used to count how many groups of data are currently input, and the comparator is used to compare the first accumulation result data with the updated second accumulation result data when the second counter is updated, and output the first feedback control signal to the addition operation processing unit according to the comparison result; The accumulation feedback unit receives the updated second accumulation result data from the addition operation processing unit or clears the second accumulation result data to zero, and feeds back the updated second accumulation result data to the addition operation processing unit; Wherein, the addition operation processing unit includes a first multiplexer and an adder, The first multiplexer is used to receive the external input data and the first accumulated result data, and select the external input data or the first accumulated result data as the first addend according to the first feedback control signal, and output it to the adder; The first accumulated result data is 0 or cached second accumulated result data, and the second accumulated result data is a calculation result output by the addition operation processing unit.
2. The accumulator according to claim 1, characterized in that The adder receives the first addend from the first multiplexer and the second accumulation result data from the accumulation feedback unit, performs an addition operation, and outputs the updated second accumulation result data.
3. The accumulator according to claim 1, characterized in that The cache comparison unit also includes a register, wherein: The first counter, the second counter and the register are used to perform beat registering on the updated second accumulated data, and the updated second accumulated result data is cached in the register as the first accumulated result data according to the comparison and judgment result of the comparator.
4. The accumulator according to claim 3, characterized in that The cache comparison unit is configured as follows: When the second counter is updated for the first time, the updated second accumulation result data is received from the addition operation processing unit and cached in the register, and output as the first accumulation result data.
5. The accumulator according to claim 4, characterized in that The cache comparison unit is further configured as: When the second counter is subsequently updated, comparing the first accumulation result data with the updated second accumulation result data; If the first accumulation result data and the updated second accumulation result data have the same sign and the first accumulation result data is not zero, then perform accumulation of the next group of accumulation data and continue to update the second accumulation result data; Otherwise, the first accumulated result is added to the second accumulated result, and the calculation result is applied to update the first accumulated result data in the register, and the first feedback control signal is output.
6. The accumulator according to claim 1, characterized in that: The accumulation feedback unit includes: a second multiplexer, used for sending the updated second accumulation result data to the addition operation processing unit.
7. A method for an accumulator, characterized in that include: Obtaining a total amount of external input data and dividing it into at least three groups, each group including a specific amount of input data, and sequentially inputting the groups into an accumulator as described in any one of claims 1 to 6; Performing an accumulation operation on the first group of input data, and saving the accumulation result of the first group as first accumulation result data; Performing an accumulation operation on the second group of input data, using the accumulation result of the second group as updated second accumulation result data; Comparing the first accumulated result data with the updated second accumulated result data, if the two have the same sign and the first accumulated result data is not zero, accumulating a third group of accumulated data and continuing to update the second accumulated result data, otherwise adding the first accumulated result data with the updated second accumulated result data, and applying the calculation result to save and update the first accumulated result data; According to the above method, input the last group of data to be accumulated in sequence to complete the accumulation; The updated second accumulation result data after the accumulation is completed is output as the final result of the accumulation calculation.
8. The method according to claim 7, characterized in that When the total amount of the external input data does not meet the grouping requirement, zeros are added after the external input data to make up the total amount.
9. The method according to claim 7, characterized in that: When the total amount of the external input data is constant, increasing the number of groups can improve the accuracy of the accumulation result.
10. The method according to claim 7, characterized in that Each time the first accumulated result data is updated and saved, the updated second accumulated result data is cleared.
11. A computing device, characterized in that: include: processor; as well as A memory storing a computer program, which, when executed by the processor, enables the processor to perform the method according to any one of claims 7 to 10.
Citation Information
Patent Citations
Fixed-point operation method and device for convolutional neural network, equipment and storage medium
CN109409514A
Accumulator and operation method thereof
CN110647308A
Floating point accumulation device and method and computer storage medium
CN113168308A
Approximate precoding convolution operation method and system based on Booth algorithm
CN115982528A
Accumulator, method and chip circuit for accumulator, and computing device
CN117170622A
