Compiling devide, compiling method, and compiling program
The compilation device and method address the inefficiency in memory access by employing loop unrolling and packed vectorization to optimize source programs, resulting in improved processing speed and efficiency for vector computers.
Patent Information
- Application Number
- PCT/JP2024/004805
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-23
- Filing Date
- 2024-02-13
- Publication Date
- 2024-09-26
AI Technical Summary
The existing compilation methods for vector computers are inefficient in reducing memory access frequency, leading to suboptimal processing performance due to insufficient optimization of source programs, especially when adjacent memory access instructions are present, resulting in decreased processing speed.
A compilation device and method that includes loop unrolling and packed vectorization to convert instructions into packed vector instructions, reducing memory access frequency by optimizing outer loops and enabling faster execution on vector computers.
This approach significantly enhances processing speed by reducing memory access frequency and improving the execution efficiency of source programs on vector computers, particularly for loops with adjacent data access, thereby achieving faster program execution.
Smart Images

Figure JP2024004805_26092024_PF_FP
Abstract
Description
Compiling device, compiling method, and compiling program
[0001] The present invention relates to a compiling device, a compiling method, and a compiling program for improving the processing performance of a computer.
[0002] The access time from a computer's arithmetic unit (e.g., a central processing unit (CPU)) to a main memory is longer than the calculation time of the arithmetic unit. Therefore, in order to improve the processing performance of the computer, in other words, to speed up computer processing, it is important to reduce the frequency of access to the main memory.
[0003] Patent Document 1 describes a method for reducing access to main memory when adjacent memory access instructions exist in a source program executable on a vector computer. Specifically, a compiler (compilation device) reduces duplicated memory accesses, thereby improving the processing performance of the vector computer.
[0004] Adjacent memory access instructions refer to multiple instructions that each access data allocated to adjacent areas in main memory. Accessing adjacent data refers to accessing data in adjacent areas in main memory. Accessing adjacent data is sometimes referred to as adjacent access.
[0005] Japanese Patent Application Laid-Open No. 2000-48009
[0006] The compiler device described in Patent Document 1 generates an instruction to slide data in a first vector register and store it in a second vector register. This may result in a shortage of elements used in the calculation (see FIG. 4 of Patent Document 1). In this case, the compiler device described in Patent Document 1 generates additional vector instructions for load / store or calculation, or scalar instructions, to compensate for the shortage of elements. In other words, the compiler device described in Patent Document 1 does not sufficiently optimize the source program, and there is a possibility that the speed improvement is insufficient.
[0007] An object of the present invention is to provide a compiling device, a compiling method, and a compiling program that can enable a computer to execute a program at higher speed.
[0008] A compiling device according to the present invention includes: loop unrolling means for performing loop unrolling of an outer loop in multiple loops in a source program; and packed vectorization means for converting instructions in the loop into packed vector instructions after the loop unrolling has been performed.
[0009] The compiling method according to the present invention performs loop unrolling of an outer loop in multiple loops in a source program, and after the loop unrolling is performed, converts instructions in the loop into packed vector instructions.
[0010] The compilation program according to the present invention causes a computer to execute a process of performing loop unrolling of an outer loop in multiple loops in a source program, and a process of converting instructions in the loop into packed vector instructions after the loop unrolling has been performed.
[0011] According to the present invention, it becomes possible to execute a program in a computer at higher speed.
[0012] FIG. 1 is a block diagram showing an example of the configuration of a compiling device. FIG. 2 is a block diagram showing an example of the configuration of a vector computer capable of executing an object program. FIG. 3 is a flowchart showing the operation of the compiling device. FIG. 4 is an explanatory diagram showing an example of a source program that cannot be vectorized. FIG. 5 is an explanatory diagram showing an example of a source program. FIG. 6 is an explanatory diagram showing an example of a source program to which loop unrolling has been performed. FIG. 7 is an explanatory diagram showing an example of a packed vector instruction. FIG. 8 is an explanatory diagram for explaining the action of a packed vector instruction. FIG. 9 is a block diagram showing an example of a computer having a CPU. FIG. 10 is a block diagram showing the main parts of the compiling device.
[0013] Hereinafter, an embodiment of the present invention will be described with reference to the drawings.
[0014] 1 is a block diagram showing an example of the configuration of a compiling device 100. The compiling device 100 shown in FIG. 1 includes a syntax analysis unit 10, a first intermediate language storage unit 20, an optimization unit 30, a second intermediate language storage unit 40, and a code generation unit 50.
[0015] The optimization unit 30 includes a loop analysis unit 31 , an outer loop unrolling unit 32 , and a packed vectorization unit 33 .
[0016] The syntax analysis unit 10 performs syntax analysis of the input source program. The syntax analysis unit 10 generates a first intermediate language based on the results of the syntax analysis, and temporarily stores the first intermediate language in the first intermediate language storage unit 20.
[0017] The optimization unit 30 reads the first intermediate language from the first intermediate language storage unit 20. The optimization unit 30 performs optimization processes such as loop unrolling, loop vectorization, and register allocation on the first intermediate language. The optimization unit 30 temporarily stores the optimized first intermediate language in the second intermediate language storage unit 40 as a second intermediate language.
[0018] The code generation unit 50 reads the second intermediate language from the second intermediate language storage unit 40. The code generation unit 50 translates the second intermediate language into machine language to generate an object program that can be executed by a vector computer.
[0019] In the optimization unit 30, the loop analysis unit 31 determines whether multiple loops in a source program include accesses to adjacent data. The loop analysis unit 31 also determines whether an inner loop can be vectorized. In the following explanation, a double loop is used as an example of a multiple loop.
[0020] The outer loop unrolling processor 32 performs loop unrolling of the outer loop (outermost loop).
[0021] The packed vectorization processor 33 applies packed vectorization to the operations of the loop after the outer loop has been unrolled. Vectorization is the process of converting the operations within the loop into vector operations. Packed vectorization is the process of converting the operation instructions within the loop into packed vector instructions or SIMD (Single Instruction Multiple Data) instructions. A packed vector instruction is an operation instruction that can process multiple data strings with a single instruction.
[0022] FIG. 2 is a block diagram showing an example of a vector computer capable of executing an object program generated by the compiling device 100. As shown in FIG.
[0023] In the vector computer 200, the arithmetic unit 210 is composed of a CPU and a GPU (Graphics Processing Unit). The arithmetic unit 210 obtains data from the main memory 220 or the vector register 230. The main memory 220 stores arrays necessary for the arithmetic unit 210 to execute calculations and data representing the results of the calculations.
[0024] The vector register 230 is a storage device that the arithmetic unit 210 can access faster than the main memory 220. The vector register 230 stores data strings loaded from the main memory 220. The arithmetic unit 210 can also store data in the vector register 230. Note that vector computers that perform vector operations on data strings held in the vector register 230, rather than on data strings held in the main memory 220, are the mainstream.
[0025] Next, the operation of the compiling device will be described with reference to Fig. 3. Fig. 3 is a flowchart showing the operation of the compiling device 100.
[0026] The syntax analysis unit 10 inputs a source program (step S101). The input source program is a program written in a high-level language. The high-level language is, for example, FORTRAN. The syntax analysis unit 10 performs syntax analysis of the source program and generates a first intermediate language (steps S102 and S103). The syntax analysis unit 10 temporarily stores the first intermediate language in the first intermediate language storage unit 20.
[0027] The loop analysis unit 31 detects a double loop in the source program (step S104). If no double loop is present in the source program, the process proceeds to step S109. If a double loop is present, the loop analysis unit 31 determines whether the outer loop of the double loop includes an access to adjacent data in the main memory (adjacent access) (step S105). If no adjacent access is present, the process proceeds to step S109.
[0028] When a program written in FORTRAN is used, a two-dimensional array (say A(I,J)) is generally allocated in main memory so that the elements in the first dimension are adjacent, such as A(I,J) and A(I+1,J). On the other hand, adjacent elements to a given element in the second dimension, such as A(I,J) and A(I,J+1), are allocated in main memory in an area spaced the same distance as the number of elements in the first dimension (N, if the maximum value of I is N). In other words, in FORTRAN, when I is a variable handled in an outer loop, there will generally be adjacent accesses in the outer loop.
[0029] If adjacent accesses exist, the loop analysis unit 31 checks whether the inner loop of the double loop can be vectorized (step S106). The loop analysis unit 31 determines that the loop cannot be vectorized if, for example, there is a dependency between the definition and reference of an array or variable in the loop.
[0030] 4 is an explanatory diagram showing an example of a source program that cannot be vectorized. In the example shown in FIG. 4, array A has a dependency, so vectorization is not possible. In such cases, an attempt is generally made to interchange the loops. In the example shown in FIG. 4, the loop at I and the loop at J are interchanged. Since there is no dependency between the loops at J, the interchange makes it possible to vectorize the inner loop.
[0031] However, the reordering makes adjacent access impossible, which results in a decrease in the processing speed of a computer that executes an object program generated from a source program in which loops have been reordered.
[0032] As will be explained below, in this embodiment, it is possible to improve the processing speed while preventing a decrease in the processing speed of the computer due to the inability to perform adjacent access.
[0033] If the inner loop is vectorizable, the outer loop unrolling unit 32 performs loop unrolling of the outer loop (step S107).
[0034] 5 and 6 are explanatory diagrams for explaining loop unrolling. Fig. 5 shows an example of a source program. Fig. 6 shows an example of a source program to which loop unrolling has been applied.
[0035] 5 shows an example in which two-stage loop unrolling is performed, but the number of stages of unrolling may be more than two. However, if the number of stages is increased, the number of accesses to the main memory will decrease, but there is a risk of a shortage of vector registers, resulting in a decrease in performance. Therefore, the number of stages of unrolling is set so that the performance improvement due to the reduction in the number of accesses to the main memory is not compromised by a decrease in performance due to a shortage of vector registers. In this sense, it is preferable that the number of stages of unrolling is two.
[0036] The packed vectorization processor 33 converts the instructions in the loop into packed vector instructions (step S108). In other words, the packed vectorization processor 33 applies packed vectorization to the outer loop and the inner loop together.
[0037] 7 is an explanatory diagram showing an example of a packed vector instruction. Assume that the object program is executed on the vector computer 200 shown in FIG. 2, and the vector register 230 is a register that can store 256 elements of 8-byte data.
[0038] 7 is an instruction to load two consecutive 4-byte data separated by (N*4) bytes from the main memory 220 into one element of the vector register 230. The PVAD instruction is an arithmetic instruction to add two 4-byte data stored in one element of the vector register 230 element by element. The PVST instruction is an instruction to store a data string in the vector register 230 separated by (N*4) bytes into the main memory 220.
[0039] 8 is a diagram illustrating the operation of a packed vector instruction. The PVAD instruction is shown as an example. As shown in FIG. 8, the PVAD instruction executes the operations B(I,J)+C(I,J) and B(I+1,J)+C(I+1,J) in the loop (see FIG. 6) together.
[0040] When the compiling device 100 of this embodiment is used, a source program in which the outer loop of a multiplexed loop cannot be vectorized or in which the access efficiency of the main memory decreases when the loop is rearranged (adjacent access becomes impossible), can be converted into a source program that can be processed at high speed by a computer.
[0041] Furthermore, the greater the number of iterations in a loop, the greater the speed-up effect of vectorization. In other words, if the number of iterations is small, the speed-up effect of vectorization is small. By applying the compiling method in the compiling device of this embodiment to a source program that includes a loop with a small number of iterations, it is possible to convert the source program into one that can be processed at high speed by a computer.
[0042] Each function (each process) in the above-described embodiments can be realized by a computer having a processor such as a CPU, a memory, etc. For example, a program for implementing the method (process) in the above-described embodiments may be stored in a storage device (storage medium), and each function may be realized by executing the program stored in the storage device with a CPU.
[0043] 9 is a block diagram showing an example of a computer having a CPU. The computer is implemented in a compiling device 100. The CPU 1000 executes processing in accordance with a program (software element: code) stored in a storage device 1001, thereby realizing the functions of the above-described embodiment. That is, it realizes the functions of the syntax analysis unit 10, optimization unit 30, and code generation unit 50 in the compiling device 100 shown in FIG.
[0044] The storage device 1001 is, for example, a non-transitory computer readable medium. Non-transitory computer readable media include various types of tangible storage media. Specific examples of non-transitory computer readable media include magnetic recording media (e.g., hard disks), magneto-optical recording media (e.g., magneto-optical disks), CD-ROMs (Compact Disc-Read Only Memory), CD-Rs (Compact Disc-Recordable), CD-R / Ws (Compact Disc-ReWritable), and semiconductor memories (e.g., mask ROMs, PROMs (Programmable ROMs), EPROMs (Erasable PROMs), and flash ROMs).
[0045] The program may also be stored in various types of transitory computer-readable media, to which the program is supplied, for example, via a wired or wireless communication path, i.e., via an electrical signal, an optical signal, or an electromagnetic wave.
[0046] The memory 1002 is realized by, for example, RAM (Random Access Memory), and is a storage means for temporarily storing data when the CPU 1000 executes processing. A configuration is also conceivable in which a program stored in the storage device 1001 or a temporary computer-readable medium is transferred to the memory 1002, and the CPU 1000 executes processing based on the program in the memory 1002. The first intermediate language storage unit 20 and the second intermediate language storage unit 40 can be realized by the memory 1002.
[0047] 10 is a block diagram showing the main parts of a compiling device 300. The compiling device 300 shown in Fig. 10 includes a loop unrolling means 301 (implemented by the outer loop unrolling processing unit 32 in the embodiment) that performs loop unrolling of an outer loop in a multiple loop in a source program, and a packed vectorization means 302 (implemented by the packed vectorization processing unit 33 in the embodiment) that converts instructions in the loop into packed vector instructions after loop unrolling has been performed.
[0048] The compiling device 300 may include adjacent access determination means (implemented by the loop analysis unit 31 in the embodiment) that determines whether or not an access to data allocated to an adjacent area in memory (e.g., main memory) is included in an outer loop, and the loop unrolling means 301 may be configured to perform loop unrolling when an access to data allocated to an adjacent area in memory is included in the outer loop.
[0049] Although the present invention has been described above with reference to the embodiments, the present invention is not limited to the above-described embodiments. Various modifications that can be understood by those skilled in the art can be made to the configuration and details of the present invention within the scope of the present invention.
[0050] This application claims priority based on Japanese Patent Application No. 2023-046153, filed on March 23, 2023, the disclosure of which is incorporated herein in its entirety.
[0051] 10 Syntax analysis unit 20 First intermediate language storage unit 30 Optimization unit 31 Loop analysis unit 32 Outer loop unrolling unit 33 Packed vectorization processing unit 40 Second intermediate language storage unit 50 Code generation unit 100 Compiler 200 Vector computer 210 Arithmetic unit 220 Main memory 230 Vector register 300 Compiler 301 Loop unrolling means 302 Packed vectorization means 1000 CPU 1001 Storage device 1002 Memory
Claims
1. A compiling device comprising: a loop unrolling means for performing loop unrolling of an outer loop in multiple loops in a source program; and a packed vectorization means for converting instructions in the loop into packed vector instructions after the loop unrolling is performed.
2. The compiling device according to claim 1, further comprising adjacent access determination means for determining whether or not access to data allocated to adjacent areas in memory is included in an outer loop, and said loop unrolling means performs said loop unrolling when access to data allocated to adjacent areas in memory is included in the outer loop.
3. The compiling device according to claim 1 or 2, wherein the multiple loops are double loops.
4. The compiling device according to claim 1 or 2, wherein the loop unrolling means performs two-stage loop unrolling.
5. A compiling method comprising the steps of: performing loop unrolling of an outer loop in multiple loops in a source program; and converting instructions in the loop into packed vector instructions after the loop unrolling is performed.
6. The compiling method according to claim 5, further comprising: determining whether or not an access to data allocated to adjacent areas in memory is included in an outer loop; and performing said loop unrolling if an access to data allocated to adjacent areas in memory is included in the outer loop.
7. A computer-readable recording medium having recorded thereon a compilation program that causes a computer to execute the following processes: a process of performing loop unrolling of an outer loop in multiple loops in a source program; and a process of converting instructions in the loop into packed vector instructions after the loop unrolling has been performed.
8. The computer-readable recording medium according to claim 7, wherein the compilation program causes a computer to determine whether or not an access to data allocated to adjacent areas in memory is included in an outer loop, and performs the loop unrolling if an access to data allocated to adjacent areas in memory is included in the outer loop.
Citation Information
Patent Citations
Code generation method, compiler and computer
JP2014137657A
Compiler program, compilation method, and information processing device
JP2021196637A
Methods and apparatus to perform automatic compiler optimization to enable streaming-store generation for unaligned contiguous write access
US20220012028A1
Zero-copy sparse matrix factorization synthesis for heterogeneous compute systems
US20230024035A1
