Skip to content

Commit adde519

Browse files
authored
Make a separate target for kernel utils (#10788)
Currently it's built into portable kernels only. Other kernels used it, and the runner must include portable kernel to avoid undefined symbols. We need to split these utils out. A fix for #10677 without BC breaking.
1 parent e113c00 commit adde519

File tree

8 files changed

+64
-6
lines changed

8 files changed

+64
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
547547
find_package_torch_headers()
548548
endif()
549549

550+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable/cpu/util)
551+
550552
if(BUILD_EXECUTORCH_PORTABLE_OPS)
551553
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
552554
endif()

extension/llm/custom_ops/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
119119
else()
120120
# If no portable_lib, custom_ops_aot_lib still gives the ability to use the
121121
# ops in PyTorch
122-
target_link_libraries(custom_ops_aot_lib PUBLIC executorch_core)
122+
target_link_libraries(custom_ops_aot_lib PUBLIC executorch_core kernels_util_all_deps)
123123
endif()
124124

125125
target_link_libraries(

extension/training/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ target_include_directories(
2525

2626
target_include_directories(extension_training PUBLIC ${EXECUTORCH_ROOT}/..)
2727
target_compile_options(extension_training PUBLIC ${_common_compile_options})
28-
target_link_libraries(extension_training executorch_core
29-
extension_data_loader extension_module_static extension_tensor extension_flat_tensor)
28+
target_link_libraries(extension_training executorch_core kernels_util_all_deps
29+
extension_data_loader extension_module_static extension_tensor extension_flat_tensor )
3030

3131

3232
list(TRANSFORM _train_xor__srcs PREPEND "${EXECUTORCH_ROOT}/")

kernels/optimized/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ add_library(optimized_kernels ${_optimized_kernels__srcs})
6464
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft")
6565
target_compile_definitions(optimized_kernels PRIVATE ET_USE_PYTORCH_HEADERS)
6666
target_link_libraries(
67-
optimized_kernels PUBLIC executorch_core cpublas extension_threadpool
67+
optimized_kernels PUBLIC executorch_core cpublas extension_threadpool kernels_util_all_deps
6868
)
6969
target_compile_options(optimized_kernels PUBLIC ${_common_compile_options})
7070
# Build a library for _optimized_kernels_srcs

kernels/portable/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ message("Generated files ${gen_command_sources}")
5252
# Focused on portability and understandability rather than speed.
5353
#
5454
add_library(portable_kernels ${_portable_kernels__srcs})
55-
target_link_libraries(portable_kernels PRIVATE executorch_core)
55+
target_link_libraries(portable_kernels PRIVATE executorch_core kernels_util_all_deps)
5656
target_compile_options(portable_kernels PUBLIC ${_common_compile_options})
5757

5858
# Build a library for _portable_kernels__srcs
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Kernel library for portable kernels. Please this file formatted by running:
8+
# ~~~
9+
# cmake-format -i CMakeLists.txt
10+
# ~~~
11+
12+
cmake_minimum_required(VERSION 3.19)
13+
14+
if(NOT CMAKE_CXX_STANDARD)
15+
set(CMAKE_CXX_STANDARD 17)
16+
endif()
17+
18+
if(NOT EXECUTORCH_ROOT)
19+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
20+
endif()
21+
22+
list(TRANSFORM _kernels_util_all_deps__srcs PREPEND "${EXECUTORCH_ROOT}/")
23+
24+
set(_common_compile_options -Wno-deprecated-declarations)
25+
26+
add_library(kernels_util_all_deps ${_kernels_util_all_deps__srcs})
27+
target_link_libraries(kernels_util_all_deps PRIVATE executorch_core)
28+
target_include_directories(kernels_util_all_deps PUBLIC ${_common_include_directories})
29+
target_compile_definitions(kernels_util_all_deps PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
30+
target_compile_options(kernels_util_all_deps PUBLIC ${_common_compile_options})

kernels/quantized/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if(NOT CMAKE_GENERATOR STREQUAL "Xcode"
142142
endif()
143143

144144
add_library(quantized_kernels ${_quantized_kernels__srcs})
145-
target_link_libraries(quantized_kernels PRIVATE executorch_core)
145+
target_link_libraries(quantized_kernels PRIVATE executorch_core kernels_util_all_deps)
146146
target_compile_options(quantized_kernels PUBLIC ${_common_compile_options})
147147
# Build a library for _quantized_kernels_srcs
148148
#

tools/cmake/cmake_deps.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ excludes = [
5656
deps = [
5757
"executorch",
5858
"executorch_core",
59+
"extension_threadpool",
60+
"kernels_util_all_deps",
61+
]
62+
63+
[targets.kernels_util_all_deps]
64+
buck_targets = [
65+
"//kernels/portable/cpu/util:all_deps",
66+
]
67+
filters = [
68+
".cpp$",
69+
]
70+
deps = [
71+
"executorch_core",
72+
"extension_threadpool",
5973
]
6074

6175
# HACK: prevent reduce_util from also showing up in custom_ops. The
@@ -89,6 +103,7 @@ deps = [
89103
"executorch",
90104
"executorch_core",
91105
"extension_threadpool",
106+
"kernels_util_all_deps",
92107
"optimized_cpublas",
93108
"portable_kernels",
94109
]
@@ -108,6 +123,8 @@ excludes = [
108123
deps = [
109124
"executorch",
110125
"executorch_core",
126+
"extension_threadpool",
127+
"kernels_util_all_deps",
111128
"portable_kernels",
112129
]
113130

@@ -147,6 +164,7 @@ deps = [
147164
"executorch_core",
148165
"executorch",
149166
"extension_threadpool",
167+
"kernels_util_all_deps",
150168
"optimized_cpublas",
151169
"portable_kernels",
152170
]
@@ -288,6 +306,8 @@ excludes = [
288306
deps = [
289307
"executorch",
290308
"executorch_core",
309+
"extension_threadpool",
310+
"kernels_util_all_deps",
291311
"portable_kernels",
292312
]
293313
# ---------------------------------- extension end ----------------------------------
@@ -306,6 +326,8 @@ excludes = [
306326
deps = [
307327
"executorch",
308328
"executorch_core",
329+
"extension_threadpool",
330+
"kernels_util_all_deps",
309331
"portable_kernels",
310332
"quantized_kernels",
311333
"etdump_flatcc",
@@ -340,6 +362,8 @@ excludes = [
340362
deps = [
341363
"executorch",
342364
"executorch_core",
365+
"extension_threadpool",
366+
"kernels_util_all_deps",
343367
"portable_kernels",
344368
]
345369

@@ -380,6 +404,7 @@ deps = [
380404
"executorch",
381405
"executorch_core",
382406
"extension_threadpool",
407+
"kernels_util_all_deps",
383408
"xnnpack_backend",
384409
"portable_kernels",
385410
"etdump_flatcc",
@@ -455,6 +480,7 @@ deps = [
455480
"extension_module",
456481
"extension_tensor",
457482
"extension_threadpool",
483+
"kernels_util_all_deps",
458484
"optimized_cpublas",
459485
"portable_kernels",
460486
"quantized_kernels",

0 commit comments

Comments
 (0)