Code compilation method and related device

By performing three compilation operations on the source code written using the parallel programming model, distinguishing and processing scalar instructions and vector instructions, the problem that traditional parallel processors cannot distinguish instruction types is solved, and the efficient operation and development difficulty of the new parallel processor is reduced.

CN116700730BActive Publication Date: 2024-11-19AZURENGINE TECH ZHUHAI INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310473268.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-27
Publication Date
2024-11-19
Estimated Expiration
2043-04-27

AI Technical Summary

Technical Problem

Traditional parallel processors cannot distinguish between vector instructions and scalar instructions when executing instructions, resulting in repeated operation of scalar instructions, wasting time and power consumption, and it is difficult for developers to take advantage of the advantages of new parallel processors. The source code written by traditional parallel programming models is not suitable. Equipped with a new processor.

Method used

Provide a code compilation method, which performs three compilation operations on the source code written using a parallel programming model through the central processor, distinguishes and processes scalar instructions and vector instructions, generates executable machine code, and uses scalar instruction processing unit and vector instruction processing unit. Perform separately to increase processing speed and reduce power consumption.

Benefits of technology

It realizes efficient operation of new parallel processors, reduces development difficulty, and enables the source code written in traditional parallel programming models to run on new processors, improving processing speed and reducing power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116700730B_ABST
    Figure CN116700730B_ABST
Patent Text Reader

Abstract

The present application provides a code compilation method and related devices, which are applied to the central processing unit of an electronic device, the electronic device includes a central processing unit and a parallel processor, the parallel processor includes a scalar instruction processing unit and a vector instruction processing unit, and the method includes: performing a first compilation operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set; performing a second compilation operation on the target intermediate instruction set to obtain a scalar-vector mixed instruction set corresponding to the target intermediate instruction set; performing a third compilation operation on the scalar-vector mixed instruction set corresponding to the target intermediate instruction set to obtain a target machine code. In this way, different processing units / processing unit groups in a 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 traditional parallel programming models to write source code, which reduces the difficulty of development.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the general encoding, decoding or code conversion technology field of the new generation information technology industry, and specifically relates 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 present application provides a code compilation method and related devices, so that the source code written by developers using the traditional parallel programming model can be compiled into machine code that can be executed by a new type of parallel processor, thereby taking advantage of the advantages of the new type of parallel processor and reducing the difficulty of development.

[0005] In a first aspect, an embodiment of the present application provides a code compilation 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] Performing a first compiling operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set;

[0007] Performing a second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, wherein the scalar-vector hybrid instruction set includes a plurality of scalar instructions and a plurality of vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing;

[0008] A third compiling operation is performed on the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set to obtain a target machine code, wherein the target machine code includes a target scalar machine code executable by the scalar instruction processing unit and a target vector machine code executable by the vector instruction processing unit group.

[0009] In a second aspect, an embodiment of the present application provides a code compilation 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:

[0010] A first compiling unit, configured to perform a first compiling operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set;

[0011] a second compiling unit, configured to perform a second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, wherein the scalar-vector hybrid instruction set includes a plurality of scalar instructions and a plurality of vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing;

[0012] A third compilation unit is used to perform a third compilation operation on the scalar-vector mixed instruction set corresponding to the target intermediate instruction set to obtain a target machine code, wherein the target machine code includes a target scalar machine code that can be executed by the scalar instruction processing unit and a target vector machine code that can be executed by the vector instruction processing unit group.

[0013] 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.

[0014] 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.

[0015] It can be seen that in the embodiment of the present application, the central processing unit of the electronic device performs a first compilation operation on the target source code written using the parallel programming model to obtain a target intermediate instruction set, then performs a second compilation operation on the target intermediate instruction set to obtain a corresponding scalar-vector mixed instruction set, and finally performs a third compilation operation on the scalar-vector mixed instruction set to obtain a target machine code that can be executed by the parallel processor in the electronic device. In this way, the central processing unit of the electronic device can distinguish scalar instructions from vector instructions in the process of converting the target intermediate instruction set into the target machine 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 traditional parallel programming models to write source code, which reduces the difficulty of development. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 is a structural block diagram of an electronic device provided in an embodiment of the present application;

[0018] Figure 2 It is a flowchart of a code compilation method provided in an embodiment of the present application;

[0019] Figure 3 It is a block diagram of the functional units of a code compilation device provided in an embodiment of the present application;

[0020] Figure 4 This is another structural block diagram of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] 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.

[0022] 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.

[0023] 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.

[0024] See also Figure 1 , Figure 1 It is a structural block diagram of an electronic device provided in an embodiment of the present application. As shown in the figure, the electronic device 10 includes a central processing unit 11 and a parallel processor 12, and the central processing unit 11 and the parallel processor 12 are connected 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 and the vector instruction processing unit group 122 are connected to realize data transmission. The parallel processor 12 can specifically be a reconfigurable parallel processor RPP (Reconfigurable Parallel Processing), the scalar instruction processing unit 121 can specifically be a processor core in the RPP, and the vector instruction processing unit group 122 can specifically be another processor core in the RPP, which may 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 to 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.

[0025] A code compilation method provided by an embodiment of the present application is introduced below.

[0026] 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 1In the central processing unit 11 shown, Figure 2 As shown, the method includes:

[0027] Step 201 , performing a first compile operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set.

[0028] In a possible example, the parallel programming model is a Computer Unified Device Architecture (CUDA) programming model.

[0029] Among them, the Compute Unified Device Architecture (CUDA) programming model is a programming model developed for the graphics processing unit GPU. Developers can program the GPU using a simple programming language based on the CUDA programming model, but 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 after the machine code obtained by the existing compilation method. 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 the target machine code that can be executed by the parallel processor mentioned in the embodiments of the present application can greatly reduce the difficulty of development.

[0030] In one possible example, performing a first compilation operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set includes: performing a first compilation operation on a target source code written using the parallel programming model using a low-level virtual machine LLVM compiler to obtain a target intermediate instruction set.

[0031] Among them, the first compilation operation can be a front-end compilation operation based on the LLVM compiler, and the front-end compilation operation can include steps such as lexical analysis, syntax analysis, semantic analysis, and generation of an intermediate instruction set, and finally obtain a target intermediate instruction set. In this example, the target intermediate instruction set can specifically be in the form of an LLVM intermediate representation layer (Intermediate Representation, IR). It can be understood that the above-mentioned LLVM represents the industry standard for a three-stage compiler system, namely the front-end compilation, intermediate representation layer, and back-end compilation stages. LLVM was originally called a "low-level virtual machine", but it is currently only an abbreviation because LLVM technology is not limited to virtual machines.

[0032] 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 instruction set, and improve compilation efficiency.

[0033] Step 202: Perform a second compile operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set.

[0034] The scalar-vector hybrid instruction set includes a plurality of scalar instructions and a plurality of vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing.

[0035] In one possible example, the target intermediate instruction set includes multiple target intermediate instructions, and the second compilation operation is performed on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, including: converting the multiple target intermediate instructions into scalar instructions to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions; determining multiple reference vector instructions from the multiple reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set.

[0036] In other possible examples, the central processing unit can also convert all intermediate instructions into vector instructions, and then determine the scalar instructions that are not related to data processing from all the vector instructions, and finally obtain a scalar-vector mixed instruction set. However, since the vector instructions are only related to the data processed by the thread, the vector instructions are mainly reflected in the computing power, and are very limited in other aspects. Therefore, it is very difficult to find the basis for converting the intermediate instructions into vector instructions. It may be impossible to convert all the intermediate instructions into vector instructions, resulting in the crash of the compilation process. In this example, the central processing unit first converts all the intermediate instructions into scalar instructions, and then determines the vector instructions related to data processing from all the scalar instructions, thereby converting them into a scalar-vector mixed instruction set. The advantage of doing this is that since the scalar instructions are not related to data processing, from the aspect of instruction composition, the scalar instructions are easier to distinguish than the vector instructions, and it is also simpler to convert the intermediate instructions into scalar instructions, which can ensure that all the intermediate instructions can be converted into scalar instructions, thereby ensuring that the compilation process will not crash.

[0037] It can be seen that in this example, the central processing unit of the electronic device converts all multiple target intermediate instructions into corresponding reference scalar instructions, and then determines the reference vector instructions related to data processing from the converted reference scalar instructions, thereby obtaining a scalar-vector mixed instruction set corresponding to the target intermediate instruction set, ensuring the stability of the compilation process and improving compilation efficiency.

[0038] In one possible example, converting the multiple target intermediate instructions into scalar instructions to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions includes: selecting the multiple target intermediate instructions as scalar instructions according to an instruction selection template to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions, wherein the instruction selection template includes multiple intermediate instructions and multiple scalar instructions corresponding one-to-one to the multiple intermediate instructions.

[0039] Among them, the instruction selection template is a pre-stored template for instruction selection in the instruction selection stage of the back-end compilation, and the back-end compilation may include the second compilation operation and the third compilation operation, and the second compilation operation may specifically be an instruction selection operation, corresponding to the instruction selection stage in the back-end compilation. In an embodiment of the present application, the second compilation operation may be a compiler program adapted to the hardware architecture of the parallel processor in the embodiment of the present application based on the process of instruction selection in the LLVM back-end compiler. When developing a compilation system, developers can create scalar instructions corresponding to each intermediate instruction, and create the instruction selection template based on the one-to-one correspondence between each intermediate instruction and each scalar instruction, and the central processing unit performs operations such as reading and storage, so that when the central processing unit converts multiple target intermediate instructions into scalar instructions, it can directly call the pre-stored instruction selection template and directly perform instruction matching, thereby quickly selecting all target intermediate instructions as reference scalar instructions.

[0040] It can be seen that in this example, the central processing unit of the electronic device can directly select multiple target intermediate instructions as reference scalar instructions based on the pre-stored instruction selection template, thereby improving the compilation speed.

[0041] In one possible example, determining multiple reference vector instructions from the multiple reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set includes: determining multiple first scalar instructions from the multiple reference scalar instructions, where the first scalar instructions refer to scalar instructions with register operands associated with thread identifiers; determining multiple reference vector instructions from the multiple reference scalar instructions based on the multiple first scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set.

[0042] Among them, an instruction is composed of an opcode and several operands. The operands can be immediate numbers, basic block labels, registers, etc. For example, in the instruction "MOV AX, BX", AX and BX are 16-bit registers. The MOV instruction is followed by a destination operand, and the destination operand is followed by a source operand. The destination operand and the source operand are separated by a comma, indicating that data is transferred from the BX register to the AX register. In this example, AX and BX are register operands. The process of determining the reference vector instruction from the reference scalar instruction is essentially to find the instruction related to data processing from all instructions. Because under the parallel processing architecture, the instructions for processing data need to run in multiple threads, and the processing of different data in the thread depends on the thread identifier (thread ID) for addressing, so it is only necessary to find the first scalar instruction with the register operand associated with the thread identifier from the reference scalar instruction, and then further determine all the instructions related to data processing from the reference scalar instruction based on the first scalar instruction to complete the determination of the vector instruction. Among them, whether the register operand of the instruction is associated with the thread ID can be determined specifically by analyzing whether the register operand of the instruction directly or indirectly depends on the thread ID. For example, whether the register operand of the instruction is associated with the thread ID can be determined based on whether the text of threadID appears directly in the instruction, or the text of threadID appears in the relevant reference of the instruction.

[0043] It can be seen that in this example, the central processing unit of the electronic device can first determine the first scalar instruction associated with the register operand thread identifier from multiple reference scalar instructions, and then further determine all reference vector instructions related to data processing in the reference scalar instructions based on the first scalar instruction, and then obtain a scalar-vector mixed instruction set to ensure the stability of the compilation process and improve compilation efficiency.

[0044] In one possible example, determining a plurality of reference vector instructions from the plurality of reference scalar instructions according to the plurality of first scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set includes: performing the following operations on the plurality of first scalar instructions: converting a target scalar register category of the first scalar instruction currently being processed into a target vector register category corresponding to the target scalar register category; converting a second scalar instruction among the plurality of reference scalar instructions into a reference vector instruction corresponding to the target vector register category, wherein the second scalar instruction refers to a scalar instruction whose register operand is used to indicate the target scalar register category; continuing to process the next first scalar instruction until all the plurality of first scalar instructions are processed to obtain the plurality of reference vector instructions; and determining a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set according to the plurality of reference vector instructions and other reference scalar instructions among the plurality of reference scalar instructions except a third scalar instruction, wherein the third scalar instruction refers to a reference scalar instruction among the plurality of reference scalar instructions that is converted into the reference vector instruction.

[0045] Wherein, the register category may include an integer 16-bit register, a floating point 16-bit register, an integer 32-bit register and a floating point 32-bit register, and each register category includes corresponding scalar registers and vector registers, for example, a scalar integer 16-bit register and a vector integer 16-bit register. In this example, the scalar register refers to a register corresponding to a scalar instruction processing unit, and the vector register refers to a register corresponding to a vector instruction processing unit group. Since the first scalar instruction is an instruction associated with a thread identifier of a register operand, it must be an instruction related to data processing, so its corresponding register also needs to be converted into a vector register. For example, scalar instruction A belongs to the first scalar instruction, and its corresponding target scalar register category is a scalar integer 16-bit register. At this time, the register is converted into the corresponding target vector register category, that is, a vector integer 16-bit register. Accordingly, since the integer 16-bit register is a vector register, all scalar instructions whose register operands in the reference scalar instruction indicate an integer 16-bit register, that is, the second scalar instruction, need to be converted into vector instructions to adapt to the register category corresponding to the vector instruction processing unit group. For example, scalar instruction B is an instruction in the reference scalar instruction set, and its register operand is not associated with a thread identifier, that is, it does not belong to the first scalar instruction, but its register operand is used to indicate a register type of a scalar integer 16-bit register, so scalar instruction B belongs to the second scalar instruction and also needs to be converted into a vector instruction. It can be understood that one first scalar instruction corresponds to a group of second scalar instructions, and there are multiple first scalar instructions in multiple reference scalar instructions, so the third scalar instruction that needs to be converted into a vector instruction in the reference scalar instruction includes multiple groups of second scalar instructions.

[0046] It can be seen that in this example, the central processing unit of the electronic device can determine other scalar instructions that are not associated with thread identifiers but are also related to data processing through the register category of the first scalar instruction with a thread identifier associated with the register operand, and then can convert all scalar instructions that meet the requirements in the reference scalar instructions into vector instructions, thereby increasing the stability of the compilation system and improving the compilation efficiency.

[0047] Step 203: Perform a third compile operation on the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set to obtain a target machine code.

[0048] Wherein, the target machine code includes a target scalar machine code that can be executed by the scalar instruction processing unit and a target vector machine code that can be executed by the vector instruction processing unit group, and the third compile operation may include physical register allocation, instruction optimization and other processes to generate the target machine code, and in this process, it will be marked which are scalar machine codes and which are vector machine codes, so as to facilitate the identification before subsequent execution. Wherein, the third compile operation can be specifically based on the LLVM back-end compiler about physical register allocation, instruction optimization and other processes adapted to the hardware architecture of the parallel processor in the embodiment of the present application and transformed. Wherein, machine code refers to instructions that can be recognized and executed by the processor / processing unit (group), which belongs to a computer low-level language, and the opposite computer high-level language refers to a language closer to people, such as the target source code in the embodiment of the present application, that is, the code written by the user, using a computer high-level language. For a computer, it is necessary to convert a computer high-level language into a computer low-level language before it can be recognized and executed by the device, and this conversion process is compilation. The compilation method described in the embodiment of the present application is the process of converting the source code written in the parallel programming model into a machine code that can be executed by a scalar instruction processing unit and a vector instruction processing unit group. After getting the machine code, the scalar instruction processing unit will read the machine code from the memory, directly execute the scalar machine code, and harden (or configure) the vector machine code into the vector instruction processing unit group. Then, a large number of vector instruction processing units will process data in parallel at the same time.

[0049] It can be seen that in the embodiment of the present application, the central processing unit of the electronic device performs a first compilation operation on the target source code written using the parallel programming model to obtain a target intermediate instruction set, then performs a second compilation operation on the target intermediate instruction set to obtain a corresponding scalar-vector mixed instruction set, and finally performs a third compilation operation on the scalar-vector mixed instruction set to obtain a target machine code that can be executed by the parallel processor in the electronic device. In this way, the central processing unit of the electronic device can distinguish scalar instructions from vector instructions in the process of converting the target intermediate instruction set into the target machine 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 traditional parallel programming models to write source code, which reduces the difficulty of development.

[0050] In accordance with the above-mentioned embodiments, please refer to Figure 3 , Figure 3 is 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: a first compiling unit 301, which is used to perform a first compiling operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set; a second compiling unit 302, which is used to perform a second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, wherein the scalar-vector hybrid instruction set includes multiple scalar instructions and multiple vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing; a third compiling unit 303, which is used to perform a third compiling operation on the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set to obtain a target machine code, wherein the target machine code includes a target scalar machine code that can be executed by the scalar instruction processing unit and a target vector machine code that can be executed by the vector instruction processing unit group.

[0051] In one possible example, the target intermediate instruction set includes multiple target intermediate instructions. In terms of performing a second compilation operation on the target intermediate instruction set to obtain a scalar-vector mixed instruction set corresponding to the target intermediate instruction set, the second compilation unit 302 is specifically used to: convert the multiple target intermediate instructions into scalar instructions to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions; determine multiple reference vector instructions from the multiple reference scalar instructions to obtain a scalar-vector mixed instruction set corresponding to the target intermediate instruction set.

[0052] In one possible example, in terms of converting the multiple target intermediate instructions into scalar instructions to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions, the second compilation unit 302 is specifically used to: select the multiple target intermediate instructions as scalar instructions according to an instruction selection template to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions, and the instruction selection template includes multiple intermediate instructions and multiple scalar instructions corresponding one by one to the multiple intermediate instructions.

[0053] In a possible example, in terms of determining multiple reference vector instructions from the multiple reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, the second compilation unit 302 is specifically used to: determine multiple first scalar instructions from the multiple reference scalar instructions, where the first scalar instruction refers to a scalar instruction with a register operand associated with a thread identifier; determine multiple reference vector instructions from the multiple reference scalar instructions based on the multiple first scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set.

[0054] In one possible example, in terms of determining multiple reference vector instructions from the multiple reference scalar instructions according to the multiple first scalar instructions to obtain the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, the second compilation unit 302 is specifically used to: perform the following operations on the multiple first scalar instructions: convert the target scalar register category of the currently processed first scalar instruction into a target vector register category corresponding to the target scalar register category; convert a second scalar instruction in the multiple reference scalar instructions into a reference vector instruction corresponding to the target vector register category, the second scalar instruction refers to a scalar instruction whose register operand is used to indicate the target scalar register category; continue to process the next first scalar instruction until all the multiple first scalar instructions are processed to obtain the multiple reference vector instructions; determine the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set according to the multiple reference vector instructions and other reference scalar instructions in the multiple reference scalar instructions except the third scalar instruction, the third scalar instruction refers to the reference scalar instruction in the multiple reference scalar instructions that is converted into the reference vector instruction.

[0055] In a possible example, the parallel programming model is a Computer Unified Device Architecture (CUDA) programming model.

[0056] In one possible example, in terms of performing a first compilation operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set, the first compilation unit 301 is specifically used to: perform a first compilation operation on a target source code written using the parallel programming model through a low-level virtual machine LLVM compiler to obtain a target intermediate instruction set.

[0057] 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.

[0058] 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.

[0059] 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.

[0060] 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.

[0061] 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.

[0062] 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.

[0063] 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.

[0064] 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.

[0065] 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.

[0066] 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.

[0067] 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.

[0068] 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.

[0069] 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: Performing a first compiling operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set, wherein the target intermediate instruction set includes a plurality of target intermediate instructions; Performing a second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, wherein the scalar-vector hybrid instruction set includes a plurality of scalar instructions and a plurality of vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing; Performing a third compiling operation on the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set to obtain a target machine code, wherein the target machine code includes a target scalar machine code executable by the scalar instruction processing unit and a target vector machine code executable by the vector instruction processing unit group; The performing of the second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set comprises: converting the plurality of target intermediate instructions into scalar instructions to obtain a plurality of reference scalar instructions corresponding to the plurality of target intermediate instructions; determining a plurality of reference vector instructions from the plurality of reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set; The method of determining a plurality of reference vector instructions from the plurality of reference scalar instructions comprises: determining a plurality of first scalar instructions from the plurality of reference scalar instructions, wherein the first scalar instructions refer to scalar instructions whose register operands are associated with thread identifiers; performing the following operations on the plurality of first scalar instructions: converting a target scalar register category of the first scalar instruction currently being processed into a target vector register category corresponding to the target scalar register category; converting a second scalar instruction from the plurality of reference scalar instructions into a reference vector instruction corresponding to the target vector register category, wherein the second scalar instruction refers to a scalar instruction whose register operands are used to indicate the target scalar register category; and continuing to process the next first scalar instruction until all the plurality of first scalar instructions are processed to obtain the plurality of reference vector instructions.

2. The method according to claim 1, characterized in that: The converting the plurality of target intermediate instructions into scalar instructions to obtain a plurality of reference scalar instructions corresponding to the plurality of target intermediate instructions comprises: The multiple target intermediate instructions are selected as scalar instructions according to an instruction selection template to obtain multiple reference scalar instructions corresponding to the multiple target intermediate instructions. The instruction selection template includes multiple intermediate instructions and multiple scalar instructions corresponding one-to-one to the multiple intermediate instructions.

3. The method according to claim 1, characterized in that: The step of determining a plurality of reference vector instructions from the plurality of reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set includes: A scalar-vector hybrid instruction set corresponding to the target intermediate instruction set is determined based on the multiple reference vector instructions and other reference scalar instructions among the multiple reference scalar instructions except a third scalar instruction, wherein the third scalar instruction refers to a reference scalar instruction among the multiple reference scalar instructions that is converted into the reference vector instruction.

4. The method according to claim 1, characterized in that: The parallel programming model is a Computer Unified Device Architecture (CUDA) programming model.

5. The method according to claim 4, characterized in that: The step of performing a first compile operation on the target source code written using the parallel programming model to obtain a target intermediate instruction set includes: A first compiling operation is performed on a target source code written using the parallel programming model by using a low-level virtual machine LLVM compiler to obtain a target intermediate instruction set.

6. 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: A first compiling unit is used to perform a first compiling operation on a target source code written using a parallel programming model to obtain a target intermediate instruction set, wherein the target intermediate instruction set includes a plurality of target intermediate instructions; a second compiling unit, configured to perform a second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set, wherein the scalar-vector hybrid instruction set includes a plurality of scalar instructions and a plurality of vector instructions, wherein the scalar instructions refer to instructions unrelated to data processing, and the vector instructions refer to instructions related to data processing; A third compiling unit is configured to perform a third compiling operation on the scalar-vector hybrid instruction set corresponding to the target intermediate instruction set to obtain a target machine code, wherein the target machine code includes a target scalar machine code executable by the scalar instruction processing unit and a target vector machine code executable by the vector instruction processing unit group; The performing of the second compiling operation on the target intermediate instruction set to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set comprises: converting the plurality of target intermediate instructions into scalar instructions to obtain a plurality of reference scalar instructions corresponding to the plurality of target intermediate instructions; determining a plurality of reference vector instructions from the plurality of reference scalar instructions to obtain a scalar-vector hybrid instruction set corresponding to the target intermediate instruction set; The method of determining a plurality of reference vector instructions from the plurality of reference scalar instructions comprises: determining a plurality of first scalar instructions from the plurality of reference scalar instructions, wherein the first scalar instructions refer to scalar instructions whose register operands are associated with thread identifiers; performing the following operations on the plurality of first scalar instructions: converting a target scalar register category of the first scalar instruction currently being processed into a target vector register category corresponding to the target scalar register category; converting a second scalar instruction from the plurality of reference scalar instructions into a reference vector instruction corresponding to the target vector register category, wherein the second scalar instruction refers to a scalar instruction whose register operands are used to indicate the target scalar register category; and continuing to process the next first scalar instruction until all the plurality of first scalar instructions are processed to obtain the plurality of reference vector instructions.

7. 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 5.

8. A computer-readable storage medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instruction is executed by a central processing unit, the steps of the method according to any one of claims 1 to 5 are implemented.