diff --git a/rugnux/RugnuxFirstPass.cpp b/rugnux/RugnuxFirstPass.cpp index 0feb426d9..c4fb4c61a 100644 --- a/rugnux/RugnuxFirstPass.cpp +++ b/rugnux/RugnuxFirstPass.cpp @@ -119,17 +119,18 @@ namespace { return spots; } - // First-pass spot finding on workers of its own, all on one card (`device`), for work that runs - // beside the first pass. Each worker keeps its engine from one call to the next - building one - // costs far more than a frame - and gives it back on that card. + // First-pass spot finding on workers of its own, spread over the cards as the first pass's own + // workers are (worker t on card t % cards), for work that runs beside the first pass. Each worker + // keeps its engine from one call to the next - building one costs far more than a frame - and + // gives it back on that card. class SpotFindingWorkers { public: SpotFindingWorkers(JFJochReader &reader, const DiffractionExperiment &x, const AzimuthalIntegrationMapping &mapping, const PixelMask &mask, const SpotFindingSettings &settings, const JFJochReaderDataset &dataset, - int start_image, int stride, size_t nworkers, int device) + int start_image, int stride, size_t nworkers) : reader(reader), x(x), mapping(mapping), mask(mask), settings(settings), dataset(dataset), - start_image(start_image), stride(stride), device(device), engines(std::max(nworkers, 1)) {} + start_image(start_image), stride(stride), engines(std::max(nworkers, 1)) {} ~SpotFindingWorkers() { OnWorkers(engines.size(), [&](size_t t) { engines[t] = Engine{}; }); @@ -164,12 +165,13 @@ namespace { std::unique_ptr profile; }; - // fn(t) on n threads of its own, on the card. + // fn(t) on n threads of its own, thread t on card t % cards: the card its engine lives on. template void OnWorkers(size_t n, Fn fn) { std::vector> futures; for (size_t t = 0; t < n; t++) futures.emplace_back(std::async(std::launch::async, [this, &fn, t] { - pin_gpu(device); + if (const int32_t gpus = get_gpu_count(); gpus > 0) + pin_gpu(static_cast(t) % gpus); fn(t); })); for (auto &f : futures) @@ -182,7 +184,7 @@ namespace { const PixelMask &mask; const SpotFindingSettings settings; const JFJochReaderDataset &dataset; - const int start_image, stride, device; + const int start_image, stride; std::vector engines; Logger logger{"Rugnux"}; }; @@ -1369,9 +1371,11 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) { // budget); otherwise that pass is run there as before. The schemes are scored there in either // case, on the run's own indexer. // - // Only with a second GPU, whose card its spot finding takes: on one card the two passes share the - // card and the reader, and measured, running them side by side saved nothing. There the check - // runs its pass after the first, as it always did. + // Only with a second GPU: on one card the two passes share the card and the reader, and measured, + // running them side by side saved nothing. There the check runs its pass after the first, as it + // always did. With two or more its spot finding spreads over all the cards, as the first pass's + // does: the file centre's spot finding is over long before this pass's, so this one is what the + // first pass waits on. struct CentreSpeculation { std::vector experiment_key; std::vector key; @@ -1413,7 +1417,7 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) { settings = config_.spot_finding, dataset, start_image, nworkers = engines.size()] { SpotFindingWorkers workers(reader_, *cs.experiment, *cs.mapping, *cs.mask, settings, *dataset, - start_image, config_.stride, nworkers, /*device=*/1); + start_image, config_.stride, nworkers); const auto find = [&](const std::vector &ordinals) { std::vector wanted; for (const int o : ordinals)