Skip to content

accel/ane: accept an H17 task stream that opens with 1 - #1790

Merged
DjDeveloperr merged 1 commit into
integration/aurorafrom
w91/ane-h17-prologue
Nov 14, 2026
Merged

DjDeveloperr merged 1 commit into
integration/aurorafrom
w91/ane-h17-prologue

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Apple's current H17 compiler opens the task stream of its matmul and add programs with the u32 1 that H16 uses. The linked MobileNetV1 program opens with 0. The gate demanded 0 for every H17 program, so H16_LOAD refused the first form with ENOEXEC and no reason in dmesg.

Change: for subtype 9 the gate accepts an opening word of 0 or 1 and refuses every other value. The selftest section builder (tools/testing/selftests/drivers/ane/h16-sections.py) takes the same two openings. Reserved bytes, the task walk and all other checks stay as they were. H16 still requires 1.

Found on the 16-inch-class M5 Max (Mac17,11) bring-up: a real Qwen3-4B k_proj matmul (2560 to 1024) compiled for H17 loads and runs once the word is patched to 0 and Apple's 25 debug symbols are cut in userspace (cosine 0.9999998 against an fp32 reference, p50 341 us per call). The symbol rule stays strict in the kernel.

Tests (UML KUnit, ane-h16-program*, ane-h16-tasks*, hwx_program/final_task_end/symbols): program_h17_hwx_test now loads the MobileNet program with an opening word of 1 and refuses 2; the H16 and H17 prologue cases pass. Two failures exist on the base commit with and without this change: program_add128_slots_test fails, and hwx_import_bounds_test crashes UML (copy_from_user fault), which stops the rest of the ane-h16-hwx suite when run whole.

Hardware proof of a prologue-1 program, on the M5 Max (Mac17,11) with this change built in (7.3.0-k114c-ARCH-p1, boot eba1142e): Apple's own compiled Qwen3-4B k_proj program (2560 to 1024, fp16 weights), task stream opening with 1, only its debug symbols cut in userspace. H16_LOAD accepts it and it runs: against an fp32 CPU reference the output has max abs error 1.08e-3 (reference abs max 2.13), relative L2 4.2e-4, cosine 0.9999998, no NaN, top-16 overlap 16/16, p50 347 us over 20 runs. The same program with the word patched to 0 on the earlier kernel gave the same numbers. Command: sel/ane-run.py --hwx program-p1.hwx --case case-x.bin:case-expected.bin --runs 20 (the in-tree selftest builder, now accepting prologue 1 for H17), output compared with numpy on the host. The tool's own ulp check prints FAIL (446/1024 exact, max 3038 ulp) because the case file compares fp16 bits against an fp32-derived expectation; the error against the fp32 reference above is the measure.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T08:05:52.581897Z 043b052 PR opened
🔒 Security Review ✅ Completed 2026-11-13T08:07:56.961831Z 043b052 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@joshuaswarren

joshuaswarren commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

CHANGES
Head 043b052.

The code is correct as far as I can read it. The read of the opening word at text.offset happens after the segment walk has bounded __text inside a file-backed segment (hwx_fits against filesz, hwx_file_add), and hwx_snapshot has already refused an empty text section, so the new text.size >= 4 check only adds safety. Any word other than 0 sets prologue = 1, so ane_hx_task_stream_validate_limit still refuses 2 and above, and the new KUnit case pins that. H16 is unchanged.

One thing should land before merge: a device run of an H17 program that opens with 1. This change widens what the kernel hands to the H17 firmware, and today the only device evidence is for opening word 0 (the k_proj run used a patched 0). If the firmware treats 1 differently on H17, the gate would let through a stream that has never run. Please add one M5 run of an unpatched Apple matmul or add program (opening word 1), with an output check against a CPU reference, to the PR body. Then this is GREEN from me.

Nit: the new sentence in Documentation/accel/apple-ane.rst makes that line about 110 columns; the rest of the file wraps at 80.

@joshuaswarren
joshuaswarren force-pushed the w91/ane-h17-prologue branch 3 times, most recently from cec9bfa to 4bf7e71 Compare November 13, 2026 08:15
Apple's current H17 compiler opens the task stream of its matmul and add
programs with the u32 1 that H16 uses, where the linked MobileNetV1
program opens with 0. The gate demanded 0 for every H17 program, so
H16_LOAD refused the first form with ENOEXEC and no further reason.

Take the prologue from the stream for subtype 9: 0 stays accepted, 1 is
accepted, any other value is refused. The reserved bytes, the task walk
and every other check are unchanged. H16 still requires 1. The selftest
section builder takes the same two openings for subtype 9.

KUnit: program_h17_hwx_test now loads the MobileNet program with an
opening word of 1 and refuses 2; ane_h17_prologue_test and the H16 cases
still pass. program_add128_slots_test fails on the base commit with and
without this change. The hardware run of a prologue-1 program is not yet
done; until then the only device evidence is for prologue 0.

Signed-off-by: Joshua Warren <[email protected]>
Assisted-by: LLM
Signed-off-by: Joshua Warren <[email protected]>
@joshuaswarren

joshuaswarren commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

GREEN
Head 37796b7.

My earlier CHANGES (at 043b052) asked for one M5 run of an unpatched Apple program whose task stream opens with 1. That is now in the PR body: on the M5 Max (Mac17,11), kernel 7.3.0-k114c-ARCH-p1 (boot eba1142e) built from this PR at 4bf7e71, Apple's compiled Qwen3-4B k_proj program with its opening word left at 1 loads through H16_LOAD and runs; against an fp32 CPU reference: max abs 1.08e-3 (reference abs max 2.13), relative L2 4.2e-4, cosine 0.9999998, no NaN, p50 347 us over 20 runs. That matches the word-patched run on the old kernel, so the firmware treats both openings the same for this program.

Delta 4bf7e71 -> 37796b7 (same base 17903f5, compared through the API): ane_h16_hwx.c is identical; ane_h16_tasks_test.c fixes the stale "H17 streams open with 0" comment and adds two checks that ane_hx_task_stream_validate takes 1 and refuses 0 when told prologue 1. So the device run covers the shipped gate code exactly.

Nit, optional: the new comment line in ane_h16_tasks_test.c is about 115 columns; checkpatch warns over 100.

Not run by me: the KUnit suite (the author reports ane-h16-tasks 6 of 6 on an x86 host build; the two base failures named in the PR body are not from this change).

@joshuaswarren

joshuaswarren commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

GREEN at 37796b7

Re-review of the H17 task-stream prologue change. My CHANGES at 4bf7e71c1090 asked for a hardware run of an unpatched H17 program that opens with 1, checked against a CPU reference, and for the stale test comment to be fixed.

The delta from 4bf7e71c1090 to this head is one file, drivers/accel/ane/ane_h16_tasks_test.c, +3/-1. The comment on ane_h17_prologue_test now says an H17 stream opens with 0 or 1. Two assertions are new: ane_hx_task_stream_validate(text, sizeof(text), 1, 1) is 0 and (…, 1, 0) is -ENOEXEC on a stream whose first word is 1. The driver code, the doc and the selftest builder are unchanged from the head I read, and they read correct then.

The hardware ask is now in the PR body: Apple's own compiled Qwen3-4B k_proj program (2560 to 1024, fp16 weights), task stream opening with 1, loaded unpatched by H16_LOAD on the M5 Max with this change built in (boot eba1142e). Against an fp32 CPU reference: max abs error 1.08e-3 (reference abs max 2.13), relative L2 4.2e-4, cosine 0.9999998, no NaN, top-16 overlap 16/16, p50 347 us over 20 runs. The command and the in-tree selftest builder are named. That closes my finding.

CI at this head: host-tests completed success (the only check run). It does not run the ANE KUnit.

Not checked by me: the hardware numbers (I read the PR body; there is no device here) and the KUnit run (I did not build it). The PR body itself says two ANE KUnit failures exist on the base commit with and without this change (program_add128_slots_test, and hwx_import_bounds_test crashing UML). I did not reproduce those.

DjDeveloperr added a commit that referenced this pull request Nov 14, 2026
accel/ane: accept H17 programs from Apple's zin_ane_compiler 10.205 (on #1790)
@DjDeveloperr
DjDeveloperr merged commit 37796b7 into integration/aurora Nov 14, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the w91/ane-h17-prologue branch November 16, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants