Cache setting program, cache setting method, and information processing device
The cache configuration program dynamically adjusts cache memory allocation based on parameter variables, addressing inefficiencies in conventional static methods by improving cache hit rates and reducing misses.
Patent Information
- Application Number
- JP2023051260
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Conventional cache control methods statically determine cache memory usage without considering dynamic changes in data reference patterns based on parameter variables, leading to inefficient cache utilization.
A cache configuration program that dynamically adjusts cache memory allocation based on the value of parameter variables by detecting parameter-dependent data variables, generating status information for different cache control conditions, and executing appropriate control methods during program execution.
Enhances cache memory efficiency by dynamically adapting to changing data reference patterns, improving cache hit rates and reducing cache misses.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to a cache setting program, a cache setting method, and an information processing device. [Background technology]
[0002] Many computers have a cache memory that is faster and has a smaller capacity than the main memory. In the case of a cache hit, where data requested by a processor is in the cache memory, the data is read from the cache memory instead of the main memory. On the other hand, in the case of a cache miss, where the requested data is not in the cache memory, the data is loaded from the main memory to the cache memory. At this time, if the free space in the cache memory is insufficient, some other data is deleted from the cache memory.
[0003] Due to the above characteristics, when executing a program that references various data with different reference frequencies, the computer may repeatedly load and delete frequently referenced data from the cache memory, which may reduce the cache hit rate. Therefore, the computer may perform cache control to reserve a portion of the memory area in the cache memory for a portion of the data in response to instructions from the program. The cache hit rate may be improved by allocating frequently referenced data to a specific memory area. This type of cache control mechanism is sometimes called a sector cache.
[0004] A way-fixing method has been proposed in which data is grouped and one data group is assigned to one way in an n-way set-associative cache memory.A compiler has also been proposed that analyzes the access status of variables and arrays written in source code, determines whether cache memory is to be used and the memory area to be used, and generates object code that changes the cache memory settings according to the determination.
[0005] A method has also been proposed for optimizing the data arrangement in a cache memory by counting the number of accesses to each of a plurality of field variables through static analysis and arranging the plurality of field variables based on the number of accesses.A hybrid cache has also been proposed, which includes an array cache area that stores data that is not replaced and a replaceable area that stores data that appears less frequently than the array cache area. [Prior art documents] [Patent documents]
[0006] [Patent Document 1] JP 2009-98933 A [Patent Document 2] JP 2011-170439 A [Patent Document 3] U.S. Patent No. 9,092,558 [Patent Document 4] US Patent Application Publication No. 2017 / 0161193 Summary of the Invention [Problem to be solved by the invention]
[0007] As described above, a computer may divide the memory area of a cache memory in response to an instruction from a program. In the conventional cache control technology, the method of using the cache memory is statically determined before the program is executed.
[0008] However, depending on the program, the reference status of each data may change depending on the value of the parameter variable at the time of execution. Therefore, the cache memory may not be used efficiently in a statically determined usage method. Therefore, in one aspect, the present invention aims to enable dynamic cache control according to the value of the parameter variable. [Means for solving the problem]
[0009] In one aspect, a cache setting program is provided that causes a computer to execute the following processes: Detecting a parameter variable and one or more data variables whose reference count depends on the value of the parameter variable from a first program; Generating status information that associates a plurality of different conditions for the value of the parameter variable with a plurality of different control methods for cache control that divides a portion of a memory area from within a cache memory for a specific data variable based on a relationship between the value of the parameter variable and the reference count of each of the one or more data variables; Adding to the first program a second program that determines which of the plurality of conditions the value of the parameter variable at execution corresponds to, and executes the control method of the plurality of control methods that corresponds to the corresponding condition.
[0010] According to another aspect, there is provided a cache setting method executed by a computer, and an information processing device having a storage unit and a processing unit. Effect of the Invention
[0011] On the one hand, it allows dynamic cache control depending on the values of parameter variables. [Brief description of the drawings]
[0012] [Figure 1] FIG. 1 is a diagram illustrating an information processing device according to a first embodiment. [Diagram 2] FIG. 11 illustrates an example of hardware of an information processing apparatus according to a second embodiment. [Diagram 3] FIG. 2 is a block diagram showing an example of the structure of a CPU. [Figure 4] 13 is a diagram illustrating an example of inserting a sector use instruction into a source code. FIG. [Diagram 5] 13A and 13B are diagrams illustrating examples of sector usage commands that dynamically control a sector cache. [Figure 6] FIG. 13 is a diagram illustrating an example of a flow of using a sector cache. [Figure 7] FIG. 13 is a diagram illustrating an example of generating SCoP text from source code. [Figure 8] FIG. 13 is a diagram illustrating an example of a table generated by source code conversion. [Figure 9] This is a diagram (continued 1) showing an example of a table generated by source code conversion. [Figure 10] This is a diagram (continued 2) showing an example of a table generated by source code conversion. [Figure 11] FIG. 13 is a diagram illustrating an example of a source code after conversion. [Figure 12] FIG. 2 is a block diagram showing an example of functions of the information processing device; [Figure 13] 13 is a flowchart illustrating an example of a procedure for source code conversion. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0013] The present embodiment will be described below with reference to the drawings. [First embodiment] A first embodiment will be described.
[0014] FIG. 1 is a diagram illustrating an information processing apparatus according to a first embodiment. The information processing device 10 of the first embodiment analyzes the program 13, generates a program 19 that instructs how to use the cache memory, and adds the program 19 to the program 13. The information processing device 10 may be a client device or a server device. The information processing device 10 may be called a computer or a cache setting device.
[0015] The information processing device 10 includes a storage unit 11 and a processing unit 12. The storage unit 11 may be a volatile semiconductor memory such as a random access memory (RAM), or may be a non-volatile storage such as a hard disk drive (HDD) or a flash memory.
[0016] The processing unit 12 is, for example, a processor such as a central processing unit (CPU), a graphics processing unit (GPU), or a digital signal processor (DSP). However, the processing unit 12 may include an electronic circuit such as an application specific integrated circuit (ASIC) or a field programmable gate array (FPGA). The processor executes a program stored in a memory such as a RAM (which may be the storage unit 11). A collection of processors may be called a multiprocessor or simply a "processor."
[0017] The storage unit 11 stores a program 13. The storage unit 11 also stores situation information 16 generated by a method described later. The storage unit 11 also stores a program 19 generated from the program 13 by a method described later.
[0018] The programs 13 and 19 may be source code written in a high-level programming language such as C. The programs 13 and 19 may also be intermediate code generated by a compiler from source code, assembly code written in assembly language, or object code written in machine language. The generation of the programs 19, which will be described later, may be executed in a preprocessor that precedes the compiler. The generation of the programs 19, which will be described later, may also be executed in the compiler.
[0019] The processing unit 12 detects, from the program 13, a parameter variable 14 and one or more data variables whose number of references depends on the value of the parameter variable 14 (hereinafter, one or more data variables may be referred to as "one or more data variables"). In the example of FIG. 1, data variables 15a and 15b are detected from the program 13. The parameter variable 14 is, for example, a numerical variable whose value is determined at run time and therefore cannot be determined by static analysis. The parameter variable 14 may be a control variable that controls the number of iterations of a loop. The data variables 15a and 15b may be array variables and may be included in the loop.
[0020] The processing unit 12 generates the status information 16 based on the relationship between the value of the parameter variable 14 and the number of times each of the one or more data variables is referenced. For example, the number of times each of the data variables 15a, 15b is referenced is expressed by an equation including the parameter variable 14.
[0021] The status information 16 associates different conditions related to the value of the parameter variable 14 with different control methods related to cache control. The cache control divides a part of the memory area from the cache memory at run time for a specific data variable. Such a cache control mechanism may be called a sector cache, and the divided memory area may be called a sector. The number of divisions may be two. In the example of FIG. 1, the status information 16 associates the condition 17a with the control method 18a, the condition 17b with the control method 18b, and the condition 17c with the control method 18c.
[0022] A control method may include allocating at least one data variable to a portion of a memory area. In that case, for example, the portion of the memory area stores only data of the allocated data variable, and does not store data of other data variables. A control method may also specify a size of the portion of the memory area to be divided. The size may be specified by the number of ways. A condition may also indicate a range of the parameter variable 14 for which an index value related to the number of references exceeds a threshold value for at least one data variable. A control method may also indicate that the cache memory is not divided.
[0023] As an example, condition 17a specifies that the value of parameter variable 14 is 2000 or more. Control method 18a secures a memory area with 8 ways from the cache memory, and assigns data variables 15a and 15b to the memory area. Condition 17b specifies that the value of parameter variable 14 is 1000 or more and less than 2000. Control method 18b secures a memory area with 4 ways from the cache memory, and assigns data variable 15a to the memory area. Condition 17c specifies that the value of parameter variable 14 is less than 1000. Control method 18c does not secure a fixed memory area.
[0024] The processing unit 12 generates a program 19 based on the situation information 16, and adds the program 19 to the program 13. The processing unit 12 may insert the program 19 at the beginning of the program 13, or at the beginning of a block where the data variables 15a and 15b are referenced. The program 19 determines which of the conditions 17a, 17b, and 17c the value of the parameter variable 14 at the time of execution corresponds to. The program 19 executes one of the control methods 18a, 18b, and 18c that corresponds to the corresponding condition.
[0025] The processing unit 12 outputs the program 13 to which the program 19 has been added. The processing unit 12 may store the program 13 to which the program 19 has been added in a non-volatile storage, may display the program 13 on a display device, or may transmit the program 13 to another information processing device.
[0026] As described above, the information processing device 10 of the first embodiment detects, from the program 13, the parameter variable 14 and one or more data variables whose reference counts depend on the value of the parameter variable 14. The information processing device 10 generates status information 16 based on the relationship between the value of the parameter variable 14 and the reference count of each data variable. The status information 16 associates a plurality of different conditions for the value of the parameter variable 14 with a plurality of different control methods for cache control. The information processing device 10 adds a program 19 to the program 13. The program 19 determines which condition the value of the parameter variable 14 at the time of execution corresponds to, and executes the control method corresponding to the corresponding condition.
[0027] As a result, the cache memory control method is determined through analysis of the program 13, and the user does not need to explicitly describe the control method. This reduces the burden on the user who creates the program 13. Also, the cache memory control method is dynamically selected according to the value of the parameter variable 14 at the time of execution. This improves the utilization efficiency of the cache memory compared to the case where only one statically determined control method is executed. In this way, dynamic cache control according to the value of the parameter variable 14 is possible.
[0028] A control method may include allocating at least one data variable to a partial memory area divided from the cache memory, thereby improving the cache hit rate for data of the allocated data variable.
[0029] Furthermore, a certain condition may indicate that an index value based on the number of references of the data variable to be allocated exceeds a threshold value. This allows data variables with high reference frequency to be allocated to a portion of the memory area. The index value may also be the average number of references per element included in the array data indicated by the data variable. This allows the reference frequency in the cache memory to be appropriately evaluated when the data variable is an array variable.
[0030] In addition, a control method may set the number of ways of a portion of the memory area based on the data size of the data variable to be allocated. This adjusts the size of the portion of the memory area so as to improve the overall cache hit rate. In addition, a control method may set the number of ways of a portion of the memory area based on the value of parameter variable 14 at the time of execution. This dynamically adjusts the size of the portion of the memory area.
[0031] In addition, at least one of the data variables may be an array variable referenced in the loop, and the parameter variable 14 may be a control variable that controls the number of iterations of the loop, thereby improving the cache hit rate for data that is referenced frequently.
[0032] [Second embodiment] Next, a second embodiment will be described. The information processing device 100 of the second embodiment converts source code before compiling, compiles the converted source code, and executes the compiled program. However, the source code conversion, compilation, and program execution may be performed by different information processing devices. The source code of the second embodiment is, for example, source code for HPC (High Performance Computing) such as scientific and technological calculations.
[0033] The information processing device 100 may be a client device or a server device. The information processing device 100 may be called a computer, a compiling device, or a cache setting device. The information processing device 100 corresponds to the information processing device 10 of the first embodiment.
[0034] FIG. 2 illustrates an example of hardware of an information processing apparatus according to the second embodiment. The information processing device 100 has a CPU 101, a RAM 102, a HDD 103, a GPU 104, an input interface 105, a medium reader 106, and a communication interface 107, all connected via a bus. The CPU 101 corresponds to the processing unit 12 in the first embodiment. The RAM 102 or the HDD 103 corresponds to the storage unit 11 in the first embodiment.
[0035] The CPU 101 is a processor that executes instructions of a program. The CPU 101 loads the program and data stored in the HDD 103 into the RAM 102 and executes the program. The information processing device 100 may have multiple processors.
[0036] The RAM 102 is a volatile semiconductor memory that temporarily stores programs executed by the CPU 101 and data used in calculations by the CPU 101. The information processing device 100 may have a type of volatile memory other than a RAM.
[0037] The HDD 103 is a non-volatile storage that stores software programs such as an operating system (OS), middleware, and application software, and data. The information processing device 100 may have other types of non-volatile storage, such as a flash memory or a solid state drive (SSD).
[0038] The GPU 104 performs image processing in cooperation with the CPU 101, and outputs an image to a display device 111 connected to the information processing device 100. The display device 111 is, for example, a CRT (Cathode Ray Tube) display, a liquid crystal display, an organic EL (Electro Luminescence) display, or a projector. Other types of output devices, such as a printer, may be connected to the information processing device 100.
[0039] The GPU 104 may be used as a general purpose computing on graphics processing unit (GPGPU). The GPU 104 may execute a program in response to an instruction from the CPU 101. The information processing device 100 may include a volatile semiconductor memory other than the RAM 102 as a GPU memory.
[0040] The input interface 105 receives an input signal from an input device 112 connected to the information processing device 100. The input device 112 is, for example, a mouse, a touch panel, or a keyboard. A plurality of input devices may be connected to the information processing device 100.
[0041] The medium reader 106 is a reading device that reads the program and data recorded on the recording medium 113. The recording medium 113 is, for example, a magnetic disk, an optical disk, or a semiconductor memory. The magnetic disk includes a flexible disk (FD) and a HDD. The optical disk includes a compact disc (CD) and a digital versatile disc (DVD). The medium reader 106 copies the program and data read from the recording medium 113 to another recording medium such as the RAM 102 or the HDD 103. The read program may be executed by the CPU 101.
[0042] The recording medium 113 may be a portable recording medium. The recording medium 113 may be used for distributing programs and data. The recording medium 113 and the HDD 103 may be called computer-readable recording media.
[0043] The communication interface 107 communicates with other information processing devices via the network 114. The communication interface 107 may be a wired communication interface connected to a wired communication device such as a switch or a router, or a wireless communication interface connected to a wireless communication device such as a base station or an access point.
[0044] FIG. 3 is a block diagram showing an example of the structure of the CPU. The CPU includes a plurality of CPU cores such as CPU cores 121a, 121b, 121c, and 121d, a cache control unit 122, and a cache memory 123. This CPU may be the CPU 101 included in the information processing device 100, or may be a CPU included in an information processing device other than the information processing device 100.
[0045] A plurality of CPU cores share the cache memory 123. For example, 13 CPU cores share the cache memory 123. A cache control unit 122 controls loading of data from the RAM to the cache memory 123 and deletion of data from the cache memory 123. Data is loaded or deleted in response to a data request from a CPU core. The cache memory 123 stores a copy of a portion of the data in the RAM. The cache memory 123 is, for example, an L2 (Level 2) cache memory.
[0046] The cache memory 123 is a set associative cache memory. The cache memory 123 includes a plurality of lines. A line may be called a set. For example, the cache memory 123 includes 2048 lines. Any one of the plurality of lines is uniquely selected from the memory address of the data to be loaded.
[0047] Each line includes multiple blocks identified by multiple ways such as ways 123a, 123b, and 123c. For example, the cache memory 123 includes 16 ways. In this case, each line includes 16 blocks. Data requested by a CPU core is stored in any one of the free blocks in the line corresponding to the memory address of the data. If there is no free block, data is deleted from any one of the blocks according to a replacement algorithm such as LRU (Least Recently Used).
[0048] The size of each block is, for example, 256 bytes. As an example, the size of the cache memory 123 is 256 bytes×2048 lines×16 ways=8 MB. In this case, the cache memory 123 can also be considered to have 16 ways, each of which is 256 bytes×2048 lines=524288 bytes.
[0049] This CPU has a sector cache function. In response to an instruction from a program being executed by the CPU core, the cache control unit 122 divides a plurality of ways included in the cache memory 123 into sector 0 and sector 1. The number of ways in sector 1 is specified by the program. Sector 1 stores only data belonging to a specific address range specified by the program. Sector 0 stores other data. Therefore, data belonging to the specific address range is less likely to be deleted from the cache memory 123.
[0050] Next, the source code of a program that uses the sector cache will be described. FIG. 4 is a diagram showing an example of inserting a sector use instruction into a source code. The information processing device 100 compiles source code with the CPU of the information processing device 100 or a CPU of another information processing device as a target. At this time, the information processing device 100 analyzes the source code and adds an optimization directive before compiling so as to improve the execution efficiency in the target CPU. The optimization directive may be added by a preprocessor. In the second embodiment, a sector use command for using the above-mentioned sector cache is added as the optimization directive.
[0051] The source code of the second embodiment is, for example, source code for HPC (High Performance Computing). The source code for HPC has a narrower number of hot spots, which are program ranges with high execution frequency, and has a kernel loop, which is a loop that takes a particularly long time to calculate. The kernel loop may refer to large-sized array data. Therefore, the information processing device 100 analyzes the kernel loop included in the source code and improves the execution efficiency of the kernel loop by utilizing a sector cache.
[0052] Source code 141 is source code that does not include a sector-using instruction. Source code 142 is source code that includes a sector-using instruction. For example, before compilation, source code 141 is converted into source code 142.
[0053] Source code 141 includes parameters M and N whose values are determined at run time. Source code 141 also includes arrays A and B. Array A is a one-dimensional array with a size of N. Array B is a two-dimensional array with a size of N×M. Source code 141 also includes double loops. The outer loop is repeated M times. The inner loop is repeated N times.
[0054] Statement S1 is executed in the outer loop but outside the inner loop. Statement S1 is an assignment statement that initializes element A[0]. Statement S2 is executed in the inner loop. Statement S2 is an assignment statement that updates element A[j] based on elements A[j] and B[j][i]. i is the loop variable of the outer loop, and j is the loop variable of the inner loop. Therefore, the number of times arrays A and B are referenced depends on parameters M and N.
[0055] Source code 142 corresponds to source code 141 with sector use instructions added before and after it. Here, it is assumed that array A is referenced many times and that it is desired to reduce cache misses for array A. Source code 142 instructs to set sector 1 with the number of ways of 14 and to allocate array A to sector 1 immediately before the execution of the double loop. Source code 142 also instructs to deallocate sector 1 immediately after the execution of the double loop.
[0056] As a result, elements of array A are stored in sector 1, and other data such as elements of array B are stored in sector 0. This prevents elements of array A from being evicted from the cache memory due to references to array B, reducing cache misses for array A.
[0057] However, as mentioned above, the number of references to arrays A and B depends on parameters M and N, whose values are determined at run time. For this reason, a fixed sector usage instruction does not necessarily improve the execution efficiency of a program. If the number of ways in sector 1 or the arrays assigned to sector 1 are inappropriate, the size of sector 1 may be too large or too small, which may result in a significant increase in cache misses on sector 0 or sector 1.
[0058] Moreover, it is a heavy burden on the user to have to consider cache usage methods such as whether to use a sector cache, the number of ways in sector 1, and the array to be allocated to sector 1. Therefore, the information processing device 100 of the second embodiment classifies cache usage methods according to parameter values, and generates a sector use instruction so that an appropriate cache usage method is automatically selected according to the parameter values at the time of execution.
[0059] FIG. 5 is a diagram showing an example of a sector usage command for dynamically controlling the sector cache. Source code 143 is an example of source code including a sector use instruction. Before compilation, source code 141 is converted into source code 143. Source code 143 corresponds to source code 141 with sector use instructions added before and after it.
[0060] Immediately before executing the double loop, source code 143 determines whether the values of parameters M and N satisfy a certain condition. If the certain condition is satisfied, source code 143 determines the number of ways, with 16 as the upper limit, depending on the size of array A. Then, source code 143 sets sector 1 with the determined number of ways, and instructs to allocate array A to sector 1. Furthermore, immediately after executing the double loop, source code 143 determines whether the values of parameters M and N satisfy a certain condition. If the certain condition is satisfied, source code 143 instructs to release sector 1. If the certain condition is not satisfied, the sector cache is not used.
[0061] As a result, the sector cache is used only when there are arrays that are referenced frequently. Also, only arrays that are referenced frequently are allocated to sector 1. Also, the number of ways in sector 1 is determined according to the runtime size of the arrays allocated to sector 1. Therefore, the sector cache is used efficiently and cache misses are reduced.
[0062] FIG. 6 is a diagram showing an example of a flow of using the sector cache. The information processing device 100 converts the source code 161 into a source code 162 through a source code conversion 166. The source code 162 is obtained by adding an optimization instruction command that specifies a method of using a sector cache to the source code 161. The information processing device 100 converts the source code 162 into an object code 163 through a compilation 167. The information processing device 100 executes a program 168 using the object code 163, a boundary value library 164, and a parameter value 165.
[0063] The boundary value library 164 is a library program that determines the type of CPU that executes the object code 163 and outputs a boundary value according to the type of CPU. The type of CPU is, for example, the generation number of the CPU. The boundary value is a threshold value related to the frequency of reference to the array, and is used as a condition for using sector 1.
[0064] Parameter value 165 is the run-time value of a parameter defined in source code 161. Parameter value 165 may be provided from outside object code 163, or may be calculated within object code 163. However, depending on the parameter, a single value may be statically determined during compilation 167. Program execution 168 dynamically selects a cache usage method based on boundary values output by boundary value library 164 and parameter value 165.
[0065] Next, the procedure of source code conversion 166 for generating a sector-using instruction will be described using an example of source code other than source code 141. FIG. 7 is a diagram showing an example of generating an SCoP text from a source code.
[0066] Source code 144 is source code that does not include a sector-using instruction. Source code 144 includes parameters M, N, and P whose values are determined at run time. Source code 144 also includes arrays A, B, C, and D. Array A is a one-dimensional array with a size of N. Arrays B, C, and D are two-dimensional arrays with a size of N×M. Source code 144 also includes double loops. The outer loop is repeated M times. The inner loop is repeated N times.
[0067] In the outer loop and outside the inner loop, statement S1 is executed. Statement S1 is an assignment statement that initializes element A[0]. In the inner loop, statements S2 and S3 are executed. Statement S2 is an assignment statement that updates element A[j] based on elements A[j] and B[j][i]. i is the loop variable of the outer loop and j is the loop variable of the inner loop.
[0068] Statement S3 is an assignment statement that updates element C[j / 2][i] based on element C[j / 2][i] and element D[j / P][i]. C[j / 2][i] indicates that only 1 / 2 of the N rows in array C are referenced. D[j / P][i] indicates that only 1 / P of the N rows in array D are referenced.
[0069] The information processing device 100 analyzes the source code 144 and generates a static control parts of program (SCoP) text 145. The SCoP text 145 omits specific calculation procedures such as constants and operators, and expresses variable definitions, variable references, and program control structures (such as loop structures). The SCoP text 145 indicates the definitions of parameters M, N, and P and arrays A, B, C, and D. The SCoP text 145 also indicates a double loop and variable references in statements S1, S2, and S3. The information processing device 100 may extract information equivalent to the SCoP text 145 using another method.
[0070] FIG. 8 is a diagram illustrating an example of a table generated by source code conversion. The information processing device 100 generates an execution count table 151 from the SCoP text 145. The execution count table 151 indicates the number of times each of a plurality of statements is executed. Statement S1 is included in the outer loop but not in the inner loop. Therefore, the number of times statement S1 is executed is M. Statements S2 and S3 are included in the inner loop. Therefore, the number of times statements S2 and S3 are executed is M×N.
[0071] Next, the information processing device 100 generates a reference range table 152 from the SCoP text 145. The reference range table 152 associates a reference position, an array, and a reference range. A reference position is specified by a sentence ID that identifies a sentence and an ordinal number that indicates the position of the array reference from the left in the sentence. A reference range indicates the range of elements referenced in an array.
[0072] For array A in statement S1, only element A[0] is referenced. For array A on the left side of statement S2, elements A[0] through A[N-1] are referenced. For array A on the right side of statement S2, elements A[0] through A[N-1] are referenced. For array B in statement S2, elements B[0][0] through B[N-1][M-1] are referenced.
[0073] For array C on the left side of statement S3, elements whose first subscript is an even number are referenced from among elements C[0][0] to C[N-1][M-1]. For array C on the right side of statement S3, 1 / 2 of the elements from elements C[0][0] to C[N-1][M-1] are referenced. For array D in statement S3, 1 / P of the elements from elements D[0][0] to D[N-1][M-1] are referenced.
[0074] FIG. 9 is a diagram (continued 1) showing an example of a table generated by source code conversion. Next, information processing apparatus 100 generates reference count table 153 from execution count table 151 and reference range table 152. Reference count table 153 associates the reference range and the reference count for each of a plurality of arrays.
[0075] The reference range of array A is element A[0] and element A[1] to element A[N-1]. The number of references to element A[0] is 3×M. The total number of references to elements A[1] to A[N-1] is 2×M×(N-1). The reference range of array B is element B[0][0] to element B[N-1][M-1], and the total number of references is M×N.
[0076] The reference range of array C is from element C[0][0] to element C[N-1][M-1] whose first subscript is an even number, and the total number of references is 2×M×N. The reference range of array D is from element D[0][0] to element D[N-1][M-1] whose first subscript is divisible by P, and the total number of references is M×N.
[0077] Next, the information processing device 100 generates a reference density table 154 from the reference count table 153. The reference density table 154 indicates the reference density of each of the multiple arrays. The reference density is an index indicating the degree to which the same element is repeatedly referenced. As an example, the reference density in the second embodiment is the ratio of the total reference count to the number of reference elements that are referenced one or more times, and indicates the average reference count per reference element.
[0078] The total number of references to array A is the sum of the reference count of element A[0], 3×M, and the reference count of other elements, 2×M×(N-1), or M×(2×N+1). There are N elements of array A that are referenced one or more times. Therefore, the reference density of array A is (M×(2×N+1)) / N. The total number of references to array B is M×N, and there are M×N reference elements of array B. Therefore, the reference density of array B is 1. The reference density of array C is approximately 4, as shown in formula (1). The reference density of array D is approximately P, as shown in formula (2).
[0079]
number
[0080]
number
[0081] Next, the information processing device 100 generates a use condition table 155 from the reference density table 154. The use condition table 155 indicates, for each of a plurality of arrays, a use condition for using sector 0 and a use condition for using sector 1. The use condition for sector 0 is that the reference density is less than a boundary value (BOUNDARY). The use condition for sector 1 is that the reference density is equal to or greater than the boundary value.
[0082] For array A, the usage condition for sector 0 is that (M×(2×N+1)) / N is less than the boundary value, and the usage condition for sector 1 is that (M×(2×N+1)) / N is greater than or equal to the boundary value. For arrays B and C, it is assumed that the reference density is small enough to always be less than the boundary value. Therefore, for arrays B and C, the usage condition for sector 0 is always true, and the usage condition for sector 1 is always false.
[0083] In addition, in HPC programs, the number of loop iterations often ranges from hundreds of thousands to millions, so the boundary value is sufficiently larger than the reference density of arrays B and C. For array D, the usage condition for sector 0 is that P is less than the boundary value, and the usage condition for sector 1 is that P is equal to or greater than the boundary value.
[0084] FIG. 10 is a diagram (continued 2) showing an example of a table generated by source code conversion. Next, the information processing device 100 generates a situation table 156 from the usage condition table 155. The situation table 156 indicates a plurality of situations classified according to the values of the parameters M, N, and P. The situation table 156 associates a situation ID that identifies a situation, an array that is assigned to the sector 1, and a condition of the values of the parameters M, N, and P that the situation is established.
[0085] The information processing device 100 selects arrays A and B for which the usage condition of sector 1 is likely to be true from the usage condition table 155. The information processing device 100 generates situations X1, X2, X3, and X4 by calculating the power set of arrays A and B.
[0086] Situation X1 is a situation in which the usage condition for sector 1 is true for both arrays A and D. In this case, arrays A and D are assigned to sector 1. Situation X2 is a situation in which the usage condition for sector 1 is true only for array A out of arrays A and D. In this case, array A is assigned to sector 1. Situation X3 is a situation in which the usage condition for sector 1 is true only for array D out of arrays A and D. In this case, array D is assigned to sector 1. Situation X4 is a situation in which situations X1, X2, and X3 are not true. In this case, sector 1 is not used.
[0087] Next, the information processing device 100 generates a way number table 157 from the reference count table 153 and the situation table 156. The way number table 157 indicates the number of ways allocated to sector 1 under each situation indicated by the situation table 156. In the example of Fig. 10, the size of each element of arrays A and D is 8 bytes.
[0088] For each situation, the information processing device 100 calculates the total size of the reference elements in the array allocated to sector 1. The information processing device 100 calculates the number of ways for storing all the reference elements by dividing the total size by the cache memory capacity per way. However, if the number of ways calculated here exceeds the number of ways that the cache memory has, the number of ways that the cache memory has is set as the upper limit.
[0089] FIG. 11 is a diagram illustrating an example of the source code after conversion. The information processing device 100 uses the status table 156 and the number of ways table 157 to add a sector use instruction to the source code 144. The source code 146 is the source code to which the sector use instruction has been added.
[0090] The source code 146 calls a boundary value library to obtain boundary values. The source code 146 also calculates the total size of the reference elements of array A and the total size of the reference elements of array D from the values of parameters M, N, and P at run time.
[0091] The source code 146 determines whether the condition of situation X1 is satisfied based on the obtained boundary value and the values of the parameters M, N, and P at the time of execution. If the condition of situation X1 is satisfied, the source code 146 determines the number of ways of sector 1 from the total size of the reference elements of arrays A and D, and allocates arrays A and D to sector 1.
[0092] If the condition of situation X1 is not met, source code 146 determines whether the condition of situation X2 is met. If the condition of situation X2 is met, source code 146 determines the number of ways of sector 1 from the total size of the reference elements of array A, and allocates array A to sector 1. If the condition of situation X2 is not met, source code 146 determines whether the condition of situation X3 is met. If the condition of situation X3 is met, source code 146 determines the number of ways of sector 1 from the total size of the reference elements of array D, and allocates array D to sector 1.
[0093] If the condition of situation X3 is not satisfied, source code 146 does not set the sector cache. After the double loop, source code 146 determines whether any of the conditions of situations X1, X2, or X3 is satisfied. If any of the conditions of situations X1, X2, or X3 is satisfied, source code 146 cancels the setting of the sector cache. In this way, the sector cache is dynamically set according to the values of parameters M, N, and P at the time of execution.
[0094] Next, the functions and processing procedures of the information processing device 100 will be described. FIG. 12 is a block diagram illustrating an example of functions of the information processing device. The information processing device 100 has a source code storage unit 131, an object code storage unit 132, a library storage unit 133, a source code conversion unit 134, a compiler 135, and a program execution unit 136. The source code storage unit 131, the object code storage unit 132, and the library storage unit 133 are implemented, for example, using the RAM 102 or the HDD 103. The source code conversion unit 134, the compiler 135, and the program execution unit 136 are implemented, for example, using the CPU 101 and a program.
[0095] The source code storage unit 131 stores source code created by a user. The source code is written in a certain high-level programming language such as C. The object code storage unit 132 stores compiled object code. The object code is written in the machine language of the target CPU.
[0096] The library storage unit 133 stores a boundary value library. The boundary value library is called from the object code. The boundary value library determines the type of CPU that executes the object code, and outputs boundary values according to the type of CPU.
[0097] The source code conversion unit 134 reads the source code from the source code storage unit 131 and analyzes a kernel loop included in the source code. The source code conversion unit 134 generates a sector use instruction for efficiently using the cache memory, and outputs the source code to which the sector use instruction has been added to the compiler 135.
[0098] The compiler 135 compiles the source code received from the source code conversion unit 134. The compiler 135 converts the source code into an intermediate code through lexical analysis, syntactic analysis, and semantic analysis, optimizes the intermediate code through compiler optimization, and converts the intermediate code into an object code. The compiler 135 stores the generated object code in the object code storage unit 132.
[0099] The program execution unit 136 reads the object code from the object code storage unit 132 and executes the read object code. At this time, the program execution unit 136 also uses the boundary value library stored in the library storage unit 133.
[0100] FIG. 13 is a flowchart showing an example of a procedure for converting source code. (S10) The source code conversion unit 134 generates an SCoP representation from the source code. (S11) The source code conversion unit 134 extracts a set of sequences, a set of parameters, and a set of statements from the text expressed in the SCoP format.
[0101] (S12) The source code conversion unit 134 calculates the number of executions of each statement from the text in the SCoP representation, and generates an execution count table 151. (S13) The source code conversion unit 134 calculates the array reference range for each reference position from the text in the SCoP representation, and generates the reference range table 152.
[0102] (S14) The source code conversion unit 134 calculates the number of references for each array element from the execution count table 151 and the reference range table 152, and generates the reference count table 153. (S15) The source code conversion unit 134 calculates the reference density for each array from the reference count table 153 and generates a reference density table 154.
[0103] (S16) The source code conversion unit 134 determines the sector 1 use condition for each array from the reference density table 154, and generates the use condition table 155. The sector 1 use condition is a parameter value condition for the reference density to be equal to or greater than the boundary value.
[0104] (S17) The source code conversion unit 134 identifies multiple situations by calculating a power set of sequences that may satisfy the sector 1 use conditions from the use condition table 155. The source code conversion unit 134 determines the sector 1 use sequence and parameter value conditions for each situation and generates a situation table 156.
[0105] (S18) The source code conversion unit 134 calculates the sector 1 size for each situation from the reference count table 153 and the situation table 156, and generates the way number table 157. The sector 1 size is calculated from the total size of the sector 1 usage array. The sector 1 size may be expressed by an equation including a parameter variable.
[0106] (S19) The source code conversion unit 134 generates a sector use instruction that performs a conditional branch according to a parameter value at the time of execution from the status table 156 and the number of ways table 157. The source code conversion unit 134 inserts the sector use instruction into the source code and outputs it. The source code conversion unit 134 may store the converted source code in a non-volatile storage, may display it on the display device 111, or may transmit it to another information processing device.
[0107] As described above, the information processing device 100 of the second embodiment analyzes the source code and adds an optimization directive command for using the sector cache to the source code. This reduces the burden on the user compared to the case where the user writes the optimization directive command manually. In addition, the information processing device 100 automatically adjusts whether or not the sector cache is used, the array allocated to sector 1, and the number of ways of sector 1. This allows the cache memory to be used efficiently and reduces cache misses.
[0108] In addition, the information processing device 100 generates an optimization directive command so that a sector cache usage method is automatically selected according to the value of a parameter variable at the time of execution. This allows the cache memory to be used efficiently under various parameter values, compared to the case where only one statically determined sector cache usage method is executed.
[0109] Furthermore, the information processing device 100 generates an optimization instruction command to select a sector cache usage method using a boundary value according to the type of CPU that executes the program. This allows the cache memory to be used efficiently under various CPUs. Furthermore, the information processing device 100 assigns an array whose reference density is equal to or greater than the boundary value to sector 1. This reduces cache misses for array elements that are referenced frequently. [Explanation of symbols]
[0110] 10. Information processing device 11 Storage section 12 Processing section 13,19 Program 14 Parameter Variables 15a,15b Data variables 16 Status Information 17a,17b,17c conditions 18a, 18b, 18c Control Method
Claims
1. Detecting from a first program a parameter variable and one or more data variables whose reference counts depend on the value of the parameter variable; generating status information that associates a plurality of different conditions for the value of the parameter variable with a plurality of different control methods for cache control that divides a portion of a memory area from a cache memory for a specific data variable based on a relationship between the value of the parameter variable and the number of references for each of the one or more data variables; adding a second program to the first program, the second program determining which of the plurality of conditions the value of the parameter variable at the time of execution corresponds to, and executing a control method of the plurality of control methods corresponding to the corresponding condition; A cache configuration program that causes a computer to carry out the process.
2. At least one control method of the plurality of control methods includes allocating at least one data variable of the one or more data variables to the portion of memory area.
2. The cache setting program according to claim 1.
3. a condition corresponding to the at least one control method among the plurality of conditions indicates that an index value based on the number of references of the at least one data variable exceeds a threshold value; 3. The cache setting program according to claim 2.
4. the one or more data variables are array variables, and the index value is an average number of references per element included in the array data indicated by the array variable; 4. The cache setting program according to claim 3.
5. the at least one control method includes setting a number of ways of the partial memory area based on a data size of the at least one data variable; 3. The cache setting program according to claim 2.
6. At least one of the control methods includes setting a number of ways of the partial memory area based on a value of the parameter variable at a time of execution.
2. The cache setting program according to claim 1.
7. The one or more data variables are array variables referenced in a loop, and the parameter variable is a variable that controls the number of iterations of the loop.
2. The cache setting program according to claim 1.
8. Detecting from a first program a parameter variable and one or more data variables whose reference counts depend on the value of the parameter variable; generating status information that associates a plurality of different conditions for the value of the parameter variable with a plurality of different control methods for cache control that divides a portion of a memory area from a cache memory for a specific data variable based on a relationship between the value of the parameter variable and the number of references for each of the one or more data variables; adding a second program to the first program, the second program determining which of the plurality of conditions the value of the parameter variable at the time of execution corresponds to, and executing a control method of the plurality of control methods corresponding to the corresponding condition; A cache configuration method for computer-implemented processing.
9. a storage unit that stores a first program including a parameter variable and one or more data variables whose number of references depends on the value of the parameter variable; a processing unit that generates status information that associates a plurality of different conditions for the value of the parameter variable with a plurality of different control methods for cache control that divides a portion of a memory area from a cache memory for a specific data variable based on a relationship between the value of the parameter variable and the number of references of each of the one or more data variables, determines which of the plurality of conditions the value of the parameter variable at the time of execution corresponds to, and adds a second program to the first program, the second program executing a control method of the plurality of control methods that corresponds to the corresponding condition; An information processing device having the above configuration.
Citation Information
Patent Citations
Method of fixing registration destination way, processor and information processing device
JP2009098933A
Compiler, compile method, and compile execution program
JP2011170439A
Hybrid cache
US20170161193A1
Grouping frequently referenced data items to co-locate for cache utilization
US9092558B2
