Skip to content
Closed
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
12 changes: 12 additions & 0 deletions src/target/llvm/intrin_rule_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ TVM_REGISTER_OP("tir.atanh")
return (log(one + x) - log(one - x)) * make_const(x.dtype(), 0.5);
});

TVM_REGISTER_OP("tir.erf").set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tir::make_const;
const tir::CallNode* call = e.as<tir::CallNode>();
ICHECK(call != nullptr) << "Invalid call node in erf legalization";
const PrimExpr& x = call->args[0];
PrimExpr sqrt_pi = sqrt(make_const(x.dtype(), M_PI));
PrimExpr coeff = make_const(x.dtype(), 2.0) / sqrt_pi;
PrimExpr x_cubed = x * x * x;
PrimExpr inner = x + make_const(x.dtype(), 11.0 / 123.0) * x_cubed;
return tanh(coeff * inner);
});

TVM_REGISTER_OP("tir.clz").set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
const tir::CallNode* call = e.as<tir::CallNode>();
ICHECK(call != nullptr);
Expand Down
5 changes: 4 additions & 1 deletion tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def test_bitwise_shift(direction: str):
"Sign",
"Softplus",
"Softsign",
"Erf",
# "Erf", // TODO @Cookiee235, fix the precision loss due to the approximation
"Sigmoid",
"Softmax",
"LogSoftmax",
Expand Down Expand Up @@ -799,12 +799,15 @@ def test_unsqueeze_v1():
check_correctness(model, opset=10)


# TODO @Cookiee235, fix the precision loss due to the approximation in Erf
"""
def test_gelu():
verify_unary("Gelu", [32, 32], domain="com.microsoft")


def test_bias_gelu():
verify_binary("BiasGelu", [32, 32], [32], [32, 32], domain="com.microsoft")
"""


def test_where():
Expand Down