JP6897213B2 - Code generator, code generator and code generator - Google Patents
Code generator, code generator and code generator Download PDFInfo
- Publication number
- JP6897213B2 JP6897213B2 JP2017058550A JP2017058550A JP6897213B2 JP 6897213 B2 JP6897213 B2 JP 6897213B2 JP 2017058550 A JP2017058550 A JP 2017058550A JP 2017058550 A JP2017058550 A JP 2017058550A JP 6897213 B2 JP6897213 B2 JP 6897213B2
- Authority
- JP
- Japan
- Prior art keywords
- instruction
- instructions
- code
- fma
- dependency
- 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.)
- Active
Links
Images
Description
本開示は、プロセッサにおいて実行可能なコードを生成する技術に関する。 The present disclosure relates to techniques for generating code that can be executed on a processor.
近年の情報処理装置(コンピュータ等)においては、SIMD(Single Instruction Multiple Data)命令を実行可能なプロセッサが用いられることがある。SIMD(Single Instruction Multiple Data)命令は、複数のデータに対して、同じ演算処理を並列に実行可能な命令(並列実行命令)である。SIMD命令の使用は、少ない数の命令を用いて複数のデータに関する演算を実行することを可能とする。 In recent information processing devices (computers and the like), a processor capable of executing SIMD (Single Instruction Multiple Data) instructions may be used. The SIMD (Single Instruction Multiple Data) instruction is an instruction (parallel execution instruction) capable of executing the same arithmetic processing in parallel for a plurality of data. The use of SIMD instructions makes it possible to perform operations on multiple data with a small number of instructions.
SIMD演算命令を用いる技術として、以下の技術が知られている。 The following techniques are known as techniques that use SIMD operation instructions.
特許文献1には、高級言語を用いて記述されたソースコードを中間表現に変換する過程において、異なるデータに対して同じ演算を適用している箇所をみつけ、SIMD命令に置き換える技術が記載されている。
特許文献2には、ソースコードの依存関係を示す演算木を生成し、各演算木に含まれる演算命令を並べた演算列から共通するサブ演算列を抽出し、サブ演算列に含まれる命令を組合せてSIMD命令を生成する技術が記載されている。 In Patent Document 2, a calculation tree showing the dependency of the source code is generated, a common sub-operation string is extracted from the operation sequence in which the operation instructions included in each operation tree are arranged, and the instructions included in the sub-operation string are used. Techniques for generating SIMD instructions in combination are described.
特許文献3には、ソースコードをコンパイルする際に命令間の依存関係を示すツリーを生成し、そのツリーの一部を、複合演算命令に置き換える技術が記載されている。
あるプログラムにおいて、同じ種類の複数の演算命令に依存関係(例えば、ある演算命令の結果を、他の演算命令が参照する関係、等)がなく、並列に実行可能な場合を想定する。この場合、これらの命令を組合せて、SIMD命令を生成することができる。例えば、上記特許文献1は、複数のデータに対して同じ演算命令が実行される場合、当該命令をSIMD命令に置き換える。
In a certain program, it is assumed that a plurality of arithmetic instructions of the same type have no dependency (for example, a relation in which the result of one arithmetic instruction is referred to by another arithmetic instruction) and can be executed in parallel. In this case, these instructions can be combined to generate a SIMD instruction. For example, in
一方、例えば、あるプログラムにおいて、同じ種類の演算命令の間に依存関係がある場合や、異なる演算命令(例えば、加減算と乗算)が連続して実行されるような場合、これらの演算命令は、必ずしも単純にSIMD命令に置き換え可能とは限らない。 On the other hand, for example, in a program, when there is a dependency between the same type of arithmetic instructions, or when different arithmetic instructions (for example, addition / subtraction and multiplication) are executed consecutively, these arithmetic instructions are used. It is not always possible to simply replace it with a SIMD instruction.
又、上記特許文献2、特許文献3に記載された方法は、プログラムの中に含まれる、ある特定の命令の組合せ(乗算命令とその乗算結果を参照する加算命令との組合せ)を積和命令(FMA(Fused Multiply and add)命令)に置き換え可能な場合に限り、係るFMA命令をSIMD命令として並列に実行可能である。即ち、これらの技術を採用した場合、SIMD命令に変換可能な命令が限定される。以上より、プログラムにおいて異なる命令を含む部分については、例えばSIMD命令を用いた実行効率の向上が困難な場合がある、という問題があった。
Further, in the method described in
本開示に係る技術は、上記のような状況を鑑みて着想されたものである。本開示に係る技術は、異なる複数の種類の命令を含むプログラムの実行効率を向上する技術を提供することを、主たる目的の1つとする。 The technology according to the present disclosure was conceived in view of the above circumstances. One of the main purposes of the technique according to the present disclosure is to provide a technique for improving the execution efficiency of a program including a plurality of different types of instructions.
本開示に係る技術の1つの態様であるコード生成装置は、コンピュータ・プログラムである解析対象コードに含まれる1以上の演算命令のうち、命令の種類が異なる上記演算命令の間の依存関係に基づいて、複数のデータに対して、異なる種類の演算を1つの命令として実行可能な融合演算命令を並列に実行可能な並列実行命令に変換可能か否かを判定するコード解析部と、上記コード解析部により、上記並列実行命令に変換可能であると判定された上記演算命令を上記融合演算命令に変換してから、その上記融合演算命令のオペランドが、上記並列実行命令として実行可能な形式に配置されたデータを生成することで、上記融合演算命令を並列に実行する上記並列実行命令を生成する命令生成部と、を備える。 The code generator, which is one aspect of the technique according to the present disclosure, is based on the dependency between the operation instructions of different types among one or more operation instructions included in the analysis target code which is a computer program. A code analysis unit that determines whether or not a fusion operation instruction that can execute different types of operations as one instruction can be converted into a parallel execution instruction that can be executed in parallel for a plurality of data, and the above code analysis. After converting the operation instruction determined to be convertible to the parallel execution instruction by the unit into the fusion operation instruction, the operand of the fusion operation instruction is arranged in a format that can be executed as the parallel execution instruction. It includes an instruction generation unit that generates the parallel execution instruction that executes the fusion operation instruction in parallel by generating the generated data.
本開示に係る技術の1つの態様であるコード生成方法は、複数の演算命令により構成されるコンピュータ・プログラムである解析対象コードに含まれる1以上の演算命令を、上記演算命令の種類と、上記演算命令の間の依存関係とに基づいて、複数のデータに対して、異なる種類の演算を1つの命令として実行可能な融合演算命令を並列に実行可能な並列実行命令に変換可能か否かを判定し、
上記並列実行命令に変換可能であると判定された上記演算命令を上記融合演算命令に変換してから、その上記融合演算命令のオペランドが、上記並列実行命令として実行可能な形式に配置されたデータを生成することで、上記融合演算命令を並列に実行する上記並列実行命令を生成することを含む。
In the code generation method, which is one aspect of the technique according to the present disclosure, one or more arithmetic instructions included in the analysis target code, which is a computer program composed of a plurality of arithmetic instructions, are divided into the above operation instruction types and the above Whether or not a fusion operation instruction that can execute different types of operations as one instruction can be converted into a parallel execution instruction that can be executed in parallel for a plurality of data based on the dependency between the operation instructions. Judge,
Data in which the operand of the fusion operation instruction is arranged in a format that can be executed as the parallel execution instruction after the operation instruction determined to be convertible to the parallel execution instruction is converted into the fusion operation instruction. Is included to generate the parallel execution instruction that executes the fusion operation instruction in parallel.
また、上記目的は、上記構成を有するコード生成装置、及び、対応するコード生成方法をコンピュータによって実現するコンピュータ・プログラム、及び、そのコンピュータ・プログラムが格納されているコンピュータ読み取り可能な記憶媒体によっても達成される。 The above object is also achieved by a code generator having the above configuration, a computer program that realizes the corresponding code generation method by a computer, and a computer-readable storage medium in which the computer program is stored. Will be done.
本開示に係る技術によれば、異なる複数の種類の命令を含むプログラムの実行効率を向上することが可能である。 According to the technique according to the present disclosure, it is possible to improve the execution efficiency of a program including a plurality of different types of instructions.
まず、本開示に関する技術的な検討事項等について、より詳細に説明する。 First, the technical matters to be examined regarding the present disclosure will be described in more detail.
一般的に、SIMD命令は、図1に例示するように、複数のデータに対して、一つの命令で同じ演算処理を並列に(同時に)実行可能である。図1に示す具体例の場合、1つのSIMD命令により、4つのデータに関する加算処理が実行される。 In general, the SIMD instruction can execute the same arithmetic processing in parallel (simultaneously) with one instruction for a plurality of data as illustrated in FIG. In the case of the specific example shown in FIG. 1, one SIMD instruction executes addition processing for four data.
このように、SIMD命令を用いることにより、複数のデータに対する演算処理を、少ない数の命令を用いて実行できる。これより、コードサイズが低減され、プログラムの実行時間が改善される。 In this way, by using the SIMD instruction, it is possible to execute arithmetic processing on a plurality of data using a small number of instructions. This reduces the code size and improves the execution time of the program.
例えば、図2に例示するように、あるコードが2つの加算命令を含む場合、ある種のコンパイラは、これらの命令を、2つの加算を並行して(同時に)実行するSIMD命令に変換することが可能である。一方、図3に例示するように、異なる命令(図3の場合は、加算命令と乗算命令)の組については、典型的には、これらの命令をSIMD命令に直接的には変換できない場合が多い。この場合、各々の命令が逐次的に実行される。即ち、この場合、SIMD命令を用いてプログラムの実行効率を改善することが困難である。 For example, as illustrated in FIG. 2, if a code contains two add instructions, some compilers may convert these instructions into SIMD instructions that execute the two additions in parallel (simultaneously). Is possible. On the other hand, as illustrated in FIG. 3, for a set of different instructions (in the case of FIG. 3, an addition instruction and a multiplication instruction), it may not be possible to directly convert these instructions into SIMD instructions. There are many. In this case, each instruction is executed sequentially. That is, in this case, it is difficult to improve the execution efficiency of the program by using the SIMD instruction.
本開示に係る技術は、上記のような事情から着想を得ており、異なる種類の命令をSIMD命令として実行可能なコード(例えば、オブジェクトコード、実行コード等のプログラム)を生成することで、コードのサイズを低減する。また、これによりプログラムの実行時間が改善される。 The technology according to the present disclosure is inspired by the above circumstances, and is coded by generating code (for example, a program such as object code or execution code) that can execute different types of instructions as SIMD instructions. Reduce the size of. This also improves the execution time of the program.
以下の各実施形態を用いて、以下、各実施形態を用いて、本開示に係る技術を実現可能な、コード生成装置、コード生成方法等について詳細に説明する。 Using each of the following embodiments, a code generation device, a code generation method, and the like that can realize the technique according to the present disclosure will be described in detail below using each embodiment.
以下の各実施形態においては、SIMD命令を実行可能な演算器、より具体的には、SIMD型の融合演算(例えば、FMA演算等)を実行可能な演算器(例えば、SIMD型FMA演算器)を有するプロセッサ向けのコード(オブジェクトコード、実行コード等)を生成する技術について説明する。 In each of the following embodiments, an arithmetic unit capable of executing SIMD instructions, more specifically, an arithmetic unit capable of executing SIMD-type fusion operations (for example, FMA operations) (for example, SIMD-type FMA arithmetic units). The technique for generating the code (object code, execution code, etc.) for the processor having the above will be described.
融合演算は、例えば、FMA演算のように、複数種類の演算を1つの演算として実行するような演算である。SIMD型の融合演算を実行可能な演算器は、融合演算を表す命令(融合演算命令)を、1つの命令として実行可能である。以下においては、説明の便宜上、融合演算としてFMA演算を用いる構成を例示する。なお、本開示に係る技術は、これには限定されず、FMA演算以外の融合演算が用いられてもよい。以下、SIMD型FMA演算器を用いる命令を、SIMD−FMA命令と記載することがある。 The fusion operation is an operation that executes a plurality of types of operations as one operation, such as an FMA operation. An arithmetic unit capable of executing a SIMD type fusion operation can execute an instruction representing a fusion operation (fusion operation instruction) as one instruction. In the following, for convenience of explanation, a configuration in which the FMA operation is used as the fusion operation will be illustrated. The technique according to the present disclosure is not limited to this, and a fusion operation other than the FMA operation may be used. Hereinafter, an instruction using a SIMD type FMA arithmetic unit may be described as a SIMD-FMA instruction.
FMA演算器は乗算器と加算器とを含むよう構成され、積和演算を1命令で実行可能な演算器である。積和演算は、例えば、((A*B)+C)という形式の演算(乗算の結果を加算する演算)である。SIMD型FMA演算器は、複数(例えば2つ)の組のFMA演算を、1命令で処理可能な演算器である。 The FMA arithmetic unit is configured to include a multiplier and an adder, and is an arithmetic unit capable of executing a product-sum operation with one instruction. The product-sum operation is, for example, an operation of the form ((A * B) + C) (an operation of adding the results of multiplication). The SIMD type FMA arithmetic unit is an arithmetic unit capable of processing a plurality of (for example, two) sets of FMA operations with one instruction.
本開示に係る技術は、例えば、解析対象のコード(例えば、ソースコード等)に含まれる演算命令の種類と依存関係とに応じて、それらの演算命令をSIMD−FMA命令に変換可能か否かを判定することを可能とする。そして、その判定結果に基づいて、それらの演算命令を、SIMD−FMA命令に変換することを可能とする。また、この際、本開示に係る技術は、SIMD−FMA命令により処理されるデータ(オペランド)を、SIMD−FMA命令により参照されるレジスタに配置可能な形式にまとめる(パックする)ことが可能である。 Whether or not the technique according to the present disclosure can convert those arithmetic instructions into SIMD-FMA instructions according to, for example, the types and dependencies of the arithmetic instructions included in the code to be analyzed (for example, source code, etc.). Can be determined. Then, based on the determination result, it is possible to convert those arithmetic instructions into SIMD-FMA instructions. Further, at this time, the technique according to the present disclosure can collect (pack) the data (operand) processed by the SIMD-FMA instruction in a format that can be arranged in the register referenced by the SIMD-FMA instruction. is there.
以下、本開示に係る技術を実現可能な実施形態について説明する。以下の各実施形態に記載されている装置等の構成は例示であり、本開示に係る技術の範囲はそれらには限定されない。以下の各実施形態における装置を構成する構成要素の区分け(例えば、機能的な単位による分割)は、本開示に係る技術を実現可能な一例である。本開示に係る技術の実現に際しては、以下の例示に限定されず、様々な構成が想定される。即ち、以下の各実施形態に例示する各構成要素は、更に分割されてもよい。また、以下の各実施形態における1以上の構成要素が、統合されてもよい。 Hereinafter, embodiments in which the technology according to the present disclosure can be realized will be described. The configurations of the devices and the like described in each of the following embodiments are examples, and the scope of the technology according to the present disclosure is not limited thereto. The division of the components constituting the apparatus in each of the following embodiments (for example, division by functional units) is an example in which the technique according to the present disclosure can be realized. In realizing the technology according to the present disclosure, various configurations are assumed without being limited to the following examples. That is, each component illustrated in each of the following embodiments may be further divided. In addition, one or more components in each of the following embodiments may be integrated.
本開示に係る技術は、単体の装置(物理的及び仮想的な装置)を用いて実現されてもよく、複数の離間した装置(物理的及び仮想的な装置)を用いて実現されてもよい。本開示に係る技術が複数の装置により実現される場合、各装置は有線、無線、又はそれらを適切に組合せた通信ネットワークにより通信可能に接続されてもよい。係る通信ネットワークは、物理的な通信ネットワークであってもよく、仮想的な通信ネットワークであってもよい。以下において説明する各実施形態を実現可能なハードウェア構成については、後述する。 The technique according to the present disclosure may be realized by using a single device (physical and virtual device), or may be realized by using a plurality of separated devices (physical and virtual device). .. When the technology according to the present disclosure is realized by a plurality of devices, each device may be communicably connected by a communication network that is wired, wireless, or a combination thereof. The communication network may be a physical communication network or a virtual communication network. The hardware configuration that can realize each of the embodiments described below will be described later.
<第1の実施形態>
以下、本開示に係る技術の第1の実施形態について説明する。
<First Embodiment>
Hereinafter, the first embodiment of the technique according to the present disclosure will be described.
[構成]
図4は、本実施形態におけるコード生成装置100の機能的な構成を例示するブロック図である。図4に例示するように、コード生成装置100は、コンパイラ101を備える。コード生成装置100は、更に、ファイル管理部104を備えてもよい。コード生成装置100を構成するこれらの構成要素の間は、適切な方法(例えば、プロセス間通信、共有メモリ、各種API(Application Programming Interface)等)を用いて、相互に通信可能に接続されていてもよい。以下、各構成要素について説明する。
[Constitution]
FIG. 4 is a block diagram illustrating a functional configuration of the
コンパイラ101は、ソースコードを入力として受け付け、字句解析処理、構文解析処理、意味解析処理、オブジェクトのコード生成処理、等を実行する。これにより、コンパイラ101は、ソースコードをオブジェクトコードに変換(コンパイル)する。この際、コンパイラ101は、例えば、オブジェクトコードのサイズの低減、オブジェクトコードから最終的に生成される実行コードの実行速度の改善、などを目的とした最適化処理を実行することができる。以下、係る最適化処理を実行可能な構成要素について説明する。
The
コンパイラ101は、コード解析部102と、命令生成部103と、を有する。
The
以下、コード解析部102がソースコード又は中間コード(ソースコードに対して、構文解析処理、字句解析処理、意味解析処理等を行うことで生成されたコード)解析する構成について説明する。なお、以下、ソースコード及び中間コードをまとめて解析対象コードと記載することがある。
Hereinafter, a configuration in which the
コード解析部102は、解析対象コードを解析し、その解析対象コードに含まれる演算命令が、SIMD命令に変換可能か否かを判定する。コード解析部102は、例えば、解析対象コードに含まれるループ処理(繰り返し処理)内部の演算が、SIMD命令に変換可能であるか否かを判定することができる。また、コード解析部102は、例えば、解析対象コードにおいて逐次実行される演算が、SIMD命令に変換可能であるか否かを判定することができる。
The
コード解析部102は、解析対象コードに含まれる演算(例えば、加減算、乗算、除算、FMA演算等)を探索する、探索部102aを含む。探索部102aは、例えば、解析対象コードに含まれるループ処理内部の演算を探索することができる。探索部102aは、探索した結果を、依存関係解析部102b(後述)に提供してもよい。
The
コード解析部102は、また、探索部102aが探索した演算の間の依存関係を解析し、それらの演算をSIMD命令に変換可能か否かを判定する、依存関係解析部102bを含む。依存関係解析部102bは、例えば、探索部102aが探索したループ処理内部における演算の依存関係を解析し、それらの演算がSIMD命令に変換可能か判定することができる。
The
命令生成部103は、コード解析部102における解析対象コードの解析結果に応じて、解析対象コードに含まれる演算を、SIMD命令に変換する。
The
命令生成部103は、演算命令(例えば、加算命令、減算命令、乗算命令等)をFMA演算の形式に変換する演算変換部103aを含む。命令生成部103は、また、SIMD命令生成部103bを含む。SIMD命令生成部103bは、複数のFMA演算間の依存関係に基づいて、組合せ可能な2つのFMA演算を選択し、SIMD命令のオペランドを表すデータを成形(パック)し、SIMD−FMA命令を生成する処理を実行する。
The
コード解析部102及び命令生成部103は、コンパイラ101において最適化処理の一部を実行する構成要素として実装されてもよい。なお、コンパイラ101は、これ以外に、字句解析、構文解析、意味解析、オブジェクト生成等の典型的な処理を実行するよう構成されてよい。これらの典型的な処理は、例えば、周知技術を用いて実装されてもよい。
The
ファイル管理部104は、ソースコード、オブジェクトコード等を記憶及び管理するよう構成される。本実施形態においては、ファイル管理部104は、ソースコード、オブジェクトコード等をファイルの形式で管理してもよい。この場合、ファイル管理部104は、ファイルシステムを用いて実現されてもよい。なお、本実施形態はこれには限定されず、ファイル管理部104は、例えば、データベース等、ファイルシステム以外の技術を用いて実現されてもよい。
The
コード生成装置100は、例えば、コード生成装置100自身により実行されるオブジェクトコードを生成してもよい。また、コード生成装置100は、例えば、図12に例示するような他の情報処理装置1200において実行可能なオブジェクトコードを生成してもよい。情報処理装置1200は、例えば、プロセッサ1201、メモリ1202、ストレージ1203等から構成されるコンピュータであってよい。
The
プロセッサ1201は、少なくとも、SIMD型FMA演算器と、SIMD演算に用いられるオペランドを記憶可能なレジスタ(SIMD−FMAレジスタと記載する場合がある)とを含むCPU(Central Processsing Unit)やMPU(Micro Processing Unit)であってよい。プロセッサ1201は、上記以外に、今日における典型的な計算処理を実行可能な構成を備えてよい。メモリ1202は、プロセッサ1201から参照可能な記憶装置であり、プロセッサ1201により実行されるオブジェクトコードを記憶することができる。ストレージ1203は、例えば、不揮発性の記憶装置(ハードディスクドライブや、半導体フラッシュメモリ等)により構成され、オブジェクトコードを記憶することが可能である。図12に例示する情報処理装置1200の構成は、一つの具体例であり、本実施形態はこれには限定されない。
The
[動作]
以下、上記のように構成されたコード生成装置100の動作について説明する。
[motion]
Hereinafter, the operation of the
図5Aは、コード解析部102における処理の一例を示すフローチャートである。コード解析部102は、解析対象コードを解析し、探索部102aの機能を用いて、解析対象コードに含まれる演算の種類を特定する(ステップS501)。コード解析部102は、例えば、解析対象コードにおけるループ処理を解析し、探索部102aの機能を用いて、ループ処理に含まれる演算の種類を特定してもよい。
FIG. 5A is a flowchart showing an example of processing in the
探索部102aは、解析対象コードに含まれる演算のうち、加減算と乗算とを選択し、SIMD命令に変換可能な演算の組合せのパターンを探索する(ステップS502)。この際、探索部102aは、例えば、オペランドの型及び精度が同じ加減算命令と、乗算命令との組合せを探索してもよい。
The
依存関係解析部102bは、探索部102aにより探索された演算の組合せについて、依存関係があるか否かを解析する。この解析の結果に応じて、依存関係解析部102bは、これらの命令をSIMD命令に変換可能であるか否かを判定する(ステップS503)。依存関係解析部102bは、例えば、複数の演算が同一のループ処理に含まれ、かつ、それぞれの演算の間に依存関係がない場合、それらの演算の組合せについて、依存関係がないと判定してもよい。
The dependency analysis unit 102b analyzes whether or not there is a dependency relationship with respect to the combination of operations searched by the
ステップS503における判定の結果、依存関係があると判定された場合(ステップS504においてYES)、コード解析部102は、それらの命令について、SIMD命令に変換しないと決定する。依存関係がある命令をSIMD命令に変換した場合、計算結果の値が変わってしまう可能性があるからである。コード解析部102は、それらの命令を、SIMD命令に変換される命令の候補から除外してよい(ステップS505)。
If it is determined that there is a dependency as a result of the determination in step S503 (YES in step S504), the
上記解析の結果、依存関係がないと判断された場合(ステップS504においてNO)、コード解析部102は、それらの命令をSIMD命令に変換可能であると判定する。
この場合、コード解析部102は、例えば、上記処理の結果を命令生成部103に提供してもよい。
If it is determined as a result of the above analysis that there is no dependency (NO in step S504), the
In this case, the
命令生成部103は、依存関係がない演算の組合せを、SIMD命令(より具体的には、SIMD−FMA命令)に変換する(ステップS506)。以下、ステップS506における処理について、図5Bに例示するフローチャートを参照して説明する。図5Bは、命令生成部103における処理の一例を例示するフローチャートである。
The
命令生成部103は、演算変換部103aの機能を用いて、加減算と乗算とを、FMA演算の形式へ変換する(ステップS508)。
The
以下、解析対象コードに含まれる非FMA演算(例えば、加算、減算、乗算、除算等の単順な算術演算)をFMA演算に変換する方法について、図6に例示する説明図を参照して説明する。命令生成部103は、解析対象コードに含まれる加算について、一方のオペランドにダミーの乗算(結果に影響しない見せかけの乗算)として値”1”をかける(乗算する)。これにより、命令生成部103は、当該加算をFMA演算に変換する(図6の601)。以下、加算をFMA演算に変換する処理を、第1の演算変換と記載することがある。加算をFMA演算に変換する際に用いられるダミーのオペランド(本具体例においては、”1”)を、第1のダミーオペランドと記載することがある。
Hereinafter, a method of converting a non-FMA operation (for example, a simple arithmetic operation such as addition, subtraction, multiplication, division, etc.) included in the analysis target code into an FMA operation will be described with reference to an explanatory diagram illustrated in FIG. To do. The
命令生成部103は、解析対象コードに含まれる減算について、一方のオペランドにダミーの乗算として値”1”をかけ(乗算し)、更に、減数のオペランドの符号を反転することで、当該減算をFMA演算に変換する(図6の602)。以下、減算をFMA演算に変換する処理を、第2の演算変換と記載することがある。減算をFMA演算に変換する際に用いられるダミーのオペランド(本具体例においては、”1”)を、第2のダミーオペランドと記載することがある。
The
命令生成部103は、解析対象コードに含まれる乗算について、当該乗算の結果に値”0”を足すダミーの加算(結果に影響しない見せかけの加算)を加えることで、当該乗算をFMA演算に変換する(図6の603)。以下、乗算をFMA演算に変換する処理を、第3の演算変換と記載する場合がある。以下、乗算をFMA演算に変換する際に用いられるダミーのオペランド(本具体例においては、”0”)を、第3のダミーオペランドと記載することがある。
The
上記のような方法によって、命令生成部103は、演算の結果を変えることなく、第1、第2、第3の演算変換により、加算、減算、及び乗算をFMA演算に変換することができる。このような変換により、例えば、コード解析部102によってSIMD命令化可能であると判断された加算(又は減算)と乗算と組合せは、2つのFMA演算の組(1つは加算(又は減算)から変換されたFMA演算、もう1つは乗算から変換されたFMA演算)、に変換される。
By the method as described above, the
SIMD命令生成部103bは、上記2つのFMA演算の組を同時に(並行して)実行可能なSIMD命令(SIMD−FMA命令)を生成する(ステップS508)。この際、SIMD命令生成部103bは、それぞれのFMA演算のオペランドが、SIMDレジスタの上位ビットと下位ビットとにパック(配置)されるように、SIMD−FMA命令のオペランドを表すデータを生成する。これにより、SIMD命令生成部103bは、SIMD−FMA命令を生成する。
The SIMD
命令生成部103の処理について、図7に例示する具体例を用いて説明する。図7に例示する具体例においては、解析対象コード(ソースコード)には、異なる種類の演算(加算及び乗算)が含まれていることから、これらの命令を単純にSIMD命令に置き換えることは困難である。
The processing of the
命令生成部103(具体的には、演算変換部103a)は、ソースコードに含まれる加算及び乗算を、FMA演算に変換する。命令生成部103(具体的には、SIMD命令生成部103b)は、FMA演算を、SIMD命令(SIMD−FMA命令)に変換する。この際、SIMD命令生成部103bは、FMA演算の各オペランドが、SIMDレジスタの上位ビットと、下位ビットとにパックされるように、SIMD−FMA命令のオペランドを表すデータを生成する。これにより、係るソースコードから変換されたオブジェクトコードが実行される際、あたかも、SIMDレジスタの上位ビットにおいては”A1+B1”なる加算処理が実行され、下位ビットにおいては、”A2*B2”なる乗算処理が実行されるかのように、演算処理を実行することが可能である。
The instruction generation unit 103 (specifically, the
図7は、2つのFMA命令をSIMD命令として実行する具体例を例示するが、本実施形態は、これには限定されない。コード生成装置100は、生成したオブジェクトコードが実行さる環境(例えば、プロセッサ1201の構成)に応じて、3つ以上のFMA命令をSIMD命令として実行する、SIMD−FMA命令を生成してもよい。
FIG. 7 illustrates a specific example of executing two FMA instructions as SIMD instructions, but the present embodiment is not limited thereto. The
以下、コード生成装置100が、n個(nは2以上の整数)のFMA命令を並列に実行可能なSIMD命令(SIMD−FMA命令)を生成する場合について概要を説明する。
Hereinafter, a case where the
この場合、命令生成部103は、オブジェクトコードが実行される環境(例えばプロセッサ1201)におけるSIMD−FMAレジスタをn等分したそれぞれの領域に、n個のFMA命令のオペランドが配置されるように、SIMD−FMA命令を生成してもよい。例えば、SIMD−FMAレジスタが64bit幅であり、FMA命令のオペランドが単精度浮動小数電データ(32bit)である場合、SIMD−FMA命令として、2つのFMA命令が並列に実行されてよい。この場合、命令生成部は、SIMD−FMAレジスタを2つの領域(上位32bit、下位32bit)に分割し、それぞれの領域に、2つのFMA演算のオペランドを配置する。例えば、SIMD−FMAレジスタが64bit幅であり、FMA命令のオペランドが半精度浮動小数電データ(16bit)である場合、SIMD−FMA命令として、4つのFMA命令が並列に実行されてもよい。この場合、命令生成部は、SIMD−FMAレジスタを4つの領域(それぞれ16bit)に分割し、それぞれの領域に、4つのFMA演算のオペランドを配置する。
In this case, the
コード生成装置100を用いた場合に得られる効果の一例を、図8乃至図10に示す具体例を用いて説明する。なお、図8乃至図10に示す具体例は、一例にすぎず、本実施形態はこれには限定されない。
An example of the effect obtained when the
図8は、解析対象コード(ソースコード)に含まれるループ中に現れる命令列の一例を示す説明図である。図8に例示する演算処理のオペランドは、全て単精度浮動小数点データ(32bit)を表すことを想定する。また、実行環境(例えば、図12に例示する情報処理装置)のプロセッサは、SIMD型FMA演算器を有することを想定する。また、係るプロセッサは、64bit幅のSIMD命令により、単精度浮動小数を同時に2個計算可能であり、1クロックあたり最大で単精度浮動小数点演算を4個実行できることを想定する。 FIG. 8 is an explanatory diagram showing an example of an instruction sequence appearing in a loop included in the analysis target code (source code). It is assumed that all the operands of the arithmetic processing illustrated in FIG. 8 represent single-precision floating-point data (32 bits). Further, it is assumed that the processor of the execution environment (for example, the information processing device illustrated in FIG. 12) has a SIMD type FMA arithmetic unit. Further, it is assumed that the processor can calculate two single-precision floating-point numbers at the same time by a 64-bit wide SIMD instruction, and can execute up to four single-precision floating-point operations per clock.
図8に示す具体例の場合、解析対象コードに(801)〜(808)の命令が含まれる。命令(801)〜(804)においては加算が行われ、命令(805)〜(808)においては乗算が行われる。図9に例示するように、命令(802)は、命令(801)の演算結果(”A1”)を参照することから、命令(802)と、命令(801)との間には依存関係がある。命令(803)、(804)についても同様に、前の命令の結果を参照することから、加算命令(801)〜(804)の間には依存関係がある。 In the case of the specific example shown in FIG. 8, the analysis target code includes the instructions (801) to (808). Addition is performed in the instructions (801) to (804), and multiplication is performed in the instructions (805) to (808). As illustrated in FIG. 9, since the instruction (802) refers to the operation result (“A1”) of the instruction (801), there is a dependency relationship between the instruction (802) and the instruction (801). is there. Similarly, with respect to the instructions (803) and (804), since the result of the previous instruction is referred to, there is a dependency relationship between the addition instructions (801) to (804).
また、命令(806)は、命令(805)の演算結果(”X1”)を参照することから命令(805)と、命令(806)との間には依存関係がある。命令(807)、命令(808)についても同様に、前の命令の結果を参照することから、乗算命令(805)〜(808)の間にも依存関係がある。即ち、 同じ種類の演算命令である命令(801)〜(804)の加算同士、及び、命令(805)〜(808)の乗算同士の間に依存関係がある。 Further, since the instruction (806) refers to the operation result (“X1”) of the instruction (805), there is a dependency relationship between the instruction (805) and the instruction (806). Similarly, for the instruction (807) and the instruction (808), since the result of the previous instruction is referred to, there is a dependency relationship between the multiplication instructions (805) to (808). That is, there is a dependency between the additions of the instructions (801) to (804), which are the same type of arithmetic instructions, and the multiplications of the instructions (805) to (808).
一方、命令(805)〜(808)の乗算命令は、命令(801)〜(804)の加算命令の結果を参照しない。即ち、命令(801)〜(804)の加算命令と、命令(805)〜(808)の乗算命令との間には依存関係がない。 On the other hand, the multiplication instructions of the instructions (805) to (808) do not refer to the result of the addition instructions of the instructions (801) to (804). That is, there is no dependency between the addition instructions of the instructions (801) to (804) and the multiplication instructions of the instructions (805) to (808).
典型的には、同じ種類の演算については、演算の間に依存関係がなければ、SIMD命令に変換することができる。一方、演算の種類が異なる命令(例えば、加算命令と乗算目例)については、単純にSIMD命令に置き換えることは困難である。 Typically, the same type of operation can be converted to a SIMD instruction if there are no dependencies between the operations. On the other hand, it is difficult to simply replace an instruction with a different operation type (for example, an addition instruction and a multiplication item example) with a SIMD instruction.
図8に例示するような命令列の場合、同じ種類の演算命令の間には依存関係があることから、単純にはSIMD命令に変換することができない。この場合、8つ命令を逐次的に実行することとなり、十分な実行性能が得られない。また、この場合、プロセッサは、1クロックで1個の演算しか実行できないことから、最大4個同時実行可能なピーク性能に対して、十分な実行効率が得られない。 In the case of the instruction sequence as illustrated in FIG. 8, since there is a dependency between the same type of operation instructions, it cannot be simply converted into a SIMD instruction. In this case, eight instructions are executed sequentially, and sufficient execution performance cannot be obtained. Further, in this case, since the processor can execute only one operation in one clock, sufficient execution efficiency cannot be obtained for the peak performance in which a maximum of four operations can be executed simultaneously.
これに対して、上記説明した本実施形態におけるコード生成装置100は、図10に例示するように、命令(801)〜(808)を、それぞれFMA演算(f1)〜(f8)に変換することができる。コード生成装置100は、依存関係のない(f1)と(f5)、(f2)と(f6)、(f3)と(f7)、(f4)と(f8)を、同時に(並行して)実行可能な命令の組であると判定する。コード生成装置100は、これらの命令をSIMD−FMA命令に変換し、命令(s1)〜(s4)を生成することができる。
On the other hand, the
コード生成装置100は、元の加算命令のオペランドがSIMDレジスタの上位ビット(上位32bit)にパックされ、元の乗算命令のオペランドがSIMDレジスタの下位ビット(下位32bit)にパックされるよう、SIMD−FMA命令を生成する。これにより、命令(s1)〜(s4)においては、あたかもSIMDレジスタの上位ビットにおいては、命令(f1)〜(f4)に相当する加算命令が実行され、下位ビットにおいては、命令(f5)〜(f8)に相当する乗算命令が実行されるかのように、演算処理が実行される。
The
図8に示す具体例においては、コード生成装置100は、SIMD命令に変換できない場合と比較して、命令数を1/2(8命令から4命令へ)に削減することが可能である。また、実行性能は、2倍になる。
In the specific example shown in FIG. 8, the
コード生成装置100は、SIMD命令として2つFMA演算命令を同時発行するコード(オブジェクトコード)を生成することができる。これより、コード生成装置100により生成されたコードを実行するプロセッサは、1クロックで実質4個の演算(乗算と加減算)を実行することが可能である。これにより、SIMD命令に変換できない場合と比較して、ピーク性能に対する実行効率が4倍になる。
The
上記のように構成されたコード生成装置100を用いた場合に得られる効果の他の一例を、図11に示す具体例を用いて説明する。なお、図11に示す具体例は、一例にすぎず、本実施形態は、これには限定されない。
Another example of the effect obtained when the
図11に例示する解析対象コード(図11の(a)部分)においては、演算命令(1101)における乗算の結果(”A0”)が、後続する他の命令(1102)〜(1103)に参照される。命令(1101)は、加算であり、命令(1102)〜(1103)は、加算及び乗算であることから、これらの命令を単純にFMA演算の命令に変換することは困難である。 In the analysis target code (part (a) of FIG. 11) illustrated in FIG. 11, the result of multiplication (“A0”) in the operation instruction (1101) is referred to the other subsequent instructions (1102) to (1103). Will be done. Since the instruction (1101) is addition and the instructions (1102) to (1103) are addition and multiplication, it is difficult to simply convert these instructions into instructions for FMA operation.
上記説明した本実施形態とは異なる方法として、例えば、命令(1101)と、他の命令(1102−1104)とを、単純に組合せることで、これらをFMA演算に変換することが考えられる。そのような方法は、例えば、上記説明した第1、第2、第3のダミー演算を用いず、FMA演算に直接的に変換可能な命令の組合せを探索すること、探索された命令をFMA演算に変換すること、及び、変換したFMA演算を実行するSIMD−FMA命令を生成すること、を含んでもよい。そのような方法を用いた場合、命令(1101)〜(1104)は、例えば、図11の(b)部分に示す命令(1105)〜(1108)に変換される。命令(1106)、(1108)はFMA命令であるが、これらの命令において、演算”B0*C0”が複数回実行される。即ち、この演算を実行するための処理(例えば、オペランドの読み込み等)に要するコスト(レイテンシ等)が、複数回発生する可能性がある。また、このような方法を用いた場合、FMA演算に変換せずに”A0”を先に計算した方が、乗算命令の数が少ない。 As a method different from the present embodiment described above, for example, it is conceivable to convert the instruction (1101) and another instruction (1102-1104) into an FMA operation by simply combining them. Such a method is, for example, searching for a combination of instructions that can be directly converted into an FMA operation without using the first, second, and third dummy operations described above, and performing an FMA operation on the searched instructions. It may include converting to and generating a SIMD-FMA instruction that executes the converted FMA operation. When such a method is used, the instructions (1101) to (1104) are converted into, for example, the instructions (1105) to (1108) shown in the portion (b) of FIG. Instructions (1106) and (1108) are FMA instructions, and in these instructions, the operation "B0 * C0" is executed a plurality of times. That is, the cost (latency, etc.) required for the process for executing this operation (for example, reading the operand) may occur a plurality of times. Further, when such a method is used, the number of multiplication instructions is smaller when "A0" is calculated first without converting to FMA calculation.
これに対して、本実施形態におけるコード生成装置100は、FMA演算に直接的に変換可能な複数の演算を組合せてFMA演算を生成するのではなく、依存関係のない命令を、それぞれFMA命令に変換する。図11に示す具体例の場合、コード生成装置100は、図11の命令(1101)〜(1104)から、命令(1109)〜(1112)を生成することができる。この場合、命令(1109)において、先に”A0”が計算されることから、演算”B0*C0”を実行するコストは、1度のみ生じる。
On the other hand, the
また、命令(1110)〜(1112)に含まれる第1、第2のダミーオペランドは、いずれも即値である。よって、ダミーオペランドに関する演算の実行に要するコストは、比較的低いと考えられる。更に、コード生成装置100は、命令(1110)〜(1112)のうち、2つの命令をSIMD−FMA命令に変換することが可能である。これにより、コード生成装置100は、命令の数を削減できる。
Further, the first and second dummy operands included in the instructions (1110) to (1112) are all immediate values. Therefore, the cost required to execute the operation related to the dummy operand is considered to be relatively low. Further, the
以上説明したように、本実施形態におけるコード生成装置100は、解析対象コードのコードサイズを低減することが可能である。また、コード生成装置100は、解析対象コードの実行速度を改善することが可能である。その理由は、以下の通りである。
As described above, the
コード生成装置100は、解析対象コードに含まれる、異なる種類の演算を表す命令列を、複数のオペランドに関する演算を並行して(同時に)実行可能な命令(SIMD命令)に変換することができる。より具体的には、コード生成装置100は、解析対象コードに含まれる演算の依存関係を判定することで、それらの演算を、SIMD命令に変換して実行可能か否か判定可能である。コード生成装置100は、解析対象コードに含まれる演算(例えば、加減算及び乗算)を、ダミーのオペランドを用いて、FMA演算に変換可能である。コード生成装置100は、依存関係のないFMA演算を、SIMD命令(SIMD−FMA命令)に変換可能である。このように、コード生成装置100は、解析対象コードの一部をSIMD−FMA命令に変換することで、SIMD命令に変換できない場合に比べて、コードサイズを低減することが可能である。更に、SIMD−FMA命令を用いることにより、コード(具体的には、解析対象コードから生成されたオブジェクトコード)の実行速度が改善される。
The
例えば、科学技術計算の分野では、配列に格納した大量のデータをループによって処理し、ループの繰返しごとに依存関係がある漸化式を計算するようなプログラムが実行されることがある。例えば、図8に示す、A(n)=A(n−1)+B(n)、X(n)=X(n−1)+Y(n)(A、B、X、Yは配列、nは配列のインデックス)は、そのような漸化式の一例であるとも考えられる。この場合、プログラムの実行により、多くの演算(例えば、加算、乗算等)命令が発行される。しかしながら、例えば、漸化式においては、同種の演算(例えば、加算同士、乗算同士)の間には依存関係があることが多い。よって、これらの命令をそのままSIMD命令に置き換える困難である。このように、ループ内に存在する同種の演算命令を、SIMD命令に単純に置き換えられない場合であっても、本実施形態におけるコード生成装置100は、異なる種別の命令を組合せてSIMD命令(SIMD−FMA命令)を生成可能である。これにより、コード生成装置100は、例えば、漸化式を含むようなプログラムであっても、コードサイズを削減することが可能である。また、コード生成装置100は、そのようなプログラムの実行速度を改善することが可能である。
For example, in the field of scientific computing, a program may be executed in which a large amount of data stored in an array is processed by a loop and a recurrence formula having a dependency relationship is calculated for each iteration of the loop. For example, as shown in FIG. 8, A (n) = A (n-1) + B (n), X (n) = X (n-1) + Y (n) (A, B, X, Y are sequences, n Is an array index) is also considered to be an example of such a recurrence formula. In this case, the execution of the program issues many arithmetic (for example, addition, multiplication, etc.) instructions. However, for example, in a recurrence formula, there are often dependencies between operations of the same type (for example, additions and multiplications). Therefore, it is difficult to replace these instructions with SIMD instructions as they are. As described above, even if the same type of operation instruction existing in the loop cannot be simply replaced with the SIMD instruction, the
例えば、組込みシステムのようにメモリのサイズが限られるシステムにおいては、コードサイズを小さくすることが求められる。このような分野においても、本実施形態において説明した方式の有用性が高いと考えられる。 For example, in a system such as an embedded system in which the memory size is limited, it is required to reduce the code size. It is considered that the method described in the present embodiment is highly useful also in such a field.
[変形例]
以下、本実施形態の変形例について説明する。本変形例におけるコード生成装置の機能的な構成は、上記第1の実施形態と同様としてよい。
[Modification example]
Hereinafter, a modified example of the present embodiment will be described. The functional configuration of the code generation device in this modification may be the same as that of the first embodiment.
上記第1の実施形態におけるコード生成装置100は、加減算と乗算との組合せを、それらの間の依存関係に応じて、SIMD命令(具体的にはSIMD−FMA命令)に変換することができる。
The
本変形例において、コード生成装置100は、上記に加え、加減算と除算との組合せを、SIMD−FMA命令に変換可能に構成される。浮動小数点数の演算においては、除数の逆数を求めることで、除算を乗算に変換可能である。このため、本変形例において、コード生成装置100は、例えば、除算を乗算に変換してから、にFMA命令に変換することで、加減算と除算との組合せから、SIMD−FMA命令を生成することが可能である。
In this modification, in addition to the above, the
<第2の実施形態>
以下、本開示に係る技術の基本的な実施形態である、第2の実施形態について説明する。
<Second embodiment>
Hereinafter, a second embodiment, which is a basic embodiment of the technique according to the present disclosure, will be described.
図13は、本実施形態におけるコード生成装置1300の機能的な構成を例示するブロック図である。図13に例示するように、コード生成装置1300は、コード解析部1301(コード解析手段)と、命令生成部1302(命令生成手段)と、を含む。
FIG. 13 is a block diagram illustrating a functional configuration of the
コード解析部1301及び命令生成部1302は、第1の実施形態と同様、ソースコードからオブジェクトコードを生成するコンパイラの一部として実現されてもよい。
The
コード生成装置1300は、例えば、第1の実施形態におけるコード生成装置100と同様、コード生成装置1300自身により実行されるオブジェクトコードを生成してもよい。また、コード生成装置1300は、例えば、図12に例示するような他の情報処理装置1200において実行可能なオブジェクトコードを生成してもよい。
The
以下、コード生成装置1300を構成する各構成要素について説明する。
Hereinafter, each component constituting the
コード解析部1301は、複数の演算命令により構成されるコンピュータ・プログラムである解析対象コードに含まれる1以上の演算命令を、その演算命令の種類と、演算命令の間の依存関係とに基づいて、融合演算命令を並列に実行可能な並列実行命令に変換可能が否かを判定する。コード解析部1301は、例えば、命令の種類が異なる演算命令の間の依存関係を確認し、それらの命令を並列実行命令に変換可能が否かを判定してもよい。
The
融合演算命令は、複数のデータに対して、異なる種類の演算を1つの命令として実行可能な命令である。融合演算命令は、例えば、FMA演算を実行する命令であってもよい。 A fusion operation instruction is an instruction that can execute different types of operations as one instruction for a plurality of data. The fusion operation instruction may be, for example, an instruction that executes an FMA operation.
並列実行命令は、1つの命令で複数のデータに関する演算を並列に実行可能な命令である。並列実行命令は、例えば、SIMD命令であってもよい。また、融合演算命令を並列に実行可能な並列実行命令は、SIMD−FMA命令であってもよい。 A parallel execution instruction is an instruction that can execute operations related to a plurality of data in parallel with one instruction. The parallel execution instruction may be, for example, a SIMD instruction. Further, the parallel execution instruction capable of executing the fusion operation instruction in parallel may be a SIMD-FMA instruction.
命令生成部1302は、コード解析部1301により、並列実行命令に変換可能であると判定された演算命令を、融合演算命令に変換する。命令生成部1302は、変換した融合演算命令のオペランドが、並列実行命令として実行可能な形式に配置されたデータを生成することで、融合演算命令を並列に実行する並列実行命令を生成する。
The
一例として、符号演算命令がFMA命令であり、並列実行命令がSIMD命令(より具体的にはSIMD−FMA命令)であることを想定する。この場合、コード解析部1301は、例えば、解析対象コードに含まれる、異なる種類の演算(例えば、加算と乗算、減算と乗算等)命令について、それらの間の依存関係を確認し、依存関係がない演算命令の組合せを選択することができる。命令生成部1302は、例えば、コード解析部1301により選択された、依存関係がない異なる種類の演算をFMA演算命令に変換し、そのFMA演算命令を組合せてSIMD−FMA命令を生成してもよい。この場合、命令生成部1302は、例えば、SIMD−FMA命令の実行に用いられるレジスタを分割した領域に、並列に実行されるFMA命令のオペランドが割り当てられるように、SIMD−FMA命令のオペランドを表すデータを生成してもよい。
As an example, it is assumed that the code operation instruction is an FMA instruction and the parallel execution instruction is a SIMD instruction (more specifically, a SIMD-FMA instruction). In this case, the
本実施形態において、コード解析部1301は、第1の実施形態におけるコード解析部102と同様に構成されてもよく、命令生成部1302は、第1の実施形態における命令生成部103と同様に構成されてもよい。
In the present embodiment, the
上記のように構成されたコード生成装置1300によれば、異なる命令を含むプログラムの実行効率を向上することが可能である。その理由は、コード解析部1301が、異なる種類の演算命令間の依存関係を判定し、命令生成部が、依存関係がない演算命令を、融合演算命令を並列に実行する並列実行命令に変換するからである。コード生成装置1300は、例えば、解析対象コードに含まれる異なる種類の演算である加算と乗算、減算と乗算とを、SIMD−FMA命令に変換したオブジェクトコードを生成することが可能である。これにより、コード生成装置1300は、オブジェクトコードのサイズを低減し、実行速度を向上することができる。
According to the
<ハードウェア及びソフトウェア・プログラム(コンピュータ・プログラム)の構成>
以下、上記各実施形態を実現可能なハードウェア構成について説明する。
<Structure of hardware and software programs (computer programs)>
Hereinafter, a hardware configuration capable of realizing each of the above embodiments will be described.
以下の説明においては、上記各実施形態におけるコード生成装置(100、1300)をまとめて、単に「コード生成装置」と記載する。またコード生成装置の各構成要素を、単に「コード生成装置の構成要素」と記載する。 In the following description, the code generators (100, 1300) in each of the above embodiments are collectively referred to as "code generator". Further, each component of the code generation device is simply described as "component of the code generation device".
上記各実施形態において説明したコード生成装置は、1つ又は複数の専用のハードウェア装置により構成されてもよい。その場合、上記各図に示した各構成要素は、一部又は全部を統合したハードウェア(処理ロジックを実装した回路構成(circuitry))として実現されてもよい。 The code generation device described in each of the above embodiments may be composed of one or a plurality of dedicated hardware devices. In that case, each component shown in each of the above figures may be realized as hardware in which a part or all of them are integrated (a circuit configuration (circuit configuration (circuit configuration) in which processing logic is implemented)).
例えば、コード生成装置をハードウェアにより実現する場合、コード生成装置の構成要素は、それぞれの機能を提供可能な回路構成を実装するSoC(System on a Chip)等により実現されてもよい。この場合、例えば、コード生成装置の構成要素が保持するデータは、SoCに統合されたRAM(Random Access Memory)領域、ROM(Read Only Memory)領域、フラッシュメモリ領域等に記憶されてもよい。なお、上記回路構成は1つの具体的態様であり、実装においては、様々なバリエーションが想定される。 For example, when the code generation device is realized by hardware, the components of the code generation device may be realized by SoC (System on a Chip) or the like that implements a circuit configuration capable of providing each function. In this case, for example, the data held by the components of the code generator may be stored in a RAM (Random Access Memory) area, a ROM (Read Only Memory) area, a flash memory area, or the like integrated in the SoC. The circuit configuration is one specific embodiment, and various variations are expected in mounting.
コード生成装置の各構成要素を接続する通信回線としては、周知の通信バスあるいは通信ネットワーク採用してもよい。また、各構成要素を接続する通信回線は、それぞれの構成要素間をピアツーピアで接続してもよい。コード生成装置を複数のハードウェア装置により構成する場合、それぞれのハードウェア装置の間は、適切な通信方法(有線、無線、またはそれらの組合せ)により通信可能に接続されていてもよい。 A well-known communication bus or communication network may be adopted as the communication line for connecting each component of the code generation device. Further, the communication line connecting each component may be connected peer-to-peer between the respective components. When the code generation device is composed of a plurality of hardware devices, the respective hardware devices may be communicably connected by an appropriate communication method (wired, wireless, or a combination thereof).
上述したコード生成装置は、図14に例示するような汎用のハードウェア装置1400と、係るハードウェア装置1400によって実行される各種ソフトウェア・プログラム(コンピュータ・プログラム、例えば、コンパイラ)とによって構成されてもよい。この場合、コード生成装置は、複数のハードウェア装置1400及びソフトウェア・プログラムにより構成されてもよい。
The code generation device described above may be composed of a general-
図14におけるプロセッサ1401は、汎用のCPU(中央処理装置:Central Processing Unit)やマイクロプロセッサ等の演算処理装置である。プロセッサ1401は、例えば、後述する不揮発性記憶装置1403に記憶された各種ソフトウェア・プログラムをメモリ1402に読み出し、係るソフトウェア・プログラムに従って処理を実行してもよい。なお、プロセッサ1401は、図12に例示するプロセッサ1201と同様、SIMD−FMA命令を実行可能な演算器を備えてもよい。
The
この場合、上記各実施形態におけるコード生成装置の構成要素は、例えば、プロセッサ1401により実行されるソフトウェア・プログラムとして実現可能である。そのようなソフトウェア・プログラムの実装においては、様々なバリエーションが想定される。
In this case, the components of the code generator in each of the above embodiments can be realized as, for example, a software program executed by the
メモリ1402は、プロセッサ1401から参照可能な、RAM等のメモリ装置であり、ソフトウェア・プログラムや各種データ等を記憶する。なお、メモリ1402は、揮発性のメモリ装置であってもよい。
The
不揮発性記憶装置1403は、例えば磁気ディスクドライブや、フラッシュメモリによる半導体記憶装置のような、不揮発性の記憶装置である。不揮発性記憶装置1403は、各種ソフトウェア・プログラムやデータ等を記憶可能である。
The
例えば、上記各実施形態における、ファイル管理部(104)は、不揮発性記憶装置1403にデータを保持してもよい。
For example, the file management unit (104) in each of the above embodiments may hold data in the
ドライブ装置1404は、例えば、後述する記録媒体1405に対するデータの読み込みや書き込みを処理する装置である。
The
記録媒体1405は、例えば、光ディスク、光磁気ディスク、半導体フラッシュメモリ等、データを記録可能な記録媒体である。
The
上述した各実施形態を例に説明したコード生成装置は、例えば、図14に例示するハードウェア装置1400に対して、上記各実施形態において説明した機能を実現可能なソフトウェア・プログラム(例えば、コンパイラ)を供給することにより、実現されてもよい。より具体的には、例えば、係る装置に対して供給したソフトウェア・プログラムを、プロセッサ1401が実行することによって、本開示に係る技術が実現されてもよい。この場合、係るハードウェア装置1400において稼働しているオペレーティングシステムや、データベース管理ソフト、ネットワークソフト等のミドルウェアなどが各処理の一部を実行してもよい。
The code generation device described by taking each of the above-described embodiments as an example is, for example, a software program (for example, a compiler) capable of realizing the functions described in each of the above-described embodiments with respect to the
上述した各実施形態において、上記各図(例えば、図4及び図13)に示した各部は、上述したハードウェアにより実行されるソフトウェア・プログラムの機能(処理)単位である、ソフトウェアモジュールとして実現されてもよい。ただし、これらの図面に示した各ソフトウェアモジュールの区分けは一例であり、実装に際しては、他の様々な構成が想定され得る。 In each of the above-described embodiments, each part shown in each of the above-mentioned figures (for example, FIGS. 4 and 13) is realized as a software module which is a function (processing) unit of a software program executed by the above-mentioned hardware. You may. However, the division of each software module shown in these drawings is an example, and various other configurations can be assumed at the time of implementation.
例えば、上記各部をソフトウェアモジュールとして実現する場合、これらのソフトウェアモジュールは、不揮発性記憶装置1403に記憶されてもよい。そして、プロセッサ1401が、それぞれの処理を実行する際に、これらのソフトウェアモジュールをメモリ1402に読み出してもよい。
For example, when each of the above parts is realized as a software module, these software modules may be stored in the
また、これらのソフトウェアモジュールは、共有メモリやプロセス間通信等により、相互に各種データを伝達できるように構成されてもよい。このような構成により、これらのソフトウェアモジュールを、相互に通信可能に接続可能である。 Further, these software modules may be configured so that various data can be transmitted to each other by shared memory, interprocess communication, or the like. With such a configuration, these software modules can be connected to each other so as to be able to communicate with each other.
更に、上記各ソフトウェア・プログラムは、記録媒体1405に記録されてもよい。この場合、上記各ソフトウェア・プログラムは、上記通信装置等の出荷段階、又は運用段階等において、適宜ドライブ装置1404を通じて不揮発性記憶装置1403に格納されるよう構成されてもよい。
Further, each of the above software programs may be recorded on the
なお、上記の場合において、上記コード生成装置への各種ソフトウェア・プログラムの供給方法として、出荷前の製造段階、又は出荷後のメンテナンス段階等において、適当な治具(ツール)を利用して当該装置内にインストールする方法を採用してもよい。また、各種ソフトウェア・プログラムの供給方法として、インターネット等の通信回線を介して外部からダウンロードする方法等のように、現在では一般的な手順を採用してもよい。 In the above case, as a method of supplying various software programs to the code generator, the device is used by using an appropriate jig (tool) at the manufacturing stage before shipment, the maintenance stage after shipment, or the like. You may adopt the method of installing in. Further, as a method of supplying various software programs, a general procedure may be adopted at present, such as a method of downloading from the outside via a communication line such as the Internet.
そして、このような場合において、本開示に係る技術は、係るソフトウェア・プログラムを構成するコード、又は係るコードが記録されたところの、コンピュータ読み取り可能な記録媒体によって構成されると捉えることができる。この場合、係る記録媒体は、ハードウェア装置1400と独立した媒体に限らず、LANやインターネットなどにより伝送されたソフトウェア・プログラムをダウンロードして記憶又は一時記憶した記憶媒体を含む。
In such a case, the technology according to the present disclosure can be regarded as being composed of a code constituting the software program or a computer-readable recording medium on which the code is recorded. In this case, the recording medium is not limited to a medium independent of the
また、上述したコード生成装置、又は、当該コード生成装置の構成要素は、図14に例示するハードウェア装置1400を仮想化した仮想化環境と、当該仮想化環境において実行される各種ソフトウェア・プログラム(コンピュータ・プログラム)とによって構成されてもよい。この場合、図14に例示するハードウェア装置1400の構成要素は、当該仮想化環境における仮想デバイスとして提供される。なお、この場合も、図14に例示するハードウェア装置1400を物理的な装置として構成した場合と同様の構成にて、本開示に係る技術を実現可能である。
Further, the above-mentioned code generation device or a component of the code generation device includes a virtual environment in which the
以上、本開示に係る技術を、上述した模範的な実施形態に適用した例として説明した。しかしながら、本開示の技術的範囲は、上述した各実施形態及び変形例に記載した範囲には限定されない。当業者には、係る実施形態に対して多様な変更又は改良を加えることが可能であることは明らかである。そのような場合、係る変更又は改良を加えた新たな実施形態も、本開示の技術的範囲に含まれ得る。更に、上述した各実施形態及び変形例、並びに、係る変更又は改良を加えた新たな実施形態を組合せた実施形態も、本開示の技術的範囲に含まれ得る。そしてこのことは、特許請求の範囲に記載した事項から明らかである。 The techniques according to the present disclosure have been described above as examples of application to the above-mentioned exemplary embodiments. However, the technical scope of the present disclosure is not limited to the scope described in each of the above-described embodiments and modifications. It will be apparent to those skilled in the art that various changes or improvements can be made to such embodiments. In such cases, new embodiments with such modifications or improvements may also be included in the technical scope of the present disclosure. Further, the technical scope of the present disclosure may also include embodiments in which the above-described embodiments and modifications, as well as new embodiments with such modifications or improvements, are combined. And this is clear from the matters stated in the claims.
100 コード生成装置
101 コンパイラ
102 コード解析部
103 命令生成部
104 ファイル管理部
1200 情報処理装置
1201 プロセッサ
1202 メモリ
1203 ストレージ
1300 コード生成装置
1301 コード解析部
1302 命令生成部
1401 プロセッサ
1402 メモリ
1403 不揮発性記憶装置
1404 ドライブ装置
1405 記録媒体
100
Claims (10)
前記依存関係がない演算命令の組合せごとに、加減算と乗算との組合せの演算命令からなる融合演算命令に変換してから、前記融合演算命令を並列に実行する並列実行命令を生成する命令生成手段と、を備え、
前記命令生成手段は、除数の逆数を求めることで、除算を乗算に変換することにより、前記依存関係がない加減算と除算との組合せの演算命令を、加減算と乗算との組合せの演算命令からなる前記融合演算命令に変換する
コード生成装置。 A code that selects a combination of operation instructions that have no dependency by analyzing the dependency between the operation instructions of different types among one or more operation instructions included in the analysis target code that is a computer program. Analytical means and
For each combination of the dependency is no operation instruction, convert the fusion operation instruction consisting operation instruction combination of addition and subtraction and multiplication, to produce a parallel execution instructions that perform pre Symbol fusion calculation instructions in parallel With instruction generation means ,
The instruction generation means is composed of an arithmetic instruction of a combination of addition / subtraction and division having no dependency, and an arithmetic instruction of a combination of addition / subtraction and multiplication by converting the division into multiplication by obtaining the reciprocal of the divisor. A code generator that converts to the fusion operation instruction.
前記命令生成手段は、前記コード解析手段により依存関係がないと判定された、種類が異なる前記演算命令を、前記融合演算命令に変換する
請求項1に記載のコード生成装置。 The code analysis means determines whether or not there is a dependency between the addition instruction and the multiplication instruction, which are the operation instructions having different operation types, among the operation instructions included in the analysis target code, and the subtraction instruction. Determine if there is a dependency between and the multiplication instruction,
The code generation device according to claim 1, wherein the instruction generation means converts the operation instructions of different types, which are determined by the code analysis means to have no dependency, into the fusion operation instructions.
請求項2に記載のコード生成装置。 The instruction generation means converts all of the operation instructions of different types determined to have no dependency by the code analysis means into the fusion operation instruction, and combines the converted fusion operation instructions. The code generator according to claim 2, wherein the parallel execution instruction for executing the fusion operation instruction in parallel is generated.
前記並列実行命令は、FMA演算命令を複数のデータに対して並列に実行可能なSIMD(Single Instruction Multiple Data)−FMA命令であり、
前記命令生成手段は、前記コード解析手段における判定の結果に応じて、依存関係がないと判定された前記演算命令をFMA演算命令に変換し、変換されたそのFMA演算命令を組合せることで、前記SIMD−FMA命令を生成する
請求項2又は3に記載のコード生成装置。 The fusion operation instruction is an FMA (Fused Multiply and added) operation instruction that executes a product-sum operation with one instruction.
The parallel execution instruction is a SIMD (Single Instruction Multiply Data) -FMA instruction capable of executing an FMA operation instruction in parallel for a plurality of data.
The instruction generation means converts the operation instruction determined to have no dependency into an FMA operation instruction according to the result of the determination in the code analysis means, and combines the converted FMA operation instructions. The code generator according to claim 2 or 3, which generates the SIMD-FMA instruction.
前記演算命令が加算命令である場合、当該加算命令の一方のオペランドに、加算の結果に影響しない値を有する第1のダミーオペランドを即値として乗算する命令を追加することで、当該加算命令をFMA演算命令に変換し、
前記演算命令が減算命令である場合、当該減算命令の一方のオペランドに減算の結果に影響しない値を有する第2のダミーオペランドを即値として乗算する命令を追加するとともに、当該減算命令の他方のオペランドの符号を反転することで、当該減算命令をFMA演算命令に変換し、
前記演算命令が乗算命令である場合、乗算の結果に影響しない値を有する第3のダミーオペランドを即値として加算する命令を追加することで、当該減算命令をFMA演算命令に変換する、
請求項4に記載のコード生成装置。 The instruction generation means
When the arithmetic instruction is an addition instruction, the addition instruction is FMA by adding an instruction to multiply one operand of the addition instruction by a first dummy operand having a value that does not affect the result of addition as an immediate value. Convert to arithmetic instructions
When the operation instruction is a subtraction instruction, an instruction to multiply one operand of the subtraction instruction by a second dummy operand having a value having a value that does not affect the result of the subtraction as an immediate value is added, and the other operand of the subtraction instruction is added. By inverting the sign of, the subtraction instruction is converted into an FMA operation instruction.
When the operation instruction is a multiplication instruction, the subtraction instruction is converted into an FMA operation instruction by adding an instruction for adding a third dummy operand having a value that does not affect the result of multiplication as an immediate value.
The code generator according to claim 4.
前記命令生成手段は、
前記SIMD−FMA命令に関するオペランドを記憶するレジスタを2つに分割した領域の内、一方の領域には、FMA演算命令に変換される前の前記演算命令のうち、加算命令又は減算命令に関するオペランドを配置し、
他方の領域には、FMA演算命令に変換される前の前記演算命令のうち、乗算命令に関するオペランドを配置するよう、前記SIMD−FMA命令のオペランドを表すデータを生成する
請求項5に記載のコード生成装置。 When the SIMD-FMA instruction can execute two FMA operation instructions in parallel,
The instruction generation means
Of the areas in which the register for storing the operands related to the SIMD-FMA instruction is divided into two, one of the areas contains the operands related to the addition instruction or the subtraction instruction among the operation instructions before being converted into the FMA operation instruction. Place and
The code according to claim 5, which generates data representing an operand of the SIMD-FMA instruction so as to arrange an operand related to a multiplication instruction among the operation instructions before being converted into an FMA operation instruction in the other area. Generator.
前記依存関係がない演算命令の組合せごとに、加減算と乗算との組合せの演算命令からなる融合演算命令に変換してから、前記融合演算命令を並列に実行する並列実行命令を生成し、
前記並列実行命令を生成する際に、除数の逆数を求めることで、除算を乗算に変換することにより、前記依存関係がない加減算と除算との組合せの演算命令を、加減算と乗算との組合せの演算命令からなる前記融合演算命令に変換する
コード生成方法。 By analyzing the dependency between the operation instructions having different types of instructions from one or more operation instructions included in the analysis target code which is a computer program, a combination of operation instructions having no dependency is selected .
Wherein for each combination of dependency is not operation instruction, convert the fusion operation instruction consisting operation instruction combination of addition and subtraction and multiplication, to produce a parallel execution instructions that perform pre Symbol fusion calculation instructions in parallel ,
When the parallel execution instruction is generated, the reciprocal of the divisor is obtained to convert the division to multiplication, so that the operation instruction of the combination of addition / subtraction and division having no dependency can be obtained from the combination of addition / subtraction and multiplication. A code generation method for converting into the fusion operation instruction consisting of an operation instruction.
請求項7に記載のコード生成方法。 It is determined whether or not there is a dependency between the operation instructions of different types among the one or more operation instructions, and the operation instruction of a different type determined to have no dependency is used as the fusion operation instruction. The code generation method according to claim 7, further comprising converting.
コンピュータ・プログラムである解析対象コードに含まれる1以上の演算命令のうち、命令の種類が異なる前記演算命令の間の依存関係を解析することにより、依存関係がない演算命令の組合せを選択する解析処理と、
前記依存関係がない演算命令の組合せごとに、加減算と乗算との組合せの演算命令からなる融合演算命令に変換してから、前記融合演算命令を並列に実行する並列実行命令を生成する命令生成処理と、を実行させ、
前記命令生成処理では、除数の逆数を求めることで、除算を乗算に変換することにより、前記依存関係がない加減算と除算との組合せの演算命令を、加減算と乗算との組合せの演算命令からなる前記融合演算命令に変換する
コード生成プログラム。 On the computer
Analysis that selects a combination of arithmetic instructions that have no dependency by analyzing the dependency between the arithmetic instructions of different types among one or more arithmetic instructions included in the code to be analyzed, which is a computer program. Processing and
For each combination of the dependency is no operation instruction, convert the fusion operation instruction consisting operation instruction combination of addition and subtraction and multiplication, to produce a parallel execution instructions that perform pre Symbol fusion calculation instructions in parallel Execute the instruction generation process ,
In the instruction generation process, the reciprocal of the divisor is obtained, and the division is converted into multiplication, so that the operation instruction of the combination of addition / subtraction and division having no dependency is composed of the operation instruction of the combination of addition / subtraction and multiplication. A code generation program that converts to the fusion operation instruction.
前記命令生成処理は、依存関係がないと判定された種類が異なる前記演算命令を、前記融合演算命令に変換する処理、更に含む
請求項9に記載のコード生成プログラム。 The analysis process includes a process of determining whether or not there is a dependency between the operation instructions of different types among the one or more operation instructions.
The code generation program according to claim 9, wherein the instruction generation process includes a process of converting the operation instruction of a different type determined to have no dependency into the fusion operation instruction.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2017058550A JP6897213B2 (en) | 2017-03-24 | 2017-03-24 | Code generator, code generator and code generator |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2017058550A JP6897213B2 (en) | 2017-03-24 | 2017-03-24 | Code generator, code generator and code generator |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2018163381A JP2018163381A (en) | 2018-10-18 |
JP6897213B2 true JP6897213B2 (en) | 2021-06-30 |
Family
ID=63860140
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2017058550A Active JP6897213B2 (en) | 2017-03-24 | 2017-03-24 | Code generator, code generator and code generator |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP6897213B2 (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112965710A (en) * | 2019-12-13 | 2021-06-15 | 阿里巴巴集团控股有限公司 | Processing method, device and system of computation graph |
-
2017
- 2017-03-24 JP JP2017058550A patent/JP6897213B2/en active Active
Also Published As
Publication number | Publication date |
---|---|
JP2018163381A (en) | 2018-10-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9619214B2 (en) | Compiler optimizations for vector instructions | |
US9542169B2 (en) | Generating SIMD code from code statements that include non-isomorphic code statements | |
JP2004234126A (en) | Compiler and compiling method | |
US10642586B2 (en) | Compiler optimizations for vector operations that are reformatting-resistant | |
JP6245031B2 (en) | Compilation program, compilation method, and compilation apparatus | |
US9594668B1 (en) | Debugger display of vector register contents after compiler optimizations for vector instructions | |
JP5966509B2 (en) | Program, code generation method, and information processing apparatus | |
US20150220315A1 (en) | Method and apparatus for compiling | |
US11656880B2 (en) | Function evaluation using multiple values loaded into registers by a single instruction | |
Voss et al. | Rapid development of Gzip with MaxJ | |
JP6897213B2 (en) | Code generator, code generator and code generator | |
Trapp et al. | Documentation of the intermediate representation firm | |
US9158511B2 (en) | Scalable partial vectorization | |
JP7295466B2 (en) | Class generation program and class generation method | |
US20220405110A1 (en) | Non-transitory computer-readable recording medium and compilation method | |
JP2019185486A (en) | Code conversion device, code conversion method, and code conversion program | |
JP3727039B2 (en) | Multiplication method in compiler | |
JP4721975B2 (en) | Compiler device and compiling method | |
Denis | High-performance regular expression matching with Parabix and LLVM | |
Bernstein et al. | Usable assembly language for GPUs: a success story | |
Braun et al. | Towards Adjoint and Directional Derivatives in FMI utilizing ADOL-C within OpenModelica. | |
De Sutter et al. | On the use of subword parallelism in medical image processing | |
Nakanishi et al. | Optimizing Reaching Definitions Overhead in Queue Processors. | |
Blum et al. | Code Specialisation of Auto-Generated GPU Kernels | |
Hohenauer et al. | SIMD Optimization |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20200217 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20210129 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20210209 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20210310 |
|
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: 20210511 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20210524 |
|
R150 | Certificate of patent or registration of utility model |
Ref document number: 6897213 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R150 |