Skip to content

Commit ea082fa

Browse files
committed
Move tensor_shape_to_c_string back to runtime/core
I moved it to kernels/portable due to build issues, but it doesn't make sense that kernels/portable code can't use this if it's in runtime/core, so let's dig in. ghstack-source-id: c98fe3d ghstack-comment-id: 2641470188 Pull Request resolved: #8296
1 parent 4d9cecc commit ea082fa

File tree

14 files changed

+48
-77
lines changed

14 files changed

+48
-77
lines changed

kernels/portable/cpu/util/broadcast_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88

99
#include <executorch/kernels/portable/cpu/util/repeat_util.h>
10-
#include <executorch/kernels/portable/cpu/util/tensor_util.h>
1110
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1211
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
12+
#include <executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h>
1313
#include <string.h>
1414

1515
namespace torch {

kernels/portable/cpu/util/targets.bzl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def define_common_targets():
7373
compiler_flags = ["-Wno-missing-prototypes"],
7474
deps = [
7575
":repeat_util",
76-
":tensor_util",
7776
"//executorch/runtime/kernel:kernel_includes",
77+
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
7878
"//executorch/runtime/core/exec_aten/util:tensor_util",
7979
],
8080
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/optimized/cpu/...", "@EXECUTORCH_CLIENTS"],
@@ -268,16 +268,6 @@ def define_common_targets():
268268
visibility = ["//executorch/kernels/portable/cpu/..."],
269269
)
270270

271-
runtime.cxx_library(
272-
name = "tensor_util",
273-
srcs = ["tensor_util.cpp"],
274-
exported_headers = ["tensor_util.h"],
275-
deps = [
276-
"//executorch/runtime/kernel:kernel_includes",
277-
],
278-
visibility = ["//executorch/kernels/portable/cpu/..."],
279-
)
280-
281271
runtime.cxx_library(
282272
name = "upsample_util",
283273
srcs = ["upsample_util.cpp"],

kernels/portable/cpu/util/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
1919

2020
include(${EXECUTORCH_ROOT}/build/Test.cmake)
2121

22-
set(_test_srcs broadcast_test.cpp reduce_test.cpp tensor_util_test.cpp)
22+
set(_test_srcs broadcast_test.cpp reduce_test.cpp)
2323

2424
et_cxx_test(
2525
kernels_portable_cpu_util_test SOURCES ${_test_srcs} EXTRA_LIBS

kernels/portable/cpu/util/test/targets.bzl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,3 @@ def define_common_targets():
2121
"//executorch/kernels/portable/cpu/util:reduce_util",
2222
],
2323
)
24-
25-
runtime.cxx_test(
26-
name = "tensor_util_test",
27-
srcs = ["tensor_util_test.cpp"],
28-
deps = [
29-
"//executorch/kernels/portable/cpu/util:tensor_util",
30-
],
31-
)

runtime/core/exec_aten/util/dim_order_util.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -260,35 +260,6 @@ ET_NODISCARD inline Error stride_to_dim_order(
260260
return Error::Ok;
261261
}
262262

263-
/**
264-
* Print a string representation of an ArrayRef of tensor sizes into a
265-
* user-provided string buffer. If the user buffer is too small, the string
266-
* will be truncated. The output is of the format (1,2,3,4).
267-
*
268-
* Note that we cannot use ArrayRef here due to a circular dependency (see
269-
* above comments).
270-
*/
271-
template <class SizesType>
272-
inline void sizes_to_string(
273-
char* output,
274-
size_t output_size,
275-
SizesType* sizes,
276-
size_t rank) {
277-
auto remaining_size = output_size;
278-
for (auto i = 0; remaining_size > 0 && i < rank; i++) {
279-
snprintf(
280-
output,
281-
remaining_size,
282-
"%s%zd",
283-
i == 0 ? "(" : ",",
284-
static_cast<size_t>(sizes[i]));
285-
auto len = strlen(output);
286-
output += len;
287-
remaining_size -= len;
288-
}
289-
snprintf(output, remaining_size, ")");
290-
}
291-
292263
} // namespace runtime
293264
} // namespace executorch
294265

runtime/core/exec_aten/util/targets.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ def define_common_targets():
7272
# specify library directory path.
7373
force_static = True,
7474
)
75+
76+
runtime.cxx_library(
77+
name = "tensor_shape_to_c_string" + aten_suffix,
78+
srcs = ["tensor_shape_to_c_string.cpp"],
79+
exported_deps = [
80+
"//executorch/runtime/core/exec_aten:lib" + aten_suffix,
81+
],
82+
exported_headers = ["tensor_shape_to_c_string.h"],
83+
visibility = [
84+
"//executorch/...",
85+
"@EXECUTORCH_CLIENTS",
86+
],
87+
)

kernels/portable/cpu/util/tensor_util.cpp renamed to runtime/core/exec_aten/util/tensor_shape_to_c_string.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "tensor_util.h"
2-
31
/*
42
* Copyright (c) Meta Platforms, Inc. and affiliates.
53
* All rights reserved.
@@ -8,7 +6,7 @@
86
* LICENSE file in the root directory of this source tree.
97
*/
108

11-
#include <executorch/runtime/core/exec_aten/util/tensor_util.h>
9+
#include <executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h>
1210

1311
#include <executorch/runtime/platform/assert.h>
1412

runtime/core/exec_aten/util/test/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
1919

2020
include(${EXECUTORCH_ROOT}/build/Test.cmake)
2121

22-
set(_test_srcs scalar_type_util_test.cpp
23-
operator_impl_example_test.cpp dim_order_util_test.cpp
22+
set(_test_srcs
23+
dim_order_util_test.cpp operator_impl_example_test.cpp
24+
scalar_type_util_test.cpp tensor_shape_to_c_string_test.cpp
25+
tensor_util_test.cpp
2426
)
2527

2628
et_cxx_test(runtime_core_exec_aten_util_test SOURCES ${_test_srcs} EXTRA_LIBS)

runtime/core/exec_aten/util/test/targets.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ def define_common_targets():
4646
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
4747
],
4848
)
49+
50+
runtime.cxx_test(
51+
name = "tensor_shape_to_c_string_test",
52+
srcs = ["tensor_shape_to_c_string_test.cpp"],
53+
deps = [
54+
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
55+
],
56+
)

0 commit comments

Comments
 (0)