fix Milvus crash when searching and building index simultaneously using SQ8H (#794)

* #715 fix Milvus crash when searching and building index simultaneously using SQ8H

* #715 fix update
pull/796/head
Cai Yudong 2019-12-19 21:45:14 +08:00 committed by Jin Hai
parent e1d20e4446
commit 04bd700668
3 changed files with 36 additions and 0 deletions

View File

@ -5,6 +5,7 @@ Please mark all change in change log and use the issue from GitHub
# Milvus 0.7.0 (TBD)
## Bug
- \#715 - Milvus crash when searching and building index simultaneously using SQ8H
- \#744 - Don't return partition table for show_tables
## Feature

View File

@ -19,6 +19,7 @@
#include "knowhere/index/vector_index/IndexIVFSQHybrid.h"
#include "knowhere/adapter/VectorAdapter.h"
#include "knowhere/common/Exception.h"
#include "knowhere/index/vector_index/helpers/FaissIO.h"
#include <utility>
@ -77,6 +78,13 @@ IVFSQHybrid::CopyGpuToCpu(const Config& config) {
faiss::Index* device_index = index_.get();
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu(device_index);
if (auto* ivf_index = dynamic_cast<faiss::IndexIVF*>(host_index)) {
if (ivf_index != nullptr) {
ivf_index->to_readonly();
}
ivf_index->backup_quantizer();
}
std::shared_ptr<faiss::Index> new_index;
new_index.reset(host_index);
return std::make_shared<IVFSQHybrid>(new_index);
@ -287,6 +295,30 @@ IVFSQHybrid::set_index_model(IndexModelPtr model) {
}
}
BinarySet
IVFSQHybrid::SerializeImpl() {
if (!index_ || !index_->is_trained) {
KNOWHERE_THROW_MSG("index not initialize or trained");
}
if (gpu_mode == 0) {
MemoryIOWriter writer;
faiss::write_index(index_.get(), &writer);
auto data = std::make_shared<uint8_t>();
data.reset(writer.data_);
BinarySet res_set;
res_set.Append("IVF", data, writer.rp);
return res_set;
} else if (gpu_mode == 2) {
return GPUIVF::SerializeImpl();
} else {
KNOWHERE_THROW_MSG("Can't serialize IVFSQ8Hybrid");
}
}
FaissIVFQuantizer::~FaissIVFQuantizer() {
if (quantizer != nullptr) {
delete quantizer;

View File

@ -81,6 +81,9 @@ class IVFSQHybrid : public GPUIVFSQ {
VectorIndexPtr
CopyCpuToGpu(const int64_t& device_id, const Config& config) override;
BinarySet
SerializeImpl();
protected:
void
search_impl(int64_t n, const float* data, int64_t k, float* distances, int64_t* labels, const Config& cfg) override;