Skip to content

native: the Metal open paths' shared helpers move to metal_shared.zig (metal.zig 593 to 546 lines) - #2425

Merged
ashhart merged 2 commits into
mainfrom
lead/metal-room
Nov 7, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/metal-room

Conversation

@ashhart

@ashhart ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

zig/src/native/metal.zig is at 593 lines, and #1850 (Nemotron on Metal with TF_KV_SHARE) needs about 10 more, which would take it past the 600 limit.

This moves six helpers that the Metal open paths share, unchanged, into zig/src/native/metal_shared.zig, together with their test: chip, deviceName, generation, prefillStep, modelContext and gibBytes. The only change to them is pub on the three that metal.zig now reaches from the other file. metal.zig goes from 593 to 546 lines.

For #1850: it moves modelContext to cuda_window.zig. After this lands, its rebase removes modelContext from metal_shared.zig instead of from metal.zig.

Tests

  • The native build, every host step that compiles metal.zig, zig build test and the plain zig build give the same results before and after. zig build -l is byte-identical.
  • No Metal device test ran: each device open was refused and logged, and none came from metal.zig's steps.
  • The landing gate's host checks pass, and lean adds nothing new.

No behaviour change.

…, so metal.zig has room for #1850

zig/src/native/metal.zig was at 593 lines. chip, deviceName, generation, prefillStep, modelContext and
gibBytes, with generation's test, move unchanged to metal_shared.zig; only the three that were private
gain pub. metal.zig names each as before, so every call site and its arguments stay as they were, and
chip and deviceName stay public there. metal.zig is now 546 lines.
@ashhart
ashhart merged commit 1d634cf into main Nov 7, 2026
1 of 11 checks passed
@ashhart
ashhart deleted the lead/metal-room branch November 10, 2026 16:34
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 17, 2026
)

Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open
begins the store's pass before the cache opens (its held pages less the lane's
promise) and resumes on the adopted pages before the host cache's restore; the
pass lives per stream across prefill_step calls, its marks cut the chunks, and
it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts
takes a Query now: .of(s.prompt()).

Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn
are carried here instead (main moved that loop out in ashhart#3021), its traceLessons
move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig
takes modelContext from cuda_window.zig with metal_shared.zig's copy removed,
as the branch's merge of ashhart#2425 did.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 18, 2026
)

Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open
begins the store's pass before the cache opens (its held pages less the lane's
promise) and resumes on the adopted pages before the host cache's restore; the
pass lives per stream across prefill_step calls, its marks cut the chunks, and
it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts
takes a Query now: .of(s.prompt()).

Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn
are carried here instead (main moved that loop out in ashhart#3021), its traceLessons
move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig
takes modelContext from cuda_window.zig with metal_shared.zig's copy removed,
as the branch's merge of ashhart#2425 did.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 19, 2026
)

Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open
begins the store's pass before the cache opens (its held pages less the lane's
promise) and resumes on the adopted pages before the host cache's restore; the
pass lives per stream across prefill_step calls, its marks cut the chunks, and
it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts
takes a Query now: .of(s.prompt()).

Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn
are carried here instead (main moved that loop out in ashhart#3021), its traceLessons
move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig
takes modelContext from cuda_window.zig with metal_shared.zig's copy removed,
as the branch's merge of ashhart#2425 did.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 22, 2026
)

Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open
begins the store's pass before the cache opens (its held pages less the lane's
promise) and resumes on the adopted pages before the host cache's restore; the
pass lives per stream across prefill_step calls, its marks cut the chunks, and
it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts
takes a Query now: .of(s.prompt()).

Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn
are carried here instead (main moved that loop out in ashhart#3021), its traceLessons
move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig
takes modelContext from cuda_window.zig with metal_shared.zig's copy removed,
as the branch's merge of ashhart#2425 did.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 23, 2026
)

Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open
begins the store's pass before the cache opens (its held pages less the lane's
promise) and resumes on the adopted pages before the host cache's restore; the
pass lives per stream across prefill_step calls, its marks cut the chunks, and
it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts
takes a Query now: .of(s.prompt()).

Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn
are carried here instead (main moved that loop out in ashhart#3021), its traceLessons
move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig
takes modelContext from cuda_window.zig with metal_shared.zig's copy removed,
as the branch's merge of ashhart#2425 did.
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.

1 participant