A GPU program compilation acceleration method

By building a temporary optimization compilation result library and reusing the optimized compilation results of GPU programs using the feature value mapping table, the problems of repeated analysis and optimization in the existing technology are solved, the GPU compilation efficiency is improved, and the application performance is improved.

CN118550547BActive Publication Date: 2024-11-08WUHAN LINGJIU MICROELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411014439.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-11-08
Estimated Expiration
2044-07-26

AI Technical Summary

Technical Problem

The existing GPU compiler has repeated analysis and optimization work during the compilation process, resulting in wasted time and affecting the performance of graphics or computing applications.

Method used

By building a temporary optimization compilation result library, reuse the optimized compilation results of GPU programs using coarse-grained and fine-grained eigenvalue mapping tables, reduce duplicate compilation and optimization operations, and improve compilation efficiency.

Benefits of technology

It significantly reduces the compilation time of GPU programs, improves the performance of graphics or computing applications, and saves resource consumption during compilation optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550547B_ABST
    Figure CN118550547B_ABST
Patent Text Reader

Abstract

The present invention provides a GPU program compilation acceleration method, which reduces the compilation time of the GPU program by reusing the optimized compilation results of the GPU program or reusing the optimized compilation results of the basic blocks of the intermediate representation form of the GPU program, thereby improving the performance of graphics or computing applications.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of GPU program compilation, and more specifically, to a GPU program compilation acceleration method. Background Art

[0002] The compilation process of the existing GPU compiler is as follows Figure 1 As shown in the figure, first, the GPU program (such as GLSL shader, HLSL shader, OpenCL computing kernel, etc.) will be compiled into an intermediate representation. The intermediate representation is generally an equivalent representation of the GPU program composed of lower-level intermediate representation instructions. The intermediate representation generally has a graph structure, in which each node corresponds to an intermediate instruction, and each longest branchless intermediate instruction sequence constitutes a basic block. The intermediate instructions are generally low-level instructions in the form of three-address codes, such as "add dst src1 src2" means "dst=src1+src2"; then the GPU compiler optimizes the intermediate representation. The basic block is generally used as a unit for the optimization of the intermediate representation due to its branchless structure. The optimization of the intermediate representation generally includes optimization within the basic block and optimization across basic blocks; finally, the optimized intermediate representation will be further converted into machine code that can be executed on the GPU hardware to complete the compilation.

[0003] When a graphics or computing application uses a GPU, it is necessary to compile the GPU program (such as GLSL shader, HLSL shader, OpenCL computing kernel, etc.) during the application running. Therefore, the time overhead of the GPU program compilation process will affect the performance of the graphics or computing application. The bottleneck of the GPU program compilation process lies in optimizing this link.

[0004] Existing GPU compiler technology will perform a corresponding complete compilation process for each independent GPU program character stream input to be compiled. For highly similar parts in different GPU programs, the same analysis and optimization work is often repeated to obtain the same results, resulting in a waste of time and further affecting the performance of graphics or computing applications. Summary of the invention

[0005] The present invention aims at solving the technical problems existing in the prior art and provides a GPU program compilation acceleration method, comprising:

[0006] Step S1: Obtain the character stream of the GPU program to be compiled;

[0007] Step S2: Calculate the coarse-grained feature value of the character stream of the GPU program to be compiled;

[0008] Step S3: searching in the coarse-grained feature value mapping table in the temporary optimized compilation result library, if there is an entry in the coarse-grained feature value mapping table whose index is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled, then proceeding to step S10, otherwise proceeding to step S4;

[0009] Step S4: compile the character stream of the GPU program to be compiled to generate an intermediate representation;

[0010] Step S5: traverse the basic blocks in the intermediate representation form, calculate the fine-grained feature value of each basic block, and search in the fine-grained feature value mapping table of the temporary optimized compilation result library. If there is an entry with an index equal to the fine-grained feature value of the current basic block in the fine-grained feature value mapping table, go to step S7, otherwise go to step S6, and after traversing all basic blocks, go to step S8;

[0011] Step S6: Optimize the current basic block, use the fine-grained feature value as an index, combine the index and the basic block optimization compilation result to form a fine-grained temporary optimization result entry, and store it in the fine-grained feature value mapping table of the temporary optimization compilation result library, and then go to step S5;

[0012] Step S7: using the fine-grained temporary optimization result in the entry with the same index as the fine-grained feature value of the current basic block in the fine-grained feature value mapping table as the current basic block optimization compilation result, and proceeding to step S5;

[0013] Step S8: Optimize the intermediate representation across basic blocks to obtain an optimized compilation result of the GPU program to be compiled;

[0014] Step S9: using the coarse-grained feature value as an index, the index and the optimization compilation result of the GPU program to be compiled are combined into a coarse-grained temporary optimization result entry and stored in a coarse-grained feature value mapping table in the temporary optimization compilation result library, and then proceeding to step S11;

[0015] Step S10: using the coarse-grained temporary optimization result in the entry whose index in the coarse-grained feature value mapping table is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled as the optimization compilation result of the GPU program to be compiled;

[0016] Step S11: outputting the optimized compilation result of the GPU program to be compiled.

[0017] The present invention provides a GPU program compilation acceleration method, which reduces the compilation time of the GPU program by reusing the optimized compilation results of the GPU program or reusing the optimized compilation results of the basic blocks of the intermediate representation form of the GPU program, thereby improving the performance of the graphics or computing application program. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A schematic diagram of the compilation process of an existing GPU compiler;

[0019] Figure 2 A flowchart of a GPU program compilation acceleration method provided by the present invention;

[0020] Figure 3 A schematic diagram of the overall process of a GPU program compilation acceleration method provided by the present invention;

[0021] Figure 4 A schematic diagram of the composition of the library for temporarily storing optimized compilation results;

[0022] Figure 5 It is a schematic diagram of the basic block instruction encoding and sequence of the intermediate representation;

[0023] Figure 6 A schematic diagram of an embodiment of a GPU program compilation acceleration method;

[0024] Figure 7 A schematic diagram of an embodiment of a GPU program compilation acceleration method in a GPU virtualization scenario. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. In addition, the technical features in the various embodiments or single embodiments provided by the present invention can be arbitrarily combined with each other to form a feasible technical solution. This combination is not subject to the constraints of the sequence of steps and / or the structural composition mode, but must be based on the ability of ordinary technicians in this field to achieve. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0026] The present invention builds a temporary optimized compilation result library across applications and virtual machines, and reuses some optimized compilation results to speed up the compilation of GPU programs. Figure 2 As shown, compared to Figure 1 The traditional compilation method reuses the optimized compilation results in the GPU program source code compilation stage and the basic block optimization stage, reducing repeated compilation and optimization operations to save compilation time. Figure 2 and Figure 3 , the main steps of the method of the present invention are:

[0027] Step S1: Obtain the character stream of the GPU program to be compiled.

[0028] Step S2: Calculate the coarse-grained feature value of the character stream of the GPU program to be compiled.

[0029] The step S2: calculating the coarse-grained feature value of the character stream of the GPU program to be compiled includes: using a hash function to calculate a hash value hash1 of the character stream of the GPU program to be compiled as the coarse-grained feature value of the character stream of the GPU program to be compiled.

[0030] It is understandable that, after obtaining the character stream of the GPU program to be compiled, a hash value of the character stream of the GPU program to be compiled is calculated using a hash function as a coarse-grained feature value. Of course, the method for calculating the coarse-grained feature value of the character stream of the GPU program to be compiled is not limited to the hash function, and other calculation methods can also be used to calculate the coarse-grained feature value of the character stream of the GPU program to be compiled.

[0031] Step S3: search in the coarse-grained feature value mapping table in the temporary optimized compilation result library. If there is an entry in the coarse-grained feature value mapping table whose index is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled, go to step S10, otherwise go to step S4.

[0032] It is understandable that the coarse-grained feature value of the character stream of the GPU program to be compiled is searched in the coarse-grained feature value mapping table in the temporary optimized compilation result library. If the same coarse-grained feature value can be found in the coarse-grained feature value mapping table, it means that the optimized compilation result of the GPU program is already in the temporary optimized compilation result library, and there is no need to optimize the GPU program to be compiled again. The GPU optimized compilation result of the same coarse-grained feature value in the coarse-grained feature value mapping table is directly used as the optimized compilation result of the GPU program to be compiled, that is, step S10 is executed, which saves the time consumed in compiling the GPU program to be compiled.

[0033] If the optimized compilation result of the GPU program with the same coarse-grained feature value cannot be found in the coarse-grained feature value mapping table, it is necessary to compile the GPU program to be compiled, and step S4 is executed.

[0034] Among them, the temporary optimized compilation result library is composed of Figure 4 As shown, the entries in the temporary optimized compilation result library are temporary optimized compilation results, and the eigenvalue mapping table is used to search for entries based on eigenvalues. The temporary optimized compilation results are divided into two categories: coarse-grained and fine-grained. The coarse-grained temporary optimized compilation results are the optimized compilation results of the GPU program, and the fine-grained temporary optimized compilation results are the optimized compilation results of the basic block. There is an eigenvalue mapping table for each of the two categories of entries, and the upper limit of the number of the two categories of entries can be configured separately to control the size of the temporary optimized compilation result library.

[0035] The temporary optimized compilation result library includes a coarse-grained feature value mapping table and a fine-grained feature value mapping table, wherein the coarse-grained feature value mapping table includes multiple entries, each entry includes an index and the corresponding optimized compilation result of the GPU program, wherein the coarse-grained feature value is a hash value calculated by inputting a hash function into the source code string data of the GPU program. The fine-grained feature value mapping table also includes multiple entries, each entry includes an index and the optimized compilation result of each basic block in the corresponding GPU program, wherein the fine-grained feature value is an index, and the fine-grained feature value is a hash value calculated by inputting a hash function into the instruction sequence of the basic block of the intermediate representation of the GPU program.

[0036] Among them, the entries of the temporary optimized compilation result library are composed of the optimized compilation results and the feature values ​​of the GPU program. The feature value mapping table is used to manage the search, addition and deletion of entries. When the configured limit on the number of entries is reached, the entries that have not been accessed for the longest time are deleted first.

[0037] Step S4: compile the character stream of the GPU program to be compiled to generate an intermediate representation.

[0038] It is understandable that when the optimized compilation result of the GPU program cannot be found in the temporary optimized compilation result library, it is necessary to compile the character stream of the GPU program to be compiled to generate an intermediate representation, which includes multiple basic blocks. The basic block instruction sequence is shown as follows: Figure 5 As shown, each intermediate representation instruction has its encoding, and the basic block instruction sequence is the sequence of instruction encodings therein.

[0039] Step S5: traverse the basic blocks in the intermediate representation, calculate the fine-grained feature value of each basic block, and search in the fine-grained feature value mapping table of the temporary optimized compilation result library. If there is an entry with an index equal to the fine-grained feature value of the current basic block in the fine-grained feature value mapping table, go to step S7, otherwise go to step S6, and after traversing all basic blocks, go to step S8.

[0040] It is understandable that for each basic block of the intermediate representation of the GPU program to be compiled, the fine-grained feature value of each basic block is calculated, wherein the fine-grained feature value of the basic block can be calculated using a hash function according to the instruction sequence of the basic block. The fine-grained feature value of the basic block is searched in the fine-grained feature value mapping table of the temporary optimized compilation result library. If there is an optimized compilation result of the basic block with the same fine-grained feature value in the fine-grained feature value mapping table, the optimized compilation result of the basic block in the fine-grained feature value mapping table is directly used as the optimized compilation result of the basic block to be compiled, and step S7 is executed. If the index of the same fine-grained feature value cannot be found in the fine-grained feature value mapping table, it means that there is no optimized compilation result of the basic block to be compiled in the fine-grained feature value mapping table, and the basic block needs to be compiled and optimized, and step S6 is executed. Each basic block generated by the intermediate representation of the GPU program to be compiled is traversed, and step S8 is executed.

[0041] Step S6: Optimize the current basic block, use the fine-grained feature value as an index, combine the index and the basic block optimization compilation result to form a fine-grained temporary optimization result entry, and store it in the fine-grained feature value mapping table of the temporary optimization compilation result library, and then go to step S5.

[0042] It is understandable that if the optimized compilation result of the corresponding basic block cannot be found in the fine-grained feature value mapping table, it is necessary to compile and optimize the current basic block. After the compilation optimization, the fine-grained features of the basic block are used as indexes, and the index and the basic block optimized compilation result are combined into a fine-grained temporary optimization result entry and stored in the fine-grained feature value mapping table of the temporary optimization compilation result library for use in searching according to the fine-grained feature values ​​in step S5.

[0043] Step S7: Use the fine-grained temporarily stored optimization result in the entry with the same index as the fine-grained feature value of the current basic block in the fine-grained feature value mapping table as the current basic block optimization compilation result, and proceed to step S5.

[0044] When the fine-grained temporary optimization result corresponding to the same fine-grained characteristic value is found in the fine-grained characteristic value mapping table of the temporary optimization compilation result library according to the fine-grained characteristic value of the basic block, that is, the optimized compilation result of the basic block, the fine-grained temporary optimization result in the fine-grained characteristic value mapping table is used as the optimized compilation result of the current basic block.

[0045] Step S8: Optimize the intermediate representation across basic blocks to obtain an optimized compilation result of the GPU program to be compiled.

[0046] It is understandable that when the optimized compilation result is completed for each basic block generated by the intermediate representation of the GPU program to be compiled, the intermediate representation is optimized across basic blocks to obtain the optimized compilation result of the GPU program to be compiled.

[0047] Step S9: using the coarse-grained feature value as an index, the index and the optimization compilation result of the GPU program to be compiled are combined into a coarse-grained temporary optimization result entry and stored in a coarse-grained feature value mapping table in the temporary optimization compilation result library, and then proceeding to step S11.

[0048] It is understandable that after step S8 obtains the optimized compilation result of the GPU program to be compiled, the coarse-grained feature value is used as an index, and the index and the optimized compilation result of the GPU program to be compiled are combined into a coarse-grained temporary optimization result entry and stored in the coarse-grained feature value mapping table in the temporary optimization compilation result library.

[0049] Step S10: using the coarse-grained temporary optimization result in the entry whose index in the coarse-grained feature value mapping table is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled as the optimized compilation result of the GPU program to be compiled.

[0050] Step S11: outputting the optimized compilation result of the GPU program to be compiled.

[0051] It can be understood that after the corresponding GPU program optimization compilation result is found in the coarse-grained feature value mapping table in the temporary optimization compilation result library according to the coarse-grained feature value of the GPU program to be compiled, the GPU program optimization compilation result in the coarse-grained feature value mapping table is used as the optimization compilation result of the current GPU program to be compiled, and the optimization compilation result of the GPU program to be compiled is output.

[0052] It should be noted that the temporary optimized compilation result library is stored in the storage space shared by different GPU compiler instances. In a single-machine application scenario, the temporary optimized compilation result library in the storage space can be accessed by multiple instances of the GPU compiler; in a virtual machine application scenario, the temporary optimized compilation result library is stored in the Host storage and can be accessed by GPU compiler instances in different virtual machines.

[0053] In the host application scenario, the GPU driver allocates storage space to store the temporary optimization compilation result library and manages the access of different GPU instances to the temporary optimization compilation result library; in the virtual machine application scenario, the temporary optimization compilation result library is stored in the host storage, and the GPU virtualization layer manages the access of GPU driver instances in different virtual machines to the unified temporary optimization compilation result library. This ensures the reuse of optimization compilation results across applications and virtual machines.

[0054] The GPU program compilation acceleration method provided by the present invention is described below based on a specific example. Figure 6, both GPU compiler instances (calls to the compiler by different applications) can access the temporary optimized compilation result library. In the embodiment of the present invention, it is assumed that there is no entry in the temporary optimized compilation result library, and graphics application 1 is executed first, and graphics application 2 is executed later. Graphics application 1 inputs shader 1 into GPU compiler instance 1 for compilation, calculates the coarse-grained feature value of shader 1, searches the temporary optimized compilation result library, where there is no matching entry, so the shader 1 source code is subjected to a complete compilation optimization process, and then the coarse-grained feature value of shader 1 and the optimized compilation result of shader 1 are combined into a coarse-grained entry, which is stored in the temporary optimized compilation result library; when graphics application 2 is executed later, shader 2 is input into GPU compiler instance 2 for compilation, and the coarse-grained feature value of shader 2 source code is used to calculate the coarse-grained feature value during the compilation process, and the shader 1 optimized compilation result entry is matched in the temporary optimized compilation result library, and the compilation optimization process of shader 2 is omitted after reuse, thereby reducing the compilation time.

[0055] Figure 7 The figure shows an embodiment of the method of the present invention in a GPU virtualization scenario, where different GPU compiler instances in different virtual machines access a unified temporary optimized compilation result library in the Host host storage, and reuse the optimized compilation results to reduce the compilation time of the GPU program.

[0056] The present invention provides a GPU program compilation acceleration method. For complete GPU programs or basic blocks with the same characteristics among multiple GPU programs to be compiled, the method of the present invention can reduce the repeated analysis and optimization process of the execution part, reduce the optimization time of the GPU program, and thus improve the performance of the GPU application. Specifically:

[0057] (1) When the GPU compiler compiles different GPU programs, there may be the same n GPU program inputs in multiple GPU programs. The compilation acceleration method of this patent can reuse the optimized compilation result of the first of these n GPU programs, saving the complete compilation optimization process of n-1 GPU programs and reducing the compilation optimization time of the GPU program.

[0058] (2) When the GPU compiler compiles different GPU programs, there may be n basic blocks with the same intermediate instruction sequence in the intermediate representation of one or more GPU programs. The compilation acceleration method of this patent can reuse the first optimized compilation result of these n basic blocks, saving the intra-block optimization process of n-1 basic blocks and reducing the optimization time of the GPU program.

[0059] (3) The upper limit of the number of entries of the two granularities in the temporary storage of the optimization compilation result library can be configured separately and can be adjusted according to the specific usage scenario.

[0060] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0061] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0062] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0063] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0064] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0065] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0066] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A GPU program compilation acceleration method, It is characterized in that include: Step S1: Obtain the character stream of the GPU program to be compiled; Step S2: Calculate the coarse-grained feature value of the character stream of the GPU program to be compiled; Step S3: searching in the coarse-grained feature value mapping table in the temporary optimized compilation result library, if there is an entry in the coarse-grained feature value mapping table whose index is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled, then proceeding to step S10, otherwise proceeding to step S4; Step S4: compile the character stream of the GPU program to be compiled to generate an intermediate representation; Step S5: traverse the basic blocks in the intermediate representation form, calculate the fine-grained feature value of each basic block, and search in the fine-grained feature value mapping table of the temporary optimized compilation result library. If there is an entry with an index equal to the fine-grained feature value of the current basic block in the fine-grained feature value mapping table, go to step S7, otherwise go to step S6, and after traversing all basic blocks, go to step S8; Step S6: Optimize the current basic block, use the fine-grained feature value as an index, combine the index and the basic block optimization compilation result to form a fine-grained temporary optimization result entry, and store it in the fine-grained feature value mapping table of the temporary optimization compilation result library, and then go to step S5; Step S7: using the fine-grained temporary optimization result in the entry with the same index as the fine-grained feature value of the current basic block in the fine-grained feature value mapping table as the current basic block optimization compilation result, and proceeding to step S5; Step S8: Optimize the intermediate representation across basic blocks to obtain an optimized compilation result of the GPU program to be compiled; Step S9: using the coarse-grained feature value as an index, the index and the optimization compilation result of the GPU program to be compiled are combined into a coarse-grained temporary optimization result entry and stored in a coarse-grained feature value mapping table in the temporary optimization compilation result library, and then proceeding to step S11; Step S10: using the coarse-grained temporary optimization result in the entry whose index in the coarse-grained feature value mapping table is equal to the coarse-grained feature value of the character stream of the GPU program to be compiled as the optimization compilation result of the GPU program to be compiled; Step S11: outputting the optimized compilation result of the GPU program to be compiled; The step S2: calculating the coarse-grained feature value of the character stream of the GPU program to be compiled, comprises: Use a hash function to calculate a hash value hash1 of the character stream of the GPU program to be compiled as a coarse-grained feature value of the character stream of the GPU program to be compiled; The step S5 calculates the fine-grained feature value of each basic block, including: A hash function is used to calculate the hash value hash2 of the basic block instruction encoding sequence as the fine-grained feature value of the basic block.

2. The GPU program compilation acceleration method according to claim 1, It is characterized in that The temporary optimized compilation result library is stored in a storage space shared by different GPU compiler instances.

3. The GPU program compilation acceleration method according to claim 2, It is characterized in that In a stand-alone application scenario, the temporary optimized compilation result library in the storage space can be accessed by multiple instances of the GPU compiler; In a virtual machine application scenario, the temporary optimized compilation result library is stored in the Host storage and can be accessed by GPU compiler instances in different virtual machines.