#24268·cudf

[FEA] Top-down migration plan: cudf::memory_resources in every public API, in dependency order

Author: devin-ai-integration[bot]Created Sep 23, 2026Updated Sep 23, 2026
Labelslibcudfimprovement

Summary

This issue is the plan for the "top-down" migration path discussed as a follow-up to #20780: convert every public libcudf API from rmm::device_async_resource_ref mr to cudf::memory_resources mr, and refactor the implementation behind each API so that temporary allocations come from mr.get_temporary_mr() instead of cudf::get_current_device_resource_ref().

Per the team decision, this path is implementation-only: no new tests, no validation harness prerequisites. Temporary-MR routing is best effort until the separate bottom-up validation effort (#20626, cudf_test/memory_resource_utilities.hpp) catches up. The final invariant we are working toward is: no libcudf API calls cudf::get_current_device_resource_ref() internally; the only place the current device resource is consulted is the one-argument cudf::memory_resources constructor at the public boundary.

The bulk of this issue is a dependency-ordered inventory of every file that needs work, so we can file many small PRs in parallel without stepping on each other.

Migration contract (what each PR does)

For each API in the work item:

  1. Signature. In the public header and the matching detail header, replace
    cpp
    rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()
    with
    cpp
    cudf::memory_resources mr = cudf::get_current_device_resource_ref()
    (the defaulted one-arg construction keeps source compatibility; existing callers passing a plain device_async_resource_ref still compile via implicit conversion).
  2. Body. At the top of the implementation:
    cpp
    auto const temp_mr = mr.get_temporary_mr();
    then
    • every cudf::get_current_device_resource_ref() → temp_mr;
    • every rmm::device_uvector<T> x(n, stream) / rmm::device_buffer(n, stream) / cudf::detail::device_scalar<T>(stream) / make_*_device_uvector*(…, stream) that relies on the defaulted mr → pass temp_mr explicitly;
    • every rmm::exec_policy[_nosync](stream, …) → temp_mr;
    • file-local helpers (anonymous-namespace functions, functors, impl classes) that allocate device memory but take no mr get a cudf::memory_resources mr parameter. Always pass cudf::memory_resources, never a bare rmm::device_async_resource_ref, even if the helper only allocates temporaries (or only output) — callers must not have to track which kind of memory a callee allocates. It is fine for a callee to use only one of the two resources.
  3. Nested calls.
    • Result is (part of) the object returned to the caller → pass mr through unchanged.
    • Result is an intermediate consumed inside this API → pass cudf::memory_resources{temp_mr, temp_mr}. (Never cudf::memory_resources{temp_mr} — the one-arg form recaptures the current device resource for the callee's temporaries.)
    • Every cuDF API you call must already accept cudf::memory_resources. If it still takes rmm::device_async_resource_ref, stop: a lower tier was missed. Migrate that callee first (its own PR), then come back. Never pass mr.get_output_mr() / temp_mr into an unmigrated cuDF API as a stopgap — the whole point of tier ordering is that this never happens. Checking for this is part of each PR's validation (see checklist).
  4. Scope discipline. One PR = one file (or one header + its .cu), migrating all mr-taking APIs defined there. Don't touch callers in other files except where a signature change forces it (it shouldn't, thanks to implicit conversion).
  5. Done when rg get_current_device_resource_ref <file> returns only defaulted-parameter hits, and no defaulted-mr container constructions remain in the file.

Existing landed examples to copy from: dictionary/encode.cu (#23642), copying/gather.cu (#23690, in flight), row-operator preprocessing (#23665).

Why order matters

Temporary resources propagate downward: a caller can only forward temp_mr into a callee if the callee accepts a resource for its temporaries. So the graph below is ordered bottom-up (Tier 0 = leaves). cudf::memory_resources is implicitly constructible from rmm::device_async_resource_ref, so callers of a migrated API keep compiling — that is what lets us do this tier-by-tier without touching callers. The reverse direction is the rule: a PR must not land while any cuDF API it calls still takes rmm::device_async_resource_ref. "Blocked by" in the tables is therefore a hard ordering constraint, not advice: finish the blockers first. If you find an unmigrated callee that the tables didn't list, that is a gap in the static graph — migrate it first and note it here.

Dependency graph and tiers

How it was computed

Static analysis of main @ 89eeabe (2026-09-22):

  • Universal Ctags over cpp/include/cudf, cpp/include/nvtext, cpp/src to find every free function whose signature contains device_async_resource_ref or memory_resources (public + detail), collapsing public/detail overloads into one API unit by (namespace, name).
  • Call edges from a regex scan of each definition body (plus absolute-qualified cudf::…::name( calls from class methods/functors in the same file), resolved by C++ namespace lookup rules. Units are grouped into work items by implementing file; strongly-connected components (cycles) are collapsed; tier = longest path to a leaf counting only unmigrated files.
  • "Temp sites" per file = get_current_device_resource_ref() calls that are not defaulted parameters + container constructions relying on the defaulted mr + file-local helpers returning owning device memory without an mr parameter. It is a workload estimate, not an exact count.
  • A file is already done if all its API units already accept cudf::memory_resources (16 units / 8 files today: copying/gather.cu + detail/gather.cuh, dictionary/{encode,decode}.cu, detail/valid_if.cuh, detail/sizes_to_offsets_iterator.cuh, strings/detail/gather.cuh, io/parquet/synthetic_column_helpers.cu). A file is signature-only if it and everything below it allocate only their outputs: it still needs the cudf::memory_resources signature change (so callers can pass mr through uniformly), but no body rerouting (45 files, listed at the end; the reductions/*.cu simple reductions and groupby/sort/group_{min,max,sum,product}*.cu are the bulk). These are trivial PRs and can be batched by directory; they are leaves, so do them in Wave 0. They are not listed in the "Blocked by" column below — treat all of them as implicit Wave 0 prerequisites.

Limitations: regex call resolution misses calls through templates/type dispatch and function pointers, and can over-approximate on overloaded names. Treat the "Blocked by" column as a strong hint, and run rg 'cudf::detail::|cudf::[a-z_]+::detail::' <file> before starting a file to confirm.

Headline numbers

Public API functions still taking rmm::device_async_resource_ref 339
Files needing a PR 306 (Tier 0: 27, T1: 26, T2: 98, T3: 22, T4: 9, T5: 42, T6: 36, T7: 21, T8: 15, T9: 8, T10: 2)
Estimated temporary allocation sites to reroute ~1050
Files needing only the signature change 45

Critical path (do these first — they unblock everything)

Two files are called by roughly a third of the codebase each; landing them first turns Tier 2 (98 files) into fully parallel work:

  1. bitmask/null_mask.cu + include/cudf/detail/null_mask.cuh (113 callers). create_null_mask, copy_bitmask, bitmask_and/or, segmented_bitmask_and, bitmask_binop, segmented_null_mask_reduction, segmented_count_bits. Forms a small cycle with the already-migrated valid_if.cuh. One PR.
  2. column/column_factories.cpp + column/column_factories.cu (100 callers). make_numeric_column, make_fixed_width_column, make_*_column, make_column_from_scalar, make_dictionary_from_scalar. Mostly pass-through (only one temp site) — small PR, big unblock.
  3. strings/strings_column_factories.cu + include/cudf/strings/detail/strings_column_factories.cuh + strings_children.cuh (51 + 39 + 31 callers). make_strings_column, make_offsets_child_column, make_strings_children, make_chars_buffer. One PR (they are mutually recursive).
  4. scalar/scalar_factories.cpp / include/cudf/scalar/scalar_factories.hpp (9 callers), copying/copy.cpp (allocate_like — 9 callers), filling/sequence.cu, copying/get_element.cu, reductions/reductions.cpp (reduce).
  5. include/cudf/detail/copy_if.cuh (23 callers) — already in flight in #24084 (needs rebase). Blocks all of stream_compaction/*, dictionary/{add,remove}_keys, join/*, strings/replace/*, text/*.
  6. The dictionary_factories.cu ↔ unary/cast_ops.cu ↔ binaryop/binaryop.cpp ↔ binaryop/compiled/binary_ops.cu cycle (fixed-point rescale calls binary_operation; make_dictionary_column casts indices). Cycles cannot be tiered, so migrate the whole cycle in one PR.

Once 1–3 land, everything in Tier 2 is independent and can be assigned freely (mostly one-PR-per-file strings/*, hash/*, datetime, round, labeling/label_bins.cu, lists/contains.cu, interop/*, ...).

Recommended waves

Wave Contents Parallelism
W0 Critical path items 1–6 above + the remaining Tier 0 leaves (self-contained detail-only files: reductions/scan/ewm.cu, io/json/json_normalization.cu, groupby/hash/output_utils.cu, sort/sort_radix.cu, stream_compaction/distinct_helpers.cuh, join/filter_join_indices/*, groupby/sort/group_{argmax,argmin,m2,quantiles,std}.cu, io/comp/gpuinflate.cu, …) ~30 PRs, all independent
W1 Tier 1 remainder: dictionary_factories.cu, cast_ops.cu, binaryop/*, copy.cpp, scalar_factories.cpp, strings/convert/convert_fixed_point.cu, quantiles/quantile.cu, copying/pack.cpp, join/key_remapping.cu, io/parquet/reader_impl_preprocess_utils.cu, … ~25 PRs
W2 Tier 2 — the long tail of leaf public APIs (98 files). Assign by directory: strings/* (~45), text/* (~8), hash/* (~8), groupby/sort/* (~8), reductions/*, lists/*, interop/*, datetime, round, transform/*, labeling ~98 PRs, fully parallel
W3 Tiers 3–4: composites over strings (combine/concatenate.cu, split/*, contains.cu, findall.cu, text/tokenize.cu), structs_column_factories.cu / structs/utilities.cu / purge_nonempty_nulls.cu (cycle with gather — one PR), io/csv/writer_impl.cu, io/json/write_json.* ~30 PRs
W4 Tier 5–6: copy_if.cuh dependents; copying/concatenate.cu + lists/copying/concatenate.cu + structs/copying/concatenate.cu + dictionary/detail/concatenate.cu (cycle — one PR); sort/sort.cu; stream_compaction/distinct.cu; lists/lists_column_factories.cu; I/O readers (avro, orc/reader_impl_decode.cu, parquet/reader_impl_chunking_utils.cu, io/json/json_tree.cu — the largest single file at ~50 sites, io/json/host_tree_algorithms.cu); tdigest; groupby/hash/* ~80 PRs
W5 Tiers 7–10: copying/scatter.cu ↔ copying/copy.cu (cycle — one PR, ~20 sites), dictionary/add_keys.cu ↔ search/contains_column.cu (cycle — one PR), dictionary/{set,match,remove}_keys.cu, dictionary/replace.cu, sort/{rank,stable_sort,segmented_sort*,top_k}.cu, search/search_ordered.cu, join/*, replace/*, partitioning/*, merge/merge.cu, row_operator/row_operators.cu, lists/set_operations.cu, io/json/{json_column,read_json}.cu, io/functions.cpp, transform/encode.cu, groupby/sort/group_topk.cu, io/parquet/experimental/deletion_vectors.cu ~45 PRs

Within a wave everything is independent; across waves, only the "Blocked by" column matters. A PR is ready to start when all of its blockers are merged. Pass-through files with 0 temp sites (e.g. structs_column_factories.cu, copy.cpp, dictionary_factories.cu) are trivial PRs — signature change only — so do them early; they still have to land before their callers.

PR checklist (paste into PR description)

  • All public + detail signatures in the file take cudf::memory_resources mr (defaulted to cudf::get_current_device_resource_ref() in public headers only).
  • auto const temp_mr = mr.get_temporary_mr(); and no remaining cudf::get_current_device_resource_ref() calls in the file.
  • No device_uvector/device_buffer/device_scalar/make_*_device_uvector* construction relies on the defaulted mr.
  • exec_policy* calls use temp_mr.
  • Nested calls: output-bearing → mr; intermediate → memory_resources{temp_mr, temp_mr}.
  • Every cuDF API called from this file already takes cudf::memory_resources (no rmm::device_async_resource_ref is handed to any cuDF callee). If not, migrate that callee in a separate PR first.
  • Every file-local allocating helper takes cudf::memory_resources mr, not a bare rmm::device_async_resource_ref.
  • Link this issue; name the file in the PR title (Route temporary allocations in strings/case.cu through memory_resources).

Full work inventory

Ordering inside each tier is by number of callers (highest leverage first). "Temp sites" is the estimated count of allocations to reroute.

Unmigrated work items: 306 files/headers; public API functions covered: 339; estimated temp-allocation sites to route: 1095.

Tier 0 — 27 work items
File (PR unit) Public APIs in unit Callers Temp sites Blocked by (unmigrated)
bitmask/null_mask.cu bitmask_and, bitmask_or, copy_bitmask, create_null_mask, segmented_bitmask_and 113 3 include/detail/null_mask.cuh
copying/get_element.cu get_element 5 2 —
filling/sequence.cu sequence 5 2 —
reductions/reductions.cpp reduce 4 5 —
include/detail/null_mask.cuh (detail only) 3 9 —
groupby/hash/output_utils.cu (detail only) 2 3 —
io/json/json_normalization.cu (detail only) 2 11 —
sort/sort_radix.cu (detail only) 2 2 —
stream_compaction/distinct_helpers.cuh (detail only) 2 2 —
copying/contiguous_split.cu contiguous_split, packed_size 1 1 —
join/filter_join_indices/filter_join_indices.cu filter_join_indices, filter_join_indices_output_size 1 7 —
reductions/scan/ewm.cu (detail only) 1 17 —
rolling/detail/rolling_fixed_window.cu rolling_window 1 2 —
include/utilities/memory_resource.hpp set_current_device_resource_ref 0 3 —
groupby/sort/group_argmax.cu (detail only) 0 1 —
groupby/sort/group_argmin.cu (detail only) 0 1 —
groupby/sort/group_m2.cu (detail only) 0 1 —
groupby/sort/group_quantiles.cu (detail only) 0 3 —
groupby/sort/group_std.cu (detail only) 0 2 —
io/comp/gpuinflate.cu (detail only) 0 6 —
io/orc/reader_impl_helpers.cpp (detail only) 0 3 —
io/parquet/experimental/page_index_filter_utils.cu (detail only) 0 4 —
io/utilities/column_buffer.hpp (detail only) 0 1 —
reductions/all.cu (detail only) 0 2 —
reductions/any.cu (detail only) 0 2 —
replace/nans.cu normalize_nans_and_zeros, replace_nans 0 1 —
strings/reverse.cu reverse 0 1 —
Tier 1 — 26 work items
File (PR unit) Public APIs in unit Callers Temp sites Blocked by (unmigrated)
column/column_factories.cpp make_dictionary_from_scalar, make_duration_column, make_fixed_point_column, make_fixed_width_column, make_numeric_column, make_timestamp_column 100 1 bitmask/null_mask.cu, column/column_factories.cu, dictionary/dictionary_factories.cu
strings/strings_column_factories.cu make_strings_column, make_strings_column_batch 51 3 bitmask/null_mask.cu, column/column_factories.cpp, include/strings/detail/strings_children.cuh, include/strings/detail/strings_column_factories.cuh
include/strings/detail/strings_column_factories.cuh (detail only) 39 0 include/strings/detail/strings_children.cuh, strings/strings_column_factories.cu
include/strings/detail/strings_children.cuh (detail only) 31 1 strings/strings_column_factories.cu
column/column_factories.cu make_column_from_scalar 15 3 bitmask/null_mask.cu, strings/strings_column_factories.cu
dictionary/dictionary_factories.cu make_dictionary_column 11 0 bitmask/null_mask.cu, unary/cast_ops.cu
copying/copy.cpp allocate_like 9 0 bitmask/null_mask.cu
scalar/scalar_factories.cpp make_default_constructed_scalar, make_duration_scalar, make_empty_scalar_like, make_fixed_width_scalar, make_list_scalar, make_numeric_scalar, make_struct_scalar, make_timestamp_scalar 9 0 copying/get_element.cu
unary/cast_ops.cu cast 6 4 binaryop/binaryop.cpp, bitmask/null_mask.cu, column/column_factories.cu
io/json/parser_features.cpp (detail only) 4 0 bitmask/null_mask.cu
reductions/segmented/update_validity.cu (detail only) 3 0 include/detail/null_mask.cuh
reductions/scan/scan.cuh (detail only) 2 0 reductions/scan/ewm.cu
reductions/segmented/counts.cu (detail only) 2 1 include/detail/null_mask.cuh
strings/convert/convert_fixed_point.cu from_fixed_point, is_fixed_point, to_fixed_point 2 2 bitmask/null_mask.cu
binaryop/binaryop.cpp binary_operation, scalar_col_valid_mask_and 1 0 binaryop/compiled/binary_ops.cu, bitmask/null_mask.cu, column/column_factories.cpp
binaryop/compiled/binary_ops.cu (detail only) 1 2 bitmask/null_mask.cu, strings/strings_column_factories.cu
copying/pack.cpp pack 1 0 copying/contiguous_split.cu
quantiles/quantile.cu quantile 1 3 bitmask/null_mask.cu
stream_compaction/distinct_helpers.hpp (detail only) 1 0 stream_compaction/distinct_helpers.cuh
groupby/sort/group_bitwise.cu (detail only) 0 1 —
io/parquet/reader_impl_preprocess_utils.cu (detail only) 0 17 reductions/reductions.cpp
join/key_remapping.cu (detail only) 0 11 bitmask/null_mask.cu
join/streaming_hash_join.cu (detail only) 0 0 bitmask/null_mask.cu
lists/copying/copying.cu (detail only) 0 2 bitmask/null_mask.cu
reductions/nth_element.cu (detail only) 0 3 copying/get_element.cu
transform/bools_to_mask.cu bools_to_mask 0 0 —
Tier 2 — 98 work items
File (PR unit) Public APIs in unit Callers Temp sites Blocked by (unmigrated)
lists/utilities.cu (detail only) 7 1 column/column_factories.cpp
hash/sha_hash.cuh (detail only) 5 1 strings/strings_column_factories.cu
strings/utilities.cu create_string_vector_from_column 5 1 column/column_factories.cpp
strings/count_matches.cu (detail only) 3 0 column/column_factories.cpp
strings/positions.cu (detail only) 3 3 strings/strings_column_factories.cu
transform/transform.cu compute_column_jit, compute_table_jit, multi_transform, transform, transform_extended, transform_lto 3 3 bitmask/null_mask.cu, strings/strings_column_factories.cu
include/strings/detail/copy_if_else.cuh (detail only) 2 2 strings/strings_column_factories.cu
interop/from_arrow_host.cu from_arrow, from_arrow_column, from_arrow_host, `fr