Commit 71cfbb0
[CoreML EP] Add Sin and Cos unary ops (#28596)
### Summary
Lower ONNX `Sin` and `Cos` to the CoreML ML Program `sin` / `cos`
elementwise ops
via the existing `UnaryOpBuilder`, registered in the op builder factory.
Like
`Erf` / `Round` / `Exp`, these have no NeuralNetwork lowering
(`UnaryFunctionLayerParams` has no sin/cos), so `IsOpSupportedImpl`
rejects them on
the NeuralNetwork format.
### Why
`Sin` / `Cos` form the sinusoidal timestep embedding of diffusion UNets.
Supporting
them keeps that prologue on CoreML instead of splitting the graph — a
tiny
Stable-Diffusion UNet goes from **2 CoreML partitions → 1, zero graph
breaks** with
this change alone.
This PR is **independent** of the rest of the series (it touches only
the unary
builder) and can be reviewed/merged in any order.
### Tests (`coreml_basic_test.cc`)
- `SinCos_MLProgram` — a Sin + Cos graph runs fully on CoreML and
matches the CPU
reference.
- `SinCosNeuralNetworkNotSupported` — the same graph falls back to CPU
on the
NeuralNetwork format.
Doc: `coreml_supported_mlprogram_ops.md` lists `Sin` and `Cos`.
### Series — CoreML EP coverage for transformer / diffusion graphs
- #28595 — Support bool Cast in ML Program *(prerequisite)*
- **#28596 — Add Sin and Cos unary ops** *(this PR — independent)*
- #28597 — Add Where and And builders *(depends on #28595)*
- #28598 — Add GatherND builder *(depends on #28595)*
Together with #28278 (scalar-`Gather`), the series takes BERT / GPT-2 /
ViT /
diffusion-UNet graphs — tiny and full-size — from 2 CoreML partitions to
1, with
zero graph breaks.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b0924f4 commit 71cfbb0
4 files changed
Lines changed: 72 additions & 2 deletions
File tree
- onnxruntime
- core/providers/coreml/builders
- impl
- test/providers/coreml
- tools/ci_build/github/apple
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
93 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2360 | 2360 | | |
2361 | 2361 | | |
2362 | 2362 | | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
2363 | 2412 | | |
2364 | 2413 | | |
2365 | 2414 | | |
| |||
2437 | 2486 | | |
2438 | 2487 | | |
2439 | 2488 | | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
2440 | 2499 | | |
2441 | 2500 | | |
2442 | 2501 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
0 commit comments