diff --git a/.ci/scripts/build-qnn-sdk.sh b/.ci/scripts/build-qnn-sdk.sh index 4518468f29c..971581eb053 100755 --- a/.ci/scripts/build-qnn-sdk.sh +++ b/.ci/scripts/build-qnn-sdk.sh @@ -33,6 +33,8 @@ set_up_aot() { -DEXECUTORCH_BUILD_DEVTOOLS=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ + -DEXECUTORCH_BUILD_EXTENSION_EXTENSION_LLM=ON \ + -DEXECUTORCH_BUILD_EXTENSION_EXTENSION_LLM_RUNNER=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ diff --git a/.ci/scripts/test_llama.sh b/.ci/scripts/test_llama.sh index f92a983a340..20fd7939a0d 100644 --- a/.ci/scripts/test_llama.sh +++ b/.ci/scripts/test_llama.sh @@ -150,6 +150,7 @@ cmake_install_executorch_libraries() { echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a" rm -rf cmake-out retry cmake --preset llm \ + -DBUILD_TESTING=OFF \ -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \ -DEXECUTORCH_BUILD_QNN="$QNN" \ diff --git a/.ci/scripts/test_llama_torchao_lowbit.sh b/.ci/scripts/test_llama_torchao_lowbit.sh index 83bfc22ba09..ae8f74a5df5 100644 --- a/.ci/scripts/test_llama_torchao_lowbit.sh +++ b/.ci/scripts/test_llama_torchao_lowbit.sh @@ -29,6 +29,8 @@ cmake -DPYTHON_EXECUTABLE=python \ -DEXECUTORCH_ENABLE_LOGGING=1 \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ diff --git a/.ci/scripts/test_llava.sh b/.ci/scripts/test_llava.sh index 43f7a7348b7..afed3c54123 100644 --- a/.ci/scripts/test_llava.sh +++ b/.ci/scripts/test_llava.sh @@ -38,6 +38,8 @@ EXECUTORCH_COMMON_CMAKE_ARGS=" \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ -DEXECUTORCH_BUILD_KERNELS_LLM=ON \ -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index ad236040cb8..e221987f3ff 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -371,7 +371,7 @@ jobs: size=${arr[4]} # threshold=48120 on devserver with gcc11.4 # todo(lfq): update once binary size is below 50kb. - threshold="55584" + threshold="63776" if [[ "$size" -le "$threshold" ]]; then echo "Success $size <= $threshold" else @@ -406,7 +406,7 @@ jobs: output=$(ls -la cmake-out/test/size_test) arr=($output) size=${arr[4]} - threshold="51728" + threshold="51744" if [[ "$size" -le "$threshold" ]]; then echo "Success $size <= $threshold" else diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index b87f8c63388..d7205514a68 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -242,12 +242,12 @@ jobs: setup_script_args="" if [[ ${{ matrix.os}} == "bare_metal" ]]; then toolchain_prefix=arm-none-eabi- - threshold="104000" # should be ~103.7KB, set threshold to 104KB. + threshold="109000" toolchain_cmake=examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then setup_script_args="--target-toolchain zephyr" toolchain_prefix=arm-zephyr-eabi- - threshold="133120" # should be ~125KB, set threshold to 130KB + threshold="135000" toolchain_cmake=examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake else echo "Fail unsupport OS selection ${{ matrix.os }}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e6e3f1b727..95e33fb109e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake) include(${PROJECT_SOURCE_DIR}/tools/cmake/Utils.cmake) include(CMakeDependentOption) include(ExternalProject) +include(GNUInstallDirs) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) @@ -175,6 +176,7 @@ if(NOT DEFINED FXDIV_SOURCE_DIR) ) set(FXDIV_SOURCE_DIR "backends/xnnpack/third-party/FXdiv") add_subdirectory("${FXDIV_SOURCE_DIR}") + executorch_move_interface_include_directories_to_build_time_only(fxdiv) set(CMAKE_POSITION_INDEPENDENT_CODE ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} ) @@ -186,7 +188,9 @@ if(EXECUTORCH_BUILD_CPUINFO) ${CMAKE_POSITION_INDEPENDENT_CODE} ) set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo") + set(CPUINFO_SOURCE_DIR + "${CMAKE_CURRENT_LIST_DIR}/backends/xnnpack/third-party/cpuinfo" + ) set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "" @@ -216,6 +220,14 @@ if(EXECUTORCH_BUILD_CPUINFO) set(CMAKE_POSITION_INDEPENDENT_CODE ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} ) + executorch_add_prefix_to_public_headers(cpuinfo "${CPUINFO_SOURCE_DIR}/") + install( + TARGETS cpuinfo + EXPORT ExecuTorchTargets + DESTINATION lib + INCLUDES + DESTINATION ${_common_include_directories} + ) endif() if(EXECUTORCH_BUILD_PTHREADPOOL) @@ -248,6 +260,17 @@ if(EXECUTORCH_BUILD_PTHREADPOOL) ) endif() add_subdirectory("${PTHREADPOOL_SOURCE_DIR}") + executorch_move_interface_include_directories_to_build_time_only(pthreadpool) + executorch_move_interface_include_directories_to_build_time_only( + pthreadpool_interface + ) + install( + TARGETS pthreadpool pthreadpool_interface fxdiv + EXPORT ExecuTorchTargets + DESTINATION lib + INCLUDES + DESTINATION ${_common_include_directories} + ) set(CMAKE_POSITION_INDEPENDENT_CODE ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} ) @@ -271,8 +294,10 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch") ) endif() set(_common_include_directories - ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10 + $ + $ + $ + $ ) # @@ -447,53 +472,54 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/configurations) # ${CMAKE_INSTALL_PREFIX}/ install( DIRECTORY runtime/core/ - DESTINATION include/executorch/runtime/core + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/core FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY runtime/executor/ - DESTINATION include/executorch/runtime/executor + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/executor FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY runtime/kernel/ - DESTINATION include/executorch/runtime/kernel + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/kernel FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY runtime/platform/ - DESTINATION include/executorch/runtime/platform + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/platform FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY extension/kernel_util/ - DESTINATION include/executorch/extension/kernel_util + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/kernel_util FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY extension/tensor/ - DESTINATION include/executorch/extension/tensor + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/tensor FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY extension/threadpool/ - DESTINATION include/executorch/extension/threadpool + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h" ) install( TARGETS executorch executorch_core + EXPORT ExecuTorchTargets INCLUDES - DESTINATION ${_common_include_directories} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake - DESTINATION lib/cmake/ExecuTorch +install(FILES tools/cmake/executorch-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExecuTorch ) if(EXECUTORCH_BUILD_ARM_BAREMETAL) @@ -546,6 +572,12 @@ endif() if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader) + install( + DIRECTORY extension/data_loader/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/data_loader + FILES_MATCHING + PATTERN "*.h" + ) endif() if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL) @@ -566,24 +598,39 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/module) install( DIRECTORY extension/module/ - DESTINATION include/executorch/extension/module + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/module FILES_MATCHING PATTERN "*.h" ) endif() if(EXECUTORCH_BUILD_EXTENSION_LLM) + if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) + set(SUPPORT_REGEX_LOOKAHEAD ON) + # llama/runner/CMakeLists.txt builds a shared library libllama_runner.so + # that transitively depends on tokenizers. Need to build tokenizers with + # -fPIC. + set(ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG + ${CMAKE_POSITION_INDEPENDENT_CODE} + ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers) -endif() - -if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple) + if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) + set(CMAKE_POSITION_INDEPENDENT_CODE + ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} + ) + endif() endif() if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/runner) endif() +if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple) +endif() + if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util) install( @@ -689,8 +736,10 @@ if(EXECUTORCH_BUILD_PYBIND) target_compile_options(portable_lib PUBLIC ${_pybind_compile_options}) target_link_libraries(portable_lib PRIVATE ${_dep_libs}) - install(TARGETS portable_lib - LIBRARY DESTINATION executorch/extension/pybindings + install( + TARGETS portable_lib + EXPORT ExecuTorchTargets + LIBRARY DESTINATION executorch/extension/pybindings ) endif() @@ -775,5 +824,11 @@ endif() include(Test.cmake) +install( + EXPORT ExecuTorchTargets + FILE ExecuTorchTargets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExecuTorch +) + # Print all the configs that were called with announce_configured_options. print_configured_options() diff --git a/backends/apple/coreml/CMakeLists.txt b/backends/apple/coreml/CMakeLists.txt index d0013fb1a5f..9879a05e3dc 100644 --- a/backends/apple/coreml/CMakeLists.txt +++ b/backends/apple/coreml/CMakeLists.txt @@ -105,18 +105,24 @@ endif() add_library(coreml_util ${UTIL_SOURCES}) target_include_directories( - coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util + coreml_util + PUBLIC + $ + $ ) if(APPLE) target_link_libraries(coreml_util PRIVATE ${FOUNDATION_FRAMEWORK}) endif() target_compile_options(coreml_util PUBLIC -fPIC) +install(TARGETS coreml_util DESTINATION lib) + install( - TARGETS coreml_util - DESTINATION lib - INCLUDES - DESTINATION ${_common_include_directories} + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/executorch/backends/apple/coreml/runtime/util + FILES_MATCHING + PATTERN "*.h" ) # CoreML inmemoryfs @@ -134,7 +140,10 @@ endif() add_library(coreml_inmemoryfs ${INMEMORYFS_SOURCES}) target_include_directories( - coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs + coreml_inmemoryfs + PUBLIC + $ + $ ) if(APPLE) target_link_libraries( @@ -150,6 +159,14 @@ install( DESTINATION ${_common_include_directories} ) +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/executorch/backends/apple/coreml/runtime/inmemoryfs + FILES_MATCHING + PATTERN "*.h" +) + # executorchcoreml if(EXECUTORCH_BUILD_PYBIND) @@ -232,9 +249,10 @@ if(APPLE) endif() install( - TARGETS coremldelegate + TARGETS coremldelegate coreml_util coreml_inmemoryfs + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES - DESTINATION ${_common_include_directories} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) endif() diff --git a/backends/apple/mps/CMakeLists.txt b/backends/apple/mps/CMakeLists.txt index af18c3dec06..5a253347b01 100644 --- a/backends/apple/mps/CMakeLists.txt +++ b/backends/apple/mps/CMakeLists.txt @@ -19,7 +19,6 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) set(_common_compile_options -Wno-deprecated-declarations) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) set(_mps_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include") @@ -51,9 +50,10 @@ add_library(mps_schema INTERFACE ${_mps_schema__outputs}) set_target_properties(mps_schema PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( mps_schema - INTERFACE ${_mps_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include - ${_common_include_directories} + INTERFACE + $ + $ + ${_common_include_directories} ) list(TRANSFORM _mps_backend__srcs PREPEND "${EXECUTORCH_ROOT}/") @@ -75,7 +75,8 @@ target_compile_options(mpsdelegate PUBLIC ${_common_compile_options}) target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc") install( - TARGETS mpsdelegate + TARGETS mpsdelegate mps_schema + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/backends/mediatek/CMakeLists.txt b/backends/mediatek/CMakeLists.txt index b87dcdd9325..23e50e8cd8a 100644 --- a/backends/mediatek/CMakeLists.txt +++ b/backends/mediatek/CMakeLists.txt @@ -30,16 +30,20 @@ target_link_libraries( ) target_sources( neuron_backend - INTERFACE ${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBackend.h - ${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBufferAllocator.h - ${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronExecutor.h - ${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronLog.h - ${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/APUWareUtilsLib.h - ${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/NeuronAdapterShim.h + INTERFACE $ + $ + $ + $ + $ + $ PRIVATE ${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronBackend.cpp ${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronExecutor.cpp ${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronBufferAllocator.cpp ) executorch_target_link_options_shared_lib(neuron_backend) -install(TARGETS neuron_backend DESTINATION lib) +install( + TARGETS neuron_backend + EXPORT ExecuTorchTargets + DESTINATION lib +) diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index 0b0836ca744..33f150413a3 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -229,7 +229,11 @@ add_subdirectory( ${QNN_EXECUTORCH_ROOT_DIR}/aot/ir ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir ) -install(TARGETS qnn_executorch_backend DESTINATION lib) +install( + TARGETS qnn_executorch_backend + EXPORT ExecuTorchTargets + DESTINATION lib +) # QNN pybind if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") diff --git a/backends/qualcomm/runtime/CMakeLists.txt b/backends/qualcomm/runtime/CMakeLists.txt index d912d65381e..eb31bee7a53 100644 --- a/backends/qualcomm/runtime/CMakeLists.txt +++ b/backends/qualcomm/runtime/CMakeLists.txt @@ -17,21 +17,21 @@ target_sources( # qnn_executorch_backend target_sources( qnn_executorch_backend - INTERFACE ${CMAKE_CURRENT_LIST_DIR}/QnnExecuTorchBackend.h + INTERFACE $ PRIVATE ${CMAKE_CURRENT_LIST_DIR}/QnnExecuTorchBackend.cpp ) # qnn_manager target_sources( qnn_manager - INTERFACE ${CMAKE_CURRENT_LIST_DIR}/QnnManager.h + INTERFACE $ PRIVATE ${CMAKE_CURRENT_LIST_DIR}/QnnManager.cpp ) # logging target_sources( qnn_executorch_logging - PUBLIC ${CMAKE_CURRENT_LIST_DIR}/Logging.h + PUBLIC $ PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Logging.cpp ) diff --git a/backends/qualcomm/scripts/build.sh b/backends/qualcomm/scripts/build.sh index 8c0f01feac6..43d968813a9 100755 --- a/backends/qualcomm/scripts/build.sh +++ b/backends/qualcomm/scripts/build.sh @@ -80,6 +80,8 @@ if [ "$BUILD_AARCH64" = true ]; then -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DEXECUTORCH_BUILD_QNN=ON \ -DEXECUTORCH_BUILD_DEVTOOLS=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ @@ -97,7 +99,7 @@ if [ "$BUILD_AARCH64" = true ]; then cmake --build $BUILD_ROOT -j$BUILD_JOB_NUMBER --target install EXAMPLE_ROOT=examples/qualcomm - CMAKE_PREFIX_PATH="${BUILD_ROOT}/lib/cmake/ExecuTorch;${BUILD_ROOT}/third-party/gflags;" + CMAKE_PREFIX_PATH="${BUILD_ROOT};${BUILD_ROOT}/third-party/gflags;" cmake $PRJ_ROOT/$EXAMPLE_ROOT \ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \ @@ -132,6 +134,8 @@ if [ "$BUILD_X86_64" = true ]; then -DQNN_SDK_ROOT=${QNN_SDK_ROOT} \ -DEXECUTORCH_BUILD_QNN=ON \ -DEXECUTORCH_BUILD_DEVTOOLS=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ @@ -151,7 +155,7 @@ if [ "$BUILD_X86_64" = true ]; then cp -fv "$PRJ_ROOT/schema/scalar_type.fbs" "$PRJ_ROOT/exir/_serialize/scalar_type.fbs" EXAMPLE_ROOT=examples/qualcomm - CMAKE_PREFIX_PATH="${BUILD_ROOT}/lib/cmake/ExecuTorch;${BUILD_ROOT}/third-party/gflags;" + CMAKE_PREFIX_PATH="${BUILD_ROOT};${BUILD_ROOT}/third-party/gflags;" echo "Update tokenizers submodule..." pushd $PRJ_ROOT/extension/llm/tokenizers diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index 68fec49a57a..cb1b8a06afd 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -40,8 +40,10 @@ set(VULKAN_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/Vulkan-Headers) set(VOLK_PATH ${VULKAN_THIRD_PARTY_PATH}/volk) set(VMA_PATH ${VULKAN_THIRD_PARTY_PATH}/VulkanMemoryAllocator) -set(COMMON_INCLUDES ${EXECUTORCH_ROOT}/.. ${VULKAN_HEADERS_PATH}/include - ${VOLK_PATH} ${VMA_PATH} +set(COMMON_INCLUDES + $ + $ + $ $ ) # Compile settings @@ -96,8 +98,10 @@ add_library(vulkan_schema INTERFACE ${GENERATED_HEADER}) set_target_properties(vulkan_schema PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( - vulkan_schema INTERFACE ${SCHEMA_INCLUDE_DIR} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + vulkan_schema + INTERFACE + ${SCHEMA_INCLUDE_DIR} + $ ) # vulkan_backend @@ -134,7 +138,8 @@ endif() # Test targets install( - TARGETS vulkan_backend + TARGETS vulkan_backend vulkan_schema + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${COMMON_INCLUDES} diff --git a/backends/xnnpack/CMakeLists.txt b/backends/xnnpack/CMakeLists.txt index 0a5ec815542..51abb4f2356 100644 --- a/backends/xnnpack/CMakeLists.txt +++ b/backends/xnnpack/CMakeLists.txt @@ -35,7 +35,6 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) add_definitions(-DENABLE_XNNPACK_KLEIDI) endif() -set(_common_include_directories ${EXECUTORCH_ROOT}/..) set(_common_compile_options -Wno-deprecated-declarations -fPIC) set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include") @@ -88,8 +87,10 @@ unset(MV_COMMAND) add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs}) set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( - xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + xnnpack_schema + INTERFACE + $ + $ ) set(xnnpack_third_party pthreadpool extension_threadpool cpuinfo) @@ -102,28 +103,65 @@ target_link_libraries( xnnpack_backend PUBLIC ${xnnpack_third_party} executorch_core xnnpack_schema extension_threadpool ) - target_include_directories( xnnpack_backend PUBLIC ${_common_include_directories} ) -target_include_directories(xnnpack_backend PUBLIC ${XNNPACK_INCLUDE_DIR}) +target_include_directories(xnnpack_backend PRIVATE ${XNNPACK_INCLUDE_DIR}) target_include_directories( xnnpack_backend - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include ) target_include_directories( xnnpack_backend - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include ) target_compile_options(xnnpack_backend PUBLIC ${_common_compile_options}) executorch_target_link_options_shared_lib(xnnpack_backend) +executorch_move_interface_include_directories_to_build_time_only(XNNPACK) install( - TARGETS xnnpack_backend + TARGETS xnnpack_backend xnnpack_schema + EXPORT ExecuTorchTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${_common_include_directories} ) +# Without this, XNNPACK fails to install because of a failure to find +# backends/xnnpack/include/xnnpack.h. +set_target_properties(XNNPACK PROPERTIES PUBLIC_HEADER "") + +set_target_properties(cpuinfo PROPERTIES PUBLIC_HEADER "") +executorch_move_interface_include_directories_to_build_time_only(fxdiv) +executorch_move_interface_include_directories_to_build_time_only(pthreadpool) +executorch_move_interface_include_directories_to_build_time_only( + pthreadpool_interface +) +install( + TARGETS XNNPACK + xnnpack-base + xnnpack-allocator + xnnpack-cache + xnnpack-hardware-config + xnnpack-indirection + xnnpack-memory + xnnpack-microkernel-utils + xnnpack-microparams-init + xnnpack-mutex + xnnpack-normalization + xnnpack-operators + xnnpack-operator-run + xnnpack-operator-utils + xnnpack-pack-lh + xnnpack-packing + xnnpack-sanitizers + xnnpack-subgraph + xnnpack-datatype + xnnpack-reference-ukernels + xnnpack-logging + EXPORT ExecuTorchTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) if(BUILD_TESTING) add_subdirectory(test) endif() diff --git a/backends/xnnpack/cmake/Dependencies.cmake b/backends/xnnpack/cmake/Dependencies.cmake index 71ade68ccb2..60ab7db6c05 100644 --- a/backends/xnnpack/cmake/Dependencies.cmake +++ b/backends/xnnpack/cmake/Dependencies.cmake @@ -61,19 +61,24 @@ set(XNNPACK_BUILD_ALL_MICROKERNELS add_subdirectory("${XNNPACK_SOURCE_DIR}") include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) list(APPEND xnnpack_third_party XNNPACK) -install(TARGETS xnnpack-microkernels-prod - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - +install( + TARGETS xnnpack-microkernels-prod + EXPORT ExecuTorchTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) - if(TARGET kleidiai) - install(TARGETS kleidiai - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - endif() + if(TARGET kleidiai) + install( + TARGETS kleidiai + EXPORT ExecuTorchTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + endif() endif() # Revert PIC Flag to what it originally was diff --git a/configurations/CMakeLists.txt b/configurations/CMakeLists.txt index dfb24d27f94..fa5412ac476 100644 --- a/configurations/CMakeLists.txt +++ b/configurations/CMakeLists.txt @@ -60,5 +60,9 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) executorch_core ) - install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib) + install( + TARGETS optimized_native_cpu_ops_lib + EXPORT ExecuTorchTargets + DESTINATION lib + ) endif() diff --git a/devtools/CMakeLists.txt b/devtools/CMakeLists.txt index 87175d50867..85492075b8c 100644 --- a/devtools/CMakeLists.txt +++ b/devtools/CMakeLists.txt @@ -5,7 +5,10 @@ # LICENSE file in the root directory of this source tree. # The include directory that will contain the generated schema headers. -set(DEVTOOLS_INCLUDE_DIR "${CMAKE_BINARY_DIR}/devtools/include") +set(DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE ${CMAKE_BINARY_DIR}/devtools/include) +set(DEVTOOLS_INCLUDE_DIR + $ +) add_subdirectory(etdump) add_subdirectory(bundled_program) diff --git a/devtools/bundled_program/CMakeLists.txt b/devtools/bundled_program/CMakeLists.txt index b1b227b3528..533a92a3e25 100644 --- a/devtools/bundled_program/CMakeLists.txt +++ b/devtools/bundled_program/CMakeLists.txt @@ -39,12 +39,15 @@ add_library( ) target_link_libraries(bundled_program PUBLIC executorch) target_include_directories( - bundled_program PUBLIC ${DEVTOOLS_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/third-party/flatbuffers/include + bundled_program + PUBLIC + ${DEVTOOLS_INCLUDE_DIR} + $ ) install( TARGETS bundled_program + EXPORT ExecuTorchTargets DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/devtools/etdump/CMakeLists.txt b/devtools/etdump/CMakeLists.txt index 847ac9914e9..040b100f940 100644 --- a/devtools/etdump/CMakeLists.txt +++ b/devtools/etdump/CMakeLists.txt @@ -21,7 +21,7 @@ foreach(schema_file ${_schema_files}) list(APPEND _schema_outputs "${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump/${generated_builder}") endforeach() -file(MAKE_DIRECTORY ${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump) +file(MAKE_DIRECTORY ${DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE}/executorch/devtools/etdump) add_custom_command( OUTPUT ${_schema_outputs} COMMAND @@ -29,7 +29,7 @@ add_custom_command( # tree instead of under the binary directory, and there's no way to change # that behavior. flatcc_cli -cwr -o - ${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump + ${DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE}/executorch/devtools/etdump ${_etdump_schema__srcs} DEPENDS flatcc_cli ${_etdump_schema__srcs} COMMENT "Generating etdump headers" @@ -56,11 +56,12 @@ target_include_directories( etdump PUBLIC ${DEVTOOLS_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/third-party/flatcc/include + $ ) install( - TARGETS etdump + TARGETS etdump flatccrt + EXPORT ExecuTorchTargets DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/examples/models/llama/runner/CMakeLists.txt b/examples/models/llama/runner/CMakeLists.txt index a73990edd96..ebe1fb201f2 100644 --- a/examples/models/llama/runner/CMakeLists.txt +++ b/examples/models/llama/runner/CMakeLists.txt @@ -23,23 +23,13 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) -# -# The `__srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. -# -set(EXECUTORCH_SRCS_FILE - "${CMAKE_CURRENT_BINARY_DIR}/../../../../executorch_srcs.cmake" -) - -extract_sources(${EXECUTORCH_SRCS_FILE}) - -include(${EXECUTORCH_SRCS_FILE}) - -# build llama_runner library -list(TRANSFORM _llama_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") - -target_include_directories( - extension_module INTERFACE ${_common_include_directories} -) +# The buck-based executorch_srcs.cmake setup was crossing package +# boundaries and trying to build stuff from +# executorch/extension/llm/runner and tokenizers. Just set up sources +# manually. +set(llama_runner_srcs + runner.cpp + ../tokenizer/llama_tiktoken.cpp) if(CMAKE_TOOLCHAIN_IOS OR ANDROID @@ -47,31 +37,28 @@ if(CMAKE_TOOLCHAIN_IOS ) # Building a share library on iOS requires code signing On Android we see # duplicated registration when using shared lib - add_library(llama_runner STATIC ${_llama_runner__srcs}) + add_library(llama_runner STATIC ${llama_runner_srcs}) else() - add_library(llama_runner SHARED ${_llama_runner__srcs}) + add_library(llama_runner SHARED ${llama_runner_srcs}) endif() -# For extension_llm_runner if(NOT TARGET extension_llm_runner) - add_subdirectory( - ${EXECUTORCH_ROOT}/extension/llm/runner - ${CMAKE_CURRENT_BINARY_DIR}/../../../../extension/llm/runner + message( + FATAL_ERROR + "ExecuTorch must be installed with EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER enabled." ) endif() -set(llama_runner_deps executorch_core extension_data_loader extension_module - extension_tensor extension_flat_tensor extension_llm_runner +set(llama_runner_deps + executorch_core extension_data_loader extension_module extension_tensor + extension_flat_tensor extension_llm_runner ) target_link_libraries(llama_runner PUBLIC ${llama_runner_deps}) - -target_link_libraries( - llama_runner PUBLIC tokenizers -) +target_link_libraries(llama_runner PUBLIC tokenizers::tokenizers) target_include_directories( - llama_runner - PUBLIC ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include + llama_runner PUBLIC ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include + ${EXECUTORCH_ROOT}/.. ) target_compile_options(llama_runner PUBLIC ${_preprocessor_flag}) diff --git a/examples/models/llava/runner/CMakeLists.txt b/examples/models/llava/runner/CMakeLists.txt index 016678e3c54..ce7c0968d9e 100644 --- a/examples/models/llava/runner/CMakeLists.txt +++ b/examples/models/llava/runner/CMakeLists.txt @@ -30,13 +30,15 @@ set(_llava_runner__srcs "${CMAKE_CURRENT_SOURCE_DIR}/llava_runner.cpp" ) -# extension llm runner lib -add_subdirectory( - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../extension/llm/runner - ${CMAKE_CURRENT_BINARY_DIR}/../../../../extension/llm/runner -) +if(NOT TARGET extension_llm_runner) + message( + FATAL_ERROR + "ExecuTorch must be installed with EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER enabled." + ) +endif() add_library(llava_runner STATIC ${_llava_runner__srcs}) +target_include_directories(llava_runner PRIVATE ${_common_include_directories}) set(llava_runner_deps executorch_core extension_data_loader extension_llm_runner extension_module extension_tensor extension_flat_tensor diff --git a/examples/models/phi-3-mini/CMakeLists.txt b/examples/models/phi-3-mini/CMakeLists.txt index 930301fdd63..4e55d4f9cb0 100644 --- a/examples/models/phi-3-mini/CMakeLists.txt +++ b/examples/models/phi-3-mini/CMakeLists.txt @@ -27,13 +27,13 @@ set(_common_include_directories list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) -executorch_target_link_options_shared_lib(executorch) - set(BUILD_TESTING OFF) -add_subdirectory( - ${EXECUTORCH_ROOT}/extension/llm/runner - ${CMAKE_BINARY_DIR}/../../../extension/llm/runner -) +if(NOT TARGET extension_llm_runner) + message( + FATAL_ERROR + "ExecuTorch must be installed with EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER enabled." + ) +endif() if(NOT TARGET gflags) add_subdirectory( diff --git a/examples/portable/custom_ops/test_custom_ops.sh b/examples/portable/custom_ops/test_custom_ops.sh index 5d21d393686..58a7de3a5f2 100644 --- a/examples/portable/custom_ops/test_custom_ops.sh +++ b/examples/portable/custom_ops/test_custom_ops.sh @@ -9,7 +9,7 @@ # EXIR to capture and export a model file. Then use `executor_runner` demo C++ # binary to run the model. -set -e +set -ex # shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/../../../.ci/scripts/utils.sh" diff --git a/examples/qualcomm/CMakeLists.txt b/examples/qualcomm/CMakeLists.txt index 6bceec128f2..d33d666b9c0 100644 --- a/examples/qualcomm/CMakeLists.txt +++ b/examples/qualcomm/CMakeLists.txt @@ -34,12 +34,6 @@ find_package(gflags REQUIRED) set(_common_compile_options -Wno-deprecated-declarations -fPIC) -# Let files say "include ". -set(_common_include_directories - ${EXECUTORCH_ROOT}/.. - ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include -) - # # The `__srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. # @@ -65,20 +59,11 @@ gen_operators_lib( target_compile_options( full_portable_ops_lib INTERFACE -DET_EVENT_TRACER_ENABLED ) -target_include_directories( - full_portable_ops_lib - PUBLIC - ${_common_include_directories} - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension/llm/tokenizers/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension/llm/tokenizers/third-party/json/single_include - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension/llm/tokenizers/third-party/llama.cpp-unicode/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension/llm/tokenizers/third-party/llama.cpp-unicode/src -) -# add tokenizers -add_subdirectory( - ${EXECUTORCH_ROOT}/extension/llm/runner - ${CMAKE_CURRENT_BINARY_DIR}/../../extension/llm/runner +# Let files say "include ". +set(_common_include_directories + ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) # build qnn_executor_runner diff --git a/examples/qualcomm/executor_runner/CMakeLists.txt b/examples/qualcomm/executor_runner/CMakeLists.txt index 1d7f6b718f2..47395244a68 100644 --- a/examples/qualcomm/executor_runner/CMakeLists.txt +++ b/examples/qualcomm/executor_runner/CMakeLists.txt @@ -21,6 +21,7 @@ target_include_directories( target_link_libraries( qnn_executor_runner qnn_executorch_backend + executorch_core extension_evalue_util extension_runner_util full_portable_ops_lib diff --git a/examples/qualcomm/oss_scripts/llama/CMakeLists.txt b/examples/qualcomm/oss_scripts/llama/CMakeLists.txt index ba483abe92b..bf83a456bca 100644 --- a/examples/qualcomm/oss_scripts/llama/CMakeLists.txt +++ b/examples/qualcomm/oss_scripts/llama/CMakeLists.txt @@ -4,7 +4,6 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. - # model sharding with custom op set(CUSTOM_OP_SRCS_FILE "${EXECUTORCH_SOURCE_DIR}/extension/llm/custom_ops/op_fallback.cpp" @@ -16,7 +15,7 @@ target_include_directories(custom_ops PUBLIC "${_common_include_directories}") target_include_directories( custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../include" ) -target_link_libraries(custom_ops PUBLIC full_portable_ops_lib) +target_link_libraries(custom_ops PUBLIC executorch_core full_portable_ops_lib) executorch_target_link_options_shared_lib(custom_ops) # preprocess qnn runner src files for llama @@ -50,10 +49,7 @@ list(APPEND _llama_runner__srcs) # build qnn llama runner add_executable(qnn_llama_runner ${_llama_runner__srcs}) target_include_directories( - qnn_llama_runner - PUBLIC - ${_common_include_directories} - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../extension/llm/tokenizers/include + qnn_llama_runner PUBLIC ${_common_include_directories} ) executorch_target_link_options_shared_lib(quantized_ops_lib) @@ -67,17 +63,15 @@ target_link_libraries( extension_llm_runner extension_module extension_tensor - tokenizers gflags custom_ops quantized_ops_lib quantized_kernels - tokenizers + tokenizers::tokenizers ) target_include_directories( - qnn_llama_runner - PUBLIC ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include + qnn_llama_runner PUBLIC ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include ) target_compile_options(qnn_llama_runner PUBLIC ${_common_compile_options}) diff --git a/examples/qualcomm/oss_scripts/t5/CMakeLists.txt b/examples/qualcomm/oss_scripts/t5/CMakeLists.txt index 4ee42b69449..70fb613bb22 100644 --- a/examples/qualcomm/oss_scripts/t5/CMakeLists.txt +++ b/examples/qualcomm/oss_scripts/t5/CMakeLists.txt @@ -21,7 +21,6 @@ set(_qnn_t5_runner__srcs add_executable(qnn_t5_runner ${_qnn_t5_runner__srcs}) target_include_directories( qnn_t5_runner PUBLIC ${_common_include_directories} - ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include ) @@ -31,10 +30,11 @@ target_link_libraries( executorch_core extension_data_loader extension_flat_tensor + extension_llm_runner extension_module extension_tensor gflags - tokenizers + tokenizers::tokenizers ) target_compile_options( diff --git a/examples/qualcomm/oss_scripts/whisper/CMakeLists.txt b/examples/qualcomm/oss_scripts/whisper/CMakeLists.txt index d3c28b218e3..5845575cba2 100644 --- a/examples/qualcomm/oss_scripts/whisper/CMakeLists.txt +++ b/examples/qualcomm/oss_scripts/whisper/CMakeLists.txt @@ -21,7 +21,6 @@ set(_qnn_whisper_runner__srcs add_executable(qnn_whisper_runner ${_qnn_whisper_runner__srcs}) target_include_directories( qnn_whisper_runner PUBLIC ${_common_include_directories} - ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include ) @@ -35,7 +34,7 @@ target_link_libraries( extension_tensor full_portable_ops_lib gflags - tokenizers + tokenizers::tokenizers ) target_compile_options( diff --git a/examples/qualcomm/qaihub_scripts/llama/CMakeLists.txt b/examples/qualcomm/qaihub_scripts/llama/CMakeLists.txt index 2a13bbe861c..4088d685ec0 100644 --- a/examples/qualcomm/qaihub_scripts/llama/CMakeLists.txt +++ b/examples/qualcomm/qaihub_scripts/llama/CMakeLists.txt @@ -32,7 +32,6 @@ add_executable(qaihub_llama2_7b_runner ${_qaihub_llama2_7b_runner__srcs}) target_include_directories( qaihub_llama2_7b_runner PUBLIC ${_common_include_directories} - ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include ) target_link_libraries( qaihub_llama2_7b_runner @@ -40,10 +39,10 @@ target_link_libraries( executorch_core extension_data_loader extension_flat_tensor + extension_llm_runner extension_module extension_tensor gflags - tokenizers ) target_compile_options( qaihub_llama2_7b_runner PUBLIC ${_common_compile_options} @@ -68,7 +67,6 @@ target_include_directories( qaihub_llama3_8b_runner PUBLIC ${_common_include_directories} - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../extension/llm/tokenizers/include ) target_link_libraries( @@ -77,10 +75,10 @@ target_link_libraries( executorch_core extension_data_loader extension_flat_tensor + extension_llm_runner extension_module extension_tensor gflags - tokenizers ) target_compile_options( qaihub_llama3_8b_runner PUBLIC ${_common_compile_options} diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index bc00fd776d0..feb4fdb6bb9 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -19,7 +19,6 @@ endif() set(EXECUTORCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) set(_common_compile_options -Wno-deprecated-declarations -fPIC) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) if(NOT ANDROID_PLATFORM) set(ANDROID_PLATFORM android-30) endif() diff --git a/extension/data_loader/CMakeLists.txt b/extension/data_loader/CMakeLists.txt index 43128087457..104cd23c977 100644 --- a/extension/data_loader/CMakeLists.txt +++ b/extension/data_loader/CMakeLists.txt @@ -27,12 +27,15 @@ endif() list(TRANSFORM _extension_data_loader__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_data_loader ${_extension_data_loader__srcs}) target_link_libraries(extension_data_loader executorch_core) -target_include_directories(extension_data_loader PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_data_loader PUBLIC ${_common_include_directories} +) target_compile_options(extension_data_loader PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_data_loader + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/evalue_util/CMakeLists.txt b/extension/evalue_util/CMakeLists.txt index 21b89bb2b7b..90546b4abae 100644 --- a/extension/evalue_util/CMakeLists.txt +++ b/extension/evalue_util/CMakeLists.txt @@ -23,6 +23,7 @@ target_compile_options(extension_evalue_util PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_evalue_util + EXPORT ExecuTorchTargets DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/flat_tensor/CMakeLists.txt b/extension/flat_tensor/CMakeLists.txt index d44ed811805..ff70bcc9565 100644 --- a/extension/flat_tensor/CMakeLists.txt +++ b/extension/flat_tensor/CMakeLists.txt @@ -21,9 +21,8 @@ add_library(extension_flat_tensor ${_extension_flat_tensor__srcs}) target_link_libraries(extension_flat_tensor executorch_core) target_include_directories( extension_flat_tensor - PUBLIC ${EXECUTORCH_ROOT}/.. - "${CMAKE_BINARY_DIR}/extension/flat_tensor/include" - "${EXECUTORCH_ROOT}/third-party/flatbuffers/include" + PUBLIC $ + $ ${_common_include_directories} ) target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options}) @@ -31,6 +30,7 @@ target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_flat_tensor + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/llm/apple/CMakeLists.txt b/extension/llm/apple/CMakeLists.txt index 572ac5813ef..aa7da842004 100644 --- a/extension/llm/apple/CMakeLists.txt +++ b/extension/llm/apple/CMakeLists.txt @@ -20,35 +20,27 @@ endif() add_library(extension_llm_apple) -file(GLOB OBJC_SOURCES - ExecuTorchLLM/Exported/*.m - ExecuTorchLLM/Exported/*.mm -) +file(GLOB OBJC_SOURCES ExecuTorchLLM/Exported/*.m ExecuTorchLLM/Exported/*.mm) -target_sources(extension_llm_apple PRIVATE - ${OBJC_SOURCES} -) +target_sources(extension_llm_apple PRIVATE ${OBJC_SOURCES}) -target_include_directories(extension_llm_apple - PUBLIC ExecuTorchLLM/Exported -) +target_include_directories(extension_llm_apple PUBLIC ExecuTorchLLM/Exported) if(NOT TARGET extension_llm_runner) - add_subdirectory( - ${EXECUTORCH_ROOT}/extension/llm/runner - ${CMAKE_CURRENT_BINARY_DIR}/../runner + message( + FATAL_ERROR + "EXECUTORCH_BUILD_EXTENSION_LLM_APPLE requires EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER." ) endif() find_library(FOUNDATION_FRAMEWORK Foundation) -target_link_libraries(extension_llm_apple - PRIVATE extension_llm_runner ${FOUNDATION_FRAMEWORK} +target_link_libraries( + extension_llm_apple PRIVATE extension_llm_runner ${FOUNDATION_FRAMEWORK} ) -set_source_files_properties(${OBJC_SOURCES} PROPERTIES COMPILE_FLAGS - "-fobjc-arc" - "-fno-exceptions" - "-fno-rtti" +set_source_files_properties( + ${OBJC_SOURCES} PROPERTIES COMPILE_FLAGS "-fobjc-arc" "-fno-exceptions" + "-fno-rtti" ) set_target_properties(extension_llm_apple PROPERTIES diff --git a/extension/llm/custom_ops/CMakeLists.txt b/extension/llm/custom_ops/CMakeLists.txt index 20890794857..c5eba4b7a19 100644 --- a/extension/llm/custom_ops/CMakeLists.txt +++ b/extension/llm/custom_ops/CMakeLists.txt @@ -35,9 +35,14 @@ extract_sources(${EXECUTORCH_SRCS_FILE}) include(${EXECUTORCH_SRCS_FILE}) -# Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) -list(APPEND _common_include_directories ${EXECUTORCH_ROOT}/third-party/ao) +set(_common_include_directories + $ + $ +) + +list(APPEND _common_include_directories + $ +) # Custom op libraries set(custom_ops_libs pthreadpool) @@ -71,16 +76,21 @@ endif() add_library(custom_ops ${_custom_ops__srcs}) find_package_torch_headers() -target_include_directories(custom_ops PUBLIC "${_common_include_directories}") +target_include_directories(custom_ops PRIVATE "${_common_include_directories}") target_include_directories( - custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include" - ${TORCH_INCLUDE_DIRS} + custom_ops + PRIVATE $ + ${TORCH_INCLUDE_DIRS} ) target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_core) target_compile_options(custom_ops PUBLIC ${_common_compile_options}) -install(TARGETS custom_ops DESTINATION lib) +install( + TARGETS custom_ops + EXPORT ExecuTorchTargets + DESTINATION lib +) if(EXECUTORCH_BUILD_KERNELS_LLM_AOT) # Add a AOT library @@ -94,11 +104,12 @@ if(EXECUTORCH_BUILD_KERNELS_LLM_AOT) ${CMAKE_CURRENT_SOURCE_DIR}/op_tile_crop_aot.cpp ) target_include_directories( - custom_ops_aot_lib PUBLIC "${_common_include_directories}" + custom_ops_aot_lib PRIVATE "${_common_include_directories}" ) target_include_directories( - custom_ops_aot_lib PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include" - ${TORCH_INCLUDE_DIRS} + custom_ops_aot_lib + PRIVATE $ + ${TORCH_INCLUDE_DIRS} ) # TODO: This only works if we install portable_lib.so to # /executorch/extension/pybindings/. @@ -134,8 +145,10 @@ if(EXECUTORCH_BUILD_KERNELS_LLM_AOT) -fexceptions ${_common_compile_options} ) - install(TARGETS custom_ops_aot_lib - LIBRARY DESTINATION executorch/extension/llm/custom_ops + install( + TARGETS custom_ops_aot_lib + EXPORT ExecuTorchTargets + LIBRARY DESTINATION executorch/extension/llm/custom_ops ) endif() diff --git a/extension/llm/runner/CMakeLists.txt b/extension/llm/runner/CMakeLists.txt index b1ec3c0fd1c..f5933e82e32 100644 --- a/extension/llm/runner/CMakeLists.txt +++ b/extension/llm/runner/CMakeLists.txt @@ -37,31 +37,38 @@ include(${EXECUTORCH_SRCS_FILE}) # build llm runner library list(TRANSFORM _extension_llm_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") -target_include_directories( - extension_module INTERFACE ${_common_include_directories} -) - add_library(extension_llm_runner STATIC ${_extension_llm_runner__srcs}) -# add tokenizers -set(SUPPORT_REGEX_LOOKAHEAD ON) -# llama/runner/CMakeLists.txt builds a shared library libllama_runner.so that -# transitively depends on tokenizers. Need to build tokenizers with -fPIC. -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -add_subdirectory( - ${EXECUTORCH_ROOT}/extension/llm/tokenizers - ${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/tokenizers -) - set(runner_deps executorch_core extension_module extension_tensor tokenizers) target_link_libraries(extension_llm_runner PUBLIC ${runner_deps}) -set_target_properties(extension_llm_runner PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties( + extension_llm_runner PROPERTIES POSITION_INDEPENDENT_CODE ON +) target_include_directories( - extension_llm_runner - INTERFACE ${_common_include_directories} - ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include + extension_llm_runner INTERFACE ${_common_include_directories} +) + +install( + TARGETS extension_llm_runner + EXPORT ExecuTorchTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES + DESTINATION ${_common_include_directories} +) +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/llm/runner + FILES_MATCHING + PATTERN "*.h" +) +# TODO: remove this once we create a proper CMake setup for sampler. +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../sampler/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/llm/sampler + FILES_MATCHING + PATTERN "*.h" ) if(BUILD_TESTING) diff --git a/extension/llm/tokenizers b/extension/llm/tokenizers index ea8691c6200..f09feca1584 160000 --- a/extension/llm/tokenizers +++ b/extension/llm/tokenizers @@ -1 +1 @@ -Subproject commit ea8691c6200c702cf28dd2aa2da902e9299b6bb3 +Subproject commit f09feca15849a790c05b3b7855e7c62ce26ba94b diff --git a/extension/module/CMakeLists.txt b/extension/module/CMakeLists.txt index cd22f1ccfc2..082c7641649 100644 --- a/extension/module/CMakeLists.txt +++ b/extension/module/CMakeLists.txt @@ -31,7 +31,9 @@ target_link_libraries( extension_module PRIVATE executorch_core extension_data_loader extension_flat_tensor ) -target_include_directories(extension_module PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_module PUBLIC ${_common_include_directories} +) target_compile_options( extension_module PUBLIC -Wno-deprecated-declarations -fPIC ) @@ -43,7 +45,9 @@ target_link_libraries( extension_module_static PRIVATE executorch_core extension_data_loader extension_flat_tensor ) -target_include_directories(extension_module_static PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_module_static PUBLIC ${_common_include_directories} +) target_compile_options( extension_module_static PUBLIC -Wno-deprecated-declarations -fPIC ) @@ -51,6 +55,7 @@ target_compile_options( # Install libraries install( TARGETS extension_module extension_module_static + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/runner_util/CMakeLists.txt b/extension/runner_util/CMakeLists.txt index 3483b3babf3..1a9721c3920 100644 --- a/extension/runner_util/CMakeLists.txt +++ b/extension/runner_util/CMakeLists.txt @@ -19,12 +19,15 @@ endif() list(TRANSFORM _extension_runner_util__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_runner_util ${_extension_runner_util__srcs}) target_link_libraries(extension_runner_util executorch_core) -target_include_directories(extension_runner_util PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_runner_util PUBLIC ${_common_include_directories} +) target_compile_options(extension_runner_util PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_runner_util + EXPORT ExecuTorchTargets DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/tensor/CMakeLists.txt b/extension/tensor/CMakeLists.txt index 51f955570db..0e409c3bfb3 100644 --- a/extension/tensor/CMakeLists.txt +++ b/extension/tensor/CMakeLists.txt @@ -19,12 +19,15 @@ endif() list(TRANSFORM _extension_tensor__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_tensor ${_extension_tensor__srcs}) target_link_libraries(extension_tensor executorch_core) -target_include_directories(extension_tensor PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_tensor PUBLIC ${_common_include_directories} +) target_compile_options(extension_tensor PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_tensor + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/threadpool/CMakeLists.txt b/extension/threadpool/CMakeLists.txt index 6e107cb6634..a6c06e84293 100644 --- a/extension/threadpool/CMakeLists.txt +++ b/extension/threadpool/CMakeLists.txt @@ -27,11 +27,14 @@ add_library( target_link_libraries( extension_threadpool PUBLIC executorch_core cpuinfo pthreadpool ) -target_include_directories(extension_threadpool PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories( + extension_threadpool PUBLIC ${_common_include_directories} +) target_include_directories( extension_threadpool - PUBLIC ${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include - ${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include + PUBLIC + $ + $ ) target_compile_definitions(extension_threadpool PUBLIC ET_USE_THREADPOOL) target_compile_options(extension_threadpool PUBLIC ${_common_compile_options}) @@ -39,6 +42,7 @@ target_compile_options(extension_threadpool PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_threadpool + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/training/CMakeLists.txt b/extension/training/CMakeLists.txt index 26a5c752d5b..1e17913141d 100644 --- a/extension/training/CMakeLists.txt +++ b/extension/training/CMakeLists.txt @@ -23,7 +23,6 @@ target_include_directories( extension_training PUBLIC ${_common_include_directories} ) -target_include_directories(extension_training PUBLIC ${EXECUTORCH_ROOT}/..) target_compile_options(extension_training PUBLIC ${_common_compile_options}) target_link_libraries( extension_training @@ -83,6 +82,7 @@ endif() # Install libraries install( TARGETS extension_training + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index 9f9094657b0..32ae865bfdf 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -79,9 +79,10 @@ gen_operators_lib( ) install( - TARGETS cpublas optimized_kernels optimized_ops_lib + # eigen_blas doesn't export itself, so we have to do our own install to export + # it. + TARGETS cpublas optimized_kernels optimized_ops_lib eigen_blas + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/optimized/ ) - -install(TARGETS cpublas DESTINATION lib) diff --git a/kernels/portable/CMakeLists.txt b/kernels/portable/CMakeLists.txt index b729d56993e..eb8475b8d5a 100644 --- a/kernels/portable/CMakeLists.txt +++ b/kernels/portable/CMakeLists.txt @@ -88,13 +88,16 @@ if(EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_KERNELS_OPTIMIZED) LIB_NAME "optimized_portable_ops_lib" KERNEL_LIBS optimized_portable_kernels DEPS executorch_core ) - install(TARGETS optimized_portable_kernels optimized_portable_ops_lib - DESTINATION lib + install( + TARGETS optimized_portable_kernels optimized_portable_ops_lib + EXPORT ExecuTorchTargets + DESTINATION lib ) endif() install( TARGETS portable_kernels portable_ops_lib + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/portable/ ) diff --git a/kernels/portable/cpu/util/CMakeLists.txt b/kernels/portable/cpu/util/CMakeLists.txt index 19d33cf84d9..047760f321e 100644 --- a/kernels/portable/cpu/util/CMakeLists.txt +++ b/kernels/portable/cpu/util/CMakeLists.txt @@ -32,3 +32,9 @@ target_compile_definitions( kernels_util_all_deps PUBLIC C10_USING_CUSTOM_GENERATED_MACROS ) target_compile_options(kernels_util_all_deps PUBLIC ${_common_compile_options}) + +install( + TARGETS kernels_util_all_deps + EXPORT ExecuTorchTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/kernels/quantized/CMakeLists.txt b/kernels/quantized/CMakeLists.txt index ddbbc1a10b8..b0c837cdefd 100644 --- a/kernels/quantized/CMakeLists.txt +++ b/kernels/quantized/CMakeLists.txt @@ -151,6 +151,7 @@ gen_operators_lib( install( TARGETS quantized_kernels quantized_ops_lib + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/quantized/ ) diff --git a/schema/CMakeLists.txt b/schema/CMakeLists.txt index e161f6b983c..fc844bbf3a6 100644 --- a/schema/CMakeLists.txt +++ b/schema/CMakeLists.txt @@ -50,9 +50,11 @@ function(generate_program_schema _schema_srcs _schema_name) target_include_directories( ${_schema_name} - INTERFACE ${_program_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + INTERFACE + $ + $ ) + endfunction() # Generate common schema @@ -63,3 +65,11 @@ generate_program_schema("${common_schema_srcs}" "common_schema") set(program_schema_srcs program.fbs) generate_program_schema("${program_schema_srcs}" "program_schema") add_dependencies(program_schema common_schema) + +install( + TARGETS common_schema program_schema + EXPORT ExecuTorchTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES + DESTINATION ${_common_include_directories} +) diff --git a/scripts/build_android_library.sh b/scripts/build_android_library.sh index 465a17a840c..d01e37affff 100755 --- a/scripts/build_android_library.sh +++ b/scripts/build_android_library.sh @@ -49,6 +49,8 @@ build_android_native_library() { -DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ + -DEXECUTORCH_BUILD_EXTENSION_LLM="${EXECUTORCH_BUILD_EXTENSION_LLM:-ON}" \ + -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER="${EXECUTORCH_BUILD_EXTENSION_LLM:-ON}" \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 054dc8569ae..5ad429e822f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,11 +26,12 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) # Find prebuilt executorch library -find_package(executorch CONFIG REQUIRED HINTS ${CMAKE_INSTALL_PREFIX}) + +list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../) +find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/..) -target_include_directories(executorch INTERFACE ${_common_include_directories}) # # The `__srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. @@ -60,7 +61,6 @@ endif() # size_test_all_ops: binary with portable ops and no delegate backend # add_executable(size_test_all_ops ${_size_test__srcs}) -executorch_target_link_options_shared_lib(portable_ops_lib) target_link_libraries( size_test_all_ops executorch extension_data_loader portable_ops_lib portable_kernels @@ -74,7 +74,6 @@ endif() # if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) add_executable(size_test_all_optimized_ops ${_size_test__srcs}) - executorch_target_link_options_shared_lib(optimized_native_cpu_ops_lib) target_link_libraries( size_test_all_optimized_ops executorch extension_data_loader optimized_native_cpu_ops_lib diff --git a/tools/cmake/Test.cmake b/tools/cmake/Test.cmake index a7a026e6ffe..652f7df5589 100644 --- a/tools/cmake/Test.cmake +++ b/tools/cmake/Test.cmake @@ -41,7 +41,7 @@ function(et_cxx_test target_name) ${EXECUTORCH_ROOT}/runtime/core/exec_aten/testing_util/tensor_util.cpp ) if(NOT TARGET GTest::gtest) - find_package(GTest) + find_package(GTest REQUIRED) endif() # Includes gtest, gmock, executorch_core by default target_link_libraries( diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index b4ce6d3edcb..e567fa503d4 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -278,3 +278,38 @@ macro(find_package_torch) find_package(Torch CONFIG REQUIRED) endif() endmacro() + +# Modify ${targetName}'s INTERFACE_INCLUDE_DIRECTORIES by wrapping each entry in +# $ so that they work with CMake EXPORT. +function(executorch_move_interface_include_directories_to_build_time_only + targetName +) + get_property( + OLD_INTERFACE_INCLUDE_DIRECTORIES + TARGET "${targetName}" + PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ) + set(FIXED_INTERFACE_INCLUDE_DIRECTORIES) + foreach(dir ${OLD_INTERFACE_INCLUDE_DIRECTORIES}) + list(APPEND FIXED_INTERFACE_INCLUDE_DIRECTORIES $) + endforeach() + set_property( + TARGET "${targetName}" PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ${FIXED_INTERFACE_INCLUDE_DIRECTORIES} + ) +endfunction() + +function(executorch_add_prefix_to_public_headers targetName prefix) + get_property( + OLD_PUBLIC_HEADERS + TARGET "${targetName}" + PROPERTY PUBLIC_HEADER + ) + set(FIXED_PUBLIC_HEADERS) + foreach(header ${OLD_PUBLIC_HEADERS}) + list(APPEND FIXED_PUBLIC_HEADERS "${prefix}${header}") + endforeach() + set_property( + TARGET "${targetName}" PROPERTY PUBLIC_HEADER ${FIXED_PUBLIC_HEADERS} + ) +endfunction() diff --git a/tools/cmake/cmake_deps.toml b/tools/cmake/cmake_deps.toml index 2f8dc4825d4..044f673f075 100644 --- a/tools/cmake/cmake_deps.toml +++ b/tools/cmake/cmake_deps.toml @@ -509,9 +509,11 @@ deps = [ "executorch_core", "extension_data_loader", "extension_flat_tensor", + "extension_llm_runner", "extension_module", "extension_tensor", "extension_threadpool", + "extension_tokenizers", "kernels_util_all_deps", "optimized_cpublas", "portable_kernels", diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index 5a92dcbf2ec..d87d3693ad8 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -24,7 +24,9 @@ # the contract of exposing these CMake variables. cmake_minimum_required(VERSION 3.24) -include("${CMAKE_CURRENT_LIST_DIR}/Utils.cmake") + +include(CMakeFindDependencyMacro) +find_package(tokenizers CONFIG) set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..") set(required_lib_list executorch executorch_core portable_kernels) @@ -35,29 +37,22 @@ set(EXECUTORCH_INCLUDE_DIRS ) foreach(lib ${required_lib_list}) set(lib_var "LIB_${lib}") - add_library(${lib} STATIC IMPORTED) find_library( ${lib_var} ${lib} HINTS "${_root}/lib" CMAKE_FIND_ROOT_PATH_BOTH ) - set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") - target_compile_definitions(${lib} INTERFACE C10_USING_CUSTOM_GENERATED_MACROS) - target_include_directories( - ${lib} - INTERFACE ${_root}/include - ${_root}/include/executorch/runtime/core/portable_type/c10 - ${_root}/lib - ) + if(NOT ${lib_var}) + set(EXECUTORCH_FOUND OFF) + return() + endif() list(APPEND EXECUTORCH_LIBRARIES ${lib}) endforeach() - -# If we reach here, ET required libraries are found. set(EXECUTORCH_FOUND ON) -target_link_libraries(executorch INTERFACE executorch_core) +include("${CMAKE_CURRENT_LIST_DIR}/ExecuTorchTargets.cmake") -set(lib_list +set(optional_lib_list flatccrt etdump bundled_program @@ -79,13 +74,6 @@ set(lib_list extension_threadpool extension_training xnnpack_backend - # Start XNNPACK Lib Deps - XNNPACK - xnnpack-microkernels-prod - kleidiai - # End XNNPACK Lib Deps - cpuinfo - pthreadpool vulkan_backend optimized_kernels optimized_portable_kernels @@ -97,105 +85,28 @@ set(lib_list quantized_ops_lib quantized_ops_aot_lib ) -foreach(lib ${lib_list}) - # Name of the variable which stores result of the find_library search - set(lib_var "LIB_${lib}") - find_library( - ${lib_var} ${lib} - HINTS "${_root}/lib" - CMAKE_FIND_ROOT_PATH_BOTH - ) - if(NOT ${lib_var}) - message("${lib} library is not found. - If needed rebuild with the proper options in CMakeLists.txt" - ) + +foreach(lib ${optional_lib_list}) + if(TARGET ${lib}) + list(APPEND EXECUTORCH_LIBRARIES ${lib}) else() - if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) - add_library(${lib} SHARED IMPORTED) - else() - # Building a share library on iOS requires code signing, so it's easier to - # keep all libs as static when CMAKE_TOOLCHAIN_IOS is used - add_library(${lib} STATIC IMPORTED) - endif() - set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") - target_include_directories( - ${lib} - INTERFACE ${_root}/include - ${_root}/include/executorch/runtime/core/portable_type/c10 - ${_root}/lib + message("${lib} library is not found. + If needed rebuild with the proper options in CMakeLists.txt" ) - 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 cpublas) - set_target_properties( - cpublas PROPERTIES INTERFACE_LINK_LIBRARIES - "extension_threadpool;eigen_blas" - ) -endif() -if(TARGET optimized_kernels) - set_target_properties( - optimized_kernels PROPERTIES INTERFACE_LINK_LIBRARIES - "executorch_core;cpublas;extension_threadpool" - ) -endif() - -if(TARGET coremldelegate) - set_target_properties( - coremldelegate PROPERTIES INTERFACE_LINK_LIBRARIES - "coreml_inmemoryfs;coreml_util" - ) -endif() - -if(TARGET etdump) - set_target_properties( - etdump PROPERTIES INTERFACE_LINK_LIBRARIES "flatccrt;executorch" - ) -endif() - -if(TARGET optimized_native_cpu_ops_lib) - if(TARGET optimized_portable_kernels) - set(_maybe_optimized_portable_kernels_lib optimized_portable_kernels) - else() - set(_maybe_optimized_portable_kernels_lib portable_kernels) - endif() - set_target_properties( - optimized_native_cpu_ops_lib - PROPERTIES INTERFACE_LINK_LIBRARIES - "optimized_kernels;${_maybe_optimized_portable_kernels_lib}" - ) -endif() -if(TARGET extension_threadpool) - target_compile_definitions(extension_threadpool INTERFACE ET_USE_THREADPOOL) - set_target_properties( - extension_threadpool PROPERTIES INTERFACE_LINK_LIBRARIES - "cpuinfo;pthreadpool" - ) -endif() - -set(shared_lib_list - # executorch -- size tests fail due to regression if we include this and I'm - # not sure it's needed. - optimized_native_cpu_ops_lib portable_ops_lib quantized_ops_lib - xnnpack_backend vulkan_backend quantized_ops_aot_lib +# The ARM baremetal size test's CMAKE_TOOLCHAIN_FILE apparently doesn't prevent +# our attempts to find_library(dl) from succeeding when building ExecuTorch, but +# that call finds the host system's libdl and there is no actual libdl available +# when building for the actual final baremetal. +get_property( + FIXED_EXECUTORCH_CORE_LINK_LIBRARIES + TARGET executorch_core + PROPERTY INTERFACE_LINK_LIBRARIES +) +list(REMOVE_ITEM FIXED_EXECUTORCH_CORE_LINK_LIBRARIES $) +set_property( + TARGET executorch_core PROPERTY INTERFACE_LINK_LIBRARIES + ${FIXED_EXECUTORCH_CORE_LINK_LIBRARIES} ) -foreach(lib ${shared_lib_list}) - if(TARGET ${lib}) - executorch_target_link_options_shared_lib(${lib}) - endif() -endforeach() - -if(TARGET xnnpack_backend) - if(TARGET kleidiai) - set(_deps "XNNPACK;xnnpack-microkernels-prod;kleidiai") - else() - set(_deps "XNNPACK;xnnpack-microkernels-prod") - endif() - set_target_properties( - xnnpack_backend PROPERTIES INTERFACE_LINK_LIBRARIES "${_deps}" - ) - executorch_target_link_options_shared_lib(xnnpack_backend) -endif() diff --git a/tools/cmake/preset/apple_common.cmake b/tools/cmake/preset/apple_common.cmake index 0928cd978dc..d58cc44a751 100644 --- a/tools/cmake/preset/apple_common.cmake +++ b/tools/cmake/preset/apple_common.cmake @@ -21,6 +21,8 @@ set_overridable_option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TENSOR ON) diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index b6626f0a513..551c69bc93e 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -79,6 +79,10 @@ define_overridable_option( define_overridable_option( EXECUTORCH_BUILD_EXTENSION_LLM_APPLE "Build the LLM Apple extension" BOOL OFF ) +define_overridable_option( + EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER "Build the LLM runner extension" BOOL + OFF +) define_overridable_option( EXECUTORCH_BUILD_EXTENSION_MODULE "Build the Module extension" BOOL OFF ) @@ -227,6 +231,16 @@ check_required_options_on( EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ) +check_required_options_on( + IF_ON EXECUTORCH_BUILD_EXTENSION_LLM_APPLE REQUIRES + EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER +) + +check_required_options_on( + IF_ON EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER REQUIRES + EXECUTORCH_BUILD_EXTENSION_LLM +) + check_required_options_on( IF_ON EXECUTORCH_BUILD_EXTENSION_MODULE REQUIRES EXECUTORCH_BUILD_EXTENSION_DATA_LOADER EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR @@ -256,6 +270,11 @@ check_required_options_on( IF_ON EXECUTORCH_BUILD_TESTS REQUIRES EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ) +check_required_options_on( + IF_ON EXECUTORCH_BUILD_XNNPACK REQUIRES EXECUTORCH_BUILD_CPUINFO + EXECUTORCH_BUILD_PTHREADPOOL +) + check_conflicting_options_on( IF_ON EXECUTORCH_BUILD_ARM_BAREMETAL CONFLICTS_WITH EXECUTORCH_BUILD_PTHREADPOOL diff --git a/tools/cmake/preset/llm.cmake b/tools/cmake/preset/llm.cmake index 3180c338acc..2cd890ee1a1 100644 --- a/tools/cmake/preset/llm.cmake +++ b/tools/cmake/preset/llm.cmake @@ -7,6 +7,8 @@ # keep sorted set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TENSOR ON) set_overridable_option(EXECUTORCH_BUILD_KERNELS_LLM ON)