rugnux all-observation arm: observations copied on the card, not staged from the reflections again

The all-observation arm of the space-group search merges on a copy of the engine (CloneIngest), and
its IngestDevice staged every observation from the ~92-byte source reflections a second time -
concurrently with the main engine's own staging of the same reflections. Now the main engine
stages, and the copy takes its card arrays with cudaMemcpyPeer (a device copy when both engines
share the card, as on a one-card machine). CloneIngest no longer copies the predicted partiality,
which only that staging read.

Output identical (cytc p.hkl md5, and with --dump-observations the dump md5).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EizBKhTqrAYago9KJG3dA3
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-10-11 10:52:57 +02:00
1 parent 42ed7261d3
commit b46b4a4657
5 files changed
+45 -19

No files matched your search

@@ -691,12 +691,6 @@ std::unique_ptr<RotationScaleMerge> RotationScaleMerge::CloneIngest(int device,
c->logger = &log;
c->gpu_device = device;
c->write_back_per_frame_scale = false;
// Of the ingest arrays, IngestDevice reads only this one (StageObservations); the rest served
// IngestHost alone.
if (ingest_partiality) {
c->ingest_partiality.reset(new float[n_partials_obs]);
std::copy_n(ingest_partiality.get(), n_partials_obs, c->ingest_partiality.get());
}
#ifdef JFJOCH_USE_CUDA
if (gpu_)
c->gpu_ = std::make_unique<RotationScaleMergeGPU>(device);
@@ -704,13 +698,16 @@ std::unique_ptr<RotationScaleMerge> RotationScaleMerge::CloneIngest(int device,
return c;
}
void RotationScaleMerge::IngestDevice() {
void RotationScaleMerge::IngestDevice(const RotationScaleMerge *observations_from) {
const ScopedGpuPin pin(gpu_device); // see IngestHost
TimingMark mark(*logger, "rsm ingest (device)");
#ifdef JFJOCH_USE_CUDA
if (resident_ingest)
if (gpu_active_ && observations_from) {
gpu_->SetPartialsLayout(n_partials_obs, n_frames, frame_start.data(), frame_count.data());
gpu_->CopyObservationsFrom(*observations_from->gpu_);
} else if (resident_ingest)
StageObservations();
if (gpu_active_ && !resident_ingest) {
if (gpu_active_ && !resident_ingest && !observations_from) {
const int n = static_cast<int>(partials.size());
gpu_->SetPartialsLayout(n, n_frames, frame_start.data(), frame_count.data());
// Staged in bounded slices: fourteen full-length arrays at once are more than half of the
@@ -122,7 +122,10 @@ public:
// builds every host array, the device half allocates the GPU's arrays and fills them. A caller can
// run the host half beside other work and the device half once the GPU has room.
void IngestHost();
void IngestDevice();
// With `observations_from` - the engine this one was copied from (CloneIngest), its own
// IngestDevice done - the observations are copied from that engine's card arrays rather than
// staged from the reflections again.
void IngestDevice(const RotationScaleMerge *observations_from = nullptr);
// Scale (per-frame G) -> smooth G -> 3D combine -> scale fulls -> merge -> error model -> statistics
// for the space group currently set on the experiment, reusing the ingested buffers.
@@ -157,8 +160,8 @@ public:
void WriteBackPerFrameScale() { FinalizePerFrameScale(last_cc, last_cc_n, last_frame_scaled); }
// A second engine on this one's ingest, on `device` and logging to `log`, for a merge to run beside
// this engine's: the host half of the ingest is copied, and the copy's IngestDevice() is still to
// be called. Call between IngestHost() and IngestDevice(). No merge depends on the merges run
// this engine's: the host half of the ingest is copied, and the copy's IngestDevice(this) is still
// to be called, after this engine's own. Call between IngestHost() and IngestDevice(). No merge depends on the merges run
// before it (see RunArm), so a merge on the copy gives what the same merge gives on this engine.
// The copy does not write its per-frame scales back (WriteBackPerFrameScale does).
[[nodiscard]] std::unique_ptr<RotationScaleMerge> CloneIngest(int device, Logger &log) const;
@@ -178,6 +181,7 @@ public:
// The GPU the engine runs on (device 0 by default). Set before Ingest(). The device only says where
// the merge runs: on cards of one model the result is the same on any of them.
void SetGpuDevice(int device) { gpu_device = device; }
[[nodiscard]] int GetGpuDevice() const { return gpu_device; }
// Whether Run() also hands back the merge's fulls unmerged (Result::scaled_fulls). Off by default:
// it is a copy as long as the fulls, wanted only by a caller that writes them.
@@ -1367,6 +1367,22 @@ void RotationScaleMergeGPU::SetObsField(ObsField f, int offset, int count, const
}
}
void RotationScaleMergeGPU::CopyObservationsFrom(const RotationScaleMergeGPU &from) {
DeviceGuard guard(impl_->device, impl_->available);
auto &d = *impl_;
const auto &f = *from.impl_;
const auto copy = [&](auto &dst, const auto &src) {
CudaCheck(cudaMemcpyPeerAsync(dst.get(), d.device, src.get(), f.device,
size_t(d.n_obs) * sizeof(*src.get()), d.s()), "copy observations");
};
copy(d.I, f.I); copy(d.sigma, f.sigma); copy(d.prescaling_corr, f.prescaling_corr);
copy(d.partiality, f.partiality); copy(d.zeta, f.zeta); copy(d.corr, f.corr);
copy(d.bkg, f.bkg); copy(d.var_bkg, f.var_bkg); copy(d.image_number, f.image_number);
copy(d.d_obs, f.d_obs); copy(d.px_obs, f.px_obs); copy(d.py_obs, f.py_obs);
copy(d.frame, f.frame); copy(d.on_ice, f.on_ice); copy(d.clipped, f.clipped);
CudaCheck(cudaStreamSynchronize(d.s()), "copy observations");
}
void RotationScaleMergeGPU::SetObsFrame(int offset, int count, const int32_t *frame) {
DeviceGuard guard(impl_->device, impl_->available);
UploadChunk(impl_->frame, offset, count, frame, impl_->s());
@@ -49,6 +49,11 @@ public:
void SetObsOnIce(int offset, int count, const uint8_t *on_ice);
void SetObsClipped(int offset, int count, const uint8_t *clipped);
// Every per-observation field the uploads above set, copied from `from` (which has them all, on
// its own device or this one) instead of being staged again from the host. Call after
// SetPartialsLayout with the same layout, before anything changes the fields on `from`.
void CopyObservationsFrom(const RotationScaleMergeGPU &from);
// Per space group: the dense ASU-group id per obs, and a group-ordered permutation of the obs whose
// group >= 0, with its CSR - so each group's observations are a contiguous, fixed-order segment for
// the reduction. Built on the device from the raw-hkl runs uploaded by SetRawRuns: rawrun_group is
+11 -7
View File
@@ -1069,16 +1069,20 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
rsm_all->SetSearchMinZeta(0.0);
rsm_all->SetExportScaledFulls(false); // as scale_and_merge sets them for a search merge
rsm_all->SetFrenchWilson(false);
all_arm_ahead = std::async(std::launch::async, [&rsm_all, &all_arm_log, device] {
pin_gpu(device); // the card and its NUMA node, as the guard's merge has them
TimingMark mark(all_arm_log, "merge P1, all observations");
rsm_all->IngestDevice();
return rsm_all->Run(/*for_search=*/true, /*full_stats=*/true,
/*measure_cc_before_corrections=*/false);
});
}
}
rsm->IngestDevice();
if (rsm_all) {
// Its observations are copied from this engine's card arrays, not staged from the
// reflections a second time.
rsm_all->IngestDevice(&*rsm);
all_arm_ahead = std::async(std::launch::async, [&rsm_all, &all_arm_log] {
pin_gpu(rsm_all->GetGpuDevice()); // the card and its NUMA node, as the guard's merge has them
TimingMark mark(all_arm_log, "merge P1, all observations");
return rsm_all->Run(/*for_search=*/true, /*full_stats=*/true,
/*measure_cc_before_corrections=*/false);
});
}
}
// The geometry pre-pass reads the per-image reflections exactly twice more: they were just