Program Listing for File thread_index.hpp¶
↰ Return to documentation for file (include/ripple/execution/thread_index.hpp
)
//==--- ripple/core/execution/thread_index.hpp ------------- -*- C++ -*- ---==//
//
// Ripple
//
// Copyright (c) 2019, 2020 Rob Clucas.
//
// This file is distributed under the MIT License. See LICENSE for details.
//
//==------------------------------------------------------------------------==//
//
#ifndef RIPPLE_EXECUTION_THREAD_INDEX_HPP
#define RIPPLE_EXECUTION_THREAD_INDEX_HPP
#include "detail/thread_index_impl_.hpp"
namespace ripple {
/*==--- [sizes] ------------------------------------------------------------==*/
template <typename Dim>
ripple_all inline auto block_size(Dim&& dim) noexcept -> size_t {
return detail::block_size(ripple_forward(dim));
}
template <typename Dim>
ripple_all inline auto grid_size(Dim&& dim) noexcept -> size_t {
return detail::grid_size(ripple_forward(dim));
}
template <typename Dim>
ripple_all inline auto global_size(Dim&& dim) noexcept -> size_t {
return detail::grid_size(dim) * detail::block_size(dim);
}
/*==--- [indexing] ---------------------------------------------------------==*/
template <typename Dim>
ripple_all inline auto thread_idx(Dim&& dim) noexcept -> size_t {
return detail::thread_idx(ripple_forward(dim));
}
template <typename Dim>
ripple_all inline auto block_idx(Dim&& dim) noexcept -> size_t {
return detail::block_idx(ripple_forward(dim));
}
template <typename Dim>
ripple_all inline auto global_idx(Dim&& dim) noexcept -> size_t {
return detail::global_idx(ripple_forward(dim));
}
template <typename Dim>
ripple_all inline auto global_norm_idx(Dim&& dim) noexcept -> float {
return (static_cast<float>(global_idx(dim)) + 0.5) /
static_cast<float>(detail::global_elements(dim));
}
template <typename Dim>
ripple_all inline auto block_norm_idx(Dim&& dim) noexcept -> float {
return static_cast<float>(block_idx(dim)) /
static_cast<float>(block_size(dim));
}
/*==--- [utilities] --------------------------------------------------------==*/
template <typename Dim>
ripple_all inline auto
first_thread_in_block(Dim&& dim) noexcept -> bool {
return detail::thread_idx(ripple_forward(dim)) == size_t{0};
}
ripple_all inline auto first_thread_in_block() noexcept -> bool {
return first_thread_in_block(dimx()) && first_thread_in_block(dimy()) &&
first_thread_in_block(dimz());
}
template <typename Dim>
ripple_all inline auto
last_thread_in_block(Dim&& dim) noexcept -> bool {
return detail::thread_idx(ripple_forward(dim)) ==
(detail::block_size(ripple_forward(dim)) - 1);
}
ripple_all inline auto last_thread_in_block() noexcept -> bool {
return last_thread_in_block(dimx()) && last_thread_in_block(dimy()) &&
last_thread_in_block(dimz());
}
template <typename Dim>
ripple_all inline auto
first_thread_in_grid(Dim&& dim) noexcept -> bool {
return detail::global_idx(ripple_forward(dim)) == size_t{0};
}
ripple_all inline auto first_thread_in_grid() noexcept -> bool {
return first_thread_in_grid(dimx()) && first_thread_in_grid(dimy()) &&
first_thread_in_grid(dimz());
}
template <typename Dim>
ripple_all inline auto last_thread_in_grid(Dim&& dim) noexcept -> bool {
return detail::global_idx(ripple_forward(dim)) ==
(detail::global_elements(ripple_forward(dim)) - 1);
}
ripple_all inline auto last_thread_in_grid() noexcept -> bool {
return last_thread_in_grid(dimx()) && last_thread_in_grid(dimy()) &&
last_thread_in_grid(dimz());
}
} // namespace ripple
#endif // RIPPLE_EXECUTION_THREAD_INDEX_HPP