Skip to content

Commit 15518c6

Browse files
committed
Reapply "Implement unary_ufunc functions using elementwise_util (#9386)"
Pull Request resolved: #11943 This PR was reverted due to internal test failures, which should be fixed now (and is being sent as an exported diff to make sure). Original summary: 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: 292614913 @exported-using-ghexport Differential Revision: [D76754824](https://our.internmc.facebook.com/intern/diff/D76754824/)
1 parent df1e9c7 commit 15518c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+242
-274
lines changed

backends/cadence/fusion_g3/operators/op_exp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ Tensor& exp_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
5959

6060
return out;
6161
} else {
62+
static constexpr const char op_name[] = "exp.out";
6263
return torch::executor::native::internal::
63-
unary_ufunc_realhbbf16_to_floathbf16(std::exp, ctx, in, out);
64+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
65+
[](auto x) { return executorch::math::exp(x); }, ctx, in, out);
6466
}
6567
}
6668

backends/cadence/fusion_g3/operators/op_rsqrt.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ namespace impl {
2525
namespace G3 {
2626
namespace native {
2727

28-
namespace {
29-
30-
double rsqrt(double x) {
31-
return 1.0 / std::sqrt(x);
32-
}
33-
34-
} // namespace
35-
3628
Tensor& rsqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
3729
#ifdef OP_ARG_CHECK
3830
// Resize for dynamic shape
@@ -60,12 +52,14 @@ Tensor& rsqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
6052

6153
return out;
6254
} else {
55+
static constexpr const char op_name[] = "rsqrt.out";
6356
return torch::executor::native::internal::
64-
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
57+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
58+
[](auto x) { return executorch::math::rsqrt(x); }, ctx, in, out);
6559
}
6660
}
6761

6862
} // namespace native
6963
} // namespace G3
7064
} // namespace impl
71-
} // namespace cadence
65+
} // namespace cadence

backends/cadence/fusion_g3/operators/op_sqrt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ Tensor& sqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
5454

5555
return out;
5656
} else {
57+
static constexpr const char op_name[] = "sqrt.out";
5758
return torch::executor::native::internal::
58-
unary_ufunc_realhbbf16_to_floathbf16(std::sqrt, ctx, in, out);
59+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
60+
[](auto x) { return executorch::math::sqrt(x); }, ctx, in, out);
5961
}
6062
}
6163

backends/cadence/fusion_g3/operators/op_tanh.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ Tensor& tanh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
5454

5555
return out;
5656
} else {
57+
static constexpr const char op_name[] = "tanh.out";
5758
return torch::executor::native::internal::
58-
unary_ufunc_realhbbf16_to_floathbf16(std::tanh, ctx, in, out);
59+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
60+
[](auto x) { return executorch::math::tanh(x); }, ctx, in, out);
5961
}
6062
}
6163

backends/cadence/hifi/operators/op_rsqrt.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ namespace cadence {
1919
namespace impl {
2020
namespace HiFi {
2121
namespace native {
22-
namespace {
23-
24-
double rsqrt(double x) {
25-
return 1.0 / std::sqrt(x);
26-
}
27-
28-
} // namespace
2922

3023
Tensor& rsqrt_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
3124
bool optimized = true;
@@ -45,8 +38,10 @@ Tensor& rsqrt_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
4538
return out;
4639
}
4740

41+
static constexpr const char op_name[] = "rsqrt.out";
4842
return torch::executor::native::internal::
49-
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
43+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
44+
[](auto x) { return executorch::math::rsqrt(x); }, ctx, in, out);
5045
}
5146

5247
} // namespace native

backends/cadence/hifi/operators/op_tanh.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ Tensor& tanh_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
3434
return out;
3535
}
3636

37+
static constexpr const char op_name[] = "tanh.out";
3738
return torch::executor::native::internal::
38-
unary_ufunc_realhbbf16_to_floathbf16(std::tanh, ctx, in, out);
39+
unary_ufunc_realhbbf16_to_floathbf16<op_name>(
40+
[](auto x) { return executorch::math::tanh(x); }, ctx, in, out);
3941
}
4042

4143
} // namespace native
4244
} // namespace HiFi
4345
} // namespace impl
44-
} // namespace cadence
46+
} // namespace cadence

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

0 commit comments

Comments
 (0)