Skip to content

Commit 76f8095

Browse files
committed
Implement unary_ufunc functions using elementwise_util
One less set of independent implementations to worry about going forward (e.g., we don't have to vectorize these separately from elementwise_util and they get all benefits of elementwise_util). ghstack-source-id: 4f94633 ghstack-comment-id: 2735017402 Pull Request resolved: #9386
1 parent 53251eb commit 76f8095

36 files changed

+231
-256
lines changed

kernels/portable/cpu/op_acos.cpp

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

1717
Tensor& acos_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::acos, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_acosh.cpp

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

1717
Tensor& acosh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::acosh, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_asin.cpp

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

1717
Tensor& asin_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::asin, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_asinh.cpp

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

1717
Tensor& asinh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::asinh, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_atan.cpp

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

1717
Tensor& atan_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::atan, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_atanh.cpp

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

1717
Tensor& atanh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::atanh, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_ceil.cpp

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

1919
Tensor& ceil_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
20-
return internal::unary_ufunc_realhbf16(std::ceil, ctx, in, 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);
2123
}
2224

2325
} // namespace native

kernels/portable/cpu/op_cos.cpp

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

1717
Tensor& cos_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::cos, ctx, in, 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);
1921
}
2022

2123
} // namespace native

kernels/portable/cpu/op_cosh.cpp

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

1717
Tensor& cosh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(
19-
std::cosh, ctx, in, 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);
2021
}
2122

2223
} // namespace native

kernels/portable/cpu/op_erf.cpp

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

1717
Tensor& erf_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhbbf16_to_floathbf16(std::erf, ctx, in, 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);
1921
}
2022

2123
} // namespace native

0 commit comments

Comments
 (0)