oneAPI 1.3 暫定仕様書 Rev. 1 の解説 (37)

その他

この記事は、https://www.oneapi.io/spec/ で 2023年9月14日に公開された『oneAPI 1.3 Provisional Specification Rev. 1』 (HTMLPDF) をベースにしています。原文は2000 ページ近くあり、翻訳の時間とリソースも限られるため、全文翻訳ではなく、記事形式で区切った仕様とその解説を提供することにしました。


この回では、『oneAPI 1.3 Provisional Specification Rev. 1』の「oneDAL」の「Operations」と「Computational modes」の節を取り上げています。

操作

操作は、入力オブジェクトによって示される記述子と他の引数を結果オブジェクトに変換する関数です。操作記述子は以下を行います。

  • 記述子で示されるアルゴリズムのすべての計算ルーチンを実行します。
  • SYCL* キューを計算ルーチンに渡します。
  • 計算ルーチンの実行前の前提条件と実行後の事後条件を検証します。

一般操作の定義

次のサンプルコードは、抽象化操作の宣言方法を示しています。特定の操作を宣言するには、%OPERATION% を操作名に置き換えます。

namespace oneapi::dal {

template <typename Descriptor>
using %OPERATION%_input_t = /* 実装定義 */;

template <typename Descriptor>
using %OPERATION%_result_t = /* 実装定義 */;

template <typename Descriptor>
%OPERATION%_result_t<Descriptor> %OPERATION%(
   sycl::queue& queue,
   const Descriptor& desc,
   const %OPERATION%_input_t<Descriptor>& input);

} // namespace oneapi::dal

それぞれの操作は次の要件を満たす必要があります。

  • 操作は次の順序で 3 つのパラメーターを受け入れなければなりません。
    • SYCL* キュー・オブジェクト
    • アルゴリズムの記述子
    • 入力オブジェクト
  • 操作は結果オブジェクトを返します。
  • %OPERATION%_input_t%OPERATION%_result_t エイリアス・テンプレートは、入力と戻り値のタイプ推測に使用されます。
  • 前提条件に違反した場合、操作は oneapi::dal::logic_error から派生する例外をスローします。
  • 事後条件に違反した場合、操作は oneapi::dal::runtime_error から派生する例外をスローします。
  • 記述子が一部の操作と互換性がない場合、コンパイル時にエラーがレポートされます。
  • 互換性のある操作と事前/事後条件のリストは、特定のアルゴリズムの仕様によって定義されます。

操作の短縮形

ユーザーコードの冗長性を軽減するため、oneDAL では一般的な操作の定義で説明されている関数に加え、各操作の短縮形 (ショートカットとも呼ばれます) のオーバーロード関数が定義されています。

  • ホストで実行されるショートカットは、ホストの一般的な関数と同じ操作を実行しますが、キューを明示的に渡す必要がありません。

    template <typename Descriptor>
    %OPERATION%_result_t<Descriptor> %OPERATION%(
       const Descriptor& desc,
       const %OPERATION%_input_t<Descriptor>& input);
    
  • 明示的な入力を省略できるショートカット。

    template <typename Descriptor, typename... Args>
    %OPERATION%_result_t<Descriptor> %OPERATION%(
       sycl::queue& queue,
       const Descriptor& desc,
       Args&&... args);
    
  • 明示的なキューと入力を省略できるショートカット。これは、前述の 2 つのショートカットを組み合わせたものです。

    template <typename Descriptor, typename...Args>
    %OPERATION%_result_t<Descriptor> %OPERATION%(
       const Descriptor& desc,
       Args&&... args);
    

入力

入力オブジェクトは、アルゴリズムが特定の操作を実行するために必要なすべてのデータを集約します。データはテーブル (英語) を介して表現されるため、通常、入力はテーブルのコレクションですが、テーブルに制限されることなく任意のタイプのオブジェクトを集約できます。

一般的に、入力クラスの定義は記述子 (英語) に類似しています。入力は、対応するゲッターとセッターメソッドを使用してアクセス可能なプロパティーを定義します。入力プロパティーの要件は、記述子プロパティーの要件 (英語) と同じです。

次のサンプルコードは、入力定義の一般的な構造を示します。特定のアルゴリズムと操作の入力を定義するには、次の文字列を置き換えます。

  • %ALGORITHM% は、アルゴリズムの名称と名前空間です。
  • %OPERATION% は、操作の名称です。
  • %PROPERTY_NAME%%PROPERTY_TYPE% は、入力プロパティーの名前とタイプです。
namespace oneapi::dal::%ALGORITHM% {

template <typename Task = task::by_default>
class OPERATION_input {
public:
   /* コンストラクター */
   %OPERATION%_input(const %PROPERTY_TYPE%& %PROPERTY_NAME%,
                     /* 追加のプロパティー */)

   /*  `%PROPERTY_NAME%` プロパティーのゲッターとセッター  */
   descriptor& set_%PROPERTY_NAME%(%PROPERTY_TYPE% value);
   %PROPERTY_TYPE% get_%PROPERTY_NAME%() const;

   /* 追加のプロパティー */
};

} // namespace oneapi::dal::%ALGORITHM%

注: 入力はアルゴリズムと操作固有であるため、各 %ALGORITHM%%OPERATION% のペアは、固有のプロパティー・セットとして定義する必要があります。

結果

結果オブジェクトは、アルゴリズムが計算したすべての出力値を集約します。入力に対するすべての仮定は結果にも適用されます。

namespace oneapi::dal::%ALGORITHM% {

template <typename Task = task::by_default>
class OPERATION_result {
public:
   /* コンストラクター */
   %OPERATION%_result(const %PROPERTY_TYPE%& %PROPERTY_NAME%,
                      /* 追加のプロパティー */)

   /*  `%PROPERTY_NAME%` プロパティーのゲッターとセッター  */
   descriptor& set_%PROPERTY_NAME%(%PROPERTY_TYPE% value);
   %PROPERTY_TYPE% get_%PROPERTY_NAME%() const;

   /* 追加のプロパティー */
};

} // namespace oneapi::dal::%ALGORITHM%

サポートされる操作

特定の操作の詳細ついては、次の「サポートされる操作」の節をご覧ください。


サポートされる操作

この節では oneDAL でサポートされる操作について説明します。一般的な操作の定義の詳細は、操作」の節をご覧ください。

次の表は、アルゴリズムの記述子とそれぞれの操作が同時に使用できるかどうかを示します。

トレーニング

トレーニング操作は、マシンラーニング・アルゴリズムのトレーニング手順を実行します。トレーニング後に得られる結果には、推論操作に渡すことが可能なモデルが含まれます。

namespace oneapi::dal {

template <typename Descriptor>
using train_input_t = /* 実装定義 */;

template <typename Descriptor>
using train_result_t = /* 実装定義 */;

template <typename Descriptor>
train_result_t<Descriptor> train(
   sycl::queue& queue,
   const Descriptor& desc,
   const train_input_t<Descriptor>& input);

} // namespace oneapi::dal

推論

推論操作は、トレーニングの結果として得られたモデルに基づいて、マシンラーニング・アルゴリズムの推論手順を実行します。

namespace oneapi::dal {

template <typename Descriptor>
using infer_input_t = /* 実装定義 */;

template <typename Descriptor>
using infer_result_t = /* 実装定義 */;

template <typename Descriptor>
infer_result_t<Descriptor> infer(
   sycl::queue& queue,
   const Descriptor& desc,
   const infer_input_t<Descriptor>& input);

} // namespace oneapi::dal

計算

アルゴリズムで明確にトレーニング・ステージと推論ステージが定義されていない場合、計算操作が実行されます。

namespace oneapi::dal {

template <typename Descriptor>
using compute_input_t = /* 実装定義 */;

template <typename Descriptor>
using compute_result_t = /* 実装定義 */;

template <typename Descriptor>
compute_result_t<Descriptor> compute(
   sycl::queue& queue,
   const Descriptor& desc,
   const compute_input_t<Descriptor>& input);

} // namespace oneapi::dal

計算モード

バッチ

バッチ処理モードでは、アルゴリズムはデータセット全体を処理して最終結果を生成します。その時点でデータセット全体が利用可能でないか、データセットがデバイスメモリーに収まらない場合、シナリオはより複雑になります。

オンライン

オンライン処理モードでは、アルゴリズムはデバイスのメモリーにストリームされたブロックでデータセットを処理します。部分的な結果は段階的に更新され、最後のデータブロックが処理されると確定されます。

分散

分散処理モードでは、アルゴリズムは複数のデバイス (計算ノード) に分散されたデータセットを処理します。各ノードでアルゴリズムは部分的な結果を生成し、最後にメインノードの結果にマージされます。


法務上の注意書き

The content of this oneAPI Specification is licensed under the Creative Commons Attribution 4.0 International License (英語). Unless stated otherwise, the sample code examples in this document are released to you under the MIT license (英語).

This specification is a continuation of Intel’s decades-long history of working with standards groups and industry/academia initiatives such as The Khronos Group*, to create and define specifications in an open and fair process to achieve interoperability and interchangeability. oneAPI is intended to be an open specification and we encourage you to help us make it better. Your feedback is optional, but to enable Intel to incorporate any feedback you may provide to this specification, and to further upstream your feedback to other standards bodies, including The Khronos Group SYCL* specification, please submit your feedback under the terms and conditions below. Any contribution of your feedback to the oneAPI Specification does not prohibit you from also contributing your feedback directly to other standard bodies, including The Khronos Group under their respective submission policies.

By opening an issue, providing feedback, or otherwise contributing to the specification, you agree that Intel will be free to use, disclose, reproduce, modify, license, or otherwise distribute your feedback at its sole discretion without any obligations or restrictions of any kind, including without limitation, intellectual property rights or licensing obligations.

This document contains information on products, services and/or processes in development. All information provided here is subject to change without notice.

© Intel Corporation. Intel、インテル、Intel ロゴ、その他のインテルの名称やロゴは、Intel Corporation またはその子会社の商標です。

* その他の社名、製品名などは、一般に各社の表示、商標または登録商標です。

« パート 36        目次        パート 38 »
タイトルとURLをコピーしました