Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cudax/include/cuda/experimental/__hierarchy/concepts.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// Part of CUDA Experimental in CUDA C++ Core Libraries,
// 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) 2026 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef _CUDA_EXPERIMENTAL___HIERARCHY_CONCEPTS_CUH
#define _CUDA_EXPERIMENTAL___HIERARCHY_CONCEPTS_CUH

#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/__concepts/concept_macros.h>

#include <cuda/std/__cccl/prologue.h>

namespace cuda::experimental
{
// todo:
// - add check that level_type is actually a valid level type
// - check that at least level_type{}.count(__g) and level_type{}.rank(__g) are valid?
template <class _Tp>
_CCCL_CONCEPT hierarchy_group = _CCCL_REQUIRES_EXPR((_Tp), _Tp& __g)(
typename(typename _Tp::level_type), //
__g.sync() //
);
} // namespace cuda::experimental

#include <cuda/std/__cccl/epilogue.h>

#endif // _CUDA_EXPERIMENTAL___HIERARCHY_CONCEPTS_CUH
38 changes: 6 additions & 32 deletions cudax/include/cuda/experimental/__hierarchy/fwd.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,19 @@

namespace cuda::experimental
{
// hierarchy group kinds

class __this_hierarchy_group_kind
{};

// hierarchy group base

template <class _Level, class _Hierarchy, class _Kind>
class __hierarchy_group_base;
template <class _Level, class _Hierarchy>
using __this_hierarchy_group_base = __hierarchy_group_base<_Level, _Hierarchy, __this_hierarchy_group_kind>;

// hierarchy groups

template <class _Hierarchy, class _Kind>
class thread_group;
template <class _Hierarchy, class _Kind>
class warp_group;
template <class _Hierarchy, class _Kind>
class block_group;
template <class _Hierarchy, class _Kind>
class cluster_group;
template <class _Hierarchy, class _Kind>
class grid_group;

// traits
class __this_group_base;

template <class _Tp>
inline constexpr bool __is_this_hierarchy_group_v = false;
template <class _Hierarchy>
inline constexpr bool __is_this_hierarchy_group_v<thread_group<_Hierarchy, __this_hierarchy_group_kind>> = true;
class this_thread;
template <class _Hierarchy>
inline constexpr bool __is_this_hierarchy_group_v<warp_group<_Hierarchy, __this_hierarchy_group_kind>> = true;
class this_warp;
template <class _Hierarchy>
inline constexpr bool __is_this_hierarchy_group_v<block_group<_Hierarchy, __this_hierarchy_group_kind>> = true;
class this_block;
template <class _Hierarchy>
inline constexpr bool __is_this_hierarchy_group_v<cluster_group<_Hierarchy, __this_hierarchy_group_kind>> = true;
class this_cluster;
template <class _Hierarchy>
inline constexpr bool __is_this_hierarchy_group_v<grid_group<_Hierarchy, __this_hierarchy_group_kind>> = true;
class this_grid;
} // namespace cuda::experimental

#include <cuda/std/__cccl/epilogue.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef _CUDA_EXPERIMENTAL___HIERARCHY_GROUP_CUH
#define _CUDA_EXPERIMENTAL___HIERARCHY_GROUP_CUH
#ifndef _CUDA_EXPERIMENTAL___HIERARCHY_THIS_GROUP_CUH
#define _CUDA_EXPERIMENTAL___HIERARCHY_THIS_GROUP_CUH

#include <cuda/std/detail/__config>

Expand Down Expand Up @@ -39,7 +39,7 @@ using __hierarchy_type_of =

// todo: use __hier_ in queries
template <class _Level, class _Hierarchy>
class __hierarchy_group_base<_Level, _Hierarchy, __this_hierarchy_group_kind>
class __this_group_base
{
static_assert(__is_hierarchy_level_v<_Level>);
static_assert(__is_hierarchy_v<_Hierarchy>);
Expand All @@ -49,9 +49,13 @@ class __hierarchy_group_base<_Level, _Hierarchy, __this_hierarchy_group_kind>
public:
using hierarchy_type = _Hierarchy;

// todo: do we want to allow construction without hierarchy? Or some `cuda::no_hierarchy` tag? Or construction from
// {level_type}_desc type? The reason is that it would be nice not to force the users to use the hierarchy type.
// Maybe even storing the reference to hierarchy is an overkill and we would be fine with the level description.

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(::cuda::std::is_same_v<_Hierarchy, __hierarchy_type_of<_HierarchyLike>>)
_CCCL_DEVICE_API __hierarchy_group_base(const _HierarchyLike& __hier_like) noexcept
_CCCL_DEVICE_API __this_group_base(const _HierarchyLike& __hier_like) noexcept
: __hier_{::cuda::__unpack_hierarchy_if_needed(__hier_like)}
{}

Expand Down Expand Up @@ -94,9 +98,9 @@ public:
};

template <class _Hierarchy>
class thread_group<_Hierarchy, __this_hierarchy_group_kind> : __this_hierarchy_group_base<thread_level, _Hierarchy>
class this_thread : __this_group_base<thread_level, _Hierarchy>
{
using __base_type = __this_hierarchy_group_base<thread_level, _Hierarchy>;
using __base_type = __this_group_base<thread_level, _Hierarchy>;

public:
using level_type = thread_level;
Expand All @@ -115,13 +119,12 @@ public:

_CCCL_TEMPLATE(class _Hierarchy)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_Hierarchy>)
_CCCL_HOST_DEVICE thread_group(const _Hierarchy&)
-> thread_group<__hierarchy_type_of<_Hierarchy>, __this_hierarchy_group_kind>;
_CCCL_HOST_DEVICE this_thread(const _Hierarchy&) -> this_thread<__hierarchy_type_of<_Hierarchy>>;

template <class _Hierarchy>
class warp_group<_Hierarchy, __this_hierarchy_group_kind> : __this_hierarchy_group_base<warp_level, _Hierarchy>
class this_warp : __this_group_base<warp_level, _Hierarchy>
{
using __base_type = __this_hierarchy_group_base<warp_level, _Hierarchy>;
using __base_type = __this_group_base<warp_level, _Hierarchy>;

public:
using level_type = warp_level;
Expand All @@ -143,13 +146,12 @@ public:

_CCCL_TEMPLATE(class _Hierarchy)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_Hierarchy>)
_CCCL_HOST_DEVICE warp_group(const _Hierarchy&)
-> warp_group<__hierarchy_type_of<_Hierarchy>, __this_hierarchy_group_kind>;
_CCCL_HOST_DEVICE this_warp(const _Hierarchy&) -> this_warp<__hierarchy_type_of<_Hierarchy>>;

template <class _Hierarchy>
class block_group<_Hierarchy, __this_hierarchy_group_kind> : __this_hierarchy_group_base<block_level, _Hierarchy>
class this_block : __this_group_base<block_level, _Hierarchy>
{
using __base_type = __this_hierarchy_group_base<block_level, _Hierarchy>;
using __base_type = __this_group_base<block_level, _Hierarchy>;

public:
using level_type = block_level;
Expand All @@ -172,13 +174,12 @@ public:

_CCCL_TEMPLATE(class _Hierarchy)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_Hierarchy>)
_CCCL_HOST_DEVICE block_group(const _Hierarchy&)
-> block_group<__hierarchy_type_of<_Hierarchy>, __this_hierarchy_group_kind>;
_CCCL_HOST_DEVICE this_block(const _Hierarchy&) -> this_block<__hierarchy_type_of<_Hierarchy>>;

template <class _Hierarchy>
class cluster_group<_Hierarchy, __this_hierarchy_group_kind> : __this_hierarchy_group_base<cluster_level, _Hierarchy>
class this_cluster : __this_group_base<cluster_level, _Hierarchy>
{
using __base_type = __this_hierarchy_group_base<cluster_level, _Hierarchy>;
using __base_type = __this_group_base<cluster_level, _Hierarchy>;

public:
using level_type = cluster_level;
Expand Down Expand Up @@ -206,13 +207,12 @@ public:

_CCCL_TEMPLATE(class _Hierarchy)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_Hierarchy>)
_CCCL_HOST_DEVICE cluster_group(const _Hierarchy&)
-> cluster_group<__hierarchy_type_of<_Hierarchy>, __this_hierarchy_group_kind>;
_CCCL_HOST_DEVICE this_cluster(const _Hierarchy&) -> this_cluster<__hierarchy_type_of<_Hierarchy>>;

template <class _Hierarchy>
class grid_group<_Hierarchy, __this_hierarchy_group_kind> : __this_hierarchy_group_base<grid_level, _Hierarchy>
class this_grid : __this_group_base<grid_level, _Hierarchy>
{
using __base_type = __this_hierarchy_group_base<grid_level, _Hierarchy>;
using __base_type = __this_group_base<grid_level, _Hierarchy>;

public:
using level_type = grid_level;
Expand All @@ -230,45 +230,9 @@ public:

_CCCL_TEMPLATE(class _Hierarchy)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_Hierarchy>)
_CCCL_HOST_DEVICE grid_group(const _Hierarchy&)
-> grid_group<__hierarchy_type_of<_Hierarchy>, __this_hierarchy_group_kind>;

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_HierarchyLike>)
[[nodiscard]] _CCCL_DEVICE_API auto this_thread(const _HierarchyLike& __hier_like) noexcept
{
return thread_group{__hier_like};
}

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_HierarchyLike>)
[[nodiscard]] _CCCL_DEVICE_API auto this_warp(const _HierarchyLike& __hier_like) noexcept
{
return warp_group{__hier_like};
}

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_HierarchyLike>)
[[nodiscard]] _CCCL_DEVICE_API auto this_block(const _HierarchyLike& __hier_like) noexcept
{
return block_group{__hier_like};
}

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_HierarchyLike>)
[[nodiscard]] _CCCL_DEVICE_API auto this_cluster(const _HierarchyLike& __hier_like) noexcept
{
return cluster_group{__hier_like};
}

_CCCL_TEMPLATE(class _HierarchyLike)
_CCCL_REQUIRES(__is_or_has_hierarchy_member_v<_HierarchyLike>)
[[nodiscard]] _CCCL_DEVICE_API auto this_grid(const _HierarchyLike& __hier_like) noexcept
{
return grid_group{__hier_like};
}
_CCCL_HOST_DEVICE this_grid(const _Hierarchy&) -> this_grid<__hierarchy_type_of<_Hierarchy>>;
} // namespace cuda::experimental

#include <cuda/std/__cccl/epilogue.h>

#endif // _CUDA_EXPERIMENTAL___HIERARCHY_GROUP_CUH
#endif // _CUDA_EXPERIMENTAL___HIERARCHY_THIS_GROUP_CUH
3 changes: 2 additions & 1 deletion cudax/include/cuda/experimental/hierarchy.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
# pragma system_header
#endif // no system header

#include <cuda/experimental/__hierarchy/concepts.cuh>
#include <cuda/experimental/__hierarchy/fwd.cuh>
#include <cuda/experimental/__hierarchy/grid_sync.cuh>
#include <cuda/experimental/__hierarchy/group.cuh>
#include <cuda/experimental/__hierarchy/this_group.cuh>

#endif // _CUDA_EXPERIMENTAL_HIERARCHY
Loading
Loading