実行プロバイダー
実行プロバイダーへの貢献
Section titled “実行プロバイダーへの貢献”このドキュメントでは、ONNX Runtimeに実行プロバイダー(EP)を貢献する方法について説明します。
実行プロバイダーは、ONNX Runtimeがさまざまなハードウェアアクセラレータで推論を実行できるようにするプラグインです。EPは、ONNXモデル内の演算子を特定のハードウェアに最適化されたライブラリにマッピングすることによって機能します。
実行プロバイダーの作成
Section titled “実行プロバイダーの作成”実行プロバイダーはC++で実装されます。EPを作成するには、IExecutionProviderインターフェイスを実装する必要があります。
class MyExecutionProvider : public IExecutionProvider { public: MyExecutionProvider(); ~MyExecutionProvider() override;
std::vector<std::unique_ptr<ComputeCapability>> GetCapability( const GraphViewer& graph_viewer, const std::vector<const KernelRegistry*>& kernel_registries) const override;
common::Status Compile(const std::vector<FusedNodeAndGraph>& fused_nodes_and_graphs, std::vector<NodeComputeInfo>& node_compute_funcs) override;};GetCapabilityメソッドは、EPが実行できるグラフ内のノードのリストを返します。Compileメソッドは、EPが実行できるノードのサブグラフをコンパイルするために使用されます。
実行プロバイダーの登録
Section titled “実行プロバイダーの登録”実行プロバイダーは、RegisterExecutionProvider関数を使用してONNX Runtimeに登録されます。
std::shared_ptr<IExecutionProviderFactory> CreateMyExecutionProviderFactory() { return std::make_shared<ExecutionProviderFactory>([]() { return std::make_unique<MyExecutionProvider>(); });}
ORT_REGISTER_EXECUTION_PROVIDER("MyExecutionProvider", CreateMyExecutionProviderFactory);実行プロバイダーのビルド
Section titled “実行プロバイダーのビルド”実行プロバイダーは、共有ライブラリとしてビルドする必要があります。その後、SessionOptionsオブジェクトのRegisterCustomOpsLibraryを呼び出すことで、実行時にONNX Runtimeにロードできます。
session_options.RegisterCustomOpsLibrary("my_execution_provider.so");