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

その他

この記事は、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」の「Data Sources」の節を取り上げています。

データソース

ここでは、データソースの概念に関連するタイプについて説明します。

リード

リード操作は、args (英語) オブジェクトによって示されるデータソースと引数を結果 (英語) オブジェクトに変換する関数です。操作は以下を行います。

  • データソースのすべてのデータを取得して変換ルーチンを実行します。
  • SYCL* キューをデータ取得および変換ルーチンに渡します。

リード操作の定義

次のサンプルコードは、リード操作の宣言方法を示しています。

namespace oneapi::dal {

template <typename Object, typename DataSource>
using read_args_t = /* 実装定義 */;

template <typename Object, typename DataSource>
using read_result_t = Object;

template <typename Object, typename DataSource>
read_result_t<Object, DataSource> read(
   sycl::queue& queue,
   const DataSource& data_source,
   const read_args_t<Object, DataSource>& args);

} // namespace oneapi::dal

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

  • 操作は次の順序で 3 つのパラメーターを受け入れなければなりません。
    • SYCL* キュー・オブジェクト
    • データソース
    • args (英語) オブジェクト
  • 操作は結果 (英語) オブジェクトを返します。
  • read_args_tread_result_t エイリアス・テンプレートは、引数と戻り値のタイプ推測に使用されます。

リード操作のショートカット

次のサンプルコードは、リード操作の宣言方法を示しています。

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

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

    template <typename Object, typename DataSource>
    read_result_t<Object, DataSource> read(
       const DataSource& data_source,
       const read_args_t<Object, DataSource>& args);
    
  • 明示的な args の作成を省略できるショートカット。

    template <typename Object, typename DataSource, typename... Args>
    read_result_t<Object, DataSource> read(
       sycl::queue& queue,
       const DataSource& data_source,
       Args&&... args);;
    
  • 明示的なキューと args の作成を省略できるショートカット。これは、前述の 2 つのショートカットを組み合わせています。

    template <typename Object, typename DataSource, typename... Args>
    read_result_t<Object, DataSource> read(
       const DataSource& data_source,
       Args&&... args);

Args

  • 文字列 %DATA_SOURCE% は、データソース名に置き換える必要があります (例、csv)。
  • %PROPERTY_NAME%%PROPERTY_TYPE% は、データソースの args プロパティーの名前とタイプに置き換える必要があります。
namespace oneapi::dal::%DATA_SOURCE% {

template <typename Object, typename DataSource>
class read_args {
public:
   read_args(
      const %PROPERTY_TYPE_1%& property_name_1,
      const %PROPERTY_TYPE_2%& property_name_2,
      /* 追加のプロパティー */
   )
   /* `%PROPERTY_NAME_1%` プロパティーのゲッターとセッター */
   descriptor& set_%PROPERTY_NAME_1%(%PROPERTY_TYPE_1% value);
   %PROPERTY_TYPE_1% get_%PROPERTY_NAME_1%() const;
   /* `%PROPERTY_NAME_2%` プロパティーのゲッターとセッター */
   descriptor& set_%PROPERTY_NAME_2%(%PROPERTY_TYPE_2% value);
   %PROPERTY_TYPE_2% get_%PROPERTY_NAME_2%() const;
   /* 追加のプロパティー */
};
} // namespace oneapi::dal::%DATA_SOURCE%

結果

読み取り操作の結果は、Object タイプのメモリー内オブジェクトのインスタンスです。

データのソースタイプ

oneDAL では一連のクラスを定義します。

データのソースタイプ 説明
CSV データソース テキストファイルからテーブル (英語) にデータを読み取ることを許可するデータソース。

CSV データソース

csv::data_source クラスは、csv ファイルとして表現されるデータソースにアクセスする API です。CSV データソースをリード操作で使用し、指定された入力ファイルからテキスト形式のデータを抽出して、与えられたパラメーター (区切り文字やリードオプションなど) を使用して処理することで数値表現に変換してメモリー内に選択されたタイプのデータセット (英語) として保存します。

CSV データソースを使用するリード操作でサポートされるメモリー内オブジェクトのタイプは oneapi::dal::table です。

CSV データソースでは、コンストラクターで入力ファイル名を指定しますが、区切り文字や読み取りオプションなどのパラメーターはデフォルト値に依存します。

使用例

using namespace oneapi;

const auto data_source = dal::csv::data_source("data.csv", ',');

const auto table = dal::read<dal::table>(data_source);

プログラミング・インターフェイス

この節のすべてのタイプと関数は、oneapi::dal 名前空間で宣言され、oneapi/dal/io/csv.hpp ヘッダーファイルをインクルードして使用できます。

enum class read_options : std::uint64_t {
   none = 0,
   parse_header = 1 << 0
};

constexpr char default_delimiter = ',';
constexpr read_options default_read_options = read_options::none;

class data_source {
public:
   data_source(const char *file_name,
               char delimiter = default_delimiter,
               read_options opts = default_read_options);

   data_source(const std::string &file_name,
               char delimiter = default_delimiter,
               read_options opts = default_read_options);

   std::string get_file_name() const;
   char get_delimiter() const;
   read_options get_read_options() const;
};

クラスについては、こちら (英語) を参照してください。

oneapi::dal::read<Object>(...) の読み取りについては、こちら (英語) を参照してください。


法務上の注意書き

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 またはその子会社の商標です。

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

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