Skip to content

refactor: replace rmm::device_scalar with cudf::detail::device_scalar - #23618

Open
vyasr wants to merge 3 commits into
NVIDIA:mainfrom
vyasr:drop-rmm-device-scalar
Open

refactor: replace rmm::device_scalar with cudf::detail::device_scalar#23618
vyasr wants to merge 3 commits into
NVIDIA:mainfrom
vyasr:drop-rmm-device-scalar

Conversation

@vyasr

@vyasr vyasr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Replaces libcudf's direct rmm::device_scalar usage with cudf::detail::device_scalar, which now owns size-1 rmm::device_uvector storage directly. Also removes the final rmm::device_scalar<cuda::std::atomic_flag> use in groupby hash aggregation by using a size-1 rmm::device_uvector instead. The developer guide is updated accordingly.

Checklist

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

vyasr added 2 commits August 10, 2026 18:36
Introduce a self-contained cudf::detail::device_scalar<T> wrapper (size-1 rmm::device_uvector storage) and migrate all libcudf source, tests, and libcudf_streaming to use it. Updates the scalar hierarchy ctor signatures from rmm::device_scalar<T> to cudf::detail::device_scalar<T> (public API change), refreshes DEVELOPER_GUIDE.md guidance.

This completes plan drop-rmm-device-scalar.md. A follow-up change removes the final rmm::device_scalar usage in compute_single_pass_aggs.cuh.
Replace the exemption rmm::device_scalar<cuda::std::atomic_flag> in compute_single_pass_aggs.cuh with rmm::device_uvector<cuda::std::atomic_flag> of size 1 — semantically identical (device_scalar is a size-1 device_uvector under the hood) but eliminates the last direct rmm::device_scalar reference from libcudf source. atomic_flag cannot use cudf::detail::device_scalar because it is not trivially copyable, but device_uvector has no such requirement.

Completes plan drop-final-rmm-device-scalar-usage.md.
@copy-pr-bot

copy-pr-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Aug 11, 2026
[[nodiscard]] T const* data() const noexcept { return _storage.data(); }

private:
rmm::device_uvector<T> _storage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we just go straight to cuda::buffer here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I chose not to, I'd prefer to do all the cuda::buffer switches concurrently so that reviewers can see the type in action in multiple places at once for comparison.

@vyasr
vyasr requested a review from bdice August 12, 2026 17:09
@vyasr vyasr added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 12, 2026
@vyasr
vyasr marked this pull request as ready for review August 12, 2026 17:09
@vyasr
vyasr requested review from a team as code owners August 12, 2026 17:09
* @param mr Device memory resource to use for device memory allocation.
*/
fixed_width_scalar(rmm::device_scalar<T>&& data,
fixed_width_scalar(cudf::detail::device_scalar<T>&& data,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This certainly gives me some pause. We have essentially turned this constructor from public to internal since it requires an internal class to call it.
This has come up before with the same concerns.
Perhaps new constructors should be added for the detail parameter and keep the rmm::device_scalar ones in place?

Use this for scalar input/outputs into device kernels, e.g., reduction results, null count, etc.

Key properties:
- Owns `rmm::device_uvector<T> _storage{1, stream, mr}`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the device_uvector important information in the developer guide?
I saw Bradley's comment about cuda::buffer and it seems this would need to be kept insync with internal/private data members of the class.


// Flag indicating whether a global memory aggregation fallback is required or not.
rmm::device_scalar<cuda::std::atomic_flag> needs_global_memory_fallback(stream);
rmm::device_uvector<cuda::std::atomic_flag> needs_global_memory_fallback(1, stream);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably worth adding or just moving the Cannot use device_scalar::value ... comment here. Using a device vector of size 1 is not an obvious solution because of atomic_flag.

@vyasr

vyasr commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Yikes I'm sorry I only meant to update the branch and not take this out of draft. Well, thank you @davidwendt @PointKernel @bdice for the reviews! I will try to address them ASAP. I was trying to figure out what to do about the public APIs before opening this up for review anyway, so David's question is apropos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants