Intel oneAPI使ってみた

note.com

使っているノートPCはSkylake (6th Gen CPU, Gen9 GPU)とギリギリ Intel oneAPI 対応プラットフォームなので、
開発環境をインストールしてサンプルを動かしてみました

本記事の対象

LinuxFPGAここを見てね

インストールするもの

インストール手順

  1. GPUドライバーの更新(上記note記事にTIPSのっけてます)
  2. Visual Studio 2019を使う場合は、先にインストールとのこと(拙環境はインストール済みなので割愛)
  3. oneAPI Base Toolkitをダウンロード. アカウントがなければ先に作成
  4. oneAPI Base Toolkitをインストール. 特に操作なし

さぁ始めよう

  • やり方は以下の2種類「お好きな方をどうぞ」
  • コマンドラインベース
    • setvars.batで環境変数通してからうんぬんかんぬん
    • 大体のサンプルはCMake使う前提らしい
    • だからCMake入れようねぇと言っているが、この後のサンプルはMSBuild使ってる謎
  • VisualStudioベース
    • 拙環境だとVS2019 ver.16.5.5と>16.4だったが、ソリューションファイル読み込みでエラーが発生したのでver.16.7.3に更新したところ読み込めるようになった
      f:id:Onswar:20200919182333p:plain
      VS2019のバージョン
    • 実行結果は以下の通り
      f:id:Onswar:20200919182337p:plain
      vector-add-usm 実行結果
      • GPUで実行しているぽい

他のサンプル

他には↓のようなサンプルがある

f:id:Onswar:20200919204643p:plain
VS2019のサンプルメニュー

oneVPL(Video Processing Library)"Hello DPC++ interop" を実行してみる

f:id:Onswar:20200919204233p:plain
タスクマネージャーのGPUペイン(dpcpp-blur.exe実行時)

GPUを使っているように見える

※ソースそのままだと実行時エラーが発生したので以下のように、device.is_gpu()を有効にするよう変更しました

// Select device on which to run kernel.
class MyDeviceSelector : public cl::sycl::device_selector {
public:
    MyDeviceSelector() {}

    int operator()(const cl::sycl::device &device) const override {
        const std::string name =
            device.get_info<cl::sycl::info::device::name>();

        std::cout << "Trying device: " << name << "..." << std::endl;
        std::cout << "  Vendor: "
                  << device.get_info<cl::sycl::info::device::vendor>()
                  << std::endl;

        if (device.is_cpu())
            return 500; // We give higher merit for CPU
        //if (device.is_accelerator()) return 400;
        //if (device.is_gpu()) return 300;
        //if (device.is_host()) return 100;
        return -1;
    }
};
// Select device on which to run kernel.
class MyDeviceSelector : public cl::sycl::device_selector {
public:
    MyDeviceSelector() {}

    int operator()(const cl::sycl::device &device) const override {
        const std::string name =
            device.get_info<cl::sycl::info::device::name>();

        std::cout << "Trying device: " << name << "..." << std::endl;
        std::cout << "  Vendor: "
                  << device.get_info<cl::sycl::info::device::vendor>()
                  << std::endl;

        //if (device.is_cpu())
        //    return 500; // We give higher merit for CPU
        //if (device.is_accelerator()) return 400;
        if (device.is_gpu()) return 300;
        //if (device.is_host()) return 100;
        return -1;
    }
};

dpcpp-blur.exe

This sample is a command line application that takes a file containing a raw I420 format video elementary stream as an argument, converts it to RGB32 with oneVPL and blurs each frame with DPC++ by using SYCL kernel, and writes the decoded output to out.rgba in RGB32 format.

I420フォーマットのビデオエレメンタリーストリームをoneVPLを使ってRGB32に変換しつつ
DPC++(Data Parallel C++)で書かれたSYCLカーネルによるブラーを毎フレームかけてout.rgbaファイルに書き出す処理をしているらしい

ffplayで再生してみるとブラーかかってる(元データしらんけど)

f:id:Onswar:20200919212242p:plain
ffplayによるout.rgbaの再生結果

おわりに

8000円で買った中古ノートPCで、スパコンでも使われるソフトウェアフレームワークを試せたのは中々楽しい oneAPIのベース技術であるSYCLはベンダー固有ではないので、どっかで役に立てばいいなぁ