Skip to content

Fix SDK CMake #1271

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

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 25 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions backends/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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})
2 changes: 1 addition & 1 deletion backends/apple/mps/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion examples/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion examples/apple/mps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 51 additions & 30 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
5 changes: 0 additions & 5 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)