Files
Jungfraujoch/docs
leonarski_fandClaude Fable 5.1 060a89cd7d CUDA: allocation streams are handed back, not leaked; a handled pool failure leaves no error
A long-running broker began cancelling every data collection with

    Device decoding failed (CUDA (GPU) error (out of memory)), falling back to host decompression
    CUDA (GPU) error (out of memory)

while nvidia-smi showed the cards less than a fifth full. Two defects, both in CUDAMemHelpers.h and
both from the pooled allocator (cudaMallocAsync) that came with rc.162.

The leak. cuda_allocation_stream() kept one stream per (thread, device) in a thread_local map of raw
cudaStream_t and never destroyed them. That was written against rugnux, where the worker threads live
as long as the process. The broker starts fresh std::async threads for every data collection - 16 or
64 of them - so every collection left that many streams behind. Measured: 0.56 MB of device memory
per leaked stream, linear to 4928 streams, never returned, with nothing on the host side growing.

The RAII wrapper (CudaStream) was there but not used at this site, and using it as-is - a stream
destroyed when its thread exits - would not have been safe: ShadowFinder builds its GPU accumulator
on a throw-away std::async thread and frees it from another thread long after, and that free is
ordered on the allocating thread's stream. So the streams are still never destroyed, but a thread
now only borrows one: CudaStream objects live in a process-wide per-device idle list, a thread takes
one on first use and hands it back when it exits. Their number is bounded by the threads that were
ever alive at once instead of by the threads ever started. The list itself is deliberately leaked, so
that nothing calls into CUDA during static destruction.

Replaying the broker's pattern against the real header, 60 collections of 64 threads:
    before   3840 streams, 260 -> 2424 MB of device memory
    after      64 streams, 260 ->  358 MB

The stale error. Every helper here throws a named message, yet the log carried the raw CUDA string,
so the failure came through a cuda_err() and not from an allocation. CudaDevicePtr falls back to
cudaMalloc when cudaMallocAsync fails, silently - but the failed call stays behind as the thread's
last error, and the cudaGetLastError() that follows the next kernel launch reports it. The buffers
were all allocated; the frame was lost anyway, once on the device-decode route (caught, hence the
warning) and once more on the host fallback (fatal). The pooled attempt failing, and a stream that
cannot be created, are both handled by falling back, so both now clear the error they leave.

What finite resource the production cards ran out of at under 4 GB used was not established - no
cap on the number of streams was found up to 4928 on the card this was measured on. The leak is the
only thing on this path that grows with uptime.

tests/CUDAMemHelpersTest.cpp: later threads end up on the same stream, concurrent threads on
different ones, a buffer is freed cleanly after its allocating thread has exited (and another has
borrowed its stream), and a pool that cannot serve a request leaves no error behind - the last by
capping a memory pool at 4 MB so that the pooled attempt fails and the fallback succeeds.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-20 18:45:03 +02:00
..
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-15 17:09:31 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2024-11-22 21:25:20 +01:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-02 21:17:31 +02:00
2026-09-17 14:42:52 +02:00
2026-09-15 17:09:31 +02:00
2026-09-17 14:42:52 +02:00
2025-11-28 12:47:35 +01:00
2026-06-23 20:29:49 +02:00
2026-07-11 07:19:11 +02:00
2024-12-02 21:17:14 +01:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-02 21:17:31 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2024-11-22 21:25:20 +01:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-15 17:09:31 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00