BraggIntegrationEngineCPU: reflection mask and owner map kept as 16x16 tiles
refl_mask (uint8) and owner (uint32) were full-frame arrays per engine, ~90 MB at 18 Mpixel, of which a call writes only the neighbourhoods of its reflections; over a sweep every page of both got touched in every worker, and the dirty-rectangle clears were row-strided memsets. They are now a TiledFrame: a per-tile directory plus a pool of 16x16 tiles allocated on first write and dropped by Clear(); reading a tile nothing wrote gives the empty value (0 / BRAGG_OWNER_NONE). Writes and reads are exactly those of the flat arrays, so the same ownership decisions. Measured (perf, 499 Hz, CPU-only build, cytc): RunImpl 1633 -> 1557 core-s, memset 88 -> 32 core-s. Peak RSS and page faults did not move measurably (myob 15.3 GB; the peak is set elsewhere). Byte-identical p.hkl, p.mtz, p_P1.mtz, p_unmerged.mtz on myob, cytc, lyso, sparse (CPU) and myob, lyso (GPU); Bragg* tests pass. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C
This commit is contained in:
1 parent
2bad92ddd6
commit
61d88cdefe
2 files changed
+48
-31
No files matched your search
@@ -44,7 +44,9 @@ struct ImageSampler {
|
||||
} // namespace
|
||||
|
||||
BraggIntegrationEngineCPU::BraggIntegrationEngineCPU(const DiffractionExperiment &experiment)
|
||||
: BraggIntegrationEngine(experiment) {}
|
||||
: BraggIntegrationEngine(experiment),
|
||||
refl_mask(static_cast<int>(xpixel), static_cast<int>(ypixel), 0),
|
||||
owner(static_cast<int>(xpixel), static_cast<int>(ypixel), BRAGG_OWNER_NONE) {}
|
||||
|
||||
template <class Sampler>
|
||||
std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
@@ -71,17 +73,8 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
// signal is excluded from this reflection's r2..r3 background ring. The region is the INNER
|
||||
// stencil ellipse, taken in each neighbour's OWN frame - an elongated neighbour whose streak
|
||||
// is still marked as a disk would leak its tails into this reflection's ring. ---
|
||||
// Back to empty what the previous call wrote (see the header).
|
||||
for (const Rect &b : refl_mask_dirty)
|
||||
for (int y = b.y0; y <= b.y1; ++y)
|
||||
std::fill(refl_mask.begin() + y * W + b.x0, refl_mask.begin() + y * W + b.x1 + 1, 0);
|
||||
refl_mask_dirty.clear();
|
||||
for (const Rect &b : owner_dirty)
|
||||
for (int y = b.y0; y <= b.y1; ++y)
|
||||
std::fill(owner.begin() + y * W + b.x0, owner.begin() + y * W + b.x1 + 1, BRAGG_OWNER_NONE);
|
||||
owner_dirty.clear();
|
||||
|
||||
refl_mask.resize(npixel, 0);
|
||||
refl_mask.Clear();
|
||||
owner.Clear();
|
||||
for (size_t i = 0; i < npredicted; ++i) {
|
||||
const auto &r = predicted[i];
|
||||
const BraggStencil st = MakeBraggStencil(r.predicted_x, r.predicted_y, stencil);
|
||||
@@ -89,12 +82,10 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
const int x1 = std::min(W - 1, static_cast<int>(std::ceil(r.predicted_x + st.ex_in + 1.0f)));
|
||||
const int y0 = std::max(0, static_cast<int>(std::floor(r.predicted_y - st.ey_in - 1.0f)));
|
||||
const int y1 = std::min(H - 1, static_cast<int>(std::ceil(r.predicted_y + st.ey_in + 1.0f)));
|
||||
if (x0 <= x1 && y0 <= y1)
|
||||
refl_mask_dirty.push_back({x0, x1, y0, y1});
|
||||
for (int y = y0; y <= y1; ++y)
|
||||
for (int x = x0; x <= x1; ++x) {
|
||||
const auto d = BraggStencilDistances(st, x - r.predicted_x, y - r.predicted_y);
|
||||
if (d.inner < r2_sq) refl_mask[y * W + x] = 1;
|
||||
if (d.inner < r2_sq) refl_mask.At(x, y) = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +97,6 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
const bool exclude = overlap == OverlapMode::Exclude && mode != IntegratorMode::BoxSum;
|
||||
const bool use_owner = overlap != OverlapMode::Off;
|
||||
if (use_owner) {
|
||||
owner.resize(npixel, BRAGG_OWNER_NONE);
|
||||
const float claim_sq = claim * claim;
|
||||
for (size_t i = 0; i < npredicted; ++i) {
|
||||
const auto &r = predicted[i];
|
||||
@@ -114,21 +104,19 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
const int x1 = std::min(W - 1, static_cast<int>(std::ceil(r.predicted_x + claim)));
|
||||
const int y0 = std::max(0, static_cast<int>(std::floor(r.predicted_y - claim)));
|
||||
const int y1 = std::min(H - 1, static_cast<int>(std::ceil(r.predicted_y + claim)));
|
||||
if (x0 <= x1 && y0 <= y1)
|
||||
owner_dirty.push_back({x0, x1, y0, y1});
|
||||
for (int y = y0; y <= y1; ++y)
|
||||
for (int x = x0; x <= x1; ++x) {
|
||||
const float dx = x - r.predicted_x, dy = y - r.predicted_y;
|
||||
const float d2 = dx * dx + dy * dy;
|
||||
if (d2 >= claim_sq) continue;
|
||||
uint32_t &o = owner[y * W + x];
|
||||
uint32_t &o = owner.At(x, y);
|
||||
o = std::min(o, BraggOwnerKey(std::sqrt(d2), inv_claim, static_cast<int>(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
auto clean = [&](int x, int y, size_t i) {
|
||||
return !use_owner
|
||||
|| BraggOwnedBy(owner[static_cast<size_t>(y) * W + x], static_cast<int>(i));
|
||||
|| BraggOwnedBy(owner.Get(x, y), static_cast<int>(i));
|
||||
};
|
||||
|
||||
// --- Pass A: box-sum every reflection (rough I, background, centroid, strong flag). ---
|
||||
@@ -213,7 +201,7 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
y_sum += y;
|
||||
++n_inner_valid;
|
||||
} else if (d.inner >= r2_sq && d.outer < r3_sq) {
|
||||
if (refl_mask[y * W + x]) { ++n_bkg_neighbour; continue; }
|
||||
if (refl_mask.Get(x, y)) { ++n_bkg_neighbour; continue; }
|
||||
if (!valid(px)) continue;
|
||||
bkg_sum += static_cast<double>(px);
|
||||
if (bkg_trim_frac > 0.0) bkg_vals.push_back(px);
|
||||
@@ -267,7 +255,7 @@ std::vector<Reflection> BraggIntegrationEngineCPU::RunImpl(const Sampler &img,
|
||||
for (int x = x0; x <= x1; ++x) {
|
||||
const auto d = BraggStencilDistances(st, x - r.predicted_x, y - r.predicted_y);
|
||||
if (!(d.inner >= r2_sq && d.outer < r3_sq)) continue;
|
||||
if (refl_mask[y * W + x]) continue;
|
||||
if (refl_mask.Get(x, y)) continue;
|
||||
const int32_t px = img[y * W + x];
|
||||
if (!valid(px)) continue;
|
||||
if (static_cast<double>(px) <= thr) {
|
||||
|
||||
Reference in new issue
Block a user