Simulation verification method and device for NPU instruction, electronic equipment and storage medium

Verifying NPU instructions through pure software simulation method solves the problems of low simulation efficiency and high cost in the existing technology, realizes efficient simulation verification in the early stage of chip design, reduces the dependence on professional hardware and circuit simulation software, and is forward-looking and low-cost features.

CN118627436APending Publication Date: 2024-09-10YAOYAO
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410523309.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-28
Publication Date
2024-09-10

Smart Images

  • Figure CN118627436A
    Figure CN118627436A
Patent Text Reader

Abstract

The invention discloses a simulation verification method and device for an NPU instruction, electronic equipment and a storage medium. Sequentially taking out each instruction from the to-be-executed instruction sequence, and delivering each instruction to an instruction queue of a corresponding execution unit; selecting one current to-be-executed instruction in the instruction queue corresponding to each execution unit; analyzing to obtain instruction parameters; judging whether the current to-be-executed instruction has a dependency condition or not according to the instruction parameter; if the dependency condition does not exist or the dependency condition is met, obtaining the input data from the simulation module, and performing format conversion on the input data to obtain the input data in a first preset format; calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into a simulation module according to a second preset format; and judging whether the instruction queues corresponding to the execution units are empty or not, and repeating the simulation verification step until the instructions in the instruction queues of the execution units are simulated. And efficient simulation verification is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of simulation technology, and in particular to a simulation verification method, device, electronic device and storage medium for NPU instructions. Background Art

[0002] When simulating and verifying NPU instructions in the chip, the execution results of NPU instructions and instruction sequences are generated by simulation and then verified for correctness. This can help chip designers quickly determine the rationality of instruction set design and the feasibility of implementing some functions during the design phase, and can quickly determine the correctness of instructions or instruction sequences generated by the NPU compiler, as well as quickly locate erroneous instructions or instruction sequences.

[0003] Currently, there are two main ways to simulate the running process of NPU instructions or instruction sequences: one is to build the NPU circuit on the circuit hardware simulator according to the finalized circuit design, actually execute the instructions or instruction sequences, and then verify the correctness of the results; the other is to use professional circuit simulation software to perform RTL simulation, simulate the running status of each clock cycle of the hardware through software, and then verify the correctness of the results.

[0004] Based on the above, the existing simulation verification methods all have disadvantages. For example, they require the support of professional hardware and circuit simulation software, the simulation process takes a long time to imitate the behavior of each clock cycle of the hardware, and the design completion of the entire NPU or part of the instructions must reach a fully operational state before simulation can be performed. Verification cannot be performed at an earlier framework design stage.

[0005] Therefore, there is an urgent need for a fast, efficient, low-cost and forward-looking instruction simulation verification method. Summary of the invention

[0006] In order to solve the technical problems of low efficiency, high cost and lack of foresight in instruction simulation verification, the purpose of the present disclosure is to provide a simulation verification method, device, electronic device and storage medium for NPU instructions.

[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.

[0008] According to one aspect of the present disclosure, a simulation verification method for an NPU instruction is provided, comprising:

[0009] Taking out each instruction from the sequence of instructions to be executed in sequence, determining the hardware execution unit to which each instruction belongs, and delivering each instruction to the instruction queue of the corresponding execution unit in sequence;

[0010] Selecting a currently executed instruction in the instruction queue corresponding to each execution unit;

[0011] Parsing the current instruction to be executed to obtain instruction parameters;

[0012] According to the instruction parameters, determining whether the current instruction to be executed has a dependency condition, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution results of other execution units;

[0013] If the dependency condition does not exist or the dependency condition has been satisfied, input data is obtained from the simulation module, and the input data is formatted to obtain input data in a first preset format, wherein the dependency condition has been satisfied means that the execution results of all the other execution units that the currently executed instruction depends on have been completed;

[0014] If the dependency condition is not satisfied, the current execution unit enters a waiting state until the dependency condition is satisfied, and obtains input data in the first preset format;

[0015] Calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit;

[0016] Determine whether the instruction queue corresponding to each execution unit is empty;

[0017] If the instruction queues corresponding to the execution units are not empty, the above simulation verification steps are repeated until the instructions in the instruction queues corresponding to the execution units obtain corresponding simulation execution results.

[0018] In one embodiment of the present disclosure, after calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into the simulation module according to a second preset format, the method includes:

[0019] Determining whether the current simulation execution result is a dependency condition of the other execution units;

[0020] If it is a dependency condition of the other execution units, sending a signal to the corresponding target execution unit;

[0021] Determining whether the target execution unit is in a waiting state;

[0022] If the target execution unit is not in a waiting state, marking that the dependency condition of the target instruction of the target execution unit on the current instruction to be executed has been satisfied;

[0023] If the target execution unit is in a waiting state and the dependency condition of the target instruction is satisfied, simulation verification of the target instruction is performed.

[0024] In one embodiment of the present disclosure, the first preset format is an input format required for calculating the preset formula in the software;

[0025] If the dependent condition does not exist or the dependent condition is satisfied, the input data is obtained from the simulation module, and the format of the input data is converted to obtain the input data in a first preset format, including:

[0026] Collecting input data from a main memory simulation module, an internal memory simulation module or an internal register simulation module according to the current instruction to be executed;

[0027] The input data is converted into the first preset format.

[0028] In one embodiment of the present disclosure, the acquisition of the preset formula includes:

[0029] According to the calculation functions to be implemented by the instructions and the characteristics of the hardware calculation unit, a preset formula is obtained so that the calculation result of the preset formula of the software is consistent with the expected calculation result of the hardware instruction.

[0030] In one embodiment of the present disclosure, the second preset format is an output data format corresponding to the current instruction to be executed.

[0031] In one embodiment of the present disclosure, the determining whether the instruction queue corresponding to each execution unit is empty includes:

[0032] Determining whether a current instruction queue in the current execution unit is empty;

[0033] If the current instruction queue of the current execution unit is not empty, a new current instruction to be executed in the current instruction queue is selected for simulation verification;

[0034] If the current instruction queue of the current execution unit is empty, the simulation verification of the current execution unit ends;

[0035] Determine whether the instruction queues corresponding to all execution units are empty;

[0036] If the instruction queues corresponding to all the execution units are empty, the simulation verification of all the execution units is completed;

[0037] If the instruction queues corresponding to all the execution units are not empty, the corresponding simulation verification continues to be performed.

[0038] In one embodiment of the present disclosure, it also includes:

[0039] According to the simulation execution result, check whether the data in the main memory simulation module, the internal memory simulation module and the internal register simulation module are consistent with expectations.

[0040] According to another aspect of the present disclosure, a simulation verification device for NPU instructions is provided, comprising:

[0041] An instruction acquisition module is used to sequentially take out each instruction from the sequence of instructions to be executed, determine the hardware execution unit to which each instruction belongs, and sequentially deliver each instruction to the instruction queue of the corresponding execution unit;

[0042] An instruction selection module is used to select a current instruction to be executed in the instruction queue corresponding to each execution unit;

[0043] A parsing module, used for parsing the current instruction to be executed and obtaining instruction parameters;

[0044] A first judgment module is used to judge whether the current instruction to be executed has a dependency condition according to the instruction parameter, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution result of other execution units;

[0045] A first data acquisition module is used to acquire input data from a simulation module and perform format conversion on the input data to obtain input data in a first preset format if the dependency condition does not exist or the dependency condition has been satisfied, wherein the dependency condition has been satisfied means that the execution results of all the other execution units that the currently executed instruction depends on have been completed;

[0046] A second data acquisition module, configured to, if the dependency condition is not satisfied, cause the current execution unit to enter a waiting state until the dependency condition is satisfied, thereby obtaining input data in the first preset format;

[0047] A calculation module, used to calculate the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and write the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit;

[0048] A second judgment module is used to judge whether the instruction queue corresponding to each execution unit is empty;

[0049] The result acquisition module is used to repeat the above simulation verification steps if the instruction queue corresponding to each execution unit is not empty until the instructions in the instruction queue corresponding to each execution unit obtain the corresponding simulation execution results.

[0050] According to another aspect of the present disclosure, an electronic device is provided, including a processor; and

[0051] A memory, configured to store executable instructions of the processor;

[0052] The processor is configured to execute any one of the above-mentioned simulation verification methods for NPU instructions by executing the executable instructions.

[0053] According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the simulation verification method for NPU instructions described in any one of the above is implemented.

[0054] The embodiment of the present disclosure provides a simulation verification method for NPU instructions, including: taking out each instruction from a sequence of instructions to be executed in turn, determining the hardware execution unit to which each instruction belongs, and delivering each instruction to the instruction queue of the corresponding execution unit in turn; selecting a current instruction to be executed in the instruction queue corresponding to each execution unit; parsing the current instruction to be executed to obtain instruction parameters; judging whether the current instruction to be executed has a dependency condition based on the instruction parameters, wherein the dependency condition refers to the execution result of the current instruction to be executed depending on other execution units; if the dependency condition does not exist or the dependency condition has been met, obtaining input data from the simulation module, and performing a simulation on the input data. According to the format conversion, the input data of the first preset format is obtained; if the dependency condition is not satisfied, the current execution unit enters a waiting state until the dependency condition is satisfied, and the input data of the first preset format is obtained; the input data of the first preset format is calculated according to the preset formula to obtain the current simulation execution result, and the current simulation execution result is written into the simulation module according to the second preset format, wherein the preset formula is set corresponding to the hardware calculation unit; it is determined whether the instruction queue corresponding to each execution unit is empty, and if the instruction queue corresponding to each execution unit is not empty, the above simulation verification steps are repeated until the instructions in the instruction queue corresponding to each execution unit obtain the corresponding simulation execution result. The correctness of the NPU instruction execution result is analyzed by a pure software simulation verification method, which does not require the support of professional hardware and circuit simulation software, and reduces costs. In the simulation of the instruction, the process of imitating the behavior of each clock cycle of the hardware in the existing simulation method is avoided, and the problem of long time in the existing simulation process is solved. At the same time, simulation can be performed before the chip circuit design is completed, which has strong foresight, and can also be easily integrated into the NPU compiler to automatically check the instruction sequence generated by the compiler, and can also be integrated into the neural network reasoning framework to participate in the full-chain simulation related to the business. Achieve efficient, low-cost and forward-looking instruction simulation verification. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0056] Figure 1 It is a flowchart of a simulation verification method for NPU instructions according to an embodiment of the present disclosure;

[0057] Figure 2 It is a specific example flow chart of a simulation verification method for NPU instructions according to an embodiment of the present disclosure;

[0058] Figure 3 A flowchart of another simulation verification method for NPU instructions according to an embodiment of the present disclosure;

[0059] Figure 4 A flowchart of a simulation verification method for NPU instructions according to an embodiment of the present disclosure is provided;

[0060] Figure 5 A flowchart of a simulation verification method for NPU instructions according to an embodiment of the present disclosure is provided;

[0061] Figure 6 The present invention is a schematic diagram of a simulation verification device for NPU instructions according to an embodiment of the present invention. DETAILED DESCRIPTION

[0062] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0063] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0064] Hereinafter, the terms "including", "having" and their cognates, which may be used in various embodiments of the present application, are intended only to indicate specific features, numbers, steps, operations, elements, components, or combinations of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing items or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations of the foregoing items.

[0065] Furthermore, the terms “first”, “second”, “third”, etc. are merely used for distinguishing descriptions and are not to be understood as indicating or implying relative importance.

[0066] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.

[0067] To facilitate understanding, the terms involved in this application are first explained below.

[0068] NPU (Neural Processing Unit) is a processor specifically used for neural network calculations. It is a special computing device. Each NPU instruction in the chip can be abstracted into a mathematical formula, and then abstracted into a function or module in a computer program. After given input data, the calculation process and results of NPU are predictable.

[0069] Regarding the first NPU instruction simulation operation method mentioned above: build an NPU circuit on a circuit hardware simulator (such as FPGA) to actually execute instructions or instruction sequences. This method can obtain the actual execution results of instructions or instruction sequences very accurately and quickly, but this method requires expensive circuit hardware simulation equipment and professional chip design tools. In addition to building the NPU hardware itself, other supporting software and hardware ecosystems are also required, such as CPU, bus, operating system, hardware driver, etc. The simulation environment construction process is complex and difficult; the simulation verification stage also requires personnel with relevant professional and knowledge backgrounds to carry out. The labor cost and time cost to complete a simulation process are high, and the simulation process and simulation cycle are long.

[0070] Regarding the aforementioned second NPU instruction simulation operation mode: use professional circuit simulation software to perform RTL simulation, and simulate the operation status of each clock cycle of the hardware through software simulation for simulation execution. This method does not require the actual construction of the hardware circuit, and can perform software simulation execution on a general PC platform, which well solves the problems caused by the hardware environment in the first method. However, this method also requires the support of professional circuit simulation software. Such professional software is also difficult to connect to the real test environment. For example, it is very cumbersome to provide input data for the NPU simulator and obtain the output of the NPU simulator. In addition, this type of software will imitate the behavior of each clock cycle of the hardware. When the chip circuit is large or the instruction sequence is long, there is a problem of too long simulation time.

[0071] In view of the shortcomings of instruction simulation verification in the above chips, the present invention adopts a pure software simulation method to verify the correctness of the NPU instruction running results, does not require the support of professional hardware and circuit simulation software, and avoids the process of imitating the behavior of each clock cycle of the hardware in the existing simulation method in the instruction simulation, thereby solving the problems of long time and low efficiency of the existing simulation process.

[0072] Reference Figure 1 As shown, in one embodiment, a simulation verification method for NPU instructions is provided, including:

[0073] S101, taking out each instruction from a sequence of instructions to be executed in sequence, determining the hardware execution unit to which each instruction belongs, and delivering each instruction to the instruction queue of the corresponding execution unit in sequence;

[0074] Figure 2 The figure shows a flow chart of the simulation verification method of the NPU instruction in a specific example. Figure 2 Provide explanation.

[0075] Specifically, the NPU has multiple execution units for executing instructions, and each execution unit can execute several categories of instructions. Instructions in the same execution unit can only be executed sequentially. Instructions in different execution units can be executed in parallel at the same time. After the simulation is started, instructions are taken out from the sequence of instructions to be executed in sequence, and the instructions are delivered to the instruction queue of the corresponding execution unit in sequence according to the hardware execution unit to which each instruction belongs.

[0076] S102, selecting a current to-be-executed instruction in the instruction queue corresponding to each execution unit;

[0077] Specifically, after executing step S101, jump to step S102, and in each execution unit, select an instruction from the respective instruction queue as the current instruction to be executed. The number of execution units may be one or more. When the NPU does not support parallel execution of instructions, it can be equivalent to consider that the NPU has only one hardware execution unit. The NPU without parallel execution capability can be equivalently regarded as the case of only one execution unit in the above assumption.

[0078] S103, parsing the current instruction to be executed to obtain instruction parameters;

[0079] After step S102, the current instruction to be executed is parsed, wherein the instruction parameters may include information such as instruction dependency, input and output configuration parameters, etc.

[0080] S104, judging whether the current instruction to be executed has a dependency condition according to the instruction parameter, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution result of other execution units;

[0081] Specifically, instructions located in different execution units may also have dependencies, that is, one of the instructions needs to wait for another or several instructions to be executed, that is, an instruction in one execution unit may need to wait for the execution result of an instruction located in other execution units. Therefore, it is necessary to execute step S104 to determine whether the current instruction to be executed has a dependency condition. If there is a dependency condition, it will affect the continuation of the simulation verification and further judgment is required. If there is no dependency condition, step S105 can be directly executed to continue the simulation verification. The current instruction to be executed may not depend on instructions in other execution units, or may depend on multiple instructions in other multiple execution units, or may depend on one or more instructions in a certain execution unit. In an example, situation 1: instruction A may depend on instructions B and C located in two other execution units. Situation 2: instruction D depends on instructions E, F and G located in other execution units at the same time.

[0082] S105, if the dependency condition does not exist or the dependency condition has been satisfied, obtaining input data from the simulation module, and performing format conversion on the input data to obtain input data in a first preset format, wherein the dependency condition has been satisfied means that the execution results of all other execution units that the currently executed instruction depends on have been completed;

[0083] In a specific embodiment, after the dependency condition is determined in step S104, step S105 includes two judgment situations. If it is determined that the dependency condition does not exist, step S201 is directly executed to obtain input data from the simulation module, and the input data is formatted to obtain input data in a first preset format. If it is determined that the dependency condition exists, step S202 needs to be executed to determine whether the dependency conditions of the current instruction to be executed in other execution units are met, that is, whether all instructions on which the current instruction to be executed depends have been executed, and whether the execution results on which the current instruction to be executed depends have been obtained to ensure the normal execution of the current instruction to be executed. After the judgment in step S202, if the dependency condition is met, it also jumps to step S201 to perform operations such as input data acquisition.

[0084] For case 1 in the above example, if instruction B has been executed and completed before instruction A starts to execute, and instruction C has also been executed and completed, when instruction B ends, the dependency condition of instruction A on instruction B will be marked as satisfied, and when instruction C ends, the dependency condition of instruction A on instruction C will be marked as satisfied, then the dependency condition of instruction A has been satisfied. In case 2, it is also required that instructions E, F, and G have all been executed and completed before instruction D starts to execute, and the dependency conditions of instruction D on instructions E, F, and G are marked as satisfied, and the status of instruction D changes to the dependency condition being satisfied.

[0085] The first preset format is the input format required for the preset formula calculation in the software, that is, the data format required by the calculation function of the preset formula in the software.

[0086] Reference Figure 3 As shown, step S105 includes:

[0087] S301, collecting input data from a main memory simulation module, an internal memory simulation module or an internal register simulation module according to the current instruction to be executed;

[0088] The simulation module in the above step S105 specifically includes a main memory simulation module, an internal memory simulation module or an internal register simulation module. Based on the chip designer's design details of instruction access input and output data and the data arrangement details in the main memory, chip internal memory or register, the input data is collected from the main memory simulation module, the internal memory simulation module or the internal register simulation module according to the input data format of the hardware instruction.

[0089] S302: Convert the input data into the first preset format.

[0090] Then convert it into the input format required by the software calculation function. Convert the input and output data storage format unique to the hardware instruction and the input and output data format of the software function.

[0091] S106, if the dependency condition is not satisfied, the current execution unit enters a waiting state until the dependency condition is satisfied, and obtains input data in the first preset format;

[0092] If the dependency condition is not satisfied after step S202, step S203 is executed to suspend the execution of the current instruction to be executed, and the current execution unit enters a waiting state. Subsequently, until the dependency condition of the current instruction to be executed is satisfied, the current instruction to be executed can proceed to step S201 to obtain input data in the first preset format.

[0093] For case 1 in the above example: If B has been executed before instruction A starts to execute, when B finishes, the dependency condition of A on B will be marked as satisfied. If C has not been executed before instruction A starts to execute, the dependency condition of instruction A is not satisfied, and the execution unit corresponding to A enters the waiting state. At this time, instruction A needs to wait for instruction C to finish executing. After instruction C finishes executing, all dependency conditions of instruction A are satisfied and execution can begin. Case 2: Before instruction D is executed, E, F and G must have been executed. If one of them has not been executed, the dependency condition of instruction D is not satisfied, and it will enter the waiting state, waiting for all to finish executing, and the dependency condition of instruction D is satisfied.

[0094] S107, calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit;

[0095] Specifically, after step S201, step S204 is executed to calculate the input data of the first preset format according to the preset formula to obtain the current simulation execution result. Then step S205 is executed to write the current simulation execution result into the simulation module according to the second preset format. Thus, after the simulation verification of the current instruction to be executed in the above steps S101 to S107, the process jumps to step S206 to complete the simulation verification of a single instruction. Among them, the preset formula is the calculation formula and function corresponding to the current instruction to be executed in the hardware. The calculation result consistent with the hardware calculation is obtained to improve the accuracy of the verification.

[0096] Among them, the second preset format is the output data format corresponding to the current instruction to be executed. Specifically, for the output data, the result calculated by the software function is placed in the corresponding main memory simulation module, internal memory simulation module or internal register simulation module. In a specific example, in the hardware unit of the MAC instruction, in order to realize parallel computing, the input data {A} and {B} may be scattered in different hardware memories inside the chip, and the array length, whether the integer has a sign bit, the integer bit width and other information may be directly extracted from the instruction itself. The calculation result may be stored in a register or a third internal hardware memory, and the input and output of the software function can be simply stored with ordinary arrays and variables. Signed and unsigned integer vectors with different bit widths may require different software functions to calculate. The input and output data storage format unique to the hardware instruction and the input and output data format of the software function are converted to improve efficiency.

[0097] S108, determining whether the instruction queue corresponding to each execution unit is empty;

[0098] The simulation execution status of each execution unit is further judged to ensure that the simulation verification of the instruction sequence is completed.

[0099] S109, if the instruction queues corresponding to the execution units are not empty, repeat the above simulation verification steps until the instructions in the instruction queues corresponding to the execution units obtain corresponding simulation execution results.

[0100] Specifically, when it is ensured that the instruction queues of all execution units are empty, the simulation verification of the instruction sequence is completed.

[0101] In this embodiment, a preset formula corresponding to the hardware instruction is designed to obtain a calculation result consistent with the hardware calculation, thereby improving the accuracy of the simulation verification. The input and output data storage format unique to the hardware instruction and the input and output data storage format of the software function are converted. When analyzing the correctness of the instruction, the operation to be performed by the specific instruction is completed through the software function to obtain the result of a single instruction. In this process, the simulation program does not need to imitate the behavior of each clock cycle of the hardware, and the software simulation does not even need to know the specific details of the hardware instruction implementation. It only needs to know where the hardware instruction takes the input data, where the operation result is stored, and the data format is kept consistent with the hardware instruction. The correctness of the NPU instruction execution result is analyzed by a pure software simulation verification method, which does not require the support of professional hardware and circuit simulation software, thereby reducing costs. In addition, in the simulation of the instruction, the process of imitating the behavior of each clock cycle of the hardware in the existing simulation method is avoided, solving the problem of the long time of the existing simulation process. At the same time, simulation can be performed before the chip circuit design is completed, which has a strong forward-looking nature, and can also be easily integrated into the NPU compiler to automatically check the instruction sequence generated by the compiler, and can also be integrated into the neural network reasoning framework to participate in the full-chain simulation related to the business. Achieve efficient, low-cost and forward-looking simulation verification of NPU instructions.

[0102] Reference Figure 4 As shown, in a specific example, step S108 includes:

[0103] S401, determining whether the instruction queue in the current execution unit is empty;

[0104] S402, if the current instruction queue of the current execution unit is not empty, selecting a new current instruction to be executed in the current instruction queue for simulation verification;

[0105] Specifically, combined Figure 2 As shown, the process returns to step S102, reselects a new current instruction to be executed, and then repeats steps S102 to S107 to perform simulation verification.

[0106] S403, if the current instruction queue of the current execution unit is empty, the simulation verification of the current execution unit ends;

[0107] When the execution unit completes the execution of the last instruction, the simulation task of the current execution unit ends and jumps to step S207, and the simulation verification of the current execution unit ends. The simulation program does not need to imitate the behavior of each clock cycle of the hardware, and can obtain the simulation task of a single execution unit. It can be simulated before the chip circuit design is completed, which is very forward-looking and can better assist developers.

[0108] S404, determining whether the instruction queues corresponding to all execution units are empty;

[0109] When the simulation task of the current execution unit is completed, S208 is executed to determine whether the simulation verification of all execution units has been completed.

[0110] S405, if the instruction queues corresponding to all the execution units are empty, the simulation verification of all the execution units is completed;

[0111] If the simulation tasks of all execution units have been completed, the simulation of the instruction sequence is completed.

[0112] S406: If the instruction queues corresponding to all the execution units are not empty, continue to perform the corresponding simulation verification.

[0113] If there are still execution units that have not completed the simulation task, that is, among all the execution units, there are still instructions in the instruction queue of a certain execution unit that have not been simulated and verified, then continue to simulate and verify the instructions that have not completed the simulation task, and perform simulation for the instructions that have not completed the simulation task through the method in the above embodiment.

[0114] In a specific example, it also includes:

[0115] S209, checking whether the data in the main memory simulation module, the internal storage simulation module and the internal register simulation module are as expected according to the simulation execution result.

[0116] After step S208, step S209 is executed, and then the instruction sequence simulation verification is finally jumped to S210. If the simulation result is the same as the expected operation result of the hardware instruction, it meets the above expectation. If the simulation result is different from the expected operation result of the hardware instruction, it does not meet the expectation.

[0117] Reference Figure 5 As shown, in a specific embodiment, after step S107, the following steps are included:

[0118] S501, determining whether the current simulation execution result is a dependency condition of the other execution units;

[0119] S502, if it is a dependency condition of the other execution units, sending a signal to the corresponding target execution unit;

[0120] Combination Figure 2 As shown, when the single instruction simulation ends, it is determined whether the execution result of the instruction is relied upon by other instructions. If the execution result of the current instruction is relied upon by instructions in other execution units, step S211 is executed to send a signal to the corresponding target execution unit, that is, the execution unit corresponding to other instructions that rely on the current simulation execution result.

[0121] S503, determining whether the target execution unit is in a waiting state;

[0122] The target instruction in the target execution unit may depend on one or more execution instructions in one or more other execution units.

[0123] S504, if the target execution unit is not in a waiting state, marking that the dependency condition of the target instruction in the target execution unit on the current instruction to be executed has been satisfied;

[0124] Specifically, the target execution unit has not yet executed the target instruction that depends on the current simulation execution result. If the execution unit that receives the signal has not yet executed the instruction that depends on this condition, then step S212 is executed to mark that the dependency condition of the target instruction on the current instruction to be executed has been satisfied. There may be multiple dependency conditions corresponding to the target instruction. For example, if the current instruction to be executed is instruction H, the target instruction I depends on instruction H and instruction J in another execution unit, and instruction H is a dependency condition of the target instruction I in the target execution unit. When instruction H is executed, it is marked that the dependency condition of the target instruction I on instruction H has been satisfied. The dependency condition has been satisfied means that the dependency conditions corresponding to the target instruction have been satisfied, and the simulation verification can be performed. However, if the dependency condition of instruction I on instruction H has been satisfied, but the dependency condition of instruction I on instruction J has not been satisfied, then the dependency condition of the target instruction I is not satisfied. When instruction J is also executed, the dependency condition of the target instruction I is satisfied. Only when the dependency conditions corresponding to the target instruction I are satisfied, will it be in the state of satisfied dependency conditions. After marking, when the target execution unit executes the target instruction H, the dependency condition has been satisfied and the simulation verification can be performed directly.

[0125] S505: If the target execution unit is in a waiting state and the dependency condition of the target instruction is satisfied, then perform simulation verification of the target instruction.

[0126] If the target execution unit is in a waiting state, the target instruction can be regarded as the current instruction to be executed, and jump to step S202 to determine whether the dependency conditions of the target instruction are met. If the execution results of other execution units in the dependency conditions of the target instruction have been executed and the dependency conditions of the target instruction are met, subsequent simulation verification can be performed on the target instruction.

[0127] In addition, this embodiment adopts a method of simulating the actual hardware execution unit with a parallel execution unit and synchronizing between modules by sending signals. In fact, in a simulation tool that simulates the ability to execute multiple instructions in parallel, other methods can also be used to handle the waiting dependency of such instructions, such as letting the module simulating the hardware execution unit idle and wait for a common status mark or constructing the dependency between instructions and using a directed acyclic graph, etc. to handle the waiting dependency. The above disclosure discloses some examples for handling instruction dependencies, but the simulation tool in this disclosure does not limit the way in which the dependency between instructions is handled.

[0128] In a specific embodiment, the acquisition of the preset formula includes:

[0129] The preset formula is obtained according to the calculation function to be implemented by each instruction and the characteristics of the hardware calculation unit, so that the calculation result of the preset formula of the software is consistent with the expected calculation result of the hardware instruction.

[0130] Specifically, the chip designers design the instructions based on the calculation formulas corresponding to the instructions in the hardware and the calculation functions to be completed by the instructions. For example, suppose the calculation function of a certain instruction in the hardware is to realize the multiplication and accumulation of two vectors, that is, to multiply the numbers in the corresponding positions of two sets of integers {M} and {N} with the same number, and then add all the products together, which is mathematically equivalent to the formula Then the software implementation can be written as a code example similar to the following:

[0131]

[0132]

[0133] When necessary, the final result or intermediate result of the calculation can be processed with overflow, carry or tail, etc., in combination with the characteristics of the hardware. In combination with the characteristics of the hardware calculation unit, the calculation result of the calculation formula implemented by the software can be completely consistent with the actual hardware calculation result, ensuring the accuracy of the simulation verification results.

[0134] Reference Figure 6 As shown, in another embodiment, a simulation verification device 600 for NPU instructions is provided, comprising:

[0135] The instruction acquisition module 601 is used to sequentially take out each instruction from the sequence of instructions to be executed, determine the hardware execution unit to which each instruction belongs, and sequentially deliver each instruction to the instruction queue of the corresponding execution unit;

[0136] The instruction selection module 602 is used to select a current instruction to be executed in the instruction queue corresponding to each execution unit;

[0137] The parsing module 603 is used to parse the current instruction to be executed and obtain instruction parameters;

[0138] A first judgment module 604 is used to judge whether the current instruction to be executed has a dependency condition according to the instruction parameter, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution result of other execution units;

[0139] A first data acquisition module 605 is used to acquire input data from a simulation module and perform format conversion on the input data to obtain input data in a first preset format if the dependency condition does not exist or the dependency condition has been satisfied, wherein the dependency condition has been satisfied means that the execution results of all other execution units that the currently executed instruction depends on have been completed;

[0140] A second data acquisition module 606, configured to, if the dependency condition is not satisfied, cause the current execution unit to enter a waiting state until the dependency condition is satisfied, and obtain input data in the first preset format;

[0141] A calculation module 607, configured to calculate the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and write the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit;

[0142] A second judgment module 608 is used to judge whether the instruction queue corresponding to each execution unit is empty;

[0143] The result acquisition module 609 repeats the above simulation verification steps if the instruction queue corresponding to each execution unit is not empty until the instructions in the instruction queue corresponding to each execution unit obtain the corresponding simulation execution results.

[0144] The present embodiment provides a simulation verification device 600 for NPU instructions, including an instruction acquisition module 601, an instruction selection module 602, a parsing module 603, a first judgment module 604, a first data acquisition module 605, a second data acquisition module 606, a calculation module 607, a second judgment module 608 and a result acquisition module 609. The simulation verification for NPU instructions is realized efficiently, at low cost and with foresight.

[0145] The functions of the simulation verification device for NPU instructions in this embodiment have been described in detail in the corresponding method embodiments, and will not be repeated in this disclosure.

[0146] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0147] In yet another embodiment of the present disclosure, an electronic device is provided, including a processor; and

[0148] A memory, configured to store executable instructions of the processor;

[0149] The processor is configured to execute any one of the above-mentioned simulation verification methods for NPU instructions by executing the executable instructions.

[0150] In yet another embodiment of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the simulation verification method for NPU instructions described in any one of the above is implemented.

[0151] This embodiment also provides an electronic device with a computer-readable storage medium capable of implementing the above-mentioned simulation verification method for NPU instructions, which is described in detail in the corresponding method embodiment and will not be described in detail in this disclosure.

[0152] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.

[0153] A computer-readable storage medium is provided in an exemplary embodiment of the present disclosure, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary implementations of the present invention described in the above "Exemplary Method" section of the present specification.

[0154] A program product for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0155] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0156] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0157] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0158] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0159] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0160] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0161] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.

[0162] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the appended claims.

Claims

1. A simulation verification method for NPU instructions, characterized in that: include: Taking out each instruction from the sequence of instructions to be executed in sequence, determining the hardware execution unit to which each instruction belongs, and delivering each instruction to the instruction queue of the corresponding execution unit in sequence; Selecting a currently executed instruction in the instruction queue corresponding to each execution unit; Parsing the current instruction to be executed to obtain instruction parameters; According to the instruction parameters, determining whether the current instruction to be executed has a dependency condition, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution results of other execution units; If the dependency condition does not exist or the dependency condition has been satisfied, input data is obtained from the simulation module, and the input data is formatted to obtain input data in a first preset format, wherein the dependency condition has been satisfied means that the execution results of all the other execution units that the currently executed instruction depends on have been completed; If the dependency condition is not satisfied, the current execution unit enters a waiting state until the dependency condition is satisfied, and obtains input data in the first preset format; Calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit; Determine whether the instruction queue corresponding to each execution unit is empty; If the instruction queues corresponding to the execution units are not empty, the above simulation verification steps are repeated until the instructions in the instruction queues corresponding to the execution units obtain corresponding simulation execution results.

2. The simulation verification method for NPU instructions according to claim 1, characterized in that: After calculating the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and writing the current simulation execution result into the simulation module according to a second preset format, the method includes: Determining whether the current simulation execution result is a dependency condition of the other execution units; If it is a dependency condition of the other execution units, sending a signal to the corresponding target execution unit; Determining whether the target execution unit is in a waiting state; If the target execution unit is not in a waiting state, marking that the dependency condition of the target instruction of the target execution unit on the current instruction to be executed has been satisfied; If the target execution unit is in a waiting state and the dependency condition of the target instruction is satisfied, simulation verification of the target instruction is performed.

3. The simulation verification method for NPU instructions according to claim 1, characterized in that: The first preset format is the input format required for calculating the preset formula in the software; If the dependent condition does not exist or the dependent condition is satisfied, the input data is obtained from the simulation module, and the format of the input data is converted to obtain the input data in a first preset format, including: Collecting input data from a main memory simulation module, an internal memory simulation module or an internal register simulation module according to the current instruction to be executed; The input data is converted into the first preset format.

4. The simulation verification method for NPU instructions according to claim 1, characterized in that: The acquisition of the preset formula includes: The preset formula is obtained according to the calculation function to be implemented by each instruction and the characteristics of the hardware calculation unit, so that the calculation result of the preset formula of the software is consistent with the expected calculation result of the hardware instruction.

5. The simulation verification method for NPU instructions according to claim 1, characterized in that: The second preset format is the output data format corresponding to the current instruction to be executed.

6. The simulation verification method for NPU instructions according to claim 1, characterized in that: The determining whether the instruction queue corresponding to each execution unit is empty includes: Determining whether a current instruction queue in the current execution unit is empty; If the current instruction queue of the current execution unit is not empty, a new current instruction to be executed in the current instruction queue is selected for simulation verification; If the current instruction queue of the current execution unit is empty, the simulation verification of the current execution unit ends; Determine whether the instruction queues corresponding to all execution units are empty; If the instruction queues corresponding to all the execution units are empty, the simulation verification of all the execution units is completed; If the instruction queues corresponding to all the execution units are not empty, the corresponding simulation verification continues to be performed.

7. The simulation verification method for NPU instructions according to claim 1, characterized in that: Also includes: According to the simulation execution result, check whether the data in the main memory simulation module, the internal memory simulation module and the internal register simulation module are consistent with expectations.

8. A simulation verification device for NPU instructions, characterized in that: include: An instruction acquisition module is used to sequentially take out each instruction from the sequence of instructions to be executed, determine the hardware execution unit to which each instruction belongs, and sequentially deliver each instruction to the instruction queue of the corresponding execution unit; An instruction selection module is used to select a current instruction to be executed in the instruction queue corresponding to each execution unit; A parsing module, used for parsing the current instruction to be executed and obtaining instruction parameters; A first judgment module is used to judge whether the current instruction to be executed has a dependency condition according to the instruction parameter, wherein the dependency condition refers to whether the current instruction to be executed depends on the execution result of other execution units; A first data acquisition module is used to acquire input data from a simulation module and perform format conversion on the input data to obtain input data in a first preset format if the dependency condition does not exist or the dependency condition has been satisfied, wherein the dependency condition has been satisfied means that the execution results of all the other execution units that the currently executed instruction depends on have been completed; A second data acquisition module, configured to, if the dependency condition is not satisfied, cause the current execution unit to enter a waiting state until the dependency condition is satisfied, thereby obtaining input data in the first preset format; A calculation module, used to calculate the input data in the first preset format according to a preset formula to obtain a current simulation execution result, and write the current simulation execution result into the simulation module according to a second preset format, wherein the preset formula is set corresponding to the hardware calculation unit; A second judgment module is used to judge whether the instruction queue corresponding to each execution unit is empty; The result acquisition module is used to repeat the above simulation verification steps if the instruction queue corresponding to each execution unit is not empty until the instructions in the instruction queue corresponding to each execution unit obtain the corresponding simulation execution results.

9. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the simulation verification method for NPU instructions according to any one of claims 1 to 7 by executing the executable instructions.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the simulation verification method for NPU instructions described in any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • NPU, instruction set, control method and device based on instruction set, and storage medium

    CN118939321A