Repository navigation
[cudax] Make group rank a template parameter in group dispatch #12622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,9 @@ struct __uniform_static_unit_count; | |||||
| template <::cuda::std::size_t... _StaticUnitCounts> | ||||||
| struct __static_unit_counts; | ||||||
|
|
||||||
| template <::cuda::std::size_t _StaticGroupCount, ::cuda::std::size_t _GroupRank, ::cuda::std::size_t _StaticUnitCount> | ||||||
| struct __per_group_count; | ||||||
|
|
||||||
| template <class _CountsTag, bool _IsAlwaysExhaustive, bool _IsAlwaysContiguous> | ||||||
| struct __mapping_result; | ||||||
|
|
||||||
|
|
@@ -227,7 +230,7 @@ struct __mapping_result<__static_unit_counts<_StaticUnitCounts...>, _IsAlwaysExh | |||||
| return static_cast<::cuda::std::uint32_t>(_StaticGroupCount); | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API ::cuda::std::uint32_t group_rank() const | ||||||
| [[nodiscard]] _CCCL_DEVICE_API constexpr ::cuda::std::uint32_t group_rank() const | ||||||
| { | ||||||
| if constexpr (!_IsAlwaysExhaustive) | ||||||
| { | ||||||
|
|
@@ -256,8 +259,12 @@ struct __mapping_result<__static_unit_counts<_StaticUnitCounts...>, _IsAlwaysExh | |||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr ::cuda::std::size_t static_unit_count(::cuda::std::size_t __i) | ||||||
| { | ||||||
| _CCCL_ASSERT(__i < _StaticGroupCount, "__i out of range"); | ||||||
| constexpr ::cuda::std::size_t __counts[]{_StaticUnitCounts...}; | ||||||
| return __counts[__i]; | ||||||
|
|
||||||
| // Use fold expression rather than constexpr array to keep runtime queries in registers. | ||||||
| ::cuda::std::size_t __index = 0; | ||||||
| ::cuda::std::size_t __result = 0; | ||||||
| ((__result = (__i == __index++) ? _StaticUnitCounts : __result), ...); | ||||||
| return __result; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API ::cuda::std::uint32_t unit_count() const | ||||||
|
|
@@ -310,6 +317,87 @@ struct __mapping_result<__static_unit_counts<_StaticUnitCounts...>, _IsAlwaysExh | |||||
| } | ||||||
| }; | ||||||
|
|
||||||
| // This mapping result is only ever used in group.with_static_unit_count(...) where it's constructed from the group's | ||||||
| // mapping result. That means that the mapping result is always valid. We still keep the is_always_exhaustive() property | ||||||
| // from the original mapping result. | ||||||
| template <::cuda::std::size_t _StaticGroupCount, | ||||||
| ::cuda::std::size_t _GroupRank, | ||||||
| ::cuda::std::size_t _StaticUnitCount, | ||||||
| bool _IsAlwaysExhaustive, | ||||||
| bool _IsAlwaysContiguous> | ||||||
| struct __mapping_result<__per_group_count<_StaticGroupCount, _GroupRank, _StaticUnitCount>, | ||||||
| _IsAlwaysExhaustive, | ||||||
| _IsAlwaysContiguous> | ||||||
| { | ||||||
| static_assert(_StaticGroupCount != ::cuda::std::dynamic_extent, "group count must be statically known"); | ||||||
| static_assert(_GroupRank < _StaticGroupCount, "group rank out of range"); | ||||||
| static_assert(_StaticUnitCount != ::cuda::std::dynamic_extent, "unit count must be statically known"); | ||||||
|
|
||||||
| ::cuda::std::uint32_t __unit_rank_; | ||||||
| ::cuda::device::lane_mask __lane_mask_; | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr ::cuda::std::size_t static_group_count() | ||||||
| { | ||||||
| return _StaticGroupCount; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API constexpr ::cuda::std::uint32_t group_count() const | ||||||
| { | ||||||
| return static_cast<::cuda::std::uint32_t>(_StaticGroupCount); | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API constexpr ::cuda::std::uint32_t group_rank() const | ||||||
| { | ||||||
| return static_cast<::cuda::std::uint32_t>(_GroupRank); | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr bool has_uniform_static_unit_count() | ||||||
| { | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr ::cuda::std::size_t static_unit_count() | ||||||
| { | ||||||
| return _StaticUnitCount; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr ::cuda::std::size_t static_unit_count(::cuda::std::size_t __i) | ||||||
| { | ||||||
| _CCCL_ASSERT(__i < _StaticGroupCount, "__i out of range"); | ||||||
| return _StaticUnitCount; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API constexpr ::cuda::std::uint32_t unit_count() const | ||||||
| { | ||||||
| return static_cast<::cuda::std::uint32_t>(_StaticUnitCount); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This form will error at compile time if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would already |
||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API ::cuda::std::uint32_t unit_rank() const | ||||||
| { | ||||||
| return __unit_rank_; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API ::cuda::device::lane_mask lane_mask() const | ||||||
| { | ||||||
| return __lane_mask_; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API constexpr bool is_valid() const | ||||||
| { | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr bool is_always_exhaustive() | ||||||
| { | ||||||
| return _IsAlwaysExhaustive; | ||||||
| } | ||||||
|
|
||||||
| [[nodiscard]] _CCCL_DEVICE_API static constexpr bool is_always_contiguous() | ||||||
| { | ||||||
| return _IsAlwaysContiguous; | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| template <bool _IsAlwaysContiguous> | ||||||
| [[nodiscard]] _CCCL_DEVICE_API ::cuda::device::lane_mask __make_lane_mask_for_n( | ||||||
| ::cuda::device::lane_mask __prev_lane_mask, ::cuda::std::uint32_t __n, ::cuda::std::uint32_t __rank) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so cursed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just standard library things :D