From 22f289d2cb91c60ca21066119c7b14d9fc702213 Mon Sep 17 00:00:00 2001 From: Mickael Ide Date: Mon, 26 Aug 2024 06:03:41 -0700 Subject: [PATCH 1/3] Fix device visibility of bitset_view::set --- cpp/include/raft/core/bitmap.cuh | 2 +- cpp/include/raft/core/bitset.cuh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/include/raft/core/bitmap.cuh b/cpp/include/raft/core/bitmap.cuh index cafd1977ab..39dcf36201 100644 --- a/cpp/include/raft/core/bitmap.cuh +++ b/cpp/include/raft/core/bitmap.cuh @@ -35,7 +35,7 @@ _RAFT_HOST_DEVICE inline bool bitmap_view::test(const index_t } template -_RAFT_HOST_DEVICE void bitmap_view::set(const index_t row, +_RAFT_DEVICE void bitmap_view::set(const index_t row, const index_t col, bool new_value) const { diff --git a/cpp/include/raft/core/bitset.cuh b/cpp/include/raft/core/bitset.cuh index 0cdb4c1fb6..057bdf85e6 100644 --- a/cpp/include/raft/core/bitset.cuh +++ b/cpp/include/raft/core/bitset.cuh @@ -46,7 +46,7 @@ _RAFT_HOST_DEVICE bool bitset_view::operator[](const index_t } template -_RAFT_HOST_DEVICE void bitset_view::set(const index_t sample_index, +_RAFT_DEVICE void bitset_view::set(const index_t sample_index, bool set_value) const { const index_t bit_element = sample_index / bitset_element_size; From fefe4a8b63346d17468cffc66e5eba36f77d4d6e Mon Sep 17 00:00:00 2001 From: Mickael Ide Date: Fri, 6 Sep 2024 07:34:56 -0700 Subject: [PATCH 2/3] Replace ceildiv with div_round_up --- cpp/include/raft/core/bitset.cuh | 22 +++++----------------- cpp/include/raft/core/bitset.hpp | 11 +++++++++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/cpp/include/raft/core/bitset.cuh b/cpp/include/raft/core/bitset.cuh index 057bdf85e6..b6e6128eca 100644 --- a/cpp/include/raft/core/bitset.cuh +++ b/cpp/include/raft/core/bitset.cuh @@ -47,7 +47,7 @@ _RAFT_HOST_DEVICE bool bitset_view::operator[](const index_t template _RAFT_DEVICE void bitset_view::set(const index_t sample_index, - bool set_value) const + bool set_value) const { const index_t bit_element = sample_index / bitset_element_size; const index_t bit_index = sample_index % bitset_element_size; @@ -60,18 +60,12 @@ _RAFT_DEVICE void bitset_view::set(const index_t sample_index } } -template -_RAFT_HOST_DEVICE inline index_t bitset_view::n_elements() const -{ - return raft::ceildiv(bitset_len_, bitset_element_size); -} - template bitset::bitset(const raft::resources& res, raft::device_vector_view mask_index, index_t bitset_len, bool default_value) - : bitset_{std::size_t(raft::ceildiv(bitset_len, bitset_element_size)), + : bitset_{std::size_t(raft::div_rounding_up_safe(bitset_len, bitset_element_size)), raft::resource::get_cuda_stream(res)}, bitset_len_{bitset_len} { @@ -83,26 +77,20 @@ template bitset::bitset(const raft::resources& res, index_t bitset_len, bool default_value) - : bitset_{std::size_t(raft::ceildiv(bitset_len, bitset_element_size)), + : bitset_{std::size_t(raft::div_rounding_up_safe(bitset_len, bitset_element_size)), raft::resource::get_cuda_stream(res)}, bitset_len_{bitset_len} { reset(res, default_value); } -template -index_t bitset::n_elements() const -{ - return raft::ceildiv(bitset_len_, bitset_element_size); -} - template void bitset::resize(const raft::resources& res, index_t new_bitset_len, bool default_value) { - auto old_size = raft::ceildiv(bitset_len_, bitset_element_size); - auto new_size = raft::ceildiv(new_bitset_len, bitset_element_size); + auto old_size = raft::div_rounding_up_safe(bitset_len_, bitset_element_size); + auto new_size = raft::div_rounding_up_safe(new_bitset_len, bitset_element_size); bitset_.resize(new_size); bitset_len_ = new_bitset_len; if (old_size < new_size) { diff --git a/cpp/include/raft/core/bitset.hpp b/cpp/include/raft/core/bitset.hpp index 0df12f25e6..3608ee43fa 100644 --- a/cpp/include/raft/core/bitset.hpp +++ b/cpp/include/raft/core/bitset.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace raft::core { /** @@ -89,7 +90,10 @@ struct bitset_view { /** * @brief Get the number of elements used by the bitset representation. */ - inline _RAFT_HOST_DEVICE auto n_elements() const -> index_t; + inline _RAFT_HOST_DEVICE auto n_elements() const -> index_t + { + return raft::div_rounding_up_safe(bitset_len_, bitset_element_size); + } inline auto to_mdspan() -> raft::device_vector_view { @@ -173,7 +177,10 @@ struct bitset { /** * @brief Get the number of elements used by the bitset representation. */ - inline auto n_elements() const -> index_t; + inline auto n_elements() const -> index_t + { + return raft::div_rounding_up_safe(bitset_len_, bitset_element_size); + } /** @brief Get an mdspan view of the current bitset */ inline auto to_mdspan() -> raft::device_vector_view From 7149cccb5b1ffcb8c3eb12fbde086dc4d48bb24f Mon Sep 17 00:00:00 2001 From: Mickael Ide Date: Fri, 6 Sep 2024 07:50:51 -0700 Subject: [PATCH 3/3] Fix style --- cpp/include/raft/core/bitmap.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/include/raft/core/bitmap.cuh b/cpp/include/raft/core/bitmap.cuh index 39dcf36201..024b1244a6 100644 --- a/cpp/include/raft/core/bitmap.cuh +++ b/cpp/include/raft/core/bitmap.cuh @@ -36,8 +36,8 @@ _RAFT_HOST_DEVICE inline bool bitmap_view::test(const index_t template _RAFT_DEVICE void bitmap_view::set(const index_t row, - const index_t col, - bool new_value) const + const index_t col, + bool new_value) const { set(row * cols_ + col, new_value); }