1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Wed, 9 Feb 2022 01:28:47 +0100
Subject: Fix implementation for 32 bit size_t
---
faiss/index_factory.cpp | 2 +-
faiss/invlists/DirectMap.cpp | 2 +-
faiss/invlists/OnDiskInvertedLists.cpp | 7 ++++---
faiss/utils/utils.cpp | 2 +-
4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/faiss/index_factory.cpp b/faiss/index_factory.cpp
index 535d239..44c5bb3 100644
--- a/faiss/index_factory.cpp
+++ b/faiss/index_factory.cpp
@@ -730,7 +730,7 @@ std::unique_ptr<Index> index_factory_sub(
}
if (verbose) {
- printf("after () normalization: %s %ld parenthesis indexes d=%d\n",
+ printf("after () normalization: %s %zu parenthesis indexes d=%d\n",
description.c_str(),
parenthesis_indexes.size(),
d);
diff --git a/faiss/invlists/DirectMap.cpp b/faiss/invlists/DirectMap.cpp
index 6cb5202..1a5c3a6 100644
--- a/faiss/invlists/DirectMap.cpp
+++ b/faiss/invlists/DirectMap.cpp
@@ -199,7 +199,7 @@ size_t DirectMap::remove_ids(const IDSelector& sel, InvertedLists* invlists) {
last_id,
ScopedCodes(invlists, list_no, last).get());
// update hash entry for last element
- hashtable[last_id] = list_no << 32 | offset;
+ hashtable[last_id] = idx_t(list_no) << 32 | idx_t(offset);
}
invlists->resize(list_no, last);
nremove++;
diff --git a/faiss/invlists/OnDiskInvertedLists.cpp b/faiss/invlists/OnDiskInvertedLists.cpp
index 5027c0e..8caded3 100644
--- a/faiss/invlists/OnDiskInvertedLists.cpp
+++ b/faiss/invlists/OnDiskInvertedLists.cpp
@@ -11,6 +11,7 @@
#include <pthread.h>
+#include <limits>
#include <unordered_set>
#include <sys/mman.h>
@@ -325,7 +326,7 @@ void OnDiskInvertedLists::update_totsize(size_t new_size) {
FAISS_THROW_IF_NOT_FMT(
err == 0,
- "truncate %s to %ld: %s",
+ "truncate %s to %zu: %s",
filename.c_str(),
totsize,
strerror(errno));
@@ -524,7 +525,7 @@ void OnDiskInvertedLists::free_slot(size_t offset, size_t capacity) {
it++;
}
- size_t inf = 1UL << 60;
+ size_t inf = (std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> 1)) >> 1;
size_t end_prev = inf;
if (it != slots.begin()) {
@@ -533,7 +534,7 @@ void OnDiskInvertedLists::free_slot(size_t offset, size_t capacity) {
end_prev = prev->offset + prev->capacity;
}
- size_t begin_next = 1L << 60;
+ size_t begin_next = inf;
if (it != slots.end()) {
begin_next = it->offset;
}
diff --git a/faiss/utils/utils.cpp b/faiss/utils/utils.cpp
index 013bf38..175a537 100644
--- a/faiss/utils/utils.cpp
+++ b/faiss/utils/utils.cpp
@@ -160,7 +160,7 @@ size_t get_mem_usage_kb() {
char buf[256];
if (!fgets(buf, 256, f))
break;
- if (sscanf(buf, "VmRSS: %ld kB", &sz) == 1)
+ if (sscanf(buf, "VmRSS: %zu kB", &sz) == 1)
break;
}
fclose(f);
|