cuda::hierarchy#

template<class _BottomUnit, class ..._LevelDescs>
class hierarchy#

Type representing a hierarchy of CUDA threads.

This type combines a number of hierarchy_level_desc objects to represent dimensions of a (possibly partial) hierarchy of CUDA threads. It supports accessing individual levels or queries combining dimensions of multiple levels. This type should not be created directly and make_hierarchy function should be used instead. For every level, the unit for its dimensions is implied by the next level in the hierarchy, except for the last type, for which its the BottomUnit template argument. In case the BottomUnit type is thread_level, the hierarchy is considered complete and there exist an alias template for it named hierarchy, that only takes the Levels… template argument.

Snippet
#include <cudax/hierarchy_dimensions.cuh>

auto hierarchy = make_hierarchy(grid_dims(256), block_dims<8, 8, 8>());
assert(hierarchy.level(grid).dims.x == 256);
static_assert(hierarchy.count(thread, block) == 8 * 8 * 8);

Template Parameters:
  • BottomUnit – Type indicating what is the unit of the last level in the hierarchy

  • Levels – Template parameter pack with the types of levels in the hierarchy, must be hierarchy_level_desc instances or types derived from it

Public Types

using bottom_unit_type = _BottomUnit#
using top_level_type = ::cuda::std::__type_index_c<0, typename _LevelDescs::level_type...>#
template<class _Level>
using level_desc_type = ::cuda::std::__type_index_c<__level_idx<_Level>, _LevelDescs...>#

Public Functions

inline constexpr hierarchy(const _LevelDescs&... __lds) noexcept#
template<class _BottomUnit2 = _BottomUnit, ::cuda::std::enable_if_t<(!::cuda::std::is_same_v<void, _BottomUnit2>), int> = 0>
inline constexpr hierarchy(
const _BottomUnit2&,
const _LevelDescs&... __lds
) noexcept#
inline constexpr hierarchy(
const ::cuda::std::tuple<_LevelDescs...> &__lds
) noexcept#
template<class _BottomUnit2 = _BottomUnit, ::cuda::std::enable_if_t<(!::cuda::std::is_same_v<void, _BottomUnit2>), int> = 0>
inline constexpr hierarchy(
const _BottomUnit2&,
const ::cuda::std::tuple<_LevelDescs...> &__lds
) noexcept#
template<typename _Unit, typename _Level>
inline constexpr auto fragment(
const _Unit& = _Unit(),
const _Level& = _Level()
) const noexcept#

Get a fragment of this hierarchy.

This member function can be used to get a fragment of the hierarchy its called on. It returns a hierarchy that includes levels starting with the level specified in Level and ending with a level before Unit. Toegether with hierarchy_add_level function it can be used to create a new hierarchy that is a modification of an existing hierarchy.

Snippet
#include <cudax/hierarchy_dimensions.cuh>

auto hierarchy = make_hierarchy(grid_dims(256), cluster_dims<4>(),
block_dims<8, 8, 8>()); auto fragment = hierarchy.fragment(block, grid);
auto new_hierarchy = hierarchy_add_level(fragment, block_dims<128>());
static_assert(new_hierarchy.count(thread, block) == 128);

Template Parameters:
  • Unit – Type indicating what should be the unit of the resulting fragment

  • Level – Type indicating what should be the top most level of the resulting fragment

template<typename _Level>
inline constexpr const level_desc_type<_Level> &level(
const _Level&
) const noexcept#

Returns level description associated with a specified hierarchy level in this hierarchy.

This function returns a copy of the object associated with the specified level, that was passed into the hierarchy on its creation. Level need to be levels present in this hierarchy.

Snippet
#include <cudax/hierarchy_dimensions.cuh>

using namespace cuda;

auto hierarchy = make_hierarchy(grid_dims(256), cluster_dims<4>(),
block_dims<8, 8, 8>());
static_assert(decltype(hierarchy.level(cluster).dims)::static_extent(0) ==
4);

Template Parameters:

Level – Specifies the requested level

template<class _OtherUnit, class ..._OtherLevels>
inline constexpr auto combine(
const hierarchy<_OtherUnit, _OtherLevels...> &__other
) const#

Returns a new hierarchy with combined levels of this and the other supplied hierarchy.

This function combines this hierarchy with the supplied hierarchy, the resulting hierarchy holds levels present in both hierarchies. In case of overlap of levels this hierarchy is prioritized, so the result always holds all levels from this hierarchy and non-overlapping levels from the other hierarchy.

Parameters:

other – The other hierarchy to be combined with this hierarchy

Returns:

Hierarchy holding the combined levels from both hierarchies

Public Static Functions

template<class _Level>
static inline constexpr bool has_level(
const _Level& = _Level{}
) noexcept#

Friends

inline friend constexpr bool operator==(
const hierarchy &__lhs,
const hierarchy &__rhs
) noexcept#
inline friend constexpr bool operator!=(
const hierarchy &__lhs,
const hierarchy &__rhs
) noexcept#
template<class _NewLevel, class _Unit, class ..._LevelDescs2>
friend constexpr auto hierarchy_add_level(
const hierarchy<_Unit, _LevelDescs2...> &hierarchy,
_NewLevel __lnew
)#