FastPedestal + optimizations in the cluster finder (#341)
Build on RHEL9 / build (push) Successful in 2m42s
Build on RHEL8 / build (push) Successful in 3m21s
Run tests using data on local RHEL8 / build (push) Failing after 3m56s
Build on local RHEL8 / build (push) Successful in 2m54s

Optimized pedestal tracking with FastPedestal and performance improvements to the cluster finder. 
- ~2x faster hitting 14k FPS on benchmark dataset on 16 core threadripper pro


**Changes**
- No bounds check on interior of frame. (only within half of a cluster)
(~15% improvement)
- Cache threshold (std*n_rms) Biggest improvement comes from not
computing std for each access
- Cache pedestal subtracted frame
- Switched to FastPedestal which assumes we reached steady state

**Things tried but rejected:**
- Always store cluster values, commit on val==max (~15% drop in frame
rate)

**Options**
- using 16 bit clusters and 16 bit pedestal. (slows down the single
threaded case but allow us to reach 12k with multi threading)

**Other notes on performance**
- Passing in memory frames from python and doing nothing: 0.8us/frame
- Passing + pedestal subtraction: 28us/frame
- Passing + pedestal + cluster finding (no store): 652us/frame
- Passing + pedestal + cluster finding: 886 us/frame
This commit is contained in:
Erik Fröjdh authored and GitHub committed 2026-09-01 18:41:12 +02:00
1 parent 568f94926b
commit eddb919328
44 files changed
+2220 -320

No files matched your search

+79 -2
View File
@@ -21,14 +21,21 @@ class ClusterFinderMTWrapper
public:
ClusterFinderMTWrapper(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0,
size_t capacity = 2000, size_t n_threads = 3)
size_t capacity = 2000, size_t n_threads = 3,
size_t queue_depth = 16)
: ClusterFinderMT<ClusterType, FRAME_TYPE, PEDESTAL_TYPE>(
image_size, nSigma, capacity, n_threads) {}
image_size, nSigma, capacity, n_threads, queue_depth) {}
size_t get_m_input_queues_size() const {
return this->m_input_queues.size();
}
size_t get_m_frame_pools_size() const { return this->m_frame_pools.size(); }
size_t get_frame_pool_depth(size_t thread_index) const {
return this->m_frame_pools[thread_index]->size();
}
size_t get_m_output_queues_size() const {
return this->m_output_queues.size();
}
@@ -100,3 +107,73 @@ TEST_CASE("multithreaded cluster finder", "[.with-data]") {
auto clustervec = clustercollector.steal_clusters();
// CHECK(clustervec.size() == ) //dont know how many clusters to expect
}
TEST_CASE("frame buffers are recycled when pushing more frames than the pool "
"holds",
"[.files]") {
using ClusterType = Cluster<int32_t, 3, 3>;
const size_t n_threads = 2;
const size_t queue_depth = 4;
const size_t n_frames = 5 * queue_depth;
const Shape<2> image_size{10, 10};
ClusterFinderMTWrapper<ClusterType> cf(image_size, 5, 200, n_threads,
queue_depth);
CHECK(cf.get_m_frame_pools_size() == n_threads);
for (size_t i = 0; i < n_threads; ++i) {
CHECK(cf.get_frame_pool_depth(i) == queue_depth);
}
NDArray<uint16_t, 2> frame(image_size, 0);
// More frames than the pool holds, so this only completes if the workers
// return the buffers to the free list.
for (size_t i = 0; i < n_frames; ++i) {
cf.find_clusters(frame.view(), i);
}
cf.stop();
CHECK(cf.m_input_queues_are_empty() == true);
}
TEST_CASE("cluster collector accepts finders with a matching cluster type") {
using ClusterType = Cluster<int32_t, 3, 3>;
using Finder = ClusterFinderMTWrapper<ClusterType, uint16_t, float>;
using OtherFinder =
ClusterFinderMTWrapper<Cluster<int32_t, 5, 5>, uint16_t, float>;
static_assert(
std::is_constructible_v<ClusterCollector<ClusterType>, Finder *>);
static_assert(
!std::is_constructible_v<ClusterCollector<ClusterType>, OtherFinder *>);
Finder cf({10, 10});
cf.stop();
ClusterCollector<ClusterType> collector(&cf);
collector.stop();
CHECK(collector.steal_clusters().empty());
}
TEST_CASE("cluster collector drains queued clusters when stopped") {
using ClusterType = Cluster<int32_t, 3, 3>;
ProducerConsumerQueue<ClusterVector<ClusterType>> source(4);
for (uint64_t frame_number = 1; frame_number <= 3; ++frame_number) {
REQUIRE(source.write(ClusterVector<ClusterType>(4, frame_number)));
}
ClusterCollector<ClusterType> collector(&source);
collector.stop();
auto clusters = collector.steal_clusters();
REQUIRE(clusters.size() == 3);
CHECK(source.isEmpty());
for (size_t i = 0; i < clusters.size(); ++i) {
CHECK(clusters[i].frame_number() == static_cast<int32_t>(i + 1));
}
}