Code compilation method and related device
By parsing and generating target instruction sets, distinguishing and executing scalar and vector instructions, it solves the problem of resource waste and power consumption of traditional parallel processors, achieves faster and lower-power parallel processing, and reduces the difficulty of developing new processors. .
Patent Information
- Application Number
- CN202310535630.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-12
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2043-05-12
AI Technical Summary
Traditional parallel processors cannot effectively distinguish and execute vector instructions and scalar instructions, resulting in resource waste and power consumption problems, and it is difficult for developers to adapt to the programming model of new parallel processors.
By parsing the function in vitro function call information in the target intermediate code, the target copy of the called function is determined, and the target instruction set is generated based on the function name and actual parameter data type, distinguishing between scalar and vector instructions for execution by the parallel processor.
Increased processing speed and reduced power consumption make it easier to develop new parallel processors, allowing developers to continue writing source code using traditional programming models.
Smart Images

Figure CN116700731B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of general encoding, decoding or code conversion technology in the new generation information technology industry, and in particular to a code compilation method and related devices. Background Art
[0002] In the process of parallel processing of data, the instruction set executed by the parallel processor contains both vector instructions related to data processing and scalar instructions unrelated to data processing. For traditional parallel processors (such as graphics processors GPU), they follow the Single Instruction Multiple Thread (SIMT) architecture to treat each instruction equally without distinguishing between vector instructions and scalar instructions in the instructions. In this way, scalar instructions will also be repeatedly executed in multiple threads, and since scalar instructions are unrelated to data processing, the repeated execution of scalar instructions is meaningless, resulting in the problem of wasted running time and power consumption in traditional parallel processors.
[0003] Currently, there is a new type of parallel processor that can execute vector instructions and scalar instructions respectively to achieve faster and lower power consumption operation. However, when developing related work for the new type of parallel processor, due to factors such as writing habits, developers still have the need to use traditional parallel programming models to write source codes, but the source codes written using the traditional parallel programming models may not be compatible with the new type of parallel processor. Summary of the invention
[0004] The embodiment of the present invention provides a code compilation method and related devices, in order to reduce the difficulty of developers in developing new parallel processors, so that electronic devices can achieve a parallel processing process with faster processing speed and lower power consumption.
[0005] In a first aspect, an embodiment of the present invention provides a code compiling method, which is applied to a central processing unit of an electronic device, wherein the electronic device includes the central processing unit and a parallel processor, wherein the parallel processor includes a scalar instruction processing unit and a vector instruction processing unit group, and the method includes:
[0006] Get the target intermediate code to be compiled;
[0007] Parsing the in-vitro function call information in the target intermediate code to obtain multiple in-vitro functions;
[0008] Determine, according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, and the multiple in vitro functions, the target copies of the multiple called functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and the called functions correspond to the function names and the data types of the actual parameters;
[0009] A target instruction set executable by the parallel processor is obtained according to the target copies of the multiple called functions, the target instruction set comprising a target scalar instruction set and a target vector instruction set, the target scalar instruction set comprising a plurality of scalar instructions executable by the scalar instruction processing unit, the scalar instructions being instructions unrelated to data processing, and the target vector instruction set comprising a plurality of vector instructions executable by the vector instruction processing unit group, the vector instructions being instructions related to data processing.
[0010] In a second aspect, an embodiment of the present invention provides a code compiling device, which is applied to a central processor of an electronic device, wherein the electronic device includes the central processor and a parallel processor, wherein the parallel processor includes a scalar instruction processing unit and a vector instruction processing unit group, and the device includes:
[0011] The acquisition module is used to obtain the target intermediate code to be compiled;
[0012] A parsing module, used for parsing the in-vitro function call information in the target intermediate code to obtain a plurality of in-vitro functions;
[0013] A determination module, configured to determine target copies of multiple called functions according to function names and data types of actual parameters corresponding to multiple function call instructions in the target intermediate code, and the multiple in vitro functions, wherein the target copies of the called functions are marked with vector attributes of formal parameters, and the called functions correspond to the function names and the data types of the actual parameters;
[0014] A generation module is used to obtain a target instruction set that can be executed by the parallel processor according to the target copies of the multiple called functions, the target instruction set includes a target scalar instruction set and a target vector instruction set, the target scalar instruction set includes a plurality of scalar instructions that can be executed by the scalar instruction processing unit, the scalar instructions refer to instructions that are not related to data processing, and the target vector instruction set includes a plurality of vector instructions that can be executed by the vector instruction processing unit group, and the vector instructions refer to instructions related to data processing.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, comprising a central processing unit, a parallel processor, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the central processing unit, and the program includes instructions for executing the steps in the first aspect of the embodiment of the present application.
[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program / instruction stored thereon, which, when executed by a central processing unit, implements the steps in the first aspect of the embodiment of the present application.
[0017] It can be seen that in the embodiment of the present application, the central processing unit of the electronic device obtains multiple in-vitro functions by parsing the in-vitro function call information in the target intermediate code to be compiled, and then determines the target copies of multiple called functions according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, as well as the multiple in-vitro functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and then obtains the target instruction set that can be executed by the parallel processor according to the target copies of the multiple called functions. In this way, the central processing unit of the electronic device can distinguish scalar instructions from vector instructions based on the target intermediate code, so that different processing units / processing unit groups in the parallel processor can correctly execute scalar / vector instructions, improve processing speed, and reduce power consumption. At the same time, when developers develop related projects for the above-mentioned parallel processors, they can still use the traditional parallel programming model to write source code, which reduces the difficulty of development. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0019] Figure 1 is a structural block diagram of an electronic device provided by an embodiment of the present invention;
[0020] Figure 2 It is a flowchart of a code compilation method provided by an embodiment of the present invention;
[0021] Figure 3 It is a block diagram of the functional units of a code compiling device provided by an embodiment of the present invention;
[0022] Figure 4 This is another structural block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0024] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0025] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0026] See also Figure 1 , Figure 1 is a structural block diagram of an electronic device provided in an embodiment of the present application. Figure 1As shown, the electronic device 10 includes a central processor 11 and a parallel processor 12, and the central processor 11 is connected to the parallel processor 12 to realize data transmission. Among them, the parallel processor 12 includes a scalar instruction processing unit 121 and a vector instruction processing unit group 122, and the scalar instruction processing unit 121 is connected to the vector instruction processing unit group 122 to realize data transmission. The parallel processor 12 can be a reconfigurable parallel processor RPP (ReconfigurableParallel Processing), the scalar instruction processing unit 121 can be a processor core in the RPP, and the vector instruction processing unit group 122 can be another processor core in the RPP, which can include multiple vector instruction processing units. The scalar instruction processing unit 121 can execute scalar instructions at a higher speed and without repetition, and can also harden or configure vector instructions into the vector instruction processing unit group 122. After the vector instructions are hardened or configured into the vector instruction processing unit group 122, the multiple vector instruction processing units simultaneously process data in parallel to achieve higher speed and lower power consumption parallel processing.
[0027] A code compilation method provided by an embodiment of the present application is introduced below.
[0028] See also Figure 2 , Figure 2 is a flowchart of a code compilation method provided in an embodiment of the present application, and the method is applied to Figure 1 In the central processing unit 11 shown, Figure 2 As shown, the method includes steps 201-204, which are specifically as follows:
[0029] Step 201, obtaining the target intermediate code to be compiled.
[0030] The target intermediate code may be an intermediate code in a code format of C language, or an intermediate code in a code format of C++, Python, etc. This solution does not limit this.
[0031] In a possible implementation, the target intermediate code to be compiled is obtained by performing a compile operation on a target source code written using a parallel programming model.
[0032] For example, the parallel programming model is a computer unified device architecture (Compute Unified Device Architecture, CUDA) programming model. Among them, the computer unified device architecture CUDA programming model is a programming model developed for a graphics processor GPU. Developers can program the GPU through a simple programming language based on the CUDA programming model, and the GPU does not distinguish between scalar instructions and vector instructions when processing parallel data. Therefore, the source code written using the CUDA programming model is not suitable for the parallel processors that can process scalar instructions and vector instructions respectively mentioned in the embodiments of the present application. However, in the relevant field, the CUDA programming model conforms to the programming habits of developers, so compiling the target source code written using the CUDA programming model into a target instruction set that can be executed by the parallel processor mentioned in the embodiments of the present application can greatly reduce the difficulty of development.
[0033] Accordingly, the compilation process of the target source code may be specifically a front-end compilation stage performed by a central processing unit. The front-end compilation operation may include steps such as lexical analysis, syntax analysis, semantic analysis, and generating intermediate codes, and finally obtaining the target intermediate code.
[0034] Exemplarily, the parallel processor involved in the embodiment of the present application is a reconfigurable parallel processor RPP, and the software system used to implement the compilation method provided in the embodiment of the present application can be called an RPP compilation system. The RPP compilation system is developed and modified on the basis of the LLVM compiler system, so the RPP compiler system also conforms to the characteristics of the LLVM compiler system in structure, that is, it includes two stages: front-end compilation and back-end compilation. Among them, the front-end compilation stage is used to convert the source code written by the developer and the like into an intermediate code, and the back-end compilation stage is used to convert the intermediate code into an instruction set executable by the target device, that is, a machine code.
[0035] It can be seen that in this example, the central processing unit can perform front-end compilation operations based on the existing LLVM compiler, quickly complete the process of converting the target source code into the target intermediate code, and improve the compilation efficiency.
[0036] In another possible implementation, the developer may manually write the target intermediate code and input the written target intermediate code into the electronic device, which is then acquired by the central processing unit and subsequently compiled.
[0037] Step 202, parsing the in-body function call information in the target intermediate code to obtain multiple in-body functions.
[0038] Among them, the function outside the function body can be understood as the function defined outside the function body.
[0039] In a possible implementation, step 202 may include steps 2021-2023, which are specifically as follows:
[0040] 2021. Parse the target intermediate code to determine the location of the entry function;
[0041] For example, if the entry function is a kernel function, the kernel function can be located by quickly parsing the outline of the kernel file.
[0042] 2022. Parse the entry function to obtain a plurality of first functions, where the first functions are external functions called by the entry function;
[0043] After the location of the kernel function is determined, the kernel function is parsed. When it is parsed that the kernel function calls an external function, the external function is recorded as the first function. By parsing the kernel function, multiple first functions can be obtained.
[0044] In a possible implementation, the multiple first functions are put into a temporary container in the module corresponding to the target intermediate code according to the function name. That is, in the process of parsing the kernel function, the first functions that meet the conditions are continuously parsed and put into the temporary container for subsequent parsing. For the compiler, a source file corresponds to a module, and a module consists of several functions or data.
[0045] 2023. The multiple first functions are parsed separately until all external functions that have a calling relationship among the multiple first functions are parsed, so as to obtain multiple second functions, where the multiple external functions include the multiple first functions and the multiple second functions.
[0046] The external functions that have a calling relationship in the first function can be understood to include the external functions that are directly called by the first function, and also include all (including direct and indirect) external functions that have external calls corresponding to the external functions that are directly called by the first function.
[0047] In a possible implementation, the multiple first functions are analyzed respectively, and it is confirmed whether there is an external function with a calling relationship among the multiple first functions;
[0048] If there are external functions with a calling relationship among the multiple first functions, the external functions with a calling relationship are parsed respectively until there are no externally referenced functions among the external functions with a calling relationship, thereby obtaining multiple second functions.
[0049] For example, for any first function f1, by parsing it, when it is confirmed that the first function f1 calls an external function g1, the external function g1 is also included in the above temporary container, and the external function g1 is parsed. When it is confirmed that the external function g1 calls other external functions, repeat the above operation and continue to parse the other external functions until all external functions related to the first function f1 (including the external function g1, other external functions called by the external function g1, etc.) are parsed. The external function g1 in this process, other external functions called by the external function g1, etc. are all recorded as the second function. Among them, if the first function f1 does not call an external function, other first functions are parsed.
[0050] By performing the above operation on all first functions until all functions in the temporary container are parsed, multiple second functions can be obtained.
[0051] In this process, vector analysis has not yet been performed on the functions in the entire module, so each function in the current module is still unique and all actual parameter types are consistent when it is called.
[0052] In this example, by exhaustively parsing the external functions that have direct calling relationships and indirect calling relationships in the target intermediate code, it can be ensured that only function objects that are referenced are included in the compilation process.
[0053] Step 203, determining target copies of multiple called functions according to the function names and the data types of the actual parameters corresponding to the multiple function call instructions in the target intermediate code, as well as the multiple in vitro functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and the called functions correspond to the function names and the data types of the actual parameters.
[0054] Among them, formal parameters are the parameters used when defining the function name and function body. Actual parameters are the parameters passed to the function when calling, that is, the values passed to the called function.
[0055] When a function is called, its actual parameter may be a vector or a scalar register, referred to as the vector attribute of the parameter.
[0056] In a possible implementation, step 203 may include steps 2031-2032, which are specifically as follows:
[0057] 2031. Determine a plurality of function bodies from the plurality of in-vitro functions according to the function names and data types of the actual parameters corresponding to the plurality of function call instructions, wherein the function bodies correspond to the function names, the data types of the actual parameters, and the in-vitro functions;
[0058] Among them, based on the function name and the data type of the actual parameter, and the multiple function bodies obtained above, multiple function bodies corresponding to the function names and the data types of the actual parameters corresponding to the multiple function call instructions can be determined.
[0059] 2032. Obtain target copies of multiple called functions according to vector attributes of actual parameters when functions corresponding to the multiple function bodies are called.
[0060] In one possible implementation, the multiple function bodies are copied to obtain initial copies of the multiple called functions; then, based on the vector attributes of the actual parameters corresponding to each of the function names and the data types of the actual parameters when the function is called, the vector attributes of the formal parameters in the initial copies of the multiple called functions are identified to obtain target copies of the multiple called functions.
[0061] That is to say, the target copy is marked with the parameter vector attribute. If a function is called multiple times with different actual parameter vector attributes, multiple function copies with different formal parameter vector attributes will be generated.
[0062] In a possible implementation, step 203 may include the following steps:
[0063] Obtaining a function call instruction corresponding to an entry function in the target intermediate code;
[0064] A plurality of first function bodies are determined from the plurality of in-vitro functions according to the function name and the data type of the actual parameter in the function call instruction corresponding to the entry function; wherein the first function body corresponds to the function name and the data type of the actual parameter and the in-vitro function.
[0065] According to the vector attributes of the actual parameters of the multiple first function bodies and the functions corresponding to the multiple first function bodies when they are called respectively, the target copies of the functions corresponding to the multiple first function bodies when they are called respectively are determined; wherein the vector attributes of the formal parameters are identified in the target copy of the called function.
[0066] Determine multiple second function bodies from the multiple function bodies according to the function names and data types of actual parameters in the function call instructions corresponding to the multiple first function bodies; wherein the functions corresponding to the multiple second function bodies include functions directly called by the functions corresponding to the first function bodies, and also include all (including direct and indirect) external functions corresponding to the external functions directly called by them that have external calls. For the introduction of this part, please refer to the record of the aforementioned step 202, which will not be repeated here.
[0067] According to the vector attributes of the actual parameters of the multiple second function bodies and the functions corresponding to the multiple second function bodies when they are respectively called, the target copies of the common functions when they are respectively called are determined, and the target copies of the multiple called functions include the target copies of the functions corresponding to the multiple first function bodies when they are respectively called and the target copies of the common functions when they are respectively called. The common functions can be understood as other functions except the entry function.
[0068] For example, starting from the first instruction of the kernel function, vector instructions and vector registers are identified one by one. Specifically, vector instructions or vector registers can be distinguished according to direct or indirect dependencies on thread IDs.
[0069] Among them, for the function call instruction, the corresponding function body is found in the function in the temporary container of the module according to the function name and the data type of the actual parameter.
[0070] Then, copy the found function body to the function set container in the module, and generate the initial copy of the called function. At the same time, according to the vector attributes of the actual parameters of the current function call, identify the vector attributes of the initial copy of the function, and obtain the corresponding target copy. Repeat the above steps until the vector analysis of the kernel function is completed.
[0071] After completing the vector analysis of the kernel function, the functions in the function set container in the module are processed one by one. If the current instruction is a function call instruction, the corresponding function body is found in the temporary container of the module according to the function name and the data type of the actual parameter. Then, a copy of the found function body is copied to the function set container in the module, and the initial copy of the called function is generated. At the same time, according to the vector attributes of the actual parameters during the current function call, the vector attributes of the formal parameters of the function copy are identified, and the corresponding target copy is obtained.
[0072] Repeat the above steps until the vector analysis of the functions in the function set container is completed.
[0073] If a function is called multiple times with different actual parameter vector attributes, multiple function copies with different formal parameter vector attributes will be generated.
[0074] Finally, the temporary container in the module can be cleared. The function set container contains all the compilable functions (i.e., the target copies of the functions) required for the entire module to run.
[0075] This example distinguishes scalar instructions from vector instructions based on the target intermediate code, so that different processing units / processing unit groups in the parallel processor can correctly execute scalar / vector instructions, thereby improving processing speed and reducing power consumption.
[0076] Step 204: Obtain a target instruction set executable by the parallel processor according to the target copies of the multiple called functions.
[0077] Among them, the target instruction set includes a target scalar instruction set and a target vector instruction set, the target scalar instruction set includes multiple scalar instructions that can be executed by the scalar instruction processing unit, and the scalar instructions refer to instructions that are not related to data processing. The target vector instruction set includes multiple vector instructions that can be executed by the vector instruction processing unit group, and the vector instructions refer to instructions related to data processing.
[0078] Taking the traditional compiler system as the LLVM compiler system, and the software system corresponding to the compilation method provided in the embodiment of the present application as the RPP compilation system as an example, the RPP compilation system continues the advantages of the LLVM compiler system, and can separate the front-end compilation stage and the back-end compilation stage, so that each stage can be executed on different computers. In one possible example, the RPP front-end compilation stage can be performed in the developer computer to convert the source code into the target intermediate code, and then the developer computer sends the target intermediate code to the user computer, and the user computer completes the RPP back-end compilation stage to obtain the target instruction set that can be executed by the user computer. In this way, the source code can be avoided from being exposed to the user computer while the instructions can be normally executed by the user computer. It can be understood that the above-mentioned developer computer and user computer can both be electronic devices involved in the embodiments of the present application.
[0079] In an embodiment of the present application, the central processing unit of the electronic device obtains multiple in-vitro functions by parsing the in-vitro function call information in the target intermediate code to be compiled, and then determines the target copies of multiple called functions according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, as well as the multiple in-vitro functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and then obtains the target instruction set that can be executed by the parallel processor according to the target copies of the multiple called functions. In this way, the central processing unit of the electronic device can distinguish scalar instructions from vector instructions based on the target intermediate code, so that different processing units / processing unit groups in the parallel processor can correctly execute scalar / vector instructions, improve processing speed, and reduce power consumption. At the same time, when developers develop related projects for the above-mentioned parallel processors, they can still use the traditional parallel programming model to write source code, which reduces the difficulty of development.
[0080] In accordance with the above-mentioned embodiment, please refer to Figure 3 , Figure 3is a functional unit block diagram of a code compilation device provided in an embodiment of the present application, wherein the device is applied to Figure 1 In the central processor 11 shown, the code compiling device 30 includes:
[0081] The acquisition module 301 is used to obtain the target intermediate code to be compiled;
[0082] A parsing module 302 is used to parse the in-vitro function call information in the target intermediate code to obtain multiple in-vitro functions;
[0083] The determination module 303 is used to determine the target copies of multiple called functions according to the function names and the data types of the actual parameters corresponding to the multiple function call instructions in the target intermediate code, and the multiple in vitro functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and the called functions correspond to the function names and the data types of the actual parameters;
[0084] A generation module 304 is used to obtain a target instruction set that can be executed by the parallel processor according to the target copies of the multiple called functions, the target instruction set includes a target scalar instruction set and a target vector instruction set, the target scalar instruction set includes a plurality of scalar instructions that can be executed by the scalar instruction processing unit, the scalar instructions refer to instructions that are not related to data processing, and the target vector instruction set includes a plurality of vector instructions that can be executed by the vector instruction processing unit group, and the vector instructions refer to instructions related to data processing.
[0085] In a possible implementation, the parsing module 302 is used to parse the target intermediate code to determine the location of the entry function;
[0086] Parsing the entry function to obtain a plurality of first functions, where the first functions are external functions called by the entry function;
[0087] The multiple first functions are parsed respectively until all external functions having a calling relationship among the multiple first functions are parsed, so as to obtain multiple second functions, wherein the multiple external functions include the multiple first functions and the multiple second functions.
[0088] In a possible implementation, the parsing module 302 is further used to parse the multiple first functions respectively, and confirm whether there is an external function with a calling relationship among the multiple first functions;
[0089] If there are external functions with a calling relationship among the multiple first functions, the external functions with a calling relationship are parsed respectively until there are no externally referenced functions among the external functions with a calling relationship, thereby obtaining multiple second functions.
[0090] In a possible implementation, the determination module 303 is used to determine a plurality of function bodies from the plurality of in-vitro functions according to the function names and data types of the actual parameters corresponding to the plurality of function call instructions, the function bodies corresponding to the function names, the data types of the actual parameters, and the in-vitro functions;
[0091] According to the vector attributes of the actual parameters of the functions corresponding to the multiple function bodies when being called, the target copies of the multiple called functions are obtained.
[0092] In a possible implementation, the determining module 303 is further configured to copy the multiple function bodies to obtain initial copies of the multiple called functions;
[0093] According to the vector attributes of the actual parameters corresponding to each of the function names and the data types of the actual parameters when the function is called, the vector attributes of the formal parameters in the initial copies of the multiple called functions are identified to obtain the target copies of the multiple called functions.
[0094] In a possible implementation, the determination module 303 is further used to obtain a function call instruction corresponding to an entry function in the target intermediate code;
[0095] Determine a plurality of first function bodies from the plurality of in vitro functions according to the function name and the data type of the actual parameter in the function call instruction corresponding to the entry function;
[0096] Determine, according to the plurality of first function bodies and vector attributes of actual parameters when the functions corresponding to the plurality of first function bodies are respectively called, target copies when the functions corresponding to the plurality of first function bodies are respectively called;
[0097] Determine a plurality of second function bodies from the plurality of in vitro functions according to the function names and data types of actual parameters in the function call instructions corresponding to the plurality of first function bodies;
[0098] According to the vector attributes of the actual parameters of the multiple second function bodies and the functions corresponding to the multiple second function bodies when they are respectively called, the target copies of the ordinary functions when they are respectively called are determined, and the target copies of the multiple called functions include the target copies of the functions corresponding to the multiple first function bodies when they are respectively called and the target copies of the ordinary functions when they are respectively called.
[0099] In a possible implementation, the target intermediate code to be compiled is obtained by performing a compile operation on a target source code written using a parallel programming model.
[0100] It can be understood that since the method embodiment and the device embodiment are different presentation forms of the same technical concept, the content of the method embodiment part in this application should be synchronously adapted to the device embodiment part and will not be repeated here.
[0101] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired or wireless means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.
[0102] Figure 4 is another structural block diagram of the electronic device provided in the embodiment of the present application. Figure 4 As shown, the electronic device 40 may include one or more of the following components: a central processor 401, and a memory 402 coupled to the central processor 401, wherein the memory 402 may store one or more computer programs, and the one or more computer programs may be configured to implement the methods described in the above embodiments when executed by the central processor 401. The electronic device 40 may be the electronic device 10 in the above embodiment, and the central processor 401 may be the central processor 11 in the above embodiment.
[0103] The central processing unit 401 utilizes various interfaces and lines to connect various parts within the entire electronic device 40, and performs various functions of the electronic device 40 and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 402, and calling data stored in the memory 402.
[0104] The memory 402 may include a random access memory (RAM) or a read-only memory (ROM). The memory 402 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 402 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the above-mentioned various method embodiments, etc. The data storage area may also store data created by the electronic device 40 during use, etc. It is understandable that the electronic device 40 may include more or fewer structural elements than those in the above-mentioned structural block diagram, which is not limited here.
[0105] An embodiment of the present application also provides a computer storage medium, on which a computer program / instruction is stored. When the computer program / instruction is executed by a central processing unit, part or all of the steps of any method recorded in the above method embodiment are implemented.
[0106] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute part or all of the steps of any method recorded in the above method embodiments.
[0107] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0108] In the several embodiments provided in the present application, it should be understood that the disclosed methods, devices and systems can be implemented in other ways. For example, the device embodiments described above are merely schematic; for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0109] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0110] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may be physically included separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0111] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform some steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a volatile memory or a non-volatile memory. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM) and direct RAM bus random access memory (DR RAM), among other media that can store program code.
[0112] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions without departing from the spirit and scope of the present invention, and can make various changes and modifications, including the combination of the above-mentioned different functions and implementation steps, including software and hardware implementation methods, all of which are within the scope of protection of the present invention.
Claims
1. A code compilation method, characterized in that: A central processing unit applied to an electronic device, the electronic device comprising the central processing unit and a parallel processor, the parallel processor comprising a scalar instruction processing unit and a vector instruction processing unit group, the method comprising: Get the target intermediate code to be compiled; Parsing the in-vitro function call information in the target intermediate code to obtain multiple in-vitro functions; Determine, according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, and the multiple in vitro functions, the target copies of the multiple called functions, wherein the target copies of the called functions are marked with vector attributes of the formal parameters, and the called functions correspond to the function names and the data types of the actual parameters; Obtaining a target instruction set executable by the parallel processor according to the target copies of the multiple called functions, the target instruction set comprising a target scalar instruction set and a target vector instruction set, the target scalar instruction set comprising a plurality of scalar instructions executable by the scalar instruction processing unit, the scalar instructions being instructions unrelated to data processing, and the target vector instruction set comprising a plurality of vector instructions executable by the vector instruction processing unit group, the vector instructions being instructions related to data processing; The step of parsing the in-vitro function call information in the target intermediate code to obtain multiple in-vitro functions includes: Parsing the target intermediate code to determine the location of the entry function; Parsing the entry function to obtain a plurality of first functions, where the first functions are external functions called by the entry function; The multiple first functions are parsed respectively until all external functions having a calling relationship among the multiple first functions are parsed, so as to obtain multiple second functions, wherein the multiple external functions include the multiple first functions and the multiple second functions.
2. The method according to claim 1, characterized in that The multiple first functions are parsed separately until all external functions having a calling relationship among the multiple first functions are parsed to obtain multiple second functions, including: Analyze the multiple first functions respectively, and confirm whether there is an external function with a calling relationship among the multiple first functions; If there are external functions with a calling relationship among the multiple first functions, the external functions with a calling relationship are parsed respectively until there are no externally referenced functions among the external functions with a calling relationship, thereby obtaining multiple second functions.
3. The method according to claim 1 or 2, characterized in that: Determining target copies of multiple called functions according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, and the multiple in vitro functions, includes: According to the function names and data types of actual parameters corresponding to the multiple function call instructions, determine multiple function bodies from the multiple in-vitro functions, the function bodies corresponding to the function names, the data types of the actual parameters, and the in-vitro functions; According to the vector attributes of the actual parameters of the functions corresponding to the multiple function bodies when being called, the target copies of the multiple called functions are obtained.
4. The method according to claim 3, characterized in that The step of obtaining target copies of multiple called functions according to the vector attributes of actual parameters of the functions corresponding to the multiple function bodies when they are called includes: Copying the plurality of function bodies to obtain initial copies of the plurality of called functions; According to the vector attributes of the actual parameters corresponding to each of the function names and the data types of the actual parameters when the function is called, the vector attributes of the formal parameters in the initial copies of the multiple called functions are identified to obtain the target copies of the multiple called functions.
5. The method according to claim 1 or 2, characterized in that: Determining target copies of multiple called functions according to the function names and data types of actual parameters corresponding to the multiple function call instructions in the target intermediate code, and the multiple in vitro functions, includes: Obtaining a function call instruction corresponding to an entry function in the target intermediate code; Determine a plurality of first function bodies from the plurality of in vitro functions according to the function name and the data type of the actual parameter in the function call instruction corresponding to the entry function; Determine, according to the plurality of first function bodies and vector attributes of actual parameters when the functions corresponding to the plurality of first function bodies are respectively called, target copies when the functions corresponding to the plurality of first function bodies are respectively called; Determine a plurality of second function bodies from the plurality of in vitro functions according to the function names and data types of actual parameters in the function call instructions corresponding to the plurality of first function bodies; According to the vector attributes of the actual parameters of the multiple second function bodies and the functions corresponding to the multiple second function bodies when they are respectively called, the target copies of the ordinary functions when they are respectively called are determined, and the target copies of the multiple called functions include the target copies of the functions corresponding to the multiple first function bodies when they are respectively called and the target copies of the ordinary functions when they are respectively called.
6. The method according to claim 1, characterized in that The target intermediate code to be compiled is obtained by performing a compile operation on the target source code written using a parallel programming model.
7. A code compiling device, characterized in that: A central processor applied to an electronic device, the electronic device comprising the central processor and a parallel processor, the parallel processor comprising a scalar instruction processing unit and a vector instruction processing unit group, the device comprising: The acquisition module is used to obtain the target intermediate code to be compiled; A parsing module is used to parse the function in-vitro function call information in the target intermediate code to obtain multiple function in-vitro functions; the parsing module is specifically used to parse the target intermediate code to determine the location of the entry function; parse the entry function to obtain multiple first functions, the first function is the external function called by the entry function; parse the multiple first functions respectively until all the external functions with calling relationships in the multiple first functions are parsed, to obtain multiple second functions, the multiple function in-vitro functions include the multiple first functions and the multiple second functions; A determination module, configured to determine target copies of multiple called functions according to function names and data types of actual parameters corresponding to multiple function call instructions in the target intermediate code, and the multiple in vitro functions, wherein the target copies of the called functions are marked with vector attributes of formal parameters, and the called functions correspond to the function names and the data types of the actual parameters; A generation module is used to obtain a target instruction set that can be executed by the parallel processor according to the target copies of the multiple called functions, the target instruction set includes a target scalar instruction set and a target vector instruction set, the target scalar instruction set includes a plurality of scalar instructions that can be executed by the scalar instruction processing unit, the scalar instructions refer to instructions that are not related to data processing, and the target vector instruction set includes a plurality of vector instructions that can be executed by the vector instruction processing unit group, and the vector instructions refer to instructions related to data processing.
8. An electronic device, characterized in that: The method comprises a central processing unit, a parallel processor, a memory and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the central processing unit, and the programs include instructions for executing the steps in the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a central processing unit, the steps of the method according to any one of claims 1 to 6 are implemented.
