diff --git a/image_analysis/indexing/CUDAMemHelpers.h b/image_analysis/indexing/CUDAMemHelpers.h index c5341a484..f0b2128bf 100644 --- a/image_analysis/indexing/CUDAMemHelpers.h +++ b/image_analysis/indexing/CUDAMemHelpers.h @@ -204,6 +204,14 @@ inline void cuda_trim_allocation_pool() { cudaGetLastError(); } +// The same on every card: for work that has ended and whose threads were pinned round-robin (pin_gpu). +inline void cuda_trim_allocation_pools() { + for (int32_t d = 0; d < get_gpu_count(); d++) { + ScopedGpuPin pin(d); + cuda_trim_allocation_pool(); + } +} + // Whether `bytes` more device memory can be had on the current device, for a step whose buffers are // sized by the data set and which ends the run when they do not fit. The free memory counts what the // pool holds with no buffer in it (up to CUDA_MEM_POOL_RELEASE_THRESHOLD) as taken, so that is handed diff --git a/image_analysis/indexing/IndexerThreadPool.cpp b/image_analysis/indexing/IndexerThreadPool.cpp index 820020e15..2707482ad 100644 --- a/image_analysis/indexing/IndexerThreadPool.cpp +++ b/image_analysis/indexing/IndexerThreadPool.cpp @@ -286,10 +286,7 @@ void IndexerThreadPool::ReleaseIndexers() { #ifdef JFJOCH_USE_CUDA // Their buffers went back to the allocation pool, which would keep them reserved for the next // buffer of whoever asks; hand them to the card. - for (int32_t d = 0; d < get_gpu_count(); d++) { - ScopedGpuPin pin(d); - cuda_trim_allocation_pool(); - } + cuda_trim_allocation_pools(); #endif } diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index 33483f7a0..d52b589ba 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -569,6 +569,11 @@ void Rugnux::StartSpeculativeGeometryProbe(std::shared_ptr run, const st Logger("Rugnux").Warning("Speculative geometry probe failed: {}", e.what()); } } +#ifdef JFJOCH_USE_CUDA + // What its indexers and image workers held went back to the allocation pool; hand it to the card, + // or it stays reserved under the merge and the validation beside which the probe ran. + cuda_trim_allocation_pools(); +#endif }); speculative_probe_ = std::move(sp); } diff --git a/rugnux/RugnuxPasses.cpp b/rugnux/RugnuxPasses.cpp index b620c9379..01ae4bc01 100644 --- a/rugnux/RugnuxPasses.cpp +++ b/rugnux/RugnuxPasses.cpp @@ -756,6 +756,11 @@ RotationScaleWalk Rugnux::WalkRotationScaleBeside(const ProcessResult &pass1, Ro // empty result reads as. logger.Info("Rotation scale {:.5f}: the probe pass did not complete ({})", k, e.what()); } +#ifdef JFJOCH_USE_CUDA + // As the speculative probe (StartSpeculativeGeometryProbe): what it held goes back to the card. + if (index_only) + cuda_trim_allocation_pools(); +#endif return res; }; const auto probe = [&](float k, bool index_only) {