diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e1e221d2a..fbe4068991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,8 @@ if(NOT EXECUTORCH_ENABLE_PROGRAM_VERIFICATION) add_definitions(-DET_ENABLE_PROGRAM_VERIFICATION=0) endif() -# -O2: Moderate opt. -ffunction-sections -fdata-sections: breaks function -# and data into sections so they can be properly gc'd. -s: strip symbol. +# -O2: Moderate opt. -ffunction-sections -fdata-sections: breaks function and +# data into sections so they can be properly gc'd. -s: strip symbol. # -fno-exceptions -fno-rtti: disables exceptions and runtime type. set(CMAKE_CXX_FLAGS_RELEASE "-O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti") @@ -136,8 +136,8 @@ option(EXECUTORCH_BUILD_XTENSA_EXAMPLE "Build the example targeted for the Xtensa Hifi4 DSP" OFF) # Build mps_executor_runner which depends on MPSGraph framework -option(EXECUTORCH_BUILD_MPS - "Build mps_executor_runner which depends on MPS" OFF) +option(EXECUTORCH_BUILD_MPS "Build mps_executor_runner which depends on MPS" + OFF) if(NOT BUCK2) set(BUCK2 buck2) @@ -198,17 +198,14 @@ endif() # libraries that it uses, like `gflags`. Disabling this can be helpful when # cross-compiling, but some required tools that would have been built need to be # provided directly (via, for example, FLATC_EXECUTABLE). -cmake_dependent_option( - EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets." ON - "NOT CMAKE_TOOLCHAIN_IOS" OFF) - +cmake_dependent_option(EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets." + ON "NOT CMAKE_TOOLCHAIN_IOS" OFF) # # flatc: Flatbuffer commandline tool to generate .h files from .fbs files # -cmake_dependent_option( - EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON - "NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF) +cmake_dependent_option(EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON + "NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF) if(EXECUTORCH_BUILD_FLATC) if(FLATC_EXECUTABLE) @@ -274,26 +271,25 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable) # gflags: Commandline flag host library. # cmake_dependent_option(EXECUTORCH_BUILD_GFLAGS "Build the gflags library." ON - EXECUTORCH_BUILD_HOST_TARGETS OFF) + EXECUTORCH_BUILD_HOST_TARGETS OFF) if(EXECUTORCH_BUILD_GFLAGS) add_subdirectory(third-party/gflags) endif() - -# Install `executorch` library as well as `executorch-config.cmake` -# under ${CMAKE_INSTALL_PREFIX}/ +# Install `executorch` library as well as `executorch-config.cmake` under +# ${CMAKE_INSTALL_PREFIX}/ install( TARGETS executorch DESTINATION lib - INCLUDES DESTINATION ${_common_include_directories} -) + INCLUDES + DESTINATION ${_common_include_directories}) install(FILES build/executorch-config.cmake DESTINATION lib/cmake/ExecuTorch) # # executor_runner: Host tool that demonstrates program execution. # -cmake_dependent_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER - "Build the executor_runner executable" ON +cmake_dependent_option( + EXECUTORCH_BUILD_EXECUTOR_RUNNER "Build the executor_runner executable" ON EXECUTORCH_BUILD_HOST_TARGETS OFF) if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. @@ -324,6 +320,15 @@ if(EXECUTORCH_BUILD_ANDROID_DEMO_APP_JNI) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/demo-apps/android/jni) endif() +if(EXECUTORCH_BUILD_SDK) + set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER + ON + CACHE BOOL "EXECUTORCH_BUILD_EXTENSION_DATA_LOADER" FORCE) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/util) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/sdk) +endif() + option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER "Build the extension/data_loader directory" OFF) if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER) @@ -362,8 +367,7 @@ if(EXECUTORCH_BUILD_COREML) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml) else() message( - FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain" - ) + FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain") endif() endif() @@ -377,12 +381,6 @@ if(EXECUTORCH_BUILD_SIZE_TEST) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) endif() -if(EXECUTORCH_BUILD_SDK) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/util) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/sdk) -endif() - if(EXECUTORCH_BUILD_EXAMPLES) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples) endif() diff --git a/backends/apple/mps/CMakeLists.txt b/backends/apple/mps/CMakeLists.txt index 2752a14fa1..1bbd905c5f 100644 --- a/backends/apple/mps/CMakeLists.txt +++ b/backends/apple/mps/CMakeLists.txt @@ -1,6 +1,6 @@ # -# Copyright (c) 2023 Apple Inc. All rights reserved. -# Provided subject to the LICENSE file in the top level directory. +# Copyright (c) 2023 Apple Inc. All rights reserved. Provided subject to the +# LICENSE file in the top level directory. # cmake_minimum_required(VERSION 3.19) @@ -25,6 +25,6 @@ set(_common_include_directories ${EXECUTORCH_ROOT}/..) list(TRANSFORM _mps_backend__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(mpsdelegate ${_mps_backend__srcs}) -target_link_libraries(mpsdelegate PRIVATE ${_executor_runner_libs}) -target_include_directories(mpsdelegate - PUBLIC ${_common_include_directories}) +target_link_libraries(mpsdelegate PRIVATE baundled_program + ${_executor_runner_libs}) +target_include_directories(mpsdelegate PUBLIC ${_common_include_directories}) diff --git a/backends/apple/mps/setup.md b/backends/apple/mps/setup.md index a30f6fa4b6..d11d8a03f6 100644 --- a/backends/apple/mps/setup.md +++ b/backends/apple/mps/setup.md @@ -62,7 +62,7 @@ python3 -m unittest backends.apple.mps.test.test_mps --verbose -k mv3 ```bash # Build the mps_executor_runner -rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DBUCK2=/tmp/buck2 —trace .. && cmake --build . && cd .. +rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DEXECUTORCH_BUILD_SDK=ON -DBUCK2=/tmp/buck2 —trace .. && cmake --build . && cd .. ``` ***Step 2***. Run the model using the `mps_executor_runner`. diff --git a/examples/apple/mps/CMakeLists.txt b/examples/apple/mps/CMakeLists.txt index 9d37b4115b..165ae3209c 100644 --- a/examples/apple/mps/CMakeLists.txt +++ b/examples/apple/mps/CMakeLists.txt @@ -46,7 +46,7 @@ add_executable(mps_executor_runner ${_mps_executor_runner__srcs}) target_include_directories( mps_executor_runner INTERFACE ${CMAKE_BINARY_DIR}/schema/include/ ${EXECUTORCH_ROOT}/third-party/flatbuffers/include) -target_link_libraries(mps_executor_runner program_schema +target_link_libraries(mps_executor_runner bundled_program program_schema ${_executor_runner_libs} ${mps_executor_runner_libs}) target_compile_options(mps_executor_runner PUBLIC ${_common_compile_options}) diff --git a/examples/apple/mps/README.md b/examples/apple/mps/README.md index 848288ff65..a1451aa412 100644 --- a/examples/apple/mps/README.md +++ b/examples/apple/mps/README.md @@ -28,7 +28,7 @@ Once we have the model binary file, then let's run it with the ExecuTorch runtim ```bash # Build the mps_executor_runner -(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DBUCK2=/tmp/buck2 —trace .. && cd ..) +(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DEXECUTORCH_BUILD_SDK=ON -DBUCK2=/tmp/buck2 —trace .. && cd ..) cmake --build cmake-out -j9 # Run the mv2 generated model using the mps_executor_runner diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 9fa9d62d84..be90065b32 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -30,20 +30,25 @@ if(NOT EXECUTORCH_ROOT) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) endif() +if(NOT FLATC_EXECUTABLE) + set(FLATC_EXECUTABLE flatc) +endif() + # Paths to headers generated from the .fbs files. set(_etdump_schemas # etdump_schema_flatcc.fbs scalar_type.fbs) -set(_etdump_schema__srcs - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_schema_flatcc.fbs - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/scalar_type.fbs) - +set(_etdump_schema_names "etdump_schema_flatcc.fbs" "scalar_type.fbs") +set(_bundled_input_schema_names "bundled_program_schema.fbs" "scalar_type.fbs") -set(_bundled_program_schema_dir - ${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema) +foreach(schema_file ${_etdump_schema_names}) + list(APPEND _etdump_schema__srcs + "${CMAKE_CURRENT_SOURCE_DIR}/etdump/${schema_file}") +endforeach() -set(_bundled_program_schema__srcs - ${_bundled_program_schema_dir}/bundled_program_schema.fbs - ${_bundled_program_schema_dir}/scalar_type.fbs) +foreach(schema_file ${_bundled_input_schema_names}) + list(APPEND _bundled_program_schema__srcs + "${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema/${schema_file}") +endforeach() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc ${CMAKE_BINARY_DIR}/third-party/flatcc) @@ -53,6 +58,7 @@ include(ExternalProject) # The include directory that will contain the generated schema headers. set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/include") +set(_bundled_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/bundled_program") # Add the host project # lint_cmake: -readability/wonkycase @@ -65,30 +71,33 @@ ExternalProject_Add( ) set(_etdump_schema__outputs) -foreach(fbs_file ${_etdump_schema__srcs}) - string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}") +foreach(fbs_file ${_etdump_schema_names}) + string(REGEX REPLACE "[.]fbs$" "_reader.h" generated "${fbs_file}") + list(APPEND _etdump_schema__outputs + "${_program_schema__include_dir}/executorch/sdk/etdump/${generated}") + string(REGEX REPLACE "[.]fbs$" "_builder.h" generated "${fbs_file}") list(APPEND _etdump_schema__outputs - "${_program_schema__include_dir}/${generated}") + "${_program_schema__include_dir}/executorch/sdk/etdump/${generated}") endforeach() +# lint_cmake: -linelength set(_bundled_program_schema__outputs) -foreach(fbs_file ${_bundled_program_schema__srcs}) +foreach(fbs_file ${_bundled_input_schema_names}) string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}") - list(APPEND _bundled_program_schema__outputs - "${_program_schema__include_dir}/${generated}") + list( + APPEND + _bundled_program_schema__outputs + "${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema/${generated}" + ) endforeach() add_library(etdump_schema INTERFACE ${_etdump_schema__outputs}) -add_library(bundled_program_schema - INTERFACE ${_bundled_program_schema__outputs}) +add_library(bundled_program_schema INTERFACE + ${_bundled_program_schema__outputs}) # Ensure the host tool is built before the main project add_dependencies(etdump_schema flatcc_cli) -message("Debug _etdump_schema__outputs: ${_etdump_schema__outputs}") -message("Debug _bundled_program_schema__outputs:\ - ${_bundled_program_schema__outputs}") - file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/sdk/etdump) file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/sdk/bundled_program) @@ -104,23 +113,35 @@ add_custom_command( COMMENT "Generating etdump headers" VERBATIM) +add_library(etdump ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_flatcc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/etdump/emitter.cpp) + +target_link_libraries( + etdump + PUBLIC etdump_schema + PRIVATE executorch) + add_custom_command( OUTPUT ${_bundled_program_schema__outputs} COMMAND - ${CMAKE_SOURCE_DIR}/third-party/flatcc/bin/flatcc -cwr -o - ${_program_schema__include_dir}/executorch/sdk/bundled_program + ${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o + "${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema" ${_bundled_program_schema__srcs} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/sdk - DEPENDS flatcc_project + DEPENDS ${FLATC_EXECUTABLE} ${_bundled_program_schema__srcs} COMMENT "Generating bundled_program headers" VERBATIM) -target_include_directories( - etdump PUBLIC ${_program_schema__include_dir} - ${CMAKE_SOURCE_DIR}/third-party/flatcc/include) +# add_library(bundled_program INTERFACE ${_bundled_program_schema__outputs}) +add_library(bundled_program + ${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/bundled_program.cpp) +target_link_libraries(bundled_program executorch bundled_program_schema) set_target_properties(bundled_program PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( - bundled_program - INTERFACE ${_program_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include) + bundled_program PUBLIC ${_bundled_schema__include_dir} + ${EXECUTORCH_ROOT}/third-party/flatbuffers/include) + +target_include_directories( + etdump PUBLIC ${_program_schema__include_dir} + ${CMAKE_SOURCE_DIR}/third-party/flatcc/include) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 9784c6f442..2e41cd717f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,8 +3,3 @@ # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. - -add_library(bundled_program - ${CMAKE_CURRENT_SOURCE_DIR}/bundled_program_verification.cpp) - -target_link_libraries(bundled_program executorch bundled_schema)