A method and device for processing instructions

By generating a directed acyclic graph and merging dependencies in the GPU instruction set, the problem of low GPU instruction execution efficiency is solved, higher instruction combination rate and security are achieved, the instruction set is simplified, and GPU execution efficiency is improved.

CN117407060BActive Publication Date: 2024-09-06GLENFLY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210853206.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-07
Publication Date
2024-09-06
Estimated Expiration
2042-07-07

AI Technical Summary

Technical Problem

When the GPU executes instructions, due to the large number of instructions and the existence of dependencies, the execution efficiency is low and the energy consumption is high, making it difficult to improve the instruction execution efficiency.

Method used

By generating a directed acyclic graph to represent the dependencies in the instruction set to be processed, merge instructions with dependencies, and reorder to obtain the target instruction set. Use the directed acyclic graph to accurately determine the possibility of instruction merging, avoid hardware platform limitations, and combine All dependent instructions without being limited to adjacent instructions.

Benefits of technology

The efficiency of GPU execution of instructions is improved, the instruction combination rate and safety are improved, the target instruction set obtained is more concise, and the instruction execution efficiency of GPU is effectively improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117407060B
    Figure CN117407060B
Patent Text Reader

Abstract

The present application relates to an instruction processing method and device. The method comprises: generating a directed acyclic graph for the instruction set to be processed according to a fixed-value reference chain of the instruction set to be processed; determining a target node having a dependency relationship with the current node in the directed acyclic graph for the current node; merging the target node and the current node into a combined node, taking the next node of the current node as the current node, and returning to the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph until the current node is the last node in the directed acyclic graph, and obtaining a new directed acyclic graph; reordering the instruction set to be processed based on the new directed acyclic graph to obtain a target instruction set. The use of this method can improve the efficiency of instruction execution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an instruction processing method and device. Background Art

[0002] Graphics Processing Unit (GPU) is an important intelligent parallel computing chip that can be used for screen display, 3D scene rendering, video encoding and decoding, virtual reality VR, augmented display AR, artificial intelligence AI, parallel deep neural network, etc. GPU can be seen in both traditional computers and various mobile devices, such as tablets, mobile phones, smart TVs, and car display devices. Therefore, it is very important to design an efficient GPU to meet the needs of parallel computing.

[0003] Programs executed on the GPU are generally called shaders, and the GPU compiler is responsible for converting shaders into a series of machine instructions that can be executed on the target GPU hardware platform. However, due to the large number of instructions and the existence of a series of dependencies between different instructions, it often takes a long time for the GPU to execute instructions and the running energy consumption is high, which is not conducive to improving the efficiency of GPU instruction execution. Summary of the invention

[0004] Based on this, it is necessary to provide an instruction processing method and device that can improve instruction execution efficiency in response to the above technical problems.

[0005] A method for processing an instruction, the method comprising:

[0006] Generate a directed acyclic graph for the instruction set to be processed according to the fixed-value reference chain of the instruction set to be processed; the directed acyclic graph is used to represent the dependency relationship between the instructions to be processed in the instruction set to be processed; the directed acyclic graph includes nodes representing each of the instructions to be processed and edges representing each of the dependency relationships;

[0007] For a current node in the directed acyclic graph, determining a target node in the directed acyclic graph that has a dependency relationship with the current node;

[0008] Merging the target node and the current node into a combined node, taking the next node of the current node as the current node, and returning to the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph, until the current node is the last node in the directed acyclic graph, thereby obtaining a new directed acyclic graph;

[0009] The to-be-processed instruction set is reordered based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two to-be-processed instructions represented by at least one combined node in the new directed acyclic graph.

[0010] In one embodiment, before the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph, the method further comprises:

[0011] Determine whether the current node is a valid node or an invalid node;

[0012] If the current node is a valid node, the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph is performed.

[0013] In one of the embodiments, after the step of determining whether the current node is a valid node or an invalid node, the method further comprises:

[0014] If the current node is an invalid node, the next node of the current node is used as the current node, and the step of determining whether the current node is a valid node or an invalid node is performed.

[0015] In one embodiment, determining a target node having a dependency relationship with the current node in the directed acyclic graph includes:

[0016] Determining, in the directed acyclic graph, candidate nodes having a dependency relationship with the current node;

[0017] If there is one candidate node, the candidate node is used as the target node; if there are multiple candidate nodes, one of the nodes is selected from the multiple candidate nodes as the target node according to a preset node selection rule.

[0018] In one of the embodiments, before the step of merging the target node and the current node into a combined node, the method further comprises:

[0019] Obtaining the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs;

[0020] If it is determined based on the instruction pipeline characteristics that the pending instruction represented by the target node cannot be combined with the pending instruction represented by the current node, the next node of the current node is used as the current node, and the step of determining the candidate node having a dependency relationship with the current node in the directed acyclic graph is executed.

[0021] In one embodiment, the method further comprises:

[0022] If it is determined according to the instruction pipeline characteristics that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined, the step of merging the target node and the current node into a combined node is executed.

[0023] An instruction processing device, comprising:

[0024] A generating module, used for generating a directed acyclic graph for the instruction set to be processed according to the fixed value reference chain of the instruction set to be processed; the directed acyclic graph is used for representing the dependency relationship between the instructions to be processed in the instruction set to be processed; the directed acyclic graph includes a node representing each of the instructions to be processed and an edge representing each of the dependency relationships;

[0025] A determination module, configured to determine, for a current node in the directed acyclic graph, a target node in the directed acyclic graph that has a dependency relationship with the current node;

[0026] A combination module, used for merging the target node and the current node into a combination node, taking the next node of the current node as the current node, and returning to the determination module until the current node is the last node in the directed acyclic graph, thereby obtaining a new directed acyclic graph;

[0027] A rearrangement module is used to reorder the pending instruction set based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two pending instructions represented by at least one combined node in the new directed acyclic graph.

[0028] In one of the embodiments, the device is also used to determine whether the current node is a valid node or an invalid node; if the current node is a valid node, the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph is executed.

[0029] In one of the embodiments, the device is further used to, if the current node is an invalid node, use the next node of the current node as the current node, and execute the step of determining whether the current node is a valid node or an invalid node.

[0030] In one of the embodiments, the determination module is specifically used to determine a candidate node having a dependency relationship with the current node in the directed acyclic graph; if there is one candidate node, the candidate node is used as the target node; if there are multiple candidate nodes, one of the nodes is selected from the multiple candidate nodes as the target node according to a preset node selection rule.

[0031] In one of the embodiments, the determination module is specifically used to obtain the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs; if it is determined based on the instruction pipeline characteristics that the instruction to be processed represented by the target node and the instruction to be processed represented by the current node cannot be combined, then the next node of the current node is used as the current node, and the step of determining the candidate node having a dependency relationship with the current node in the directed acyclic graph is executed.

[0032] In one of the embodiments, the determination module is further specifically used to execute the step of merging the target node and the current node into a combined node if it is determined based on the instruction pipeline characteristics that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined.

[0033] The above-mentioned instruction processing method and device generate a directed acyclic graph for representing the dependency relationship between each instruction to be processed in the instruction set to be processed according to the fixed-value reference chain of the instruction set to be processed; wherein the directed acyclic graph includes nodes representing each instruction to be processed and edges representing each dependency relationship; then, for the current node in the directed acyclic graph, a target node having a dependency relationship with the current node is determined in the directed acyclic graph; the target node and the current node are merged into a combined node, the next node of the current node is used as the current node, and the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph is returned until the current node is the last node in the directed acyclic graph, and a new directed acyclic graph is obtained; then based on the new directed acyclic graph, the target node having a dependency relationship with the current node is processed. The processing instruction set is reordered to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two instructions to be processed represented by at least one combined node in a new directed acyclic graph; in this way, the instruction merging problem can be solved from the perspective of compilation technology, and the directed acyclic graph used to represent the dependency relationship between the instructions to be processed in the instruction set to be processed is used to accurately determine whether the instructions to be processed can be merged, thereby avoiding the limitations of the hardware platform; at the same time, all instructions with dependencies can be combined without limiting the combination of adjacent instructions, so that the instruction combination rate and security of the instruction set to be processed are effectively improved, and the obtained target instruction set is more concise, thereby effectively improving the efficiency of GPU execution instructions. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 is a flow chart of an instruction processing method in one embodiment;

[0035] Figure 2 is a schematic diagram of a pixel shader pseudo code in one embodiment;

[0036] Figure 3 A schematic diagram of an intermediate form code in one embodiment;

[0037] Figure 4 A schematic diagram of a basic block identifier of a pixel shader pseudo code in one embodiment;

[0038] Figure 5 A schematic diagram of a DU chain corresponding to an intermediate form code in an embodiment;

[0039] Figure 6 A directed acyclic graph in one embodiment;

[0040] FIG. 7( a ) is a schematic diagram showing the effect of an instruction replacement operation in one embodiment;

[0041] FIG7( b ) is a schematic diagram showing the effect of an instruction combination operation in one embodiment;

[0042] Figure 8 is another directed acyclic graph in one embodiment;

[0043] Fig. 9 A directed acyclic graph in another embodiment;

[0044] Fig.10 Another directed acyclic graph in another embodiment;

[0045] Fig.11 is a schematic diagram of a target instruction set in one embodiment;

[0046] Fig.12 is a flow chart of an instruction processing method in another embodiment;

[0047] Fig.13 A flow chart of an instruction combination strategy in an embodiment;

[0048] Fig.14 The figure is a structural block diagram of an instruction processing device in one embodiment. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0050] In order to better describe the embodiments of the present invention, the special terms and related concepts used in this application are explained below.

[0051] A DU chain (define-use-chain) is a sparse representation of variable data flow information. A variable's DU chain connects the variable's definition to all possible uses of the variable.

[0052] A dependency is a relationship that constrains the order in which instructions in a code are executed. This relationship must be followed for the code to execute correctly.

[0053] Dependencies are mainly divided into control dependence and data dependence; control dependence is a constraint caused by program control flow, and data dependence is a constraint caused by data flow between instructions. A set of dependencies can be represented by a directed graph called a dependency graph, in which nodes represent instructions and edges represent dependencies between instructions.

[0054] In a basic block, since there is no cycle, its dependency graph is always a directed acyclic graph (DAG), called the basic block dependency DAG. The basic block dependency DAG is applicable to language codes at any level, such as source code, intermediate code, and target instructions.

[0055] In one embodiment, Figure 1 As shown, an instruction processing method is provided, which is described by taking the method applied to a compiler as an example, and includes the following steps:

[0056] Step S110, generating a directed acyclic graph for the instruction set to be processed according to the fixed value reference chain of the instruction set to be processed.

[0057] The instruction set to be processed may be an instruction set consisting of at least two instructions to be merged. In practical applications, the instruction set to be processed may be a section of MIR (intermediate format code) or a section of LIR (low-level format code).

[0058] The directed acyclic graph is used to represent the dependency relationship between the instructions to be processed in the instruction set to be processed. The directed acyclic graph includes nodes representing the instructions to be processed and edges representing the dependency relationships.

[0059] In a specific implementation, the compiler may convert the pseudocode of a program (eg, a shader) into an intermediate form code or a low-level form code waiting for optimization; then, the compiler uses the code to be optimized as the above-mentioned instruction set to be processed.

[0060] Then, the compiler can identify the basic block. For the instruction set to be processed in any basic block, the compiler can obtain the fixed value reference chain of the instruction set to be processed, and build a directed acyclic graph (DAG) for the instruction set to be processed based on the fixed value reference chain of the instruction set to be processed.

[0061] In order to facilitate the understanding of those skilled in the art, the following uses pixel shader (PS, Pixel Shader) pseudo code as an example to illustrate the specific implementation method. Figure 2 As shown, Figure 2 A pixel shader pseudo code is shown as an example. The compiler can compile and perform a series of optimizations on the pixel shader pseudo code, that is, convert the pixel shader pseudo code into a corresponding intermediate format code (MIR), that is, an instruction set to be processed. Figure 3 , Figure 3 The intermediate form code corresponding to a pixel shader pseudocode is shown as an example. Each MIR instruction in the intermediate form code writes (defines) a symbol register, where R# is a general register, P# is a prediction register, R811008~R811009 represent the input variable color of PS, R811012~R811013 represent the input variable cond of PS, R815104 represents the output variable gl_FragColor.x of PS, and R815106 represents the output variable gl_FragColor.z of PS. The operations in the PS fragment are converted into instruction codes in MIR, such as "+" is converted into FADD, "*" is converted into FMUL, and the comparison operator "<" is converted into ICMP_LT, etc. It should be noted that the number before each instruction represents the number of the current instruction. Due to some optimizations, redundant instructions have been deleted. Figure 3 The numbers corresponding to the instructions in are not consecutive.

[0062] The compiler then identifies the basic blocks, since Figure 2 All MIR instructions in the pixel shader pseudocode shown are located in the same basic block, namely Block 1. Therefore, the basic block identifier of this pixel shader pseudocode is as follows: Figure 4 As shown. For the instruction set to be processed in Block1, the compiler can obtain the DU chain corresponding to the instruction set to be processed. Figure 5 , Figure 5 The DU chain corresponding to a section of the intermediate form code is shown as an example. Figure 5 Each define in the DU chain has a usage.

[0063] The compiler can use this DU chain to Figure 3 The intermediate form code shown builds the corresponding dependency DAG, such as Figure 6 The directed acyclic graph shown in FIG. The directed acyclic graph is used to represent the dependency relationship between each instruction to be processed in the instruction set to be processed. The directed acyclic graph includes nodes representing each instruction to be processed and edges representing each dependency relationship.

[0064] Specifically, if Figure 6 As shown in the figure, a node in the directed acyclic graph contains an instruction. The node number represents the order in which the instructions in the node appear in the instruction fragment. The smaller the number, the earlier the instruction appears. The edge represents the dependency relationship between instructions. Figure 6 There is only one dependency, data dependency, in which the previous instruction writes to a register and the next instruction uses this register. For example, instruction 8 writes to R97632 and instruction 12 uses R97632, which means that instruction 12 can only be executed after instruction 8 executes several clock cycles, that is, there is a waiting time (latency) between the two instructions. The latency mark is omitted in this dependency DAG.

[0065] Step S120, for the current node in the directed acyclic graph, determine a target node in the directed acyclic graph that has a dependency relationship with the current node.

[0066] In a specific implementation, after the compiler determines the directed acyclic graph of the instruction to be processed, the compiler can start processing each node in turn until all nodes in the directed acyclic graph are traversed; specifically, the compiler can determine the target node in the directed acyclic graph that has a dependency relationship with the current node for the current node in the directed acyclic graph. The dependency relationship may include control dependency and data dependency, etc. In practical applications, the target node can also be named as the usage node of the current node.

[0067] In actual applications, there may be one or more nodes that have a dependency relationship with the current node. When there is only one node that has a dependency relationship with the current node, the node is the usage node of the current node. When there are multiple nodes that have a dependency relationship with the current node, the compiler can select an optimal node from the multiple nodes according to some characteristics of the target platform as the usage node of the current node.

[0068] Step S130, merge the target node and the current node into a combined node, take the next node of the current node as the current node, and return to the step of determining the target node that has a dependency relationship with the current node in the directed acyclic graph, until the current node is the last node in the directed acyclic graph, and a new directed acyclic graph is obtained.

[0069] In the specific implementation, after the compiler determines the optimal usage node of the current node, the compiler can determine whether the current define and usage Node can be combined according to the instruction pipeline characteristics of the target platform. If the combination can be performed, the target node and the current node are merged into a combined node. Then, when determining the next node, the next node of the current node is used as the current node, and the step of determining the target node with a dependency relationship with the current node in the directed acyclic graph is returned. The above steps are executed cyclically until the current node is the last node in the directed acyclic graph, and a new directed acyclic graph is obtained.

[0070] Still continuing with the above example, Figure 6 Node0 in the table currently only contains instruction 8 and has not been combined. It is a valid node. According to the DU chain, we find the usage of define R97632, which is instruction 12, corresponding to Node2. Here, R97632 has only one usage, so Node2 is considered to be the optimal usage node. Node0 contains only one multiplication instruction FMUL, which belongs to the ALG instruction and writes to register R97632. Node2 contains only one format conversion instruction, which uses R97632, that is, converting R97632 from floating point to integer, and assigning the conversion result to R97640. If Node0 and Node2 are combined to meet the target platform characteristics 1 and 2, SFWD is used to replace the register R97632 written by the first instruction in the combination, and replaces the register R97632 read by the second instruction. The replacement effect is shown in Figure 7(a). The symbol + in the figure indicates that the current instruction is combined with the next instruction. In this combination, two general registers R811008 / R811009 are read and one general register R97640 is written, which meets characteristic 3. Therefore, Node0 and Node2 meet the combination condition. It is worth noting that if R97632 of instruction 8 has multiple usages, R97632 of instruction 8 cannot be replaced by SFWD. Assuming that the optimal usage Node is still Node2, the combination effect is shown in Figure 7(b). Instruction 8 writes R97632 for use by other usage nodes, and also writes SFWD for use by instruction 12. However, this combination requires writing two registers R97632 / R97640, which violates characteristic 3 and cannot be combined.

[0071] Combine the nodes that meet the combination conditions. Since the combination replaces some general registers with SFWD, the data flow information changes, so the DU chain needs to be updated in time. When combining, merge the instructions in the usage Node into the defineNode, change the edge pointing to the usage Node to point to the define Node, remove the edge between define and usage Node, change the edge starting from the usage Node to start from the define Node, and mark the usage Node as invalid.

[0072] Combine Node0 and Node2. First update the DU chain. As can be seen from Figure 7(a), R97632 has been completely replaced by SFWD. Figure 5 Remove the chain corresponding to R97632 from the DU chain shown. Next, merge the edges and instructions of the nodes, merge the instructions in Node2 into Node0, let the edge pointing to Node2 point to Node0, change the edge from Node2 to be from Node0, and mark Node2 as an invalid Node. Remove the edge between Node0 and Node2. The schematic diagram of merging Node0 and Node2 is shown in Figure 8 As shown in the figure, it can be seen that after the merger, there are two instructions in Node0, but no instructions in Node2, and the two dotted edges are the removed edges.

[0073] At this point, Node0 has been processed. Use the same method to process Node1, Node2, Node3, ... in sequence until all Nodes have been processed. Figure 6 The dependency DAG shown eventually becomes Fig. 9 The dependency DAG shown is the new directed acyclic graph.

[0074] Step S140, reordering the instruction set to be processed based on the new directed acyclic graph to obtain a target instruction set.

[0075] The target instruction set includes at least one combined instruction; the combined instruction is composed of at least two instructions to be processed represented by at least one combined node in the new directed acyclic graph.

[0076] In a specific implementation, after obtaining the new directed acyclic graph, the compiler reorders the instruction set to be processed based on the new directed acyclic graph to obtain a target instruction set including at least one combined instruction, wherein the combined instruction may be an instruction composed of at least two instructions to be processed.

[0077] Continuing with the previous example, the compiler reorders the instructions in the basic block block1 so that the second instruction in the combination is next to the first instruction in the combination, and the two instructions are treated as one operation on the EUDP pipeline. First, clear the instructions in the current basic block, then select the appropriate Node in turn according to the current DAG, and add the instructions in the Node to the basic block. The Nodes in the DAG root node set have no dependencies on each other, so any Node in the set can be selected each time, but in order to maintain the approximate original instruction order, the Node with the smallest number is selected each time, and the instructions contained in the selected Node are added to the basic block, and then the DAG is trimmed, that is, the selected Node is deleted from the DAG, and the root node set will also change accordingly. Repeat the Node selection process until the root node set is empty.

[0078] from Fig. 9 It can be seen that the root set of the current DAG is Node0, Node1, and Node5. Select Node0 with the smallest number, add its instructions 8 and 12 to the basic block, and then delete Node0 from the DAG. The DAG at this time is as follows: Fig.10 As shown in the figure, it can be seen that the root node set becomes Node1, Node5, and this process is repeated until the root set is empty.

[0079] Finally, the instruction form and order of the basic block are obtained as follows Fig.11 As shown in the figure, Figure 3 The instruction fragment shown finally combines three pairs of instructions. In the subsequent optimization and compilation process, the instructions in a combination are always bundled together as a whole. Figure 3 There are 8 instructions, that is, 8 independent instruction operations, and Fig.11 There are only 5 instruction operations in the , which can reduce the instruction issuance time and improve the ,instruction-level parallelism.,In addition, each combination uses SFWD, and there is no need to allocate ,additional registers to SFWD, which can save register resources to a certain extent.

[0080] In the above instruction processing method, a directed acyclic graph is generated according to the fixed-value reference chain of the instruction set to be processed, which is used to characterize the dependency relationship between each instruction to be processed in the instruction set to be processed; wherein the directed acyclic graph includes nodes representing each instruction to be processed and edges representing each dependency relationship; then, for the current node in the directed acyclic graph, a target node having a dependency relationship with the current node is determined in the directed acyclic graph; the target node and the current node are merged into a combined node, the next node of the current node is used as the current node, and the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph is returned until the current node is the last node in the directed acyclic graph, and a new directed acyclic graph is obtained; then, based on the new directed acyclic graph, the processing is processed. The processing instruction set is reordered to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two pending instructions represented by at least one combined node in a new directed acyclic graph; in this way, the instruction merging problem can be solved from the perspective of compilation technology, and the directed acyclic graph used to represent the dependency relationship between the pending instructions in the pending instruction set is used to accurately determine whether the pending instructions can be merged, thereby avoiding the limitations of the hardware platform; at the same time, all instructions with dependencies can be combined without limiting the combination of adjacent instructions, so that the instruction combination rate and security of the pending instruction set are effectively improved, and the obtained target instruction set is more concise, thereby effectively improving the efficiency of GPU execution instructions.

[0081] In another embodiment, determining a target node having a dependency relationship with a current node in a directed acyclic graph includes: determining a candidate node having a dependency relationship with the current node in the directed acyclic graph; if there is one candidate node, using the candidate node as the target node; if there are multiple candidate nodes, selecting one of the multiple candidate nodes as the target node according to a preset node selection rule.

[0082] In the specific implementation, in the process of determining the target node with a dependency relationship with the current node in the directed acyclic graph, the compiler can determine the candidate node with a dependency relationship with the current node in the directed acyclic graph according to the DU chain, that is, find the Nodes corresponding to all usages assigned (define) to the current node in the directed acyclic graph, that is, the candidate nodes. Then, the optimal use Node, that is, the target node, is selected. If there is only one candidate node, then the candidate node is the best, and the compiler uses the candidate node as the target node; if there are multiple candidate nodes, the compiler selects the best candidate node as the target node according to some characteristics or rules of the target platform.

[0083] According to the technical solution of this embodiment, in the process of the compiler determining a target node having a dependency relationship with a current node in a directed acyclic graph, if the compiler determines that there are multiple candidate nodes having a dependency relationship with the current node in the directed acyclic graph, the best candidate node is selected as the target node according to the characteristics or rules of the target platform, so that a suitable target node can be selected for each current node for combination, thereby facilitating the subsequent effective combination of the instructions represented by the current node and the instructions represented by the target node.

[0084] In another embodiment, before the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph, the method further includes: determining whether the current node is a valid node or an invalid node; if the current node is a valid node, executing the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph. If the current node is an invalid node, taking the next node of the current node as the current node, and executing the step of determining whether the current node is a valid node or an invalid node.

[0085] In the specific implementation, before the compiler determines the target node with a dependency relationship with the current node in the directed acyclic graph, it is also necessary to determine whether the current node is a valid node or an invalid node; if the current node is a valid node, the step of determining the target node with a dependency relationship with the current node in the directed acyclic graph is executed. If the current node is an invalid node, the next node of the current node is used as the current node, and the step of determining whether the current node is a valid node or an invalid node is executed. It should be noted that the specific limitations of the compiler's execution of determining the target node with a dependency relationship with the current node in the directed acyclic graph can be found above and will not be repeated here.

[0086] For example, before the compiler determines the target node that has a dependency relationship with the current node in the directed acyclic graph, the compiler determines whether the current node is marked as an invalid node. Figure 6 After processing Node0 and Node2, the compiler marks Node2 as an invalid Node. At this time, Node0 is processed, and the compiler uses the same method to process Node1, Node2, Node3, ... in sequence. When the compiler processes Node2, it finds that the Node is invalid, that is, Node2 is an invalid node. The compiler skips it directly without processing and continues to process subsequent Nodes until all Nodes are processed.

[0087] The technical solution of this embodiment determines whether the current node is a valid node or an invalid node before determining the target node that has a dependency relationship with the current node in the directed acyclic graph. If the current node is an invalid node, the invalid node is directly skipped, thereby avoiding the compiler from searching for the corresponding target node for the invalid node, effectively reducing the data processing amount of the compiler, and improving the efficiency of the compiler in processing instruction sets.

[0088] In another embodiment, before the step of merging the target node and the current node into a combined node, the method also includes: obtaining instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs; if it is determined based on the instruction pipeline characteristics that the instructions to be processed represented by the target node and the instructions to be processed represented by the current node cannot be combined, then the next node of the current node is used as the current node, and the step of determining candidate nodes having a dependency relationship with the current node in the directed acyclic graph is executed.

[0089] If it is determined according to the instruction pipeline characteristics that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined, then the step of merging the target node and the current node into a combined node is executed.

[0090] In a specific implementation, before merging the target node and the current node into a combined node, the compiler can also pre-determine whether the target node and the current node can be merged. Specifically, the compiler can obtain the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs; and based on the instruction pipeline characteristics, determine whether the instruction to be processed represented by the target node and the instruction to be processed represented by the current node can be combined;

[0091] Among them, the target platform may have the following characteristics in terms of instruction combination:

[0092] 1. A maximum of two instructions can be combined;

[0093] 2. Supported combinations: ALG+FMT, ALG+LGC, ALG+SEL, ALG+Branch, FMT+LGC, FMT+SEL, FMT+Branch, LGC+SEL, LGC+Branch, SEL+Branch.

[0094] Among them, ALG represents calculation instructions, FMT represents format conversion instructions, LGC represents logic instructions, SEL represents selection instructions, and Branch represents conditional branch instructions.

[0095] 3. A combination can write at most 1 general register R# and read 3 general registers R#;

[0096] 4. All instructions in the combination are treated as one operation and executed in different stages of the EUDP pipeline. When the pipeline ends, all instructions are executed.

[0097] 5. Support special register SFWD, which is used to store the execution result of the first instruction in the combination, and the second instruction can quickly read the value in the register without waiting. It should be noted that the present disclosure does not list all the features of the target platform and is not limited to this.

[0098] When it is determined that the pending instruction represented by the target node cannot be combined with the pending instruction represented by the current node, the next node of the current node is used as the current node, and the step of determining the candidate node with a dependency relationship with the current node in the directed acyclic graph is executed. That is, the compiler skips the current node and uses the same processing method to process the next node of the current node. When it is determined that the pending instruction represented by the target node can be combined with the pending instruction represented by the current node, the step of merging the target node and the current node into a combined node is executed. It should be noted that the specific definition of the compiler executing the step of merging the target node and the current node into a combined node can be found above and will not be repeated here.

[0099] In another embodiment, Fig.12 As shown, an instruction processing method is provided, which is described by taking the method applied to a compiler as an example, and includes the following steps:

[0100] Step S1210, generating a directed acyclic graph for the instruction set to be processed according to the constant reference chain of the instruction set to be processed; the directed acyclic graph is used to characterize the dependency relationship between each instruction to be processed in the instruction set to be processed; the directed acyclic graph includes nodes representing each instruction to be processed, and edges representing each dependency relationship.

[0101] Step S1220, for the current node in the directed acyclic graph, determining whether the current node is a valid node or an invalid node;

[0102] Step S1230, if the current node is a valid node, determining a candidate node having a dependency relationship with the current node in the directed acyclic graph;

[0103] Step S1240: If there are multiple candidate nodes, one of the nodes is selected from the multiple candidate nodes as the target node according to a preset node selection rule.

[0104] Step S1250, obtaining the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs;

[0105] Step S1260: if it is determined according to the instruction pipeline characteristics that the instruction to be processed represented by the target node and the instruction to be processed represented by the current node can be combined, the target node and the current node are combined into a combined node;

[0106] Step S1270, taking the next node of the current node as the current node, and returning to the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph, until the current node is the last node in the directed acyclic graph, and obtaining a new directed acyclic graph;

[0107] Step S1280, reorder the pending instruction set based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two pending instructions represented by at least one combined node in the new directed acyclic graph.

[0108] It should be noted that the specific limitations of the above steps can refer to the specific limitations of an instruction processing method above.

[0109] In another embodiment, Fig.13 As shown, an instruction combination strategy flow chart is provided exemplarily. Among them, the compiler identifies the basic block and obtains the basic block set; for the instruction set to be processed of each basic block in the basic block set, the compiler can obtain the fixed value reference chain of the instruction set to be processed, and build a directed acyclic graph (DAG) for the instruction set to be processed according to the fixed value reference chain of the instruction set to be processed. For each current node in the directed acyclic graph, the compiler determines whether the current node is a valid node or an invalid node.

[0110] If the current node is a valid node, the target node that has a dependency relationship with the current node is determined in the directed acyclic graph, that is, the optimal usage node. After the compiler determines the optimal usage node of the current node, the compiler can determine whether the current define and usage Node can be combined according to the instruction pipeline characteristics of the target platform. If the combination is possible, the target node and the current node are merged into a combined node, and the next node of the current node is used as the current node, that is, the subsequent nodes are processed.

[0111] If the current node is an invalid node, the next node of the current node is used as the current node, and the subsequent nodes are processed until all nodes in the directed acyclic graph are processed to obtain a new directed acyclic graph. After obtaining the new directed acyclic graph, the compiler reorders the instruction set to be processed based on the new directed acyclic graph to obtain a target instruction set including at least one combined instruction. The combined instruction may refer to an instruction composed of at least two instructions to be processed.

[0112] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0113] Based on the same inventive concept, the embodiment of the present application also provides an instruction processing device for implementing the instruction processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more instruction processing device embodiments provided below can refer to the limitations on the instruction processing method above, and will not be repeated here.

[0114] In one embodiment, Fig.14 As shown, an instruction processing device is provided, comprising:

[0115] A generating module 1410 is used to generate a directed acyclic graph for the instruction set to be processed according to the fixed value reference chain of the instruction set to be processed; the directed acyclic graph is used to represent the dependency relationship between the instructions to be processed in the instruction set to be processed; the directed acyclic graph includes a node representing each of the instructions to be processed and an edge representing each of the dependency relationships;

[0116] A determination module 1420 is used to determine, for a current node in the directed acyclic graph, a target node having a dependency relationship with the current node in the directed acyclic graph;

[0117] A combination module 1430 is used to combine the target node and the current node into a combination node, take the next node of the current node as the current node, and return to the determination module until the current node is the last node in the directed acyclic graph to obtain a new directed acyclic graph;

[0118] The rearrangement module 1440 is used to reorder the pending instruction set based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two pending instructions represented by at least one combined node in the new directed acyclic graph.

[0119] In one of the embodiments, the device is also used to determine whether the current node is a valid node or an invalid node; if the current node is a valid node, the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph is executed.

[0120] In one of the embodiments, the device is further used to, if the current node is an invalid node, use the next node of the current node as the current node, and execute the step of determining whether the current node is a valid node or an invalid node.

[0121] In one of the embodiments, the determination module is specifically used to determine a candidate node having a dependency relationship with the current node in the directed acyclic graph; if there is one candidate node, the candidate node is used as the target node; if there are multiple candidate nodes, one of the nodes is selected from the multiple candidate nodes as the target node according to a preset node selection rule.

[0122] In one of the embodiments, the determination module is specifically used to obtain the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs; if it is determined based on the instruction pipeline characteristics that the instruction to be processed represented by the target node and the instruction to be processed represented by the current node cannot be combined, then the next node of the current node is used as the current node, and the step of determining the candidate node having a dependency relationship with the current node in the directed acyclic graph is executed.

[0123] In one of the embodiments, the determination module is further specifically used to execute the step of merging the target node and the current node into a combined node if it is determined based on the instruction pipeline characteristics that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined.

[0124] Each module in the above instruction processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0125] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0126] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0127] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A command processing method, characterized in that: The method comprises: Generate a directed acyclic graph for the instruction set to be processed according to the fixed-value reference chain of the instruction set to be processed; the directed acyclic graph is used to represent the dependency relationship between the instructions to be processed in the instruction set to be processed; the directed acyclic graph includes nodes representing each of the instructions to be processed and edges representing each of the dependency relationships; For a current node in the directed acyclic graph, determining a target node having a dependency relationship with the current node in the directed acyclic graph, specifically comprising: determining a candidate node having a dependency relationship with the current node in the directed acyclic graph; if there is one candidate node, using the candidate node as the target node; if there are multiple candidate nodes, selecting one of the multiple candidate nodes as the target node according to a preset node selection rule; If it is determined that the instruction to be processed represented by the target node and the instruction to be processed represented by the current node cannot be combined according to the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs, the next node of the current node is used as the current node, and the step of determining the candidate node having a dependency relationship with the current node in the directed acyclic graph is performed; Merging the target node and the current node into a combined node, taking the next node of the current node as the current node, and returning to the step of determining the target node having a dependency relationship with the current node in the directed acyclic graph, until the current node is the last node in the directed acyclic graph, thereby obtaining a new directed acyclic graph; The to-be-processed instruction set is reordered based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two to-be-processed instructions represented by at least one combined node in the new directed acyclic graph.

2. The method according to claim 1, characterized in that Before the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph, the method further includes: Determine whether the current node is a valid node or an invalid node; If the current node is a valid node, the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph is performed.

3. The method according to claim 2, characterized in that After the step of determining whether the current node is a valid node or an invalid node, the method further includes: If the current node is an invalid node, the next node of the current node is used as the current node, and the step of determining whether the current node is a valid node or an invalid node is performed.

4. The method according to claim 1, characterized in that: The method further comprises: If it is determined according to the instruction pipeline characteristics that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined, the step of merging the target node and the current node into a combined node is executed.

5. An instruction processing device, characterized in that: The device comprises: A generating module, used for generating a directed acyclic graph for the instruction set to be processed according to the fixed value reference chain of the instruction set to be processed; the directed acyclic graph is used for representing the dependency relationship between the instructions to be processed in the instruction set to be processed; the directed acyclic graph includes a node representing each of the instructions to be processed and an edge representing each of the dependency relationships; A determination module is used to determine, for a current node in the directed acyclic graph, a target node having a dependency relationship with the current node in the directed acyclic graph, specifically comprising: determining a candidate node having a dependency relationship with the current node in the directed acyclic graph; if there is one candidate node, using the candidate node as the target node; if there are multiple candidate nodes, selecting one of the multiple candidate nodes as the target node according to a preset node selection rule; The determination module is further configured to, if it is determined that the instructions to be processed represented by the target node and the instructions to be processed represented by the current node cannot be combined according to the instruction pipeline characteristics of the target platform to which the instruction set to be processed belongs, use the next node of the current node as the current node, and execute the step of determining a candidate node having a dependency relationship with the current node in the directed acyclic graph; A combination module, used for merging the target node and the current node into a combination node, taking the next node of the current node as the current node, and returning to the determination module until the current node is the last node in the directed acyclic graph, thereby obtaining a new directed acyclic graph; A rearrangement module is used to reorder the pending instruction set based on the new directed acyclic graph to obtain a target instruction set; the target instruction set includes at least one combined instruction; the combined instruction is composed of at least two pending instructions represented by at least one combined node in the new directed acyclic graph.

6. The device according to claim 5, characterized in that The device is also used to determine whether the current node is a valid node or an invalid node; if the current node is a valid node, the step of determining a target node having a dependency relationship with the current node in the directed acyclic graph is executed.

7. The device according to claim 6, characterized in that The device is also used for, if the current node is an invalid node, taking the next node of the current node as the current node, and executing the step of determining whether the current node is a valid node or an invalid node.

8. The device according to claim 5, characterized in that The determination module is further specifically used to execute the step of merging the target node and the current node into a combined node if it is determined, based on the instruction pipeline characteristics, that the pending instruction represented by the target node and the pending instruction represented by the current node can be combined.