Skip to content

Commit

Permalink
swap device_ and non-device typenames
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jan 20, 2025
1 parent c8c289f commit 3b13f97
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 64 deletions.
14 changes: 7 additions & 7 deletions common/unified/components/range_minimum_query_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ void compute_lookup_inside_blocks(
// non-trivial objects on the device.
GKO_NOT_IMPLEMENTED;
#else
using device_type = device_range_minimum_query<IndexType>;
constexpr auto block_size = device_type::block_size;
using rmq_type = gko::range_minimum_query<IndexType>;
constexpr auto block_size = rmq_type::block_size;
using tree_index_type = std::decay_t<decltype(*block_tree_index)>;
using device_lut_type = typename device_type::block_lut_type;
using lut_type = typename device_type::block_lut_view_type;
using device_lut_type = typename rmq_type::block_lut_type;
using lut_type = typename rmq_type::block_lut_view_type;
static_assert(
lut_type::num_trees <= std::numeric_limits<tree_index_type>::max(),
"block type storage too small");
Expand All @@ -58,7 +58,7 @@ void compute_lookup_inside_blocks(
auto size) {
// we need to put this here because some compilers interpret capture
// rules around constexpr incorrectly
constexpr auto block_size = device_type::block_size;
constexpr auto block_size = rmq_type::block_size;
constexpr auto infinity = std::numeric_limits<IndexType>::max();
const auto num_blocks = ceildiv(size, block_size);
for (auto block_idx = collated_block_idx * collation_width;
Expand Down Expand Up @@ -99,15 +99,15 @@ template <typename IndexType>
void compute_lookup_across_blocks(
std::shared_ptr<const DefaultExecutor> exec, const IndexType* block_min,
IndexType num_blocks,
range_minimum_query_superblocks<IndexType>& superblocks)
device_range_minimum_query_superblocks<IndexType>& superblocks)
{
#ifdef GKO_COMPILING_DPCPP
GKO_NOT_IMPLEMENTED;
#else
if (num_blocks < 2) {
return;
}
using superblock_type = range_minimum_query_superblocks<IndexType>;
using superblock_type = device_range_minimum_query_superblocks<IndexType>;
using storage_type = typename superblock_type::storage_type;
// we need to collate all writes that target the same memory word in a
// single thread
Expand Down
24 changes: 12 additions & 12 deletions core/components/range_minimum_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ GKO_REGISTER_OPERATION(compute_lookup_across_blocks,


template <typename IndexType>
device_range_minimum_query<IndexType>::device_range_minimum_query(
array<IndexType> data)
range_minimum_query<IndexType>::range_minimum_query(array<IndexType> data)
: num_blocks_{static_cast<index_type>(
ceildiv(static_cast<index_type>(data.get_size()), block_size))},
lut_{data.get_executor()},
Expand Down Expand Up @@ -55,21 +54,22 @@ device_range_minimum_query<IndexType>::device_range_minimum_query(


template <typename IndexType>
typename device_range_minimum_query<IndexType>::view_type
device_range_minimum_query<IndexType>::get() const
typename range_minimum_query<IndexType>::view_type
range_minimum_query<IndexType>::get() const
{
return range_minimum_query{values_.get_const_data(),
block_min_.get_const_data(),
block_argmin_storage_.get_const_data(),
block_tree_indices_.get_const_data(),
superblock_storage_.get_const_data(),
lut_.get(),
static_cast<index_type>(values_.get_size())};
return device_range_minimum_query{
values_.get_const_data(),
block_min_.get_const_data(),
block_argmin_storage_.get_const_data(),
block_tree_indices_.get_const_data(),
superblock_storage_.get_const_data(),
lut_.get(),
static_cast<index_type>(values_.get_size())};
}


#define GKO_DEFINE_DEVICE_RANGE_MINIMUM_QUERY(IndexType) \
class device_range_minimum_query<IndexType>
class range_minimum_query<IndexType>

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DEFINE_DEVICE_RANGE_MINIMUM_QUERY);

Expand Down
45 changes: 22 additions & 23 deletions core/components/range_minimum_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ struct cartesian_tree {


template <int block_size>
class block_range_minimum_query_lookup_table {
class device_block_range_minimum_query_lookup_table {
public:
using tree = detail::cartesian_tree<block_size>;
// how many trees does the lookup table (LUT) contain?
constexpr static int num_trees = tree::num_trees;
// how many bits do we need theoretically for this block?
constexpr static int num_bits = ceil_log2_constexpr(block_size);

constexpr block_range_minimum_query_lookup_table() : lookup_table{}
constexpr device_block_range_minimum_query_lookup_table() : lookup_table{}
{
const auto& representatives = tree::compute_tree_representatives();
for (int tree = 0; tree < num_trees; tree++) {
Expand Down Expand Up @@ -269,13 +269,12 @@ class block_range_minimum_query_lookup_table {
* @tparam block_size the small block size to build the lookup table for.
*/
template <int block_size>
class device_block_range_minimum_query_lookup_table {
class block_range_minimum_query_lookup_table {
public:
using view_type = block_range_minimum_query_lookup_table<block_size>;
using view_type = device_block_range_minimum_query_lookup_table<block_size>;

/** Initializes the lookup table in device memory for the given executor. */
device_block_range_minimum_query_lookup_table(
std::shared_ptr<const Executor> exec)
block_range_minimum_query_lookup_table(std::shared_ptr<const Executor> exec)
: data_{exec, sizeof(view_type)}
{
view_type lut{};
Expand Down Expand Up @@ -321,7 +320,7 @@ struct range_minimum_query_result {
* with infinity values, which are never the minimum.
*/
template <typename IndexType>
class range_minimum_query_superblocks {
class device_range_minimum_query_superblocks {
public:
using index_type = IndexType;
using storage_type = std::make_unsigned_t<index_type>;
Expand All @@ -337,9 +336,8 @@ class range_minimum_query_superblocks {
* `storage_size(size)`
* @param size the number of values in the value array
*/
explicit constexpr range_minimum_query_superblocks(const index_type* values,
storage_type* storage,
index_type size)
explicit constexpr device_range_minimum_query_superblocks(
const index_type* values, storage_type* storage, index_type size)
: values_{values}, storage_{storage}, size_{size}
{}

Expand Down Expand Up @@ -530,13 +528,13 @@ class range_minimum_query_superblocks {
* Minimum Queries on Static Arrays," doi: 10.1137/090779759.
*/
template <int block_size, typename IndexType>
class range_minimum_query {
class device_range_minimum_query {
public:
using index_type = IndexType;
using block_lookup_type =
block_range_minimum_query_lookup_table<block_size>;
device_block_range_minimum_query_lookup_table<block_size>;
using superblock_lookup_type =
range_minimum_query_superblocks<const index_type>;
device_range_minimum_query_superblocks<const index_type>;
using storage_type = typename superblock_lookup_type::storage_type;
using query_result = range_minimum_query_result<index_type>;

Expand All @@ -551,7 +549,7 @@ class range_minimum_query {
* @param block_lut the lookup table for RMQs inside small Cartesian trees
* @param size the number of elements in the value array
*/
explicit constexpr range_minimum_query(
explicit constexpr device_range_minimum_query(
const index_type* values, const index_type* block_min,
const uint32* block_argmin, const uint16* block_tree_index,
const storage_type* superblock_storage,
Expand Down Expand Up @@ -656,26 +654,26 @@ class range_minimum_query {


/**
* Owning version of range_minimum_query, which creates the necessary data from
* an input array automatically.
* Owning version of device_range_minimum_query, which creates the necessary
* data from an input array automatically.
*
* @tparam IndexType the type of indices and values in the underlying array.
*/
template <typename IndexType>
class device_range_minimum_query {
class range_minimum_query {
public:
constexpr static int block_size = 8;
constexpr static int block_argmin_num_bits =
ceil_log2_constexpr(block_size);
using index_type = IndexType;
using view_type = range_minimum_query<block_size, index_type>;
using block_lut_type =
device_block_range_minimum_query_lookup_table<block_size>;
using view_type = device_range_minimum_query<block_size, index_type>;
using block_lut_type = block_range_minimum_query_lookup_table<block_size>;
using block_lut_view_type = typename block_lut_type::view_type;
using block_argmin_view_type = bit_packed_span<int, index_type, uint32>;
using block_argmin_storage_type =
typename block_argmin_view_type::storage_type;
using superblock_view_type = range_minimum_query_superblocks<index_type>;
using superblock_view_type =
device_range_minimum_query_superblocks<index_type>;
using superblock_storage_type = typename superblock_view_type::storage_type;

/**
Expand All @@ -685,10 +683,11 @@ class device_range_minimum_query {
*
* @param data the value array
*/
device_range_minimum_query(array<IndexType> data);
range_minimum_query(array<IndexType> data);

/**
* Returns the range_minimum_query view for the data, to be used in kernels.
* Returns the device_range_minimum_query view for the data, for use in
* kernels.
*/
view_type get() const;

Expand Down
2 changes: 1 addition & 1 deletion core/components/range_minimum_query_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace kernels {
void compute_lookup_across_blocks( \
std::shared_ptr<const DefaultExecutor> exec, \
const IndexType* block_min, IndexType num_blocks, \
range_minimum_query_superblocks<IndexType>& superblocks)
device_range_minimum_query_superblocks<IndexType>& superblocks)


#define GKO_DECLARE_ALL_AS_TEMPLATES \
Expand Down
14 changes: 8 additions & 6 deletions core/test/components/range_minimum_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(RangeMinimumQuery, LookupRepresentatives)
{
constexpr auto size = 8;
using tree = gko::detail::cartesian_tree<size>;
gko::block_range_minimum_query_lookup_table<size> table;
gko::device_block_range_minimum_query_lookup_table<size> table;
const auto reps = tree::compute_tree_representatives();
for (const auto& rep : reps) {
const auto tree = tree::compute_tree_index(rep, tree::ballot_number);
Expand All @@ -54,7 +54,7 @@ TEST(RangeMinimumQuery, LookupRepresentatives)
TEST(RangeMinimumQuery, LookupExhaustive)
{
constexpr auto size = 8;
gko::block_range_minimum_query_lookup_table<size> table;
gko::device_block_range_minimum_query_lookup_table<size> table;
int values[size]{};
std::iota(values, values + size, 0);
do {
Expand All @@ -75,9 +75,9 @@ TEST(RangeMinimumQuery, LookupExhaustive)

TEST(RangeMinimumQuery, OffsetsAreCorrect)
{
constexpr auto data = gko::range_minimum_query_superblocks<
constexpr auto data = gko::device_range_minimum_query_superblocks<
gko::int32>::compute_block_offset_lookup();
constexpr auto data_long = gko::range_minimum_query_superblocks<
constexpr auto data_long = gko::device_range_minimum_query_superblocks<
gko::int64>::compute_block_offset_lookup();
ASSERT_EQ(data[0], 0);
ASSERT_EQ(data_long[0], 0);
Expand Down Expand Up @@ -123,7 +123,8 @@ TEST(RangeMinimumQuery, NumLevelsIsCorrect)
{
const auto test = [](auto value) {
using index_type = decltype(value);
using superblocks = gko::range_minimum_query_superblocks<index_type>;
using superblocks =
gko::device_range_minimum_query_superblocks<index_type>;
ASSERT_EQ(superblocks::num_levels(0), 0);
ASSERT_EQ(superblocks::num_levels(1), 0);
ASSERT_EQ(superblocks::num_levels(2), 1);
Expand All @@ -149,7 +150,8 @@ TEST(RangeMinimumQuery, LevelForDistanceIsCorrect)
{
const auto test = [](auto value) {
using index_type = decltype(value);
using superblocks = gko::range_minimum_query_superblocks<index_type>;
using superblocks =
gko::device_range_minimum_query_superblocks<index_type>;
ASSERT_EQ(superblocks::level_for_distance(0), 0);
ASSERT_EQ(superblocks::level_for_distance(1), 0);
ASSERT_EQ(superblocks::level_for_distance(2), 0);
Expand Down
10 changes: 5 additions & 5 deletions reference/components/range_minimum_query_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ void compute_lookup_inside_blocks(
IndexType size, bit_packed_span<int, IndexType, uint32>& block_argmin,
IndexType* block_min, uint16* block_tree_index)
{
using device_type = device_range_minimum_query<IndexType>;
constexpr auto block_size = device_type::block_size;
using rmq_type = gko::range_minimum_query<IndexType>;
constexpr auto block_size = rmq_type::block_size;
using tree_index_type = std::decay_t<decltype(*block_tree_index)>;
using lut_type = typename device_type::block_lut_view_type;
using lut_type = typename rmq_type::block_lut_view_type;
lut_type table;
static_assert(
lut_type::num_trees <= std::numeric_limits<tree_index_type>::max(),
Expand Down Expand Up @@ -59,9 +59,9 @@ template <typename IndexType>
void compute_lookup_across_blocks(
std::shared_ptr<const DefaultExecutor> exec, const IndexType* block_min,
IndexType num_blocks,
range_minimum_query_superblocks<IndexType>& superblocks)
device_range_minimum_query_superblocks<IndexType>& superblocks)
{
using superblock_type = range_minimum_query_superblocks<IndexType>;
using superblock_type = device_range_minimum_query_superblocks<IndexType>;
constexpr auto infinity = std::numeric_limits<IndexType>::max();
if (num_blocks < 2) {
return;
Expand Down
7 changes: 4 additions & 3 deletions reference/test/components/range_minimum_query_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RangeMinimumQuery : public ::testing::Test {
protected:
using index_type = IndexType;
using storage_type = std::make_unsigned_t<index_type>;
using device_type = gko::device_range_minimum_query<index_type>;
using device_type = gko::range_minimum_query<index_type>;
using block_argmin_view_type = typename device_type::block_argmin_view_type;
using superblock_view_type = typename device_type::superblock_view_type;
constexpr static auto block_size = device_type::block_size;
Expand Down Expand Up @@ -71,7 +71,8 @@ TYPED_TEST(RangeMinimumQuery, ComputeLookupSmall)
block_argmin_num_bits, num_blocks};
std::vector<index_type> block_min(num_blocks);
std::vector<gko::uint16> block_tree_index(num_blocks);
gko::block_range_minimum_query_lookup_table<block_size> small_lut;
gko::device_block_range_minimum_query_lookup_table<block_size>
small_lut;

gko::kernels::reference::range_minimum_query::
compute_lookup_inside_blocks(this->ref, values.data(), size,
Expand Down Expand Up @@ -185,7 +186,7 @@ TYPED_TEST(RangeMinimumQuery, FullQuery)
for (index_type size : this->sizes) {
SCOPED_TRACE(size);
const auto values = this->create_random_values(size);
gko::device_range_minimum_query<index_type> rmq{
gko::range_minimum_query<index_type> rmq{
gko::array<index_type>{this->ref, values.begin(), values.end()}};

for (auto first : gko::irange{size}) {
Expand Down
14 changes: 7 additions & 7 deletions test/components/range_minimum_query_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class RangeMinimumQuery : public CommonTestFixture {
protected:
using index_type = T;
using storage_type = std::make_unsigned_t<index_type>;
using block_argmin_view_type = typename gko::device_range_minimum_query<
index_type>::block_argmin_view_type;
using block_argmin_view_type =
typename gko::range_minimum_query<index_type>::block_argmin_view_type;
using superblock_view_type =
gko::range_minimum_query_superblocks<index_type>;
gko::device_range_minimum_query_superblocks<index_type>;
constexpr static auto block_size =
gko::device_range_minimum_query<index_type>::block_size;
gko::range_minimum_query<index_type>::block_size;

RangeMinimumQuery()
: rng{19654}, sizes{0, 1, 7, 8, 9, 1023, 1024, 1025, 10000, 100000}
Expand Down Expand Up @@ -189,7 +189,7 @@ template <typename IndexType>
void run_rmq_device(std::shared_ptr<const gko::EXEC_TYPE> exec,
const gko::array<IndexType>& dbegins,
const gko::array<IndexType>& dends,
const gko::device_range_minimum_query<IndexType>& drmq,
const gko::range_minimum_query<IndexType>& drmq,
gko::array<IndexType>& doutput_min,
gko::array<IndexType>& doutput_argmin)
{
Expand Down Expand Up @@ -222,8 +222,8 @@ TYPED_TEST(RangeMinimumQuery, QueryIsEquivalentToRef)
gko::array<index_type> dends{this->exec, ends};
gko::array<index_type> doutput_min{this->exec, begins.get_size()};
gko::array<index_type> doutput_argmin{this->exec, begins.get_size()};
gko::device_range_minimum_query<index_type> rmq{std::move(values)};
gko::device_range_minimum_query<index_type> drmq{std::move(dvalues)};
gko::range_minimum_query<index_type> rmq{std::move(values)};
gko::range_minimum_query<index_type> drmq{std::move(dvalues)};

for (const auto i :
gko::irange{static_cast<index_type>(begins.get_size())}) {
Expand Down

0 comments on commit 3b13f97

Please sign in to comment.