JP2011197876A - Program, apparatus and method for optimization processing - Google Patents
Program, apparatus and method for optimization processing Download PDFInfo
- Publication number
- JP2011197876A JP2011197876A JP2010062312A JP2010062312A JP2011197876A JP 2011197876 A JP2011197876 A JP 2011197876A JP 2010062312 A JP2010062312 A JP 2010062312A JP 2010062312 A JP2010062312 A JP 2010062312A JP 2011197876 A JP2011197876 A JP 2011197876A
- Authority
- JP
- Japan
- Prior art keywords
- loop
- blocking
- array
- optimization
- calculation formula
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
Description
本発明は,プログラミング言語で記述されたソースプログラムに含まれるループの最適化を行う最適化処理プログラム,最適化処理装置および最適化処理方法に関するものである。 The present invention relates to an optimization processing program, an optimization processing apparatus, and an optimization processing method for optimizing a loop included in a source program described in a programming language.
コンパイラには,キャッシュメモリをソフトウェアから有効活用するための技術として,ブロッキングと呼ばれる最適化の技術が用意されている。ブロッキングは,ソースプログラム中に存在する多重ループの処理構造に対して,その最内ループ内で使用する配列に対するメモリアクセスがキャッシュメモリのサイズに収まるように,多重ループの回転数を分割する技術である。コンパイラがソースプログラムに対してブロッキングによる最適化を実行することにより,配列のデータが常にキャッシュメモリ上に保持されるようになり,キャッシュヒット率が向上する。 The compiler provides an optimization technique called blocking as a technique for effectively using cache memory from software. Blocking is a technology that divides the number of rotations of a multi-loop so that memory access to the array used in the innermost loop is within the size of the cache memory for the multi-loop processing structure existing in the source program. is there. When the compiler performs blocking optimization on the source program, the array data is always held in the cache memory, and the cache hit rate is improved.
なお,最適化の対象となる多重ループについて,その最内ループと最内の1つ外側のループに関してのみ最適化を行うブロッキングの技術が知られている。また,3次元以上の配列を含む多重ループについて,その最内ループに関してのみ最適化を行うブロッキングの技術が知られている。 A blocking technique is known in which optimization is performed only for the innermost loop and the innermost loop outside the multiple loop to be optimized. In addition, there is known a blocking technique that optimizes only the innermost loop of a multiple loop including a three-dimensional array or more.
上述の従来のブロッキングによる多重ループの最適化の技術には,3重以上のループに対してブロッキングを適用することができない,3次元以上の配列を含む多重ループに対してブロッキングを適用することができないという問題があった。 In the conventional technique for optimizing multiple loops by blocking, it is not possible to apply blocking to three or more loops, and it is possible to apply blocking to multiple loops including arrays of three or more dimensions. There was a problem that I could not.
近年,ハードウェア性能の向上に合わせて,より高度で複雑な科学演算が行われる傾向がある。このようなニーズに答えるためには,上記の従来技術の問題を解決する必要がある。 In recent years, there has been a tendency for more sophisticated and complex scientific operations to be performed as hardware performance improves. In order to answer such needs, it is necessary to solve the above-mentioned problems of the prior art.
本発明は,上記の問題の解決を図り,3重ループ以上のループに対して,また3次元以上の配列を含む多重ループに対して,広範囲にブロッキングによる最適化の実行を可能とする技術を提供することを目的とする。 The present invention is a technique for solving the above-described problems and enabling optimization by blocking over a wide range for loops of three or more loops and for multiple loops including arrays of three or more dimensions. The purpose is to provide.
開示するプログラムは,プログラミング言語で記述されたソースプログラムをコンパイルするコンパイラにおいて,ソースプログラムに含まれる多重ループに対するブロッキングによる最適化の処理を行うコンピュータを,次のように機能させる。 In the disclosed program, a compiler that compiles a source program written in a programming language causes a computer that performs optimization processing by blocking against multiple loops included in the source program to function as follows.
すなわち,前記プログラムは,前記プログラムがインストールされて実行されるコンピュータに,ソースプログラムに含まれる多重ループから最内ループにのみ実行文を有する構造のループをブロッキング対象ループとして抽出する手順と,ブロッキング対象ループ内に存在する配列を抽出する手順と,抽出された配列の中に添え字として出現する制御変数の順序がブロッキング対象ループの最内ループから最外ループに向かって出現する制御変数の順序と異なる配列が存在する場合に,ブロッキング対象ループに対するブロッキングが有効であると判定する手順と,ブロッキングが有効であると判定されたブロッキング対象ループについて,ブロッキング対象ループに対するブロッキングによって最適化される範囲で配列が使用するメモリサイズを算出する計算式を配列ごとに生成する手順と,配列ごとに生成された計算式からブロッキング対象ループに対するブロッキングによって最適化される範囲でブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式を生成する手順と,全配列が使用するメモリサイズを計算する計算式を用いて,ブロッキング対象ループに対するブロッキングによって最適化される範囲で配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する手順と,自動計算された分割ブロック長を用いてブロッキング対象ループに対するブロッキングによる最適化を行う手順とを実行させる。 That is, the program includes a procedure for extracting, as a blocking target loop, a loop having a structure having an executable statement only in the innermost loop from the multiple loops included in the source program on a computer on which the program is installed and executed. The procedure for extracting an array existing in a loop, and the order of control variables appearing as subscripts in the extracted array from the innermost loop of the blocking target loop to the outermost loop When there is a different sequence, the procedure for determining that blocking for the blocking target loop is effective and the blocking target loop for which blocking is determined to be effective are arranged within the range optimized by blocking for the blocking target loop. Memory used by Calculate the memory size used by all arrays in the blocking target loop within the range that is optimized by blocking for the blocking target loop from the calculation formula generated for each array Using the procedure for generating the calculation formula to be used and the calculation formula for calculating the memory size used by all arrays, the divided block length that does not cause a cache miss due to access to the array within the range optimized by blocking for the blocking loop is determined. A procedure for automatic calculation and a procedure for performing optimization by blocking the blocking target loop using the automatically calculated divided block length are executed.
上記の技術によって,3重以上のループに対して,最内ループ内に含まれる配列の次元数に影響なく,広範囲にブロッキングによる最適化を実行することが可能となる。これにより,従来はブロッキングによる最適化の実行が不可能であったループに対してもブロッキングを適用して,キャッシュメモリのヒット率が改善することで,最適化されるプログラムの実行性能が向上する。 With the above technique, it is possible to perform optimization by blocking over a wide range without affecting the number of dimensions of the array included in the innermost loop for a loop of three or more layers. This improves the execution performance of the optimized program by improving the cache memory hit rate by applying blocking to loops that could not be optimized by blocking. .
以下,本実施の形態について,図を用いて説明する。 Hereinafter, the present embodiment will be described with reference to the drawings.
まず,本実施の形態によるブロッキングの技術を説明する前に,従来のブロッキングの技術について,簡単に説明する。 First, before describing the blocking technique according to the present embodiment, a conventional blocking technique will be briefly described.
図1は,3重ループに対する従来のブロッキングの例を説明する図である。 FIG. 1 is a diagram illustrating an example of conventional blocking for a triple loop.
図1(A)は,最適化対象ループの例を示す。図1(A)に示す最適化対象ループは,ループI,ループJ,ループKの3重ループである。図1(A)に示す最適化対象ループでは,最内ループ内にのみ,2次元の配列を用いた演算の実行文が含まれている。 FIG. 1A shows an example of the optimization target loop. The optimization target loop shown in FIG. 1A is a triple loop of loop I, loop J, and loop K. In the optimization target loop shown in FIG. 1A, only the innermost loop includes an execution statement for an operation using a two-dimensional array.
なお,本実施の形態では,制御変数をループの名称に用いるものとする。具体的には,本実施の形態では,制御変数IのループをループIと呼ぶものとする。 In this embodiment, the control variable is used as the name of the loop. Specifically, in the present embodiment, the loop of the control variable I is called a loop I.
図1(B)は,図1(A)に示す最適化対象ループに対して,インデックス交換を行った結果を示す。インデックスとは,制御変数のことである。インデックス交換は,配列へのアクセスがメモリ上の連続領域へのアクセスとなるように,内側のループと外側のループとを入れ換える処理である。ブロッキングは連続領域へのメモリアクセスに対して効果が高いため,インデックス交換により連続領域へのメモリアクセスとなる場合は,事前にインデックス交換を行う必要がある。インデックス交換の詳細については,特許文献1の段落[0034]〜[0043],図3に記載されている。 FIG. 1B shows the result of index exchange for the optimization target loop shown in FIG. An index is a control variable. The index exchange is a process of exchanging the inner loop and the outer loop so that access to the array is access to a continuous area in the memory. Since blocking is highly effective for memory access to the continuous area, if the memory access to the continuous area is caused by index exchange, it is necessary to exchange the index in advance. Details of the index exchange are described in paragraphs [0034] to [0043] of FIG.
図1(C)は,図1(B)に示すインデックス交換後の最適化対象ループに対して,従来のブロッキングを行った結果を示す。従来の技術では,最内ループとその1つ外側のループとに対してのみ,すなわち図1に示す例ではループIとループJとに対してのみ,ブロッキングが行われる。図1(C)に示すブロッキング後の最適化対象ループにおいて,ループの分割単位を示す分割ブロック長blockには,コンパイラのブロッキング機能によって,適切な値が求められる。 FIG. 1 (C) shows the result of performing conventional blocking on the optimization target loop after the index exchange shown in FIG. 1 (B). In the prior art, blocking is performed only for the innermost loop and the loop that is one outer side thereof, that is, only for the loop I and the loop J in the example shown in FIG. In the optimization target loop after blocking shown in FIG. 1C, an appropriate value is obtained for the divided block length block indicating the division unit of the loop by the blocking function of the compiler.
図2は,メモリアクセスの例を示す図である。 FIG. 2 is a diagram illustrating an example of memory access.
図2に示すメモリアクセスの例は,図1(C)に示すブロッキング後の最適化対象ループにおけるメモリアクセスの例である。図2において,太線の枠は,各配列のデータが記憶されたメモリ領域を示し,細線の枠は,一辺が分割ブロック長blockである領域を示している。図2において,網掛けの領域は,図1(C)に示すブロッキング後の最適化対象ループにおいて,制御変数JJ,IIを固定して,ループI,ループJ,ループKとが回転したときの,演算の実行文に含まれる配列ごとのアクセス領域を示す。 The example of memory access shown in FIG. 2 is an example of memory access in the optimization target loop after blocking shown in FIG. In FIG. 2, a thick line frame indicates a memory area in which data of each array is stored, and a thin line frame indicates an area whose one side is a divided block length block. In FIG. 2, the shaded area is when the control variables JJ and II are fixed and the loops I, J, and K are rotated in the optimization target loop after blocking shown in FIG. , Indicates the access area for each array included in the execution statement of the operation.
図2に示すように,ブロッキングが行われたループの制御変数IとJとを添え字とする配列Aについては,メモリアクセスが局所化されているため,キャッシュメモリに効率的にデータをのせることができる。しかし,ブロッキングが行われなかったループの制御変数Kを添え字に含む配列B,配列Cについては,メモリアクセスが局所化されないため,キャッシュメモリに効率的にデータをのせることができない。 As shown in FIG. 2, since the memory access is localized for the array A having the subscripts of the control variables I and J of the loop in which blocking is performed, the data is efficiently placed in the cache memory. be able to. However, since the memory access is not localized for the arrays B and C including the control variable K of the loop that has not been blocked as a subscript, data cannot be efficiently placed in the cache memory.
このように,従来のブロッキングの技術では,3重以上のループを対象としたブロッキングができないため,キャッシュメモリに効率的にデータをのせることができる配列の範囲が,狭い範囲に限られていた。 In this way, with the conventional blocking technique, since it is not possible to block over three or more loops, the range of arrays in which data can be efficiently placed in the cache memory has been limited to a narrow range. .
図3は,3重ループのすべてに対してブロッキングを行った場合のブロッキング後の最適化対象ループの例を示す図である。 FIG. 3 is a diagram illustrating an example of an optimization target loop after blocking when blocking is performed on all triple loops.
図3に示すブロッキング後の最適化対象ループの例は,図1(B)に示すインデックス交換後の最適化対象ループにおいて,3重ループのすべてに対してブロッキングを行ったと仮定した場合の結果の例である。 The example of the optimization target loop after blocking shown in FIG. 3 is the result of assuming that blocking is performed for all of the triple loops in the optimization target loop after index exchange shown in FIG. It is an example.
例えば,実行文に含まれる配列の添え字において,各ループの制御変数の登場回数があまり変わらないような場合には,すべてのループに対してブロッキングを行うことにより,よりよいメモリ効率が得られる場合がある。 For example, if the number of occurrences of control variables in each loop does not change much in the array subscripts included in the executable statement, better memory efficiency can be obtained by blocking all loops. There is a case.
図4は,メモリアクセスの例を示す図である。 FIG. 4 is a diagram illustrating an example of memory access.
図4に示すメモリアクセスの例は,図3に示すブロッキング後の最適化対象ループにおけるメモリアクセスの例である。すなわち,図4に示すメモリアクセスの例は,図1(B)に示すインデックス交換後の最適化対象ループにおいて,3重ループのすべてに対してブロッキングを行ったと仮定した場合のブロッキング後の最適化対象ループにおけるメモリアクセスの例である。 The memory access example shown in FIG. 4 is an example of memory access in the optimization target loop after blocking shown in FIG. That is, the example of the memory access shown in FIG. 4 is an optimization after blocking when it is assumed that all the triple loops are blocked in the optimization target loop after the index exchange shown in FIG. It is an example of the memory access in an object loop.
図4において,太線の枠は,各配列のデータが記憶されたメモリ領域を示し,細線の枠は,一辺が分割ブロック長blockである領域を示している。図2において,網掛けの領域は,図3に示すブロッキング後の最適化対象ループにおいて,制御変数JJ,II,KKとを固定して,ループI,ループJ,ループKとが回転したときの,演算の実行文に含まれる配列ごとのアクセス領域を示す。 In FIG. 4, a thick line frame indicates a memory area in which data of each array is stored, and a thin line frame indicates an area whose one side is a divided block length block. In FIG. 2, the shaded area is when the control variables JJ, II, and KK are fixed and the loops I, J, and K are rotated in the optimization target loop after blocking shown in FIG. , Indicates the access area for each array included in the execution statement of the operation.
図4に示すように,3重ループのすべてに対してブロッキングを行ったと仮定すると,配列A,配列B,配列Cのすべてについて,メモリアクセスが局所化されるため,すべての配列のデータを,キャッシュメモリに効率的にのせることができる。 As shown in FIG. 4, assuming that blocking is performed for all the triple loops, memory access is localized for all of the arrays A, B, and C. The cache memory can be loaded efficiently.
図3に示すような3重以上のループを対象としたブロッキングを行うことができれば,従来のブロッキングの技術と比較して,よりメモリ効率が高いループの最適化を行うことができるようになる。 If blocking for a loop of three or more loops as shown in FIG. 3 can be performed, a loop with higher memory efficiency can be optimized as compared with the conventional blocking technique.
図5は,3次元の配列を含む多重ループに対する従来のブロッキングの例を説明する図である。 FIG. 5 is a diagram for explaining an example of conventional blocking for a multiple loop including a three-dimensional array.
図5(A)は,最適化対象ループの例を示す。図5(A)に示す最適化対象ループは,ループI,ループJ,ループKの3重ループである。図5(A)に示す最適化対象ループでは,最内ループ内にのみ,3次元の配列を含む演算の実行文が含まれている。 FIG. 5A shows an example of the optimization target loop. The optimization target loop shown in FIG. 5A is a triple loop of loop I, loop J, and loop K. In the optimization target loop shown in FIG. 5A, only the innermost loop includes an execution statement for an operation including a three-dimensional array.
図5(B)は,図5(A)に示す最適化対象ループに対して,従来のブロッキングを行った結果を示す。従来の技術では,最内ループ内で3次元以上の配列が使用されている場合に,翻訳コストの問題から,最内ループのみ,すなわち図5に示す例ではループIのみをブロッキングの対象とする。しかし,実際には,制御変数Jを更新するループJに対してもブロッキングは有効である。 FIG. 5B shows the result of conventional blocking performed on the optimization target loop shown in FIG. In the conventional technique, when an array of three or more dimensions is used in the innermost loop, only the innermost loop, that is, only the loop I in the example shown in FIG. . However, in practice, blocking is also effective for the loop J that updates the control variable J.
このように,従来のブロッキングの技術では,3次元の配列を含む多重ループに対しては,最内ループを対象としたブロッキングしかできないため,あまり効果的なループの最適化はできなかった。 As described above, with the conventional blocking technique, it is only possible to block the innermost loop with respect to a multiple loop including a three-dimensional array. Therefore, the loop cannot be optimized very effectively.
図6は,3次元の配列を含む多重ループに対して,最内ループ以外のループもブロッキングを行った場合のブロッキング後の最適化対象ループの例を示す図である。 FIG. 6 is a diagram illustrating an example of an optimization target loop after blocking when a loop other than the innermost loop is also blocked with respect to a multiple loop including a three-dimensional array.
図6に示すブロッキング後の最適化対象ループの例は,図5(A)に示す3次元の配列を含む最適化対象ループにおいて,ループIとループJとに対してブロッキングを行ったと仮定した場合の結果の例である。 The example of the optimization target loop after blocking shown in FIG. 6 is based on the assumption that blocking is performed on loop I and loop J in the optimization target loop including the three-dimensional array shown in FIG. This is an example of the result.
図6に示すように,3次元以上の配列を含む多重ループにおいて,最内ループ以外のループもブロッキングの対象とすることで,よりメモリ効率が高いループの最適化を行うことができるようになる。 As shown in FIG. 6, in a multiple loop including a three-dimensional array or more, loops other than the innermost loop are also subject to blocking, so that the loop with higher memory efficiency can be optimized. .
近年,ハードウェア性能の向上に合わせて,より高度で複雑な科学演算が行われる傾向がある。このようなニーズに応えるためには,図3や図6に示すように,3重以上の多重ループや3次元以上の配列を含む多重ループに対しても,ブロッキングの範囲を広げることにより,プログラムの実行性能を向上させる必要がある。 In recent years, there has been a tendency for more sophisticated and complex scientific operations to be performed as hardware performance improves. In order to meet such needs, as shown in FIG. 3 and FIG. 6, the program can be expanded by broadening the blocking range even for multiple loops including three or more multiple loops and multiple loops including three-dimensional arrays. It is necessary to improve the execution performance.
以下では,3重以上の多重ループや3次元以上の配列を含む多重ループに対するブロッキングの問題の解決を図った,本実施の形態のブロッキングの技術について説明する。 In the following, a blocking technique according to the present embodiment for solving the blocking problem with respect to multiple loops having three or more layers or multiple loops including three-dimensional or more arrays will be described.
図7は,本実施の形態によるコンパイラの機能構成例を示す図である。 FIG. 7 is a diagram illustrating a functional configuration example of the compiler according to the present embodiment.
図7において,実線の矢印は主に制御の流れを示し,破線の矢印は主にデータの流れを示す。 In FIG. 7, the solid-line arrows mainly indicate the flow of control, and the broken-line arrows mainly indicate the data flow.
コンピュータ1は,コンパイラ10,記憶部20,リンカ30,オペレーティングシステム40を備える。オペレーティングシステム40は,アプリケーションが共通して利用する基本的な機能を提供する。
The
記憶部20は,ソースプログラム21,オブジェクトファイル22,実行ファイル23などを記憶する,コンピュータ1がアクセス可能な記憶装置である。ソースプログラム21は,Fortranなどのプログラミング言語で記述されたアプリケーションのプログラムである。オブジェクトファイル22は,コンパイラ10によってソースプログラム21から生成された,アプリケーションのオブジェクトコードのファイルである。実行ファイル23は,リンカ30によってオブジェクトファイル22とライブラリとがリンクされた,アプリケーションの実行形式プログラムのファイルである。
The
コンパイラ10は,ソースプログラム21をコンパイルし,オブジェクトファイルを生成する。リンカ30は,オブジェクトファイル22とライブラリとをリンクし,実行ファイル23を生成する。
The
コンパイラ10は,ソースプログラム入力部11,入出力制御部12,中間言語生成部13,中間言語記憶部14,最適化処理部15,コード生成部18,オブジェクトファイル出力部19を備える。
The
ソースプログラム入力部11は,コンパイルが指定されたソースプログラム21をオープンする。入出力制御部12は,オプション,ファイルの種別に応じて必要な処理を選択する。
The source
中間言語生成部13は,ソースプログラム21を,最適化処理部15による最適化の処理で利用する中間コードに変換し,中間言語記憶部14に格納する。中間言語記憶部14は,中間言語生成部13によりソースプログラム21から変換された中間コードを記憶する,コンピュータ1がアクセス可能な記憶装置である。高級言語で記述されたソースプログラム21に対してそのまま最適化の処理を施すことは,非常に困難である。そのため,コンパイラ10は,最適化の処理が施しやすいデータ構造体でソースプログラム21を表現する中間コードに変換してから,その中間コードに対して最適化の処理を施す。
The intermediate
最適化処理部15は,中間言語記憶部14に記憶された中間コードに対して,最適化の処理を行う。最適化処理部15は,ソース解析部16,最適化実行部17を備える。ソース解析部16は,中間言語記憶部14に記憶された中間コードを解析して,有効な最適化を選択し,最適化実行部17に指示する。最適化実行部17は,指示された最適化を,中間言語記憶部14に記憶された中間コードに対して適用する。
The
コード生成部18は,最適化された中間コードから,アセンブラコードを生成する。オブジェクトファイル出力部19は,アセンブラコードからオブジェクトファイル22を生成する。
The
図8は,本実施の形態によるコンピュータのハードウェア構成例を示す図である。 FIG. 8 is a diagram illustrating a hardware configuration example of a computer according to the present embodiment.
コンピュータ1は,CPU(Central Processing Unit )2,RAM(Random Access Memory)やROM(Read Only Memory)などのメモリ3,HDD(Hard Disk Drive )4などのハードウェアを備える。メモリ3の一部は,CPU2が高速にアクセス可能なキャッシュメモリである。また,コンピュータ1には,キーボードやマウスなどの入力装置5,ディスプレイなどの表示装置6が接続されている。
The
図7に示すコンピュータ1が備えるコンパイラ10,記憶部20,リンカ30,オペレーティングシステム40等が提供する機能は,図8に示すコンピュータ1のハードウェアとソフトウェアプログラムとによって実現される。
Functions provided by the
図9は,本実施の形態によるソース解析部の機能構成例を示す図である。 FIG. 9 is a diagram illustrating a functional configuration example of the source analysis unit according to the present embodiment.
本実施の形態では,ソース解析部16は,多重ループを最適化するブロッキングに関する処理として,アクセスパターンの解析,メモリサイズ計算式の作成,分割ブロック長の算出などの処理を実施する。最適化処理部15は,ソース解析部16により得られた情報を最適化実行部17に伝播することで,ソースプログラム21に含まれるループの最適化を実行し,コンパイラ10により生成されるプログラムの高速化を図る。
In the present embodiment, the
ソース解析部16は,多重ループを最適化するブロッキングに関する処理として,中間言語記憶部14に記憶された中間コードを解析して,ブロッキングによるループ分割の単位である分割ブロック長を自動計算する。中間言語記憶部14は,ソースプログラム21に含まれるループに関する中間コードのデータとして,ループデータを記憶する。図9に示すループデータ記憶部200は,中間言語記憶部14におけるループデータの記憶領域である。
The
なお,本実施の形態では,最適化処理部15によるブロッキングに関する処理の前に,ループの内外を交換するインデックス変換や,並列するループを含む多重ループを直列の入れ子構造に変形するループ分割等の最適化が,すでに実行されているものとする。
In the present embodiment, before the processing related to blocking by the
ソース解析部16は,ブロッキングに関する機能部として,処理対象ループ解析部100,配列解析部110,アクセスパターン解析部120,メモリサイズ計算式生成部130,分割ブロック長計算部140,ブロッキング指示部150等の各機能部を有する。また,ソース解析部16は,配列情報記憶部160,配列別メモリ計算情報記憶部170,メモリサイズ計算情報記憶部180等の各記憶部を有する。ソース解析部16が有する各機能部,各記憶部は,コンピュータ1が備えるCPU2,メモリ3,HDD4等のハードウェアと,ソフトウェアプログラムとによって実現される。
The
処理対象ループ解析部100は,最適化の対象となるループからタイトな構造を持つループを抽出する。以下では,中間コードで表現されたソースプログラム21に含まれる最適化の対象となるループを,最適化対象ループと呼ぶものとする。また,処理対象ループ解析部100によって,最適化対象ループから抽出されるタイトな構造を持つループを,ブロッキング対象ループと呼ぶものとする。
The processing target
配列解析部110は,ブロッキング対象ループの最内ループ内を解析し,ブロッキング対象ループ内に存在する配列を抽出する。配列解析部110は,ブロッキング対象ループ内から抽出された配列の情報を配列情報記憶部160に記憶する。配列情報記憶部160は,ブロッキング対象ループ内から抽出された配列の情報を記憶する,コンピュータがアクセス可能な記憶装置である。
The
アクセスパターン解析部120は,ブロッキング対象ループにおいて最内ループから最外ループに向かって出現する制御変数の順序と,ブロッキング対象ループ内から抽出された配列の添え字に出現する制御変数の順序との関係を解析する。アクセスパターン解析部120は,添え字に出現する制御変数の順序が,最内ループから最外ループに向かって出現する制御変数の順序とは異なる配列が存在する場合に,ブロッキング対象ループに対するブロッキングによる最適化が有効であると判定する。
The access
メモリサイズ計算式生成部130は,ブロッキング対象ループ内の配列ごとに,ブロッキング対象ループに対するブロッキングによって最適化される範囲で,配列が使用するメモリサイズを算出する計算式を生成する。以下では,ブロッキングによって最適化される範囲で配列が使用するメモリサイズを算出する計算式を,配列別メモリ計算式と呼ぶものとする。メモリサイズ計算式生成部130は,配列別メモリ計算式の情報を配列別メモリ計算情報記憶部170に記憶する。配列別メモリ計算情報記憶部170は,配列別メモリ計算式の情報を記憶する,コンピュータがアクセス可能な記憶装置である。
The memory size calculation
また,メモリサイズ計算式生成部130は,配列別メモリ計算式から,ブロッキング対象ループに対するブロッキングによって最適化される範囲で,ブロッキング対象ループ内の全配列が使用するメモリサイズを算出する計算式を生成する。以下では,ブロッキングによって最適化される範囲でブロッキング対象ループ内の全配列が使用するメモリサイズを算出する計算式を,メモリサイズ計算式と呼ぶものとする。メモリサイズ計算式生成部130は,メモリサイズ計算式の情報をメモリサイズ計算情報記憶部180に記憶する。メモリサイズ計算情報記憶部180は,メモリサイズ計算式の情報を記憶する,コンピュータがアクセス可能な記憶装置である。
In addition, the memory size calculation
分割ブロック長計算部140は,メモリサイズ計算式を用いて,ブロッキング対象ループに対するブロッキングによって最適化される範囲で,配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する。
The divided block
ブロッキング指示部150は,分割ブロック長計算部140によって得られた分割ブロック長を用いた,ブロッキング対象ループに対するブロッキングによる最適化の指示を行う。
The blocking
最適化実行部17は,ソース解析部16により求められた分割ブロック長を用いて,ブロッキング対象ループに対するブロッキングによる最適化を実行する。より具体的には,最適化実行部17は,ソース解析部16により求められた分割ブロック長を用いて分割数を指示するループをもとのブロッキング対象ループの外に生成して,もとのブロッキング対象ループを変形する。
The
図10は,本実施の形態の最適化処理部によるブロッキング最適化処理フローチャートである。 FIG. 10 is a flowchart of the blocking optimization process performed by the optimization processing unit according to this embodiment.
最適化処理部15のソース解析部16において,処理対象ループ解析部100は,処理対象ループ解析処理を行う(ステップS1)。処理対象ループ解析処理は,最適化の対象となるループからタイトな構造を持つループを抽出する処理である。処理対象ループ解析処理の詳細については,後述する。
In the
配列解析部110は,配列解析処理を行う(ステップS2)。配列解析処理は,ブロッキング対象ループ内に存在する配列を抽出する処理である。配列解析処理の詳細については,後述する。
The
アクセスパターン解析部120は,アクセスパターン解析処理を行う(ステップS3)。アクセスパターン解析処理は,ブロッキング対象ループ内のループの制御変数の出現順と,ブロッキング対象ループ内の配列の制御変数の出現順との関係から,ブロッキング対象ループに対するブロッキングによる最適化の有効/無効を判定する処理である。アクセスパターン解析処理の詳細については,後述する。
The access
メモリサイズ計算式生成部130は,メモリサイズ計算式生成処理を行う(ステップS4)。メモリサイズ計算式生成処理は,ブロッキング対象ループに対するブロッキング対象ループに対するブロッキングによって最適化される範囲で,ブロッキング対象ループ内の全配列が使用するメモリサイズを算出する計算式を生成する処理である。メモリサイズ計算式生成処理の詳細については,後述する。
The memory size calculation
分割ブロック長計算部140は,分割ブロック長計算処理を行う(ステップS5)。分割ブロック長計算処理は,メモリサイズ計算式を用いて,ブロッキング対象ループに対するブロッキングによって最適化される範囲のループの処理で,配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する処理である。分割ブロック長計算処理の詳細については,後述する。
The divided block
ブロッキング指示部150は,ブロッキング指示処理を行う(ステップS6)。ブロッキング指示処理は,求めた分割ブロック長を用いた,ブロッキング対象ループに対するブロッキングによる最適化の指示を行う処理である。ブロッキング指示処理の詳細については,後述する。
The blocking
最適化処理部15の最適化実行部17は,ソース解析部16により得られた分割ブロック長を用いた,ブロッキング対象ループに対するブロッキングによる最適化を実行する(ステップS7)。
The
以下では,本実施の形態によるソース解析部16が備えるブロッキングに関する各機能部の処理について,具体的な例を用いて説明する。
Hereinafter, the processing of each functional unit related to blocking included in the
図11は,本実施の形態による最適化の対象となるループとブロッキングによる最適化実行後のループとの例を示す図である。 FIG. 11 is a diagram illustrating an example of a loop to be optimized according to the present embodiment and a loop after execution of optimization by blocking.
図11(A)は,ソースプログラム21における最適化の対象となるループの例を示す。以下では,最適化の対象となるループを,最適化対象ループと呼ぶものとする。図11(A)に示す最適化対象ループは,最内ループ内に3次元の配列を持つ,3重の多重ループである。
FIG. 11A shows an example of a loop to be optimized in the
図11(B)は,図11(A)に示す最適化対象ループに対して本実施の形態のブロッキングによる最適化を実行した場合の,目標となる最適化実行後のループの例を示す。図11(B)に示す最適化実行後のループは,図(A)に示す最適化対象ループのループI,ループJ,ループKのすべてのループについて,分割ブロック長blockを用いたブロッキングによる最適化が実行された状態となっている。 FIG. 11B shows an example of a loop after execution of optimization as a target when optimization by blocking of the present embodiment is executed on the optimization target loop shown in FIG. The loop after the optimization execution shown in FIG. 11B is the optimum by blocking using the divided block length block for all of the loops I, J, and K of the optimization target loop shown in FIG. Is in a state of being executed.
図11(B)に示すように,最適化実行後のループでは,分割ブロック長blockを用いて分割数を指示するループII,ループJJ,ループKKがもとのループI,ループJ,ループKの外に生成され,もとのループI,ループJ,ループKが変形されている。図11(B)における最適化実行後のループにおいて,内側のループI,ループJ,ループKからなる多重ループが,ブロッキングによって最適化される範囲のループとなる。本実施の形態によるソース解析部16では,ブロッキングによって最適化される範囲のループ内の処理では,配列に対するアクセスによってキャッシュミスが発生しないような分割ブロック長blockを,自動計算する。
As shown in FIG. 11B, in the loop after execution of optimization, the loop II, loop JJ, and loop KK that indicate the number of divisions using the divided block length block are the original loop I, loop J, and loop K. The original loop I, loop J, and loop K are transformed. In the loop after the optimization execution in FIG. 11B, the multiple loop composed of the inner loop I, loop J, and loop K becomes a loop in the range optimized by blocking. The
以下では,本実施の形態によるソース解析部16によって,図11(A)に示す最適化対象ループに対するブロッキングによる最適化で用いる分割ブロック長blockを,自動的に計算する例を説明する。
Hereinafter, an example in which the
なお,図11に示すループのプログラムは,ソースプログラム21の形式で表現しているが,実際の最適化処理部15では,中間コードに変換されたループのプログラムに対して処理が行われる。
The loop program shown in FIG. 11 is expressed in the form of the
図12は,本実施の形態によるループデータのデータ構造の例を示す図である。 FIG. 12 is a diagram illustrating an example of a data structure of loop data according to the present embodiment.
図12に示すループデータ210は,ソースプログラム21に含まれるループが中間コードに変換されたデータテーブルの例である。図12に示すループデータ210kは,図11(A)に示す最適化対象ループのループKについてのループデータ210である。図12に示すループデータ210jは,図11(A)に示す最適化対象ループのループJについてのループデータ210である。図12に示すループデータ210iは,図11(A)に示す最適化対象ループのループIについてのループデータ210である。
12 is an example of a data table in which a loop included in the
図12に示すループデータ210は,ループ名,prev(previous),next,配列データ,ブロッキングフラグ,分割ブロック長,有効フラグ等の情報を有する。なお,実際のループデータ210は,ループに関する膨大な量の情報を有するデータである。図12には,ループに関する膨大な量の情報を有するループデータ210の一部のみが記載されている。 The loop data 210 shown in FIG. 12 includes information such as a loop name, prev (previous), next, array data, blocking flag, divided block length, and valid flag. The actual loop data 210 is data having an enormous amount of information regarding the loop. FIG. 12 shows only a part of the loop data 210 having a huge amount of information regarding the loop.
図12に示すループデータ210におけるループ名は,ループで値が更新される制御変数の名前を示す。 The loop name in the loop data 210 shown in FIG. 12 indicates the name of the control variable whose value is updated in the loop.
図12に示すループデータ210におけるprevは,外側のループのループデータ210に対するポインタを示す。図12において,例えばループデータ210jのprevにおける“*K”は,ループJの外側のループであるループKのループデータ210kに対するポインタを表している。なお,図12において,外側にループを持たないループKのループデータ210kのprevは,“NULL”である。
Prev in the loop data 210 shown in FIG. 12 indicates a pointer to the loop data 210 of the outer loop. In FIG. 12, for example, “* K” in prev of the
図12に示すループデータ210におけるnextは,内側のループのループデータ210に対するポインタを示す。例えば,ループデータ210jのnextにおける“*I”は,ループJの内側のループであるループIのループデータ210iに対するポインタを表している。なお,図12において,内側にループを持たないループIのループデータ210iのnextは,“NULL”である。
Next in the loop data 210 shown in FIG. 12 indicates a pointer to the loop data 210 of the inner loop. For example, “* I” in the next of the
図12に示すループデータ210における配列データは,最内ループ内に存在する配列に関する情報である配列データに対するポインタを示す。ループデータ210の配列データのデフォルトは,“NULL”である。ループデータ210における配列データは,後述の配列解析部110の処理によって設定される。
The array data in the loop data 210 shown in FIG. 12 indicates a pointer to array data that is information relating to the array existing in the innermost loop. The default of the array data of the loop data 210 is “NULL”. The sequence data in the loop data 210 is set by processing of the
図12に示すループデータ210におけるブロッキングフラグは,ブロッキング実行可否の指示の有無を示す。本実施の形態では,ループごとに,外部的にブロッキングによる最適化の有無を指示できるケースも想定している。本実施の形態では,特に指示のないループについては,ループデータ210のブロッキングフラグに“TRUE”が設定される。最適化指示行などによりブロッキングが抑止されたループについては,ループデータ210のブロッキングフラグに“FALSE”が設定される。 The blocking flag in the loop data 210 shown in FIG. In the present embodiment, it is also assumed that for each loop, the presence or absence of optimization by blocking can be externally instructed. In the present embodiment, “TRUE” is set in the blocking flag of the loop data 210 for a loop that has no particular instruction. For a loop whose blocking is suppressed by an optimization instruction line or the like, “FALSE” is set in the blocking flag of the loop data 210.
図12に示すループデータ210における分割ブロック長は,ブロッキングで用いる分割ブロック長を示す。本実施の形態では,ループごとに,外部的に固定の分割ブロック長を指示できるケースも想定している。本実施の形態では,特に固定の分割ブロック長の指示がないループについては,ループデータ210の分割ブロック長に,ブロッキングで用いる分割ブロック長を自動計算することを示す“0”が設定される。最適化指示行などにより固定の分割ブロック長が指示されたループについては,ループデータ210の分割ブロック長に指示された値が設定される。なお,ループデータ210のブロッキングフラグが“FALSE”であるループについては,ループデータ210の分割ブロック長に,ブロッキングを実行しない旨を示す“−1”が設定される。 The divided block length in the loop data 210 shown in FIG. 12 indicates the divided block length used for blocking. In this embodiment, it is assumed that a fixed division block length can be externally designated for each loop. In the present embodiment, “0” indicating that the divided block length used for blocking is automatically calculated is set as the divided block length of the loop data 210 for a loop that does not instruct a fixed divided block length. For a loop for which a fixed division block length is designated by an optimization instruction line or the like, the value designated for the division block length of the loop data 210 is set. For a loop in which the blocking flag of the loop data 210 is “FALSE”, “−1” indicating that blocking is not executed is set in the divided block length of the loop data 210.
図12に示すループデータ210における有効フラグは,ブロッキングによる最適化が有効であるか否かを示す。ループデータ210の有効フラグのデフォルトは,“NULL”である。ループデータ210の有効フラグは,後述のアクセスパターン解析部120の処理によって設定される。
The valid flag in the loop data 210 shown in FIG. 12 indicates whether optimization by blocking is valid. The default valid flag of the loop data 210 is “NULL”. The valid flag of the loop data 210 is set by processing of the access
本実施の形態の処理対象ループ解析部100による処理の例を説明する。
An example of processing performed by the processing target
処理対象ループ解析部100は,まず,プログラムに含まれるDOループやFORループなどのループの入れ子関係を解析し,多重ループにおける最内ループを探し出す。より具体的には,処理対象ループ解析部100は,ループデータ記憶部200に記憶されたループデータ210を,外側のループから順にnextのポインタを辿って,nextが“NULL”である最内ループを見つけ出す。例えば,処理対象ループ解析部100は,図11(A)に示す最適化対象ループにおいて,最外のループKからループJ,ループIへと順に辿り,子ループがないループIを最内ループとして抽出する。
The processing target
次に,処理対象ループ解析部100は,抽出された最内ループから順に外側にループを広げながら,タイトな構造を持つループの範囲を抽出する。処理対象ループ解析部100は,抽出されたタイトな構造を持つループの範囲を,ブロッキングによる最適化の対象ループとする。以下では,ブロッキングによる最適化の対象ループを,ブロッキング対象ループと呼ぶものとする。
Next, the processing target
ループにおけるタイトな構造とは,ループが直列の入れ子構造をなし,最内ループにのみ実行文を有する構造である。本実施の形態では,タイトな構造を持つ多重ループをタイトなループと呼ぶものとする。途中のループとループとの間に実行文が含まれる場合には,実行文を含むループよりも下のループがタイトなループとみなされる。 A tight structure in a loop is a structure in which loops are serially nested and an executable statement is included only in the innermost loop. In the present embodiment, a multiple loop having a tight structure is called a tight loop. When an executable statement is included between loops in the middle, the loop below the loop containing the executable statement is regarded as a tight loop.
図13は,本実施の形態によるタイトなループを説明する図である。 FIG. 13 is a diagram for explaining a tight loop according to the present embodiment.
図13(A)に示すループは,ループXとループYからなる2重ループである。図13(A)に示すループは,最内のループYの内側にのみ演算の実行文を有している。すなわち,ループXとループYとからなる多重ループは,タイトなループである。 The loop shown in FIG. 13A is a double loop composed of a loop X and a loop Y. The loop shown in FIG. 13A has an execution statement for calculation only inside the innermost loop Y. That is, the multiple loop composed of the loop X and the loop Y is a tight loop.
図13(B)に示すループは,ループXとループYからなる2重ループである。図13(B)に示すループでは,ループXとループYとの間に演算の実行文が含まれている。そのため,ループXとループYとからなる多重ループは,タイトなループではない。 The loop shown in FIG. 13B is a double loop composed of a loop X and a loop Y. In the loop shown in FIG. 13B, an execution statement for the operation is included between the loop X and the loop Y. Therefore, the multiple loop composed of loop X and loop Y is not a tight loop.
図13(C)に示すループは,ループX,ループY,ループZからなる3重ループである。図13(C)に示すループでは,ループXとループYとの間に演算の実行文が含まれており,ループX,ループY,ループZからなる多重ループは,タイトなループではない。ただし,ループYとループZとの間には実行文が含まれていないので,ループYとループZとからなる多重ループは,タイトなループである。処理対象ループ解析部100は,このようなタイトなループの範囲を抽出する。
The loop shown in FIG. 13C is a triple loop including loop X, loop Y, and loop Z. In the loop shown in FIG. 13C, the execution statement of the operation is included between the loop X and the loop Y, and the multiple loop composed of the loop X, the loop Y, and the loop Z is not a tight loop. However, since an executable statement is not included between the loop Y and the loop Z, the multiple loop composed of the loop Y and the loop Z is a tight loop. The processing target
例えば,図11(A)に示す最適化対象ループでは,最内のループIの内側にのみ演算の実行分が存在する。処理対象ループ解析部100は,図11(A)に示す最適化対象ループからループK,ループJ,ループIの3重ループをタイトなループとして抽出し, ブロッキング対象ループとする。すなわち,図11(A)に示す最適化対象ループは,そのままブロッキング対象ループとなる。
For example, in the optimization target loop shown in FIG. 11 (A), the execution amount of the calculation exists only inside the innermost loop I. The processing target
図14は,本実施の形態の処理対象ループ解析部による処理対象ループ解析処理フローチャートである。 FIG. 14 is a processing target loop analysis processing flowchart by the processing target loop analysis unit of the present embodiment.
処理対象ループ解析部100は,処理対象の多重ループから最内ループを抽出する(ステップS10)。処理対象ループ解析部100は,抽出された最内ループをタイトな最外ループとする(ステップS11)。ここでのタイトな最外ループは,その時点でタイトなループであることが確認されているループのうち,最外のループを示す。
The processing target
処理対象ループ解析部100は,現在のタイトな最外ループの外側に,ループがあるかを判定する(ステップS12)。
The processing target
現在のタイトな最外ループの外側にループがある場合には(ステップS12のYES),処理対象ループ解析部100は,現在のタイトな最外ループの1つ外側のループを含む多重ループがタイトなループであるかを判定する(ステップS13)。
If there is a loop outside the current tight outermost loop (YES in step S12), the processing target
現在のタイトな最外ループの1つ外側のループを含む多重ループがタイトなループであれば(ステップS13のYES),処理対象ループ解析部100は,タイトな最外ループを,現在のタイトな最外ループのその1つ外側のループに更新する(ステップS14)。処理対象ループ解析部100は,ステップS12に戻って,更新されたタイトな最外ループの処理に移る。
If the multiple loop including the loop outside the current tight outermost loop is a tight loop (YES in step S13), the processing target
現在のタイトな最外ループの外側にループがない場合には(ステップS12のNO),処理対象ループ解析部100は,最内ループからタイトな最外ループまでのループをブロッキング対象ループとする(ステップS15)。また,現在のタイトな最外ループの1つ外側のループを含む多重ループがタイトなループでなければ(ステップS13のNO),処理対象ループ解析部100は,最内ループからタイトな最外ループまでのループをブロッキング対象ループとする(ステップS15)。
When there is no loop outside the current tight outermost loop (NO in step S12), the processing target
次に,本実施の形態の配列解析部110による処理の例を説明する。
Next, an example of processing by the
配列解析部110は,処理対象ループ解析部100の処理によって抽出された,ブロッキング対象ループの最内ループ内で利用されている配列を抽出する。このとき,配列解析部110は,演算の実行によってメモリ3を更新する配列と,メモリ3を参照する配列とのすべてを列挙する。
The
例えば,図11(A)のブロッキング対象ループにおいて,最内ループ内から,以下の6つの配列が抽出される。 For example, in the blocking target loop of FIG. 11A, the following six sequences are extracted from the innermost loop.
配列A(I,J,K)
配列A(I,J,K)
配列B(J,K,I)
配列C(K,I,J)
配列D(I,X,J)
配列D(I,Y,J)
このうち,最内ループ内の演算の実行文の左辺にある配列A(I,J,K)が演算の実行によってメモリ3を更新する配列であり,演算の実行文の右辺にある残りの5つの配列がメモリ3を参照する配列である。
Array A (I, J, K)
Array A (I, J, K)
Array B (J, K, I)
Array C (K, I, J)
Array D (I, X, J)
Array D (I, Y, J)
Among these, the array A (I, J, K) on the left side of the execution statement of the operation in the innermost loop is an array for updating the
配列解析部110は,抽出された配列のうち,配列名と添え字とが全く同じ配列が複数ある場合には,それらの配列をまとめて1つの配列とみなす。配列名と添え字とが全く同じ配列に対するアクセスは,すべてメモリ3上の同じ領域へのアクセスとなる。すなわち,ブロッキング対象ループ内の処理で,配列名と添え字とが全く同じ配列に何度アクセスしても,アクセスするメモリ3は変わらない。そのため,後述のブロッキングによる最適化が行われたループ内の処理で配列が使用するメモリサイズを計算する手順では,配列名と添え字とが全く同じ配列が複数あっても,1つ分だけ計算すれば十分となる。
When there are a plurality of sequences having the same sequence name and subscript among the extracted sequences, the
例えば,図11(A)において,最内ループから抽出された配列には,配列A(I,J,K)が2つある。このとき,配列解析部110は,1つの配列A(I,J,K)が抽出されたものとみなす。
For example, in FIG. 11A, the arrays extracted from the innermost loop include two arrays A (I, J, K). At this time, the
配列解析部110は,最内ループ内から抽出された各配列について,配列データを生成する。配列解析部110は,生成された配列データを,ブロッキング対象ループ内から抽出された配列の情報として,配列情報記憶部160に記憶する。
The
図15は,本実施の形態による配列データの管理を説明する図である。 FIG. 15 is a diagram for explaining management of array data according to the present embodiment.
図15に示す配列データ165は,配列解析部110によって,図11(A)における最内ループ内から抽出された配列データ165の例である。配列データ165aは,配列A(I,J,K)の配列データである。配列データ165bは,配列B(J,K,I)の配列データである。配列データ165cは,配列C(K,I,J)の配列データである。配列データ165d1 は,配列D(I,X,J)の配列データである。配列データ165d2 は,配列D(I,Y,J)の配列データである。このように,配列解析部110は,抽出された配列の数だけ,配列データ165を生成する。
The sequence data 165 shown in FIG. 15 is an example of the sequence data 165 extracted from the innermost loop in FIG. 11A by the
図15に示す配列データ165は,該当配列についての配列名,添え字等の情報を有する。配列データ165において,添え字のフィールドは,配列の次元数分だけ用意される。すなわち,図15に示すように,3次元の配列の配列データ165であれば,添え字#1,添え字#2,添え字#3の3つの添え字のフィールドが存在する。
The array data 165 shown in FIG. 15 has information such as an array name and a suffix for the corresponding array. In the array data 165, as many subscript fields as the number of dimensions of the array are prepared. That is, as shown in FIG. 15, in the case of array data 165 of a three-dimensional array, there are three subscript fields,
また,図15に示すように,配列解析部110は,ループデータ記憶部200に記憶されたループデータ210における配列データのフィールドに,生成した配列データ165へのポインタを設定する。ここでは,最内ループのループデータ210に対してのみ,生成した配列データ165へのポインタが設定されるものとする。例えば,図15に示すように,ブロッキング対象ループの最内ループであるループIのループデータ210iにおける配列データのフィールドに,5つの配列データ165へのポインタが設定される。
As shown in FIG. 15, the
図16は,本実施の形態の配列解析部による配列解析処理フローチャートである。 FIG. 16 is a flowchart of sequence analysis processing by the sequence analysis unit of this embodiment.
配列解析部110は,ブロッキング対象ループの最内ループ内に存在する配列を1つ選択する(ステップS20)。配列解析部110は,選択した配列の配列名を取得する(ステップS21)。配列解析部110は,選択した配列の次元数,すなわち添え字の数を取得する(ステップS22),配列解析部110は,選択した配列の添え字を登場順に取得する(ステップS23)。
The
配列解析部110は,配列名と添え字とが,選択された配列と全く同じである配列の配列データ165がすでにあるかを判定する(ステップS24)。配列名と添え字とが,選択された配列と全く同じである配列の配列データ165がまだなければ(ステップS24のNO),配列解析部110は,選択された配列の配列データ165を生成する(ステップS25)。このとき,配列解析部110は,取得された配列の次元数分の添え字フィールドを有する配列データ165を用意する。生成された配列データ165は,配列情報記憶部160に記憶される。
The
配列解析部110は,最内ループ内に存在するすべての配列について処理が終了したかを判定する(ステップS26)。すべての配列についてまだ処理が終了していなければ(ステップS26のNO),配列解析部110は,ステップS20に戻って次の配列の処理に移る。すべての配列について処理が終了していれば(ステップS26のYES),配列解析部110は,処理を終了する。
The
次に,本実施の形態のアクセスパターン解析部120による処理の例を説明する。
Next, an example of processing by the access
アクセスパターン解析部120は,配列解析部110によって抽出された配列のアクセスパターンを解析する。
The access
アクセスパターンは,配列に対するメモリアクセスのパターンを示す。本実施の形態では,配列に対するメモリアクセスにおいて,アドレスに沿って順次メモリ3にアクセスするパターンをストレートと呼び,アドレスの間隔を空けて点々とメモリ3にアクセスするパターンをクロスと呼ぶものとする。アクセスパターンは,配列の添え字に登場する制御変数によって判断することができる。
The access pattern indicates a memory access pattern for the array. In the present embodiment, in memory access to an array, a pattern that sequentially accesses the
図17は,本実施の形態によるアクセスパターンを説明する図である。 FIG. 17 is a diagram for explaining an access pattern according to the present embodiment.
図17に示すループK,ループJ,ループIからなる多重ループにおいて,制御変数K,J,Iを更新するテンポが速い順に並べると,最内ループから最外ループに向かって出現する制御変数の順序で,I→J→Kとなる。本実施の形態では,ブロッキング対象ループの最内ループから最外ループに向かう順序で出現する制御変数を並べたものを,制御変数の連鎖と呼ぶものとする。 In the multiple loop composed of loop K, loop J, and loop I shown in FIG. 17, when control variables K, J, and I are arranged in order of increasing tempo, control variables that appear from the innermost loop toward the outermost loop are displayed. In order, I → J → K. In this embodiment, an arrangement of control variables that appear in the order from the innermost loop to the outermost loop of the blocking target loop is called a chain of control variables.
図17(A)に示す多重ループにおいて,最内のループIの内側には配列A(I,J,K)が存在する。この配列A(I,J,K)の添え字として使われている制御変数を,その登場する次元の順に並べると,I→J→Kとなる。本実施の形態では,ブロッキング対象ループの最内ループ内にある配列において,その配列に添え字として使われている制御変数をその出現順に並べたものを,添え字の連鎖と呼ぶものとする。このように,添え字の連鎖が制御変数の連鎖と同じ配列のアクセスパターンが,ストレートである。 In the multiple loop shown in FIG. 17A, the array A (I, J, K) exists inside the innermost loop I. When the control variables used as subscripts of this array A (I, J, K) are arranged in the order of their appearing dimensions, I → J → K. In the present embodiment, in an array in the innermost loop of the blocking target loop, a control variable used as a subscript in the array in the order of appearance is called a subscript chain. Thus, an access pattern in which the subscript chain is the same as the control variable chain is straight.
図17(B)に示すブロッキング対象ループにおいて,上述したように制御変数の連鎖は,I→J→Kである。また,最内ループ内にある配列B(J,K,I)の添え字の連鎖は,J→K→Iである。このように,添え字の連鎖が制御変数の連鎖と異なる配列のアクセスパターンが,クロスである。 In the blocking target loop shown in FIG. 17B, as described above, the chain of control variables is I → J → K. The subscript chain of the array B (J, K, I) in the innermost loop is J → K → I. Thus, an access pattern of an array in which the subscript chain is different from the control variable chain is cross.
ブロッキングによる最適化は,配列に対するメモリアクセスがメモリ3のアドレス順序ではなく,点在するようなケースにおいて,メモリ3へのアクセス範囲を局所化することで,キャッシュヒット率を向上させる最適化である。そのため,アクセスパターンがメモリ3を順次アクセスするストレートの配列しかないような多重ループに対してブロッキングによる最適化を適用しても,効果が出ない場合が多い。
The optimization by blocking is an optimization that improves the cache hit rate by localizing the access range to the
そこで,本実施の形態では,アクセスパターン解析部120によって,ブロッキング対象ループ内の各配列のアクセスパターンを解析することにより,ブロッキング対象ループに対してブロッキングによる最適化を適用することの有効性をチェックする。アクセスパターン解析部120は,ブロッキング対象ループが,アクセスパターンがメモリ3を点々とアクセスするクロスの配列を内側に持つような場合に,そのブロッキング対象ループに対するブロッキングによる最適化が有効であると判定する。
Therefore, in this embodiment, the access
アクセスパターン解析部120は,ブロッキング対象ループに対するブロッキングによる最適化が有効であると判定すれば,そのブロッキング対象ループの最内ループのループデータ210における有効フラグを“TRUE”に設定する。
If the access
例えば,前述したように,配列解析部110は,図11(A)に示すブロッキング対象ループの内部から5つの配列を抽出し,5つの配列データ165を作成する。アクセスパターン解析部120は,配列解析部110により生成された5つの配列データ165を配列情報記憶部160から取得し,取得された配列データ165から各配列の添え字の連鎖を作成する。
For example, as described above, the
このとき,アクセスパターン解析部120は,添え字にブロッキング対象ループ内で値が不変のものがあれば,その添え字を省いて添え字の連鎖を作成する。ブロッキング対象ループ内で値が不変のものは,ブロッキング対象ループに含まれるループの制御変数以外のもの,例えば固定値やブロッキング対象ループより外側のループの制御変数などである。
At this time, if there is a subscript whose value does not change in the blocking target loop, the access
図11(A)に示すブロッキング対象ループの内部から抽出された5つの配列についての添え字の連鎖は,次のようになる。 The subscript chain for the five sequences extracted from the inside of the blocking target loop shown in FIG. 11A is as follows.
配列A(I,J,K): I→J→K
配列B(J,K,I): J→K→I
配列C(K,I,J): K→I→J
配列D(I,X,J): I→J
配列D(I,Y,J): I→J
配列D(I,X,J),配列D(I,Y,J)については,それぞれX,Yがブロッキング対象ループ内で不変値であるので,添え字の連鎖から省かれる。
Array A (I, J, K): I → J → K
Array B (J, K, I): J → K → I
Array C (K, I, J): K → I → J
Array D (I, X, J): I → J
Array D (I, Y, J): I → J
The arrays D (I, X, J) and D (I, Y, J) are omitted from the chain of subscripts because X and Y are invariant values in the blocking target loop, respectively.
ここで,図11(A)に示すブロッキング対象ループに含まれるループは,内側から順に,ループI,ループJ,ループKである。よって,図11(A)に示すブロッキング対象ループの制御変数の連鎖は,I→J→Kとなる。 Here, the loops included in the blocking target loop shown in FIG. 11A are loop I, loop J, and loop K in order from the inside. Therefore, the chain of control variables in the blocking target loop shown in FIG. 11A is I → J → K.
図11(A)に示すブロッキング対象ループの制御変数の連鎖と,各配列の添え字の連鎖とを比較すると,各配列のアクセスパターンは,次のようになる。 When the chain of control variables in the blocking target loop shown in FIG. 11A is compared with the chain of subscripts of each array, the access pattern of each array is as follows.
配列A(I,J,K): ストレート
配列B(J,K,I): クロス
配列C(K,I,J): クロス
配列D(I,X,J): ストレート
配列D(I,Y,J): ストレート
このように,配列B(J,K,I)と配列C(K,I,J)のアクセスパターンがクロスであるので,アクセスパターン解析部120は,図11(A)に示すブロッキング対象ループに対するブロッキングによる最適化が有効であると判定する。
Array A (I, J, K): Straight Array B (J, K, I): Cross Array C (K, I, J): Cross Array D (I, X, J): Straight Array D (I, Y) , J): Straight In this way, since the access patterns of the array B (J, K, I) and the array C (K, I, J) are crosses, the access
図18は,本実施の形態によるループデータにおける有効フラグを設定した例を示す図である。 FIG. 18 is a diagram showing an example in which a valid flag is set in loop data according to the present embodiment.
図18に示すように,アクセスパターン解析部120は,ブロッキングによる最適化が有効であると判定された図11(A)に示すブロッキング対象ループについて,最内ループIのループデータ210iにおける有効フラグを,“TRUE”に設定する。
As shown in FIG. 18, the access
図19は,本実施の形態のアクセスパターン解析部によるアクセスパターン解析処理フローチャートである。 FIG. 19 is a flowchart of access pattern analysis processing by the access pattern analysis unit of the present embodiment.
アクセスパターン解析部120は,ブロッキング対象ループの最内ループのループデータ210における有効フラグを,無効を示す“FALSE”で初期化する(ステップS30)。
The access
アクセスパターン解析部120は,ブロッキング対象ループが多重ループであるかを判定する(ステップS31)。ブロッキング対象ループが多重ループでなければ(ステップS31のNO),アクセスパターン解析部120は,処理を終了する。ブロッキング対象ループが1重のループである場合には,そのブロッキング対象ループにブロッキングによる最適化を適用しても,効果が出ない場合が多い。本実施の形態では,このような1重ループであるブロッキング対象ループに対するブロッキングを行わない。なお,上述の処理対象ループ解析部100の処理において,タイトなループが1重ループである場合に,ブロッキング対象ループから外すようにしてもよい。
The access
ブロッキング対象ループが多重ループであれば(ステップS31のYES),アクセスパターン解析部120は,ブロッキング対象ループのループデータ210から,制御変数の連鎖を作成する(ステップS32)。
If the blocking target loop is a multiple loop (YES in step S31), the access
アクセスパターン解析部120は,配列情報記憶部160から,ブロッキング対象ループの最内ループ内にある配列の配列データ165を1つ選択する(ステップS33)。アクセスパターン解析部120は,選択された配列データ165の添え字の連鎖作成処理を行う(ステップS34)。添え字の連鎖作成処理については,後述する。
The access
アクセスパターン解析部120は,制御変数の連鎖と選択された配列データ165の添え字の連鎖とを比較し,アクセスパターンを確認する(ステップS35)。アクセスパターンがクロスであれば(ステップS35のクロス),アクセスパターン解析部120は,ブロッキング対象ループの最内ループのループデータ210における有効フラグに,有効を示す“TRUE”を設定し(ステップS36),処理を終了する。
The access
アクセスパターンがストレートであれば(ステップS35のストレート),アクセスパターン解析部120は,ブロッキング対象ループの最内ループ内にあるすべての配列の配列データ165について処理が終了したかを判定する(ステップS37)。すべての配列データ165についてまだ処理が終了していなければ(ステップS37のNO),アクセスパターン解析部120は,ステップS33に戻って次の配列データ165の処理に移る。すべての配列データ165について処理が終了していれば(ステップS37のYES),アクセスパターン解析部120は,処理を終了する。
If the access pattern is straight (straight in step S35), the access
図20は,本実施の形態のアクセスパターン解析部による添え字の連鎖作成処理フローチャートである。 FIG. 20 is a flowchart of subscript chain creation processing by the access pattern analysis unit of this embodiment.
アクセスパターン解析部120は,添え字の連鎖を作成する対象配列の配列データ165から,出現順に添え字を1つ取得する(ステップS340)。アクセスパターン解析部120は,取得された添え字がブロッキング対象ループに含まれるループの制御変数であるかを判定する(ステップS341)。
The access
取得された添え字がブロッキング対象ループに含まれるループの制御変数であれば(ステップS341のYES),アクセスパターン解析部120は,取得された添え字を添え字の連鎖に追加する(ステップS342)。
If the acquired subscript is a control variable of a loop included in the blocking target loop (YES in step S341), the access
アクセスパターン解析部120は,配列データ165内のすべての添え字について処理が終了したかを判定する(ステップS343)。すべての添え字についてまだ処理が終了していなければ(ステップS343のNO),アクセスパターン解析部120は,ステップS340に戻って次の添え字の処理に移る。すべての添え字について処理が終了していれば(ステップS343のYES),アクセスパターン解析部120は,処理を終了する。
The access
次に,本実施の形態のメモリサイズ計算式生成部130による処理の例を説明する。
Next, an example of processing by the memory size calculation
メモリサイズ計算式生成部130は,アクセスパターン解析部120による判定の結果,ループデータ210における有効フラグが“TRUE”となっているブロッキング対象ループについて,メモリサイズ計算式を生成する。メモリサイズ計算式は,ブロッキング対象ループに対するブロッキングによって最適化される範囲で,ブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式である。
As a result of the determination by the access
例えば,図11(B)に示すブロッキング後の最適化対象ループにおいて,ループK,ループJ,ループIが,分割ブロック長blockを用いたブロッキングによって最適化された範囲である。このとき,メモリサイズ計算式は,図11(B)に示すブロッキング後の最適化対象ループにおけるループK,ループJ,ループIのみが回転する範囲で,その最内ループ内の全配列が使用するメモリサイズを計算する計算式である。 For example, in the optimization target loop after blocking shown in FIG. 11B, loop K, loop J, and loop I are ranges optimized by blocking using the divided block length block. At this time, the memory size calculation formula is used by all the arrays in the innermost loop within a range in which only the loop K, loop J, and loop I in the optimization target loop after blocking shown in FIG. This is a calculation formula for calculating the memory size.
メモリサイズ計算式生成部130は,ブロッキング対象ループ内の配列ごとに生成される配列別メモリ計算式から,メモリサイズ計算式を生成する。配列別メモリ計算式は,配列ごとに生成される,ブロッキング対象ループに対するブロッキングによって最適化される範囲で,それぞれの配列が使用するメモリサイズを計算する計算式である。
The memory size calculation
図21は,本実施の形態による配列別メモリ計算式の生成を説明する図である。 FIG. 21 is a diagram for explaining the generation of the memory calculation formula for each array according to the present embodiment.
図21(A)は,最内ループIの内側に4次元の配列A(I,J,K,L)を有する,ループL,ループK,ループJ,ループIからなるタイトな4重ループの例を示す。ここでは,図21に示す4重ループに対してブロッキングによる最適化を行った場合に,ブロッキングによって最適化された範囲で,配列A(I,J,K,L)が使用するメモリサイズを計算する計算式を生成する例を説明する。 FIG. 21A shows a tight quadruple loop consisting of loop L, loop K, loop J, and loop I having a four-dimensional array A (I, J, K, L) inside the innermost loop I. An example is shown. Here, when optimization by blocking is performed on the quadruple loop shown in FIG. 21, the memory size used by the array A (I, J, K, L) is calculated within the range optimized by blocking. An example of generating a calculation formula is described.
なお,図21(A)に示すように,配列A(I,J,K,L)は,配列の型が実数(real)であることが宣言されており,配列A(I,J,K,L)の型サイズは,8バイトとなる。また,ループLにはブロッキングを実行しない旨が指示されており,そのループデータ210におけるブロッキングフラグには,“FALSE”が設定されている。また,ループJには固定の分割ブロック長20が指示されており,そのループデータ210における分割ブロック長のフィールドには,20が設定されている。ループKとループIに対しては,特定の指示がないので,そのループデータ210における分割ブロック長のフィールドには,自動計算を示す0が設定されている。
As shown in FIG. 21A, the array A (I, J, K, L) is declared that the type of the array is a real number, and the array A (I, J, K) , L) type size is 8 bytes. Further, the loop L is instructed not to execute blocking, and “FALSE” is set in the blocking flag in the loop data 210. Further, a fixed divided
図21(B)は,配列別メモリ計算データ175の例を示す。配列別メモリ計算データ175は,本実施の形態において,配列別メモリ計算式を表すデータである。配列別メモリ計算データ175は,可変部と固定部とを有する。
FIG. 21B shows an example of
可変部は,配列別メモリ計算式において,自動計算される分割ブロック長の値によって,配列が使用するメモリサイズが変化する部分を示している。図21(B)に示す配列別メモリ計算データ175において,nは自動計算する分割ブロック長を示す。計算式を生成する配列において,自動計算される分割ブロック長で最適化を行うループの制御変数である添え字の個数をZとすると,配列別メモリ計算データ175の可変部は,nZ で表される。ここでは,Zを指数部と呼ぶ。
The variable part indicates a part where the memory size used by the array changes depending on the value of the automatically calculated divided block length in the memory calculation formula for each array. In the
固定部は,配列別メモリ計算式において,自動計算される分割ブロック長の値によって,配列が使用するメモリサイズが変化しない部分を示している。配列別メモリ計算データ175の固定部は,計算式を生成する配列において固定の分割ブロック長が指定されたループの制御変数が添え字に含まれていない場合には,配列の型サイズの値となる。また,配列別メモリ計算データ175の固定部は,計算式を生成する配列において固定の分割ブロック長が指定されたループの制御変数が添え字に含まれている場合には,その固定のブロック長と配列の型サイズとを掛け合わせた値となる。
The fixed portion indicates a portion where the memory size used by the array does not change depending on the value of the automatically calculated divided block length in the memory calculation formula for each array. The fixed part of the array-specific
なお,ブロッキングを実行しない旨が指定されたループの制御変数である添え字は,配列別メモリ計算式に含めない。また,ブロッキング対象ループ内で値が不変の添え字は,ブロッキングによる最適化の影響を受けないので,配列別メモリ計算式の生成では無視される。 A subscript that is a control variable of a loop in which blocking is not executed is not included in the memory calculation for each array. In addition, subscripts whose values do not change in the blocking target loop are not affected by the optimization due to blocking, and are therefore ignored when generating memory formulas for each array.
例えば,図21(A)に示す多重ループ内の配列A(I,J,K,L)において,添え字Iと添え字Kの2つが,自動計算される分割ブロック長で最適化を行うループの制御変数である。よって,指数部Z=2となり,配列別メモリ計算式における可変部は,n2 となる。また,添え字Jは,固定の分割ブロック長として20が指定されたループの制御変数である。配列Aの型サイズが8バイトであるので,配列別メモリ計算式における固定部は,8(配列の型サイズ)×20(固定の分割ブロック長)=160となる。なお,添え字Lについては,ブロッキングを実行しない旨が指定されたループの制御変数であるので,配列別メモリ計算式における可変部にも固定部にも含まれない。 For example, in the array A (I, J, K, L) in the multiple loop shown in FIG. 21A, a loop in which two subscripts I and K are optimized with the automatically calculated divided block length. Control variable. Therefore, the exponent part Z = 2, and the variable part in the memory calculation formula for each array is n 2 . The subscript J is a control variable of a loop in which 20 is designated as a fixed divided block length. Since the type size of the array A is 8 bytes, the fixed part in the memory calculation formula for each array is 8 (array type size) × 20 (fixed divided block length) = 160. Note that the subscript L is a control variable of a loop in which it is specified that blocking is not executed, and thus is not included in the variable part or the fixed part in the memory calculation formula for each array.
配列別メモリ計算データ175には,可変部の計算結果を示すフィールドに,固定部の計算結果が格納される。すなわち,図21(B)に示すように,可変部の計算結果n2 のフィールドに,固定部の計算結果160が格納される。なお,配列別メモリ計算データ175において,各フィールドの固定部の初期値は0である。
In the
図21(B)に示す配列別メモリ計算データ175が表す配列別メモリ計算式は,
(n0 ×0)+(n1 ×0)+(n2 ×160)+(n3 ×0)+(n4 ×0)
=160n2
となる。この配列別メモリ計算式160n2 が,図21(A)に示す多重ループに対して分割ブロック長nを用いたブロッキングによる最適化を実行した場合の,配列A(I,J,K,L)が使用するメモリサイズを計算する計算式となる。
The memory calculation formula for each array represented by the memory calculation data for each
(N 0 × 0) + (n 1 × 0) + (n 2 × 160) + (n 3 × 0) + (n 4 × 0)
= 160n 2
It becomes. This array memory calculation formula 160n 2 is an array A (I, J, K, L) in the case where optimization by blocking using the divided block length n is performed on the multiple loop shown in FIG. Is a calculation formula for calculating the memory size used.
図22は,本実施の形態による配列別メモリ計算式からのメモリサイズ計算式の生成を説明する図である。 FIG. 22 is a diagram for explaining generation of a memory size calculation formula from an array-specific memory calculation formula according to the present embodiment.
メモリサイズ計算式生成部130は,図11(A)に示すブロッキング対象ループから抽出された各配列について,配列情報記憶部160に記憶された各配列データ165と,ループデータ記憶部200に記憶された各ループデータ210とを用いて,配列別メモリ計算式を生成する。
The memory size calculation
ここでは,配列A,配列B,配列C,配列Dのすべてについて,配列の型としてreal型が宣言されており,すべての配列の型サイズが8バイトであるものとする。 Here, it is assumed that the real type is declared as the array type for all of the arrays A, B, C, and D, and the type size of all the arrays is 8 bytes.
配列A(I,J,K),配列B(J,K,I),配列C(K,I,J)については,すべての添え字がブロッキング対象ループに含まれるループの制御変数であるので,配列別メモリ計算式の可変部はn3 となる。また,ブロッキング対象ループに固定の分割ブロック長が指示されたループがないので,配列別メモリ計算式の固定部は配列の型サイズのみで8となる。なお,ブロッキング対象ループに含まれる各ループのループデータ210におけるブロッキングフラグは,すべて“TRUE”である。よって,配列A(I,J,K),配列B(J,K,I),配列C(K,I,J)の配列別メモリ計算式は,すべて8n3 となる。 For array A (I, J, K), array B (J, K, I), and array C (K, I, J), all subscripts are control variables for the loops included in the blocking target loop. The variable part of the memory calculation formula for each array is n 3 . Further, since there is no loop for which a fixed divided block length is instructed in the blocking target loop, the fixed part of the memory calculation formula for each array is 8 only in the array type size. Note that all blocking flags in the loop data 210 of each loop included in the blocking target loop are “TRUE”. Therefore, the array-specific memory calculation formulas for array A (I, J, K), array B (J, K, I), and array C (K, I, J) are all 8n 3 .
配列D(I,X,J),配列D(I,Y,J)については,それぞれ,添え字X,添え字Yが,ブロッキング対象ループに含まれるループの制御変数ではなく,ブロッキング対象ループ内で不変の値となる。添え字Iと添え字Jはブロッキング対象ループに含まれるループの制御変数であるので,配列別メモリ計算式の可変部はn2 となる。また,ブロッキング対象ループに固定の分割ブロック長が指示されたループがないので,配列別メモリ計算式の固定部は配列の型サイズのみで8となる。よって,配列D(I,X,J),配列D(I,Y,J)の配列別メモリ計算式は,それぞれ8n2 となる。 For array D (I, X, J) and array D (I, Y, J), subscript X and subscript Y are not control variables of the loop included in the blocking target loop, but are in the blocking target loop, respectively. It becomes an invariant value. Since subscript I and subscript J are control variables of the loop included in the blocking target loop, the variable part of the memory calculation formula for each array is n 2 . Further, since there is no loop for which a fixed divided block length is instructed in the blocking target loop, the fixed part of the memory calculation formula for each array is 8 only in the array type size. Therefore, the memory calculation formula for each of the arrays D (I, X, J) and D (I, Y, J) is 8n 2 .
各配列について生成された配列別メモリ計算式を表す配列別メモリ計算データ175は,図22に示す通りとなる。配列別メモリ計算データ175aは,配列A(I,J,K)が使用するメモリサイズを計算する配列別メモリ計算式を表すデータである。配列別メモリ計算データ175bは,配列B(J,K,I)が使用するメモリサイズを計算する配列別メモリ計算式を表すデータである。配列別メモリ計算データ175cは,配列C(K,I,J)が使用するメモリサイズを計算する配列別メモリ計算式を表すデータである。配列別メモリ計算データ175d1 は,配列D(I,X,J)が使用するメモリサイズを計算する配列別メモリ計算式を表すデータである。配列別メモリ計算データ175d2 は,配列D(I,Y,J)が使用するメモリサイズを計算する配列別メモリ計算式を表すデータである。メモリサイズ計算式生成部130は,生成された各配列別メモリ計算データ175を,配列別メモリ計算情報記憶部170に記憶する。
The array-specific
次に,メモリサイズ計算式生成部130は,配列ごとの配列別メモリ計算式から,全配列が使用するメモリサイズを計算するメモリサイズ計算式を生成する。メモリサイズ計算式は,配列ごとに生成されたすべての配列別メモリ計算式を加算することで得られる。
Next, the memory size calculation
図22において,メモリサイズ計算データ185は,メモリサイズ計算式を表すデータである。メモリサイズ計算データ185のデータ構造は,配列別メモリ計算データ175のデータ構造と同様である。
In FIG. 22, memory
メモリサイズ計算式生成部130は,図22に示すように,配列別メモリ計算情報記憶部170に記憶された全配列の配列別メモリ計算データ175の固定部を,メモリサイズ計算データ185上でマージする。なお,メモリサイズ計算データ185において,各フィールドの固定部の初期値は0である。
As shown in FIG. 22, the memory size calculation
このように,メモリサイズ計算式生成部130により,図11に示すブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式を表すデータとして,図22に示すメモリサイズ計算データ185が生成される。メモリサイズ計算式生成部130は,生成されたメモリサイズ計算データ185を,メモリサイズ計算情報記憶部180に記憶する。
As described above, the memory size calculation
図22に示すメモリサイズ計算データ185が表すメモリサイズ計算式は,
(n0 ×0)+(n1 ×0)+(n2 ×16)+(n3 ×24)
=16n2 +24n3
となる。なお,配列の型サイズの単位をバイトで計算しているので,このメモリサイズ計算式で得られるサイズの単位は,バイトである。
The memory size calculation formula represented by the memory
(N 0 × 0) + (n 1 × 0) + (n 2 × 16) + (n 3 × 24)
= 16n 2 + 24n 3
It becomes. Since the unit of the array type size is calculated in bytes, the unit of size obtained by this memory size calculation formula is bytes.
図23は,本実施の形態のメモリサイズ計算式生成部によるメモリサイズ計算式生成処理フローチャートである。 FIG. 23 is a flowchart of a memory size calculation formula generation process by the memory size calculation formula generation unit of the present embodiment.
メモリサイズ計算式生成部130は,配列情報記憶部160に記憶された,ブロッキング対象ループ内から抽出された配列の配列データ165を,1つ選択する(ステップS40)。メモリサイズ計算式生成部130は,選択された配列データ165について,配列別メモリ計算データ生成処理を行う(ステップS41)。配列別メモリ計算データ生成処理の詳細については,後述する。
The memory size calculation
メモリサイズ計算式生成部130は,ブロッキング対象ループ内から抽出されたすべての配列の配列データ165について処理が終了したかを判定する(ステップS42)。すべての配列の配列データ165についてまだ処理が終了していなければ(ステップS42のNO),メモリサイズ計算式生成部130は,ステップS40に戻って次の配列の配列データ165の処理に移る。
The memory size calculation
すべての配列の配列データ165について処理が終了していれば(ステップS42のYES),メモリサイズ計算式生成部130は,生成されたすべての配列別メモリ計算データ175から,固定部に値が格納された可変部における最大の指数部の値を取得する(ステップS43)。メモリサイズ計算式生成部130は,指数部が,0から取得された最大の指数部までの可変部のフィールドを有するメモリサイズ計算データ185を生成する(ステップS44)。
If processing has been completed for array data 165 of all arrays (YES in step S42), the memory size calculation
メモリサイズ計算式生成部130は,配列別メモリ計算データ175を1つ選択する(ステップS45)。メモリサイズ計算式生成部130は,選択された配列別メモリ計算データ175を,メモリサイズ計算データ185にマージする(ステップS46)。
The memory size calculation
メモリサイズ計算式生成部130は,生成されたすべての配列別メモリ計算データ175について処理が終了したかを判定する(ステップS47)。すべての配列別メモリ計算データ175についてまだ処理が終了していなければ(ステップS47のNO),メモリサイズ計算式生成部130は,ステップS45に戻って次の配列別メモリ計算データ175の処理に移る。すべての配列別メモリ計算データ175について処理が終了していれば(ステップS47のYES),メモリサイズ計算式生成部130は,処理を終了する。
The memory size calculation
図24は,本実施の形態のメモリサイズ計算式生成部による配列別メモリ計算データ生成処理フローチャートである。 FIG. 24 is a memory calculation data generation processing flowchart for each array by the memory size calculation formula generation unit of this embodiment.
メモリサイズ計算式生成部130は,aを1に,Zを0に初期化する(ステップS410)。
The memory size calculation
メモリサイズ計算式生成部130は,配列データ165から添え字を1つ選択する(ステップS411)。
The memory size calculation
メモリサイズ計算式生成部130は,ループデータ記憶部200に記憶されたブロッキング対象ループのループデータ210を参照し,選択された添え字がブロッキング対象ループに含まれるループの制御変数であるかを判定する(ステップS412)。選択された添え字が制御変数でなければ(ステップS412のNO),メモリサイズ計算式生成部130は,ステップS417の処理に進む。
The memory size calculation
選択された添え字が制御変数であれば(ステップS412のYES),メモリサイズ計算式生成部130は,選択された添え字を制御変数とするループのループデータ210におけるブロッキングフラグが“TRUE”であるかを判定する(ステップS413)。ブロッキングフラグが“TRUE”でなければ(ステップS413のNO),メモリサイズ計算式生成部130は,ステップS417の処理に進む。
If the selected subscript is a control variable (YES in step S412), the memory size calculation
ブロッキングフラグが“TRUE”であれば(ステップS413のYES),メモリサイズ計算式生成部130は,選択された添え字を制御変数とするループのループデータ210における分割ブロック長に固定の分割ブロック長が設定されているかを判定する(ステップS414)。固定の分割ブロック長が設定されていれば(ステップS414のYES),メモリサイズ計算式生成部130は,aの値を,a×指定された固定の分割ブロック長の値で更新する(ステップS415)。固定の分割ブロック長が指定されていなければ(ステップS414のNO),メモリサイズ計算式生成部130は,Zの値をインクリメントする(ステップS416)。
If the blocking flag is “TRUE” (YES in step S413), the memory size calculation
メモリサイズ計算式生成部130は,配列データ165のすべての添え字について処理が終了したかを判定する(ステップS417)。すべての添え字についてまだ処理が終了していなければ(ステップS417のNO),メモリサイズ計算式生成部130は,ステップS411に戻って次の添え字の処理に移る。
The memory size calculation
すべての添え字について処理が終了していれば(ステップS417のYES),メモリサイズ計算式生成部130は,配列の型サイズbを取得する(ステップS418)。メモリサイズ計算式生成部130は,c=a×bを計算する(ステップS419)。メモリサイズ計算式生成部130は,配列別メモリ計算データ175の可変部がnZ であるフィールドの固定部に,算出されたcを設定する(ステップS420)。
If the processing has been completed for all the subscripts (YES in step S417), the memory size calculation
次に,本実施の形態の分割ブロック長計算部140による処理の例を説明する。
Next, an example of processing performed by the divided block
分割ブロック長計算部140は,メモリサイズ計算式生成部130により生成されたメモリサイズ計算式に,分割ブロック長を入力し,メモリサイズを計算する。このとき,分割ブロック長計算部140は,メモリサイズ計算式に入力する分割ブロック長を小さい値から徐々に大きくしていき,得られたメモリサイズがキャッシュメモリのサイズを超えない,適切な分割ブロック長を求める。
The divided block
図25は,本実施の形態によるメモリサイズ計算式を用いて分割ブロック長を自動計算する例を説明する図である。 FIG. 25 is a diagram illustrating an example in which the divided block length is automatically calculated using the memory size calculation formula according to this embodiment.
図25において,メモリサイズ計算データ185は,図11(A)に示すブロッキング対象ループに基づいて生成された,図22に示すメモリサイズ計算データ185である。すなわち,図25に示すメモリサイズ計算データ185は,メモリサイズ計算式16n2 +24n3 を表すメモリサイズ計算データ185である。
25, the memory
図25において,キャッシュサイズは,コンピュータ1が備える階層型のメモリ3における1次キャッシュメモリのサイズを示す。ここでは,キャッシュサイズが131072バイトであるものとする。
In FIG. 25, the cache size indicates the size of the primary cache memory in the
分割ブロック長計算部140は,メモリサイズ計算データ185のnに,分割ブロック長として仮定した値を入力し,メモリサイズを算出する。分割ブロック長計算部140は,算出されたメモリサイズとキャッシュサイズとを比較し,メモリサイズがキャッシュサイズを超えているかをチェックする。
The divided block
メモリサイズ計算データ185に分割ブロック長と仮定して入力する値は,任意である。本実施の形態では,キャッシュラインやアライメントを意識して,メモリサイズ計算データ185に8の倍数を入力していくものとする。また,図25では,算出されたメモリサイズとキャッシュサイズとの比較結果として,メモリサイズがキャッシュサイズ以下の場合には○が,メモリサイズがキャッシュサイズを超えている場合には×が記載されている。
The value that is input to the memory
まず,分割ブロック長計算部140は,メモリサイズ計算データ185のnに,分割ブロック長として8を入力する。このとき,メモリサイズ計算データ185によって得られるメモリサイズは,13312バイトとなる。算出されたメモリサイズは,キャッシュサイズ以下であるので,比較結果は○となる。
First, the divided block
次に,分割ブロック長計算部140は,メモリサイズ計算データ185のnに,分割ブロック長として16を入力する。このとき,メモリサイズ計算データ185によって得られるメモリサイズは,102400バイトとなる。算出されたメモリサイズは,キャッシュサイズ以下であるので,比較結果は○となる。
Next, the divided block
次に,分割ブロック長計算部140は,メモリサイズ計算データ185のnに,分割ブロック長として24を入力する。このとき,メモリサイズ計算データ185によって得られるメモリサイズは,340992バイトとなる。算出されたメモリサイズは,キャッシュサイズを超えているので,比較結果は×となる。
Next, the divided block
分割ブロック長計算部140は,キャッシュサイズを超えない最大のメモリサイズが得られた入力値16を,図11(A)に示すブロッキング対象ループに対するブロッキングによる最適化で用いる,自動計算された分割ブロック長として決定する。
The divided block
図26は,本実施の形態の分割ブロック長計算部による分割ブロック長計算処理フローチャートである。 FIG. 26 is a divided block length calculation processing flowchart by the divided block length calculation unit of the present embodiment.
分割ブロック長計算部140は,分割ブロック長の値を−1に設定する(ステップS50)。分割ブロック長計算部140は,−1に設定された分割ブロック長を,メモリ3上の退避領域に退避する(ステップS51)。ここまでの処理は,メモリサイズ計算データ185に入力する分割ブロック長の値を初期化する処理である。メモリサイズ計算データ185に最初の分割ブロック長を入力して得られるメモリサイズがキャッシュサイズを超えてしまうような場合には,ブロッキング対象ループに対する自動計算されたブロック長を用いたブロッキングは行われない。そのため,分割ブロック長の初期値として,ブロッキングによる最適化を実行しない旨を示す−1が設定される。
The divided block
分割ブロック長計算部140は,分割ブロック長に最初の入力値を設定する(ステップS52)。分割ブロック長計算部140は,オペレーティングシステム40に対して問い合わせを行い,キャッシュサイズを取得する(ステップS53)。
The divided block
分割ブロック長計算部140は,メモリサイズ計算データ185に分割ブロック長を入力して,メモリサイズを算出する(ステップS54)。分割ブロック長計算部140は,算出されたメモリサイズが,取得されたキャッシュサイズを超えているかを判定する(ステップS55)。
The divided block
メモリサイズがキャッシュサイズを超えていなければ(ステップS55のNO),分割ブロック長計算部140は,分割ブロック長の値をメモリ3上の退避領域に退避する(ステップS56)。この処理で,退避領域に前に退避された分割ブロック長が更新される。分割ブロック長計算部140は,メモリサイズ計算データ185に入力する分割ブロック長の値を増加し(ステップS57),ステップS54に戻って,増加された分割ブロック長の処理に移る。
If the memory size does not exceed the cache size (NO in step S55), the divided block
メモリサイズがキャッシュサイズを超えていれば(ステップS55のYES),分割ブロック長計算部140は,その時点でメモリ3の退避領域に退避されている値を,自動計算された分割ブロック長の値として決定し(ステップS58),処理を終了する。
If the memory size exceeds the cache size (YES in step S55), the divided block
次に,本実施の形態のブロッキング指示部150による処理の例を説明する。
Next, an example of processing by the blocking
ブロッキング指示部150は,分割ブロック長計算部140により決定された分割ブロック長を用いたブロッキングによる最適化実行の指示を行う。より具体的には,ブロッキング指示部150は,ループデータ記憶部200に記憶されたブロッキング対象ループの各ループデータ210における分割ブロック長に対して,自動計算された分割ブロック長の値を設定する。このとき,ブロッキング指示部150は,ループデータ210における分割ブロック長に自動計算を示す0が設定されているものについてのみ,自動計算された分割ブロック長の設定を行う。
The blocking
例えば,本実施の形態では,ブロッキング指示部150は,図12に示すブロッキング対象ループの各ループデータ210における分割ブロック長に対して,図25に示す例で決定された分割ブロック長の値16を設定する。
For example, in the present embodiment, the blocking
図27は,本実施の形態によるブロッキング指示部によるブロッキング指示処理フローチャートである。 FIG. 27 is a flowchart of a blocking instruction process by the blocking instruction unit according to this embodiment.
ブロッキング指示部150は,ループデータ記憶部200に記憶された,ブロッキング対象ループに含まれるループのループデータ210を,1つ選択する(ステップS60)。
The blocking
ブロッキング指示部150は,選択されたループデータ210におけるブロッキングフラグが“TRUE”であるかを判定する(ステップS61)。また,ブロッキング指示部150は,選択されたループデータ210における分割ブロック長に,固定の分割ブロック長が設定されているかを判定する(ステップS62)。
The blocking
ブロッキングフラグが“TRUE”であり(ステップS61のYES),かつ分割ブロック長に固定の分割ブロック長が設定されていない場合には(ステップS62のNO),ブロッキング指示部150は,選択されたループデータ210の分割ブロック長に,自動計算された分割ブロック長の値を設定する(ステップS63)。
When the blocking flag is “TRUE” (YES in step S61) and a fixed divided block length is not set as the divided block length (NO in step S62), the blocking
ブロッキング指示部150は,ブロッキング対象ループに含まれるループのすべてのループデータ210について処理が終了したかを判定する(ステップS64)。すべてのループデータ210についてまだ処理が終了していなければ(ステップS64のNO),ブロッキング指示部150は,ステップS60に戻って次のループデータ210の処理に移る。すべてのループデータ210について処理が終了していれば(ステップS64のYES),ブロッキング指示部150は,処理を終了する。
The blocking
最適化実行部17は,中間コードの一部としてループデータ記憶部200に記憶されたループデータ210における分割ブロック長の値を用いて,ブロッキング対象ループに対するブロッキングによる最適化を実行する。
The
以下,図28〜図31を用いて,本実施の形態のブロッキングによる最適化の具体的な実施例をいくつか説明する。 Hereinafter, some specific examples of optimization by blocking according to the present embodiment will be described with reference to FIGS. 28 to 31.
図28は,本実施の形態のブロッキングによる最適化を3重以上のループに対して実行した例である。 FIG. 28 shows an example in which the optimization by blocking according to the present embodiment is executed for a loop of three or more layers.
図28に示す最適化対象ループは,ループK,ループJ,ループIからなる。図28に示す最適化対象ループは,最内のループI内にのみ演算の実行文を有するタイトなループであるので,処理対象ループ解析部100は,図28に示す最適化対象ループをそのままブロッキング対象ループとする。配列解析部110は,3つの配列を抽出する。アクセスパターン解析部120は,抽出された配列C(K,J)のアクセスパターンがクロスであるので,図28に示す最適化対象ループに対するブロッキングによる最適化が有効であると判定する。
The optimization target loop shown in FIG. 28 includes a loop K, a loop J, and a loop I. Since the optimization target loop shown in FIG. 28 is a tight loop having an execution statement for computation only in the innermost loop I, the processing target
抽出された3つの配列の型は,すべてreal(配列の型サイズは8バイト)で宣言されているものとする。また,3つの配列は,すべてブロッキング対象ループに含まれるループの制御変数を添え字とする,2次元の配列である。メモリサイズ計算式生成部130は,メモリサイズ計算式24n2 を生成する。
The extracted three array types are all declared as real (the array type size is 8 bytes). In addition, the three arrays are two-dimensional arrays in which the control variables of the loops included in the blocking target loop are used as subscripts. The memory size calculation
キャッシュサイズとして,131072バイトが取得されたものとする。分割ブロック長計算部140は,メモリサイズ計算式24n2 に8の倍数を小さい値から順に入力していく。分割ブロック長計算部140は,メモリサイズ計算式24n2 から得られるメモリサイズが,キャッシュサイズを超えない最大のnを,自動計算された分割ブロック長として,決定する。ここでは,n=72のときに得られるメモリサイズ124416バイトが,キャッシュサイズを超えない最大のメモリサイズとなる。
It is assumed that 131072 bytes are acquired as the cache size. The divided block
ブロッキング指示部150は,得られた値72を自動計算される分割ブロック長として,最適化実行部17に指示する。最適化実行部17は,自動計算された分割ブロック長block=72を用いて,図28に示す最適化対象ループに対するブロッキングによる最適化を実行する。図28に示す最適化対象ループに対するブロッキングによる最適化の実行結果として,図28に示すブロッキング後ループが得られる。
The blocking
このように,本実施の形態のブロッキングによる最適化の技術によって,3重ループ以上に対するブロッキングによる最適化が可能となる。 As described above, the optimization by blocking according to the present embodiment enables optimization by blocking with respect to three or more loops.
図29は,本実施の形態のブロッキングによる最適化を3次元以上の配列を含む多重ループに対して実行した例である。 FIG. 29 shows an example in which the optimization by blocking according to the present embodiment is performed on a multiple loop including a three-dimensional array or more.
図29に示す最適化対象ループは,ループK,ループJ,ループIからなる。図29に示す最適化対象ループは,最内のループI内にのみ,3次元の配列を持つ演算の実行文を有するタイトなループであるので,処理対象ループ解析部100は,図29に示す最適化対象ループをそのままブロッキング対象ループとする。配列解析部110は,5つの配列を抽出する。アクセスパターン解析部120は,抽出された配列B(J,K,I)のアクセスパターンがクロスであるので,図29に示す最適化対象ループに対するブロッキングによる最適化が有効であると判定する。
The optimization target loop shown in FIG. 29 includes a loop K, a loop J, and a loop I. Since the optimization target loop shown in FIG. 29 is a tight loop having an execution statement of an operation having a three-dimensional array only in the innermost loop I, the processing target
抽出された5つの配列の型は,すべてreal(配列の型サイズは8バイト)で宣言されているものとする。また,5つの配列のうちの3つは,すべてブロッキング対象ループに含まれるループの制御変数を添え字とする,3次元の配列である。5つの配列のうちの2つは,ブロッキング対象ループに含まれるループの制御変数でない添え字を1つ含む,3次元の配列である。メモリサイズ計算式生成部130は,メモリサイズ計算式16n2 +24n3 を生成する。
The extracted five array types are all declared as real (the array type size is 8 bytes). In addition, three of the five arrays are three-dimensional arrays that have subscripts as control variables of the loops included in the blocking target loop. Two of the five arrays are three-dimensional arrays including one subscript that is not a control variable of a loop included in the blocking target loop. The memory size calculation
キャッシュサイズとして,131072バイトが取得されたものとする。分割ブロック長計算部140は,メモリサイズ計算式16n2 +24n3 に8の倍数を小さい値から順に入力していく。分割ブロック長計算部140は,メモリサイズ計算式16n2 +24n3 から得られるメモリサイズが,キャッシュサイズを超えない最大のnを,自動計算された分割ブロック長として,決定する。ここでは,n=16のときに得られるメモリサイズ102400バイトが,キャッシュサイズを超えない最大のメモリサイズとなる。
It is assumed that 131072 bytes are acquired as the cache size. The divided block
ブロッキング指示部150は,得られた値16を自動計算される分割ブロック長として,最適化実行部17に指示する。最適化実行部17は,自動計算された分割ブロック長block=16を用いて,図29に示す最適化対象ループに対するブロッキングによる最適化を実行する。図29に示す最適化対象ループに対するブロッキングによる最適化の実行結果として,図29に示すブロッキング後ループが得られる。
The blocking
このように,本実施の形態のブロッキングによる最適化の技術によって,3次元以上の配列を含む多重ループに対するブロッキングによる最適化が可能となる。 As described above, the optimization by blocking according to the present embodiment enables the optimization by blocking with respect to multiple loops including arrays of three or more dimensions.
図30は,本実施の形態のブロッキングによる最適化をブロッキング抑止の最適化指示行を含む多重ループに対して実行した例である。 FIG. 30 shows an example in which the optimization by blocking according to the present embodiment is executed for a multiple loop including an optimization instruction line for blocking inhibition.
図30に示す最適化対象ループは,ループK,ループJ,ループIからなる。図30に示す最適化対象ループは,最内のループI内にのみ,2次元の配列を持つ演算の実行文を有するタイトなループであるので,処理対象ループ解析部100は,図30に示す最適化対象ループをそのままブロッキング対象ループとする。配列解析部110は,3つの配列を抽出する。アクセスパターン解析部120は,抽出された配列C(K,J)のアクセスパターンがクロスであるので,図30に示す最適化対象ループに対するブロッキングによる最適化が有効であると判定する。
The optimization target loop shown in FIG. 30 includes a loop K, a loop J, and a loop I. Since the optimization target loop shown in FIG. 30 is a tight loop having an execution statement of an operation having a two-dimensional array only in the innermost loop I, the processing target
抽出された3つの配列の型は,すべてreal(配列の型サイズは8バイト)で宣言されているものとする。また,図30に示す最適化対象ループは,ループJに対するブロッキング抑止の最適化指示行を含んでいる。3つの配列のうちの1つは,すべてブロッキング抑止の対象となっていない,ブロッキング対象ループに含まれるループの制御変数を添え字とする,2次元の配列である。3つの配列のうちの2つは,ブロッキング抑止の対象となっているループの制御変数を1つ含む,すべてブロッキング対象ループに含まれるループの制御変数を添え字とする,2次元の配列である。メモリサイズ計算式生成部130は,メモリサイズ計算式8n2 +16nを生成する。
The extracted three array types are all declared as real (the array type size is 8 bytes). Further, the optimization target loop shown in FIG. 30 includes an optimization instruction line for blocking suppression for the loop J. One of the three arrays is a two-dimensional array in which all of the control variables of the loop included in the blocking target loop are not subscripted and are subscripts. Two of the three arrays are two-dimensional arrays that contain one control variable for the loop that is subject to blocking suppression, and that are subscripted from the control variables for the loops that are all included in the blocking target loop. . The memory size calculation
キャッシュサイズとして,131072バイトが取得されたものとする。分割ブロック長計算部140は,メモリサイズ計算式8n2 +16nに8の倍数を小さい値から順に入力していく。分割ブロック長計算部140は,メモリサイズ計算式8n2 +16nから得られるメモリサイズが,キャッシュサイズを超えない最大のnを,自動計算された分割ブロック長として,決定する。ここでは,n=120のときに得られるメモリサイズ117120バイトが,キャッシュサイズを超えない最大のメモリサイズとなる。
It is assumed that 131072 bytes are acquired as the cache size. The divided block
ブロッキング指示部150は,得られた値120を自動計算される分割ブロック長として,最適化実行部17に指示する。最適化実行部17は,自動計算された分割ブロック長block=120を用いて,図30に示す最適化対象ループに対するブロッキングによる最適化を実行する。このとき,最適化実行部17は,ブロッキング抑止の対象となっているループJに対しては,ブロッキングによる最適化を実行しない。図30に示す最適化対象ループに対するブロッキングによる最適化の実行結果として,図30に示すブロッキング後ループが得られる。
The blocking
このように,本実施の形態のブロッキングによる最適化の技術によって,あらかじめブロッキング抑止が指示されたループを除いた,最適化対象ループに対するブロッキングによる最適化が可能となる。 As described above, the optimization by blocking of the optimization target loop can be performed except for the loop for which blocking suppression is instructed in advance by the optimization technique by blocking according to the present embodiment.
図31は,本実施の形態のブロッキングによる最適化を固定の分割ブロック長の最適化指示行を含む多重ループに対して実行した例である。 FIG. 31 shows an example in which the optimization by blocking according to the present embodiment is performed on a multiple loop including an optimization instruction line having a fixed divided block length.
図31に示す最適化対象ループは,ループK,ループJ,ループIからなる。図31に示す最適化対象ループは,最内のループI内にのみ,2次元の配列を持つ演算の実行文を有するタイトなループであるので,処理対象ループ解析部100は,図31に示す最適化対象ループをそのままブロッキング対象ループとする。配列解析部110は,3つの配列を抽出する。アクセスパターン解析部120は,抽出された配列C(K,J)のアクセスパターンがクロスであるので,図31に示す最適化対象ループに対するブロッキングによる最適化が有効であると判定する。
The optimization target loop shown in FIG. 31 includes a loop K, a loop J, and a loop I. Since the optimization target loop shown in FIG. 31 is a tight loop having an execution statement of an operation having a two-dimensional array only in the innermost loop I, the processing target
抽出された3つの配列の型は,すべてreal(配列の型サイズは8バイト)で宣言されているものとする。また,図31に示す最適化対象ループは,ループJに対して固定の分割ブロック長(値48)を指示した最適化指示行を含んでいる。3つの配列のうちの1つは,すべて固定の分割ブロック長が指示されていない,ブロッキング対象ループに含まれるループの制御変数を添え字とする,2次元の配列である。3つの配列のうちの2つは,固定の分割ブロック長が指示されたループの制御変数を1つ含む,すべてブロッキング対象ループに含まれるループの制御変数を添え字とする,2次元の配列である。メモリサイズ計算式生成部130は,メモリサイズ計算式8n2 +768nを生成する。
The extracted three array types are all declared as real (the array type size is 8 bytes). Further, the optimization target loop shown in FIG. 31 includes an optimization instruction row instructing a fixed divided block length (value 48) for the loop J. One of the three arrays is a two-dimensional array in which a fixed variable block length is not specified and the control variable of the loop included in the blocking target loop is used as a subscript. Two of the three arrays are two-dimensional arrays that contain one control variable for the loop for which a fixed division block length is specified and that are subscripted from the control variables for the loops that are all included in the blocking target loop. is there. The memory size calculation
キャッシュサイズとして,131072バイトが取得されたものとする。分割ブロック長計算部140は,メモリサイズ計算式8n2 +768nに8の倍数を小さい値から順に入力していく。分割ブロック長計算部140は,メモリサイズ計算式8n2 +768nから得られるメモリサイズが,キャッシュサイズを超えない最大のnを,自動計算された分割ブロック長として,決定する。ここでは,n=88のときに得られるメモリサイズ129536バイトが,キャッシュサイズを超えない最大のメモリサイズとなる。
It is assumed that 131072 bytes are acquired as the cache size. The divided block
ブロッキング指示部150は,得られた値88を自動計算される分割ブロック長として,最適化実行部17に指示する。最適化実行部17は,自動計算された分割ブロック長block=88を用いて,図31に示す最適化対象ループに対するブロッキングによる最適化を実行する。このとき,最適化実行部17は,固定の分割ブロック長が指示されたループJに対しては,その指示された固定の分割ブロック長の値48を用いて,ブロッキングによる最適化を実行する。図31に示す最適化対象ループに対するブロッキングによる最適化の実行結果として,図31に示すブロッキング後ループが得られる。
The blocking
このように,本実施の形態のブロッキングによる最適化の技術によって,あらかじめ固定の分割ブロック長が指示されたループにはそれを用いて,それ以外のループには自動計算された分割ブロック長を用いて,最適化対象ループに対するブロッキングによる最適化が可能となる。 As described above, by using the optimization technique based on blocking according to the present embodiment, the fixed division block length is used in advance for the loop, and the automatically calculated division block length is used for other loops. Therefore, it is possible to optimize the loop to be optimized by blocking.
以上説明した本実施の形態の最適化処理部15による処理は,コンピュータが備えるCPU,メモリ等のハードウェアとソフトウェアプログラムとにより実現することができ,そのプログラムをコンピュータ読み取り可能な記録媒体に記録することも,ネットワークを通して提供することも可能である。
The processing by the
以上,本実施の形態について説明したが,本発明はその主旨の範囲において種々の変形が可能であることは当然である。 Although the present embodiment has been described above, the present invention can naturally be modified in various ways within the scope of the gist thereof.
1 コンピュータ
2 CPU
3 メモリ
4 HDD
5 入力装置
6 表示装置
10 コンパイラ
11 ソースプログラム入力部
12 入出力制御部
13 中間言語生成部
14 中間言語記憶部
200 ループデータ記憶部
15 最適化処理部
16 ソース解析部
100 処理対象ループ解析部
110 配列解析部
120 アクセスパターン解析部
130 メモリサイズ計算式生成部
140 分割ブロック長計算部
150 ブロッキング指示部
160 配列情報記憶部
170 配列別メモリ計算情報記憶部
180 メモリサイズ計算情報記憶部
17 最適化実行部
18 コード生成部
19 オブジェクトファイル出力部
20 記憶部
21 ソースプログラム
22 オブジェクトファイル
23 実行ファイル
30 リンカ
40 オペレーティングシステム
1
3 Memory 4 HDD
DESCRIPTION OF
Claims (5)
前記コンピュータに,
前記ソースプログラムに含まれる多重ループから,最内ループにのみ実行文を有する構造のループを,ブロッキング対象ループとして抽出する手順と,
前記ブロッキング対象ループ内に存在する配列を抽出する手順と,
前記抽出された配列の中に,添え字として出現する制御変数の順序が,前記ブロッキング対象ループの最内ループから最外ループに向かって出現する制御変数の順序と異なる配列が存在する場合に,前記ブロッキング対象ループに対するブロッキングが有効であると判定する手順と,
ブロッキングが有効であると判定された前記ブロッキング対象ループについて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で配列が使用するメモリサイズを算出する計算式を,前記配列ごとに生成する手順と,
前記配列ごとに生成された計算式から,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で前記ブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式を生成する手順と,
前記全配列が使用するメモリサイズを計算する計算式を用いて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で,配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する手順と,
前記自動計算された分割ブロック長を用いて,前記ブロッキング対象ループに対するブロッキングによる最適化を行う手順とを
実行させるための最適化処理プログラム。 In a compiler for compiling a source program written in a programming language, a program for causing a computer to perform optimization processing by blocking multiple loops included in the source program,
In the computer,
A procedure for extracting, from the multiple loops included in the source program, a loop having a structure having an executable statement only in the innermost loop as a blocking target loop;
Extracting a sequence present in the blocking loop;
In the extracted array, if there is an array in which the order of control variables appearing as subscripts is different from the order of control variables appearing from the innermost loop to the outermost loop of the blocking target loop, A procedure for determining that blocking for the blocking target loop is effective;
A procedure for generating, for each array, a calculation formula for calculating a memory size used by the array in a range optimized by blocking with respect to the blocking target loop for the blocking target loop determined to be effective.
Generating a calculation formula for calculating a memory size used by all the arrays in the blocking target loop from a calculation formula generated for each array in a range optimized by blocking with respect to the blocking target loop;
A procedure for automatically calculating a divided block length in which a cache miss does not occur due to access to an array within a range optimized by blocking for the blocking target loop, using a calculation formula for calculating a memory size used by all the arrays;
An optimization processing program for executing a procedure for performing optimization by blocking on the blocking target loop using the automatically calculated divided block length.
前記ブロッキングによる最適化を行う手順では,前記自動計算された分割ブロック長を用いて,前記ブロッキングを実行しない旨が指示されたループを除外して,前記ブロッキング対象ループに対するブロッキングによる最適化を行う
ことを特徴とする請求項1に記載された最適化処理プログラム。 In the procedure for generating the calculation formula for each array, the blocking target loop that is determined to be effective for blocking is optimized by blocking the blocking target loop except the loop instructed not to execute blocking. Generate a calculation formula for each array to calculate the memory size used by the array
In the procedure for performing the optimization by blocking, using the automatically calculated divided block length, the loop instructed not to execute the blocking is excluded, and the blocking target loop is optimized by the blocking. The optimization processing program according to claim 1, wherein:
前記ブロッキングによる最適化を行う手順では,前記ブロッキング対象ループに含まれる前記固定の分割ブロック長が指示されたループに対しては,前記指示された固定のブロック長を用いてブロッキングによる最適化を行い,前記ブロッキング対象ループに含まれる前記固定の分割ブロック長が指示されていないループに対しては,前記自動計算された分割ブロック長を用いてブロッキングによる最適化を行う
ことを特徴とする請求項1または請求項2に記載された最適化処理プログラム。 In the procedure for generating the calculation formula for each array, the blocking target loop that is determined to be effective for blocking is optimized by blocking the blocking target loop including a loop in which a fixed division block length is indicated. Generate a calculation formula for each array to calculate the memory size used by the array in the range,
In the procedure for performing the optimization by blocking, for the loop designated by the fixed divided block length included in the loop to be blocked, optimization by blocking is performed using the designated fixed block length. The optimization by blocking is performed using the automatically calculated divided block length for a loop in which the fixed divided block length included in the blocking target loop is not specified. Alternatively, the optimization processing program according to claim 2.
前記ソースプログラムに含まれる多重ループから,最内ループにのみ実行文を有する構造のループを,ブロッキング対象ループとして抽出する処理対象ループ解析部と,
前記ブロッキング対象ループ内に存在する配列を抽出する配列解析部と,
前記抽出された配列の中に,添え字として出現する制御変数の順序が,前記ブロッキング対象ループの最内ループから最外ループに向かって出現する制御変数の順序と異なる配列が存在する場合に,前記ブロッキング対象ループに対するブロッキングが有効であると判定するアクセスパターン解析部と,
ブロッキングが有効であると判定された前記ブロッキング対象ループについて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で配列が使用するメモリサイズを算出する計算式を,前記配列ごとに生成し,その配列ごとに生成された計算式から,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で前記ブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式を生成するメモリサイズ計算式生成部と,
前記全配列が使用するメモリサイズを計算する計算式を用いて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で,配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する分割ブロック長計算部と,
前記自動計算された分割ブロック長を用いて,前記ブロッキング対象ループに対するブロッキングによる最適化を行う最適化実行部とを備える
ことを特徴とする最適化処理装置。 In a compiler for compiling a source program described in a programming language, an optimization processing device that executes optimization processing by blocking against multiple loops included in the source program,
A processing target loop analysis unit that extracts a loop having an executable statement only in the innermost loop as a blocking target loop from the multiple loops included in the source program;
A sequence analysis unit for extracting a sequence existing in the blocking target loop;
In the extracted array, if there is an array in which the order of control variables appearing as subscripts is different from the order of control variables appearing from the innermost loop to the outermost loop of the blocking target loop, An access pattern analyzer that determines that blocking is effective for the blocking loop;
For each of the arrays for which the blocking is determined to be effective, a calculation formula for calculating the memory size used by the array within a range optimized by the blocking for the blocking target loop is generated for each array. A memory size calculation formula generation unit that generates a calculation formula for calculating a memory size used by all the arrays in the blocking target loop within a range optimized by blocking with respect to the blocking target loop, from the calculation formula generated for each block; ,
Divided block length that automatically calculates a divided block length that does not cause a cache miss due to access to the array within a range optimized by blocking for the blocking target loop, using a calculation formula that calculates the memory size used by the entire array A calculation unit;
An optimization processing device comprising: an optimization execution unit that performs optimization by blocking the blocking target loop using the automatically calculated divided block length.
前記コンピュータが,
前記ソースプログラムに含まれる多重ループから,最内ループにのみ実行文を有する構造のループを,ブロッキング対象ループとして抽出する過程と,
前記ブロッキング対象ループ内に存在する配列を抽出する過程と,
前記抽出された配列の中に,添え字として出現する制御変数の順序が前記ブロッキング対象ループの最内ループから最外ループに向かって出現する制御変数の順序と異なる配列が存在する場合に,前記ブロッキング対象ループに対するブロッキングが有効であると判定する過程と,
ブロッキングが有効であると判定された前記ブロッキング対象ループについて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で配列が使用するメモリサイズを算出する計算式を,前記配列ごとに生成する過程と,
前記配列ごとに生成された計算式から,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で前記ブロッキング対象ループ内の全配列が使用するメモリサイズを計算する計算式を生成する過程と,
前記全配列が使用するメモリサイズを計算する計算式を用いて,前記ブロッキング対象ループに対するブロッキングによって最適化される範囲で,配列に対するアクセスによってキャッシュミスが発生しない分割ブロック長を自動計算する過程と,
前記自動計算された分割ブロック長を用いて,前記ブロッキング対象ループに対するブロッキングによる最適化を行う過程とを実行する
ことを特徴とする最適化処理方法。 In a compiler that compiles a source program written in a programming language, an optimization processing method in which a computer executes optimization processing by blocking against multiple loops included in the source program,
The computer is
Extracting a loop having a structure having an executable statement only in the innermost loop as a blocking target loop from multiple loops included in the source program;
Extracting a sequence present in the blocking loop;
When there is an array in the extracted array in which the order of control variables appearing as subscripts is different from the order of control variables appearing from the innermost loop to the outermost loop of the blocking target loop, A process for determining that blocking is effective for a blocking target loop;
A step of generating, for each array, a calculation formula for calculating a memory size used by the array within a range optimized by blocking with respect to the blocking target loop for the blocking target loop determined to be effective;
Generating a calculation formula for calculating a memory size used by all the arrays in the blocking target loop from a calculation formula generated for each array in a range optimized by blocking with respect to the blocking target loop;
A process of automatically calculating a divided block length in which a cache miss does not occur due to an access to an array within a range optimized by blocking for the blocking target loop, using a calculation formula for calculating a memory size used by the entire array;
The optimization processing method is characterized in that, using the automatically calculated divided block length, a process of performing optimization by blocking the blocking target loop is executed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2010062312A JP5402746B2 (en) | 2010-03-18 | 2010-03-18 | Optimization processing program, optimization processing apparatus, and optimization processing method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2010062312A JP5402746B2 (en) | 2010-03-18 | 2010-03-18 | Optimization processing program, optimization processing apparatus, and optimization processing method |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2011197876A true JP2011197876A (en) | 2011-10-06 |
JP5402746B2 JP5402746B2 (en) | 2014-01-29 |
Family
ID=44876022
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2010062312A Expired - Fee Related JP5402746B2 (en) | 2010-03-18 | 2010-03-18 | Optimization processing program, optimization processing apparatus, and optimization processing method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP5402746B2 (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2020524318A (en) * | 2017-06-19 | 2020-08-13 | グーグル エルエルシー | Alternate loop limit |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH05265770A (en) * | 1992-03-18 | 1993-10-15 | Fujitsu Ltd | Computer language processing method |
JPH09128245A (en) * | 1995-10-30 | 1997-05-16 | Hitachi Ltd | Compiling processing system |
-
2010
- 2010-03-18 JP JP2010062312A patent/JP5402746B2/en not_active Expired - Fee Related
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH05265770A (en) * | 1992-03-18 | 1993-10-15 | Fujitsu Ltd | Computer language processing method |
JPH09128245A (en) * | 1995-10-30 | 1997-05-16 | Hitachi Ltd | Compiling processing system |
Non-Patent Citations (2)
Title |
---|
CSNG200400319001; 寒川 光: '並列性の追及-プログラマから見たRISC計算機の内側-' 並列処理シンポジウム JSPP2001 招待講演、チュートリアル資料, 20010608, pp.16〜17 * |
JPN6013048174; 寒川 光: '並列性の追及-プログラマから見たRISC計算機の内側-' 並列処理シンポジウム JSPP2001 招待講演、チュートリアル資料, 20010608, pp.16〜17 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2020524318A (en) * | 2017-06-19 | 2020-08-13 | グーグル エルエルシー | Alternate loop limit |
JP7035080B2 (en) | 2017-06-19 | 2022-03-14 | グーグル エルエルシー | Alternate loop limit |
Also Published As
Publication number | Publication date |
---|---|
JP5402746B2 (en) | 2014-01-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11048502B1 (en) | Systems, devices, and methods for source code generation from binary files | |
Sagarna et al. | Scatter search in software testing, comparison and collaboration with estimation of distribution algorithms | |
Han et al. | Exploiting locality for irregular scientific codes | |
CN102314370B (en) | Indexable type converts | |
Davis et al. | Performance assessment of OpenMP compilers targeting NVIDIA V100 GPUs | |
JP6384331B2 (en) | Information processing apparatus, information processing method, and information processing program | |
KR20140001864A (en) | Tile communication operator | |
TW201303730A (en) | Vectorization of scalar functions including vectorization annotations and vectorized function signatures matching | |
Oancea et al. | Financial software on GPUs: between Haskell and Fortran | |
JP7355123B2 (en) | Program generation device, program generation method, and program | |
Singh et al. | SWAPPER: A framework for automatic generation of formula simplifiers based on conditional rewrite rules | |
JP5402746B2 (en) | Optimization processing program, optimization processing apparatus, and optimization processing method | |
JP6366033B2 (en) | Optimization method of IF statement in program | |
JP2005122481A (en) | Compiler system and linker system | |
JP7310943B2 (en) | Program generation device, program generation method and program | |
US20170206068A1 (en) | Program optimization based on directives for intermediate code | |
JP5244750B2 (en) | Test case generation apparatus and method | |
CN112558977A (en) | Polyhedron optimization method for heterogeneous many-core rear-end cost-based model | |
Wang et al. | A learning algorithm for Bayesian networks and its efficient implementation on GPUs | |
Ren et al. | Nuwa: a quantum circuit transpiler based on a finite-horizon heuristic for placement and routing | |
JP2009301453A (en) | Distributed memory type multiprocessor system, masked reverse shift communication method and program | |
Pietroń et al. | GPGPU for difficult black-box problems | |
Marrero et al. | DIGNEA: A tool to generate diverse and discriminatory instance suites for optimisation domains | |
Voglis et al. | p-MEMPSODE: Parallel and irregular memetic global optimization | |
Dal et al. | Investigation of the impact of different versions of GCC on various metaheuristic-based solvers for traveling salesman problem |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20130108 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20130826 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20131001 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20131014 |
|
R150 | Certificate of patent or registration of utility model |
Ref document number: 5402746 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
LAPS | Cancellation because of no payment of annual fees |