Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion include/hibf/misc/counting_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ class counting_vector : public std::vector<value_t, seqan::hibf::contrib::aligne
sub
};

template <size_t multiple>
inline constexpr size_t next_multiple_of(size_t const value) noexcept
{
if constexpr (multiple == 8u)
return ((value + 7u) >> 3) << 3;
else if constexpr (multiple == 16u)
return ((value + 15u) >> 4) << 4;
else if constexpr (multiple == 32u)
return ((value + 31u) >> 5) << 5;
else if constexpr (multiple == 64u)
return ((value + 63u) >> 6) << 6;
else
static_assert("multiple must be one of 8, 16, 32, 64.");
}

//!\brief Bin-wise adds or subtracts the bits of a seqan::hibf::bit_vector.
template <operation op>
inline void impl(bit_vector const & bit_vector)
Expand All @@ -244,7 +259,7 @@ class counting_vector : public std::vector<value_t, seqan::hibf::contrib::aligne
bits_type const * bit_vector_ptr = reinterpret_cast<bits_type const *>(bit_vector.data());
value_t * counting_vector_ptr = base_t::data();

size_t const bits = next_multiple_of_64(bit_vector.size());
size_t const bits = next_multiple_of<simd::bits_per_iterations>(bit_vector.size());
assert(bits <= this->capacity()); // Not enough memory reserved for AVX512 chunk access.
size_t const iterations = bits / simd::bits_per_iterations;

Expand Down
7 changes: 7 additions & 0 deletions test/snippet/ibf/counting_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ int main()
ibf.emplace(712, seqan::hibf::bin_index{3u});
ibf.emplace(237, seqan::hibf::bin_index{9u});

#if !HIBF_HAS_AVX512
// The counting_vector must be at least as big as the number of bins.
seqan::hibf::counting_vector<uint16_t> counts(12, 0);
#else
// With AVX512:
// 512 (AVX) / 16 (value type of counting_vector) = 32 per iteration
// Next multiple of 32 for 12: 32
seqan::hibf::counting_vector<uint16_t> counts(32, 0);
#endif

auto agent = ibf.containment_agent();

Expand Down