Merge branch 'fft-admit' into rc175: FFT indexer construction waits for GPU work beside it before failing

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 14:06:12 +02:00
commit 8dbaa9f8d7
11 files changed
+181 -30

No files matched your search

+60
View File
@@ -15,6 +15,7 @@
#include <thread>
#include "../image_analysis/indexing/CUDAMemHelpers.h"
#include "../image_analysis/indexing/IndexerThreadPool.h"
// The broker starts fresh worker threads for every data collection. A stream per thread ever started
// is a device-memory leak that ends a long-running broker, so threads that follow one another have to
@@ -127,6 +128,65 @@ TEST_CASE("CudaPinnedPool_ReusedByTheNextEngine", "[CUDAMemHelpers]") {
CHECK(cuda_release_pinned_pool() == 0);
}
// An FFT indexer that finds the card full waits for the GPU work beside it to give its memory back, and
// is built then: the main line's for the probes, a probe's for the main line's image pass - never for a
// probe, itself included. With nothing to wait for it fails at once, as one that does not fit always has.
TEST_CASE("IndexerThreadPool_FFTIndexerWaitsForGPUWorkBeside", "[CUDAMemHelpers]") {
if (get_gpu_count() == 0)
SKIP("No CUDA GPU present");
IndexingSettings settings;
settings.Algorithm(IndexingAlgorithmEnum::FFT).IndexingThreads(1);
DiffractionExperiment x;
x.ImportIndexingSettings(settings);
const std::vector<Coord> recip{{0.1, 0, 0}, {0, 0.1, 0}, {0, 0, 0.1}};
// The whole card, held by the work beside.
std::optional<std::vector<CudaDevicePtr<uint8_t>>> held;
const auto fill = [&held] {
held.emplace();
for (size_t chunk = size_t(256) << 20; chunk >= (size_t(1) << 20); chunk /= 2)
while (true) {
try {
held->emplace_back(chunk, CudaAlloc::Synchronous);
} catch (const JFJochException &) {
break;
}
}
};
IndexerThreadPool probe(settings, IndexerConstruction::OnFirstUse, /*beside=*/true);
IndexerThreadPool pool(settings, IndexerConstruction::OnFirstUse);
fill();
{
GPUWorkBeside work;
CHECK(probe.Run(x, recip).error != nullptr);
}
{
std::optional<GPUImagePass> image_pass(std::in_place);
std::thread ends([&] {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
held.reset();
image_pass.reset();
});
GPUWorkBeside work;
CHECK(probe.Run(x, recip).error == nullptr);
ends.join();
}
fill();
{
std::optional<GPUWorkBeside> work(std::in_place);
std::thread ends([&] {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
held.reset();
work.reset();
});
CHECK(pool.Run(x, recip).error == nullptr);
ends.join();
}
}
#endif
// A merge that finds the card full waits for the GPU work running beside it: until the last one