A neural network accelerator compilation method and device

By generating instructions for parallel operation strategies and using circular buffers and superscalar technology to optimize neural network accelerators, the problem of low efficiency and poor versatility of neural networks in edge deployment is solved, achieving more efficient computing and real-time deployment.

CN113554161BActive Publication Date: 2024-10-15TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110821142.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-20
Publication Date
2024-10-15
Estimated Expiration
2041-07-20

AI Technical Summary

Technical Problem

When existing technologies deploy neural networks at the edge, there are problems of low efficiency and poor versatility. Especially in terms of data transmission and instruction set adjustment, it is difficult to achieve real-time requirements.

Method used

By generating dependencies and compiler instruction queues based on neural network structure information and preset instruction types, we determine the parallel running strategy, use circular buffers and superscalar technology to optimize the acceleration instructions of the neural network accelerator, and achieve parallelism of feature maps and weights. Parallel processing of loading and convolution calculations.

Benefits of technology

It improves the computing efficiency and resource utilization of neural networks at the edge, achieves faster deployment and real-time performance, and accelerates the reasoning process of AI algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113554161B_ABST
    Figure CN113554161B_ABST
Patent Text Reader

Abstract

The present invention provides a neural network accelerator compilation method and device, the method comprising: based on neural network structure information and preset instruction types, generating dependencies between each preset instruction type and multiple neural network compiler instruction queues, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; according to the dependency, determining the parallel operation strategy between each neural network compiler instruction queue; according to the parallel operation strategy, generating acceleration instructions for the neural network accelerator. The present invention can effectively solve the problems of neural network parameter loading and module utilization by integrating flexible dynamic adjustment technologies such as circular buffers and superscalars in a neural network dedicated accelerator, so that neural networks can be deployed more quickly at the edge.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a neural network accelerator compilation method and device. Background Art

[0002] At present, the technology in the field of artificial intelligence (AI) has made great progress. Deep neural networks suitable for complex tasks such as recognition, detection and tracking are applied in all walks of life. In order to deploy AI algorithms at the edge and realize end-cloud collaboration, embedded neural network processor technology has developed rapidly.

[0003] The computational and spatial costs of neural network reasoning are high. In order to support low-power and low-computing edge hardware, a large number of compression technologies such as quantized learning and sparse pruning have been proposed, and operators such as convolution have also achieved parallel computing at the edge. Among them, quantized learning replaces the floating-point weights float32 in the original network with integer int8, which not only reduces the size of network parameters but also speeds up the calculation speed of convolution at the cost of a small loss of precision; sparse pruning removes unimportant parameters and redundant structures such as layers in the network, saving parameter storage space and greatly saving reasoning time.

[0004] However, technologies such as quantized learning and sparse pruning are all used to reduce the size of the neural network during the training and reasoning phase, and are not combined with dedicated neural network accelerators at the edge for optimization. The computation of neural network algorithms at the edge is still inefficient and has poor versatility. Data transfer between different layers still consumes a lot of redundant resources, and the utilization of each module still has a lot of room for improvement. At the same time, the instruction set run by the accelerator requires complex adjustments from the cloud to the edge, and it is far from meeting the real-time requirements through convolution hardware acceleration alone. Therefore, there is an urgent need for a neural network accelerator compilation method and device to solve the above problems. Summary of the invention

[0005] In view of the problems existing in the prior art, the present invention provides a neural network accelerator compilation method and device.

[0006] The present invention provides a neural network accelerator compilation method, comprising:

[0007] Based on the neural network structure information and the preset instruction type, a dependency relationship between each preset instruction type and a plurality of neural network compiler instruction queues are generated, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type;

[0008] Determine a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship;

[0009] According to the parallel operation strategy, an acceleration instruction of the neural network accelerator is generated.

[0010] According to a neural network accelerator compilation method provided by the present invention, the dependency relationship between each preset instruction type and multiple neural network compiler instruction queues are generated based on the neural network structure information and the preset instruction type, including:

[0011] According to the preset instruction type, construct corresponding neural network compiler instructions, wherein the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions, and result storage instructions;

[0012] According to the neural network structure information, determine whether there is parallel operation between each neural network compiler instruction, and build a dependency relationship between each preset instruction type according to the parallel operation determination result, wherein the neural network structure information at least includes a preceding layer, a succeeding layer, the number of input and output channels, a convolution kernel size, and an input and output data width and an input and output data height;

[0013] Based on the first-in-first-out method and the dependency relationship, a corresponding neural network compiler instruction queue is generated according to the neural network compiler instructions of the same preset instruction type.

[0014] According to a neural network accelerator compilation method provided by the present invention, the parallel operation strategy between each neural network compiler instruction queue is determined according to the dependency relationship, including:

[0015] According to the parallel operation judgment result, the neural network compiler instructions that cannot be run in parallel are marked by a flag bit to obtain the dependency relationship between the preset instruction types;

[0016] Based on superscalar technology, a parallel execution strategy between each neural network compiler instruction queue is generated according to the dependency relationship.

[0017] According to a neural network accelerator compilation method provided by the present invention, the superscalar technology is used to generate a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship, including:

[0018] Based on the circular cache method, according to the feature map loading instructions and weight loading instructions of the current layer of the neural network, the feature map and weight are loaded in parallel into their corresponding SRAMs;

[0019] Perform convolution calculation according to the convolution calculation instruction of the current layer of the neural network to obtain the convolution calculation result of the current layer of the neural network;

[0020] According to the result storage instruction of the current layer of the neural network and the weight loading instruction of the next layer of the neural network, the convolution calculation result obtained by the current layer of the neural network is stored back to the DDR through parallel loading, and the weight of the next layer of the neural network is loaded into the corresponding SRAM.

[0021] According to a neural network accelerator compilation method provided by the present invention, after generating the acceleration instruction of the neural network accelerator according to the parallel operation strategy, the method further includes:

[0022] According to the neural network structure information, slicing the neural network is performed;

[0023] Perform ping-pong operations on the sliced ​​neural network.

[0024] According to a neural network accelerator compilation method provided by the present invention, after generating acceleration instructions for the neural network accelerator according to the parallel operation strategy, the method further includes:

[0025] The neural network accelerator is based on a producer-consumer model and operates according to the acceleration instructions.

[0026] The present invention also provides a neural network accelerator compilation device, characterized in that it includes:

[0027] A preset instruction and dependency generation module, used to generate a dependency relationship between each preset instruction type and a plurality of neural network compiler instruction queues based on the neural network structure information and the preset instruction type, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type;

[0028] A parallel strategy generation module, used to determine the parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship;

[0029] A compiling module is used to generate acceleration instructions for a neural network accelerator according to the parallel operation strategy.

[0030] According to a neural network accelerator compilation device provided by the present invention, the preset instruction and dependency relationship generation module includes:

[0031] An instruction generation unit, used to construct corresponding neural network compiler instructions according to a preset instruction type, wherein the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions, and result storage instructions;

[0032] A dependency generation unit is used to determine whether there is parallel operation between each neural network compiler instruction according to the neural network structure information, and to construct a dependency relationship between each preset instruction type according to the parallel operation determination result, wherein the neural network structure information at least includes a preceding layer, a succeeding layer, the number of input and output channels, a convolution kernel size, and an input and output data width and an input and output data height;

[0033] An instruction queue generation unit is used to generate a corresponding neural network compiler instruction queue based on a first-in-first-out method and the dependency relationship according to neural network compiler instructions of the same preset instruction type.

[0034] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the neural network accelerator compilation methods described above are implemented.

[0035] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the neural network accelerator compilation methods described above.

[0036] The present invention provides a neural network accelerator compilation method and device, which can effectively solve the problems of neural network parameter loading and module utilization by integrating flexible dynamic adjustment technologies such as circular buffer and superscalar into a neural network dedicated accelerator, so that the neural network can be deployed more quickly on the edge. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 A schematic diagram of the process flow of the neural network accelerator compilation method provided by the present invention;

[0039] Figure 2 A schematic diagram of the overall framework of the neural network accelerator provided by the present invention;

[0040] Figure 3 A schematic diagram of the acceleration instruction structure of the neural network accelerator provided by the present invention;

[0041] Figure 4 A schematic diagram of the distribution of the circular buffer provided by the present invention;

[0042] Figure 5 A schematic diagram of a neural network segmentation method provided by the present invention;

[0043] Figure 6 A schematic diagram of the instruction flow of the neural network accelerator provided by the present invention;

[0044] Figure 7 A schematic diagram of the neural network acceleration effect provided by the present invention;

[0045] Figure 8 A schematic diagram of the structure of a neural network accelerator compiling device provided by the present invention;

[0046] Fig. 9 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION

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

[0048] Figure 1 A flowchart of the neural network accelerator compilation method provided by the present invention is shown in FIG. Figure 1 As shown, the present invention provides a neural network accelerator compilation method, comprising:

[0049] Step 101, based on the neural network structure information and the preset instruction type, generate the dependency relationship between each preset instruction type and multiple neural network compiler instruction queues, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type.

[0050] In the present invention, the structure of the network model is first analyzed to obtain the neural network structure information about the model, and at the same time, a variety of neural network compiler instructions are constructed according to preset instruction types.

[0051] Furthermore, the generation of dependencies between each preset instruction type and multiple neural network compiler instruction queues based on the neural network structure information and the preset instruction type specifically includes:

[0052] Step S1, constructing corresponding neural network compiler instructions according to preset instruction types, wherein the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions and result storage instructions.

[0053] In the present invention, the neural network compiler instructions are mainly composed of feature map load (FM) instructions, weight load (WT) instructions, convolution calculation (CAL) instructions and result save (RS) instructions, and the corresponding sequence is composed of instructions of these four preset instruction types.

[0054] Step S2, based on the neural network structure information, determine whether there is parallel operation between each neural network compiler instruction, and build a dependency relationship between each preset instruction type based on the parallel operation judgment result, wherein the neural network structure information at least includes the preceding layer, the succeeding layer, the number of input and output channels, the convolution kernel size, the input and output data width, and the input and output data height.

[0055] In the present invention, the neural network compiler needs to analyze the parameter information of each layer of the neural network, including the following basic parameters in the convolution layer of the neural network: preceding layer, succeeding layer, number of input and output channels, convolution kernel size, and input and output width and height, etc. Through these basic information, it can be obtained that there is parallel operation between instructions. In the present invention, by performing dependency analysis on the neural network structure information, the FM instructions and WT instructions of each layer of each neural network are loaded into the preset position of the static random access memory (SRAM) on the neural network accelerator, so as to perform convolution calculations and store the results back in the current layer of the neural network.

[0056] Step S3, based on the first-in-first-out method and the dependency relationship, generate a corresponding neural network compiler instruction queue according to the neural network compiler instructions of the same preset instruction type.

[0057] Figure 2 The overall framework diagram of the neural network accelerator provided by the present invention can be referred to Figure 2 As shown, taking any layer of a neural network for illustration, each neural network compiler instruction of the same preset instruction type, according to the First In First Out (FIFO) rule, forms a corresponding neural network compiler instruction queue of each type. Preferably, the present invention is based on a producer consumer model, and sets a corresponding resource dependency lock (LOCK) in each type of instruction queue.

[0058] Step 102: Determine the parallel operation strategy between each neural network compiler instruction queue based on the dependency relationship.

[0059] In the present invention, reference may be made to Figure 2As shown, the feature map loading instruction queue is sent to the feature map loading control part, and the DDR loads the feature map data into the corresponding area of ​​the SRAM (i.e., the FM SRAM). The single-layer data of the present invention is divided into two parts, and the calculation is accelerated by the ping-pong operation mode. Through calculations such as convolution pooling, the output is placed in the annular adjacent buffer of the SRAM; at the same time, based on the dependency between the instructions, the result storage of the current layer and the weight loading of the next layer are parallel. At this time, through the result storage instruction, the calculation result is returned to the DDR for the calculation of the next layer of the neural network, and the weight of the next layer is loaded into the corresponding area of ​​the SRAM (i.e., the WT SRAM). By repeating the above operations, a parallel operation strategy between each neural network compiler instruction queue is generated to realize multi-layer transmission of the neural network, thereby maximizing the utilization of the SRAM area on the neural network accelerator.

[0060] Step 103: Generate acceleration instructions for the neural network accelerator according to the parallel operation strategy.

[0061] In the present invention, the neural network instruction compiler can convert the neural network based on the circular buffer and superscalar technology through Python conversion scripts, generate an acceleration instruction set that can be run by a chip or FPGA accelerator, and the acceleration instruction set can achieve AI acceleration more efficiently on edge devices. In the present invention, the neural network instruction compiler includes a network structure interpreter (for analyzing the structure of the neural network), an instruction generator (for generating corresponding neural network compiler instructions according to the instruction type), a dependency generator (for obtaining dependencies based on the neural network structure information and related instructions), and a simulator to achieve fast compilation of different neural networks and generate optimized code that can be executed by edge accelerators.

[0062] Figure 3 A schematic diagram of the acceleration instruction structure of the neural network accelerator provided by the present invention is shown in FIG. Figure 3 As shown in the figure, the instruction consists of 64 bits, including opcode, Inst-info and Inst-Depend, etc. Inst-info contains the instruction name and debugging information, which indicates whether the instruction is FM, WT, CAL or RS; Inst-Depend is the information required for processing instruction dependencies, including ping-pong operations and status information. In addition, the instruction also contains the size information of each layer of the neural network, the block address and absolute address of the FM and WT related to the neural network, as well as slice information and other information required for hardware acceleration.

[0063] The neural network accelerator compilation method provided by the present invention can effectively solve the problems of neural network parameter loading and module utilization by integrating flexible dynamic adjustment technologies such as circular buffer and superscalar into the neural network dedicated accelerator, so that the neural network can be deployed more quickly on the edge.

[0064] Based on the above embodiment, the parallel operation strategy between each neural network compiler instruction queue is determined according to the dependency relationship, including:

[0065] According to the parallel operation judgment result, the neural network compiler instructions that cannot be run in parallel are marked by a flag bit to obtain the dependency relationship between the preset instruction types;

[0066] Based on superscalar technology, a parallel execution strategy between each neural network compiler instruction queue is generated according to the dependency relationship.

[0067] In the present invention, by using superscalar technology on a neural network accelerator, feature map weight loading, calculation result storage and convolution calculation instructions are parallelized during neural network reasoning. At the same time, a flag is added during instruction compilation to mark instructions that cannot be executed in parallel. Combining superscalar technology in a neural network accelerator can delay instructions that cannot be executed due to data dependency, thereby reducing the impact of data disasters.

[0068] Since only convolution calculations in the neural network require strict sequential execution, weight loading can be performed in advance, and result storage can be delayed. Therefore, in one embodiment, based on superscalar technology, when the convolution calculation of the current layer of the neural network is running, the result is stored back. At this time, the feature map of the next layer has not been generated, and naturally the feature map cannot be loaded. However, the weight loading of the next layer has no data instruction dependency, and the weights can be loaded in advance; in addition, based on the circular buffer, the ping-pong operation can be supported for neural network slices, and the feature map data of pong can be loaded while the convolution calculation of ping is being performed.

[0069] On the basis of the above embodiment, the superscalar technology is used to generate a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship, including:

[0070] Based on the circular cache method, the feature map and weight are loaded in parallel into their corresponding SRAMs according to the feature map loading instructions and weight loading instructions of the current layer of the neural network.

[0071] In the present invention, since SRAM has a faster access speed than double data rate (DDR) memory, but at the same time has high cost and power consumption, SRAM resources are usually less in edge hardware. The present invention uses a circular buffer in the SRAM area of ​​the neural network accelerator based on a circular cache method. Figure 4 For the distribution diagram of the circular buffer provided by the present invention, please refer to Figure 4 As shown, the circular buffer requires two pointers, the read end and the write end, to mark a buffer. When the write end writes to the buffer boundary, it will jump to the other boundary and continue writing until the write end pointer coincides with the read end pointer. At this time, the buffer is in the FULL state and can no longer be written. The read end will continue to read data until it coincides with the write end pointer.

[0072] Perform convolution calculation according to the convolution calculation instruction of the current layer of the neural network to obtain the convolution calculation result of the current layer of the neural network;

[0073] According to the result storage instruction of the current layer of the neural network and the weight loading instruction of the next layer of the neural network, the convolution calculation result obtained by the current layer of the neural network is stored back to the DDR through parallel loading, and the weight of the next layer of the neural network is loaded into the corresponding SRAM.

[0074] The present invention realizes an instruction compiler of a flexible neural network accelerator by analyzing the structure of a network model. In compiling neural network instructions, the required computing space and computing resources of each layer are efficiently allocated, the high-speed cache space is utilized to the maximum extent, and data loading and convolution calculation are processed in parallel by multiple transmissions, thus avoiding waiting for data resource loading and waste of computing units.

[0075] Based on the above embodiment, after generating the acceleration instruction of the neural network accelerator according to the parallel operation strategy, the method further includes:

[0076] According to the neural network structure information, slicing the neural network is performed;

[0077] Perform ping-pong operations on the sliced ​​neural network.

[0078] In the present invention, the FM and WT of each layer of the neural network are assigned to the preset position of the circular buffer through the above-mentioned neural network structure information, and the neural network is sliced ​​according to the size of the on-chip resources of the neural network accelerator, including placing the feature map data in multiple acceleration cores for calculation. By reasonably slicing the feature map, redundant parameter repeated loading is avoided. Figure 5 This is a schematic diagram of the neural network segmentation method provided by the present invention. The segmentation process of the neural network can refer to Figure 5 shown.

[0079] Based on the above embodiment, after generating the acceleration instruction of the neural network accelerator according to the parallel operation strategy, the method further includes:

[0080] The neural network accelerator is based on a producer-consumer model and operates according to the acceleration instructions.

[0081] In the present invention, the network model structure is analyzed by a neural network compiler, each instruction is added to a natural sequence, and dependent instructions of the other three instructions required by each instruction are obtained according to the network structure.

[0082] In the present invention, when the neural network accelerator is running, it is necessary to realize superscalar according to the instruction dependency relationship. During compilation, each instruction is added to the natural sequence, and the dependent instructions of the other three instructions required by each instruction are obtained according to the neural network structure. The overall logic of the hardware operation of the neural network accelerator of the present invention uses the producer-consumer model. The instruction operation consumes resources, and the instruction is completed to produce resources for other specific instruction controllers. When the current resource emission conditions are met, the instruction is emitted, and the corresponding register resource is reduced by one. After the instruction is completed, the resource is generated, and the corresponding register is increased by one, so that the four instructions can be run in parallel in the neural network accelerator without being affected by the accelerator performance and storage bandwidth. Figure 6 The schematic diagram of the instruction flow of the neural network accelerator provided by the present invention can be referred to Figure 6 As shown, each type of instruction is queued independently, different types of instructions can be run in parallel, and the same type of instructions can be run sequentially. It should be noted that the instruction structure of the neural network accelerator provided by the present invention can be expanded to other types of instructions such as miscellaneous calculations according to needs.

[0083] Figure 7 This is a schematic diagram of the neural network acceleration effect provided by the present invention, which can be referred to Figure 7 As shown, the four neural network compiler instructions can run in parallel on the neural network accelerator, maximizing the use of hardware resources for convolution calculations, avoiding the waiting time for reading and writing input and output data, and being able to run the neural network in a shorter time, realizing real-time deployment of edge AI.

[0084] The neural network accelerator compilation method provided by the present invention has more targeted optimization for the hardware deployment of neural networks, is applicable to various network structures, different layer sizes, and different continuous layer structures, can maximize the use of hardware high-speed buffers, and superscalar can efficiently use all edge hardware resources. Compared with existing quantitative pruning acceleration and traditional compilers, the compiler proposed by the present invention is more in line with the instruction operations in the accelerator hardware, and generates code with considerable performance for dedicated accelerators.

[0085] Figure 8A schematic diagram of the structure of the neural network accelerator compilation device provided by the present invention is shown in FIG. Figure 8 As shown, the present invention provides a neural network accelerator compilation device, including a preset instruction and dependency generation module 801, a parallel strategy generation module 802 and a compilation module 803, wherein the preset instruction and dependency generation module 801 is used to generate dependencies between each preset instruction type and multiple neural network compiler instruction queues based on neural network structure information and preset instruction types, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; the parallel strategy generation module 802 is used to determine the parallel operation strategy between each neural network compiler instruction queue according to the dependency; the compilation module 803 is used to generate acceleration instructions for the neural network accelerator according to the parallel operation strategy.

[0086] The neural network accelerator compilation device provided by the present invention can effectively solve problems such as neural network parameter loading and module utilization by integrating flexible dynamic adjustment technologies such as circular buffers and superscalars into a neural network dedicated accelerator, so that the neural network can be deployed more quickly on the edge.

[0087] On the basis of the above embodiment, the preset instruction and dependency generation module includes an instruction generation unit, a dependency generation unit and an instruction queue generation unit, wherein the instruction generation unit is used to construct corresponding neural network compiler instructions according to the preset instruction type, and the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions and result storage instructions; the dependency generation unit is used to determine whether there is parallel operation between each neural network compiler instruction according to the neural network structure information, and construct the dependency between each preset instruction type according to the parallel operation judgment result, and the neural network structure information at least includes the preceding layer, the succeeding layer, the number of input and output channels, the convolution kernel size, the input and output data width and the input and output data height; the instruction queue generation unit is used to generate a corresponding neural network compiler instruction queue according to the neural network compiler instructions of the same preset instruction type based on the first-in-first-out method and the dependency.

[0088] The device provided by the present invention is used to execute the above-mentioned method embodiments. Please refer to the above-mentioned embodiments for the specific processes and detailed contents, which will not be repeated here.

[0089] Fig. 9 A schematic diagram of the structure of an electronic device provided by the present invention, such as Fig. 9As shown, the electronic device may include: a processor 901, a communications interface 902, a memory 903 and a communications bus 904, wherein the processor 901, the communications interface 902 and the memory 903 communicate with each other through the communications bus 904. The processor 901 may call the logic instructions in the memory 903 to execute the neural network accelerator compilation method, the method comprising: based on the neural network structure information and the preset instruction type, generating the dependency relationship between each preset instruction type and a plurality of neural network compiler instruction queues, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; determining the parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship; generating the acceleration instruction of the neural network accelerator according to the parallel operation strategy.

[0090] In addition, the logic instructions in the above-mentioned memory 903 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk.

[0091] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the neural network accelerator compilation method provided by the above methods, and the method includes: based on neural network structure information and preset instruction types, generating dependencies between each preset instruction type and multiple neural network compiler instruction queues, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; determining a parallel operation strategy between each neural network compiler instruction queue based on the dependency relationship; and generating acceleration instructions for the neural network accelerator based on the parallel operation strategy.

[0092] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the neural network accelerator compilation method provided by the above-mentioned embodiments, the method comprising: based on neural network structure information and preset instruction types, generating dependencies between each preset instruction type and multiple neural network compiler instruction queues, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; determining a parallel operation strategy between each neural network compiler instruction queue based on the dependency relationship; and generating acceleration instructions for the neural network accelerator based on the parallel operation strategy.

[0093] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0094] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0095] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A neural network accelerator compilation method, characterized in that: include: Based on the neural network structure information and the preset instruction type, a dependency relationship between each preset instruction type and a plurality of neural network compiler instruction queues are generated, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; Determine a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship; Generate acceleration instructions for a neural network accelerator according to the parallel operation strategy; Determining the parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship includes: According to the parallel operation judgment result, the neural network compiler instructions that cannot be run in parallel are marked by flag bits to obtain the dependency relationship between preset instruction types; Based on the superscalar technology, generating a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship; The method based on the superscalar technology and according to the dependency relationship, generates a parallel operation strategy between each neural network compiler instruction queue, including: Based on the circular cache method, according to the feature map loading instructions and weight loading instructions of the current layer of the neural network, the feature map and weight are loaded into their corresponding SRAM in parallel; Perform convolution calculation according to the convolution calculation instruction of the current layer of the neural network to obtain the convolution calculation result of the current layer of the neural network; According to the result storage instruction of the current layer of the neural network and the weight loading instruction of the next layer of the neural network, the convolution calculation result obtained by the current layer of the neural network is stored back to the DDR through parallel loading, and the weight of the next layer of the neural network is loaded into the corresponding SRAM.

2. The neural network accelerator compilation method according to claim 1, characterized in that: The method generates dependencies between each preset instruction type and multiple neural network compiler instruction queues based on the neural network structure information and the preset instruction type, including: According to the preset instruction type, construct corresponding neural network compiler instructions, wherein the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions, and result storage instructions; According to the neural network structure information, determine whether there is parallel operation between each neural network compiler instruction, and build a dependency relationship between each preset instruction type according to the parallel operation determination result, wherein the neural network structure information at least includes a preceding layer, a succeeding layer, the number of input and output channels, a convolution kernel size, and an input and output data width and an input and output data height; Based on the first-in-first-out method and the dependency relationship, a corresponding neural network compiler instruction queue is generated according to the neural network compiler instructions of the same preset instruction type.

3. The neural network accelerator compilation method according to claim 1, characterized in that: After generating the acceleration instruction of the neural network accelerator according to the parallel operation strategy, the method further includes: According to the neural network structure information, slicing the neural network is performed; Perform ping-pong operations on the sliced ​​neural network.

4. The neural network accelerator compilation method according to claim 1, characterized in that: After generating an acceleration instruction for the neural network accelerator according to the parallel operation strategy, the method further includes: The neural network accelerator is based on a producer-consumer model and operates according to the acceleration instructions.

5. A neural network accelerator compilation device, characterized in that: include: A preset instruction and dependency generation module, used to generate a dependency relationship between each preset instruction type and a plurality of neural network compiler instruction queues based on the neural network structure information and the preset instruction type, wherein the neural network compiler instruction queue is a queue composed of neural network compiler instructions of the same preset instruction type; A parallel strategy generation module, used to determine the parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship; A compiling module, used to generate acceleration instructions for a neural network accelerator according to the parallel operation strategy; The parallel strategy generation module is specifically used for: According to the parallel operation judgment result, the neural network compiler instructions that cannot be run in parallel are marked by flag bits to obtain the dependency relationship between preset instruction types; Based on the superscalar technology, generating a parallel operation strategy between each neural network compiler instruction queue according to the dependency relationship; The method based on the superscalar technology and according to the dependency relationship, generates a parallel operation strategy between each neural network compiler instruction queue, including: Based on the circular cache method, according to the feature map loading instructions and weight loading instructions of the current layer of the neural network, the feature map and weight are loaded into their corresponding SRAM in parallel; Perform convolution calculation according to the convolution calculation instruction of the current layer of the neural network to obtain the convolution calculation result of the current layer of the neural network; According to the result storage instruction of the current layer of the neural network and the weight loading instruction of the next layer of the neural network, the convolution calculation result obtained by the current layer of the neural network is stored back to the DDR through parallel loading, and the weight of the next layer of the neural network is loaded into the corresponding SRAM.

6. The neural network accelerator compiling device according to claim 5, characterized in that: The preset instruction and dependency relationship generation module includes: An instruction generation unit, used to construct corresponding neural network compiler instructions according to a preset instruction type, wherein the neural network compiler instructions include feature map loading instructions, weight loading instructions, convolution calculation instructions, and result storage instructions; A dependency generation unit is used to determine whether there is parallel operation between each neural network compiler instruction according to the neural network structure information, and to construct a dependency relationship between each preset instruction type according to the parallel operation determination result, wherein the neural network structure information at least includes a preceding layer, a succeeding layer, the number of input and output channels, a convolution kernel size, and an input and output data width and an input and output data height; An instruction queue generation unit is used to generate a corresponding neural network compiler instruction queue based on a first-in-first-out method and the dependency relationship according to neural network compiler instructions of the same preset instruction type.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the neural network accelerator compilation method as described in any one of claims 1 to 4 are implemented.

8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the neural network accelerator compilation method as described in any one of claims 1 to 4 are implemented.