Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,412 changes: 1,152 additions & 260 deletions docs/Dialects/onnx.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lit~=15.0
# numpy 1.24 deprecates np.object, np.bool, np.float, np.complex, np.str,
# and np.int which are used heavily in onnx-mlir.
numpy==2.0.1
onnx==1.19.1
onnx==1.21.0
protobuf==4.25.3
pyyaml==6.0.3
pytest==8.3.2
Expand Down
38 changes: 20 additions & 18 deletions src/Builder/OpBuildTable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -853,14 +853,15 @@ dialect_op_opsets_map_[""]["Attention"] = {24, 23};
dialect_op_opsets_map_[""]["AveragePool"] = {22, 19, 11, 10, 7, 1};
dialect_op_opsets_map_[""]["BatchNormalization"] = {15, 14, 9, 7, 6, 1};
dialect_op_opsets_map_[""]["Bernoulli"] = {22, 15};
dialect_op_opsets_map_[""]["BitCast"] = {26};
dialect_op_opsets_map_[""]["BitShift"] = {11};
dialect_op_opsets_map_[""]["BitwiseAnd"] = {18};
dialect_op_opsets_map_[""]["BitwiseNot"] = {18};
dialect_op_opsets_map_[""]["BitwiseOr"] = {18};
dialect_op_opsets_map_[""]["BitwiseXor"] = {18};
dialect_op_opsets_map_[""]["BlackmanWindow"] = {17};
dialect_op_opsets_map_[""]["Cast"] = {24, 23, 21, 19, 13, 9, 6, 1};
dialect_op_opsets_map_[""]["CastLike"] = {24, 23, 21, 19, 15};
dialect_op_opsets_map_[""]["Cast"] = {25, 24, 23, 21, 19, 13, 9, 6, 1};
dialect_op_opsets_map_[""]["CastLike"] = {25, 24, 23, 21, 19, 15};
dialect_op_opsets_map_[""]["Ceil"] = {13, 6, 1};
dialect_op_opsets_map_[""]["Celu"] = {12};
dialect_op_opsets_map_[""]["CenterCropPad"] = {18};
Expand All @@ -869,18 +870,19 @@ dialect_op_opsets_map_[""]["Col2Im"] = {18};
dialect_op_opsets_map_[""]["Compress"] = {11, 9};
dialect_op_opsets_map_[""]["Concat"] = {13, 11, 4, 1};
dialect_op_opsets_map_[""]["ConcatFromSequence"] = {11};
dialect_op_opsets_map_[""]["Constant"] = {24, 23, 21, 19, 13, 12, 11, 9, 1};
dialect_op_opsets_map_[""]["ConstantOfShape"] = {24, 23, 21, 20, 9};
dialect_op_opsets_map_[""]["Constant"] = {25, 24, 23, 21, 19, 13, 12, 11, 9, 1};
dialect_op_opsets_map_[""]["ConstantOfShape"] = {25, 24, 23, 21, 20, 9};
dialect_op_opsets_map_[""]["Conv"] = {22, 11, 1};
dialect_op_opsets_map_[""]["ConvInteger"] = {10};
dialect_op_opsets_map_[""]["ConvTranspose"] = {22, 11, 1};
dialect_op_opsets_map_[""]["Cos"] = {22, 7};
dialect_op_opsets_map_[""]["Cosh"] = {22, 9};
dialect_op_opsets_map_[""]["CumProd"] = {26};
dialect_op_opsets_map_[""]["CumSum"] = {14, 11};
dialect_op_opsets_map_[""]["DFT"] = {20, 17};
dialect_op_opsets_map_[""]["DeformConv"] = {22, 19};
dialect_op_opsets_map_[""]["DepthToSpace"] = {13, 11, 1};
dialect_op_opsets_map_[""]["DequantizeLinear"] = {24, 23, 21, 19, 13, 10};
dialect_op_opsets_map_[""]["DequantizeLinear"] = {25, 24, 23, 21, 19, 13, 10};
dialect_op_opsets_map_[""]["Det"] = {22, 11};
dialect_op_opsets_map_[""]["Div"] = {14, 13, 7, 6, 1};
dialect_op_opsets_map_[""]["Dropout"] = {22, 13, 12, 10, 7, 6, 1};
Expand All @@ -892,7 +894,7 @@ dialect_op_opsets_map_[""]["Erf"] = {13, 9};
dialect_op_opsets_map_[""]["Exp"] = {13, 6, 1};
dialect_op_opsets_map_[""]["Expand"] = {13, 8};
dialect_op_opsets_map_[""]["EyeLike"] = {22, 9};
dialect_op_opsets_map_[""]["Flatten"] = {24, 23, 21, 13, 11, 9, 1};
dialect_op_opsets_map_[""]["Flatten"] = {25, 24, 23, 21, 13, 11, 9, 1};
dialect_op_opsets_map_[""]["Floor"] = {13, 6, 1};
dialect_op_opsets_map_[""]["GRU"] = {22, 14, 7, 3, 1};
dialect_op_opsets_map_[""]["Gather"] = {13, 11, 1};
Expand All @@ -912,8 +914,8 @@ dialect_op_opsets_map_[""]["HannWindow"] = {17};
dialect_op_opsets_map_[""]["HardSigmoid"] = {22, 6, 1};
dialect_op_opsets_map_[""]["HardSwish"] = {22, 14};
dialect_op_opsets_map_[""]["Hardmax"] = {13, 11, 1};
dialect_op_opsets_map_[""]["Identity"] = {24, 23, 21, 19, 16, 14, 13, 1};
dialect_op_opsets_map_[""]["If"] = {24, 23, 21, 19, 16, 13, 11, 1};
dialect_op_opsets_map_[""]["Identity"] = {25, 24, 23, 21, 19, 16, 14, 13, 1};
dialect_op_opsets_map_[""]["If"] = {25, 24, 23, 21, 19, 16, 13, 11, 1};
dialect_op_opsets_map_[""]["ImageDecoder"] = {20};
dialect_op_opsets_map_[""]["InstanceNormalization"] = {22, 6, 1};
dialect_op_opsets_map_[""]["IsInf"] = {20, 10};
Expand All @@ -926,7 +928,7 @@ dialect_op_opsets_map_[""]["Less"] = {13, 9, 7, 1};
dialect_op_opsets_map_[""]["LessOrEqual"] = {16, 12};
dialect_op_opsets_map_[""]["Log"] = {13, 6, 1};
dialect_op_opsets_map_[""]["LogSoftmax"] = {13, 11, 1};
dialect_op_opsets_map_[""]["Loop"] = {24, 23, 21, 19, 16, 13, 11, 1};
dialect_op_opsets_map_[""]["Loop"] = {25, 24, 23, 21, 19, 16, 13, 11, 1};
dialect_op_opsets_map_[""]["LpNormalization"] = {22, 1};
dialect_op_opsets_map_[""]["LpPool"] = {22, 18, 11, 2, 1};
dialect_op_opsets_map_[""]["MatMul"] = {13, 9, 1};
Expand Down Expand Up @@ -954,11 +956,11 @@ dialect_op_opsets_map_[""]["OptionalGetElement"] = {18, 15};
dialect_op_opsets_map_[""]["OptionalHasElement"] = {18, 15};
dialect_op_opsets_map_[""]["Or"] = {7, 1};
dialect_op_opsets_map_[""]["PRelu"] = {16, 9, 7, 6, 1};
dialect_op_opsets_map_[""]["Pad"] = {24, 23, 21, 19, 18, 13, 11, 2, 1};
dialect_op_opsets_map_[""]["Pad"] = {25, 24, 23, 21, 19, 18, 13, 11, 2, 1};
dialect_op_opsets_map_[""]["Pow"] = {15, 13, 12, 7, 1};
dialect_op_opsets_map_[""]["QLinearConv"] = {10};
dialect_op_opsets_map_[""]["QLinearMatMul"] = {21, 10};
dialect_op_opsets_map_[""]["QuantizeLinear"] = {24, 23, 21, 19, 13, 10};
dialect_op_opsets_map_[""]["QuantizeLinear"] = {25, 24, 23, 21, 19, 13, 10};
dialect_op_opsets_map_[""]["RMSNormalization"] = {23};
dialect_op_opsets_map_[""]["RNN"] = {22, 14, 7, 1};
dialect_op_opsets_map_[""]["RandomNormal"] = {22, 1};
Expand All @@ -979,14 +981,14 @@ dialect_op_opsets_map_[""]["ReduceSum"] = {13, 11, 1};
dialect_op_opsets_map_[""]["ReduceSumSquare"] = {18, 13, 11, 1};
dialect_op_opsets_map_[""]["RegexFullMatch"] = {20};
dialect_op_opsets_map_[""]["Relu"] = {14, 13, 6, 1};
dialect_op_opsets_map_[""]["Reshape"] = {24, 23, 21, 19, 14, 13, 5, 1};
dialect_op_opsets_map_[""]["Reshape"] = {25, 24, 23, 21, 19, 14, 13, 5, 1};
dialect_op_opsets_map_[""]["Resize"] = {19, 18, 13, 11, 10};
dialect_op_opsets_map_[""]["ReverseSequence"] = {10};
dialect_op_opsets_map_[""]["RoiAlign"] = {22, 16, 10};
dialect_op_opsets_map_[""]["RotaryEmbedding"] = {23};
dialect_op_opsets_map_[""]["Round"] = {22, 11};
dialect_op_opsets_map_[""]["STFT"] = {17};
dialect_op_opsets_map_[""]["Scan"] = {24, 23, 21, 19, 16, 11, 9, 8};
dialect_op_opsets_map_[""]["Scan"] = {25, 24, 23, 21, 19, 16, 11, 9, 8};
dialect_op_opsets_map_[""]["Scatter"] = {11, 9};
dialect_op_opsets_map_[""]["ScatterElements"] = {18, 16, 13, 11};
dialect_op_opsets_map_[""]["ScatterND"] = {18, 16, 13, 11};
Expand All @@ -998,13 +1000,13 @@ dialect_op_opsets_map_[""]["SequenceErase"] = {11};
dialect_op_opsets_map_[""]["SequenceInsert"] = {11};
dialect_op_opsets_map_[""]["SequenceLength"] = {11};
dialect_op_opsets_map_[""]["SequenceMap"] = {17};
dialect_op_opsets_map_[""]["Shape"] = {24, 23, 21, 19, 15, 13, 1};
dialect_op_opsets_map_[""]["Shape"] = {25, 24, 23, 21, 19, 15, 13, 1};
dialect_op_opsets_map_[""]["Shrink"] = {9};
dialect_op_opsets_map_[""]["Sigmoid"] = {13, 6, 1};
dialect_op_opsets_map_[""]["Sign"] = {13, 9};
dialect_op_opsets_map_[""]["Sin"] = {22, 7};
dialect_op_opsets_map_[""]["Sinh"] = {22, 9};
dialect_op_opsets_map_[""]["Size"] = {24, 23, 21, 19, 13, 1};
dialect_op_opsets_map_[""]["Size"] = {25, 24, 23, 21, 19, 13, 1};
dialect_op_opsets_map_[""]["Slice"] = {13, 11, 10, 1};
dialect_op_opsets_map_[""]["Softmax"] = {13, 11, 1};
dialect_op_opsets_map_[""]["SoftmaxCrossEntropyLoss"] = {13, 12};
Expand All @@ -1014,7 +1016,7 @@ dialect_op_opsets_map_[""]["SpaceToDepth"] = {13, 1};
dialect_op_opsets_map_[""]["Split"] = {18, 13, 11, 2, 1};
dialect_op_opsets_map_[""]["SplitToSequence"] = {24, 11};
dialect_op_opsets_map_[""]["Sqrt"] = {13, 6, 1};
dialect_op_opsets_map_[""]["Squeeze"] = {24, 23, 21, 13, 11, 1};
dialect_op_opsets_map_[""]["Squeeze"] = {25, 24, 23, 21, 13, 11, 1};
dialect_op_opsets_map_[""]["StringConcat"] = {20};
dialect_op_opsets_map_[""]["StringNormalizer"] = {10};
dialect_op_opsets_map_[""]["StringSplit"] = {20};
Expand All @@ -1028,10 +1030,10 @@ dialect_op_opsets_map_[""]["TfIdfVectorizer"] = {9};
dialect_op_opsets_map_[""]["ThresholdedRelu"] = {22, 10};
dialect_op_opsets_map_[""]["Tile"] = {13, 6, 1};
dialect_op_opsets_map_[""]["TopK"] = {24, 11, 10, 1};
dialect_op_opsets_map_[""]["Transpose"] = {24, 23, 21, 13, 1};
dialect_op_opsets_map_[""]["Transpose"] = {25, 24, 23, 21, 13, 1};
dialect_op_opsets_map_[""]["Trilu"] = {14};
dialect_op_opsets_map_[""]["Unique"] = {11};
dialect_op_opsets_map_[""]["Unsqueeze"] = {24, 23, 21, 13, 11, 1};
dialect_op_opsets_map_[""]["Unsqueeze"] = {25, 24, 23, 21, 13, 11, 1};
dialect_op_opsets_map_[""]["Upsample"] = {10, 9, 7, 1};
dialect_op_opsets_map_[""]["Where"] = {16, 9};
dialect_op_opsets_map_[""]["Xor"] = {7, 1};
Expand Down
30 changes: 21 additions & 9 deletions src/Dialect/ONNX/ONNXOps.td.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,7 @@ def ONNXDivOp:ONNX_Op<"Div",

This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md).

For integer inputs, the result is computed using truncating division (rounding toward zero).
(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.
}];
let arguments = (ins AnyTypeOf<[TensorOf<[UI8]>, TensorOf<[UI16]>, TensorOf<[UI32]>, TensorOf<[UI64]>, TensorOf<[I8]>, TensorOf<[I16]>, TensorOf<[I32]>, TensorOf<[I64]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[BF16]>, TensorOf<[quant_QuantizedType]>]>:$A,
Expand Down Expand Up @@ -2226,7 +2227,7 @@ def ONNXDynamicQuantizeLinearOp:ONNX_Op<"DynamicQuantizeLinear",
Zero point is calculated as:
```
intermediate_zero_point = qmin - min(x)/y_scale
y_zero_point = cast(round(saturate(itermediate_zero_point)))
y_zero_point = cast(round(saturate(intermediate_zero_point)))
```

* where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8
Expand Down Expand Up @@ -2417,8 +2418,8 @@ def ONNXErfOp:ONNX_Op<"Erf",
let description = [{
Computes the error function of the given input tensor element-wise.
}];
let arguments = (ins AnyTypeOf<[TensorOf<[UI8]>, TensorOf<[UI16]>, TensorOf<[UI32]>, TensorOf<[UI64]>, TensorOf<[I8]>, TensorOf<[I16]>, TensorOf<[I32]>, TensorOf<[I64]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[BF16]>, TensorOf<[quant_QuantizedType]>]>:$input);
let results = (outs AnyTypeOf<[TensorOf<[UI8]>, TensorOf<[UI16]>, TensorOf<[UI32]>, TensorOf<[UI64]>, TensorOf<[I8]>, TensorOf<[I16]>, TensorOf<[I32]>, TensorOf<[I64]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[BF16]>, TensorOf<[quant_QuantizedType]>]>:$output);
let arguments = (ins AnyTypeOf<[TensorOf<[BF16]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[quant_QuantizedType]>]>:$input);
let results = (outs AnyTypeOf<[TensorOf<[BF16]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[quant_QuantizedType]>]>:$output);
let extraClassDeclaration = [{
static int getNumberOfOperands() {
return 1;
Expand Down Expand Up @@ -4481,7 +4482,7 @@ def ONNXLoopOp:ONNX_Op<"Loop",
1) Values from the enclosing scope (i.e. variable \"a\" here) are in scope and can
be referenced in the inputs of the loop.
2) Any values computed in the loop body that needs to be used in a subsequent
iteration or after the loop are modelled using a pair of variables in the loop-body,
iteration or after the loop are modeled using a pair of variables in the loop-body,
consisting of an input variable (eg., b_in) and an output variable (eg., b_out).
These are referred to as loop-carried dependences. The loop operation node
supplies the input value of the input variable for the first iteration, and
Expand Down Expand Up @@ -4542,6 +4543,9 @@ def ONNXLpNormalizationOp:ONNX_Op<"LpNormalization",
let summary = "ONNX LpNormalization operation";
let description = [{
Given a matrix, apply Lp-normalization along the provided axis.
The output is computed as: `output = input / Lp_norm(input, axis)`.
When the Lp norm is zero (i.e., all elements along the axis are zero),
the output is defined to be zero to avoid division by zero.
}];
let arguments = (ins AnyTypeOf<[TensorOf<[BF16]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[quant_QuantizedType]>]>:$input,
DefaultValuedAttr<SI64Attr, "-1">:$axis,
Expand Down Expand Up @@ -5363,6 +5367,7 @@ def ONNXNonMaxSuppressionOp:ONNX_Op<"NonMaxSuppression",
let description = [{
Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.
Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.
Boxes are suppressed if their IOU with a previously selected box is strictly greater than iou_threshold (i.e., boxes with IOU exactly equal to the threshold are kept).
Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to
orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system
result in the same boxes being selected by the algorithm.
Expand Down Expand Up @@ -8673,7 +8678,7 @@ def ONNXScatterNDOp:ONNX_Op<"ScatterND",
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
output[tuple(indices[idx])] = updates[idx]
```

The order of iteration in the above loop is not specified.
Expand All @@ -8690,7 +8695,7 @@ def ONNXScatterNDOp:ONNX_Op<"ScatterND",
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = f(output[indices[idx]], updates[idx])
output[tuple(indices[idx])] = f(output[tuple(indices[idx])], updates[idx])
```

where the `f` is `+`, `*`, `max` or `min` as specified.
Expand Down Expand Up @@ -10362,9 +10367,16 @@ def ONNXTransposeOp:ONNX_Op<"Transpose",
let hasCanonicalizer = 1;
let summary = "ONNX Transpose operation";
let description = [{
Transpose the input tensor similar to numpy.transpose. For example, when
perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape
will be (2, 1, 3).
Returns a transpose of the input tensor. (Similar to `numpy.transpose`).
The optional attribute `perm` must be a permutation of the dimensions of
the input tensor. Axis `i` of the output tensor corresponds to the axis
`perm[i]` of the input tensor.
For example, when perm=(1, 0, 2), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 1, 3).
When perm=(1, 2, 0), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 3, 1).
If the attribute `perm` is omitted, its default value is `(n-1, ..., 0)`,
where `n` is the rank of the input tensor.
}];
let arguments = (ins AnyTypeOf<[TensorOf<[UI8]>, TensorOf<[UI16]>, TensorOf<[UI32]>, TensorOf<[UI64]>, TensorOf<[I8]>, TensorOf<[I16]>, TensorOf<[I32]>, TensorOf<[I64]>, TensorOf<[BF16]>, TensorOf<[F16]>, TensorOf<[F32]>, TensorOf<[F64]>, TensorOf<[StringType]>, TensorOf<[I1]>, TensorOf<[Complex<F32>]>, TensorOf<[Complex<F64>]>, TensorOf<[F8E4M3FN]>, TensorOf<[F8E4M3FNUZ]>, TensorOf<[F8E5M2]>, TensorOf<[F8E5M2FNUZ]>, TensorOf<[UI<4>]>, TensorOf<[I<4>]>, TensorOf<[quant_QuantizedType]>]>:$data,
OptionalAttr<I64ArrayAttr>:$perm);
Expand Down
5 changes: 4 additions & 1 deletion src/Dialect/ONNX/ONNXOps/OpHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,12 @@ Type convertONNXTypeToMLIRType(
return builder.getIntegerType(/*width=*/4);
case onnx::TensorProto_DataType::TensorProto_DataType_UINT4:
return builder.getIntegerType(/*width=*/4, false);

case onnx::TensorProto_DataType::TensorProto_DataType_COMPLEX64:
case onnx::TensorProto_DataType::TensorProto_DataType_COMPLEX128:
case onnx::TensorProto_DataType::TensorProto_DataType_FLOAT4E2M1:
case onnx::TensorProto_DataType::TensorProto_DataType_FLOAT8E8M0:
case onnx::TensorProto_DataType::TensorProto_DataType_INT2:
case onnx::TensorProto_DataType::TensorProto_DataType_UINT2:
case onnx::TensorProto_DataType::TensorProto_DataType_UNDEFINED:
llvm_unreachable("Unsupported data type encountered.");
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/Support/SuppressWarnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
_Pragma("clang diagnostic ignored \"-Wstring-conversion\"") \
_Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \
_Pragma("clang diagnostic ignored \"-Wsuggest-override\"") \
_Pragma("clang diagnostic ignored \"-Wc++98-compat-extra-semi\"")

_Pragma("clang diagnostic ignored \"-Wc++98-compat-extra-semi\"") \
_Pragma("clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
#define SUPPRESS_WARNINGS_POP _Pragma("clang diagnostic pop")
#elif defined(__GNUC__)
#define SUPPRESS_WARNINGS_PUSH \
Expand Down
2 changes: 1 addition & 1 deletion third_party/onnx
Submodule onnx updated 895 files
Loading