Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GPU IndexTypes to support Milvus-GPU #259

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/impl/TypeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@
if (type == "BIN_IVF_FLAT") {
return IndexType::BIN_IVF_FLAT;
}
if (type == "GPU_IVF_FLAT") {
return IndexType::GPU_IVF_FLAT;

Check warning on line 397 in src/impl/TypeUtils.cpp

View check run for this annotation

Codecov / codecov/patch

src/impl/TypeUtils.cpp#L397

Added line #L397 was not covered by tests
}
if (type == "GPU_IVF_PQ") {
return IndexType::GPU_IVF_PQ;

Check warning on line 400 in src/impl/TypeUtils.cpp

View check run for this annotation

Codecov / codecov/patch

src/impl/TypeUtils.cpp#L400

Added line #L400 was not covered by tests
}
return IndexType::INVALID;
}

Expand Down Expand Up @@ -897,6 +903,10 @@
return "BIN_FLAT";
case milvus::IndexType::BIN_IVF_FLAT:
return "BIN_IVF_FLAT";
case milvus::IndexType::GPU_IVF_FLAT:
return "GPU_IVF_FLAT";
case milvus::IndexType::GPU_IVF_PQ:
return "GPU_IVF_PQ";

Check warning on line 909 in src/impl/TypeUtils.cpp

View check run for this annotation

Codecov / codecov/patch

src/impl/TypeUtils.cpp#L908-L909

Added lines #L908 - L909 were not covered by tests
default:
return "INVALID";
}
Expand Down
7 changes: 7 additions & 0 deletions src/impl/types/IndexDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Status
validate_index_and_metric(const MetricType metric_type, const IndexType index_type) {
if ((metric_type == milvus::MetricType::IP || metric_type == milvus::MetricType::L2) &&
(index_type == milvus::IndexType::FLAT || index_type == milvus::IndexType::IVF_FLAT ||
index_type == milvus::IndexType::GPU_IVF_FLAT || index_type == milvus::IndexType::GPU_IVF_PQ ||
index_type == milvus::IndexType::IVF_SQ8 || index_type == milvus::IndexType::IVF_PQ ||
index_type == milvus::IndexType::HNSW || index_type == milvus::IndexType::IVF_HNSW ||
index_type == milvus::IndexType::RHNSW_FLAT || index_type == milvus::IndexType::RHNSW_SQ ||
Expand Down Expand Up @@ -90,6 +91,12 @@ validate_params(const IndexDesc& data, const std::unordered_map<std::string, int
Validation{milvus::IndexType::IVF_PQ, "m", 1, 65536, true}, // TODO: m requires mod(dim) == 0
Validation{milvus::IndexType::IVF_PQ, "nbits", 1, 16, false},

Validation{milvus::IndexType::GPU_IVF_FLAT, "nlist", 1, 65536, true},

Validation{milvus::IndexType::GPU_IVF_PQ, "nlist", 1, 65536, true},
Validation{milvus::IndexType::GPU_IVF_PQ, "m", 1, 65536, true}, // TODO: m requires mod(dim) == 0
Validation{milvus::IndexType::GPU_IVF_PQ, "nbits", 1, 16, false},

Validation{milvus::IndexType::HNSW, "M", 4, 64, true},
Validation{milvus::IndexType::HNSW, "efConstruction", 8, 512, true},

Expand Down
2 changes: 2 additions & 0 deletions src/include/milvus/types/IndexType.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum class IndexType {
IVF_FLAT,
IVF_SQ8,
IVF_PQ,
GPU_IVF_FLAT,
GPU_IVF_PQ,
HNSW,
IVF_HNSW,
RHNSW_FLAT,
Expand Down
29 changes: 29 additions & 0 deletions test/it/TestCreateIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,33 @@ TEST_F(MilvusMockedTest, TestCreateIndexFailed) {

status = client_->CreateIndex(collection_name, index_desc, progress_monitor);
EXPECT_FALSE(status.IsOk());
}

TEST_F(MilvusMockedTest, TestCreateGPUIndexInstantly) {
milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()};
client_->Connect(connect_param);

std::string collection_name = "test_collection";
std::string field_name = "test_field";
std::string index_name = "test_gpu_index";
auto index_type = milvus::IndexType::GPU_IVF_FLAT;
auto metric_type = milvus::MetricType::IP;
int64_t index_id = 0;

milvus::IndexDesc index_desc(field_name, "", index_type, metric_type, index_id);
index_desc.AddExtraParam("nlist", 1024);
const auto progress_monitor = ::milvus::ProgressMonitor::NoWait();

EXPECT_CALL(service_, Flush(_, AllOf(Property(&FlushRequest::collection_names, ElementsAre(collection_name))), _))
.WillOnce([&](::grpc::ServerContext*, const FlushRequest*, FlushResponse*) { return ::grpc::Status{}; });

EXPECT_CALL(service_, CreateIndex(_,
AllOf(Property(&CreateIndexRequest::collection_name, collection_name),
Property(&CreateIndexRequest::field_name, field_name)),
_))
.WillOnce([](::grpc::ServerContext*, const CreateIndexRequest*, ::milvus::proto::common::Status*) {
return ::grpc::Status{};
});
auto status = client_->CreateIndex(collection_name, index_desc, progress_monitor);
EXPECT_TRUE(status.IsOk());
}
Loading