A method, device and storage medium for accumulating image data
By dividing the image data into multiple data groups and adjusting the accumulation order, the problem of accuracy loss in floating-point accumulation operations is solved, and high-precision accumulation operations are realized without increasing computational complexity or memory consumption.
Patent Information
- Application Number
- CN202011411000.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-04
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2040-12-04
AI Technical Summary
In floating-point number accumulation operation, due to the problem of large numbers eating decimals, the accuracy is lost, and the prior art is difficult to achieve accuracy compensation while ensuring performance.
By dividing the image data into multiple data groups and adjusting the accumulation order of data in the data group, we ensure that data of the same order of magnitude are added each time, thereby avoiding the situation where large numbers eat decimals.
It effectively solves the problem of precision overflow in accumulated scenarios, maintains the simplicity and performance of calculation operations, and avoids additional memory consumption and increased computational complexity.
Smart Images

Figure CN114596184B_ABST
Abstract
Description
Technical Field
[0001] The present invention generally relates to the field of computers and more particularly to a method, device and storage medium for floating point number accumulation operations. Background Art
[0002] With the development of computer technology, neural networks are increasingly being used in the processing of audio, video and other data, especially image data. In related technologies, the amount of data operations is also increasing, and accumulation operations are widely used in various neural network operators. However, the biggest problem in accumulation operations is that floating-point data loses precision during the accumulation process due to the problem of large numbers eating up small numbers.
[0003] Therefore, there is an urgent need for a precision compensation method that can achieve similar effects while ensuring performance. Summary of the invention
[0004] In order to at least partially solve the technical problems mentioned in the background technology, the solution of the present invention provides a method, a device and a readable storage medium for accumulating image data.
[0005] In one aspect, the present invention discloses a method for accumulating image data, the method comprising: acquiring multiple image data to form a data group; sorting the data in the data group according to numerical values; adding the data with the largest value to the data with the smallest value, and adding the data with the second largest value to the data with the second smallest value in the data group, and adding the data in pairs according to this rule to obtain multiple intermediate data; updating the data group according to the multiple intermediate data; wherein the sorting, adding and updating steps are repeatedly performed with the updated data group until only one intermediate data is generated in the adding step, and the intermediate data is the accumulation result of the data group.
[0006] In another aspect, the present invention discloses a device for calculating and accumulating image data, the device comprising: an acquisition module for acquiring multiple image data to form a data group; a sorting module for sorting the data in the data group according to the size of the values; a calculation module for adding the data with the largest value to the data with the smallest value, and the data with the second largest value to the data with the second smallest value in the data group, and adding the data in pairs according to this rule to obtain multiple intermediate data; an updating module for updating the data group according to the multiple intermediate data; wherein the sorting, adding and updating steps are repeatedly performed with the updated data group until only one intermediate data is generated in the adding step, and the intermediate data is the accumulation result of the data group.
[0007] In another aspect, the present invention discloses a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processing device, the aforementioned method is executed.
[0008] The present invention divides the image data into multiple data groups, and by adjusting the order of data accumulation in the data groups, no additional memory consumption is required, and the entire calculation operation is still only a one-step addition operation, so it will not lead to an increase in computational complexity and will not reduce the performance of the entire algorithm. Most importantly, the present invention adjusts the order of accumulation to ensure that data of the same order of magnitude are added each time accumulation is performed, and there will be no situation where large numbers eat up small numbers, thereby effectively solving the problem of precision overflow in the accumulation scenario. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0010] Figure 1 is a schematic diagram showing the structure of a board according to an embodiment of the present invention;
[0011] Figure 2 is a structural diagram showing an integrated circuit device according to an embodiment of the present invention;
[0012] Figure 3 A flow chart showing a method for accumulating data graphs according to an embodiment of the present invention; and
[0013] Figure 4 Schematic diagram of an apparatus according to an embodiment of the present invention. DETAILED DESCRIPTION
[0014] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0015] It should be understood that the terms "first", "second", "third" and "fourth" etc. in the claims, specifications and drawings of the present invention are used to distinguish different objects rather than to describe a specific order. The terms "include" and "comprise" used in the specification and claims of the present invention indicate the presence of the described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.
[0016] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the claims, the singular forms of "a", "an" and "the" are intended to include the plural forms unless the context clearly indicates otherwise. It should also be further understood that the term "and / or" used in the specification of the present invention and the claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.
[0017] As used in this specification and claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context.
[0018] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0019] Figure 1 FIG. 1 is a schematic diagram showing the application scenario of the present invention, and is a schematic diagram of the structure of a board 10. Figure 1 As shown, the board 10 includes a chip 101, which is a system-on-chip (SoC), or a system on a chip, integrated with one or more combined processing devices, which are artificial intelligence computing units that support various deep learning and machine learning algorithms, such as image segmentation algorithms, video encoding and decoding algorithms, etc., to meet the intelligent processing needs in complex scenarios in the fields of computer vision, speech, natural language processing, data mining, etc. In particular, deep learning technology is widely used in the field of cloud intelligence. A notable feature of cloud intelligence applications is the large amount of image data, which places high demands on the storage capacity and computing power of the platform. The board 10 of this embodiment is suitable for cloud intelligence applications and has huge off-chip storage, on-chip storage, and powerful computing power.
[0020] The chip 101 is connected to an external device 103 via an external interface device 102. The external device 103 is, for example, a server, a computer, a camera, a display, a mouse, a keyboard, a network card, or a wifi interface. The data to be processed can be transmitted from the external device 103 to the chip 101 via the external interface device 102. The calculation result of the chip 101 can be transmitted back to the external device 103 via the external interface device 102. According to different application scenarios, the external interface device 102 can have different interface forms, such as a PCIe interface.
[0021] The board 10 also includes a storage device 104 for storing data, such as video sequences, image data, etc., which includes one or more storage units 105. The storage device 104 is connected to the control device 106 and the chip 101 through a bus and transmits data. The control device 106 in the board 10 is configured to control the state of the chip 101. To this end, in an application scenario, the control device 106 may include a single-chip microcomputer (Micro Controller Unit, MCU).
[0022] Figure 2 1 is a block diagram showing the combined processing device in the chip 101 of this embodiment. Figure 2 As shown in , the combined processing device 20 includes a computing device 201 , an interface device 202 , a processing device 203 and a DRAM 204 .
[0023] The computing device 201 is configured to execute user-specified operations, and is mainly implemented as a single-core intelligent processor or a multi-core intelligent processor to perform deep learning or machine learning calculations. It can interact with the processing device 203 through the interface device 202 to jointly complete the user-specified operations.
[0024] The interface device 202 is used to transmit data and control instructions between the computing device 201 and the processing device 203. For example, the computing device 201 can obtain input video image data from the processing device 203 via the interface device 202 and write it into the storage device on the computing device 201 chip. Further, the computing device 201 can obtain control instructions from the processing device 203 via the interface device 202 and write them into the control cache on the computing device 201 chip. Alternatively or optionally, the interface device 202 can also read data in the storage device of the computing device 201 and transmit it to the processing device 203.
[0025] The processing device 203 is a general processing device that performs basic controls including but not limited to data handling, starting and / or stopping the computing device 201. Depending on the implementation, the processing device 203 can be a central processing unit (CPU), a graphics processing unit (GPU) or one or more types of processors in other general and / or special processors, which include but are not limited to digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs. As mentioned above, only with respect to the computing device 201 of the present invention, it can be regarded as having a single-core structure or a homogeneous multi-core structure. However, when the computing device 201 and the processing device 203 are integrated and considered together, the two are regarded as forming a heterogeneous multi-core structure.
[0026] DRAM 204 is used to store data to be processed, and is a DDR memory, which is usually 16G or larger in size and is used to store data of the computing device 201 and / or the processing device 203 .
[0027] Accumulation operations are widely used in various neural network operators, such as softmax, batchnorm, l1loss, 2loss, reduce sum operators, etc. The basic process of accumulation operation is: sum = A1 + A2 + A3 + ... + An, where A1, A2, A3 ... An are floating-point operation data, and sum represents the accumulation result of floating-point data.
[0028] Cumulative operations are very common in neural network applications, such as the convolutional neural network (CNN network) that is widely used in image classification tasks. Generally, when training a network, the neural network adjusts the parameters of each layer by inputting training samples, so that the results calculated by the neural network are as close as possible to the actual results. Neural network training includes forward propagation and back propagation. Forward propagation is based on the existing model. The input training samples are calculated through each layer of the neural network, and the input feature map is gradually extracted as abstract features. Back propagation is based on the loss function calculated based on the forward propagation result and the true value. The gradient descent method is used to calculate the partial derivative of the loss function for each parameter through the chain rule to update the parameters. Then the updated parameters are used for training, and this is repeated many times until the forward propagation calculation results meet expectations.
[0029] In this embodiment, one generation of training (epoch) refers to the process of using all training samples for one training. The set of these training samples is the training set, and each training batch size (batchsize) of training samples is an iteration. For example, if the training set has 1000 training samples and the batch size is set to 10, then each iteration requires 10 training samples to participate in the training, and there are 100 iterations in one generation of training. In practice, the training of the neural network model may go through multiple generations of training. The last layer will calculate the loss function. Taking the commonly used loss function as L2Loss as an example, the core operation is cumulative summation, and the scale of the accumulated data is large, generally with a data volume of more than one billion.
[0030] For such large-scale data accumulation, if the normal accumulation operation is used, in the end, a value of hundreds of millions plus a decimal of a few tenths will appear, and then the precision loss of the large number will occur. The so-called large number eating the decimal means that when two numbers with a large difference are added, the mantissa after the decimal point of the decimal is easily truncated, resulting in precision error. For example, when two floating-point numbers are added, they are 32-bit data, and their precision is 6-7 digits after the decimal point. Specifically, the representation method of floating-point numbers is float: 2^23=8388608, a total of seven digits, which means that there can be a maximum of 7 significant digits, but the numerical precision can be guaranteed to be 6 digits, that is, the precision of the floating-point number is 6 to 7 significant digits. Assume two floating point numbers: a = 123456, b = 2.189; a + b should be 123458.189, but because the precision is only 6-7 decimal places, the result of 123458.189 will not be obtained. The 89 at the end may be truncated. In more detail, the percentile 8 may not be truncated, but the thousandth 9 will definitely be truncated. It can be seen that one addition has produced an error of at least 0.009. If 1000 such additions are performed, the error will be 9, which is obviously unacceptable. Therefore, in floating point accumulation operations, precision compensation is required.
[0031] If the common Kahan accumulation algorithm is used, first of all, Kahan needs to occupy 4 blocks of memory space, of which 3 blocks are used to store intermediate temporary variables, and only one block is used to store valid data, which wastes memory space. Secondly, from the calculation formula of Kahan, to complete the entire Kahan algorithm, it involves 3 calculation operations and 1 copy operation. Compared with the original one-step addition calculation operation, the Kahan algorithm increases the complexity of the calculation. In the hardware scenario with a calculation bottleneck, the Kahan algorithm means that the performance of the entire algorithm is reduced by a quarter.
[0032] Specifically, the drawback of the Kahan sum algorithm is that it requires three intermediate variables c, y, and t to save intermediate results. This drawback is not prominent in scalar calculations, but in the vector calculation process, three on-chip spaces equal to the input data size need to be set to save intermediate variables. Since the Kahan algorithm requires three additional spaces to save intermediate variables, for an input data size, the Kahan algorithm has 3 corresponding intermediate variables for one input data size, so the space needs to be divided into 4 parts, but only one of them is actually used to save the calculation data, which means that the on-chip space available for storing input data is reduced by three quarters. For parallel computing, on-chip space means computing performance to some extent, which directly leads to a quarter reduction in computing performance.
[0033] By adjusting the accumulation order, the present invention does not require additional memory consumption, and the entire calculation operation is still only a one-step addition operation, so it will not lead to an increase in computational complexity and will not reduce the performance of the entire algorithm. Most importantly, by adjusting the accumulation order, the present invention ensures that data of the same order of magnitude are added each time accumulation is performed, and there will be no situation where large numbers eat up small numbers, thereby effectively solving the problem of precision overflow in the accumulation scenario.
[0034] This embodiment provides a solution for accumulating image data based on the aforementioned hardware environment.
[0035] Figure 3 A flow chart of a method for data graph accumulation according to an embodiment of the present invention is shown. The method is applied to a single or multiple processor cores in the board 10 or the combined device 20 described above.
[0036] Step 301, obtain multiple image data to form a data group. When using a neural network to process data, first pre-process the large amount of data obtained to form a data group. Among them, step 301 includes:
[0037] Step 302: Classify the plurality of image data into at least one level group according to the order of magnitude.
[0038] Among them, the order of magnitude refers to the scale of the quantity or the level of size, and a fixed ratio is maintained between each level. Commonly used ratios are 10, 2, 1000, and 1024. If there is no special mark, scientific notation is generally used, and the order of magnitude is based on 10 (how many powers of 10). For example: 1.0e9 represents 10 to the 9th power, and the order of magnitude is 9; 1.0e-6 represents 10 to the negative 6th power, and the order of magnitude is -6; 3.2e8 represents 3.2 times 10 to the 8th power. Classifying image data according to order of magnitude means that image data of the same order of magnitude are divided into the same level group, and image data of different orders of magnitude are divided into different level groups. For example, a group of image data is all 1.ne9, and n represents a positive integer. Then the order of magnitude of this group of image data is 9, which is the same order of magnitude, and this group of image data is divided into a level group. For example, in another set of image data, including 1.ne3, 1.me9, 1.pe6, where n, m, and p are all positive integers, this set of data includes data with orders of magnitude of 3, 9, and 6. According to the order of magnitude, this set of data can be divided into three level groups, namely, level groups with orders of magnitude of 3, 9, and 6.
[0039] Step 303: Determine whether all the class groups have been designated. Designation means that the divided class groups are designated as data groups, and subsequent calculations are performed on each data group. Class groups that have been designated will not be designated again.
[0040] If there are still unassigned level groups among all the level groups, then step 304 is executed to designate one of the at least one level group as the data group. There is no limitation on the method of designating the level group. The level group can be designated randomly or in a certain order according to the actual situation, such as from large to small in terms of order of magnitude, or according to the parity of order of magnitude, etc. For example, a group of image data is divided into six level groups, namely level group one, level group two, level group three, level group four, level group five and level group six, assuming that all level groups have not been designated. When designating the level group, any one of level group one, level group two, level group three, level group four, level group five and level group six can be designated as the data group first. It can also be designated in the order of the level groups, from small to large, or in other ways.
[0041] Further, multiple level groups can be designated as corresponding data groups at the same time. After the level groups are designated as data groups, the multiple level groups can be used for subsequent processing in parallel (the steps after step 304 are executed, and the specific steps are described below). For example, the six level groups of the above-mentioned image data are designated as corresponding six data groups at the same time, namely data group 1, data group 2, data group 3, data group 4, data group 5 and data group 6. The combination device 20 includes multiple processor cores, each processor core processes one data group respectively, and the multiple processor cores process multiple data groups in parallel at the same time (the steps after step 304 are executed, and the specific steps are described below). After each processor core executes the corresponding data group, its corresponding final intermediate result is obtained.
[0042] Then, step 305 is executed to sort the data in the data group according to the numerical value. The data in the specified one or more data groups are sorted according to the data size. The data in the data group is sorted in ascending or descending order. The data in different data groups can be sorted according to different methods, for example, data group one sorts the data in data group one in ascending order, and data group two sorts the data in data group two in descending order. The present invention does not impose any limitation on the sorting method.
[0043] Step 306: In the data group, the data with the largest value is added to the data with the smallest value, and the data with the second largest value is added to the data with the second smallest value. According to this rule, the data are added in pairs to obtain a plurality of intermediate data.
[0044] In order to avoid a large difference between the data, which would lead to a loss of precision during accumulation, the present invention adds the data with the largest value to the data with the smallest value in the data group, adds the data with the second largest value to the data with the second smallest value, and so on, so that the difference between the intermediate data obtained is as small as possible, which can reduce the loss of precision in the subsequent accumulation process.
[0045] For example, after step 305, a group of data A1, A2, A3, ..., An is obtained, where the group of data is arranged in ascending order. In step 303, A1=A1+An; A2=A2+A(n-1); A3=A3+A(n-2); ...; A(n / 2)=A(n / 2)+A(n / 2+1), generating n / 2 or (n / 2)+1 intermediate data.
[0046] Step 307, determine whether the intermediate data is one. If not, that is, the intermediate data is more than one data, it means that the data in the data group has not completed all operations, and then execute step 308 to update the data group according to the multiple intermediate data, that is, replace all the data in the data group with the intermediate data obtained in step 306.
[0047] Then, the process returns to step 305 , and based on the updated data group, steps 305 , 306 and 308 are repeatedly executed on the data in the data group.
[0048] Still take a group of data in the above step 305 as an example. The first accumulation obtains A1, A2, A3...; A(n / 2) groups of intermediate data, which means that the data in the data group has not completed all operations, then the data group is updated according to the obtained multiple groups of intermediate data, and the data of the updated data group is the aforementioned multiple groups of intermediate data. Then the updated data group is added multiple times until the last accumulation process in step 306: sum = A1 + A2, and an intermediate data sum is obtained. The intermediate data sum is the cumulative sum of all data in the data group. Only one intermediate data is generated in the addition step, and the intermediate data is the cumulative result of the data group. In step 307, it is determined that there is only one intermediate result, which means that the data has been accumulated last year, and the data of the next level group needs to be processed, so return to step 303 to determine whether there are still level groups that have not been specified. If all level groups have been specified, then step 309 is executed to add up the cumulative results of all level groups to obtain the cumulative result of the image data.
[0049] In more detail, when all level groups are specified, it means that the data of all level groups are calculated through steps 305-307, and finally each level group obtains an intermediate result corresponding to it. When the level groups are divided, they are divided according to the order of magnitude, so the order of magnitude of the data in each level group is different, and the order of magnitude of the final intermediate data obtained by the data groups corresponding to different level groups is also different. For example: the result of 1.0e9+1.0e-6+1.0e-6 is calculated to be 1000000000.0000019, which is different from the true value 1000000000.000002. Therefore, for the intermediate data of different orders of magnitude obtained in the end, all the accumulated results are accumulated and summed based on the Kahan sum algorithm to obtain the accumulated result of the multiple image data.
[0050] The Kahan sum algorithm is another method that can avoid large numbers eating up small numbers and reduce precision loss in addition operations. It has a number used to remember the truncated small number. Do the same calculation as above, assuming that a=123456 and b=2.189, and want to calculate a+b. The Kahan sum algorithm is done like this: sum=a+b (inaccurate), and temp=(a+b)-ab. The result of temp is not 0, but equal to -0.009, which is the truncated small number. This error is saved by a temporary variable. When calculating the next addition, this error can be made up and the error can be updated to sum.
[0051] In fact, it can also be understood that because the value of sum is too large, it occupies the precision of the decimal, and this decimal seems to be negligible at present, but it may accumulate into a large error after multiple iterations. Therefore, temp is used to store this error decimal to avoid the problem of large numbers eating up decimals.
[0052] In an optional embodiment, the above-mentioned method of accumulating image data can be applied to neural network calculations.
[0053] Figure 4 Another embodiment of the present invention is shown, which is a device 400 for accumulating data images. The device 400 includes: an acquisition module 401, a sorting module 402, a calculation module 403 and an update module 404. The acquisition module 401 is used to acquire multiple image data to form a data group; the sorting module 402 is used to sort the data in the data group according to the value; the calculation module 403 is used to add the data with the largest value to the data with the smallest value, and the data with the second largest value to the data with the second smallest value in the data group, and add the data in pairs according to this rule to obtain multiple intermediate data; the update module 404 is used to update the data group according to the multiple intermediate data.
[0054] The sorting, calculating and updating modules 402, 403, 404 repeatedly perform the sorting, adding and updating operations on the updated data group until the calculating module 403 generates only one intermediate data, which is the accumulated result of the data group.
[0055] In a possible embodiment, the acquisition module 401 includes a classification module 411 and a determination module 412. The classification module 411 is used to classify the plurality of image data into at least one level group according to the order of magnitude; the determination module 412 is used to determine whether all level groups have been designated, and if not, designate one of the at least one level group as the data group.
[0056] In an optional embodiment, the device 400 further includes an accumulation module 405. If all the level groups have been specified, the accumulation module 405 accumulates all the accumulation results based on the Kahan sum algorithm to obtain the accumulation result of the plurality of image data. The device 400 is applied to neural network calculation.
[0057] When performing accumulation operations on large-scale data, in order to avoid the problem of large numbers eating up small numbers, the present invention divides the image data into multiple level groups according to orders of magnitude, each level group contains data of the same order of magnitude, and calculates the data of each level group separately, and accumulates them in the form of maximum and minimum values, and second largest and second smallest values in each cluster. This can make one or more intermediate numbers after accumulation approximately equal, reduce the precision loss in the accumulation process, and improve the accuracy of the operation.
[0058] According to different application scenarios, the electronic equipment or device of the present invention may include a server, a cloud server, a server cluster, a data processing device, a robot, a computer, a printer, a scanner, a tablet computer, a smart terminal, a PC device, an Internet of Things terminal, a mobile terminal, a mobile phone, a driving recorder, a navigator, a sensor, a camera, a camera, a video camera, a projector, a watch, a headset, a mobile storage, a wearable device, a visual terminal, an automatic driving terminal, a vehicle, a household appliance, and / or a medical device. The vehicle includes an airplane, a ship, and / or a vehicle; the household appliance includes a television, an air conditioner, a microwave oven, a refrigerator, an electric rice cooker, a humidifier, a washing machine, an electric light, a gas stove, and a range hood; the medical device includes a nuclear magnetic resonance apparatus, a B-ultrasound apparatus, and / or an electrocardiograph. The electronic equipment or device of the present invention can also be applied to the Internet, the Internet of Things, a data center, energy, transportation, public administration, manufacturing, education, power grid, telecommunications, finance, retail, construction sites, medical treatment and other fields. Further, the electronic equipment or device of the present invention can also be used in the cloud, edge end, terminal and other application scenarios related to artificial intelligence, big data and / or cloud computing. In one or more embodiments, electronic devices or apparatuses with high computing power according to the solution of the present invention can be applied to cloud devices (such as cloud servers), while electronic devices or apparatuses with low power consumption can be applied to terminal devices and / or edge devices (such as smart phones or cameras). In one or more embodiments, the hardware information of the cloud device and the hardware information of the terminal device and / or edge device are compatible with each other, so that according to the hardware information of the terminal device and / or edge device, appropriate hardware resources can be matched from the hardware resources of the cloud device to simulate the hardware resources of the terminal device and / or edge device, so as to complete the unified management, scheduling and collaborative work of end-to-end or cloud-edge-to-end.
[0059] It should be noted that, for the purpose of simplicity, the present invention describes some methods and embodiments thereof as a series of actions and combinations thereof, but those skilled in the art will appreciate that the scheme of the present invention is not limited by the order of the described actions. Therefore, based on the disclosure or teaching of the present invention, those skilled in the art will appreciate that some of the steps therein may be performed in other orders or simultaneously. Further, those skilled in the art will appreciate that the embodiments described in the present invention may be regarded as optional embodiments, i.e., the actions or modules involved therein are not necessarily necessary for the implementation of one or some schemes of the present invention. In addition, depending on the different schemes, the present invention also has different emphases on the description of some embodiments. In view of this, those skilled in the art will appreciate that the parts not described in detail in a certain embodiment of the present invention may also refer to the relevant descriptions of other embodiments.
[0060] In terms of specific implementation, based on the disclosure and teachings of the present invention, those skilled in the art can understand that several embodiments disclosed in the present invention can also be implemented in other ways not disclosed herein. For example, with respect to the various units in the electronic device or device embodiments described above, this article splits them on the basis of considering the logical functions, and there may be other ways of splitting them in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features or functions in the units or components can be selectively disabled. In terms of the connection relationship between different units or components, the connection discussed in the above text in conjunction with the accompanying drawings can be a direct or indirect coupling between units or components. In some scenarios, the aforementioned direct or indirect coupling involves a communication connection using an interface, wherein the communication interface can support electrical, optical, acoustic, magnetic or other forms of signal transmission.
[0061] In the present invention, 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. The aforementioned components or units may be located at the same location or distributed on multiple network units. In addition, according to actual needs, some or all of the units may be selected to achieve the purpose of the scheme described in the embodiment of the present invention. In addition, in some scenarios, multiple units in the embodiment of the present invention may be integrated into one unit or each unit may exist physically separately.
[0062] In some other implementation scenarios, the above-mentioned integrated unit can also be implemented in the form of hardware, that is, a specific hardware circuit, which may include digital circuits and / or analog circuits, etc. The physical implementation of the hardware structure of the circuit may include but is not limited to physical devices, and the physical devices may include but are not limited to devices such as transistors or memristors. In view of this, the various devices described herein (such as computing devices or other processing devices) can be implemented by appropriate hardware processors, such as central processing units, GPUs, FPGAs, DSPs, and ASICs, etc. Further, the aforementioned storage unit or storage device may be any appropriate storage medium (including magnetic storage media or magneto-optical storage media, etc.), which may be, for example, a variable resistive memory (Resistive Random Access Memory, RRAM), a dynamic random access memory (Dynamic Random Access Memory, DRAM), a static random access memory (Static Random Access Memory, SRAM), an enhanced dynamic random access memory (Enhanced Dynamic Random Access Memory, EDRAM), a high bandwidth memory (High Bandwidth Memory, HBM), a hybrid memory cube (Hybrid Memory Cube, HMC), ROM and RAM, etc.
[0063] The foregoing content can be better understood in accordance with the following terms:
[0064] Item A1. A method for accumulating image data, the method comprising: acquiring a plurality of image data to form a data group; sorting the data in the data group according to the magnitude of the values; adding the data with the largest value to the data with the smallest value, and adding the data with the second largest value to the data with the second smallest value, and adding the data in pairs according to this rule to obtain a plurality of intermediate data; and
[0065] The data group is updated according to the plurality of intermediate data; wherein the sorting, adding and updating steps are repeatedly performed with the updated data group until only one intermediate data is generated in the adding step, and the intermediate data is the accumulated result of the data group.
[0066] Item A2. According to the method described in Item A1, the acquisition step includes: classifying the multiple image data into at least one level group according to order of magnitude; determining whether all level groups have been designated, and if not, designating one of the at least one level group as the data group.
[0067] Item A3. The method according to Item A2 further comprises: if all the level groups have been specified, summing up all the accumulated results based on a Kahan sum algorithm to obtain an accumulated result of the multiple image data.
[0068] Item A4. The method according to Item A3, wherein the method is applied in neural network calculations.
[0069] Item A5, a device for calculating and accumulating image data, wherein the device comprises: an acquisition module for acquiring multiple image data to form a data group; a sorting module for sorting the data in the data group according to the size of the values; a calculation module for adding the data with the largest value to the data with the smallest value, and the data with the second largest value to the data with the second smallest value in the data group, and adding the data in pairs according to this rule to obtain multiple intermediate data; and an update module for updating the data group according to the multiple intermediate data; wherein the sorting, calculation and update modules repeatedly perform sorting, addition and update operations on the updated data group until the calculation module generates only one intermediate data, and the intermediate data is the accumulation result of the data group.
[0070] Item A6. According to the device described in Item A5, the acquisition module includes: a classification module, used to classify the multiple image data into at least one level group according to the order of magnitude; a judgment module, used to judge whether all level groups have been designated, and if not, designate one of the at least one level groups as the data group.
[0071] Item A7. An apparatus according to Item A6, wherein the apparatus further comprises an accumulation module, and if all the level groups have been specified, the accumulation module accumulates all the accumulation results based on a Kahan sum algorithm to obtain an accumulation result of the multiple image data.
[0072] Item A8. An apparatus according to Item A7, wherein the apparatus is applied to neural network calculations.
[0073] Item A9. A computer-readable storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement the method described in any one of Items A1 to A4.
[0074] The embodiments of the present invention are described in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A method for accumulating image data, wherein the image data comprises floating point numbers, characterized in that: The method comprises: Acquire a plurality of the image data to form a data group; Wherein, the acquiring of the plurality of image data comprises: Classifying the plurality of image data into at least one level group according to order of magnitude, wherein image data of the same order of magnitude are classified into the same level group, and image data of different orders of magnitude are classified into different level groups; The following operations are performed for each data group: Sorting the data in the data group according to the value; In the data group, the data with the largest value is added to the data with the smallest value, and the data with the second largest value is added to the data with the second smallest value, and the data are added in pairs according to this rule to obtain a plurality of intermediate data; and updating the data group according to the plurality of intermediate data; The sorting, adding and updating steps are repeatedly performed with the updated data group until only one intermediate data is generated in the adding step to reduce the loss of accuracy. The intermediate data is the accumulated result of the data group.
2. The method according to claim 1, characterized in that The obtaining step further comprises: It is determined whether all the level groups have been designated, and if not, one of the at least one level group is designated as the data group.
3. The method according to claim 2, characterized in that The method further comprises: If all the level groups have been specified, all the accumulated results are accumulated based on the Kahansum algorithm to obtain the accumulated results of the multiple image data.
4. The method according to any one of claims 1 to 3, characterized in that: The method is applied in neural network calculations.
5. A device for calculating and accumulating image data, wherein the image data comprises floating point numbers, characterized in that: The device comprises: An acquisition module, used for acquiring a plurality of the image data to form a data group; Wherein, the acquisition module includes: a classification module, configured to classify the plurality of image data into at least one level group according to order of magnitude, wherein image data of the same order of magnitude are classified into the same level group, and image data of different orders of magnitude are classified into different level groups; Wherein, for each of the data groups: A sorting module, used for sorting the data in the data group according to the value; A calculation module, used for adding the data with the largest value to the data with the smallest value, and the data with the second largest value to the data with the second smallest value, and adding the data in pairs according to this rule to obtain a plurality of intermediate data; and An updating module, used for updating the data group according to the plurality of intermediate data; The sorting, calculating and updating module repeatedly performs the sorting, adding and updating operations on the updated data group until the calculating module generates only one intermediate data to reduce the loss of accuracy. The intermediate data is the accumulated result of the data group.
6. The device according to claim 5, characterized in that The acquisition module also includes: The judging module is used to judge whether all the level groups have been designated, and if not, designate one of the at least one level group as the data group.
7. The device according to claim 6, characterized in that The device further comprises an accumulation module, and if all the level groups have been designated, the accumulation module accumulates all the accumulation results based on a Kahansum algorithm to obtain an accumulation result of the plurality of image data.
8. The device according to claim 7, wherein: The device is applied to neural network calculation.
9. A computer readable storage medium having stored thereon computer program instructions for accumulating image data, characterized in that: When the computer program instructions are executed by the server, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Addition method, semiconductor device, and electronic device
CN111344665A
Electronic device and method for controlling electronic device
WO2020091253A1