Refinement: the engine polls for its evaluations and the pair count comes back pinned; the slots beyond one per card go to the cards the ladder's long trials leave free

The GPU engine's waits on its stream (every evaluation, the refits' transforms) and the model density's wait for
the (brick, atom) pair count were blocking event and stream synchronisations; where a weight trial has a card to
itself, as on a box with a card per trial, the wake-up of the sleeping thread is on the critical path of every
evaluation. Both now poll, and the pair count and overflow flag come back into pinned memory instead of a
pageable int (a pageable copy back is staged and blocks the host for the whole stream).

OwnSlotDevices places the slots beyond one per card on the cards the ladder's long trials (those refining B)
leave free, so that on four cards the three B rungs have a card each and the three B-held rungs share the fourth,
instead of two cards each carrying a B rung beside a B-held one. The outcome does not depend on the placement.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
This commit is contained in:
leonarski_fandClaude Fable 5.1 committed 2026-10-26 22:41:43 +01:00
1 parent 68e567bd02
commit 3189f71e8f
4 files changed
+32 -10

No files matched your search

@@ -311,6 +311,7 @@ ModelDensityGPU::ModelDensityGPU(cudaStream_t stream, size_t max_atoms_, size_t
value_sorted = CudaDevicePtr<int>(np, sync);
brick_start = CudaDevicePtr<int>(nb, sync);
brick_end = CudaDevicePtr<int>(nb, sync);
host_count = CudaHostPtr<int>(2);
cub_bytes = CubBytes(na, np);
cub_temp = CudaDevicePtr<char>(std::max<size_t>(cub_bytes, 1), sync);
}
@@ -351,11 +352,14 @@ void ModelDensityGPU::Compute(const float4 *d_pos, float *d_grid) {
cuda_err(cudaGetLastError());
size_t temp = cub_bytes;
cuda_err(cub::DeviceScan::ExclusiveSum(cub_temp.get(), temp, count.get(), offset.get(), n_atoms + 1, stream));
int npairs = 0;
int over = 0;
cuda_err(cudaMemcpyAsync(&npairs, offset.get() + n_atoms, sizeof(int), cudaMemcpyDeviceToHost, stream));
cuda_err(cudaMemcpyAsync(&over, overflow.get(), sizeof(int), cudaMemcpyDeviceToHost, stream));
cuda_err(cudaStreamSynchronize(stream));
// the count and the flag into pinned memory, the stream polled for them: this wait is on every evaluation
cuda_err(cudaMemcpyAsync(host_count.get(), offset.get() + n_atoms, sizeof(int), cudaMemcpyDeviceToHost, stream));
cuda_err(cudaMemcpyAsync(host_count.get() + 1, overflow.get(), sizeof(int), cudaMemcpyDeviceToHost, stream));
cudaError_t err;
while ((err = cudaStreamQuery(stream)) == cudaErrorNotReady) {}
cuda_err(err);
const int npairs = host_count[0];
const int over = host_count[1];
if (over)
throw JFJochException(JFJochExceptionCategory::GPUCUDAError, "model density: an atom's box over the bricks per axis");
if (static_cast<size_t>(npairs) > max_pairs)