Skip to content
Open
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
52 changes: 6 additions & 46 deletions src/target/llvm/intrin_rule_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,16 @@ TVM_REGISTER_OP("tirx.tan")

TVM_REGISTER_OP("tirx.cosh")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
using tirx::make_zero;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr);
const PrimExpr& x = call->args[0];
PrimExpr two = make_const(x.dtype(), 2);
PrimExpr neg_one = make_const(x.dtype(), -1);
PrimExpr exp_negx = exp(neg_one * x);
PrimExpr exp_posx = exp(x);
PrimExpr ret = (exp_posx + exp_negx) / two;
return ret;
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.sinh")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
using tirx::make_zero;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr);
const PrimExpr& x = call->args[0];
PrimExpr two = make_const(x.dtype(), 2);
PrimExpr neg_one = make_const(x.dtype(), -1);
PrimExpr exp_negx = exp(neg_one * x);
PrimExpr exp_posx = exp(x);
PrimExpr ret = (exp_posx - exp_negx) / two;
return ret;
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.asin")
Expand Down Expand Up @@ -232,35 +216,23 @@ TVM_REGISTER_OP("tirx.acos")

TVM_REGISTER_OP("tirx.atan")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr) << "Invalid call node in atan legalization";
const PrimExpr& x = call->args[0];
PrimExpr one = make_const(x.dtype(), 1.0);
PrimExpr denom = sqrt(x * x + one);
return asin(x / denom);
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.asinh")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr) << "Invalid call node in asinh legalization";
const PrimExpr& x = call->args[0];
PrimExpr one = make_const(x.dtype(), 1.0);
PrimExpr sqrt_val = sqrt(x * x + one);
return log(x + sqrt_val);
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.acosh")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr) << "Invalid call node in acosh legalization";
const PrimExpr& x = call->args[0];
PrimExpr one = make_const(x.dtype(), 1.0);
PrimExpr sqrt_val = sqrt(x * x - one);
return log(x + sqrt_val);
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.atanh")
Expand All @@ -275,21 +247,9 @@ TVM_REGISTER_OP("tirx.atanh")

TVM_REGISTER_OP("tirx.erf")
.set_attr<FLegalize>("llvm.FLegalize", [](const PrimExpr& e) -> PrimExpr {
using tirx::make_const;
const tirx::CallNode* call = e.as<tirx::CallNode>();
TVM_FFI_ICHECK(call != nullptr) << "Invalid call node in erf legalization";
const PrimExpr& x = call->args[0];
PrimExpr abs_x = tvm::abs(x);
PrimExpr t = make_const(x.dtype(), 1.0) /
(make_const(x.dtype(), 1.0) + make_const(x.dtype(), 0.3275911) * abs_x);
PrimExpr a1 = make_const(x.dtype(), 0.254829592);
PrimExpr a2 = make_const(x.dtype(), -0.284496736);
PrimExpr a3 = make_const(x.dtype(), 1.421413741);
PrimExpr a4 = make_const(x.dtype(), -1.453152027);
PrimExpr a5 = make_const(x.dtype(), 1.061405429);
PrimExpr poly = (((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t);
PrimExpr approx = make_const(x.dtype(), 1.0) - poly * exp(-abs_x * abs_x);
return tvm::tirx::Select(x < 0, -approx, approx);
return ::tvm::codegen::intrin::DispatchPureExtern<::tvm::codegen::intrin::FloatSuffix>(e);
});

TVM_REGISTER_OP("tirx.clz")
Expand Down
2 changes: 1 addition & 1 deletion tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def test_bitwise_shift(direction: str):
"Tanh",
# "Asin", // TODO @jikechao, fix the precision loss due to the Taylor approximation
# "Acos",
# "Atan",
"Atan",
"Asinh",
"Acosh",
"Atanh",
Expand Down
Loading