Skip to content

Reserve the memory into_packed_data() allocates - #23894

Open
madsbk wants to merge 4 commits into
NVIDIA:mainfrom
madsbk:into-packed-data-reservation
Open

Reserve the memory into_packed_data() allocates#23894
madsbk wants to merge 4 commits into
NVIDIA:mainfrom
madsbk:into-packed-data-reservation

Conversation

@madsbk

@madsbk madsbk commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

When a table_chunk is not already packed, into_packed_data() calls cudf::pack() straight into br->device_mr(). The allocation is roughly the size of the table and nothing reserved it, so the memory system under-counts and backpressure cannot see it coming.

It now takes a MemoryReservation instead of a BufferResource, and into_packed_data_cost() reports what it will allocate. That is zero when the chunk is already packed, since the packed data is then moved out rather than serialized, so the sole caller reserves the right amount on every path rather than over-reserving on the spilled one.

Both non-packed constructors already compute cudf::packed_size() into data_alloc_size_, so the cost needs no extra work at call time.

Breaking change

into_packed_data() takes a MemoryReservation rather than a BufferResource, in C++ and in Python. The BufferResource overload is gone rather than kept alongside, since every other allocating method on table_chunk already takes a reservation and leaving it would leave a blocking path that is easier to reach than the correct one.

Callers pair it with into_packed_data_cost():

chunk, extra = await make_table_chunks_available_or_wait(
    context, chunk, reserve_extra=chunk.into_packed_data_cost(), net_memory_delta=0
)
packed = chunk.into_packed_data(extra)

Note

The cudf::chunked_pack() TODO on the same line is still open. A bounce buffer would bound the allocation instead of needing room for a whole second copy.

@madsbk madsbk added improvement Improvement / enhancement to an existing function breaking Breaking change labels Aug 31, 2026
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API. cudf-polars Issues specific to cudf-polars labels Aug 31, 2026
@madsbk
madsbk force-pushed the into-packed-data-reservation branch from 4641835 to 2376f3d Compare September 1, 2026 12:04
@madsbk
madsbk force-pushed the into-packed-data-reservation branch from 2376f3d to 32b04d2 Compare September 1, 2026 13:42
@madsbk
madsbk force-pushed the into-packed-data-reservation branch from 32b04d2 to eca1764 Compare September 1, 2026 13:54
@madsbk
madsbk marked this pull request as ready for review September 1, 2026 14:44
@madsbk
madsbk requested review from a team as code owners September 1, 2026 14:44
@madsbk
madsbk requested review from bdice and wence- September 1, 2026 14:44
@NVIDIA NVIDIA deleted a comment from copy-pr-bot Bot Sep 1, 2026
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 19adebee-bd01-4ab9-bb0a-155d2c48e3e8

📥 Commits

Reviewing files that changed from the base of the PR and between e3ce22f and d87cca4.

📒 Files selected for processing (1)
  • cpp/libcudf_streaming/tests/streaming/test_table_chunk.cpp

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added a method to report the device memory required to pack a table chunk.
    • Already-packed chunks now report zero additional memory requirements.
  • API Updates
    • Packing now requires an explicit device-memory reservation.
    • Insufficient reservations are rejected with a documented error.
    • Updated C++ and Python interfaces to support reservation-based packing.
  • Bug Fixes
    • Packing allocations are now tracked against reserved device memory, improving memory accounting and reliability.

Walkthrough

table_chunk packing now reports its device-memory cost and requires a MemoryReservation. C++ and Python APIs, the allgather path, and tests now use reservation-tracked packing.

Changes

Table chunk packing

Layer / File(s) Summary
C++ packing contract and validation
cpp/libcudf_streaming/include/cudf_streaming/table_chunk.hpp, cpp/libcudf_streaming/src/table_chunk.cpp, cpp/libcudf_streaming/tests/streaming/test_table_chunk.cpp
The C++ API reports packing cost, consumes a device-memory reservation, and tests exact consumption and insufficient capacity.
Python binding and reservation bridge
python/cudf_streaming/cudf_streaming/table_chunk.pxd, python/cudf_streaming/cudf_streaming/table_chunk.pyi, python/cudf_streaming/cudf_streaming/table_chunk.pyx, python/cudf_streaming/cudf_streaming/tests/test_table_chunk.py
The Python API exposes into_packed_data_cost() and passes MemoryReservation directly to C++. Tests reserve the reported cost.
Allgather packing reservation
python/cudf_polars/cudf_polars/streaming/actor_graph/collectives/allgather.py
Inserter.insert reserves the chunk packing cost before conversion.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to d87cc

The change adds explicit memory reservation for table packing and updates the represented C++ and Python callers. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: bdice, vyasr

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: memory allocated by into_packed_data() is now reserved.
Description check ✅ Passed The description accurately explains the reservation API change, the new cost method, the breaking change, and the remaining TODO.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

@NVIDIA NVIDIA deleted a comment from coderabbitai Bot Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change cudf-polars Issues specific to cudf-polars improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants