Representation and Reference Lowering of ONNX Models in MLIR Compiler Infrastructure
View the Project on GitHub onnx/onnx-mlir
This project is maintained by onnx
Hosted on GitHub Pages — Theme by orderedlist
onnx-mlir
|
Static Public Member Functions | |
static OMTensorList | mainGraph (OMTensorList list) |
static String[] | queryEntryPoints () |
static String | inputSignature () |
static String | inputSignature (String entry_point) |
static String | outputSignature () |
static String | outputSignature (String entry_point) |
ONNX-MLIR project comes with an executable onnx-mlir
capable of compiling onnx models to a jar. In this documentation, we demonstrate how to interact programmatically with the compiled jar using ONNX-MLIR's Java Runtime API.
OMModel
is the class implementing the default model entry point and input/output signature functions.
OMTensor
is the class used to describe the runtime information (rank, shape, data type, etc) associated with a tensor input or output.
OMTensorList
is the class used to hold an array of OMTensor so that they can be passed into and out of the compiled model as inputs and outputs.
All compiled models will have the same exact Java function signature equivalent to:
Intuitively, the model takes a list of tensors as input and returns a list of tensors as output.
We demonstrate using the API functions to run a simple ONNX model consisting of an add operation. To create such an onnx model, use this python script
To compile the above model, run onnx-mlir --EmitJNI add.onnx
and a jar file "add.jar" should appear. We can use the following Java code to call into the compiled function computing the sum of two inputs:
Compile with javac -cp javaruntime.jar Add.java
, you should see a class Add.class
appearing. Run it with java -cp .:add.jar Add
, and the output should be:
Exactly as it should be.
|
inlinestatic |
Input signature of default model runtime entry point
|
inlinestatic |
|
inlinestatic |
Default model runtime entry point
list | input tensor list |
|
inlinestatic |
Output signature of default model runtime entry point
|
inlinestatic |
|
inlinestatic |
Query all entry point names in the model.