You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Device memory: accounting, and spilling to host memory under a budget or when an allocation fails #387
Plan:#511, docs/design/plans/device-memory.md (with #469), which replaces the wiki's Device memory plan.
Tack does not know how much device memory it holds. When a GPU runs out, _allocate collects Python's garbage, empties the backend's cache, tries once more, and then raises DeviceMemoryError, usually from a temporary inside a filter. Derived data (faces, edges, point links, locators, cell geometry) stays on the device as long as its dataset lives.
This adds, on CUDA, HIP and Level Zero (Metal and the CPU get accounting only):
Accounting: per device, bytes in use, the peak, what caches keep, bytes spilled, and the driver's free and total. Exposed as tack.memory_info(), tack.reset_peak_memory() and a tack.memory_peak() scope.
Spilling:
with a budget (tack.set_memory_budget(bytes, device=None)), before an allocation would pass it;
without one, whenever an allocation fails.
The arrays used least recently are copied to ordinary host memory and their device memory freed. Derived data is spilled like any other array. Host reads and writes of a spilled array use its host copy and leave it spilled. Only the device brings it back: device_ptr, which every launch reads, and the buffer's device-to-device operations. The host copy is never handed out, since a restore frees it.
Memory Tack cannot move is never spilled: wrapped and imported pointers, memory handed out (DLPack, export_memory, share()), MPI buffers, scalar packs, texture images, and the arrays of the launch being prepared.
Steps:
Accounting on every backend, with its API, docs and tests.
Spilling when an allocation fails (CUDA, HIP, Level Zero): states, the restore hook, a weak registry in least-recently-used order, the exclusions, launches made resident.
tack.set_memory_budget.
Validation on the GPUs: AhmedML's sweep under a budget well below its peak (outputs equal, cost measured), the M6 dataset on a 16 GB GPU, HIP and Level Zero.
Related: #386 (the GPU backends clear every new buffer).
The plan looks right for Tack. Its description of today’s allocation path, where buffers are created and freed, and the list of memory Tack can’t move all match the code. A few things are missing or need deciding before the code.
Most important
Unified memory: On the DGX Spark’s GB10, and on Intel’s integrated GPUs, device memory is host memory. Spilling there copies data within the same RAM, and cuMemGetInfo reports system memory. The plan should turn spilling off on integrated devices (CU_DEVICE_ATTRIBUTE_INTEGRATED, L0 ZE_DEVICE_PROPERTY_FLAG_INTEGRATED), as it already does for Metal. Accounting should still run.
Pinning covers only execute. Native reductions, texture uploads, DLPack export and share() also read device_ptr and then use it. If a spill runs between that read and the use (another thread allocating, or an allocation inside the operation), the pointer is freed. Every user of device_ptr needs the same “resident and not spillable until queued” rule, under the same lock as spilling.
Smaller
The spill copy’s ordering. The plan says a copy into pageable memory “waits for the queued work”. That holds for the legacy default stream, not necessarily for Tack’s stream. It’s safer to say the copy is enqueued on Tack’s stream (cuMemcpyDtoHAsync, hipMemcpyDtoHAsync), followed by a sync.
What in_use and peak count. Do they include HIP’s cache and Metal’s pool, or only live arrays? Tests will want live arrays only, with cached reported separately. Please say so in the table.
The budget versus other libraries. A budget in bytes ignores memory that PyTorch, VTK or another process holds on the same GPU. Consider letting the budget be a fraction of device_free when it’s set, or say plainly that it covers Tack’s arrays only.
Warp backend. It has its own allocate_array. Is it in or out of the accounting?
Testing “never a spilled pointer”. A debug flag where device_ptr checks the state and raises would make that test direct, instead of waiting for a corrupted result.
Activity
jlee-kitware commentedon Nov 12, 2026
The plan looks right for Tack. Its description of today’s allocation path, where buffers are created and freed, and the list of memory Tack can’t move all match the code. A few things are missing or need deciding before the code.
Most important
Smaller