Repository navigation
metal: the two pairs of u32 copy kernels from one source (#2251) - #4740
Conversation
|
Thanks @jschmied for consolidating these copy kernels. The wrappers keep the existing kernel names, arguments and bounds. One build dependency needs adding. The new shared copy include isn't registered with Drama 3's Metal library compile step. If only that include changes, a rebuild can reuse the cached codec library with the old copy kernel while other kernels get the update. Please register the shared file as an input to that compile.
|
|
Done in How it was checked, on Linux with a stub
On a Mac (M3 Pro), No shader text changed, so the Mac rows in the body still hold. x86 full set on |
|
Thanks, @jschmied. The stale codec rebuild issue is fixed: the codec compile now explicitly tracks the shared copy include. The cache invalidation check addresses the exact failure from the previous review. The two macro forms preserve the original bounds, kernel names, buffer positions and threadgroup attribute, and the source assembly supplies each consumer consistently. Combined with the supplied identical IR and codec library, I found no runtime byte or token change. No additional device cells are needed from this review.
|
glm_copy_u32 and Drama 3's codec c_copy (n values, bounds-checked) and Nemotron's tf_copy_u32 and Flash Next's pf_copy (one value a thread) had the same bodies. They now come from TF_COPY_U32_N and TF_COPY_U32 in core/copy_u32.metal. c_copy keeps its 256-thread reservation; names and buffer indices are unchanged, and pf_copy's arguments are named src and dst like the others. The offline Drama 3 metallib includes the core file; the embedded codec text has it inlined.
…nput The codec includes the shared u32 copy macros, but its compile step only listed d3_common.h, so a change to copy_u32.metal alone reused the cached codec .air with the old copy kernel.
e8e86f0 to
e2fa228
Compare
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Part of #2251 (group: the two copy pairs). Head e8e86f0, two commits on main b192eaa.
Review 7105928679: Drama 3's metallib step now lists
core/copy_u32.metalas an input of thecodec.metalcompile, besided3_common.h(zig/build/drama3_metal.zig). Checked on Linux with a stubxcrunthat only writes outputs,zig build -Dtarget=aarch64-macos drama3-metal-quant-check --summary all: with nothing changed every.airis cached; an edit tocopy_u32.metalalone rerunsd3_codec.aironly; the same edit without the change reruns nothing. On a Mac (M3 Pro),zig build drama3-generate --summary allon e8e86f0 rebuildsd3_codec.airafter touching or editing onlycore/copy_u32.metal; on the parent 478fcb6 it stays cached. No shader text changed, so the rows below (on 478fcb6) still hold. x86 full set on e8e86f0:zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths2431/2431 steps, 25036/25195 tests (159 skipped);check-native-cuda-host compile-cuda-tests17/17; pr_check 0 errors; lean 165 vs 165, 0 new;zig fmt --checkandgit diff --checkclean.What changes
glm_copy_u32(glm_glue.metal) and Drama 3'sc_copy(drama3/codec.metal): n values, bounds-checked;tf_copy_u32(nemotron_glue.metal) and Flash Next'spf_copy(prefill/fn_prompt.metal): one value a thread.TF_COPY_U32_N(NAME)andTF_COPY_U32(NAME)in the newcore/copy_u32.metal.c_copykeeps itsmax_total_threads_per_threadgroup(256). Names and buffer indices are unchanged;pf_copy's arguments,SandT, are nowsrcanddstlike the others'.sources.zigputscore_copy_u32ahead ofglm_glue,nemotron_glueandflashnext_prompt;drama3/codec.metalincludes../core/copy_u32.metal, which the offline Drama 3 metallib resolves;sources.drama3.codec(the text the kernel contract compiles) has it inlined at comptime.Core vs backend-only:
core/copy_u32.metalis the shared Metal piece; the rest is each family's Metal source and its assembly insources.zig. Drama 3's CUDAc_copyis untouched.Same bits (M3 Pro, macOS 27.2, metal 32023.921, Zig 0.17.0; main b192eaa against this head)
IR: the runtime libraries emitted on both arms (with and without tensor units) change only in
nemotron_glue, the GLM glue and the two Flash Next prompt libraries. Each compiled with-std=metal4.1 -S -emit-llvmunder its manifest's flags:nemotron_glue(10 functions) and the GLM glue (23): identical;pf_copy'sair.arg_name(S/Ttosrc/dst);drama3.metallibfromzig build drama3-generate: byte-identical on both arms (md5 af34df1a184d5d3259d4ee72a1dd41c0), the same 43 functions.Kernel contract,
tf-kernel-contract --only, main = head:PASS limits: 42 selected registered Metal launches against M1-M5, 0 problems, identical on both arms. The--only flashnextrun then stops witherror: UnknownLaunchbefore its SUMMARY line, on main as on this head:metal_drama3.zig's source lookup is reached from that filter. Not from this change; I can open an issue for it if you want one.Family checks:
test-glm-copies-host test-nemotron-copies-host test-kernel-symbols-host test-flashnext-glue-contract-host: 21/21 steps, 66/66 tests. Drama 3's host set (check-drama-metal-host,test-drama-metal-quant-host,check-drama-codec-bindings, the prefill/owner/host/cfg/nvfp4-reference/combine-stress tests): 35/35 steps, 111/113 (2 skipped).Served hash: not run. Every served kernel's IR is identical and the Drama 3 metallib is byte-identical, so no reply can change; for the same reason no seeded, resume, concurrency or refusal checks against main.
x86 CI green on a merge of this head with three sibling metal: unify duplicated kernels (attention partials, norms, gemm_nax wrappers, glue, RoPE) #2251 groups: merge 72b153f490 of b83b26a, a3e5359, 478fcb6 and ebf6db7 on main b192eaa (the groups touch separate files, apart from separate hunks of
sources.zigin the copy and vision groups).zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths: 2431/2431 steps, 16239/16350 tests (111 skipped);check-native-cuda-host compile-cuda-tests17/17;zig fmt --checkandgit diff --checkclean. pr_check and lean flagged one new multi-line comment in the prompt-pick group'score/prompt_pick.metal; on the merge with that one-line fix (16ea8fe6e4, prompt pick at 7cd71d9): pr_check 0 errors, lean 165 vs 165 on main, 0 new.Proposed CHANGELOG line (for you to place):