Skip to content

[WIP] CMake refactor #4710

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
90 changes: 73 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,22 +445,22 @@ endif()
add_subdirectory(schema)

#
# executorch_no_prim_ops: Minimal runtime library
# executorch_core: Minimal runtime library
#
# The bare-minimum runtime library, supporting the Program and Method
# interfaces. Does not contain any operators, including primitive ops. Does not
# contain any backends.
#

# Remove any PAL-definition files from the sources.
list(FILTER _executorch_no_prim_ops__srcs EXCLUDE REGEX
list(FILTER _executorch_core__srcs EXCLUDE REGEX
"runtime/platform/default/[^/]*.cpp$"
)

# Add the source file that maps to the requested default PAL implementation.
if(EXECUTORCH_PAL_DEFAULT MATCHES "^(posix|minimal)$")
message(STATUS "executorch: Using PAL default '${EXECUTORCH_PAL_DEFAULT}'")
list(APPEND _executorch_no_prim_ops__srcs
list(APPEND _executorch_core__srcs
"runtime/platform/default/${EXECUTORCH_PAL_DEFAULT}.cpp"
)
else()
Expand All @@ -470,44 +470,44 @@ else()
)
endif()

add_library(executorch_no_prim_ops ${_executorch_no_prim_ops__srcs})
target_link_libraries(executorch_no_prim_ops PRIVATE program_schema)
add_library(executorch_core ${_executorch_core__srcs})
target_link_libraries(executorch_core PRIVATE program_schema)
if(EXECUTORCH_USE_DL)
# Check if dl exists for this toolchain and only then link it.
find_library(DL_LIBRARY_EXISTS NAMES dl)
# Check if the library was found
if(DL_LIBRARY_EXISTS)
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
target_link_libraries(executorch_core PRIVATE dl) # For dladdr()
endif()
endif()
target_include_directories(
executorch_no_prim_ops PUBLIC ${_common_include_directories}
executorch_core PUBLIC ${_common_include_directories}
)
target_compile_options(executorch_no_prim_ops PUBLIC ${_common_compile_options})
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
if(MAX_KERNEL_NUM)
target_compile_definitions(
executorch_no_prim_ops PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
executorch_core PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
)
endif()

if(EXECUTORCH_BUILD_PYBIND AND APPLE)
# shared version
add_library(
executorch_no_prim_ops_shared SHARED ${_executorch_no_prim_ops__srcs}
executorch_core_shared SHARED ${_executorch_core__srcs}
)
target_link_libraries(executorch_no_prim_ops_shared PRIVATE program_schema)
target_link_libraries(executorch_core_shared PRIVATE program_schema)
if(DL_LIBRARY_EXISTS)
target_link_libraries(executorch_no_prim_ops_shared PRIVATE dl) # For dladdr()
target_link_libraries(executorch_core_shared PRIVATE dl) # For dladdr()
endif()
target_include_directories(
executorch_no_prim_ops_shared PUBLIC ${_common_include_directories}
executorch_core_shared PUBLIC ${_common_include_directories}
)
target_compile_options(
executorch_no_prim_ops_shared PUBLIC ${_common_compile_options}
executorch_core_shared PUBLIC ${_common_compile_options}
)
if(MAX_KERNEL_NUM)
target_compile_definitions(
executorch_no_prim_ops_shared PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
executorch_core_shared PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
)
endif()
endif()
Expand All @@ -520,7 +520,7 @@ endif()
# any backends.
#
add_library(executorch ${_executorch__srcs})
target_link_libraries(executorch PRIVATE executorch_no_prim_ops)
target_link_libraries(executorch PRIVATE executorch_core)
target_include_directories(executorch PUBLIC ${_common_include_directories})
target_compile_options(executorch PUBLIC ${_common_compile_options})
target_link_options_shared_lib(executorch)
Expand Down Expand Up @@ -560,7 +560,7 @@ endif()
# Install `executorch` library as well as `executorch-config.cmake` under
# ${CMAKE_INSTALL_PREFIX}/
install(
TARGETS executorch executorch_no_prim_ops
TARGETS executorch executorch_core
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down Expand Up @@ -787,5 +787,61 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
)
endif()

function(executorch_runtime target_name)
set(options OPTIMIZED QUANTIZED)
set(multi_value_args BACKEND EXTENSION)

cmake_parse_arguments(ETR "${options}" "" "${multi_value_args}" ${ARGN})

set(runtime_deps executorch)

# Link backends.
foreach(backend IN LISTS ETR_BACKEND)
string(TOLOWER "${backend}" backend_l)

if(backend_l STREQUAL "coreml")
list(APPEND runtime_deps coremldelegate)
elseif(backend_l STREQUAL "mps")
list(APPEND runtime_deps mpsdelegate)
elseif(backend_l STREQUAL "qualcomm")
list(APPEND runtime_deps qnn_executorch_backend)
elseif(backend_l STREQUAL "vulkan")
list(APPEND runtime_deps vulkan_backend)
elseif(backend_l STREQUAL "xnnpack")
list(APPEND runtime_deps xnnpack_backend)
else()
message(FATAL_ERROR "Unknown backend \"${backend}}\".")
endif()
endforeach()

# Link extensions.
foreach(extension IN LISTS ETR_EXTENSION)
string(TOLOWER "${extension}" extension_l)

if(extension_l STREQUAL "apple")
list(APPEND runtime_deps extension_apple)
elseif(extension_l STREQUAL "dataloader")
list(APPEND runtime_deps extension_data_loader)
elseif(extension_l STREQUAL "module")
list(APPEND runtime_deps extension_module)
endif()
endforeach()

# Include optimized or portable operator library.
if(ETR_OPTIMIZED)
list(APPEND runtime_deps optimized_native_cpu_ops_lib)
else()
list(APPEND runtime_deps portable_ops_lib)
endif()

# Include quantized operator library.
if(ETR_QUANTIZED)
list(APPEND runtime_deps quantized_ops_lib)
endif()

add_library("${target_name}" INTERFACE)
target_link_libraries("${target_name}" INTERFACE "${runtime_deps}")
endfunction()

# Print all summary
executorch_print_configuration_summary()
6 changes: 3 additions & 3 deletions backends/apple/coreml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ target_include_directories(
coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
)
target_include_directories(coremldelegate PRIVATE ${EXECUTORCH_ROOT}/..)
target_link_libraries(coremldelegate PRIVATE executorch_no_prim_ops)
target_link_libraries(coremldelegate PRIVATE executorch_core)

if(EXECUTORCH_BUILD_SDK)
target_sources(coremldelegate PRIVATE ${SDK_SOURCES} ${PROTOBUF_SOURCES})
Expand All @@ -151,7 +151,7 @@ find_library(SQLITE_LIBRARY sqlite3)

target_link_libraries(
coremldelegate
PRIVATE executorch_no_prim_ops ${ACCELERATE_FRAMEWORK} ${COREML_FRAMEWORK}
PRIVATE executorch_core ${ACCELERATE_FRAMEWORK} ${COREML_FRAMEWORK}
${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY}
)

Expand All @@ -168,7 +168,7 @@ target_compile_options(coremldelegate PRIVATE "-fno-exceptions")

if(EXECUTORCH_BUILD_SDK)
target_compile_options(
executorch_no_prim_ops PUBLIC -DET_EVENT_TRACER_ENABLED
executorch_core PUBLIC -DET_EVENT_TRACER_ENABLED
)
target_compile_options(coremldelegate PRIVATE "-frtti")
target_compile_options(libprotobuf-lite PRIVATE "-frtti")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
C9E7D7952AB3F9BF00CCAE5D /* ETCoreMLModelManagerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E7D78D2AB3F9BF00CCAE5D /* ETCoreMLModelManagerTests.mm */; };
C9E7D7962AB3F9BF00CCAE5D /* KeyValueStoreTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E7D78E2AB3F9BF00CCAE5D /* KeyValueStoreTests.mm */; };
C9E7D7A22AB3FBB200CCAE5D /* CoreMLBackendDelegateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E7D7A12AB3FBB200CCAE5D /* CoreMLBackendDelegateTests.mm */; };
F24817E52BC655E100E80D98 /* libexecutorch_no_prim_ops.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */; };
F24817E52BC655E100E80D98 /* libexecutorch_core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F24817E42BC655E100E80D98 /* libexecutorch_core.a */; };
C9EC7E1B2BC73B3200A6B166 /* MultiArrayTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9EC7E1A2BC73B3200A6B166 /* MultiArrayTests.mm */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -299,7 +299,7 @@
C9EA3DB22B71A2B200B7D7BD /* CoreML.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreML.framework; path = System/Library/Frameworks/CoreML.framework; sourceTree = SDKROOT; };
C9EA3FDE2B73EEA000B7D7BD /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
C9EA3FE52B73EF6300B7D7BD /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libexecutorch_no_prim_ops.a; path = ../libraries/libexecutorch_no_prim_ops.a; sourceTree = "<group>"; };
F24817E42BC655E100E80D98 /* libexecutorch_core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libexecutorch_core.a; path = ../libraries/libexecutorch_core.a; sourceTree = "<group>"; };
C9EC7E092BC662A300A6B166 /* objc_array_util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = objc_array_util.h; path = ../util/objc_array_util.h; sourceTree = "<group>"; };
C9EC7E1A2BC73B3200A6B166 /* MultiArrayTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MultiArrayTests.mm; path = ../test/MultiArrayTests.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -310,7 +310,7 @@
buildActionMask = 2147483647;
files = (
C94D510F2ABDF87500AF47FD /* Accelerate.framework in Frameworks */,
F24817E52BC655E100E80D98 /* libexecutorch_no_prim_ops.a in Frameworks */,
F24817E52BC655E100E80D98 /* libexecutorch_core.a in Frameworks */,
C94D510E2ABDF86800AF47FD /* libsqlite3.tbd in Frameworks */,
C94D50D92ABD7B2400AF47FD /* CoreML.framework in Frameworks */,
C99883862B95AD7D000953A3 /* libprotobuf-lite.a in Frameworks */,
Expand Down Expand Up @@ -529,7 +529,7 @@
C96560942AABFDCE005F8126 /* libsqlite3.tbd */,
C96560922AABF992005F8126 /* CoreML.framework */,
C96560902AABF982005F8126 /* Accelerate.framework */,
F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */,
F24817E42BC655E100E80D98 /* libexecutorch_core.a */,
C965608D2AABF72A005F8126 /* libexecutorch.a */,
);
name = "Recovered References";
Expand Down
2 changes: 1 addition & 1 deletion backends/apple/coreml/scripts/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cmake --build "$CMAKE_PROTOBUF_BUILD_DIR_PATH" -j9 -t libprotobuf-lite
echo "ExecuTorch: Copying libraries"
mkdir "$LIBRARIES_DIR_PATH"
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch.a" "$LIBRARIES_DIR_PATH"
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch_no_prim_ops.a" "$LIBRARIES_DIR_PATH"
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch_core.a" "$LIBRARIES_DIR_PATH"
cp -f "$CMAKE_PROTOBUF_BUILD_DIR_PATH/libprotobuf-lite.a" "$LIBRARIES_DIR_PATH"

#Copy ExecuTorch headers
Expand Down
2 changes: 1 addition & 1 deletion backends/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ target_link_libraries(
mpsdelegate
PRIVATE bundled_program
mps_schema
executorch_no_prim_ops
executorch_core
${FOUNDATION_FRAMEWORK}
${METAL_FRAMEWORK}
${MPS_FRAMEWORK}
Expand Down
2 changes: 1 addition & 1 deletion backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ target_link_libraries(
)
target_link_libraries(
qnn_executorch_backend PRIVATE qnn_executorch_header qnn_schema qnn_manager
executorch_no_prim_ops qcir_utils
executorch_core qcir_utils
)
target_link_libraries(utils PRIVATE qnn_executorch_logging)
target_link_libraries(
Expand Down
2 changes: 1 addition & 1 deletion backends/xnnpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ include(cmake/Dependencies.cmake)
list(TRANSFORM _xnnpack_backend__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(xnnpack_backend STATIC ${_xnnpack_backend__srcs})
target_link_libraries(
xnnpack_backend PRIVATE ${xnnpack_third_party} executorch_no_prim_ops
xnnpack_backend PRIVATE ${xnnpack_third_party} executorch_core
xnnpack_schema
)

Expand Down
4 changes: 2 additions & 2 deletions build/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ function(gen_custom_ops_aot_lib)

target_link_options_shared_lib(${GEN_LIB_NAME})
if(EXECUTORCH_BUILD_PYBIND AND APPLE)
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_no_prim_ops)
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_core)
target_link_options(${GEN_LIB_NAME} PRIVATE -undefined dynamic_lookup)
else()
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_no_prim_ops)
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_core)
endif()
endfunction()

Expand Down
Loading
Loading