metal: commit the queued GPU work before the CPU lane runs (they overlap)

This commit is contained in:
Niko1221 committed 2026-10-24 16:11:09 +02:00
1 parent 42a982e033
commit 7c77f388dd
3 files changed
+9

No files matched your search

@@ -138,6 +138,7 @@ inline cudaError_t cudaDeviceDisablePeerAccess(int) { return cudaSuccess; } //
// the deferred command buffer mtl_rt batches the port's dispatches into: a copy (or any host read of a device result)
// has to commit it first, or it reads memory the GPU has not written yet. Defined in ds4_finish.cpp.
extern "C" void ds4_metal_flush();
extern "C" void ds4_metal_kick();
template <class T> inline cudaError_t cudaMalloc(T** p, size_t n) { return strata::gpu::malloc_device(p, n); }
inline cudaError_t cudaFree(void* p) { return strata::gpu::free_device(p); }
+5
View File
@@ -2101,8 +2101,13 @@ extern "C" void* ds4_ctx_mark() {
return g_cx->mark();
}
extern "C" void ds4_ctx_wait(void* token) {
if (g_cx) g_cx->split_runs(); // (what is queued after the mark starts on the GPU while the host waits)
if (g_cx && token) g_cx->wait_mark(token);
}
// commit the batched dispatches without waiting: the GPU starts on them while the host goes on (the CPU lane)
extern "C" void ds4_metal_kick() {
if (g_cx) g_cx->split_runs();
}
extern "C" void ds4_metal_flush() {
// The engine's copies (the embedding rows, the streamed experts, the readbacks) are encoded on strata::gpu's default
+3
View File
@@ -8285,6 +8285,9 @@ struct Model::Impl {
}
if (!ents.empty()) {
const double tc = now_ms();
#if defined(STRATA_METAL)
ds4_metal_kick(); // (the VRAM experts run on the GPU while the CPU lane works)
#endif
cpu_experts(l, h_x, ents);
std::fill(h_part, h_part + (size_t) T * D, 0.0f);
for (int sl = 0; sl < nslots; ++sl) {