運用 - 2.5 日本語

Vitis AI ユーザー ガイド (UG1414)

Document ID
UG1414
Release Date
2022-06-15
Version
2.5 日本語

このセクションでは、graph_runner API でカスタム op を使用して pytorch モデルを運用します。graph_runner API は、C++ と Python の両方をサポートしています。Vitis-AI/examples/Vitis-AI-Library/samples/graph_runner にある graph_runner のサンプルを参照してください。

  1. テスト コードを格納する新規ディレクトリを作成します。
  2. ソース ファイルを作成し、このサンプル用に次の関数を実装します。
    1. パラメーターの解析と初期化
    2. プリプロセス
    3. Model_run
    4. ポストプロセス
    このサンプルの基本的なフローは、次のとおりです。
    図 1. このサンプルの基本的なフロー
  3. プログラムをビルドします。
    1. cpp ソース ファイルが 1 つしかない場合など、シンプルなプロジェクトでは、Vitis-AI/examples/Vitis-AI-Library/samples/graph_runner から任意の既存 build.sh をコピーして、適宜変更することもできます。次のコマンドを実行してプログラムをビルドします。
      cd <your sample folder>
      bash build.sh
      次の図に、resnet50_graph_runner サンプルの build.sh を示します。
    2. このサンプルのようにプロジェクトが複雑な場合は、CMakeLists.txt を使用した方が簡単にコンパイルできます。CMakeLists.txt の詳細は、Vitis-AI/examples/Custom_OP_Demo/pytorch_example/deployment/cpp/pointpillars_graph_runner/CMakeLists.txt を参照してください。
      次のコマンドを実行してプログラムをビルドします。
      cd <your sample folder>
      mkdir build
      cd build
      cmake ..
      make

    コンパイルが正しく完了すると、実行可能プログラム sample_pointpillars_graph_runner<your sample folder> に生成されます。

  4. プログラムをテストする
    プログラムをテストする前に、xmodel、テスト イメージ、カスタム op ライブラリ libvart_op_imp_PPScatterV2.so および実行可能プログラム sample_pointpillars_graph_runner をボードにコピーしてください。カスタム op ライブラリは /usr/lib に置いてください。次のコマンドを実行してテストを実行します。
    ./sample_pointpillars_graph_runner ./pointpillars_full_customer_op.xmodel sample_pointpillars.bin

    次に、このサンプルの実行結果を示します。

    root@xilinx-zcu102-2021_2:~/pointpillars_graph_runner# ./sample_pointpillars_graph_runner pointpillars_op.xmodel sample_pointpillars.bin
    WARNING: Logging before InitGoogleLogging() is written to STDERR
    W1202 05:59:20.517452 1307 tool_function.cpp:177] [UNILOG][WARNING] The operator named VoxelNet__VoxelNet_input_4, type: PPScatterV2, is not defined in XIR. XIR creates the definition of this operator automatically. You should specify the shape and the data_type of the output tensor of this operation by set_attr("shape", std::vector) and set_attr("data_type", std::string)
    result: 0
    0 18.541065 3.999999 -1.732742 1.703191 4.419279 1.465484 1.679375 0.880797
    0 34.522400 1.505865 -1.515198 1.503061 3.550991 1.420396 1.710625 0.851953
    0 10.917599 4.705865 -1.622433 1.650789 4.350764 1.634866 1.632500 0.851953
    1 21.338514 -2.400001 -1.681677 0.600000 1.963422 1.784916 4.742843 0.777300
    0 57.891731 -4.188268 -1.536627 1.575194 3.780010 1.512004 2.007500 0.679179
カスタム op のサンプルをプロファイリングする場合は、次に示すように環境変数 DEEPHI_PROFILING=1 を使用します。
env DEEPHI_PROFILING=1 ./sample_pointpillars_graph_runner ./pointpillars_full_customer_op.xmodel sample_pointpillars.bin
次に、プロファイリング結果を示します。
I1130 01:29:53.038476 15571 cpu_task.cpp:163] CPU_UPDATE_INPUT : 5us
I1130 01:29:53.038684 15571 cpu_task.cpp:166] CPU_UPDATE_OUTPUT : 55us
I1130 01:29:53.038872 15571 cpu_task.cpp:169] CPU_SYNC_FOR_READ : 46us
I1130 01:29:53.039050 15571 cpu_task.cpp:181] CPU_OP_EXEC : 32us
I1130 01:29:53.039232 15571 cpu_task.cpp:181] CPU_OP_EXEC : 36us
I1130 01:29:53.039597 15571 cpu_task.cpp:181] CPU_OP_EXEC : 232us
I1130 01:29:53.066352 15571 cpu_task.cpp:181] CPU_OP_EXEC : 26575us
I1130 01:29:53.066745 15571 cpu_task.cpp:195] CPU_SYNC_FOR_WRITE : 1us