diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIDMAP.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIDMAP.cpp index d368a06ac9..303ab2d13c 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIDMAP.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIDMAP.cpp @@ -58,7 +58,7 @@ BinaryIDMAP::Query(const DatasetPtr& dataset_ptr, const Config& config) { auto ret_ds = std::make_shared(); if (index_->metric_type == faiss::METRIC_Hamming) { auto pf_dist = (float*)malloc(p_dist_size); - int32_t* pi_dist = (int32_t*)p_dist; + int32_t* pi_dist = reinterpret_cast(p_dist); for (int i = 0; i < elems; i++) { *(pf_dist + i) = (float)(*(pi_dist + i)); } diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIVF.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIVF.cpp index 33fc722d6a..33a052e588 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIVF.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexBinaryIVF.cpp @@ -64,7 +64,7 @@ BinaryIVF::Query(const DatasetPtr& dataset_ptr, const Config& config) { auto ret_ds = std::make_shared(); if (index_->metric_type == faiss::METRIC_Hamming) { auto pf_dist = (float*)malloc(p_dist_size); - int32_t* pi_dist = (int32_t*)p_dist; + int32_t* pi_dist = reinterpret_cast(p_dist); for (int i = 0; i < elems; i++) { *(pf_dist + i) = (float)(*(pi_dist + i)); } diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp index 4134cd552e..c6f8074a4a 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp @@ -114,9 +114,9 @@ NSG::Train(const DatasetPtr& dataset_ptr, const Config& config) { idmap->AddWithoutIds(dataset_ptr, config); impl::Graph knng; const float* raw_data = idmap->GetRawVectors(); - const int64_t device_id = config[knowhere::meta::DEVICEID].get(); const int64_t k = config[IndexParams::knng].get(); #ifdef MILVUS_GPU_VERSION + const int64_t device_id = config[knowhere::meta::DEVICEID].get(); if (device_id == -1) { auto preprocess_index = std::make_shared(); preprocess_index->Train(dataset_ptr, config); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/VecIndexFactory.cpp b/core/src/index/knowhere/knowhere/index/vector_index/VecIndexFactory.cpp index f90ba79c9b..05674e9c9e 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/VecIndexFactory.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/VecIndexFactory.cpp @@ -47,7 +47,9 @@ namespace knowhere { VecIndexPtr VecIndexFactory::CreateVecIndex(const IndexType& type, const IndexMode mode) { +#ifdef MILVUS_GPU_VERSION auto gpu_device = -1; // TODO: remove hardcode here, get from invoker +#endif if (type == IndexEnum::INDEX_FAISS_IDMAP) { return std::make_shared(); } else if (type == IndexEnum::INDEX_FAISS_IVFFLAT) { diff --git a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp index 5786f63afa..93a5fb62cc 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp @@ -53,7 +53,8 @@ GPUIVF::Train(const DatasetPtr& dataset_ptr, const Config& config) { void GPUIVF::Add(const DatasetPtr& dataset_ptr, const Config& config) { - if (auto spt = res_.lock()) { + auto spt = res_.lock(); + if (spt != nullptr) { ResScope rs(res_, gpu_id_); IVF::Add(dataset_ptr, config); } else { @@ -65,7 +66,8 @@ VecIndexPtr GPUIVF::CopyGpuToCpu(const Config& config) { std::lock_guard lk(mutex_); - if (auto device_idx = std::dynamic_pointer_cast(index_)) { + auto device_idx = std::dynamic_pointer_cast(index_); + if (device_idx != nullptr) { faiss::Index* device_index = index_.get(); faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu(device_index); diff --git a/core/src/index/knowhere/knowhere/index/vector_offset_index/gpu/IndexGPUIVF_NM.cpp b/core/src/index/knowhere/knowhere/index/vector_offset_index/gpu/IndexGPUIVF_NM.cpp index 82be441ceb..ade6bcf152 100644 --- a/core/src/index/knowhere/knowhere/index/vector_offset_index/gpu/IndexGPUIVF_NM.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_offset_index/gpu/IndexGPUIVF_NM.cpp @@ -54,7 +54,8 @@ GPUIVF_NM::Train(const DatasetPtr& dataset_ptr, const Config& config) { void GPUIVF_NM::Add(const DatasetPtr& dataset_ptr, const Config& config) { - if (auto spt = res_.lock()) { + auto spt = res_.lock(); + if (spt != nullptr) { ResScope rs(res_, gpu_id_); IVF::Add(dataset_ptr, config); } else { @@ -71,7 +72,8 @@ VecIndexPtr GPUIVF_NM::CopyGpuToCpu(const Config& config) { std::lock_guard lk(mutex_); - if (auto device_idx = std::dynamic_pointer_cast(index_)) { + auto device_idx = std::dynamic_pointer_cast(index_); + if (device_idx != nullptr) { faiss::Index* device_index = index_.get(); faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu_without_codes(device_index); diff --git a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp index 8c6649fdb7..c9be654fec 100644 --- a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp +++ b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp @@ -346,11 +346,11 @@ test_with_nprobes(const std::string& ann_test_name, const std::string& index_key std::unordered_map mode_str_map = { {MODE_CPU, "MODE_CPU"}, {MODE_MIX, "MODE_MIX"}, {MODE_GPU, "MODE_GPU"}}; - double copy_time = 0.0; faiss::Index *gpu_index = nullptr, *index = nullptr; if (query_mode != MODE_CPU) { faiss::gpu::GpuClonerOptions option; option.allInGpu = true; + double copy_time = 0.0; faiss::IndexComposition index_composition; index_composition.index = cpu_index;