Refinement: the mask grid sized without allocating it; the L-BFGS pairs keep their s.y

BulkSolventMask::MaskGrid, documented as "sizes and spacing set, values not allocated", allocated and zeroed the
whole fine mask grid (up to 2^26 floats) - in BulkSolventMask's constructor and in every GPU engine's, i.e. once
more for each weight-trial slot, only for the grid's size. It now takes good_grid_size() as set_size_from_spacing()
does, and the CPU engine's Fmask() allocates its copy. rugnux_refine_test, RTX 5080, -N 8: 9yl4 8.6 -> 7.8 s,
7d98 4.85 -> 4.0 s (engine 0.66 -> 0.16 s, slots 0.60 -> 0.23 s on 9yl4); the high-resolution sets, whose mask
grid is small, are unchanged.

RefinementMinimiser keeps s.y of every pair it stores and Direction() takes rho and gamma from it instead of two
more dot products per pair per call (the same Dot() of the same vectors): Direction's CPU time -22% on 9yl4; no
wall change with the trials side by side, where other slots fill the card meanwhile.

Bitwise: refined CIF identical on 5reo, 5f6m, 9yl4, 7d98, a 5f6m MD start (GPU) and 6o2h (CPU engine).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit 6f5caf5e1b1183a752acc5cca78bfb7ef002b12a)
This commit is contained in:
leonarski_f committed 2026-10-26 09:16:33 +01:00
1 parent 6da51dc5d7
commit a8d3a8dbc2
2 files changed
+15 -3

No files matched your search

@@ -282,7 +282,14 @@ gemmi::Grid<float> BulkSolventMask::MaskGrid(const gemmi::UnitCell &cell, const
grid.unit_cell = cell;
grid.spacegroup = &sg;
const double spacing = std::max(std::min(d_min / 3.0, MASK_SPACING_MAX), std::cbrt(cell.volume / MASK_POINTS_MAX));
grid.set_size_from_spacing(spacing, gemmi::GridSizeRounding::Up);
// set_size_from_spacing()'s size, without allocating the values
const std::array<int, 3> n = gemmi::good_grid_size({{cell.a / spacing, cell.b / spacing, cell.c / spacing}},
gemmi::GridSizeRounding::Up, &sg);
grid.nu = n[0];
grid.nv = n[1];
grid.nw = n[2];
grid.calculate_spacing();
grid.axis_order = gemmi::AxisOrder::XYZ;
return grid;
}
@@ -291,6 +298,7 @@ void BulkSolventMask::Fmask(const gemmi::Model &model, const std::vector<gemmi::
if (orbit_leaders_.empty()) // at the first mask: a GPU engine's refinement never draws one here
orbit_leaders_ = OrbitLeaders(grid_, nthreads_);
gemmi::Grid<float> mask = grid_;
mask.data.resize(mask.point_count());
PutMaskOnGrid(mask, model, orbit_leaders_, nthreads_);
const gemmi::FPhiGrid<float> fm = MapToFPhi(mask);
f.clear();