fix: resolve compiler warnings and enable -Werror across all CI platforms (#460)
This commit is contained in:
@@ -62,7 +62,7 @@ class AlignedFileReader {
|
||||
public:
|
||||
virtual IOContext &get_ctx() = 0;
|
||||
|
||||
virtual ~AlignedFileReader() {};
|
||||
virtual ~AlignedFileReader() {}
|
||||
|
||||
virtual void register_thread() = 0;
|
||||
virtual void deregister_thread() = 0;
|
||||
@@ -77,7 +77,6 @@ class AlignedFileReader {
|
||||
|
||||
class LinuxAlignedFileReader : public AlignedFileReader {
|
||||
private:
|
||||
uint64_t file_sz;
|
||||
int file_desc;
|
||||
|
||||
IOContext bad_ctx = (IOContext)-1;
|
||||
|
||||
@@ -402,8 +402,6 @@ int DiskAnnIndexer::linear_search(DiskAnnContext *ctx) {
|
||||
ailego::ElapsedTime query_timer;
|
||||
ailego::ElapsedTime cpu_timer;
|
||||
|
||||
uint32_t num_ios = 0;
|
||||
|
||||
std::vector<diskann_id_t> frontier;
|
||||
frontier.reserve(2 * beam_width_);
|
||||
|
||||
@@ -462,7 +460,6 @@ int DiskAnnIndexer::linear_search(DiskAnnContext *ctx) {
|
||||
|
||||
stats.disk_page_reads++;
|
||||
stats.io_num++;
|
||||
num_ios++;
|
||||
}
|
||||
|
||||
io_timer.reset();
|
||||
@@ -540,8 +537,6 @@ int DiskAnnIndexer::keys_search(const std::vector<uint64_t> &keys,
|
||||
ailego::ElapsedTime io_timer;
|
||||
ailego::ElapsedTime cpu_timer;
|
||||
|
||||
uint32_t num_ios = 0;
|
||||
|
||||
std::vector<diskann_id_t> frontier;
|
||||
frontier.reserve(2 * beam_width_);
|
||||
|
||||
@@ -602,7 +597,6 @@ int DiskAnnIndexer::keys_search(const std::vector<uint64_t> &keys,
|
||||
|
||||
stats.disk_page_reads++;
|
||||
stats.io_num++;
|
||||
num_ios++;
|
||||
}
|
||||
|
||||
io_timer.reset();
|
||||
@@ -675,8 +669,6 @@ int DiskAnnIndexer::get_vector(diskann_id_t id, IndexContext::Pointer &context,
|
||||
ailego::ElapsedTime io_timer;
|
||||
ailego::ElapsedTime cpu_timer;
|
||||
|
||||
uint32_t num_ios = 0;
|
||||
|
||||
std::vector<diskann_id_t> frontier;
|
||||
frontier.reserve(2 * beam_width_);
|
||||
|
||||
@@ -714,7 +706,6 @@ int DiskAnnIndexer::get_vector(diskann_id_t id, IndexContext::Pointer &context,
|
||||
|
||||
stats.disk_page_reads++;
|
||||
stats.io_num++;
|
||||
num_ios++;
|
||||
|
||||
io_timer.reset();
|
||||
|
||||
@@ -798,8 +789,6 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
candidates.insert(Neighbor(best_medoid, dist));
|
||||
visit_filter.set_visited(best_medoid);
|
||||
|
||||
uint32_t cmps = 0;
|
||||
uint32_t hops = 0;
|
||||
uint32_t num_ios = 0;
|
||||
|
||||
std::vector<diskann_id_t> frontier;
|
||||
@@ -896,10 +885,10 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
|
||||
cpu_timer.reset();
|
||||
|
||||
float distances[neighbor_num];
|
||||
std::vector<float> distances(neighbor_num);
|
||||
pq_table_->compute_dists(neighbor_num, node_neighbors, pq_chunk_num_,
|
||||
ctx->pq_table_dist_buffer(),
|
||||
ctx->pq_coord_buffer(), distances);
|
||||
ctx->pq_coord_buffer(), distances.data());
|
||||
|
||||
stats.dist_num += neighbor_num;
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
@@ -907,7 +896,6 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
for (uint64_t m = 0; m < neighbor_num; ++m) {
|
||||
diskann_id_t id = node_neighbors[m];
|
||||
visit_filter.set_visited(id);
|
||||
cmps++;
|
||||
|
||||
Neighbor nn(id, distances[m]);
|
||||
candidates.insert(nn);
|
||||
@@ -937,10 +925,10 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
reinterpret_cast<diskann_id_t *>(node_buf + 1);
|
||||
|
||||
cpu_timer.reset();
|
||||
float distances[neighbor_num];
|
||||
std::vector<float> distances(neighbor_num);
|
||||
pq_table_->compute_dists(neighbor_num, node_neighbors, pq_chunk_num_,
|
||||
ctx->pq_table_dist_buffer(),
|
||||
ctx->pq_coord_buffer(), distances);
|
||||
ctx->pq_coord_buffer(), distances.data());
|
||||
|
||||
stats.dist_num += neighbor_num;
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
@@ -949,7 +937,6 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
for (uint64_t m = 0; m < neighbor_num; ++m) {
|
||||
diskann_id_t id = node_neighbors[m];
|
||||
visit_filter.set_visited(id);
|
||||
cmps++;
|
||||
stats.dist_num++;
|
||||
|
||||
Neighbor nn(id, distances[m]);
|
||||
@@ -958,8 +945,6 @@ int DiskAnnIndexer::cached_beam_search(DiskAnnContext *ctx) {
|
||||
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
}
|
||||
|
||||
hops++;
|
||||
}
|
||||
|
||||
stats.total_us += query_timer.micro_seconds();
|
||||
@@ -1034,8 +1019,6 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
pq_table_->preprocess_pq_dist_table(ctx->query_rotated(),
|
||||
ctx->pq_table_dist_buffer());
|
||||
|
||||
uint32_t cmps = 0;
|
||||
uint32_t hops = 0;
|
||||
uint32_t num_ios = 0;
|
||||
|
||||
std::vector<diskann_id_t> frontier;
|
||||
@@ -1138,10 +1121,10 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
|
||||
cpu_timer.reset();
|
||||
|
||||
float distances[neighbor_num];
|
||||
std::vector<float> distances(neighbor_num);
|
||||
pq_table_->compute_dists(neighbor_num, node_neighbors, pq_chunk_num_,
|
||||
ctx->pq_table_dist_buffer(),
|
||||
ctx->pq_coord_buffer(), distances);
|
||||
ctx->pq_coord_buffer(), distances.data());
|
||||
|
||||
stats.dist_num += neighbor_num;
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
@@ -1149,7 +1132,6 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
for (uint64_t m = 0; m < neighbor_num; ++m) {
|
||||
diskann_id_t id = node_neighbors[m];
|
||||
visit_filter.set_visited(id);
|
||||
cmps++;
|
||||
|
||||
Neighbor nn(id, distances[m]);
|
||||
candidates.insert(nn);
|
||||
@@ -1189,12 +1171,12 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
|
||||
cpu_timer.reset();
|
||||
|
||||
float distances[neighbor_num];
|
||||
std::vector<float> distances(neighbor_num);
|
||||
diskann_id_t *node_neighbors =
|
||||
reinterpret_cast<diskann_id_t *>(node_buf + 1);
|
||||
pq_table_->compute_dists(neighbor_num, node_neighbors, pq_chunk_num_,
|
||||
ctx->pq_table_dist_buffer(),
|
||||
ctx->pq_coord_buffer(), distances);
|
||||
ctx->pq_coord_buffer(), distances.data());
|
||||
|
||||
stats.dist_num += neighbor_num;
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
@@ -1203,7 +1185,6 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
for (uint64_t m = 0; m < neighbor_num; ++m) {
|
||||
diskann_id_t id = node_neighbors[m];
|
||||
visit_filter.set_visited(id);
|
||||
cmps++;
|
||||
stats.dist_num++;
|
||||
|
||||
Neighbor nn(id, distances[m]);
|
||||
@@ -1212,8 +1193,6 @@ int DiskAnnIndexer::cached_beam_search_by_group(DiskAnnContext *ctx) {
|
||||
|
||||
stats.cpu_us += cpu_timer.micro_seconds();
|
||||
}
|
||||
|
||||
hops++;
|
||||
}
|
||||
|
||||
stats.total_us += query_timer.micro_seconds();
|
||||
|
||||
@@ -272,7 +272,7 @@ int DiskAnnStreamer::get_vector(uint64_t key, Context::Pointer &context,
|
||||
return diskann_indexer_->get_vector(key, context, vector);
|
||||
}
|
||||
|
||||
const void *DiskAnnStreamer::get_vector_by_id(uint32_t id) const {
|
||||
const void *DiskAnnStreamer::get_vector_by_id(uint32_t /*id*/) const {
|
||||
// DiskAnn vectors are stored on disk in sector format;
|
||||
// a const void* access requires sector I/O via create_context
|
||||
// Return nullptr to indicate this path is not supported.
|
||||
|
||||
@@ -181,7 +181,7 @@ int FlatStreamer<BATCH_SIZE>::flush(uint64_t checkpoint) {
|
||||
template <size_t BATCH_SIZE>
|
||||
int FlatStreamer<BATCH_SIZE>::dump(const IndexDumper::Pointer &dumper) {
|
||||
std::string searcher_name = "FlatSearcher";
|
||||
if (BATCH_SIZE == 16) {
|
||||
if constexpr (BATCH_SIZE == 16) {
|
||||
searcher_name = "FlatSearcher16";
|
||||
}
|
||||
meta_.set_searcher(searcher_name, 0U, ailego::Params());
|
||||
|
||||
@@ -105,7 +105,7 @@ static inline void Transpose(size_t align_size, const void *src, size_t m,
|
||||
template <size_t K>
|
||||
void TransposeQueries(const void *query, const IndexQueryMeta &qmeta,
|
||||
size_t query_count, std::string *out) {
|
||||
if (K <= 1) {
|
||||
if constexpr (K <= 1) {
|
||||
ailego_assert(query_count == 1);
|
||||
(void)query_count;
|
||||
out->append(reinterpret_cast<const char *>(query) + out->size(),
|
||||
|
||||
@@ -70,7 +70,7 @@ int ChunkBroker::load_storage(uint32_t &chunk_size) {
|
||||
chunk_meta_segment_->data_size());
|
||||
return IndexError_InvalidFormat;
|
||||
}
|
||||
std::memcpy(&chunk_meta_, data_block.data(), size);
|
||||
std::memcpy(static_cast<void *>(&chunk_meta_), data_block.data(), size);
|
||||
if (chunk_meta_.chunk_size != chunk_size) {
|
||||
LOG_WARN(
|
||||
"chunk_size mismatch: config=%u, index=%zu. "
|
||||
|
||||
@@ -108,10 +108,10 @@ class ChunkBroker {
|
||||
|
||||
struct HnswChunkMeta {
|
||||
HnswChunkMeta(void) {
|
||||
memset(this, 0, sizeof(HnswChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswChunkMeta));
|
||||
}
|
||||
void clear() {
|
||||
memset(this, 0, sizeof(HnswChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswChunkMeta));
|
||||
}
|
||||
|
||||
uint64_t chunk_cnts[CHUNK_TYPE_MAX];
|
||||
|
||||
@@ -205,7 +205,7 @@ int HnswContext::update_context(ContextType type, const IndexMeta &meta,
|
||||
uint32_t magic_num) {
|
||||
uint32_t doc_cnt;
|
||||
|
||||
if (ailego_unlikely(type != type_)) {
|
||||
if (ailego_unlikely(static_cast<uint32_t>(type) != type_)) {
|
||||
LOG_ERROR(
|
||||
"HnswContext doesn't support shared by different type, "
|
||||
"src=%u dst=%u",
|
||||
|
||||
@@ -77,11 +77,11 @@ struct HNSWHeader {
|
||||
}
|
||||
|
||||
HNSWHeader(const HNSWHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
}
|
||||
|
||||
HNSWHeader &operator=(const HNSWHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ struct HNSWHeader {
|
||||
|
||||
//! Clear all fields to init value
|
||||
void inline clear() {
|
||||
memset(this, 0, sizeof(HNSWHeader));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HNSWHeader));
|
||||
hnsw.entry_point = kInvalidNodeId;
|
||||
graph.size = sizeof(GraphHeader);
|
||||
hnsw.size = sizeof(HnswHeader);
|
||||
|
||||
@@ -505,7 +505,7 @@ int HnswStreamerEntity::dump(const IndexDumper::Pointer &dumper) {
|
||||
return 0U;
|
||||
};
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
return meta->level;
|
||||
return meta->bits.level;
|
||||
};
|
||||
auto ret = dump_segments(dumper, keys.data(), get_level);
|
||||
if (ailego_unlikely(ret < 0)) {
|
||||
|
||||
@@ -225,7 +225,7 @@ class HnswStreamerEntity : public HnswEntity {
|
||||
uint32_t index : 28; // index is composite type: chunk idx, and the
|
||||
// N th neighbors in chunk, they two composite
|
||||
// the 28 bits location
|
||||
};
|
||||
} bits;
|
||||
uint32_t data;
|
||||
};
|
||||
|
||||
@@ -259,6 +259,7 @@ class HnswStreamerEntity : public HnswEntity {
|
||||
std::shared_ptr<std::vector<const uint8_t *>> node_bases,
|
||||
std::shared_ptr<std::vector<const uint8_t *>> upper_bases)
|
||||
: stats_(stats),
|
||||
upper_neighbor_rw_mutex_(upper_neighbor_rw_mutex),
|
||||
chunk_size_(chunk_size),
|
||||
node_index_mask_bits_(node_index_mask_bits),
|
||||
node_cnt_per_chunk_(1UL << node_index_mask_bits_),
|
||||
@@ -268,7 +269,6 @@ class HnswStreamerEntity : public HnswEntity {
|
||||
filter_same_key_(filter_same_key),
|
||||
get_vector_enabled_(get_vector_enabled),
|
||||
use_key_info_map_(use_key_info_map),
|
||||
upper_neighbor_rw_mutex_(upper_neighbor_rw_mutex),
|
||||
upper_neighbor_index_(upper_neighbor_index),
|
||||
keys_map_lock_(keys_map_lock),
|
||||
keys_map_(keys_map),
|
||||
@@ -331,9 +331,10 @@ class HnswStreamerEntity : public HnswEntity {
|
||||
ailego_assert_abort(it != upper_neighbor_index_->end(),
|
||||
"Get upper neighbor header failed");
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
uint32_t chunk_idx = (meta->index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset = (((meta->index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
uint32_t chunk_idx = (meta->bits.index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset =
|
||||
(((meta->bits.index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
sync_chunks(ChunkBroker::CHUNK_TYPE_UPPER_NEIGHBOR, chunk_idx,
|
||||
&upper_neighbor_chunks_);
|
||||
ailego_assert_abort(chunk_idx < upper_neighbor_chunks_.size(),
|
||||
@@ -413,9 +414,9 @@ class HnswStreamerEntity : public HnswEntity {
|
||||
ailego_assert_with(chunk_index < (1U << (28 - upper_neighbor_mask_bits_)),
|
||||
"invalid chunk index");
|
||||
UpperNeighborIndexMeta meta;
|
||||
meta.level = level;
|
||||
meta.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
meta.bits.level = level;
|
||||
meta.bits.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
size_t zero_start = chunk_offset;
|
||||
chunk_offset += upper_neighbor_size_ * level;
|
||||
|
||||
@@ -821,9 +822,10 @@ class HnswMmapStreamerEntity : public HnswStreamerEntity {
|
||||
ailego_assert_abort(it != upper_neighbor_index_->end(),
|
||||
"Get upper neighbor header failed");
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
uint32_t chunk_idx = (meta->index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset = (((meta->index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
uint32_t chunk_idx = (meta->bits.index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset =
|
||||
(((meta->bits.index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
const char *base = get_upper_neighbor_chunk_base(chunk_idx);
|
||||
MmapMemoryBlock block(const_cast<char *>(base + offset));
|
||||
return TypedNeighbors(std::move(block));
|
||||
@@ -985,8 +987,8 @@ class HnswContiguousStreamerEntity : public HnswMmapStreamerEntity {
|
||||
ailego_assert_abort(it != upper_neighbor_index_->end(),
|
||||
"Get upper neighbor header failed");
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
uint32_t chunk_idx = (meta->index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t local_idx = (meta->index) & upper_neighbor_mask_;
|
||||
uint32_t chunk_idx = (meta->bits.index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t local_idx = (meta->bits.index) & upper_neighbor_mask_;
|
||||
size_t global_offset =
|
||||
upper_chunk_offsets_[chunk_idx] +
|
||||
static_cast<size_t>(local_idx + level - 1) * upper_neighbor_size_;
|
||||
|
||||
@@ -70,7 +70,7 @@ int HnswRabitqChunkBroker::load_storage(size_t chunk_size) {
|
||||
chunk_meta_segment_->data_size());
|
||||
return IndexError_InvalidFormat;
|
||||
}
|
||||
std::memcpy(&chunk_meta_, data_block.data(), size);
|
||||
std::memcpy(static_cast<void *>(&chunk_meta_), data_block.data(), size);
|
||||
if (chunk_meta_.chunk_size != chunk_size) {
|
||||
LOG_ERROR(
|
||||
"Params hnsw chunk size=%zu mismatch from previous %zu "
|
||||
|
||||
@@ -95,10 +95,10 @@ class HnswRabitqChunkBroker {
|
||||
|
||||
struct HnswChunkMeta {
|
||||
HnswChunkMeta(void) {
|
||||
memset(this, 0, sizeof(HnswChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswChunkMeta));
|
||||
}
|
||||
void clear() {
|
||||
memset(this, 0, sizeof(HnswChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswChunkMeta));
|
||||
}
|
||||
|
||||
uint64_t chunk_cnts[CHUNK_TYPE_MAX];
|
||||
|
||||
@@ -206,7 +206,7 @@ int HnswRabitqContext::update_context(ContextType type, const IndexMeta &meta,
|
||||
uint32_t magic_num) {
|
||||
uint32_t doc_cnt;
|
||||
|
||||
if (ailego_unlikely(type != type_)) {
|
||||
if (ailego_unlikely(static_cast<uint32_t>(type) != type_)) {
|
||||
LOG_ERROR(
|
||||
"HnswRabitqContext doesn't support shared by different type, "
|
||||
"src=%u dst=%u",
|
||||
|
||||
@@ -228,8 +228,7 @@ class HnswRabitqAddDistCalculator {
|
||||
const void *query_;
|
||||
uint32_t dim_;
|
||||
|
||||
uint32_t compare_cnt_; // record distance compute times
|
||||
uint32_t compare_cnt_batch_; // record batch distance compute time
|
||||
uint32_t compare_cnt_; // record distance compute times
|
||||
bool error_{false};
|
||||
|
||||
// get raw vector
|
||||
|
||||
@@ -190,8 +190,7 @@ int64_t HnswRabitqEntity::dump_vectors(
|
||||
|
||||
size_t padding_size = AlignSize(vector_dump_size) - vector_dump_size;
|
||||
|
||||
char padding[padding_size];
|
||||
memset(padding, 0, sizeof(padding));
|
||||
std::vector<char> padding(padding_size, 0);
|
||||
const void *data = nullptr;
|
||||
uint32_t crc = 0U;
|
||||
size_t vecs_size = 0UL;
|
||||
@@ -216,12 +215,12 @@ int64_t HnswRabitqEntity::dump_vectors(
|
||||
continue;
|
||||
}
|
||||
|
||||
len = dumper->write(padding, padding_size);
|
||||
len = dumper->write(padding.data(), padding_size);
|
||||
if (len != padding_size) {
|
||||
LOG_ERROR("Dump vectors failed, write=%zu expect=%zu", len, padding_size);
|
||||
return IndexError_WriteData;
|
||||
}
|
||||
crc = ailego::Crc32c::Hash(padding, padding_size, crc);
|
||||
crc = ailego::Crc32c::Hash(padding.data(), padding_size, crc);
|
||||
vecs_size += padding_size;
|
||||
}
|
||||
|
||||
@@ -242,7 +241,7 @@ int64_t HnswRabitqEntity::dump_graph_neighbors(
|
||||
graph_meta.reserve(doc_cnt());
|
||||
size_t offset = 0;
|
||||
uint32_t crc = 0;
|
||||
node_id_t mapping[l0_neighbor_cnt()];
|
||||
std::vector<node_id_t> mapping(l0_neighbor_cnt());
|
||||
|
||||
uint32_t min_neighbor_count = 10000;
|
||||
uint32_t max_neighbor_count = 0;
|
||||
@@ -271,7 +270,7 @@ int64_t HnswRabitqEntity::dump_graph_neighbors(
|
||||
for (node_id_t i = 0; i < neighbors.size(); ++i) {
|
||||
mapping[i] = neighbor_mapping[neighbors[i]];
|
||||
}
|
||||
data = mapping;
|
||||
data = mapping.data();
|
||||
}
|
||||
if (dumper->write(data, size) != size) {
|
||||
LOG_ERROR("Dump graph neighbor id=%zu failed, size %zu",
|
||||
@@ -322,7 +321,7 @@ int64_t HnswRabitqEntity::dump_upper_neighbors(
|
||||
hnsw_meta.reserve(doc_cnt());
|
||||
size_t offset = 0;
|
||||
uint32_t crc = 0;
|
||||
node_id_t buffer[upper_neighbor_cnt() + 1];
|
||||
std::vector<node_id_t> buffer(upper_neighbor_cnt() + 1);
|
||||
for (node_id_t id = 0; id < doc_cnt(); ++id) {
|
||||
node_id_t new_id = reorder_mapping.empty() ? id : reorder_mapping[id];
|
||||
auto level = get_level(new_id);
|
||||
@@ -337,7 +336,8 @@ int64_t HnswRabitqEntity::dump_upper_neighbors(
|
||||
ailego_assert_with(!!neighbors.data, "invalid neighbors");
|
||||
ailego_assert_with(neighbors.size() <= neighbor_cnt(cur_level),
|
||||
"invalid neighbors");
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
size_t buffer_bytes = buffer.size() * sizeof(node_id_t);
|
||||
memset(buffer.data(), 0, buffer_bytes);
|
||||
buffer[0] = neighbors.size();
|
||||
if (neighbor_mapping.empty()) {
|
||||
memcpy(&buffer[1], &neighbors[0], neighbors.size() * sizeof(node_id_t));
|
||||
@@ -346,13 +346,13 @@ int64_t HnswRabitqEntity::dump_upper_neighbors(
|
||||
buffer[i + 1] = neighbor_mapping[neighbors[i]];
|
||||
}
|
||||
}
|
||||
if (dumper->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
|
||||
if (dumper->write(buffer.data(), buffer_bytes) != buffer_bytes) {
|
||||
LOG_ERROR("Dump graph neighbor id=%zu failed, size %zu",
|
||||
static_cast<size_t>(id), sizeof(buffer));
|
||||
static_cast<size_t>(id), buffer_bytes);
|
||||
return IndexError_WriteData;
|
||||
}
|
||||
crc = ailego::Crc32c::Hash(buffer, sizeof(buffer), crc);
|
||||
offset += sizeof(buffer);
|
||||
crc = ailego::Crc32c::Hash(buffer.data(), buffer_bytes, crc);
|
||||
offset += buffer_bytes;
|
||||
}
|
||||
}
|
||||
size_t padding_size = 0;
|
||||
|
||||
@@ -113,11 +113,11 @@ struct HNSWHeader {
|
||||
}
|
||||
|
||||
HNSWHeader(const HNSWHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
}
|
||||
|
||||
HNSWHeader &operator=(const HNSWHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ struct HNSWHeader {
|
||||
|
||||
//! Clear all fields to init value
|
||||
void inline clear() {
|
||||
memset(this, 0, sizeof(HNSWHeader));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HNSWHeader));
|
||||
hnsw.entry_point = kInvalidNodeId;
|
||||
graph.size = sizeof(GraphHeader);
|
||||
hnsw.size = sizeof(HnswHeader);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace zvec {
|
||||
namespace core {
|
||||
|
||||
class HnswRabitqQueryEntity;
|
||||
struct HnswRabitqQueryEntity;
|
||||
|
||||
//! hnsw graph algorithm implement
|
||||
class HnswRabitqQueryAlgorithm {
|
||||
|
||||
@@ -81,8 +81,8 @@ int HnswRabitqStreamerEntity::cleanup() {
|
||||
int HnswRabitqStreamerEntity::update_neighbors(
|
||||
level_t level, node_id_t id,
|
||||
const std::vector<std::pair<node_id_t, ResultRecord>> &neighbors) {
|
||||
char buffer[neighbor_size_];
|
||||
NeighborsHeader *hd = reinterpret_cast<NeighborsHeader *>(buffer);
|
||||
std::vector<char> buffer(neighbor_size_);
|
||||
NeighborsHeader *hd = reinterpret_cast<NeighborsHeader *>(buffer.data());
|
||||
hd->neighbor_cnt = neighbors.size();
|
||||
size_t i = 0;
|
||||
for (; i < neighbors.size(); ++i) {
|
||||
@@ -434,7 +434,7 @@ int HnswRabitqStreamerEntity::dump(const IndexDumper::Pointer &dumper) {
|
||||
return 0U;
|
||||
};
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
return meta->level;
|
||||
return meta->bits.level;
|
||||
};
|
||||
auto ret = dump_segments(dumper, keys.data(), get_level);
|
||||
if (ailego_unlikely(ret < 0)) {
|
||||
|
||||
@@ -195,7 +195,7 @@ class HnswRabitqStreamerEntity : public HnswRabitqEntity {
|
||||
uint32_t index : 28; // index is composite type: chunk idx, and the
|
||||
// N th neighbors in chunk, they two composite
|
||||
// the 28 bits location
|
||||
};
|
||||
} bits;
|
||||
uint32_t data;
|
||||
};
|
||||
|
||||
@@ -294,9 +294,10 @@ class HnswRabitqStreamerEntity : public HnswRabitqEntity {
|
||||
ailego_assert_abort(it != upper_neighbor_index_->end(),
|
||||
"Get upper neighbor header failed");
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
uint32_t chunk_idx = (meta->index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset = (((meta->index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
uint32_t chunk_idx = (meta->bits.index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset =
|
||||
(((meta->bits.index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
sync_chunks(HnswRabitqChunkBroker::CHUNK_TYPE_UPPER_NEIGHBOR, chunk_idx,
|
||||
&upper_neighbor_chunks_);
|
||||
ailego_assert_abort(chunk_idx < upper_neighbor_chunks_.size(),
|
||||
@@ -378,9 +379,9 @@ class HnswRabitqStreamerEntity : public HnswRabitqEntity {
|
||||
ailego_assert_with(chunk_index < (1U << (28 - upper_neighbor_mask_bits_)),
|
||||
"invalid chunk index");
|
||||
UpperNeighborIndexMeta meta;
|
||||
meta.level = level;
|
||||
meta.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
meta.bits.level = level;
|
||||
meta.bits.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
size_t zero_start = chunk_offset;
|
||||
chunk_offset += upper_neighbor_size_ * level;
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ int RabitqReformer::load(IndexStorage::Pointer storage) {
|
||||
LOG_ERROR("Failed to read header");
|
||||
return IndexError_InvalidFormat;
|
||||
}
|
||||
memcpy(&header, block.data(), sizeof(header));
|
||||
memcpy(static_cast<void *>(&header), block.data(), sizeof(header));
|
||||
impl_->dimension = header.dim;
|
||||
impl_->padded_dim = header.padded_dim;
|
||||
impl_->ex_bits = header.ex_bits;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace zvec {
|
||||
namespace core {
|
||||
|
||||
class HnswRabitqQueryEntity;
|
||||
struct HnswRabitqQueryEntity;
|
||||
|
||||
/*! RaBitQ Reformer
|
||||
* Loads centroids and performs query transformation and vector quantization.
|
||||
|
||||
@@ -34,7 +34,7 @@ struct RabitqConverterHeader {
|
||||
uint32_t reserve[3];
|
||||
|
||||
RabitqConverterHeader() {
|
||||
memset(this, 0, sizeof(RabitqConverterHeader));
|
||||
memset(static_cast<void *>(this), 0, sizeof(RabitqConverterHeader));
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(RabitqConverterHeader) % 32 == 0,
|
||||
|
||||
@@ -71,7 +71,7 @@ int SparseChunkBroker::load_storage(size_t chunk_size) {
|
||||
chunk_meta_segment_->data_size());
|
||||
return IndexError_InvalidFormat;
|
||||
}
|
||||
std::memcpy(&chunk_meta_, data_block.data(), size);
|
||||
std::memcpy(static_cast<void *>(&chunk_meta_), data_block.data(), size);
|
||||
if (chunk_meta_.chunk_size != chunk_size) {
|
||||
LOG_ERROR(
|
||||
"Params hnsw chunk size=%zu mismatch from previous %zu "
|
||||
|
||||
@@ -97,10 +97,10 @@ class SparseChunkBroker {
|
||||
|
||||
struct HnswSparseChunkMeta {
|
||||
HnswSparseChunkMeta(void) {
|
||||
memset(this, 0, sizeof(HnswSparseChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswSparseChunkMeta));
|
||||
}
|
||||
void clear() {
|
||||
memset(this, 0, sizeof(HnswSparseChunkMeta));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HnswSparseChunkMeta));
|
||||
}
|
||||
|
||||
uint64_t chunk_cnts[CHUNK_TYPE_MAX];
|
||||
|
||||
@@ -203,7 +203,7 @@ int HnswSparseContext::update_context(ContextType type,
|
||||
uint32_t magic_num) {
|
||||
uint32_t doc_cnt;
|
||||
|
||||
if (ailego_unlikely(type != type_)) {
|
||||
if (ailego_unlikely(static_cast<uint32_t>(type) != type_)) {
|
||||
LOG_ERROR(
|
||||
"HnswSparseContext doesn't support shared by different type, "
|
||||
"src=%u dst=%u",
|
||||
|
||||
@@ -94,11 +94,11 @@ struct HNSWSparseHeader {
|
||||
}
|
||||
|
||||
HNSWSparseHeader(const HNSWSparseHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
}
|
||||
|
||||
HNSWSparseHeader &operator=(const HNSWSparseHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ struct HNSWSparseHeader {
|
||||
|
||||
//! Clear all fields to init value
|
||||
void inline clear() {
|
||||
memset(this, 0, sizeof(HNSWSparseHeader));
|
||||
memset(static_cast<void *>(this), 0, sizeof(HNSWSparseHeader));
|
||||
hnsw.entry_point = kInvalidNodeId;
|
||||
graph.size = sizeof(SparseGraphHeader);
|
||||
hnsw.size = sizeof(HnswSparseHeader);
|
||||
|
||||
@@ -538,7 +538,7 @@ int HnswSparseStreamerEntity::dump(const IndexDumper::Pointer &dumper) {
|
||||
return 0U;
|
||||
};
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
return meta->level;
|
||||
return meta->bits.level;
|
||||
};
|
||||
auto ret = dump_segments(dumper, keys.data(), get_level);
|
||||
if (ailego_unlikely(ret < 0)) {
|
||||
|
||||
@@ -207,7 +207,7 @@ class HnswSparseStreamerEntity : public HnswSparseEntity {
|
||||
uint32_t index : 28; // index is composite type: chunk idx, and the
|
||||
// N th neighbors in chunk, they two composite
|
||||
// the 28 bits location
|
||||
};
|
||||
} bits;
|
||||
uint32_t data;
|
||||
};
|
||||
|
||||
@@ -311,9 +311,10 @@ class HnswSparseStreamerEntity : public HnswSparseEntity {
|
||||
ailego_assert_abort(it != upper_neighbor_index_->end(),
|
||||
"Get upper neighbor header failed");
|
||||
auto meta = reinterpret_cast<const UpperNeighborIndexMeta *>(&it->second);
|
||||
uint32_t chunk_idx = (meta->index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset = (((meta->index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
uint32_t chunk_idx = (meta->bits.index) >> upper_neighbor_mask_bits_;
|
||||
uint32_t offset =
|
||||
(((meta->bits.index) & upper_neighbor_mask_) + level - 1) *
|
||||
upper_neighbor_size_;
|
||||
sync_chunks(SparseChunkBroker::CHUNK_TYPE_UPPER_NEIGHBOR, chunk_idx,
|
||||
&upper_neighbor_chunks_);
|
||||
ailego_assert_abort(chunk_idx < upper_neighbor_chunks_.size(),
|
||||
@@ -392,9 +393,9 @@ class HnswSparseStreamerEntity : public HnswSparseEntity {
|
||||
ailego_assert_with(chunk_index < (1U << (28 - upper_neighbor_mask_bits_)),
|
||||
"invalid chunk index");
|
||||
UpperNeighborIndexMeta meta;
|
||||
meta.level = level;
|
||||
meta.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
meta.bits.level = level;
|
||||
meta.bits.index = (chunk_index << upper_neighbor_mask_bits_) |
|
||||
(chunk_offset / upper_neighbor_size_);
|
||||
chunk_offset += upper_neighbor_size_ * level;
|
||||
if (ailego_unlikely(!upper_neighbor_index_->insert(id, meta.data))) {
|
||||
LOG_ERROR("HashMap insert value failed");
|
||||
|
||||
@@ -55,11 +55,11 @@ struct VamanaHeader {
|
||||
}
|
||||
|
||||
VamanaHeader(const VamanaHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
}
|
||||
|
||||
VamanaHeader &operator=(const VamanaHeader &header) {
|
||||
memcpy(this, &header, sizeof(header));
|
||||
memcpy(static_cast<void *>(this), &header, sizeof(header));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ struct VamanaHeader {
|
||||
}
|
||||
|
||||
void inline clear() {
|
||||
memset(this, 0, sizeof(VamanaHeader));
|
||||
memset(static_cast<void *>(this), 0, sizeof(VamanaHeader));
|
||||
graph.entry_point = kInvalidNodeId;
|
||||
graph.size = sizeof(VamanaGraphHeader);
|
||||
graph.alpha = 1.2f;
|
||||
@@ -204,7 +204,8 @@ class VamanaEntity {
|
||||
// data_type: IndexMeta::DataType value (e.g. DT_FP32=2, DT_INT8=4,
|
||||
// DT_FP16=1)
|
||||
// Returns the medoid node ID, or kInvalidNodeId if no valid data.
|
||||
virtual node_id_t calculate_medoid(uint32_t dimension, uint32_t data_type) {
|
||||
virtual node_id_t calculate_medoid(uint32_t /*dimension*/,
|
||||
uint32_t /*data_type*/) {
|
||||
return kInvalidNodeId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user