CoreML primitives are organized by convention only: repo-root artifacts, CWD-relative loading, and one partial bundle in git
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
build.rs generates four CoreML primitives, compiles them with coremlc, and copies each one into the repo root. They are real dependencies — the ANE dispatcher loads them at run time — but nothing about how they are stored, found, or ignored is written down, and the parts that are written down have drifted from the code.
This issue is about organizing them properly. It is not urgent: the current arrangement works on a developer machine run from the repo root.
What exists today
| Bundle | Generated by build.rs | Loaded by | In git |
|---|---|---|---|
matmul_4x4.mlmodelc |
yes | npu_dispatch.mm:355 |
ignored |
affine_4.mlmodelc |
yes | npu_dispatch.mm:440 |
ignored |
matmul_512x512_fp16.mlmodelc |
yes | npu_dispatch.mm:260 (dynamic name) |
ignored |
matmul_1024x1024_fp16.mlmodelc |
yes | npu_dispatch.mm:260 (dynamic name) |
ignored |
matmul.mlmodelc |
no | nothing | partially tracked |
The problems
1. Artifacts land in the repo root. build.rs compiles into OUT_DIR and then copies to env::current_dir(), with the comment "so tests/runtime can easily find them". Five .mlmodelc/ directories sit at top level, ignored individually.
2. Models are found by bare relative path. [NSURL fileURLWithPath:@"affine_4.mlmodelc"] resolves against the process working directory. Run vxc from anywhere but the repo root and every model misses; the dispatcher logs the miss and falls back to the CPU. Correct, but it means ANE routing silently depends on the launch directory, and a shipped binary (#368) has no way to find them at all.
3. .gitignore needs an edit per shape. The four rules are spelled out one per name. npu_dispatch.mm:224 says adding a shape "is a line in the build list rather than an edit to this file" — true of the dispatcher, but it still takes a second edit in .gitignore, and a missed one commits a build output.
4. matmul.mlmodelc is tracked, unreferenced, and incomplete. Committed in 43d4ce03, it predates the generated primitives. Only model.mil is tracked — coremldata.bin and analytics/ are not — so the version in git is not a loadable bundle. No code refers to it; the only mentions are in docs/npu_dispatch_plan.md, a design doc describing the original prototype.
5. A comment claims tests that do not exist. build.rs:243 and scripts/tools/generate_ane_primitives.py:87 both keep the 4x4 pair "for the affine path and the tests written to it". The affine path half is true. No test loads affine_4, and the one test that mentions the affine route says it never reaches it (tests/integration_test/ane_device_test.rs:141).
6. The affine route is hardcoded to 4 elements. npu_dispatch.mm:675 requires res_sizes[0] == 4 && a_sizes[0] == 4, so affine_4 is the only affine primitive that can ever be reached. This is the hardcoded style the matmul comment describes itself as having replaced.
Suggested organization
Roughly in order of value:
- Give the bundles one directory and one ignore rule. Put them under something like
build/ane-primitives/rather than the repo root, and ignore the directory once instead of naming each shape. Adding a primitive then costs exactly one edit, in the build list. - Resolve models through a search path, not the CWD. Check, in order: an env var (
VX_ANE_MODEL_DIR), a directory next to the running executable, then the current directory as it behaves now. That keeps developer runs working, makes the dependency explicit, and is what a shipped binary would need. - Decide
matmul.mlmodelc's fate. Nothing loads it and the tracked copy is incomplete. Either delete it and updatedocs/npu_dispatch_plan.mdto describe the generated primitives, or — if it is wanted as a fixture independent of a local Xcode — commit the whole bundle and have something actually load it. The current half state serves neither purpose. - Make the comments match. Drop the "tests written to it" claim, or add a test that exercises the affine route. The route is currently covered by nothing.
- Consider making the affine route shape-driven, the way the f16 matmul route builds
matmul_<d>x<d>_fp16from the shape — or state plainly in the comment that it is a fixed 4-element demo path, so the next reader does not assume it generalizes.
Not in scope
Whether the affine route earns its place at all. CoreML prefers the CPU for small tensors, so a 4-element affine primitive is unlikely to reach the Neural Engine; that is worth measuring separately rather than deciding here.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with build.rs and scripts/tools/generate_ane_primitives.py, then trace the loading sites in npu_dispatch.mm and the related entries in .gitignore. Compare the current artifact and lookup behavior with the suggested organization, and review docs/npu_dispatch_plan.md and tests/integration_test/ane_device_test.rs; done means the chosen layout, lookup behavior, tracked bundle decision, and comments or coverage are consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, macos, python, rust
- Domain
- build-system, desktop
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100