onnx-mlir/src/dialect/onnx/onnx.td

131 lines
4.7 KiB
TableGen
Raw Normal View History

//===- ONNXOps.td -- ONNX operation definitions ---------*- tablegen -*----===//
//
// Copyright 2019 The IBM Research Authors
//
// =============================================================================
//
// Defines MLIR ONNX operations.
//
//===----------------------------------------------------------------------===//
#ifdef ONNX_OPS
#else
#define ONNX_OPS
#ifdef OP_BASE
#else
include "mlir/IR/OpBase.td"
#endif // OP_BASE
#ifdef SHAPE_INFERENCE_INTERFACE
#else
include "pass/shape_inference_interface.td"
#endif // SHAPE_INFERENCE_INTERFACE
def ONNX_Dialect : Dialect {
let name = "onnx";
let cppNamespace = "";
}
// Base class for ONNX dialect operations. This operation inherits from the base
// `Op` class in OpBase.td, and provides:
// * The parent dialect of the operation.
// * The mnemonic for the operation, or the name without the dialect prefix.
// * A list of traits for the operation.
class ONNX_Op<string mnemonic, list<OpTrait> traits = []> :
Op<ONNX_Dialect, mnemonic, traits>;
//===----------------------------------------------------------------------===//
// ONNX Operations
//===----------------------------------------------------------------------===//
//the tablegen code onnxop.in is generated with gen_doc.py
//clone and install onnx
// git clone --recursive https://github.com/onnx/onnx.git
2019-12-21 13:41:40 +08:00
// set up env for anaconda3 and for ONNF (BOOSTROOT, cmake, gcc ...)
// cd onnx
//install onnx
// CC=gcc CXX=g++ pip install -e .
//run the script
// python onnx/defs/gen_doc.py
//result is in docs/onnxop.inc
//current limitations:
// 1. Attributes are not processed
// 2. output type inference not implemented except Add
// 3. Type Attribute: 'optional' and 'Variadic hetergeneous' are ignored
// 4. type of string, complex64 and complex128 for input/output are ignored
// 5. unsigned int are treated as signed one
include "dialect/onnx/onnxop.inc"
// Indicate entry point functions of ONNX graph.
def ONNXEntryPointOp: ONNX_Op<"EntryPoint"> {
let summary = "Indicate ONNX entry point";
let description = [{
The "onnx.EntryPoint" function indicates the main entry point of ONNX model.
}];
let builders = [OpBuilder<[{Builder *builder, OperationState &state,
FuncOp function, int numInputs, int numOutputs}]>];
let extraClassDeclaration = [{
static ONNXEntryPointOp create(Location location, FuncOp& func,
int numInputs, int numOutputs);
static StringRef getEntryPointFuncAttrName() { return "func"; }
static StringRef getNumInputsAttrName() { return "numInputs"; }
static StringRef getNumOutputsAttrName() { return "numOutputs"; }
}];
}
//===----------------------------------------------------------------------===//
// ONNX Operations for handling optional arguments
//===----------------------------------------------------------------------===//
// To allow pattern matching on operations with optional arguments/outputs we
// implement variants of the original ONNX dialect operations. The ONNX
// operations automatically generated by the `gen_doc.py` script and included
// in the `onnxop.inc` file have all optional arguments and outputs present.
// In the operations below we include the variants with missing operands
// or outputs. This decision affects only ONNX operations with optional
// arguments not ONNX operations with variadic operands.
2020-01-16 03:11:32 +08:00
def ONNXGemmNoBiasOp: ONNX_Op<"GemmNoBias",
2019-11-20 23:59:48 +08:00
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
2020-01-16 03:11:32 +08:00
let summary = "ONNX general matrix multiply operation without bias.";
2019-11-20 23:59:48 +08:00
let description = [{
2020-01-16 03:11:32 +08:00
The "onnx.Gemm" generic matrix multiplication without bias.
2019-11-20 23:59:48 +08:00
}];
2020-01-16 03:11:32 +08:00
let arguments = (ins AnyTypeOf<[AnyMemRef, AnyTensor]>:$lhs_in, AnyTypeOf<[AnyMemRef, AnyTensor]>:$rhs_in);
let results = (outs AnyTypeOf<[AnyMemRef, AnyTensor]>);
}
2020-01-16 02:26:50 +08:00
def ONNXConvNoBiasOp:ONNX_Op<"ConvNoBias",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
2020-01-16 02:26:50 +08:00
let summary = "ONNX Conv operation with no Bias operand.";
let description = [{
"The convolution operator consumes an input tensor and a filter, and"
"computes the output."
}];
2020-01-16 02:26:50 +08:00
let arguments = (ins AnyTypeOf<[AnyMemRef, AnyTensor]>:$X, AnyTypeOf<[AnyMemRef, AnyTensor]>:$W);
let results = (outs AnyTypeOf<[AnyMemRef, AnyTensor]>);
let verifier = [{ return ::verify(*this); }];
}
def ONNXMaxPoolSingleOutOp: ONNX_Op<"MaxPoolSingleOut",
[NoSideEffect]> {
let summary = "ONNX MaxPool operation with a single output.";
let description = [{
"ONNX MaxPool operation with a single output."
"See ONNXMaxPoolOp for a full description of the MaxPool semantics."
}];
let arguments = (ins AnyTypeOf<[AnyMemRef, AnyTensor]>:$X);
let results = (outs AnyTypeOf<[AnyMemRef, AnyTensor]>);
}
#endif // ONNX_OPS