Variable recalculation method, system and equipment based on data flow analysis and medium
By using data flow analysis and variable recalculation methods, the memory bandwidth pressure and memory access latency issues of thread coarsening synchronization on the SIMD architecture are resolved, thereby improving performance and resource utilization efficiency.
Patent Information
- Application Number
- CN202511704158.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-19
- Publication Date
- 2026-02-24
AI Technical Summary
Existing technologies for thread coarsening synchronization on SIMD architectures suffer from frequent array accesses that increase memory bandwidth pressure and memory access latency, compromising memory access predictability and leading to performance degradation.
By analyzing data flow, Boolean attributes are set on the ternary grid, cross-subkernel variables are identified and classified into uniform, recomputable and non-recomputable variables, respectively, and stack-based or array-based storage is allocated. The calculation sequence of recomputable variables is recorded, and recomputation is performed to replace memory access.
It reduces the scope and size of context arrays, lowers memory bandwidth pressure and access latency, preserves the predictability of memory access, improves compiler optimization and vectorization performance, and achieves efficient resource utilization.
Smart Images

Figure CN121560385A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of heterogeneous parallel programming technology, and in particular to a variable recalculation method, system, device and medium based on data flow analysis. Background Technology
[0002] Mainstream parallel programming models (such as CUDA and OpenCL) typically employ the SPMD (Single Program Multiple Data) model, which naturally maps to the parallel execution of large-scale logical threads (work items) on SIMT (Single Instruction Multiple Threads) hardware such as GPUs, and ensures semantic consistency through hardware synchronization primitives (such as barriers). However, SIMD architectures (such as CPUs, multi-core DSPs, and some dedicated accelerators) do not possess such abundant hardware thread resources. Directly allocating a separate thread to each logical work item would result in excessive scheduling and synchronization overhead, leading to a significant performance degradation.
[0003] To address this, compilers and runtimes typically employ thread coarsening techniques, packaging multiple logical work items into a work-item loop and simulating their sequential execution on a hardware thread or SIMD vector unit. In this model, achieving proper synchronization becomes a critical challenge. GPU hardware usually has efficient built-in barrier mechanisms, while non-SIMT devices must simulate synchronization semantics in software. A common approach is to divide the kernel program into multiple sub-kernels based on synchronization points, with each sub-kernel constructing its own work-item loop, and the sub-kernels executing sequentially according to the synchronization points. To maintain synchronization semantics, the local state of each logical work item needs to be preserved during implementation. Existing methods preserve work-item state by expanding work-item private variables whose lifecycles span multiple sub-kernels into context arrays, with the array index determined by the work-item ID.
[0004] However, while this variable expansion mechanism ensures correctness, it also introduces significant performance drawbacks. Since each logical work item needs to maintain independent private variables in the context array, frequent array accesses inevitably increase memory bandwidth pressure, especially on architectures lacking efficient caching mechanisms, where access latency is even more severe. Furthermore, the array indices introduced by variable expansion often lead to indirect access, compromising the predictability of memory accesses and thus reducing the compiler's potential optimization space in areas such as loop optimization and vectorization. In addition, storing the context array also incurs additional resource consumption and performance burden. Summary of the Invention
[0005] Therefore, it is necessary to provide a variable recalculation method, system, device, and medium based on data flow analysis that can reduce redundant storage and memory access operations to address the above-mentioned technical problems.
[0006] A variable recalculation method based on data flow analysis, the method comprising: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0007] Cross-subkernel variables are identified and classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0008] The first data structure set is constructed by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0009] Based on the first data structure set, code transformation is performed when creating the work item loop, completing the recalculation and expansion of variables.
[0010] A variable recalculation system based on data flow analysis, the system comprising: The variable attribute determination module is used to set the Boolean attribute on the ternary cell of the recalculation seed, and propagate the Boolean attribute according to the preset instruction type so that the Boolean attribute is unified through the cell union operation at the data control flow merging point to obtain the recalculation determination result of each variable.
[0011] The classification module is used to identify cross-subkernel variables. Cross-subkernel variables are classified according to the recomputability determination result to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0012] The data structure set construction module is used to construct the first data structure set by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0013] The recalculation module is used to perform code transformation based on the first data structure set when creating a work item loop, and to complete the recalculation and expansion of variables.
[0014] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0015] Cross-subkernel variables are identified and classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0016] The first data structure set is constructed by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0017] Based on the first data structure set, code transformation is performed when creating the work item loop, completing the recalculation and expansion of variables.
[0018] A computer-readable storage medium having a computer program stored thereon, the computer program performing the following steps when executed by a processor: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0019] Cross-subkernel variables are identified and classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0020] The first data structure set is constructed by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0021] Based on the first data structure set, code transformation is performed when creating the work item loop, completing the recalculation and expansion of variables.
[0022] The aforementioned variable recomputation method, system, device, and medium based on data flow analysis first accurately determines variable recomputability through ternary galvanic attribute propagation and merging operations, providing a basis for differentiated processing. For cross-sub-kernel variables, they are classified into three categories based on the determination results: uniform, recomputable, and non-recomputable. Uniform variables are directly allocated to stack variables, avoiding array storage overhead; recomputable variables are recorded with a calculation sequence, replacing memory access with recomputation, completely eliminating their storage and memory access requirements; only non-recomputable variables are allocated to stack arrays, and the array size and access frequency are reduced through the ordered management of the first data structure set. This classification processing mechanism reduces the scope and size of the context array from the root, reducing memory bandwidth pressure and access latency. At the same time, stack variable and ordered array access retain the predictability of memory access, providing space for compiler loop optimization, vectorization, etc. Finally, through code transformation of the work item loop, the differentiated logic and recomputation logic are seamlessly integrated, maximizing the reduction of redundant storage and memory access operations while ensuring variable consistency, achieving the dual goals of performance improvement and efficient resource utilization. Attached Figure Description
[0023] Figure 1 This is a flowchart of a variable recalculation method based on data flow analysis in one embodiment; Figure 2 This is a flowchart of a recomputable data stream analysis and transformation framework for thread-coarsened synchronization in one embodiment. Figure 3 In one embodiment, the attribute lattice and transfer function for data flow analysis are recalculated; Figure 4 This document describes the classification and corresponding processing of variable attributes in one embodiment. Figure 5 Here is a work item loop diagram after reconstructing the PHI instruction control flow in one embodiment; Figure 6 This is a structural diagram of a variable recalculation system based on data flow analysis in one embodiment; Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0025] In one embodiment, such as Figure 1 As shown, a variable recalculation method based on data flow analysis is provided, including the following steps: Step 102: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0026] Step 104: Identify cross-subkernel variables. Cross-subkernel variables are classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0027] Step 106: Construct the first data structure set by allocating variables on the stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on the stack for non-recalcible variables.
[0028] Step 108: Based on the first data structure set, code transformation is performed when creating the work item loop to complete the recalculation and expansion of variables.
[0029] In the aforementioned variable recomputation method based on data flow analysis, the recomputability of variables is first accurately determined through ternary galvanic attribute propagation and merging operations, providing a basis for differentiated processing. For cross-sub-kernel variables, they are classified into three categories according to the determination results: uniform, recomputable, and non-recomputable. Uniform variables are directly allocated to stack variables, avoiding array storage overhead; recomputable variables are recorded through calculation sequences, replacing memory access with recomputation, completely eliminating their storage and memory access requirements; only non-recomputable variables are allocated to stack arrays, and the array size and access frequency are reduced through the ordered management of the first data structure set. This classification mechanism reduces the scope and size of the context array from the root, reducing memory bandwidth pressure and access latency. At the same time, stack variables and ordered array access retain the predictability of memory access, providing space for compiler loop optimization, vectorization, etc. Finally, through code transformation of the work item loop, the differentiated logic and recomputation logic are seamlessly integrated, maximizing the reduction of redundant storage and memory access operations while ensuring variable consistency, achieving the dual goals of performance improvement and efficient resource utilization.
[0030] In one embodiment, a Boolean attribute is set on the ternary cell of the recomputable seed. The Boolean attribute is propagated according to a preset instruction type. Specifically: if the instruction type is a logical or arithmetic instruction without side effects, then the variable is marked as recomputable when all operands are recomputable. If the instruction type is a Phi instruction, then the branch predicates of the operands and all predecessor basic blocks are checked. Only when all operands and branch predicates are recomputable is the variable marked as recomputable. If the instruction type is an instruction with side effects, then the variable is marked as non-recomputable.
[0031] In one embodiment, the Boolean attributes are: unknown, recomputable, and non-recomputable. The recomputable seed is a constant, a uniform variable, or a work item ID variable.
[0032] In one embodiment, identifying cross-subkernel variables is specifically as follows: if there is no barrier on any control flow path from the definition of the variable to its use, or if there is a barrier on one of the paths from the definition of the variable to its use and the instruction type of the variable is a Phi instruction and the preceding basic block corresponding to the Phi instruction does not belong to the subkernel where the instruction using the variable is located, then the variable is a non-cross-subkernel variable. Otherwise, the variable is a cross-subkernel variable.
[0033] In one embodiment, after creating stack memory allocation instructions for uniform variables, local variables are allocated on the stack, and the mapping between uniform variables and stack memory allocation instructions is saved in AllocaMap. The computation sequence of recomputable variables is recorded. Starting with each recomputable variable, it is added to the working list. Variables to be processed are sequentially retrieved from the working list, and their operands are recursively judged. Computation instructions are collected until the list is empty. The working list is updated based on the judgment result, and the mapping between recomputable variables and the corresponding set of computation instructions is saved in ReComputeMap. Stack memory allocation instructions are created to expand the array of non-recomputable variables, allocating an array the size of the working group. Each element corresponds to a private variable for each working item, and the mapping between non-recomputable variables and stack memory allocation instructions is saved in AllocaMap. A first data structure set is constructed based on AllocaMap and ReComputeMap.
[0034] In one embodiment, the operands of the variable to be processed are recursively evaluated. If the operand is a uniform variable, it is not added to the working list, and the working list is updated. If the operand does not exist in AllocaMap, a stack memory allocation instruction is created for the operand, and mapped and saved to AllocaMap. If the operand is the work item ID variable, it is not added to the working list, and the working list is updated. If the operand is a non-uniform instruction and not a work item ID variable, after adding it to the working list, it is determined whether the instruction of the operand is a Phi instruction. If the instruction of the operand is a Phi instruction, a PhiPathMap is established to record the mapping relationship between Phi instructions and Phil instruction control flow paths, and a BlockInstsMap is used to record the computation instructions associated with each basic block on the control flow path. If the instruction of the operand is not a Phi instruction, the operand is added to the ComputeSet set, and the remaining operands of the variable to be processed are recursively evaluated. During the recursive traversal of the operands of Phi instructions and the branch conditions of the predecessor basic blocks, if the current instruction is within the control flow path, the mapping between the operand and the corresponding basic block is recorded in BlockInstsMap and added to the working list. If it is not within the path, the operand is added to the ComputeSet set and added to the working list. The execution cost of each instruction in the computation sequence is continuously accumulated to obtain the recomputation cost of the variables corresponding to the operands. The mapping between the variables determined to be subject to recomputation optimization and the computation instruction set and ComputeSet is recorded in ReComputeMap until the list is empty. Based on the judgment result, the working list is updated and stored in the recomputable set.
[0035] In one embodiment, based on the first data structure set, for each sub-kernel, a loop preamble block is created before the work item loop to load uniform variables from local variables on the stack, and a basic block is added after the innermost loop header to load non-recomputable variables from an array on the stack. Before processing other recomputable instructions, the control flow structure of the Phi instructions is restored first. Then, the ReComputeMap is traversed, and the computation sequence for each recomputable variable is copied to the InnermostBlock. The use of variables within the work item loop is replaced with the recomputation results, completing the recomputation and expansion of the variables.
[0036] In one embodiment, such as Figure 2 The diagram shows a flowchart of a recomputational data flow analysis and transformation framework based on thread-coarsened synchronization. The specific steps are as follows: Step 1: Perform iterative data flow analysis on the kernel function control flow graph to obtain the recomputability property of each variable.
[0037] Specifically, such as Figure 3As shown, in the SSA representation of the control flow graph, Boolean attributes are established on ternary cells for each variable, with values ranging from unknown, recalculated, and non-recalculated. Initially, constants, uniform variables, and work item ID variables are directly marked as recalculated to serve as the seed set for the analysis.
[0038] Furthermore, a propagation rule for recomputable properties is defined. During iterative propagation, variable properties are updated based on different instruction types. When the instruction is an arithmetic or logical operation without side effects, the result is also marked as recomputable as long as all its operands are recomputable. When the instruction is a Phi instruction, in addition to checking all operands, it is also necessary to verify whether the branch predicates of the predecessor basic block are recomputable. Only when all conditions are met is the Phi instruction marked as recomputable. If the instruction is a memory access, atomic operation, or external function call, which may bring side effects, it is marked as non-recomputable. Through this propagation rule, this invention can progressively cover the recomputability of all variables.
[0039] Furthermore, an iterative working list algorithm is employed to continuously propagate and update variable properties across the finite lattice. The analysis converges to a fixed point when the sets of entry and exit points for all basic blocks no longer change. At this point, the recomputability of each variable has been stably determined.
[0040] Step 2: Determine cross-subkernel variables. Based on the recalculation analysis results, cross-subkernel variables are divided into three categories: uniform variables, recalcible variables, and non-recalculation variables.
[0041] Specifically, the kernel functions are traversed, and each instruction is checked to see if it meets the following two conditions: 1) There are no barriers on any control flow path from the instruction definition to its use; 2) Although a barrier exists on a certain path from the instruction definition to its use, the variable being used is a Phi instruction, and the predecessor basic block of the Phi instruction corresponding to that use does not belong to the subkernel where that use is located. Instructions that meet the above conditions are non-subkernel cross-instructions and do not require further analysis.
[0042] Furthermore, for cross-subkernel variables, consistency analysis is first used to determine whether they are uniform. If v is not a uniform variable, further recalculation analysis is conducted to determine whether v can be recalculated. Figure 4 As shown, all cross-kernel variables are ultimately divided into three categories: uniform variables, recomputable variables, and non-recomputable variables.
[0043] Step 3: Allocate variables on the stack for uniform variables, record the calculation sequence of recalculated variables, allocate arrays on the stack for non-recalculated variables, and construct the first data structure set.
[0044] Specifically, a stack memory allocation instruction is created for the uniform variable to allocate local variables on the stack to ensure the correctness of its value setting and use in multiple sub-kernels, and the mapping between the uniform variable and the stack memory allocation instruction is saved in AllocaMap.
[0045] Furthermore, the computation sequence of recomputable variables is recorded, and the recomputation cost is accumulated to determine whether recomputation optimization should be performed. The recording process uses a working list mechanism. Starting with each variable requiring recomputation, it is added to the working list. Then, variables in the list are retrieved and processed sequentially, and their operands are recursively evaluated until the working list is empty. If the operand is a uniform variable, it is not added to the working list. If the operand does not exist in the AllocaMap, a stack memory allocation instruction is created for it, and the mapping is saved to the AllocaMap. If the operand is a work item ID, it is not added to the working list. If the operand is a non-uniform instruction and not a work item ID, it is added to the working list, and it is further determined whether the instruction is a Phi instruction.
[0046] Furthermore, for Phi instructions, a PhiPathMap is created to record the mapping relationship between Phi instructions and their control flow paths, and a BlockInstsMap is created to record each basic block on the control flow path and its associated computation instructions. During the recursive traversal of the operands of Phi instructions and the branch conditions of the predecessor basic blocks, if the current instruction is within the control flow path, its mapping to the corresponding basic block is recorded in the BlockInstsMap and added to the working list; if it is not within the path, it is added to the ComputeSet set and added to the working list. If it is not a Phi instruction, it is added to the ComputeSet set, and the recursion continues for its operands.
[0047] Furthermore, throughout the recursive process, the execution cost of each instruction in the computation sequence is continuously accumulated to obtain the recomputation cost of the variable. Finally, after comparing this cost with the memory access latency, it is decided whether to perform recomputation optimization. For variables determined to undergo recomputation optimization, their mapping to the computation instruction set ComputeSet is recorded in ReComputeMap.
[0048] Furthermore, the non-recomputable variables are expanded into arrays, and stack memory allocation instructions are created to allocate on-stack arrays for them. These non-recomputable variables include recomputable variables for which recomputation is costly. The array size is the workgroup size, and each element corresponds to a private variable for each work item. The mapping between variables and stack memory allocation instructions is saved in AllocaMap.
[0049] Step 4: Based on the first data structure set, complete the code transformation when creating the work item loop to achieve recalculation and variable expansion.
[0050] Specifically, for each sub-kernel, a PreBlock is created before the work item loop to load uniform variables from local variables on the stack. An InnermostBlock is added after the innermost loop header to load non-recomputable variables from an array on the stack. The AllocaMap is traversed; if the stack memory allocation instruction does not allocate an array, a load instruction is created in the PreBlock to load the uniform variable from stack memory. Otherwise, in the InnermostBlock, pointers to the corresponding elements are retrieved from the context array using the loop iteration variable as an index, and the variables corresponding to each work item are loaded from stack memory based on these pointers.
[0051] Furthermore, before processing other recomputable instructions, the control flow structure of the Phi instructions is restored first. Specifically, for each Phi instruction, a dedicated basic block is first created as its "convergence point," and the Phi instructions are copied to the convergence point. Then, based on the control flow path recorded in PhiPathMap, a corresponding new block is generated for each basic block on the path. Subsequently, the branch instructions of each basic block on the original path are extracted from BlockInstsMap and copied to the newly created basic block, restoring the control relationships between the basic blocks on the control flow path, and the corresponding computation instructions are copied within each basic block, thereby restoring the complete control flow logic. Figure 5 As shown, the control flow path is inserted into the original work item loop as a whole. The divergence point is set as the direct successor of the original InnermostBlock, while the convergence point becomes the new InnermostBlock, providing the correct control flow basis for subsequent variable recomputation. The ReComputeMap is traversed, and for each recomputable variable, its computation sequence is copied to the InnermostBlock. The usage of the variable within the work item loop is then replaced with the recomputation result.
[0052] It is worth noting that replacing the traditional array expansion method with recomputation significantly optimizes the execution performance of thread coarsening synchronization. First, it reduces read / write operations on large-scale context arrays, fundamentally lowering storage and access overhead. Second, it avoids disrupting memory access regularity through indirect array indexing, preserving the compiler's potential advantages in loop optimization and vectorization. Third, by reducing the dimension and size of the context array, it effectively alleviates storage space pressure in large-scale parallel scenarios. The recomputability determination problem is formalized into a data flow analysis framework, systematically solving the problem of variable recomputability in a globally consistent manner. This framework possesses formalization, convergence, and scalability. By iteratively solving for fixed points on a finite lattice using a working list, it ensures stable and reliable determination results even in complex control flow scenarios. Furthermore, this method is universal and can be extended to the migration and optimization of all SPMD-based parallel programming models, including OpenCL and CUDA, on CPUs, multi-core DSPs, and other non-SIMT architectures. In summary, the recomputation data flow analysis and transformation framework provides an efficient, universal, and scalable implementation mechanism for thread coarsening synchronization.
[0053] It should be understood that, although Figures 1-2 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figures 1-2 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0054] In one embodiment, such as Figure 6 As shown, a variable recalculation system based on data flow analysis is provided, including: a variable attribute determination module 602, a classification module 604, a data structure set construction module 606, and a recalculation module 608, wherein: The variable attribute determination module 602 is used to set the Boolean attribute on the ternary cell of the recalculation seed, and propagate the Boolean attribute according to the preset instruction type so that the Boolean attribute is unified at the data control flow merging point through the cell union operation to obtain the recalculation determination result of each variable.
[0055] The classification module 604 is used to identify cross-subkernel variables. Cross-subkernel variables are classified according to the recomputability determination result to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0056] The data structure set construction module 606 is used to construct the first data structure set by allocating variables on the stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on the stack for non-recalcible variables.
[0057] The recalculation module 608 is used to perform code transformation based on the first data structure set when creating a work item loop, and to complete the recalculation and expansion of variables.
[0058] Specific limitations regarding the variable recalculation system based on data flow analysis can be found in the limitations of the variable recalculation method based on data flow analysis above, and will not be repeated here. Each module in the aforementioned variable recalculation system based on data flow analysis can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.
[0059] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When executed by the processor, the computer program implements a variable recalculation method based on data flow analysis. The display screen can be an LCD screen or an e-ink display screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0060] Those skilled in the art will understand that Figures 6-7 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device to which the present invention is applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0061] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to perform the following steps: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0062] Cross-subkernel variables are identified and classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0063] The first data structure set is constructed by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0064] Based on the first data structure set, code transformation is performed when creating the work item loop, completing the recalculation and expansion of variables.
[0065] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor: Set the Boolean attribute on the ternary cell of the recomputable seed, propagate the Boolean attribute according to the preset instruction type, so that the Boolean attribute is unified at the data control flow merging point through the cell union operation, and obtain the recomputability determination result of each variable.
[0066] Cross-subkernel variables are identified and classified according to the recomputability determination results to obtain uniform variables, recomputable variables, and non-recomputable variables.
[0067] The first data structure set is constructed by allocating variables on a stack for uniform variables, recording the calculation sequence of recalcible variables, and allocating arrays on a stack for non-recalcible variables.
[0068] Based on the first data structure set, code transformation is performed when creating the work item loop, completing the recalculation and expansion of variables.
[0069] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0070] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.
[0071] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.
Claims
1. A variable recalculation method based on data flow analysis, characterized in that, The method includes: Set Boolean attributes on the ternary lattice of the recomputable seed, propagate the Boolean attributes according to the preset instruction type, so that the Boolean attributes are unified at the data control flow merging point through the union operation of the lattice, and obtain the recomputability determination result of each variable; Identify cross-subkernel variables, which are classified according to the recomputability determination result to obtain uniform variables, recomputable variables, and non-recomputable variables; A first data structure set is constructed by allocating variables on a stack to the uniform variables, recording the calculation sequence of the recomputable variables, and allocating arrays on a stack to the non-recomputable variables; Based on the first data structure set, code transformation is performed when creating the work item loop to complete the recalculation and expansion of variables.
2. The method according to claim 1, characterized in that, Define Boolean properties on the ternary cell of the recomputable seed, and propagate these Boolean properties according to a preset instruction type, including: A Boolean attribute is set on the ternary cell of the recomputable seed. The Boolean attribute is propagated according to a preset instruction type. Specifically, if the instruction type is a logical or arithmetic instruction without side effects, the determination result of the variable is marked as recomputable when all operands are recomputable. If the instruction type is a Phi instruction, the branch predicates of the operands and all predecessor basic blocks are checked. Only when all operands and branch predicates are recomputable is the determination result of the variable under the Phi instruction marked as recomputable. If the instruction type is an instruction with side effects, the determination result of the variable is marked as non-recomputable.
3. The method according to claim 2, characterized in that, The Boolean properties are: unknown, recomputable, and non-recomputable. The recomputable seed is a constant, a uniform variable, and a work item ID variable.
4. The method according to claim 3, characterized in that, Identify cross-subkernel variables, including: Identifying cross-subkernel variables is specifically as follows: if there is no barrier on any control flow path from the definition of the variable to its use, or if there is a barrier on one of the paths from the definition of the variable to its use and the instruction type of the variable is a Phi instruction and the predecessor basic block corresponding to the Phi instruction does not belong to the subkernel where the instruction using the variable is located, then the variable is a non-cross-subkernel variable; otherwise, the variable is a cross-subkernel variable.
5. The method according to claim 4, characterized in that, A first data structure set is constructed by allocating variables on a stack to the uniform variables, recording the calculation sequence of the recomputable variables, and allocating arrays on a stack to the non-recomputable variables, including: After creating a stack memory allocation instruction for the uniform variable, local variables are allocated on the stack, and the mapping between the uniform variable and the stack memory allocation instruction is saved in AllocaMap. Record the calculation sequence of the recomputable variable. Starting with each recomputable variable, add it to the working list, then take out the variables to be processed in the working list in sequence, recursively judge the operands of the variables to be processed, collect calculation instructions, until the list is empty, update the working list according to the judgment result, and save the mapping between the recomputable variable and the corresponding set of calculation instructions to ReComputeMap. Create a stack memory allocation instruction to expand the array of the non-recomputable variables, allocate an array of the size of the workgroup, with each element corresponding to the private variable of each work item, and save the mapping of the non-recomputable variables and the stack memory allocation instruction to the AllocaMap; Construct a first data structure set based on the AllocaMap and the ReComputeMap.
6. The method according to claim 5, characterized in that, The operands of the variable to be processed are recursively evaluated until the list is empty. Based on the evaluation result, the working list is updated and stored in the recomputed set, including: The operands of the variable to be processed are recursively judged. If the operand is a uniform variable, it is not added to the working list and the working list is updated. If the operand does not exist in AllocaMap, a stack memory allocation instruction is created for the operand and mapped and saved to AllocaMap. If the operand is the work item ID variable, then it is not added to the work list, and the work list is updated. If the operand is a non-uniform instruction and not the work item ID variable, then after adding it to the work list, it is determined whether the instruction of the operand is a Phi instruction. If the instruction of the operand is a Phi instruction, then a PhiPathMap is established to record the mapping relationship between the Phi instruction and the control flow path of the Phil instruction, and a BlockInstsMap is used to record the computation instructions associated with each basic block on the control flow path and the basic block. If the instruction of the operand is not a Phi instruction, then the operand is added to the ComputeSet set, and the remaining operands of the variable to be processed are recursively processed. During the recursive traversal of the operands of the Phi instruction and the branch conditions of the predecessor basic block, if the current instruction is within the control flow path, the mapping between the operand and the corresponding basic block is recorded in BlockInstsMap and added to the working list; if it is not within the path, the operand is added to the ComputeSet collection and added to the working list. The execution cost of each instruction in the computation sequence is continuously accumulated to obtain the recomputation cost of the variable corresponding to the operand. The mapping between the variable to be recomputed and the computation instruction set and ComputeSet is recorded in ReComputeMap until the list is empty. The working list is updated according to the judgment result and stored in the recomputable set.
7. The method according to claim 6, characterized in that, Based on the first data structure set, code transformation is performed during the creation of the work item loop to complete the recalculation and expansion of variables, including: Based on the first set of data structures, for each sub-kernel, a loop leader block is created before the work item loop to load uniform variables from local variables on the stack, and a basic block is added after the innermost loop header to load non-recomputed variables from arrays on the stack. Before processing other recomputable instructions, prioritize restoring the control flow structure of the Phi instructions; The process involves iterating through the ReComputeMap, copying the computation sequence to the InnermostBlock for each recomputable variable, and replacing the use of the variable within the work item loop with the recomputation result, thus completing the recomputation and expansion of the variable.
8. A variable recalculation system based on data flow analysis, characterized in that, The system includes: The variable attribute determination module is used to set the Boolean attribute on the ternary cell of the recalculation seed, and propagate the Boolean attribute according to the preset instruction type so that the Boolean attribute is unified through the cell union operation at the data control flow merging point to obtain the recalculation determination result of each variable. A classification module is used to identify cross-subkernel variables, which are classified according to the recomputability determination result to obtain uniform variables, recomputable variables, and non-recomputable variables. A data structure set construction module is used to construct a first data structure set by allocating variables on a stack to the uniform variables, recording the calculation sequence of the recomputable variables, and allocating arrays on a stack to the non-recomputable variables; The recalculation module is used to perform code transformation based on the first data structure set when creating a work item loop, and to complete the recalculation and expansion of variables.
9. 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.
10. 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.