Skip to content

Commit

Permalink
reduce constexpr complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jan 13, 2025
1 parent 2644869 commit cfd773a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions common/unified/components/range_minimum_query_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ void compute_lookup_small(std::shared_ptr<const DefaultExecutor> exec,
1 << (std::decay_t<decltype(block_argmin)>::bits_per_word_log2 -
ceil_log2_constexpr(ceil_log2_constexpr(small_block_size)));
const device_lut_type lut{exec};
constexpr auto infinity = std::numeric_limits<IndexType>::max();
run_kernel(
exec,
[] GKO_KERNEL(auto collated_block_idx, auto values, auto block_argmin,
auto block_min, auto block_type, auto lut, auto size) {
constexpr auto infinity = std::numeric_limits<IndexType>::max();
const auto num_blocks = ceildiv(size, small_block_size);
for (auto block_idx = collated_block_idx * collation_width;
block_idx <
Expand Down Expand Up @@ -87,12 +87,12 @@ void compute_lookup_large(
// we need to collate all writes that target the same memory word in a
// single thread
constexpr auto level0_collation_width = sizeof(word_type) * CHAR_BIT;
constexpr auto infinity = std::numeric_limits<IndexType>::max();
// initialize the first level of blocks
run_kernel(
exec,
[] GKO_KERNEL(auto collated_i, auto block_min, auto superblocks,
auto num_blocks) {
constexpr auto infinity = std::numeric_limits<IndexType>::max();
for (auto i = collated_i * level0_collation_width;
i < std::min<int64>((collated_i + 1) * level0_collation_width,
num_blocks);
Expand Down
4 changes: 1 addition & 3 deletions core/components/range_minimum_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ struct cartesian_tree {
}
return all_representatives[num_nodes];
}

constexpr static auto representatives = compute_tree_representatives();
};


Expand All @@ -141,7 +139,7 @@ class block_range_minimum_query_lookup_table {

constexpr block_range_minimum_query_lookup_table() : lookup_table{}
{
const auto& representatives = tree::representatives;
const auto& representatives = tree::compute_tree_representatives();
for (int tree = 0; tree < num_trees; tree++) {
const auto& rep = representatives[tree];
for (int first = 0; first < block_size; first++) {
Expand Down
8 changes: 4 additions & 4 deletions core/test/components/range_minimum_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(RangeMinimumQuery, RepresentativesAreExhaustive)
using tree = gko::detail::cartesian_tree<size>;
int values[size]{};
std::iota(values, values + size, 0);
constexpr auto reps = tree::representatives;
const auto reps = tree::compute_tree_representatives();
do {
const auto tree_number = tree::compute_tree_index(values);
const auto rep_tree_number =
Expand All @@ -34,7 +34,7 @@ TEST(RangeMinimumQuery, RepresentativesLargeAreExhaustive)
using tree = gko::detail::cartesian_tree<size>;
int values[size]{};
std::iota(values, values + size, 0);
constexpr auto reps = tree::representatives;
const auto reps = tree::compute_tree_representatives();
do {
const auto tree_number = tree::compute_tree_index(values);
const auto rep_tree_number =
Expand All @@ -49,8 +49,8 @@ TEST(RangeMinimumQuery, LookupRepresentatives)
{
constexpr auto size = 8;
using tree = gko::detail::cartesian_tree<size>;
/*constexpr*/ gko::block_range_minimum_query_lookup_table<size> table;
auto reps = tree::compute_tree_representatives();
gko::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);
for (const auto first : gko::irange{size}) {
Expand Down

0 comments on commit cfd773a

Please sign in to comment.