Azimuthal geometry cache keeps six geometries instead of one
A run alternates between a handful of centres (file, measured, post-refined, probe, the beam-centre ladder's trial centres), and every miss rebuilt the 16.7 Mpx geometry table. The cache now keeps the six most recently used (~170 MB each at 16 Mpx). Tables are bit-identical whether cached or built. p.mtz md5 unchanged on myob/cytc/thau/kdp (GPU build). Timing: no measurable change on myob/cytc/thau at 3 repeats; it removes table rebuilds where geometries alternate. 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
a395f358ef
commit
fc61700c95
2 files changed
+25
-15
No files matched your search
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "JFJochMath.h"
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
@@ -128,16 +129,18 @@ void AzimuthalIntegrationMapping::SetupConvGeomCached(const DiffractionGeometry
|
||||
static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
|
||||
std::lock_guard lock(cache.m);
|
||||
if (cache.key != key) {
|
||||
auto &entries = cache.entries;
|
||||
auto it = std::find_if(entries.begin(), entries.end(), [&](const auto &e) { return e.key == key; });
|
||||
if (it == entries.end()) {
|
||||
SetupConvGeom(geom, nullptr);
|
||||
cache.key = key;
|
||||
cache.pixel_to_bin = pixel_to_bin;
|
||||
cache.pixel_resolution = pixel_resolution;
|
||||
cache.corrections = corrections;
|
||||
if (entries.size() == AzimuthalIntegrationGeometryCache::MAX_ENTRIES)
|
||||
entries.erase(entries.begin());
|
||||
entries.push_back({key, pixel_to_bin, pixel_resolution, corrections});
|
||||
} else {
|
||||
pixel_to_bin = cache.pixel_to_bin;
|
||||
pixel_resolution = cache.pixel_resolution;
|
||||
corrections = cache.corrections;
|
||||
std::rotate(it, it + 1, entries.end());
|
||||
pixel_to_bin = entries.back().pixel_to_bin;
|
||||
pixel_resolution = entries.back().pixel_resolution;
|
||||
corrections = entries.back().corrections;
|
||||
}
|
||||
|
||||
// What SetupPixel leaves at a masked pixel.
|
||||
|
||||
@@ -9,19 +9,26 @@
|
||||
#include "DiffractionExperiment.h"
|
||||
#include "PixelMask.h"
|
||||
|
||||
// The per-pixel geometry of the last mapping built through it, before the mask: every pixel's
|
||||
// The per-pixel geometry of the last few mappings built through it, before the mask: every pixel's
|
||||
// resolution, correction and bin. None of these depends on the mask - a masked pixel is only left
|
||||
// out - so a mapping for the same geometry under another mask takes them from here and blanks its own
|
||||
// masked pixels, instead of evaluating the geometry of every pixel again. Building a mapping is that
|
||||
// evaluation, and on a 16 Mpx detector it is a tenth of a second on every core. One entry; a mapping
|
||||
// being built holds it, so two built at once for the same geometry evaluate it once.
|
||||
// evaluation, and on a 16 Mpx detector it is a tenth of a second on every core. A run alternates
|
||||
// between a handful of centres - the file's, the measured one, the post-refined one, the beam-centre
|
||||
// ladder's trial centres, each built once to index and again to score - so several are kept, the
|
||||
// least recently used going first (~170 MB each at 16 Mpx). A mapping being built holds the cache,
|
||||
// so two built at once for the same geometry evaluate it once.
|
||||
class AzimuthalIntegrationGeometryCache {
|
||||
friend class AzimuthalIntegrationMapping;
|
||||
static constexpr size_t MAX_ENTRIES = 6;
|
||||
struct Entry {
|
||||
std::vector<uint32_t> key; // bit patterns of everything SetupPixel reads
|
||||
std::vector<uint16_t> pixel_to_bin;
|
||||
std::vector<float> pixel_resolution;
|
||||
std::vector<float> corrections;
|
||||
};
|
||||
std::mutex m;
|
||||
std::vector<uint32_t> key; // bit patterns of everything SetupPixel reads
|
||||
std::vector<uint16_t> pixel_to_bin;
|
||||
std::vector<float> pixel_resolution;
|
||||
std::vector<float> corrections;
|
||||
std::vector<Entry> entries; // most recently used last
|
||||
};
|
||||
|
||||
class AzimuthalIntegrationMapping {
|
||||
|
||||
Reference in new issue
Block a user