diff --git a/common/unified/components/range_minimum_query_kernels.cpp b/common/unified/components/range_minimum_query_kernels.cpp index 327cccb6af7..de8e264bbd9 100644 --- a/common/unified/components/range_minimum_query_kernels.cpp +++ b/common/unified/components/range_minimum_query_kernels.cpp @@ -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; - constexpr auto block_size = device_type::block_size; + using rmq_type = gko::range_minimum_query; + constexpr auto block_size = rmq_type::block_size; using tree_index_type = std::decay_t; - 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::max(), "block type storage too small"); @@ -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::max(); const auto num_blocks = ceildiv(size, block_size); for (auto block_idx = collated_block_idx * collation_width; @@ -99,7 +99,7 @@ template void compute_lookup_across_blocks( std::shared_ptr exec, const IndexType* block_min, IndexType num_blocks, - range_minimum_query_superblocks& superblocks) + device_range_minimum_query_superblocks& superblocks) { #ifdef GKO_COMPILING_DPCPP GKO_NOT_IMPLEMENTED; @@ -107,7 +107,7 @@ void compute_lookup_across_blocks( if (num_blocks < 2) { return; } - using superblock_type = range_minimum_query_superblocks; + using superblock_type = device_range_minimum_query_superblocks; using storage_type = typename superblock_type::storage_type; // we need to collate all writes that target the same memory word in a // single thread diff --git a/core/components/range_minimum_query.cpp b/core/components/range_minimum_query.cpp index 4e10cb6fcea..07cb69fcdff 100644 --- a/core/components/range_minimum_query.cpp +++ b/core/components/range_minimum_query.cpp @@ -23,8 +23,7 @@ GKO_REGISTER_OPERATION(compute_lookup_across_blocks, template -device_range_minimum_query::device_range_minimum_query( - array data) +range_minimum_query::range_minimum_query(array data) : num_blocks_{static_cast( ceildiv(static_cast(data.get_size()), block_size))}, lut_{data.get_executor()}, @@ -55,21 +54,22 @@ device_range_minimum_query::device_range_minimum_query( template -typename device_range_minimum_query::view_type -device_range_minimum_query::get() const +typename range_minimum_query::view_type +range_minimum_query::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(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(values_.get_size())}; } #define GKO_DEFINE_DEVICE_RANGE_MINIMUM_QUERY(IndexType) \ - class device_range_minimum_query + class range_minimum_query GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DEFINE_DEVICE_RANGE_MINIMUM_QUERY); diff --git a/core/components/range_minimum_query.hpp b/core/components/range_minimum_query.hpp index aca259af22f..eccbeecbc58 100644 --- a/core/components/range_minimum_query.hpp +++ b/core/components/range_minimum_query.hpp @@ -193,7 +193,7 @@ struct cartesian_tree { template -class block_range_minimum_query_lookup_table { +class device_block_range_minimum_query_lookup_table { public: using tree = detail::cartesian_tree; // how many trees does the lookup table (LUT) contain? @@ -201,7 +201,7 @@ class block_range_minimum_query_lookup_table { // 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++) { @@ -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 -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; + using view_type = device_block_range_minimum_query_lookup_table; /** Initializes the lookup table in device memory for the given executor. */ - device_block_range_minimum_query_lookup_table( - std::shared_ptr exec) + block_range_minimum_query_lookup_table(std::shared_ptr exec) : data_{exec, sizeof(view_type)} { view_type lut{}; @@ -321,7 +320,7 @@ struct range_minimum_query_result { * with infinity values, which are never the minimum. */ template -class range_minimum_query_superblocks { +class device_range_minimum_query_superblocks { public: using index_type = IndexType; using storage_type = std::make_unsigned_t; @@ -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} {} @@ -530,13 +528,13 @@ class range_minimum_query_superblocks { * Minimum Queries on Static Arrays," doi: 10.1137/090779759. */ template -class range_minimum_query { +class device_range_minimum_query { public: using index_type = IndexType; using block_lookup_type = - block_range_minimum_query_lookup_table; + device_block_range_minimum_query_lookup_table; using superblock_lookup_type = - range_minimum_query_superblocks; + device_range_minimum_query_superblocks; using storage_type = typename superblock_lookup_type::storage_type; using query_result = range_minimum_query_result; @@ -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, @@ -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 -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; - using block_lut_type = - device_block_range_minimum_query_lookup_table; + using view_type = device_range_minimum_query; + using block_lut_type = block_range_minimum_query_lookup_table; using block_lut_view_type = typename block_lut_type::view_type; using block_argmin_view_type = bit_packed_span; using block_argmin_storage_type = typename block_argmin_view_type::storage_type; - using superblock_view_type = range_minimum_query_superblocks; + using superblock_view_type = + device_range_minimum_query_superblocks; using superblock_storage_type = typename superblock_view_type::storage_type; /** @@ -685,10 +683,11 @@ class device_range_minimum_query { * * @param data the value array */ - device_range_minimum_query(array data); + range_minimum_query(array 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; diff --git a/core/components/range_minimum_query_kernels.hpp b/core/components/range_minimum_query_kernels.hpp index 0f8aa411cc9..b777dcb2e1b 100644 --- a/core/components/range_minimum_query_kernels.hpp +++ b/core/components/range_minimum_query_kernels.hpp @@ -33,7 +33,7 @@ namespace kernels { void compute_lookup_across_blocks( \ std::shared_ptr exec, \ const IndexType* block_min, IndexType num_blocks, \ - range_minimum_query_superblocks& superblocks) + device_range_minimum_query_superblocks& superblocks) #define GKO_DECLARE_ALL_AS_TEMPLATES \ diff --git a/core/test/components/range_minimum_query.cpp b/core/test/components/range_minimum_query.cpp index a99e319e861..02f4b30eaf5 100644 --- a/core/test/components/range_minimum_query.cpp +++ b/core/test/components/range_minimum_query.cpp @@ -33,7 +33,7 @@ TEST(RangeMinimumQuery, LookupRepresentatives) { constexpr auto size = 8; using tree = gko::detail::cartesian_tree; - gko::block_range_minimum_query_lookup_table table; + gko::device_block_range_minimum_query_lookup_table table; const auto reps = tree::compute_tree_representatives(); for (const auto& rep : reps) { const auto tree = tree::compute_tree_index(rep, tree::ballot_number); @@ -54,7 +54,7 @@ TEST(RangeMinimumQuery, LookupRepresentatives) TEST(RangeMinimumQuery, LookupExhaustive) { constexpr auto size = 8; - gko::block_range_minimum_query_lookup_table table; + gko::device_block_range_minimum_query_lookup_table table; int values[size]{}; std::iota(values, values + size, 0); do { @@ -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); @@ -123,7 +123,8 @@ TEST(RangeMinimumQuery, NumLevelsIsCorrect) { const auto test = [](auto value) { using index_type = decltype(value); - using superblocks = gko::range_minimum_query_superblocks; + using superblocks = + gko::device_range_minimum_query_superblocks; ASSERT_EQ(superblocks::num_levels(0), 0); ASSERT_EQ(superblocks::num_levels(1), 0); ASSERT_EQ(superblocks::num_levels(2), 1); @@ -149,7 +150,8 @@ TEST(RangeMinimumQuery, LevelForDistanceIsCorrect) { const auto test = [](auto value) { using index_type = decltype(value); - using superblocks = gko::range_minimum_query_superblocks; + using superblocks = + gko::device_range_minimum_query_superblocks; ASSERT_EQ(superblocks::level_for_distance(0), 0); ASSERT_EQ(superblocks::level_for_distance(1), 0); ASSERT_EQ(superblocks::level_for_distance(2), 0); diff --git a/reference/components/range_minimum_query_kernels.cpp b/reference/components/range_minimum_query_kernels.cpp index 51553947a94..1de963ae668 100644 --- a/reference/components/range_minimum_query_kernels.cpp +++ b/reference/components/range_minimum_query_kernels.cpp @@ -23,10 +23,10 @@ void compute_lookup_inside_blocks( IndexType size, bit_packed_span& block_argmin, IndexType* block_min, uint16* block_tree_index) { - using device_type = device_range_minimum_query; - constexpr auto block_size = device_type::block_size; + using rmq_type = gko::range_minimum_query; + constexpr auto block_size = rmq_type::block_size; using tree_index_type = std::decay_t; - 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::max(), @@ -59,9 +59,9 @@ template void compute_lookup_across_blocks( std::shared_ptr exec, const IndexType* block_min, IndexType num_blocks, - range_minimum_query_superblocks& superblocks) + device_range_minimum_query_superblocks& superblocks) { - using superblock_type = range_minimum_query_superblocks; + using superblock_type = device_range_minimum_query_superblocks; constexpr auto infinity = std::numeric_limits::max(); if (num_blocks < 2) { return; diff --git a/reference/test/components/range_minimum_query_kernels.cpp b/reference/test/components/range_minimum_query_kernels.cpp index cad389ddc20..8bbe131fdf6 100644 --- a/reference/test/components/range_minimum_query_kernels.cpp +++ b/reference/test/components/range_minimum_query_kernels.cpp @@ -21,7 +21,7 @@ class RangeMinimumQuery : public ::testing::Test { protected: using index_type = IndexType; using storage_type = std::make_unsigned_t; - using device_type = gko::device_range_minimum_query; + using device_type = gko::range_minimum_query; 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; @@ -71,7 +71,8 @@ TYPED_TEST(RangeMinimumQuery, ComputeLookupSmall) block_argmin_num_bits, num_blocks}; std::vector block_min(num_blocks); std::vector block_tree_index(num_blocks); - gko::block_range_minimum_query_lookup_table small_lut; + gko::device_block_range_minimum_query_lookup_table + small_lut; gko::kernels::reference::range_minimum_query:: compute_lookup_inside_blocks(this->ref, values.data(), size, @@ -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 rmq{ + gko::range_minimum_query rmq{ gko::array{this->ref, values.begin(), values.end()}}; for (auto first : gko::irange{size}) { diff --git a/test/components/range_minimum_query_kernels.cpp b/test/components/range_minimum_query_kernels.cpp index 561e6ac8ffc..b7cdcc6c2e7 100644 --- a/test/components/range_minimum_query_kernels.cpp +++ b/test/components/range_minimum_query_kernels.cpp @@ -25,12 +25,12 @@ class RangeMinimumQuery : public CommonTestFixture { protected: using index_type = T; using storage_type = std::make_unsigned_t; - 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::block_argmin_view_type; using superblock_view_type = - gko::range_minimum_query_superblocks; + gko::device_range_minimum_query_superblocks; constexpr static auto block_size = - gko::device_range_minimum_query::block_size; + gko::range_minimum_query::block_size; RangeMinimumQuery() : rng{19654}, sizes{0, 1, 7, 8, 9, 1023, 1024, 1025, 10000, 100000} @@ -189,7 +189,7 @@ template void run_rmq_device(std::shared_ptr exec, const gko::array& dbegins, const gko::array& dends, - const gko::device_range_minimum_query& drmq, + const gko::range_minimum_query& drmq, gko::array& doutput_min, gko::array& doutput_argmin) { @@ -222,8 +222,8 @@ TYPED_TEST(RangeMinimumQuery, QueryIsEquivalentToRef) gko::array dends{this->exec, ends}; gko::array doutput_min{this->exec, begins.get_size()}; gko::array doutput_argmin{this->exec, begins.get_size()}; - gko::device_range_minimum_query rmq{std::move(values)}; - gko::device_range_minimum_query drmq{std::move(dvalues)}; + gko::range_minimum_query rmq{std::move(values)}; + gko::range_minimum_query drmq{std::move(dvalues)}; for (const auto i : gko::irange{static_cast(begins.get_size())}) {