Skip to content

Commit bc5ee30

Browse files
committed
Add proper CMake build for extension_parallel
Previously it was copied in several places per executorch_srcs.cmake. Needed for #8932 Test Plan: Compare cmake-out/executorch_srcs.cmake before/after for my usual testing cmake config with "all the CPU stuff" on; found that thread_parallel.cpp is now duplicated only in one place instead of multiple (it's in llama_runner, which needs a general fixup because it's duplicating several extensions). ghstack-source-id: d09bf5e6c6561574999d81b13b3fa3d363639596 ghstack-comment-id: 2698715235 Pull Request resolved: #8938
1 parent 5dd96c3 commit bc5ee30

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ endif()
749749

750750
if(EXECUTORCH_BUILD_PTHREADPOOL
751751
AND EXECUTORCH_BUILD_CPUINFO
752-
AND CMAKE_CXX_STANDARD GREATER_EQUAL 14
753752
)
754753
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/threadpool)
754+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/parallel)
755755
endif()
756756

757757
if(EXECUTORCH_BUILD_PYBIND)

build/cmake_deps.toml

+19
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ excludes = [
7373
deps = [
7474
"executorch",
7575
"executorch_core",
76+
"extension_parallel",
7677
"extension_threadpool",
7778
"portable_kernels",
7879
]
@@ -115,6 +116,7 @@ excludes = [
115116
deps = [
116117
"executorch_core",
117118
"executorch",
119+
"extension_parallel",
118120
]
119121

120122
[targets.optimized_native_cpu_ops]
@@ -129,6 +131,8 @@ excludes = [
129131
deps = [
130132
"executorch_core",
131133
"executorch",
134+
"extension_parallel",
135+
"extension_threadpool",
132136
"portable_kernels",
133137
]
134138
# ---------------------------------- core end ----------------------------------
@@ -208,6 +212,19 @@ deps = [
208212
"extension_runner_util",
209213
]
210214

215+
[targets.extension_parallel]
216+
buck_targets = [
217+
"//extension/parallel:thread_parallel",
218+
]
219+
filters = [
220+
".cpp$",
221+
]
222+
deps = [
223+
"executorch",
224+
"executorch_core",
225+
"extension_threadpool",
226+
]
227+
211228
[targets.extension_tensor]
212229
buck_targets = [
213230
"//extension/tensor:tensor",
@@ -395,6 +412,7 @@ deps = [
395412
"executorch",
396413
"executorch_core",
397414
"optimized_kernels",
415+
"extension_parallel",
398416
"extension_threadpool",
399417
"xnnpack_backend",
400418
]
@@ -431,6 +449,7 @@ deps = [
431449
"executorch_core",
432450
"extension_data_loader",
433451
"extension_module",
452+
"extension_parallel",
434453
"portable_kernels",
435454
"quantized_kernels",
436455
"xnnpack_backend",

build/executorch-config.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ set(lib_list
6767
portable_ops_lib
6868
extension_module
6969
extension_module_static
70+
extension_parallel
7071
extension_runner_util
7172
extension_tensor
7273
extension_threadpool
@@ -114,3 +115,16 @@ foreach(lib ${lib_list})
114115
list(APPEND EXECUTORCH_LIBRARIES ${lib})
115116
endif()
116117
endforeach()
118+
119+
# TODO: investigate use of install(EXPORT) to cleanly handle
120+
# target_compile_options/target_compile_definitions for everything.
121+
if(TARGET extension_parallel)
122+
set_target_properties(
123+
extension_parallel PROPERTIES INTERFACE_LINK_LIBRARIES extension_threadpool
124+
)
125+
endif()
126+
if(TARGET cpublas)
127+
set_target_properties(
128+
cpublas PROPERTIES INTERFACE_LINK_LIBRARIES extension_parallel
129+
)
130+
endif()

extension/parallel/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
# Please keep this file formatted by running:
8+
# ~~~
9+
# cmake-format -i CMakeLists.txt
10+
# ~~~
11+
12+
if(NOT (EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_CPUINFO))
13+
message(FATAL_ERROR "extension/parallel requires extension/threadpool")
14+
endif()
15+
16+
add_library(extension_parallel thread_parallel.cpp)
17+
18+
target_link_libraries(extension_parallel PUBLIC executorch_core extension_threadpool)
19+
target_compile_options(extension_parallel PUBLIC ${_common_compile_options})
20+
21+
install(
22+
TARGETS extension_parallel
23+
DESTINATION lib
24+
INCLUDES
25+
DESTINATION ${_common_include_directories})

kernels/optimized/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endif()
4343
list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/")
4444
add_library(cpublas STATIC ${_optimized_cpublas__srcs})
4545
target_link_libraries(
46-
cpublas PRIVATE executorch_core eigen_blas extension_threadpool
46+
cpublas PUBLIC executorch_core eigen_blas extension_parallel extension_threadpool
4747
)
4848
target_compile_options(cpublas PUBLIC ${_common_compile_options})
4949

@@ -63,7 +63,7 @@ list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
6363
add_library(optimized_kernels ${_optimized_kernels__srcs})
6464
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft")
6565
target_link_libraries(
66-
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool
66+
optimized_kernels PUBLIC executorch_core cpublas extension_threadpool
6767
)
6868
target_compile_options(optimized_kernels PUBLIC ${_common_compile_options})
6969
# Build a library for _optimized_kernels_srcs

0 commit comments

Comments
 (0)