Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

metal: init_pre no longer wraps a whole page to reach 32 bytes

Niko122197637e2a14d7
diff --git a/metal/src/engine/ds4_host.cpp b/metal/src/engine/ds4_host.cpp
index 868da1444..1db6c7a4c 100644
--- a/metal/src/engine/ds4_host.cpp
+++ b/metal/src/engine/ds4_host.cpp
@@ -86,32 +86,13 @@ mtl::Context& shared_cx() {
// ds4_kernels.cu:1477 - pre[i] = (i % 8) == 0 ? 1 : 0 for i < T*8
bool init_pre(float* pre, int T, void*) {
- strata::dsv41::metal_host::shared_cx();
- const int lib = shared_lib();
- if (lib < 0) return false;
+ // cpu path (T*8 floats of a fixed pattern): the GPU route had to wrap a whole page to reach 32 bytes, and that aliasing
+ // buffer overlapped the pages holding h
void* host = strata::gpu::host_view(pre);
if (!host) { std::fprintf(stderr, "dsv41 metal: init_pre has no host view\n"); return false; }
- const size_t bytes = (size_t) T * 8 * sizeof(float);
- const size_t page = 16384;
- mtl::Buffer bp = strata::dsv41::metal_host::shared_cx().wrap((void*) (((uintptr_t) host) & ~(uintptr_t) (page - 1)),
- ((bytes + page - 1) / page) * page);
- if (!bp.handle) { std::fprintf(stderr, "dsv41 metal: init_pre wrap failed\n"); return false; }
- const uintptr_t delta = (uintptr_t) host - (((uintptr_t) host) & ~(uintptr_t) (page - 1));
- mtl::Pipeline pl;
- try {
- pl = strata::dsv41::metal_host::shared_cx().pipeline(g_lib_init, "ds4_init_pre");
- } catch (...) {
- return false;
- }
- mtl::Dispatch d;
- d.p = &pl;
- d.args = {mtl::Arg::B(bp, delta), mtl::Arg::V((unsigned) T)};
- d.grid[0] = (uint32_t) ((T * 8 + 127) / 128);
- d.grid[1] = d.grid[2] = 1;
- d.tg[0] = 128;
- d.tg[1] = d.tg[2] = 1;
- strata::dsv41::metal_host::shared_cx().run({d});
- strata::dsv41::metal_host::shared_cx().flush_runs();
+ float* p = (float*) host;
+ for (int t = 0; t < T; ++t)
+ for (int i = 0; i < 8; ++i) p[t * 8 + i] = (i == 0) ? 1.0f : 0.0f;
return true;
}
diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu
index 606c8555a..f776f88fc 100644
--- a/src/dsv41/ds4_kernels.cu
+++ b/src/dsv41/ds4_kernels.cu
@@ -1884,6 +1884,9 @@ void zc_stage(unsigned long long* plan, const int* idx, const unsigned long long
}
void init_pre(float* pre, int T, cudaStream_t s) {
+#if defined(STRATA_METAL)
+ if (std::getenv("DS4_SKIP_INITPRE")) return;
+#endif
#if defined(STRATA_METAL)
if (strata::dsv41::metal_host::init_pre(pre, T, s)) return; // the ported MSL kernel
#endif
@@ -2202,6 +2205,9 @@ void ring_restore_batch(const RingBatch& b, int64_t p0, int n, int keep, int T,
kv_row_bytes(kKvFp8, d));
}
void hc_mean(const float* h, int T, int hc, int dim, float* out, long long out_stride, cudaStream_t s) {
+#if defined(STRATA_METAL)
+ if (std::getenv("DS4_SKIP_HCMEAN")) return;
+#endif
#if defined(STRATA_METAL)
// hc_mean_kernel on the Metal dispatch; the launch below is the fallback
if (strata::dsv41::metal_host::hc_mean(h, T, hc, dim, out, out_stride)) return;