Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper CMake build for extension_parallel #8938

Merged
merged 7 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ endif()

if(EXECUTORCH_BUILD_PTHREADPOOL
AND EXECUTORCH_BUILD_CPUINFO
AND CMAKE_CXX_STANDARD GREATER_EQUAL 14
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/threadpool)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/parallel)
endif()

if(EXECUTORCH_BUILD_PYBIND)
Expand Down
19 changes: 19 additions & 0 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
Expand Down Expand Up @@ -115,6 +116,7 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
]

[targets.optimized_native_cpu_ops]
Expand All @@ -129,6 +131,8 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
# ---------------------------------- core end ----------------------------------
Expand Down Expand Up @@ -208,6 +212,19 @@ deps = [
"extension_runner_util",
]

[targets.extension_parallel]
buck_targets = [
"//extension/parallel:thread_parallel",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"executorch_core",
"extension_threadpool",
]

[targets.extension_tensor]
buck_targets = [
"//extension/tensor:tensor",
Expand Down Expand Up @@ -395,6 +412,7 @@ deps = [
"executorch",
"executorch_core",
"optimized_kernels",
"extension_parallel",
"extension_threadpool",
"xnnpack_backend",
]
Expand Down Expand Up @@ -431,6 +449,7 @@ deps = [
"executorch_core",
"extension_data_loader",
"extension_module",
"extension_parallel",
"portable_kernels",
"quantized_kernels",
"xnnpack_backend",
Expand Down
14 changes: 14 additions & 0 deletions build/executorch-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set(lib_list
portable_ops_lib
extension_module
extension_module_static
extension_parallel
extension_runner_util
extension_tensor
extension_threadpool
Expand Down Expand Up @@ -114,3 +115,16 @@ foreach(lib ${lib_list})
list(APPEND EXECUTORCH_LIBRARIES ${lib})
endif()
endforeach()

# TODO: investigate use of install(EXPORT) to cleanly handle
# target_compile_options/target_compile_definitions for everything.
if(TARGET extension_parallel)
set_target_properties(
extension_parallel PROPERTIES INTERFACE_LINK_LIBRARIES extension_threadpool
)
endif()
if(TARGET cpublas)
set_target_properties(
cpublas PROPERTIES INTERFACE_LINK_LIBRARIES extension_parallel
)
endif()
25 changes: 25 additions & 0 deletions extension/parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

# Please keep this file formatted by running:
# ~~~
# cmake-format -i CMakeLists.txt
# ~~~

if(NOT (EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_CPUINFO))
message(FATAL_ERROR "extension/parallel requires extension/threadpool")
endif()

add_library(extension_parallel thread_parallel.cpp)

target_link_libraries(extension_parallel PUBLIC executorch_core extension_threadpool)
target_compile_options(extension_parallel PUBLIC ${_common_compile_options})

install(
TARGETS extension_parallel
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories})
4 changes: 2 additions & 2 deletions kernels/optimized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ endif()
list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(cpublas STATIC ${_optimized_cpublas__srcs})
target_link_libraries(
cpublas PRIVATE executorch_core eigen_blas extension_threadpool
cpublas PUBLIC executorch_core eigen_blas extension_parallel extension_threadpool
)
target_compile_options(cpublas PUBLIC ${_common_compile_options})

Expand All @@ -63,7 +63,7 @@ list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(optimized_kernels ${_optimized_kernels__srcs})
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft")
target_link_libraries(
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool
optimized_kernels PUBLIC executorch_core cpublas extension_threadpool
)
target_compile_options(optimized_kernels PUBLIC ${_common_compile_options})
# Build a library for _optimized_kernels_srcs
Expand Down
Loading