cuda::experimental::hierarchy::count

Defined in include/cuda/experimental/__hierarchy/hierarchy_levels.cuh

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

Counts the number of entities in a CUDA hierarchy level.

Returns how many instances of Unit are in Level. 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 num_threads_in_block = hierarchy::count(thread, block);
    int num_blocks_in_grid = grid.count(block);

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

Template Parameters
  • Unit – Specifies what should be counted

  • Level – Specifies at what CUDA hierarchy level the count should happen