Method, apparatus, medium and program product for compiling kernel functions

By converting compilation modules into compilation sub-modules and configuring resources, the problems of low resource utilization and compilation efficiency in traditional methods are solved, asynchronous compilation and independent resource allocation are achieved, and resource utilization and compilation efficiency are significantly improved.

CN118409758BActive Publication Date: 2024-09-06北京壁仞科技开发有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410888968.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-09-06
Estimated Expiration
2044-07-03

AI Technical Summary

Technical Problem

The traditional method for compiling kernel functions has the problems of low resource utilization and low compilation efficiency of multi-function modules, mainly due to the difficulty in resource allocation and extended compilation time caused by global resource interdependence and synchronous compilation.

Method used

Convert the compilation module into a compilation sub-module, so that each core function and the device function it calls are configured in the same compilation sub-module, and configure resources for each compilation sub-module to achieve asynchronous compilation and independent allocation of resources.

Benefits of technology

Improved resource utilization and compilation efficiency of multi-function modules, and significantly reduced compilation time through asynchronous compilation and independent resource configuration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409758B
    Figure CN118409758B
Patent Text Reader

Abstract

The present invention relates to a method, device, medium and program product for compiling a kernel function. The method comprises: converting a compiling module into a compiling submodule, so that each kernel function and the device function called by it are configured in the same compiling submodule; for the compiling submodule, configuring resources for allocating data used by the device function in the compiling submodule; and compiling for each compiling submodule. The present invention can effectively improve the utilization rate of resources and the compiling efficiency of multi-function modules.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention generally relate to the field of data processing, and more specifically to the field of deep learning, a method for compiling a kernel function, a computing device, a computer-readable storage medium, and a computer program product. Background Art

[0002] In the programming of artificial intelligence chips (for example, Graphics Processing Unit (GPU), General-Purpose Computing on Graphics Processing Unit (GPGPU)), functions are divided into two types: kernel functions (i.e., Kernel) and device functions (i.e., Device functions). Kernel can only be called by functions on the host side, while Device functions can be called by both Kernel and Device functions. Therefore, Kernel can be considered as the entrance to GPU programs. As the number of users gradually increases, GPU programs become more and more complex. Source files (SourceFile) often contain a large number of Kernel and Device functions, and each Kernel may call multiple Device functions, and each Device function may also be called by multiple Kernels.

[0003] Traditional methods for compiling kernel functions, such as Link Time Optimization (LTO) compiler optimization methods, are a method for achieving better runtime performance through whole program analysis and cross-module optimization. In the front-end stage of compilation, the Low Level Virtual Machine (LLVM) generates an intermediate language representation (i.e., LLVM IR, IR stands for Intermediate Representation) bitcode file of LLVM generated by the high-level language through the front-end. The suffix of the LLVM IR bitcode file is usually ".bc". The linker recognizes these LLVM IR bitcode files and calls the back-end to generate executable files (i.e., Executable and Linkable Format, ELF files) during the linking process.

[0004] In the above-mentioned traditional compilation method, since the device function may be called by multiple kernel functions in the same program file or compilation module, there is a problem of global resource interdependence, which makes it difficult to allocate some global and limited resources, and thus makes it difficult to effectively improve resource utilization. In addition, since the device function of the same program file or compilation module is called by multiple kernel functions, various synchronizations are required during compilation, and asynchronous compilation is difficult, which greatly increases the compilation time of multi-function modules.

[0005] In summary, the disadvantages of the traditional method for compiling kernel functions are that it is difficult to effectively improve resource utilization and the compilation efficiency of multi-function modules. Summary of the invention

[0006] The present invention provides a method for compiling a kernel function, a computing device, a computer-readable storage medium and a computer program product, which can effectively improve the utilization of resources and the compilation efficiency of multi-function modules.

[0007] According to a first aspect of the present invention, a method for compiling a kernel function is provided. The method comprises: converting a compiling module into a compiling submodule, so that each kernel function and the device function called by it are configured in the same compiling submodule; for the compiling submodule, configuring resources for allocating data used by the device function in the compiling submodule; and compiling for each compiling submodule.

[0008] According to a second aspect of the present invention, a computing device is also provided. The computing device comprises: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the computing device can perform the method of the first aspect of the present invention.

[0009] According to a third aspect of the present invention, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a machine, the method of the first aspect of the present invention is executed.

[0010] According to a fourth aspect of the present invention, there is further provided a computer program product, comprising a computer program, wherein when the computer program is executed by a machine, the method of the first aspect of the present invention is performed.

[0011] In some embodiments, converting a compilation module into a compilation sub-module includes: generating multiple compilation sub-modules based at least on the number of kernel functions in a program file, each compilation sub-module being configured with at most one kernel function, the program file including one or more compilation modules, each compilation module being configured with one of a kernel function and a device function; based on the calling relationship of each compilation sub-module, copying the device function directly or indirectly called by the kernel function to the compilation sub-module where the kernel function is located; and assigning the device functions configured or copied to each compilation sub-module a function name related to the kernel function of the compilation sub-module.

[0012] In some embodiments, generating multiple compilation sub-modules includes: in the front-end stage, in response to a compilation module in a program file being configured with a kernel function, determining the number of configured kernel functions so as to generate the same number of compilation sub-modules as the number of kernel functions based on the compilation module, each compilation sub-module being configured with a kernel function.

[0013] In some embodiments, generating multiple compilation sub-modules further includes: in the front-end stage, in response to the compilation module in the program file not being configured with a kernel function that calls a device function, converting the compilation module into a compilation sub-module that is only configured with a device function.

[0014] In some embodiments, copying the device function directly or indirectly called by the kernel function to the compilation submodule where the kernel function is located includes: in the linking stage, copying the device function called by the current kernel function in the current compilation submodule and the device functions in other compilation submodules called by the device function called by the current kernel function to the current compilation submodule.

[0015] In some embodiments, for each compilation submodule, compilation includes: via multi-threading, the optimizer asynchronously optimizes each compilation submodule to generate optimized intermediate code; the backend asynchronously maps the optimized intermediate code corresponding to each compilation submodule to the target instruction set to generate opcodes; and via the linking after the backend, function redirection and metadata integration are performed on the generated opcodes to reassemble them into a complete binary file.

[0016] In some embodiments, the configured resources include at least one of: a register, an address, data content, and an identifier used by an instruction.

[0017] In some embodiments, reassembling into a complete binary file includes: in a linking stage after the back end, if it is determined that the current device function is not referenced by the kernel function or other device functions, deleting the current device function.

[0018] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other features, advantages and aspects of the embodiments of the present invention will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements.

[0020] Figure 1A A schematic diagram of a method for compiling a kernel function involving two kernel functions in the related art is schematically shown.

[0021] Figure 1B A schematic diagram of a method for compiling kernel functions involving three kernel functions in the related art is schematically shown.

[0022] Figure 2 The figure schematically shows a computing device for implementing a compiling method according to an embodiment of the present invention.

[0023] Figure 3 A schematic diagram of a compiler for executing a method for compiling a kernel function according to an embodiment of the present invention is shown.

[0024] Figure 4 A flow chart of a method for compiling a kernel function according to an embodiment of the present invention is shown.

[0025] Figure 5 A schematic diagram of a method for allocating resources according to an embodiment of the present invention is shown.

[0026] Figure 6 A flow chart of a method for converting a compilation module into a compilation sub-module according to an embodiment of the present invention is shown.

[0027] Figure 7 A flow chart of a method for compiling each compiling submodule according to an embodiment of the present invention is shown.

[0028] In the various drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION

[0029] The preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.

[0030] As used herein, the term "including" and its variations mean open inclusion, i.e., "including but not limited to". Unless otherwise stated, the term "or" means "and / or". The term "based on" means "based at least in part on". The terms "an example embodiment" and "an embodiment" mean "at least one example embodiment". The term "another embodiment" means "at least one additional embodiment". The terms "first", "second", etc. may refer to different or the same objects.

[0031] The following combination Figure 1A and 1B Introduces the traditional method for compiling kernel functions. Figure 1A A schematic diagram of a method for compiling a kernel function involving two kernel functions in the related art is schematically shown. Figure 1B A schematic diagram of a method for compiling kernel functions involving three kernel functions in the related art is schematically shown.

[0032] For example, Figure 1A As shown, there are two kernel functions and three device functions in the source file. The two kernel functions are, for example, the first kernel function (Kernel A) and the second kernel function (Kernel B). The three device functions are, for example, the first device function (Device 0), the second device function (Device 1) and the third device function (Device 2). It should be understood that, for example, if each device function needs to use a piece of data (the data used by the device function is, for example, a global variable, such as a global parameter called by the device function), these data need to be allocated some global resources, such as address space or registers to store the data (such as a global variable). Figure 1A As shown in the figure, since Device 0 is called by two kernel functions, the first register C0 is allocated for data access. Device 1 is only called by Kernel A, and Device 2 is only called by Kernel B. Since Device 1 and Device 2 are called by different kernel functions, Device 1 and Device 2 will not be called at the same time. Therefore, the data used in the two device functions Device 1 and Device 2 can be allocated the second register C1 for access. Globally, Kernel A and Kernel B both use the first register C0 and the second register C1 to access the two data they need.

[0033] However, if Figure 1BAs shown in the figure, there is a third kernel function Kernel C in the source file. The third kernel function Kernel C needs to call Device 1 and Device 2, so the resource allocation will change. Since both Device 1 and Device 2 will be called by Kernel C, the two data used by Device 1 and Device 2 respectively cannot be accessed through the second register C1. Therefore, the third register C2 needs to be reallocated for Device 2 to access the data used by Device 2. However, this situation is not favorable from a global perspective, because although each Kernel only needs to access the data of two device functions, it ultimately takes 3 registers to allocate these data. Due to the complexity of the program call graph, it is difficult to ensure that global, limited resources can be reallocated to other data. As a result, some global, limited resources are difficult to allocate, which in turn makes it difficult to effectively improve resource utilization. In addition, since the device function of the same program file or compilation module is called by multiple kernel functions, various synchronizations are required during compilation, making it difficult to perform asynchronous compilation, which in turn makes it difficult to effectively improve the compilation efficiency of multi-function modules.

[0034] In summary, the disadvantages of the traditional method for compiling kernel functions are that it is difficult to effectively improve resource utilization and the compilation efficiency of multi-function modules.

[0035] In order to at least partially solve one or more of the above problems and other potential problems, an exemplary embodiment of the present invention proposes a method for compiling kernel functions. In this method, by converting the compilation module into a compilation submodule, each kernel function and the device function it calls are configured in the same compilation submodule, so that the device function is separated according to the kernel function that calls the device function, and there is no longer a problem of mutual dependence of global resources; by configuring resources for the compilation submodule to allocate the data used by the device function in the compilation submodule, each kernel function can have a complete set of configurable resources, thereby improving the utilization of resources and reducing the difficulty of configuring global resources. At the same time, since the compilation submodule is completely separated, all optimizations and backends of different kernel functions can be completed completely independently and asynchronously, thereby significantly improving the compilation speed and efficiency of multi-function modules. Therefore, the present invention can effectively improve the utilization of resources and the compilation efficiency of multi-function modules.

[0036] Figure 2 The figure schematically shows a computing device 200 for implementing a compiling method according to an embodiment of the present invention.

[0037] It should be understood that the computing device 200 may have one or more processing units and a memory, wherein the processing unit includes a dedicated processing unit such as a graphics processor, a field programmable gate array (FPGA), an application-specific integrated circuit (ASIC), or a general-purpose graphics processor, and a general-purpose processing unit such as a CPU. The computing device 200, for example, also includes at least: a compiling module conversion unit 202, a compiling submodule resource configuration unit 204, and a compiling submodule compiling unit 206. It should be understood that the compiling module conversion unit 202, the compiling submodule resource configuration unit 204, and the compiling submodule compiling unit 206 are software modules that can run on one or more processing units configured by the computing device 200.

[0038] The compiling module conversion unit 202 is used to convert the compiling module into a compiling sub-module, so that each kernel function and the device function called by it are configured in the same compiling sub-module.

[0039] Regarding the compiling submodule resource configuration unit 204, it is used to configure resources for the compiling submodule to allocate data used by the device function in the compiling submodule.

[0040] The compiling submodule compiling unit 206 is used to compile each compiling submodule.

[0041] The following will be combined Figure 3 , Figure 4 , Figure 5 A method 400 for compiling a kernel function according to an embodiment of the present invention is described. Figure 3 A schematic diagram of a compiler 300 for executing a compiling method according to an embodiment of the present invention is shown. Figure 4 A flowchart of a method 400 for compiling a kernel function according to an embodiment of the present invention is shown. Figure 5 FIG. 4 is a schematic diagram showing a method for allocating resources according to an embodiment of the present invention. It should be understood that the method 400 may be used, for example, in Figure 2 The method 400 is executed at the described computing device 200. The method 400 may also include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0042] like Figure 3As shown, the compiler 300 at least includes a front-end 320, an optimizer 360, a back-end 370, and a traditional linker 390. The optimizer 360, the back-end 370, and the traditional linker 390 can be encapsulated as a linker 340, for example. The front-end 320 is configured to convert a program file 310 (or a "source file") in a high-level language into an intermediate language representation bitcode file (or simply referred to as an "intermediate representation file"). In the present invention, the front-end 320 is also configured to split the compilation module, for example.

[0043] The following combination Figure 3 The various steps of the method 400 are introduced. It should be understood that the method 400 may be a method for compiling a kernel function based on a GPU.

[0044] At step 402, the computing device 200 converts the compilation module into a compilation submodule, so that each kernel function and the device function it calls are configured in the same compilation submodule. In some embodiments, the compilation module is, for example, a compilation module included in a program file, and the compilation submodule is, for example, a submodule of an intermediate language representation bitcode file.

[0045] In some embodiments, a method for converting a compilation module into a compilation sub-module includes, for example: splitting a compilation module configured with a kernel function into compilation sub-modules according to the kernel function via a front end, so that the compilation sub-module includes a kernel function; if the current compilation module only includes device functions, converting the current compilation module into a compilation sub-module including only the device function via the front end.

[0046] Regarding the compilation module, it can be referred to as a module. It should be understood that the compilation module is a complete unit of compilation, which contains basic elements of compilation such as functions and global variables. Usually, the compilation of a complete executable file needs to be performed in units of compilation modules. Figure 3 As shown, the program file 310 (which is, for example, a source file in a high-level language) includes multiple compilation modules. The multiple compilation modules include, for example but not limited to: a first compilation module 312, a second compilation module 314, and a third compilation module 316. Each compilation module may include one or more functions. For example, the first compilation module 312 includes multiple kernel functions and one device function, for example, a first kernel function (Kernel A), a second kernel function (Kernel B), and first device functions (Device 0) respectively called by them. The second compilation module 314, for example, includes a third kernel function (Kernel C) and a third device function (Device 2) called by it. The second compilation module 316, for example, includes a second device function (Device 1). It should be understood that Figure 3 The relationship among the program files, compilation modules and functions shown in the example is only exemplary. For example, the program file may also include only one compilation module, which includes multiple kernel functions and device functions.

[0047] Regarding the kernel function, it is the entry function of the GPU program. The user will call the GPU kernel function from the CPU side through the driver application programming interface (API) to start executing the GPU program, and it cannot be called by any method other than the driver API.

[0048] Regarding device functions, they are common functions in GPU programs and can be called by kernel functions or other device functions, but cannot be called directly from the CPU side. It should be understood that the same device function may be called by multiple different kernel functions.

[0049] Regarding the compilation submodule, in some embodiments, it is, for example, a submodule of an intermediate language representation bitcode file. In other embodiments, a compilation submodule is, for example, an intermediate language representation bitcode file.

[0050] Regarding the method for converting a compilation module into a compilation submodule, it includes, for example: the computing device 200 generates multiple compilation submodules based at least on the number of kernel functions in the program file, each compilation submodule is configured with at most one kernel function, the program file includes one or more compilation modules, each compilation module is configured with one of a kernel function and a device function; based on the calling relationship of each compilation submodule, the device function directly or indirectly called by the kernel function is copied to the compilation submodule where the kernel function is located; and the device function configured or copied to each compilation submodule is assigned a function name related to the kernel function of the compilation submodule. Regarding the method for converting a compilation module into a compilation submodule, the following will be combined with Figure 3 and Figure 6 The above is explained and no further elaboration is given here.

[0051] For example, Figure 3As shown, the computing device 200 converts the first compilation module to the third compilation module (the conversion at least includes splitting), and generates four compilation sub-modules. For example, the first kernel function (Kernel A) and the device functions Device 0_A and Device 1_A called by it are configured in the first compilation sub-module (as indicated by mark 352). The second kernel function (Kernel B) and the device functions Device 0_B and Device 2_B called by it are configured in the second compilation sub-module (as indicated by mark 354). The third kernel function (Kernel C) and the device functions Device 1_C and Device2_C called by it are configured in the third compilation sub-module (as indicated by mark 356). Thus, in each compilation sub-module, each kernel function will only call private device functions. In some embodiments, the second device function (Device 1) is configured in the fourth compilation sub-module (as indicated by mark 358).

[0052] At step 404 , the computing device 200 configures resources for the compilation submodule to allocate data used by the device function in the compilation submodule.

[0053] Regarding resources, for example, they are global resources. Resources are, for example but not limited to, one or more of registers, addresses, data contents, and identifiers used by instructions.

[0054] The following combination Figure 3 and Figure 5 Step 404 is further described.

[0055] like Figure 5 As shown, the computing device 200 configures the first register C0 and the second register C1 for the device functions Device 0_A and Device 1_A called by the first kernel function (Kernel A) of the first compiling submodule 352, respectively. The first register C0 and the second register C1 are configured for the device functions Device 0_B and Device 2_B called by the second kernel function (Kernel B) of the second compiling submodule 354, respectively. It should be understood that for different compiling submodules, the kernel functions called by them change, the context of the program has changed, and the entire set of global variables (such as registers) can be used to reallocate the data used by the device functions in different compiling submodules. Similarly, the first register C0 and the second register C1 are configured for the third kernel function (Kernel C) of the third compiling submodule 356 and the device functions Device 1_C and Device 2_C called by them, respectively. It can be seen that only two registers need to be allocated for the data used by the device functions called by the three kernel functions, while according to the traditional compilation method (such as Figure 1BAs shown in FIG. 1 ), three registers need to be allocated. In other words, since each kernel function and the device function it calls are configured in the same compilation submodule, the compilation process of each compilation submodule can be independent of each other, and there is no longer a problem of mutual dependence of global resources. Therefore, the present invention enables each kernel function to have a complete set of configurable resources, thereby significantly improving resource utilization.

[0056] At step 406, the computing device 200 compiles each compilation submodule. It should be understood that since each kernel function and the device function it calls are configured in the same compilation submodule, the present invention can compile each compilation submodule asynchronously without considering the calling relationship of other compilation submodules.

[0057] Regarding the method for compiling each compilation submodule, it includes multiple methods, for example, in some embodiments, the method for compiling each compilation submodule includes: the optimizer asynchronously optimizes each compilation submodule via multithreading to generate optimized intermediate code; the backend asynchronously maps the optimized intermediate code corresponding to each compilation submodule to the target instruction set to generate an opcode; and through linking, function redirection and metadata integration are performed on the generated opcode to reassemble it into a complete binary file 380. The following will be combined with Figure 3 and Figure 7 The specific implementation method of the method for compiling each compilation submodule is described, which will not be repeated here.

[0058] In the above scheme, by converting the compilation module into a compilation submodule, each kernel function and the device function it calls are configured in the same compilation submodule, so that the device function is separated according to the kernel function that calls the device function, and there is no longer a problem of mutual dependence of global resources; by configuring resources for the compilation submodule to allocate the data used by the device function in the compilation submodule, each kernel function can have a complete set of configurable resources, thereby improving the utilization of resources and reducing the difficulty of configuring global resources. At the same time, since the compilation submodules are completely separated, all optimizations and backends of different kernel functions can be completed completely independently and asynchronously, thereby significantly improving the compilation speed and efficiency of multi-function modules. Therefore, the present invention can effectively improve the utilization of resources and the compilation efficiency of multi-function modules.

[0059] The following will be combined Figure 3 and Figure 6 A method 600 for converting a compilation module into a compilation sub-module block according to an embodiment of the present invention is described. Figure 6FIG. 6 is a flowchart of a method 600 for converting a compilation module into a compilation submodule according to an embodiment of the present invention. Figure 2 The method 600 is executed at the described computing device 200. The method 600 may also include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0060] At step 602, the computing device 200 generates multiple compilation sub-modules based at least on the number of kernel functions in the program file, each compilation sub-module is configured with at most one kernel function, and the program file includes one or more compilation modules, each compilation module is configured with one of a kernel function and a device function.

[0061] Regarding the method for generating multiple compilation sub-modules, it includes, for example: in the front-end stage, in response to the compilation module in the program file being configured with a kernel function, determining the number of configured kernel functions, so as to generate the same number of compilation sub-modules as the number of the kernel functions based on the compilation module, each compilation sub-module being configured with a kernel function. In some embodiments, in the front-end stage, in response to the compilation module in the program file not being configured with a kernel function that calls a device function, converting the compilation module into a compilation sub-module that is only configured with a device function.

[0062] like Figure 3 As shown, if the front end 320 of the compiler 300 of the computing device 200 determines that the compilation modules (e.g., the first compilation module 312, the second compilation module 314) in the program file 310 are configured with kernel functions, based on the number of configured kernel functions, the same number of compilation sub-modules as the number of configured kernel functions are generated (e.g., the first compilation module 312 is split into the first compilation sub-module and the second compilation sub-module, wherein the mark 332 indicates the first compilation sub-module after conversion by the front end 320, and the mark 334 indicates the second compilation sub-module after conversion by the front end 320, and the first compilation sub-module and the second compilation sub-module at this time have not yet completed the copying of the device function in the linking stage), so that each compilation sub-module is configured with a kernel function. If the front end 320 of the compiler 300 determines that the current module in the program file 310 only includes device functions and there is no kernel function that calls the device function, the current module is converted into a compilation sub-module that only includes device functions.

[0063] It should be understood that, in the front-end stage, the computing device 200 determines that a device function is called by multiple kernel functions, and copies the device function so that the main body and the copy of the device function are configured in the compilation submodule where the kernel function that calls the device function is located. Figure 3As shown, in the front-end stage, a copy of the first device function (Device 0) in the same compilation module as the first kernel function (Kernel A) and the second kernel function (Kernel B) is made, so that the first device function (Device 0) body and its copy are respectively configured to the first compilation submodule where the first kernel function (Kernel A) is located and the second compilation submodule (after front-end conversion) where the second kernel function (Kernel B) is located.

[0064] Specifically, the front end 320 determines that the first compilation module 312 in the program file 310 includes two kernel functions, namely, the first kernel function (Kernel A) and the second kernel function (Kernel B), then the front end 320 generates two corresponding compilation sub-modules based on the first compilation module 312, namely, the first compilation sub-module and the second compilation sub-module. Among them, the first compilation sub-module is configured with the first kernel function (Kernel A) and the first device function (Device 0), and the second compilation sub-module is configured with the second kernel function (Kernel B) and the first device function (Device 0). In addition, the front end 320 analyzes that the second compilation module 314 in the program file 310 includes a kernel function, namely, the third kernel function (Kernel C), then the front end 320 generates a corresponding compilation sub-module based on the second compilation module 314, namely, the third compilation sub-module (mark 336 indicates the third compilation sub-module after the front end 320 converts). Among them, the third compilation sub-module is configured with the third kernel function (Kernel C) and the third device function (Device2).

[0065] For example, Figure 3 As shown, the front end 320 determines that the third compilation module 316 in the program file 310 does not include a kernel function, but only includes a second device function (Device 1), then the front end 320 generates a corresponding fourth compilation sub-module based on the third compilation module 316 (mark 338 indicates the fourth compilation sub-module after conversion by the front end 320), wherein the fourth compilation sub-module is configured with the second device function (Device 1).

[0066] At step 604, the computing device 200 copies the device function directly or indirectly called by the kernel function to the compilation submodule where the kernel function is located based on the calling relationship of each compilation submodule. For example, in the linking stage, the device function called by the current kernel function in the current compilation submodule and the device functions in other compilation submodules called by the device function called by the current kernel function are copied to the current compilation submodule. Thus, the compilation submodule through the linking stage can completely include the kernel function and the device function directly or indirectly called by it.

[0067] In the linking stage, the computing device 200 copies the second device function (Device 1) in two copies based on the calling relationship of the kernel function, so that the two copies are respectively configured to the first compiling submodule 352 where the first kernel function Kernel A is located and the third compiling submodule 356 where the third kernel function Kernel C is located. Similarly, since the second kernel function Kernel B needs to call the third device function Device 2, the third device function Device 2 is copied in one copy so that its copy is configured to the second compiling submodule 356 where the second kernel function Kernel B is located (it should be understood that the marks 352, 354, 356, and 358 respectively indicate the first compiling submodule, the second compiling submodule, the third compiling submodule, and the fourth compiling submodule processed in the linking stage).

[0068] At step 606, the computing device 200 assigns the device functions configured or copied to each compilation submodule with function names related to the kernel functions of the compilation submodules. Thus, the function names contain the names of the device functions and the kernel functions that call them, which can avoid duplication or conflict in naming.

[0069] For example, the first device function (Device 0) and the second device function (Device 1) called by the first kernel function (Kernel A) of the first compiling submodule 352 are assigned the function names Device 0_A and Device 1_A related to the first kernel function (Kernel A) (for example, the function name "Device 0_A" includes the name of the device function "Device 0" and the associated name "A" of the first kernel function). The first device function (Device 0) and the third device function (Device 2) called by the second kernel function (Kernel B) of the second compiling submodule are assigned the function names Device 0_B and Device 2_B related to the second kernel function (Kernel B). The second device function (Device 1) and the third device function (Device 2) called by the second kernel function (Kernel C) of the third compiling submodule are assigned the function names Device 1_C and Device 2_C related to the third kernel function (Kernel C).

[0070] By adopting the above means, all kernel functions in the program file and the device functions they call are completely configured to the same compilation sub-module and separated from other compilation sub-modules. Therefore, different compilation sub-modules can run the backend asynchronously and will not compete with each other for resources shared by the compilation sub-modules.

[0071] The following will be combined Figure 3 and Figure 7A method 700 for compiling each compiling submodule according to an embodiment of the present invention is described. Figure 7 FIG. 7 is a flowchart of a method 700 for compiling each compilation submodule according to an embodiment of the present invention. Figure 2 The method 700 is executed at the described computing device 200. The method 700 may also include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0072] At step 702 , the optimizer asynchronously optimizes each compilation submodule via multiple threads to generate optimized intermediate codes.

[0073] For example, Figure 3 The mark 350 in indicates, for example, an intermediate language representation bitcode file processed by the link stage. In some embodiments, the intermediate language representation bitcode file 350 includes, for example, a first compilation submodule 352, a second compilation submodule 354, a third compilation submodule 356, and a fourth compilation submodule 358 processed by the link stage. In other embodiments, each compilation submodule is, for example, an intermediate language representation bitcode file. Through the optimizer 360, various conversion attempts are asynchronously performed for the first compilation submodule 352, the second compilation submodule 354, the third compilation submodule 356, and the fourth compilation submodule 358 using multithreading to improve the execution time of the code, such as eliminating redundant calculations, etc., thereby generating optimized intermediate codes.

[0074] At step 704 , the back end asynchronously maps the optimized intermediate code corresponding to each compilation sub-module to the target instruction set to generate an opcode.

[0075] For example, the back end 370 asynchronously maps the optimized intermediate code corresponding to each compilation sub-module to the target instruction set to generate an operation code (opcode).

[0076] At step 706, in the linking stage after the back end, function redirection and metadata integration are performed on the generated opcodes so as to be reassembled into a complete binary file.

[0077] For example, through traditional linking 390, function redirection and metadata integration are performed to reassemble into a complete binary file 380 (such as an ELF file). For example, the location of the function is adjusted according to the requirements of the driver, such as the calling order.

[0078] In some embodiments, the method of reassembling into a complete binary file includes, for example: in the linking stage after the backend, if it is determined that the current device function is not referenced by the kernel function or other device functions, deleting the opcode corresponding to the current device function. In another embodiment, the compilation submodule where the device function that is not called by the kernel function or other device function is located can also be deleted in the linking stage before the optimizer. It should be understood that by deleting the compilation submodule where the uncalled device function is located, or deleting the opcode corresponding to the uncalled device function, the generated code can be made more concise.

[0079] By adopting the above means, the optimizer and the backend of the present invention can complete the compilation asynchronously, thereby significantly accelerating the compilation speed.

[0080] The various processes and processing described above, such as methods 400, 600, and 700, may be performed at a computing device. The computing device, for example, includes: at least one processor (at least one graphics processor and at least one central processing unit); and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor. In some embodiments, methods 400, 600, and 700 may be implemented as a computer software program or program product, which is tangibly contained in a machine-readable medium. In some embodiments, part or all of the computer program may be loaded and / or installed on a computing device via a read-only memory (ROM) and / or a communication unit. When the computer program is loaded into a random access memory (RAM) and executed by a GPU and a CPU, one or more actions of methods 400, 600, and 700 described above may be performed.

[0081] The present invention may be a method, an apparatus, a system and / or a computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions for executing various aspects of the present invention. The computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. The computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof.

[0082] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to various computing / processing devices, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. Various aspects of the present invention are described herein 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 box of the flowchart and / or block diagram, and the combination of boxes in the flowchart and / or block diagram, can be implemented by computer-readable program instructions.

[0083] These computer-readable program instructions can be provided to a central processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the central processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0084] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the function involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.

[0085] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps loaded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.

[0086] The above specific implementations do not constitute a limitation on the protection scope of the present application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made according to design requirements and other factors.

Claims

1. A method for compiling a kernel function, characterized in that: The method comprises: Converting the compilation module into a compilation submodule, so that each kernel function and the device function called by it are configured in the same compilation submodule, wherein converting the compilation module into the compilation submodule comprises: based on the calling relationship of each compilation submodule, copying the device function directly or indirectly called by the kernel function to the compilation submodule where the kernel function is located, wherein each compilation submodule is configured with at most one kernel function; For a compiling submodule, configuring resources for allocating data used by a device function in the compiling submodule; and Compile each compiled submodule asynchronously.

2. The method according to claim 1, characterized in that Converting a compiled module to a compiled submodule also includes: Based at least on the number of kernel functions in a program file, a plurality of compilation submodules are generated, wherein the program file includes one or more compilation modules, each compilation module is configured with at least one of a kernel function and a device function; and the device functions configured or copied to each compilation submodule are assigned function names related to the kernel functions of the compilation submodules.

3. The method according to claim 2, characterized in that Generate multiple compilation submodules including: In the front-end stage, in response to a compilation module in a program file being configured with a kernel function, the number of configured kernel functions is determined so as to generate the same number of compilation sub-modules as the kernel functions based on the compilation module, each compilation sub-module being configured with a kernel function.

4. The method according to claim 3, characterized in that Generating multiple compilation submodules also includes: In the front-end stage, in response to the compilation module in the program file not being configured with a core function that calls a device function, the compilation module is converted into a compilation sub-module that is only configured with a device function.

5. The method according to claim 4, characterized in that Copying the device function directly or indirectly called by the kernel function to the compilation submodule where the kernel function is located includes: In the linking stage, the device functions called by the current kernel function in the current compilation submodule and the device functions in other compilation submodules called by the device functions called by the current kernel function are copied to the current compilation submodule.

6. The method according to claim 1, characterized in that For each compilation submodule, asynchronous compilation includes: The optimizer asynchronously optimizes each compilation submodule via multithreading to generate optimized intermediate codes; The back end asynchronously maps the optimized intermediate code corresponding to each compilation sub-module to the target instruction set to generate an opcode; and After the backend link, function redirection and metadata integration are performed on the generated opcodes to reassemble them into a complete binary file.

7. The method according to claim 1, characterized in that The configured resources include: at least one of a register, an address, data content, and an identifier used by an instruction.

8. The method according to claim 1, characterized in that Reassembling into a complete binary consists of: In the linking stage after the backend, if it is determined that the current device function is not referenced by the kernel function or other device functions, the current device function is deleted.

9. A computing device, characterized in that: include: at least one processor; as well as a memory communicatively coupled to the at least one processor; in The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

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 by a machine, the method according to any one of claims 1 to 8 is performed.

11. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a machine, performs the method according to any one of claims 1 to 8.