Skip to content

[mlir][tosa] Reorder ERF op to align with TOSA spec #133814

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 1 commit into from
Apr 1, 2025
Merged

Conversation

Jerry-Ge
Copy link
Member

Minor non-functional change of the dialect to better align with the operator order from the TOSA specification: https://www.mlplatform.org/tosa/tosa_spec.html

Minor non-functional change of the dialect to better align with the operator
order from the TOSA specification: https://www.mlplatform.org/tosa/tosa_spec.html

Signed-off-by: Jerry Ge <[email protected]>
Change-Id: I1d2250aa5931b8d6285494bd86a1f828baa9fa89
@llvmbot
Copy link
Member

llvmbot commented Mar 31, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-tosa

Author: Jerry-Ge (Jerry-Ge)

Changes

Minor non-functional change of the dialect to better align with the operator order from the TOSA specification: https://www.mlplatform.org/tosa/tosa_spec.html


Full diff: https://github.com/llvm/llvm-project/pull/133814.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td (+26-26)
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index 1ba44db02f25f..75f167afd9dd0 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -499,21 +499,16 @@ def Tosa_ClampOp : Tosa_ElementwiseUnaryOp<"clamp"> {
 }
 
 //===----------------------------------------------------------------------===//
-// Operator: sigmoid
+// Operator: erf
 //===----------------------------------------------------------------------===//
-def Tosa_SigmoidOp : Tosa_ElementwiseUnaryOp<"sigmoid"> {
-  let summary = "Computes elementwise sigmoid of input.";
+def Tosa_ErfOp : Tosa_ElementwiseUnaryOp<"erf"> {
+  let summary = "Computes gauss error function of input.";
 
   let description = [{
-    Applies the sigmoid logistic function to each element of the input tensor:
-    $ sigmoid(x) = \frac{1}{1 + e^{-x}} $.
-
-    For quantized integer data types, the TABLE operator should be used instead.
-    Each implementation may choose an appropriate TABLE given the scale and zero
-    point of the input data. Eight or sixteen bit precision tables may be used
-    based on the input tensor to the sigmoid function. The sigmoid table has 513
-    entries each of 16-bit precision and covering the input range -16.0 to +16.0
-    in steps of 1/16.
+    Gauss error function: $ erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt $
+    For quantized integer data types, the TABLE operator should be used instead
+    with the following definition. The ERF table has 513 entries each of
+    16-bit precision and covering the input range -4.0 to +4.0 in steps of 1/64.
   }];
 
   let arguments = (ins
@@ -528,21 +523,26 @@ def Tosa_SigmoidOp : Tosa_ElementwiseUnaryOp<"sigmoid"> {
     Profile<[Tosa_PRO_FP]>,
     Extension<[Tosa_EXT_BF16]>,
   ];
+
+  let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
 }
 
 //===----------------------------------------------------------------------===//
-// Operator: tanh
+// Operator: sigmoid
 //===----------------------------------------------------------------------===//
-def Tosa_TanhOp : Tosa_ElementwiseUnaryOp<"tanh"> {
-  let summary = "Computes elementwise hyperbolic tangent of input.";
+def Tosa_SigmoidOp : Tosa_ElementwiseUnaryOp<"sigmoid"> {
+  let summary = "Computes elementwise sigmoid of input.";
 
   let description = [{
-    Parameterized hyperbolic tangent: $ tanh(x) = \frac{1 - e^{-2x}}{1 + e^{-2x}} $.
+    Applies the sigmoid logistic function to each element of the input tensor:
+    $ sigmoid(x) = \frac{1}{1 + e^{-x}} $.
 
     For quantized integer data types, the TABLE operator should be used instead.
     Each implementation may choose an appropriate TABLE given the scale and zero
     point of the input data. Eight or sixteen bit precision tables may be used
-    based on the input tensor to the tanh function.
+    based on the input tensor to the sigmoid function. The sigmoid table has 513
+    entries each of 16-bit precision and covering the input range -16.0 to +16.0
+    in steps of 1/16.
   }];
 
   let arguments = (ins
@@ -560,16 +560,18 @@ def Tosa_TanhOp : Tosa_ElementwiseUnaryOp<"tanh"> {
 }
 
 //===----------------------------------------------------------------------===//
-// Operator: erf
+// Operator: tanh
 //===----------------------------------------------------------------------===//
-def Tosa_ErfOp : Tosa_ElementwiseUnaryOp<"erf"> {
-  let summary = "Computes gauss error function of input.";
+def Tosa_TanhOp : Tosa_ElementwiseUnaryOp<"tanh"> {
+  let summary = "Computes elementwise hyperbolic tangent of input.";
 
   let description = [{
-    Gauss error function: $ erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt $
-    For quantized integer data types, the TABLE operator should be used instead
-    with the following definition. The ERF table has 513 entries each of
-    16-bit precision and covering the input range -4.0 to +4.0 in steps of 1/64.
+    Parameterized hyperbolic tangent: $ tanh(x) = \frac{1 - e^{-2x}}{1 + e^{-2x}} $.
+
+    For quantized integer data types, the TABLE operator should be used instead.
+    Each implementation may choose an appropriate TABLE given the scale and zero
+    point of the input data. Eight or sixteen bit precision tables may be used
+    based on the input tensor to the tanh function.
   }];
 
   let arguments = (ins
@@ -584,8 +586,6 @@ def Tosa_ErfOp : Tosa_ElementwiseUnaryOp<"erf"> {
     Profile<[Tosa_PRO_FP]>,
     Extension<[Tosa_EXT_BF16]>,
   ];
-
-  let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
 }
 
 //===----------------------------------------------------------------------===//

@Jerry-Ge
Copy link
Member Author

The files changed view is a little bit ugly. This change simply moved the ERF op definition to right after CLAMP

Copy link
Contributor

@CoTinker CoTinker left a comment

Choose a reason for hiding this comment

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

LGTM

@GeorgeARM GeorgeARM merged commit fd0785e into llvm:main Apr 1, 2025
14 checks passed
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request Apr 2, 2025
Minor non-functional change of the dialect to better align with the
operator order from the TOSA specification:
https://www.mlplatform.org/tosa/tosa_spec.html

Signed-off-by: Jerry Ge <[email protected]>
lhutton1 pushed a commit to lhutton1/llvm-project that referenced this pull request Jun 11, 2025
Upstream PR: llvm#133814

Minor non-functional change of the dialect to better align with the operator
order from the TOSA specification: https://www.mlplatform.org/tosa/tosa_spec.html

Signed-off-by: Jerry Ge <[email protected]>
Change-Id: I1d2250aa5931b8d6285494bd86a1f828baa9fa89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants