From c1b745fdfc7e27467eef181d38ecae543a339275 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 14 Oct 2026 12:01:57 +0200 Subject: [PATCH] Image-loop workers per card bounded by the card's memory A worker of the full-analysis image loop holds about 24 bytes a detector pixel on its card (sixteen held 6.3 GB on a 16.8 Mpx detector, measured with nsys). The workers now keep to half of the card's total memory: on a 16 GB card that is still the sixteen of before for detectors up to ~21 Mpx; on an 8 GB card with a 16.8 Mpx detector it is ten, where sixteen ran out of memory with ~7 GB free. How many workers there are changes only the loop's speed. An explicit -N is obeyed as before. Co-Authored-By: Claude Opus 5.5 (1M context) --- rugnux/RugnuxImagePass.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rugnux/RugnuxImagePass.cpp b/rugnux/RugnuxImagePass.cpp index 90060a378..3ba388961 100644 --- a/rugnux/RugnuxImagePass.cpp +++ b/rugnux/RugnuxImagePass.cpp @@ -368,9 +368,19 @@ void Rugnux::ImagePass(PipelineLocals &p) { // which is what a previous attempt at this got wrong. // Only the full-analysis worker drives a card; the azimuthal one preprocesses and integrates on // the CPU and wants every thread it can have, so the cap must not reach it. + // A worker also holds about 24 bytes a detector pixel of its card - sixteen held 6.3 GB on a 16.8 Mpx + // detector - and the workers keep to half of the card, so a small card gets fewer of them. How many + // there are changes only how fast the loop runs, never what it computes. const int gpus = get_gpu_count(); + int workers_per_card = 16; + if (gpus > 0) { + constexpr int64_t WORKER_BYTES_PER_PIXEL = 24; + const auto fit = static_cast(get_gpu_total_memory(0) / 2) + / (WORKER_BYTES_PER_PIXEL * experiment_.GetPixelsNum()); + workers_per_card = static_cast(std::clamp(fit, 1, 16)); + } const int image_workers = (per_image_analysis && config_.nthreads_auto && gpus > 0) - ? std::min(config_.nthreads, std::max(16, 16 * gpus)) + ? std::min(config_.nthreads, workers_per_card * gpus) : config_.nthreads; if (image_workers < config_.nthreads) logger.Info("Per-image loop: {} of {} threads ({} GPUs) - past what a card can take queue "