Skip to content

Enhance shape inference for ONNX Reshape #3122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 18, 2025

Conversation

tungld
Copy link
Collaborator

@tungld tungld commented Apr 16, 2025

This patch is to enhance the shape inference for ONNX Reshape in the case where we can infer a static value for the output dimension at position of -1.

In Reshape, when the second input shape is a 1D tensor containing the dimensions of the output. shape can accept a value of -1, meaning that the output dimension is computed from the remaining dimensions.
In some situations, the remaining dimensions have unknown dimensions but these unknown dimensions are the same as the the unknown dimensions in the input. So we can remove these unknown dimensions when computing the dimension at -1, which increases the chance of getting a static value for position -1.

For example, in the following program, we can infer the dimension at position -1 (the second dim from the last of tensor<?x?x?x64xf32) to be 32 instead of unknown.

  %1 = onnx.Constant dense<64> : tensor<1xi64>
  %2 = onnx.Constant dense<-1> : tensor<1xi64>
  %3 = "onnx.Dim"(%arg0) {axis = 0 : si64} : (tensor<?x?x2048xf32>) -> tensor<1xi64>
  %4 = "onnx.Dim"(%arg0) {axis = 1 : si64} : (tensor<?x?x2048xf32>) -> tensor<1xi64>
  %5 = "onnx.Concat"(%3, %4, %2, %1) {axis = 0 : si64} : (tensor<1xi64>, tensor<1xi64>, tensor<1xi64>, tensor<1xi64>) -> tensor<4xi64>
  %6 = "onnx.Reshape"(%arg0, %5) {allowzero = 0 : si64} : (tensor<?x?x2048xf32>, tensor<4xi64>) -> tensor<?x?x?x64xf32>

In this example, the output shape is [%3, %4, -1, 64]. Because %3 and %4 are the same as the 1st and 2nd dims of %arg0 respectively, we can ignore them in computing dim at position -1. So the dim at position -1 is simple 2048/64 or 32.

Copy link
Collaborator

@AlexandreEichenberger AlexandreEichenberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart! Added two questions to make sure the corner cases are covered.


bool isBijective = true;
for (int64_t i = 0; i < outputRank; ++i) {
if (!isBijective) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this on purpose at the top? If the last i iteration results in isBijective is set to false, then this code is never executed. If that is what you want, maybe a small comments to explain the corner case where bijective is false but the sets are not cleared.

Copy link
Collaborator Author

@tungld tungld Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I fixed this case by moving the check outside the for loop. Thanks!

if (dimOp.getData() != refData)
continue;
int64_t axis = dimOp.getAxis();
if (auto search = dataIgnoredDims.find(axis);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment on the condition being tested would be useful.
Are you also testing the case where (though unlikely)

(%1, %2, 64) -> (%1, %1, %2, -1)

namely where %1 appears twice, which would be clearly not bijective.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a lit test for this case.

@chentong319
Copy link
Collaborator

chentong319 commented Apr 16, 2025

For readability, can we propagate 'onnx.dim_params' attribute introduced by onnx model along onnx.dim op?

@chentong319
Copy link
Collaborator

It seems to me that the code works on the restricted pattern with the data of reshape coming from MatMul. Could we relax the condition a little bit for a general case for data?
We need onnx.dim(%data, i) and value of %shape[i] to compute the size of unspecified dimension.
For the value of shape[I], we track back to the defining op, onnx.ConcatOp, and then to its inputs of constant or onnx.dim op. That's the pattern appears in the model. Anyway, we may define a utility function with a general name in case we find more pattern to locate the definition from onnx.dim.
For the onnx.dim(%data, i), do we have to track back to its defining op or simply rely on DimAnalysis to check it with the onnx.dim from the value of shape?
Anyway, in the process of cancel out the same onnx.dim, I think that the canceled one should be removed from the list after matched. For example, in 'onnx.Reshape(%data, %reshape): (tensor<?x?x?x256xf32>, tensor<4xi64>)`, there may be two symbols, one of which appears twice in the dimension.

@tungld
Copy link
Collaborator Author

tungld commented Apr 17, 2025

@chentong319 trying to understand your comment.

For the onnx.dim(%data, i), do we have to track back to its defining op or simply rely on DimAnalysis to check it with the onnx.dim from the value of shape?

I think using DimAnalysis would be definitely better, so that we can check dim equality for two arbitrary dims without tracing back. Unfortunately, it is non-trivial to use DimAnalysis inside shape inference at this moment because 1) DimAnalysis uses ShapeHelper here so we may have a cyclic dependency, 2) DimAnalysis depends on the IR at a time, whenever the IR changes DimAnalysis needs to be updated.

Anyway, in the process of cancel out the same onnx.dim, I think that the canceled one should be removed from the list after matched. For example, in 'onnx.Reshape(%data, %reshape): (tensor<?x?x?x256xf32>, tensor<4xi64>)`, there may be two symbols, one of which appears twice in the dimension.

Yes, it looks similar to Alex's example, I added a lit test for this case.

@tungld
Copy link
Collaborator Author

tungld commented Apr 17, 2025

For readability, can we propagate 'onnx.dim_params' attribute introduced by onnx model along onnx.dim op?

It sounds a good thing. Will think about that.

@chentong319
Copy link
Collaborator

chentong319 commented Apr 17, 2025

  1. Agree with complexity of using DimAnalysis.

  2. The example I was thinking of is more like this:
    %0 = onnx.Dim(%D1, 0): (tensor<?xf32> {onnx.dim_params = "0:dimA"} -> tensor<1xi64>
    %1 = onnx.Dim(%D2, 0): (tensor<?xf32> {onnx.dim_params = "0:dimA"} -> tensor<1xi64>
    %2 = onnx.Dim(%D3, 0): (tensor<?xf32> {onnx.dim_params = "0:dimB"} -> tensor<1xi64>
    %3 = onnx.Constant<-1>
    %4 = onnx.Constant<64>
    %shape = onnx.Concat(%0, %1, %2, %3, %4, %5)
    onnx.Reshape(%data, %shape) : (tensor<?x?x?x256xf32> {onnx.dim_params = "0:dimA,1:dimB, 2:dimA"}, tensor<5xi64>) -> tensor<*xf32>

I assume that the dim_params is propagated so that it is easier for me to show the relationship of the symbolic dimensions.
This result should be tensor<?x?x?x4x64xf32>
It is a general case, which we may not need to worry about now.

By the way, from the example I constructed, it is very useful to propagate the dim_params. It is a simplified symbolic DimAnalysis. We should do it. Schedule a discussion?

Copy link
Collaborator

@chentong319 chentong319 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tungld
Copy link
Collaborator Author

tungld commented Apr 18, 2025

tensor<?xf32> {onnx.dim_params = "0:dimB"}

Is it possible to define that attribute {onnx.dim_params = "0:dimB"} for a tensor? I know it's possible for function arguments, but not sure about a single tensor type.

@tungld tungld merged commit 076492a into onnx:main Apr 18, 2025
7 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16539 [push] null... failed after 1 hr 26 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16541 [push] null... failed after 1 hr 44 min

tungld added a commit to brnorris03/onnx-mlir that referenced this pull request May 9, 2025
* Add a special case in shape inference for reshape

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>
jorickert added a commit that referenced this pull request May 19, 2025
* update float types, tosa, other misc changes

Signed-off-by: Boyana Norris <[email protected]>

* fix buildOnnxToTosaPaddingConstOp

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests (wip)

Signed-off-by: Boyana Norris <[email protected]>

* updte doc

Signed-off-by: Boyana Norris <[email protected]>

* use stablehlo tagged version

Signed-off-by: Boyana Norris <[email protected]>

* fixed more lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix .clang-format

Signed-off-by: Boyana Norris <[email protected]>

* fix lit (wip)

Signed-off-by: Boyana Norris <[email protected]>

* revert .clang-format change

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix formatting

Signed-off-by: Boyana Norris <[email protected]>

* lit tests pass (except jni -- not tested)

Signed-off-by: Boyana Norris <[email protected]>

* manually fix formatting; can't get clang-format to do it on any of my machines

Signed-off-by: Boyana Norris <[email protected]>

* revert lit test changes unrelated to update

Signed-off-by: Boyana Norris <[email protected]>

* update llvm and stablhlo shas, misc minor updates

Signed-off-by: Boyana Norris <[email protected]>

* remove non-existent passes

Signed-off-by: Boyana Norris <[email protected]>

* lit updates (wip)

Signed-off-by: Tung D. Le <[email protected]>

* Bump Upsample to Opset 10 and change the opset versioning to allow to skip over opset versions if a newer, backwards compatible one exists. (#3065)

* Bump Upsample to Opset 10

This is a non-functional change, the only difference is that Upsample was marked as deprecated with Opset 10

Signed-off-by: Rickert, Jonas <[email protected]>

* Use a map of the available opset versions in onnx to select the node opset to use.

Introduces a new built-time generated map that contains all versions of an operation as defined by onnx.
To determine the opset version for a node/op:
1.	Determine the latest valid opset version. This is the newest version in this opset-version-map that is older or equal to the current graph opset.
2.	Select the newest version from the versions supported by onnx-mlir that is equal or newer to the latest valid opset version. This allows it to skip over opset versions, that have a newer backwards compatible version.
Example:
	Versions in onnx and supported by onnx-mlir: [3, 5].
	Graph opset version to node version: 3 -> 3, 4 -> 3, 5 -> 5

	Versions in onnx: [7, 9, 10]. Version 10 is backwards compatible to version 9.
	Version supported by onnx-mlir: [7, 10].
	Graph opset version to node version: 7 -> 7, 8 -> 7, 9 -> 10, 10 -> 10

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Improve scripts (#3089)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Bump various ops to opset 21, adding int4/uint4 and 8 bit float support. (#3064)

* Add support for TensorProto::UINT4/INT4

Signed-off-by: Rickert, Jonas <[email protected]>

* Upgrade onnx.Cast to opset 21

Signed-off-by: Rickert, Jonas <[email protected]>

* Bump various ops to opset 21.

These are all backwards compatibel version bumps, only adding support for int/uint4.

Bumped ops:
Flatten
Identity
If
Loop
Pad
Reshape
Scan
Shape
Size
Squeeze
Transpose
Unsqueeze

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Added minimal support to do some timing of OM Runtime functionality (#3095)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* adding __errno_location call for mvs (#3099)

Signed-off-by: Christopher Munoz <[email protected]>

* Rewriting pattern to remove WhereOp and EqualOp.  (#3094)

Remove ONNXWhereOp and ONNXEqualOp into newly created ConcatOp.

---------

Signed-off-by: Haruki Imai <[email protected]>

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation (#3101)

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* removing weak attribute of errorno (#3103)

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Fix the custom build link for docs/Docker.md (#3104)

Signed-off-by: JiQiu <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Python driver for torch model (#3093)

* implementation

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* test

Signed-off-by: Chen Tong <[email protected]>

* py format

Signed-off-by: Chen Tong <[email protected]>

* torch.compile

Signed-off-by: Chen Tong <[email protected]>

* refine

Signed-off-by: Chen Tong <[email protected]>

* add debug

Signed-off-by: Chen Tong <[email protected]>

* respond

Signed-off-by: Chen Tong <[email protected]>

* response

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* implement (#3108)

Signed-off-by: Chen Tong <[email protected]>

* Followups for torch model driver (#3106)

* simplify

Signed-off-by: Chen Tong <[email protected]>

* complete

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* Fix an error in ZHighConstantPropagation for QuantizedStick (#3112)

Signed-off-by: Tung D. Le <[email protected]>

* Add z17 for -march (#3113)

* done

Signed-off-by: Tong Chen <[email protected]>

* convert

Signed-off-by: Tong Chen <[email protected]>

* fix

Signed-off-by: Tong Chen <[email protected]>

* format

Signed-off-by: Tong Chen <[email protected]>

---------

Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>

* Decompose Hardswish into simpler ONNX ops (#3107)

* Decompose and lower Hardswish

Signed-off-by: Kumarappan <[email protected]>

* Providing the decomposition as compile time option with krnl dialect lowering as default

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Reorder relu to maxpool optimization pass in ONNX dialect (#3109)

* Reorder Relu and maxpool optimization

Signed-off-by: Arkar-Hema <[email protected]>

* Swap Relu and maxpool only when Relu is not a consumer of conv

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Move onnx.Constant before the root op when fusing onnx ops (#3119)

Signed-off-by: Tung D. Le <[email protected]>

* Support QLinearMatMul on CPU (#3117)

* Support QLinearMatMul on CPU

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* Update black-format-check.yml (#3118)

Signed-off-by: Andreas Fehlner <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Merge nested concat Ops optimization pass in ONNX dialect (#3111)

* Merging nested concat ops

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Enhance shape inference for ONNX Reshape (#3122)

* Add a special case in shape inference for reshape

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* update zdnn1.1.2 (#3130)

Signed-off-by: Sunny Anand <[email protected]>

* Updating supported ops on NNPA md for z17.  (#3120)

* starting to update new z17 NNPA ops

Signed-off-by: Christopher Munoz <[email protected]>

---------

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* fix CVE-2025-32434 (#3135)

Signed-off-by: Sunny Anand <[email protected]>

* Fuse consecutive clips pattern (#3132)

* Fuse consecutive clips pattern

Signed-off-by: Kumarappan <[email protected]>


---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Replace deprecated applyPatternsAndFoldGreedily with applyPatternsGreedily. This functions also folds by default, so it is an NFC

Signed-off-by: Rickert, Jonas <[email protected]>

* Fix clang-format

Signed-off-by: Rickert, Jonas <[email protected]>

* Replace bufferization::createOwnershipBasedBufferDeallocationPass with mlir::createConvertBufferizationToMemRefPass

Signed-off-by: Rickert, Jonas <[email protected]>

* Update onnx-to-tosa reshape lit test

Signed-off-by: Rickert, Jonas <[email protected]>

* Move gemm_to_fc tests to gemm_to_matmul

Signed-off-by: Rickert, Jonas <[email protected]>

* Change tosaBuilder::mul function signature to make clear that the shift is an int8

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable buffer_loop_hoisting test as it gets completly optimized away

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against dynamic dim in result

Signed-off-by: Rickert, Jonas <[email protected]>

* Use resize operaton input and output type to calculate the border, instead of using the calculated numerator/denominator

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against linear interpolation of integer types

Signed-off-by: Rickert, Jonas <[email protected]>

* Add test for disallowed onnx.Resize on its with linear interpolation to tosa

Signed-off-by: Rickert, Jonas <[email protected]>

* Add 'Pure' annotation to some krnl ops and recreate documentation

Signed-off-by: Rickert, Jonas <[email protected]>

* Build stablehlo with static libs

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable memref.prefetch since it does not work with the new bufferization

Signed-off-by: Tung D. Le <[email protected]>

* Conv add const where the constant is a scalar (#3145)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* added support for Celu op (#3139)

Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>

* Fix some warnings related to stickification for NNPA (#3147)

Signed-off-by: Tung D. Le <[email protected]>

* Removing duplicate file (#3146)

Signed-off-by: Christopher Munoz <[email protected]>

* migrated instance/group normalization from decompose to canonicalize (#3148)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Fusion of Matmul add covering the stacked/unstacked/bcast1/bcast23 patterns (#3140)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Support --march=native (#3134)

* changes

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* linkage

Signed-off-by: Chen Tong <[email protected]>

* lib

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* fix another error on s390x

Signed-off-by: Tung D. Le <[email protected]>

* lower Ub to LLVM since vector.shape_cast is lowered to UB

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Boyana Norris <[email protected]>
Signed-off-by: Tung D. Le <[email protected]>
Signed-off-by: Rickert, Jonas <[email protected]>
Signed-off-by: Alexandre Eichenberger <[email protected]>
Signed-off-by: Christopher Munoz <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: JiQiu <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Kumarappan <[email protected]>
Signed-off-by: Arkar-Hema <[email protected]>
Signed-off-by: Andreas Fehlner <[email protected]>
Signed-off-by: Sunny Anand <[email protected]>
Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>
Co-authored-by: Jonas Rickert <[email protected]>
Co-authored-by: Christopher Munoz <[email protected]>
Co-authored-by: Haruki Imai <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
Co-authored-by: qjivy <[email protected]>
Co-authored-by: Tong Chen <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: kumarappan-cmyk <[email protected]>
Co-authored-by: Arkar-Hema <[email protected]>
Co-authored-by: Andreas Fehlner <[email protected]>
Co-authored-by: logeshwaranmcw <[email protected]>
jorickert added a commit to Xilinx/onnx-mlir that referenced this pull request Jun 26, 2025
LLVM update 43d71ba (onnx#3086)

* update float types, tosa, other misc changes

Signed-off-by: Boyana Norris <[email protected]>

* fix buildOnnxToTosaPaddingConstOp

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests (wip)

Signed-off-by: Boyana Norris <[email protected]>

* updte doc

Signed-off-by: Boyana Norris <[email protected]>

* use stablehlo tagged version

Signed-off-by: Boyana Norris <[email protected]>

* fixed more lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix .clang-format

Signed-off-by: Boyana Norris <[email protected]>

* fix lit (wip)

Signed-off-by: Boyana Norris <[email protected]>

* revert .clang-format change

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix formatting

Signed-off-by: Boyana Norris <[email protected]>

* lit tests pass (except jni -- not tested)

Signed-off-by: Boyana Norris <[email protected]>

* manually fix formatting; can't get clang-format to do it on any of my machines

Signed-off-by: Boyana Norris <[email protected]>

* revert lit test changes unrelated to update

Signed-off-by: Boyana Norris <[email protected]>

* update llvm and stablhlo shas, misc minor updates

Signed-off-by: Boyana Norris <[email protected]>

* remove non-existent passes

Signed-off-by: Boyana Norris <[email protected]>

* lit updates (wip)

Signed-off-by: Tung D. Le <[email protected]>

* Bump Upsample to Opset 10 and change the opset versioning to allow to skip over opset versions if a newer, backwards compatible one exists. (onnx#3065)

* Bump Upsample to Opset 10

This is a non-functional change, the only difference is that Upsample was marked as deprecated with Opset 10

Signed-off-by: Rickert, Jonas <[email protected]>

* Use a map of the available opset versions in onnx to select the node opset to use.

Introduces a new built-time generated map that contains all versions of an operation as defined by onnx.
To determine the opset version for a node/op:
1.	Determine the latest valid opset version. This is the newest version in this opset-version-map that is older or equal to the current graph opset.
2.	Select the newest version from the versions supported by onnx-mlir that is equal or newer to the latest valid opset version. This allows it to skip over opset versions, that have a newer backwards compatible version.
Example:
	Versions in onnx and supported by onnx-mlir: [3, 5].
	Graph opset version to node version: 3 -> 3, 4 -> 3, 5 -> 5

	Versions in onnx: [7, 9, 10]. Version 10 is backwards compatible to version 9.
	Version supported by onnx-mlir: [7, 10].
	Graph opset version to node version: 7 -> 7, 8 -> 7, 9 -> 10, 10 -> 10

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Improve scripts (onnx#3089)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Bump various ops to opset 21, adding int4/uint4 and 8 bit float support. (onnx#3064)

* Add support for TensorProto::UINT4/INT4

Signed-off-by: Rickert, Jonas <[email protected]>

* Upgrade onnx.Cast to opset 21

Signed-off-by: Rickert, Jonas <[email protected]>

* Bump various ops to opset 21.

These are all backwards compatibel version bumps, only adding support for int/uint4.

Bumped ops:
Flatten
Identity
If
Loop
Pad
Reshape
Scan
Shape
Size
Squeeze
Transpose
Unsqueeze

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Added minimal support to do some timing of OM Runtime functionality (onnx#3095)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* adding __errno_location call for mvs (onnx#3099)

Signed-off-by: Christopher Munoz <[email protected]>

* Rewriting pattern to remove WhereOp and EqualOp.  (onnx#3094)

Remove ONNXWhereOp and ONNXEqualOp into newly created ConcatOp.

---------

Signed-off-by: Haruki Imai <[email protected]>

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation (onnx#3101)

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* removing weak attribute of errorno (onnx#3103)

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Fix the custom build link for docs/Docker.md (onnx#3104)

Signed-off-by: JiQiu <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Python driver for torch model (onnx#3093)

* implementation

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* test

Signed-off-by: Chen Tong <[email protected]>

* py format

Signed-off-by: Chen Tong <[email protected]>

* torch.compile

Signed-off-by: Chen Tong <[email protected]>

* refine

Signed-off-by: Chen Tong <[email protected]>

* add debug

Signed-off-by: Chen Tong <[email protected]>

* respond

Signed-off-by: Chen Tong <[email protected]>

* response

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* implement (onnx#3108)

Signed-off-by: Chen Tong <[email protected]>

* Followups for torch model driver (onnx#3106)

* simplify

Signed-off-by: Chen Tong <[email protected]>

* complete

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* Fix an error in ZHighConstantPropagation for QuantizedStick (onnx#3112)

Signed-off-by: Tung D. Le <[email protected]>

* Add z17 for -march (onnx#3113)

* done

Signed-off-by: Tong Chen <[email protected]>

* convert

Signed-off-by: Tong Chen <[email protected]>

* fix

Signed-off-by: Tong Chen <[email protected]>

* format

Signed-off-by: Tong Chen <[email protected]>

---------

Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>

* Decompose Hardswish into simpler ONNX ops (onnx#3107)

* Decompose and lower Hardswish

Signed-off-by: Kumarappan <[email protected]>

* Providing the decomposition as compile time option with krnl dialect lowering as default

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Reorder relu to maxpool optimization pass in ONNX dialect (onnx#3109)

* Reorder Relu and maxpool optimization

Signed-off-by: Arkar-Hema <[email protected]>

* Swap Relu and maxpool only when Relu is not a consumer of conv

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Move onnx.Constant before the root op when fusing onnx ops (onnx#3119)

Signed-off-by: Tung D. Le <[email protected]>

* Support QLinearMatMul on CPU (onnx#3117)

* Support QLinearMatMul on CPU

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* Update black-format-check.yml (onnx#3118)

Signed-off-by: Andreas Fehlner <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Merge nested concat Ops optimization pass in ONNX dialect (onnx#3111)

* Merging nested concat ops

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Enhance shape inference for ONNX Reshape (onnx#3122)

* Add a special case in shape inference for reshape

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* update zdnn1.1.2 (onnx#3130)

Signed-off-by: Sunny Anand <[email protected]>

* Updating supported ops on NNPA md for z17.  (onnx#3120)

* starting to update new z17 NNPA ops

Signed-off-by: Christopher Munoz <[email protected]>

---------

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* fix CVE-2025-32434 (onnx#3135)

Signed-off-by: Sunny Anand <[email protected]>

* Fuse consecutive clips pattern (onnx#3132)

* Fuse consecutive clips pattern

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Replace deprecated applyPatternsAndFoldGreedily with applyPatternsGreedily. This functions also folds by default, so it is an NFC

Signed-off-by: Rickert, Jonas <[email protected]>

* Fix clang-format

Signed-off-by: Rickert, Jonas <[email protected]>

* Replace bufferization::createOwnershipBasedBufferDeallocationPass with mlir::createConvertBufferizationToMemRefPass

Signed-off-by: Rickert, Jonas <[email protected]>

* Update onnx-to-tosa reshape lit test

Signed-off-by: Rickert, Jonas <[email protected]>

* Move gemm_to_fc tests to gemm_to_matmul

Signed-off-by: Rickert, Jonas <[email protected]>

* Change tosaBuilder::mul function signature to make clear that the shift is an int8

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable buffer_loop_hoisting test as it gets completly optimized away

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against dynamic dim in result

Signed-off-by: Rickert, Jonas <[email protected]>

* Use resize operaton input and output type to calculate the border, instead of using the calculated numerator/denominator

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against linear interpolation of integer types

Signed-off-by: Rickert, Jonas <[email protected]>

* Add test for disallowed onnx.Resize on its with linear interpolation to tosa

Signed-off-by: Rickert, Jonas <[email protected]>

* Add 'Pure' annotation to some krnl ops and recreate documentation

Signed-off-by: Rickert, Jonas <[email protected]>

* Build stablehlo with static libs

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable memref.prefetch since it does not work with the new bufferization

Signed-off-by: Tung D. Le <[email protected]>

* Conv add const where the constant is a scalar (onnx#3145)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* added support for Celu op (onnx#3139)

Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>

* Fix some warnings related to stickification for NNPA (onnx#3147)

Signed-off-by: Tung D. Le <[email protected]>

* Removing duplicate file (onnx#3146)

Signed-off-by: Christopher Munoz <[email protected]>

* migrated instance/group normalization from decompose to canonicalize (onnx#3148)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Fusion of Matmul add covering the stacked/unstacked/bcast1/bcast23 patterns (onnx#3140)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Support --march=native (onnx#3134)

* changes

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* linkage

Signed-off-by: Chen Tong <[email protected]>

* lib

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* fix another error on s390x

Signed-off-by: Tung D. Le <[email protected]>

* lower Ub to LLVM since vector.shape_cast is lowered to UB

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Boyana Norris <[email protected]>
Signed-off-by: Tung D. Le <[email protected]>
Signed-off-by: Rickert, Jonas <[email protected]>
Signed-off-by: Alexandre Eichenberger <[email protected]>
Signed-off-by: Christopher Munoz <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: JiQiu <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Kumarappan <[email protected]>
Signed-off-by: Arkar-Hema <[email protected]>
Signed-off-by: Andreas Fehlner <[email protected]>
Signed-off-by: Sunny Anand <[email protected]>
Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>
Co-authored-by: Jonas Rickert <[email protected]>
Co-authored-by: Christopher Munoz <[email protected]>
Co-authored-by: Haruki Imai <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
Co-authored-by: qjivy <[email protected]>
Co-authored-by: Tong Chen <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: kumarappan-cmyk <[email protected]>
Co-authored-by: Arkar-Hema <[email protected]>
Co-authored-by: Andreas Fehlner <[email protected]>
Co-authored-by: logeshwaranmcw <[email protected]>
jorickert added a commit to Xilinx/onnx-mlir that referenced this pull request Jul 1, 2025
AMD changes: Update lowering and tests for onnx->tosa conversions that are not upstream

Partial cherry-pick of f03b287

LLVM update 43d71ba (onnx#3086)

* update float types, tosa, other misc changes

Signed-off-by: Boyana Norris <[email protected]>

* fix buildOnnxToTosaPaddingConstOp

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests (wip)

Signed-off-by: Boyana Norris <[email protected]>

* updte doc

Signed-off-by: Boyana Norris <[email protected]>

* use stablehlo tagged version

Signed-off-by: Boyana Norris <[email protected]>

* fixed more lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix .clang-format

Signed-off-by: Boyana Norris <[email protected]>

* fix lit (wip)

Signed-off-by: Boyana Norris <[email protected]>

* revert .clang-format change

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix formatting

Signed-off-by: Boyana Norris <[email protected]>

* lit tests pass (except jni -- not tested)

Signed-off-by: Boyana Norris <[email protected]>

* manually fix formatting; can't get clang-format to do it on any of my machines

Signed-off-by: Boyana Norris <[email protected]>

* revert lit test changes unrelated to update

Signed-off-by: Boyana Norris <[email protected]>

* update llvm and stablhlo shas, misc minor updates

Signed-off-by: Boyana Norris <[email protected]>

* remove non-existent passes

Signed-off-by: Boyana Norris <[email protected]>

* lit updates (wip)

Signed-off-by: Tung D. Le <[email protected]>

* Bump Upsample to Opset 10 and change the opset versioning to allow to skip over opset versions if a newer, backwards compatible one exists. (onnx#3065)

* Bump Upsample to Opset 10

This is a non-functional change, the only difference is that Upsample was marked as deprecated with Opset 10

Signed-off-by: Rickert, Jonas <[email protected]>

* Use a map of the available opset versions in onnx to select the node opset to use.

Introduces a new built-time generated map that contains all versions of an operation as defined by onnx.
To determine the opset version for a node/op:
1.	Determine the latest valid opset version. This is the newest version in this opset-version-map that is older or equal to the current graph opset.
2.	Select the newest version from the versions supported by onnx-mlir that is equal or newer to the latest valid opset version. This allows it to skip over opset versions, that have a newer backwards compatible version.
Example:
	Versions in onnx and supported by onnx-mlir: [3, 5].
	Graph opset version to node version: 3 -> 3, 4 -> 3, 5 -> 5

	Versions in onnx: [7, 9, 10]. Version 10 is backwards compatible to version 9.
	Version supported by onnx-mlir: [7, 10].
	Graph opset version to node version: 7 -> 7, 8 -> 7, 9 -> 10, 10 -> 10

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Improve scripts (onnx#3089)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Bump various ops to opset 21, adding int4/uint4 and 8 bit float support. (onnx#3064)

* Add support for TensorProto::UINT4/INT4

Signed-off-by: Rickert, Jonas <[email protected]>

* Upgrade onnx.Cast to opset 21

Signed-off-by: Rickert, Jonas <[email protected]>

* Bump various ops to opset 21.

These are all backwards compatibel version bumps, only adding support for int/uint4.

Bumped ops:
Flatten
Identity
If
Loop
Pad
Reshape
Scan
Shape
Size
Squeeze
Transpose
Unsqueeze

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Added minimal support to do some timing of OM Runtime functionality (onnx#3095)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* adding __errno_location call for mvs (onnx#3099)

Signed-off-by: Christopher Munoz <[email protected]>

* Rewriting pattern to remove WhereOp and EqualOp.  (onnx#3094)

Remove ONNXWhereOp and ONNXEqualOp into newly created ConcatOp.

---------

Signed-off-by: Haruki Imai <[email protected]>

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation (onnx#3101)

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* removing weak attribute of errorno (onnx#3103)

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Fix the custom build link for docs/Docker.md (onnx#3104)

Signed-off-by: JiQiu <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Python driver for torch model (onnx#3093)

* implementation

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* test

Signed-off-by: Chen Tong <[email protected]>

* py format

Signed-off-by: Chen Tong <[email protected]>

* torch.compile

Signed-off-by: Chen Tong <[email protected]>

* refine

Signed-off-by: Chen Tong <[email protected]>

* add debug

Signed-off-by: Chen Tong <[email protected]>

* respond

Signed-off-by: Chen Tong <[email protected]>

* response

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* implement (onnx#3108)

Signed-off-by: Chen Tong <[email protected]>

* Followups for torch model driver (onnx#3106)

* simplify

Signed-off-by: Chen Tong <[email protected]>

* complete

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* Fix an error in ZHighConstantPropagation for QuantizedStick (onnx#3112)

Signed-off-by: Tung D. Le <[email protected]>

* Add z17 for -march (onnx#3113)

* done

Signed-off-by: Tong Chen <[email protected]>

* convert

Signed-off-by: Tong Chen <[email protected]>

* fix

Signed-off-by: Tong Chen <[email protected]>

* format

Signed-off-by: Tong Chen <[email protected]>

---------

Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>

* Decompose Hardswish into simpler ONNX ops (onnx#3107)

* Decompose and lower Hardswish

Signed-off-by: Kumarappan <[email protected]>

* Providing the decomposition as compile time option with krnl dialect lowering as default

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Reorder relu to maxpool optimization pass in ONNX dialect (onnx#3109)

* Reorder Relu and maxpool optimization

Signed-off-by: Arkar-Hema <[email protected]>

* Swap Relu and maxpool only when Relu is not a consumer of conv

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Move onnx.Constant before the root op when fusing onnx ops (onnx#3119)

Signed-off-by: Tung D. Le <[email protected]>

* Support QLinearMatMul on CPU (onnx#3117)

* Support QLinearMatMul on CPU

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* Update black-format-check.yml (onnx#3118)

Signed-off-by: Andreas Fehlner <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Merge nested concat Ops optimization pass in ONNX dialect (onnx#3111)

* Merging nested concat ops

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Enhance shape inference for ONNX Reshape (onnx#3122)

* Add a special case in shape inference for reshape

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* update zdnn1.1.2 (onnx#3130)

Signed-off-by: Sunny Anand <[email protected]>

* Updating supported ops on NNPA md for z17.  (onnx#3120)

* starting to update new z17 NNPA ops

Signed-off-by: Christopher Munoz <[email protected]>

---------

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* fix CVE-2025-32434 (onnx#3135)

Signed-off-by: Sunny Anand <[email protected]>

* Fuse consecutive clips pattern (onnx#3132)

* Fuse consecutive clips pattern

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Replace deprecated applyPatternsAndFoldGreedily with applyPatternsGreedily. This functions also folds by default, so it is an NFC

Signed-off-by: Rickert, Jonas <[email protected]>

* Fix clang-format

Signed-off-by: Rickert, Jonas <[email protected]>

* Replace bufferization::createOwnershipBasedBufferDeallocationPass with mlir::createConvertBufferizationToMemRefPass

Signed-off-by: Rickert, Jonas <[email protected]>

* Update onnx-to-tosa reshape lit test

Signed-off-by: Rickert, Jonas <[email protected]>

* Move gemm_to_fc tests to gemm_to_matmul

Signed-off-by: Rickert, Jonas <[email protected]>

* Change tosaBuilder::mul function signature to make clear that the shift is an int8

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable buffer_loop_hoisting test as it gets completly optimized away

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against dynamic dim in result

Signed-off-by: Rickert, Jonas <[email protected]>

* Use resize operaton input and output type to calculate the border, instead of using the calculated numerator/denominator

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against linear interpolation of integer types

Signed-off-by: Rickert, Jonas <[email protected]>

* Add test for disallowed onnx.Resize on its with linear interpolation to tosa

Signed-off-by: Rickert, Jonas <[email protected]>

* Add 'Pure' annotation to some krnl ops and recreate documentation

Signed-off-by: Rickert, Jonas <[email protected]>

* Build stablehlo with static libs

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable memref.prefetch since it does not work with the new bufferization

Signed-off-by: Tung D. Le <[email protected]>

* Conv add const where the constant is a scalar (onnx#3145)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* added support for Celu op (onnx#3139)

Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>

* Fix some warnings related to stickification for NNPA (onnx#3147)

Signed-off-by: Tung D. Le <[email protected]>

* Removing duplicate file (onnx#3146)

Signed-off-by: Christopher Munoz <[email protected]>

* migrated instance/group normalization from decompose to canonicalize (onnx#3148)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Fusion of Matmul add covering the stacked/unstacked/bcast1/bcast23 patterns (onnx#3140)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Support --march=native (onnx#3134)

* changes

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* linkage

Signed-off-by: Chen Tong <[email protected]>

* lib

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* fix another error on s390x

Signed-off-by: Tung D. Le <[email protected]>

* lower Ub to LLVM since vector.shape_cast is lowered to UB

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Boyana Norris <[email protected]>
Signed-off-by: Tung D. Le <[email protected]>
Signed-off-by: Rickert, Jonas <[email protected]>
Signed-off-by: Alexandre Eichenberger <[email protected]>
Signed-off-by: Christopher Munoz <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: JiQiu <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Kumarappan <[email protected]>
Signed-off-by: Arkar-Hema <[email protected]>
Signed-off-by: Andreas Fehlner <[email protected]>
Signed-off-by: Sunny Anand <[email protected]>
Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>
Co-authored-by: Jonas Rickert <[email protected]>
Co-authored-by: Christopher Munoz <[email protected]>
Co-authored-by: Haruki Imai <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
Co-authored-by: qjivy <[email protected]>
Co-authored-by: Tong Chen <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: kumarappan-cmyk <[email protected]>
Co-authored-by: Arkar-Hema <[email protected]>
Co-authored-by: Andreas Fehlner <[email protected]>
Co-authored-by: logeshwaranmcw <[email protected]>
Signed-off-by: Jonas Rickert <[email protected]>
jorickert added a commit to Xilinx/onnx-mlir that referenced this pull request Jul 1, 2025
AMD changes: Update lowering and tests for onnx->tosa conversions that are not upstream

Partial cherry-pick of f03b287

LLVM update 43d71ba (onnx#3086)

* update float types, tosa, other misc changes

Signed-off-by: Boyana Norris <[email protected]>

* fix buildOnnxToTosaPaddingConstOp

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests (wip)

Signed-off-by: Boyana Norris <[email protected]>

* updte doc

Signed-off-by: Boyana Norris <[email protected]>

* use stablehlo tagged version

Signed-off-by: Boyana Norris <[email protected]>

* fixed more lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix .clang-format

Signed-off-by: Boyana Norris <[email protected]>

* fix lit (wip)

Signed-off-by: Boyana Norris <[email protected]>

* revert .clang-format change

Signed-off-by: Boyana Norris <[email protected]>

* fix lit tests

Signed-off-by: Boyana Norris <[email protected]>

* fix formatting

Signed-off-by: Boyana Norris <[email protected]>

* lit tests pass (except jni -- not tested)

Signed-off-by: Boyana Norris <[email protected]>

* manually fix formatting; can't get clang-format to do it on any of my machines

Signed-off-by: Boyana Norris <[email protected]>

* revert lit test changes unrelated to update

Signed-off-by: Boyana Norris <[email protected]>

* update llvm and stablhlo shas, misc minor updates

Signed-off-by: Boyana Norris <[email protected]>

* remove non-existent passes

Signed-off-by: Boyana Norris <[email protected]>

* lit updates (wip)

Signed-off-by: Tung D. Le <[email protected]>

* Bump Upsample to Opset 10 and change the opset versioning to allow to skip over opset versions if a newer, backwards compatible one exists. (onnx#3065)

* Bump Upsample to Opset 10

This is a non-functional change, the only difference is that Upsample was marked as deprecated with Opset 10

Signed-off-by: Rickert, Jonas <[email protected]>

* Use a map of the available opset versions in onnx to select the node opset to use.

Introduces a new built-time generated map that contains all versions of an operation as defined by onnx.
To determine the opset version for a node/op:
1.	Determine the latest valid opset version. This is the newest version in this opset-version-map that is older or equal to the current graph opset.
2.	Select the newest version from the versions supported by onnx-mlir that is equal or newer to the latest valid opset version. This allows it to skip over opset versions, that have a newer backwards compatible version.
Example:
	Versions in onnx and supported by onnx-mlir: [3, 5].
	Graph opset version to node version: 3 -> 3, 4 -> 3, 5 -> 5

	Versions in onnx: [7, 9, 10]. Version 10 is backwards compatible to version 9.
	Version supported by onnx-mlir: [7, 10].
	Graph opset version to node version: 7 -> 7, 8 -> 7, 9 -> 10, 10 -> 10

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Improve scripts (onnx#3089)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Bump various ops to opset 21, adding int4/uint4 and 8 bit float support. (onnx#3064)

* Add support for TensorProto::UINT4/INT4

Signed-off-by: Rickert, Jonas <[email protected]>

* Upgrade onnx.Cast to opset 21

Signed-off-by: Rickert, Jonas <[email protected]>

* Bump various ops to opset 21.

These are all backwards compatibel version bumps, only adding support for int/uint4.

Bumped ops:
Flatten
Identity
If
Loop
Pad
Reshape
Scan
Shape
Size
Squeeze
Transpose
Unsqueeze

Signed-off-by: Rickert, Jonas <[email protected]>

---------

Signed-off-by: Rickert, Jonas <[email protected]>

* Added minimal support to do some timing of OM Runtime functionality (onnx#3095)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* adding __errno_location call for mvs (onnx#3099)

Signed-off-by: Christopher Munoz <[email protected]>

* Rewriting pattern to remove WhereOp and EqualOp.  (onnx#3094)

Remove ONNXWhereOp and ONNXEqualOp into newly created ConcatOp.

---------

Signed-off-by: Haruki Imai <[email protected]>

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation (onnx#3101)

* Enable NNPA saturation by default and change the option to --nnpa-disable-saturation

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* removing weak attribute of errorno (onnx#3103)

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Fix the custom build link for docs/Docker.md (onnx#3104)

Signed-off-by: JiQiu <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Python driver for torch model (onnx#3093)

* implementation

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* test

Signed-off-by: Chen Tong <[email protected]>

* py format

Signed-off-by: Chen Tong <[email protected]>

* torch.compile

Signed-off-by: Chen Tong <[email protected]>

* refine

Signed-off-by: Chen Tong <[email protected]>

* add debug

Signed-off-by: Chen Tong <[email protected]>

* respond

Signed-off-by: Chen Tong <[email protected]>

* response

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* implement (onnx#3108)

Signed-off-by: Chen Tong <[email protected]>

* Followups for torch model driver (onnx#3106)

* simplify

Signed-off-by: Chen Tong <[email protected]>

* complete

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

* fix

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* Fix an error in ZHighConstantPropagation for QuantizedStick (onnx#3112)

Signed-off-by: Tung D. Le <[email protected]>

* Add z17 for -march (onnx#3113)

* done

Signed-off-by: Tong Chen <[email protected]>

* convert

Signed-off-by: Tong Chen <[email protected]>

* fix

Signed-off-by: Tong Chen <[email protected]>

* format

Signed-off-by: Tong Chen <[email protected]>

---------

Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>

* Decompose Hardswish into simpler ONNX ops (onnx#3107)

* Decompose and lower Hardswish

Signed-off-by: Kumarappan <[email protected]>

* Providing the decomposition as compile time option with krnl dialect lowering as default

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Reorder relu to maxpool optimization pass in ONNX dialect (onnx#3109)

* Reorder Relu and maxpool optimization

Signed-off-by: Arkar-Hema <[email protected]>

* Swap Relu and maxpool only when Relu is not a consumer of conv

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Move onnx.Constant before the root op when fusing onnx ops (onnx#3119)

Signed-off-by: Tung D. Le <[email protected]>

* Support QLinearMatMul on CPU (onnx#3117)

* Support QLinearMatMul on CPU

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* Update black-format-check.yml (onnx#3118)

Signed-off-by: Andreas Fehlner <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Merge nested concat Ops optimization pass in ONNX dialect (onnx#3111)

* Merging nested concat ops

Signed-off-by: Arkar-Hema <[email protected]>

---------

Signed-off-by: Arkar-Hema <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Enhance shape inference for ONNX Reshape (onnx#3122)

* Add a special case in shape inference for reshape

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Tung D. Le <[email protected]>

* update zdnn1.1.2 (onnx#3130)

Signed-off-by: Sunny Anand <[email protected]>

* Updating supported ops on NNPA md for z17.  (onnx#3120)

* starting to update new z17 NNPA ops

Signed-off-by: Christopher Munoz <[email protected]>

---------

Signed-off-by: Christopher Munoz <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* fix CVE-2025-32434 (onnx#3135)

Signed-off-by: Sunny Anand <[email protected]>

* Fuse consecutive clips pattern (onnx#3132)

* Fuse consecutive clips pattern

Signed-off-by: Kumarappan <[email protected]>

---------

Signed-off-by: Kumarappan <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>

* Replace deprecated applyPatternsAndFoldGreedily with applyPatternsGreedily. This functions also folds by default, so it is an NFC

Signed-off-by: Rickert, Jonas <[email protected]>

* Fix clang-format

Signed-off-by: Rickert, Jonas <[email protected]>

* Replace bufferization::createOwnershipBasedBufferDeallocationPass with mlir::createConvertBufferizationToMemRefPass

Signed-off-by: Rickert, Jonas <[email protected]>

* Update onnx-to-tosa reshape lit test

Signed-off-by: Rickert, Jonas <[email protected]>

* Move gemm_to_fc tests to gemm_to_matmul

Signed-off-by: Rickert, Jonas <[email protected]>

* Change tosaBuilder::mul function signature to make clear that the shift is an int8

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable buffer_loop_hoisting test as it gets completly optimized away

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against dynamic dim in result

Signed-off-by: Rickert, Jonas <[email protected]>

* Use resize operaton input and output type to calculate the border, instead of using the calculated numerator/denominator

Signed-off-by: Rickert, Jonas <[email protected]>

* Guard against linear interpolation of integer types

Signed-off-by: Rickert, Jonas <[email protected]>

* Add test for disallowed onnx.Resize on its with linear interpolation to tosa

Signed-off-by: Rickert, Jonas <[email protected]>

* Add 'Pure' annotation to some krnl ops and recreate documentation

Signed-off-by: Rickert, Jonas <[email protected]>

* Build stablehlo with static libs

Signed-off-by: Rickert, Jonas <[email protected]>

* Disable memref.prefetch since it does not work with the new bufferization

Signed-off-by: Tung D. Le <[email protected]>

* Conv add const where the constant is a scalar (onnx#3145)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* added support for Celu op (onnx#3139)

Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>

* Fix some warnings related to stickification for NNPA (onnx#3147)

Signed-off-by: Tung D. Le <[email protected]>

* Removing duplicate file (onnx#3146)

Signed-off-by: Christopher Munoz <[email protected]>

* migrated instance/group normalization from decompose to canonicalize (onnx#3148)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Fusion of Matmul add covering the stacked/unstacked/bcast1/bcast23 patterns (onnx#3140)

Signed-off-by: Alexandre Eichenberger <[email protected]>

* Support --march=native (onnx#3134)

* changes

Signed-off-by: Chen Tong <[email protected]>

* format

Signed-off-by: Chen Tong <[email protected]>

* linkage

Signed-off-by: Chen Tong <[email protected]>

* lib

Signed-off-by: Chen Tong <[email protected]>

---------

Signed-off-by: Chen Tong <[email protected]>

* fix another error on s390x

Signed-off-by: Tung D. Le <[email protected]>

* lower Ub to LLVM since vector.shape_cast is lowered to UB

Signed-off-by: Tung D. Le <[email protected]>

---------

Signed-off-by: Boyana Norris <[email protected]>
Signed-off-by: Tung D. Le <[email protected]>
Signed-off-by: Rickert, Jonas <[email protected]>
Signed-off-by: Alexandre Eichenberger <[email protected]>
Signed-off-by: Christopher Munoz <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: JiQiu <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Tong Chen <[email protected]>
Signed-off-by: Kumarappan <[email protected]>
Signed-off-by: Arkar-Hema <[email protected]>
Signed-off-by: Andreas Fehlner <[email protected]>
Signed-off-by: Sunny Anand <[email protected]>
Signed-off-by: logeshwaranmcw <[email protected]>
Co-authored-by: Alexandre Eichenberger <[email protected]>
Co-authored-by: Jonas Rickert <[email protected]>
Co-authored-by: Christopher Munoz <[email protected]>
Co-authored-by: Haruki Imai <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
Co-authored-by: qjivy <[email protected]>
Co-authored-by: Tong Chen <[email protected]>
Co-authored-by: Sunny Anand <[email protected]>
Co-authored-by: kumarappan-cmyk <[email protected]>
Co-authored-by: Arkar-Hema <[email protected]>
Co-authored-by: Andreas Fehlner <[email protected]>
Co-authored-by: logeshwaranmcw <[email protected]>
Signed-off-by: Jonas Rickert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants