From fd4c9ad541c819c7ae2987f9cc758b856e6afd13 Mon Sep 17 00:00:00 2001 From: jze9 Date: Tue, 7 Jul 2026 23:08:37 +0500 Subject: [PATCH] GPU: cut per-step device->host sync in batch integrator The naive port synced every step (bool(any(active)) early-break), which on GPU is a device->host copy per iteration that serializes the pipeline and made cupy slower than numpy. Check the break condition only every 256 steps. Correctness unchanged (batch still validates vs scipy and CPU). Co-Authored-By: Claude Sonnet 5 --- src/gausse/gpu/batch_integrator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gausse/gpu/batch_integrator.py b/src/gausse/gpu/batch_integrator.py index 7e60322..fce4051 100644 --- a/src/gausse/gpu/batch_integrator.py +++ b/src/gausse/gpu/batch_integrator.py @@ -139,9 +139,12 @@ def integrate_batch_discharge( energy_diss = xp.zeros(n, dtype=xp.float64) _old_err = xp.seterr(all="ignore") if hasattr(xp, "seterr") else None # стиффные конфиги переполняют fixed-step - for _ in range(max_steps): + # проверку «все ли готовы» делаем НЕ каждый шаг: на GPU это device->host + # синхронизация, которая убивает конвейер. Раз в SYNC_EVERY шагов достаточно. + SYNC_EVERY = 256 + for step in range(max_steps): active = ~done - if not bool(xp.any(active)): + if step % SYNC_EVERY == 0 and not bool(xp.any(active)): break q_old, i_old, x_old, v_old = q, i, x, v