mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
addd unittest for ExecutionImpl
Former-commit-id: 67a0c021813a1588ba6779a14bca33de337a9bbf
This commit is contained in:
parent
d089b9d2af
commit
d5caefd334
@ -31,8 +31,6 @@ enum class MetricType {
|
||||
class ExecutionEngine {
|
||||
public:
|
||||
|
||||
virtual Status AddWithIdArray(const std::vector<float>& vectors, const std::vector<long>& vector_ids);
|
||||
|
||||
virtual Status AddWithIds(long n, const float *xdata, const long *xids) = 0;
|
||||
|
||||
virtual size_t Count() const = 0;
|
||||
|
||||
@ -138,10 +138,8 @@ Status ExecutionEngineImpl::Load(bool to_cache) {
|
||||
} else {
|
||||
ENGINE_LOG_DEBUG << "Disk io from: " << location_;
|
||||
}
|
||||
} catch (knowhere::KnowhereException &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
} catch (std::exception &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
}
|
||||
}
|
||||
@ -166,10 +164,8 @@ Status ExecutionEngineImpl::CopyToGpu(uint64_t device_id) {
|
||||
try {
|
||||
index_ = index_->CopyToGpu(device_id);
|
||||
ENGINE_LOG_DEBUG << "CPU to GPU" << device_id;
|
||||
} catch (knowhere::KnowhereException &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
} catch (std::exception &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
}
|
||||
}
|
||||
@ -195,10 +191,8 @@ Status ExecutionEngineImpl::CopyToCpu() {
|
||||
try {
|
||||
index_ = index_->CopyToCpu();
|
||||
ENGINE_LOG_DEBUG << "GPU to CPU";
|
||||
} catch (knowhere::KnowhereException &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
} catch (std::exception &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
}
|
||||
}
|
||||
@ -233,10 +227,8 @@ Status ExecutionEngineImpl::Merge(const std::string &location) {
|
||||
double physical_size = server::CommonUtil::GetFileSize(location);
|
||||
server::CollectExecutionEngineMetrics metrics(physical_size);
|
||||
to_merge = read_index(location);
|
||||
} catch (knowhere::KnowhereException &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
} catch (std::exception &e) {
|
||||
ENGINE_LOG_ERROR << e.what();
|
||||
return Status(DB_ERROR, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
123
cpp/unittest/db/engine_test.cpp
Normal file
123
cpp/unittest/db/engine_test.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <gtest/gtest.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "db/engine/EngineFactory.h"
|
||||
#include "db/engine/ExecutionEngineImpl.h"
|
||||
#include "server/ServerConfig.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace zilliz::milvus;
|
||||
|
||||
TEST(EngineTest, FACTORY_TEST) {
|
||||
{
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
512,
|
||||
"/tmp/milvus_index_1",
|
||||
engine::EngineType::INVALID,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
ASSERT_TRUE(engine_ptr == nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
512,
|
||||
"/tmp/milvus_index_1",
|
||||
engine::EngineType::FAISS_IDMAP,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
ASSERT_TRUE(engine_ptr != nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
512,
|
||||
"/tmp/milvus_index_1",
|
||||
engine::EngineType::FAISS_IVFFLAT,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
ASSERT_TRUE(engine_ptr != nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
512,
|
||||
"/tmp/milvus_index_1",
|
||||
engine::EngineType::FAISS_IVFSQ8,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
ASSERT_TRUE(engine_ptr != nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
512,
|
||||
"/tmp/milvus_index_1",
|
||||
engine::EngineType::NSG_MIX,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
ASSERT_TRUE(engine_ptr != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EngineTest, ENGINE_IMPL_TEST) {
|
||||
uint16_t dimension = 64;
|
||||
std::string file_path = "/tmp/milvus_index_1";
|
||||
auto engine_ptr = engine::EngineFactory::Build(
|
||||
dimension,
|
||||
file_path,
|
||||
engine::EngineType::FAISS_IVFFLAT,
|
||||
engine::MetricType::IP,
|
||||
1024
|
||||
);
|
||||
|
||||
std::vector<float> data;
|
||||
std::vector<long> ids;
|
||||
const int row_count = 10000;
|
||||
data.reserve(row_count*dimension);
|
||||
ids.reserve(row_count);
|
||||
for(long i = 0; i < row_count; i++) {
|
||||
ids.push_back(i);
|
||||
for(uint16_t k = 0; k < dimension; k++) {
|
||||
data.push_back(i*dimension + k);
|
||||
}
|
||||
}
|
||||
|
||||
auto status = engine_ptr->AddWithIds((long)ids.size(), data.data(), ids.data());
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
ASSERT_EQ(engine_ptr->Dimension(), dimension);
|
||||
ASSERT_EQ(engine_ptr->Count(), ids.size());
|
||||
|
||||
server::ConfigNode& config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_CACHE);
|
||||
config.AddSequenceItem(server::CONFIG_GPU_IDS, "0");
|
||||
|
||||
status = engine_ptr->CopyToGpu(0);
|
||||
//ASSERT_TRUE(status.ok());
|
||||
|
||||
auto new_engine = engine_ptr->Clone();
|
||||
ASSERT_EQ(new_engine->Dimension(), dimension);
|
||||
ASSERT_EQ(new_engine->Count(), ids.size());
|
||||
status = new_engine->CopyToCpu();
|
||||
//ASSERT_TRUE(status.ok());
|
||||
|
||||
auto engine_build = new_engine->BuildIndex("/tmp/milvus_index_2", engine::EngineType::FAISS_IVFSQ8);
|
||||
//ASSERT_TRUE(status.ok());
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user