Method for operating a neural network model, readable medium, and electronic device
Through parallel processing and internal storage of operation results, the problem of running speed and resource occupation of the deep neural network model is solved, and more efficient computing performance is achieved.
Patent Information
- Application Number
- CN202110974281.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-24
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-08-24
AI Technical Summary
As the complexity and data volume of deep neural network models increase, traditional neural network model operating methods cannot meet the computing speed requirements in the AI field, resulting in excessive hardware resource usage and affecting performance.
By running different network layers in the neural network model in parallel and storing part of the operation results in the internal memory of the processor, the number of accesses to external memory is reduced. The computing layer and the sorting layer are used to separate data processing to increase running speed and reduce resources. occupied.
It significantly improves the running speed of the neural network model and the performance of electronic equipment, reduces the occupation of hardware resources, and improves the computing efficiency.
Smart Images

Figure CN113673701B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to an operating method, a readable medium and an electronic device of a neural network model. Background Art
[0002] With the rapid development of artificial intelligence (AI), neural networks, especially deep neural networks (DNN), are increasingly used in the field of artificial intelligence. At the same time, with the increase in the number of network layers and network types of DNN models, as well as the increase in the amount of input data of DNN models, the hardware resources (such as memory resources) occupied by running DNN models are also increasing. The traditional operation method of neural network models can no longer meet the demand for DNN computing speed in the AI field. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a method for operating a neural network model, a readable medium, and an electronic device. By operating different network layers in the neural network model in parallel, and storing the operation results of some network layers in the neural network model in the memory inside the processor, the number of times the memory outside the processor is accessed during the operation of the neural network model is reduced, the operation speed of the neural network model is increased, the hardware resources occupied by the operation of the neural network model are reduced, and the performance of the electronic device running the neural network model is improved.
[0004] In a first aspect, an embodiment of the present application provides a method for operating a neural network model, which is applied to an electronic device, the electronic device comprising a processor, a first memory disposed outside the processor, and a second memory disposed inside the processor, wherein the neural network model comprises a calculation layer and a sorting layer;
[0005] And the method comprises:
[0006] The processor uses the calculation layer and the sorting layer to perform the following processing on the first data part and the second data part successively obtained from the data to be processed:
[0007] A first data portion is obtained, and a first calculation result is obtained by calculating the first data portion through a calculation layer of a neural network model, and the first calculation result is stored in a first storage area of a second memory, wherein the data amount of the first calculation result of the first data portion is smaller than the storage space of the first storage area; and after the first calculation result is stored in the first storage area, the following operations are performed:
[0008] The first calculation result read from the first storage area is sorted by the sorting layer to obtain a first sorting result, and the first sorting result is stored in the first memory, and the second data part is obtained, and the second data part is calculated to obtain a second calculation result, and the second calculation result is stored in the second storage area of the second memory, wherein the data amount of the calculation result of the second data part is smaller than the storage space of the second storage area.
[0009] That is to say, in the embodiment of the present application, the data to be processed can be divided into multiple data parts, and the processor can read different data parts from the data to be processed in turn to perform calculation layer calculation to obtain the calculation layer calculation results of the data part, and then store the calculation results in the second memory; and in the process of the processor calculating a data part through the calculation layer, the processor can sort the calculation results of other data parts stored in the second memory through the sorting layer, and transmit the sorting results to the first memory. In this way, the results of the calculation of the data to be processed through the calculation layer will not be transmitted to the first memory, which reduces the number of times the first memory is accessed during the operation of the neural network model, and the processor always performs the calculation layer calculation of one data part and the sorting layer sorting of another data part in parallel in most cases, thus improving the running speed of the neural network model, reducing the space of the first memory occupied when running the neural network model, and improving the performance of the electronic device.
[0010] In a possible implementation of the first aspect, after storing the second calculation result in the second storage area of the second memory, the method further includes:
[0011] The second calculation results read from the second storage area are sorted by the sorting layer to obtain a second sorting result, and the second sorting result is stored in the first memory.
[0012] In a possible implementation of the first aspect above, the first storage area and the second storage area are the same in size.
[0013] In an embodiment of the present application, when the available space of the second memory and the size of the data portion to be processed that the processor reads at a single time are constant, the size of the data portion that the processor reads at a single time can be maximized, thereby improving the running speed of the neural network model.
[0014] In a possible implementation of the first aspect above, the computing layer includes at least one of the following neural networks: a convolutional network, an element addition network, an element multiplication network, and a matrix element correspondence multiplication network.
[0015] In a possible implementation of the first aspect above, the sorting layer includes at least one of the following neural networks: a depth-to-space conversion network, a space-to-depth conversion network, a transposition network, a cropping network, and a padding network.
[0016] In a second aspect, an embodiment of the present application provides an electronic device for running a neural network model, the electronic device comprising a processor, a first memory disposed outside the processor, and a second memory disposed inside the processor, wherein:
[0017] The processor uses the computing layer and the sorting layer of the neural network model to process the first data part and the second data part successively obtained from the data to be processed as follows:
[0018] A first data portion is obtained, and a first calculation result is obtained by calculating the first data portion through a calculation layer of a neural network model, and the first calculation result is stored in a first storage area of a second memory, wherein the data amount of the first calculation result of the first data portion is smaller than the storage space of the first storage area; and after the first calculation result is stored in the first storage area, the following operations are performed:
[0019] The first calculation result read from the first storage area is sorted by the sorting layer to obtain a first sorting result, and the first sorting result is stored in the first memory, and the second data part is obtained, and the second data part is calculated to obtain a second calculation result, and the second calculation result is stored in the second storage area of the second memory, wherein the data amount of the calculation result of the second data part is smaller than the storage space of the second storage area.
[0020] In a possible implementation of the second aspect above, after the processor stores the second calculation result in the second storage area of the second memory, it sorts the second calculation result read from the second storage area through the sorting layer to obtain a second sorting result, and stores the second sorting result in the first memory.
[0021] In a possible implementation of the second aspect above, the processor also includes a direct memory access controller, and the direct memory access controller sorts the first calculation results read from the first storage area through the sorting layer to obtain a first sorting result, and stores the first sorting result in the first memory; and the direct memory access controller sorts the second calculation results read from the second storage area through the sorting layer to obtain a second sorting result, and stores the second sorting result in the first memory.
[0022] In a possible implementation of the second aspect above, the processor also includes an operation unit, and the operation unit calculates the first data part to obtain a first calculation result, and stores the first calculation result in a first storage area of the second memory; and the operation unit calculates the second data part to obtain a second calculation result, and stores the second calculation result in a second storage area of the second memory.
[0023] In a possible implementation of the second aspect, the first storage area and the second storage area are the same in size.
[0024] In a possible implementation of the second aspect above, the computing layer includes at least one of the following neural networks: a convolutional network, an element addition network, an element multiplication network, and a matrix element correspondence multiplication network.
[0025] In a possible implementation of the second aspect above, the sorting layer includes at least one of the following neural networks: a depth-to-space conversion network, a space-to-depth conversion network, a transposition network, a cropping network, and a padding network.
[0026] In a third aspect, an embodiment of the present application provides a readable medium having instructions stored thereon, which, when executed by a processor of an electronic device, enables the electronic device to implement any one of the neural network model operation methods provided by the first aspect and various possible implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 According to some embodiments of the present application, a schematic diagram of the structure of a neural network model is shown;
[0028] Figure 2 According to some embodiments of the present application, a structural schematic diagram of an electronic device is shown;
[0029] Figure 3A According to some embodiments of the present application, a flowchart of a method for operating a neural network model is shown;
[0030] Figure 3B According to some embodiments of the present application, a timing diagram of a neural network model operation method is shown;
[0031] Figure 4A According to some embodiments of the present application, a flowchart of a method for operating a neural network model is shown;
[0032] Figure 4B According to some embodiments of the present application, a timing diagram of a neural network model operation method is shown;
[0033] Figure 5According to some embodiments of the present application, a schematic diagram of a calculation process of a neural network model is shown;
[0034] Figure 6 According to some embodiments of the present application, a schematic diagram of dividing an image data matrix into blocks is shown;
[0035] Figure 7 According to some embodiments of the present application, a schematic diagram of performing computational layer computation on data block 1 is shown;
[0036] Figure 8 According to some embodiments of the present application, a schematic diagram of performing computational layer computation on data block 2 is shown;
[0037] Fig. 9 According to some embodiments of the present application, a schematic diagram of performing sorting of the calculation results of the calculation layer of data block 1 is shown;
[0038] Fig.10 According to some embodiments of the present application, a schematic diagram of performing computational layer computation on data block 3 is shown;
[0039] Fig.11 According to some embodiments of the present application, a schematic diagram of performing sorting of the calculation results of the calculation layer of data block 2 is shown;
[0040] Fig.12 According to some embodiments of the present application, a schematic diagram of performing sorting on the calculation results of the calculation layer of the data block 3 is shown. DETAILED DESCRIPTION
[0041] Illustrative embodiments of the present application include, but are not limited to, methods of operating a neural network model, readable media, and electronic devices.
[0042] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0043] First, the structure of the neural network model applicable to the operation method of the neural network model provided in the embodiment of the present application is introduced.
[0044] Figure 1 According to some embodiments of the present application, a schematic diagram of the structure of a neural network model is shown. Figure 1As shown, the neural network model 10 includes an input layer 11, a computing layer 12, a sorting layer 13 and an output layer 14, wherein the input layer 11 is used to obtain data for neural network calculation; the computing layer 12 is a neural network layer that needs to perform arithmetic and / or logical calculations on the data, such as a convolutional layer, an element addition layer, an element multiplication layer, etc.; the sorting layer 13 is a layer that does not need to calculate the data but only needs to rearrange the order of the data, such as Tensorflow TM (A symbolic mathematical system based on data flow programming, which is widely used in the programming implementation of various machine learning algorithms), and the sorting layer 13 is the next layer of the calculation layer 12, which is used to sort the data in the calculation results of the calculation layer 12; the output layer 14 is used to output the calculation results of the neural network model 10. In other words, the neural network model operation method provided in each embodiment of the present application is applicable to a neural network model including a calculation layer 12 and a sorting layer 13, and the sorting layer 13 is connected to the calculation layer 12 (that is, the calculation result of the calculation layer 12 is the input of the sorting layer 13). It can be understood that Figure 1 The structure of the neural network model 10 shown is only an example. In other embodiments, the neural network model 10 may also include more or fewer network layers. Those skilled in the art should understand that the neural network model operation method provided in the embodiments of the present application is applicable to various types of neural network models including computing layers and sorting layers, and is not limited here.
[0045] It can be understood that in other embodiments, the computing layer 12 may also be other types of neural networks that require other types of data processing, such as an Element-wise Product layer that multiplies corresponding elements of two matrices; the sorting layer 13 may also be other types of neural networks, such as a Crop layer that reduces the size of input data, etc., which is not limited here.
[0046] To facilitate understanding of the technical solution of the embodiment of the present application, the electronic device 20 that executes the calculation process of the neural network model 10 is introduced below.
[0047] Figure 2 According to some embodiments of the present application, a structural diagram of an electronic device 20 is shown, such as Figure 2As shown, the electronic device 20 includes a processor 21, a system memory 22 (first memory), a non-volatile memory 23, an input / output device 24, a communication interface 25, and a system control logic 26 for coupling the processor 21, the system memory 22, the non-volatile memory 23, the input / output device 24, and the communication interface 25. Among them:
[0048] The processor 201 may include one or more processing units, for example, a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processor (DSP), a microprocessor (MCU), a field programmable gate array (FPGA), an artificial intelligence processing unit (AIPU), a neural network processor (NPU), etc., and a processing module or processing circuit. Among them, different processing units can be independent devices or integrated in one or more processors. In some embodiments, the processor 201 can execute the calculation process of the neural network model 10.
[0049] In some embodiments, the processor 21 may include a control unit (controller) 210, an operation unit 211 (operator), and a storage unit 212 (second memory), wherein the control unit 210 is used to schedule the processor 21. In some embodiments, the control unit 210 also includes a direct memory access controller (Direct Memory Access Controller, DMAC) 2101, which is used to transfer data in the storage unit 212 to other units, such as to the system memory 22. In some embodiments, the DMAC 2101 can also be used to sort the data in the storage unit 212 and transfer it to the system memory 22.
[0050] The operation unit 211 is used to perform specific arithmetic and / or logic operations. In some embodiments, the operation unit may include an arithmetic logic unit, which refers to a combinational logic circuit that can implement multiple groups of arithmetic operations and logic operations, and is used to perform arithmetic and logic operations. In other implementations, the operation unit 211 may also include multiple application-specific integrated circuits (ASICs) suitable for running neural network models, such as convolution calculation units, vector calculation units, etc.
[0051] The storage unit 212 is used to temporarily store input and / or output data of the operation unit 211 .
[0052] It is understandable that in other embodiments, the DMAC 2101 may not be integrated into the processor 21, but may be an independent module coupled to the system control logic 26, which is not limited in the embodiments of the present application.
[0053] The system memory 22 may include a random access memory (RAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), and other memories, and is used to temporarily store data or instructions of the electronic device 20. For example, in some embodiments, the system memory 22 may be used to temporarily store the calculation results of the calculation layer 12, and may also be used to temporarily store the sorting results of the sorting layer 13.
[0054] The non-volatile memory 23 may include one or more tangible, non-temporary computer-readable media for permanently storing data and / or instructions. The non-volatile memory 23 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as a hard disk drive (HDD), a compact disc (CD), a digital versatile disc (DVD), a solid-state drive (SSD), etc. In some embodiments, the non-volatile memory 23 may also be a removable storage medium, such as a secure digital (SD) memory card, etc. In some embodiments, the non-volatile memory 23 is used to permanently store data or instructions of the electronic device 20, such as instructions for storing the neural network model 10.
[0055] The input / output (I / O) device 24 may include input devices, such as a keyboard, a mouse, a touch screen, etc., for converting user operations into analog or digital signals and transmitting them to the processor 21; and output devices, such as a speaker, a printer, a display, etc., for displaying information in the electronic device 20 to the user in the form of sound, text, images, etc.
[0056] The communication interface 25 provides a software / hardware interface for the electronic device 20 to communicate with other electronic devices, so that the electronic device 20 can exchange data with other electronic devices 20. For example, the electronic device 20 can obtain data for running a neural network model from other electronic devices through the communication interface 25, and can also transmit the calculation results of the neural network model to other electronic devices through the communication interface 25.
[0057] The system control logic 26 may include any suitable interface controller to provide any suitable interface to other modules of the electronic device 20 so that the modules of the electronic device 20 can communicate with each other. For example, in some embodiments, the system control logic 26 and the DMAC 2101 may cooperate to sort the calculation results of the calculation layer and transmit them to the system memory 22.
[0058] In some embodiments, at least one of the processors 21 may be packaged together with the logic of one or more controllers for the system control logic 26 to form a system in package (SiP). In other embodiments, at least one of the processors 21 may also be integrated with the logic of one or more controllers for the system control logic 26 on the same chip to form a system-on-chip (SoC).
[0059] Understandably, Figure 2 The hardware structure of the electronic device 20 shown is only an example. In other embodiments, the electronic device 20 may also include more or fewer modules, and some modules may be combined or split, which is not limited in the embodiments of the present application.
[0060] It can be understood that the electronic device 20 can be any electronic device capable of running a neural network model, including but not limited to laptop computers, desktop computers, tablet computers, mobile phones, servers, wearable devices, head-mounted displays, mobile email devices, portable game consoles, portable music players, reader devices, and televisions in which one or more processors are embedded or coupled, and the embodiments of the present application are not limited thereto.
[0061] The following is a detailed introduction to the process of the electronic device 20 executing the neural network model operation method provided in the embodiment of the present application in combination with the hardware structure of the electronic device 20.
[0062] An embodiment of the present application provides a method for operating a neural network model, in which the processor 21 first performs a computing layer calculation on the input data, and stores the computing layer calculation results in the system memory 22, then reads the computing layer calculation results from the system memory 22 for sorting layer sorting, and finally transmits the sorting results to the system memory 22.
[0063] Figure 3A According to some embodiments of the present application, a flowchart of a neural network model operation method is shown. Figure 3B According to some embodiments of the present application, a timing diagram of a neural network model calculation is shown. Figure 3A and Figure 3B The embodiment of the present application is introduced, and the operation method includes the following steps:
[0064] Step 301: The computing unit 211 reads a data block N from the input data according to the size of the storage unit 212 to perform computing layer calculations and generate computing layer calculation results C of the data block N. N , and C N Stored in the storage unit 212.
[0065] It can be understood that in some embodiments, the computing unit 211 can determine the size of the data block read at a time according to the size of the area in the storage unit 212 that can be used to store the calculation results, thereby dividing the input data into multiple sub-data blocks. Figure 3B , the input data is a three-dimensional matrix of size W×H×C. Due to the limitation of the space size of the area in the storage unit 212 that can be used to store the calculation results, the processor 21 cannot perform calculation layer calculation on all the input data at the same time. Therefore, the processor 21 can divide the input data into n sub-data blocks in the H direction according to the size of the area in the storage unit 212 that can be used to store the calculation results, that is, data block 1, data block 2, ..., data block n. The operation unit 211 reads one data block each time to perform calculation layer calculation, and stores the calculation results in the storage unit 212 during the calculation process. Wherein, 1≤N≤n.
[0066] It can be understood that the sizes of data block 1, data block 2, ..., data block n can be the same or different, and the embodiment of the present application does not limit this.
[0067] It will be appreciated that in some embodiments, the size of the data block N is smaller than the available space of the storage unit 212 .
[0068] Step 302: The processor 21 calculates the result C NThe processor 21 transmits the calculation result C to the system memory 22 after the computing unit 211 completes the calculation layer calculation of a data block, for example, after completing the calculation layer calculation of the data block N. N Transferred to the system memory 22.
[0069] Step 303: The processor 21 determines whether the computational layer computations of all data blocks have been completed. If yes, the process goes to step 304; otherwise, the process goes to step 301.
[0070] It can be understood that when the computing layer calculation of the data block n is completed, the computing layer calculation of the input data is completed. At this time, the computing layer calculation results of the input data are stored in the system memory 22.
[0071] Step 304: The processor 21 reads the calculation result C from the system memory 22 N The processor 21 sequentially reads the calculation layer calculation results of each data block from the calculation layer calculation results stored in the system memory 22, for example, reading the calculation layer calculation result C of data block N. N .
[0072] Step 305: DMAC 2101 calculates the result C N Perform sorting layer sorting to generate sorting result R N , and sort the result R N The DMAC 2101 calculates the result C of the computation layer of the data block N. N Sort the sorting layer and send the sorting result R N Transmitted to the system memory 22 to generate the neural network model calculation result of data block N (the calculation result of data block N).
[0073] It can be understood that in other embodiments, the sorting process of the sorting layer can also be executed by other modules, such as the computing unit 211, and the embodiment of the present application is not limited thereto.
[0074] Step 306: The processor 21 determines whether the sorting of the sorting layers of all data blocks has been completed. If yes, the operation ends, otherwise, the process goes to step 304.
[0075] It can be understood that when the sorting layer of the data block n is sorted, the neural network model calculation of the input data is completed.
[0076] In this way, the processor 21 needs to read / write the memory 22 multiple times when performing neural network calculations, and when it is necessary to store all the calculation results of the calculation layer in the system memory 22, it takes up space in the system memory 22 and affects the performance of the electronic device 20. In addition, since the calculation layer calculations and sorting layer sorting are performed serially on data blocks 1 to data n during the operation of the neural network model, the calculation speed is slow.
[0077] In order to solve the problems in the above-mentioned embodiments, the embodiments of the present application also provide a method for running a neural network model, by setting multiple storage areas in the storage unit 212 for storing the calculation layer calculation results of different parts of the input data (data to be processed), for example, setting two storage areas of the same size in the storage unit 212, respectively used to store the calculation layer calculation results of two adjacent data blocks in the input data, and, in the process of the operation unit 211 performing calculation layer calculation on a data block and storing it in one of the storage areas of the storage unit 212, the DMAC 2101 performs sorting layer sorting on the calculation layer calculation result of the previous data block stored in another storage area in the storage unit 212, and transmits the sorting result to the system memory 22. In this way, in the calculation cycle other than the calculation cycle of performing calculation layer calculation on the first data block and the calculation cycle of performing sorting layer sorting on the last data block, the processor 21 can perform calculation layer calculation and sorting layer sorting on different data blocks in parallel, thereby improving the running speed of the neural network model. In addition, the processor 21 accesses the system memory 22 only when transmitting the sorting result to the system memory 22, which reduces the number of times the processor 21 accesses the system memory 22, further improves the operating speed, reduces the occupancy of the system memory 22, and improves the performance of the electronic device 20.
[0078] It can be understood that in various embodiments of the present application, a calculation cycle refers to the time required for the processor 21 to perform calculation layer calculation or sorting layer sorting on a single data block. In some embodiments, if only calculation layer calculation or sorting layer sorting is performed in a single calculation cycle, the calculation cycle is the time for calculation layer calculation or sorting layer sorting. In other embodiments, if both calculation layer calculation and sorting layer sorting are performed in a single calculation cycle, the calculation cycle is the time that takes longer in calculation layer calculation and sorting layer sorting.
[0079] Specifically, Figure 4A According to some embodiments of the present application, a flowchart of a method for operating a neural network model is shown. Figure 4B A timing diagram of a neural network model operation method is shown. Figure 4A and Figure 4B The embodiment of the present application is introduced, and the operation method includes the following steps:
[0080] Step 401 : The processor 21 sets a plurality of storage areas in the storage unit 212 .
[0081] It can be understood that in order to facilitate the process of the computing unit 211 performing computing layer calculations on a part of the input data, the DMAC 2101 can perform a sorting layer sorting on the computing layer calculation results of other parts of the input data, and multiple storage areas can be set in the storage unit 212 to store the computing layer calculation results of different parts of the input data. For example, in some embodiments, two storage areas, namely, the storage area S0 and the storage area S1, can be set in the storage unit 212 to store the computing layer calculation results of different parts of the input data.
[0082] In some embodiments, the aforementioned storage area S0 (first storage area) and storage area S1 (second storage area) may be of the same size, so that the size of the input data read by the computing unit 211 at a time is the same, which facilitates the division of the input data. In addition, if the available space in the storage unit 212 is constant, the same size of the storage area S0 and the storage area S1 can maximize the size of the input data read by the computing unit 211 at a time when the size of the input data read by the computing unit at a time is the same, thereby improving the calculation speed.
[0083] In other embodiments, the storage area S0 and the storage area S1 may not be of the same size, which is not limited here. Moreover, in the case where the storage area S0 and the storage area S1 are of different sizes, if the operation unit 211 reads the same size of input data each time, the size of the input data read by the operation unit 211 each time can be determined according to the size of the calculation result of the calculation layer that can be stored in the smaller one of the storage area S0 and the storage area S1, that is, the size of the input data processed by the processor 21 in a single calculation cycle is adapted to the smaller one of the storage area S0 and the storage area S1.
[0084] It can be understood that in some embodiments, the total size of the aforementioned multiple storage areas can be determined according to the available storage space in the storage unit 212. For example, when the storage areas set are the aforementioned storage area S0 and storage area S1, in the case where the available space in the storage unit 212 is smaller than a, the sizes of the storage area S0 and the storage area S1 can be (ab) / 2, where b is the reserved size of the storage unit 212, so as to avoid the full load of the storage unit 212 affecting the normal operation of the processor 21.
[0085] It can be understood that in the embodiment of the present application, the use of two storage areas S0 and S1 as an example to illustrate the setting of the storage area is only an example. In other embodiments, other numbers of storage areas may also be set, which is not limited here.
[0086] Step 402: The computing unit 211 determines the size of the input data to be read each time according to the sizes of the multiple storage areas that are set.
[0087] For example, in some embodiments, the operation unit 211 can determine the size s of the input data corresponding to the calculation result of the size that can be stored in the space of multiple storage areas, thereby dividing the input data into several data blocks with a size less than s, and reading at least one data block with a total size less than s each time to perform the calculation layer calculation.
[0088] Specifically, in some embodiments, the computing unit 211 may determine the size of the input data corresponding to the computing layer computing result that can be stored in the storage area S0 or the storage area S1 according to the size of the area that can be used to store the computing result in the storage unit 212, for example, according to the size of the storage area S0 or the storage area S1, that is, the size of the input data that the computing unit 211 reads at a time. Figure 4B , the input data is the same as the above embodiment, that is, when the input data is a matrix of size W×H×C, the available area in the storage unit 212 is the same as the above embodiment. Since the storage area S0 and the storage area S1 of the same size are set in the available area, the size of the data block calculated by the processor 21 at a time is half of the above embodiment. Therefore, the input data can be divided into 2n sub-data blocks in the H direction, that is, data block 1, data block 2, ..., data block 2n, and one data block is read each time for calculation layer calculation. It can be understood that the sizes of data block 1, data block 2, ..., data block 2n in the H direction can be the same or different, and the embodiment of the present application does not limit it.
[0089] Step 403: the operation unit 211 reads data from the input data in sequence to perform calculation layer calculations, and stores the calculation results in the set multiple storage areas respectively.
[0090] It can be understood that in some embodiments, the calculation results of two adjacent calculation layers can be stored in different storage areas to avoid the calculation layer results generated by the operation unit 211 being overwritten before the DMAC 2101 completes the sorting of the calculation layer results, thereby affecting the accuracy of the calculation results. Figure 4B When the computing unit performs computing layer calculation on data block 1, the computing unit may store the computing result C1 in the storage area S0, and when the computing unit performs computing layer calculation on data block 2, the computing result C2 may be stored in the storage area S1.
[0091] It can be understood that in some embodiments, when the storage area set in the aforementioned step 401 is the storage area S0 and the storage area S1, the calculation results of two adjacent calculation layers are stored in different storage areas. Therefore, the calculation results of each alternate data block exist in the same storage area. Therefore, when the operation unit 211 has completed the calculation layer calculation of the data block N and the DMAC 2101 has not yet completed the calculation layer calculation result C of the data block N-1, N-1 When sorting the sorting layer, the operation unit 211 needs to wait until the DMAC 2101 completes the calculation result C N-1 After the sorting layer is sorted, the data block N+1 is calculated at the calculation layer to avoid the operation unit 211 and the DMAC 2011 operating on the same storage area.
[0092] Step 404: DMAC 2101 performs sorting layer sorting on the calculation layer calculation results stored in the storage unit 212, and sends the sorting results to the system memory 22. After the operation unit 211 completes the calculation layer calculation of the read input data and stores the calculation results in one of the aforementioned multiple storage areas, DMAC 2101 can perform sorting layer sorting on the calculation results stored in the area and store them in the system memory 22. In addition, during the process of DMAC2101 performing sorting layer sorting, the operation unit 211 can continue to read the input data to perform calculation layer calculation and send the calculation results to other storage areas.
[0093] For example, in some embodiments, as described above, it is assumed that the processor 21 calculates the result C when executing step 403. N-1 If the calculation result C is stored in the storage area S1, the DMAC 2101 performs the calculation on the calculation result C stored in the storage area S1. N-1 Perform sorting layer sorting to generate sorting result R N-1 , and sort the result R N-1 The result C is sent to the system memory 22. The DMAC 2101 calculates the result C N-1 During the sorting process, the computing unit 211 can perform a computing layer calculation on the data block N to generate a calculation result C N And the calculated result C N Stored in storage area S0.
[0094] It can be understood that in most cases (except for the calculation period T′1 for calculating the calculation layer of data block 1 and the calculation period T′ for sorting the sorting layer of data block n) 2n+1 Step 403 and step 404 are always executed in parallel, that is, when the computing unit 211 performs the computing layer calculation on the data block N, the DMAC 2101 performs the computing layer calculation result C on the data block N-1. N-1Sort by sorting layer.
[0095] It is understood that in some embodiments, when DMAC 2101 has completed the calculation of the result C N-1 When the sorting layer of the data block N is sorted and the operation unit 211 has not completed the calculation layer calculation of the data block N, the DMAC 2101 needs to wait until the operation unit 211 completes the calculation layer calculation of the data block N, and then calculate the calculation layer calculation result C of the data block N stored in the storage area S0 or the storage area S1. N Sorting layer sorting is performed to prevent the operation unit 211 and the DMAC 2011 from operating on the same storage area.
[0096] It can be understood that in other embodiments, the sorting layer sorting may not be performed by DMAC 2011, and the embodiment of the present application does not limit this.
[0097] Step 405: The processor 21 determines whether the neural network calculation of all input data has been completed. If the neural network calculation of all input data has been completed, the calculation process ends; otherwise, the process goes to step 403.
[0098] refer to Figure 3B , since the input data is divided into n data blocks, the processor 21 can only perform calculation layer calculation or sorting layer sorting on a single data block in a single calculation cycle, so Figure 3B The embodiment shown requires 2n computation cycles (T1 to T 2n ) to complete the neural network calculation of the aforementioned input data. Figure 4B Since the input data is divided into 2n data blocks, the processor 21 only performs calculation layer calculation or sorting layer sorting in the first calculation cycle and the last calculation cycle, and performs calculation layer calculation and sorting layer sorting on two different data blocks in the middle calculation cycle. Therefore Figure 4B In the embodiment shown, 2n+1 calculation cycles (T′1 to T′ 2n+1 ) completes the neural network calculation for input data of the same size.
[0099] because Figure 3A and Figure 3B The size of the data block processed by the processor 21 in a single computing cycle of the provided neural network model operation method is Figure 4A and Figure 4B The neural network model running method provided is twice the size of the data block processed in a single cycle, and thus it can be considered that T1+T2+…+T 2n The total time t is approximately T′1+T′2+…+T′ 2n+1 Twice the total time t′, that is, using FIG. 4A to FIG. 4BThe provided method for running a neural network model can significantly improve the running speed of the neural network model. Moreover, referring to Figure 4B , by using FIG. 4A to FIG. 4B the provided method for running a neural network model, the calculation results of the calculation layer do not need to be stored in the system memory 22, reducing the number of times of accessing the system memory 22 during the running of the neural network model. Consequently, the calculation speed is improved. Additionally, it can also reduce the occupation of the system memory 22 during neural network calculations, saving the bandwidth of the electronic device 20, thereby enhancing the performance of the electronic device 20.
[0100] Next, in combination with Figure 4A and Figure 4B the provided method for running a neural network model, taking the calculation layer 12 of the neural network model 10 as a convolutional layer and the sorting layer 13 as a Depth to Space layer as an example, the technical solution of the method for running a neural network model provided by the embodiments of the present application will be introduced in detail.
[0101] To facilitate the understanding of the technical solution of the embodiments of the present application, before introducing the calculation process of the neural network model, the calculation process of convolution will be introduced first. Assume that the size of matrix A is M×M, the size of the convolution kernel K is N×N, and the convolution stride is k. Then the convolution result H of matrix A and convolution kernel K can be expressed as:
[0102] (1)
[0103] In formula (1), H(m, n) is the element in the m-th row and n-th column of matrix H; m and n satisfy the following relational expressions:
[0104] , .
[0105] Among them is the floor operation, that is is the largest integer less than X. Since M - N < M and k is a positive integer, it can be seen that , which means that the size of the convolution result H is always less than or equal to the size of matrix A.
[0106] To ensure that the size of the matrix corresponding to the convolution result is the same as the size of the input data and avoid losing the data features at the edges of the picture data matrix, usually during the convolution calculation, rows with a value of 0 are filled before the first row and after the last row of the input matrix, and rows or columns with a value of 0 are filled before the first column and after the last column of the input matrix, that is, rows or columns with a value of 0 are filled around the input matrix. Assume that the number of values of 0 filled around the input matrix A is P for each side. At this time, the size of the input matrix A becomes (M + 2P)×(M + 2P). At this time, m and n in formula (1) satisfy the following relational expressions:
[0107] , .
[0108] make , the value of P can be calculated.
[0109] The basic functions of the neural network model are introduced below.
[0110] Figure 5 According to some embodiments of the present application, a schematic diagram of a calculation process of a neural network in which the calculation layer 12 is a convolutional layer and the sorting layer 13 is a Depth to Space layer is shown. Figure 5 , the input data of the input layer 11 of the neural network model 10 is image data, the size of the image data matrix A0 is 9×9×1 (that is, W is 9, H is 9, C is 1), and each element in the image data matrix corresponds to a pixel of the image. The computation layer 12 includes 9 convolution kernels K of size 3×3 i (i=1, 2, ..., 9), and the image data matrix is convolved with 9 convolution kernels in the calculation layer 12 according to formula (1) to extract 9 features of the image data. In addition, P=1 during the calculation process, so that the image data matrix generates 9 feature matrices of size 9×9×1 (O1 to O9 in the figure) after convolution by the calculation layer 12, that is, the calculation result of the calculation layer 12 can be expressed as a 9×9×9 (W×H×C) matrix A1.
[0111] Continue to refer Figure 5 , the sorting layer 13 reorders the 1×1×9 matrix with the same size of W and H in the calculation result of the calculation layer 12 to generate a 3×3×1 matrix, and uses this matrix to replace the positions of the elements with the same size of W and H in the image data matrix. Since each element in the image data matrix corresponds to a pixel of the image data, that is to say, after the neural network calculation, each pixel in the input image data is replaced by 9 pixels, thereby improving the resolution of the image. In some embodiments, the above neural network is also called a super-resolution network. For example, in the calculation result matrix A1 of the calculation layer 12, A1 (1, 1, i), where i = 1, 2, ..., 9, the values of A, B, C, D, E, F, G, H, I are respectively, and in the reordered 3×3×1 matrix A2 11 for:
[0112]
[0113] And, after sorting layer 13 completes the sorting, it uses A2 11Replace the position of A0 (1, 1) in the image data matrix A0. It can be understood that after the sorting layer 13 completes the sorting of the calculation result matrix A1, that is, after the image data matrix A0 is calculated by the neural network model 10, the output result is a 27×27×1 matrix, so that the resolution of the input image data becomes 3 times the original.
[0114] The following is combined Figure 4A and Figure 4B The neural network model operation method provided and Figure 5 The calculation process of the neural network model 10 shown provides a detailed introduction to the technical solution of the embodiment of the present application.
[0115] Assume that the space in the storage unit 212 of the processor 21 that can be used to store the result of the convolution layer can store a matrix of size 9×6×9, so two storage areas S0 and S1 that can store matrices of size 9×3×9 respectively can be set in the space. Figure 6 , at this time, the image data matrix A0 can be divided into data blocks 1, data blocks 2 and data blocks 3 with a height of 3 in the height direction (H direction), corresponding to rows 1 to 3, rows 4 to 6 and rows 7 to 9 of A0 respectively, so that the data block and the 9 convolution kernels K i The calculation result after convolution has a size of 9×3×9, and can be stored in the storage area S0 or the storage area S1.
[0116] As mentioned above, in calculating the image data matrix A0 and the convolution kernel K i During convolution, rows with values of 0 are filled before the first row and after the last row of the image data matrix A0, and columns with values of 0 are filled before the first column and after the last column of the image data matrix A0, thereby ensuring that the convolution result is the same size as the image data matrix A0, and avoiding loss of features of the image data matrix A0 due to convolution. In an embodiment of the present application, in order to ensure that the convolution result after the image data matrix A0 is divided into blocks is the same as when the block calculation is not performed, it is necessary to fill the 0 rows and / or columns in different ways according to the position of the data block.
[0117] Specifically, continue to refer to Figure 6, when the calculated data block is the first data block, for example, data block 1, the operation unit 211 reads data block 1 and the next row of data of the data block, and adds a row with a value of 0 before the first row of the read data, and adds a column with a value of 0 before the first column and after the last column of the read data. That is to say, when the convolution calculation is performed on data block 1, the data A01 actually involved in the convolution calculation is the data of the 1st to 4th rows in the image data matrix A0 before the first row, after adding a row with a value of 0, and after adding a column with a value of 0 before the first column and after the last column; similarly, when the calculated data block is an intermediate data block, for example, data block 2, the operation unit 211 reads data block 2 and the previous and next rows of the data block, and adds a column with a value of 0 before the first column and after the last column of the read data. That is to say, the operation When unit 211 performs convolution calculation on data block 2, the data A02 actually participating in the convolution calculation is the data of rows 3 to 7 in the image data matrix A0, with one column of value 0 added before the first column and after the last column; similarly, when the calculated data block is the last data block, for example, data block 3, the operation unit 211 reads data block 3 and the previous row of data of the data block, and adds one row of value 0 after the last row of the read data, as well as one column of value 0 before the first column and after the last column of the read data, that is to say, when performing convolution calculation on data block 3, the data A03 actually participating in the convolution calculation is the data of rows 6 to 9 in the image data matrix A0, with one row of value 0 added after the last row, and one column of value 0 added before the first column and after the last column.
[0118] further, Figure 7 According to some embodiments of the present application, a schematic diagram of performing convolution calculation on data block 1 is shown. Figure 7 As shown, the operation unit 211 first performs convolution calculation on the data A01 and the convolution kernel K1 according to formula (1) to generate a calculation result C 1-1 And store it in the storage area S0. During the calculation process, according to formula (1), m=1 to 3, n=1 to 9 are taken in turn to calculate the convolution result of data A01 and convolution kernel K1. For example, when m=1 and n=1 are taken in formula (1), the data in A01 involved in the calculation is the data in area 71 shown in the figure. At this time, C 1-1 (1, 1) = 12; for another example, when m = 3, n = 9 in formula (1), the data in A01 involved in the calculation is the data in area 72 in the figure. At this time, C 1-1(3, 9) = 44. After the operation unit 211 completes the convolution calculation of A01 and the convolution kernel K1, it calculates the convolution of A01 and the convolution kernels K2 to K9 in turn, and stores the results in the storage area S0, thereby forming the calculation layer calculation result C1 of the data block 1. It can be understood that when the operation unit 211 completes the convolution calculation of the data A01 and the convolution kernels K1 to K9, the calculation layer calculation result C1 of the data block 1 is stored in the storage area S0.
[0119] It can be understood that in some embodiments, the operation unit 211 may include multiple units for performing convolution calculations. In this case, the operation unit 211 can simultaneously execute the calculation of data A01 and multiple convolution kernels. For example, when the operation unit 211 includes 9 convolution calculation units, the operation unit 211 can simultaneously calculate the convolution of data A01 and convolution kernels K1 to K9, which is not limited here.
[0120] refer to Figure 8 After completing the convolution calculation of data block 1 and storing the calculation result C1 in the storage area S0, the operation unit 211 starts to perform convolution calculation on data block 2. Please refer to the calculation process of the aforementioned data block 1 for the process, which will not be repeated here. The difference from the aforementioned data block 1 is that the convolution calculation result C2 of data block 2 is stored in the storage area S1.
[0121] refer to Fig. 9 , while the operation unit 211 performs convolution calculation on the data block 2, the DMAC 2101 performs Depth to Space sorting on the convolution calculation result C1 of the data block 1 stored in the storage area S0. That is, the sorting layer 13 re-sorts the 1×1×9 matrix with the same W and H in C1 to generate a 3×3×1 matrix, and uses the matrix to replace the positions of the elements with the same W and H in the data block 1. For example, the calculation result matrix C1 (1, 1, i), where i = 1, 2, ..., 9, in the calculation layer 12 is respectively 12, 12, 16, 11, 32, 67, 47, 47, 11, and the re-sorted 3×3×1 matrix C 1-11 for:
[0122]
[0123] In addition, DMAC 2101 uses C 1-11 Replace W=1, H=1 in data block 1, that is, the position of image data matrix A0 (1, 1), and store it in system memory 22. It can be understood that DMAC 2101 completes the sorting layer of the convolution calculation result C1 of data block 1, that is, generates the sorting layer sorting result R1 of the calculation result C1, that is, the neural network calculation result of data block 1, and the size of the result is 27×9×1.
[0124] After DMAC 2101 completes the sorting of the convolution calculation results of data block 1, the operation unit 211 performs convolution calculation on data block 3. Fig.10 , the operation unit 211 performs convolution calculations on the data A03 corresponding to the data block 3 with the convolution kernels K1 to K9 respectively and stores the calculation results in the storage area S0. The specific calculation process refers to the convolution calculation process of the data block 1, which will not be repeated here. Fig.11 , during the process of the operation unit 211 performing convolution calculation on the data block 3, the DMAC 2101 performs Depth to Space sorting on the convolution calculation result C2 of the data block 2 stored in the storage area S1, generates the sorting result R2 of the calculation result C2, and transmits the sorting result R2 to the system memory 22. For details, please refer to the aforementioned process of sorting the calculation result C1 of the data block 1, which will not be repeated here. After the DMAC 2101 completes the Depth to Space sorting of the calculation result C2 of the data block 2, the neural network calculation results of the data block 1 and the data block 2 are stored in the system memory 22.
[0125] After DMAC 2101 completes the sorting of the convolution calculation results of data block 2, if the operation unit 211 has completed the convolution calculation of data block 3 and stored the calculation result C3 in the storage area S0, refer to Fig.11 , DMAC 2101 performs Depth to Space sorting on the convolution calculation results of data block 3 stored in storage area S0, generates calculation result C3 sorting result R3, and passes sorting result R3 to system memory 22. At this time, system memory 22 stores the neural network calculation results of input data of size 9×9×1. It can be seen that after the operation, the size of the image data becomes 27×27×1, and the number of elements of the image data matrix in both row and column directions becomes 3 times that of the original image data, which means that the resolution (pixel density) of the image data is increased to 3 times that of the original image.
[0126] Through the neural network model operation method provided by the embodiment of the present application, when calculating a neural network model including a calculation layer and a sorting layer following the calculation layer, the operation speed of the neural network model is improved by executing the calculation of the calculation layer and the sorting of the sorting layer in parallel, and there is no need to access the system memory 22 during the calculation of the calculation layer, which reduces the number of accesses to the system memory 22 and further improves the operation speed of the neural network model. In addition, since there is no need to transmit the calculation results of the calculation layer to the system memory 22 during the calculation of the calculation layer, the occupation of the system memory 22 is reduced, the bandwidth of the electronic device is saved, and the performance of the electronic device is improved.
[0127] It can be understood that the technical solution of the embodiment of the present application introduced by taking the neural network model 10 as a super-resolution network in the aforementioned embodiment is only an example. In some embodiments, the neural network model 10 can also be a neural network model with other functions, such as a neural network model for intelligently editing videos, a neural network model for identifying the vehicle driving environment in an intelligent driving scenario, a neural network model for identifying sound files in a voice input scenario, a neural network model for intelligently identifying photo scenes and adjusting camera parameters in a shooting scenario, etc., which are not limited here.
[0128] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.
[0129] Program code may be applied to input instructions to perform the functions described herein and to generate output information. The output information may be applied to one or more output devices in a known manner. For purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0130] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.
[0131] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed over a network or through other computer-readable media. Therefore, a machine-readable medium may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including but not limited to floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROM), random access memories (RAM), erasable programmable read-only memories (EPROM), electrically erasable programmable read-only memories (EEPROM), magnetic or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).
[0132] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.
[0133] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.
[0134] It should be noted that in the examples and description of this patent, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises one" does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0135] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.
Claims
1. A method for operating a neural network model, applied to an electronic device, the electronic device comprising a processor, a first memory disposed outside the processor, and a second memory disposed inside the processor, characterized in that: The neural network model includes a calculation layer and a sorting layer, wherein the sorting layer is a layer that does not need to calculate the data, and the sorting layer includes at least one of the following neural networks: a depth-to-space conversion network, a space-to-depth conversion network, a transposition network, a cropping network, and a filling network; And the method comprises: The processor uses the calculation layer and the sorting layer to perform the following processing on the first data part and the second data part successively obtained from the data to be processed: Determine the size of the first data portion and the size of the second data portion according to the size of the first storage area of the second storage area and the second storage area of the second storage area, wherein the first data portion and the second data portion are respectively from two adjacent data blocks in the data to be processed; Acquire the first data portion, and calculate the first data portion through the calculation layer of the neural network model to obtain a first calculation result, and store the first calculation result in a first storage area of the second memory, wherein the data amount of the first calculation result of the first data portion is smaller than the storage space of the first storage area, and the first data portion includes 0 rows and / or columns filled according to the position of the first data portion in the data to be processed; and After storing the first calculation result in the first storage area, performing the following operations: sorting the first calculation results read from the first storage area by the sorting layer to obtain a first sorting result, and storing the first sorting result in the first memory, and Acquire the second data portion, calculate the second data portion to obtain a second calculation result, and store the second calculation result in a second storage area of the second memory, wherein the amount of data of the calculation result of the second data portion is smaller than the storage space of the second storage area, and the second data portion includes 0 rows and / or columns filled according to the position of the second data portion in the data to be processed.
2. The method according to claim 1, characterized in that After storing the second calculation result in the second storage area of the second memory, the method further includes: The second calculation results read from the second storage area are sorted by the sorting layer to obtain a second sorting result, and the second sorting result is stored in the first memory.
3. The method according to claim 1 or 2, characterized in that: The first storage area and the second storage area have the same size.
4. The method according to claim 3, characterized in that The computing layer includes at least one of the following neural networks: a convolutional network, an element addition network, an element multiplication network, and a matrix element correspondence multiplication network.
5. An electronic device for running a neural network model, characterized in that: The electronic device includes a processor, a first memory disposed outside the processor, and a second memory disposed inside the processor, wherein: The processor uses the computing layer and the sorting layer of the neural network model to process the first data part and the second data part successively obtained from the data to be processed as follows: Determine the size of the first data portion and the size of the second data portion according to the size of the first storage area of the second storage area and the second storage area of the second storage area, wherein the first data portion and the second data portion are respectively from two adjacent data blocks in the data to be processed; Acquire the first data portion, and calculate the first data portion through the calculation layer of the neural network model to obtain a first calculation result, and store the first calculation result in a first storage area of the second memory, wherein the data amount of the first calculation result of the first data portion is smaller than the storage space of the first storage area, and the first data portion includes 0 rows and / or columns filled according to the position of the first data portion in the data to be processed; and After storing the first calculation result in the first storage area, performing the following operations: The first calculation results read from the first storage area are sorted by the sorting layer to obtain a first sorting result, and the first sorting result is stored in the first memory, wherein the sorting layer is a layer that does not need to calculate the data, and the sorting layer includes at least one of the following neural networks: a depth-to-space conversion network, a space-to-depth conversion network, a transposition network, a cropping network, and a filling network, and Acquire the second data portion, calculate the second data portion to obtain a second calculation result, and store the second calculation result in a second storage area of the second memory, wherein the amount of data of the calculation result of the second data portion is smaller than the storage space of the second storage area, and the second data portion includes 0 rows and / or columns filled according to the position of the second data portion in the data to be processed.
6. The electronic device according to claim 5, characterized in that: After the processor stores the second calculation result in the second storage area of the second memory, it sorts the second calculation result read from the second storage area through the sorting layer to obtain a second sorting result, and stores the second sorting result in the first memory.
7. The electronic device according to claim 6, characterized in that: The processor further includes a direct memory access controller, and the direct memory access controller sorts the first calculation results read from the first storage area through the sorting layer to obtain a first sorting result, and stores the first sorting result in the first memory; as well as The direct memory access controller sorts the second calculation results read from the second storage area through the sorting layer to obtain a second sorting result, and stores the second sorting result in the first memory.
8. The electronic device according to claim 7, characterized in that: The processor further includes a computing unit, and the computing unit calculates the first data portion to obtain a first calculation result, and stores the first calculation result in a first storage area of the second memory; as well as The computing unit calculates the second data portion to obtain a second calculation result, and stores the second calculation result in a second storage area of the second memory.
9. The electronic device according to any one of claims 5 to 8, characterized in that: The first storage area and the second storage area have the same size.
10. The electronic device according to claim 9, characterized in that: The computing layer includes at least one of the following neural networks: a convolutional network, an element addition network, an element multiplication network, and a matrix element correspondence multiplication network.
11. A readable medium, characterized in that: The readable medium contains instructions, which, when executed by a processor of an electronic device, enable the electronic device to implement the neural network model operation method described in any one of claims 1 to 4.
