mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2937] Metal build broken on current main (v0.1.45-metal): 3 separate defects in the perf-merge sync #1183
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#1183
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DarkJoll on GitHub (Oct 17, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2937
Metal build broken on current main (v0.1.45-metal): 3 separate defects in the perf-merge sync
Summary
A fresh install on an Apple Silicon Mac (
git clone+./setup.sh, followingdocs/MAC.md) fails to build the engine at commit477ac13c. Three separate defects, all introduced because the f-145 perf-PR group merges (5a6f4ed5,8bdef963,df6262f2,21c57972,b277412e,cbc6e3d8,e8b1edbc,f260925a) and the #2666 peer-experts work changed the shared host code and the kernel headers without re-syncing the Metal side:metal/include/metal_compat/cuda_runtime.h) lacks six names the shared host code now uses → compile errors.metal/src/engine/stubs.cpp) is stale: one stale signature (member → hard compile error) and 21 entry points that are referenced but undefined → link failure.strata::kernels::fused_gr_persist_init, is called unconditionally fromVerifier::init(src/core/verify.cpp:646), so even with the stub the engine would stop at start-up (exit 86, "no Metal implementation yet").The Metal target (
metal/CMakeLists.txt) is a separate CMake project that never compiles in the CUDA/HIP/SYCL builds, so none of the PC-side changes were caught: the perf group is measured on RTX 2080 Ti / R9700 / gfx12 hardware only.Environment
git clone https://github.com/Niko1221/Strata, commit477ac13c(v0.1.45-metal)./setup.sh→ step 4 (engine build) fails; the model download never startsDefect 1 — shim missing six names
src/core/peer_experts.cpp(added by #2666;e6ad6c81fixed the HIP compat for exactly this, "peer_experts.cpp did not compile on HIP in f-145-int", but not the Metal one):src/core/verify.cpp(sm75/cuda86 group):(
cudaDeviceDisablePeerAccessis called with one argument at verify/peer_experts sites; the real CUDA signature has a defaultedflags, so the shim needs the default too.)Defect 2 — stale generated stubs
After the shim is fixed, compilation passes and the link fails with 21 undefined symbols (ld64):
All referenced from the shared host objects (
verify.cpp.o,prefill.cpp.o,mtp.cpp.o,native_expert.cpp.o,generate.cpp.o) — the same calls run on every backend, and the last stub regeneration predates the perf group, so none of them have a Metal implementation or a stub.The stale-signature part:
Gemm::bf16gained a trailingbool x_f16(8bdef963, sm75 series), so the committed 9-parameter out-of-line stub no longer matches the declaration:The same drift, in its quiet form, hit four free functions: the committed stubs of
gr_norm/gr_norm_rs/gr_write_norm_rs/gr_write_cvec_norm_rsare one parameter short of the currentprefill/kernels.hppdeclarations. Free functions make that compile (it becomes a dead overload), but the 9/9/12/16-parameter versions the host code now references are what the link needs — and the dead overloads are a latent landmine (an 8-argument call would silently bind to the stub).Defect 3 —
fused_gr_persist_initstops the engine at startVerifier::initcallsstrata::kernels::fused_gr_persist_init();unconditionally (src/core/verify.cpp:646, no#if). The feature isSTRATA_HC_PERSIST=1, a HIP-only read variant: the non-HIP CUDA build compiles an empty body for it (src/kernels/cuda/fused_gr.cu:3030,#elsebranch), and on Metal the .cu is not built at all. So on Metal the call reaches the stub andmissing()stops the engine (metal/src/engine/missing.cpp: "no Metal implementation yet", exit 86) on every start, regardless of model or settings. The Metal side needs the same empty body the CUDA build has (the project already does this for the siblingfused_gr_check()at metal/src/engine/setup_host.cpp:59).Runtime reachability of the 21 (so the stubs never fire on a default Mac)
Audited each call site: 20 of the 21 sit behind opt-in or PC-only gates and are not reached on a default Apple Silicon run —
fused_gr_read_persistfused_gr_supported(), which on Metal is the stub →falsenative_quantize_q8_1_ilqil=STRATA_QILenv ordevice_is_sm75()(Turing; false on Apple silicon)gdn_step_norm_groups(×2)STRATA_BATCH_GDN_GROUPS=1(opt-in)qsa_block_scores_rows,qsa_decode_attn_batch_rowsSTRATA_BATCH_ATTN_ROWS=1(opt-in)qsa_decode_attn_splitSTRATA_QSA_SPLIT_ATTN=1(opt-in)wait_copy_i32_from_mapped,copy_rows_from_mapped_afterfuse_wait_on():STRATA_FUSE_WAITon non-HIP, off by defaultwait_flag_ge_stamped(×3)m_bal_ != nullptr(set_pcie_balance, multi-GPU) or the fused-wait branchwait_handoff,handoff_publishhflag_*_d_ != nullptr(overlapped layer split, multi-GPU)res_patchdrive.d.res_dirty, set only withSTRATA_ADAPT_EVICT_SYNCiq256_gu_rows_exact_oneSTRATA_CPU_IQ_ALL_EXACT1andggml_cpu_has_avx2()(never true on arm64)gr_norm,gr_norm_rs,gr_write_norm_rs,gr_write_cvec_norm_rs,f16_range_read,gemm_f16_range_read,hc_q8_to_bf16Prefill::run_impl/bf16_proj; underSTRATA_GPU_METAL,Prefill::runreturns viametal_engine::prompt_runfirst (src/prefill/prefill.cpp:4814)Only
fused_gr_persist_init(defect 3) is reached on the default path. A stub that stops the engine is the project's documented behavior for "never expected to be called here", so the 20 are correct as stubs; the one needs the no-op body.The fix (5 files, all under
metal/)Everything is inside the Metal-only project (
metal/is a standalone CMake target, "never part of the CUDA / HIP / SYCL builds" — metal/CMakeLists.txt:1-2; the CUDA/HIP builds never includemetal/include), so the PC builds are unaffected by construction. 58 insertions, 6 deletions:metal/include/metal_compat/cuda_runtime.h— add the six names, forwarding tostrata::gpulike every other name in the file.metal/include/strata/gpu/runtime.hpp+metal/src/gpu/runtime.cpp— the sixstrata::gpufunctions, each following the file's existing pattern:device_cc_major/minor:*v = 0; return fail(kErrorUnsupported)— the same pattern asdevice_sm_count/device_clock_khz("Apple reports no core count"). Effect:device_is_sm75()(src/core/verify.cpp:276) getsok = false→per_dev = 1→false. Correct: an Apple GPU is not a Turing card, andstrata::sm75_default(0, 0)isfalseanyway.cudaMemcpyPeer→ one-GPU: a plain device-to-device copy (memcpy_sync),kErrorInvalidValuefor a non-zero device ordinal. Never actually run on a single-GPU Mac (p2p_stays false:device_enable_peer_accessfails).cudaDeviceDisablePeerAccess→fail(kErrorUnsupported), the same asdevice_enable_peer_access; the caller clears the last error right after.stream_priority_range→(0, 0),stream_create_with_priority→stream_create(s, f): one priority level, i.e. the default — matching the existing precedent inmtp.cpp:438("HIP, Metal: the default priority"). Only reachable withSTRATA_PIPED_CONCURRENT=1(opt-in), so default behavior is unchanged.metal/src/engine/stubs.cpp— regenerated with the project's ownmetal/tools/gen_stubs.pyfrom the link log: thebf16stub updated to the current 10-parameter signature, the fourgr_*stubs updated to their current signatures, the 16 remaining new entry points added (21 minusfused_gr_persist_init, which moves to the no-op below), plus the eight headers the regenerated set includes that the old file lacked.metal/src/engine/setup_host.cpp—void fused_gr_persist_init() {}next to the existingfused_gr_check() {}(defect 3); the corresponding line is removed from stubs.cpp to avoid a duplicate definition.Full patch
The diff above is the verbatim
git diffof the five files (193 lines) at commit477ac13c;git applyit against a fresh clone to reproduce the fixed tree.How I checked
On the machine above (Apple silicon, macOS 27.0):
ninja -C build-metal(every target, including allmetal/tests/*) — 0 errors, 0 warnings of new kinds; the only warning is the pre-existingld: warning: ignoring duplicate librariesfrom thestratalink line (metal/CMakeLists.txt:123 listsstrata_metal_kernelstwice).ctest: 1/1 pass (runtime_hello, the only registered test).gr_parity— ALL PASS (bitwise on the prepared planes; rel-L2 ≤ 3.4e-08 on the rest);prompt_parity— ALL PASS (route_topk: 0 id mismatches over 300 tokens).strata --help: runs.metal/, which the CUDA/HIP/SYCL builds never compile (metal/CMakeLists.txt:1-2, metal/include/metal_compat/cuda_runtime.h:5-8).Suggested follow-up (separate PR)
metal/tools/gen_stubs.pydetects the repo root as the last-I.../includeargument that contains astrata/directory. The engine target's real include order (CMake:-I include ... -I metal/include) putsmetal/includelast, so running the generator with the build's actual compile line silently scansmetal/include/strata(which only hasgpu/), finds zero headers, and emits a 0-stub file with "undefined 21, unmatched 21" and no error — it then replaces the good 249-stub file and the next link fails with ~228 "referenced from" symbols. Suggest asserting that the scanned header count is non-zero (or that the root has akernels/directory) so a wrong root fails loudly.@Niko1221 commented on GitHub (Oct 19, 2026):
Thanks for taking the time to report this.
We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.
To reopen it takes about two minutes:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.