mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-16 18:31:27 +00:00
* initial setup and rename "how to" to "setup" * move API to main nav * move api to main nav * add get starated, rework nav order * rename to install move mds out of install section * update api nav and home page * add install docs and python qs updates * python get started work * remove c and obj c for now * move java, python, and obj-c docs under api folder * move java api html to iframe (ugh) * remove api docs w/o details, move api text getstar * remove api docs wo detail updates get started * remvoe iframes * move eco system to main nav * fix api buttons * added more examples moved intro to ORT * fix links * fix get started titles * fix get started titles * fix more links * fix more links * more link fixes * fix nav remove inferencing and training subnav * fix top nav remove inference and training nav * fix title * fix tutorials nav hierarchy * fix python api button * add tenorflow keras example * fix quickstart toc * add imports fix spacing * fix links * update nav and python get started page * move ort training example, add coming soon for iot * update C# get started * fix spacing on quantization * Add some js get started content * fix formatting * fix typo * removed onnx-pytorch and onnx-tf * updated pip install torch and added links iot page * added pytorch tutorial heirarchy * updated web to docs soon added release blog link * add web link
62 lines
3 KiB
Markdown
62 lines
3 KiB
Markdown
---
|
|
title: Add a new execution provider
|
|
parent: Execution Providers
|
|
nav_order: 14
|
|
---
|
|
|
|
# Add a new Execution Provider to ONNX Runtime
|
|
{: .no_toc }
|
|
|
|
## Contents
|
|
{: .no_toc }
|
|
|
|
* TOC placeholder
|
|
{:toc}
|
|
|
|
## Create the Execution Provider
|
|
|
|
1. Create a folder under onnxruntime/core/providers
|
|
2. Create a folder under include/onnxruntime/core/providers, it should has the same name as the first step.
|
|
3. Create a new class, which must inherit from [IExecutionProvider](https://github.com/microsoft/onnxruntime/tree/master/include//onnxruntime/core/framework/execution_provider.h). The source code should be put in 'onnxruntime/core/providers/[your_provider_name]'
|
|
4. Create a new header file under include/onnxruntime/core/providers/[your_provider_name]. The file should provide one function for creating an OrtProviderFactoryInterface. You may use 'include/onnxruntime/core/providers/cpu/cpu_provider_factory.h' as a template. You don't need to provide a function for creating MemoryInfo.
|
|
5. Put a symbols.txt under 'onnxruntime/core/providers/[your_provider_name]'. The file should contain all the function names that would be exported from you provider. Usually, just a single function for creating provider factory is enough.
|
|
6. Add your provider in onnxruntime_providers.cmake. Build it as a static lib.
|
|
7. Add one line in cmake/onnxruntime.cmake, to the 'target_link_libraries' function call. Put your provider there.
|
|
|
|
Examples:
|
|
|
|
* [CPU Execution Provider](https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/cpu_execution_provider.h)
|
|
* [CUDA Execution Provider](https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cuda/cuda_execution_provider.h)
|
|
* [DNNL Execution Provider](https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/dnnl/dnnl_execution_provider.h)
|
|
|
|
## Use the Execution Provider
|
|
|
|
1. Create a factory for that provider, by using the c function you exported in 'symbols.txt'
|
|
2. Put the provider factory into session options
|
|
3. Create session from that session option
|
|
|
|
Example:
|
|
|
|
```c
|
|
OrtEnv* env;
|
|
OrtInitialize(ORT_LOGGING_LEVEL_WARNING, "test", &env)
|
|
OrtSessionOptions* session_option = OrtCreateSessionOptions();
|
|
OrtProviderFactoryInterface** factory;
|
|
OrtCreateCUDAExecutionProviderFactory(0, &factory);
|
|
OrtSessionOptionsAppendExecutionProvider(session_option, factory);
|
|
OrtReleaseObject(factory);
|
|
OrtCreateSession(env, model_path, session_option, &session);
|
|
```
|
|
|
|
## Test the Execution Provider
|
|
|
|
To ease the testing of your execution provider, you can add a new case for it to the `onnx_test_runner` command,
|
|
do this by adding it to `onnxruntime/test/onnx/main.cc` file, following the pattern for other existing providers.
|
|
|
|
Once you have this in place, you can run the `onnx_test_runner`, like this:
|
|
|
|
```
|
|
$ cd build/PLATFORM/CONFIGURATION
|
|
$ ./onnx_test_runner -e YOUR_BACKEND ./testdata/ort_minimal_e2e_test_data/
|
|
$ ./onnx_test_runner -e YOUR_BACKEND ./testdata/gemm_activation_fusion/
|
|
```
|