From 0196ccb89cab5d22425eba8ecd7a8731a66b065c Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 24 Jun 2025 15:31:43 -0700 Subject: [PATCH] Update [ghstack-poisoned] --- kernels/optimized/cpu/op_sigmoid.cpp | 103 ------------------ kernels/optimized/optimized.yaml | 5 - kernels/test/targets.bzl | 2 +- .../optimized/op_registration_util.bzl | 6 - 4 files changed, 1 insertion(+), 115 deletions(-) delete mode 100644 kernels/optimized/cpu/op_sigmoid.cpp diff --git a/kernels/optimized/cpu/op_sigmoid.cpp b/kernels/optimized/cpu/op_sigmoid.cpp deleted file mode 100644 index 5154ffc6331..00000000000 --- a/kernels/optimized/cpu/op_sigmoid.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 - -#include -#include -#include - -namespace torch { -namespace executor { -namespace native { - -namespace { - -template -constexpr bool is_half_or_bf16_v = std::is_same_v || - std::is_same_v; - -template < - typename CTYPE_IN, - typename CTYPE_OUT, - typename std::enable_if< - std::is_same_v && !is_half_or_bf16_v && - !is_half_or_bf16_v, - int>::type = 0> -void sigmoid_data( - const CTYPE_IN* in_data, - const size_t numel, - CTYPE_OUT* out_data) { - using Vec = at::vec::Vectorized; - at::vec::map( - [](Vec x) { - auto one_plus_exp = x.neg().exp() + Vec(static_cast(1.0)); - return one_plus_exp.reciprocal(); - }, - out_data, - in_data, - numel); -} - -template < - typename CTYPE_IN, - typename CTYPE_OUT, - typename std::enable_if< - !std::is_same_v || is_half_or_bf16_v || - is_half_or_bf16_v, - int>::type = 0> -void sigmoid_data( - const CTYPE_IN* in_data, - const size_t numel, - CTYPE_OUT* out_data) { - for (size_t i = 0; i < numel; i++) { - CTYPE_OUT xi = static_cast(in_data[i]); - out_data[i] = (1.0f / (1.0f + std::exp(-xi))); - } -} - -} // namespace - -using Tensor = executorch::aten::Tensor; - -Tensor& -opt_sigmoid_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { - (void)ctx; - - ET_KERNEL_CHECK( - ctx, in.scalar_type() != ScalarType::Bool, InvalidArgument, out); - ET_KERNEL_CHECK(ctx, tensor_is_floating_type(out), InvalidArgument, out); - - ET_KERNEL_CHECK( - ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out); - - // Resize for dynamic shape - ET_KERNEL_CHECK_MSG( - ctx, - resize_tensor(out, in.sizes()) == Error::Ok, - InvalidArgument, - out, - "Failed to resize output tensor."); - - ScalarType in_type = in.scalar_type(); - ScalarType out_type = out.scalar_type(); - ET_SWITCH_REALHB_TYPES(in_type, ctx, "sigmoid.out", CTYPE_IN, [&]() { - ET_SWITCH_FLOATH_TYPES(out_type, ctx, "sigmoid.out", CTYPE_OUT, [&]() { - sigmoid_data( - in.const_data_ptr(), - in.numel(), - out.mutable_data_ptr()); - }); - }); - - return out; -} - -} // namespace native -} // namespace executor -} // namespace torch diff --git a/kernels/optimized/optimized.yaml b/kernels/optimized/optimized.yaml index 42a065f63ed..395a3f97f85 100644 --- a/kernels/optimized/optimized.yaml +++ b/kernels/optimized/optimized.yaml @@ -52,11 +52,6 @@ - arg_meta: null kernel_name: torch::executor::opt_exp_out -- op: sigmoid.out - kernels: - - arg_meta: null - kernel_name: torch::executor::opt_sigmoid_out - - op: gelu.out kernels: - arg_meta: null diff --git a/kernels/test/targets.bzl b/kernels/test/targets.bzl index bde3b8632b0..f21a22e6627 100644 --- a/kernels/test/targets.bzl +++ b/kernels/test/targets.bzl @@ -307,7 +307,7 @@ def define_common_targets(): _common_op_test("op_scatter_add_test", ["aten", "portable"]) _common_op_test("op_select_scatter_test", ["aten", "portable"]) _common_op_test("op_select_copy_test", ["aten", "portable"]) - _common_op_test("op_sigmoid_test", ["aten", "portable", "optimized"]) + _common_op_test("op_sigmoid_test", ["aten", "portable"]) _common_op_test("op_sign_test", ["aten", "portable"]) _common_op_test("op_sin_test", ["aten", "portable"]) _common_op_test("op_sinh_test", ["aten", "portable"]) diff --git a/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl b/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl index 4b49e966b9b..4ab13359b27 100644 --- a/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl +++ b/shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl @@ -202,12 +202,6 @@ OPTIMIZED_ATEN_OPS = ( ], deps = [":fft_utils"], ), - op_target( - name = "op_sigmoid", - deps = [ - "//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch", - ], - ), op_target( name = "op_gelu", deps = [