Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 1.38 KB

AddingCustomOp.md

File metadata and controls

27 lines (21 loc) · 1.38 KB

Adding a new op

A new op can be written and registered with ONNXRuntime in the following 3 ways

1. Using a dynamic shared library

  • First write the implementation of the op and schema (if required) and assemble them in a shared library. See this for an example. Currently this is supported for Linux only.

Example of creating a shared lib using g++ on Linux: g++ -std=c++14 -shared test_custom_op.cc -o test_custom_op.so -fPIC -I. -Iinclude/onnxruntime -L. -lonnxruntime -DONNX_ML -DONNX_NAMESPACE=onnx

  • Register the shared lib with ONNXRuntime. See this for an example.

2. Using RegisterCustomRegistry API

  • Implement your kernel and schema (if required) using the OpKernel and OpSchema APIs (headers are in the include folder).
  • Create a CustomRegistry object and register your kernel and schema with this registry.
  • Register the custom registry with ONNXRuntime using RegisterCustomRegistry API.

See this for an example.

3. Contributing the op to ONNXRuntime

This is mostly meant for ops that are in the process of being proposed to ONNX. This way you don't have to wait for an approval from the ONNX team if the op is required in production today. See this for an example.