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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user