cuda::experimental::hierarchy::rank

Defined in /home/runner/work/cccl/cccl/cudax/include/cuda/experimental/__hierarchy/hierarchy_levels.cuh

template<typename Unit, typename Level>
auto cuda::experimental::hierarchy::rank(const Unit&, const Level&)

Ranks an entity the calling thread belongs to in a CUDA hierarchy level.

Returns a unique numeric rank within Level of the Unit that the calling thread belongs to. Returned rank is always in range 0 to count - 1. Unit and Level need to be core CUDA hierarchy levels, for example grid_level or block_level. This function is also available as a level type member function, in that case it only takes a unit argument.

Snippet

#include <cudax/hierarchy_dimensions.cuh>

using namespace cuda::experimental;

__global__ void kernel()
{
    // Can be called with the instances of level types
    int thread_rank_in_block = hierarchy::rank(thread, block);
    int block_rank_in_grid = grid.rank(block);

    // Or using the level types as template arguments
    int thread_rank_in_grid = hierarchy::rank<thread_level, grid_level>();
}

Template Parameters
  • Unit – Specifies the entity that the rank is requested for

  • Level – Specifies at what CUDA hierarchy level the rank is requested