Claude 503009596d [CCCL-PORT] CachingDeviceAllocator buffer reuse in prefix attention tile loop
CCCL source read: cub/util_allocator.cuh
  CachingDeviceAllocator pre-allocates bins of device memory and reuses
  them across kernel invocations. Key insight: avoid repeated cudaMalloc/
  cudaFree inside hot loops — allocate once outside, reuse with slicing.

Applied to _forward_prefix_pytorch's online softmax tile loop:
  OLD: Each tile iteration allocated 3 new tensors (m_blk, m_new, corr)
       via implicit torch operations. With ~16 tiles per context phase +
       ~16 tiles per chunk phase = ~96 unnecessary CUDA malloc/free calls.
  NEW: Pre-allocate _m_blk, _m_new, _corr once outside both Phase loops.
       Use torch.amax(out=), torch.maximum(out=), torch.exp(out=) to write
       directly into pre-allocated buffers. Zero new allocations per tile.

Also applies to Phase 2 (current-chunk tokens) which has identical
softmax update pattern — same 3 buffers reused across both phases.

BI-V100 impact: 16 SMs with 50GB HBM — CUDA malloc overhead is
proportionally larger than on 148-SM GPUs because the memory controller
has fewer concurrent requests to amortize allocation latency.
2026-08-05 08:36:10 +00:00
2026-07-30 17:03:23 +08:00

project_6

Description
No description provided
Readme 427 MiB
Languages
C++ 41.8%
Cuda 31.6%
Python 22.2%
C 2.1%
CMake 1.1%
Other 1.1%