2.4 KiB
Import ONNX specifications into ONNX-MLIR
ONNX specifications are defined under onnx/defs
directory in the ONNX project repository.
There is a python script onnx/defs/gen_doc.py that automatically generate documents about operations in ONNX (docs/Operations.md).
ONNX-MLIR modified this script to import ONNX specifications into ONNX-MLIR.
There are two files generated for ONNX MLIR with the modified gen_doc.py:
src/Dialect/ONNX/ONNXOps.td.inc
: Operation definition for MLIR TableGen.src/Dialect/ONNX/ONNXOps.td
includes this file.src/Builder/OpBuildTable.inc
: C++ code for ONNX-MLIR frontend to import operation nodes from ONNX model.src/Builder/FrontendDialectTransformer.cpp
includes this file.
How to use the script
- Install ONNX. We highly recommend that you use the one located at
third_party/onnx.
- Make target
OMONNXOpsIncTranslation
. For example,
make OMONNXOpsIncTranslation
Target OMONNXOpsIncTranslation
invokes the script and places the generated files into the correct directories correspondingly.
Consistency
For reference to the schema and semantics of an operation, please refer to ONNX Dialect. Even though we strive to support the latest version of ONNX specification as quickly as we can, there will inevitably be a delay between the introduction of new changes in the ONNX specification and the adoption in our codebase. Due to the possibility of such a delay, operator definition within the ONNX project repository may describe features and schemas that we do not yet support.
Customization
In addition to following the ONNX specification, the modified gen_doc.py provides some mechanism for you to customize the output. Several tables are defined at the beginning of the script:
special_attr_defaults
: gives attribute special default value.special_op_handler
: creates special import function in frontend_dialect_transformer.cpp. Currently, a special handler is used for operations with operational argumentsOpsWithShapeInference
: list of operations which have shape inference definedOpsWithCanonicalizer
: list of operations which have a canonical formOpsWithPromotableConstOperands
: list of operations which have operands that, if produced by constant operations, should be promoted to become an attribute (via attribute promotion)custom_builder_ops_list
: list of operations which need custom build methods to deduce result types