rugnux: measured-centre spot finding beside the first pass uses every card
The speculation that spot-finds and indexes at the measured beam centre beside the first pass (only with two GPUs or more) put all its spot-finding workers on card 1. The file centre's spot finding ends long before the speculation's, so the speculation is what the first pass waits on (T4 server, kdp: main pass spot finding done at 1.3 s, speculation at 5.6 s). Its workers now take card t % cards, as the first pass's own workers do; worker t builds and frees its engine on the same card, since the destructor's OnWorkers maps t the same way. Spots are a pure function of the frame, so which card finds them cannot change them. The prototype measured kdp 25.9 -> 23.6 s on the 4-card T4 with md5 unchanged on 5 sets. On a one-card machine the speculation does not start (get_gpu_count() < 2), so nothing changes there: p.mtz md5 identical to rc175-next 41fab6156 on myob_x10sa, cytc_x10sa, thau_x10sa_16keV, 8a1a, 11if, 7qis, 6h5t, kdp_x10sa_20keV at default -N, -N 8 and CUDA_VISIBLE_DEVICES=0 (5080 workstation). The multi-card gain and the 2-card risk (speculation workers now share card 0 with the main pass) are not measured here. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
This commit is contained in:
1 parent
b43844ae06
commit
f33d8e2a68
1 file changed
+16
-12
+16
-12
@@ -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<size_t>(nworkers, 1)) {}
|
||||
start_image(start_image), stride(stride), engines(std::max<size_t>(nworkers, 1)) {}
|
||||
|
||||
~SpotFindingWorkers() {
|
||||
OnWorkers(engines.size(), [&](size_t t) { engines[t] = Engine{}; });
|
||||
@@ -164,12 +165,13 @@ namespace {
|
||||
std::unique_ptr<AzimuthalIntegrationProfile> 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 <class Fn> void OnWorkers(size_t n, Fn fn) {
|
||||
std::vector<std::future<void>> 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<int32_t>(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<Engine> 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<double> experiment_key;
|
||||
std::vector<double> 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<int> &ordinals) {
|
||||
std::vector<int> wanted;
|
||||
for (const int o : ordinals)
|
||||
|
||||
Reference in new issue
Block a user