Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23391
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 66fd8b0 with merge base 61ec450 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
9d457ae to
84780b8
Compare
dae7df4 to
756e906
Compare
|
@claude review this PR |
|
Claude finished @metascroy's task in 2m 27s —— View job This PR adds the Swift and Objective-C bridge to the Core AI SDK, plus the CMake packaging for it. The main problem is that the runtime availability API can't do its job: the bridge objects are built with an OS 27 minimum and CoreAI is linked strongly, so Detailed reviewPR Review: #23391SummaryThis PR adds the private Swift and Objective-C bridge to the Core AI SDK and its CMake/package plumbing. The tensor copy, overflow checks and error mapping look correct. The issues below are mostly about how the bridge links and how its contract is documented. API Design
Thread Safety
Infrastructure
Testing
Code Quality
RecommendationNeeds Discussion: the main question is whether the bridge should be weak-linked so that |
Summary: Add the private bridge between ExecuTorch's Objective-C++ code and the Swift `CoreAI` framework, and package it for CMake consumers. No ExecuTorch delegate is added yet; a later commit wires this bridge into `CoreAIBackend`. - `runtime/ETCoreAIBridge.h`: Objective-C protocols for model acquisition, prepared models, sessions and tensor transfer, plus availability, device architecture and loader factory entry points. - `runtime/ETCoreAIModel.swift` (module `CoreAIBridge`): restore models from bookmarks, specialize source bundles with the persistent default SDK cache, bind named functions with ordered inputs/outputs and evict cache entries. Asynchronous SDK calls run in detached tasks and report through completion blocks; function binding completes synchronously. Only an SDK nil result is a cache miss; thrown errors keep their underlying cause. - Inputs are borrowed from caller storage through Core AI raw views; only shape metadata is copied. Outputs use one `memcpy` for dense row-major arrays and fall back to strided copies otherwise. - `runtime/ETCoreAITensor.mm`, `runtime/coreai_bridge.mm`: tensor wrappers and the C entry points. They build as the private `coreai_bridge_obj` object library so the delegate can absorb them and host tests can substitute a fake bridge. - Build: `backends/apple/coreai/CMakeLists.txt` requires CMake 3.31 and the Ninja or Xcode generator, keeps ExecuTorch's numeric preprocessor definitions away from swiftc, applies an OS 27 minimum to Core AI targets only, and builds `coreai_swift`. `cmake/PublishSwiftHeader.cmake` publishes the generated Objective-C header for Xcode. - Tests: `runtime/test/SwiftBridgeTests.swift` builds with the bridge sources into the `coreai_swift_bridge_test` XCTest bundle (Ninja, macOS), which CTest runs under `xcrun xctest`. - README: "SDK Bridge" and the build requirements in "Building". Changes outside `backends/apple/coreai` are CMake and CI only and only take effect when `EXECUTORCH_BUILD_COREAI=ON`: - `tools/cmake/ExecuTorchCoreAIDependencies.cmake` (new): resolves Foundation, CoreAI and Swift runtime link paths from the consumer's SDK, so installed packages do not embed the producer's Xcode paths. It fails configuration for SDKs older than 27. - `CMakeLists.txt`: install `ExecuTorchCoreAIDependencies.cmake` into the package config. - `tools/cmake/preset/default.cmake`: note the SDK 27 requirement in the option description. - `.github/workflows/coreai.yml`: also trigger on changes to `ExecuTorchCoreAIDependencies.cmake`. 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` and `coreai_swift_bridge_test`. The XCTest bundle links CoreAI, so it only runs on the macOS 27 runner; locally it is built but not run.
Summary: Make the synchronous calling contract explicit and protect real model execution against binding and validation regressions. Consolidate callback handling without changing scheduling or retry behavior. Test Plan: CoreAI native and Swift CTest targets passed on macOS 27. All 17 Swift tests passed, including five new real-SDK session tests; five repeated suite runs also passed. The Python backend suite passed all 113 tests in the pinned CoreAI environment. A bounded probe using the production acquisition helper reproduced cooperative-pool starvation with 16 synchronously blocking Swift-task callers under the default runtime. GCD and async-continuation controls completed successfully. This was a scheduling-only probe, not real inference.
84780b8 to
e36e1ed
Compare
756e906 to
66fd8b0
Compare
|
@claude review this code Updated head: Context on the previous findings: this is intentionally a strongly linked OS-27-only bridge. Availability checks do not promise compatibility with older operating systems; adding weak linking would be a different feature. Requiring CMake 3.31 and Ninja/Xcode when CoreAI is enabled is intentional because that configuration includes the Swift bridge, not a separate Foundation-only build. The downstream delegate supplies the remaining Objective-C linkage, so this layer should not be judged as an independently complete installed delegate. Cooperative-pool starvation was a credible risk, not a reproduced deadlock; the Swift calling restriction is documented without claiming a different executor is required. Completion contracts and actual session/binding/execution/output-order tests were improved. |
|
Claude finished @metascroy's task in 5m 30s —— View job No blockers on the updated head: the earlier linking, toolchain and install points are treated as settled, and what's left is mostly build-graph and test-robustness problems in the Swift XCTest fixture, plus a few small API points. Detailed reviewPR Review: #23391SummaryThis PR adds the private Swift/Objective-C bridge to the Core AI SDK, with CMake packaging and an XCTest bundle that runs real sessions against an exported fixture. Three independent reviewers went through every changed line. The completion-exactly-once paths, the borrowed-input lifetime, the overflow checks and the strided output copy all held up. As you asked, this review treats strong linking, OS 27 only, CMake 3.31 with Ninja/Xcode, and the delegate supplying the remaining linkage as settled. Nothing was built or run, because the runner is Linux with no Apple SDK. API Design
Infrastructure
Testing
Code Quality
RecommendationApprove once the fixture build-graph items ( |
Adds the private bridge between ExecuTorch's Objective-C++ code and the Swift
CoreAIframework, and packages it for CMake consumers. No ExecuTorch delegate yet; a later PR wires this intoCoreAIBackend.runtime/ETCoreAIBridge.h: Objective-C protocols for model acquisition, prepared models, sessions and tensor transfer, plus availability, device architecture and loader factory entry points.runtime/ETCoreAIModel.swift(moduleCoreAIBridge):memcpyfor dense row-major arrays and strided copies otherwise.runtime/ETCoreAITensor.mm,runtime/coreai_bridge.mm: tensor wrappers and C entry points, built as the privatecoreai_bridge_objobject library so the delegate can absorb them and host tests can substitute a fake bridge.backends/apple/coreai/CMakeLists.txt): requires CMake 3.31 and Ninja/Xcode, keeps ExecuTorch's numeric preprocessor definitions away from swiftc, applies an OS 27 minimum only to Core AI targets, and buildscoreai_swift.cmake/PublishSwiftHeader.cmakepublishes the generated header for Xcode.runtime/test/SwiftBridgeTests.swiftis built with the bridge sources into thecoreai_swift_bridge_testXCTest bundle (Ninja, macOS) and run by CTest underxcrun xctest. The invalid-URL case uses a non-filecoreai-test:URL.backends/apple/coreaiare CMake and CI only, and only take effect whenEXECUTORCH_BUILD_COREAI=ON:tools/cmake/ExecuTorchCoreAIDependencies.cmake(new): resolves Foundation, CoreAI and Swift runtime link paths from the consumer's SDK; fails configuration for SDKs older than 27.CMakeLists.txt: install that file into the package config.tools/cmake/preset/default.cmake: note the SDK 27 requirement..github/workflows/coreai.yml: also trigger on changes toExecuTorchCoreAIDependencies.cmake.Stack: 5 of 9, based on #23390. Review only this PR's commit. Next: #23392.
Test plan: built locally for macOS 27.0;
ctest -Nlistscoreai_host_testandcoreai_swift_bridge_test, which the Core AI workflow runs on the macOS 27 runner. The XCTest bundle links CoreAI, so it only runs there (first CI run of it).lintrunneris clean.