Skip to content

[CoreAI] Integrate the delegate execute path - #23393

Draft
metascroy wants to merge 1 commit into
coreai-v2/05a-load-coordinatorfrom
coreai-v2/05b-sdk-delegate
Draft

metascroy wants to merge 1 commit into
coreai-v2/05a-load-coordinatorfrom
coreai-v2/05b-sdk-delegate

Conversation

@metascroy

@metascroy metascroy commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Wires the Core AI bridge into an ExecuTorch BackendInterface so CoreAIBackend can load and run models (runtime/coreai_backend.mm).

  • init parses the manifest, checks the OS floor, selects the platform/architecture assets, acquires a prepared model through the load coordinator and binds the named function with ordered inputs/outputs.
  • execute validates dtype (FP16/FP32), CPU storage, default dim order and contiguity, borrows input bytes without copying, then validates and resizes every output before copying any results.
  • init and execute block their calling thread on Swift concurrency work, so the README tells callers not to invoke them from Swift async code.
  • Build: backends/apple/coreai/CMakeLists.txt builds coreaidelegate (static, or shared against executorch_shared) from the backend sources plus coreai_bridge_obj, linking coreai_swift with the C++ linker so ExecuTorch's C/C++ options never reach swiftc.
  • Tests:
    • The fake bridge gains function binding, sessions, execution and the C entry points the backend calls, so the real backend runs in coreai_host_test (delegate suite).
    • coreai_runtime_smoke checks final linkage, registration retention and availability. With EXECUTORCH_BUILD_TESTS=ON it is built and registered with CTest; otherwise it stays out of the default build.
  • README: execution semantics, device-architecture selection, the default assets root, "Runtime options", and delegate linkage in "Building".
  • Changes outside backends/apple/coreai are CMake only and only take effect when EXECUTORCH_BUILD_COREAI=ON:
    • tools/cmake/preset/default.cmake: EXECUTORCH_BUILD_COREAI requires the data loader extension.
    • CMakeLists.txt: add coreaidelegate to the backend list.

Stack: 7 of 9, based on #23392. Review only this PR's commit. Next: #23394.

Test plan: built locally for macOS 27.0; ctest -N lists coreai_host_test, coreai_swift_bridge_test and coreai_runtime_smoke, which the Core AI workflow runs on the macOS 27 runner. The smoke binary needs OS 27, so it only runs there (first CI run of it). lintrunner is clean.

@pytorch-bot

pytorch-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23393

Note: Links to docs will display an error until the docs builds have been completed.

❌ 8 Cancelled Jobs, 3 Pending, 3 Unclassified Failures

As of commit a6f16ff with merge base 0b3d26d (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 3, 2026
@metascroy
metascroy force-pushed the coreai-v2/05b-sdk-delegate branch from c14c6ea to 836b175 Compare October 4, 2026 19:48
@metascroy
metascroy force-pushed the coreai-v2/05a-load-coordinator branch from 2f63441 to 12fd39f Compare October 4, 2026 19:48
Summary:
Wire the Core AI bridge into an ExecuTorch `BackendInterface` so
`CoreAIBackend` can load and run models.

- `runtime/coreai_backend.mm`: the `BackendInterface`. `init` parses the
  manifest, checks the OS floor, selects the platform/architecture assets,
  acquires a prepared model through the load coordinator and binds the named
  function with ordered inputs/outputs. `execute` validates dtype (FP16/FP32),
  CPU storage, default dim order and contiguity, borrows input bytes without
  copying, then validates and resizes every output before copying any results.
- Build: `backends/apple/coreai/CMakeLists.txt` builds `coreaidelegate`
  (static, or shared against `executorch_shared`) from the backend sources
  plus the `coreai_bridge_obj` objects, and links `coreai_swift`. The delegate
  and its test consumers link with the C++ linker, so ExecuTorch's C/C++
  compile options never reach swiftc.
- Tests: the fake bridge gains function binding, sessions and execution, plus
  the C entry points the backend calls, so the real backend runs in
  `coreai_host_test`. `coreai_runtime_smoke` checks final linkage, registration
  retention and availability; with `EXECUTORCH_BUILD_TESTS=ON` it is built and
  registered with CTest, otherwise it is excluded from the default build.
- README: execution semantics, device-architecture selection, the default
  assets root, "Runtime options", and delegate linkage in "Building".

`init` and `execute` block their calling thread on Swift concurrency work, so
the README tells callers not to invoke them from Swift `async` code.

Changes outside `backends/apple/coreai` are CMake only and, like the other
backends, only take effect when `EXECUTORCH_BUILD_COREAI=ON`:
- `tools/cmake/preset/default.cmake`: `EXECUTORCH_BUILD_COREAI` now requires
  the data loader extension.
- `CMakeLists.txt`: add `coreaidelegate` to the backend list.

Test Plan:
```
# Local: configure and build only
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=27.0 -DEXECUTORCH_BUILD_COREAI=ON \
  -DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
cmake --build build --target backends/apple/coreai/all
# CI (macOS 27 runner, .github/workflows/coreai.yml)
ctest --test-dir build/backends/apple/coreai --output-on-failure --no-tests=error
```
CTest runs `coreai_host_test` (adding the delegate suite),
`coreai_swift_bridge_test` and `coreai_runtime_smoke`. The smoke binary needs
OS 27, so locally it is built but not run.
@metascroy
metascroy force-pushed the coreai-v2/05b-sdk-delegate branch from 836b175 to a6f16ff Compare October 5, 2026 03:14
@metascroy
metascroy force-pushed the coreai-v2/05a-load-coordinator branch from 12fd39f to 1beeef8 Compare October 5, 2026 03:14

This branch was successfully deployed

1 active deployment
cadence — a6f16fff Deployed Oct 5, 2026 by metascroy via hifi-op-test / hifi4 #31509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant