Skip to content

Commit 502db64

Browse files
authored
Create a pybind preset (#10932)
### Summary In this diff we create a `pybind` preset that is copied with configurations from [setup.py](https://github.com/pytorch/executorch/blob/7175ca420dc5a173f8635da976457bf6f17bbbc1/setup.py). In upcoming diffs, we will completely gut setup.py and point directly to this preset. ### Test plan ``` $ cmake --list-presets Available configure presets: "macos-arm64" - Build everything buildable on macOS arm64 "pybind" - Build pybindings exported in the wheel ``` ``` $ cmake --preset pybind && cmake --build cmake-out --parallel ``` cc @larryliu0820
1 parent d0848ca commit 502db64

File tree

6 files changed

+91
-23
lines changed

6 files changed

+91
-23
lines changed

CMakePresets.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
{
1717
"name": "macos-arm64",
18+
"displayName": "Build everything buildable on macOS arm64",
1819
"inherits": ["common"],
1920
"generator": "Xcode",
2021
"cacheVariables": {
@@ -28,6 +29,20 @@
2829
"type": "equals",
2930
"rhs": "Darwin"
3031
}
32+
},
33+
{
34+
"name": "pybind",
35+
"displayName": "Build pybindings exported in the wheel",
36+
"inherits": ["common"],
37+
"cacheVariables": {
38+
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/pybind.cmake",
39+
"CMAKE_OSX_DEPLOYMENT_TARGET": "10.15"
40+
},
41+
"condition": {
42+
"type": "inList",
43+
"string": "${hostSystemName}",
44+
"list": ["Darwin", "Linux", "Windows"]
45+
}
3146
}
3247
]
3348
}

backends/xnnpack/CMakeLists.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ endif()
2525

2626
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2727

28-
# NB: Enabling this will serialize execution of delegate instances Keeping this
29-
# OFF by default to maintain existing behavior, to be revisited.
30-
option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE
31-
"Enable workspace sharing across different delegate instances" ON
32-
)
33-
# Keeping this OFF by default due to regressions in decode and model load with
34-
# kleidi kernels
35-
option(EXECUTORCH_XNNPACK_ENABLE_KLEIDI "Enable Arm Kleidi kernels" OFF)
36-
37-
# Turning this on cache weights between partitions and methods. If weights
38-
# are shared across methods/partitions then this can reduce load time and
39-
# memory usage
40-
41-
# Keeping this off maintains existing behavior. Turning this on serializes
42-
# execution and initialization of delegates, to be revisited
43-
option(EXECUTORCH_XNNPACK_ENABLE_WEIGHT_CACHE
44-
"Enable weights cache to cache and manage all packed weights" OFF)
45-
4628
if(EXECUTORCH_XNNPACK_ENABLE_WEIGHT_CACHE)
4729
add_definitions(-DENABLE_XNNPACK_WEIGHTS_CACHE)
4830
endif()

kernels/quantized/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
# ~~~
1111
cmake_minimum_required(VERSION 3.19)
1212

13-
option(EXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT
14-
"Build the optimized ops library for AOT export usage" OFF
15-
)
16-
1713
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1814
if(NOT CMAKE_CXX_STANDARD)
1915
set(CMAKE_CXX_STANDARD 17)
@@ -91,7 +87,13 @@ if(NOT CMAKE_GENERATOR STREQUAL "Xcode"
9187
# pybindings.
9288
if(TARGET portable_lib)
9389
add_library(quantized_pybind_kernels_lib ${_quantized_kernels__srcs})
94-
target_link_libraries(quantized_pybind_kernels_lib PRIVATE portable_lib)
90+
target_link_libraries(
91+
quantized_pybind_kernels_lib
92+
PRIVATE
93+
portable_lib
94+
executorch_core
95+
kernels_util_all_deps
96+
)
9597
target_compile_options(
9698
quantized_pybind_kernels_lib PUBLIC ${_common_compile_options}
9799
)

runtime/executor/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ et_cxx_test(
148148
portable_kernels
149149
extension_data_loader
150150
extension_runner_util
151+
program_schema
151152
)
152153
add_dependencies(tensor_parser_test generated_pte_files)
153154
set_property(TEST tensor_parser_test PROPERTY ENVIRONMENT ${test_env})

tools/cmake/preset/default.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ define_overridable_option(
7474
"Build the custom ops lib for AOT"
7575
BOOL OFF
7676
)
77+
define_overridable_option(
78+
EXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT
79+
"Build the optimized ops library for AOT export usage"
80+
BOOL OFF
81+
)
7782
define_overridable_option(
7883
EXECUTORCH_BUILD_EXTENSION_DATA_LOADER
7984
"Build the Data Loader extension"
@@ -109,6 +114,11 @@ define_overridable_option(
109114
"Build the training extension"
110115
BOOL OFF
111116
)
117+
define_overridable_option(
118+
EXECUTORCH_BUILD_EXTENSION_APPLE
119+
"Build the Apple extension"
120+
BOOL OFF
121+
)
112122
define_overridable_option(
113123
EXECUTORCH_BUILD_MPS
114124
"Build the MPS backend"
@@ -227,13 +237,41 @@ define_overridable_option(
227237
set(_default_executorch_build_executor_runner ON)
228238
if(APPLE AND "${SDK_NAME}" STREQUAL "iphoneos")
229239
set(_default_executorch_build_executor_runner OFF)
240+
elseif(DEFINED EXECUTORCH_BUILD_PRESET_FILE)
241+
set(_default_executorch_build_executor_runner OFF)
230242
endif()
231243
define_overridable_option(
232244
EXECUTORCH_BUILD_EXECUTOR_RUNNER
233245
"Build the executor_runner executable"
234246
BOOL ${_default_executorch_build_executor_runner}
235247
)
236248

249+
# NB: Enabling this will serialize execution of delegate instances Keeping this
250+
# OFF by default to maintain existing behavior, to be revisited.
251+
define_overridable_option(
252+
EXECUTORCH_XNNPACK_SHARED_WORKSPACE
253+
"Enable workspace sharing across different delegate instances"
254+
BOOL ON
255+
)
256+
# Keeping this OFF by default due to regressions in decode and model load with
257+
# kleidi kernels
258+
define_overridable_option(
259+
EXECUTORCH_XNNPACK_ENABLE_KLEIDI
260+
"Enable Arm Kleidi kernels"
261+
BOOL OFF
262+
)
263+
# Turning this on cache weights between partitions and methods. If weights
264+
# are shared across methods/partitions then this can reduce load time and
265+
# memory usage
266+
#
267+
# Keeping this off maintains existing behavior. Turning this on serializes
268+
# execution and initialization of delegates, to be revisited
269+
define_overridable_option(
270+
EXECUTORCH_XNNPACK_ENABLE_WEIGHT_CACHE
271+
"Enable weights cache to cache and manage all packed weights"
272+
BOOL OFF
273+
)
274+
237275
# MARK: - Validations
238276
# At this point all the options should be configured with their final value.
239277

tools/cmake/preset/pybind.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set_overridable_option(EXECUTORCH_BUILD_PYBIND ON)
8+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON)
9+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT ON)
10+
# Enable logging even when in release mode. We are building for desktop, where
11+
# saving a few kB is less important than showing useful error information to
12+
# users.
13+
set_overridable_option(EXECUTORCH_ENABLE_LOGGING ON)
14+
set_overridable_option(EXECUTORCH_LOG_LEVEL Info)
15+
set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON)
16+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TENSOR ON)
17+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON)
18+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM ON)
19+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT ON)
20+
21+
22+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
23+
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
24+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
25+
# Linux-specific code here
26+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WIN32")
27+
# Windows or other OS-specific code here
28+
else()
29+
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME for pybind: ${CMAKE_SYSTEM_NAME}")
30+
endif()

0 commit comments

Comments
 (0)