Skip to content

Add CoreML backend options with compute unit configuration (#18369)#18369

Open
metascroy wants to merge 1 commit intopytorch:mainfrom
metascroy:export-D92358632
Open

Add CoreML backend options with compute unit configuration (#18369)#18369
metascroy wants to merge 1 commit intopytorch:mainfrom
metascroy:export-D92358632

Conversation

@metascroy
Copy link
Contributor

@metascroy metascroy commented Mar 20, 2026

Summary:

This diff adds type-safe backend options support to the CoreML delegate, allowing users to configure compute units (CPU, GPU, Neural Engine) at model load time using the new LoadBackendOptionsMap infrastructure.

Key changes:

  • Added LoadOptionsBuilder class in coreml_backend_options.h providing a fluent API for setting CoreML options with compile-time type safety
  • ComputeUnit enum nested inside the builder for type-safe compute unit selection (CPU_ONLY, CPU_AND_GPU, CPU_AND_NE, ALL)
  • Integrated runtime spec retrieval in backend_delegate.mm to read compute_unit option from BackendInitContext
  • Added comprehensive unit tests for the new options builder

Example usage:

using executorch::backends::coreml::LoadOptionsBuilder;

LoadOptionsBuilder coreml_opts;
coreml_opts.setComputeUnit(LoadOptionsBuilder::ComputeUnit::CPU_AND_GPU);

LoadBackendOptionsMap map;
map.set_options(coreml_opts);

module.load(method_name, map);

Differential Revision: D92358632

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 20, 2026

🔗 Helpful Links

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

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

❌ 1 New Failure, 42 Pending

As of commit 73c5fdb with merge base fd1581d (image):

NEW FAILURE - The following job has failed:

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 Mar 20, 2026
@meta-codesync
Copy link
Contributor

meta-codesync bot commented Mar 20, 2026

@metascroy has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92358632.

@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync bot changed the title Add CoreML backend options with compute unit configuration Add CoreML backend options with compute unit configuration (#18369) Mar 20, 2026
metascroy added a commit to metascroy/executorch that referenced this pull request Mar 20, 2026
…8369)

Summary:

This diff adds type-safe backend options support to the CoreML delegate, allowing users to configure compute units (CPU, GPU, Neural Engine) at model load time using the new `LoadBackendOptionsMap` infrastructure.

Key changes:
- Added `LoadOptionsBuilder` class in `coreml_backend_options.h` providing a fluent API for setting CoreML options with compile-time type safety
- `ComputeUnit` enum nested inside the builder for type-safe compute unit selection (CPU_ONLY, CPU_AND_GPU, CPU_AND_NE, ALL)
- Integrated runtime spec retrieval in `backend_delegate.mm` to read `compute_unit` option from `BackendInitContext`
- Added comprehensive unit tests for the new options builder

Example usage:
```cpp
using executorch::backends::coreml::LoadOptionsBuilder;

LoadOptionsBuilder coreml_opts;
coreml_opts.setComputeUnit(LoadOptionsBuilder::ComputeUnit::CPU_AND_GPU);

LoadBackendOptionsMap map;
map.set_options(coreml_opts);

module.load(method_name, map);
```

Differential Revision: D92358632
…8369)

Summary:
Pull Request resolved: pytorch#18369

This diff adds type-safe backend options support to the CoreML delegate, allowing users to configure compute units (CPU, GPU, Neural Engine) at model load time using the new `LoadBackendOptionsMap` infrastructure.

Key changes:
- Added `LoadOptionsBuilder` class in `coreml_backend_options.h` providing a fluent API for setting CoreML options with compile-time type safety
- `ComputeUnit` enum nested inside the builder for type-safe compute unit selection (CPU_ONLY, CPU_AND_GPU, CPU_AND_NE, ALL)
- Integrated runtime spec retrieval in `backend_delegate.mm` to read `compute_unit` option from `BackendInitContext`
- Added comprehensive unit tests for the new options builder

Example usage:
```cpp
using executorch::backends::coreml::LoadOptionsBuilder;

LoadOptionsBuilder coreml_opts;
coreml_opts.setComputeUnit(LoadOptionsBuilder::ComputeUnit::CPU_AND_GPU);

LoadBackendOptionsMap map;
map.set_options(coreml_opts);

module.load(method_name, map);
```

Differential Revision: D92358632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant