Skip to content

Commit 7b7cbd5

Browse files
authored
Merge pull request #306 from eseiler/fix/avx512
fix(avx512): assert in snippet
2 parents ad0c9cf + cba7391 commit 7b7cbd5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

include/hibf/misc/counting_vector.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ class counting_vector : public std::vector<value_t, seqan::hibf::contrib::aligne
228228
sub
229229
};
230230

231+
template <size_t multiple>
232+
inline constexpr size_t next_multiple_of(size_t const value) noexcept
233+
{
234+
if constexpr (multiple == 8u)
235+
return ((value + 7u) >> 3) << 3;
236+
else if constexpr (multiple == 16u)
237+
return ((value + 15u) >> 4) << 4;
238+
else if constexpr (multiple == 32u)
239+
return ((value + 31u) >> 5) << 5;
240+
else if constexpr (multiple == 64u)
241+
return ((value + 63u) >> 6) << 6;
242+
else
243+
static_assert("multiple must be one of 8, 16, 32, 64.");
244+
}
245+
231246
//!\brief Bin-wise adds or subtracts the bits of a seqan::hibf::bit_vector.
232247
template <operation op>
233248
inline void impl(bit_vector const & bit_vector)
@@ -244,7 +259,7 @@ class counting_vector : public std::vector<value_t, seqan::hibf::contrib::aligne
244259
bits_type const * bit_vector_ptr = reinterpret_cast<bits_type const *>(bit_vector.data());
245260
value_t * counting_vector_ptr = base_t::data();
246261

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

test/snippet/ibf/counting_vector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ int main()
1717
ibf.emplace(712, seqan::hibf::bin_index{3u});
1818
ibf.emplace(237, seqan::hibf::bin_index{9u});
1919

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

2330
auto agent = ibf.containment_agent();
2431

0 commit comments

Comments
 (0)