A Compilation Optimization Method and System Based on Conflict Resolution for RVV

By identifying and fixing register conflicts in the RISC-V compiler during compilation, the register overflow problem was resolved, the compilation optimization efficiency of deep learning models was improved, and unnecessary vector loading and storage overhead was avoided.

CN123114487APending Publication Date: 2026-11-17SHANDONG UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611627194.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-21
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing deep learning compilers lack a unified model for the physical resources of RISC-V vector extensions during the optimization process, which makes it impossible to identify and fix register overflow issues in a timely manner, affecting the compiler's execution efficiency.

Method used

By using a candidate scheduling vector conflict identification and targeted repair mechanism, register overflow is identified and eliminated, generating optimized code that meets hardware constraints and avoiding register overflow.

Benefits of technology

It improves the compilation and optimization efficiency of deep learning models, avoids additional vector loading and storage overhead, and improves the execution efficiency of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114487A_ABST
    Figure CN123114487A_ABST
Patent Text Reader

Abstract

This invention discloses an RVV compilation optimization method and system based on conflict resolution, belonging to the field of deep learning compilation optimization technology. Addressing the problem that existing compilers cannot identify the conflict between the vector iteration gains caused by increasing LMUL and physical register overruns during the scheduling phase, leading to register overflows and additional memory accesses, this invention constructs candidate scheduling vectors, identifies register conflicts among candidate comparison groups with only different LMUL values, performs targeted repair on output blocks, reduction blocks, or fusion boundaries based on the type of active vector value contributing the most to the maximum occupancy location, and filters feasible candidates that satisfy all hardware constraints through constraint back-substitution, selecting the target scheduling vector from among them. This proactively eliminates the risk of register overflow during compilation, avoids additional loading and storage, and improves code generation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning compiler optimization technology, and in particular to an RVV compiler optimization method and system based on conflict resolution. Background Technology

[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.

[0003] In deep learning compilers, optimization techniques such as operator fusion, loop partitioning, and vectorization are typically executed separately in different compilation stages, each pursuing a local optimum. However, due to the lack of a unified model for the physical resources of RISC-V vector extensions, the benefits of one optimization parameter may incur a reverse cost in another physical resource. For example, to reduce the iteration overhead of vector instructions, the compiler increases the vector register set ratio. While this increases the number of elements processed in a single vector instruction and reduces the number of loop iterations, it also multiplies the number of physical vector registers occupied by each vector operand. If the operator also uses a fusion strategy to simultaneously maintain multiple parallel accumulated vectors to achieve instruction-level parallelism, the accumulated physical register usage can easily exceed the number of registers that the processor can allocate, leading to register overflow and generating a large number of additional vector load and store instructions, thus offsetting the benefits of the optimization.

[0004] Existing compilation schemes either only perform a posteriori weighted sorting of candidate parameters during the scheduling phase, failing to clearly identify the source of conflict between the aforementioned benefits and costs, or passively handle register overflow issues by the backend register allocator, inserting overflow loading and overflow storage only during the code generation phase. They lack a mechanism to proactively repair conflicts based on their source during the scheduling phase, making it difficult for the actually generated code to simultaneously achieve optimal performance in operator fusion, vectorization, and register resources. Summary of the Invention

[0005] To address the shortcomings of existing technologies, this invention provides an RVV compilation optimization method and system based on conflict resolution. By identifying and directionally repairing candidate scheduling vector conflicts, it eliminates register overruns, generates optimized code that meets hardware constraints, avoids register overflows, and improves execution efficiency.

[0006] To achieve the above objectives, the present invention is implemented through the following technical solution: In a first aspect, the present invention provides an RVV compilation optimization method based on conflict resolution, comprising: Obtain the unified iteration domain and active interval set of the fusion candidate subgraph; Based on the unified iteration domain and active interval set, a candidate scheduling vector set is generated in combination with hardware resource parameters; Calculate the maximum physical vector register occupancy and on-chip resident capacity for each candidate scheduling vector, and determine the program location that obtains the maximum physical vector register occupancy and the type of active vector value that contributes the most to the occupancy at the program location based on the active interval; identify register conflicts in candidate comparison groups where only LMULs differ; perform targeted repair on output blocks, reduction blocks, or fusion boundaries based on the active vector value type to resolve register conflicts; The repaired candidate scheduling vectors are subjected to constraint back-substitution, and a feasible candidate set is generated based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints. The target scheduling vector is selected from the feasible candidate set as the RVV compilation optimization result.

[0007] Furthermore, the candidate scheduling vector includes at least a fusion boundary, output dimension blocks, reduction dimension blocks, selected vector element width, vector register group multiplier, and vector register lifecycle strategy; The number of parallel accumulated vector groups is determined by the mapping rules of the vector microkernel. When the output dimension block is modified, the number of parallel accumulated vector groups is recalculated.

[0008] Further, the maximum physical vector register occupancy for each candidate scheduling vector is calculated, including: The effective vector register group ratio of each active vector value is determined based on the effective element width of each active vector value and the vector register group ratio. For each program location, the active vector values ​​participating in the candidate allocation are converted into physical vector register occupancy according to the corresponding effective vector register group ratio and register group alignment rules, and then summed. Take the maximum sum of all program locations and use it as the maximum physical vector register occupancy for the candidate scheduling vector.

[0009] Furthermore, the on-chip resident capacity is obtained by summing the number of bytes corresponding to the input fragment, weight fragment, broadcast parameter fragment, output fragment, fused intermediate fragment, boundary swap-in and swap-out data, buffer, and cache line alignment filling corresponding to the current candidate scheduling vector.

[0010] Furthermore, the physical vector register constraint is that the maximum physical vector register occupancy does not exceed the number of allocable physical vector registers; The number of allocatable physical vector registers is the total number of physical vector registers minus the number of registers reserved by the target backend and not participating in candidate allocation.

[0011] Furthermore, in candidate comparison groups where only LMUL differs, register conflicts are identified, including grouping two candidates whose fields are identical except for LMUL into a comparison group; The candidate with the larger vector register group multiplier in the comparison group is determined as the first candidate, and the candidate with the smaller vector register group multiplier is determined as the second candidate; When the first candidate has a smaller number of vector segments or a smaller number of vector loop iterations than the second candidate due to the increased vector register group ratio, and the maximum physical vector register occupied by the first candidate exceeds the number of allocable physical vector registers, a register conflict is determined to exist.

[0012] Furthermore, the targeted repair includes: When the active vector value type is a parallel accumulation vector, the output dimension block that determines the number of parallel accumulation vector groups is reduced and the number of parallel accumulation vector groups is recalculated; When the active vector value type is a reduction intermediate quantity, reduce the reduction dimension block size; When the active vector value type is an active temporary quantity, the generation sequence of the temporary quantity is changed or the fusion boundary is shortened, and the active interval set is regenerated after the fusion boundary is shortened. When the active vector value type is an operand vector, reduce the number of operand vector groups that are prefetched or held simultaneously, or change the loading timing of the operand vectors.

[0013] A second aspect of the present invention provides an RVV compilation optimization system based on conflict resolution, comprising: The fusion subgraph analysis module is used to obtain the unified iteration domain and active interval set of the fusion candidate subgraphs. Candidate scheduling vector generation module: used to generate a set of candidate scheduling vectors based on the unified iteration domain and active interval set, combined with hardware resource parameters; Physical resource assessment and conflict resolution module: used to calculate the maximum physical vector register occupancy and on-chip resident capacity of each candidate scheduling vector, and determine the program location that obtains the maximum physical vector register occupancy and the type of active vector value that contributes the most to the occupancy at the program location based on the active range; identify register conflicts in candidate comparison groups where only LMULs are different; and perform targeted repair on output blocks, reduction blocks, or fusion boundaries based on the active vector value type to resolve register conflicts. Constraint Back-substitution Filtering Module: Used to perform constraint back-substitution on the repaired candidate scheduling vectors, and generate a feasible candidate set based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints; Target selection output module: used to select the target scheduling vector from the feasible candidate set as the RVV compilation optimization result.

[0014] In a third aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the steps of the method as described in the first aspect.

[0015] In a fourth aspect, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method as described in the first aspect.

[0016] Compared with the prior art, the beneficial effects of the present invention are: This invention employs a candidate scheduling vector conflict identification and targeted repair mechanism to proactively identify the conflict between the vector iteration gains caused by the increase of LMUL and the physical vector register overrun during compilation. Based on the type of active value that caused the overrun, targeted repair and constraint back-substitution are performed, thereby eliminating the risk of register overflow before generating target code, avoiding additional vector loading and storage overhead, and improving code generation efficiency. Attached Figure Description

[0017] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0018] Figure 1 This is a flowchart of the method according to Embodiment 1 of the present invention; Figure 2 This is a diagram showing the relationship between candidate scheduling vectors, active regions, and physical vector register groups in this invention. Figure 3 This is a flowchart of the register group conflict identification, targeted repair, and constraint back-substitution process of the present invention; Figure 4 This is a diagram of the RVV cycle and register lifecycle stages based on the actual VL of this invention; Figure 5 This is a schematic diagram illustrating the optional multi-core NUMA mapping, cache line isolation, and resident capacity back-substitution of the present invention. Detailed Implementation

[0019] The following detailed description is exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0020] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.

[0021] In this embodiment of the invention, the data collection and processing strictly adhere to the requirements of relevant laws and regulations, obtaining informed consent or separate consent from the data subject, and conducting subsequent data use and processing within the scope of laws, regulations, and the data subject's authorization. All data acquisition in this embodiment is based on compliance with laws and regulations and user consent, representing the lawful application of the data.

[0022] Terminology Explanation: RISC-V Vector Extension (RVV): A standard extension for vector processing in the RISC-V architecture, or a vector extension compatible with its instruction semantics.

[0023] Vector Register Bit Width (VLEN): The bit width of a single physical vector register in the target processor.

[0024] Application Vector Length (AVL): The number of application layer elements that are currently pending processing in the vector loop.

[0025] Vector Length (VL): The actual vector length returned and written to the vector length register by the vector length setting instruction. The compiled loop updates the data address, loop offset, and AVL with this actual return value.

[0026] Vector Register Group Multiplier (LMUL): The vector register group multiplier in the current vector type configuration.

[0027] Maximum Vector Length (VLMAX): The maximum number of vector elements that can be represented given a Vector Register Bit Width (VLEN), a Selected Element Width (SEW), and an LMUL configuration. For the integer LMUL used in this specific embodiment of the invention, VLMAX can be calculated as follows: Sure.

[0028] Selected Element Width (SEW): The width of the vector elements selected for the current vector type configuration.

[0029] Effective Element Width (EEW): The effective element width of a specific vector operand or result.

[0030] Effective Vector Register Group Multiplier (EMUL): The effective vector register group multiplier for a specific vector operand or result, which can be determined based on EEW, SEW, and LMUL. For widening operations, the EMUL of the result vector can be greater than the LMUL of the source vector.

[0031] Non-Uniform Memory Access (NUMA): Used for computer memory architecture design in multiprocessor systems.

[0032] Fusion candidate subgraph: Multiple computation graph nodes and their data edges selected from the intermediate representation of the model to be compiled, which have producer-consumer data dependencies and are allowed to be executed in a fusion kernel.

[0033] Active range: The compile-time range of a vector value from its generation position to its final consumption position.

[0034] Active set: The set of vector values ​​that have not yet been consumed at the same program position.

[0035] Physical vector register occupancy: At a given program location, the number of physical vector registers in the active set, calculated based on the vector values ​​allocated by the candidate scheduler, according to LMUL, EMUL, and register set alignment rules. Registers reserved by the target backend and not participating in candidate allocation are deducted from the allocatable quantity and are not counted repeatedly in the physical occupancy.

[0036] Candidate scheduling vector: used to express compile-time candidate states of fusion boundary, block size, SEW, LMUL, number of parallel accumulation groups, register lifecycle strategy, and optional task mapping parameters.

[0037] Parameter fragment: The byte range of Bias, Scale or other broadcast parameters that reside with the current output fragment, and the number of resident bytes is denoted as Tparam.

[0038] Hard illegal conditions: Target instruction encoding, register set alignment, block boundary, or resource conditions that cannot be eliminated by the repair actions permitted by this invention. Candidates that satisfy hard illegal conditions are directly marked as infeasible.

[0039] Remediable conflicts: The candidate currently has physical register occupancy, on-chip resident capacity, cache line alignment, or task mapping overrun, but can regain a feasible state by modifying at least one field in the candidate scheduling vector.

[0040] Constraint back-substitution: After each repair of a candidate scheduling vector, the physical vector register usage, on-chip resident capacity, number of vector segments, main memory access volume, number of tasks, synchronization overhead or memory mapping cost that the repair action may affect are recalculated, and the feasibility of the candidate is reassessed accordingly.

[0041] The terms mentioned above are commonly used technical terms in this field, but they have specific meanings in the context of this invention. Those skilled in the art should understand these terms in conjunction with the overall technical solution of this invention. The following embodiments will provide a detailed description of the technical solution of this invention to facilitate its implementation by those skilled in the art.

[0042] Example 1 Existing deep learning compilers typically only perform a posteriori weighted sorting of candidate parameters during the scheduling phase, or delegate passive register overflow handling to the backend register allocator during the code generation phase. They lack a mechanism to uniformly model hardware physical resources and proactively identify conflict sources during the scheduling phase. As a result, the conflict between the vector iteration benefits brought by increasing LMUL and physical register overruns cannot be detected and corrected in a timely manner. Often, a large number of vector loading and storage instructions are passively inserted after the target code is generated, which offsets the optimization benefits.

[0043] To address this, the present invention constructs candidate scheduling vectors during compilation and establishes candidate comparison groups with only different LMUL values. Based on the type of active vector value that contributes the most at the location of the largest physical register occupancy, it performs targeted repair on output blocks, reduction blocks, or fusion boundaries. By using constraint back-substitution, the repaired register occupancy, on-chip resident capacity, and memory access metrics are re-substituted into all hardware constraints for verification. Feasible candidates that meet all hard constraints are screened, and the target scheduling vector is selected from them. This proactively eliminates the risk of register overflow before code generation, avoids unnecessary loading and storage, and improves the execution efficiency of the compiled and optimized code.

[0044] In a typical embodiment of the present invention, such as Figure 1 As shown, an RVV compilation optimization method based on conflict resolution is disclosed, and the specific steps include: S1: Obtain the unified iteration domain and active interval set of the fusion candidate subgraph; S2: Generate a set of candidate scheduling vectors based on the unified iteration domain and active interval set, combined with hardware resource parameters; S3: Calculate the maximum physical vector register occupancy and on-chip resident capacity of each candidate scheduling vector to determine the program location and the active vector value type that contributes the most to the occupancy at the program location; in the candidate comparison group where only LMUL is different, identify register conflicts and perform targeted repair on the output block, reduction block or fusion boundary according to the active vector value type to resolve register conflicts; S4: Perform constraint back-substitution on the repaired candidate scheduling vectors, and generate a feasible candidate set based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints; S5: Select the target scheduling vector from the feasible candidate set as the RVV compilation optimization result.

[0045] The RVV compilation optimization method based on conflict resolution described above will be explained in detail below with reference to specific implementation methods. This embodiment uses the same fused subgraph, the same target hardware description, the same candidate set, and the same target scheduling vector to sequentially execute input parsing, candidate generation, conflict identification, targeted repair, constraint back-substitution, code generation, and multi-core mapping, avoiding splitting progressively related processing stages into multiple isolated embodiments. The tensor size, candidate parameters, and resource usage values ​​in this embodiment are used to illustrate the executable process of the compilation method. Register usage, on-chip resident bytes, and logical intermediate tensor accesses are compile-time calculated values ​​obtained based on given input and hardware configuration, and do not represent unmeasured actual runtime or speedup ratio. Actual latency, throughput, and hardware counter results can be further collected on a specific target processor or instruction set simulator.

[0046] In step S1, fusionable computational nodes are determined from the intermediate representation of the deep learning model to be compiled based on the producer-consumer data dependency relationship, their cyclic dimensions are merged into a unified iterative domain, and an active interval set is generated based on the program range between the definition point and the last use point of each vector value.

[0047] As one embodiment, the compiler receives an intermediate representation of the deep learning model to be compiled. This intermediate representation takes the form of a directed acyclic graph (DAG), where nodes represent computational operators (such as matrix multiplication, bias addition, activation functions, etc.), and edges represent the transmission relationship of tensor data between producers and consumers. The compiler traverses this DAG, starting from the output node and tracing back along the data flow, to identify adjacent computational nodes with producer-consumer dependencies. When several nodes satisfy the internal single-consumer condition (i.e., each intermediate tensor is consumed by only one downstream node) and the increment of the intermediate tensor resident capacity and the increment of the active interval overlap introduced after fusion are both within a preset threshold, these nodes are marked as fusion candidate subgraphs.

[0048] For the determined candidate subgraphs for fusion, the compiler extracts the cyclic iteration dimensions of each computation node. For example, matrix multiplication contains M dimensions (output rows), N dimensions (output columns), and K dimensions (reduction dimension). The bias addition activation function inherits the M and N dimensions of matrix multiplication without introducing new independent dimensions. The compiler merges these cyclic dimensions to generate a unified iteration domain. This provides a traversal range for subsequent block divisions.

[0049] The compiler further performs compile-time data flow analysis on each vector value in the fusion candidate subgraph. Let a certain vector value... By the The instruction is generated and is... If the instruction is consumed last, then... The active range is defined as the interval from the point of origin. To the final consumption position The scope of the program, denoted as The compiler iterates through all vector values, records the definition instructions and all usage instructions for each value, determines its last consumption position, and forms a set of active regions. This set is used for subsequent calculations of the active vector value set at each program location. Then, based on the LMUL or EMUL of each vector value, the maximum value occupied by the physical vector register is calculated. .

[0050] In this embodiment, taking matrix multiplication with FP16 precision input and FP32 precision accumulation as an example, and operator fusion compilation with bias addition and GELU activation function, the fusion subgraph and input information are obtained as follows: The compiler receives an intermediate representation of the model to be compiled. This intermediate representation includes a MatMul node, a Bias node, and a GELU node connected sequentially. The output of the MatMul node is consumed only by the Bias node, and the output of the Bias node is consumed only by the GELU node; therefore, the three nodes satisfy the internal single-consumer condition of the fusion candidate subgraph. The inputs and outputs of this embodiment are shown in Table 1 below.

[0051] Table 1 Input-output tensor table of fused subgraph

[0052] Merge Subgraph Execution MatMul uses FP16 input and FP32 accumulation, while GELU is implemented using an FP32 vector approximation configured in the target backend. This embodiment employs a post-processing sequence that updates the accumulation vector in situ and requires only one auxiliary FP32 vector group. The scalar coefficients are stored in a scalar register. The specific approximation coefficients of GELU are not part of the conflict resolution core of this invention, and the compiler can also call other vectorized implementations that meet the error requirements and have known active ranges.

[0053] In this embodiment, a unified iteration domain and active interval set are generated, as detailed below: The unified iteration domain after the fusion of MatMul, Bias, and GELU is ,in, The range is 0 to 63. The range is 0 to 195. The range is from 0 to 127.

[0054] The compiler establishes the active range categories as shown in Table 2 based on the fusion node sequence and the microkernel instruction sequence.

[0055] Table 2. Active Zone Category Comparison Table

[0056] For the integer LMUL used in this embodiment, the maximum number of vector elements corresponding to the candidate scheduling vector can be expressed as: The vector length setting instruction returns the actual VL based on AVL and VLMAX. The compiler does not fix the VL for all AVL intervals as a simple min(AVL, VLMAX), but instead uses the actual VL returned by the instruction to advance the loop. At a minimum, the following conditions must be met: VL equals AVL when AVL is not greater than VLMAX; VL is greater than zero when AVL is greater than zero; VL is neither greater than AVL nor greater than VLMAX.

[0057] In this embodiment, during FP16 input and FP32 widened accumulation, the FP32 accumulation result has twice the effective element width relative to the FP16 input. Therefore: .

[0058] During the specification phase, VR-ACC and VR-OP have overlapping lifecycles; before entering the Bias and GELU phases, VR-OP has been released, and the compiler processes VR-ACC groups one by one, enabling VR-TMP to be reused between different output vectors.

[0059] In step S2, based on the cyclic traversal range provided by the unified iterative domain and the lifecycle information of each vector value provided by the active interval set, combined with hardware resource parameters such as the vector register bit width, number of registers, SEW / LMUL candidate combinations, and on-chip storage capacity of the target RISC-V processor, a set of candidate scheduling vectors that satisfy the hardware constraint search space is generated by enumerating different parameter combinations such as fusion boundary, output dimension block, reduction dimension block, selected vector element width SEW, LMUL, number of parallel accumulated vector groups, and vector register lifecycle strategy.

[0060] As one implementation, the compiler uses a unified iteration domain as the basis for the traversal space of loop blocks and the set of active intervals as the basis for register lifetime analysis. Based on hardware resource parameters such as vector register bit width VLEN, total number of physical vector registers Rtotal, number of reserved vector registers Rreserved, SEW / LMUL candidate combinations, and on-chip storage capacity Ccache in the hardware resource description, it performs combined enumeration of fusion boundary, output dimension block, reduction dimension block, selected vector element width SEW, vector register group multiplier LMUL, and vector register lifetime strategy.

[0061] The output dimension partitioning further determines the number of parallel accumulation vector groups through a mapping rule oriented towards a vector microkernel. When the output dimension block is modified, the number of parallel accumulation vector groups is recalculated; the reduction dimension block determines the processing granularity of each reduction iteration; SEW and LMUL determine the maximum vector length VLMAX under the current configuration, and derive the effective register group multiple EMUL for each vector value accordingly. The compiler records each combination of the above parameters as a candidate scheduling vector, and constructs a candidate scheduling vector set { by the Cartesian product of each candidate field}. , , ..., This data is used for subsequent physical resource assessment and conflict identification steps.

[0062] This embodiment uses the target hardware resource parameters shown in Table 3 below. This description is used for static compilation simulation; the NUMA distance is the relative cost in the platform description file and does not represent the measured latency in nanoseconds.

[0063] Table 3 Target Hardware Resource Parameter Comparison Table

[0064] In this embodiment, the candidate generator enables candidates with an LMUL value of 1 or 2 for the fused subgraph. Other LMUL values ​​can be enabled by other target configurations and processed using the same physical occupancy calculation, conflict resolution, and constraint back-substitution process.

[0065] In this embodiment, an initial candidate scheduling vector set is generated as follows: This embodiment fixes the fusion boundary F, Um=2, Un=4, Tk=32, SEW=16, and the lifecycle policy Pvr, only enumerating LMUL=1 and LMUL=2 to generate... and Two initial candidates are provided for subsequent conflict identification and targeted remediation. (Follow-up...) of The repair is performed after the initial LMUL causal comparison is completed, and the repair candidates are... It is not used to reverse the initial comparison group. The candidate scheduling vector can be represented as:

[0066] in, This represents the fusion boundary of MatMul, Bias, and GELU. The number of parallel groups for M-dimensional output; The number of parallel groups for N-dimensional output; Divide the specification dimensions into blocks; This indicates the aforementioned strategy of accumulating long lifecycles and reusing post-processing temporary quantities in groups.

[0067] The output dimension block, as a field of the candidate scheduling vector, is decomposed into corresponding parallel group components (such as the number of parallel groups in the M-dimensional and N-dimensional directions) based on the actual number of dimensions of the tensor. The number of parallel accumulation vector groups is determined by the mapping rules of the vector-oriented microkernel. When the output dimension block is modified, the number of parallel accumulation vector groups is recalculated.

[0068] The number of parallel accumulation vector groups is included as an independent field in the candidate scheduling vector, and is computed in parallel using two output rows. The number of parallel vector groups in the output dimension M (e.g., output rows) is determined by the number of rows in the output block; let be... The number of parallel vector groups in the N-axis direction (e.g., output columns) of the output dimension is determined by the column width of the output block; the reduced dimension block is denoted as... The logical column width of the output microblock is determined by... It is determined that, under the mapping rules of this embodiment, the number of parallel accumulation vector groups maintained simultaneously is... Therefore, reduce The number of simultaneously active cumulative vector groups will be reduced according to the established relationship.

[0069] When VLEN is 256 bits and SEW is 16 bits: when LMUL is 1, VLMAX is 16; when LMUL is 2, VLMAX is 32.

[0070] The initial candidate scheduling vector set is shown in Tables 4 and 5 below.

[0071] Table 4 Initial Candidate Scheduling Vector Parameter Comparison Table

[0072] Table 5 Performance Indicators Comparison of Initial Candidate Scheduling Vectors

[0073] As can be seen from Tables 4 and 5, and Merge boundary except LMUL They are all the same. Under this single-variable comparison condition, Increasing LMUL from 1 to 2 increases the number of FP16 elements processed by a full vector group from 16 to 32, reduces the number of N-dimensional output blocks from 4 to 2, and reduces the number of vector groups required to process a complete N-dimensional array from 13 to 7. However, whether this benefit is usable depends on calculating physical register usage based on the EMUL of the FP32 accumulation result and the active range.

[0074] In step S3, for each candidate scheduling vector, the sum of the physical register occupancy of all active vector values ​​at each program location is calculated based on the overlap of active intervals, converted to LMUL or EMUL. The maximum value is taken as the maximum physical vector register occupancy, and the program location that obtains the maximum value and the type of the active vector value that contributes the most to the occupancy at that location are recorded. At the same time, the number of bytes of input, weight, output, parameter, intermediate, boundary, buffer, and alignment padding are accumulated as the on-chip resident capacity. Candidates with all fields being the same except for LMUL are paired up to form comparison groups. When a candidate with a larger LMUL gains an advantage due to a reduction in the number of vector iterations but its physical register occupancy exceeds the allocatable number, a register conflict is determined. Then, based on the type of the active vector value that contributes the most to the location that obtains the maximum occupancy, targeted repair is performed on the output block, reduction block, or fusion boundary to eliminate register overrun.

[0075] S301: As one implementation method, the EMUL and physical vector register occupancy is calculated as follows: The effective vector register group ratio for each active vector value is determined based on the effective element width and vector register group ratio of each active vector value: for vector values ​​with an effective element width of EEW... Its effective register set multiplier It can be represented as:

[0076] Set program location The set of active vector values ​​is For each program position, the active vector values ​​participating in the candidate allocation will be... The number of physical vector registers occupied according to the target backend register set rules is Then the candidate scheduling vector The maximum physical vector register occupancy is:

[0077] Among them, according to The LMUL or EMUL and register set alignment rules are converted to physical vector register occupancy. The maximum sum across all program locations is taken as the maximum physical vector register occupancy for that candidate scheduling vector; if the mask register is not reserved, it is counted as the active vector value. If a space has already been reserved, it will not be counted again. The alignment rule means that each vector register group (of size LMUL or EMUL) must occupy a contiguous physical vector register, and the starting register number must be an integer multiple of the group size (for group sizes of 2, 4, and 8, the numbering starts from an even number, a multiple of 4, and a multiple of 8, respectively). When allocating, it is also necessary to skip the registers reserved at the target back end (such as v0-v3) and must not overlap with any other active group.

[0078] The physical vector register constraint is that the maximum physical vector register occupancy does not exceed the number of allocable physical vector registers, where the number of allocable physical vector registers is the total number of physical vector registers minus the number of registers reserved by the target backend and not participating in candidate allocation.

[0079] Let the total number of physical vector registers be The number of candidates retained by the target backend and not involved in candidate allocation is The number of allocable physical vector registers is:

[0080] The register set overrun is:

[0081] when If the value is greater than zero and there are allowed chunking, lifecycle, or LMUL repair actions, the candidate enters conflict resolution instead of directly entering cost sorting.

[0082] As one implementation method, the on-chip resident capacity is calculated as follows:

[0083] in, Physical on-chip resident capacity for candidate evaluation; These represent the number of bytes used for input slices, weight slices, broadcast parameter slices, output slices, fused intermediate slices, boundary swap-in and swap-out data, buffers, and cache line alignment padding.

[0084] The on-chip resident capacity constraint is that the sum of the number of bytes for input fragments, weight fragments, broadcast parameter fragments, output fragments, fused intermediate fragments, boundary swap-in and swap-out data, buffers, and cache line alignment fills does not exceed the product of the physical on-chip storage capacity and the preset security factor. When the output dimension block or the reduction dimension block is modified, the corresponding fragment byte count in the on-chip resident capacity constraint is recalculated and the constraint is re-evaluated to determine whether it is satisfied.

[0085] Specifically, if the preset safety factor λ is greater than 0 and not greater than 1, then the on-chip residency constraint is:

[0086] The compiler recalculates the constraint when any of the above changes, such as block repair, cache line alignment, or buffer size.

[0087] Based on the set of active intervals, determine the set of active vector values ​​at each program location. For each program location, convert each active vector value at the program location into physical vector register occupancy according to its vector register group ratio or effective vector register group ratio and register group alignment rules, and sum them up. Take the maximum sum value among all program locations as the maximum physical vector register occupancy. The program location corresponding to the maximum sum value is the program location where the maximum physical vector register occupancy is obtained. At this program location, group each active vector value according to the type of parallel accumulation vector, reduction intermediate quantity, activation temporary quantity, and operand vector, and summarize the physical register occupancy contribution of each type. The type with the largest contribution is the active vector value type with the largest occupancy contribution at the program location.

[0088] In this embodiment, the physical register usage and on-chip resident capacity are calculated as follows: for , Equal to 2 and The value equals 4, thus maintaining 8 FP32 accumulator vector groups simultaneously. Each accumulator vector group has an EMULacc value of 2, and the actual number of physical vector registers occupied by the accumulator vector groups is: One physical vector register.

[0089] In this embodiment, the target backend uses the current weight vector group and the next weight vector group to form an instruction pipeline during the reduction phase. The elements of matrix A are broadcast by scalar registers. When LMUL equals 1, the two weight vector groups occupy a total of 2 physical vector registers, therefore: . satisfy .for Meanwhile, the number of accumulated vector groups remains at 8, but each group's EMULacc equals 4. The actual number of physical vector registers occupied by the accumulated vector groups is: One physical vector register.

[0090] When LMUL equals 2, the current weight vector group and the next weight vector group each occupy 2 physical vector registers, and the operand vector group in the reduction phase occupies a total of 4 physical vector registers. Therefore: . The register set overrun is: .

[0091] The on-chip resident capacity is calculated based on the current input fragment, weighted fragment, parameter fragment, output fragment, and a set of prefetch buffers. This embodiment uses parameter fragmentation. Bias is segmented; the fusion intermediate results are kept in the vector register, therefore The value is 0; this MatMul has no convolutional boundaries for data swapping in and out, therefore... =0; before enabling multi-core cache line isolation =0. Prefetch buffer It equals the capacity of another set of input fragments and weight fragments, used to form a double buffer.

[0092] for When Tn equals 64: Input fragments Bytes; weighted sharding Bytes; Output Fragments Bytes; parameter fragments Bytes; prefetch buffer byte.

[0093] Total resident capacity is: byte.

[0094] for When Tn equals 128: Input fragments Bytes; weighted sharding Bytes; Output Fragments Bytes; parameter fragments Bytes; prefetch buffer byte.

[0095] Total resident capacity is: byte.

[0096] visible, and The resident capacity does not exceed 24576 bytes, therefore, It is not an illegal candidate for on-chip capacity, but a repairable conflict candidate for "vector segmentation gains exist and physical register set exceeds limits".

[0097] S302: Identify register conflicts in candidate comparison groups where only LMUL differs, including: Two candidate scheduling vectors with identical fusion boundaries (excluding vector register group multiplier), output dimension blocks, reduction dimension blocks, selected vector element widths, number of parallel accumulation vector groups, and vector register lifetime strategies are selected to form a comparison group. The candidate with the larger vector register group multiplier in the comparison group is determined as the first candidate, and the candidate with the smaller vector register group multiplier is determined as the second candidate; When the first candidate has a smaller number of vector segments or a smaller number of vector loop iterations than the second candidate due to the increased vector register group ratio, and the maximum physical vector register occupied by the first candidate exceeds the number of allocable physical vector registers, a register conflict is determined to exist.

[0098] The register conflict status includes candidate identifier, change in the vector register group ratio that caused the conflict, improvement in vector segmentation or vector loop iteration indicators, program location where the maximum physical vector register occupancy is achieved, physical occupancy contribution of each active vector value type at the program location, active vector value type with the largest occupancy contribution, physical vector register over-limit, candidate repair action, pre-repair indicators, post-repair indicators, and feasibility status.

[0099] As one implementation method, candidate scheduling vector The conflict status includes at least the candidate identifier, source parameter change, revenue indicators, affected physical resources, exceeding the limit, type of active value that leads to maximum occupation, repair action, indicators before repair, indicators after repair, and feasibility status.

[0100] For conflicts between LMUL and register sets, the compiler first groups candidates with identical fields (excluding LMUL) into a comparison group to isolate the impact of differences in output block, reduction block, SEW, number of parallel accumulation vector groups, and lifetime strategy on metrics. The source parameter change is an increase in LMUL for the first candidate relative to the second candidate; the benefit metrics are a reduction in the number of vector segments, the number of outer vector blocks, or the vector loop iteration metric; the affected physical resource is the allocable physical vector registers; and the over-limit is... The compiler determines that... Location of the program to obtain the maximum value , position The active vector values ​​at each location are grouped into types such as parallel accumulation vector, reduction intermediate quantity, operand vector, activation temporary quantity, and mask vector. The physical occupancy contribution of each type is summarized, and the output block, reduction block, lifetime timing, or LMUL is modified first based on the type with the largest occupancy contribution.

[0101] In this embodiment, register group conflict states are generated as follows: The compiler will select candidates with identical fields except for LMUL. and Construct an LMUL comparison group, and set LMUL equal to 2. If determined as the first candidate, then LMUL = 1. It was selected as the second candidate. Compared to The benefit is that the number of N-dimensional output blocks is reduced from 4 to 2 and the number of complete N-dimensional vector groups is reduced from 13 to 7; The affected resource is the physical vector register; the limit is 8. (In use) Position of the reduction phase for achieving the maximum value The occupancy contribution of the FP32 parallel accumulation vector VR-ACC is 32, and the occupancy contribution of the operand vector VR-OP is 4. Therefore, the active value type with the largest occupancy contribution is VR-ACC.

[0102] The generated conflict states can be represented as shown in Table 6.

[0103] Table 6 Initial Candidates Conflict Status Comparison Table

[0104] Since the overlimit issue is primarily caused by parallel accumulation vectors, the compiler does not prioritize modifying it. Instead, it first reduces the number of parallel accumulation vector groups that determine the number of vector groups. .

[0105] S303: Targeted repair, including: When the active vector value type is a parallel accumulation vector, the output dimension block that determines the number of parallel accumulation vector groups is reduced and the number of parallel accumulation vector groups is recalculated; When the active vector value type is a reduction intermediate quantity, reduce the reduction dimension block size; When the active vector value type is an active temporary quantity, the generation sequence of the temporary quantity is changed or the fusion boundary is shortened, and the active interval set is regenerated after the fusion boundary is shortened. When the active vector value type is an operand vector, reduce the number of operand vector groups that are prefetched or held simultaneously, or change the loading timing of the operand vectors.

[0106] The targeted repair also includes: If the physical vector register constraint is still not met after the targeted repair is completed, or if the number of vector segments or the number of vector loop iterations used as a benefit indicator after repair is no less than the corresponding indicator of the second candidate, the vector register group ratio will be rolled back to the vector register group ratio value of the second candidate.

[0107] In this embodiment, targeted repair is performed, as follows: compiler Apply output dimension block repair, Reduce the value from 4 to 3, keeping other fields unchanged, to obtain repair candidates. :

[0108] The logical output columns are divided into blocks as follows: The number of N-dimensional output blocks is: Compared to before the repair The number of output blocks increased from 2 to 3; compared to a smaller LMUL The number of digits has been reduced from 4 to 3.

[0109] In step S4, the maximum physical vector register occupancy and on-chip resident capacity are recalculated for the repaired candidate scheduling vectors. Only candidate scheduling vectors that simultaneously meet the two hard constraints of register occupancy not exceeding the allocable number and on-chip resident capacity not exceeding the available capacity are added to the feasible candidate set.

[0110] In this embodiment, the repair candidates are subjected to constrained back-substitution, as follows: right Recalculate register usage. At the same time maintain There are FP32 accumulated vector groups, each with EMULacc equal to 4, therefore: The operand vector set during the reduction phase occupies 4 physical vector registers, therefore: . The physical vector register constraint is satisfied, and the over-limit is reduced from 8 to 0.

[0111] right Recalculate on-chip resident capacity: Input fragments Bytes; weighted sharding Bytes; Output Fragments Bytes; parameter fragments Bytes; prefetch buffer byte.

[0112] Total resident capacity is byte.

[0113] 13696 bytes no more than 24576 bytes This simultaneously satisfies physical register and on-chip residency constraints. During the reduction phase, 24 physical registers are used for six FP32 accumulation vector groups, and 4 physical registers are used for operand vector groups. To verify that the counting results simultaneously satisfy register group alignment, this embodiment reserves v0-v3, assigns the six accumulation groups with EMUL equal to 4 to v4-v7, v8-v11, v12-v15, v16-v19, v20-v23, and v24-v27 respectively, and assigns the two operand groups with LMUL equal to 2 to v28-v29 and v30-v31. The starting numbers of each group satisfy the corresponding register group alignment rules.

[0114] After reduction, the operand vector group is released; the Bias and GELU stages process the accumulated result using FP32 vector types with the same number of elements, and v28-v31 are treated as a VR-TMP group with EMUL equal to 4. The compiler completes Bias, GELU, and storage for each output vector group, allowing the same VR-TMP group to be reused among the six output vector groups, so the maximum physical footprint of the post-processing stage still does not exceed 28.

[0115] In this embodiment, After one fix, it enters the feasible candidate set. If its Rphy still exceeds 28, the compiler will continue to reduce it. If it continues to decrease If the vector segmentation benefit is lower than the corresponding smaller LMUL candidate, the compiler will roll back to LMUL; if the overlimit comes from GELU temporarys rather than accumulated amounts, the compiler can also change the post-processing timing or shorten the fusion boundary; if the overlimit comes from the simultaneous prefetching of the current and next weight vector groups, the compiler will cancel the advance holding of the next weight vector group or delay its loading timing, and recalculate the VR-OP occupancy, prefetch buffer capacity and vector iteration cost.

[0116] In step S5, among the feasible candidate set, the main memory access volume, vector loop iteration count, register occupancy rate, optional synchronization overhead, and NUMA remote access cost are normalized and weighted, and the candidate scheduling vector with the minimum comprehensive cost is selected as the final compilation optimization result.

[0117] As one implementation method, only candidates that meet the constraints of target instruction encoding, physical vector registers, on-chip residency, and data dependency can enter the feasible candidate set. This includes enabling indicators such as main memory access volume, vector segmentation or loop iteration metrics, physical vector register occupancy, synchronization overhead, and NUMA access cost. The compiler bases the values ​​on the platform. Obtain the normalized index And calculate:

[0118] Among them, weight Provided by the target platform description, offline calibration, or compiler fixing strategy. If two candidates... If they are the same, the target scheduling vector is selected in the following order: fewer main memory accesses, fewer vector segments or loop iterations, lower physical vector register occupancy, fewer remote accesses, and fewer synchronizations, in order to obtain a reproducible target scheduling vector.

[0119] It should be noted that in the multi-objective cost function, the weights of each metric need to be determined based on the characteristics of the target platform and offline benchmark results to reflect the relative importance of memory bandwidth bottlenecks and computational density. For typical RISC-V vector processors, the weight of main memory access should be set to the highest, followed by the weight of vector segmentation or loop iteration count, and then the weight of physical vector register occupancy. The weights of NUMA remote access and synchronization overhead depend on the actual impact of multi-core, multi-NUMA scenarios. All metric weights must be non-negative and normalized to ensure a sum of 1. When the operating environment is a single-core or UMA architecture, NUMA and synchronization-related metrics should be disabled, and the weights of the remaining metrics should be re-normalized. The compiler can be fine-tuned based on the measured performance data of the target platform, but fixed values ​​that have not been fully benchmarked and verified through sensitivity analysis should not be used as a general preferred range.

[0120] The termination condition is as follows: conflict resolution for a single candidate terminates when any of the following conditions are met: the candidate satisfies all constraints after back-substitution and enters the feasible candidate set; all allowed repair actions fail; the repaired candidate state already exists in the visited state set; the preset finite number of repairs is reached; or a hard illegal condition that cannot be repaired is triggered.

[0121] In this embodiment, the target scheduling vector is selected as follows: and All meet hard resource constraints. because If the value is 8, it will not be included in the feasible candidate set. and The comparison is shown in Table 7 below.

[0122] Table 7 and Comparison table

[0123] Both candidates meet the requirements of zero register overrun and on-chip residency, and both retain complete fusion, thus having the same number of main memory accesses to the logic intermediate tensor. Although the dwell capacity is higher However, it is still below budget; the number of times it processes a complete N-dimensional vector group is reduced from 13 to 7, and the number of N-dimensional output blocks is reduced from 4 to 3. The target platform strategy in this embodiment prioritizes candidates with fewer vector group accesses when main memory access is the same, and then uses physical vector register occupancy and resident margin as selection criteria when the values ​​are equal. Therefore, it selects... As the target scheduling vector .

[0124] For the non-fusion execution mode, the FP32 intermediate output size of MatMul is: byte.

[0125] If the intermediate output is written back at least once and read once before Bias or GELU, a logical intermediate tensor main memory access of 100352 bytes is generated. Target scheduling vector Within a fused kernel, the block accumulation results are maintained and Bias and GELU are executed directly. Therefore, in this embodiment where there are no external consumers, a complete write-back and a complete reread of this logical intermediate tensor are not required. This value represents the logical access volume calculated per tensor size and is not equivalent to the measured DRAM traffic on a specific processor.

[0126] In this embodiment, the generated RVV loop and register allocation results based on the actual VL are as follows: Target scheduling vector correspond Equal to 2 Given that the input SEW equals 3, Tk equals 32, input LMUL equals 16, input LMUL equals 2, and FP32 accumulation EMUL equals 4, the compiler uses a vector type with SEW equal to 32 and LMUL equal to 4 during the Bias and GELU post-processing of the FP32 accumulation result. This ensures that the VLMAX in the post-processing stage is 32, the same as the VLMAX when the input is FP16 and LMUL equals 2, and corresponds to the EMUL of the widened accumulation result.

[0127] The register lifetime allocation results for the target scheduling vector are shown in Table 8 below.

[0128] Table 8 Target Scheduling Vector Register lifetime allocation result table

[0129] In this embodiment, optional multi-core, NUMA, and cache line mappings are generated as follows: This step describes the further processing of the target scheduling vector when multi-core mapping is enabled, and does not change the primary selection result of the aforementioned conflict between LMUL and physical register set.

[0130] The compiler constructs task blocks using M-dimensional row blocks and N-dimensional output blocks. The 64 output lines are divided into 32 M-dimensional row blocks (each containing 2 lines), and each M-dimensional row block contains 3 N-dimensional output blocks. The task graph forms a total of 96 independently schedulable output tasks, with each task performing all K-reduction, Bias, and GELU operations internally.

[0131] Four core groups process non-overlapping M-dimensional row blocks. Core groups 0 and 1 are bound to NUMA node 0, and core groups 2 and 3 are bound to NUMA node 1. Row fragments of input A are placed according to the core group executing the block; weight B is read-only data and can be placed as local copies on two NUMA nodes. Row fragments of output C are placed on the node where the core group executing that row block resides. Necessary cross-node data access or data transfer edges are recorded only when the end consumer crosses nodes.

[0132] The logical output C contains 196 FP32 elements per line, and the number of bytes per line is: byte.

[0133] 784 is not an integer multiple of the 64-byte cache line length. If different core groups concurrently write to adjacent lines, the end of one line and the beginning of the next line may be in the same cache line. The compiler internally aligns the output line span upwards to 832 bytes in the physical layout, i.e., adding 48 bytes of padding to each line, and records both the logical column number 196 and the physical line span of 832 bytes in the task mapping table.

[0134] For a line containing 2 rows Output line blocks, with padding for the sum of the two lines. It is 96 bytes. Each M-dimensional row block is computed only once, without repeated accumulation of the three N-dimensional output tasks within that row block. To conservatively estimate peak residency capacity, the fill retention of that row block is combined with the peak residency of a single N-dimensional task for back-substitution: byte.

[0135] 13792 bytes is still less than 24576 bytes, therefore cache line isolation does not violate on-chip resident conditions. If alignment padding causes resident capacity to exceed the limit, the compiler will reduce it. Change the core group line block boundaries or use a separate aligned output buffer, and include the corresponding rearrangement accesses in the candidate cost.

[0136] When an external interface requires a continuous 784-byte logical row span, the compiler generates a compaction step described by a task mapping table after the fused output and includes the compaction access cost in the main memory access cost; when subsequent operators accept tensor descriptions with physical row spans, they directly pass 832-byte physical row spans to avoid additional compaction.

[0137] Since there are no reduction data dependencies between output tasks, no global barriers are inserted between core groups; the same core group only performs intra-group synchronization before the double buffer is reused by the next task. If the increase in double buffering causes the resident capacity to exceed the limit, the buffer quantity and block size are treated as repairable fields and the data is re-supplied.

[0138] The compiler outputs the target scheduling vector. The core records for this embodiment are: RVV loop, register lifecycle allocation table, task mapping table, and conflict resolution record. Table 9 shows these records.

[0139] Table 9 Before Repair After repair Comparison table of various indicators

[0140] The above results demonstrate that the method described in this invention is not... It is not a direct discard, nor is it a passive insertion of load and storage after a backend overflow occurs. Instead, it is based on the physical register set exceeding the limit caused by VR-ACC. The constraints were reduced from 4 to 3, and the repaired register occupancy, resident capacity, and number of output blocks were re-substituted into the constraints. The repair candidate, while retaining complete fusion, reduced the scheduling-level physical register overrun from 8 to 0, and retained a smaller number of N-dimensional output blocks compared to the feasible candidate with LMUL equal to 1.

[0141] Figure 2 This is a flowchart of the candidate scheduling vector resource evaluation and register conflict identification process. The flowchart uses the RVV hardware resource description, candidate scheduling vectors, and active interval set as input to calculate the VLMAX corresponding to each candidate scheduling vector, the EMUL of each active vector value, and the maximum physical vector register occupancy (Rphy). Then, candidate scheduling vectors with the same fields except LMUL are grouped into a comparison group to determine whether a candidate with a larger LMUL exceeds the number of allocable physical vector registers while achieving vector segmentation or iterative benefits. If it does, a register group conflict state is generated; otherwise, other constraint checks are performed. In the resource evaluation, the set of active vector values ​​at each program location is determined based on the active interval. Each vector value is converted to physical vector register occupancy using LMUL or EMUL and summed. The maximum sum at each program location is taken as Rphy. This occupancy information is used for subsequent conflict source identification and targeted repair.

[0142] Figure 3This diagram illustrates the process of identifying, targeting, and performing constraint-based back-substitution for register set conflicts. Starting from the register set conflict state, the diagram selects a repair direction based on the primary conflict source: when the source is a parallel accumulation vector (VR-ACC), the output dimension block is reduced; when the source is a reduction intermediate quantity, the reduction dimension block is reduced; when the source is an activation temporary quantity (VR-TMP), the temporary quantity generation timing is adjusted or the fusion boundary is shortened; when the source is an operand vector (VR-OP), the number of operand vector groups prefetched or held simultaneously is reduced, or the loading timing is adjusted. The diagram merges activation temporary quantities and operand vectors into a single branch; the actual repair action is selected based on the specific conflict source. After generating the repair candidate scheduling vector, register occupancy, on-chip resident capacity, and related memory access constraints are recalculated and back-substitution verification is performed; candidates that satisfy all constraints are added to the feasible candidate set; otherwise, they fall back to a smaller LMUL or continue repair.

[0143] Figure 4 This is a flowchart of block-based loop progression and vector register reuse based on the actual VL. The flowchart shows the process from left to right: The compiler performs a vector length setting operation (represented by `vsetvl` in the diagram) based on the current AVL and obtains the actual VL; during the K reduction phase, VR-ACC is maintained and VR-OP is reused briefly; after reduction, VR-OP is released; upon entering the Bias / GELU post-processing phase, the vector length is reset and the VR-TMP temporary vector register set is reused; subsequently, calculations and storage are performed according to the actual VL, addresses and remaining elements are updated, and the next task block is processed after the current segment is completed.

[0144] Figure 5 This is a flowchart illustrating the optional multi-core NUMA mapping, cache line isolation, and on-chip resident capacity back-substitution process. The diagram shows two NUMA nodes configured with local input shards and weight replicas, respectively, and the core groups within each node mapped to the corresponding output line blocks. Each core group processes a set of non-overlapping output line blocks. Cache line isolation is then performed, and Tpad is calculated, with the fill amount back-substituted to the on-chip resident capacity. If the resident capacity constraint is not met, the block or task mapping is adjusted, and the back-substitution is performed again. Once the constraint is satisfied, the task mapping table is output.

[0145] In addition, this solution is also applicable to Conv and Attention; the Conv and Attention methods share the same core processing mechanism as the above embodiments, only the iteration domain, activity value type and modifiable block fields are different.

[0146] Example 2 In a typical embodiment of the present invention, an RVV compilation optimization system based on conflict resolution is provided, comprising: The fusion subgraph analysis module is used to obtain the unified iteration domain and active interval set of the fusion candidate subgraphs. Candidate scheduling vector generation module: used to generate a set of candidate scheduling vectors based on the unified iteration domain and active interval set, combined with hardware resource parameters; Physical resource assessment and conflict resolution module: used to calculate the maximum physical vector register occupancy and on-chip resident capacity of each candidate scheduling vector, and determine the program location that obtains the maximum physical vector register occupancy and the type of active vector value that contributes the most to the occupancy at the program location based on the active range; identify register conflicts in candidate comparison groups where only LMULs are different; and perform targeted repair on output blocks, reduction blocks, or fusion boundaries based on the active vector value type to resolve register conflicts. Constraint Back-substitution Filtering Module: Used to perform constraint back-substitution on the repaired candidate scheduling vectors, and generate a feasible candidate set based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints; Target selection output module: used to select the target scheduling vector from the feasible candidate set as the RVV compilation optimization result.

[0147] Example 3 The purpose of this embodiment is to provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps of the method of Embodiment 1.

[0148] Example 4 The purpose of this embodiment is to provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method of Embodiment 1.

[0149] The steps and methods involved in Embodiments 3 and 4 above correspond to those in Embodiment 1. For specific implementation details, please refer to the relevant description section of Embodiment 1. The term "computer-readable storage medium" should be understood as a single medium or multiple media including one or more instruction sets; it should also be understood as including any medium capable of storing, encoding, or carrying an instruction set for execution by a processor and enabling the processor to perform any of the methods in this invention.

[0150] Those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computer devices. Optionally, they can be implemented using computer-executable program code, thereby allowing them to be stored in a storage device for execution by a computer device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. The present invention is not limited to any particular combination of hardware and software.

[0151] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

[0152] While the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, this is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative effort based on the technical solutions of the present invention are still within the scope of protection of the present invention.

Claims

1. A RVV compilation optimization method based on conflict resolution, characterized in that, include: Obtain the unified iteration domain and active interval set of the fusion candidate subgraph; Based on the unified iteration domain and active interval set, a candidate scheduling vector set is generated in combination with hardware resource parameters; Calculate the maximum physical vector register occupancy and on-chip resident capacity for each candidate scheduling vector, and determine the program location that obtains the maximum physical vector register occupancy and the type of active vector value that contributes the most to the occupancy at the program location based on the active interval; In candidate comparison groups where only LMUL differs, register conflicts are identified; targeted repairs are performed on output blocks, reduction blocks, or fusion boundaries based on the active vector value type to resolve register conflicts. The repaired candidate scheduling vectors are subjected to constraint back-substitution, and a feasible candidate set is generated based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints. The target scheduling vector is selected from the feasible candidate set as the RVV compilation optimization result.

2. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, The candidate scheduling vector includes at least the fusion boundary, output dimension block, reduction dimension block, selected vector element width, vector register group multiplier, and vector register lifecycle strategy. The number of parallel accumulated vector groups is determined by the mapping rules of the vector microkernel. When the output dimension block is modified, the number of parallel accumulated vector groups is recalculated.

3. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, Calculate the maximum physical vector register occupancy for each candidate scheduling vector, including: The effective vector register group ratio of each active vector value is determined based on the effective element width of each active vector value and the vector register group ratio. For each program location, the active vector values ​​participating in the candidate allocation are converted into physical vector register occupancy according to the corresponding effective vector register group ratio and register group alignment rules, and then summed. Take the maximum sum of all program locations and use it as the maximum physical vector register occupancy for the candidate scheduling vector.

4. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, The on-chip resident capacity is obtained by summing the number of bytes corresponding to the input fragment, weight fragment, broadcast parameter fragment, output fragment, fused intermediate fragment, boundary swap-in and swap-out data, buffer and cache line alignment filling corresponding to the current candidate scheduling vector.

5. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, The physical vector register constraint is that the maximum physical vector register occupancy does not exceed the number of allocable physical vector registers; The number of allocatable physical vector registers is the total number of physical vector registers minus the number of registers reserved by the target backend and not participating in candidate allocation.

6. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, In candidate comparison groups where only LMUL differs, register conflicts are identified by grouping two candidates whose candidate fields are identical except for LMUL into a comparison group. The candidate with the larger vector register group multiplier in the comparison group is determined as the first candidate, and the candidate with the smaller vector register group multiplier is determined as the second candidate; When the first candidate has a smaller number of vector segments or a smaller number of vector loop iterations than the second candidate due to the increased vector register group ratio, and the maximum physical vector register occupied by the first candidate exceeds the number of allocable physical vector registers, a register conflict is determined to exist.

7. The RVV compilation optimization method based on conflict resolution as claimed in claim 1, wherein, The targeted repair includes: When the active vector value type is a parallel accumulation vector, the output dimension block that determines the number of parallel accumulation vector groups is reduced and the number of parallel accumulation vector groups is recalculated; When the active vector value type is a reduction intermediate quantity, reduce the reduction dimension block size; When the active vector value type is an active temporary quantity, the generation sequence of the temporary quantity is changed or the fusion boundary is shortened, and the active interval set is regenerated after the fusion boundary is shortened. When the active vector value type is an operand vector, reduce the number of operand vector groups that are prefetched or held simultaneously, or change the loading timing of the operand vectors.

8. A conflict resolution based RVV compilation optimization system characterized in that, include: The fusion subgraph analysis module is used to obtain the unified iteration domain and active interval set of the fusion candidate subgraphs. Candidate scheduling vector generation module: used to generate a set of candidate scheduling vectors based on the unified iteration domain and active interval set, combined with hardware resource parameters; Physical resource assessment and conflict resolution module: used to calculate the maximum physical vector register occupancy and on-chip resident capacity of each candidate scheduling vector, and determine the program location that obtains the maximum physical vector register occupancy and the type of active vector value that contributes the most to the occupancy at the program location based on the active range; In candidate comparison groups where only LMUL differs, register conflicts are identified; targeted repairs are performed on output blocks, reduction blocks, or fusion boundaries based on the active vector value type to resolve register conflicts. Constraint Back-substitution Filtering Module: Used to perform constraint back-substitution on the repaired candidate scheduling vectors, and generate a feasible candidate set based on the candidate scheduling vectors that satisfy the physical vector register constraints and on-chip resident capacity constraints; Target selection output module: used to select the target scheduling vector from the feasible candidate set as the RVV compilation optimization result.

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

10. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1-7.