Skip to content

Commit f55681f

Browse files
authored
Revert "Optimize scale-factor-2 nearest-neighbor upsampling portable op" (pytorch#23260)
Reverts pytorch#22999 Many buck failures on internal CI: D122355607 cc @JakeStevens
1 parent bfdfe10 commit f55681f

13 files changed

Lines changed: 1 addition & 375 deletions

‎kernels/optimized/CMakeLists.txt‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3-
# Copyright 2026 Arm Limited and/or its affiliates.
43
#
54
# This source code is licensed under the BSD-style license found in the
65
# LICENSE file in the root directory of this source tree.
@@ -108,25 +107,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64" OR ANDROID_ABI STREQUAL
108107
)
109108
endif()
110109

111-
# The nearest-2x fast path uses only baseline AArch64 Advanced SIMD. Keep
112-
# arm_neon.h and its implementation out of all other architecture builds.
113-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64" OR ANDROID_ABI STREQUAL
114-
"arm64-v8a"
115-
)
116-
add_library(
117-
upsample_nearest2d_neon_impl OBJECT
118-
${EXECUTORCH_ROOT}/kernels/optimized/cpu/op_upsample_nearest2d_neon.cpp
119-
)
120-
target_compile_options(
121-
upsample_nearest2d_neon_impl PRIVATE ${_common_compile_options}
122-
)
123-
target_link_libraries(upsample_nearest2d_neon_impl PRIVATE executorch_core)
124-
target_link_libraries(
125-
optimized_kernels
126-
PRIVATE $<BUILD_LOCAL_INTERFACE:upsample_nearest2d_neon_impl>
127-
)
128-
endif()
129-
130110
# Build a library for _optimized_kernels_srcs
131111
#
132112
# optimized_ops_lib: Register optimized ops kernels into Executorch runtime

‎kernels/optimized/cpu/op_upsample_nearest2d.cpp‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎kernels/optimized/cpu/op_upsample_nearest2d_neon.cpp‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

‎kernels/optimized/cpu/op_upsample_nearest2d_neon.h‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎kernels/optimized/cpu/targets.bzl‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,6 @@ def define_common_targets():
109109
],
110110
)
111111

112-
runtime.cxx_library(
113-
name = "upsample_nearest2d_neon_impl",
114-
srcs = select({
115-
"DEFAULT": [],
116-
"ovr_config//cpu:arm64": ["op_upsample_nearest2d_neon.cpp"],
117-
}),
118-
exported_headers = ["op_upsample_nearest2d_neon.h"],
119-
visibility = ["PUBLIC"],
120-
exported_deps = [
121-
"//executorch/runtime/kernel:kernel_includes",
122-
],
123-
)
124-
125112
# Used for dtype selective build. Collect source and header files.
126113
runtime.filegroup(
127114
name = "optimized_source_files",

‎kernels/optimized/optimized.yaml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# Copyright 2026 Arm Limited and/or its affiliates.
32
#
43
# This yaml file contains operators that have optimized kernels available.
54

@@ -122,8 +121,3 @@
122121
kernels:
123122
- arg_meta: null
124123
kernel_name: torch::executor::opt_where_out
125-
126-
- op: upsample_nearest2d.vec_out
127-
kernels:
128-
- arg_meta: null
129-
kernel_name: torch::executor::opt_upsample_nearest2d_vec_out

‎kernels/portable/cpu/op_upsample_nearest2d.cpp‎

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,25 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
* All rights reserved.
4-
* Copyright 2026 Arm Limited and/or its affiliates.
54
*
65
* This source code is licensed under the BSD-style license found in the
76
* LICENSE file in the root directory of this source tree.
87
*/
98

109
#include <executorch/kernels/portable/cpu/util/upsample_util.h>
1110
#include <executorch/runtime/kernel/kernel_includes.h>
12-
#include <executorch/runtime/kernel/thread_parallel_interface.h>
13-
14-
#include <cstring>
1511

1612
namespace torch {
1713
namespace executor {
1814
namespace native {
1915

2016
namespace {
21-
22-
template <typename CTYPE>
23-
bool upsample_nearest2d_2x_nchw_fast_path(
24-
const Tensor& in,
25-
const float scale_h,
26-
const float scale_w,
27-
Tensor& out) {
28-
if (scale_h != 0.5f || scale_w != 0.5f || out.size(2) != in.size(2) * 2 ||
29-
out.size(3) != in.size(3) * 2) {
30-
return false;
31-
}
32-
33-
const int64_t in_h = in.size(2);
34-
const int64_t in_w = in.size(3);
35-
const int64_t out_h = out.size(2);
36-
const int64_t out_w = out.size(3);
37-
38-
const bool in_contiguous_nchw = in.strides()[3] == 1 &&
39-
in.strides()[2] == in_w && in.strides()[1] == in_h * in_w &&
40-
in.strides()[0] == in.size(1) * in_h * in_w;
41-
const bool out_contiguous_nchw = out.strides()[3] == 1 &&
42-
out.strides()[2] == out_w && out.strides()[1] == out_h * out_w &&
43-
out.strides()[0] == out.size(1) * out_h * out_w;
44-
if (!in_contiguous_nchw || !out_contiguous_nchw) {
45-
return false;
46-
}
47-
48-
const auto in_data = in.const_data_ptr<CTYPE>();
49-
auto out_data = out.mutable_data_ptr<CTYPE>();
50-
const int64_t planes = in.size(0) * in.size(1);
51-
const int64_t in_plane_size = in_h * in_w;
52-
const int64_t out_plane_size = out_h * out_w;
53-
int64_t grain_size =
54-
::executorch::extension::internal::GRAIN_SIZE / out_plane_size;
55-
if (grain_size < 1) {
56-
grain_size = 1;
57-
}
58-
59-
const bool success = ::executorch::extension::parallel_for(
60-
0, planes, grain_size, [&](const auto begin, const auto end) {
61-
for (const auto plane : c10::irange(begin, end)) {
62-
const CTYPE* in_plane = in_data + plane * in_plane_size;
63-
CTYPE* out_plane = out_data + plane * out_plane_size;
64-
65-
for (int64_t h = 0; h < in_h; ++h) {
66-
const CTYPE* in_row = in_plane + h * in_w;
67-
CTYPE* out_row0 = out_plane + (2 * h) * out_w;
68-
CTYPE* out_row1 = out_row0 + out_w;
69-
70-
for (int64_t w = 0; w < in_w; ++w) {
71-
const CTYPE value = in_row[w];
72-
out_row0[2 * w] = value;
73-
out_row0[2 * w + 1] = value;
74-
}
75-
std::memcpy(out_row1, out_row0, out_w * sizeof(CTYPE));
76-
}
77-
}
78-
});
79-
80-
return success;
81-
}
82-
8317
template <typename CTYPE>
8418
void upsample_nearest2d_kernel_impl_nchw(
8519
const Tensor& in,
8620
const float scale_h,
8721
const float scale_w,
8822
Tensor& out) {
89-
if (upsample_nearest2d_2x_nchw_fast_path<CTYPE>(in, scale_h, scale_w, out)) {
90-
return;
91-
}
92-
9323
const auto in_data = in.const_data_ptr<CTYPE>();
9424
auto out_data = out.mutable_data_ptr<CTYPE>();
9525

‎kernels/test/CMakeLists.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3-
# Copyright 2026 Arm Limited and/or its affiliates.
43
#
54
# This source code is licensed under the BSD-style license found in the
65
# LICENSE file in the root directory of this source tree.
@@ -364,7 +363,6 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
364363
"op_native_layer_norm_test.cpp"
365364
"op_neg_test.cpp"
366365
"op_sub_test.cpp"
367-
"op_upsample_nearest2d_test.cpp"
368366
"op_where_test.cpp"
369367
"UnaryUfuncRealHBBF16ToFloatHBF16Test.cpp"
370368
${CMAKE_CURRENT_BINARY_DIR}/include/optimized/executorch/kernels/test/supported_features.cpp

0 commit comments

Comments
 (0)