Copy propagation method, device, storage medium and program product of GPU instruction

By acquiring the control flow graph and working list of the target program, calculating fixed points, identifying basic blocks within thread bundles, performing global and local copy propagation, and conducting security checks, this approach addresses the problem of insufficient optimization in existing GPU compilers and improves the optimization performance of GPU compilers.

CN121209967BActive Publication Date: 2026-02-13SHANGHAI BIREN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511772645.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-28
Publication Date
2026-02-13
Estimated Expiration
2045-11-28

AI Technical Summary

Technical Problem

Existing GPU compilers typically only consider localized optimizations during copy propagation, resulting in poor optimization performance.

Method used

By obtaining the control flow graph and working list of the target program, the fixed point is calculated, the basic blocks within the thread bundle are identified, global and local copy propagation is performed, and a security check is conducted until the fixed point is reached and copy propagation stops.

Benefits of technology

It improves the optimization performance of the GPU compiler, reduces the possibility of errors during copy propagation, and fully considers the specific characteristics of the GPU and thread bundle boundaries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121209967B_ABST
    Figure CN121209967B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence chips, in particular to a GPU instruction copy propagation method and device, a storage medium and a program product. The method comprises the following steps: obtaining a control flow graph and a work list of a target program; calculating a fixed point based on the work list and a data flow equation; identifying a thread bundle to which a basic block in the control flow graph belongs; collecting GPU instructions requiring global copy propagation in the basic blocks in each thread bundle; performing safety checking on the basic blocks in each thread bundle to obtain a first checking result; if the first checking result indicates that the checking is passed, performing copy propagation of the GPU instructions in the same thread bundle until the copy propagation is stopped when the fixed point is reached. The method can effectively improve the optimization effect of a GPU compiler.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence chips, in particular to a GPU instruction copy propagation method and device, a storage medium and a program product. BACKGROUND

[0002] With the wide application of GPUs (Graphics Processing Units) in general computing fields, the optimization technology of GPU compilers becomes more and more important. The performance of a GPU program largely depends on the optimization ability of a GPU compiler on an instruction sequence, and instruction replacement (i.e. copy propagation) is a key technology in compiler optimization. However, in the conventional copy propagation scheme, only the copy propagation in a local range is considered when performing copy propagation, which leads to insufficient optimization and poor optimization effect of the GPU compiler. SUMMARY

[0003] Therefore, it is necessary to provide a GPU instruction copy propagation method, device, storage medium and program product to effectively improve the optimization effect of the GPU compiler.

[0004] In a first aspect, the present application provides a GPU instruction copy propagation method, comprising:

[0005] obtaining a control flow graph and a worklist of a target program;

[0006] calculating a fixed point based on the worklist and a data flow equation;

[0007] identifying a thread bundle to which a basic block in the control flow graph belongs;

[0008] collecting GPU instructions requiring global copy propagation in the basic blocks in each thread bundle;

[0009] performing safety checking on the basic blocks in each thread bundle to obtain a first checking result;

[0010] if the first checking result indicates that the checking is passed, performing copy propagation of the GPU instructions in the same thread bundle until the copy propagation is stopped when the fixed point is reached.

[0011] In one embodiment, the obtaining of the control flow graph and the worklist of the target program comprises:

[0012] constructing a control flow graph of a target program, taking a basic block as a node and a control flow as an edge;

[0013] adding the basic blocks in the control flow graph to an initial worklist to obtain a worklist.

[0014] In one embodiment, the calculating the fixed points based on the worklist and dataflow equations comprises:

[0015] selecting a basic block to be processed from the worklist for each basic block in the worklist;

[0016] finding a successor of the basic block to be processed within the thread bundle based on the dataflow equations;

[0017] determining variables alive at the end of the basic block to be processed according to the successor and the dataflow equations;

[0018] if the variables are not changed and the worklist is not empty, returning to the step of selecting a basic block to be processed from the worklist until the worklist is empty, obtaining all the fixed points.

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

[0020] if the variables are changed, updating the variables;

[0021] adding a predecessor of the basic block to be processed to the worklist and returning to the step of selecting a basic block to be processed from the worklist.

[0022] In one embodiment, the propagating the copy of the GPU instruction within the same thread bundle until the fixed point is reached comprises:

[0023] propagating the copy of the GPU instruction within the same thread bundle;

[0024] if the propagation reaches a position where the redefinition of the source register is blocked, the fixed point is reached, and the propagation of the copy of the GPU instruction is stopped.

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

[0026] identifying a loop structure within the same thread bundle;

[0027] detecting whether the redefinition of the source register exists within the loop structure;

[0028] the if the propagation reaches a position where the redefinition of the source register is blocked, the fixed point is reached, and the propagation of the copy of the GPU instruction is stopped comprises:

[0029] if the GPU instruction is located in the loop structure and the redefinition of the source register exists, the fixed point is reached, and the propagation of the copy of the GPU instruction is stopped.

[0030] In one of the embodiments, the identifying the thread bundle to which the basic block in the control flow graph belongs comprises:

[0031] For the stage of global copy propagation, identifying the thread bundle to which the basic block in the control flow graph belongs;

[0032] The method further comprises: for the stage of local copy propagation, collecting, in the basic blocks within each thread bundle, GPU instructions requiring local copy propagation;

[0033] Performing a security check on the basic block in the control flow graph to obtain a second check result;

[0034] If the second check result indicates that the check passes, performing copy propagation on the GPU instructions requiring local copy propagation in the basic block in turn.

[0035] In one of the embodiments, the method further comprises:

[0036] If the second check result indicates that the check fails, skipping the GPU instructions currently subject to local copy propagation.

[0037] In a second aspect, the application further provides a copy propagation device of GPU instructions, comprising:

[0038] An obtaining module, configured to obtain a control flow graph and a work list of a target program;

[0039] A calculating module, configured to calculate a fixed point based on the work list and a data flow equation;

[0040] An identifying module, configured to identify the thread bundle to which the basic block in the control flow graph belongs;

[0041] A collecting module, configured to collect, in the basic blocks within each thread bundle, GPU instructions requiring global copy propagation;

[0042] A checking module, configured to perform a security check on the basic block within each thread bundle to obtain a first check result;

[0043] A propagating module, configured to, if the first check result indicates that the check passes, perform copy propagation on the GPU instructions within the same thread bundle until the copy propagation is stopped when the fixed point is reached.

[0044] In one of the embodiments, the obtaining module is further configured to construct a control flow graph of a target program, taking a basic block as a node and a control flow as an edge; and add the basic block in the control flow graph to an initial work list to obtain a work list.

[0045] In one of the embodiments, the computing module is further configured to: select a basic block to be processed from the worklist for each basic block in the worklist; find a successor basic block of the basic block to be processed in the thread bundle based on a data flow equation; determine a variable active at the end of the basic block to be processed according to the successor basic block and the data flow equation; and return to the step of selecting the basic block to be processed from the worklist until the worklist is empty, and obtain all the fixed points, if the variable does not change and the worklist is not empty.

[0046] In one of the embodiments, the apparatus further comprises:

[0047] an updating module configured to update the variable if the variable changes.

[0048] an adding module configured to add a predecessor basic block of the basic block to be processed to the worklist, and return to the step of selecting the basic block to be processed from the worklist.

[0049] In one of the embodiments, the propagating module is further configured to propagate the copy of the GPU instruction in the same thread bundle, and stop the propagation of the copy of the GPU instruction if the propagation reaches a position where a redefinition of a block is defined.

[0050] In one of the embodiments, the identifying module is further configured to identify a loop structure in the same thread bundle.

[0051] The checking module is further configured to detect whether there is a redefinition of a source register in the loop structure.

[0052] The propagating module is further configured to stop the propagation of the copy of the GPU instruction if the GPU instruction is located in the loop structure and there is the redefinition of the source register.

[0053] In one of the embodiments, the identifying module is further configured to identify a thread bundle to which a basic block in the control flow graph belongs for a global copy propagation stage.

[0054] The collecting module is further configured to collect GPU instructions requiring local copy propagation in the basic blocks in each thread bundle for a local copy propagation stage.

[0055] The checking module is further configured to perform a safety check on the basic blocks in the control flow graph to obtain a second checking result.

[0056] The propagating module is further configured to sequentially propagate the copy of the GPU instruction requiring local copy propagation in the basic blocks if the second checking result indicates that the check passes.

[0057] In one embodiment, the propagation module is further configured to skip the current local copy propagation of the GPU instruction if the second check result indicates a failure of the check.

[0058] In a third aspect, the present application provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the copy propagation method of the GPU instruction when executing the computer program.

[0059] In a fourth aspect, the present application provides a computer readable storage medium, which stores a computer program, and the computer program implements the steps of the copy propagation method of the GPU instruction when executed by a processor.

[0060] In a fifth aspect, the present application provides a computer program product, comprising a computer program, and the computer program implements the steps of the copy propagation method of the GPU instruction when executed by a processor.

[0061] The copy propagation method, device, equipment, medium and program product of the GPU instruction described above, the control flow graph and the work list of a target program are acquired; the fixed point is calculated based on the work list and the data flow equation; the thread bundle to which the basic block in the control flow graph belongs is identified; the GPU instruction requiring global copy propagation is collected in the basic block in each thread bundle, and the use of the instruction in the entire program life cycle is fully considered; the safety check is performed on the basic block in each thread bundle, and after passing the check, the copy propagation of the GPU instruction is performed in the same thread bundle until the copy propagation is stopped when the fixed point is reached, which can effectively reduce or avoid the possibility of error in the copy propagation process, and in addition, the GPU specific characteristics are fully considered, that is, the thread bundle boundary is considered, so that the optimization effect of the GPU compiler can be greatly improved. BRIEF DESCRIPTION OF DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other related drawings can also be obtained without creative labor.

[0063] Figure 1 The flowchart of the copy propagation method of the GPU instruction in one embodiment;

[0064] Figure 2 The schematic diagram of the control flow graph in one embodiment;

[0065] Figure 3Fig. 1 is a schematic diagram of a control flow graph in another embodiment;

[0066] Figure 4 Fig. 2 is a schematic diagram of a flow for calculating a fixed point in an embodiment;

[0067] Figure 5 Fig. 3 is a schematic diagram of a flow for global copy propagation and local copy propagation in an embodiment;

[0068] Figure 6 Fig. 4 is a schematic diagram of a flow for copy propagation of GPU instructions in another embodiment;

[0069] Figure 7 Fig. 5 is a structural block diagram of a copy propagation device for GPU instructions in an embodiment;

[0070] Figure 8 Fig. 6 is a structural block diagram of a copy propagation device for GPU instructions in another embodiment;

[0071] Figure 9 Fig. 7 is an internal structural diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0072] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.

[0073] It should be noted that the terms "first", "second", etc. used in the present application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "include" and "have" and any variations thereof used in the present application are intended to cover non-exclusive inclusion. The term "multiple" used in the present application refers to two or more. The term "and / or" used in the present application refers to one of the options or any combination of multiple options.

[0074] In an exemplary embodiment, as shown in Figure 1 Fig. 1, a copy propagation method of GPU instructions is provided, which can be applied to a terminal or a server with a GPU chip. Taking the case where the method is applied to a terminal for example, the specific implementation is as follows:

[0075] Step 102, obtaining a control flow graph and a worklist of a target program.

[0076] The target program can be a computer program executed by a GPU and needing to be optimized. A control flow graph (CFG) can also be referred to as a control flow diagram, and is an abstract graph data structure used in compilers to represent the possible flow of execution of a process in a graph, and can also reflect the real-time execution process of a process. The work list can be a list for storing basic blocks, and the corresponding basic block is taken from the work list when a fixed point calculation is performed.

[0077] The basic block can be a sequence of instructions executed sequentially in the target program, and has a single entry and exit. The internal instructions of the basic block cannot be interrupted or repeated by external jumps. In the scheme of the present application, the basic block is the basic unit of copy propagation, and is used to analyze the constant value and usage of a variable.

[0078] In one embodiment, the terminal can construct a control flow graph of the target program, with basic blocks as nodes and control flows as edges; add the basic blocks in the control flow graph to an initial work list to obtain a work list.

[0079] In constructing the control flow graph, the terminal can parse the target program to obtain each basic block and the corresponding control flow of the target program, and then construct the control flow graph with the basic blocks as nodes and the control flows as edges. For example, for the following target program, the control flow graph shown in FIG. 1 can be constructed, and the code and the corresponding basic blocks of the target program are as follows: Figure 2

[0080] int ft (int x, int y, int z)

[0081] {

[0082] if (y>1 && z==0) / / basic block 1 and basic block 2

[0083] {

[0084] x=(int)(x / y); / / basic block 3

[0085] }

[0086] if(y==2| x>1) / / basic block 4 and basic block 5

[0087] {

[0088] x=x+1; / / basic block 6

[0089] }

[0090] return x; / / basic block 7

[0091] } ​

[0092] In addition, the terminal can initialize the work list first to obtain an initial work list, and then write the basic blocks into the work list.

[0093] In one embodiment, after the construction of the control flow graph is completed, the terminal can perform validity detection on the control flow graph, such as verifying the consistency between the structure of the control flow graph and the source program (i.e., the target program described above), and if the detection is passed, the subsequent activity analysis process is performed; if the detection is not passed, the control flow graph is cleared, and the construction process of the control flow graph is re-executed.

[0094] In step 104, a fixed point is calculated based on the work list and the data flow equation.

[0095] The data flow equation can be a set of mathematical equations describing how information (such as the value or state of a variable) is generated, transmitted, and extinguished in the control flow graph of a program, and the corresponding equation is as follows:

[0096] liveOut[B] =∪(liveIn[S]);

[0097] liveIn[B] = use[B]∪(liveOut[B] - def[B]);

[0098] Wherein, B represents a basic block, liveOut[B] represents a set of active variables at the exit of the basic block B (i.e., after the last statement of B is executed); S represents a successor basic block of the basic block B, i.e., the next basic block that the control flow can enter after leaving the basic block B, liveIn[S] represents a set of active variables at the entrance of the basic block S (i.e., the successor basic block of the basic block B); liveIn[B] represents a set of active variables at the entrance of the basic block B (i.e., before the first statement of the basic block B is executed); use[B] represents a set of variables that have been used before any definition in the basic block B, if a variable is used in the basic block B, it is active at the entrance of the basic block B; def[B] represents a set of variables that are defined before any use in the basic block B.

[0099] In one embodiment, in the case of selecting global copy propagation, for the stage of global copy propagation, the thread bundle to which the basic block in the control flow graph belongs is identified. In the case of selecting local copy propagation, for the stage of local copy propagation, the thread bundle to which the basic block in the control flow graph belongs is not identified, and the process of local copy propagation is performed.

[0100] In one embodiment, the terminal can select a to-be-processed basic block from the worklist for each basic block in the worklist; find a successor basic block of the to-be-processed basic block in the thread bundle based on the data flow equation; determine a variable active at the end of the to-be-processed basic block according to the successor basic block and the data flow equation; if the variable does not change and the worklist is not empty, return to the step of selecting the to-be-processed basic block from the worklist until the worklist is empty, and obtain all the fixed points.

[0101] In one embodiment, the to-be-processed basic block can be a basic block currently to be processed in the worklist.

[0102] In another embodiment, if the variable changes, the terminal updates the variable; adds a predecessor basic block of the to-be-processed basic block to the worklist, and returns to the step of selecting the to-be-processed basic block from the worklist.

[0103] For example, in combination with Figure 3 and Figure 4 For example, in combination with Figure 3 , the basic blocks B1 to B5 are basic blocks in the same thread bundle (warp), and the corresponding worklist is [B1, B2, B3, B4, B5], and the initial state of the basic blocks is shown in Table 1:

[0104] Table 1

[0105] Basic block use def liveIn liveOut B1 {} {x} {} {} B2 {} {y} {} {} B3 {x} {} {} {} B4 {y} {z} {} {} B5 {z} {} {} {}

[0106] First, initialize liveIn and liveOut of the basic blocks, add the basic blocks to the worklist, and then take out the basic block B from the worklist, and use the data flow equation to iteratively calculate the fixed points, as follows:

[0107] (1) Iteration 1: Process B5 (backward analysis, start from the exit block)

[0108] liveOut[B5] = {}, no successor basic block;

[0109] liveIn[B5] = use[B5]∪(liveOut[B5] - def[B5]) = {z}∪({} - {}) = {z};

[0110] liveIn[B5] changes: {}→{z}, update liveIn[B5] and liveOut[B5], and add predecessors B3 and B4 to the worklist;

[0111] Worklist: [B1, B2, B3, B4];

[0112] (2) Iteration 2: Process B4

[0113] liveOut[B4] = liveIn[B5] = {z} ;

[0114] liveIn[B4] = use[B4]∪(liveOut[B4] - def[B4]) = {y}∪({z} - {z}) ={y} ;

[0115] liveIn[B4] changes: {}→{y}, update liveIn[B4] and liveOut[B4], add predecessor B2 to worklist;

[0116] worklist: [B1, B2, B3] ;

[0117] (3) Iteration 3: process B3

[0118] liveOut[B3] = liveIn[B5] = {z} ;

[0119] liveIn[B3] = use[B3]∪(liveOut[B3] - def[B3]) = {x}∪({z} - {}) = {x,z} ;

[0120] liveIn[B3] changes: {}→{x, z}, update liveIn[B3] and liveOut[B3], add predecessor B2 to worklist;

[0121] worklist: [B1, B2] ;

[0122] (4) Iteration 4: process B2;

[0123] liveOut[B2] = liveIn[B3]∪liveIn[B4] = {x, z}∪{y} = {x, y, z} ;

[0124] liveIn[B2] = use[B2]∪(liveOut[B2] - def[B2]) = {}∪({x, y, z} - {y})= {x, z} ;

[0125] liveIn[B2] changes: {}→{x, z}, update liveIn[B2] and liveOut[B2], add predecessor B1 to worklist;

[0126] worklist: [B1] ;

[0127] (5) Iteration 5: process B1

[0128] liveOut[B1] = liveIn[B2] = {x, z};

[0129] liveIn[B1] = use[B1]∪(liveOut[B1] - def[B1]) = {}∪({x, z} - {x}) ={z};

[0130] The change in liveIn[B1] is: {} → {z}, which updates liveIn[B1] and liveOut[B1]. If there is no predecessor basic block, it can be added.

[0131] Job list: [].

[0132] Step 106: Identify the thread bundle to which the basic block in the control flow graph belongs.

[0133] In this context, a warp is a fundamental unit of execution in the GPU execution model. A warp contains a fixed number of threads that execute concurrently on the same streaming multiprocessor (SM). By identifying the warp to which a basic block belongs, warp boundary constraints are considered, and the GPU's warp execution characteristics are followed. Subsequently, during global copy propagation, global copy propagation occurs within the same warp.

[0134] Step 108: Collect the GPU instructions that need to be globally copied and propagated within the basic blocks of each thread bundle.

[0135] Among them, GPU instructions that require global copying and propagation can be called global copy instructions.

[0136] In one embodiment, during the computation of a fixed point, the terminal can obtain GPU instructions for each basic block in the control flow graph, and on this basis, collect GPU instructions within the same thread bundle that need to be globally copied and propagated.

[0137] Step 110: Perform a security check on the basic blocks within each thread bundle to obtain the first check result.

[0138] The security check can be to check whether a specific variable in a GPU instruction has been redefined, that is, whether the source register corresponding to the variable in the GPU instruction has been redefined. For example, in the GPU instruction b = a, variable a represents the source register (or source operand). Redefinition can mean that the source register has been assigned a new value, such as by reassigning it through another assignment instruction such as a = x + y.

[0139] Step 112: If the first check result indicates that the check is passed, then the GPU instruction copying and propagation will be performed within the same thread bundle until the fixed point is reached and the copying and propagation will stop.

[0140] In one embodiment, the terminal can perform copy propagation of the GPU instructions within the same thread bundle; if the copy propagation reaches a location where the definition of the source register is blocked, a fixed point is reached and the copy propagation of the GPU instructions is stopped.

[0141] For example, during the copy propagation of the GPU instructions within the same thread bundle, it is detected whether the copy propagation reaches a location where the source register is redefined, and if the source register is redefined, a fixed point is reached and the copy propagation of the GPU instructions is stopped.

[0142] In another embodiment, if the copy propagation does not reach a location where the definition of the source register is blocked, the terminal can perform copy propagation of the GPU instructions to a successor basic block.

[0143] In one embodiment, the terminal can identify a loop structure within the same thread bundle; it is detected whether there is a redefinition of the source register within the loop structure; thus, if the GPU instruction is located within the loop structure and there is a redefinition of the source register, a fixed point is reached and the copy propagation of the GPU instructions is stopped.

[0144] In another embodiment, after the terminal identifies a loop structure within the same thread bundle, it can detect whether there is a redefinition of the target register within the loop structure, and if the GPU instruction is located within the loop structure and there is a redefinition of the target register, the copy propagation of the GPU instructions is stopped; if the GPU instruction is located within the loop structure and there is no redefinition of the target register, the copy propagation of the GPU instructions can be continued.

[0145] For example, as in the following code, there is a redefinition of the target register, and the copy propagation needs to be stopped:

[0146] b = a; / / global copy instruction

[0147] b = x + y; / / the target register b is redefined

[0148] c = b + 5; / / cannot be propagated as c = a + 5

[0149] For another example, as in the following code, there is no redefinition of the target register, and the copy propagation can be continued:

[0150] b = a; / / global copy instruction

[0151] c = b + 5; / / can be safely propagated as c = a + 5

[0152] d = b * 2; / / can be safely propagated as d = a * 2

[0153] In one embodiment, for the global copy propagation phase, the thread bundle to which the basic block in the control flow graph belongs is identified; for the local copy propagation phase, GPU instructions requiring local copy propagation are collected from the basic blocks within each thread bundle; a security check is performed on the basic blocks in the control flow graph to obtain a second check result; if the second check result indicates that the check passes, the GPU instructions requiring local copy propagation are sequentially copied and propagated within the basic block. Conversely, if the second check result indicates that the check fails, the GPU instructions currently undergoing local copy propagation are skipped.

[0154] In one embodiment, during the computation of a fixed point, the terminal can obtain GPU instructions for each basic block in the control flow graph. Based on this, it can collect GPU instructions that need to be locally copied and propagated within the basic block, thereby enabling the copying and propagation of GPU instructions within the basic block.

[0155] For example, such as Figure 5 As shown, the propagation phase is selected first. If the global copy propagation phase is selected, the global copy propagation process begins, global copy instructions are collected, and then a global security check is performed. If the security check fails, the current global copy propagation is skipped; if the security check passes, global copy propagation is executed. During the propagation process, it is determined whether the execution reaches the register redefinition location. If the execution reaches the register redefinition location, the current global copy propagation is stopped; if the execution does not reach the register redefinition location, the copy propagation of the subsequent basic block continues.

[0156] Furthermore, if the local copy propagation phase is selected (i.e., the local copy propagation phase), the local copy propagation process begins. Local copy instructions are identified, and then a security check is performed on the basic block. If the security check fails, the local copy instruction is skipped; if the security check passes, copy propagation is performed within the basic block, replacing the used variables. Additionally, during propagation, it is determined whether the execution reaches the location where the source or destination register is redefined. If the redefined location is reached, the current local copy propagation stops; otherwise, the source register is substituted with variables.

[0157] In one embodiment, during the copying and propagation process, the terminal can also collect instructions to be deleted (i.e. GPU instructions to be deleted), then perform a deletability check and activity tracking. If the GPU instruction is inactive, the instruction can be deleted.

[0158] As an example, here we combine Figure 6 The scheme of this application is described in detail as follows:

[0159] First, a control flow graph is constructed, and it is determined whether the control flow graph is valid, i.e., whether the structure of the control flow graph is consistent with the source program. If not, the control flow graph is cleared, and the control flow graph is reconstructed. If yes, an activity analysis is initialized, a definition and use relationship is calculated, a fixed point is calculated using a data flow equation, a copy propagation pass (i.e., a functional module for copy propagation) is executed, and then a cache is cleared, a loop structure in a warp is calculated, a global copy instruction is collected, a feasibility check, such as a safety check, is performed, and after passing the check, global copy propagation is performed to replace a global variable. After the global copy propagation is completed, local copy propagation can be performed.

[0160] During the copy propagation, a dead code elimination pass (i.e., a functional module for eliminating dead code instructions) can be executed, and then a to-be-deleted instruction is collected, a deletability check is performed, and an enhanced activity tracking is performed to confirm that the conditions are met, and the to-be-deleted instruction is deleted.

[0161] In the above embodiments, a control flow graph and a worklist of a target program are obtained, a fixed point is calculated based on the worklist and a data flow equation, a thread bundle to which a basic block in the control flow graph belongs is identified, a GPU instruction that needs global copy propagation is collected in the basic block in each thread bundle, taking into full account the use of the instruction in the entire program life cycle, a safety check is performed on the basic block in each thread bundle, and after passing the check, copy propagation of the GPU instruction is performed in the same thread bundle until the copy propagation is stopped when the fixed point is reached, which can effectively reduce or avoid the possibility of error during copy propagation, and in addition, GPU-specific characteristics are fully considered, i.e., the thread bundle boundary is considered, so the optimization effect of the GPU compiler can be greatly improved.

[0162] It should be understood that although each step in the flowchart involved in each of the above embodiments is displayed in sequence according to the arrow, these steps are not necessarily executed in the order indicated by the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in each of the above embodiments can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or steps or stages in other steps. It can be understood that the steps in different embodiments can be freely combined as needed, and various non-contradictory schemes formed by the combination are within the scope of protection of the present application.

[0163] Based on the same inventive concept, the embodiments of the present application further provide a GPU instruction copy propagation device for implementing the GPU instruction copy propagation method described above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more GPU instruction copy propagation device embodiments provided below can refer to the limitations of the GPU instruction copy propagation method in the above text, which will not be repeated here.

[0164] In one exemplary embodiment, as shown in Figure 7 A GPU instruction copy propagation device is provided, comprising: an acquisition module 702, a calculation module 704, an identification module 706, a collection module 708, an inspection module 710, and a propagation module 712, wherein:

[0165] The acquisition module 702 is configured to acquire a control flow graph and a worklist of a target program.

[0166] The calculation module 704 is configured to calculate fixed points based on the worklist and a data flow equation.

[0167] The identification module 706 is configured to identify a thread bundle to which a basic block in the control flow graph belongs.

[0168] The collection module 708 is configured to collect GPU instructions requiring global copy propagation in the basic blocks within each thread bundle.

[0169] The inspection module 710 is configured to perform safety inspection on the basic blocks within each thread bundle to obtain a first inspection result.

[0170] The propagation module 712 is configured to, if the first inspection result indicates that the inspection is passed, perform copy propagation of the GPU instructions within the same thread bundle until the copy propagation is stopped when a fixed point is reached.

[0171] In one embodiment, the acquisition module 702 is further configured to construct a control flow graph of the target program, taking a basic block as a node and a control flow as an edge; and add the basic blocks in the control flow graph to an initial worklist to obtain the worklist.

[0172] In one embodiment, the calculation module 704 is further configured to, for each basic block in the worklist, select a to-be-processed basic block from the worklist; find a successor basic block of the to-be-processed basic block within a thread bundle based on a data flow equation; determine a variable that is alive at the end of the to-be-processed basic block according to the successor basic block and the data flow equation; and if the variable has not changed and the worklist is not empty, return to the step of selecting the to-be-processed basic block from the worklist until the worklist is empty, to obtain all fixed points.

[0173] In one embodiment, as shown in Figure 8As shown, the apparatus further includes:

[0174] The updating module 714 is configured to update the variable if the variable is changed.

[0175] The adding module 716 is configured to add the predecessor basic block of the to-be-processed basic block into the work list, and return the step of selecting the to-be-processed basic block from the work list.

[0176] In one of the embodiments, the propagation module 712 is further configured to perform copy propagation of the GPU instruction in the same thread bundle; if the copy propagation reaches a position where a redefinition block is redefined, a fixed point is reached, and the copy propagation of the GPU instruction is stopped.

[0177] In one of the embodiments, the identification module 706 is further configured to identify a loop structure in the same thread bundle.

[0178] The checking module 710 is further configured to detect whether there is a redefinition of a source register in the loop structure.

[0179] The propagation module 712 is further configured to, if the GPU instruction is located in the loop structure and there is a redefinition of the source register, reach a fixed point, and stop the copy propagation of the GPU instruction.

[0180] In one of the embodiments, the identification module 706 is further configured to, for a global copy propagation stage, identify a thread bundle to which a basic block in a control flow graph belongs.

[0181] The collection module 708 is further configured to, for a local copy propagation stage, collect, in the basic blocks in each thread bundle, a GPU instruction that needs local copy propagation.

[0182] The checking module 710 is further configured to perform a safety check on the basic blocks in the control flow graph, to obtain a second checking result.

[0183] The propagation module 712 is further configured to, if the second checking result indicates that the check is passed, sequentially perform copy propagation on the GPU instruction that needs local copy propagation in the basic block.

[0184] In one of the embodiments, the propagation module 712 is further configured to, if the second checking result indicates that the check is not passed, skip the current local copy propagation of the GPU instruction.

[0185] The GPU instruction copy propagation method, device, equipment, storage medium and program product, obtain a control flow graph and a worklist of a target program; calculate a fixed point based on the worklist and a data flow equation; identify a thread bundle to which a basic block in the control flow graph belongs; collect GPU instructions that need global copy propagation in the basic blocks in each thread bundle, fully considering the use of the instructions in the entire program life cycle; perform safety checking on the basic blocks in each thread bundle, and after passing the checking, perform copy propagation of the GPU instructions in the same thread bundle, and stop the copy propagation when the fixed point is reached, which can effectively reduce or avoid the possibility of errors in the copy propagation process, and further fully consider the GPU specific characteristics, that is, the thread bundle boundary, so that the optimization effect of the GPU compiler can be greatly improved.

[0186] The modules in the GPU instruction copy propagation device can be implemented by software, hardware and combinations thereof in whole or in part. The modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operations corresponding to the modules.

[0187] In an exemplary embodiment, a computer device, which can be a server, is provided, including a processor, a memory, an input / output interface (I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store data such as a target program to be optimized, a control flow graph and a basic block. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with external terminals through a network connection. The computer program is executed by the processor to implement a GPU instruction copy propagation method.

[0188] In an exemplary embodiment, a computer device, which can be a terminal, is provided, and its internal structure diagram can be as shown in Figure 9As shown in the figure. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through the system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with the external terminal in a wired or wireless manner. The wireless manner can be realized through WIFI, mobile cellular network, near field communication (Near Field Communication, NFC) or other technologies. The computer program is executed by the processor to realize a GPU instruction replication and propagation method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.

[0189] Those skilled in the art can understand that, Figure 9 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.

[0190] In one exemplary embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the GPU instruction replication and propagation method.

[0191] In one embodiment, a computer readable storage medium is provided, having a computer program stored thereon, and the computer program is executed by the processor to implement the steps of the GPU instruction replication and propagation method.

[0192] In one embodiment, a computer program product is provided, including a computer program, and the computer program is executed by the processor to implement the steps of the GPU instruction replication and propagation method.

[0193] 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. The computer program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above-mentioned embodiment methods. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. The non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, 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. The volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, the RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., without being limited thereto.

[0194] The technical features of the above embodiments can be combined in any manner. To make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combinations of the technical features do not exist contradictions, they should be considered as the scope of the present application.

[0195] The above-described embodiments are merely illustrative of several embodiments of the present application, and the description is relatively specific and detailed, but should not be understood as a limitation on the scope of the patent. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of protection of the present application should be subject to the appended claims.

Claims

1. A method for copying and propagating GPU instructions, characterized in that, The method includes: Obtain the control flow graph and work list of the target program; The fixed point is calculated based on the work list and data flow equation; Identify the thread bundle to which the basic block in the control flow graph belongs; Within the basic blocks of each thread bundle, collect GPU instructions that need to be globally copied and propagated; A security check is performed on the basic blocks within each thread bundle to obtain the first check result; If the first check result indicates that the check is passed, then the GPU instruction is copied and propagated within the same thread bundle until the fixed point is reached and the copying and propagation stops.

2. The method according to claim 1, characterized in that, The process of obtaining the control flow graph and working list of the target program includes: Construct a control flow graph for the target program, with basic blocks as nodes and control flow as edges; The basic blocks in the control flow graph are added to the initial work list to obtain the work list.

3. The method according to claim 1, characterized in that, The calculation of the fixed point based on the working list and data flow equations includes: For each basic block in the work list, select the basic block to be processed from the work list; The successor basic block of the basic block to be processed within the thread bundle is found based on the data flow equation; Based on the subsequent basic block and the data flow equation, determine the variables that are active at the end of the basic block to be processed; If the variable has not changed and the work list is not empty, then return to the step of selecting the basic block to be processed from the work list until the work list is empty, thus obtaining all the fixed points.

4. The method according to claim 3, characterized in that, The method further includes: If the variable changes, then the variable is updated; Add the predecessor basic block of the basic block to be processed to the working list, and return to the step of selecting the basic block to be processed from the working list.

5. The method according to claim 1, characterized in that, The process of copying and propagating the GPU instructions within the same thread bundle until the fixed point is reached includes: The GPU instructions are copied and propagated within the same thread bundle; If the copy propagation reaches the point where the blocking is redefined, then the fixed point is reached and the copy propagation of the GPU instruction stops.

6. The method according to claim 5, characterized in that, The method further includes: Loop structures are identified within the same thread bundle; Detect whether there is a redefinition of the source register within the loop structure; The step of stopping the copying and propagation of GPU instructions if the copying and propagation reaches the redefinition blocking point and reaches the fixed point includes: If the GPU instruction is located in the loop structure and there is a redefinition of the source register, then the fixed point is reached and the copying and propagation of the GPU instruction stops.

7. The method according to claim 1, characterized in that, The process of identifying the thread bundle to which the basic block in the control flow graph belongs includes: For the global replication propagation phase, identify the thread bundle to which the basic block in the control flow graph belongs; The method further includes: for the local copy propagation phase, collecting GPU instructions that need to be locally copied and propagated in the basic blocks within each thread bundle; A security check is performed on the basic blocks in the control flow graph to obtain a second check result; If the second check result indicates that the check passes, then the GPU instructions that need to be locally copied and propagated are copied and propagated sequentially within the basic block.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Multi-phase field model parallel computing system and method based on GPU

    CN116051358A

  • Reachability query method and system based on GPU acceleration

    CN120011601A