Nested loop conversion device, information processing method, and information processing program

The multiple loop conversion device addresses the issue of discontinuous memory access in vector computers by generating a mask to ensure continuous access, combining loops, and truncating operations, thereby enhancing processing efficiency and preventing performance deterioration.

WO2024181090A1PCT designated stage expired Publication Date: 2024-09-06NEC CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
PCT/JP2024/004483
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-27
Filing Date
2024-02-09
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

Existing loop unification techniques in vector computers often convert continuous memory access to discontinuous access, leading to increased memory access delays and decreased throughput, as the original area size of the variable accessed within a loop differs from the number of iterations, preventing efficient vector operation efficiency.

Method used

A multiple loop conversion device that generates a mask to represent operation truncation and combines outer and inner loops into a single loop, ensuring continuous memory access by expanding the inner loop and adding code to truncate operations based on the mask, thereby maintaining efficient memory access.

Benefits of technology

Prevents conversion to discontinuous memory access, maintaining continuous access and improving computer processing performance by allowing efficient vector operations while managing overhead within a predetermined range.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure JP2024004483_06092024_PF_FP
    Figure JP2024004483_06092024_PF_FP
Patent Text Reader

Abstract

In order to prevent discontinuous memory access when converting a nested loop in a program into a single loop, a nested loop conversion device 10 comprises: a mask generation means 11 that generates a mask representing the execution of processing for truncating calculations; and a loop structure conversion means 12 that performs unification to combine the outer and inner loops of a nested loop into a single loop, and, on the basis of the mask, creates a code representing the execution of the processing for truncating the calculation and adds the code to the source code.
Need to check novelty before this filing date? Find Prior Art

Description

Multiple loop conversion device, information processing method, and information processing program

[0001] The present invention relates to a multiple loop transformation device for transforming multiple loops in a program into a single loop, an information processing method, and an information processing program.

[0002] In order to improve the execution time of a computer such as a vector computer, there is a loop collapse technique that converts multiple loops in a program into a single loop (see, for example, Patent Document 1).

[0003] By converting a multiple loop into a single loop, the overhead caused by repetition is reduced. For example, in a vector computer that uses vector operation instructions, the vector length increases, improving the efficiency of vector operations.

[0004] JP-A No. 06-004300 JP-A No. 11-242598

[0005] In vector operations, the efficiency of loading the vector data to be operated on is also important. If the data is contiguous in memory, the data can be loaded with highly efficient continuous access. However, if the data is scattered in memory, the data must be loaded with slow, discontinuous access.

[0006] If the original size of the area of ​​a variable that is accessed consecutively in a loop that is the target of loop singleization differs from the number of iterations of the loop being singled, i.e., the size of the area accessed during each iteration, applying loop singleization will prevent consecutive access to data. In other words, data will inevitably be accessed discontinuously. When data is accessed discontinuously, a wide memory area will be accessed. As a result, memory access delays will increase and throughput will decrease.

[0007] In a vector computer, if the original continuous access processing is converted to discontinuous access by loop singletization, the performance improvement benefits obtained by loop singletization are reduced by the slower memory access speed. Therefore, if continuous access cannot be maintained, it may not be desirable to perform loop singletization.

[0008] In addition, Patent Document 2 describes performing vector operations with mask data in order to improve the performance of a vector computer. The mask described in Patent Document 2 determines a mask pattern based on a data string consisting of false values ​​(e.g., 9) or true values ​​(e.g., 1).

[0009] An object of the present invention is to provide a multiple loop conversion device, an information processing method, and an information processing program that, when converting multiple loops in a program into single loops, can avoid converting the program code into one that causes discontinuous memory accesses.

[0010] A multiple loop transformation device according to the present invention is a multiple loop transformation device that unifies multiple loops in input source code, and includes mask generation means that generates a mask indicating that processing to truncate operations will be executed, and loop structure transformation means that unifies the multiple loops by combining an outer loop and an inner loop in the multiple loops into a single loop, and that creates code indicating that processing to truncate operations will be executed based on the mask and adds the code to the source code.

[0011] The multiple loop transformation method according to the present invention is a method for unifying multiple loops in input source code, which generates a mask indicating that processing will be performed to truncate operations, unifies the multiple loops by combining the outer loop and inner loop into a single loop, and creates code indicating that processing will be performed to truncate operations based on the mask, and adds this code to the source code.

[0012] The multiple loop transformation program according to the present invention is a multiple loop transformation program for unifying multiple loops in input source code, and causes a computer to perform the following processes: generating a mask indicating that processing for truncating operations will be executed; unifying the multiple loops by combining the outer loop and inner loop in the multiple loop into a single loop; and creating code indicating that processing for truncating operations will be executed based on the mask, and adding the code to the source code.

[0013] According to the present invention, when multiple loops in a program are converted into a single loop, it is possible to avoid converting the program code into one that causes discontinuous memory accesses.

[0014] 1 is a block diagram showing an example of the configuration of an embodiment of a multiple loop transformation device. FIG. 2 is an explanatory diagram showing an example of source code to be transformed. FIG. 3 is an explanatory diagram showing an example of source code after transformation by general single loop. FIG. 4 is a schematic diagram showing memory access when using source code after transformation by general single loop. FIG. 5 is a flowchart showing the operation of the multiple loop transformation device of an embodiment. FIG. 6 is an explanatory diagram showing an example of source code after transformation by loop single loop executed by the multiple loop transformation device. FIG. 7 is a schematic diagram showing memory access when using source code after transformation by loop single loop executed by the multiple loop transformation device. FIG. 8 is a block diagram showing an example of a computer having a CPU. FIG. 9 is a block diagram showing main parts of the multiple loop transformation device.

[0015] Hereinafter, an embodiment of the present invention will be described with reference to the drawings.

[0016] 1 is a block diagram showing an example of the configuration of a multiple loop transformation device 100. The multiple loop transformation device 100 receives program code (source code) from a storage device (memory) 200 and stores the converted source code in a storage device (memory) 300. The memory 200 and the memory 300 may be the same device.

[0017] The multiple loop transformation apparatus 100 includes a detection unit 110 , an overhead determination unit 120 , a mask generation unit 130 , and a loop structure transformation unit 140 .

[0018] The detection unit 110 detects a loop structure from a series of processes described in the source code input from the memory 200 .

[0019] The overhead determining unit 120 determines whether the overhead generated when the loop structure is transformed falls within a predetermined range.

[0020] If it is determined that the overhead falls within a predetermined range, the mask generating unit 130 generates a mask based on the source code detected by the detecting unit 110 .

[0021] The loop structure transformation unit 140 performs unification by combining the outer loop and the inner loop of a multiple loop into a single loop. The loop structure transformation unit 140 outputs transformed source code generated by unrolling the innermost loop. The transformed source code is stored in, for example, the memory 300. When performing unification, the loop structure transformation unit 140 also generates code representing the execution of a process to truncate operations based on the mask generated by the mask generation unit 130. In other words, the mask represents the execution of a process to truncate operations. The process of generating code representing the execution of a process to truncate operations is sometimes referred to as mask processing.

[0022] Next, the operation of the multiple loop conversion apparatus 100 will be described.

[0023] FIG. 2 is an explanatory diagram showing an example of source code to be converted. In the example shown in FIG. 2, an array A is allocated to an area (0 to i max and 0 to j max Hereinafter, the size of this area will be referred to as the original size of the variable's area.

[0024] In Figure 2, in the inner loop (loop for j), j=j st From j=j ed It is shown that the process of adding b(i, j) to A(i, j) is executed up to the number of times indicated by i=i. st From i=i ed In the example shown in FIG. 2, the inner loop is the innermost loop. ed <j max is.

[0025] FIG. 3 is an explanatory diagram showing an example of source code after conversion by general loop singletization. In the example shown in FIG. st =1 and ist =1.

[0026] When the input source code shown in FIG. 2 is converted as shown in FIG. 3, the original size of the area (0 to j) of the variables that are continuously accessed in the loop (inner loop) that is the target of loop singleization is max ) is the number of iterations in the inner loop (i st ~i ed In other words, the size of the original area of ​​the variables accessed consecutively in the inner loop (0 to j max ) is different from the size of the area accessed in the repeated process.

[0027] Therefore, when a typical loop is made single, non-sequential access to memory occurs.

[0028] 4 is a schematic diagram showing memory access when using source code converted by general loop singletization. In FIG. 4, the upper row shows memory addresses. The lower row shows data stored at those addresses. In the lower row, the data with diagonal lines is the data that is actually accessed.

[0029] The specific operation of the multiple loop transformation device 100 will be described with reference to the flowchart in Fig. 5. Take the case of handling the source code to be transformed, as illustrated in Fig. 2, as an example. Hereinafter, loop single-threading may be simply referred to as "single-threading."

[0030] The detection unit 110 receives source code from the memory 200 (step S101), and checks whether or not an inner loop that can be unified exists in the source code (step S102).

[0031] If there is no inner loop that can be unified, the process ends (step S103).If there is an inner loop that can be unified, the process proceeds to step S104.

[0032] As an example, in step S103, the detection unit 110 determines that the multi-dimensional array can be reduced to a single array if multiple loops exist and the multi-dimensional array can be regarded as a one-dimensional array.

[0033] In step S104, the overhead determination unit 120 estimates the overhead when the inner loop (in this case, the innermost loop) is made into a single loop.

[0034] If the overhead determining unit 120 determines that the overhead is within a predetermined range, the process proceeds to step S106 (step S105). If the overhead determining unit 120 determines that the overhead exceeds the predetermined range, the process ends.

[0035] Overhead is a load incidental to the unification of a computer, which leads to a decrease in the processing speed of the computer. In other words, overhead is, for example, an increase in load due to the unification of a computer that executes source code converted by the multiple loop transformation device 100. As an example, consider a case where loop processing is vectorized to enable the application of vector instructions. The number of data items that can be processed by one vector instruction is limited to the maximum value of the vector computer used. Furthermore, in a vector computer, a vector instruction loads data from memory, performs an operation, and stores the data in memory in a batch for the length of the vector.

[0036] Note that the overhead is not limited to that based on the increase in vector instructions, and may include, for example, a process of truncating operations based on a mask.

[0037] If the number of iterations in the inner loop of the source code to be converted (i.e., the vector length) exceeds the number of data items that can be processed by one vector instruction, multiple vector instructions will be executed. As the vector length becomes larger, many vector instructions will be executed.

[0038] If the processing time required to execute source code without single-threading is shorter than the processing time required to execute a large number of vector instructions, single-threading may actually increase the processing time. In other words, processing efficiency may decrease. In other words, overhead occurs due to single-threading.

[0039] In an example where a vector instruction is used, the overhead determination unit 120 can estimate the overhead from the number of data items (i.e., the maximum value) that can be processed by the vector instruction on the vector computer being used and the vector length (i.e., the number of iterations in the loop).

[0040] The "predetermined range" used in the processing of step S105 corresponds to, for example, the allowable range of increase in processing speed resulting from the single-redundancy system. The predetermined range (in this example, the allowable range of increase) may be 0, but in this embodiment, the effect of being able to maintain continuous memory access when the single-redundancy system is implemented is expected. Therefore, the predetermined range is set to a value with a certain amount of leeway. In other words, continuous memory accessibility is maintained by allowing a certain amount of overhead.

[0041] In step S106, the mask generation unit 130 generates a mask. As will be described later, in this embodiment, in order to maintain continuous memory access, in addition to the data originally used for the operation, other data in a memory area corresponding to the size of the original area of ​​the variable is also subject to the operation. The operation results for the other data are unnecessary results. Therefore, it is necessary to prevent the operation results from being output (for example, stored in memory). A mask is used to prevent unnecessary operation results from being output, i.e., to truncate the operation results.

[0042] The loop structure transformation unit 140 unrolls the inner loop in the loop structure (step S107). In step S107, the loop structure transformation unit 140 further adds a code for discarding operations to the source code.

[0043] The loop structure conversion unit 140 outputs the converted source code, which is singled and to which a code indicating that a process for discarding the operation is executed is added (step S108).

[0044] The processes executed by the mask generation unit 130 and the loop structure conversion unit 140 will be described in more detail with reference to FIGS.

[0045] Fig. 6 is an explanatory diagram showing an example of source code generated by the loop structure transformation unit 140. Fig. 7 is a schematic diagram showing memory access when the source code generated by the loop structure transformation unit 140 is used.

[0046] In the example shown in FIG. 6, "A(i, j) = (i st <= i <= i ed && j st <= j <= j ed ) ? A(i, j)+b(i, j): A(i, j)" in "A(i, j) = (i st <= i <= i ed && j st <= j <= j ed )" corresponds to the mask generated by the mask generation unit 130. max *j max The calculation "A(i, j)+b(i, j)" is performed within the range of "i st <= i <= i ed " and "j st <= j <= j ed It is shown that the calculation result of "A(i, j)+b(i, j)" for data outside the range of " should be rejected.

[0047] 7, the upper row indicates a memory address, the lower row indicates the data stored at that address, and the data with diagonal lines in the lower row is the data that is actually accessed.

[0048] In the example shown in FIG. 7, each loop (i=i st , i=i st +1, i=i st +2, ...), the data referenced for the operation (j=j st ~j=j ed ), data in the sleeve area of ​​the memory area corresponding to the size of the original area of ​​the variable is added as data to be calculated. Note that in the example shown in Figure 7, it is assumed that the data referenced for calculation in each loop are adjacent with the sleeve area in between.

[0049] In the example shown in FIG. 7, data (variables) in an area corresponding to the size of the original area of ​​the variable are accessed, so that discontinuous access to data is prevented.

[0050] As described above, in this embodiment, the original continuous access process can be prevented from being converted into discontinuous access when multiple loops are unified. In other words, the degradation of computer processing performance caused by unification can be prevented.

[0051] In this embodiment, if the overhead determination unit 120 determines that the overhead falls within a predetermined range, the unification with masking processing (the processing of steps S106 to S108) is performed. However, the mask generation unit 130 and the loop structure conversion unit 140 may perform the unification with masking processing in response to a user instruction.

[0052] As an example, when the multiple loop transformation apparatus 100 is incorporated into a compiler, the user can be configured to give an execution instruction to the compiler.

[0053] Furthermore, the multiple loop transformation device 100 can be applied to a compiler having a function of optimizing (including vectorization) source code to be input to a vector computer.

[0054] Furthermore, in this embodiment, a double loop is used as an example of a multiple loop, but the multiple loop conversion device 100 can also perform single conversion with mask processing on the innermost loop of multiple loops other than a double loop.

[0055] Each component in each of the above embodiments can be configured as a single piece of hardware, or as a single piece of software. Each component can also be configured as multiple pieces of hardware, or as multiple pieces of software. Furthermore, some of the components can be configured as hardware, and the other parts can be configured as software.

[0056] Each function (each process) in the above-described embodiments can be realized by a computer having a processor such as a CPU (Central Processing Unit), 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 having the CPU execute the program stored in the storage device.

[0057] 8 is a block diagram showing an example of a computer having a CPU. The computer is implemented in the multiple loop transformation device 100. The CPU 1000 executes processing in accordance with a program (software element: code) stored in the storage device 1001, thereby realizing the functions of the above-described embodiment. That is, it realizes the functions of the detection unit 110, overhead determination unit 120, mask generation unit 130, and loop structure transformation unit 140 in the multiple loop transformation device 100 shown in FIG. 1.

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

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

[0060] The memory 1002 is realized by, for example, a 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 held 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.

[0061] 9 is a block diagram showing the main components of a multiple loop transformation device 10. The multiple loop transformation device 10 shown in Fig. 9 includes a mask generation means 11 that generates a mask indicating that a process for truncating operations is to be executed, and a loop structure transformation means 12 that unifies the multiple loops by combining the outer loop and the inner loop into a single loop, and creates code indicating that a process for truncating operations is to be executed based on the mask, and adds the code to the source code.

[0062] The multiple loop transformation device 10 may be configured to transform input source code into source code that operates on data in an area (an area equivalent to the original size of the variable) that is larger than the memory area referenced in the operation in the inner loop. Such a configuration can prevent the original continuous access process from being converted to discontinuous access due to the unification.

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

[0064] This application claims priority based on Japanese Patent Application No. 2023-028152, filed on February 27, 2023, the entire disclosure of which is incorporated herein by reference.

[0065] REFERENCE SIGNS LIST 10 Multiple loop transformation device 11 Mask generation means 12 Loop structure transformation means 100 Multiple loop transformation device 110 Detection unit 120 Overhead determination unit 130 Mask generation unit 140 Loop structure transformation unit 1000 CPU 1001 Storage device 1002 Memory

Claims

1. A multiple loop transformation device that consolidates multiple loops in input source code, comprising: a mask generation means that generates a mask indicating that a process for truncating operations will be executed; and a loop structure transformation means that consolidates an outer loop and an inner loop in the multiple loops into a single loop, and creates code indicating that a process for truncating operations will be executed based on the mask, and adds the code to the source code.

2. The multiple loop transformation device according to claim 1, wherein the loop structure transformation means transforms the input source code into source code that operates on data in an area allocated to the variable to be operated on that is larger than the memory area referenced by the operation in the inner loop.

3. A multiple loop transformation device as claimed in claim 1 or claim 2, further comprising an overhead determination means for estimating overhead based on source code after unification has been performed, and when it is determined that the overhead falls within a predetermined range, the mask generation means generates a mask and the loop structure transformation means performs unification.

4. The multiple loop transformation device according to claim 3, wherein the overhead is an increase in load due to an increase in vector instructions in a vector computer that executes the source code.

5. The multiple loop transformation device according to claim 1 or 2, wherein said mask generation means generates a mask and said loop structure transformation means performs single loop transformation when an execution instruction is given from a user.

6. A multiple loop transformation method for consolidating multiple loops in input source code, comprising the steps of: generating a mask indicating that a process for truncating operations will be executed; unifying the multiple loops by combining an outer loop and an inner loop in the multiple loops into a single loop; and creating code indicating that a process for truncating operations will be executed based on the mask; and adding the code to the source code.

7. A computer-readable recording medium having recorded thereon a multiple loop conversion program for consolidating multiple loops in input source code, the multiple loop conversion program causing a computer to execute the following processes: generating a mask indicating that a process for truncating operations is to be executed; and consolidating an outer loop and an inner loop in the multiple loops into a single loop, and creating code indicating that a process for truncating operations is to be executed based on the mask, and adding the code to the source code.

Citation Information

Patent Citations

  • Program optimization method, program optimization program and program optimization apparatus

    JP2016040691A

  • Information processing device, conversion program, and conversion method

    JP2017211695A