-
Notifications
You must be signed in to change notification settings - Fork 487
Rework hierarchy levels #6957
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
Merged
Merged
Rework hierarchy levels #6957
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
000c2eb
Rework hierarchy levels
davebayer 28edad3
add missing launches to native cluster level queries
davebayer 0256d3e
remove dependency on runtime storage
davebayer 893beba
Merge branch 'main' into rework_hierarchy
pciolkosz ecd12ea
Merge branch 'main' into rework_hierarchy
pciolkosz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _CUDA___FWD_HIERARCHY_H | ||
| #define _CUDA___FWD_HIERARCHY_H | ||
|
|
||
| #include <cuda/std/detail/__config> | ||
|
|
||
| #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
| # pragma GCC system_header | ||
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
| # pragma clang system_header | ||
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
| # pragma system_header | ||
| #endif // no system header | ||
|
|
||
| #include <cuda/std/__cstddef/types.h> | ||
| #include <cuda/std/__type_traits/is_base_of.h> | ||
|
|
||
| #include <cuda/std/__cccl/prologue.h> | ||
|
|
||
| _CCCL_BEGIN_NAMESPACE_CUDA | ||
|
|
||
| // hierarchy level | ||
|
|
||
| template <class _Level> | ||
| struct hierarchy_level_base; | ||
|
|
||
| template <class _Level> | ||
| struct __native_hierarchy_level_base; | ||
|
|
||
| struct grid_level; | ||
| struct cluster_level; | ||
| struct block_level; | ||
| struct warp_level; | ||
| struct thread_level; | ||
|
|
||
| template <class _Tp> | ||
| inline constexpr bool __is_hierarchy_level_v = ::cuda::std::is_base_of_v<hierarchy_level_base<_Tp>, _Tp>; | ||
|
|
||
| template <class _Tp> | ||
| inline constexpr bool __is_native_hierarchy_level_v = | ||
| ::cuda::std::is_base_of_v<__native_hierarchy_level_base<_Tp>, _Tp>; | ||
|
|
||
| // hierarchy | ||
|
|
||
| template <class _BottomUnit, class... _Levels> | ||
| struct hierarchy_dimensions; | ||
|
|
||
| template <class _Tp> | ||
| inline constexpr bool __is_hierarchy_v = false; | ||
| template <class _BottomUnit, class... _Levels> | ||
| inline constexpr bool __is_hierarchy_v<hierarchy_dimensions<_BottomUnit, _Levels...>> = true; | ||
|
|
||
| template <typename... _Levels> | ||
| struct allowed_levels; | ||
|
|
||
| _CCCL_END_NAMESPACE_CUDA | ||
|
|
||
| #include <cuda/std/__cccl/epilogue.h> | ||
|
|
||
| #endif // _CUDA___FWD_HIERARCHY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _CUDA___HIERARCHY_BLOCK_LEVEL_H | ||
| #define _CUDA___HIERARCHY_BLOCK_LEVEL_H | ||
|
|
||
| #include <cuda/std/detail/__config> | ||
|
|
||
| #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
| # pragma GCC system_header | ||
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
| # pragma clang system_header | ||
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
| # pragma system_header | ||
| #endif // no system header | ||
|
|
||
| #include <cuda/__fwd/hierarchy.h> | ||
| #include <cuda/__hierarchy/hierarchy_query_result.h> | ||
| #include <cuda/__hierarchy/native_hierarchy_level_base.h> | ||
| #include <cuda/std/__concepts/concept_macros.h> | ||
| #include <cuda/std/__mdspan/extents.h> | ||
| #include <cuda/std/__type_traits/is_integer.h> | ||
|
|
||
| #include <cuda/std/__cccl/prologue.h> | ||
|
|
||
| _CCCL_BEGIN_NAMESPACE_CUDA | ||
|
|
||
| struct block_level : __native_hierarchy_level_base<block_level> | ||
| { | ||
| using product_type = unsigned; | ||
| using allowed_above = allowed_levels<grid_level, cluster_level>; | ||
| using allowed_below = allowed_levels<thread_level>; | ||
|
|
||
| using __next_native_level = cluster_level; | ||
|
|
||
| using __base_type = __native_hierarchy_level_base<block_level>; | ||
| using __base_type::count_as; | ||
| using __base_type::extents_as; | ||
| using __base_type::index_as; | ||
| using __base_type::rank_as; | ||
|
|
||
| // interactions with cluster level | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static ::cuda::std::dims<3, _Tp> extents_as(const cluster_level&) noexcept | ||
| { | ||
| ::dim3 __dims{1u, 1u, 1u}; | ||
| NV_IF_TARGET(NV_PROVIDES_SM_90, (__dims = ::__clusterDim();)) | ||
| return ::cuda::std::dims<3, _Tp>{static_cast<_Tp>(__dims.x), static_cast<_Tp>(__dims.y), static_cast<_Tp>(__dims.z)}; | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static _Tp count_as(const cluster_level&) noexcept | ||
| { | ||
| unsigned __count = 1; | ||
| NV_IF_TARGET(NV_PROVIDES_SM_90, (__count = ::__clusterSizeInBlocks();)) | ||
| return static_cast<_Tp>(__count); | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static hierarchy_query_result<_Tp> index_as(const cluster_level&) noexcept | ||
| { | ||
| ::dim3 __idx{0u, 0u, 0u}; | ||
| NV_IF_TARGET(NV_PROVIDES_SM_90, (__idx = ::__clusterRelativeBlockIdx();)) | ||
| return {static_cast<_Tp>(__idx.x), static_cast<_Tp>(__idx.y), static_cast<_Tp>(__idx.z)}; | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static _Tp rank_as(const cluster_level&) noexcept | ||
| { | ||
| unsigned __rank = 0; | ||
| NV_IF_TARGET(NV_PROVIDES_SM_90, (__rank = ::__clusterRelativeBlockRank();)) | ||
| return static_cast<_Tp>(__rank); | ||
| } | ||
|
|
||
| // interactions with grid level | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static ::cuda::std::dims<3, _Tp> extents_as(const grid_level&) noexcept | ||
| { | ||
| return ::cuda::std::dims<3, _Tp>{ | ||
| static_cast<_Tp>(gridDim.x), static_cast<_Tp>(gridDim.y), static_cast<_Tp>(gridDim.z)}; | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static _Tp count_as(const grid_level&) noexcept | ||
| { | ||
| return static_cast<_Tp>(gridDim.x) * static_cast<_Tp>(gridDim.y) * static_cast<_Tp>(gridDim.z); | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static hierarchy_query_result<_Tp> index_as(const grid_level&) noexcept | ||
| { | ||
| return {static_cast<_Tp>(blockIdx.x), static_cast<_Tp>(blockIdx.y), static_cast<_Tp>(blockIdx.z)}; | ||
| } | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static _Tp rank_as(const grid_level& __level) noexcept | ||
| { | ||
| const auto __dims = dims_as<_Tp>(__level); | ||
| const auto __idx = index_as<_Tp>(__level); | ||
| return static_cast<_Tp>((__idx.z * __dims.y + __idx.y) * __dims.x + __idx.x); | ||
| } | ||
|
|
||
| // interactions with grid level in hierarchy | ||
|
|
||
| _CCCL_TEMPLATE(class _Tp, class _Hierarchy) | ||
| _CCCL_REQUIRES(::cuda::std::__cccl_is_integer_v<_Tp> _CCCL_AND __is_hierarchy_v<_Hierarchy>) | ||
| [[nodiscard]] _CCCL_DEVICE_API static _Tp rank_as(const grid_level& __level, const _Hierarchy& __hier) noexcept | ||
| { | ||
| static_assert(has_unit_or_level_v<block_level, _Hierarchy>, "_Hierarchy doesn't contain block level"); | ||
| static_assert(has_level_v<grid_level, _Hierarchy>, "_Hierarchy doesn't contain grid level"); | ||
|
|
||
| const auto __dims = dims_as<_Tp>(__level, __hier); | ||
| const auto __idx = index_as<_Tp>(__level, __hier); | ||
| return static_cast<_Tp>((__idx.z * __dims.y + __idx.y) * __dims.x + __idx.x); | ||
| } | ||
| }; | ||
|
|
||
| _CCCL_GLOBAL_CONSTANT block_level block; | ||
|
|
||
| _CCCL_END_NAMESPACE_CUDA | ||
|
|
||
| #include <cuda/std/__cccl/epilogue.h> | ||
|
|
||
| #endif // _CUDA___HIERARCHY_BLOCK_LEVEL_H | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.