Skip to content

Implement unary_ufunc functions using elementwise_util #9386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 126 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
31a49e0
Update
swolchok Mar 19, 2025
9fcd885
Update
swolchok Mar 19, 2025
29d6de9
Update
swolchok Mar 19, 2025
79b908c
Update
swolchok Mar 19, 2025
fd62a07
Update
swolchok Mar 19, 2025
854c991
Update
swolchok Mar 19, 2025
def7ed4
Update
swolchok Mar 19, 2025
40c1b1b
Update
swolchok Mar 19, 2025
7c78357
Update
swolchok Mar 19, 2025
7ba269a
Update
swolchok Mar 19, 2025
edd45fb
Update
swolchok Mar 19, 2025
b9c545f
Update
swolchok Mar 20, 2025
3091007
Update
swolchok Mar 20, 2025
4a00cac
Update
swolchok Mar 20, 2025
21b81bf
Update
swolchok Mar 20, 2025
4c4add0
Update
swolchok Mar 20, 2025
8782a90
Update
swolchok Mar 20, 2025
75f8970
Update
swolchok Mar 20, 2025
2d19e75
Update
swolchok Mar 20, 2025
b61a8a2
Update
swolchok Mar 25, 2025
91161bd
Update
swolchok Mar 25, 2025
4add706
Update
swolchok Mar 25, 2025
5348a92
Update
swolchok Mar 25, 2025
001d72c
Update
swolchok Mar 25, 2025
e49080d
Update
swolchok Mar 25, 2025
44ee51a
Update
swolchok Mar 25, 2025
61afee1
Update
swolchok Mar 25, 2025
f659627
Update
swolchok Mar 25, 2025
f1c5429
Update
swolchok Mar 25, 2025
b34f04f
Update
swolchok Mar 25, 2025
f934bc0
Update
swolchok Mar 25, 2025
3a74f25
Update
swolchok Mar 25, 2025
bbc7ba8
Update
swolchok Mar 25, 2025
151bf4a
Update
swolchok Mar 25, 2025
0654e25
Update
swolchok Mar 25, 2025
9a93839
Update
swolchok Mar 26, 2025
bb16a55
Update
swolchok Mar 26, 2025
2242f1e
Update
swolchok Mar 26, 2025
0822028
Update
swolchok Mar 26, 2025
f1b97dc
Update
swolchok Mar 26, 2025
7336ff1
Update
swolchok Mar 26, 2025
7f57a19
Update
swolchok Mar 26, 2025
5d95c06
Update
swolchok Mar 26, 2025
42623bb
Update
swolchok Mar 26, 2025
284bc17
Update
swolchok Mar 26, 2025
29c2cfd
Update
swolchok Mar 26, 2025
30a2145
Update
swolchok Mar 26, 2025
4553283
Update
swolchok Mar 26, 2025
39610ad
Update
swolchok Mar 26, 2025
b3120fa
Update
swolchok Mar 26, 2025
350bcd8
Update
swolchok Mar 26, 2025
37e5b7d
Update
swolchok Mar 26, 2025
f53bb31
Update
swolchok Mar 26, 2025
ff2c358
Update
swolchok Mar 26, 2025
9c2340f
Update
swolchok Mar 26, 2025
545777f
Update
swolchok Mar 26, 2025
61b2a26
Update
swolchok Mar 26, 2025
7086659
Update
swolchok Mar 28, 2025
e13de0e
Update
swolchok Mar 28, 2025
943ab82
Update
swolchok Mar 28, 2025
f22d039
Update
swolchok Mar 28, 2025
45ce46d
Update
swolchok Mar 28, 2025
754dba4
Update
swolchok Mar 28, 2025
d5dfe2f
Update
swolchok Mar 28, 2025
3f1b775
Update
swolchok Mar 28, 2025
e55ac4a
Update
swolchok Mar 28, 2025
34eb5d4
Update
swolchok Mar 28, 2025
ea9dc6f
Update
swolchok Mar 28, 2025
7d7859e
Update
swolchok Mar 28, 2025
b98829d
Update
swolchok Mar 28, 2025
3140910
Update
swolchok Mar 28, 2025
afad88e
Update
swolchok Mar 28, 2025
946f2e0
Update
swolchok Mar 28, 2025
242995d
Update
swolchok Mar 28, 2025
7c23fec
Update
swolchok Mar 28, 2025
7f2bbdb
Update
swolchok Apr 2, 2025
960315e
Update
swolchok Apr 2, 2025
9e42e93
Update
swolchok Apr 2, 2025
96d258e
Update
swolchok Apr 2, 2025
e6f66ab
Update
swolchok Apr 2, 2025
a756254
Update
swolchok Apr 2, 2025
de9d52f
Update
swolchok Apr 2, 2025
ef74fe1
Update
swolchok Apr 2, 2025
b2e23ae
Update
swolchok Apr 2, 2025
7dc5cee
Update
swolchok Apr 2, 2025
20f3046
Update
swolchok Apr 2, 2025
3aa266d
Update
swolchok Apr 2, 2025
3c88a56
Update
swolchok Apr 2, 2025
153735d
Update
swolchok Apr 2, 2025
cac4293
Update
swolchok Apr 2, 2025
85451ea
Update
swolchok Apr 2, 2025
77a4fc6
Update
swolchok Apr 2, 2025
21ae5da
Update
swolchok Apr 2, 2025
a61c9b8
Update
swolchok Apr 2, 2025
0beabbb
Update
swolchok Apr 2, 2025
a7876b5
Update
swolchok May 27, 2025
3d59208
add tests that are long enough to hit the vectorized path
swolchok May 28, 2025
6541b28
actually verified test coverage
swolchok May 28, 2025
61a2f32
split out some commits
swolchok May 28, 2025
aedb0fa
split out some commits
swolchok May 28, 2025
a6d2402
split out some commits
swolchok May 28, 2025
78e1abb
fix visibility
swolchok May 28, 2025
f72595a
fix visibility
swolchok May 28, 2025
5a0da3f
fix visibility
swolchok May 28, 2025
b10c80f
Update
swolchok May 28, 2025
b721485
Update
swolchok May 28, 2025
c0ad8ac
Update
swolchok May 28, 2025
14a42e0
Update
swolchok May 28, 2025
17e45db
Update
swolchok May 28, 2025
678f180
Update
swolchok May 28, 2025
ca96ac7
Update
swolchok May 28, 2025
402caf2
rebase, fix lint in #9432
swolchok May 29, 2025
a4df2da
rebase, fix lint in #9432
swolchok May 29, 2025
84170e4
rebase, fix lint in #9432
swolchok May 29, 2025
aa5009b
rebase, fix lint in #9432
swolchok May 29, 2025
6e71130
rebase, fix lint in #9432
swolchok May 29, 2025
9573d9f
rebase, fix lint in #9432
swolchok May 29, 2025
7baa2f4
rebase, fix lint in #9432
swolchok May 29, 2025
4a0d1db
Update
swolchok Jun 9, 2025
ca9db4c
Update
swolchok Jun 9, 2025
aa453d7
Update
swolchok Jun 9, 2025
39528d3
Update
swolchok Jun 9, 2025
3f4a6a5
Update
swolchok Jun 9, 2025
9967037
Update
swolchok Jun 9, 2025
be32080
Update
swolchok Jun 9, 2025
d14a503
Update
swolchok Jun 9, 2025
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
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_acos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_acosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_asin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_asinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_atan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_atanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_ceil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace native {
using executorch::aten::Tensor;

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_cosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_erf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
7 changes: 5 additions & 2 deletions kernels/portable/cpu/op_expm1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
*/

#include <executorch/kernels/portable/cpu/pattern/pattern.h>
#include <executorch/kernels/portable/cpu/util/elementwise_util.h>
#include <executorch/runtime/kernel/kernel_includes.h>
#include <cmath>
#include <type_traits>

namespace torch {
namespace executor {
namespace native {

Tensor& expm1_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return internal::unary_ufunc_realhbbf16_to_floathbf16(
std::expm1, ctx, in, out);
static constexpr const char op_name[] = "expm1.out";
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
[](auto x) { return executorch::math::expm1(x); }, ctx, in, out);
}

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_floor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace native {
using executorch::aten::Tensor;

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_isinf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ namespace native {
Tensor& isinf_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
// Lambda is syntactic sugar needed to workaround compilation on some older
// non-compatible distros where isnan is returning int rather than bool
return internal::unary_ufunc_realhb_to_bool(
[](double x) -> bool { return std::isinf(x); }, ctx, in, out);
static constexpr const char op_name[] = "isinf.out";
return internal::unary_ufunc_realhb_to_bool<op_name>(
[](auto x) -> bool { return std::isinf(x); }, ctx, in, out);
}

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_isnan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ namespace native {
Tensor& isnan_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
// Lambda is syntactic sugar needed to workaround compilation on some older
// non-compatible distros where isnan is returning int rather than bool
return internal::unary_ufunc_realhb_to_bool(
[](double x) -> bool { return std::isnan(x); }, ctx, in, out);
static constexpr const char op_name[] = "isnan.out";
return internal::unary_ufunc_realhb_to_bool<op_name>(
[](auto x) -> bool { return std::isnan(x); }, ctx, in, out);
}

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_log10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_log1p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_log2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
13 changes: 3 additions & 10 deletions kernels/portable/cpu/op_reciprocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,11 @@
namespace torch {
namespace executor {
namespace native {
namespace {

double reciprocal(double x) {
return 1.0 / x;
}

} // namespace

Tensor&
reciprocal_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return internal::unary_ufunc_realhbbf16_to_floathbf16(
reciprocal, ctx, in, out);
static constexpr const char op_name[] = "reciprocal.out";
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
[](auto x) { return executorch::math::reciprocal(x); }, ctx, in, out);
}

} // namespace native
Expand Down
11 changes: 3 additions & 8 deletions kernels/portable/cpu/op_rsqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
namespace torch {
namespace executor {
namespace native {
namespace {

double rsqrt(double x) {
return 1.0 / std::sqrt(x);
}

} // namespace

Tensor& rsqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return internal::unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
static constexpr const char op_name[] = "rsqrt.out";
return internal::unary_ufunc_realhbbf16_to_floathbf16<op_name>(
[](auto x) { return executorch::math::rsqrt(x); }, ctx, in, out);
}

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_sin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_sinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_sqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_tan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
5 changes: 3 additions & 2 deletions kernels/portable/cpu/op_tanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
4 changes: 3 additions & 1 deletion kernels/portable/cpu/op_trunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace executor {
namespace native {

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

} // namespace native
Expand Down
28 changes: 28 additions & 0 deletions kernels/portable/cpu/pattern/pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <executorch/kernels/portable/cpu/pattern/pattern.h>

namespace torch::executor::native::internal {

bool check_and_resize_inputs(
KernelRuntimeContext& ctx,
const Tensor& in,
Tensor& out) {
ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, false);
ET_KERNEL_CHECK_MSG(
ctx,
resize_tensor(out, in.sizes()) == Error::Ok,
InvalidArgument,
false,
"Failed to resize output tensor.");
return true;
}

} // namespace torch::executor::native::internal
Loading
Loading