Skip to content

Refactor host_span to use cuda::std::span internally and remove span_base#23072

Merged
rapids-bot[bot] merged 8 commits into
rapidsai:mainfrom
PointKernel:host-span-cuda-std-span
Jul 8, 2026
Merged

Refactor host_span to use cuda::std::span internally and remove span_base#23072
rapids-bot[bot] merged 8 commits into
rapidsai:mainfrom
PointKernel:host-span-cuda-std-span

Conversation

@PointKernel

Copy link
Copy Markdown
Member

Description

Contributes to #20539.

This PR refactors cudf::host_span to be backed by cuda::std::span internally instead of the custom cudf::detail::span_base, and removes span_base entirely now that it has no other users. The custom logic needed for copy-engine optimizations is retained: host_span still tracks is_device_accessible and still constructs from cudf-supported host containers.

Not in this PR: removing the custom device_span alias and dropping cudf::dynamic_extent.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@PointKernel
PointKernel requested a review from a team as a code owner July 1, 2026 19:49
@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Jul 1, 2026
@PointKernel PointKernel added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function 3 - Ready for Review Ready for review by team labels Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b97c90c0-1862-43d8-a54c-5900a9de17ce

📥 Commits

Reviewing files that changed from the base of the PR and between cde923f and 138feb1.

📒 Files selected for processing (1)
  • cpp/include/cudf/utilities/span.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/include/cudf/utilities/span.hpp

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated span utilities to use newer CUDA span primitives while keeping the existing host_span API and behavior intact.
    • Switched dynamic_extent to use cuda::std::dynamic_extent.
    • Reworked host_span to wrap an internal cuda::std::span and updated its accessors, constructors, subspan, and conversions accordingly.
    • Added missing forward declarations for null-mask helper operations to improve compilation compatibility.
  • Chores
    • Refreshed copyright header text.

Walkthrough

This PR refactors cudf::host_span to wrap cuda::std::span, updates dynamic_extent to use cuda::std::dynamic_extent, and adds forward declarations for two cudf::detail bitmask helper templates in null_mask.cuh, along with SPDX header updates.

Changes

host_span Internal Storage Refactor

Layer / File(s) Summary
dynamic_extent redefinition and includes
cpp/include/cudf/utilities/span.hpp
dynamic_extent switches to cuda::std::dynamic_extent, the unused <limits> include is removed, and the SPDX header text is updated.
host_span class definition and constructors
cpp/include/cudf/utilities/span.hpp
host_span stops inheriting span_base, stores _span as a cuda::std::span, and initializes _span and _is_device_accessible across the pointer, container, const-container, and copy constructors.
host_span accessor and iterator methods
cpp/include/cudf/utilities/span.hpp
operator[], front, back, begin, end, data, size, size_bytes, empty, first, last, subspan, and the conversion operator to std::span<T> now delegate to _span.

null_mask.cuh Forward Declarations

Layer / File(s) Summary
Forward declarations for bitmask binop helpers
cpp/include/cudf/detail/null_mask.cuh
Forward declarations for inplace_bitmask_binop and inplace_segmented_bitmask_binop are added before later template code uses them, and the SPDX header text is updated.

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

Possibly related PRs

  • rapidsai/cudf#22588: Related host_span API and implementation migration involving the same header and span-type changes.

Suggested reviewers: shrshi, mroeschke, wence-

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: refactoring host_span to use cuda::std::span and removing span_base.
Description check ✅ Passed The description matches the changeset and accurately describes the host_span refactor and span_base removal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cpp/include/cudf/utilities/span.hpp (1)

114-127: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

HIGH: Preserve allocator device-accessibility in container constructors.

_is_device_accessible now stays at the default false for container-backed spans, so pinned host vectors lose the flag that copy-engine paths rely on.

Proposed fix
 private:
   using span_type = cuda::std::span<T, Extent>;  ///< The underlying span type
+
+  template <typename C>
+  static constexpr bool container_is_device_accessible(C const& in)
+  {
+    if constexpr (requires { in.get_allocator().is_device_accessible(); }) {
+      return in.get_allocator().is_device_accessible();
+    } else {
+      return false;
+    }
+  }
 
 public:
@@
-  constexpr host_span(C& in) : _span{thrust::raw_pointer_cast(in.data()), in.size()}
+  constexpr host_span(C& in)
+    : _span{thrust::raw_pointer_cast(in.data()), in.size()},
+      _is_device_accessible{container_is_device_accessible(in)}
   {
   }
@@
-  constexpr host_span(C const& in) : _span{thrust::raw_pointer_cast(in.data()), in.size()}
+  constexpr host_span(C const& in)
+    : _span{thrust::raw_pointer_cast(in.data()), in.size()},
+      _is_device_accessible{container_is_device_accessible(in)}
   {
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/include/cudf/utilities/span.hpp` around lines 114 - 127, The
container-backed host_span constructors are not preserving allocator
device-accessibility, so spans built from device-accessible host containers lose
the flag that copy-engine paths depend on. Update the host_span(C&) and
host_span(C const&) constructors to derive and store _is_device_accessible from
the source container’s allocator/device-accessibility trait, consistent with the
existing span state. Use the host_span template constructors and the
container-support checks already present to locate the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/include/cudf/utilities/span.hpp`:
- Around line 233-246: The host_span subview helpers first() and last() are
dropping the device-accessibility state, so pinned-memory slices lose the
_is_device_accessible flag while subspan() preserves it. Update host_span::first
and host_span::last to construct the returned host_span with the same
accessibility metadata as the source span, using the existing host_span
constructors/fields around _span and _is_device_accessible so these views stay
device-accessible.

---

Outside diff comments:
In `@cpp/include/cudf/utilities/span.hpp`:
- Around line 114-127: The container-backed host_span constructors are not
preserving allocator device-accessibility, so spans built from device-accessible
host containers lose the flag that copy-engine paths depend on. Update the
host_span(C&) and host_span(C const&) constructors to derive and store
_is_device_accessible from the source container’s allocator/device-accessibility
trait, consistent with the existing span state. Use the host_span template
constructors and the container-support checks already present to locate the fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 114a1e0b-01ec-4f62-b605-abc2e21827e6

📥 Commits

Reviewing files that changed from the base of the PR and between e7cae5e and 93ac913.

📒 Files selected for processing (2)
  • cpp/include/cudf/detail/null_mask.cuh
  • cpp/include/cudf/utilities/span.hpp

Comment thread cpp/include/cudf/utilities/span.hpp Outdated
@PointKernel

Copy link
Copy Markdown
Member Author

Re: the outside-diff comment on the container constructors (host_span(C&) / host_span(C const&)) not preserving allocator device-accessibility — not applying this one.

The container constructors defaulted _is_device_accessible to false before this PR as well, so it isn't a regression. Device-accessibility for cudf's pinned host containers is carried by host_vector's own conversion operator, which already passes get_allocator().is_device_accessible() into the 3-arg host_span ctor:

[[nodiscard]] operator host_span<T const>() const
{
return host_span<T const>{
base::data(), base::size(), base::get_allocator().is_device_accessible()};
}
[[nodiscard]] operator host_span<T>()
{
return host_span<T>{base::data(), base::size(), base::get_allocator().is_device_accessible()};
}

The generic host_span(C&) ctor only handles std::vector / thrust::host_vector / std::basic_string, whose allocators have no is_device_accessible(), so the proposed requires-guarded helper would return false for all of them and change nothing.

Comment thread cpp/include/cudf/detail/null_mask.cuh
Comment thread cpp/include/cudf/utilities/span.hpp Outdated
Comment thread cpp/include/cudf/utilities/span.hpp Outdated
@PointKernel
PointKernel requested a review from davidwendt July 6, 2026 21:20
@PointKernel

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 6926817 into rapidsai:main Jul 8, 2026
136 checks passed
@PointKernel
PointKernel deleted the host-span-cuda-std-span branch July 8, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants