少ないリソースを酷使する

低レイヤーとレトロPC(PC98,MSX)が好きな情報学生

OpenVINOで Intel Xe GPU を使うには一手間必要

Intel Xe GPU 環境に対応したOpenVINOのインストールはリファレンスのデフォルト手順通りではうまくいかないという話.

環境

CPU: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
GPU: Intel(R) Iris(R) Xe Graphics
OS: Ubuntu 20.04.2 LTS (x86_64)
OpenVINO tool kit: 2021.2.185

失敗例

過去に書いたOpenVINOの導入手順通りだとGPUが使えない.
t-takeda.hatenablog.com
デモを実行しようとすると以下のようなエラーが出る.

$ ./demo_benchmark_app.sh -d GPU

- 省略 -

[ INFO ] Device info: 
[ ERROR ] Failed to create plugin /opt/intel/openvino_2021.2.185/deployment_tools/inference_engine/lib/intel64/libclDNNPlugin.so for device GPU
Please, check your environment
[CLDNN ERROR]. clGetPlatformIDs error -1001

Error on or near line 221; exiting with status 1

原因

原因は多分,OpenVINOのセットアップツールでインストールできるIntel® Graphics Compute Runtime for OpenCL™(現在では Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver - 通称:NEO という呼び方か?)のバージョンが古いからだろう.
インストールしようとした時に出るメッセージにちゃんと理由が書いてある.

$ sudo -E su
root@hoge:/opt/intel/openvino_2021/install_dependencies# ./install_NEO_OCL_driver.sh
Intel® Graphics Compute Runtime for OpenCL™ Driver installer
Checking current driver version...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Checking processor generation...
install_NEO_OCL_driver.sh: Detected 10th generation Intel® Core™ processor (formerly Ice Lake) or 11th generation Intel® Core™ processor (formerly Tiger Lake).
Driver version 20.35.17767 is going to be installed to fully utilize hardware features and performance.
You are still able to use the older version 19.41.14441. Use the older driver? (y/n) [n] y
Intel® Graphics Compute Runtime for OpenCL™ Driver installation skipped because current version greater or equal to 19.41.14441
Installation of Intel® Graphics Compute Runtime for OpenCL™ Driver interrupted.

公式のインストールガイドにも書いてある.
https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_linux.html#additional-GPU-steps

Higher hardware versions require a higher driver version, namely 20.35 instead of 19.41. If the script fails to uninstall the driver, uninstall it manually. During the script execution, you may see the following

つまりは「Gen10以降のIntelチップで使うならCompute Runtimeは20.35以降のバージョンをインストールせよ」ということである.

もし環境構築に失敗したら(OpenVINOのuninstall)

環境構築に失敗した場合,余計な問題を避けるため,一旦以下のコマンドでOpenVINOをアンインストールしよう.
念の為その後再起動もするとよい.

$ cd /opt/intel/openvino_2021/openvino_toolkit_uninstaller/
$ sudo ./uninstall.sh 

成功例

参考になった情報

https://community.intel.com/t5/Intel-Distribution-of-OpenVINO/The-inference-engine-returns-error-clGetPlatformIDs-error-1001/m-p/1246561 https://www.intel.co.jp/content/www/jp/ja/support/articles/000057923/software/development-software.html

最新のCompute Runtimeをインストール

過去に書いた記事の[とりあえず動作確認]までやる.
その後,最新のIntel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driverを入れる.
インストールの仕方はリリース情報にコマンド付きで細かく説明されているので正確な情報はそこを参照すべし.
https://github.com/intel/compute-runtime/releases/latest

参考までに,今回のインストールのコマンド履歴を書いておく.
(以下のコードはコピペせずに,常に最新のリリースのインストール方法を確認すべし)

$ cd ~/
$ mkdir neo
$ cd neo
wget https://github.com/intel/compute-runtime/releases/download/21.09.19150/intel-gmmlib_20.3.2_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.6410/intel-igc-core_1.0.6410_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.6410/intel-igc-opencl_1.0.6410_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.09.19150/intel-opencl_21.09.19150_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.09.19150/intel-ocloc_21.09.19150_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.09.19150/intel-level-zero-gpu_1.0.19150_amd64.deb

$ wget https://github.com/intel/compute-runtime/releases/download/21.09.19150/ww09.sum
$ sha256sum -c ww09.sum

$ sudo dpkg -i *.deb

sudoなしで実行できるようにする

このままでもOpenVINOはGPUバイスで動くのだが,なんでか毎回sudoを付けなければいけない.
clinfosudo clinfoとしなければGPUの情報が出てこない.
OpenCLをインストールしたことがある人ならわかるかもしれないが,これはユーザグループの問題だ,
今までだったらユーザをvideoグループに追加すれば万事解決だったが,今回はどうもそれではうまくいかなくてかなり悩んだ.
結果的にユーザをrenderというグループに追加することで解決した.これでsudoしなくてもOpenCLが呼び出せる.

$ sudo usermod -a -G video $LOGNAME 
$ sudo usermod -a -G render $LOGNAME 
$ cat /etc/group | grep $LOGNAME 
sudo:x:27:<USERNAME>
video:x:44:<USERNAME>
<USERNAME>:x:1001:
render:x:130:<USERNAME>

同じような問題でissueを立てている人もいたが,どこかのバージョンアップを機にグループ名がvideoからrenderに変わったのか...?
https://github.com/intel/compute-runtime/issues/350

やっとデモが動かせる!

さてさて,それでは早速Xe環境でデモを動かしてみよう.
以下のフォルダにデモの実行スクリプトが入っている.

$ cd /opt/intel/openvino_2021/deployment_tools/demo/

今回はdemo_benchmark_app.shなるものを実行してみる.
これは畳み込みニューラルネットワークSqueezeNetを1000回実行してベンチマークをとるものである.
...多分.

CPU実行

$ ./demo_benchmark_app.sh
Full device name: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz

Count:      1000 iterations
Duration:   1854.49 ms
Latency:    7.41 ms
Throughput: 539.23 FPS

GPU実行

$ ./demo_benchmark_app.sh -d GPU
Full device name: Intel(R) Iris(R) Xe Graphics [0x9a49] (iGPU)

Count:      1000 iterations
Duration:   1075.82 ms
Latency:    4.24 ms
Throughput: 929.52 FPS

GPUを使った実行の方が速いため,ちゃんとGPUを使っているのがわかる.やったね!