From b0c6c01566b244cdae73974bc25bb83b2e5b5965 Mon Sep 17 00:00:00 2001 From: Khalil Ferjaoui Date: Tue, 6 Oct 2026 17:23:15 +0200 Subject: [PATCH] CUDA: keep registered input arrays alive in Python bindings - Prevent `del data` from freeing the buffer while it is still registered with CUDA. --- python/src/bind_ClusterFinderCUDA.hpp | 1 + python/src/bind_ClusterFinderCUDAGraph.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/python/src/bind_ClusterFinderCUDA.hpp b/python/src/bind_ClusterFinderCUDA.hpp index 91883c00..4eb15a8e 100644 --- a/python/src/bind_ClusterFinderCUDA.hpp +++ b/python/src/bind_ClusterFinderCUDA.hpp @@ -313,6 +313,7 @@ sqrt(max(sum2/n - mean^2, 0)). Counterpart to `noise` for the device pedestal.)" info.ptr, static_cast(info.size) * static_cast(info.itemsize)); }, + py::keep_alive<1, 2>(), R"(Pin a numpy array as a locked host buffer so that find_clusters_batched transfers it at full DMA bandwidth (~22 GB/s) instead of going through the CUDA driver's diff --git a/python/src/bind_ClusterFinderCUDAGraph.hpp b/python/src/bind_ClusterFinderCUDAGraph.hpp index d82517e1..33e08d81 100644 --- a/python/src/bind_ClusterFinderCUDAGraph.hpp +++ b/python/src/bind_ClusterFinderCUDAGraph.hpp @@ -103,6 +103,7 @@ void define_ClusterFinderCUDAGraph(py::module &m, const std::string &typestr) { info.ptr, static_cast(info.size) * static_cast(info.itemsize)); }, + py::keep_alive<1, 2>(), R"(Pin a numpy array as a locked host buffer so that find_clusters_batched transfers it at full DMA bandwidth. Call once before the processing loop with the full data array.