diff --git a/cpp/bench.cpp b/cpp/bench.cpp index 2801ccc0..dad0353f 100644 --- a/cpp/bench.cpp +++ b/cpp/bench.cpp @@ -47,6 +47,7 @@ using namespace unum::usearch; using namespace unum; +using label_t = std::int64_t; using vector_id_t = std::uint32_t; using vector_view_t = span_gt; @@ -534,24 +535,24 @@ void run_big_or_small(dataset_at& dataset, args_t const& args, index_config_t co if (args.native) { if (args.metric_cos) { std::printf("-- Metric: Angular\n"); - run_typed, std::size_t, neighbor_id_at>>(dataset, args, config, limits); + run_typed, label_t, neighbor_id_at>>(dataset, args, config, limits); } else if (args.metric_l2) { std::printf("-- Metric: Euclidean\n"); - run_typed, std::size_t, neighbor_id_at>>(dataset, args, config, limits); + run_typed, label_t, neighbor_id_at>>(dataset, args, config, limits); } else if (args.metric_haversine) { std::printf("-- Metric: Haversine\n"); - run_typed, std::size_t, neighbor_id_at>>(dataset, args, config, limits); + run_typed, label_t, neighbor_id_at>>(dataset, args, config, limits); } else { std::printf("-- Metric: Inner Product\n"); - run_typed, std::size_t, neighbor_id_at>>(dataset, args, config, limits); + run_typed, label_t, neighbor_id_at>>(dataset, args, config, limits); } } else - run_punned>(dataset, args, config, limits); + run_punned>(dataset, args, config, limits); } void report_alternative_setups() { using set_member_t = std::uint32_t; - using sets_index_t = index_gt, std::size_t, std::uint32_t>; + using sets_index_t = index_gt, label_t, std::uint32_t>; set_member_t set_a[] = {10, 12, 15}; set_member_t set_b[] = {11, 12, 15, 16}; sets_index_t index; @@ -684,7 +685,11 @@ int main(int argc, char** argv) { // std::printf("-- Expansion @ Search: %zu\n", config.expansion_search); if (args.big) +#ifdef USEARCH_64BIT_ENV run_big_or_small(dataset, args, config, limits); +#else + std::printf("Error: Don't use 40 bit identifiers in 32bit environment\n"); +#endif else run_big_or_small(dataset, args, config, limits); diff --git a/include/usearch/index.hpp b/include/usearch/index.hpp index f15712c8..24d95609 100644 --- a/include/usearch/index.hpp +++ b/include/usearch/index.hpp @@ -41,6 +41,13 @@ #define USEARCH_DEFINED_ARM #endif +// Inferring hardware bitness: 32 vs 64 +#if __WORDSIZE == 64 +#define USEARCH_64BIT_ENV +#else +#define USEARCH_32BIT_ENV +#endif + #if !defined(USEARCH_USE_OPENMP) #define USEARCH_USE_OPENMP 0 #endif @@ -169,9 +176,9 @@ inline std::size_t ceil2(std::size_t v) noexcept { v |= v >> 4; v |= v >> 8; v |= v >> 16; - // For 64 bit systems - if constexpr (sizeof(void*) == 8) - v |= v >> 32; +#ifdef USEARCH_64BIT_ENV + v |= v >> 32; +#endif v++; return v; } @@ -971,6 +978,8 @@ class sorted_buffer_gt { /** * @brief Five-byte integer type to address node clouds with over 4B entries. + * + * @note Avoid usage in 32bit environment */ class usearch_pack_m uint40_t { unsigned char octets[5]; @@ -1299,7 +1308,7 @@ struct viewed_file_t { * */ template , // - typename label_at = std::size_t, // + typename label_at = std::int64_t, // typename id_at = std::uint32_t, // typename allocator_at = std::allocator, // typename point_allocator_at = allocator_at> //