From 3779345269d29e196556307e17a7af9533a6b39a Mon Sep 17 00:00:00 2001 From: Manuel Candales Date: Mon, 25 Aug 2025 12:24:51 -0700 Subject: [PATCH] [ET][Portable] Expose portable ops as utils (div/mul/sub/le/lt/ge/gt/eq/ne) Differential Revision: [D80963876](https://our.internmc.facebook.com/intern/diff/D80963876/) [ghstack-poisoned] --- kernels/portable/cpu/op_div.cpp | 74 +++++++++++++++++++ kernels/portable/cpu/op_div.h | 50 +++++++++++++ kernels/portable/cpu/op_eq.cpp | 38 ++++++++++ kernels/portable/cpu/op_eq.h | 36 +++++++++ kernels/portable/cpu/op_ge.cpp | 38 ++++++++++ kernels/portable/cpu/op_ge.h | 36 +++++++++ kernels/portable/cpu/op_gt.cpp | 38 ++++++++++ kernels/portable/cpu/op_gt.h | 36 +++++++++ kernels/portable/cpu/op_le.cpp | 38 ++++++++++ kernels/portable/cpu/op_le.h | 36 +++++++++ kernels/portable/cpu/op_lt.cpp | 38 ++++++++++ kernels/portable/cpu/op_lt.h | 36 +++++++++ kernels/portable/cpu/op_mul.cpp | 38 ++++++++++ kernels/portable/cpu/op_mul.h | 36 +++++++++ kernels/portable/cpu/op_ne.cpp | 38 ++++++++++ kernels/portable/cpu/op_ne.h | 36 +++++++++ kernels/portable/cpu/op_sub.cpp | 42 +++++++++++ kernels/portable/cpu/op_sub.h | 38 ++++++++++ .../kernels/portable/op_registration_util.bzl | 9 +++ 19 files changed, 731 insertions(+) create mode 100644 kernels/portable/cpu/op_div.h create mode 100644 kernels/portable/cpu/op_eq.h create mode 100644 kernels/portable/cpu/op_ge.h create mode 100644 kernels/portable/cpu/op_gt.h create mode 100644 kernels/portable/cpu/op_le.h create mode 100644 kernels/portable/cpu/op_lt.h create mode 100644 kernels/portable/cpu/op_mul.h create mode 100644 kernels/portable/cpu/op_ne.h create mode 100644 kernels/portable/cpu/op_sub.h diff --git a/kernels/portable/cpu/op_div.cpp b/kernels/portable/cpu/op_div.cpp index 51a65747b33..799df58b655 100644 --- a/kernels/portable/cpu/op_div.cpp +++ b/kernels/portable/cpu/op_div.cpp @@ -16,6 +16,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { namespace { @@ -279,6 +280,79 @@ Tensor& div_scalar_mode_out( return out; } +} // namespace impl + +Tensor& div_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::div_out(ctx, a, b, out); +} + +Tensor& div_out_mode( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + std::optional mode, + Tensor& out) { + return impl::div_out_mode(ctx, a, b, mode, out); +} + +Tensor& div_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::div_scalar_out(ctx, a, b, out); +} + +Tensor& div_scalar_mode_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + std::optional mode, + Tensor& out) { + return impl::div_scalar_mode_out(ctx, a, b, mode, out); +} + +namespace utils { + +Tensor& div_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::div_out(ctx, a, b, out); +} + +Tensor& div_out_mode( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + std::optional mode, + Tensor& out) { + return impl::div_out_mode(ctx, a, b, mode, out); +} + +Tensor& div_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::div_scalar_out(ctx, a, b, out); +} + +Tensor& div_scalar_mode_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + std::optional mode, + Tensor& out) { + return impl::div_scalar_mode_out(ctx, a, b, mode, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_div.h b/kernels/portable/cpu/op_div.h new file mode 100644 index 00000000000..e024f14dea5 --- /dev/null +++ b/kernels/portable/cpu/op_div.h @@ -0,0 +1,50 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& div_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& div_out_mode( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + std::optional mode, + Tensor& out); + +Tensor& div_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +Tensor& div_scalar_mode_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + std::optional mode, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_eq.cpp b/kernels/portable/cpu/op_eq.cpp index 9e21b82c43c..2758e27a72c 100644 --- a/kernels/portable/cpu/op_eq.cpp +++ b/kernels/portable/cpu/op_eq.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& eq_tensor_out( KernelRuntimeContext& ctx, @@ -36,6 +37,43 @@ Tensor& eq_scalar_out( ctx, a, b, out); } +} // namespace impl + +Tensor& eq_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::eq_tensor_out(ctx, a, b, out); +} + +Tensor& eq_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::eq_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& eq_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::eq_tensor_out(ctx, a, b, out); +} + +Tensor& eq_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::eq_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_eq.h b/kernels/portable/cpu/op_eq.h new file mode 100644 index 00000000000..77aa7c78c55 --- /dev/null +++ b/kernels/portable/cpu/op_eq.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& eq_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& eq_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_ge.cpp b/kernels/portable/cpu/op_ge.cpp index d5e7576b7ae..4e001089862 100644 --- a/kernels/portable/cpu/op_ge.cpp +++ b/kernels/portable/cpu/op_ge.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& ge_tensor_out( KernelRuntimeContext& ctx, @@ -36,6 +37,43 @@ Tensor& ge_scalar_out( ctx, a, b, out); } +} // namespace impl + +Tensor& ge_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::ge_tensor_out(ctx, a, b, out); +} + +Tensor& ge_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::ge_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& ge_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::ge_tensor_out(ctx, a, b, out); +} + +Tensor& ge_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::ge_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_ge.h b/kernels/portable/cpu/op_ge.h new file mode 100644 index 00000000000..c151b88458e --- /dev/null +++ b/kernels/portable/cpu/op_ge.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& ge_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& ge_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_gt.cpp b/kernels/portable/cpu/op_gt.cpp index cd65a3b68d9..b86e15f3c10 100644 --- a/kernels/portable/cpu/op_gt.cpp +++ b/kernels/portable/cpu/op_gt.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& gt_tensor_out( KernelRuntimeContext& ctx, @@ -34,6 +35,43 @@ Tensor& gt_scalar_out( return internal::comparison_scalar_out(ctx, a, b, out); } +} // namespace impl + +Tensor& gt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::gt_tensor_out(ctx, a, b, out); +} + +Tensor& gt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::gt_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& gt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::gt_tensor_out(ctx, a, b, out); +} + +Tensor& gt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::gt_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_gt.h b/kernels/portable/cpu/op_gt.h new file mode 100644 index 00000000000..ca52710fd8d --- /dev/null +++ b/kernels/portable/cpu/op_gt.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& gt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& gt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_le.cpp b/kernels/portable/cpu/op_le.cpp index 909de1bfad2..c20c6046cb9 100644 --- a/kernels/portable/cpu/op_le.cpp +++ b/kernels/portable/cpu/op_le.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& le_tensor_out( KernelRuntimeContext& ctx, @@ -36,6 +37,43 @@ Tensor& le_scalar_out( ctx, a, b, out); } +} // namespace impl + +Tensor& le_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::le_tensor_out(ctx, a, b, out); +} + +Tensor& le_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::le_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& le_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::le_tensor_out(ctx, a, b, out); +} + +Tensor& le_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::le_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_le.h b/kernels/portable/cpu/op_le.h new file mode 100644 index 00000000000..fc0a7bd579c --- /dev/null +++ b/kernels/portable/cpu/op_le.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& le_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& le_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_lt.cpp b/kernels/portable/cpu/op_lt.cpp index 5af89920536..be38efcb76d 100644 --- a/kernels/portable/cpu/op_lt.cpp +++ b/kernels/portable/cpu/op_lt.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& lt_tensor_out( KernelRuntimeContext& ctx, @@ -34,6 +35,43 @@ Tensor& lt_scalar_out( return internal::comparison_scalar_out(ctx, a, b, out); } +} // namespace impl + +Tensor& lt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::lt_tensor_out(ctx, a, b, out); +} + +Tensor& lt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::lt_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& lt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::lt_tensor_out(ctx, a, b, out); +} + +Tensor& lt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::lt_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_lt.h b/kernels/portable/cpu/op_lt.h new file mode 100644 index 00000000000..b438911e832 --- /dev/null +++ b/kernels/portable/cpu/op_lt.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& lt_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& lt_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_mul.cpp b/kernels/portable/cpu/op_mul.cpp index 6d4f30106ca..ab5d23663d2 100644 --- a/kernels/portable/cpu/op_mul.cpp +++ b/kernels/portable/cpu/op_mul.cpp @@ -14,6 +14,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& mul_out( KernelRuntimeContext& ctx, @@ -126,6 +127,43 @@ Tensor& mul_scalar_out( return out; } +} // namespace impl + +Tensor& mul_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::mul_out(ctx, a, b, out); +} + +Tensor& mul_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::mul_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& mul_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::mul_out(ctx, a, b, out); +} + +Tensor& mul_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::mul_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_mul.h b/kernels/portable/cpu/op_mul.h new file mode 100644 index 00000000000..9efdfa05ab2 --- /dev/null +++ b/kernels/portable/cpu/op_mul.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& mul_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& mul_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_ne.cpp b/kernels/portable/cpu/op_ne.cpp index a4b292359df..514273dd434 100644 --- a/kernels/portable/cpu/op_ne.cpp +++ b/kernels/portable/cpu/op_ne.cpp @@ -13,6 +13,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& ne_tensor_out( KernelRuntimeContext& ctx, @@ -36,6 +37,43 @@ Tensor& ne_scalar_out( ctx, a, b, out); } +} // namespace impl + +Tensor& ne_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::ne_tensor_out(ctx, a, b, out); +} + +Tensor& ne_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::ne_scalar_out(ctx, a, b, out); +} + +namespace utils { + +Tensor& ne_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + return impl::ne_tensor_out(ctx, a, b, out); +} + +Tensor& ne_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + return impl::ne_scalar_out(ctx, a, b, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_ne.h b/kernels/portable/cpu/op_ne.h new file mode 100644 index 00000000000..38cad69c9f8 --- /dev/null +++ b/kernels/portable/cpu/op_ne.h @@ -0,0 +1,36 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& ne_tensor_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out); + +Tensor& ne_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/kernels/portable/cpu/op_sub.cpp b/kernels/portable/cpu/op_sub.cpp index b914c411303..bfa2fd7c977 100644 --- a/kernels/portable/cpu/op_sub.cpp +++ b/kernels/portable/cpu/op_sub.cpp @@ -14,6 +14,7 @@ namespace torch { namespace executor { namespace native { +namespace impl { Tensor& sub_out( KernelRuntimeContext& ctx, @@ -129,6 +130,47 @@ Tensor& sub_scalar_out( return out; } +} // namespace impl + +Tensor& sub_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + const Scalar& alpha, + Tensor& out) { + return impl::sub_out(ctx, a, b, alpha, out); +} + +Tensor& sub_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + const Scalar& alpha, + Tensor& out) { + return impl::sub_scalar_out(ctx, a, b, alpha, out); +} + +namespace utils { + +Tensor& sub_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + const Scalar& alpha, + Tensor& out) { + return impl::sub_out(ctx, a, b, alpha, out); +} + +Tensor& sub_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + const Scalar& alpha, + Tensor& out) { + return impl::sub_scalar_out(ctx, a, b, alpha, out); +} + +} // namespace utils } // namespace native } // namespace executor } // namespace torch diff --git a/kernels/portable/cpu/op_sub.h b/kernels/portable/cpu/op_sub.h new file mode 100644 index 00000000000..ba2e4e4c985 --- /dev/null +++ b/kernels/portable/cpu/op_sub.h @@ -0,0 +1,38 @@ +/* + * 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 + +#pragma once + +namespace torch { +namespace executor { +namespace native { +namespace utils { + +using Scalar = executorch::aten::Scalar; +using Tensor = executorch::aten::Tensor; + +Tensor& sub_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + const Scalar& alpha, + Tensor& out); + +Tensor& sub_scalar_out( + KernelRuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + const Scalar& alpha, + Tensor& out); + +} // namespace utils +} // namespace native +} // namespace executor +} // namespace torch diff --git a/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl b/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl index a0394113126..7a2cf6dd7b3 100644 --- a/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl +++ b/shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl @@ -514,6 +514,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:math_util", ":scalar_utils", ], + exposed_as_util = True, ), op_target( name = "op_elu", @@ -537,6 +538,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_empty", @@ -639,6 +641,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_gelu", @@ -666,6 +669,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_hardtanh", @@ -716,6 +720,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_leaky_relu", @@ -815,6 +820,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_masked_fill", @@ -904,6 +910,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:elementwise_util", ":scalar_utils", ], + exposed_as_util = True, ), op_target( name = "op_narrow_copy", @@ -947,6 +954,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_neg", @@ -1237,6 +1245,7 @@ ATEN_OPS = ( "//executorch/kernels/portable/cpu/util:dtype_util", "//executorch/kernels/portable/cpu/util:elementwise_util", ], + exposed_as_util = True, ), op_target( name = "op_sum",