forked from onnx/onnx-mlir
-
Notifications
You must be signed in to change notification settings - Fork 25
Add onnx.Abs to tosa.Abs lowering with quant types #605
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
Draft
tr00
wants to merge
1
commit into
feature/onnx-to-tosa
Choose a base branch
from
tarik.quant-types
base: feature/onnx-to-tosa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |||||
| //====------ ONNXToTOSACommon.hpp - ONNX dialects to TOSA lowering --------===// | ||||||
| // | ||||||
| // Copyright 2020-2024 The TensorFlow Authors. All Rights Reserved. | ||||||
| // Copyright (c) 2022-2024 Advanced Micro Devices, Inc. | ||||||
| // Copyright (c) 2022-2026 Advanced Micro Devices, Inc. | ||||||
| // | ||||||
| // ============================================================================= | ||||||
| // | ||||||
|
|
@@ -104,6 +104,11 @@ inline bool isTOSAFloat(mlir::Type type) { | |||||
| type); | ||||||
| } | ||||||
|
|
||||||
| inline bool isTOSAQuantizedInt(mlir::Type type) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| auto quantizedType = mlir::dyn_cast<mlir::quant::UniformQuantizedType>(type); | ||||||
| return quantizedType && isTOSAInt(quantizedType.getStorageType()); | ||||||
| } | ||||||
|
|
||||||
| //===----------------------------------------------------------------------===// | ||||||
| // This is to get a TOSA operation of a given type for a specific operation. | ||||||
| //===----------------------------------------------------------------------===// | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Copyright (c) 2026 Advanced Micro Devices, Inc. | ||
|
|
||
| // RUN: onnx-mlir-opt --shape-inference --convert-onnx-to-tosa -cse %s -split-input-file | FileCheck %s | ||
|
|
||
| // ----- | ||
|
|
@@ -786,6 +788,29 @@ func.func @test_abs_f64(%arg0: tensor<3xf64>) -> tensor<3xf64> { | |
| // CHECK: return {{.*}}: tensor<3xf64> | ||
| } | ||
|
|
||
| func.func @test_abs_qi8(%arg0: tensor<3x!quant.uniform<i8:f32, 1.0>>) -> tensor<3x!quant.uniform<i8:f32, 1.0>> { | ||
| %0 = "onnx.Abs"(%arg0) : (tensor<3x!quant.uniform<i8:f32, 1.0>>) -> tensor<3x!quant.uniform<i8:f32, 1.0>> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get a test where the input and output quantization parameters are not the same? |
||
| return %0 : tensor<3x!quant.uniform<i8:f32, 1.0>> | ||
| // CHECK-LABEL: func @test_abs_qi8 | ||
| // CHECK-NEXT: [[VAR_0_:%.+]] = tosa.abs [[PARAM_0_]] : (tensor<3x!quant.uniform<i8:f32, 1.000000e+00>>) -> tensor<3x!quant.uniform<i8:f32, 1.000000e+00>> | ||
| // CHECK-NEXT: return [[VAR_0_]] : tensor<3x!quant.uniform<i8:f32, 1.000000e+00>> | ||
| // CHECK-NEXT: } | ||
| } | ||
|
|
||
| // Per-channel quantized types use quant.uniform<i8:f32:1 {s0, s1, ...}>, | ||
| // which is not currently handled by the ONNX-to-TOSA elementwise conversion. | ||
| // Only per-tensor uniform quantized types are supported. | ||
| // This test checks that the conversion does not fail but keeps the original op. | ||
|
|
||
| func.func @test_abs_qi8_channel(%arg0: tensor<3x4x!quant.uniform<i8:f32:1, {1.0, 2.0, 3.0, 4.0}>>) -> tensor<3x4x!quant.uniform<i8:f32:1, {1.0, 2.0, 3.0, 4.0}>> { | ||
| %0 = "onnx.Abs"(%arg0) : (tensor<3x4x!quant.uniform<i8:f32:1, {1.0, 2.0, 3.0, 4.0}>>) -> tensor<3x4x!quant.uniform<i8:f32:1, {1.0, 2.0, 3.0, 4.0}>> | ||
| return %0 : tensor<3x4x!quant.uniform<i8:f32:1, {1.0, 2.0, 3.0, 4.0}>> | ||
|
|
||
| // CHECK-LABEL: func @test_abs_qi8_channel | ||
| // CHECK: "onnx.Abs" | ||
| // CHECK: return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| func.func @test_erf_f32(%arg0: tensor<3xf32>) -> tensor<3xf32> { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move the implementation to the .cpp file?
For a small function like this it does not make a big difference, but generally having implementations in .cpp files helps to keep compile time and recompilations down