Skip to content

Commit 7d6ca43

Browse files
committed
Revert "Implement unary_ufunc functions using elementwise_util (#9386)"
This reverts commit dffbd42.
1 parent 120eb85 commit 7d6ca43

35 files changed

+251
-222
lines changed

kernels/portable/cpu/op_acos.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& acos_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "acos.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::acos(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::acos, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_acosh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& acosh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "acosh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::acosh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::acosh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_asin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& asin_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "asin.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::asin(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::asin, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_asinh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& asinh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "asinh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::asinh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::asinh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_atan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& atan_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "atan.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::atan(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::atan, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_atanh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& atanh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "atanh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::atanh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::atanh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_ceil.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ namespace native {
1717
using executorch::aten::Tensor;
1818

1919
Tensor& ceil_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
20-
static constexpr const char op_name[] = "ceil.out";
21-
return internal::unary_ufunc_realhbf16<op_name>(
22-
[](auto x) { return executorch::math::ceil(x); }, ctx, in, out);
20+
return internal::unary_ufunc_realhbf16(std::ceil, ctx, in, out);
2321
}
2422

2523
} // namespace native

kernels/portable/cpu/op_cos.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& cos_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "cos.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::cos(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::cos, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_cosh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& cosh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "cosh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::cosh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::cosh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_erf.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& erf_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "erf.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::erf(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::erf, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_exp.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& exp_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "exp.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::exp(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::exp, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_expm1.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
*/
88

99
#include <executorch/kernels/portable/cpu/pattern/pattern.h>
10-
#include <executorch/kernels/portable/cpu/util/elementwise_util.h>
1110
#include <executorch/runtime/kernel/kernel_includes.h>
1211
#include <cmath>
13-
#include <type_traits>
1412

1513
namespace torch {
1614
namespace executor {
1715
namespace native {
1816

1917
Tensor& expm1_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
20-
static constexpr const char op_name[] = "expm1.out";
21-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
22-
[](auto x) { return executorch::math::expm1(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::expm1, ctx, in, out);
2320
}
2421

2522
} // namespace native

kernels/portable/cpu/op_floor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ namespace native {
1717
using executorch::aten::Tensor;
1818

1919
Tensor& floor_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
20-
static constexpr const char op_name[] = "floor.out";
21-
return internal::unary_ufunc_realhbf16<op_name>(
22-
[](auto x) { return executorch::math::floor(x); }, ctx, in, out);
20+
return internal::unary_ufunc_realhbf16(std::floor, ctx, in, out);
2321
}
2422

2523
} // namespace native

kernels/portable/cpu/op_isinf.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ namespace native {
1717
Tensor& isinf_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
1818
// Lambda is syntactic sugar needed to workaround compilation on some older
1919
// non-compatible distros where isnan is returning int rather than bool
20-
static constexpr const char op_name[] = "isinf.out";
21-
return internal::unary_ufunc_realhb_to_bool<op_name>(
22-
[](auto x) -> bool { return std::isinf(x); }, ctx, in, out);
20+
return internal::unary_ufunc_realhb_to_bool(
21+
[](double x) -> bool { return std::isinf(x); }, ctx, in, out);
2322
}
2423

2524
} // namespace native

kernels/portable/cpu/op_isnan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ namespace native {
1717
Tensor& isnan_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
1818
// Lambda is syntactic sugar needed to workaround compilation on some older
1919
// non-compatible distros where isnan is returning int rather than bool
20-
static constexpr const char op_name[] = "isnan.out";
21-
return internal::unary_ufunc_realhb_to_bool<op_name>(
22-
[](auto x) -> bool { return std::isnan(x); }, ctx, in, out);
20+
return internal::unary_ufunc_realhb_to_bool(
21+
[](double x) -> bool { return std::isnan(x); }, ctx, in, out);
2322
}
2423

2524
} // namespace native

kernels/portable/cpu/op_log.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& log_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "log.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::log(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::log, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_log10.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& log10_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "log10.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::log10(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::log10, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_log1p.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& log1p_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "log1p.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::log1p(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::log1p, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_log2.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& log2_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "log2.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::log2(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::log2, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_reciprocal.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
namespace torch {
1313
namespace executor {
1414
namespace native {
15+
namespace {
16+
17+
double reciprocal(double x) {
18+
return 1.0 / x;
19+
}
20+
21+
} // namespace
22+
1523
Tensor&
1624
reciprocal_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
17-
static constexpr const char op_name[] = "reciprocal.out";
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
19-
[](auto x) { return executorch::math::reciprocal(x); }, ctx, in, out);
25+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
26+
reciprocal, ctx, in, out);
2027
}
2128

2229
} // namespace native

kernels/portable/cpu/op_rsqrt.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
namespace torch {
1313
namespace executor {
1414
namespace native {
15+
namespace {
16+
17+
double rsqrt(double x) {
18+
return 1.0 / std::sqrt(x);
19+
}
20+
21+
} // namespace
1522

1623
Tensor& rsqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
17-
static constexpr const char op_name[] = "rsqrt.out";
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
19-
[](auto x) { return executorch::math::rsqrt(x); }, ctx, in, out);
24+
return internal::unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
2025
}
2126

2227
} // namespace native

kernels/portable/cpu/op_sin.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& sin_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "sin.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::sin(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::sin, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_sinh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& sinh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "sinh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::sinh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::sinh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_sqrt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& sqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "sqrt.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::sqrt(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::sqrt, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_tan.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& tan_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "tan.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::tan(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::tan, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/op_tanh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& tanh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "tanh.out";
19-
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
20-
[](auto x) { return executorch::math::tanh(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19+
std::tanh, ctx, in, out);
2120
}
2221

2322
} // namespace native

kernels/portable/cpu/op_trunc.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& trunc_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
static constexpr const char op_name[] = "trunc.out";
19-
return internal::unary_ufunc_realhbf16<op_name>(
20-
[](auto x) { return executorch::math::trunc(x); }, ctx, in, out);
18+
return internal::unary_ufunc_realhbf16(std::trunc, ctx, in, out);
2119
}
2220

2321
} // namespace native

kernels/portable/cpu/pattern/pattern.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)