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
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
52 changes: 26 additions & 26 deletions mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)";
}

//===----------------------------------------------------------------------===//
Expand Down