Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
35 changes: 35 additions & 0 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ deps = [
"executorch_core",
]

# HACK: prevent reduce_util from also showing up in custom_ops. The
# actual medium-term fix is to stop using Buck to drive our CMake
# builds.
[targets.reduce_util]
buck_targets = [
"//kernels/portable/cpu/util:reduce_util",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"executorch_core",
]

[targets.optimized_kernels]
buck_targets = [
"//kernels/optimized:generated_lib",
Expand All @@ -73,6 +88,7 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
Expand Down Expand Up @@ -115,6 +131,7 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
]

[targets.optimized_native_cpu_ops]
Expand All @@ -129,6 +146,8 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
# ---------------------------------- core end ----------------------------------
Expand Down Expand Up @@ -208,6 +227,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,7 +427,9 @@ deps = [
"executorch",
"executorch_core",
"optimized_kernels",
"extension_parallel",
"extension_threadpool",
"reduce_util",
"xnnpack_backend",
]

Expand Down Expand Up @@ -431,6 +465,7 @@ deps = [
"executorch_core",
"extension_data_loader",
"extension_module",
"extension_parallel",
"portable_kernels",
"quantized_kernels",
"xnnpack_backend",
Expand Down
15 changes: 15 additions & 0 deletions build/executorch-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ set(lib_list
neuron_backend
qnn_executorch_backend
portable_ops_lib
custom_ops
extension_module
extension_module_static
extension_parallel
extension_runner_util
extension_tensor
extension_threadpool
Expand Down Expand Up @@ -114,3 +116,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()
13 changes: 2 additions & 11 deletions examples/models/llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ~~~
# It should also be cmake-lint clean.
#
cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE
Copy link
Contributor Author

@swolchok swolchok Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering how high we can bump this and if we can raise it globally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I said on Discord:

the concern would be if there are projects that would want to take an ExecuTorch dep, but actually need an older CMake version. seems like we can raise it, but should avoid doing so unnecessarily.

so, i'm going to make this change in this PR but not roll it out to the top-level ExecuTorch CMakeLists.txt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the only way to achieve whole-archive? I dont know much on the implication of requiring this but I suppose non-trivial number of folks using et may come to use for llama

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we pip install latest cmake anyway. people who follow our directions will get 3.31.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good if we can do a codemod to change all CMakeLists.txt to have the same requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change all CMakeLists.txt to have the same requirement.

@larryliu0820 I wouldn't mind doing this, I just thought it might be beneficial to only increase the requirement for the llama example use cases that need this stuff and leave the core/embedded cases lower. What do you think?

project(llama_runner)

# Duplicating options as root CMakeLists.txt
Expand Down Expand Up @@ -84,14 +84,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../../../extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llama_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -119,8 +111,7 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
endif()

if(EXECUTORCH_BUILD_TORCHAO)
Expand Down
9 changes: 0 additions & 9 deletions examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llava_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -132,7 +124,6 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
endif()

Expand Down
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