Skip to content

Commit

Permalink
Improve: Caching hardware SIMD capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Oct 24, 2023
1 parent eccaad8 commit 554346a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ class aligned_allocator_gt {
using size_type = std::size_t;
using pointer = element_at*;
using const_pointer = element_at const*;
template <typename other_element_at> struct rebind { using other = aligned_allocator_gt<other_element_at>; };
template <typename other_element_at> struct rebind {
using other = aligned_allocator_gt<other_element_at>;
};

constexpr std::size_t alignment() const { return alignment_ak; }

Expand Down Expand Up @@ -1356,8 +1358,8 @@ class metric_punned_t {
}

private:
bool configure_with_simsimd() noexcept {
#if USEARCH_USE_SIMSIMD
bool configure_with_simsimd(simsimd_capability_t simd_caps) noexcept {
simsimd_metric_kind_t kind = simsimd_metric_unknown_k;
simsimd_datatype_t datatype = simsimd_datatype_unknown_k;
simsimd_capability_t allowed = simsimd_cap_any_k;
Expand All @@ -1379,18 +1381,21 @@ class metric_punned_t {
}
simsimd_metric_punned_t simd_metric = NULL;
simsimd_capability_t simd_kind = simsimd_cap_any_k;
simsimd_capability_t simd_caps = simsimd_capabilities();
simsimd_find_metric_punned(kind, datatype, simd_caps, allowed, &simd_metric, &simd_kind);
if (simd_metric == nullptr)
return false;

raw_ptr_ = (punned_ptr_t)simd_metric;
isa_kind_ = simd_kind;
return true;
}
bool configure_with_simsimd() noexcept {
static simsimd_capability_t static_capabilities = simsimd_capabilities();
return configure_with_simsimd(static_capabilities);
}
#else
return false;
bool configure_with_simsimd() noexcept { return false; }
#endif
}

void configure_with_auto_vectorized() noexcept {
switch (metric_kind_) {
Expand Down

0 comments on commit 554346a

Please sign in to comment.