From 45d5b3d2b30f77b54952b1b6308667e12e597905 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 24 Apr 2024 23:24:24 -0700 Subject: [PATCH 1/4] Extend setup cmake ability Summary: For executorch users, we see a common pattern that they have to: ```bash bash install_requirements.sh --pybind xnnpack cmake -S . -Bcmake-out ... cmake --build ... ``` This is repeating cmake build twice, the first one is inside setup.py. Here I'm adding a way to allow setup.py to install the libraries seperately, by passing `CMAKE_ARGS` and `CMAKE_BUILD_ARGS` into setup.py, through `install_requirements.sh`. After this change, user can do: ```bash export CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX= \ -DEXECUTORCH_BUILD_OPTIMIZED=ON \ ..." export CMAKE_BUILD_ARGS="--target install" bash install_requirements.sh --pybind xnnpack ``` Then we should be able to find `libxnnpack.a` `liboptimized_ops_lib.a` etc under install dir. Test Plan: Reviewers: Subscribers: Tasks: Tags: --- extension/data_loader/CMakeLists.txt | 2 +- install_requirements.sh | 2 +- setup.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extension/data_loader/CMakeLists.txt b/extension/data_loader/CMakeLists.txt index 90008b1981c..1a0ec7b9cc1 100644 --- a/extension/data_loader/CMakeLists.txt +++ b/extension/data_loader/CMakeLists.txt @@ -25,6 +25,6 @@ target_compile_options(extension_data_loader PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_data_loader - DESTINATION ${CMAKE_BINARY_DIR}/lib + DESTINATION lib INCLUDES DESTINATION ${_common_include_directories}) diff --git a/install_requirements.sh b/install_requirements.sh index 966ccd8a9be..d541a30b221 100755 --- a/install_requirements.sh +++ b/install_requirements.sh @@ -27,7 +27,6 @@ fi # Parse options. EXECUTORCH_BUILD_PYBIND=OFF -CMAKE_ARGS="" for arg in "$@"; do case $arg in @@ -110,4 +109,5 @@ $PIP_EXECUTABLE install --extra-index-url "${TORCH_NIGHTLY_URL}" \ EXECUTORCH_BUILD_PYBIND="${EXECUTORCH_BUILD_PYBIND}" \ CMAKE_ARGS="${CMAKE_ARGS}" \ + CMAKE_BUILD_ARGS="${CMAKE_BUILD_ARGS}" \ $PIP_EXECUTABLE install . --no-build-isolation -v diff --git a/setup.py b/setup.py index 6591123d5e6..413a028e1e2 100644 --- a/setup.py +++ b/setup.py @@ -398,6 +398,14 @@ def run(self): if "CMAKE_ARGS" in os.environ: cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] + # Allow adding extra build args through the environment. Used by some + # tests and demos to expand the set of targets included in the pip + # package. + if "CMAKE_BUILD_ARGS" in os.environ: + build_args += [ + item for item in os.environ["CMAKE_BUILD_ARGS"].split(" ") if item + ] + # Put the cmake cache under the temp directory, like # "pip-out/temp./cmake-out". cmake_cache_dir = os.path.join(repo_root, self.build_temp, "cmake-out") From e3ec7b1eb42acee2a659649f94302492b64d94dd Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 24 Apr 2024 23:52:56 -0700 Subject: [PATCH 2/4] Find libcustom_ops.a Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- build/executorch-config.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/build/executorch-config.cmake b/build/executorch-config.cmake index 60c8ebda5e6..65df7de12a0 100644 --- a/build/executorch-config.cmake +++ b/build/executorch-config.cmake @@ -39,6 +39,7 @@ set(lib_list qnn_executorch_backend portable_ops_lib extension_module xnnpack_backend XNNPACK cpuinfo pthreadpool vulkan_backend optimized_kernels cpublas eigen_blas optimized_ops_lib optimized_native_cpu_ops_lib quantized_kernels quantized_ops_lib + custom_ops ) foreach(lib ${lib_list}) # Name of the variable which stores result of the find_library search From 78bb9bb1dc4e58ec4a6cfc89f9614fe0217f1a6e Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Thu, 25 Apr 2024 00:51:22 -0700 Subject: [PATCH 3/4] revert custom_ops change Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- build/executorch-config.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/build/executorch-config.cmake b/build/executorch-config.cmake index 65df7de12a0..60c8ebda5e6 100644 --- a/build/executorch-config.cmake +++ b/build/executorch-config.cmake @@ -39,7 +39,6 @@ set(lib_list qnn_executorch_backend portable_ops_lib extension_module xnnpack_backend XNNPACK cpuinfo pthreadpool vulkan_backend optimized_kernels cpublas eigen_blas optimized_ops_lib optimized_native_cpu_ops_lib quantized_kernels quantized_ops_lib - custom_ops ) foreach(lib ${lib_list}) # Name of the variable which stores result of the find_library search From b9500e262a5a71b6adcddca80088a84a6cc177b2 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Thu, 25 Apr 2024 09:28:22 -0700 Subject: [PATCH 4/4] Separate out data loader changes Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- extension/data_loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/data_loader/CMakeLists.txt b/extension/data_loader/CMakeLists.txt index 1a0ec7b9cc1..90008b1981c 100644 --- a/extension/data_loader/CMakeLists.txt +++ b/extension/data_loader/CMakeLists.txt @@ -25,6 +25,6 @@ target_compile_options(extension_data_loader PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_data_loader - DESTINATION lib + DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories})