Skip to content

Commit f2252a6

Browse files
Avoid duplicate ops registration in macOS executor_runner (#19804)
### Summary The macOS preset builds `executor_runner` with optimized kernels enabled, so the top-level runner link logic already selects `optimized_native_cpu_ops_lib` as the ops registration library. `coremldelegate` was also linking `portable_ops_lib` and `portable_kernels` through `EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER`. Since `coremldelegate` is included through `executorch_backends`, `executor_runner` could force-load both `portable_ops_lib` and `optimized_native_cpu_ops_lib`. Their generated static initializers register overlapping ATen kernels, causing `executor_runner` to abort before `main()` with a duplicate registration error. This removes the CoreML-side ops-lib link and removes the obsolete `EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER` preset option. The CoreML executor runner under `examples/apple/coreml/executor_runner` is not a CMake target, so this option was not actually building that runner. ### Compatibility The `coreml_executor_runner` built by `examples/apple/coreml/scripts/build_executor_runner.sh` is unaffected. That script builds the relevant CMake targets, then stages `libportable_ops_lib.a` and `libportable_kernels.a` into `examples/apple/coreml/executor_runner/libraries/`. The Xcode project links those archives directly, independent of `libcoremldelegate.a`'s internal link list, so the Xcode-built runner keeps working through its own link line. Other CMake consumers of `coremldelegate` already select an ops registration library independently before force-loading `coremldelegate`, so they are unaffected by removing the private portable-kernel link from the delegate. Non-Apple platforms do not build `coremldelegate` because `backends/apple/coreml/CMakeLists.txt` is gated by `if(APPLE)`. The iOS and iOS-simulator presets never set the removed option. ### Test plan ```bash cmake --preset macos cmake --build cmake-out --target executor_runner --config Debug -j ./cmake-out/Debug/executor_runner cmake --build cmake-out --target coremldelegate --config Debug -j ``` Verified the `executor_runner` link line no longer contains `libportable_ops_lib.a` or unprefixed `libportable_kernels.a`. `liboptimized_native_cpu_ops_lib.a` is still force-loaded. `liboptimized_portable_kernels.a` is still present, which is expected because it is one of `optimized_native_cpu_ops_lib`'s kernel libraries. Running without `--model_path` now reaches `main()`, resets the threadpool, and fails only on the expected missing `model.pte` path instead of aborting during static kernel registration. Authored with Claude. cc @larryliu0820 @GregoryComer @kimishpatel @YifanShenSZ @cymbalrush @metascroy Co-authored-by: Digant Desai <digantdesai@meta.com>
1 parent 3a6e400 commit f2252a6

3 files changed

Lines changed: 0 additions & 11 deletions

File tree

backends/apple/coreml/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,6 @@ if(APPLE)
230230

231231
executorch_target_link_options_shared_lib(coremldelegate)
232232

233-
if(EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER)
234-
target_link_libraries(
235-
coremldelegate PRIVATE portable_ops_lib portable_kernels
236-
)
237-
endif()
238-
239233
target_compile_options(
240234
coremldelegate PRIVATE -fobjc-arc -fno-exceptions -x objective-c++
241235
-Wno-null-character -Wno-receiver-expr

tools/cmake/preset/default.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ define_overridable_option(
194194
define_overridable_option(
195195
EXECUTORCH_BUILD_VGF "Build the Arm VGF backend" BOOL OFF
196196
)
197-
define_overridable_option(
198-
EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER "Build CoreML executor runner." BOOL
199-
OFF
200-
)
201197
define_overridable_option(
202198
EXECUTORCH_BUILD_WASM "Build the ExecuTorch JavaScript API" BOOL OFF
203199
)

tools/cmake/preset/macos.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/apple_common.cmake)
99
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL ON)
1010
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON)
1111
set_overridable_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER ON)
12-
set_overridable_option(EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER ON)

0 commit comments

Comments
 (0)