Method and device for inserting synchronization instruction

By automatically inserting synchronization instruction pairs between functional instructions and optimizing the synchronization path graph based on data dependencies, the problem of functional instruction parallelism degradation in traditional technology is solved and the processing performance of the processor is improved.

CN112130898BActive Publication Date: 2024-09-24HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910551144.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-06-24
Publication Date
2024-09-24
Estimated Expiration
2039-06-24

Smart Images

  • Figure CN112130898B
    Figure CN112130898B
Patent Text Reader

Abstract

The present application discloses a method and device for inserting synchronization instructions, and relates to the field of computers. The method identifies the functional instructions to be synchronized by automatically analyzing the data dependency relationship between instructions in a program, and then inserts the synchronization instructions. After obtaining a first program block containing one or more statements, it is determined that there are a first functional instruction and a second functional instruction with data dependency in the first program block, and then a synchronization instruction pair is inserted between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs, which can effectively improve the parallelism between the functional instructions and improve the processing performance of the DAE or DAE-like processor in processing the functional instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method and device for inserting synchronization instructions. Background Art

[0002] When a computing architecture based on Decoupled Access-Execute (DAE) or a DAE-like processor executes a program's functional instructions, functional instructions of the same functional type can be processed serially, and functional instructions of different functional types can be processed in parallel. However, in conventional technology, a synchronization instruction pair is inserted between adjacent functional instructions. In this way, two functional instructions that could have been executed in parallel may degenerate into serial execution due to the existence of a synchronization relationship, resulting in the problem of degradation of parallelism between functional instructions. Summary of the invention

[0003] The present application provides a method and device for inserting synchronization instructions, so as to improve the parallelism between functional instructions when a synchronization instruction pair is inserted between functional instructions.

[0004] In order to achieve the above objectives, this application adopts the following technical solutions:

[0005] In the first aspect, an embodiment of the present application provides a method for inserting synchronization instructions, which can be applied to a computer device, or the method can be applied to a computing device that can support a computer device to implement the method, for example, the computing device includes a chip system, and the method includes: obtaining a first program block containing one or more statements, determining that there are a first functional instruction and a second functional instruction with data dependency in the first program block, and inserting a synchronization instruction pair between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs. Each of the one or more statements includes one or more functional instructions. The first functional instruction and the second functional instruction may refer to any two functional instructions in the first program block.

[0006] The method for inserting synchronization instructions provided in the present application can effectively improve the parallelism between functional instructions by automatically inserting synchronization instruction pairs between functional instructions based on data dependencies between functional instructions, thereby improving the processing performance of DAE or DAE-like processors in processing functional instructions.

[0007] In a possible implementation, the first program block includes simple statements and / or compound statements; wherein a simple statement is a statement containing only one functional instruction, and a compound statement is a statement containing multiple functional instructions, such as a branch statement or a loop statement.

[0008] In a possible implementation manner, a first function instruction and a second function instruction having data dependency access data at the same address, and at least one of the first function instruction and the second function instruction updates the data.

[0009] In a possible implementation, the address ranges of data accessed by the data-dependent first function instruction and the second function instruction overlap, and at least one of the first function instruction and the second function instruction updates the data.

[0010] In a possible implementation, the first function instruction and the second function instruction having data dependency transfer data through a shared storage space, for example, the first function instruction and the second function instruction transfer data through a specific register.

[0011] In a possible implementation, a directed dependency relationship of functional instructions that have established synchronization can be represented by a synchronization path graph; the synchronization path graph includes multiple functional instruction nodes and synchronization paths between the multiple functional instruction nodes, each of the multiple functional instruction nodes corresponds to a functional instruction, and the synchronization path includes a serial synchronization path and an instruction synchronization path, the serial synchronization path is a path connecting nodes corresponding to two functional instructions that have serial dependency, the instruction synchronization path is a path connecting nodes corresponding to two functional instructions that have data dependency, and the serial dependency is a dependency relationship between functional instructions processed in a serial manner by a processing unit.

[0012] Furthermore, an instruction synchronization path between the node of the first function instruction and the node of the second function instruction is established in the first synchronization path graph.

[0013] Furthermore, in the first synchronization path diagram, a serial synchronization path is established for functional instructions that have serial dependencies, for example, a serial synchronization path is established between a node corresponding to the first functional instruction and a node corresponding to a third functional instruction, wherein the first functional instruction and the third functional instruction have a serial dependency, that is, the first functional instruction and the third functional instruction are executed in a serial manner by the same processing unit.

[0014] In a possible implementation, inserting a synchronization instruction pair between a statement to which a first functional instruction belongs and a statement to which a second functional instruction belongs includes: inserting a synchronization instruction pair between a statement to which the first functional instruction belongs and a statement to which the second functional instruction belongs according to a first synchronization path diagram.

[0015] In a possible implementation, inserting a synchronization instruction pair between a statement to which a first functional instruction belongs and a statement to which a second functional instruction belongs according to a first synchronization path graph includes: determining that in the first synchronization path graph, a synchronization path from a node corresponding to the first functional instruction to a node corresponding to the second functional instruction is unreachable, and inserting a synchronization instruction pair between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs. The embodiment of the present application uses a synchronization path graph to represent the synchronization and serial dependency between functional instructions. For two functional instructions with data dependency, a synchronization instruction pair is inserted only when it is confirmed based on the synchronization path graph that the path between them is unreachable. This can reduce the redundancy of synchronization instructions after insertion based on data dependency, avoid unnecessary insertion of synchronization instructions that leads to reduced instruction parallelism, and further affect the performance of the processor in executing the program.

[0016] In one possible implementation, the first program block includes a loop statement, and the method further includes: determining that there are a fourth functional instruction and a fifth functional instruction with data dependence in the loop statement; determining that in the first synchronization path diagram, the synchronization path from the node corresponding to the fourth functional instruction to the node corresponding to the fifth functional instruction is unreachable, and inserting a synchronization instruction pair between the statement to which the fourth functional instruction belongs and the statement to which the fifth functional instruction belongs.

[0017] In one possible implementation, the first program block includes a loop statement, and the method further includes: identifying a fourth functional instruction and a fifth functional instruction having data dependencies in the loop statement; determining that in the synchronization path diagram and the reverse synchronization path diagram, the synchronization paths from the node corresponding to the fifth functional instruction to the node corresponding to the fourth functional instruction are both unreachable, and inserting a synchronization instruction pair between the statement to which the fourth functional instruction belongs and the statement to which the fifth functional instruction belongs, wherein the directed dependency relationship of the functional instructions that have established synchronization in the loop statement is represented by the reverse synchronization path diagram; the reverse synchronization path diagram includes multiple functional instruction nodes and synchronization paths between the multiple functional instruction nodes, and the direction of the synchronization path between the nodes of the functional instructions indicated in the reverse synchronization path diagram is opposite to that in the synchronization path diagram.

[0018] In one possible implementation, the synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction, and the method further includes: in the first program block into which the synchronization instruction pair has been inserted, configuring the second synchronization instruction for the unpaired first synchronization instruction; and / or configuring the first synchronization instruction for the unpaired second synchronization instruction.

[0019] Compared with the conventional technique of directly inserting the pairing synchronization instruction before and after the loop statement, the method of inserting the pairing synchronization instruction provided by the present application can stretch the pairing synchronization instruction as far forward or as far backward as possible before and after the loop statement. Thus, the pairing synchronization instruction is avoided from introducing unnecessary synchronization between functional instructions. By stretching the pairing synchronization instruction, the parallelism between functional instructions is further improved.

[0020] In another possible implementation, the method further includes: if the configured second synchronization instruction and the configured first synchronization instruction are a synchronization instruction pair, configuring an externalization mark for the configured second synchronization instruction and the configured first synchronization instruction; if the loop statement is a statement nested within another loop statement, externalizing the configured second synchronization instruction and the configured first synchronization instruction.

[0021] In a multi-layer loop nesting scenario, the traditional technology is to directly insert the pairing synchronization instruction of the inner loop before and after the inner loop statement, then the pairing synchronization instruction will be executed multiple times with the outer loop, and may even cause a reduction in parallelism. The method for inserting synchronization instructions provided in the embodiment of the present application can externalize the pairing synchronization instructions that have not yet been inserted into the synchronization instruction, and by externalizing the pairing synchronization instructions, the execution of the pairing synchronization instructions is reduced. Therefore, by externalizing the pairing synchronization instructions, the parallelism between functional instructions is further improved.

[0022] In a possible implementation, the method further includes: inserting a first synchronization instruction before a first statement in the first program block; or / and inserting a second synchronization instruction after a last statement in the first program block.

[0023] In another possible implementation, the synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction, and the method further includes: inserting the first synchronization instruction after the sixth function instruction outside the loop statement in the first program block, the sixth function instruction has a data dependency on the fifth function instruction in the loop statement, or the synchronization path from the node corresponding to the sixth function instruction in the first synchronization path diagram to the node corresponding to the fifth function instruction is reachable; and / or, inserting the second synchronization instruction before the sixth function instruction outside the loop statement in the first program block, the sixth function instruction has a data dependency on the fifth function instruction in the loop statement, or the synchronization path from the node corresponding to the sixth function instruction in the first synchronization path diagram to the node corresponding to the fifth function instruction is reachable.

[0024] In a possible implementation, the synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction; the first synchronization instruction is a push instruction for writing a synchronization message to a synchronization queue; the second synchronization instruction is a pop instruction for obtaining a synchronization message from the synchronization queue.

[0025] In a possible implementation, a push instruction is executed by a synchronized processing unit, and the push instruction is inserted after the synchronized functional instruction; a pop instruction is executed by a synchronized processing unit, and the push instruction is inserted before the functional instruction that needs to be synchronized.

[0026] In a possible implementation, a push instruction is expressed as push(x,y), and a pop instruction is expressed as pop(x,y), where x is the ID of the synchronized processing unit, and y is the ID of the synchronized processing unit.

[0027] The processing unit in the embodiment of the present application, unless otherwise specified, refers to a logically independent processing unit that can be executed in parallel with other processing units.

[0028] In a second aspect, an embodiment of the present application further provides a computing device for implementing the method described in the first aspect or any possible implementation of the first aspect. The computing device is a computer device or a computing device that supports a computer device to implement the method described in the first aspect, for example, the computing device includes a chip system.

[0029] In a possible implementation, the computing device includes: a processor and a memory, wherein the memory stores a first program block and a compiler program. The processor is configured to run the compiler program to implement the method described in the first aspect or any possible implementation of the first aspect.

[0030] In one possible implementation, the computing device includes one or more functional modules for implementing the method described in the first aspect or any possible implementation of the first aspect. These functional modules can be implemented by hardware, or can be implemented by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. For example, a transceiver is used to complete the functions of a receiving unit and a sending unit, a processor is used to complete the functions of a processing unit, and a memory is used to store a computer program or instruction for implementing the method described in the first aspect or any possible implementation of the first aspect. The processor, transceiver and memory are connected through a bus and communicate with each other.

[0031] In a possible implementation manner, a computer program for implementing the method described in the first aspect or any possible implementation manner of the first aspect is stored in a computer-readable storage medium.

[0032] In a third aspect, an embodiment of the present application further provides a computer device for implementing the method described in the first aspect or any possible implementation of the first aspect. For example, the computer device includes a processor for implementing the functions of the method described in the first aspect. The computer device may also include a memory for storing program instructions and data. The memory is coupled to the processor, and the processor can call and execute program instructions stored in the memory to implement the method described in the first aspect or any possible implementation of the first aspect. The computer device may also include a communication interface, and the communication interface is used for the computer device to communicate with other devices. Exemplarily, if the computer device is a network device, the other device is a terminal. If the computer device is a terminal, the other device is a network device.

[0033] In a fourth aspect, an embodiment of the present application further provides a computer device, comprising: at least one processor, and a memory coupled to the at least one processor, wherein the memory is used to store a computer program, the computer program comprising a program for inserting synchronization instructions according to the method described in the above-mentioned first aspect or any possible implementation of the first aspect, and the computer program with the synchronization instructions inserted is executed by the at least one processor.

[0034] In a fifth aspect, the present application further provides a computer-readable storage medium, comprising: computer instructions; when the computer instructions are executed by a processor, the computer device executes the method described in the above-mentioned first aspect or any possible implementation of the first aspect.

[0035] In a sixth aspect, the present application further provides a computer program product comprising instructions, which, when executed by a processor, executes the method described in the first aspect or any possible implementation of the first aspect.

[0036] In the seventh aspect, the present application provides a chip system, which includes at least one processor and a memory coupled to the at least one processor, wherein the memory stores a computer program, wherein the computer program includes a program for inserting synchronization instructions according to the method described in the first aspect or any possible implementation of the first aspect, and the computer program with the inserted synchronization instructions is executed by the at least one processor to implement the corresponding function.

[0037] In a possible implementation, the chip system may include multiple chips, or may include chips and other discrete devices.

[0038] In addition, the technical effects brought about by the design methods of any of the above aspects can refer to the technical effects brought about by the different design methods in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 An example diagram of an instruction sequence execution timing provided by the prior art;

[0040] Figure 2 A schematic diagram of the composition of a computer device provided in an embodiment of the present application;

[0041] Figure 3 An example diagram of an abstract syntax tree structure provided for this application;

[0042] Figure 4 An example diagram of the system operation logic structure provided for this application;

[0043] Figure 5 A flowchart of a method for inserting a synchronization instruction provided in an embodiment of the present application;

[0044] Figure 5A A schematic diagram of the process of accessing a memory interval by a functional instruction provided by this application;

[0045] Figure 6 Another example diagram of an abstract syntax tree structure provided for this application;

[0046] Figure 7 A schematic diagram of a first synchronization path diagram provided by the present application;

[0047] Figure 8 A flowchart of another method for inserting synchronization instructions provided in an embodiment of the present application;

[0048] Fig. 9 A schematic diagram of another first synchronization path diagram provided by the present application;

[0049] Fig.10 Another example diagram of an abstract syntax tree structure provided for this application;

[0050] Fig.11 A schematic diagram of another first synchronization path diagram provided by the present application;

[0051] Fig.12 A flowchart of another method for inserting a synchronization instruction provided in an embodiment of the present application;

[0052] Fig.13 This is another example diagram of an abstract syntax tree structure provided by this application;

[0053] Fig.14 A schematic diagram of another first synchronization path diagram provided by the present application;

[0054] Fig.15 A schematic diagram of a second synchronization path diagram provided by the present application;

[0055] Fig.16 A flowchart of another method for inserting a synchronization instruction provided in an embodiment of the present application;

[0056] Fig.17 A schematic diagram of the composition of a computing device provided in an embodiment of the present application;

[0057] Fig.18 A schematic diagram of the composition of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0058] The terms "first", "second", "third", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects rather than to limit a specific order.

[0059] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0060] "Multiple" means two or more, and other quantifiers are similar. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, for elements (element) in the singular form "a", "an", and "the", unless the context clearly stipulates otherwise, they do not mean "one or only one", but "one or more than one". For example, "a device" means one or more such devices. Furthermore, at least one (at least one of)... "means one or any combination of the subsequent associated objects, for example, "at least one of A, B and C" includes A, B, C, AB, AC, BC, or ABC.

[0061] In order to make the description of the following embodiments clear and concise, a brief introduction to the related technology is first given:

[0062] DAE or DAE-like processors: DAE or DAE-like processors can be divided into multiple logically independent processing units (or decoupled processing units) according to the functional type of the functional instructions. Each processing unit can execute instructions of the same functional type (or functional instructions) in a serial manner. Different processing units can execute functional instructions of different functional types in parallel. When executing a program (or an instruction sequence), the overall target program performance can be significantly improved by executing functional instructions in parallel. DAE or DAE-like processors are widely used in specific fields with data-intensive computing characteristics (such as the field of artificial intelligence (AI), etc.).

[0063] In some embodiments, a DAE or DAE-like processor may include two processing units: data access and calculation. The data access processing unit is used to execute memory read and write instructions. The calculation processing unit is used to execute logical calculation instructions. Optionally, the data access processing unit and the calculation processing unit may be further split to obtain more processing units. For example, the data access processing unit may be further divided into a data loading processing unit, a data storage processing unit, and the like. The data loading processing unit is used to execute memory read instructions. The data storage processing unit is used to execute memory write instructions. In practical applications, other processing units with more functions may be divided as needed. This is just an example, and this application does not limit this. In this article, for ease of description, all examples assume that a DAE or DAE-like processor includes a data access processing unit and a calculation processing unit. The identification (ID) of the data access processing unit may be abbreviated as A, and the identification of the calculation processing unit may be abbreviated as E.

[0064] According to the provisions of DAE or DAE-like processors, when writing or compiling a program executed by such DAE or DAE-like processors, it is necessary to explicitly insert synchronization instructions between functional instructions belonging to different processing units that have data dependencies (or called data dependency relationships), so as to avoid disorder caused by different processing units executing functional instructions of different functional types in parallel.

[0065] Data dependency: refers to the relationship that two functional instructions need to be processed by different processing units, and one functional instruction can only be executed after the other functional instruction is completed.

[0066] Serial dependency: refers to two functional instructions that need to be processed by the same processing unit, and the two functional instructions are executed by the same processing unit in a serial manner.

[0067] Then, the synchronization between two functional instructions belonging to different processing units can be achieved through the synchronization queue between the two processing units, and requires the insertion of additional synchronization instructions to complete the queueing and dequeuing of synchronization messages. Among them, the synchronization instruction is usually implemented as two paired instructions. Then, the synchronization instruction can also be called a synchronization instruction pair. For example, the synchronization instruction pair may include a queueing (push) instruction and a dequeuing (pop) instruction.

[0068] push instruction: used to instruct writing a synchronization message to the synchronization queue. Usually executed by the synchronized processing unit. The push instruction is usually inserted after the synchronized functional instruction. Since a processing unit executes functional instructions in a serial manner, when the push instruction is executed, it means that the synchronized functional instruction before the push instruction has been executed. In this article, the push instruction can be expressed as push(x,y), where x represents the identifier of the synchronized processing unit and y represents the identifier of the synchronized processing unit. For example, assuming that the synchronized processing unit is a computing processing unit and the synchronized processing unit is a data access processing unit, the push instruction can be expressed as push(E,A); or, the synchronized processing unit is a data access processing unit and the synchronized processing unit is a computing processing unit, the push instruction can be expressed as push(A,E).

[0069] pop instruction: used to instruct to obtain synchronization messages from the synchronization queue. Usually executed by the synchronization processing unit. The pop instruction is usually inserted before the synchronization function instruction that needs to be synchronized. When the queue is empty, the synchronization processing unit blocks and waits until the synchronization message is written by the synchronized processing unit. Therefore, when the pop instruction is executed, it means that the push instruction corresponding to the pop instruction has been executed. Since a processing unit executes functional instructions in a serial manner, when the synchronization function instruction is executed, the pop instruction execution, the push instruction corresponding to the pop instruction, and the synchronized function instruction have all been executed. Thereby achieving synchronization between the synchronized function instruction and the synchronization function instruction. In this article, the pop instruction can be expressed as pop(x,y), where x represents the identifier of the synchronized processing unit and y represents the identifier of the synchronization processing unit. For example, assuming that the synchronized processing unit is a computing processing unit and the synchronization processing unit is a data access processing unit, the pop instruction can be expressed as pop(E,A); or, the synchronized processing unit is a data access processing unit and the synchronization processing unit is a computing processing unit, the pop instruction can be expressed as pop(A,E).

[0070] Backus-Naur Form (BNF): is a formal notation used to describe the syntax of a specific programming language. Usually, a programming language may include grammatical structures such as sequence, loop, and branch. In this article, these grammatical structures can be defined based on BNF. BNF can be used to describe other codes with similar grammar descriptions, so I will not go into details. The following is a BNF grammar:

[0071]

[0072]

[0073] In the conventional technology, a pair of synchronization instructions can be inserted between adjacent functional instructions. For example, as shown below, it is a sequential structure program:

[0074] x=load(0x100) / / S1

[0075] x=x+1 / / S2

[0076] y=load(0x200) / / S3

[0077] y=y+x / / S4

[0078] Among them, statements S1 and S3 correspond to data loading instructions and need to be executed by the data access processing unit. Statements S2 and S4 correspond to logic calculation instructions and need to be executed by the calculation processing unit. S2 depends on S1, and S4 depends on S2 and S3. Insert a synchronization instruction pair between S1 and S2, insert a synchronization instruction pair between S2 and S3, and insert a synchronization instruction pair between S3 and S4. After inserting the synchronization instruction pair, the program is as follows:

[0079] x=load(0x100) / / S1

[0080] push(A,E)

[0081] pop(A,E)

[0082] x=x+1 / / S2

[0083] push(E,A)

[0084] pop(E,A)

[0085] y=load(0x200) / / S3

[0086] push(A,E)

[0087] pop(A,E)

[0088] y=y+x / / S4

[0089] Based on the above program after inserting the synchronization instruction pair, such as Figure 1 As shown, it is an example diagram of an instruction sequence execution timing provided by the prior art. It can be seen from the instruction sequence execution timing that the data access processing unit and the computing processing unit execute statements in the order in which the statements are arranged, that is, the data access processing unit first executes statement S1, then executes statement push(A,E), then the computing processing unit executes statement pop(A,E), then executes statement S2 and statement push(E,A), the data access processing unit then executes statement pop(E,A), statement S3 and statement push(A,E), and the computing processing unit then executes statement pop(A,E) and statement S4. Therefore, after inserting the synchronization instruction pair, the dependency relationship of S2 depending on S1 and S4 depending on S2 and S3 is satisfied.

[0090] For loop structure programs, since the loop body may need to be executed repeatedly, that is, in the next loop, the first statement of the loop body needs to wait until the last statement of the loop body is executed before execution, so it is necessary to insert a synchronization instruction pair between the last statement of the loop body and the first statement of the loop body, that is, insert a push instruction after the last statement and insert a pop instruction before the first statement. In addition, since the push instruction and the pop instruction need to appear in pairs, and the push instruction needs to be before the pop instruction, for the pop instruction inserted before the first statement, an additional push instruction is added before the first loop for pairing (hereinafter referred to as push pairing); for the push inserted after the last statement, an additional pop instruction is added after the last loop for pairing (hereinafter referred to as pop pairing).

[0091] The following is an example of a loop structure program:

[0092] for(i=0;i <n;i++){

[0093] x=load(0x100) / / S1

[0094] x=x+1 / / S2

[0095] }

[0096] Among them, S1 corresponds to the data loading instruction and needs to be executed by the data access processing unit; S2 corresponds to the logic calculation instruction and needs to be executed by the calculation processing unit. S2 depends on S1. Insert a synchronization instruction pair between S1 and S2, insert a pop instruction before S1, insert a push instruction after S2, and then pair the synchronization instructions. After inserting the synchronization instruction pair, the program is as follows:

[0097] push(E,A) / / push pairing

[0098] for(i=0;i <n;i++){

[0099] pop(E,A)

[0100] x=load(0x100) / / S1

[0101] push(A,E)

[0102] pop(A,E)

[0103] x=x+1 / / S2

[0104] push(E,A)

[0105] }

[0106] pop(E,A) / / pop pairing

[0107] For branch structure programs, it is uncertain which branch statement will be executed during program execution. Therefore, it is necessary to insert the synchronization instruction pair outside the branch structure body boundary. In this way, it is guaranteed that the push instruction and pop instruction pair can always be achieved.

[0108] The following is an example of a branch structure program:

[0109] x=load(0x100) / / S1

[0110] If(cond){

[0111] x=x+1 / / S2

[0112] }

[0113] store(x,0x200) / / S3

[0114] Among them, the two statements S1 and S3 correspond to data loading instructions and need to be executed by the data access processing unit. S2 corresponds to the logic calculation instruction and needs to be executed by the calculation processing unit. S2 depends on S1, and S3 depends on S1 and S2. Insert the synchronization instruction pair at the outer boundary of the branch structure. After inserting the synchronization instruction pair, the program is as follows:

[0115] x=load(0x100) / / S1

[0116] push(A,E)

[0117] pop(A,E)

[0118] If(cond){

[0119] x=x+1 / / S2

[0120] }

[0121] push(E,A)

[0122] pop(E,A)

[0123] store(x,0x200) / / S3

[0124] Although, according to the above method, it is possible to insert synchronization instructions between functional instructions processed by different processing units, and avoid the disorder phenomenon that occurs when different processing units execute functional instructions of different functional types in parallel. However, after inserting the synchronization instruction pair using the above method, the functional instructions that could originally be executed in parallel may be degraded to serial execution due to the existence of indirect dependencies, and the hardware capabilities of parallel execution of DAE or DAE-like processors cannot be fully utilized. For example, in the above sequential structure program, the two statements S2 and S3 can originally be executed in parallel. After inserting the synchronization instruction pair using the above method, the parallel capability between the two statements S2 and S3 will be lost, and the two statements S2 and S3 need to be executed serially.

[0125] It should be noted that the program code to be inserted with the synchronization instruction pair can be regarded as a program block (block) containing one or more statements. A statement can be a compound statement (such as a loop statement or a branch statement), and a loop statement or a branch statement can be nested to contain a subprogram block. For example, if the statement is a loop statement, the loop statement includes the loop body, and if the statement is a branch statement, the branch statement includes the branch body.

[0126] The present application provides a method for inserting synchronization instructions, the method comprising: after obtaining a first program block containing one or more statements, determining the first functional instruction and the second functional instruction with data dependency in the first program block, and inserting a synchronization instruction pair between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs. Each of the one or more statements includes one or more functional instructions. The first functional instruction and the second functional instruction may refer to any two functional instructions in the first program block. Thus, by automatically inserting a synchronization instruction pair between functional instructions based on the data dependency between functional instructions, the parallelism between functional instructions can be effectively improved, thereby improving the processing performance of DAE or DAE-like processors in processing functional instructions. The method for inserting synchronization instructions provided in the present application can be applicable to devices including DAE or DAE-like processors.

[0127] Figure 2A schematic diagram of the composition of a computer device provided in an embodiment of the present application. The computer device 200 may be a device including a DAE or DAE-like processor or a computer device supporting a DAE or DAE-like processor to implement the method of inserting synchronization instructions. For example, the computer device 200 may be a chip system. In the embodiment of the present application, the chip system includes one or more chips, and may also include chips and other discrete devices. Figure 2 As shown, the computer device may include at least one processor 21 , a memory 22 , a communication interface 23 , a communication bus 24 , and an input and output device 25 .

[0128] Combine the following Figure 2 A detailed introduction to the various components of computer equipment:

[0129] The processor 21 is the control center of the computer device, which can be a processor or a general term for multiple processing elements. In a specific implementation, as an embodiment, the processor 21 can include a central processing unit (CPU) or multiple CPUs, such as Figure 2 The processor 21 may also be an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application, such as one or more microprocessors (digital signal processors, DSP), or one or more field programmable gate arrays (field programmable gate arrays, FPGA).

[0130] Taking the processor 21 as one or more CPUs as an example, the processor 21 can execute various functions of the computer device by running or executing software programs stored in the memory 22 of the computer device and calling data stored in the memory 22.

[0131] In a specific implementation, as an embodiment, a computer device may include multiple processors, such as Figure 2 21 and processor 26 shown in FIG. Each of these processors may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0132] In an embodiment of the present application, the processor is mainly used to determine the existence of a first functional instruction and a second functional instruction with data dependency in the first program block after acquiring a first program block containing one or more statements, and insert a synchronization instruction pair between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs. Each of the one or more statements includes one or more functional instructions. The first functional instruction and the second functional instruction may refer to any two functional instructions in the first program block.

[0133] The memory 22 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 22 may exist independently and be connected to the processor 21 via a communication bus 24. The memory 22 may also be integrated with the processor 21.

[0134] The memory 22 is used to store program codes and execute software programs of the solution of the present application, and is controlled and executed by the processor 21 .

[0135] The communication interface 23 is used to communicate with other devices or a communication network. The communication interface 23 may include a receiving unit to implement a receiving function, and a sending unit to implement a sending function.

[0136] The communication bus 24 may be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 2 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0137] The input / output device 25 is used to obtain the program (or input code) from the memory 22, transmit the input code to the processor, and transmit the program (output code) after inserting the synchronization instruction pair from the processor to the memory for storage. It should be noted that the program code is a program source code that follows a specific BNF grammar, or an intermediate representation (Intermediate Representation) of a compiler, etc.

[0138] Figure 2 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0139] Optionally, after the processor obtains the program, the program can be converted into an abstract syntax tree (AST) (or syntax tree (ST)), and synchronization instruction pairs can be inserted into the program based on the abstract syntax tree. In computer science, an abstract syntax tree is an abstract representation of the syntax structure of the source code. It represents the syntax structure of a programming language in a tree-like form, and each node on the tree represents a structure or a single functional instruction in the source code. The parent-child node relationship corresponds to the nested inclusion relationship of statements. Multiple child nodes connected to the same parent node are sequential statements. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax. For example, nested parentheses are implied in the tree structure and are not presented in the form of nodes; and conditional jump statements such as "if-condition-then" can be represented by nodes with two branches.

[0140] For example, the following program is a program including a loop statement, and the loop body includes a branch statement.

[0141]

[0142]

[0143] Convert this program into an abstract syntax tree, such as Figure 3 As shown in (a) in the figure, the node "block", the node "for(n)" and the node "if(cond)" are parent nodes respectively. The node "for(n)" is the child node of the node "block". The node "S1", the node "if(cond)" and the node "S3" are the child nodes of the node "for(n)". The node "S2" is the child node of the node "if(cond)".

[0144] Then, starting from the root node (node ​​"block"), on the abstract syntax tree, the synchronization instruction nodes are inserted between the child nodes connected to the parent node based on each non-child node (parent node) in a deep recursive manner. Since S2 depends on S1, S3 depends on S2, such as Figure 3 As shown in (b), a synchronization instruction node is inserted between node "S1" and node "if(cond)", and a synchronization instruction node is inserted between node "if(cond)" and node "S3". Since there is no dependency from statement S3 to statement S1, there is no need to insert a reverse synchronization instruction pair between statement S3 and statement S1.

[0145] Then, according to the abstract syntax tree of the inserted synchronization instruction node, the corresponding output code is generated.

[0146] Figure 4 This is an example diagram of the logical structure of a system operation provided by the present application. Among them, the input-output device 25 reads the input code from the memory 22, transmits the input code to the processor 21 through the communication bus 24, and the processor 21 converts the input code into an abstract syntax tree, and inserts the synchronization instruction node based on the abstract syntax tree. Since the abstract syntax tree is a recursive structure, and each recursive node is contained in a block node, a deep recursive method can be used to insert the synchronization instruction node layer by layer from bottom to top, and then the abstract syntax tree with the inserted synchronization instruction node is converted into the output code, and the processor 21 transmits the output code to the input-output device 25, and the input-output device 25 writes the output code into the memory 22.

[0147] Below, taking the first program block as an example, the implementation method of the method for inserting synchronization instructions provided by the present application is described in detail in conjunction with the accompanying drawings. Assume that the first program block includes n statements, wherein n is an integer, n is greater than or equal to 1, and n represents the number of statements included in the first program block. Each of the n statements includes one or more functional instructions. After starting to execute the first program block, it can be defaulted to block (bolck) entry, traverse n statements, and each statement in the n statements can be processed according to the method for inserting synchronization instructions provided in the embodiment of the present application. After traversing each statement in the n statements, it indicates that the block ends.

[0148] In the first possible design, the first program block is a sequentially structured program. The n statements included in the first program block can all be single functional instructions. The following takes the i-th functional instruction in the first program block as an example to illustrate the process of inserting synchronization instructions, where i is an integer, i∈[1,n]. It can be understood that the i-th functional instruction is the functional instruction currently traversed. Figure 5 As shown, it is a flowchart of a method for inserting a synchronization instruction provided by an embodiment of the present application, and the method may include:

[0149] S501 , determining a functional instruction that has a serial dependency on the i th functional instruction.

[0150] In some embodiments, statements in the first program block are traversed along a first direction starting from the ith functional instruction to determine a functional instruction that has a serial dependency with the ith functional instruction. Two functional instructions with a serial dependency are executed in a serial manner by the same processing unit.

[0151] In some embodiments, if the i-th functional instruction is the first functional instruction of the first program block, it indicates that there are no functional instructions that can be traversed along the first direction starting from the first functional instruction, and of course no functional instruction that has a serial dependency with the first functional instruction has been determined.

[0152] In other embodiments, the functional instructions arranged along the first direction starting from the i-th functional instruction and the i-th functional instruction are executed by different processing units, indicating that there is no serial dependency between the functional instructions arranged along the first direction starting from the i-th functional instruction and the i-th functional instruction, and of course, the functional instructions having a serial dependency with the i-th functional instruction have not been determined.

[0153] If a functional instruction having a serial dependency with the i-th functional instruction is determined, S502 is executed.

[0154] S502: Establish a serial synchronization path between the node of the i-th functional instruction and the nodes of the functional instructions that are serially dependent on the i-th functional instruction in the first synchronization path graph.

[0155] The present application provides a first synchronization path graph, which is a dynamically maintained directed dependency graph for expressing functional instructions that have established synchronization. The first synchronization path graph can be called a global forward synchronization path graph. The nodes of the graph represent functional instructions, and the edges between the nodes represent synchronization paths. The synchronization paths here include serial synchronization paths and instruction synchronization paths.

[0156] Since the same processing unit executes two adjacent functional instructions in a serial manner, it can be considered that the two adjacent functional instructions processed by the same processing unit naturally have a serial dependency. Then, the serial synchronization path can refer to the edge connecting the nodes of the two adjacent functional instructions processed by the same processing unit.

[0157] The so-called instruction synchronization path may refer to an edge connecting nodes of two functional instructions that are processed by different processing units and have data dependency.

[0158] In some embodiments, if a functional instruction that has a serial dependency on the i-th functional instruction is determined, a node of the i-th functional instruction is added to the first synchronization path graph, and a serial synchronization path from the node of the functional instruction that has a serial dependency on the i-th functional instruction to the node of the i-th functional instruction is added.

[0159] In other embodiments, if no functional instruction that is serially dependent on the ith functional instruction is determined, it is only necessary to add the node of the ith functional instruction in the first synchronization path diagram, and in this case, the serial synchronization path of adding the node of the ith functional instruction is not involved. For example, if the ith functional instruction is the first functional instruction of the first program block, it indicates that there are no traversable functional instructions along the first direction starting from the first functional instruction, and of course, no functional instruction that is serially dependent on the first functional instruction is determined.

[0160] S503: Determine Q functional instructions that have data dependency on the i-th functional instruction.

[0161] In some embodiments, statements in the first program block may be traversed along a first direction starting from the ith functional instruction to determine Q functional instructions having data dependency on the ith functional instruction, where Q is an integer.

[0162] Among them, according to the different traversal directions of the statements in the first program block, the first direction may also be different.

[0163] For example, when the traversal direction of the statements in the first program block is the sequential arrangement direction of the statements included in the first program block, the first direction may be the opposite direction of the sequential arrangement direction of the statements included in the first program block.

[0164] For another example, when the traversal direction of the statements in the first program block is opposite to the sequential arrangement direction of the statements included in the first program block, the first direction may be the sequential arrangement direction of the statements included in the first program block.

[0165] For the convenience of description, the following description will be given by taking the first direction as the opposite direction of the sequential arrangement direction of the statements included in the first program block and the second direction as the sequential arrangement direction of the statements included in the first program block as an example.

[0166] In some embodiments, it is possible to determine whether data dependency exists between any two functional instructions based on read-after-write, write-after-read, write-after-write, etc., performed on the same block of memory data.

[0167] For example, for two functional instructions I1 and I2, if one of the following conditions exists, it is considered that I1 and I2 have data dependency:

[0168] 1) I1 and I2 access data at the same address, and at least one of I1 and I2 will update the memory data;

[0169] 2) The address ranges of the data accessed by I1 and I2 overlap, and at least one of I1 and I2 will update the data in the overlapping part;

[0170] 3) There are other potential dependencies between I1 and I2, such as the need to transfer data between I1 and I2 through a shared storage space.

[0171] The following code example illustrates how to determine whether there is data dependency between functional instructions. For the sake of convenience, the following example uses the memory access interval tag definition:

[0172] Memory access interval: M (element type, element offset, number of elements accessed); element type refers to the type of continuous data elements in the access interval, such as float16, which represents a 16-bit floating point number. Element offset / number of elements accessed is in units of element type length.

[0173] The code example is as follows:

[0174] set_round_mode(round_to_nearest) / / S1: Set floating point rounding mode

[0175] vector_sqrt(M(float16,100,100),M(float16,0,100)) / / S2: vector data element-by-element sqrt

[0176] vector_sqrt(M(float16,200,100),M(float16,100,100)) / / S3: vector data element-by-element sqrt

[0177] vector_set(M(float16,0,600),0) / / S4: clear vector data element by element

[0178] In the example above:

[0179] Instruction S1 sets the rounding mode for floating point calculations. The corresponding hardware will write to a special register.

[0180] Instruction S2 performs sqrt on each element of the 100 f16 data in M(f16,0,100), and then writes them into M(f16,100,100).

[0181] Instruction S3 performs sqrt on each element of the 100 f16 data in M(f16,100,100), and then writes them into M(f16,200,100).

[0182] Instruction S4 clears the 300 elements in M(f16,0,300) to zero respectively.

[0183] Figure 5A The process of the above instructions accessing the memory interval is shown. Based on this, the data dependency relationship between the instructions can be determined as follows:

[0184] 1) Since both S2 and S3 depend on the flag stored in the register set by S1 for calculation, S2 and S3 depend on S1;

[0185] 2) The read interval of S3 overlaps with the write interval M of S2, so S3 depends on S2;

[0186] 3) The write address of S4 and the read address of S2 are both 0, and they overlap the read and write intervals. So S4 depends on S2;

[0187] 4) The write interval M of S4 overlaps with the read interval and write interval of S3, so S4 depends on S3.

[0188] It should be noted that the determination of whether there is data dependency between any two functional instructions can be performed in the process of traversing the functional instructions in the first program block along the first direction starting from the i-th functional instruction. Of course, the above method can also be used to analyze the data dependency between any two functional instructions in the first program block before traversing the functional instructions in the first program block, and then store the information of the functional instructions with data dependency in the first program block. This application is not limited to this.

[0189] In particular, if Q=0, it means that no functional instruction that has data dependency with the ith functional instruction has been determined, and at this time, there is no need to insert a synchronization instruction pair. For example, if the ith functional instruction is the first functional instruction of the first program block, it means that there are no traversable functional instructions along the first direction starting from the first functional instruction, and of course no functional instruction that has data dependency with the first functional instruction has been determined. For another example, the functional instructions arranged along the first direction starting from the ith functional instruction and the ith functional instruction are both executed by the same processing unit, indicating that the functional instructions arranged along the first direction starting from the ith functional instruction have serial dependency with the ith functional instruction, and of course no functional instruction that has data dependency with the ith functional instruction has been determined.

[0190] In some embodiments, when Q=0 and i=n, ​​it means that the i-th functional instruction is the last functional instruction of the first program block, and no functional instruction having data dependency with the i-th functional instruction is determined. At this time, the execution of the first program block ends.

[0191] In some other embodiments, when Q = 0 and i < n, it indicates that the i-th functional instruction is not the last functional instruction of the first program block. At this time, i is incremented by 1, and the traversal of other functional instructions of the first program block continues in the second direction. For specific details, refer to the detailed description of S501 to S505.

[0192] When Q is greater than or equal to 1, it indicates that a functional instruction with a data dependency on the i-th functional instruction has been determined, and S504 is executed.

[0193] S504. Insert a pair of synchronization instructions between the statement to which the i-th functional instruction belongs and the statements to which each of the P functional instructions belongs.

[0194] In the embodiments of the present application, each statement in the first program block is a single functional instruction. Inserting a pair of synchronization instructions between the statement to which the i-th functional instruction belongs and the statements to which each of the Q functional instructions belongs can also be understood as inserting a pair of synchronization instructions between the i-th functional instruction and each of the Q functional instructions.

[0195] In a possible implementation manner, a pair of synchronization instructions can be inserted between the i-th functional instruction and each of the Q functional instructions according to the first synchronization path diagram.

[0196] For example, the first synchronization path diagram can be queried to determine whether the path from the node of each functional instruction in the Q functional instructions to the node of the i-th functional instruction is reachable, so as to determine the P functional instructions among the Q functional instructions that have not established a synchronization relationship with the i-th functional instruction, where P is an integer and 0 ≤ P ≤ Q.

[0197] If the path from the node of the functional instruction with a data dependency on the i-th functional instruction to the node of the i-th functional instruction is reachable, it indicates that the functional instruction with a data dependency on the i-th functional instruction and the i-th functional instruction have established synchronization. For example, the path between the node of the functional instruction with a data dependency on the i-th functional instruction and the node of the i-th functional instruction may be made reachable through an instruction synchronization path and a serial synchronization path.

[0198] If the path from the node of the functional instruction with a data dependency on the i-th functional instruction to the node of the i-th functional instruction is not reachable, it indicates that the functional instruction with a data dependency on the i-th functional instruction and the i-th functional instruction are not synchronized.

[0199] In particular, if P = 0, it indicates that there is no functional instruction among the Q functional instructions that has not established a synchronization relationship with the i-th functional instruction, which can also be understood as that the path from the node of each functional instruction in the Q functional instructions to the node of the i-th functional instruction is reachable. At this time, there is no need to perform the insertion operation of the pair of synchronization instructions.

[0200] When P is greater than or equal to 1, it indicates that there are functional instructions among the Q functional instructions that have not established a synchronization relationship with the i-th functional instruction. Synchronization instruction pairs are inserted between the i-th functional instruction and each of the P functional instructions.

[0201] In some embodiments, the synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction; the first synchronization instruction is a push instruction for writing a synchronization message to the synchronization queue; the second synchronization instruction is a pop instruction for retrieving a synchronization message from the synchronization queue.

[0202] In some embodiments, a push instruction can be inserted after the functional instruction that has not established a synchronization relationship with the i-th functional instruction, and a pop instruction can be inserted before the i-th functional instruction.

[0203] Optionally, synchronization instruction pairs can be inserted between the i-th functional instruction and each of the P functional instructions according to the reverse direction of the order arrangement direction of the statements included in the first program block. For example, a push instruction can be inserted first after the functional instruction closest to the i-th functional instruction among the P functional instructions, and a pop instruction can be inserted before the i-th functional instruction. Then, a push instruction can be inserted after the functional instruction with the second-closest distance to the i-th functional instruction among the P functional instructions, and a pop instruction can be inserted before the pop instruction inserted before the i-th functional instruction, and so on, to complete the process of inserting synchronization instruction pairs between the i-th functional instruction and each of the P functional instructions.

[0204] In some embodiments, when P = 0 and i = n, it means that the i-th functional instruction is the last functional instruction of the first program block, and there are no functional instructions among the Q functional instructions that have not established a synchronization relationship with the i-th functional instruction. At this time, the execution of the first program block ends.

[0205] In other embodiments, when P = 0 and i < n, it means that the i-th functional instruction is not the last functional instruction of the first program block. At this time, continue to traverse the other functional instructions of the first program block in the second direction. For specific details, refer to the detailed description of S501 - S505.

[0206] Thus, the functional instructions with established synchronization relationships are dynamically maintained through the first synchronization path diagram, and references are made before inserting new synchronization instructions. If the paths between statements are reachable, there is no need to insert synchronization instruction pairs anymore, eliminating redundant synchronization and effectively improving the parallelism between functional instructions.

[0207] S505. Establish an instruction synchronization path between the node of the i-th functional instruction and the nodes of each of the P functional instructions in the first synchronization path diagram.

[0208] An instruction synchronization path from a node of each functional instruction in the P functional instructions to a node of the i-th functional instruction is added to the first synchronization path graph.

[0209] It should be noted that if the path from the node of the functional instruction that has data dependency on the i-th functional instruction to the node of the i-th functional instruction is reachable, it indicates that the functional instruction that has data dependency on the i-th functional instruction and the i-th functional instruction have been synchronized. For example, the node of the functional instruction that has data dependency on the i-th functional instruction and the node of the i-th functional instruction may be reachable through the instruction synchronization path and the serial synchronization path. In this case, there is no need to update the first synchronization path diagram.

[0210] In some embodiments, when i=n, ​​it indicates that the i-th functional instruction is the last functional instruction of the first program block, and at this time, the execution of the first program block is completed.

[0211] The method for inserting synchronization instructions provided in the embodiment of the present application automatically inserts synchronization instruction pairs between functional instructions that have not established a synchronization relationship based on the data dependency between functional instructions processed by different processing units, thereby establishing synchronization between functional instructions with data dependency, and can effectively improve the parallelism between functional instructions, thereby improving the processing performance of DAE or DAE-like processors in processing functional instructions.

[0212] In order to express the synchronization between statements (stmt or block) through the first synchronization path diagram, it is first necessary to define the entry function instruction set and the exit function instruction set of the statement. For each stmt or block, as long as its direct or indirect sub-statement contains a functional instruction processed by a processing unit, then the stmt or block will have an entry function instruction set and an exit function instruction set belonging to the processing unit. The processing unit can be a data access processing unit or a computing processing unit.

[0213] The entry function instruction set of a statement refers to a set of all function instructions that may be executed first in the processing unit after the statement is executed by the processing unit.

[0214] Specifically, if the statement is a loop structure, the entry function instruction set of the statement is the entry function instruction set of the loop body of the statement;

[0215] If the statement has an else branch structure, the entry function instruction set of the statement is the union of the entry function instruction sets of the then and else branches;

[0216] If the statement has no else branch structure, the entry function instruction set of the statement is the entry function instruction set of the then branch body;

[0217] If the statement is a block structure, traverse from the first statement of the block along the second direction to the first statement S that contains the functional instructions of the processing unit and is not a "branch structure". The union of the entry functional instruction sets of all statements from the first statement of the block (including the first statement) to statement S (including statement S) at the processing unit;

[0218] If the statement is a single functional instruction, the entry functional instruction set of the statement is a set constructed with the functional instruction as the only element.

[0219] The exit function instruction set of a statement refers to the set of all function instructions that may be executed last in the processing unit before the statement is exited by the processing unit.

[0220] Specifically, if the statement is a loop structure, the exit function instruction set of the statement is the exit function instruction set of the loop body of the statement;

[0221] If the statement is an else branch structure, the exit function instruction set of the statement is the union of the exit function instruction sets of the then and else branches;

[0222] If the statement has no else branch structure, the exit function instruction set of the statement is the exit function instruction set of the then branch body;

[0223] If the statement is a block structure, traverse from the last statement of the block in the first direction to the first statement S that contains the functional instructions of the processing unit and is not a "branch structure". The union of the exit functional instruction sets of all statements from statement S (including statement S) to the last statement of the block (including the last statement) in the processing unit;

[0224] If the statement is a single functional instruction, it is a set constructed with the functional instruction as the only element.

[0225] For two statements S1 and S2, when a dependency is established between the exit function instruction set A of S1 and the entry function instruction set B of S2, it means that a synchronization path is added between each function instruction in A and each function instruction in B respectively.

[0226] For example, the single statement:

[0227] x=0 / / S1

[0228] The statement S1 is executed by the computing processing unit, and both the entry function instruction set and the exit function instruction set of the computing processing unit are [S1].

[0229] Another example is the branch statement:

[0230]

[0231] The entry function instruction set of the branch statement if(cond) in the computing processing unit is [S1, S3], and the exit function instruction set of the branch statement if(cond) in the computing processing unit is [S1, S4]. The entry function instruction set of the branch statement if(cond) in the data access processing unit is [S2], and the exit function instruction set of the branch statement if(cond) in the data access processing unit is [S2].

[0232] Another example is the block statement:

[0233]

[0234] The entry function instruction set of the block statement in the computing processing unit is [S2, S3], and the exit function instruction set of the block statement in the computing processing unit is [S3]. The entry function instruction set of the block statement in the data access processing unit is [S1], and the exit function instruction set of the block statement in the data access processing unit is [S4].

[0235] Another example is the loop statement:

[0236]

[0237]

[0238] The entry function instruction set of the loop statement in the computing processing unit is [S2, S3], and the exit function instruction set of the loop statement in the computing processing unit is [S3]. The entry function instruction set of the loop statement in the data access processing unit is [S1], and the exit function instruction set of the loop statement in the data access processing unit is [S4].

[0239] Combine the following Figure 6 and Figure 7 The following example illustrates the process of inserting a synchronization instruction pair into a sequential structure program. As shown below, the sequential structure program includes 5 statements (S1 to S5), each of which is a single functional instruction.

[0240]

[0241] Among them, statements S1, S4 and S5 are processed by the data access processing unit. Statements S2 and S3 are processed by the computing processing unit. Statements S1, S4 and S5 have serial dependencies. Statements S2 and S3 have serial dependencies. Data dependencies include: statement S3 depends on statement S1 and statement S2, statement S4 depends on statement S3, and statement S5 depends on statement S2.

[0242] 1. Convert the sequential structure program into an abstract syntax tree, such as Figure 6 As shown in (a) of FIG. 1 , the node "block" is the parent node, and the nodes "S1", "S2", "S3", "S4" and "S5" are the child nodes of the node "block" respectively.

[0243] 2. Traverse and process the five child nodes (S1 to S5) in the block in turn, and execute the process of inserting synchronization instruction pairs.

[0244] Node "S1": Add node "S1" to the first synchronization path graph. Since statement S1 is the first statement in the block, there are no statements in the block that can be traversed along the first direction starting from statement S1. Of course, no functional instructions that have a serial dependency on statement S1 have been determined, so there is no need to add a serial synchronization path for node "S1". It can be understood that statement S1 is an instruction in the entry functional instruction set of the data access processing unit. Similarly, no functional instructions that have a data dependency on statement S1 have been determined, and there is no need to insert a synchronization instruction pair, and there is no need to add an instruction synchronization path for node "S1". The abstract syntax tree remains Figure 6 As shown in (a) in the figure, no change is required. The change of the first synchronization path diagram is as follows Figure 7 As shown in (a) in .

[0245] Node "S2": Add node "S2" to the first synchronization path graph. Starting from statement S2, traverse the statements in the block along the first direction. No statement with serial dependency on statement S2 is determined, so the serial synchronization path of adding node "S2" is not involved. It can be understood that statement S2 is an instruction in the entry function instruction set of the computing processing unit. Starting from statement S2, traverse the statements in the block along the first direction. No statement with data dependency on statement S2 is determined, and there is no need to insert a synchronization instruction pair, so the instruction synchronization path of adding node "S2" is not involved. The abstract syntax tree remains Figure 6 As shown in (a) in the figure, no changes are required. The first synchronization path diagram is Figure 7 The change of (a) in Figure 7 (b) in .

[0246] Node "S3": Add node "S3" in the first synchronization path graph. Starting from statement S3, traverse the statements in the block along the first direction to determine statement S2 that has a serial dependency on statement S3. Add a serial synchronization path from node "S2" to node "S3" in the first synchronization path graph. Starting from statement S3, traverse the statements in the block along the first direction to determine statement S1 that has a data dependency on statement S3, and query the first synchronization path graph to determine that the path from node "S1" to node "S3" is unreachable, insert a synchronization instruction pair between statement S1 and statement S3, that is, insert push(A,E) after statement S1, and insert pop(A,E) before statement S3, and add an instruction synchronization path from node "S1" to node "S3" in the first synchronization path graph. The abstract syntax tree is composed of Figure 6 The change of (a) in Figure 6 (b) in the first synchronization path diagram. Figure 7 (b) in the equation changes to Figure 7 (c) in .

[0247] Node "S4": Add node "S4" in the first synchronization path graph. Starting from statement S4, traverse the statements in the block along the first direction, and determine statement S1 that has a serial dependency on statement S4. Add a serial synchronization path from node "S1" to node "S4" in the first synchronization path graph. Starting from statement S4, traverse the statements in the block along the first direction, determine statement S3 that has a data dependency on statement S4, and query the first synchronization path graph to determine that the path from node "S3" to node "S4" is unreachable, insert a synchronization instruction pair between statement S3 and statement S4, that is, insert push(E,A) after statement S3, and insert pop(E,A) before statement S4, and add an instruction synchronization path from node "S3" to node "S4" in the first synchronization path graph. The abstract syntax tree is composed of Figure 6 (b) in the equation changes to Figure 6 (c) in the first synchronization path diagram. Figure 7 The change of (c) in Figure 7 (d) in.

[0248] Node "S5": Add node "S5" to the first synchronization path graph. Starting from statement S5, traverse the statements in the block along the first direction to determine statement S4 that has a serial dependency on statement S5. Add a serial synchronization path from node "S4" to node "S5" in the first synchronization path graph. Starting from statement S5, traverse the statements in the block along the first direction to determine statement S2 that has a data dependency on statement S5, and query the first synchronization path graph to determine that the path from node "S2" to node "S5" is reachable (S2->S3->S4->S5), so there is no need to insert additional synchronization instruction pairs, and there is no need to add an instruction synchronization path from node "S2" to node "S5". The abstract syntax tree remains Figure 6 As shown in (c) in the figure, no changes are required. The first synchronization path diagram is Figure 7 The change of (d) in Figure 7 (e) in .

[0249] 3. Convert the abstract syntax tree of the inserted synchronization instruction pair into a program of the sequence structure after the inserted synchronization instruction pair. The program of the sequence structure after the inserted synchronization instruction pair is as follows:

[0250] x=load(0x100) / / S1

[0251] push(A,E)

[0252] y=10 / / S2

[0253] pop(A,E)

[0254] z=x+y / / S3

[0255] push(E,A)

[0256] pop(E,A)

[0257] store(z,0x200) / / S4

[0258] store(y,0x300) / / S5

[0259] In a second possible design, the first program block can be a structure of a compound statement. If the compound statement is a branch statement (if), n statements are statements in the branch structure, and the n statements can all be single functional instructions. The difference from the first possible design mentioned above is that after establishing synchronization for the statements in the branch structure, it is also necessary to establish synchronization between the statements in the first program block and the statements outside the first program block. For details, refer to the following description of the relevant embodiments.

[0260] Figure 8 A flowchart of a method for inserting a synchronization instruction provided in an embodiment of the present application is shown in FIG. Figure 8As shown, the method may include:

[0261] S801, determining a functional instruction that has a serial dependency on the i-th functional instruction.

[0262] In some embodiments, statements in the first program block are traversed along a first direction starting from the i-th functional instruction to determine functional instructions that have a serial dependency on the i-th functional instruction.

[0263] S802: Establish a serial synchronization path between the node of the i-th functional instruction and the nodes of the functional instructions that have serial dependencies with the i-th functional instruction in the first synchronization path graph.

[0264] For details, please refer to the detailed description of S501 to S502 above, which will not be elaborated here.

[0265] S803: Determine Q functional instructions that have data dependency on the i-th functional instruction.

[0266] In some embodiments, the statements in the first program block may be traversed along the first direction starting from the ith functional instruction to determine Q functional instructions that have data dependencies with the ith functional instruction, where Q is an integer. For details, please refer to the specific description of S503 above, which will not be repeated here.

[0267] It should be noted that the first program block is a branch structure. When Q=0 and i=n, ​​it means that the i-th functional instruction is the last functional instruction of the first program block, and no functional instruction that has data dependency with the i-th functional instruction has been determined. At this time, execute S806~S810.

[0268] When Q is greater than or equal to 1, it indicates that a functional instruction having data dependency with the i-th functional instruction has been determined, and S804 is executed.

[0269] S804 . Insert a synchronization instruction pair between the statement to which the i-th functional instruction belongs and the statement to which each of the P functional instructions belongs.

[0270] In a possible implementation manner, a synchronization instruction pair may be inserted between the i-th function instruction and each of the Q function instructions according to the first synchronization path diagram.

[0271] For example, the first synchronization path diagram can be queried to determine whether the path from the node of each functional instruction among Q functional instructions to the node of the i-th functional instruction is reachable, so as to determine P functional instructions among the Q functional instructions that have not established a synchronization relationship with the i-th functional instruction, where P is an integer, 0≤P≤Q.

[0272] For details, please refer to the detailed description of S504 above, which will not be elaborated here.

[0273] It should be noted that the first program block is a branch structure. When P = 0 and i = n, it means that the i-th functional instruction is the last functional instruction of the first program block, and there is no functional instruction among the Q functional instructions that has not established a synchronization relationship with the i-th functional instruction. At this time, S806 to S810 are executed.

[0274] S805. Establish an instruction synchronization path between the node of the i-th functional instruction and the nodes of each functional instruction among the P functional instructions in the first synchronization path diagram.

[0275] Add an instruction synchronization path from the node of each functional instruction among the P functional instructions to the node of the i-th functional instruction in the first synchronization path diagram.

[0276] Specifically, reference can be made to the specific description of S505 above, which will not be elaborated here.

[0277] In some embodiments, when i = n, it means that the i-th functional instruction is the last functional instruction of the first program block. At this time, S806 to S810 are executed.

[0278] In other embodiments, when i < n, it means that the i-th functional instruction is not the last functional instruction of the first program block. At this time, continue to traverse other statements of the first program block in the second direction, and establish synchronization between this statement and the statements in the first program block starting from this statement in the first direction. Specifically, refer to the detailed description of S801 to S805.

[0279] S806. Determine the functional instructions that have a serial dependency with the entry functional instruction in the first program block.

[0280] In some embodiments, starting from the branch statement, traverse the functional instructions before the branch statement in the first direction to determine the functional instructions that have a serial dependency with the entry functional instruction in the first program block. Two functional instructions with a serial dependency are executed serially by the same processing unit. If a functional instruction that has a serial dependency with the entry functional instruction in the first program block is traversed, S807 is executed.

[0281] In the present application, the entry functional instruction can refer to the entry functional instructions of different processing units.

[0282] For example, the entry functional instruction can refer to the instructions in the entry functional instruction set executed by the data access processing unit. Specifically, starting from the branch statement, traverse the functional instructions processed by the data access processing unit before the branch statement in the first direction.

[0283] For another example, the entry function instruction set may also refer to instructions in the entry function instruction set executed by the computing processing unit. Specifically, starting from the branch statement, the function instructions processed by the computing processing unit before the branch statement are traversed in the first direction.

[0284] S807: Establish a serial synchronization path between the node of the functional instruction that has a serial dependency on the entry functional instruction and the node of the entry functional instruction in the first synchronization path graph.

[0285] A serial synchronization path from a node of a functional instruction having a serial dependency on an entry functional instruction to a node of the entry functional instruction is added to the first synchronization path graph.

[0286] Specifically, for each non-empty processing unit entry function instruction in the branch statement, starting from the branch statement (excluding the branch statement), search along the first direction until the statement processed by the non-empty processing unit in the second program block, and the statement is a non-"branch structure". Then, for the traversed statements processed by each processing unit, establish a serial synchronization path from the exit function instruction set corresponding to the processing unit to the entry function instruction set corresponding to the processing unit in the branch statement.

[0287] S808 . Determine K functional instructions that have data dependencies on the i-th functional instruction.

[0288] In some embodiments, the functional instructions before the branch statement can be traversed along the first direction starting from the ith functional instruction to determine K functional instructions that have data dependencies with the ith functional instruction, where K is an integer. The K functional instructions that have data dependencies with the ith functional instruction are statements outside the first program block.

[0289] In particular, if K=0, it means that no functional instruction that has data dependency with the ith functional instruction has been determined. In this case, there is no need to perform the insertion operation of the synchronization instruction pair. For example, there are no other functional instructions before the branch statement along the first direction starting from the ith functional instruction, and of course, no functional instruction that has data dependency with the ith functional instruction has been determined. For another example, the statements arranged along the first direction starting from the ith functional instruction and the ith functional instruction are both executed by the same processing unit, indicating that the statements arranged along the first direction starting from the ith functional instruction have serial dependency with the ith functional instruction, and of course, no functional instruction that has data dependency with the ith functional instruction has been determined.

[0290] Optionally, since the first program block may also be nested in the second program block, the statements in the second program block traversed along the first direction starting from the ith functional instruction may include compound statements, so the traversed statement may be a functional instruction or a compound statement. After traversing the statements in the second program block along the first direction starting from the ith functional instruction, each statement in the traversed statements is analyzed with the ith functional instruction to determine whether there is data dependency between the traversed statements and the ith functional instruction, or to determine whether there is data dependency between the functional instructions in the traversed statements and the ith functional instruction, so as to determine the functional instructions that have data dependency with the ith functional instruction.

[0291] If there is a function instruction I1 in the traversed statement and there is a function instruction I2 in the current statement, a synchronization instruction pair has been inserted between the traversed statement and the current statement. A synchronization path is established in the first synchronization path diagram between the exit function instruction set of the processing unit corresponding to the function instruction I1 and the entry function instruction set of the processing unit corresponding to the function instruction I2.

[0292] In some embodiments, if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the i-th functional instruction.

[0293] For example, if there is a function instruction I1 in the traversed statement, there is a function instruction I2 in the current statement, and I1 and I2 meet the following conditions:

[0294] 1) Functional instruction I1 and functional instruction I2 are processed by different processing units;

[0295] 2) There is data dependency between functional instruction I1 and functional instruction I2;

[0296] 3) In the first synchronization path diagram, the path between the node of the functional instruction I1 and the node of the functional instruction I2 is unreachable;

[0297] It is necessary to insert a synchronization instruction pair between the traversed statement to which the functional instruction I1 belongs and the current statement to which the functional instruction I2 belongs. For the functional instructions I1 and I2 that need to be synchronized between the traversed statement and the current statement, a push instruction is inserted after the traversed statement and a pop instruction is inserted before the current statement.

[0298] For other specific explanations, please refer to the above description of S503 and will not be elaborated here.

[0299] When K is greater than or equal to 1, it indicates that a functional instruction having data dependency with the i-th functional instruction has been determined, and S809 is executed.

[0300] S809. Insert a synchronization instruction pair between the branch statement and the statement to which each of the L functional instructions belongs.

[0301] In a possible implementation, L functional instructions that have not established a synchronization relationship with the i-th functional instruction among the K functional instructions may be determined according to the first synchronization path diagram. L is an integer, 0≤L≤K.

[0302] In some embodiments, if the functional instruction that does not establish a synchronization relationship with the i-th functional instruction is not a statement in a compound statement, a push instruction is inserted after the functional instruction, and a pop instruction is inserted before the branch statement.

[0303] In other embodiments, if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the branch statement.

[0304] For other specific explanations, please refer to the above description of S504 and will not be elaborated here.

[0305] When L is greater than or equal to 1, it indicates that there is a function instruction among the K function instructions that has not established a synchronization relationship with the i-th function instruction, and S810 is executed.

[0306] S810: Establish an instruction synchronization path of a node of the i-th functional instruction and a node of each functional instruction in the L functional instructions in a first synchronization path graph.

[0307] In the first synchronization path graph, an instruction synchronization path from the nodes of the L functional instructions to the node of the i-th functional instruction is added.

[0308] The above S806 to S810 describe the process of establishing synchronization between the statements in the branch statement and the statements before the branch statement.

[0309] In particular, in some embodiments, the first program block may be a separate program block, not nested in other program blocks. In this case, S806 and S808 may be executed as usual, but no functional instructions that are serially dependent on the entry functional instructions in the first program block are traversed, and no functional instructions that are data dependent on the functional instructions in the first program block are traversed. At this time, there is no need to execute S807, S809-S810.

[0310] In other embodiments, the first program block may be a nested structure, where the first program block is nested in the second program block. Other statements in the second program block are included before the first program block, and synchronization is established for other statements in the second program block. For details, please refer to the detailed description of S806 to S810 above, which will not be repeated here. However, other statements in the second program block are not included after the first program block, which indicates that the second program block has been executed, and after executing S810, no other steps need to be executed.

[0311] In other embodiments, if the first program block is a nested structure, the first program block is nested in the second program block, but other statements in the second program block are also included after the first program block. In this case, it indicates that the second program block has not been executed. After executing S810, it is necessary to traverse the statements before other statements in the second program block along the first direction for other statements in the second program block to determine the functional instructions that have data dependencies and serial dependencies with other functional instructions in the second program block. For details, please refer to the detailed description of S501 to S505 above, which will not be repeated here. It should be noted that if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the current statement.

[0312] In particular, in the first synchronization path diagram, when the nodes connecting two functional instructions of any path are located in a branch statement and outside a branch statement respectively, the path can be called a branch path. A branch path is a special synchronization path. Among them, when the source node of the branch path is located outside the branch statement, the branch path can be called a branch entry path. When the source node of the branch path is located in the branch statement, the branch path can be called a branch exit path.

[0313] For any two nodes N in the first synchronization path graph s 、N e , if there are m sequentially connected synchronization paths: (N s ,N1), (N1,N2), (N2,N3),…(N m-1 ,N e ), and the m synchronization paths meet one of the following conditions, then the path from Ns to Ne is considered reachable:

[0314] 1) None of the m synchronization paths are branch paths;

[0315] 2) There are n branch paths in the m synchronization paths: (P1, P2), (P3, P4), ... (P 2*n-1 ,P 2*n ). For any branch into the path (Ps ,P s+1 ), if there is a corresponding branch exit path (P r ,P r+1 ), and P s-1 (If s is 1, then take N s ) and P r+2 (If r is 2*n-1, then take N e ) meets the following conditions:

[0316] If (P s ,P s+ 1) and (P r ,P r+1 ) corresponds to a branch with an else branch structure, then from P s-1 There are at least two different paths that can reach P through then and else respectively. r+2 ; If the corresponding branch has no else branch structure, then from P s-1 There are at least two paths from the start to P that can reach P through then and not through then. r+1 .

[0317] For example, the following program with nested branch structure is shown:

[0318]

[0319] Assuming that there are synchronization paths from S1 to S7, the corresponding first synchronization path diagram is as follows: Fig. 9 As shown, if the node "S1" is outside the branch statement if(c1)) and the node "S2" is inside the branch statement if(c)), then the path from the node "S1" to the node "S2" is the branch entry path.

[0320] Node "S4" is outside the branch statement if(c2)) and node "S5" is inside the branch statement if(c2)) then the path from node "S4" to node "S5" is the branch entry path.

[0321] Node "S4" is outside the branch statement else(c2)) and node "S6" is inside the branch statement else(c2)) then the path from node "S4" to node "S6" is the branch entry path.

[0322] Node "S5" is inside the branch statement if(c2)) and node "S7" is outside the branch statement if(c2)) then the path from node "S5" to node "S7" is the branch exit path.

[0323] Node "S6" is inside the branch statement else(c2)) and node "S7" is outside the branch statement else(c2)) then the path from node "S6" to node "S7" is the branch exit path.

[0324] For example, there are two connected paths (S2, S3) and (S3, S4) between node "S2" and node "S4", and neither of these two paths is a branch path. Therefore, the path from node "S2" to node "S4" is reachable.

[0325] For another example, there are four connected paths (S1, S2), (S2, S3), (S3, S4), and (S4, S5) between node "S1" and node "S5". Although (S1, S2) and (S4, S5) are both branch paths, the branch entry path (S1, S2) does not have a corresponding branch exit path (i.e., it passes through the same branch if (c1) as (S1, S2); the branch entry path (S4, S5) does not have a corresponding branch exit path. Therefore, the path from node "S1" to node "S5" is reachable.

[0326] For another example, there are three connected paths (S3, S4), (S4, S5) and (S5, S7) between node "S3" and node "S7". Among them, there are two branch paths (S4, S5) and (S5, S7). If (c2) branches into the path (S4, S5), there is a corresponding branch exit path (S5, S7). And node "S3" (corresponding to Ps-1) and node "S7" (corresponding to Pr+2) meet the following conditions: starting from node "S3", there is also a path (S3, S4), (S4, S6) and (S6, S7), and this path crosses else (c2). Therefore, the path from node "S3" to node "S7" is reachable.

[0327] For another example, although there are 5 connected paths (S1, S2), (S2, S3), (S3, S4), (S4, S5) and (S5, S7) between node "S1" and node "S7", there are branch entry paths (S1, S2) and (S4, S5) and corresponding branch exit paths (S5, S7). And there is no path that does not cross if (c1) between node "S1" and node "S7". Therefore, the synchronization path from node "S1" to node "S7" is unreachable.

[0328] Combine the following Fig.10 and Fig.11 The process of inserting a synchronization instruction pair into a program with a nested branch structure is illustrated as follows. As shown below, the program with a nested branch structure includes 4 statements (S1 to S4), and statements S2 and S3 are in the branch body.

[0329]

[0330] Among them, statements S1 and S4 are processed by the data access processing unit. Statements S2 and S3 are processed by the computing processing unit. Statements S1 and S4 have serial dependencies. Data dependencies include: statement S2 depends on statement S1, statement S3 depends on statement S1, and statement S4 depends on statement S2 and statement S3.

[0331] 1. Convert the program with nested branch structure into an abstract syntax tree, such as Fig.10 As shown in (a) in the figure, node "block1" and node "if" are parent nodes, and node "S1", node "if", and node "S4" are child nodes of node "block1" respectively. Node "block(then)" is the child node of node "if". Node "block(else)" is the child node of node "if". Node "block(then)" and node "block(else)" are parent nodes. Node "S2" is the child node of node "block(then)". Node "S3" is the child node of node "block(else)".

[0332] 2. Traverse and process the nodes in block 1 in sequence, and execute the process of inserting synchronization instruction pairs.

[0333] Node "S1": Add node "S1" to the first synchronization path graph. Since statement S1 is the first statement in block1, there are no statements in block1 that can be traversed along the first direction starting from statement S1. Of course, no functional instructions that have a serial dependency on statement S1 have been determined, so there is no need to add a serial synchronization path for node "S1". It can be understood that statement S1 is an instruction in the entry functional instruction set of the data access processing unit. Similarly, no functional instructions that have a data dependency on statement S1 have been determined, and there is no need to insert a synchronization instruction pair, and there is no need to add an instruction synchronization path for node "S1". The abstract syntax tree remains Fig.10 As shown in (a) in the figure, no change is required. The change of the first synchronization path diagram is as follows Fig.11 As shown in (a) in .

[0334] Node "if": The branch statement nests block(then) and block(else). Block(then) includes a statement S2, and block(else) includes a statement S3, which inserts a synchronization instruction pair into block(then) and block(else) respectively.

[0335] Node "S2": Add node "S2" to the first synchronization path graph. Starting from statement S2, traverse the statements in block (then) along the first direction. No statement with serial dependency on statement S2 is determined, so there is no need to add the serial synchronization path of node "S2". Starting from statement S2, traverse the statements in block (then) along the first direction. No statement with data dependency on statement S2 is determined. There is no need to insert a synchronization instruction pair, so there is no need to add the instruction synchronization path of node "S2". The abstract syntax tree remains Fig.10 As shown in (a) in the figure, no changes are required. The first synchronization path diagram is Fig.11 The change of (a) in Fig.11 (b) in .

[0336] Node "S3": Add node "S3" to the first synchronization path graph. Starting from statement S3, traverse the statements in block (else) along the first direction. No statement with serial dependency on statement S3 is determined, so there is no need to add the serial synchronization path of node "S3". Starting from statement S3, traverse the statements in block (else) along the first direction. No statement with data dependency on statement S3 is determined. There is no need to insert a synchronization instruction pair, so there is no need to add the instruction synchronization path of node "S3". The abstract syntax tree remains Fig.10 As shown in (a) in the figure, no changes are required. The first synchronization path diagram is Fig.11 (b) in the equation changes to Fig.11 (c) in .

[0337] Since all statements included in the branch statement are processed by the computing processing unit, the entry function instruction set and the exit function instruction set of the computing processing unit are both [S2, S3]. There is no function instruction corresponding to the computing processing unit before the branch statement, so there is no need to establish a serial synchronization path between the statements in the block (then) and the statements in the block (else).

[0338] In addition, according to the above S806-S810, it can be determined that statements S2 and S3 in the branch statement depend on statement S1, so a synchronization instruction pair is added between statement S1 and the branch statement, that is, push(A,E) is inserted after statement S1, and pop(A,E) is inserted before the branch statement. And an instruction synchronization path is established between statement S1 and the entry function instruction set [S2,S3] of the branch statement. The abstract syntax tree is composed of Fig.10 The change of (a) in Fig.10 (b) in the first synchronization path diagram. Fig.11 The change of (c) in Fig.11 (d) in.

[0339] Node "S4": Add node "S4" to the first synchronization path graph. Starting from statement S4, traverse the statements in block1 along the first direction to determine statement S1 that has a serial dependency with statement S4. Add a serial synchronization path from node "S1" to node "S4" in the first synchronization path graph. Starting from statement S4, traverse the statements in block1 along the first direction to determine statements S2 and S3 that have data dependencies with statement S4, and query the first synchronization path graph to determine that the path from node "S3" to node "S4" is unreachable, and the path from node "S2" to node "S4" is unreachable, insert a synchronization instruction pair between statement S4 and the branch statement, that is, establish a synchronization relationship between the exit function instruction set [S2, S3] of the branch statement and statement S4, insert push (E, A) after the end of the branch body included in the branch statement, and insert pop (E, A) before statement S4. Add the instruction synchronization path from node "S2" to node "S4" and the instruction synchronization path from node "S3" to node "S4" in the first synchronization path graph. The abstract syntax tree is composed of Fig.10 (b) in the equation changes to Fig.10 (c) in the first synchronization path diagram. Fig.11 The change of (d) in Fig.11 (e) in .

[0340] 3. Convert the abstract syntax tree of the inserted synchronization instruction pair into a program of the nested branch structure after the inserted synchronization instruction pair. The program of the nested branch structure after the inserted synchronization instruction pair is as follows:

[0341]

[0342]

[0343] In a third possible design, the first program block may be a structure of a compound statement. If the compound statement is a loop statement (for), the n statements may be statements in the loop body, and the n statements may all be single functional instructions. The difference from the first possible design described above is that after establishing synchronization for the statements in the loop structure, it is also necessary to perform a reverse traversal of the n statements in the first program block, insert a pair of synchronization instructions between the statements in the loop body, establish reverse synchronization, and configure paired synchronization instructions. In addition, it is also necessary to establish synchronization between the statements in the first program block and the statements outside the first program block. For details, refer to the following description of the relevant embodiments.

[0344] Fig.12 A flowchart of a method for inserting a synchronization instruction provided in an embodiment of the present application is shown in FIG. Fig.12 As shown, the method may include:

[0345] S1201 , determining a functional instruction that has a serial dependency on the i th functional instruction.

[0346] In some embodiments, statements in the first program block are traversed along a first direction starting from the i-th functional instruction to determine functional instructions that have a serial dependency on the i-th functional instruction.

[0347] S1202: Establish a serial synchronization path between the node of the ith functional instruction and the nodes of the functional instructions that have serial dependencies with the ith functional instruction in the first synchronization path graph.

[0348] For details, please refer to the detailed description of S501 to S502 above, which will not be elaborated here.

[0349] S1203 . Determine Q functional instructions that have data dependencies on the i-th functional instruction.

[0350] In some embodiments, the statements in the first program block may be traversed along the first direction starting from the ith functional instruction to determine Q functional instructions that have data dependencies with the ith functional instruction, where Q is an integer. For details, please refer to the specific description of S503 above, which will not be repeated here.

[0351] It should be noted that the first program block is a loop structure. When Q=0 and i=n, ​​it means that the i-th functional instruction is the last functional instruction of the first program block, and no functional instruction that has data dependency with the i-th functional instruction has been determined. At this time, execute S1206~S1219.

[0352] When Q is greater than or equal to 1, it indicates that a functional instruction having data dependency with the i-th functional instruction has been determined, and S1204 is executed.

[0353] S1204 . Insert a synchronization instruction pair between the statement to which the i-th functional instruction belongs and the statement to which each of the P functional instructions belongs.

[0354] In a possible implementation manner, a synchronization instruction pair may be inserted between the i-th function instruction and each of the Q function instructions according to the first synchronization path diagram.

[0355] For example, the first synchronization path diagram can be queried to determine whether the path from the node of each functional instruction among Q functional instructions to the node of the i-th functional instruction is reachable, so as to determine P functional instructions among the Q functional instructions that have not established a synchronization relationship with the i-th functional instruction, where P is an integer, 0≤P≤Q.

[0356] For details, please refer to the detailed description of S504 above, which will not be elaborated here.

[0357] It should be noted that the first program block is a loop structure. When P = 0 and i = n, it means that the i-th functional instruction is the last functional instruction of the first program block, and there is no functional instruction among the Q functional instructions that has not established a synchronization relationship with the i-th functional instruction. At this time, S1206 to S1219 are executed.

[0358] S1205. Establish an instruction synchronization path between the node of the i-th functional instruction and the nodes of each functional instruction among the P functional instructions in the first synchronization path diagram.

[0359] Add an instruction synchronization path from the node of each functional instruction among the P functional instructions to the node of the i-th functional instruction in the first synchronization path diagram.

[0360] Specifically, reference can be made to the specific description of S505 above, which will not be elaborated here.

[0361] In some embodiments, when i = n, it means that the i-th functional instruction is the last functional instruction of the first program block. At this time, S1206 to S1219 are executed.

[0362] In other embodiments, when i < n, it means that the i-th functional instruction is not the last functional instruction of the first program block. At this time, continue to traverse other statements of the first program block in the second direction, and establish synchronization between this statement and the statements in the first program block starting from this statement in the first direction. Specifically, reference can be made to the detailed description of S1201 to S1205.

[0363] After executing S1201 to S1205 on the n statements, it is also necessary to perform a reverse traversal on the n statements in the first program block, insert synchronization instruction pairs between the statements in the loop body, and establish reverse synchronization. Specifically, it is described as follows.

[0364] Since the first synchronization path diagram is a directed acyclic graph, in order to avoid loops, the present application provides a second synchronization path diagram. The second synchronization path diagram is a directed dependency graph that is dynamically maintained and used to express the directed dependency relationship between the functional instructions for which reverse synchronization has been established. The second synchronization path diagram can be called a nested structure local reverse synchronization path diagram. It can also be understood that the second synchronization path diagram is the reverse synchronization path diagram of the nodes of the statements in the first program block. The second synchronization path diagram is used for the reverse synchronization process of the current program block. The nodes of the graph represent functional instructions, and the edges between the nodes represent synchronization paths. The synchronization paths include serial synchronization paths and instruction synchronization paths.

[0365] The so-called serial synchronization path can refer to the serial synchronization path between the last functional instruction (i.e., the exit functional instruction set) and the first functional instruction (i.e., the entry functional instruction set) processed by the same processing unit in the first program block.

[0366] The so-called instruction synchronization path may refer to any two statements S1 and S2 in the first program block, and statement S1 is located before statement S2 (or statement S1 is equal to statement S2). If instruction synchronization is established from the processing unit D2 of statement S2 to the processing unit D1 of statement S1, then a synchronization path needs to be established from the exit function instruction set of statement S2 in D2 to the entry function instruction set of statement S1 in D1.

[0367] When the second synchronization path map is used for the first time, the second synchronization path map needs to be initialized first. Execute S1206.

[0368] S1206: Establish a serial synchronization path from the exit function instruction set of each non-empty processing unit of the loop body to the entry function instruction set of the corresponding processing unit in the second synchronization path graph. Execute S1207.

[0369] For example, a serial synchronization path is established from the exit function instruction set of the data access processing unit of the loop body to the entry function instruction set of the data access processing unit.

[0370] For another example, a serial synchronization path is established from the exit function instruction set of the computing processing unit of the loop body to the entry function instruction set of the computing processing unit.

[0371] Assume that there are two sequential statements S1 and S2 in the first program block, and statement S1 is before statement S2. If the functional instruction I2 in statement S2 and the functional instruction I1 in statement S1 meet the following conditions: in the second synchronization path graph, there is a reachable path (N1->N2), so that (I2,N1) and (N2,I1) are both reachable, then the reverse path from functional instruction I2 to functional instruction I1 is considered reachable.

[0372] S1207 . Determine E functional instructions that have data dependencies on the i-th functional instruction.

[0373] In some embodiments, statements in the first program block are traversed along a first direction starting from the last functional instruction in the first program block to the ith functional instruction, and E functional instructions having data dependency on the ith functional instruction are determined, where E is an integer.

[0374] In particular, if E=0, it means that no functional instruction having data dependency with the i-th functional instruction has been determined. In this case, there is no need to perform the insertion operation of the reverse synchronization instruction pair.

[0375] Optionally, if the first direction is the sequential arrangement direction of the statements included in the first program block, the statements in the first program block can be traversed along the first direction starting from the first functional instruction in the first program block to the i-th functional instruction, and E functional instructions that have data dependencies on the i-th functional instruction can be determined.

[0376] It should be noted that the first program block is a loop structure. When E=0 and i=n, ​​it means that the i-th functional instruction is the last functional instruction of the first program block, and no functional instruction that has data dependency with the i-th functional instruction has been determined. At this time, execute S1210~S1219.

[0377] When E is greater than or equal to 1, it indicates that a functional instruction having data dependency with the i-th functional instruction has been determined, and S1208 is executed.

[0378] S1208. Insert a synchronization instruction pair between the statement to which the i-th functional instruction belongs and the statement to which each of the F functional instructions belongs.

[0379] In some embodiments, when inserting a synchronization instruction pair, the F functional instructions among the E functional instructions that have not established a synchronization relationship with the i-th functional instruction are determined according to the second synchronization path diagram and the first synchronization path diagram, where F is an integer, 0≤F≤E. Specifically, the second synchronization path diagram and the first synchronization path diagram can be queried to determine whether the path from the node of each functional instruction among the E functional instructions to the node of the i-th functional instruction is reachable, so as to determine the functional instructions among the E functional instructions that have not established a synchronization relationship with the i-th functional instruction. For other specific explanations, please refer to the above description of S504, which will not be repeated here.

[0380] For example, assuming that statements S1, S2, and S3 are arranged in order, it is necessary to establish a reverse synchronization path from statement S2 to statement S1. The first synchronization path graph is queried to obtain that the node path from statement S2 to the node of statement S3 is reachable, and the second synchronization path graph is queried to obtain that the reverse path from the node of statement S3 to the node of statement S1 is reachable. At this time, it can be determined that the reverse synchronization path from the node of statement S2 to the node of statement S1 is reachable, and a reverse synchronization relationship has been established between statement S2 and statement S1.

[0381] Specifically, a push instruction is inserted after a functional instruction that has data dependency with the i-th functional instruction, and a pop instruction is inserted before the i-th functional instruction.

[0382] For example, if there is a function instruction I1 in the traversed statement, there is a function instruction I2 in the current statement, and I1 and I2 meet the following conditions:

[0383] 1) Functional instruction I1 and functional instruction I2 are processed by different processing units;

[0384] 2) There is data dependency between functional instruction I1 and functional instruction I2;

[0385] 3) In the second synchronization path diagram, the path between the node of the functional instruction I1 and the node of the functional instruction I2 is unreachable;

[0386] It is necessary to insert a synchronization instruction pair between the traversed statement to which the functional instruction I1 belongs and the current statement to which the functional instruction I2 belongs. For the functional instructions I1 and I2 that need to be reversely synchronized between the traversed statement and the current statement, a push instruction is inserted after the traversed statement and a pop instruction is inserted before the current statement.

[0387] When F is greater than or equal to 1, it indicates that there is a function instruction among the E function instructions that has not established a synchronization relationship with the i-th function instruction, and S1209 is executed.

[0388] S1209: Establish an instruction synchronization path of the nodes of F functional instructions and the node of the i-th functional instruction in the second synchronization path graph.

[0389] In the second synchronization path diagram, add an instruction synchronization path from the nodes of F functional instructions to the node of the i-th functional instruction. In some embodiments, a synchronization path is established from the exit functional instruction set of the processing unit corresponding to the functional instruction I1 of the statement to be synchronized to the entry functional instruction set corresponding to the processing unit of the i-th functional instruction in the functional instruction I2.

[0390] Furthermore, after synchronization is established for the statements in the first program block, it is also necessary to synchronize the statements in the loop statement with the statements before the loop statement.

[0391] S1210: Determine a functional instruction that has a serial dependency on an entry functional instruction in the first program block.

[0392] In some embodiments, starting from the loop statement, the functional instructions before the loop statement are traversed in the first direction to determine the functional instructions that have a serial dependency with the entry functional instruction in the first program block. The two functional instructions with a serial dependency are executed in a serial manner by the same processing unit. If a functional instruction that has a serial dependency with the entry functional instruction in the first program block is traversed, S1211 is executed.

[0393] For other specific explanations, please refer to the above description of S806 and will not be elaborated here.

[0394] S1211. Establish, in the first synchronization path graph, a serial synchronization path between nodes of functional instructions that are serially dependent on the entry functional instruction and nodes of the entry functional instruction.

[0395] A serial synchronization path from a node of a functional instruction having a serial dependency on an entry functional instruction to a node of the entry functional instruction is added to the first synchronization path graph.

[0396] For the specific explanation of S1211, please refer to the above description of S807, which will not be elaborated here.

[0397] Furthermore, it is also necessary to pair the synchronization instructions that meet the conditions, that is, insert the pairing synchronization instructions and establish the corresponding instruction synchronization path in the first synchronization path diagram. The pairing synchronization instructions include push pairing synchronization instructions and pop pairing synchronization instructions.

[0398] The push pair synchronization instruction means that the corresponding push instruction needs to be inserted before the loop statement.

[0399] The pop pairing synchronization instruction means that the corresponding pop instruction needs to be inserted after the loop statement.

[0400] The pairing synchronization instruction can be generated during the block processing of the loop structure, and then the corresponding synchronization instruction is inserted into the outer block (parent block). Specifically, as described in the following S1215.

[0401] S1212: Insert a first pairing synchronization instruction after a functional instruction that has data dependency with the i-th functional instruction, or insert a first pairing synchronization instruction after a functional instruction that has been synchronized with the i-th functional instruction.

[0402] In some embodiments, assuming that a pop instruction is inserted before the ith functional instruction, starting from the loop statement, traversing the statements before the loop statement along the first direction, if a functional instruction with data dependency on the ith functional instruction is traversed, or a functional instruction that is synchronized with the ith functional instruction is traversed, a push pairing synchronization instruction is inserted after the functional instruction with data dependency, or a push pairing synchronization instruction is inserted after the synchronized functional instruction. The first pairing synchronization instruction may refer to a push pairing synchronization instruction.

[0403] For example, assuming that the statement after the pop instruction is S2, there is a functional instruction I1 in statement S2, and the processing unit that processes statement S2 is D1, and starting from statement S2, traverse the statements before statement S2 along the first direction. If traversing to statement S1, there is a functional instruction I2 in statement S1, and the processing unit that processes statement S1 is D2, and one of the following conditions is met, it is considered that it is suitable to insert a push pairing synchronization instruction after statement S1.

[0404] 1) There is data dependency between functional instruction I1 and functional instruction I2, indicating that a corresponding instruction synchronization path will be established from statement S1 to statement S2;

[0405] 2) In the first synchronization path diagram, the path between the node of functional instruction I1 and the node of functional instruction I2 is reachable, indicating that synchronization has been established from statement S1 to statement S2, so inserting a push pair synchronization instruction will not introduce additional parallel overhead.

[0406] Then, in the first synchronization path graph, an instruction synchronization path is established from the exit function instruction set of statement S1 in the processing unit D2 to the entry function instruction set of statement S2 in the processing unit D1.

[0407] Optionally, assuming that a push instruction is inserted after the ith functional instruction, for the statement after the ith functional instruction, if there is a functional instruction that has data dependency with the ith functional instruction, or a functional instruction that has been synchronized with the ith functional instruction, a pop pairing synchronization instruction is inserted after the functional instruction with data dependency, or a pop pairing synchronization instruction is inserted after the synchronized functional instruction. The second pairing synchronization instruction may refer to a pop pairing synchronization instruction.

[0408] It should be noted that the pairing synchronization instruction and the synchronization instruction to be paired have the same source processing unit and destination processing unit.

[0409] For example, assume that the statement before the push instruction is S3, there is a functional instruction I1 in statement S3, and the processing unit for processing statement S3 is D1. If statement S4 is traversed, there is a functional instruction I2 in statement S4, and the processing unit for processing statement S4 is D2, and one of the following conditions is met, it is considered that it is suitable to insert a pop pairing synchronization instruction before statement S4.

[0410] 1) There is data dependency between functional instruction I1 and functional instruction I2, indicating that statement S3 to statement S4 will establish a corresponding instruction synchronization path;

[0411] 2) In the first synchronization path diagram, the path between the node of functional instruction I1 and the node of functional instruction I2 is reachable, indicating that synchronization has been established from statement S3 to statement S4, so inserting the pop pairing synchronization instruction will not introduce additional parallel overhead.

[0412] Then, in the first synchronization path graph, an instruction synchronization path is established from the exit functional instruction set of statement S3 in the processing unit D2 to the entry functional instruction set of statement S4 in the processing unit D1.

[0413] Compared with the conventional technique of directly inserting the pairing synchronization instruction before and after the loop statement, the method of inserting the pairing synchronization instruction provided by the present application can stretch the pairing synchronization instruction as far forward or as far backward as possible before and after the loop statement. Thus, the pairing synchronization instruction is avoided from introducing unnecessary synchronization between functional instructions. Thus, by stretching the pairing synchronization instruction, the parallelism between functional instructions is further improved.

[0414] For example, as shown in the following program, statements S1 and S2 have no dependency, but statements S2 and S3 have data dependency. When the traditional technology is used to insert the pairing synchronization instruction, when the loop body is first iterated, statements S1 and S2 are additionally introduced into the synchronization dependency due to the push pairing synchronization instruction from statement S3 to statement S2, that is, push(E,A) is inserted after statement S1.

[0415] y=0 / / S1

[0416] push(E,A) / / Existing push pairing

[0417] for(inner,...){

[0418] pop(E,A)

[0419] x=load(0x100) / / S2

[0420] push(A,E)

[0421] pop(A,E)

[0422] x=x+1 / / S3

[0423] push(E,A)

[0424] }

[0425] pop(E,A) / / pop pairing

[0426] The method for inserting a pairing synchronization instruction provided by the present application extends the push pairing synchronization instruction forward to before statement S1, so that the redundant synchronization dependency between statement S1 and statement S2 is eliminated. As shown in the following program:

[0427] push(E,A) / / push pairing after stretching

[0428] y=0 / / S1

[0429] for(inner,...){

[0430] pop(E,A)

[0431] x=load(0x100) / / S2

[0432] push(A,E)

[0433] pop(A,E)

[0434] x=x+1 / / S3

[0435] push(E,A)

[0436] }

[0437] pop(E,A) / / pop pairing

[0438] S1213. Determine K functional instructions that have data dependencies on the i-th functional instruction.

[0439] In some embodiments, the functional instructions before the loop statement can be traversed along the first direction starting from the ith functional instruction to determine K functional instructions that have data dependency on the ith functional instruction, where K is an integer. The K functional instructions that have data dependency on the ith functional instruction are statements outside the first program block.

[0440] In particular, if K=0, it means that no functional instruction that has data dependency with the ith functional instruction has been determined. In this case, there is no need to perform the insertion operation of the synchronization instruction pair. For example, there are no other functional instructions before the loop statement along the first direction starting from the ith functional instruction, and of course no functional instruction that has data dependency with the ith functional instruction has been determined. For another example, the statements arranged along the first direction starting from the ith functional instruction and the ith functional instruction are both executed by the same processing unit, indicating that the statements arranged along the first direction starting from the ith functional instruction have serial dependency with the ith functional instruction, and of course no functional instruction that has data dependency with the ith functional instruction has been determined.

[0441] For other specific explanations, please refer to the above description of S503 and will not be elaborated here.

[0442] When K is greater than or equal to 1, it indicates that a functional instruction having data dependency with the i-th functional instruction has been determined, and S1214 is executed.

[0443] S1214. Insert a synchronization instruction pair between the loop statement and the statement to which each of the L functional instructions belongs.

[0444] In a possible implementation, L functional instructions that have not established a synchronization relationship with the i-th functional instruction among the K functional instructions may be determined according to the first synchronization path diagram. L is an integer, 0≤L≤K.

[0445] In some embodiments, if the functional instruction that does not establish a synchronization relationship with the i-th functional instruction is not a statement in a compound statement, a push instruction is inserted after the functional instruction, and a pop instruction is inserted before the loop statement.

[0446] In other embodiments, if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the loop statement.

[0447] For other specific explanations, please refer to the above description of S504 and will not be elaborated here.

[0448] When L is greater than or equal to 1, it indicates that there is a function instruction among the K function instructions that has not established a synchronization relationship with the i-th function instruction, and S1215 is executed.

[0449] S1215 . Establish an instruction synchronization path of a node of the i-th functional instruction and a node of each functional instruction in the L functional instructions in the first synchronization path graph.

[0450] In the first synchronization path graph, an instruction synchronization path from the nodes of the L functional instructions to the node of the i-th functional instruction is added.

[0451] In a multi-layer loop scenario, the traditional technology is to directly insert the pairing synchronization instruction of the inner loop before and after the inner loop statement, then the pairing synchronization instruction will be executed multiple times with the outer loop, and may even cause a reduction in parallelism. The method of inserting synchronization instructions provided in the present application can externalize the pairing synchronization instructions that have not yet been inserted into the synchronization instruction, and by externalizing the pairing synchronization instructions, the execution of the pairing synchronization instructions is reduced. Therefore, by externalizing the pairing synchronization instructions, the parallelism between functional instructions is further improved.

[0452] If the first pairing synchronization instruction and the second pairing synchronization instruction are a synchronization instruction pair, the first pairing synchronization instruction and the second pairing synchronization instruction pair can be marked as being externalized. If the first program block is nested in other loop statements, the first pairing synchronization instruction and the second pairing synchronization instruction can also be externalized. The method also includes the following steps.

[0453] S1216: Pair the first pairing synchronization instruction with the second pairing synchronization instruction.

[0454] If there are a push pair synchronization instruction and a pop pair synchronization instruction with the same synchronized processing unit and the same synchronizing processing unit, both are marked as external.

[0455] S1217: Extract the first pairing synchronization instruction and the second pairing synchronization instruction.

[0456] If the first program block is a nested structure in a multi-layer loop, the first pairing synchronization instruction and the second pairing synchronization instruction are extracted. It should be noted that when extracting, the push pairing synchronization instruction and the pop pairing synchronization instruction need to be extracted.

[0457] As shown in the following multi-layer loop, the paired synchronization instructions are advanced from statement S3 to statement S1. Since push(E,A) and pop(E,A) after statement S3 are paired, synchronization is established between statement S3 and statement S1.

[0458]

[0459] After the pair synchronization instruction is promoted from the block where the initial m loop is located to the block where the n loop is located, statements S3 and S1 can be executed in parallel. The following program is shown:

[0460]

[0461]

[0462] Optionally, if there are no other statements after the loop statement, there is no need to establish synchronization of the functional instructions. If other statements are included after the loop statement, the synchronization of the functional instructions is also established according to the description of S501 to S505, which will not be repeated here. It should be noted that if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the statement to which the i-th functional instruction belongs.

[0463] In addition, for all remaining synchronization instructions in the first program block that have not yet been paired, that is, the functional instructions that have data dependencies with the functional instructions into which the synchronization instructions are inserted have not been traversed, or the functional instructions that have been synchronized with the functional instructions into which the synchronization instructions are inserted have not been traversed, the present application also includes the following steps. Assume that the first program block is nested in the second program block.

[0464] S1218, inserting a first pairing synchronization instruction before the first statement in the second program block; or / and,

[0465] It can be understood that the first pairing synchronization instruction is inserted before the first statement in the outermost program block.

[0466] S1219. Insert a second pairing synchronization instruction after the last statement in the second program block.

[0467] It can be understood that the second pairing synchronization instruction is inserted after the last statement in the outermost program block.

[0468] The method for inserting synchronization instructions provided by the present application automatically inserts synchronization instruction pairs between functional instructions that have not established a synchronization relationship based on data dependency between functional instructions and a synchronization path graph, establishes synchronization between functional instructions with data dependency, and can effectively improve the parallelism between functional instructions, thereby improving the processing performance of DAE or DAE-like processors in processing functional instructions. Among them, inserting synchronization instruction pairs based on data dependency between functional instructions significantly reduces indirect synchronization between functional instructions; and inserting synchronization instruction pairs based on the synchronization path graph significantly reduces the insertion of redundant synchronization instruction pairs based on data dependency between functional instructions.

[0469] In particular, in some embodiments, the first program block may be a separate program block, not nested in other program blocks. In this case, S1210 and S1213 may be performed as usual, but no functional instructions having serial dependencies with the entry functional instructions in the first program block are traversed, and no functional instructions having data dependencies with the functional instructions in the first program block are traversed.

[0470] In some other embodiments, the first program block may be a nested structure, where the first program block is nested in the second program block. Other statements in the second program block are also included before the first program block, and synchronization is established for other statements in the second program block. For details, please refer to the detailed description of S501 to S506 above, which will not be repeated here. However, other statements in the second program block are not included after the first program block, which indicates that the second program block has been executed.

[0471] In other embodiments, if the first program block is a nested structure, the first program block is nested in the second program block, but other statements in the second program block are also included after the first program block. In this case, it indicates that the second program block has not been executed. After executing S1219, it is necessary to traverse the statements before other statements in the second program block along the first direction for other statements in the second program block, determine the functional instructions that have data dependencies and serial dependencies with other statements in the second program block, and then establish synchronization with other statements in the second program block. For details, please refer to the detailed description of S501 to S505 above, which will not be repeated here. It should be noted that if the functional instruction that has not established a synchronization relationship with the i-th functional instruction is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the current statement.

[0472] In addition, in the conventional technology, programmers can also manually insert synchronization instructions into the program, but this has problems such as dependence on the programmer's skills and complexity. The difference of the method for inserting synchronization instructions provided by the present application is that by automatically inserting synchronization instruction pairs, the insertion of synchronization instruction pairs is made more universal, and the complexity of inserting synchronization instruction pairs is completely shielded from the programmer.

[0473] Combine the following Fig.13 and Fig.14 The following example illustrates the process of inserting a synchronization instruction pair into a program with a nested loop structure. As shown below, the program with a nested loop structure includes four statements (S1 to S4). Statements S2 and S3 are within the loop body. The loop statement for(i) nests the loop statement for(j).

[0474]

[0475] Among them, statements S2 and S4 are processed by the data access processing unit. Statements S1 and S3 are processed by the computing processing unit. Statements S2 and S4 have a serial dependency. Statements S1 and S3 have a serial dependency. Data dependencies include: statement S3 depends on statement S1 and statement S2, and statement S4 depends on statement S1 and statement S3.

[0476] 1. Convert the program with nested loop structure into an abstract syntax tree, such as Fig.13 As shown in (a) in the figure, node "block1" is the parent node, and node "S1", node "for(i)" and node "S4" are the child nodes of node "block1" respectively. Node "for(i)" is the parent node, and block2 is nested in it. Node "block2" is the child node of node "for(i)". Node "for(j)" is the child node of node "block2". Node "for(j)" is the parent node. Nodes "S2" and "S3" are the child nodes of node "for(j)".

[0477] 2. Traverse and process the nodes in block 1 in sequence, and execute the process of inserting synchronization instruction pairs.

[0478] Node "S1": Add node "S1" to the first synchronization path graph. Since statement S1 is the first statement in block1, there are no statements in block1 that can be traversed along the first direction starting from statement S1. Of course, no functional instructions that have a serial dependency on statement S1 have been determined, so there is no need to add a serial synchronization path for node "S1". Similarly, no functional instructions that have a data dependency on statement S1 have been determined, so there is no need to insert a synchronization instruction pair, and there is no need to add an instruction synchronization path for node "S1". The abstract syntax tree remains Fig.13 As shown in (a) in the figure, no change is required. The change of the first synchronization path diagram is as follows Fig.14 As shown in (a) in .

[0479] Node "for(i)": The loop statement for(i) is a loop structure. The loop body block2 of for(i) is recursively processed. The loop body block2 only includes one loop statement for(j), that is, the loop statement for(i) is nested within the loop statement for(j). The child node "for(j)" of the node "block2" is processed.

[0480] Node "for(j)": The loop statement for(j) is a loop structure, and the loop body block3 of for(j) is recursively processed. The loop body block3 includes statements S2 and S3, and processes the child nodes "S2" and "S3" of the node "for(j)".

[0481] Node "S2": Add node "S2" to the first synchronization path graph. Starting from statement S2, traverse the statements in block3 along the first direction. No statement with serial dependency on statement S2 is determined, so there is no need to add the serial synchronization path of node "S2". Starting from statement S2, traverse the statements in block3 along the first direction. No statement with data dependency on statement S2 is determined. There is no need to insert a synchronization instruction pair, so there is no need to add the instruction synchronization path of node "S2". The abstract syntax tree remains Fig.13 As shown in (a) in the figure, no changes are required. The first synchronization path diagram is Fig.14 The change of (a) in Fig.14 (b) in .

[0482] Node "S3": Add node "S3" to the first synchronization path graph. Starting from statement S3, traverse the statements in block3 along the first direction. No statement that has a serial dependency on statement S3 is determined, so the serial synchronization path for adding node "S3" is not involved. Starting from statement S3, traverse the statements in block3 along the first direction, determine statement S2 that has a data dependency on statement S3, and query the first synchronization path graph to determine that the path from node "S2" to node "S3" is unreachable. Insert a synchronization instruction pair between statement S2 and statement S3, that is, insert push(A,E) after statement S2, and insert pop(A,E) before statement S3. Add an instruction synchronization path from node "S2" to node "S3" in the first synchronization path graph. The abstract syntax tree is composed of Fig.13 The change of (a) in Fig.13 (b) in the first synchronization path diagram. Fig.14 (b) in the equation changes to Fig.14 (c) in .

[0483] In addition, according to the above S1301 to S1308, the statements in the loop body block3 can be inserted with a reverse synchronization instruction pair, and a paired synchronization instruction can be generated at the same time. Specifically, the second synchronization path graph is initialized first, and nodes "S2" and "S3" are added to the second synchronization path graph to establish a reverse serial synchronization path in the second synchronization path graph. The second synchronization path graph is as follows Fig.15As shown. Since statement S2 is executed by the data access processing unit and statement S3 is executed by the computing processing unit, the processing units of the two statements are different and each corresponding processing unit is the only node under block3, so the establishment of the reverse serial path between node "S2" and node "S3" is not involved.

[0484] Then, with statement S2 as the statement currently being processed, start from statement S3 (the last functional instruction) in block3 and traverse the statements in block3 along the first direction to statement S2, determine that there is data dependency between statement S3 and statement S2, and the path from node "S3" to node "S2" in the second synchronization path graph is unreachable, insert a reverse synchronization instruction pair between statement S3 and statement S2, that is, insert push(E,A) after statement S3, insert pop(E,A) before statement S2, and add a reverse instruction synchronization path from node "S3" to node "S2" in the second synchronization path graph. In addition, since the program of the nested loop structure is a multi-layer loop structure, that is, block3 is nested in the loop statement for(i), and the two reverse synchronization instructions have the same source processing unit and destination processing unit, the two reverse synchronization instructions can be paired with external tags. The two reverse synchronization instructions do not meet the pairing conditions and are not paired.

[0485] S3 is the statement currently being processed. Since S3 is the last functional instruction in block3, we start from S3 (the last functional instruction) in block3 and traverse the statements in block3 in the first direction until S3. We have not determined any functional instructions that have data dependencies with S3, and do not involve the insertion of reverse synchronization instructions. The abstract syntax tree is composed of Fig.13 (b) in the equation changes to Fig.13 (c) in the first synchronization path diagram. Fig.14 As shown in (c) in the figure, no change is required. The second synchronization path diagram is still Fig.15 shown.

[0486] Furthermore, the statements in the loop body and the statements outside the loop body are synchronized. Since the statement for(j) is the only node in block2, there is no need to synchronize the statements in block3 with the statements in block2. The two synchronization instructions to be paired, push(E,A) and pop(E,A), do not meet the pairing instruction insertion condition, and the insertion is not performed. The two synchronization instructions to be paired, push(E,A) and pop(E,A), meet the external withdrawal condition, set the external withdrawal flag, return recursively, and then do further processing in block1.

[0487] Starting from statement S2, the statements in block1 are traversed along the first direction. No statement with serial dependency on statement S2 is determined, so there is no need to add a serial synchronization path for node "S2". Starting from statement S2, the statements in block1 are traversed along the first direction. No statement with data dependency on statement S2 is determined, and there is no need to insert a synchronization instruction pair, so there is no need to add an instruction synchronization path for node "S2". Starting from statement S3, the statements in block1 are traversed along the first direction. It is determined that statement S1 and statement S3 are serially dependent, and a serial synchronization path from node "S1" to node "S3" is added to the first synchronization path graph. Starting from statement S3, the statements in block1 are traversed along the first direction. It is determined that statement S1 and statement S2 are data dependent, and the first synchronization path graph is queried to determine that the path from node "S1" to node "S3" is reachable, and there is no need to insert a synchronization instruction pair. The abstract syntax tree remains Fig.13 As shown in (c) in the figure, no changes are required. The first synchronization path diagram is Fig.14 The change of (c) in Fig.14 (d) in.

[0488] Node "S4": Add node "S4" to the first synchronization path graph. Starting from statement S4, traverse the statements in block1 along the first direction to determine statement S2 that has a serial dependency on statement S4. Add a serial synchronization path from node "S2" to node "S4" in the first synchronization path graph. Starting from statement S4, traverse the statements in block1 along the first direction to determine statement S3 that has a data dependency on statement S4, and query the first synchronization path graph to determine that the path from node "S3" to node "S4" is unreachable, and insert a synchronization instruction pair between statement S3 and statement S4. However, since the reverse synchronization instruction push(E,A) has been inserted after statement S3, insert the paired synchronization instruction pop(E,A) before statement S4. Add an instruction synchronization path from node "S3" to node "S4" in the first synchronization path graph. The abstract syntax tree is composed of Fig.13 The change of (c) in Fig.13 (d) in the first synchronization path diagram. Fig.14 The change of (d) in Fig.14 (e) in .

[0489] The remaining reverse synchronization instruction push(E,A) does not meet the external condition (the current block1 is not in the loop), so push(E,A) is inserted before the first statement S1 of block1. The abstract syntax tree is Fig.13 The change of (d) in Fig.13 (e) in .

[0490] 3. Convert the abstract syntax tree of the inserted synchronization instruction pair into a program of the nested loop structure after the inserted synchronization instruction pair. The program of the nested loop structure after the inserted synchronization instruction pair is as follows:

[0491]

[0492] The above-mentioned embodiments respectively provide detailed introductions to the process of inserting synchronization instructions into a program with a sequential structure, a program with a branch structure and a program with a loop structure.

[0493] In some implementations, programs with sequential structures, programs with branch structures, and programs with loop structures can be nested in any form. For example, a program with a branch structure is nested in a program with a sequential structure. For another example, a program with a loop structure is nested in a program with a sequential structure. For another example, multiple layers of branch statements are nested, multiple layers of loop statements are nested, branch statements and loop statements are mixed and nested, etc., and this application does not limit this. So, no matter how the nesting is performed, a method for inserting synchronization instructions provided in an embodiment of the present application processes each statement included in a program block. Fig.16 A flowchart of a method for inserting a synchronization instruction provided in an embodiment of the present application is shown in FIG. Fig.16 As shown, the method may include:

[0494] S1601. Obtain a first program block including one or more statements.

[0495] Each statement in one or more statements includes one or more functional instructions. A statement can be a single functional instruction or a compound statement.

[0496] The statements included in the first program block are traversed starting from the first statement according to the order of the statements included in the first program block. It is determined whether the currently traversed statement is a compound statement, that is, S1602 is executed. Assume that the first program block includes n statements, and the i-th statement is the currently traversed statement, i is an integer, i∈[1,n].

[0497] S1602: Determine whether the i-th statement is a compound statement.

[0498] If the ith statement is not a compound statement, that is, the ith statement is a single functional instruction, the statements in the first program block are traversed along the first direction starting from the ith statement, and S501 to S506 are executed. For specific explanations, refer to the description of S501 to S506 for inserting the synchronization instruction pair.

[0499] It should be noted that if the functional instruction that has not established a synchronization relationship with the i-th statement is a statement in a compound statement, a push instruction can be inserted after the end of the structure of the compound statement including the functional instruction, and a pop instruction can be inserted before the i-th statement.

[0500] If the i-th statement is a compound statement, the statements in the compound statement are traversed, synchronization instruction pairs are inserted into the statements in the compound statement, and then the statements in the compound statement are synchronized with the statements outside the compound statement. A compound statement can be a branch statement or a loop statement.

[0501] For example, if the i-th statement is a branch statement, S801 to S810 are executed, that is, the synchronization instruction pair is first inserted into the statements in the branch structure of the branch statement, and then the statements in the branch structure are synchronized with the statements outside the branch structure, and the statement is recursively returned to continue traversing the outer block. For a specific explanation, please refer to the above description of S801 to S810.

[0502] For another example, when the traversed statement is a loop statement, execute S1201 to S1219, that is, first insert a synchronization instruction pair into the statements in the loop body of the loop statement, then synchronize the statements in the loop body with the statements outside the loop body, recursively return, and continue traversing the outer block.

[0503] Whenever a compound statement is traversed, the statements in the compound statement are processed first, and then recursively returned, and then the statements outside the compound statement are processed, thereby completing the insertion process of the synchronization instruction pair for the entire program.

[0504] In the embodiments provided in the present application above, the method provided in the embodiments of the present application is introduced from the perspective of a computing device. It is understandable that in order to implement the various functions in the method provided in the embodiments of the present application above, the computing device includes a hardware structure and / or software module corresponding to the execution of each function. It should be easily appreciated by those skilled in the art that, in combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.

[0505] The embodiment of the present application can divide the computing device into functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0506] In the case of dividing each functional module into corresponding functional modules, Fig.17 A possible schematic diagram of the composition of the computing device involved in the above embodiments is shown, and the computing device can execute the steps described in any method embodiment of the method embodiments of the present application. Fig.17 As shown, the computing device is a computer device or a computing device that supports a computer device to implement the method provided in the embodiment, for example, the computing device may be a chip system or a computer device. The computing device may include: a processing unit 1701.

[0507] The processing unit 1701 is used to support the computing device to execute the method described in the embodiment of the present application. For example, the processing unit 1701 is used to execute or to support the computing device to execute Figure 5 S501 to S505 in the method of inserting synchronization instructions shown in FIG. Figure 8 S801 to S810 in the method of inserting synchronization instructions shown in FIG. Fig.12 S1201 to S1219 in the method of inserting synchronization instructions shown, Fig.16 S1601, S1602, S501 to S505, S801 to S810, and S1201 to S1219 in the method of inserting synchronization instructions shown.

[0508] In the embodiments of the present application, further, Fig.17 As shown, the computing device may further include: a sending unit 1702 and a receiving unit 1703 .

[0509] The sending unit 1702 is used to send the program into which the synchronization instruction pair has been inserted.

[0510] The receiving unit 1703 is used to receive a program that needs to be inserted with a synchronization instruction pair.

[0511] It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module and will not be repeated here.

[0512] The computing device provided in the embodiments of the present application is used to execute the method of any of the above embodiments, and thus can achieve the same effect as the method of the above embodiments.

[0513] like Fig.18 The chip system 1800 provided in an embodiment of the present application is shown, which is used to execute a computer program in which a synchronization instruction is inserted according to the method for inserting a synchronization instruction provided in an embodiment of the present application to implement the corresponding function. The chip system 1800 may be an artificial intelligence (AI) chip. Among them, the chip system 1800 may include one or more chips, and may also include chips and other discrete devices.

[0514] The chip system 1800 may also include at least one memory 1802 for storing a computer program in which synchronization instructions are inserted according to the method for inserting synchronization instructions provided in an embodiment of the present application. The memory 1802 is coupled to the processor 1801. The coupling in the embodiment of the present application is an indirect coupling or communication connection between devices, units or modules, which may be electrical, mechanical or other forms, for information exchange between devices, units or modules. The processor 1801 may operate in conjunction with the memory 1802. The processor 1801 may execute program instructions stored in the memory 1802. At least one of the at least one memory may be included in the processor.

[0515] The chip system 1800 may also include a communication interface 1803 for communicating with other devices via a transmission medium, so that the device in the chip system 1800 can communicate with other devices. The processor 1801 uses the communication interface 1803 to send and receive computer programs and is used to execute computer programs with synchronization instructions inserted.

[0516] The specific connection medium between the communication interface 1803, the processor 1801 and the memory 1802 is not limited in the embodiment of the present application. Fig.18 The communication interface 1803, the processor 1801 and the memory 1802 are connected via a bus 1804. Fig.18 The connections between the other components are shown in bold lines, which are only for illustration and are not intended to be limiting. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.18 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0517] In the embodiments of the present application, the processor may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0518] In the embodiment of the present application, the memory may be a non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), etc., or a volatile memory (volatile memory), such as a random access memory (RAM). The memory is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory in the embodiment of the present application may also be a circuit or any other device that can implement a storage function, for storing program instructions and / or data.

[0519] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0520] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0521] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0522] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0523] In the method provided in the embodiment of the present application, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a network device, a terminal or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital video disc (DVD)), or a semiconductor medium (eg, an SSD), etc.

[0524] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for inserting a synchronization instruction, characterized in that: include: Obtaining a first program block including one or more statements, each of the one or more statements including one or more functional instructions; Determine that there are a first functional instruction and a second functional instruction with data dependency in the first program block; A synchronization instruction pair is inserted between the statement to which the first functional instruction belongs and the statement to which the second functional instruction belongs.

2. The method according to claim 1, characterized in that The first function instruction and the second function instruction having data dependency access data at the same address, and at least one of the first function instruction and the second function instruction updates the data.

3. The method according to claim 1, characterized in that The address ranges of data accessed by the first function instruction and the second function instruction having data dependency overlap, and at least one of the first function instruction and the second function instruction will update the data.

4. The method according to claim 1, characterized in that: The first function instruction and the second function instruction having data dependency transfer data through a shared storage space.

5. The method according to any one of claims 1 to 4, characterized in that: Also includes: The directed dependency relationship of the functional instructions that have established synchronization is represented by a first synchronization path graph; The first synchronization path diagram includes multiple functional instruction nodes and synchronization paths between the multiple functional instruction nodes, each of the multiple functional instruction nodes corresponds to a functional instruction, and the synchronization path includes a serial synchronization path and an instruction synchronization path. The serial synchronization path is a path connecting nodes corresponding to two functional instructions having serial dependencies, and the instruction synchronization path is a path connecting nodes corresponding to two functional instructions having data dependencies. The serial dependency is a dependency relationship between functional instructions executed in a serial manner by a processing unit.

6. The method according to claim 5, characterized in that The method further comprises: An instruction synchronization path between the node of the first function instruction and the node of the second function instruction is established in the first synchronization path graph.

7. The method according to claim 5, characterized in that The method further comprises: Determine that the first function instruction and the third function instruction that are serially dependent exist in the first program block; A serial synchronization path between the node of the first function instruction and the node of the third function instruction is established in the first synchronization path graph.

8. The method according to claim 7, characterized in that The method further comprises: Determine that there are a fourth function instruction and a fifth function instruction on which data is dependent in the first program block; Determine in the first synchronization path diagram that the synchronization path from the node corresponding to the fourth functional instruction to the node corresponding to the fifth functional instruction is unreachable, and insert a synchronization instruction pair between the statement to which the fourth functional instruction belongs and the statement to which the fifth functional instruction belongs.

9. The method according to claim 7, characterized in that: The first program block includes a loop statement, and the loop statement includes a plurality of functional instructions. The method further includes: Determine that there are a fourth function instruction and a fifth function instruction in the loop statement that have data dependency; Determine that in the first synchronization path graph and the second synchronization path graph, the synchronization path from the node corresponding to the fifth functional instruction to the node corresponding to the fourth functional instruction is unreachable, and insert a synchronization instruction pair between the statement to which the fourth functional instruction belongs and the statement to which the fifth functional instruction belongs, wherein the directed dependency relationship of the functional instructions with established synchronization in the loop statement is represented by the second synchronization path graph; the second synchronization path graph includes multiple functional instruction nodes and synchronization paths between the multiple functional instruction nodes, and the directions of the synchronization paths between the nodes of the functional instructions indicated in the second synchronization path graph and the first synchronization path graph are different.

10. The method according to claim 9, characterized in that The synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction, and the method further includes: configuring the second synchronization instruction for the unpaired first synchronization instruction; and / or, The first synchronization instruction is configured for the unpaired second synchronization instruction.

11. The method according to claim 10, characterized in that The method further comprises: If the configured second synchronization instruction and the configured first synchronization instruction are a synchronization instruction pair, configuring an external flag for the configured second synchronization instruction and the configured first synchronization instruction; If the loop statement is a nested statement within a loop statement, the configured second synchronization instruction and the configured first synchronization instruction are extracted.

12. The method according to claim 9, characterized in that The synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction, and the method further includes: inserting the first synchronization instruction before the first statement in the first program block; and / or, The second synchronization instruction is inserted after the last statement in the first program block.

13. The method according to claim 9, characterized in that The synchronization instruction pair includes a first synchronization instruction and a second synchronization instruction, and the method further includes: The first synchronization instruction is inserted after the sixth function instruction outside the loop statement in the first program block, the sixth function instruction has data dependency with the fifth function instruction in the loop statement, or the synchronization path from the node corresponding to the sixth function instruction to the node corresponding to the fifth function instruction in the first synchronization path diagram is reachable; and / or, The second synchronization instruction is inserted before the sixth function instruction outside the loop statement in the first program block, the sixth function instruction has data dependency with the fifth function instruction in the loop statement, or the synchronization path from the node corresponding to the sixth function instruction in the first synchronization path diagram to the node corresponding to the fifth function instruction is reachable.

14. A computing device, characterized in that: include: At least one processor, a memory and a bus, wherein the memory is used to store a computer program, so that when the computer program is executed by the at least one processor, the method according to any one of claims 1 to 13 is implemented.

15. A computer device, characterized in that: include: At least one processor, a memory and a bus, wherein the memory stores a computer program into which synchronization instructions are inserted according to the method of any one of claims 1 to 13, and the at least one processor executes the computer program into which synchronization instructions are inserted to implement corresponding functions.

16. A computer-readable storage medium, characterized in that: include: Computer software instructions; When the computer software instructions are executed in a computer device or a chip built in the computer device, the computer device is caused to execute the method according to any one of claims 1 to 13.