Neural network calculation method and neural network calculation device
By adopting a multi-layer jump calculation method in neural network calculations and only storing some front-layer elements, the problem of large memory capacity and low efficiency in traditional methods is solved, memory usage and cost are reduced, and it is suitable for a variety of application scenarios.
Patent Information
- Application Number
- CN202310313448.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-03-17
- Filing Date
- 2023-03-28
- Publication Date
- 2024-09-20
AI Technical Summary
In existing neural network calculation methods, the size of intermediate data requires a large amount of memory capacity, which increases chip size and cost, and the traditional layer-by-layer calculation method is inefficient.
Using the multi-layer jump calculation method, the selected elements are calculated through the front-layer calculation data set, and only part of the front-layer elements need to be stored, reducing memory usage.
It effectively reduces memory usage and cost, improves computing efficiency, and is suitable for less time-sensitive applications such as voice recognition and home security monitoring.
Smart Images

Figure CN118673972A
Abstract
Description
Technical Field
[0001] The present disclosure relates to a computing method and a computing device, and more particularly to a neural network computing method and a neural network computing device. Background Art
[0002] For neural network (NN) calculations, the size of the intermediate data reflects the required memory size. When the memory such as SRAM, DRAM, and cache has sufficient size, the computational efficiency of the neural network can be improved. However, a larger memory capacity requires a larger chip size and increases the cost.
[0003] In the traditional calculation process of the neural network model, data needs to be calculated layer by layer. The intermediate data of a certain layer needs to be calculated and stored in the memory. This requires a considerable memory capacity. Summary of the invention
[0004] The present disclosure relates to a neural network computing method and a neural network computing device, wherein the data of the neural network can be calculated by a front-layer computing data set, and only a part of the front-layer elements of any front layer need to be stored. Therefore, the memory usage can be greatly reduced, and the memory area and cost can be effectively reduced.
[0005] According to one aspect of the present disclosure, a neural network calculation method is proposed, which includes the following steps: determining at least one selection layer; determining multiple front layers; these front layers are before the selection layer; selecting a selection element from multiple selection elements of the selection layer; defining a front layer calculation data set related to the selection element; the front layer calculation data set is composed of a part of the multiple front layer elements of these front layers; and calculating the selection element based on the front layer calculation data set.
[0006] According to another aspect of the present disclosure, a neural network computing device is proposed, which includes: a decision unit, a selection unit, a definition unit and a calculation unit; the decision unit is used to determine at least one selection layer and determine multiple front layers; these front layers are before the selection layer; the selection unit is used to select a selection element from multiple selection elements of the selection layer; the definition unit is used to define a front layer computing data set related to the selection element; the front layer computing data set is composed of a part of the multiple front layer elements of these front layers; the calculation unit is used to calculate the selection element based on the front layer computing data set.
[0007] According to another aspect of the present disclosure, a neural network calculation method is proposed, which includes the following steps: determining at least one selection layer; determining multiple front layers; these front layers are before the selection layer; selecting one or more selection elements from multiple selection elements of the selection layer; defining one or more front layer calculation data sets related to these selection elements; each front layer calculation data set is composed of a part of the multiple front layer elements of these front layers; and calculating these selection elements based on these front layer calculation data sets.
[0008] In order to better understand the above and other aspects of the present disclosure, embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1A to Figure 1C An example is provided to illustrate how neural networks perform calculations in a layer-by-layer manner;
[0010] Figure 2 The example illustrates how the neural network uses the "multi-layer skipping" method to perform calculations in the present disclosure;
[0011] Figure 3 An example is given to illustrate a neural network calculation method according to an embodiment;
[0012] Figure 4 An example is given to illustrate the previous layer calculation data of a selected element;
[0013] Figure 5 The example illustrates one-dimensional front-layer calculation data;
[0014] Figure 6 A neural network computing device according to an embodiment is shown;
[0015] Figure 7 A flowchart of a neural network calculation method according to an embodiment is shown;
[0016] Figure 8 A flowchart of a neural network calculation method according to another embodiment is shown; and
[0017] Fig. 9 Example illustrating previous calculation data for more than one selected element.
[0018] Description of reference numerals:
[0019] 100: Neural network computing device;
[0020] 110: Decision unit;
[0021] 130: Select unit;
[0022] 140: define unit;
[0023] 150: computing unit;
[0024] 160: judgment unit;
[0025] 170: storage unit;
[0026] C, D, E, p, q, m, n, H, W: quantity;
[0027] E1i, E2i, Ej, Ej+1: front layer elements;
[0028] E31, E32, Ej+2, Ej+2': select elements;
[0029] E3i, Ej+2, Ek+6: select elements;
[0030] E4i: Elements;
[0031] F1, F2: filter layer;
[0032] Gj+2, Gj+2', Gk+6: front layer calculation data set;
[0033] L1, L2, Lj, Lj+1: front layer;
[0034] L3, Lj+2, Lk+6: selection layer;
[0035] Ly1, Ly2, Ly3, Ly4: convolutional layers;
[0036] R1i, R2i, R3i: range;
[0037] S110, S120, S130, S30', S140, S140', S150, S150', S160, S170: steps;
[0038] VDj, VDj', VDj+1, VDj+1': front layer calculation data. DETAILED DESCRIPTION
[0039] Please refer to Figure 1A to Figure 1C , which illustrates how neural networks perform calculations in a layer-by-layer manner. Figure 1A As shown, the neural network has multiple convolution layers Ly1 to Ly4. In the "layer by layer" approach, all elements on all convolution layers Ly1 need to be stored (the slash indicates the part that needs to be stored) before calculating any element in convolution layer Ly2. After all elements on convolution layer Ly2 are calculated, the convolution layer Ly1 is entered. Figure 1B Calculation.
[0040] exist Figure 1BIn the above example, all elements of the convolution layer Ly2 need to be stored (the slash indicates the part that needs to be stored) before calculating any element of the convolution layer Ly3. After all elements of the convolution layer Ly3 are calculated, the convolution layer Ly3 will be entered. Figure 1C Calculation.
[0041] exist Figure 1C In the above figure, all elements on all convolutional layers Ly3 need to be stored (the slash indicates the part that needs to be stored) before calculating any element in convolutional layer Ly4.
[0042] As described above, when the "layer by layer" approach is adopted, an entire convolutional layer Ly1, Ly2, Ly3 or Ly4 needs to be stored each time, which consumes a large amount of memory capacity.
[0043] Please refer to Figure 2 , which illustrates how the neural network uses the "multi-layer jump" method to perform calculations. Figure 2 As shown, all elements of range R2i in convolution layer Ly2 can be calculated through elements of range R1i in convolution layer Ly1. All elements of range R3i in convolution layer Ly3 can be calculated through elements of range R2i in convolution layer Ly2. A certain element E4i in convolution layer Ly4 can be calculated through elements of range R3i in convolution layer Ly3. In other words, a certain element E4i in convolution layer Ly4 can be calculated through range R1i in convolution layer Ly1, range R2i in convolution layer Ly2, and range R3i in convolution layer Ly3. After calculating each element in convolution layer Ly4 one by one, the calculation of convolution layer Ly4 can also be completed. Therefore, by using this "multi-layer jump" method for calculation, only range R1i in convolution layer Ly1, range R2i in convolution layer Ly2, and range R3i in convolution layer Ly3 need to be stored, and a certain element E4i in convolution layer Ly4 can be calculated smoothly.
[0044] Please refer to Figure 3 , which illustrates a neural network calculation method according to an embodiment. In this embodiment, the neural network does not use a "layer by layer" method to perform calculations. Instead, when a "multi-layer skip" method is used to perform calculations, the previous layers L1 and L2 before a certain selected layer L3 can be used to calculate each selected element E3i in the selected layer L3.
[0045] For example, a certain selection element E31 is selected from one of the multiple selection elements E3i of the selection layer L3. Based on the size of the filter layer F2, p×q×C front layer elements E2i need to be taken out from the front layer L2. Based on the size of the filter layer F1, (p+m-1)×(q+n-1)×E front layer elements E1i need to be taken out from the front layer L1.
[0046] Furthermore, a certain selection element E32 is selected from one of the multiple selection elements E3i of the selection layer L3. Based on the size of the filter layer F2, p×q×C front layer elements E2i need to be taken out from the front layer L2. Based on the size of the filter layer F1, (p+m-1)×(q+n-1)×E front layer elements E1i need to be taken out from the front layer L1.
[0047] That is to say, if you want to calculate a selected element E3i of the selected layer L3, you only need to store at most (p+m-1)×(q+n-1)×E previous layer elements E1i. On the contrary, if the previous layer L1 and the previous layer L2 are calculated layer by layer, H×W×E previous layer elements Eli need to be stored. Obviously, (p+m-1)×(q+n-1)×E is much lower than H×W×E. Compared with calculating layer by layer, the "multi-layer jump" calculation method adopted in this embodiment can greatly reduce the usage of memory.
[0048] Please refer to Figure 4 , which illustrates the previous layer calculation data of a selected element. For the selected element Ej+2 of the selected layer Lj+2, based on the filtering and convolution conditions, some related previous layer elements Ej+i can be found in the previous layer Lj+1. The previous layer element Ej+1 of the previous layer Lj+1 can be defined as the previous layer calculation data VDj+1 of the selected element Ej+2.
[0049] All front-layer calculation data VDj+1, DVj of the front layers Lj+1, Lj before selecting the element Ej+2 can be defined as the front-layer calculation data set Gj+2.
[0050] With more gaps, the previous layer calculation data of the selected element will become wider. For example, the previous layer calculation data VDj is larger than the previous layer calculation data VDj+1. In one embodiment, the number of previous layers can be greater than 2.
[0051] The size of the data calculated by the front layer is also affected by the configuration of the neural network, such as the size of the filter layer, stride size, depth, pooling process, number of layers, etc.
[0052] Please refer to Figure 5 , which illustrates one-dimensional front-layer calculation data. For the selected element Ek+6 of the selected layer Lk+6, the selected element Ek+6 can be processed through two 3×1 convolutions, a 3×1 convolution with a step of 2, a 3×1 convolution, a 2×1 pooling, and a 3×1 convolution. Through the structure of the neural network, the relevant front-layer calculation data set Gk+6 can be obtained. The layer calculation data sets Gk+6 before different selected elements Ek+6 can be calculated in parallel to improve the calculation performance.
[0053] Please refer to Table 1, which uses the VGG16 neural network as an example. If the data is calculated layer by layer, the maximum required intermediate data size is 3136K. If the data is calculated using the previous layer calculation data, for the 1×1×256 selected elements after the "Pooling 3" layer, the required intermediate data size is 396K and the required previous layer calculation data size is 110.25K. The total data size required in this way is 506.25K (396K+110.25K), which only uses 0.16 times the original memory usage.
[0054] Table 1
[0055]
[0056]
[0057] Please refer to Table 2, which uses the ResNET18 neural network as an example. If the data is calculated layer by layer, the maximum required intermediate data size is 784K. If the data is calculated using the previous layer calculation data, for the 1×1×256 selected elements after "Layer 10", the required intermediate data size is 49K and the required previous layer calculation data size is 49K. The total data size required in this way is 98K (48K+48K), which only uses 0.125 times the original memory usage.
[0058] Table 2
[0059]
[0060]
[0061]
[0062] Please refer to Table 3, which uses the ResNET18 neural network as another example. If the data is calculated layer by layer, the maximum required intermediate data size is 784K. If the data is calculated using the previous layer calculation data, for the 1×1×128 selected elements after the "Layer 6" layer, the required intermediate data size is 98K and the required previous layer calculation data size is 7.563K. The total data size required in this way is 105.563K (98K+7.563K), which only uses 0.135 times the original memory usage.
[0063] Table 3
[0064]
[0065]
[0066] According to the above embodiment, the neural network can obtain a large reduction in memory data by calculating the data in the front layer. Figure 6 , which illustrates a neural network computing device 100 according to an embodiment. The neural network computing device 100 is used to calculate the data of the neural network through the previous layer computing data. The neural network computing device 100 is, for example, a computer, a chip, a circuit, a circuit board, a program code, or a storage device storing the program code. The neural network computing device 100 includes a determination unit 110, a selection unit 130, a definition unit 140, a calculation unit 150, a judgment unit 160, and a storage unit 170. The storage unit 170 is used to store data. The storage unit 170 is, for example, a memory, a disk, or a cloud storage center. The determination unit 110, the selection unit 130, the definition unit 140, the calculation unit 150, and the judgment unit 160 are used to execute various computer operation programs. The determination unit 110, the selection unit 130, the definition unit 140, the calculation unit 150, and the judgment unit 160 are, for example, a chip, a circuit, a circuit board, a program code, or a storage device storing the program code. Through these components, the data of the neural network can be calculated through the previous layer computing data. The operation of these components will be described in detail below using a flow chart.
[0067] Please refer to Figure 7 , which depicts a flowchart of a neural network calculation method according to an embodiment. The neural network calculation method is used for a visual geometry group model (Visual Geometry Group model, VGG model), a residual network model (ResNET model) or a binary neural network model (Binary neural network model) to perform calculations. In step S110, as Figure 3 As shown, the decision unit 110 determines at least one selected layer (such as selected layer L3). In this step, the decision unit 110 can determine the selected layer according to the size of the previous layer calculation data. In order to minimize the required previous layer calculation data size, more than one selected layer can be determined. After the calculation of one selected layer is completed, the calculation of the next selected layer can be continued.
[0068] Next, in step S120, Figure 3 As shown, the decision unit 110 determines a plurality of previous layers (such as previous layers L1, L2) before the selected layer (such as the selected layer L3). In this step, each layer between the previously calculated selected layer (or input) and the currently calculated selected layer is determined as the previous layer.
[0069] Then, in step S130, Figure 3 As shown, the selection unit 130 selects a selection element (such as selection element E31) from a plurality of selection elements (such as selection element E3i) in the selection layer (such as selection layer L3). In this step, all the selection elements E3i in the selection layer L3 are selected as selection elements one by one. After a selection element (such as selection element E31) is calculated, another selection element (such as selection element E32) can be selected.
[0070] Next, in step S140, Figure 4 As shown, the definition unit 140 defines a previous layer calculation data set (such as the previous layer calculation data set Gj+2) related to the selection element (such as the selection element Ej+2). The previous layer calculation data set Gj+2 is composed of some previous layer elements Ej+1 of the previous layer Lj+1 and some previous layer elements Ej of the previous layer Lj.
[0071] Then, in step S150, Figure 4 As shown, the calculation unit 150 calculates the selection element (such as the selection element Ej+2) according to the previous layer calculation data set (such as the previous layer calculation data set Gj+2). In this step, only part of the previous layer elements Ej+1 in the previous layer Lj+1 are stored, and only part of the previous layer elements Ej in the previous layer Lj are stored.
[0072] Next, in step S160, Figure 4 As shown, the judgment unit 160 judges whether all the selected elements of the selected layer (such as the selected layer Lj+2) are selected and calculated. When all the selected elements of the selected layer are selected and calculated, the process proceeds to step S170; when not all the selected elements are selected and calculated, the process returns to step S130. Step S130 of selecting the selected elements and step S150 of calculating the selected elements are repeated until all the selected elements in the selected layer are selected and calculated.
[0073] In step S170, the determination unit 160 determines whether all layers of the neural network have been calculated. When all layers of the neural network have been calculated, the process ends; when not all layers of the neural network have been calculated, the process returns to step S110. Step S110 of determining the selected layer and step S120 of determining the previous layer are repeated until all layers of the neural network have been calculated.
[0074] According to the above neural network calculation method, since only part of the front layer elements in the front layer need to be stored, the memory usage can be greatly reduced. Therefore, the memory area and cost can be reduced. In some applications, such as sound recognition, the calculation is not highly sensitive to time. The neural network calculation method of this embodiment is used for this type of application.
[0075] In addition to sound recognition, some object detection applications do not require a very high frame rate. For example, in home security monitoring applications, only a few frames per second are needed to detect an object and trigger the recording function. The neural network calculation method of this embodiment is very suitable for this type of application.
[0076] In the above steps S130 to S150, only one selected element is calculated at a time. In other embodiments, more than one selected element can be calculated in parallel. Figure 8 , which depicts a flow chart of a neural network calculation method according to another embodiment. In step S130', Fig. 9 As shown, the selection unit 130 selects one or more selection elements (such as selection elements Ej+2, Ej+2') from a plurality of selection elements in a selection layer (such as selection layer Lj+2). Fig. 9 The example illustrates the calculation data of the previous layer of more than one selection element. In this step, some selection elements (such as selection elements Ej+2 and Ej+2') are selected from the selection elements of the selection layer (such as the selection layer Lj+2). After the selection elements Ej+2 and Ej+2' are calculated, the selection elements are continued to be selected from the remaining selection elements.
[0077] Next, in step S140', Fig. 9 As shown, the definition unit 140 defines one or more previous layer calculation data sets (such as previous layer calculation data sets Gj+2, Gj+2') related to these selection elements (such as selection elements Ej+2, Ej+2'). Each previous layer calculation data set Gj+2, Gj+2' is composed of part of the previous layer element Ej+1 of the previous layer Lj+1 and part of the previous layer element Ej of the previous layer element Ej. The previous layer calculation data VDj+1, VDj of the previous layer calculation data set Gj+2 partially overlap with the previous layer calculation data VDj+1', VDj' of the previous layer calculation data set Gj+2'. The previous layer calculation data set Gj+2 and the previous layer calculation data set Gj+2' can be stored in the same memory, and the overlapping data can be stored in the same location.
[0078] Next, in step S150', Fig. 9 As shown, the calculation unit 150 calculates these selection elements (such as selection elements Ej+2, Ej+2') based on these previous layer calculation data sets (such as previous layer calculation data sets Gj+2, Gj+2'). In this step, since the previous layer calculation data set Gj+2 overlaps with the previous layer calculation data set Gj+2', the calculation of the selection elements Ej+2, Ej+2' can share some previous layer elements of the previous layer. Therefore, the calculation efficiency can be further improved.
[0079] According to the above embodiment, the data of the neural network can be calculated by the previous layer calculation data, and only part of the previous layer elements of any previous layer need to be stored. Therefore, the memory usage can be greatly reduced, and the memory area and cost can be effectively reduced.
[0080] In summary, although the present disclosure has been disclosed as above by way of embodiments, it is not intended to limit the present disclosure. A person skilled in the art of the present disclosure may make various changes and modifications without departing from the spirit and scope of the present disclosure. Therefore, the scope of protection of the present disclosure shall be determined by the scope of the attached claims.
Claims
1. A neural network calculation method, comprising: Determine at least one selection layer; Determine a plurality of front layers, the plurality of front layers being before the selected layer; Select a selection element from a plurality of selection elements in the selection layer; defining a previous layer calculation data set associated with the selected element, wherein the previous layer calculation data set is composed of a portion of the previous layer elements of the previous layers; and The selected element is calculated based on the at least one previous layer calculation data set.
2. The neural network computing method according to claim 1, wherein the number of the plurality of front layers is greater than 2.
3. The neural network calculation method according to claim 1, further comprising: Determine whether all of the plurality of selected elements of the selected layer are selected and calculated; The step of selecting the selection element and the step of calculating the selection element are repeatedly performed until all of the multiple selection elements of the selection layer are selected and calculated.
4. The neural network calculation method according to claim 1, wherein the number of the at least one selected layer is greater than 1.
5. A neural network computing device, comprising: a determining unit, configured to determine at least one selected layer and determine a plurality of front layers, wherein the plurality of front layers are before the selected layer; A selection unit, used for selecting a selection element from a plurality of selection elements of the selection layer; a defining unit, configured to define a front-layer calculation data set associated with the selected element, the front-layer calculation data set being composed of a portion of the plurality of front-layer elements of the plurality of front layers; and A computing unit is used to compute the selected element based on the at least one previous layer computing data set.
6. The neural network computing device according to claim 5, further comprising: a judging unit, configured to judge whether all the plurality of selected elements of the selected layer are selected and calculated; The step of selecting the selection element and the step of calculating the selection element are repeatedly performed until all of the multiple selection elements of the selection layer are selected and calculated.
7. The neural network computing device according to claim 5, wherein the number of the at least one selected layer is greater than 1.
8. A neural network calculation method, comprising: Determine at least one selection layer; Determine a plurality of front layers, the plurality of front layers being before the selected layer; Select one or more selection elements from the multiple selection elements of the selection layer; defining one or more front-layer calculation data sets associated with the plurality of selected elements, wherein each of the front-layer calculation data sets is composed of a portion of a plurality of front-layer elements of the plurality of front layers; and The plurality of selection elements are calculated according to the plurality of previous layer calculation data sets.
9. The neural network computing method according to claim 8, wherein the plurality of selected elements are computed in parallel.
10. The neural network computing method according to claim 8, wherein the plurality of visual data sets are stored in a same memory.
