Code loop expansion processing method and system for double SIMD (Single Instruction Multiple Data) components

Through the compiler's automatic identification and optimization of loop expansion technology, the problem that the existing technology cannot efficiently utilize dual SIMD components is solved, and the code optimization for dual SIMD components is realized, and program performance is improved, especially in digital signal processing, big data and Application effects in the field of artificial intelligence.

CN118916038APending Publication Date: 2024-11-08Chinese People's Liberation Army Cyberspace Force Information Engineering University
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411042606.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-08

Smart Images

  • Figure CN118916038A_ABST
    Figure CN118916038A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer compiling, in particular to a code loop expansion processing method and system for double SIMD components, and the method comprises the steps: automatically vectorizing a target program through a compiler, and generating a vector statement; aiming at the automatic vectorization optimization requirement of the double SIMD component, identifying and marking loop bodies containing SIMD statements in vector statements; and when the marked loop body is traversed, if the target platform supports pipeline execution of the double SIMD components, loop expansion is executed on the loop body for specified times on the target platform. According to the method, the loop expansion facing the double SIMD components is realized in a mode of adding the compiling options, manual program modification is avoided, the use efficiency of the double SIMD components is improved, the requirement for the specific number of cycles of automatic loop expansion is met, the code characteristics of the non-vectorized loop body are not influenced, the code performance is improved, and the method is suitable for popularization and application. The method has a good application prospect in the fields of digital signal processing, big data, artificial intelligence, high-performance calculation and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer compilation, and in particular to a code loop unrolling processing method and system for dual SIMD components. Background Art

[0002] SIMD components refer to a set of dedicated multimedia extension instruction sets. This instruction set uses single instruction multiple data (SIMD) extension technology, which can perform the same operation on multiple data at the same time, called SIMD extension components. SIMD extension components can process data in multimedia programs in parallel, improving the running speed of multimedia programs. The implementation of dual SIMD components on domestic Shenwei processors draws on the pipeline technology when designing CPUs. Pipeline technology refers to a quasi-parallel processing implementation technology in which multiple instructions overlap to perform operations when a program is executed. That is, a sequential process is decomposed into several sub-processes, and each process can be effectively executed simultaneously with other sub-processes. There are two sets of SIMD extension components on the domestic Shenwei processor, and they can be executed in a pipeline manner.

[0003] Automatic vectorization is an important compilation optimization method. It uses the data parallel processing capability provided by SIMD extension components to effectively improve program performance and plays an important role in many application scenarios such as digital signal processing, big data, artificial intelligence, and high-performance computing. Now mainstream compilers such as GCC, LLVM, and ICC all support automatic vectorization optimization. Loop unrolling is a common program optimization technology. It is an optimization method that sacrifices the size of the program to speed up the execution of the program. This technology can be completed by application programmers or automatically optimized by the compiler. Loop unrolling reduces the number of loop branch instructions executed by copying the code in the loop body multiple times, increases the space for processor instruction scheduling, and ultimately obtains more instruction-level parallelism. Reasonable use of loop unrolling technology can increase register reuse. However, the number of loop unrolling is not the greater the better. When unrolling, it needs to be handled according to the characteristics of the target platform. If the number of unrolling is too many, the intermediate variables will increase during program calculation, but the number of registers of the target machine is fixed. When the number of variables exceeds the number of registers, the variables can only be stored in the stack, resulting in performance degradation.

[0004] Currently, there are three main loop unrolling technologies: (1) Manual unrolling. The application programmer manually unrolls the loop body the desired number of times. This method is inefficient and prone to errors. (2) Adding instruction statements. Add instruction statements to the specified loop body in the application to indicate that the loop body needs to be unrolled and how many times it needs to be unrolled. This solution also requires modifying the source program and adding appropriate instruction statements to the source program. (3) Adding compilation options during compilation to automatically unroll the loop. This method is the most efficient loop unrolling method, but it will unroll all loop bodies the same number of times. Existing loop unrolling technologies cannot meet the requirements for efficient use of dual SIMD components. Summary of the invention

[0005] To this end, the present invention provides a code loop unrolling processing method and system for dual SIMD components, which utilizes compiler optimization to automatically identify loop bodies containing vector statements and unroll the specified loop bodies a specific number of times, thereby meeting the purpose of efficiently utilizing dual SIMD components on a target platform and improving program code performance.

[0006] According to the design scheme provided by the present invention, on the one hand, a code loop unrolling processing method for a dual SIMD component is provided, which is used for compiling and optimizing target program codes, comprising:

[0007] Use the compiler to automatically vectorize the target program and generate vector statements;

[0008] To meet the needs of automatic vectorization optimization of dual SIMD components, identify and mark loop bodies containing SIMD statements in vector statements;

[0009] When traversing the marked loop body, if the target platform supports pipeline execution of dual SIMD components, loop unrolling is performed a specified number of times on the target platform.

[0010] As a code loop unrolling processing method for dual SIMD components of the present invention, further, a compiler is used to automatically vectorize the target program and generate vector statements, including:

[0011] The compiler is used to generate an intermediate representation of the target program, and each loop body of the target program is traversed, and all basic blocks in each loop body are traversed, and statements containing vector instructions in the basic block are obtained and the current loop body is marked.

[0012] As a code loop unrolling processing method for dual SIMD components of the present invention, further, identifying and marking the loop body containing SIMD statements in the vector statement, comprising:

[0013] It is determined whether a specified statement is used in a vector statement. If the specified statement is used, it is determined that the vector statement contains a SIMD statement, and a loop body corresponding to the vector statement is marked. The specified statement is an insn statement. If the specified statement is not used, the current loop body is skipped.

[0014] As the code loop unrolling processing method for dual SIMD components of the present invention, further, judging whether a specified statement is used in a vector statement also includes:

[0015] All innermost loop bodies in the vector statement are traversed to identify and mark the innermost loop body using the specified statement until all innermost loop bodies in the vector statement are traversed.

[0016] As a code loop unrolling processing method for dual SIMD components of the present invention, further, performing loop unrolling for a specified number of times on the loop body on the target platform comprises:

[0017] Classify loop unrolling according to the number of loop iterations;

[0018] According to the loop unrolling classification result, the corresponding function in the compiler is called to perform loop unrolling for the loop body for the specified number of times.

[0019] As a code loop unrolling processing method for a dual SIMD component of the present invention, the loop unrolling is further classified according to the number of loop iterations, including:

[0020] If the number of loop iterations is a constant, the corresponding loop unrolling is classified as the first category. If the number of loop iterations is calculated during runtime, the corresponding loop unrolling is classified as the second category. If the number of loop iterations is other cases, the loop unrolling is classified as the third category.

[0021] As a code loop unrolling processing method for dual SIMD components of the present invention, further, performing loop unrolling for a specified number of times on the loop body on the target platform comprises:

[0022] The loop body is unrolled a specified number of times using the loop unrolling method provided by the compiler, where the specified number of times is 2.

[0023] On the other hand, the present invention also provides a code loop unrolling processing system for dual SIMD components, which is used for compiling and optimizing target program codes, and comprises: a vectorization module, a tag recognition module and a loop unrolling module, wherein:

[0024] A vectorization module, used to automatically vectorize the target program using the compiler and generate vector statements;

[0025] A tag recognition module is used to identify and mark loop bodies containing SIMD statements in vector statements according to the automatic vectorization optimization requirements of dual SIMD components;

[0026] The loop unrolling module is used for executing the loop unrolling for a specified number of times on the target platform when traversing the marked loop body if the target platform supports pipeline execution of the dual SIMD components.

[0027] Beneficial effects of the present invention:

[0028] The present invention can use a compilation option different from a traditional loop unrolling option. The traditional loop unrolling option can unroll all loop bodies. In the scheme of this case, the compilation option can be used in the compiler to realize automatic determination of loop unrolling of loop bodies containing vectorized statements; the optimization pass is added in the compiler's intermediate optimization pass to realize automatic determination of loop unrolling of specific loop bodies, and there is no need to modify the source program. The optimization pass determines whether to unroll a loop body by traversing all the innermost loop bodies in all programs, looping insn statements containing vector mode data, and searching for loops containing special instructions or special data patterns in the compiler's intermediate optimization pass. All loop bodies can be traversed in the intermediate representation register transfer language rtl stage, and loop bodies that meet the conditions can be found in each loop body; loop unrolling for dual SIMD components can be realized only by adding compilation options, so that manual program modification is avoided, the use efficiency of dual SIMD components is improved, and program performance is improved. The invention has good application prospects in the fields of digital signal processing, big data, artificial intelligence, high-performance computing, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a schematic diagram of the code loop unrolling process for the dual SIMD component in the embodiment;

[0030] Figure 2 It is a schematic diagram of loop unrolling judgment logic for dual SIMD components in the embodiment;

[0031] Figure 3 It is a pseudo code diagram for implementing a specified function in the embodiment;

[0032] Figure 4 The pseudo code of the optimization process in the embodiment is shown. DETAILED DESCRIPTION

[0033] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.

[0034] Currently, mainstream compilers such as GCC have integrated a wealth of loop unrolling optimization options and guidance statements. However, these cannot meet the optimization requirements for dual SIMD components. If the existing loop unrolling compilation options of the compiler are used, the scalar and vector loop structures will be unrolled together. However, the actual situation is that the scalar loop body does not need to be unrolled. The number of registers used in the scalar loop body is different from the number of vector registers in the vector statement, and before the scalar unrolling, there is no analysis on whether the loop unrolling is needed. Therefore, unrolling the scalar loop body and the vector loop body at the same time will not achieve the expected execution acceleration.

[0035] Now the compilers are all integrated with guidance statements. By adding loop expansion guidance statements to the loop body in the program, the specified loop body can be expanded, and the expansion factor can also be specified. However, guidance statements require modifying the source program, which increases the workload of application programmers.

[0036] Therefore, in order to solve the problem of how to efficiently utilize the dual SIMD components in the domestic Shenwei processor, the embodiment of the present invention, see Figure 1 As shown, a code loop unrolling processing method for dual SIMD components is provided for compiling and optimizing target program codes, comprising:

[0037] S101. Automatically vectorize the target program and generate vector statements using a compiler.

[0038] Specifically, the compiler can be used to generate an intermediate representation of the target program, traverse each loop body of the target program, traverse all basic blocks in each loop body, obtain statements containing vector instructions in the basic block and mark the current loop body.

[0039] S102 . According to the automatic vectorization optimization requirement of the dual SIMD components, the loop body containing SIMD statements in the vector statements is identified and marked.

[0040] Specifically, by judging whether a specified statement is used in a vector statement, if the specified statement is used, it is determined that the vector statement contains a SIMD statement, and a loop body corresponding to the vector statement is marked. The specified statement is an insn statement. If the specified statement is not used, the current loop body is skipped.

[0041] All innermost loop bodies in the vector statement are traversed to identify and mark the innermost loop body using the specified statement until all innermost loop bodies in the vector statement are traversed.

[0042] like Figure 2As shown, in order to facilitate the recognition of vectorized statements in the intermediate conversion stage of the compiler, a pass can be inserted after the automatic vectorization optimization pass, named pass_rtl_unroll_loops_for_simd. This optimization pass is before the pass_rtl_unroll_loops optimization pass to ensure that it is not affected by all loop unrolling options. Figure 2 The entire loop unrolling judgment framework for the new optimization pass for dual SIMD components is presented in the figure. The implementation of this optimization pass is completed in the intermediate representation stage during compilation. First, if this optimization pass is used, you need to add compilation options during compilation. Secondly, in the analysis stage, determine whether there is a loop body containing SIMD statements in the program, and mark it after finding it. Finally, in the loop unrolling stage, determine whether the target platform supports pipeline execution of dual SIMD components and decide which execution method to use.

[0043] The compile option (-funroll-loops-simd) in stage 1 is added when compiling the program. The function of this option is to mark the program as needing to generate instructions to satisfy the dual SIMD part. This compile option is confirmed and added by the application programmer. This option is off by default.

[0044] Phase 2 is executed in the intermediate code representation phase of the program, i.e., the RTL phase. The object of processing is each loop body in the program. We traverse each loop body, traverse all basic blocks in each loop body, and find the basic blocks that contain statements using vector instructions. If there are statements containing vector instructions, the loop is marked.

[0045] In phase 3, the check_insn_contain_vector function is used to determine whether there is a vector statement in the loop body. The function is implemented as follows Figure 3 As shown. This function recursively traverses all insn statements in the loop body and checks whether the statements contain vector mode data. If yes, it returns true, otherwise it returns false.

[0046] S103 . When traversing the marked loop body, if the target platform supports pipeline execution of dual SIMD components, loop unrolling is performed a specified number of times on the target platform for the loop body.

[0047] Specifically, loop unrolling may be classified according to the number of loop iterations; and according to the loop unrolling classification result, a corresponding function in the compiler is called to perform loop unrolling for a corresponding specified number of times on the loop body.

[0048] If the number of loop iterations is a constant, the corresponding loop unrolling is classified as the first category. If the number of loop iterations is calculated during runtime, the corresponding loop unrolling is classified as the second category. If the number of loop iterations is other cases, the loop unrolling is classified as the third category.

[0049] The loop body is unrolled a specified number of times using the loop unrolling method provided by the compiler, where the specified number of times is 2.

[0050] After completing the traversal of all loops, the optimization pass will process the marked loop bodies. Before deciding to unroll the loop, determine whether the target platform supports dual SIMD components, that is, whether the target platform needs to unroll the vectorized loop body twice. If the target platform supports it, then decide to unroll the loop twice.

[0051] The pseudo code of the optimization process in this pass is shown in Algorithm 1. Among them, when deciding to unroll the loop, it is divided into three processing methods according to the different loop iterations: decide_unroll_constant_iterations, decide_unroll_runtime_iterations and decide_unroll_stupid. These three processing methods correspond to the number of loop iterations being constant, computable at runtime, and others. These three function implementations use the function processing procedures that come with the compiler to avoid the development of duplicate code. When using this optimization pass, you only need to add a compilation option to turn it on during compilation. After deciding to unroll the loop, this optimization pass subsequently uses the loop unrolling method that comes with GCC to unroll the loop body.

[0052] On the other hand, the present invention also provides a code loop unrolling processing system for dual SIMD components, which is used for compiling and optimizing target program codes, and comprises: a vectorization module, a tag recognition module and a loop unrolling module, wherein:

[0053] A vectorization module, used to automatically vectorize the target program using the compiler and generate vector statements;

[0054] A tag recognition module is used to identify and mark loop bodies containing SIMD statements in vector statements according to the automatic vectorization optimization requirements of dual SIMD components;

[0055] The loop unrolling module is used for executing the loop unrolling for a specified number of times on the target platform when traversing the marked loop body if the target platform supports pipeline execution of the dual SIMD components.

[0056] By adding optimization passes in the compiler, when compiling the program, after turning on the automatic vectorization optimization option for the dual SIMD component, the loop body that has been vectorized can be automatically expanded, and the expanded statements can be reordered through subsequent optimization passes to achieve automatic vectorization support for the dual SIMD component function on a specific target platform. This not only meets the requirement of automatic loop expansion for a specific number of loops, but also does not affect the code characteristics of the non-vectorized loop body, thereby improving code performance.

[0057] Unless otherwise specifically stated, the relative steps, numerical expressions and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present invention.

[0058] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0059] The units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods to implement the described functions for each specific application, but such implementation is not considered to be beyond the scope of the present invention.

[0060] Those skilled in the art will appreciate that all or part of the steps in the above method can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more integrated circuits, and accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of software function modules. The present invention is not limited to any specific form of combination of hardware and software.

[0061] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A code loop unrolling processing method for dual SIMD components, used for compiling and optimizing target program codes, characterized in that: Include: Use the compiler to automatically vectorize the target program and generate vector statements; To meet the needs of automatic vectorization optimization of dual SIMD components, identify and mark loop bodies containing SIMD statements in vector statements; When traversing the marked loop body, if the target platform supports pipeline execution of dual SIMD components, loop unrolling is performed a specified number of times on the target platform.

2. The code loop unrolling processing method for dual SIMD components according to claim 1, characterized in that: Use the compiler to automatically vectorize the target program and generate vector statements, including: The compiler is used to generate an intermediate representation of the target program, and each loop body of the target program is traversed, and all basic blocks in each loop body are traversed, and statements containing vector instructions in the basic block are obtained and the current loop body is marked.

3. The code loop unrolling processing method for dual SIMD components according to claim 1 or 2, characterized in that: Identify and mark loop bodies containing SIMD statements in vector statements, including: It is determined whether a specified statement is used in a vector statement. If the specified statement is used, it is determined that the vector statement contains a SIMD statement, and a loop body corresponding to the vector statement is marked. The specified statement is an insn statement. If the specified statement is not used, the current loop body is skipped.

4. The code loop unrolling processing method for dual SIMD components according to claim 3, characterized in that: Determine whether the specified statement is used in the vector statement, and also include: All innermost loop bodies in the vector statement are traversed to identify and mark the innermost loop body using the specified statement until all innermost loop bodies in the vector statement are traversed.

5. The code loop unrolling processing method for dual SIMD components according to claim 1, characterized in that: Performs loop unrolling on the target platform a specified number of times, including: Classify loop unrolling according to the number of loop iterations; According to the loop unrolling classification result, the corresponding function in the compiler is called to perform loop unrolling for the loop body for the specified number of times.

6. The code loop unrolling processing method for dual SIMD components according to claim 5, characterized in that: Loop unrolling is classified according to the number of loop iterations, including: If the number of loop iterations is a constant, the corresponding loop unrolling is classified as the first category. If the number of loop iterations is calculated during runtime, the corresponding loop unrolling is classified as the second category. If the number of loop iterations is other cases, the loop unrolling is classified as the third category.

7. The code loop unrolling processing method for dual SIMD components according to claim 1, characterized in that: Performs loop unrolling on the target platform a specified number of times, including: The loop body is unrolled a specified number of times using the loop unrolling method provided by the compiler, where the specified number of times is 2.

8. A code loop unrolling processing system for dual SIMD components, used for compiling and optimizing target program codes, characterized in that: Contains: vectorization module, tag recognition module and loop unrolling module, among which, A vectorization module, used to automatically vectorize the target program using the compiler and generate vector statements; A tag recognition module is used to identify and mark loop bodies containing SIMD statements in vector statements according to the automatic vectorization optimization requirements of dual SIMD components; The loop unrolling module is used for executing the loop unrolling for a specified number of times on the target platform when traversing the marked loop body if the target platform supports pipeline execution of the dual SIMD components.

9. An electronic device, characterized in that: include: at least one processor, and a memory coupled to the at least one processor; The memory stores a computer program, and the computer program can be executed by the at least one processor to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 7 can be implemented.