[GH-ISSUE #2937] Metal build broken on current main (v0.1.45-metal): 3 separate defects in the perf-merge sync #1183

Closed
opened 2026-11-04 01:49:10 +07:00 by bsakaguchi · 1 comment
Owner

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, following docs/MAC.md) fails to build the engine at commit 477ac13c. 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:

  1. The Metal compat shim (metal/include/metal_compat/cuda_runtime.h) lacks six names the shared host code now uses → compile errors.
  2. The generated stub file (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.
  3. One of the 21, strata::kernels::fused_gr_persist_init, is called unconditionally from Verifier::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

  • Apple Silicon Mac, macOS 27.0, Command Line Tools (Apple clang)
  • git clone https://github.com/Niko1221/Strata, commit 477ac13c (v0.1.45-metal)
  • ./setup.sh → step 4 (engine build) fails; the model download never starts

Defect 1 — shim missing six names

src/core/peer_experts.cpp (added by #2666; e6ad6c81 fixed the HIP compat for exactly this, "peer_experts.cpp did not compile on HIP in f-145-int", but not the Metal one):

peer_experts.cpp:72:13:  error: use of undeclared identifier 'cudaMemcpyPeer'
peer_experts.cpp:157:29: error: use of undeclared identifier 'cudaDeviceDisablePeerAccess'
peer_experts.cpp:158:34: error: use of undeclared identifier 'cudaDeviceDisablePeerAccess'

src/core/verify.cpp (sm75/cuda86 group):

verify.cpp:285:54: error: use of undeclared identifier 'cudaDevAttrComputeCapabilityMajor'
verify.cpp:286:54: error: use of undeclared identifier 'cudaDevAttrComputeCapabilityMinor'
verify.cpp:859:17: error: use of undeclared identifier 'cudaDeviceGetStreamPriorityRange'
verify.cpp:860:17: error: use of undeclared identifier 'cudaStreamCreateWithPriority'

(cudaDeviceDisablePeerAccess is called with one argument at verify/peer_experts sites; the real CUDA signature has a defaulted flags, 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):

strata::kernels::wait_handoff                     strata::kernels::hc_q8_to_bf16
strata::kernels::handoff_publish                  strata::kernels::gdn_step_norm_groups
strata::kernels::wait_flag_ge_stamped             strata::kernels::fused_gr_persist_init
strata::kernels::fused_gr_read_persist            strata::kernels::qsa_block_scores_rows
strata::kernels::qsa_decode_attn_split            strata::kernels::native_quantize_q8_1_il
strata::kernels::wait_copy_i32_from_mapped        strata::kernels::qsa_decode_attn_batch_rows
strata::kernels::copy_rows_from_mapped_after      strata::kernels::cpu::iq256_gu_rows_exact_one
strata::kernels::res_patch                        strata::prefill::f16_range_read
strata::prefill::gemm_f16_range_read              strata::prefill::gr_norm
strata::prefill::gr_norm_rs                       strata::prefill::gr_write_norm_rs
strata::prefill::gr_write_cvec_norm_rs            strata::prefill::Gemm::bf16 (stale signature)

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::bf16 gained a trailing bool x_f16 (8bdef963, sm75 series), so the committed 9-parameter out-of-line stub no longer matches the declaration:

stubs.cpp:328:29: error: out-of-line definition of 'bf16' does not match any declaration in 'strata::prefill::Gemm'

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_rs are one parameter short of the current prefill/kernels.hpp declarations. 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_init stops the engine at start

Verifier::init calls strata::kernels::fused_gr_persist_init(); unconditionally (src/core/verify.cpp:646, no #if). The feature is STRATA_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, #else branch), and on Metal the .cu is not built at all. So on Metal the call reaches the stub and missing() 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 sibling fused_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 —

entry point gate
fused_gr_read_persist branch requires fused_gr_supported(), which on Metal is the stub → false
native_quantize_q8_1_il qil = STRATA_QIL env or device_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_rows STRATA_BATCH_ATTN_ROWS=1 (opt-in)
qsa_decode_attn_split STRATA_QSA_SPLIT_ATTN=1 (opt-in)
wait_copy_i32_from_mapped, copy_rows_from_mapped_after fuse_wait_on(): STRATA_FUSE_WAIT on non-HIP, off by default
wait_flag_ge_stamped (×3) m_bal_ != nullptr (set_pcie_balance, multi-GPU) or the fused-wait branch
wait_handoff, handoff_publish hflag_*_d_ != nullptr (overlapped layer split, multi-GPU)
res_patch drive.d.res_dirty, set only with STRATA_ADAPT_EVICT_SYNC
iq256_gu_rows_exact_one STRATA_CPU_IQ_ALL_EXACT1 and ggml_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_bf16 all called only from Prefill::run_impl / bf16_proj; under STRATA_GPU_METAL, Prefill::run returns via metal_engine::prompt_run first (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 include metal/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 to strata::gpu like every other name in the file.
  • metal/include/strata/gpu/runtime.hpp + metal/src/gpu/runtime.cpp — the six strata::gpu functions, each following the file's existing pattern:
    • device_cc_major/minor: *v = 0; return fail(kErrorUnsupported) — the same pattern as device_sm_count / device_clock_khz ("Apple reports no core count"). Effect: device_is_sm75() (src/core/verify.cpp:276) gets ok = false → per_dev = 1 → false. Correct: an Apple GPU is not a Turing card, and strata::sm75_default(0, 0) is false anyway.
    • cudaMemcpyPeer → one-GPU: a plain device-to-device copy (memcpy_sync), kErrorInvalidValue for a non-zero device ordinal. Never actually run on a single-GPU Mac (p2p_ stays false: device_enable_peer_access fails).
    • cudaDeviceDisablePeerAccess → fail(kErrorUnsupported), the same as device_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 in mtp.cpp:438 ("HIP, Metal: the default priority"). Only reachable with STRATA_PIPED_CONCURRENT=1 (opt-in), so default behavior is unchanged.
  • metal/src/engine/stubs.cpp — regenerated with the project's own metal/tools/gen_stubs.py from the link log: the bf16 stub updated to the current 10-parameter signature, the four gr_* stubs updated to their current signatures, the 16 remaining new entry points added (21 minus fused_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 existing fused_gr_check() {} (defect 3); the corresponding line is removed from stubs.cpp to avoid a duplicate definition.

Full patch

diff --git a/metal/include/metal_compat/cuda_runtime.h b/metal/include/metal_compat/cuda_runtime.h
index eb64243e..66c1937f 100644
--- a/metal/include/metal_compat/cuda_runtime.h
+++ b/metal/include/metal_compat/cuda_runtime.h
@@ -46,7 +46,9 @@ inline constexpr unsigned cudaEventDisableTiming = strata::gpu::kEventDisableTim
 inline constexpr unsigned cudaEventBlockingSync = strata::gpu::kEventBlockingSync;
 inline constexpr unsigned cudaStreamNonBlocking = strata::gpu::kStreamNonBlocking;
 enum cudaStreamCaptureMode { cudaStreamCaptureModeGlobal = 0, cudaStreamCaptureModeThreadLocal = 1, cudaStreamCaptureModeRelaxed = 2 };
-enum cudaDeviceAttr { cudaDevAttrClockRate = 13, cudaDevAttrMultiProcessorCount = 16, cudaDevAttrIntegrated = 18 };
+enum cudaDeviceAttr { cudaDevAttrClockRate = 13,
+                      cudaDevAttrComputeCapabilityMajor = 75, cudaDevAttrComputeCapabilityMinor = 81,
+                      cudaDevAttrMultiProcessorCount = 16, cudaDevAttrIntegrated = 18 };
 
 // ---- errors, devices
 inline cudaError_t cudaGetLastError() { return strata::gpu::get_last_error(); }
@@ -65,11 +67,14 @@ inline cudaError_t cudaDeviceGetAttribute(int* v, cudaDeviceAttr a, int d) {
         case cudaDevAttrIntegrated: return strata::gpu::device_integrated(v, d);
         case cudaDevAttrMultiProcessorCount: return strata::gpu::device_sm_count(v, d);
         case cudaDevAttrClockRate: return strata::gpu::device_clock_khz(v, d);
+        case cudaDevAttrComputeCapabilityMajor: return strata::gpu::device_cc_major(v, d);
+        case cudaDevAttrComputeCapabilityMinor: return strata::gpu::device_cc_minor(v, d);
     }
     return strata::gpu::compat_detail::bad();
 }
 inline cudaError_t cudaDeviceCanAccessPeer(int* v, int d, int p) { return strata::gpu::device_can_access_peer(v, d, p); }
 inline cudaError_t cudaDeviceEnablePeerAccess(int p, unsigned f) { return strata::gpu::device_enable_peer_access(p, f); }
+inline cudaError_t cudaDeviceDisablePeerAccess(int p, unsigned f = 0) { return strata::gpu::device_disable_peer_access(p, f); }
 
 // ---- memory and copies
 template <class T> inline cudaError_t cudaMalloc(T** p, size_t n) { return strata::gpu::malloc_device(p, n); }
@@ -93,10 +98,17 @@ inline cudaError_t cudaMemcpy2DAsync(void* d, size_t dp, const void* s, size_t s
 inline cudaError_t cudaMemcpyPeerAsync(void* d, int dd, const void* s, int sd, size_t n, cudaStream_t st = nullptr) {
     return strata::gpu::memcpy_peer_async(d, dd, s, sd, n, st);
 }
+inline cudaError_t cudaMemcpyPeer(void* d, int dd, const void* s, int sd, size_t n) {
+    return strata::gpu::memcpy_peer(d, dd, s, sd, n);
+}
 
 // ---- streams, events, host functions
 inline cudaError_t cudaStreamCreate(cudaStream_t* s) { return strata::gpu::stream_create(s); }
 inline cudaError_t cudaStreamCreateWithFlags(cudaStream_t* s, unsigned f) { return strata::gpu::stream_create(s, f); }
+inline cudaError_t cudaDeviceGetStreamPriorityRange(int* lo, int* hi) { return strata::gpu::stream_priority_range(lo, hi); }
+inline cudaError_t cudaStreamCreateWithPriority(cudaStream_t* s, unsigned f, int prio) {
+    return strata::gpu::stream_create_with_priority(s, f, prio);
+}
 inline cudaError_t cudaStreamDestroy(cudaStream_t s) { return strata::gpu::stream_destroy(s); }
 inline cudaError_t cudaStreamSynchronize(cudaStream_t s) { return strata::gpu::stream_synchronize(s); }
 inline cudaError_t cudaStreamQuery(cudaStream_t s) { return strata::gpu::stream_query(s); }
diff --git a/metal/include/strata/gpu/runtime.hpp b/metal/include/strata/gpu/runtime.hpp
index 7791dc4a..68665659 100644
--- a/metal/include/strata/gpu/runtime.hpp
+++ b/metal/include/strata/gpu/runtime.hpp
@@ -70,9 +70,12 @@ Error get_device_properties(DeviceProp* p, int dev);
 Error device_integrated(int* v, int dev);
 Error device_sm_count(int* v, int dev);
 Error device_clock_khz(int* v, int dev);
+Error device_cc_major(int* v, int dev);
+Error device_cc_minor(int* v, int dev);
 Error runtime_version(int* v);
 Error device_can_access_peer(int* v, int dev, int peer);
 Error device_enable_peer_access(int peer, unsigned flags);
+Error device_disable_peer_access(int peer, unsigned flags);
 inline constexpr Error kErrorPeerAccessAlreadyEnabled = Error(704);
 
 Error malloc_device_raw(void** p, size_t bytes);
@@ -96,9 +99,12 @@ Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind k, Stream
 Error memcpy_2d_async(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width, size_t height, CopyKind k,
                       Stream s = nullptr);
 Error memcpy_peer_async(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes, Stream s = nullptr);
+Error memcpy_peer(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes);
 
 Error stream_create(Stream* s, unsigned flags);
 inline Error stream_create(Stream* s) { return stream_create(s, 0); }
+Error stream_priority_range(int* lo, int* hi);
+Error stream_create_with_priority(Stream* s, unsigned flags, int prio);
 Error stream_destroy(Stream s);
 Error stream_synchronize(Stream s);
 Error stream_query(Stream s);
diff --git a/metal/src/engine/setup_host.cpp b/metal/src/engine/setup_host.cpp
index e4599092..c11a5920 100644
--- a/metal/src/engine/setup_host.cpp
+++ b/metal/src/engine/setup_host.cpp
@@ -57,6 +57,7 @@ bool native_qsa_indexer_enabled() { return g_qsa_indexer.load(std::memory_order_
 void native_rope_set_enabled(bool v) { g_rope.store(v, std::memory_order_relaxed); }
 bool native_rope_enabled() { return g_rope.load(std::memory_order_relaxed); }
 void fused_gr_check() {}   // the CUDA read variants' self-test: no variants on Metal
+void fused_gr_persist_init() {}   // STRATA_HC_PERSIST=1 is a HIP-only read variant: nothing to init on Metal
 
 // ---- scratch sizes
 uint64_t ple_block_scratch_bytes() {
diff --git a/metal/src/engine/stubs.cpp b/metal/src/engine/stubs.cpp
index 2b651e54..17393cc8 100644
--- a/metal/src/engine/stubs.cpp
+++ b/metal/src/engine/stubs.cpp
@@ -114,6 +114,14 @@
 #include "strata/spec/draft_source.hpp"
 #include "strata/spec/suffix_drafter.hpp"
 #include <type_traits>
+#include "strata/core/family_layout.hpp"
+#include "strata/core/geometry.hpp"
+#include "strata/core/host_graph_launch.hpp"
+#include "strata/core/sm75_series.hpp"
+#include "strata/core/tc_sm75.hpp"
+#include "strata/kernels/cpu/nvfp4_avx2.hpp"
+#include "strata/kernels/cpu/nvfp4_avx512.hpp"
+#include "strata/prefill/mmq_kq_abi.hpp"
 
 namespace strata::metal_engine { void missing(const char* name); }
 
@@ -325,7 +333,7 @@ namespace strata::kernels { void topk_512_step(const float * p0, const QsaShapes
 namespace strata::kernels { void wait_flag_ge(const uint32_t * p0, uint32_t p1, void * p2) { strata::metal_engine::missing("strata::kernels::wait_flag_ge"); } }
 namespace strata::kernels { void wait_flag_ge_or(const uint32_t * p0, uint32_t p1, const uint32_t * p2, void * p3) { strata::metal_engine::missing("strata::kernels::wait_flag_ge_or"); } }
 namespace strata::kernels { void window_ids(int32_t * p0, int p1, int p2, int32_t * p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::kernels::window_ids"); } }
-auto strata::prefill::Gemm::bf16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7, int64_t p8) -> void { strata::metal_engine::missing("strata::prefill::Gemm::bf16"); }
+auto strata::prefill::Gemm::bf16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7, int64_t p8, bool p9) -> void { strata::metal_engine::missing("strata::prefill::Gemm::bf16"); }
 auto strata::prefill::Gemm::bf16_hcd_exact(const uint16_t * p0, int64_t p1, const uint16_t * p2, float * p3, int64_t p4, int64_t p5, int64_t p6) -> bool { strata::metal_engine::missing("strata::prefill::Gemm::bf16_hcd_exact"); return {}; }
 auto strata::prefill::Gemm::f16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7) -> void { strata::metal_engine::missing("strata::prefill::Gemm::f16"); }
 auto strata::prefill::Gemm::native(const uint16_t * p0, int p1, const void * p2, float * p3, int64_t p4, int64_t p5, int64_t p6, int64_t p7, float p8, int64_t p9) -> void { strata::metal_engine::missing("strata::prefill::Gemm::native"); }
@@ -342,13 +350,13 @@ namespace strata::prefill { void gdn_recurrence(float * p0, const float * p1, co
 namespace strata::prefill { void gr_broadcast(const float * p0, float * p1, int64_t p2, void * p3) { strata::metal_engine::missing("strata::prefill::gr_broadcast"); } }
 namespace strata::prefill { void gr_mix(const float * p0, const float * p1, float * p2, uint16_t * p3, int64_t p4, void * p5, uint16_t * p6, uint16_t * p7) { strata::metal_engine::missing("strata::prefill::gr_mix"); } }
 namespace strata::prefill { void gr_mix_r(const float * p0, const float * p1, const float * p2, const float * p3, float * p4, uint16_t * p5, int64_t p6, void * p7, uint16_t * p8, uint16_t * p9) { strata::metal_engine::missing("strata::prefill::gr_mix_r"); } }
-namespace strata::prefill { void gr_norm(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7) { strata::metal_engine::missing("strata::prefill::gr_norm"); } }
-namespace strata::prefill { void gr_norm_rs(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, int64_t p8) { strata::metal_engine::missing("strata::prefill::gr_norm_rs"); } }
+namespace strata::prefill { void gr_norm(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, bool p8) { strata::metal_engine::missing("strata::prefill::gr_norm"); } }
+namespace strata::prefill { void gr_norm_rs(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, int64_t p8, bool p9) { strata::metal_engine::missing("strata::prefill::gr_norm_rs"); } }
 namespace strata::prefill { void gr_silu(const float * p0, uint16_t * p1, int64_t p2, void * p3, uint16_t * p4) { strata::metal_engine::missing("strata::prefill::gr_silu"); } }
 namespace strata::prefill { bool gr_upmix(const uint16_t * p0, const uint16_t * p1, const float * p2, const float * p3, const float * p4, float * p5, uint16_t * p6, uint16_t * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::prefill::gr_upmix"); return {}; } }
 namespace strata::prefill { void gr_write(float * p0, const float * p1, const float * p2, int64_t p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::prefill::gr_write"); } }
-namespace strata::prefill { void gr_write_cvec_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, const float * p5, const int * p6, int p7, const float * p8, float p9, float * p10, uint16_t * p11, int64_t p12, void * p13, uint16_t * p14, int64_t p15) { strata::metal_engine::missing("strata::prefill::gr_write_cvec_norm_rs"); } }
-namespace strata::prefill { void gr_write_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, float p5, float * p6, uint16_t * p7, int64_t p8, void * p9, uint16_t * p10, int64_t p11) { strata::metal_engine::missing("strata::prefill::gr_write_norm_rs"); } }
+namespace strata::prefill { void gr_write_cvec_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, const float * p5, const int * p6, int p7, const float * p8, float p9, float * p10, uint16_t * p11, int64_t p12, void * p13, uint16_t * p14, int64_t p15, bool p16) { strata::metal_engine::missing("strata::prefill::gr_write_cvec_norm_rs"); } }
+namespace strata::prefill { void gr_write_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, float p5, float * p6, uint16_t * p7, int64_t p8, void * p9, uint16_t * p10, int64_t p11, bool p12) { strata::metal_engine::missing("strata::prefill::gr_write_norm_rs"); } }
 namespace strata::prefill { void kv_append(const float * p0, const float * p1, int64_t p2, int64_t p3, const int32_t * p4, int64_t p5, uint16_t * p6, uint16_t * p7, int8_t * p8, int8_t * p9, uint16_t * p10, uint16_t * p11, void * p12, const strata::kernels::KvHostPools * p13, const strata::kernels::KvHostPools * p14) { strata::metal_engine::missing("strata::prefill::kv_append"); } }
 namespace strata::prefill { void moe_combine(const float * p0, const int32_t * p1, const float * p2, const float * p3, const float * p4, float * p5, int64_t p6, void * p7) { strata::metal_engine::missing("strata::prefill::moe_combine"); } }
 namespace strata::prefill { void moe_combine_peer(const float * p0, const int32_t * p1, const float * p2, const float * p3, const float * p4, const float * p5, int64_t p6, float * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::prefill::moe_combine_peer"); } }
@@ -365,3 +373,19 @@ namespace strata::prefill { void swiglu_interleaved(const float * p0, uint16_t *
 namespace strata::prefill { void swiglu_pair(const float * p0, const float * p1, uint16_t * p2, int64_t p3, void * p4) { strata::metal_engine::missing("strata::prefill::swiglu_pair"); } }
 namespace strata::prefill { void to_bf16(const float * p0, uint16_t * p1, int64_t p2, void * p3, uint16_t * p4) { strata::metal_engine::missing("strata::prefill::to_bf16"); } }
 namespace strata::prefill { void to_f16(const float * p0, uint16_t * p1, int64_t p2, void * p3) { strata::metal_engine::missing("strata::prefill::to_f16"); } }
+namespace strata::kernels { void copy_rows_from_mapped_after(const uint32_t * p0, uint32_t p1, float * p2, const float * p3, int64_t p4, int64_t p5, const int32_t * p6, const int32_t * p7, void * p8) { strata::metal_engine::missing("strata::kernels::copy_rows_from_mapped_after"); } }
+namespace strata::kernels::cpu { void iq256_gu_rows_exact_one(int p0, const uint8_t * p1, size_t p2, size_t p3, int p4, const void * p5, float * p6, int p7, int p8) { strata::metal_engine::missing("strata::kernels::cpu::iq256_gu_rows_exact_one"); } }
+namespace strata::kernels { bool fused_gr_read_persist(const FusedGrArgs * p0, int p1, void * p2) { strata::metal_engine::missing("strata::kernels::fused_gr_read_persist"); return {}; } }
+namespace strata::kernels { void gdn_step_norm_groups(const GdnGroups & p0, const float * p1, int p2, const float * p3, const float * p4, const float * p5, const float * p6, float p7, float * p8, int p9, int p10, bool p11, void * p12) { strata::metal_engine::missing("strata::kernels::gdn_step_norm_groups"); } }
+namespace strata::kernels { void handoff_publish(float * p0, const float * p1, int64_t p2, const float * p3, int64_t p4, const float * p5, int64_t p6, uint32_t * p7, uint32_t * p8, void * p9, const uint32_t * p10) { strata::metal_engine::missing("strata::kernels::handoff_publish"); } }
+namespace strata::kernels { void hc_q8_to_bf16(const void * p0, const float * p1, uint16_t * p2, long long p3, void * p4) { strata::metal_engine::missing("strata::kernels::hc_q8_to_bf16"); } }
+namespace strata::kernels { void native_quantize_q8_1_il(const float * p0, void * p1, void * p2, int p3, int p4, void * p5) { strata::metal_engine::missing("strata::kernels::native_quantize_q8_1_il"); } }
+namespace strata::kernels { void qsa_block_scores_rows(const QsaScoreRows & p0, const float * p1, const int32_t * p2, int64_t p3, int64_t p4, const QsaShapes & p5, float * p6, void * p7) { strata::metal_engine::missing("strata::kernels::qsa_block_scores_rows"); } }
+namespace strata::kernels { void qsa_decode_attn_batch_rows(const float * p0, const QsaAttnPoolsRows & p1, const int32_t * p2, const int32_t * p3, int64_t p4, const QsaShapes & p5, float * p6, float * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::kernels::qsa_decode_attn_batch_rows"); } }
+namespace strata::kernels { bool qsa_decode_attn_split(const float * p0, const QsaAttnPools & p1, const int32_t * p2, const int32_t * p3, int64_t p4, const QsaShapes & p5, float * p6, uint64_t p7, float * p8, int64_t p9, void * p10) { strata::metal_engine::missing("strata::kernels::qsa_decode_attn_split"); return {}; } }
+namespace strata::kernels { void res_patch(int32_t * p0, const int32_t * p1, int p2, void * p3) { strata::metal_engine::missing("strata::kernels::res_patch"); } }
+namespace strata::kernels { void wait_copy_i32_from_mapped(const uint32_t * p0, uint32_t p1, int32_t * p2, const int32_t * p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::kernels::wait_copy_i32_from_mapped"); } }
+namespace strata::kernels { void wait_flag_ge_stamped(const uint32_t * p0, uint32_t p1, unsigned long long * p2, unsigned long long * p3, void * p4) { strata::metal_engine::missing("strata::kernels::wait_flag_ge_stamped"); } }
+namespace strata::kernels { void wait_handoff(const uint32_t * p0, uint32_t p1, uint32_t * p2, unsigned long long p3, void * p4) { strata::metal_engine::missing("strata::kernels::wait_handoff"); } }
+namespace strata::prefill { bool f16_range_read(float & p0, unsigned long long & p1, bool p2) { strata::metal_engine::missing("strata::prefill::f16_range_read"); return {}; } }
+namespace strata::prefill { bool gemm_f16_range_read(float * p0, unsigned long long * p1, bool p2) { strata::metal_engine::missing("strata::prefill::gemm_f16_range_read"); return {}; } }
diff --git a/metal/src/gpu/runtime.cpp b/metal/src/gpu/runtime.cpp
index edc31155..53889996 100644
--- a/metal/src/gpu/runtime.cpp
+++ b/metal/src/gpu/runtime.cpp
@@ -376,9 +376,12 @@ Error mem_get_info(size_t* free_b, size_t* total_b) {
 Error device_integrated(int* v, int) { *v = 1; return kSuccess; }
 Error device_sm_count(int* v, int) { *v = 0; return fail(kErrorUnsupported); }   // Apple reports no core count
 Error device_clock_khz(int* v, int) { *v = 0; return fail(kErrorUnsupported); }
+Error device_cc_major(int* v, int) { *v = 0; return fail(kErrorUnsupported); }   // Apple reports no compute capability
+Error device_cc_minor(int* v, int) { *v = 0; return fail(kErrorUnsupported); }
 Error runtime_version(int* v) { *v = 0; return kSuccess; }
 Error device_can_access_peer(int* v, int, int) { *v = 0; return kSuccess; }
 Error device_enable_peer_access(int, unsigned) { return fail(kErrorUnsupported); }
+Error device_disable_peer_access(int, unsigned) { return fail(kErrorUnsupported); }
 Error get_device_properties(DeviceProp* p, int dev) {
     if (dev != 0) return fail(kErrorInvalidValue);
     *p = DeviceProp{};
@@ -463,6 +466,10 @@ Error memcpy_peer_async(void* dst, int dst_dev, const void* src, int src_dev, si
     if (dst_dev != 0 || src_dev != 0) return fail(kErrorInvalidValue);   // one GPU
     return memcpy_async(dst, src, bytes, kDeviceToDevice, st);
 }
+Error memcpy_peer(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes) {
+    if (dst_dev != 0 || src_dev != 0) return fail(kErrorInvalidValue);   // one GPU: a peer copy is a plain copy
+    return memcpy_sync(dst, src, bytes, kDeviceToDevice);
+}
 Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind, Stream st) {
     StreamImpl* s = S(st);
     if (s->rec) {
@@ -475,6 +482,8 @@ Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind, Stream st
 }
 
 Error stream_create(Stream* s, unsigned) { *s = make_stream(); return kSuccess; }
+Error stream_priority_range(int* lo, int* hi) { *lo = 0; *hi = 0; return kSuccess; }   // one priority level
+Error stream_create_with_priority(Stream* s, unsigned flags, int) { return stream_create(s, flags); }
 Error stream_destroy(Stream s) {
     if (!s) return kSuccess;
     flush(s);

The diff above is the verbatim git diff of the five files (193 lines) at commit 477ac13c; git apply it against a fresh clone to reproduce the fixed tree.

How I checked

On the machine above (Apple silicon, macOS 27.0):

  • Build: full ninja -C build-metal (every target, including all metal/tests/*) — 0 errors, 0 warnings of new kinds; the only warning is the pre-existing ld: warning: ignoring duplicate libraries from the strata link line (metal/CMakeLists.txt:123 lists strata_metal_kernels twice).
  • ctest: 1/1 pass (runtime_hello, the only registered test).
  • Parity against the CPU reference on the real GPU: 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.
  • PC builds: untouched by construction — every changed file lives under metal/, which the CUDA/HIP/SYCL builds never compile (metal/CMakeLists.txt:1-2, metal/include/metal_compat/cuda_runtime.h:5-8).
  • Not measured (needs a model download, 66-84 GB): a full server run with a pack. The default-path argument above is by call-site gate, not by measurement; if you have a Mac with a model, a Q2_0 start + 200 tokens is the check.

Suggested follow-up (separate PR)

metal/tools/gen_stubs.py detects the repo root as the last -I.../include argument that contains a strata/ directory. The engine target's real include order (CMake: -I include ... -I metal/include) puts metal/include last, so running the generator with the build's actual compile line silently scans metal/include/strata (which only has gpu/), 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 a kernels/ directory) so a wrong root fails loudly.

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`, following `docs/MAC.md`) fails to build the engine at commit `477ac13c`. 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: 1. The Metal compat shim (`metal/include/metal_compat/cuda_runtime.h`) lacks six names the shared host code now uses → **compile errors**. 2. The generated stub file (`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**. 3. One of the 21, `strata::kernels::fused_gr_persist_init`, is called **unconditionally** from `Verifier::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 - Apple Silicon Mac, macOS 27.0, Command Line Tools (Apple clang) - `git clone https://github.com/Niko1221/Strata`, commit `477ac13c` (v0.1.45-metal) - `./setup.sh` → step 4 (engine build) fails; the model download never starts ## Defect 1 — shim missing six names `src/core/peer_experts.cpp` (added by #2666; `e6ad6c81` fixed the *HIP* compat for exactly this, "peer_experts.cpp did not compile on HIP in f-145-int", but not the Metal one): ``` peer_experts.cpp:72:13: error: use of undeclared identifier 'cudaMemcpyPeer' peer_experts.cpp:157:29: error: use of undeclared identifier 'cudaDeviceDisablePeerAccess' peer_experts.cpp:158:34: error: use of undeclared identifier 'cudaDeviceDisablePeerAccess' ``` `src/core/verify.cpp` (sm75/cuda86 group): ``` verify.cpp:285:54: error: use of undeclared identifier 'cudaDevAttrComputeCapabilityMajor' verify.cpp:286:54: error: use of undeclared identifier 'cudaDevAttrComputeCapabilityMinor' verify.cpp:859:17: error: use of undeclared identifier 'cudaDeviceGetStreamPriorityRange' verify.cpp:860:17: error: use of undeclared identifier 'cudaStreamCreateWithPriority' ``` (`cudaDeviceDisablePeerAccess` is called with one argument at verify/peer_experts sites; the real CUDA signature has a defaulted `flags`, 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): ``` strata::kernels::wait_handoff strata::kernels::hc_q8_to_bf16 strata::kernels::handoff_publish strata::kernels::gdn_step_norm_groups strata::kernels::wait_flag_ge_stamped strata::kernels::fused_gr_persist_init strata::kernels::fused_gr_read_persist strata::kernels::qsa_block_scores_rows strata::kernels::qsa_decode_attn_split strata::kernels::native_quantize_q8_1_il strata::kernels::wait_copy_i32_from_mapped strata::kernels::qsa_decode_attn_batch_rows strata::kernels::copy_rows_from_mapped_after strata::kernels::cpu::iq256_gu_rows_exact_one strata::kernels::res_patch strata::prefill::f16_range_read strata::prefill::gemm_f16_range_read strata::prefill::gr_norm strata::prefill::gr_norm_rs strata::prefill::gr_write_norm_rs strata::prefill::gr_write_cvec_norm_rs strata::prefill::Gemm::bf16 (stale signature) ``` 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::bf16` gained a trailing `bool x_f16` (`8bdef963`, sm75 series), so the committed 9-parameter out-of-line stub no longer matches the declaration: ``` stubs.cpp:328:29: error: out-of-line definition of 'bf16' does not match any declaration in 'strata::prefill::Gemm' ``` 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_rs` are one parameter short of the current `prefill/kernels.hpp` declarations. 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_init` stops the engine at start `Verifier::init` calls `strata::kernels::fused_gr_persist_init();` unconditionally (src/core/verify.cpp:646, no `#if`). The feature is `STRATA_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`, `#else` branch), and on Metal the .cu is not built at all. So on Metal the call reaches the stub and `missing()` 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 sibling `fused_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 — | entry point | gate | |---|---| | `fused_gr_read_persist` | branch requires `fused_gr_supported()`, which on Metal is the stub → `false` | | `native_quantize_q8_1_il` | `qil` = `STRATA_QIL` env or `device_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_rows` | `STRATA_BATCH_ATTN_ROWS=1` (opt-in) | | `qsa_decode_attn_split` | `STRATA_QSA_SPLIT_ATTN=1` (opt-in) | | `wait_copy_i32_from_mapped`, `copy_rows_from_mapped_after` | `fuse_wait_on()`: `STRATA_FUSE_WAIT` on non-HIP, off by default | | `wait_flag_ge_stamped` (×3) | `m_bal_ != nullptr` (`set_pcie_balance`, multi-GPU) or the fused-wait branch | | `wait_handoff`, `handoff_publish` | `hflag_*_d_ != nullptr` (overlapped layer split, multi-GPU) | | `res_patch` | `drive.d.res_dirty`, set only with `STRATA_ADAPT_EVICT_SYNC` | | `iq256_gu_rows_exact_one` | `STRATA_CPU_IQ_ALL_EXACT1` **and** `ggml_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_bf16` | all called only from `Prefill::run_impl` / `bf16_proj`; under `STRATA_GPU_METAL`, `Prefill::run` returns via `metal_engine::prompt_run` first (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 include `metal/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 to `strata::gpu` like every other name in the file. - **`metal/include/strata/gpu/runtime.hpp`** + **`metal/src/gpu/runtime.cpp`** — the six `strata::gpu` functions, each following the file's existing pattern: - `device_cc_major/minor`: `*v = 0; return fail(kErrorUnsupported)` — the same pattern as `device_sm_count` / `device_clock_khz` ("Apple reports no core count"). Effect: `device_is_sm75()` (src/core/verify.cpp:276) gets `ok = false` → `per_dev = 1` → `false`. Correct: an Apple GPU is not a Turing card, and `strata::sm75_default(0, 0)` is `false` anyway. - `cudaMemcpyPeer` → one-GPU: a plain device-to-device copy (`memcpy_sync`), `kErrorInvalidValue` for a non-zero device ordinal. Never actually run on a single-GPU Mac (`p2p_` stays false: `device_enable_peer_access` fails). - `cudaDeviceDisablePeerAccess` → `fail(kErrorUnsupported)`, the same as `device_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 in `mtp.cpp:438` ("HIP, Metal: the default priority"). Only reachable with `STRATA_PIPED_CONCURRENT=1` (opt-in), so default behavior is unchanged. - **`metal/src/engine/stubs.cpp`** — regenerated with the project's own `metal/tools/gen_stubs.py` from the link log: the `bf16` stub updated to the current 10-parameter signature, the four `gr_*` stubs updated to their current signatures, the 16 remaining new entry points added (21 minus `fused_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 existing `fused_gr_check() {}` (defect 3); the corresponding line is *removed* from stubs.cpp to avoid a duplicate definition. ### Full patch ```diff diff --git a/metal/include/metal_compat/cuda_runtime.h b/metal/include/metal_compat/cuda_runtime.h index eb64243e..66c1937f 100644 --- a/metal/include/metal_compat/cuda_runtime.h +++ b/metal/include/metal_compat/cuda_runtime.h @@ -46,7 +46,9 @@ inline constexpr unsigned cudaEventDisableTiming = strata::gpu::kEventDisableTim inline constexpr unsigned cudaEventBlockingSync = strata::gpu::kEventBlockingSync; inline constexpr unsigned cudaStreamNonBlocking = strata::gpu::kStreamNonBlocking; enum cudaStreamCaptureMode { cudaStreamCaptureModeGlobal = 0, cudaStreamCaptureModeThreadLocal = 1, cudaStreamCaptureModeRelaxed = 2 }; -enum cudaDeviceAttr { cudaDevAttrClockRate = 13, cudaDevAttrMultiProcessorCount = 16, cudaDevAttrIntegrated = 18 }; +enum cudaDeviceAttr { cudaDevAttrClockRate = 13, + cudaDevAttrComputeCapabilityMajor = 75, cudaDevAttrComputeCapabilityMinor = 81, + cudaDevAttrMultiProcessorCount = 16, cudaDevAttrIntegrated = 18 }; // ---- errors, devices inline cudaError_t cudaGetLastError() { return strata::gpu::get_last_error(); } @@ -65,11 +67,14 @@ inline cudaError_t cudaDeviceGetAttribute(int* v, cudaDeviceAttr a, int d) { case cudaDevAttrIntegrated: return strata::gpu::device_integrated(v, d); case cudaDevAttrMultiProcessorCount: return strata::gpu::device_sm_count(v, d); case cudaDevAttrClockRate: return strata::gpu::device_clock_khz(v, d); + case cudaDevAttrComputeCapabilityMajor: return strata::gpu::device_cc_major(v, d); + case cudaDevAttrComputeCapabilityMinor: return strata::gpu::device_cc_minor(v, d); } return strata::gpu::compat_detail::bad(); } inline cudaError_t cudaDeviceCanAccessPeer(int* v, int d, int p) { return strata::gpu::device_can_access_peer(v, d, p); } inline cudaError_t cudaDeviceEnablePeerAccess(int p, unsigned f) { return strata::gpu::device_enable_peer_access(p, f); } +inline cudaError_t cudaDeviceDisablePeerAccess(int p, unsigned f = 0) { return strata::gpu::device_disable_peer_access(p, f); } // ---- memory and copies template <class T> inline cudaError_t cudaMalloc(T** p, size_t n) { return strata::gpu::malloc_device(p, n); } @@ -93,10 +98,17 @@ inline cudaError_t cudaMemcpy2DAsync(void* d, size_t dp, const void* s, size_t s inline cudaError_t cudaMemcpyPeerAsync(void* d, int dd, const void* s, int sd, size_t n, cudaStream_t st = nullptr) { return strata::gpu::memcpy_peer_async(d, dd, s, sd, n, st); } +inline cudaError_t cudaMemcpyPeer(void* d, int dd, const void* s, int sd, size_t n) { + return strata::gpu::memcpy_peer(d, dd, s, sd, n); +} // ---- streams, events, host functions inline cudaError_t cudaStreamCreate(cudaStream_t* s) { return strata::gpu::stream_create(s); } inline cudaError_t cudaStreamCreateWithFlags(cudaStream_t* s, unsigned f) { return strata::gpu::stream_create(s, f); } +inline cudaError_t cudaDeviceGetStreamPriorityRange(int* lo, int* hi) { return strata::gpu::stream_priority_range(lo, hi); } +inline cudaError_t cudaStreamCreateWithPriority(cudaStream_t* s, unsigned f, int prio) { + return strata::gpu::stream_create_with_priority(s, f, prio); +} inline cudaError_t cudaStreamDestroy(cudaStream_t s) { return strata::gpu::stream_destroy(s); } inline cudaError_t cudaStreamSynchronize(cudaStream_t s) { return strata::gpu::stream_synchronize(s); } inline cudaError_t cudaStreamQuery(cudaStream_t s) { return strata::gpu::stream_query(s); } diff --git a/metal/include/strata/gpu/runtime.hpp b/metal/include/strata/gpu/runtime.hpp index 7791dc4a..68665659 100644 --- a/metal/include/strata/gpu/runtime.hpp +++ b/metal/include/strata/gpu/runtime.hpp @@ -70,9 +70,12 @@ Error get_device_properties(DeviceProp* p, int dev); Error device_integrated(int* v, int dev); Error device_sm_count(int* v, int dev); Error device_clock_khz(int* v, int dev); +Error device_cc_major(int* v, int dev); +Error device_cc_minor(int* v, int dev); Error runtime_version(int* v); Error device_can_access_peer(int* v, int dev, int peer); Error device_enable_peer_access(int peer, unsigned flags); +Error device_disable_peer_access(int peer, unsigned flags); inline constexpr Error kErrorPeerAccessAlreadyEnabled = Error(704); Error malloc_device_raw(void** p, size_t bytes); @@ -96,9 +99,12 @@ Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind k, Stream Error memcpy_2d_async(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width, size_t height, CopyKind k, Stream s = nullptr); Error memcpy_peer_async(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes, Stream s = nullptr); +Error memcpy_peer(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes); Error stream_create(Stream* s, unsigned flags); inline Error stream_create(Stream* s) { return stream_create(s, 0); } +Error stream_priority_range(int* lo, int* hi); +Error stream_create_with_priority(Stream* s, unsigned flags, int prio); Error stream_destroy(Stream s); Error stream_synchronize(Stream s); Error stream_query(Stream s); diff --git a/metal/src/engine/setup_host.cpp b/metal/src/engine/setup_host.cpp index e4599092..c11a5920 100644 --- a/metal/src/engine/setup_host.cpp +++ b/metal/src/engine/setup_host.cpp @@ -57,6 +57,7 @@ bool native_qsa_indexer_enabled() { return g_qsa_indexer.load(std::memory_order_ void native_rope_set_enabled(bool v) { g_rope.store(v, std::memory_order_relaxed); } bool native_rope_enabled() { return g_rope.load(std::memory_order_relaxed); } void fused_gr_check() {} // the CUDA read variants' self-test: no variants on Metal +void fused_gr_persist_init() {} // STRATA_HC_PERSIST=1 is a HIP-only read variant: nothing to init on Metal // ---- scratch sizes uint64_t ple_block_scratch_bytes() { diff --git a/metal/src/engine/stubs.cpp b/metal/src/engine/stubs.cpp index 2b651e54..17393cc8 100644 --- a/metal/src/engine/stubs.cpp +++ b/metal/src/engine/stubs.cpp @@ -114,6 +114,14 @@ #include "strata/spec/draft_source.hpp" #include "strata/spec/suffix_drafter.hpp" #include <type_traits> +#include "strata/core/family_layout.hpp" +#include "strata/core/geometry.hpp" +#include "strata/core/host_graph_launch.hpp" +#include "strata/core/sm75_series.hpp" +#include "strata/core/tc_sm75.hpp" +#include "strata/kernels/cpu/nvfp4_avx2.hpp" +#include "strata/kernels/cpu/nvfp4_avx512.hpp" +#include "strata/prefill/mmq_kq_abi.hpp" namespace strata::metal_engine { void missing(const char* name); } @@ -325,7 +333,7 @@ namespace strata::kernels { void topk_512_step(const float * p0, const QsaShapes namespace strata::kernels { void wait_flag_ge(const uint32_t * p0, uint32_t p1, void * p2) { strata::metal_engine::missing("strata::kernels::wait_flag_ge"); } } namespace strata::kernels { void wait_flag_ge_or(const uint32_t * p0, uint32_t p1, const uint32_t * p2, void * p3) { strata::metal_engine::missing("strata::kernels::wait_flag_ge_or"); } } namespace strata::kernels { void window_ids(int32_t * p0, int p1, int p2, int32_t * p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::kernels::window_ids"); } } -auto strata::prefill::Gemm::bf16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7, int64_t p8) -> void { strata::metal_engine::missing("strata::prefill::Gemm::bf16"); } +auto strata::prefill::Gemm::bf16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7, int64_t p8, bool p9) -> void { strata::metal_engine::missing("strata::prefill::Gemm::bf16"); } auto strata::prefill::Gemm::bf16_hcd_exact(const uint16_t * p0, int64_t p1, const uint16_t * p2, float * p3, int64_t p4, int64_t p5, int64_t p6) -> bool { strata::metal_engine::missing("strata::prefill::Gemm::bf16_hcd_exact"); return {}; } auto strata::prefill::Gemm::f16(const uint16_t * p0, const uint16_t * p1, float * p2, int64_t p3, int64_t p4, int64_t p5, int64_t p6, float p7) -> void { strata::metal_engine::missing("strata::prefill::Gemm::f16"); } auto strata::prefill::Gemm::native(const uint16_t * p0, int p1, const void * p2, float * p3, int64_t p4, int64_t p5, int64_t p6, int64_t p7, float p8, int64_t p9) -> void { strata::metal_engine::missing("strata::prefill::Gemm::native"); } @@ -342,13 +350,13 @@ namespace strata::prefill { void gdn_recurrence(float * p0, const float * p1, co namespace strata::prefill { void gr_broadcast(const float * p0, float * p1, int64_t p2, void * p3) { strata::metal_engine::missing("strata::prefill::gr_broadcast"); } } namespace strata::prefill { void gr_mix(const float * p0, const float * p1, float * p2, uint16_t * p3, int64_t p4, void * p5, uint16_t * p6, uint16_t * p7) { strata::metal_engine::missing("strata::prefill::gr_mix"); } } namespace strata::prefill { void gr_mix_r(const float * p0, const float * p1, const float * p2, const float * p3, float * p4, uint16_t * p5, int64_t p6, void * p7, uint16_t * p8, uint16_t * p9) { strata::metal_engine::missing("strata::prefill::gr_mix_r"); } } -namespace strata::prefill { void gr_norm(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7) { strata::metal_engine::missing("strata::prefill::gr_norm"); } } -namespace strata::prefill { void gr_norm_rs(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, int64_t p8) { strata::metal_engine::missing("strata::prefill::gr_norm_rs"); } } +namespace strata::prefill { void gr_norm(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, bool p8) { strata::metal_engine::missing("strata::prefill::gr_norm"); } } +namespace strata::prefill { void gr_norm_rs(const float * p0, const float * p1, float p2, float * p3, uint16_t * p4, int64_t p5, void * p6, uint16_t * p7, int64_t p8, bool p9) { strata::metal_engine::missing("strata::prefill::gr_norm_rs"); } } namespace strata::prefill { void gr_silu(const float * p0, uint16_t * p1, int64_t p2, void * p3, uint16_t * p4) { strata::metal_engine::missing("strata::prefill::gr_silu"); } } namespace strata::prefill { bool gr_upmix(const uint16_t * p0, const uint16_t * p1, const float * p2, const float * p3, const float * p4, float * p5, uint16_t * p6, uint16_t * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::prefill::gr_upmix"); return {}; } } namespace strata::prefill { void gr_write(float * p0, const float * p1, const float * p2, int64_t p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::prefill::gr_write"); } } -namespace strata::prefill { void gr_write_cvec_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, const float * p5, const int * p6, int p7, const float * p8, float p9, float * p10, uint16_t * p11, int64_t p12, void * p13, uint16_t * p14, int64_t p15) { strata::metal_engine::missing("strata::prefill::gr_write_cvec_norm_rs"); } } -namespace strata::prefill { void gr_write_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, float p5, float * p6, uint16_t * p7, int64_t p8, void * p9, uint16_t * p10, int64_t p11) { strata::metal_engine::missing("strata::prefill::gr_write_norm_rs"); } } +namespace strata::prefill { void gr_write_cvec_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, const float * p5, const int * p6, int p7, const float * p8, float p9, float * p10, uint16_t * p11, int64_t p12, void * p13, uint16_t * p14, int64_t p15, bool p16) { strata::metal_engine::missing("strata::prefill::gr_write_cvec_norm_rs"); } } +namespace strata::prefill { void gr_write_norm_rs(float * p0, const float * p1, const float * p2, int64_t p3, const float * p4, float p5, float * p6, uint16_t * p7, int64_t p8, void * p9, uint16_t * p10, int64_t p11, bool p12) { strata::metal_engine::missing("strata::prefill::gr_write_norm_rs"); } } namespace strata::prefill { void kv_append(const float * p0, const float * p1, int64_t p2, int64_t p3, const int32_t * p4, int64_t p5, uint16_t * p6, uint16_t * p7, int8_t * p8, int8_t * p9, uint16_t * p10, uint16_t * p11, void * p12, const strata::kernels::KvHostPools * p13, const strata::kernels::KvHostPools * p14) { strata::metal_engine::missing("strata::prefill::kv_append"); } } namespace strata::prefill { void moe_combine(const float * p0, const int32_t * p1, const float * p2, const float * p3, const float * p4, float * p5, int64_t p6, void * p7) { strata::metal_engine::missing("strata::prefill::moe_combine"); } } namespace strata::prefill { void moe_combine_peer(const float * p0, const int32_t * p1, const float * p2, const float * p3, const float * p4, const float * p5, int64_t p6, float * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::prefill::moe_combine_peer"); } } @@ -365,3 +373,19 @@ namespace strata::prefill { void swiglu_interleaved(const float * p0, uint16_t * namespace strata::prefill { void swiglu_pair(const float * p0, const float * p1, uint16_t * p2, int64_t p3, void * p4) { strata::metal_engine::missing("strata::prefill::swiglu_pair"); } } namespace strata::prefill { void to_bf16(const float * p0, uint16_t * p1, int64_t p2, void * p3, uint16_t * p4) { strata::metal_engine::missing("strata::prefill::to_bf16"); } } namespace strata::prefill { void to_f16(const float * p0, uint16_t * p1, int64_t p2, void * p3) { strata::metal_engine::missing("strata::prefill::to_f16"); } } +namespace strata::kernels { void copy_rows_from_mapped_after(const uint32_t * p0, uint32_t p1, float * p2, const float * p3, int64_t p4, int64_t p5, const int32_t * p6, const int32_t * p7, void * p8) { strata::metal_engine::missing("strata::kernels::copy_rows_from_mapped_after"); } } +namespace strata::kernels::cpu { void iq256_gu_rows_exact_one(int p0, const uint8_t * p1, size_t p2, size_t p3, int p4, const void * p5, float * p6, int p7, int p8) { strata::metal_engine::missing("strata::kernels::cpu::iq256_gu_rows_exact_one"); } } +namespace strata::kernels { bool fused_gr_read_persist(const FusedGrArgs * p0, int p1, void * p2) { strata::metal_engine::missing("strata::kernels::fused_gr_read_persist"); return {}; } } +namespace strata::kernels { void gdn_step_norm_groups(const GdnGroups & p0, const float * p1, int p2, const float * p3, const float * p4, const float * p5, const float * p6, float p7, float * p8, int p9, int p10, bool p11, void * p12) { strata::metal_engine::missing("strata::kernels::gdn_step_norm_groups"); } } +namespace strata::kernels { void handoff_publish(float * p0, const float * p1, int64_t p2, const float * p3, int64_t p4, const float * p5, int64_t p6, uint32_t * p7, uint32_t * p8, void * p9, const uint32_t * p10) { strata::metal_engine::missing("strata::kernels::handoff_publish"); } } +namespace strata::kernels { void hc_q8_to_bf16(const void * p0, const float * p1, uint16_t * p2, long long p3, void * p4) { strata::metal_engine::missing("strata::kernels::hc_q8_to_bf16"); } } +namespace strata::kernels { void native_quantize_q8_1_il(const float * p0, void * p1, void * p2, int p3, int p4, void * p5) { strata::metal_engine::missing("strata::kernels::native_quantize_q8_1_il"); } } +namespace strata::kernels { void qsa_block_scores_rows(const QsaScoreRows & p0, const float * p1, const int32_t * p2, int64_t p3, int64_t p4, const QsaShapes & p5, float * p6, void * p7) { strata::metal_engine::missing("strata::kernels::qsa_block_scores_rows"); } } +namespace strata::kernels { void qsa_decode_attn_batch_rows(const float * p0, const QsaAttnPoolsRows & p1, const int32_t * p2, const int32_t * p3, int64_t p4, const QsaShapes & p5, float * p6, float * p7, int64_t p8, void * p9) { strata::metal_engine::missing("strata::kernels::qsa_decode_attn_batch_rows"); } } +namespace strata::kernels { bool qsa_decode_attn_split(const float * p0, const QsaAttnPools & p1, const int32_t * p2, const int32_t * p3, int64_t p4, const QsaShapes & p5, float * p6, uint64_t p7, float * p8, int64_t p9, void * p10) { strata::metal_engine::missing("strata::kernels::qsa_decode_attn_split"); return {}; } } +namespace strata::kernels { void res_patch(int32_t * p0, const int32_t * p1, int p2, void * p3) { strata::metal_engine::missing("strata::kernels::res_patch"); } } +namespace strata::kernels { void wait_copy_i32_from_mapped(const uint32_t * p0, uint32_t p1, int32_t * p2, const int32_t * p3, int64_t p4, void * p5) { strata::metal_engine::missing("strata::kernels::wait_copy_i32_from_mapped"); } } +namespace strata::kernels { void wait_flag_ge_stamped(const uint32_t * p0, uint32_t p1, unsigned long long * p2, unsigned long long * p3, void * p4) { strata::metal_engine::missing("strata::kernels::wait_flag_ge_stamped"); } } +namespace strata::kernels { void wait_handoff(const uint32_t * p0, uint32_t p1, uint32_t * p2, unsigned long long p3, void * p4) { strata::metal_engine::missing("strata::kernels::wait_handoff"); } } +namespace strata::prefill { bool f16_range_read(float & p0, unsigned long long & p1, bool p2) { strata::metal_engine::missing("strata::prefill::f16_range_read"); return {}; } } +namespace strata::prefill { bool gemm_f16_range_read(float * p0, unsigned long long * p1, bool p2) { strata::metal_engine::missing("strata::prefill::gemm_f16_range_read"); return {}; } } diff --git a/metal/src/gpu/runtime.cpp b/metal/src/gpu/runtime.cpp index edc31155..53889996 100644 --- a/metal/src/gpu/runtime.cpp +++ b/metal/src/gpu/runtime.cpp @@ -376,9 +376,12 @@ Error mem_get_info(size_t* free_b, size_t* total_b) { Error device_integrated(int* v, int) { *v = 1; return kSuccess; } Error device_sm_count(int* v, int) { *v = 0; return fail(kErrorUnsupported); } // Apple reports no core count Error device_clock_khz(int* v, int) { *v = 0; return fail(kErrorUnsupported); } +Error device_cc_major(int* v, int) { *v = 0; return fail(kErrorUnsupported); } // Apple reports no compute capability +Error device_cc_minor(int* v, int) { *v = 0; return fail(kErrorUnsupported); } Error runtime_version(int* v) { *v = 0; return kSuccess; } Error device_can_access_peer(int* v, int, int) { *v = 0; return kSuccess; } Error device_enable_peer_access(int, unsigned) { return fail(kErrorUnsupported); } +Error device_disable_peer_access(int, unsigned) { return fail(kErrorUnsupported); } Error get_device_properties(DeviceProp* p, int dev) { if (dev != 0) return fail(kErrorInvalidValue); *p = DeviceProp{}; @@ -463,6 +466,10 @@ Error memcpy_peer_async(void* dst, int dst_dev, const void* src, int src_dev, si if (dst_dev != 0 || src_dev != 0) return fail(kErrorInvalidValue); // one GPU return memcpy_async(dst, src, bytes, kDeviceToDevice, st); } +Error memcpy_peer(void* dst, int dst_dev, const void* src, int src_dev, size_t bytes) { + if (dst_dev != 0 || src_dev != 0) return fail(kErrorInvalidValue); // one GPU: a peer copy is a plain copy + return memcpy_sync(dst, src, bytes, kDeviceToDevice); +} Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind, Stream st) { StreamImpl* s = S(st); if (s->rec) { @@ -475,6 +482,8 @@ Error memcpy_async(void* dst, const void* src, size_t bytes, CopyKind, Stream st } Error stream_create(Stream* s, unsigned) { *s = make_stream(); return kSuccess; } +Error stream_priority_range(int* lo, int* hi) { *lo = 0; *hi = 0; return kSuccess; } // one priority level +Error stream_create_with_priority(Stream* s, unsigned flags, int) { return stream_create(s, flags); } Error stream_destroy(Stream s) { if (!s) return kSuccess; flush(s); ``` The diff above is the verbatim `git diff` of the five files (193 lines) at commit `477ac13c`; `git apply` it against a fresh clone to reproduce the fixed tree. ## How I checked On the machine above (Apple silicon, macOS 27.0): - **Build:** full `ninja -C build-metal` (every target, including all `metal/tests/*`) — 0 errors, 0 warnings of new kinds; the only warning is the pre-existing `ld: warning: ignoring duplicate libraries` from the `strata` link line (metal/CMakeLists.txt:123 lists `strata_metal_kernels` twice). - **`ctest`:** 1/1 pass (`runtime_hello`, the only registered test). - **Parity against the CPU reference on the real GPU:** `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. - **PC builds:** untouched by construction — every changed file lives under `metal/`, which the CUDA/HIP/SYCL builds never compile (metal/CMakeLists.txt:1-2, metal/include/metal_compat/cuda_runtime.h:5-8). - **Not measured (needs a model download, 66-84 GB):** a full server run with a pack. The default-path argument above is by call-site gate, not by measurement; if you have a Mac with a model, a Q2_0 start + 200 tokens is the check. ## Suggested follow-up (separate PR) `metal/tools/gen_stubs.py` detects the repo root as the **last** `-I.../include` argument that contains a `strata/` directory. The engine target's real include order (CMake: `-I include ... -I metal/include`) puts `metal/include` last, so running the generator with the build's actual compile line silently scans `metal/include/strata` (which only has `gpu/`), 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 a `kernels/` directory) so a wrong root fails loudly.
Author
Owner

@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:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6271375161 --> @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: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1183
No description provided.