chore: fix more warnings (#418)

This commit is contained in:
egolearner 2026-05-21 11:15:41 +08:00 committed by GitHub
parent 51c6d9e0ec
commit 9bfc4b556a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 81 additions and 59 deletions

View File

@ -625,11 +625,16 @@ function(_targets_link_dependencies _NAME)
APPEND LIBS_INCS
"$<TARGET_PROPERTY:${LIB},INTERFACE_INCLUDE_DIRECTORIES>"
)
list(
APPEND LIBS_SYSTEM_INCS
"$<TARGET_PROPERTY:${LIB},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>"
)
endif()
endforeach()
if(LIBS_DEPS)
add_dependencies(${_NAME} ${LIBS_DEPS})
target_include_directories(${_NAME} SYSTEM PRIVATE "${LIBS_SYSTEM_INCS}")
target_include_directories(${_NAME} PRIVATE "${LIBS_INCS}")
endif()
endfunction()

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include <ailego/internal/cpu_features.h>
#include <zvec/ailego/internal/platform.h>
#include <zvec/ailego/utility/float_helper.h>
@ -428,8 +429,9 @@ static inline float float32(uint16_t val) {
uint16_t hval = static_cast<uint16_t>(val >> 10);
uint32_t bits =
mantissa_table[offset_table[hval] + (val & 0x3FF)] + exponent_table[hval];
float *p = reinterpret_cast<float *>(&bits);
return (*p);
float result;
std::memcpy(&result, &bits, sizeof(result));
return result;
}
// Refer: https://github.com/Maratyszcza/FP16/blob/master/third-party/half.hpp

View File

@ -158,10 +158,10 @@ class FlatSparseStreamer : public IndexStreamer {
enum State { STATE_INIT = 0, STATE_INITED = 1, STATE_OPENED = 2 };
IndexMeta meta_{};
Stats stats_{};
FlatSparseStreamerEntity entity_;
uint32_t magic_{0U};
Stats stats_{};
State state_{STATE_INIT};
//! avoid add vector while dumping index

View File

@ -102,7 +102,7 @@ int HnswContext::update(const ailego::Params &params) {
}
if (params.has(p)) {
bool bf_enabled;
bool bf_enabled = false;
params.get(p, &bf_enabled);
if (bf_enabled ^ (filter_mode_ == VisitFilter::BloomFilter)) {
need_update = true;

View File

@ -103,7 +103,7 @@ int HnswRabitqContext::update(const ailego::Params &params) {
}
if (params.has(p)) {
bool bf_enabled;
bool bf_enabled = false;
params.get(p, &bf_enabled);
if (bf_enabled ^ (filter_mode_ == VisitFilter::BloomFilter)) {
need_update = true;

View File

@ -196,6 +196,7 @@ class HnswRabitqStreamer : public IndexStreamer {
}
};
Stats stats_{};
HnswRabitqStreamerEntity entity_;
HnswRabitqAlgorithm::UPointer alg_;
IndexMeta meta_{};
@ -211,8 +212,6 @@ class HnswRabitqStreamer : public IndexStreamer {
HnswRabitqQueryAlgorithm::UPointer query_alg_; // query algorithm
// provider_ provides raw vector, which is used to build graph
IndexProvider::Pointer provider_{};
Stats stats_{};
std::mutex mutex_{};
size_t max_index_size_{0UL};

View File

@ -98,7 +98,7 @@ int HnswSparseContext::update(const ailego::Params &params) {
}
if (params.has(p)) {
bool bf_enabled;
bool bf_enabled = false;
params.get(p, &bf_enabled);
if (bf_enabled ^ (filter_mode_ == VisitFilter::BloomFilter)) {
need_update = true;

View File

@ -176,6 +176,7 @@ class HnswSparseStreamer : public IndexStreamer {
}
};
Stats stats_{};
HnswSparseStreamerEntity entity_;
HnswSparseAlgorithm::UPointer alg_;
IndexMeta meta_{};
@ -183,7 +184,6 @@ class HnswSparseStreamer : public IndexStreamer {
IndexMetric::MatrixSparseDistance add_distance_{};
IndexMetric::MatrixSparseDistance search_distance_{};
Stats stats_{};
std::mutex mutex_{};
size_t max_index_size_{0UL};

View File

@ -218,19 +218,20 @@ class VamanaEntity {
std::vector<IndexStorage::MemoryBlock> &vec_blocks) const = 0;
virtual const Neighbors get_neighbors(node_id_t id) const = 0;
virtual int add_vector(key_t key, const void *vec, node_id_t *id) {
virtual int add_vector(key_t /*key*/, const void * /*vec*/,
node_id_t * /*id*/) {
return IndexError_NotImplemented;
}
virtual int add_vector_with_id(node_id_t id, const void *vec) {
virtual int add_vector_with_id(node_id_t /*id*/, const void * /*vec*/) {
return IndexError_NotImplemented;
}
virtual int update_neighbors(
node_id_t id,
const std::vector<std::pair<node_id_t, dist_t>> &neighbors) {
node_id_t /*id*/,
const std::vector<std::pair<node_id_t, dist_t>> & /*neighbors*/) {
return IndexError_NotImplemented;
}
virtual void add_neighbor(node_id_t id, uint32_t size,
node_id_t neighbor_id) {}
virtual void add_neighbor(node_id_t /*id*/, uint32_t /*size*/,
node_id_t /*neighbor_id*/) {}
// --- Neighbor distance storage (CSR-like, lazy-loaded) ---
// Each node has max_degree dist_t slots, the i-th slot stores the distance
@ -250,19 +251,20 @@ class VamanaEntity {
// Get pointer to the distance array for node `id`.
// Returns nullptr if dist storage is not loaded.
virtual const dist_t *get_neighbor_dists(node_id_t id) const {
virtual const dist_t *get_neighbor_dists(node_id_t /*id*/) const {
return nullptr;
}
// Update all neighbor distances for node `id` from a prune result.
virtual void update_neighbor_dists(
node_id_t id,
const std::vector<std::pair<node_id_t, dist_t>> &neighbors) {}
node_id_t /*id*/,
const std::vector<std::pair<node_id_t, dist_t>> & /*neighbors*/) {}
// Set the distance for the `idx`-th neighbor of node `id`.
virtual void set_neighbor_dist(node_id_t id, uint32_t idx, dist_t dist) {}
virtual void set_neighbor_dist(node_id_t /*id*/, uint32_t /*idx*/,
dist_t /*dist*/) {}
virtual int dump(const IndexDumper::Pointer &dumper) {
virtual int dump(const IndexDumper::Pointer & /*dumper*/) {
return IndexError_NotImplemented;
}

View File

@ -173,7 +173,6 @@ class VamanaStreamer : public IndexStreamer {
size_t bruteforce_threshold_{VamanaEntity::kDefaultBruteForceThreshold};
size_t max_scan_limit_{VamanaEntity::kDefaultMaxScanLimit};
size_t min_scan_limit_{VamanaEntity::kDefaultMinScanLimit};
float bf_negative_prob_{VamanaEntity::kDefaultBFNegativeProbability};
float max_scan_ratio_{VamanaEntity::kDefaultScanRatio};
uint32_t magic_{0U};

View File

@ -175,8 +175,8 @@ class VamanaStreamerEntity : public VamanaEntity {
use_key_info_map_(use_key_info_map),
keys_map_lock_(keys_map_lock),
keys_map_(keys_map),
node_chunks_(std::move(node_chunks)),
broker_(broker) {
broker_(broker),
node_chunks_(std::move(node_chunks)) {
*mutable_header() = hd;
neighbor_size_ = neighbors_size();
}

View File

@ -135,8 +135,9 @@ int IndexMapping::create(const std::string &path, size_t seg_meta_capacity) {
int IndexMapping::init_meta_section() {
if (current_header_start_offset_ % ailego::MemoryHelper::PageSize() != 0) {
LOG_ERROR("File offset %llu is not a multiple of the page size: %zu",
current_header_start_offset_, ailego::MemoryHelper::PageSize());
LOG_ERROR("File offset %zu is not a multiple of the page size: %zu",
(size_t)current_header_start_offset_,
ailego::MemoryHelper::PageSize());
return IndexError_InvalidValue;
}
@ -261,7 +262,6 @@ void IndexMapping::close(void) {
void IndexMapping::refresh(uint64_t check_point) {
// support add_with_id
for (auto item : header_addr_map_) {
auto header_start_offset = item.first;
auto header = item.second;
auto footer = reinterpret_cast<IndexFormat::MetaFooter *>(
reinterpret_cast<uint8_t *>(header) + header->meta_footer_offset);
@ -461,8 +461,8 @@ int IndexMapping::flush(void) {
auto header = item.second;
if (file_.write(header_start_offset, header, header->content_offset) !=
header->content_offset) {
LOG_ERROR("Failed to write segment, size %llu, %s",
header->content_offset,
LOG_ERROR("Failed to write segment, size %zu, %s",
(size_t)header->content_offset,
ailego::FileHelper::GetLastErrorString().c_str());
return IndexError_WriteData;
}

View File

@ -27,6 +27,7 @@ namespace zvec::core_interface {
int HNSWRabitqIndex::CreateAndInitStreamer(const BaseIndexParam &param) {
#if !RABITQ_SUPPORTED
(void)param;
LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)");
return core::IndexError_Unsupported;
#else
@ -87,6 +88,8 @@ int HNSWRabitqIndex::_prepare_for_search(
const BaseIndexQueryParam::Pointer &search_param,
core::IndexContext::Pointer &context) {
#if !RABITQ_SUPPORTED
(void)search_param;
(void)context;
LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)");
return core::IndexError_Unsupported;
#else
@ -125,6 +128,7 @@ int HNSWRabitqIndex::_prepare_for_search(
int HNSWRabitqIndex::_get_coarse_search_topk(
const BaseIndexQueryParam::Pointer &search_param) {
#if !RABITQ_SUPPORTED
(void)search_param;
LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)");
return -1;
#else

View File

@ -349,9 +349,6 @@ void MixedStreamerReducer::add_vec(int *result) {
void MixedStreamerReducer::add_vec_with_builder(int *result) {
ailego::ElapsedTime timer;
auto target_streamer_query_meta = IndexQueryMeta{
IndexMeta::MetaType::MT_DENSE, target_streamer_->meta().data_type(),
target_streamer_->meta().dimension()};
AILEGO_DEFER([&]() {
// make producer quit

View File

@ -532,7 +532,7 @@ class MipsConverter : public IndexConverter {
switch (holder->data_type()) {
case IndexMeta::DataType::DT_FP16:
for (; iter->is_valid(); iter->next()) {
float score;
float score = 0.0f;
ailego::Norm2Matrix<ailego::Float16, 1>::Compute(
reinterpret_cast<const ailego::Float16 *>(iter->data()), dim,
&score);
@ -549,7 +549,7 @@ class MipsConverter : public IndexConverter {
case IndexMeta::DataType::DT_FP32:
for (; iter->is_valid(); iter->next()) {
float score;
float score = 0.0f;
ailego::Norm2Matrix<float, 1>::Compute(
reinterpret_cast<const float *>(iter->data()), dim, &score);

View File

@ -111,7 +111,7 @@ class MipsReformer : public IndexReformer {
out->resize((qmeta.dimension() + m_value_) * sizeof(ailego::Float16));
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Norm2Matrix<float, 1>::Compute(
reinterpret_cast<const float *>(query), qmeta.dimension(), &norm);
@ -137,7 +137,7 @@ class MipsReformer : public IndexReformer {
out->resize((qmeta.dimension() + m_value_) * sizeof(float));
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Normalizer<float>::L2(reinterpret_cast<float *>(&(*out)[0]),
qmeta.dimension(), &norm);
}
@ -155,7 +155,7 @@ class MipsReformer : public IndexReformer {
out->resize((qmeta.dimension() + m_value_) * sizeof(ailego::Float16));
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Normalizer<ailego::Float16>::L2(
reinterpret_cast<ailego::Float16 *>(&(*out)[0]), qmeta.dimension(),
&norm);
@ -193,7 +193,7 @@ class MipsReformer : public IndexReformer {
reinterpret_cast<const float *>(query) + i * qmeta.dimension();
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Norm2Matrix<float, 1>::Compute(sub_query, qmeta.dimension(),
&norm);
ailego::FloatHelper::ToFP16(
@ -222,7 +222,7 @@ class MipsReformer : public IndexReformer {
out->resize(offset + (qmeta.dimension() + m_value_) * sizeof(float));
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Normalizer<float>::L2(
reinterpret_cast<float *>(&(*out)[offset]), qmeta.dimension(),
&norm);
@ -250,7 +250,7 @@ class MipsReformer : public IndexReformer {
(qmeta.dimension() + m_value_) * sizeof(ailego::Float16));
if (normalize_) {
float norm;
float norm = 0.0f;
ailego::Normalizer<ailego::Float16>::L2(
reinterpret_cast<ailego::Float16 *>(&(*out)[offset]),
qmeta.dimension(), &norm);

View File

@ -179,7 +179,7 @@ class BufferStorage : public IndexStorage {
}
//! Initialize storage
int init(const ailego::Params &params) override {
int init(const ailego::Params & /*params*/) override {
return 0;
}
@ -204,9 +204,9 @@ class BufferStorage : public IndexStorage {
return ret;
}
LOG_INFO(
"BufferStorage opened: file=%s, max_segment_size=%lu, "
"BufferStorage opened: file=%s, max_segment_size=%zu, "
"segment_count=%zu",
file_name_.c_str(), max_segment_size_, segments_.size());
file_name_.c_str(), (size_t)max_segment_size_, segments_.size());
return 0;
}
@ -515,7 +515,6 @@ class BufferStorage : public IndexStorage {
ailego::VecBufferPool::Pointer buffer_pool_{nullptr};
ailego::VecBufferPoolHandle::Pointer buffer_pool_handle_{nullptr};
uint64_t current_header_start_offset_{0u};
uint64_t buffer_size_{2lu * 1024 * 1024 * 1024}; // 2G
};
INDEX_FACTORY_REGISTER_STORAGE(BufferStorage);

View File

@ -189,7 +189,6 @@ TablePtr BufferPoolForwardStore::fetch(const std::vector<std::string> &columns,
std::vector<std::vector<std::pair<int, std::shared_ptr<arrow::Scalar>>>>
sorted_scalars(col_indices.size());
auto &buf_mgr = ailego::BufferManager::Instance();
for (const auto &[rg_id, pairs] : rg_to_local) {
for (size_t i = 0; i < col_indices.size(); ++i) {
int col_idx = col_indices[i];
@ -317,7 +316,6 @@ ExecBatchPtr BufferPoolForwardStore::fetch(
int64_t offset = GetRowGroupOffset(rg_id);
std::vector<arrow::Datum> scalars;
auto &buf_mgr = ailego::BufferManager::Instance();
for (size_t i = 0; i < col_indices.size(); ++i) {
int col_idx = col_indices[i];
auto buffer_id = ailego::ParquetBufferID(file_path_, col_idx, rg_id);

View File

@ -127,7 +127,6 @@ class ParquetRecordBatchReader : public arrow::RecordBatchReader {
std::vector<std::shared_ptr<arrow::Array>> chunks(col_indices_.size());
if (with_cache_) {
auto &buf_mgr = ailego::BufferManager::Instance();
for (size_t col_idx = 0; col_idx < col_indices_.size(); ++col_idx) {
auto buffer_id = ailego::ParquetBufferID(file_path_, col_idx, rg_id);
auto buffer_handle =

View File

@ -77,7 +77,6 @@ class FieldSchema {
}
FieldSchema(FieldSchema &&) = default;
FieldSchema &operator=(FieldSchema &&) = default;
;
~FieldSchema() = default;
public:
@ -304,6 +303,18 @@ class CollectionSchema {
max_doc_count_per_segment_ = other.max_doc_count_per_segment_;
}
CollectionSchema &operator=(const CollectionSchema &other) {
if (this == &other) {
return *this;
}
name_ = other.name_;
fields_.clear();
fields_map_.clear();
copy_fields(other.fields_);
max_doc_count_per_segment_ = other.max_doc_count_per_segment_;
return *this;
}
public:
std::string to_string() const;

View File

@ -30,7 +30,7 @@
#ifdef _MSC_VER
#define TURBO_ALWAYS_INLINE __forceinline
#else
#define TURBO_ALWAYS_INLINE __attribute__((always_inline))
#define TURBO_ALWAYS_INLINE inline __attribute__((always_inline))
#endif
namespace zvec::turbo::avx512_vnni::internal {

View File

@ -97,7 +97,7 @@ void cosine_int8_batch_distance(const void *const *vectors, const void *query,
float qb = q_tail[1];
float qs = q_tail[2];
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
const float *m_tail = reinterpret_cast<const float *>(
reinterpret_cast<const int8_t *>(vectors[i]) + original_dim);
float ma = m_tail[0];

View File

@ -27,13 +27,15 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-Wno-unused-function
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(libprotobuf PRIVATE
-Wno-deprecated-declarations
target_compile_options(libprotobuf PRIVATE
-Wno-deprecated-declarations
-Wno-unused-function
-Wno-maybe-uninitialized
-Wno-sign-compare
-Wno-return-type
-Wno-stringop-overflow
-Wno-stringop-overread
-Wno-array-bounds
)
target_compile_options(libprotoc PRIVATE
-Wno-unused-private-field

View File

@ -166,6 +166,11 @@ int setup_hnsw_rabitq_streamer(const IndexStreamer::Pointer &streamer,
hnsw_rabitq_streamer->set_provider(provider);
return 0;
#else
(void)streamer;
(void)meta;
(void)config_root;
(void)converter_name;
(void)build_holder;
cerr << "HNSW RaBitQ is not supported on this platform" << endl;
return -1;
#endif
@ -311,20 +316,20 @@ int do_build_sparse_by_streamer(IndexStreamer::Pointer &streamer,
add_to_streamer_sparse = [&](uint64_t pkey, const uint32_t sparse_count,
const uint32_t *sparse_indices,
const void *sparse_query,
const IndexQueryMeta &qmeta,
const IndexQueryMeta &query_meta,
IndexContext::Pointer &context) -> int {
return streamer->add_impl(pkey, sparse_count, sparse_indices, sparse_query,
qmeta, context);
query_meta, context);
};
if (g_disable_id_map) {
add_to_streamer_sparse = [&](uint64_t pkey, const uint32_t sparse_count,
const uint32_t *sparse_indices,
const void *sparse_query,
const IndexQueryMeta &qmeta,
const IndexQueryMeta &query_meta,
IndexContext::Pointer &context) -> int {
return streamer->add_with_id_impl(static_cast<uint32_t>(pkey),
sparse_count, sparse_indices,
sparse_query, qmeta, context);
sparse_query, query_meta, context);
};
}
@ -490,16 +495,16 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
std::function<int(uint64_t, const void *, const IndexQueryMeta &,
IndexContext::Pointer &)>
add_to_streamer = [&](uint64_t pkey, const void *query,
const IndexQueryMeta &qmeta,
const IndexQueryMeta &query_meta,
IndexContext::Pointer &context) -> int {
return streamer->add_impl(pkey, query, qmeta, context);
return streamer->add_impl(pkey, query, query_meta, context);
};
if (g_disable_id_map) {
add_to_streamer = [&](uint64_t pkey, const void *query,
const IndexQueryMeta &qmeta,
const IndexQueryMeta &query_meta,
IndexStreamer::Context::Pointer &context) -> int {
return streamer->add_with_id_impl(static_cast<uint32_t>(pkey), query,
qmeta, context);
query_meta, context);
};
}