Merge pull request #572 from Yukikaze-CZR/0.6.0

#504 The code coverage rate of core/src/scheduler/optimizer is too low
pull/581/head
Jin Hai 2019-11-27 15:52:58 +08:00 committed by GitHub
commit ba8c597931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 214 additions and 137 deletions

View File

@ -22,6 +22,7 @@ Please mark all change in change log and use the ticket from JIRA.
- \#458 - Index data is not compatible between 0.5 and 0.6 - \#458 - Index data is not compatible between 0.5 and 0.6
- \#465 - Server hang caused by searching with nsg index - \#465 - Server hang caused by searching with nsg index
- \#486 - gpu no usage during index building - \#486 - gpu no usage during index building
- \#504 - The code coverage rate of core/src/scheduler/optimizer is too low
- \#509 - IVF_PQ index build trapped into dead loop caused by invalid params - \#509 - IVF_PQ index build trapped into dead loop caused by invalid params
- \#513 - Unittest DELETE_BY_RANGE sometimes failed - \#513 - Unittest DELETE_BY_RANGE sometimes failed
- \#523 - Erase file data from cache once the file is marked as deleted - \#523 - Erase file data from cache once the file is marked as deleted

View File

@ -77,8 +77,8 @@ class ExecutionEngine {
virtual Status virtual Status
CopyToCpu() = 0; CopyToCpu() = 0;
virtual std::shared_ptr<ExecutionEngine> // virtual std::shared_ptr<ExecutionEngine>
Clone() = 0; // Clone() = 0;
virtual Status virtual Status
Merge(const std::string& location) = 0; Merge(const std::string& location) = 0;

View File

@ -415,18 +415,18 @@ ExecutionEngineImpl::CopyToCpu() {
return Status::OK(); return Status::OK();
} }
ExecutionEnginePtr // ExecutionEnginePtr
ExecutionEngineImpl::Clone() { // ExecutionEngineImpl::Clone() {
if (index_ == nullptr) { // if (index_ == nullptr) {
ENGINE_LOG_ERROR << "ExecutionEngineImpl: index is null, failed to clone"; // ENGINE_LOG_ERROR << "ExecutionEngineImpl: index is null, failed to clone";
return nullptr; // return nullptr;
} // }
//
auto ret = std::make_shared<ExecutionEngineImpl>(dim_, location_, index_type_, metric_type_, nlist_); // auto ret = std::make_shared<ExecutionEngineImpl>(dim_, location_, index_type_, metric_type_, nlist_);
ret->Init(); // ret->Init();
ret->index_ = index_->Clone(); // ret->index_ = index_->Clone();
return ret; // return ret;
} //}
Status Status
ExecutionEngineImpl::Merge(const std::string& location) { ExecutionEngineImpl::Merge(const std::string& location) {

View File

@ -64,8 +64,8 @@ class ExecutionEngineImpl : public ExecutionEngine {
Status Status
CopyToCpu() override; CopyToCpu() override;
ExecutionEnginePtr // ExecutionEnginePtr
Clone() override; // Clone() override;
Status Status
Merge(const std::string& location) override; Merge(const std::string& location) override;

View File

@ -47,16 +47,16 @@ GPUIDMAP::CopyGpuToCpu(const Config& config) {
return std::make_shared<IDMAP>(new_index); return std::make_shared<IDMAP>(new_index);
} }
VectorIndexPtr // VectorIndexPtr
GPUIDMAP::Clone() { // GPUIDMAP::Clone() {
auto cpu_idx = CopyGpuToCpu(Config()); // auto cpu_idx = CopyGpuToCpu(Config());
//
if (auto idmap = std::dynamic_pointer_cast<IDMAP>(cpu_idx)) { // if (auto idmap = std::dynamic_pointer_cast<IDMAP>(cpu_idx)) {
return idmap->CopyCpuToGpu(gpu_id_, Config()); // return idmap->CopyCpuToGpu(gpu_id_, Config());
} else { // } else {
KNOWHERE_THROW_MSG("IndexType not Support GpuClone"); // KNOWHERE_THROW_MSG("IndexType not Support GpuClone");
} // }
} //}
BinarySet BinarySet
GPUIDMAP::SerializeImpl() { GPUIDMAP::SerializeImpl() {

View File

@ -41,8 +41,8 @@ class GPUIDMAP : public IDMAP, public GPUIndex {
int64_t* int64_t*
GetRawIds() override; GetRawIds() override;
VectorIndexPtr // VectorIndexPtr
Clone() override; // Clone() override;
VectorIndexPtr VectorIndexPtr
CopyGpuToGpu(const int64_t& device_id, const Config& config) override; CopyGpuToGpu(const int64_t& device_id, const Config& config) override;

View File

@ -158,11 +158,11 @@ GPUIVF::CopyGpuToCpu(const Config& config) {
} }
} }
VectorIndexPtr // VectorIndexPtr
GPUIVF::Clone() { // GPUIVF::Clone() {
auto cpu_idx = CopyGpuToCpu(Config()); // auto cpu_idx = CopyGpuToCpu(Config());
return knowhere::cloner::CopyCpuToGpu(cpu_idx, gpu_id_, Config()); // return knowhere::cloner::CopyCpuToGpu(cpu_idx, gpu_id_, Config());
} //}
VectorIndexPtr VectorIndexPtr
GPUIVF::CopyGpuToGpu(const int64_t& device_id, const Config& config) { GPUIVF::CopyGpuToGpu(const int64_t& device_id, const Config& config) {

View File

@ -75,8 +75,8 @@ class GPUIVF : public IVF, public GPUIndex {
VectorIndexPtr VectorIndexPtr
CopyGpuToGpu(const int64_t& device_id, const Config& config) override; CopyGpuToGpu(const int64_t& device_id, const Config& config) override;
VectorIndexPtr // VectorIndexPtr
Clone() final; // Clone() final;
protected: protected:
void void

View File

@ -164,15 +164,15 @@ IDMAP::Train(const Config& config) {
index_.reset(index); index_.reset(index);
} }
VectorIndexPtr // VectorIndexPtr
IDMAP::Clone() { // IDMAP::Clone() {
std::lock_guard<std::mutex> lk(mutex_); // std::lock_guard<std::mutex> lk(mutex_);
//
auto clone_index = faiss::clone_index(index_.get()); // auto clone_index = faiss::clone_index(index_.get());
std::shared_ptr<faiss::Index> new_index; // std::shared_ptr<faiss::Index> new_index;
new_index.reset(clone_index); // new_index.reset(clone_index);
return std::make_shared<IDMAP>(new_index); // return std::make_shared<IDMAP>(new_index);
} //}
VectorIndexPtr VectorIndexPtr
IDMAP::CopyCpuToGpu(const int64_t& device_id, const Config& config) { IDMAP::CopyCpuToGpu(const int64_t& device_id, const Config& config) {

View File

@ -42,8 +42,8 @@ class IDMAP : public VectorIndex, public FaissBaseIndex {
Search(const DatasetPtr& dataset, const Config& config) override; Search(const DatasetPtr& dataset, const Config& config) override;
int64_t int64_t
Count() override; Count() override;
VectorIndexPtr // VectorIndexPtr
Clone() override; // Clone() override;
int64_t int64_t
Dimension() override; Dimension() override;
void void

View File

@ -257,20 +257,20 @@ IVF::CopyCpuToGpu(const int64_t& device_id, const Config& config) {
#endif #endif
} }
VectorIndexPtr // VectorIndexPtr
IVF::Clone() { // IVF::Clone() {
std::lock_guard<std::mutex> lk(mutex_); // std::lock_guard<std::mutex> lk(mutex_);
//
auto clone_index = faiss::clone_index(index_.get()); // auto clone_index = faiss::clone_index(index_.get());
std::shared_ptr<faiss::Index> new_index; // std::shared_ptr<faiss::Index> new_index;
new_index.reset(clone_index); // new_index.reset(clone_index);
return Clone_impl(new_index); // return Clone_impl(new_index);
} //}
//
VectorIndexPtr // VectorIndexPtr
IVF::Clone_impl(const std::shared_ptr<faiss::Index>& index) { // IVF::Clone_impl(const std::shared_ptr<faiss::Index>& index) {
return std::make_shared<IVF>(index); // return std::make_shared<IVF>(index);
} //}
void void
IVF::Seal() { IVF::Seal() {

View File

@ -38,8 +38,8 @@ class IVF : public VectorIndex, public FaissBaseIndex {
explicit IVF(std::shared_ptr<faiss::Index> index) : FaissBaseIndex(std::move(index)) { explicit IVF(std::shared_ptr<faiss::Index> index) : FaissBaseIndex(std::move(index)) {
} }
VectorIndexPtr // VectorIndexPtr
Clone() override; // Clone() override;
IndexModelPtr IndexModelPtr
Train(const DatasetPtr& dataset, const Config& config) override; Train(const DatasetPtr& dataset, const Config& config) override;
@ -81,8 +81,8 @@ class IVF : public VectorIndex, public FaissBaseIndex {
virtual std::shared_ptr<faiss::IVFSearchParameters> virtual std::shared_ptr<faiss::IVFSearchParameters>
GenParams(const Config& config); GenParams(const Config& config);
virtual VectorIndexPtr // virtual VectorIndexPtr
Clone_impl(const std::shared_ptr<faiss::Index>& index); // Clone_impl(const std::shared_ptr<faiss::Index>& index);
virtual void virtual void
search_impl(int64_t n, const float* data, int64_t k, float* distances, int64_t* labels, const Config& cfg); search_impl(int64_t n, const float* data, int64_t k, float* distances, int64_t* labels, const Config& cfg);

View File

@ -63,10 +63,10 @@ IVFPQ::GenParams(const Config& config) {
return params; return params;
} }
VectorIndexPtr // VectorIndexPtr
IVFPQ::Clone_impl(const std::shared_ptr<faiss::Index>& index) { // IVFPQ::Clone_impl(const std::shared_ptr<faiss::Index>& index) {
return std::make_shared<IVFPQ>(index); // return std::make_shared<IVFPQ>(index);
} //}
VectorIndexPtr VectorIndexPtr
IVFPQ::CopyCpuToGpu(const int64_t& device_id, const Config& config) { IVFPQ::CopyCpuToGpu(const int64_t& device_id, const Config& config) {

View File

@ -41,8 +41,8 @@ class IVFPQ : public IVF {
std::shared_ptr<faiss::IVFSearchParameters> std::shared_ptr<faiss::IVFSearchParameters>
GenParams(const Config& config) override; GenParams(const Config& config) override;
VectorIndexPtr // VectorIndexPtr
Clone_impl(const std::shared_ptr<faiss::Index>& index) override; // Clone_impl(const std::shared_ptr<faiss::Index>& index) override;
}; };
} // namespace knowhere } // namespace knowhere

View File

@ -54,10 +54,10 @@ IVFSQ::Train(const DatasetPtr& dataset, const Config& config) {
return std::make_shared<IVFIndexModel>(ret_index); return std::make_shared<IVFIndexModel>(ret_index);
} }
VectorIndexPtr // VectorIndexPtr
IVFSQ::Clone_impl(const std::shared_ptr<faiss::Index>& index) { // IVFSQ::Clone_impl(const std::shared_ptr<faiss::Index>& index) {
return std::make_shared<IVFSQ>(index); // return std::make_shared<IVFSQ>(index);
} //}
VectorIndexPtr VectorIndexPtr
IVFSQ::CopyCpuToGpu(const int64_t& device_id, const Config& config) { IVFSQ::CopyCpuToGpu(const int64_t& device_id, const Config& config) {

View File

@ -38,8 +38,8 @@ class IVFSQ : public IVF {
CopyCpuToGpu(const int64_t& device_id, const Config& config) override; CopyCpuToGpu(const int64_t& device_id, const Config& config) override;
protected: protected:
VectorIndexPtr // VectorIndexPtr
Clone_impl(const std::shared_ptr<faiss::Index>& index) override; // Clone_impl(const std::shared_ptr<faiss::Index>& index) override;
}; };
} // namespace knowhere } // namespace knowhere

View File

@ -158,10 +158,10 @@ NSG::Dimension() {
return index_->dimension; return index_->dimension;
} }
VectorIndexPtr // VectorIndexPtr
NSG::Clone() { // NSG::Clone() {
KNOWHERE_THROW_MSG("not support"); // KNOWHERE_THROW_MSG("not support");
} //}
void void
NSG::Seal() { NSG::Seal() {

View File

@ -49,8 +49,8 @@ class NSG : public VectorIndex {
Count() override; Count() override;
int64_t int64_t
Dimension() override; Dimension() override;
VectorIndexPtr // VectorIndexPtr
Clone() override; // Clone() override;
void void
Seal() override; Seal() override;

View File

@ -210,6 +210,9 @@ CPUSPTAGRNG::Load(const BinarySet& binary_set) {
IndexModelPtr IndexModelPtr
CPUSPTAGRNG::Train(const DatasetPtr& origin, const Config& train_config) { CPUSPTAGRNG::Train(const DatasetPtr& origin, const Config& train_config) {
SetParameters(train_config); SetParameters(train_config);
if (train_config != nullptr) {
train_config->CheckValid(); // throw exception
}
DatasetPtr dataset = origin->Clone(); DatasetPtr dataset = origin->Clone();
// if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine // if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
@ -295,6 +298,9 @@ CPUSPTAGRNG::SetParameters(const Config& config) {
DatasetPtr DatasetPtr
CPUSPTAGRNG::Search(const DatasetPtr& dataset, const Config& config) { CPUSPTAGRNG::Search(const DatasetPtr& dataset, const Config& config) {
SetParameters(config); SetParameters(config);
if (config != nullptr) {
config->CheckValid(); // throw exception
}
auto tensor = dataset->tensor()[0]; auto tensor = dataset->tensor()[0];
auto p = (float*)tensor->raw_mutable_data(); auto p = (float*)tensor->raw_mutable_data();
for (auto i = 0; i < 10; ++i) { for (auto i = 0; i < 10; ++i) {
@ -325,10 +331,10 @@ CPUSPTAGRNG::Dimension() {
return index_ptr_->GetFeatureDim(); return index_ptr_->GetFeatureDim();
} }
VectorIndexPtr // VectorIndexPtr
CPUSPTAGRNG::Clone() { // CPUSPTAGRNG::Clone() {
KNOWHERE_THROW_MSG("not support"); // KNOWHERE_THROW_MSG("not support");
} //}
void void
CPUSPTAGRNG::Seal() { CPUSPTAGRNG::Seal() {

View File

@ -36,8 +36,8 @@ class CPUSPTAGRNG : public VectorIndex {
BinarySet BinarySet
Serialize() override; Serialize() override;
VectorIndexPtr // VectorIndexPtr
Clone() override; // Clone() override;
void void
Load(const BinarySet& index_array) override; Load(const BinarySet& index_array) override;

View File

@ -49,8 +49,8 @@ class VectorIndex : public Index {
Seal() = 0; Seal() = 0;
// TODO(linxj): Deprecated // TODO(linxj): Deprecated
virtual VectorIndexPtr // virtual VectorIndexPtr
Clone() = 0; // Clone() = 0;
virtual int64_t virtual int64_t
Count() = 0; Count() = 0;

View File

@ -180,10 +180,10 @@ struct SPTAGCfg : public Cfg {
SPTAGCfg() = default; SPTAGCfg() = default;
bool // bool
CheckValid() override { // CheckValid() override {
return true; // return true;
}; // };
}; };
using SPTAGConfig = std::shared_ptr<SPTAGCfg>; using SPTAGConfig = std::shared_ptr<SPTAGCfg>;

View File

@ -139,9 +139,9 @@ TEST_F(IDMAPTest, copy_test) {
{ {
// clone // clone
auto clone_index = index_->Clone(); // auto clone_index = index_->Clone();
auto clone_result = clone_index->Search(query_dataset, conf); // auto clone_result = clone_index->Search(query_dataset, conf);
AssertAnns(clone_result, nq, k); // AssertAnns(clone_result, nq, k);
} }
{ {
@ -159,9 +159,9 @@ TEST_F(IDMAPTest, copy_test) {
auto new_result = clone_index->Search(query_dataset, conf); auto new_result = clone_index->Search(query_dataset, conf);
AssertAnns(new_result, nq, k); AssertAnns(new_result, nq, k);
auto clone_gpu_idx = clone_index->Clone(); // auto clone_gpu_idx = clone_index->Clone();
auto clone_gpu_res = clone_gpu_idx->Search(query_dataset, conf); // auto clone_gpu_res = clone_gpu_idx->Search(query_dataset, conf);
AssertAnns(clone_gpu_res, nq, k); // AssertAnns(clone_gpu_res, nq, k);
// gpu to cpu // gpu to cpu
auto host_index = knowhere::cloner::CopyGpuToCpu(clone_index, conf); auto host_index = knowhere::cloner::CopyGpuToCpu(clone_index, conf);

View File

@ -62,6 +62,7 @@ class IVFTest : public DataGen, public TestWithParam<::std::tuple<std::string, P
Generate(DIM, NB, NQ); Generate(DIM, NB, NQ);
index_ = IndexFactory(index_type); index_ = IndexFactory(index_type);
conf = ParamGenerator::GetInstance().Gen(parameter_type); conf = ParamGenerator::GetInstance().Gen(parameter_type);
conf->Dump();
} }
void void

View File

@ -57,11 +57,13 @@ class NSGInterfaceTest : public DataGen, public ::testing::Test {
tmp_conf->candidate_pool_size = 100; tmp_conf->candidate_pool_size = 100;
tmp_conf->metric_type = knowhere::METRICTYPE::L2; tmp_conf->metric_type = knowhere::METRICTYPE::L2;
train_conf = tmp_conf; train_conf = tmp_conf;
train_conf->Dump();
auto tmp2_conf = std::make_shared<knowhere::NSGCfg>(); auto tmp2_conf = std::make_shared<knowhere::NSGCfg>();
tmp2_conf->k = k; tmp2_conf->k = k;
tmp2_conf->search_length = 30; tmp2_conf->search_length = 30;
search_conf = tmp2_conf; search_conf = tmp2_conf;
search_conf->Dump();
} }
void void
@ -92,7 +94,7 @@ TEST_F(NSGInterfaceTest, basic_test) {
ASSERT_EQ(index_->Count(), nb); ASSERT_EQ(index_->Count(), nb);
ASSERT_EQ(index_->Dimension(), dim); ASSERT_EQ(index_->Dimension(), dim);
ASSERT_THROW({ index_->Clone(); }, knowhere::KnowhereException); // ASSERT_THROW({ index_->Clone(); }, knowhere::KnowhereException);
ASSERT_NO_THROW({ ASSERT_NO_THROW({
index_->Add(base_dataset, knowhere::Config()); index_->Add(base_dataset, knowhere::Config());
index_->Seal(); index_->Seal();

View File

@ -19,19 +19,17 @@
#include "scheduler/SchedInst.h" #include "scheduler/SchedInst.h"
#include "scheduler/Utils.h" #include "scheduler/Utils.h"
#include "scheduler/tasklabel/SpecResLabel.h" #include "scheduler/tasklabel/SpecResLabel.h"
#ifdef MILVUS_GPU_VERSION
namespace milvus { namespace milvus {
namespace scheduler { namespace scheduler {
void void
BuildIndexPass::Init() { BuildIndexPass::Init() {
#ifdef MILVUS_GPU_VERSION
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
Status s = config.GetGpuResourceConfigBuildIndexResources(build_gpu_ids_); Status s = config.GetGpuResourceConfigBuildIndexResources(build_gpu_ids_);
if (!s.ok()) { if (!s.ok()) {
throw; throw;
} }
#endif
} }
bool bool
@ -56,3 +54,4 @@ BuildIndexPass::Run(const TaskPtr& task) {
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
@ -52,3 +53,4 @@ using BuildIndexPassPtr = std::shared_ptr<BuildIndexPass>;
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#include "scheduler/optimizer/FaissFlatPass.h" #include "scheduler/optimizer/FaissFlatPass.h"
#include "cache/GpuCacheMgr.h" #include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h" #include "scheduler/SchedInst.h"
@ -29,7 +29,6 @@ namespace scheduler {
void void
FaissFlatPass::Init() { FaissFlatPass::Init() {
#ifdef MILVUS_GPU_VERSION
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_); Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
if (!s.ok()) { if (!s.ok()) {
@ -39,7 +38,6 @@ FaissFlatPass::Init() {
if (!s.ok()) { if (!s.ok()) {
throw; throw;
} }
#endif
} }
bool bool
@ -71,3 +69,4 @@ FaissFlatPass::Run(const TaskPtr& task) {
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
@ -54,3 +55,4 @@ using FaissFlatPassPtr = std::shared_ptr<FaissFlatPass>;
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#include "scheduler/optimizer/FaissIVFFlatPass.h" #include "scheduler/optimizer/FaissIVFFlatPass.h"
#include "cache/GpuCacheMgr.h" #include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h" #include "scheduler/SchedInst.h"
@ -72,3 +72,4 @@ FaissIVFFlatPass::Run(const TaskPtr& task) {
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
@ -54,3 +55,4 @@ using FaissIVFFlatPassPtr = std::shared_ptr<FaissIVFFlatPass>;
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#include "scheduler/optimizer/FaissIVFSQ8HPass.h" #include "scheduler/optimizer/FaissIVFSQ8HPass.h"
#include "cache/GpuCacheMgr.h" #include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h" #include "scheduler/SchedInst.h"
@ -29,7 +29,7 @@ namespace scheduler {
void void
FaissIVFSQ8HPass::Init() { FaissIVFSQ8HPass::Init() {
#ifdef MILVUS_GPU_VERSION #ifdef CUSTOMIZATION
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_); Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
if (!s.ok()) { if (!s.ok()) {
@ -41,6 +41,7 @@ FaissIVFSQ8HPass::Init() {
bool bool
FaissIVFSQ8HPass::Run(const TaskPtr& task) { FaissIVFSQ8HPass::Run(const TaskPtr& task) {
#ifdef CUSTOMIZATION
if (task->Type() != TaskType::SearchTask) { if (task->Type() != TaskType::SearchTask) {
return false; return false;
} }
@ -65,7 +66,9 @@ FaissIVFSQ8HPass::Run(const TaskPtr& task) {
auto label = std::make_shared<SpecResLabel>(res_ptr); auto label = std::make_shared<SpecResLabel>(res_ptr);
task->label() = label; task->label() = label;
return true; return true;
#endif
} }
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
@ -54,3 +55,4 @@ using FaissIVFSQ8HPassPtr = std::shared_ptr<FaissIVFSQ8HPass>;
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#include "scheduler/optimizer/FaissIVFSQ8Pass.h" #include "scheduler/optimizer/FaissIVFSQ8Pass.h"
#include "cache/GpuCacheMgr.h" #include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h" #include "scheduler/SchedInst.h"
@ -72,3 +72,4 @@ FaissIVFSQ8Pass::Run(const TaskPtr& task) {
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#ifdef MILVUS_GPU_VERSION
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
@ -54,3 +55,4 @@ using FaissIVFSQ8PassPtr = std::shared_ptr<FaissIVFSQ8Pass>;
} // namespace scheduler } // namespace scheduler
} // namespace milvus } // namespace milvus
#endif

View File

@ -180,13 +180,13 @@ VecIndexImpl::CopyToCpu(const Config& cfg) {
#endif #endif
} }
VecIndexPtr // VecIndexPtr
VecIndexImpl::Clone() { // VecIndexImpl::Clone() {
// TODO(linxj): exception handle // // TODO(linxj): exception handle
auto clone_index = std::make_shared<VecIndexImpl>(index_->Clone(), type); // auto clone_index = std::make_shared<VecIndexImpl>(index_->Clone(), type);
clone_index->dim = dim; // clone_index->dim = dim;
return clone_index; // return clone_index;
} //}
int64_t int64_t
VecIndexImpl::GetDeviceId() { VecIndexImpl::GetDeviceId() {

View File

@ -60,8 +60,8 @@ class VecIndexImpl : public VecIndex {
Status Status
Load(const knowhere::BinarySet& index_binary) override; Load(const knowhere::BinarySet& index_binary) override;
VecIndexPtr // VecIndexPtr
Clone() override; // Clone() override;
int64_t int64_t
GetDeviceId() override; GetDeviceId() override;

View File

@ -75,8 +75,8 @@ class VecIndex : public cache::DataObj {
CopyToCpu(const Config& cfg = Config()) = 0; CopyToCpu(const Config& cfg = Config()) = 0;
// TODO(linxj): Deprecated // TODO(linxj): Deprecated
virtual VecIndexPtr // virtual VecIndexPtr
Clone() = 0; // Clone() = 0;
virtual int64_t virtual int64_t
GetDeviceId() = 0; GetDeviceId() = 0;

View File

@ -229,6 +229,7 @@ TEST_F(DBTest, DB_TEST) {
} }
TEST_F(DBTest, SEARCH_TEST) { TEST_F(DBTest, SEARCH_TEST) {
milvus::scheduler::OptimizerInst::GetInstance()->Init();
std::string config_path(CONFIG_PATH); std::string config_path(CONFIG_PATH);
config_path += CONFIG_FILE; config_path += CONFIG_FILE;
milvus::server::Config& config = milvus::server::Config::GetInstance(); milvus::server::Config& config = milvus::server::Config::GetInstance();
@ -290,8 +291,51 @@ TEST_F(DBTest, SEARCH_TEST) {
milvus::engine::ResultDistances result_distances; milvus::engine::ResultDistances result_distances;
stat = db_->Query(TABLE_NAME, tags, k, nq, 10, xq.data(), result_ids, result_distances); stat = db_->Query(TABLE_NAME, tags, k, nq, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok()); ASSERT_TRUE(stat.ok());
stat = db_->Query(TABLE_NAME, tags, k, 1100, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
} }
index.engine_type_ = (int)milvus::engine::EngineType::FAISS_IVFFLAT;
db_->CreateIndex(TABLE_NAME, index); // wait until build index finish
{
std::vector<std::string> tags;
milvus::engine::ResultIds result_ids;
milvus::engine::ResultDistances result_distances;
stat = db_->Query(TABLE_NAME, tags, k, nq, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
stat = db_->Query(TABLE_NAME, tags, k, 1100, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
}
index.engine_type_ = (int)milvus::engine::EngineType::FAISS_IVFSQ8;
db_->CreateIndex(TABLE_NAME, index); // wait until build index finish
{
std::vector<std::string> tags;
milvus::engine::ResultIds result_ids;
milvus::engine::ResultDistances result_distances;
stat = db_->Query(TABLE_NAME, tags, k, nq, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
stat = db_->Query(TABLE_NAME, tags, k, 1100, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
}
#ifdef CUSTOMIZATION
index.engine_type_ = (int)milvus::engine::EngineType::FAISS_IVFSQ8H;
db_->CreateIndex(TABLE_NAME, index); // wait until build index finish
{
std::vector<std::string> tags;
milvus::engine::ResultIds result_ids;
milvus::engine::ResultDistances result_distances;
stat = db_->Query(TABLE_NAME, tags, k, nq, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
stat = db_->Query(TABLE_NAME, tags, k, 1100, 10, xq.data(), result_ids, result_distances);
ASSERT_TRUE(stat.ok());
}
#endif
{ // search by specify index file { // search by specify index file
milvus::engine::meta::DatesT dates; milvus::engine::meta::DatesT dates;
std::vector<std::string> file_ids = {"1", "2", "3", "4", "5", "6"}; std::vector<std::string> file_ids = {"1", "2", "3", "4", "5", "6"};

View File

@ -88,12 +88,12 @@ TEST_F(EngineTest, ENGINE_IMPL_TEST) {
status = engine_ptr->CopyToGpu(0, false); status = engine_ptr->CopyToGpu(0, false);
// ASSERT_TRUE(status.ok()); // ASSERT_TRUE(status.ok());
auto new_engine = engine_ptr->Clone(); // auto new_engine = engine_ptr->Clone();
ASSERT_EQ(new_engine->Dimension(), dimension); // ASSERT_EQ(new_engine->Dimension(), dimension);
ASSERT_EQ(new_engine->Count(), ids.size()); // ASSERT_EQ(new_engine->Count(), ids.size());
status = new_engine->CopyToCpu(); status = engine_ptr->CopyToCpu();
// ASSERT_TRUE(status.ok()); // ASSERT_TRUE(status.ok());
auto engine_build = new_engine->BuildIndex("/tmp/milvus_index_2", milvus::engine::EngineType::FAISS_IVFSQ8); auto engine_build = engine_ptr->BuildIndex("/tmp/milvus_index_2", milvus::engine::EngineType::FAISS_IVFSQ8);
// ASSERT_TRUE(status.ok()); // ASSERT_TRUE(status.ok());
} }

View File

@ -37,10 +37,10 @@ class MockVecIndex : public engine::VecIndex {
const float* xt = nullptr) { const float* xt = nullptr) {
} }
engine::VecIndexPtr // engine::VecIndexPtr
Clone() override { // Clone() override {
return milvus::engine::VecIndexPtr(); // return milvus::engine::VecIndexPtr();
} // }
int64_t int64_t
GetDeviceId() override { GetDeviceId() override {

View File

@ -47,10 +47,10 @@ class MockVecIndex : public milvus::engine::VecIndex {
return milvus::Status(); return milvus::Status();
} }
milvus::engine::VecIndexPtr // milvus::engine::VecIndexPtr
Clone() override { // Clone() override {
return milvus::engine::VecIndexPtr(); // return milvus::engine::VecIndexPtr();
} // }
int64_t int64_t
GetDeviceId() override { GetDeviceId() override {
@ -120,7 +120,7 @@ TEST(CacheTest, DUMMY_TEST) {
mock_index.Add(1, nullptr, nullptr); mock_index.Add(1, nullptr, nullptr);
mock_index.BuildAll(1, nullptr, nullptr, cfg); mock_index.BuildAll(1, nullptr, nullptr, cfg);
mock_index.Search(1, nullptr, nullptr, nullptr, cfg); mock_index.Search(1, nullptr, nullptr, nullptr, cfg);
mock_index.Clone(); // mock_index.Clone();
mock_index.CopyToCpu(cfg); mock_index.CopyToCpu(cfg);
mock_index.CopyToGpu(1, cfg); mock_index.CopyToGpu(1, cfg);
mock_index.GetDeviceId(); mock_index.GetDeviceId();

View File

@ -181,12 +181,22 @@ TEST_P(KnowhereWrapperTest, SERIALIZE_TEST) {
TEST(whatever, test_config) { TEST(whatever, test_config) {
milvus::engine::TempMetaConf conf; milvus::engine::TempMetaConf conf;
conf.nprobe = 16;
auto nsg_conf = std::make_shared<milvus::engine::NSGConfAdapter>(); auto nsg_conf = std::make_shared<milvus::engine::NSGConfAdapter>();
nsg_conf->Match(conf); nsg_conf->Match(conf);
nsg_conf->MatchSearch(conf, milvus::engine::IndexType::FAISS_IVFPQ_GPU); nsg_conf->MatchSearch(conf, milvus::engine::IndexType::NSG_MIX);
auto pq_conf = std::make_shared<milvus::engine::IVFPQConfAdapter>(); auto pq_conf = std::make_shared<milvus::engine::IVFPQConfAdapter>();
pq_conf->Match(conf); pq_conf->Match(conf);
pq_conf->MatchSearch(conf, milvus::engine::IndexType::FAISS_IVFPQ_MIX);
auto kdt_conf = std::make_shared<milvus::engine::SPTAGKDTConfAdapter>();
kdt_conf->Match(conf);
kdt_conf->MatchSearch(conf, milvus::engine::IndexType::SPTAG_KDT_RNT_CPU);
auto bkt_conf = std::make_shared<milvus::engine::SPTAGBKTConfAdapter>();
bkt_conf->Match(conf);
bkt_conf->MatchSearch(conf, milvus::engine::IndexType::SPTAG_BKT_RNT_CPU);
} }
// #include "knowhere/index/vector_index/IndexIDMAP.h" // #include "knowhere/index/vector_index/IndexIDMAP.h"