diff --git a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp index a62ac3ed6b..5434bb071b 100644 --- a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp +++ b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp @@ -38,14 +38,12 @@ GPUIVF::Train(const DatasetPtr& dataset_ptr, const Config& config) { if (gpu_res != nullptr) { ResScope rs(gpu_res, gpu_id_, true); faiss::gpu::GpuIndexIVFFlatConfig idx_config; - idx_config.device = gpu_id_; + idx_config.device = static_cast(gpu_id_); int32_t nlist = config[IndexParams::nlist]; faiss::MetricType metric_type = GetMetricType(config[Metric::TYPE].get()); - auto device_index = - new faiss::gpu::GpuIndexIVFFlat(gpu_res->faiss_res.get(), dim, nlist, metric_type, idx_config); - device_index->train(rows, reinterpret_cast(p_data)); - - index_.reset(device_index); + index_ = std::make_shared(gpu_res->faiss_res.get(), dim, nlist, metric_type, + idx_config); + index_->train(rows, reinterpret_cast(p_data)); res_ = gpu_res; } else { KNOWHERE_THROW_MSG("Build IVF can't get gpu resource"); diff --git a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFPQ.cpp b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFPQ.cpp index 449ff7955d..dead07cf02 100644 --- a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFPQ.cpp +++ b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFPQ.cpp @@ -31,11 +31,15 @@ GPUIVFPQ::Train(const DatasetPtr& dataset_ptr, const Config& config) { auto gpu_res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_); if (gpu_res != nullptr) { ResScope rs(gpu_res, gpu_id_, true); - auto device_index = new faiss::gpu::GpuIndexIVFPQ( - gpu_res->faiss_res.get(), dim, config[IndexParams::nlist].get(), config[IndexParams::m], - config[IndexParams::nbits], GetMetricType(config[Metric::TYPE].get())); + faiss::gpu::GpuIndexIVFPQConfig idx_config; + idx_config.device = static_cast(gpu_id_); + int32_t nlist = config[IndexParams::nlist]; + int32_t m = config[IndexParams::m]; + int32_t nbits = config[IndexParams::nbits]; + faiss::MetricType metric_type = GetMetricType(config[Metric::TYPE].get()); + index_ = std::make_shared(gpu_res->faiss_res.get(), dim, nlist, m, nbits, + metric_type, idx_config); device_index->train(rows, reinterpret_cast(p_data)); - index_.reset(device_index); res_ = gpu_res; } else { KNOWHERE_THROW_MSG("Build IVFPQ can't get gpu resource"); diff --git a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFSQ.cpp b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFSQ.cpp index e58d68a815..11afb55a80 100644 --- a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFSQ.cpp +++ b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVFSQ.cpp @@ -33,11 +33,13 @@ GPUIVFSQ::Train(const DatasetPtr& dataset_ptr, const Config& config) { auto gpu_res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_); if (gpu_res != nullptr) { ResScope rs(gpu_res, gpu_id_, true); - auto device_index = new faiss::gpu::GpuIndexIVFScalarQuantizer( - gpu_res->faiss_res.get(), dim, config[IndexParams::nlist].get(), faiss::QuantizerType::QT_8bit, - GetMetricType(config[Metric::TYPE].get())); - device_index->train(rows, reinterpret_cast(p_data)); - index_.reset(device_index); + faiss::gpu::GpuIndexIVFScalarQuantizerConfig idx_config; + idx_config.device = static_cast(gpu_id_); + int32_t nlist = config[IndexParams::nlist]; + faiss::MetricType metric_type = GetMetricType(config[Metric::TYPE].get()); + index_ = std::make_shared( + gpu_res->faiss_res.get(), dim, nlist, faiss::QuantizerType::QT_8bit, metric_type, true, idx_config); + index_->train(rows, (float*)p_data); res_ = gpu_res; } else { KNOWHERE_THROW_MSG("Build IVFSQ can't get gpu resource"); diff --git a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp index 074cfdc47b..f382dfd504 100644 --- a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp +++ b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp @@ -33,27 +33,22 @@ IVFSQHybrid::Train(const DatasetPtr& dataset_ptr, const Config& config) { GET_TENSOR_DATA_DIM(dataset_ptr) gpu_id_ = config[knowhere::meta::DEVICEID]; - std::stringstream index_type; - index_type << "IVF" << config[IndexParams::nlist] << "," - << "SQ8Hybrid"; - auto build_index = - faiss::index_factory(dim, index_type.str().c_str(), GetMetricType(config[Metric::TYPE].get())); - auto gpu_res = FaissGpuResourceMgr::GetInstance().GetRes(gpu_id_); if (gpu_res != nullptr) { ResScope rs(gpu_res, gpu_id_, true); - auto device_index = faiss::gpu::index_cpu_to_gpu(gpu_res->faiss_res.get(), gpu_id_, build_index); - device_index->train(rows, reinterpret_cast(p_data)); - - index_.reset(device_index); + faiss::gpu::GpuIndexIVFSQHybridConfig idx_config; + idx_config.device = static_cast(gpu_id_); + int32_t nlist = config[IndexParams::nlist]; + faiss::MetricType metric_type = GetMetricType(config[Metric::TYPE].get()); + index_ = std::make_shared( + gpu_res->faiss_res.get(), dim, nlist, faiss::QuantizerType::QT_8bit, metric_type, true, idx_config); + index_->train(rows, reinterpret_cast(p_data)); res_ = gpu_res; gpu_mode_ = 2; + index_mode_ = IndexMode::MODE_GPU; } else { - delete build_index; KNOWHERE_THROW_MSG("Build IVFSQHybrid can't get gpu resource"); } - - delete build_index; } VecIndexPtr diff --git a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.h b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.h index d3fe1f0f99..535ae57cfd 100644 --- a/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.h +++ b/internal/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.h @@ -38,12 +38,14 @@ class IVFSQHybrid : public GPUIVFSQ { explicit IVFSQHybrid(const int& device_id) : GPUIVFSQ(device_id) { index_type_ = IndexEnum::INDEX_FAISS_IVFSQ8H; gpu_mode_ = 0; + index_mode_ = IndexMode::MODE_CPU; } explicit IVFSQHybrid(std::shared_ptr index) : GPUIVFSQ(-1) { index_type_ = IndexEnum::INDEX_FAISS_IVFSQ8H; index_ = index; gpu_mode_ = 0; + index_mode_ = IndexMode::MODE_CPU; } explicit IVFSQHybrid(std::shared_ptr index, const int64_t device_id, ResPtr& resource)