Skip to content
Merged
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
2 changes: 1 addition & 1 deletion backends/cadence/fusion_g3/operators/op_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Tensor& exp_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return out;
} else {
return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(std::exp, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(std::exp, std::exp, ctx, in, out);
}
}

Expand Down
7 changes: 4 additions & 3 deletions backends/cadence/fusion_g3/operators/op_rsqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace native {

namespace {

double rsqrt(double x) {
template <typename T>
T rsqrt(T x) {
return 1.0 / std::sqrt(x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this should be T(1.0) otherwise we're forcing computation in double, right?

}

Expand Down Expand Up @@ -61,11 +62,11 @@ Tensor& rsqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return out;
} else {
return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, rsqrt, ctx, in, out);
}
}

} // namespace native
} // namespace G3
} // namespace impl
} // namespace cadence
} // namespace cadence
3 changes: 2 additions & 1 deletion backends/cadence/fusion_g3/operators/op_sqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Tensor& sqrt_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return out;
} else {
return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(std::sqrt, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(
std::sqrt, std::sqrt, ctx, in, out);
}
}

Expand Down
3 changes: 2 additions & 1 deletion backends/cadence/fusion_g3/operators/op_tanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Tensor& tanh_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
return out;
} else {
return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(std::tanh, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(
std::tanh, std::tanh, ctx, in, out);
}
}

Expand Down
5 changes: 3 additions & 2 deletions backends/cadence/hifi/operators/op_rsqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace HiFi {
namespace native {
namespace {

double rsqrt(double x) {
template <typename T>
T rsqrt(T x) {
return 1.0 / std::sqrt(x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto T(1.0)

}

Expand All @@ -46,7 +47,7 @@ Tensor& rsqrt_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
}

return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(rsqrt, rsqrt, ctx, in, out);
}

} // namespace native
Expand Down
4 changes: 2 additions & 2 deletions backends/cadence/hifi/operators/op_tanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Tensor& tanh_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
}

return torch::executor::native::internal::
unary_ufunc_realhbbf16_to_floathbf16(std::tanh, ctx, in, out);
unary_ufunc_realhbbf16_to_floathbf16(std::tanh, std::tanh, ctx, in, out);
}

} // namespace native
} // namespace HiFi
} // namespace impl
} // namespace cadence
} // namespace cadence
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_acos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(acos_out, std::acos)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_acosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(acosh_out, std::acosh)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_asin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(asin_out, std::asin)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_asinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(asinh_out, std::asinh)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_atan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(atan_out, std::atan)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_atanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(atanh_out, std::atanh)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(cos_out, std::cos)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_cosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(cosh_out, std::cosh)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_erf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(erf_out, std::erf)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(exp_out, std::exp)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_expm1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ 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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(expm1_out, std::expm1)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(log_out, std::log)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_log10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(log10_out, std::log10)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_log1p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(log1p_out, std::log1p)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_log2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(log2_out, std::log2)

} // namespace native
} // namespace executor
Expand Down
9 changes: 3 additions & 6 deletions kernels/portable/cpu/op_reciprocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ namespace executor {
namespace native {
namespace {

double reciprocal(double x) {
template <typename T>
T reciprocal(T 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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(reciprocal_out, reciprocal)

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

double rsqrt(double x) {
template <typename T>
T rsqrt(T 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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(rsqrt_out, rsqrt)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_sin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(sin_out, std::sin)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_sinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(sinh_out, std::sinh)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_sqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(sqrt_out, std::sqrt)

} // namespace native
} // namespace executor
Expand Down
4 changes: 1 addition & 3 deletions kernels/portable/cpu/op_tan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(tan_out, std::tan)

} // namespace native
} // namespace executor
Expand Down
5 changes: 1 addition & 4 deletions kernels/portable/cpu/op_tanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace torch {
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);
}
DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(tanh_out, std::tanh)

} // namespace native
} // namespace executor
Expand Down
9 changes: 8 additions & 1 deletion kernels/portable/cpu/pattern/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,18 @@ Tensor& unary_ufunc_realhb_to_bool(
* the math operation which is applied to the input tensor element-wise.
*/
Tensor& unary_ufunc_realhbbf16_to_floathbf16(
double (*fn)(double),
float (*fn_float)(float),
double (*fn_double)(double),
KernelRuntimeContext& ctx,
const Tensor& in,
Tensor& out);

#define DEFINE_UNARY_UFUNC_REALHBBF16_TO_FLOATHBF16(op_name, fn) \
Tensor& op_name(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { \
return internal::unary_ufunc_realhbbf16_to_floathbf16( \
fn, fn, ctx, in, out); \
}

Comment on lines +93 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not define this macro to use the full namespace (prefixed with :: so it works from anywhere) so that backends/cadence can use it too?

} // namespace internal
} // namespace native
} // namespace executor
Expand Down
Loading
Loading