mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
commit
e9a1b36231
23
CHANGELOG.md
23
CHANGELOG.md
@ -12,22 +12,37 @@ Please mark all change in change log and use the ticket from JIRA.
|
||||
- \#340 - Test cases run failed on 0.6.0
|
||||
- \#353 - Rename config.h.in to version.h.in
|
||||
- \#374 - sdk_simple return empty result
|
||||
- \#377 - Create partition success if tag name only contains spaces
|
||||
- \#397 - sdk_simple return incorrect result
|
||||
- \#399 - Create partition should be failed if partition tag existed
|
||||
- \#412 - Message returned is confused when partition created with null partition name
|
||||
- \#416 - Drop the same partition success repeatally
|
||||
- \#440 - Query API in customization still uses old version
|
||||
- \#458 - Index data is not compatible between 0.5 and 0.6
|
||||
|
||||
## Feature
|
||||
- \#12 - Pure CPU version for Milvus
|
||||
- \#77 - Support table partition
|
||||
- \#226 - Experimental shards middleware for Milvus
|
||||
- \#127 - Support new Index type IVFPQ
|
||||
- \#226 - Experimental shards middleware for Milvus
|
||||
- \#227 - Support new index types SPTAG-KDT and SPTAG-BKT
|
||||
- \#346 - Support build index with multiple gpu
|
||||
|
||||
## Improvement
|
||||
- \#275 - Rename C++ SDK IndexType
|
||||
- \#284 - Change C++ SDK to shared library
|
||||
- \#255 - Add ivfsq8 test report detailed version
|
||||
- \#260 - C++ SDK README
|
||||
- \#266 - Rpc request source code refactor
|
||||
- \#314 - add Find FAISS in CMake
|
||||
- \#275 - Rename C++ SDK IndexType
|
||||
- \#284 - Change C++ SDK to shared library
|
||||
- \#306 - Use int64 for all config integer
|
||||
- \#310 - Add Q&A for 'protocol https not supported or disable in libcurl' issue
|
||||
- \#314 - add Find FAISS in CMake
|
||||
- \#322 - Add option to enable / disable prometheus
|
||||
- \#358 - Add more information in build.sh and install.md
|
||||
- \#404 - Add virtual method Init() in Pass abstract class
|
||||
- \#409 - Add a Fallback pass in optimizer
|
||||
- \#433 - C++ SDK query result is not easy to use
|
||||
- \#449 - Add ShowPartitions example for C++ SDK
|
||||
|
||||
## Task
|
||||
|
||||
|
||||
22
README.md
22
README.md
@ -5,10 +5,10 @@
|
||||

|
||||

|
||||
[](https://codebeat.co/projects/github-com-jinhai-cn-milvus-master)
|
||||

|
||||

|
||||

|
||||
|
||||
[中文版](README_CN.md)
|
||||
[中文版](README_CN.md) | [日本語版](README_JP.md)
|
||||
|
||||
## What is Milvus
|
||||
|
||||
@ -16,9 +16,9 @@ Milvus is the world's fastest similarity search engine for massive-scale feature
|
||||
|
||||
For more detailed introduction of Milvus and its architecture, see [Milvus overview](https://www.milvus.io/docs/en/aboutmilvus/overview/).
|
||||
|
||||
Milvus provides stable [Python](https://github.com/milvus-io/pymilvus), [Java](https://github.com/milvus-io/milvus-sdk-java) and C++ APIs.
|
||||
Milvus provides stable [Python](https://github.com/milvus-io/pymilvus), [Java](https://github.com/milvus-io/milvus-sdk-java) and [C++](https://github.com/milvus-io/milvus/tree/master/core/src/sdk) APIs.
|
||||
|
||||
Keep up-to-date with newest releases and latest updates by reading Milvus [release notes](https://www.milvus.io/docs/en/release/v0.5.0/).
|
||||
Keep up-to-date with newest releases and latest updates by reading Milvus [release notes](https://www.milvus.io/docs/en/release/v0.5.3/).
|
||||
|
||||
## Get started
|
||||
|
||||
@ -52,11 +52,13 @@ We use [GitHub issues](https://github.com/milvus-io/milvus/issues) to track issu
|
||||
|
||||
To connect with other users and contributors, welcome to join our [Slack channel](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk).
|
||||
|
||||
## Thanks
|
||||
## Contributors
|
||||
|
||||
We greatly appreciate the help of the following people.
|
||||
Below is a list of Milvus contributors. We greatly appreciate your contributions!
|
||||
|
||||
- [akihoni](https://github.com/akihoni) found a broken link and a small typo in the README file.
|
||||
- [akihoni](https://github.com/akihoni) provided the CN version of README, and found a broken link in the doc.
|
||||
- [goodhamgupta](https://github.com/goodhamgupta) fixed a filename typo in the bootcamp doc.
|
||||
- [erdustiggen](https://github.com/erdustiggen) changed from std::cout to LOG for error messages, and fixed a clang format issue as well as some grammatical errors.
|
||||
|
||||
## Resources
|
||||
|
||||
@ -64,6 +66,8 @@ We greatly appreciate the help of the following people.
|
||||
|
||||
- [Milvus bootcamp](https://github.com/milvus-io/bootcamp)
|
||||
|
||||
- [Milvus test reports](https://github.com/milvus-io/milvus/tree/master/docs)
|
||||
|
||||
- [Milvus Medium](https://medium.com/@milvusio)
|
||||
|
||||
- [Milvus CSDN](https://zilliz.blog.csdn.net/)
|
||||
@ -74,6 +78,4 @@ We greatly appreciate the help of the following people.
|
||||
|
||||
## License
|
||||
|
||||
[Apache License 2.0](LICENSE)
|
||||
|
||||
|
||||
[Apache License 2.0](LICENSE)
|
||||
173
README_CN.md
173
README_CN.md
@ -1,155 +1,35 @@
|
||||

|
||||
|
||||
[](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk)
|
||||

|
||||

|
||||
[](https://codebeat.co/projects/github-com-jinhai-cn-milvus-master)
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
- [Slack 频道](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk)
|
||||
- [Twitter](https://twitter.com/milvusio)
|
||||
- [Facebook](https://www.facebook.com/io.milvus.5)
|
||||
- [博客](https://www.milvus.io/blog/)
|
||||
- [CSDN](https://zilliz.blog.csdn.net/)
|
||||
- [中文官网](https://www.milvus.io/zh-CN/)
|
||||
|
||||
# 欢迎来到 Milvus
|
||||
|
||||
## Milvus 是什么
|
||||
|
||||
Milvus 是一款开源的、针对海量特征向量的相似性搜索引擎。基于异构众核计算框架设计,成本更低,性能更好。在有限的计算资源下,十亿向量搜索仅毫秒响应。
|
||||
|
||||
Milvus 提供稳定的 Python、Java 以及 C++ 的 API 接口。
|
||||
若要了解 Milvus 详细介绍和整体架构,请访问 [Milvus 简介](https://www.milvus.io/docs/zh-CN/aboutmilvus/overview/)。
|
||||
|
||||
通过 [版本发布说明](https://milvus.io/docs/zh-CN/release/v0.5.0/) 获取最新发行版本的 Milvus。
|
||||
Milvus 提供稳定的 [Python](https://github.com/milvus-io/pymilvus)、[Java](https://github.com/milvus-io/milvus-sdk-java) 以及 C++ 的 API 接口。
|
||||
|
||||
- 异构众核
|
||||
|
||||
Milvus 基于异构众核计算框架设计,成本更低,性能更好。
|
||||
|
||||
- 多元化索引
|
||||
|
||||
Milvus 支持多种索引方式,使用量化索引、基于树的索引和图索引等算法。
|
||||
|
||||
- 资源智能管理
|
||||
|
||||
Milvus 根据实际数据规模和可利用资源,智能调节优化查询计算和索引构建过程。
|
||||
|
||||
- 水平扩容
|
||||
|
||||
Milvus 支持在线 / 离线扩容,仅需执行简单命令,便可弹性伸缩计算节点和存储节点。
|
||||
|
||||
- 高可用性
|
||||
|
||||
Milvus 集成了 Kubernetes 框架,能有效避免单点障碍情况的发生。
|
||||
|
||||
- 简单易用
|
||||
|
||||
Milvus 安装简单,使用方便,并可使您专注于特征向量。
|
||||
|
||||
- 可视化监控
|
||||
|
||||
您可以使用基于 Prometheus 的图形化监控,以便实时跟踪系统性能。
|
||||
|
||||
## 整体架构
|
||||
|
||||

|
||||
通过 [版本发布说明](https://milvus.io/docs/zh-CN/release/v0.5.3/) 获取最新版本的功能和更新。
|
||||
|
||||
## 开始使用 Milvus
|
||||
|
||||
### 硬件要求
|
||||
请参阅 [Milvus 安装指南](https://www.milvus.io/docs/zh-CN/userguide/install_milvus/) 使用 Docker 容器安装 Milvus。若要基于源码编译,请访问 [源码安装](install.md)。
|
||||
|
||||
| 硬件设备 | 推荐配置 |
|
||||
| -------- | ------------------------------------- |
|
||||
| CPU | Intel CPU Haswell 及以上 |
|
||||
| GPU | NVIDIA Pascal 系列及以上 |
|
||||
| 内存 | 8 GB 或以上(取决于具体向量数据规模) |
|
||||
| 硬盘 | SATA 3.0 SSD 及以上 |
|
||||
|
||||
### 使用 Docker
|
||||
|
||||
您可以方便地使用 Docker 安装 Milvus。具体请查看 [Milvus 安装指南](https://milvus.io/docs/zh-CN/userguide/install_milvus/)。
|
||||
|
||||
### 从源代码编译
|
||||
|
||||
#### 软件要求
|
||||
|
||||
- Ubuntu 18.04 及以上
|
||||
- CMake 3.14 及以上
|
||||
- CUDA 10.0 及以上
|
||||
- NVIDIA driver 418 及以上
|
||||
|
||||
#### 编译
|
||||
|
||||
##### 第一步 安装依赖项
|
||||
|
||||
```shell
|
||||
$ cd [Milvus sourcecode path]/core
|
||||
$ ./ubuntu_build_deps.sh
|
||||
```
|
||||
|
||||
##### 第二步 编译
|
||||
|
||||
```shell
|
||||
$ cd [Milvus sourcecode path]/core
|
||||
$ ./build.sh -t Debug
|
||||
or
|
||||
$ ./build.sh -t Release
|
||||
```
|
||||
|
||||
当您成功编译后,所有 Milvus 必需组件将安装在`[Milvus root path]/core/milvus`路径下。
|
||||
|
||||
##### 启动 Milvus 服务
|
||||
|
||||
```shell
|
||||
$ cd [Milvus root path]/core/milvus
|
||||
```
|
||||
|
||||
在 `LD_LIBRARY_PATH` 中添加 `lib/` 目录:
|
||||
|
||||
```shell
|
||||
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/milvus/lib
|
||||
```
|
||||
|
||||
启动 Milvus 服务:
|
||||
|
||||
```shell
|
||||
$ cd scripts
|
||||
$ ./start_server.sh
|
||||
```
|
||||
|
||||
若要停止 Milvus 服务,请使用如下命令:
|
||||
|
||||
```shell
|
||||
$ ./stop_server.sh
|
||||
```
|
||||
|
||||
若需要修改 Milvus 配置文件 `conf/server_config.yaml` 和`conf/log_config.conf`,请查看 [Milvus 配置](https://milvus.io/docs/zh-CN/reference/milvus_config/)。
|
||||
若要更改 Milvus 设置,请参阅 [Milvus 配置](https://www.milvus.io/docs/zh-CN/reference/milvus_config/)。
|
||||
|
||||
### 开始您的第一个 Milvus 程序
|
||||
|
||||
#### 运行 Python 示例代码
|
||||
您可以尝试用 [Python](https://www.milvus.io/docs/en/userguide/example_code/) 或 [Java example code](https://github.com/milvus-io/milvus-sdk-java/tree/master/examples) 运行 Milvus 示例代码。
|
||||
|
||||
请确保系统的 Python 版本为 [Python 3.5](https://www.python.org/downloads/) 或以上。
|
||||
|
||||
安装 Milvus Python SDK。
|
||||
|
||||
```shell
|
||||
# Install Milvus Python SDK
|
||||
$ pip install pymilvus==0.2.3
|
||||
```
|
||||
|
||||
创建 `example.py` 文件,并向文件中加入 [Python 示例代码](https://github.com/milvus-io/pymilvus/blob/master/examples/advanced_example.py)。
|
||||
|
||||
运行示例代码
|
||||
|
||||
```shell
|
||||
# Run Milvus Python example
|
||||
$ python3 example.py
|
||||
```
|
||||
|
||||
#### 运行 C++ 示例代码
|
||||
若要使用 C++ 示例代码,请使用以下命令:
|
||||
|
||||
```shell
|
||||
# Run Milvus C++ example
|
||||
@ -157,41 +37,44 @@ $ python3 example.py
|
||||
$ ./sdk_simple
|
||||
```
|
||||
|
||||
#### 运行 Java 示例代码
|
||||
## 路线图
|
||||
|
||||
请确保系统的 Java 版本为 Java 8 或以上。
|
||||
|
||||
请从[此处](https://github.com/milvus-io/milvus-sdk-java/tree/master/examples)获取 Java 示例代码。
|
||||
请阅读我们的[路线图](https://milvus.io/docs/zh-CN/roadmap/)以了解更多即将开发的新功能。
|
||||
|
||||
## 贡献者指南
|
||||
|
||||
我们由衷欢迎您推送贡献。关于贡献流程的详细信息,请参阅 [贡献者指南](https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md)。本项目遵循 Milvus [行为准则](https://github.com/milvus-io/milvus/blob/master/CODE_OF_CONDUCT.md)。如果您希望参与本项目,请遵守该准则的内容。
|
||||
我们由衷欢迎您推送贡献。关于贡献流程的详细信息,请参阅[贡献者指南](https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md)。本项目遵循 Milvus [行为准则](https://github.com/milvus-io/milvus/blob/master/CODE_OF_CONDUCT.md)。如果您希望参与本项目,请遵守该准则的内容。
|
||||
|
||||
我们使用 [GitHub issues](https://github.com/milvus-io/milvus/issues/new/choose) 追踪问题和补丁。若您希望提出问题或进行讨论,请加入我们的社区。
|
||||
我们使用 [GitHub issues](https://github.com/milvus-io/milvus/issues) 追踪问题和补丁。若您希望提出问题或进行讨论,请加入我们的社区。
|
||||
|
||||
## 加入 Milvus 社区
|
||||
|
||||
欢迎加入我们的 [Slack 频道](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk) 以便与其他用户和贡献者进行交流。
|
||||
欢迎加入我们的 [Slack 频道](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk)以便与其他用户和贡献者进行交流。
|
||||
|
||||
## Milvus 路线图
|
||||
## 贡献者
|
||||
|
||||
请阅读我们的[路线图](https://milvus.io/docs/zh-CN/roadmap/)以获得更多即将开发的新功能。
|
||||
以下是 Milvus 贡献者名单,在此我们深表感谢:
|
||||
|
||||
- [akihoni](https://github.com/akihoni) 提供了中文版 README,并发现了 README 中的无效链接。
|
||||
- [goodhamgupta](https://github.com/goodhamgupta) 发现并修正了在线训练营文档中的文件名拼写错误。
|
||||
- [erdustiggen](https://github.com/erdustiggen) 将错误信息里的 std::cout 修改为 LOG,修正了一个 Clang 格式问题和一些语法错误。
|
||||
|
||||
## 相关链接
|
||||
|
||||
[Milvus 官方网站](https://www.milvus.io/)
|
||||
- [Milvus.io](https://www.milvus.io)
|
||||
|
||||
[Milvus 文档](https://www.milvus.io/docs/en/userguide/install_milvus/)
|
||||
- [Milvus 在线训练营](https://github.com/milvus-io/bootcamp)
|
||||
|
||||
[Milvus 在线训练营](https://github.com/milvus-io/bootcamp)
|
||||
- [Milvus 测试报告](https://github.com/milvus-io/milvus/tree/master/docs)
|
||||
|
||||
[Milvus 博客](https://www.milvus.io/blog/)
|
||||
- [Milvus Medium](https://medium.com/@milvusio)
|
||||
|
||||
[Milvus CSDN](https://zilliz.blog.csdn.net/)
|
||||
- [Milvus CSDN](https://zilliz.blog.csdn.net/)
|
||||
|
||||
[Milvus 路线图](https://milvus.io/docs/en/roadmap/)
|
||||
- [Milvus Twitter](https://twitter.com/milvusio)
|
||||
|
||||
- [Milvus Facebook](https://www.facebook.com/io.milvus.5)
|
||||
|
||||
## 许可协议
|
||||
|
||||
[Apache 许可协议2.0版](https://github.com/milvus-io/milvus/blob/master/LICENSE)
|
||||
|
||||
|
||||
75
README_JP.md
Normal file
75
README_JP.md
Normal file
@ -0,0 +1,75 @@
|
||||

|
||||
|
||||
|
||||
[](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk)
|
||||

|
||||

|
||||
[](https://codebeat.co/projects/github-com-jinhai-cn-milvus-master)
|
||||

|
||||

|
||||
|
||||
|
||||
# Milvus へようこそ
|
||||
|
||||
## 概要
|
||||
|
||||
Milvusは世界中一番早い特徴ベクトルにむかう類似性検索エンジンです。不均質な計算アーキテクチャーに基づいて効率を最大化出来ます。数十億のベクタの中に目標を検索できるまで数ミリ秒しかかからず、最低限の計算資源だけが必要です。
|
||||
|
||||
Milvusは安定的な[Python](https://github.com/milvus-io/pymilvus)、[Java](https://github.com/milvus-io/milvus-sdk-java)又は [C++](https://github.com/milvus-io/milvus/tree/master/core/src/sdk) APIsを提供します。
|
||||
|
||||
Milvus [リリースノート](https://milvus.io/docs/en/release/v0.5.3/)を読んで最新バージョンや更新情報を手に入れます。
|
||||
|
||||
|
||||
## はじめに
|
||||
|
||||
DockerでMilvusをインストールすることは簡単です。[Milvusインストール案内](https://milvus.io/docs/en/userguide/install_milvus/) を参考してください。ソースからMilvusを構築するために、[ソースから構築する](install.md)を参考してください。
|
||||
|
||||
Milvusをコンフィグするために、[Milvusコンフィグ](https://github.com/milvus-io/docs/blob/master/reference/milvus_config.md)を読んでください。
|
||||
|
||||
### 初めてのMilvusプログラムを試す
|
||||
|
||||
[Python](https://www.milvus.io/docs/en/userguide/example_code/)や[Java](https://github.com/milvus-io/milvus-sdk-java/tree/master/examples)などのサンプルコードを使ってMilvusプログラムを試す。
|
||||
|
||||
C++サンプルコードを実行するために、次のコマンドをつかってください。
|
||||
|
||||
```shell
|
||||
# Run Milvus C++ example
|
||||
$ cd [Milvus root path]/core/milvus/bin
|
||||
$ ./sdk_simple
|
||||
```
|
||||
|
||||
## Milvusロードマップ
|
||||
|
||||
[ロードマップ](https://milvus.io/docs/en/roadmap/)を読んで、追加する予定の特性が分かります。
|
||||
|
||||
## 貢献規約
|
||||
|
||||
本プロジェクトへの貢献に心より感謝いたします。 Milvusを貢献したいと思うなら、[貢献規約](CONTRIBUTING.md)を読んでください。 本プロジェクトはMilvusの[行動規範](CODE_OF_CONDUCT.md)に従います。プロジェクトに参加したい場合は、行動規範を従ってください。
|
||||
|
||||
[GitHub issues](https://github.com/milvus-io/milvus/issues) を使って問題やバッグなとを報告しでください。 一般てきな問題なら, Milvusコミュニティに参加してください。
|
||||
|
||||
## Milvusコミュニティを参加する
|
||||
|
||||
他の貢献者と交流したい場合は、Milvusの [slackチャンネル](https://join.slack.com/t/milvusio/shared_invite/enQtNzY1OTQ0NDI3NjMzLWNmYmM1NmNjOTQ5MGI5NDhhYmRhMGU5M2NhNzhhMDMzY2MzNDdlYjM5ODQ5MmE3ODFlYzU3YjJkNmVlNDQ2ZTk)に参加してください。
|
||||
|
||||
|
||||
## 参考情報
|
||||
|
||||
- [Milvus.io](https://www.milvus.io)
|
||||
|
||||
- [Milvus](https://github.com/milvus-io/bootcamp)
|
||||
|
||||
- [Milvus テストレポート](https://github.com/milvus-io/milvus/tree/master/docs)
|
||||
|
||||
- [Milvus Medium](https://medium.com/@milvusio)
|
||||
|
||||
- [Milvus CSDN](https://zilliz.blog.csdn.net/)
|
||||
|
||||
- [Milvus ツイッター](https://twitter.com/milvusio)
|
||||
|
||||
- [Milvus Facebook](https://www.facebook.com/io.milvus.5)
|
||||
|
||||
|
||||
## ライセンス
|
||||
|
||||
[Apache 2.0ライセンス](LICENSE)
|
||||
34
ci/jenkins/Jenkinsfile
vendored
34
ci/jenkins/Jenkinsfile
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
String cron_timezone = "TZ=Asia/Shanghai"
|
||||
String cron_string = BRANCH_NAME == "master" ? "H 0 * * * " : ""
|
||||
cron_string = BRANCH_NAME == "0.5.1" ? "H 1 * * * " : cron_string
|
||||
cron_string = BRANCH_NAME == "0.6.0" ? "H 1 * * * " : cron_string
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
@ -53,7 +53,7 @@ pipeline {
|
||||
stage("Run Build") {
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-build"
|
||||
label "${env.BINRARY_VERSION}-build"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/milvus-gpu-version-build-env-pod.yaml'
|
||||
}
|
||||
@ -62,7 +62,7 @@ pipeline {
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/build.groovy"
|
||||
}
|
||||
@ -71,7 +71,7 @@ pipeline {
|
||||
}
|
||||
stage('Code Coverage') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/coverage.groovy"
|
||||
}
|
||||
@ -80,7 +80,7 @@ pipeline {
|
||||
}
|
||||
stage('Upload Package') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/package.groovy"
|
||||
}
|
||||
@ -93,7 +93,7 @@ pipeline {
|
||||
stage("Publish docker images") {
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-publish"
|
||||
label "${env.BINRARY_VERSION}-publish"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/docker-pod.yaml'
|
||||
}
|
||||
@ -113,9 +113,13 @@ pipeline {
|
||||
}
|
||||
|
||||
stage("Deploy to Development") {
|
||||
environment {
|
||||
HELM_RELEASE_NAME = "${env.PIPELINE_NAME}-${env.SEMVER}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}".toLowerCase()
|
||||
}
|
||||
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-dev-test"
|
||||
label "${env.BINRARY_VERSION}-dev-test"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/testEnvironment.yaml'
|
||||
}
|
||||
@ -183,7 +187,7 @@ pipeline {
|
||||
stage("Run Build") {
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-build"
|
||||
label "${env.BINRARY_VERSION}-build"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/milvus-cpu-version-build-env-pod.yaml'
|
||||
}
|
||||
@ -192,7 +196,7 @@ pipeline {
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/build.groovy"
|
||||
}
|
||||
@ -201,7 +205,7 @@ pipeline {
|
||||
}
|
||||
stage('Code Coverage') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/coverage.groovy"
|
||||
}
|
||||
@ -210,7 +214,7 @@ pipeline {
|
||||
}
|
||||
stage('Upload Package') {
|
||||
steps {
|
||||
container('milvus-build-env') {
|
||||
container("milvus-${env.BINRARY_VERSION}-build-env") {
|
||||
script {
|
||||
load "${env.WORKSPACE}/ci/jenkins/step/package.groovy"
|
||||
}
|
||||
@ -223,7 +227,7 @@ pipeline {
|
||||
stage("Publish docker images") {
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-publish"
|
||||
label "${env.BINRARY_VERSION}-publish"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/docker-pod.yaml'
|
||||
}
|
||||
@ -243,9 +247,13 @@ pipeline {
|
||||
}
|
||||
|
||||
stage("Deploy to Development") {
|
||||
environment {
|
||||
HELM_RELEASE_NAME = "${env.PIPELINE_NAME}-${env.SEMVER}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}".toLowerCase()
|
||||
}
|
||||
|
||||
agent {
|
||||
kubernetes {
|
||||
label "${BINRARY_VERSION}-dev-test"
|
||||
label "${env.BINRARY_VERSION}-dev-test"
|
||||
defaultContainer 'jnlp'
|
||||
yamlFile 'ci/jenkins/pod/testEnvironment.yaml'
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ metadata:
|
||||
componet: cpu-build-env
|
||||
spec:
|
||||
containers:
|
||||
- name: milvus-build-env
|
||||
- name: milvus-cpu-build-env
|
||||
image: registry.zilliz.com/milvus/milvus-cpu-build-env:v0.6.0-ubuntu18.04
|
||||
env:
|
||||
- name: POD_IP
|
||||
|
||||
@ -7,7 +7,7 @@ metadata:
|
||||
componet: gpu-build-env
|
||||
spec:
|
||||
containers:
|
||||
- name: milvus-build-env
|
||||
- name: milvus-gpu-build-env
|
||||
image: registry.zilliz.com/milvus/milvus-gpu-build-env:v0.6.0-ubuntu18.04
|
||||
env:
|
||||
- name: POD_IP
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
try {
|
||||
def helmResult = sh script: "helm status ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}", returnStatus: true
|
||||
def helmResult = sh script: "helm status ${env.HELM_RELEASE_NAME}", returnStatus: true
|
||||
if (!helmResult) {
|
||||
sh "helm del --purge ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}"
|
||||
sh "helm del --purge ${env.HELM_RELEASE_NAME}"
|
||||
}
|
||||
} catch (exc) {
|
||||
def helmResult = sh script: "helm status ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}", returnStatus: true
|
||||
def helmResult = sh script: "helm status ${env.HELM_RELEASE_NAME}", returnStatus: true
|
||||
if (!helmResult) {
|
||||
sh "helm del --purge ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}"
|
||||
sh "helm del --purge ${env.HELM_RELEASE_NAME}"
|
||||
}
|
||||
throw exc
|
||||
}
|
||||
|
||||
@ -3,11 +3,7 @@ sh 'helm repo update'
|
||||
dir ('milvus-helm') {
|
||||
checkout([$class: 'GitSCM', branches: [[name: "0.6.0"]], userRemoteConfigs: [[url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.6.0:refs/remotes/origin/0.6.0"]]])
|
||||
dir ("milvus") {
|
||||
if ("${env.BINRARY_VERSION}" == "gpu") {
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f gpu_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
} else {
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
}
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.HELM_RELEASE_NAME} -f ci/db_backend/sqlite_${env.BINRARY_VERSION}_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,47 +1,45 @@
|
||||
container('publish-images') {
|
||||
timeout(time: 15, unit: 'MINUTES') {
|
||||
dir ("docker/deploy/${env.BINRARY_VERSION}/${env.OS_NAME}") {
|
||||
def binaryPackage = "${PROJECT_NAME}-${PACKAGE_VERSION}.tar.gz"
|
||||
timeout(time: 15, unit: 'MINUTES') {
|
||||
dir ("docker/deploy/${env.BINRARY_VERSION}/${env.OS_NAME}") {
|
||||
def binaryPackage = "${PROJECT_NAME}-${PACKAGE_VERSION}.tar.gz"
|
||||
|
||||
withCredentials([usernamePassword(credentialsId: "${params.JFROG_CREDENTIALS_ID}", usernameVariable: 'JFROG_USERNAME', passwordVariable: 'JFROG_PASSWORD')]) {
|
||||
def downloadStatus = sh(returnStatus: true, script: "curl -u${JFROG_USERNAME}:${JFROG_PASSWORD} -O ${params.JFROG_ARTFACTORY_URL}/milvus/package/${binaryPackage}")
|
||||
withCredentials([usernamePassword(credentialsId: "${params.JFROG_CREDENTIALS_ID}", usernameVariable: 'JFROG_USERNAME', passwordVariable: 'JFROG_PASSWORD')]) {
|
||||
def downloadStatus = sh(returnStatus: true, script: "curl -u${JFROG_USERNAME}:${JFROG_PASSWORD} -O ${params.JFROG_ARTFACTORY_URL}/milvus/package/${binaryPackage}")
|
||||
|
||||
if (downloadStatus != 0) {
|
||||
error("\" Download \" ${params.JFROG_ARTFACTORY_URL}/milvus/package/${binaryPackage} \" failed!")
|
||||
}
|
||||
if (downloadStatus != 0) {
|
||||
error("\" Download \" ${params.JFROG_ARTFACTORY_URL}/milvus/package/${binaryPackage} \" failed!")
|
||||
}
|
||||
sh "tar zxvf ${binaryPackage}"
|
||||
def imageName = "${PROJECT_NAME}/engine:${DOCKER_VERSION}"
|
||||
}
|
||||
sh "tar zxvf ${binaryPackage}"
|
||||
def imageName = "${PROJECT_NAME}/engine:${DOCKER_VERSION}"
|
||||
|
||||
try {
|
||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
||||
if (isExistSourceImage == 0) {
|
||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
||||
}
|
||||
|
||||
def customImage = docker.build("${imageName}")
|
||||
|
||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
||||
if (isExistTargeImage == 0) {
|
||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
||||
}
|
||||
|
||||
docker.withRegistry("https://${params.DOKCER_REGISTRY_URL}", "${params.DOCKER_CREDENTIALS_ID}") {
|
||||
customImage.push()
|
||||
}
|
||||
} catch (exc) {
|
||||
throw exc
|
||||
} finally {
|
||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
||||
if (isExistSourceImage == 0) {
|
||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
||||
}
|
||||
|
||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
||||
if (isExistTargeImage == 0) {
|
||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
||||
}
|
||||
try {
|
||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
||||
if (isExistSourceImage == 0) {
|
||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
||||
}
|
||||
}
|
||||
|
||||
def customImage = docker.build("${imageName}")
|
||||
|
||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
||||
if (isExistTargeImage == 0) {
|
||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
||||
}
|
||||
|
||||
docker.withRegistry("https://${params.DOKCER_REGISTRY_URL}", "${params.DOCKER_CREDENTIALS_ID}") {
|
||||
customImage.push()
|
||||
}
|
||||
} catch (exc) {
|
||||
throw exc
|
||||
} finally {
|
||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
||||
if (isExistSourceImage == 0) {
|
||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
||||
}
|
||||
|
||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
||||
if (isExistTargeImage == 0) {
|
||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
timeout(time: 90, unit: 'MINUTES') {
|
||||
dir ("tests/milvus_python_test") {
|
||||
sh 'python3 -m pip install -r requirements.txt'
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/sqlite\" --ip ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}-milvus-engine.milvus.svc.cluster.local"
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/sqlite\" --ip ${env.HELM_RELEASE_NAME}-engine.milvus.svc.cluster.local"
|
||||
}
|
||||
// mysql database backend test
|
||||
load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/cleanupSingleDev.groovy"
|
||||
load "ci/jenkins/jenkinsfile/cleanupSingleDev.groovy"
|
||||
|
||||
if (!fileExists('milvus-helm')) {
|
||||
dir ("milvus-helm") {
|
||||
@ -13,14 +13,10 @@ timeout(time: 90, unit: 'MINUTES') {
|
||||
}
|
||||
dir ("milvus-helm") {
|
||||
dir ("milvus") {
|
||||
if ("${env.BINRARY_VERSION}" == "gpu") {
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f gpu_values.yaml -f ci/db_backend/mysql_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
} else {
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f ci/db_backend/mysql_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
}
|
||||
sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.HELM_RELEASE_NAME} -f ci/db_backend/mysql_${env.BINRARY_VERSION}_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
}
|
||||
}
|
||||
dir ("tests/milvus_python_test") {
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/mysql\" --ip ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}-milvus-engine.milvus.svc.cluster.local"
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/mysql\" --ip ${env.HELM_RELEASE_NAME}-engine.milvus.svc.cluster.local"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
timeout(time: 60, unit: 'MINUTES') {
|
||||
dir ("tests/milvus_python_test") {
|
||||
sh 'python3 -m pip install -r requirements.txt'
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/sqlite\" --level=1 --ip ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}-milvus-engine.milvus.svc.cluster.local"
|
||||
sh "pytest . --alluredir=\"test_out/dev/single/sqlite\" --level=1 --ip ${env.HELM_RELEASE_NAME}-engine.milvus.svc.cluster.local"
|
||||
}
|
||||
|
||||
// mysql database backend test
|
||||
// load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/cleanupSingleDev.groovy"
|
||||
// load "ci/jenkins/jenkinsfile/cleanupSingleDev.groovy"
|
||||
|
||||
// if (!fileExists('milvus-helm')) {
|
||||
// dir ("milvus-helm") {
|
||||
@ -14,14 +14,10 @@ timeout(time: 60, unit: 'MINUTES') {
|
||||
// }
|
||||
// dir ("milvus-helm") {
|
||||
// dir ("milvus") {
|
||||
// if ("${env.BINRARY_VERSION}" == "gpu") {
|
||||
// sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f gpu_values.yaml -f ci/db_backend/mysql_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
// } else {
|
||||
// sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION} -f ci/db_backend/mysql_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
// }
|
||||
// sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.HELM_RELEASE_NAME} -f ci/db_backend/mysql_${env.BINRARY_VERSION}_values.yaml -f ci/filebeat/values.yaml --namespace milvus ."
|
||||
// }
|
||||
// }
|
||||
// dir ("tests/milvus_python_test") {
|
||||
// sh "pytest . --alluredir=\"test_out/dev/single/mysql\" --level=1 --ip ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-${env.BINRARY_VERSION}-milvus-engine.milvus.svc.cluster.local"
|
||||
// sh "pytest . --alluredir=\"test_out/dev/single/mysql\" --level=1 --ip ${env.HELM_RELEASE_NAME}-engine.milvus.svc.cluster.local"
|
||||
// }
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ BUILD_TYPE="Debug"
|
||||
BUILD_UNITTEST="OFF"
|
||||
INSTALL_PREFIX="/opt/milvus"
|
||||
FAISS_ROOT=""
|
||||
CUSTOMIZATION="OFF" # default use origin faiss
|
||||
BUILD_COVERAGE="OFF"
|
||||
USE_JFROG_CACHE="OFF"
|
||||
RUN_CPPLINT="OFF"
|
||||
@ -23,7 +24,7 @@ GPU_VERSION="OFF"
|
||||
WITH_MKL="OFF"
|
||||
CUDA_COMPILER=/usr/local/cuda/bin/nvcc
|
||||
|
||||
while getopts "o:t:b:f:gulcjmh" arg
|
||||
while getopts "o:t:b:f:gxulcjmh" arg
|
||||
do
|
||||
case $arg in
|
||||
o)
|
||||
@ -41,6 +42,9 @@ do
|
||||
g)
|
||||
GPU_VERSION="ON";
|
||||
;;
|
||||
x)
|
||||
CUSTOMIZATION="ON";
|
||||
;;
|
||||
u)
|
||||
echo "Build and run unittest cases" ;
|
||||
BUILD_UNITTEST="ON";
|
||||
@ -66,6 +70,7 @@ parameter:
|
||||
-b: core code build directory
|
||||
-f: faiss root path
|
||||
-g: gpu version
|
||||
-x: milvus customization (default: OFF)
|
||||
-u: building unit test options(default: OFF)
|
||||
-l: run cpplint, clang-format and clang-tidy(default: OFF)
|
||||
-c: code coverage(default: OFF)
|
||||
@ -74,7 +79,7 @@ parameter:
|
||||
-h: help
|
||||
|
||||
usage:
|
||||
./build.sh -o \${INSTALL_PREFIX} -t \${BUILD_TYPE} -b \${CORE_BUILD_DIR} -f \${FAISS_ROOT} [-u] [-l] [-c] [-j] [-m] [-h]
|
||||
./build.sh -o \${INSTALL_PREFIX} -t \${BUILD_TYPE} -b \${CORE_BUILD_DIR} -f \${FAISS_ROOT} [-g] [-x] [-u] [-l] [-c] [-j] [-m] [-h]
|
||||
"
|
||||
exit 0
|
||||
;;
|
||||
@ -96,6 +101,7 @@ CMAKE_CMD="cmake \
|
||||
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
|
||||
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \
|
||||
-DMILVUS_GPU_VERSION=${GPU_VERSION} \
|
||||
-DCUSTOMIZATION=${CUSTOMIZATION} \
|
||||
-DBUILD_UNIT_TEST=${BUILD_UNITTEST} \
|
||||
-DBUILD_COVERAGE=${BUILD_COVERAGE} \
|
||||
-DUSE_JFROG_CACHE=${USE_JFROG_CACHE} \
|
||||
|
||||
@ -116,7 +116,7 @@ for test in `ls ${DIR_UNITTEST}`; do
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ${args}
|
||||
echo ${DIR_UNITTEST}/${test} "run failed"
|
||||
exit -1
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
@ -143,7 +143,7 @@ ${LCOV_CMD} -r "${FILE_INFO_OUTPUT}" -o "${FILE_INFO_OUTPUT_NEW}" \
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "gen ${FILE_INFO_OUTPUT_NEW} failed"
|
||||
exit -2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# gen html report
|
||||
|
||||
2
core/.gitignore
vendored
2
core/.gitignore
vendored
@ -9,3 +9,5 @@ output.info
|
||||
output_new.info
|
||||
server.info
|
||||
*.pyc
|
||||
src/grpc/python_gen.h
|
||||
src/grpc/python/
|
||||
|
||||
@ -27,9 +27,7 @@ metric_config:
|
||||
port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534]
|
||||
|
||||
cache_config:
|
||||
|
||||
cpu_cache_capacity: 16 # GB, CPU memory used for cache, must be a positive integer
|
||||
cpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
|
||||
cpu_cache_capacity: 16 # GB, size of CPU memory used for cache, must be a positive integer
|
||||
cache_insert_data: false # whether to load inserted data into cache, must be a boolean
|
||||
|
||||
engine_config:
|
||||
@ -37,7 +35,10 @@ engine_config:
|
||||
# if nq >= use_blas_threshold, use OpenBlas, slower with stable response times
|
||||
gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only
|
||||
|
||||
resource_config:
|
||||
search_resources: # define the device used for search computation
|
||||
- cpu
|
||||
index_build_device: cpu # CPU used for building index
|
||||
gpu_resource_config:
|
||||
enable: false # whether to enable GPU resources
|
||||
cache_capacity: 4 # GB, size of GPU memory per card used for cache, must be a positive integer
|
||||
search_resources: # define the GPU devices used for search computation, must be in format gpux
|
||||
- gpu0
|
||||
build_index_resources: # define the GPU devices used for index building, must be in format gpux
|
||||
- gpu0
|
||||
|
||||
@ -27,10 +27,7 @@ metric_config:
|
||||
port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534]
|
||||
|
||||
cache_config:
|
||||
cpu_cache_capacity: 16 # GB, CPU memory used for cache, must be a positive integer
|
||||
cpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
|
||||
gpu_cache_capacity: 4 # GB, GPU memory used for cache, must be a positive integer
|
||||
gpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
|
||||
cpu_cache_capacity: 16 # GB, size of CPU memory used for cache, must be a positive integer
|
||||
cache_insert_data: false # whether to load inserted data into cache, must be a boolean
|
||||
|
||||
engine_config:
|
||||
@ -38,8 +35,10 @@ engine_config:
|
||||
# if nq >= use_blas_threshold, use OpenBlas, slower with stable response times
|
||||
gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only
|
||||
|
||||
resource_config:
|
||||
search_resources: # define the devices used for search computation, must be in format: cpu or gpux
|
||||
- cpu
|
||||
gpu_resource_config:
|
||||
enable: true # whether to enable GPU resources
|
||||
cache_capacity: 4 # GB, size of GPU memory per card used for cache, must be a positive integer
|
||||
search_resources: # define the GPU devices used for search computation, must be in format gpux
|
||||
- gpu0
|
||||
build_index_resources: # define the GPU devices used for index building, must be in format gpux
|
||||
- gpu0
|
||||
index_build_device: gpu0 # CPU / GPU used for building index, must be in format: cpu or gpux
|
||||
|
||||
3
core/scripts/migration/mysql_6_to_4.sql
Normal file
3
core/scripts/migration/mysql_6_to_4.sql
Normal file
@ -0,0 +1,3 @@
|
||||
alter table Tables drop column owner_table;
|
||||
alter table Tables drop column partition_tag;
|
||||
alter table Tables drop column version;
|
||||
7
core/scripts/migration/sqlite_6_to_4.sql
Normal file
7
core/scripts/migration/sqlite_6_to_4.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE 'TempTables' ( 'id' INTEGER PRIMARY KEY NOT NULL , 'table_id' TEXT UNIQUE NOT NULL , 'state' INTEGER NOT NULL , 'dimension' INTEGER NOT NULL , 'created_on' INTEGER NOT NULL , 'flag' INTEGER DEFAULT 0 NOT NULL , 'index_file_size' INTEGER NOT NULL , 'engine_type' INTEGER NOT NULL , 'nlist' INTEGER NOT NULL , 'metric_type' INTEGER NOT NULL);
|
||||
|
||||
INSERT INTO TempTables SELECT id, table_id, state, dimension, created_on, flag, index_file_size, engine_type, nlist, metric_type FROM Tables;
|
||||
|
||||
DROP TABLE Tables;
|
||||
|
||||
ALTER TABLE TempTables RENAME TO Tables;
|
||||
4
core/src/cache/GpuCacheMgr.cpp
vendored
4
core/src/cache/GpuCacheMgr.cpp
vendored
@ -37,7 +37,7 @@ GpuCacheMgr::GpuCacheMgr() {
|
||||
Status s;
|
||||
|
||||
int64_t gpu_cache_cap;
|
||||
s = config.GetCacheConfigGpuCacheCapacity(gpu_cache_cap);
|
||||
s = config.GetGpuResourceConfigCacheCapacity(gpu_cache_cap);
|
||||
if (!s.ok()) {
|
||||
SERVER_LOG_ERROR << s.message();
|
||||
}
|
||||
@ -45,7 +45,7 @@ GpuCacheMgr::GpuCacheMgr() {
|
||||
cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL << 32);
|
||||
|
||||
float gpu_mem_threshold;
|
||||
s = config.GetCacheConfigGpuCacheThreshold(gpu_mem_threshold);
|
||||
s = config.GetGpuResourceConfigCacheThreshold(gpu_mem_threshold);
|
||||
if (!s.ok()) {
|
||||
SERVER_LOG_ERROR << s.message();
|
||||
}
|
||||
|
||||
@ -84,12 +84,12 @@ DBImpl::Start() {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ENGINE_LOG_TRACE << "DB service start";
|
||||
// ENGINE_LOG_TRACE << "DB service start";
|
||||
shutting_down_.store(false, std::memory_order_release);
|
||||
|
||||
// for distribute version, some nodes are read only
|
||||
if (options_.mode_ != DBOptions::MODE::CLUSTER_READONLY) {
|
||||
ENGINE_LOG_TRACE << "StartTimerTasks";
|
||||
// ENGINE_LOG_TRACE << "StartTimerTasks";
|
||||
bg_timer_thread_ = std::thread(&DBImpl::BackgroundTimerTask, this);
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ DBImpl::Stop() {
|
||||
meta_ptr_->CleanUp();
|
||||
}
|
||||
|
||||
ENGINE_LOG_TRACE << "DB service stop";
|
||||
// ENGINE_LOG_TRACE << "DB service stop";
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -279,6 +279,11 @@ DBImpl::DropPartitionByTag(const std::string& table_id, const std::string& parti
|
||||
|
||||
std::string partition_name;
|
||||
auto status = meta_ptr_->GetPartitionName(table_id, partition_tag, partition_name);
|
||||
if (!status.ok()) {
|
||||
ENGINE_LOG_ERROR << status.message();
|
||||
return status;
|
||||
}
|
||||
|
||||
return DropPartition(partition_name);
|
||||
}
|
||||
|
||||
@ -553,7 +558,7 @@ DBImpl::StartMetricTask() {
|
||||
return;
|
||||
}
|
||||
|
||||
ENGINE_LOG_TRACE << "Start metric task";
|
||||
// ENGINE_LOG_TRACE << "Start metric task";
|
||||
|
||||
server::Metrics::GetInstance().KeepingAliveCounterIncrement(METRIC_ACTION_INTERVAL);
|
||||
int64_t cache_usage = cache::CpuCacheMgr::GetInstance()->CacheUsage();
|
||||
@ -579,7 +584,7 @@ DBImpl::StartMetricTask() {
|
||||
server::Metrics::GetInstance().GPUTemperature();
|
||||
server::Metrics::GetInstance().CPUTemperature();
|
||||
|
||||
ENGINE_LOG_TRACE << "Metric task finished";
|
||||
// ENGINE_LOG_TRACE << "Metric task finished";
|
||||
}
|
||||
|
||||
Status
|
||||
@ -751,7 +756,7 @@ DBImpl::BackgroundMergeFiles(const std::string& table_id) {
|
||||
|
||||
void
|
||||
DBImpl::BackgroundCompaction(std::set<std::string> table_ids) {
|
||||
ENGINE_LOG_TRACE << "Background compaction thread start";
|
||||
// ENGINE_LOG_TRACE << " Background compaction thread start";
|
||||
|
||||
Status status;
|
||||
for (auto& table_id : table_ids) {
|
||||
@ -774,7 +779,7 @@ DBImpl::BackgroundCompaction(std::set<std::string> table_ids) {
|
||||
}
|
||||
meta_ptr_->CleanUpFilesWithTTL(ttl);
|
||||
|
||||
ENGINE_LOG_TRACE << "Background compaction thread exit";
|
||||
// ENGINE_LOG_TRACE << " Background compaction thread exit";
|
||||
}
|
||||
|
||||
void
|
||||
@ -807,7 +812,7 @@ DBImpl::StartBuildIndexTask(bool force) {
|
||||
|
||||
void
|
||||
DBImpl::BackgroundBuildIndex() {
|
||||
ENGINE_LOG_TRACE << "Background build index thread start";
|
||||
// ENGINE_LOG_TRACE << "Background build index thread start";
|
||||
|
||||
std::unique_lock<std::mutex> lock(build_index_mutex_);
|
||||
meta::TableFilesSchema to_index_files;
|
||||
@ -830,7 +835,7 @@ DBImpl::BackgroundBuildIndex() {
|
||||
}
|
||||
}
|
||||
|
||||
ENGINE_LOG_TRACE << "Background build index thread exit";
|
||||
// ENGINE_LOG_TRACE << "Background build index thread exit";
|
||||
}
|
||||
|
||||
Status
|
||||
@ -853,8 +858,12 @@ DBImpl::GetPartitionsByTags(const std::string& table_id, const std::vector<std::
|
||||
auto status = meta_ptr_->ShowPartitions(table_id, partiton_array);
|
||||
|
||||
for (auto& tag : partition_tags) {
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
server::StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
for (auto& schema : partiton_array) {
|
||||
if (server::StringHelpFunctions::IsRegexMatch(schema.partition_tag_, tag)) {
|
||||
if (server::StringHelpFunctions::IsRegexMatch(schema.partition_tag_, valid_tag)) {
|
||||
partition_name_array.insert(schema.table_id_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ static const char* ARCHIVE_CONF_DISK = "disk";
|
||||
static const char* ARCHIVE_CONF_DAYS = "days";
|
||||
|
||||
struct ArchiveConf {
|
||||
using CriteriaT = std::map<std::string, int>;
|
||||
using CriteriaT = std::map<std::string, int64_t>;
|
||||
|
||||
explicit ArchiveConf(const std::string& type, const std::string& criterias = std::string());
|
||||
|
||||
|
||||
@ -35,7 +35,9 @@ enum class EngineType {
|
||||
NSG_MIX,
|
||||
FAISS_IVFSQ8H,
|
||||
FAISS_PQ,
|
||||
MAX_VALUE = FAISS_PQ,
|
||||
SPTAG_KDT,
|
||||
SPTAG_BKT,
|
||||
MAX_VALUE = SPTAG_BKT,
|
||||
};
|
||||
|
||||
enum class MetricType {
|
||||
|
||||
@ -124,6 +124,14 @@ ExecutionEngineImpl::CreatetVecIndex(EngineType type) {
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case EngineType::SPTAG_KDT: {
|
||||
index = GetVecIndexFactory(IndexType::SPTAG_KDT_RNT_CPU);
|
||||
break;
|
||||
}
|
||||
case EngineType::SPTAG_BKT: {
|
||||
index = GetVecIndexFactory(IndexType::SPTAG_BKT_RNT_CPU);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ENGINE_LOG_ERROR << "Unsupported index type";
|
||||
return nullptr;
|
||||
@ -144,7 +152,14 @@ ExecutionEngineImpl::HybridLoad() const {
|
||||
}
|
||||
|
||||
const std::string key = location_ + ".quantizer";
|
||||
std::vector<uint64_t> gpus = scheduler::get_gpu_pool();
|
||||
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::vector<int64_t> gpus;
|
||||
Status s = config.GetGpuResourceConfigSearchResources(gpus);
|
||||
if (!s.ok()) {
|
||||
ENGINE_LOG_ERROR << s.message();
|
||||
return;
|
||||
}
|
||||
|
||||
// cache hit
|
||||
{
|
||||
@ -355,6 +370,7 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
|
||||
|
||||
Status
|
||||
ExecutionEngineImpl::CopyToIndexFileToGpu(uint64_t device_id) {
|
||||
gpu_num_ = device_id;
|
||||
auto to_index_data = std::make_shared<ToIndexData>(PhysicalSize());
|
||||
cache::DataObjPtr obj = std::static_pointer_cast<cache::DataObj>(to_index_data);
|
||||
milvus::cache::GpuCacheMgr::GetInstance(device_id)->InsertItem(location_, obj);
|
||||
@ -578,12 +594,16 @@ ExecutionEngineImpl::GpuCache(uint64_t gpu_id) {
|
||||
Status
|
||||
ExecutionEngineImpl::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
Status s = config.GetResourceConfigIndexBuildDevice(gpu_num_);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
std::vector<int64_t> gpu_ids;
|
||||
Status s = config.GetGpuResourceConfigBuildIndexResources(gpu_ids);
|
||||
for (auto id : gpu_ids) {
|
||||
if (gpu_num_ == id) {
|
||||
return Status::OK();
|
||||
}
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
std::string msg = "Invalid gpu_num";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
||||
@ -122,8 +122,8 @@ class ExecutionEngineImpl : public ExecutionEngine {
|
||||
int64_t dim_;
|
||||
std::string location_;
|
||||
|
||||
int32_t nlist_ = 0;
|
||||
int32_t gpu_num_ = 0;
|
||||
int64_t nlist_ = 0;
|
||||
int64_t gpu_num_ = 0;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "metrics/Metrics.h"
|
||||
#include "utils/Exception.h"
|
||||
#include "utils/Log.h"
|
||||
#include "utils/StringHelpFunctions.h"
|
||||
|
||||
#include <mysql++/mysql++.h>
|
||||
#include <string.h>
|
||||
@ -1162,17 +1163,23 @@ MySQLMetaImpl::CreatePartition(const std::string& table_id, const std::string& p
|
||||
|
||||
// not allow create partition under partition
|
||||
if (!table_schema.owner_table_.empty()) {
|
||||
return Status(DB_ERROR, "Nested partition is not allow");
|
||||
return Status(DB_ERROR, "Nested partition is not allowed");
|
||||
}
|
||||
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
server::StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
|
||||
// not allow duplicated partition
|
||||
std::string exist_partition;
|
||||
GetPartitionName(table_id, valid_tag, exist_partition);
|
||||
if (!exist_partition.empty()) {
|
||||
return Status(DB_ERROR, "Duplicate partition is not allowed");
|
||||
}
|
||||
|
||||
if (partition_name == "") {
|
||||
// not allow duplicated partition
|
||||
std::string exist_partition;
|
||||
GetPartitionName(table_id, tag, exist_partition);
|
||||
if (!exist_partition.empty()) {
|
||||
return Status(DB_ERROR, "Duplicated partition is not allow");
|
||||
}
|
||||
|
||||
// generate unique partition name
|
||||
NextTableId(table_schema.table_id_);
|
||||
} else {
|
||||
table_schema.table_id_ = partition_name;
|
||||
@ -1182,9 +1189,14 @@ MySQLMetaImpl::CreatePartition(const std::string& table_id, const std::string& p
|
||||
table_schema.flag_ = 0;
|
||||
table_schema.created_on_ = utils::GetMicroSecTimeStamp();
|
||||
table_schema.owner_table_ = table_id;
|
||||
table_schema.partition_tag_ = tag;
|
||||
table_schema.partition_tag_ = valid_tag;
|
||||
|
||||
return CreateTable(table_schema);
|
||||
status = CreateTable(table_schema);
|
||||
if (status.code() == DB_ALREADY_EXIST) {
|
||||
return Status(DB_ALREADY_EXIST, "Partition already exists");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Status
|
||||
@ -1231,6 +1243,12 @@ MySQLMetaImpl::GetPartitionName(const std::string& table_id, const std::string&
|
||||
try {
|
||||
server::MetricCollector metric;
|
||||
mysqlpp::StoreQueryResult res;
|
||||
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
server::StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
|
||||
{
|
||||
mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_);
|
||||
|
||||
@ -1240,7 +1258,7 @@ MySQLMetaImpl::GetPartitionName(const std::string& table_id, const std::string&
|
||||
|
||||
mysqlpp::Query allPartitionsQuery = connectionPtr->query();
|
||||
allPartitionsQuery << "SELECT table_id FROM " << META_TABLES << " WHERE owner_table = " << mysqlpp::quote
|
||||
<< table_id << " AND partition_tag = " << mysqlpp::quote << tag << " AND state <> "
|
||||
<< table_id << " AND partition_tag = " << mysqlpp::quote << valid_tag << " AND state <> "
|
||||
<< std::to_string(TableSchema::TO_DELETE) << ";";
|
||||
|
||||
ENGINE_LOG_DEBUG << "MySQLMetaImpl::AllTables: " << allPartitionsQuery.str();
|
||||
@ -1252,7 +1270,7 @@ MySQLMetaImpl::GetPartitionName(const std::string& table_id, const std::string&
|
||||
const mysqlpp::Row& resRow = res[0];
|
||||
resRow["table_id"].to_string(partition_name);
|
||||
} else {
|
||||
return Status(DB_NOT_FOUND, "Partition " + tag + " of table " + table_id + " not found");
|
||||
return Status(DB_NOT_FOUND, "Partition " + valid_tag + " of table " + table_id + " not found");
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
return HandleException("GENERAL ERROR WHEN GET PARTITION NAME", e.what());
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "metrics/Metrics.h"
|
||||
#include "utils/Exception.h"
|
||||
#include "utils/Log.h"
|
||||
#include "utils/StringHelpFunctions.h"
|
||||
|
||||
#include <sqlite_orm.h>
|
||||
#include <unistd.h>
|
||||
@ -757,17 +758,23 @@ SqliteMetaImpl::CreatePartition(const std::string& table_id, const std::string&
|
||||
|
||||
// not allow create partition under partition
|
||||
if(!table_schema.owner_table_.empty()) {
|
||||
return Status(DB_ERROR, "Nested partition is not allow");
|
||||
return Status(DB_ERROR, "Nested partition is not allowed");
|
||||
}
|
||||
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
server::StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
|
||||
// not allow duplicated partition
|
||||
std::string exist_partition;
|
||||
GetPartitionName(table_id, valid_tag, exist_partition);
|
||||
if(!exist_partition.empty()) {
|
||||
return Status(DB_ERROR, "Duplicate partition is not allowed");
|
||||
}
|
||||
|
||||
if (partition_name == "") {
|
||||
// not allow duplicated partition
|
||||
std::string exist_partition;
|
||||
GetPartitionName(table_id, tag, exist_partition);
|
||||
if(!exist_partition.empty()) {
|
||||
return Status(DB_ERROR, "Duplicated partition is not allow");
|
||||
}
|
||||
|
||||
// generate unique partition name
|
||||
NextTableId(table_schema.table_id_);
|
||||
} else {
|
||||
table_schema.table_id_ = partition_name;
|
||||
@ -777,9 +784,14 @@ SqliteMetaImpl::CreatePartition(const std::string& table_id, const std::string&
|
||||
table_schema.flag_ = 0;
|
||||
table_schema.created_on_ = utils::GetMicroSecTimeStamp();
|
||||
table_schema.owner_table_ = table_id;
|
||||
table_schema.partition_tag_ = tag;
|
||||
table_schema.partition_tag_ = valid_tag;
|
||||
|
||||
return CreateTable(table_schema);
|
||||
status = CreateTable(table_schema);
|
||||
if (status.code() == DB_ALREADY_EXIST) {
|
||||
return Status(DB_ALREADY_EXIST, "Partition already exists");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Status
|
||||
@ -814,13 +826,18 @@ SqliteMetaImpl::GetPartitionName(const std::string& table_id, const std::string&
|
||||
try {
|
||||
server::MetricCollector metric;
|
||||
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
server::StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
|
||||
auto name = ConnectorPtr->select(columns(&TableSchema::table_id_),
|
||||
where(c(&TableSchema::owner_table_) == table_id
|
||||
and c(&TableSchema::partition_tag_) == tag));
|
||||
and c(&TableSchema::partition_tag_) == valid_tag));
|
||||
if (name.size() > 0) {
|
||||
partition_name = std::get<0>(name[0]);
|
||||
} else {
|
||||
return Status(DB_NOT_FOUND, "Table " + table_id + "'s partition " + tag + " not found");
|
||||
return Status(DB_NOT_FOUND, "Table " + table_id + "'s partition " + valid_tag + " not found");
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
return HandleException("Encounter exception when get partition name", e.what());
|
||||
|
||||
@ -1321,8 +1321,7 @@ class RowRecord :
|
||||
void clear_vector_data();
|
||||
float vector_data(int index) const;
|
||||
void set_vector_data(int index, float value);
|
||||
// void add_vector_data(float value);
|
||||
void add_vector_data(std::vector<float>::const_iterator begin, std::vector<float>::const_iterator end);
|
||||
void add_vector_data(float value);
|
||||
const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >&
|
||||
vector_data() const;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedField< float >*
|
||||
@ -1474,9 +1473,7 @@ class InsertParam :
|
||||
void clear_row_id_array();
|
||||
::PROTOBUF_NAMESPACE_ID::int64 row_id_array(int index) const;
|
||||
void set_row_id_array(int index, ::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
// void add_row_id_array(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
void add_row_id_array(std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator begin,
|
||||
std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator end);
|
||||
void add_row_id_array(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >&
|
||||
row_id_array() const;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >*
|
||||
@ -2139,9 +2136,7 @@ class TopKQueryResult :
|
||||
void clear_ids();
|
||||
::PROTOBUF_NAMESPACE_ID::int64 ids(int index) const;
|
||||
void set_ids(int index, ::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
// void add_ids(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
void add_ids(std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator begin,
|
||||
std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator end);
|
||||
void add_ids(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >&
|
||||
ids() const;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >*
|
||||
@ -2152,8 +2147,7 @@ class TopKQueryResult :
|
||||
void clear_distances();
|
||||
float distances(int index) const;
|
||||
void set_distances(int index, float value);
|
||||
// void add_distances(float value);
|
||||
void add_distances(std::vector<float>::const_iterator begin, std::vector<float>::const_iterator end);
|
||||
void add_distances(float value);
|
||||
const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >&
|
||||
distances() const;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedField< float >*
|
||||
@ -3928,14 +3922,9 @@ inline void RowRecord::set_vector_data(int index, float value) {
|
||||
vector_data_.Set(index, value);
|
||||
// @@protoc_insertion_point(field_set:milvus.grpc.RowRecord.vector_data)
|
||||
}
|
||||
//inline void RowRecord::add_vector_data(float value) {
|
||||
// vector_data_.Add(value);
|
||||
// // @@protoc_insertion_point(field_add:milvus.grpc.RowRecord.vector_data)
|
||||
//}
|
||||
inline void RowRecord::add_vector_data(std::vector<float>::const_iterator begin,
|
||||
std::vector<float>::const_iterator end) {
|
||||
vector_data_.Add(begin, end);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.RowRecord.vector_data)
|
||||
inline void RowRecord::add_vector_data(float value) {
|
||||
vector_data_.Add(value);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.RowRecord.vector_data)
|
||||
}
|
||||
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >&
|
||||
RowRecord::vector_data() const {
|
||||
@ -4048,14 +4037,9 @@ inline void InsertParam::set_row_id_array(int index, ::PROTOBUF_NAMESPACE_ID::in
|
||||
row_id_array_.Set(index, value);
|
||||
// @@protoc_insertion_point(field_set:milvus.grpc.InsertParam.row_id_array)
|
||||
}
|
||||
//inline void InsertParam::add_row_id_array(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
// row_id_array_.Add(value);
|
||||
// // @@protoc_insertion_point(field_add:milvus.grpc.InsertParam.row_id_array)
|
||||
//}
|
||||
inline void InsertParam::add_row_id_array(std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator begin,
|
||||
std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator end) {
|
||||
row_id_array_.Add(begin, end);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.InsertParam.row_id_array)
|
||||
inline void InsertParam::add_row_id_array(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
row_id_array_.Add(value);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.InsertParam.row_id_array)
|
||||
}
|
||||
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >&
|
||||
InsertParam::row_id_array() const {
|
||||
@ -4604,14 +4588,9 @@ inline void TopKQueryResult::set_ids(int index, ::PROTOBUF_NAMESPACE_ID::int64 v
|
||||
ids_.Set(index, value);
|
||||
// @@protoc_insertion_point(field_set:milvus.grpc.TopKQueryResult.ids)
|
||||
}
|
||||
//inline void TopKQueryResult::add_ids(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
// ids_.Add(value);
|
||||
// // @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.ids)
|
||||
//}
|
||||
inline void TopKQueryResult::add_ids(std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator begin,
|
||||
std::vector<::PROTOBUF_NAMESPACE_ID::int64>::const_iterator end) {
|
||||
ids_.Add(begin,end);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.ids)
|
||||
inline void TopKQueryResult::add_ids(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
ids_.Add(value);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.ids)
|
||||
}
|
||||
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::int64 >&
|
||||
TopKQueryResult::ids() const {
|
||||
@ -4639,13 +4618,9 @@ inline void TopKQueryResult::set_distances(int index, float value) {
|
||||
distances_.Set(index, value);
|
||||
// @@protoc_insertion_point(field_set:milvus.grpc.TopKQueryResult.distances)
|
||||
}
|
||||
//inline void TopKQueryResult::add_distances(float value) {
|
||||
// distances_.Add(value);
|
||||
// // @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.distances)
|
||||
//}
|
||||
inline void TopKQueryResult::add_distances(std::vector<float>::const_iterator begin, std::vector<float>::const_iterator end) {
|
||||
distances_.Add(begin, end);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.distances)
|
||||
inline void TopKQueryResult::add_distances(float value) {
|
||||
distances_.Add(value);
|
||||
// @@protoc_insertion_point(field_add:milvus.grpc.TopKQueryResult.distances)
|
||||
}
|
||||
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >&
|
||||
TopKQueryResult::distances() const {
|
||||
|
||||
@ -88,14 +88,14 @@ endif ()
|
||||
include(ThirdPartyPackagesCore)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp -mavx -mf16c -msse4 -mpopcnt")
|
||||
if (KNOWHERE_GPU_VERSION)
|
||||
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3")
|
||||
endif ()
|
||||
else ()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE -fopenmp")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -fPIC -DELPP_THREAD_SAFE -fopenmp -mavx -mf16c -msse4 -mpopcnt")
|
||||
if (KNOWHERE_GPU_VERSION)
|
||||
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O0 -g")
|
||||
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3 -g")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
||||
@ -733,7 +733,16 @@ macro(build_faiss)
|
||||
|
||||
if (USE_JFROG_CACHE STREQUAL "ON")
|
||||
string(MD5 FAISS_COMBINE_MD5 "${FAISS_MD5}${LAPACK_MD5}${OPENBLAS_MD5}")
|
||||
set(FAISS_CACHE_PACKAGE_NAME "faiss_${FAISS_COMBINE_MD5}.tar.gz")
|
||||
if (KNOWHERE_GPU_VERSION)
|
||||
set(FAISS_COMPUTE_TYPE "gpu")
|
||||
else ()
|
||||
set(FAISS_COMPUTE_TYPE "cpu")
|
||||
endif()
|
||||
if (FAISS_WITH_MKL)
|
||||
set(FAISS_CACHE_PACKAGE_NAME "faiss_${FAISS_COMPUTE_TYPE}_mkl_${FAISS_COMBINE_MD5}.tar.gz")
|
||||
else ()
|
||||
set(FAISS_CACHE_PACKAGE_NAME "faiss_${FAISS_COMPUTE_TYPE}_openblas_${FAISS_COMBINE_MD5}.tar.gz")
|
||||
endif()
|
||||
set(FAISS_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${FAISS_CACHE_PACKAGE_NAME}")
|
||||
set(FAISS_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${FAISS_CACHE_PACKAGE_NAME}")
|
||||
|
||||
|
||||
@ -30,10 +30,10 @@ set(external_srcs
|
||||
|
||||
set(index_srcs
|
||||
knowhere/index/preprocessor/Normalize.cpp
|
||||
knowhere/index/vector_index/IndexKDT.cpp
|
||||
knowhere/index/vector_index/IndexSPTAG.cpp
|
||||
knowhere/index/vector_index/IndexIDMAP.cpp
|
||||
knowhere/index/vector_index/IndexIVF.cpp
|
||||
knowhere/index/vector_index/helpers/KDTParameterMgr.cpp
|
||||
knowhere/index/vector_index/helpers/SPTAGParameterMgr.cpp
|
||||
knowhere/index/vector_index/IndexNSG.cpp
|
||||
knowhere/index/vector_index/nsg/NSG.cpp
|
||||
knowhere/index/vector_index/nsg/NSGIO.cpp
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "Log.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
@ -50,6 +52,18 @@ struct Cfg {
|
||||
CheckValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Dump() {
|
||||
KNOWHERE_LOG_DEBUG << DumpImpl().str();
|
||||
}
|
||||
|
||||
virtual std::stringstream
|
||||
DumpImpl() {
|
||||
std::stringstream ss;
|
||||
ss << "dim: " << d << ", metric: " << int(metric_type) << ", gpuid: " << gpu_id << ", k: " << k;
|
||||
return ss;
|
||||
}
|
||||
};
|
||||
using Config = std::shared_ptr<Cfg>;
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ FaissBaseIndex::SerializeImpl() {
|
||||
try {
|
||||
faiss::Index* index = index_.get();
|
||||
|
||||
SealImpl();
|
||||
// SealImpl();
|
||||
|
||||
MemoryIOWriter writer;
|
||||
faiss::write_index(index, &writer);
|
||||
@ -60,6 +60,8 @@ FaissBaseIndex::LoadImpl(const BinarySet& index_binary) {
|
||||
faiss::Index* index = faiss::read_index(&reader);
|
||||
|
||||
index_.reset(index);
|
||||
|
||||
SealImpl();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@ -86,9 +86,6 @@ GPUIVF::SerializeImpl() {
|
||||
faiss::Index* index = index_.get();
|
||||
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu(index);
|
||||
|
||||
// TODO(linxj): support seal
|
||||
// SealImpl();
|
||||
|
||||
faiss::write_index(host_index, &writer);
|
||||
delete host_index;
|
||||
}
|
||||
|
||||
@ -97,7 +97,6 @@ IVF::Serialize() {
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lk(mutex_);
|
||||
Seal();
|
||||
return SerializeImpl();
|
||||
}
|
||||
|
||||
|
||||
@ -1,180 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <SPTAG/AnnService/inc/Core/Common.h>
|
||||
#include <SPTAG/AnnService/inc/Core/VectorSet.h>
|
||||
#include <SPTAG/AnnService/inc/Server/QueryParser.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#undef mkdir
|
||||
|
||||
#include "knowhere/index/vector_index/IndexKDT.h"
|
||||
#include "knowhere/index/vector_index/helpers/Definitions.h"
|
||||
//#include "knowhere/index/preprocessor/normalize.h"
|
||||
#include "knowhere/adapter/SptagAdapter.h"
|
||||
#include "knowhere/common/Exception.h"
|
||||
#include "knowhere/index/vector_index/helpers/KDTParameterMgr.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
BinarySet
|
||||
CPUKDTRNG::Serialize() {
|
||||
std::vector<void*> index_blobs;
|
||||
std::vector<int64_t> index_len;
|
||||
|
||||
// TODO(zirui): dev
|
||||
// index_ptr_->SaveIndexToMemory(index_blobs, index_len);
|
||||
BinarySet binary_set;
|
||||
|
||||
//
|
||||
// auto sample = std::make_shared<uint8_t>();
|
||||
// sample.reset(static_cast<uint8_t*>(index_blobs[0]));
|
||||
// auto tree = std::make_shared<uint8_t>();
|
||||
// tree.reset(static_cast<uint8_t*>(index_blobs[1]));
|
||||
// auto graph = std::make_shared<uint8_t>();
|
||||
// graph.reset(static_cast<uint8_t*>(index_blobs[2]));
|
||||
// auto metadata = std::make_shared<uint8_t>();
|
||||
// metadata.reset(static_cast<uint8_t*>(index_blobs[3]));
|
||||
//
|
||||
// binary_set.Append("samples", sample, index_len[0]);
|
||||
// binary_set.Append("tree", tree, index_len[1]);
|
||||
// binary_set.Append("graph", graph, index_len[2]);
|
||||
// binary_set.Append("metadata", metadata, index_len[3]);
|
||||
return binary_set;
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::Load(const BinarySet& binary_set) {
|
||||
// TODO(zirui): dev
|
||||
|
||||
// std::vector<void*> index_blobs;
|
||||
//
|
||||
// auto samples = binary_set.GetByName("samples");
|
||||
// index_blobs.push_back(samples->data.get());
|
||||
//
|
||||
// auto tree = binary_set.GetByName("tree");
|
||||
// index_blobs.push_back(tree->data.get());
|
||||
//
|
||||
// auto graph = binary_set.GetByName("graph");
|
||||
// index_blobs.push_back(graph->data.get());
|
||||
//
|
||||
// auto metadata = binary_set.GetByName("metadata");
|
||||
// index_blobs.push_back(metadata->data.get());
|
||||
//
|
||||
// index_ptr_->LoadIndexFromMemory(index_blobs);
|
||||
}
|
||||
|
||||
// PreprocessorPtr
|
||||
// CPUKDTRNG::BuildPreprocessor(const DatasetPtr &dataset, const Config &config) {
|
||||
// return std::make_shared<NormalizePreprocessor>();
|
||||
//}
|
||||
|
||||
IndexModelPtr
|
||||
CPUKDTRNG::Train(const DatasetPtr& origin, const Config& train_config) {
|
||||
SetParameters(train_config);
|
||||
DatasetPtr dataset = origin->Clone();
|
||||
|
||||
// if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
// && preprocessor_) {
|
||||
// preprocessor_->Preprocess(dataset);
|
||||
//}
|
||||
|
||||
auto vectorset = ConvertToVectorSet(dataset);
|
||||
auto metaset = ConvertToMetadataSet(dataset);
|
||||
index_ptr_->BuildIndex(vectorset, metaset);
|
||||
|
||||
// TODO: return IndexModelPtr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::Add(const DatasetPtr& origin, const Config& add_config) {
|
||||
SetParameters(add_config);
|
||||
DatasetPtr dataset = origin->Clone();
|
||||
|
||||
// if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
// && preprocessor_) {
|
||||
// preprocessor_->Preprocess(dataset);
|
||||
//}
|
||||
|
||||
auto vectorset = ConvertToVectorSet(dataset);
|
||||
auto metaset = ConvertToMetadataSet(dataset);
|
||||
index_ptr_->AddIndex(vectorset, metaset);
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::SetParameters(const Config& config) {
|
||||
for (auto& para : KDTParameterMgr::GetInstance().GetKDTParameters()) {
|
||||
// auto value = config.get_with_default(para.first, para.second);
|
||||
index_ptr_->SetParameter(para.first, para.second);
|
||||
}
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
CPUKDTRNG::Search(const DatasetPtr& dataset, const Config& config) {
|
||||
SetParameters(config);
|
||||
auto tensor = dataset->tensor()[0];
|
||||
auto p = (float*)tensor->raw_mutable_data();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
for (auto j = 0; j < 10; ++j) {
|
||||
std::cout << p[i * 10 + j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::vector<SPTAG::QueryResult> query_results = ConvertToQueryResult(dataset, config);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (auto i = 0; i < query_results.size(); ++i) {
|
||||
auto target = (float*)query_results[i].GetTarget();
|
||||
std::cout << target[0] << ", " << target[1] << ", " << target[2] << std::endl;
|
||||
index_ptr_->SearchIndex(query_results[i]);
|
||||
}
|
||||
|
||||
return ConvertToDataset(query_results);
|
||||
}
|
||||
|
||||
int64_t
|
||||
CPUKDTRNG::Count() {
|
||||
index_ptr_->GetNumSamples();
|
||||
}
|
||||
|
||||
int64_t
|
||||
CPUKDTRNG::Dimension() {
|
||||
index_ptr_->GetFeatureDim();
|
||||
}
|
||||
|
||||
VectorIndexPtr
|
||||
CPUKDTRNG::Clone() {
|
||||
KNOWHERE_THROW_MSG("not support");
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNG::Seal() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// TODO(linxj):
|
||||
BinarySet
|
||||
CPUKDTRNGIndexModel::Serialize() {
|
||||
}
|
||||
|
||||
void
|
||||
CPUKDTRNGIndexModel::Load(const BinarySet& binary) {
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
@ -0,0 +1,348 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <SPTAG/AnnService/inc/Core/Common.h>
|
||||
#include <SPTAG/AnnService/inc/Core/VectorSet.h>
|
||||
#include <SPTAG/AnnService/inc/Server/QueryParser.h>
|
||||
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#undef mkdir
|
||||
|
||||
#include "knowhere/adapter/SptagAdapter.h"
|
||||
#include "knowhere/common/Exception.h"
|
||||
#include "knowhere/index/vector_index/IndexSPTAG.h"
|
||||
#include "knowhere/index/vector_index/helpers/Definitions.h"
|
||||
#include "knowhere/index/vector_index/helpers/SPTAGParameterMgr.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
CPUSPTAGRNG::CPUSPTAGRNG(const std::string& IndexType) {
|
||||
if (IndexType == "KDT") {
|
||||
index_ptr_ = SPTAG::VectorIndex::CreateInstance(SPTAG::IndexAlgoType::KDT, SPTAG::VectorValueType::Float);
|
||||
index_ptr_->SetParameter("DistCalcMethod", "L2");
|
||||
index_type_ = SPTAG::IndexAlgoType::KDT;
|
||||
} else {
|
||||
index_ptr_ = SPTAG::VectorIndex::CreateInstance(SPTAG::IndexAlgoType::BKT, SPTAG::VectorValueType::Float);
|
||||
index_ptr_->SetParameter("DistCalcMethod", "L2");
|
||||
index_type_ = SPTAG::IndexAlgoType::BKT;
|
||||
}
|
||||
}
|
||||
|
||||
BinarySet
|
||||
CPUSPTAGRNG::Serialize() {
|
||||
std::string index_config;
|
||||
std::vector<SPTAG::ByteArray> index_blobs;
|
||||
|
||||
std::shared_ptr<std::vector<std::uint64_t>> buffersize = index_ptr_->CalculateBufferSize();
|
||||
std::vector<char*> res(buffersize->size() + 1);
|
||||
for (uint64_t i = 1; i < res.size(); i++) {
|
||||
res[i] = new char[buffersize->at(i - 1)];
|
||||
auto ptr = &res[i][0];
|
||||
index_blobs.emplace_back(SPTAG::ByteArray((std::uint8_t*)ptr, buffersize->at(i - 1), false));
|
||||
}
|
||||
|
||||
index_ptr_->SaveIndex(index_config, index_blobs);
|
||||
|
||||
size_t length = index_config.length();
|
||||
char* cstr = new char[length];
|
||||
snprintf(cstr, length, "%s", index_config.c_str());
|
||||
|
||||
BinarySet binary_set;
|
||||
auto sample = std::make_shared<uint8_t>();
|
||||
sample.reset(static_cast<uint8_t*>(index_blobs[0].Data()));
|
||||
auto tree = std::make_shared<uint8_t>();
|
||||
tree.reset(static_cast<uint8_t*>(index_blobs[1].Data()));
|
||||
auto graph = std::make_shared<uint8_t>();
|
||||
graph.reset(static_cast<uint8_t*>(index_blobs[2].Data()));
|
||||
auto deleteid = std::make_shared<uint8_t>();
|
||||
deleteid.reset(static_cast<uint8_t*>(index_blobs[3].Data()));
|
||||
auto metadata1 = std::make_shared<uint8_t>();
|
||||
metadata1.reset(static_cast<uint8_t*>(index_blobs[4].Data()));
|
||||
auto metadata2 = std::make_shared<uint8_t>();
|
||||
metadata2.reset(static_cast<uint8_t*>(index_blobs[5].Data()));
|
||||
auto config = std::make_shared<uint8_t>();
|
||||
config.reset(static_cast<uint8_t*>((void*)cstr));
|
||||
|
||||
binary_set.Append("samples", sample, index_blobs[0].Length());
|
||||
binary_set.Append("tree", tree, index_blobs[1].Length());
|
||||
binary_set.Append("deleteid", deleteid, index_blobs[3].Length());
|
||||
binary_set.Append("metadata1", metadata1, index_blobs[4].Length());
|
||||
binary_set.Append("metadata2", metadata2, index_blobs[5].Length());
|
||||
binary_set.Append("config", config, length);
|
||||
binary_set.Append("graph", graph, index_blobs[2].Length());
|
||||
|
||||
// MemoryIOWriter writer;
|
||||
// size_t len = 0;
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// len = index_blobs[i].Length();
|
||||
// assert(len != 0);
|
||||
// writer(&len, sizeof(size_t), 1);
|
||||
// writer(index_blobs[i].Data(), len, 1);
|
||||
// len = 0;
|
||||
// }
|
||||
// writer(&length, sizeof(size_t), 1);
|
||||
// writer(cstr, length, 1);
|
||||
// auto data = std::make_shared<uint8_t>();
|
||||
// data.reset(writer.data_);
|
||||
// BinarySet binary_set;
|
||||
// binary_set.Append("sptag", data, writer.total);
|
||||
|
||||
// MemoryIOWriter writer;
|
||||
// size_t len = 0;
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// if (i == 2) continue;
|
||||
// len = index_blobs[i].Length();
|
||||
// assert(len != 0);
|
||||
// writer(&len, sizeof(size_t), 1);
|
||||
// writer(index_blobs[i].Data(), len, 1);
|
||||
// len = 0;
|
||||
// }
|
||||
// writer(&length, sizeof(size_t), 1);
|
||||
// writer(cstr, length, 1);
|
||||
// auto data = std::make_shared<uint8_t>();
|
||||
// data.reset(writer.data_);
|
||||
// BinarySet binary_set;
|
||||
// binary_set.Append("sptag", data, writer.total);
|
||||
// auto graph = std::make_shared<uint8_t>();
|
||||
// graph.reset(static_cast<uint8_t*>(index_blobs[2].Data()));
|
||||
// binary_set.Append("graph", graph, index_blobs[2].Length());
|
||||
|
||||
return binary_set;
|
||||
}
|
||||
|
||||
void
|
||||
CPUSPTAGRNG::Load(const BinarySet& binary_set) {
|
||||
std::string index_config;
|
||||
std::vector<SPTAG::ByteArray> index_blobs;
|
||||
|
||||
auto samples = binary_set.GetByName("samples");
|
||||
index_blobs.push_back(SPTAG::ByteArray(samples->data.get(), samples->size, false));
|
||||
|
||||
auto tree = binary_set.GetByName("tree");
|
||||
index_blobs.push_back(SPTAG::ByteArray(tree->data.get(), tree->size, false));
|
||||
|
||||
auto graph = binary_set.GetByName("graph");
|
||||
index_blobs.push_back(SPTAG::ByteArray(graph->data.get(), graph->size, false));
|
||||
|
||||
auto deleteid = binary_set.GetByName("deleteid");
|
||||
index_blobs.push_back(SPTAG::ByteArray(deleteid->data.get(), deleteid->size, false));
|
||||
|
||||
auto metadata1 = binary_set.GetByName("metadata1");
|
||||
index_blobs.push_back(SPTAG::ByteArray(metadata1->data.get(), metadata1->size, false));
|
||||
|
||||
auto metadata2 = binary_set.GetByName("metadata2");
|
||||
index_blobs.push_back(SPTAG::ByteArray(metadata2->data.get(), metadata2->size, false));
|
||||
|
||||
auto config = binary_set.GetByName("config");
|
||||
index_config = reinterpret_cast<char*>(config->data.get());
|
||||
|
||||
// std::vector<SPTAG::ByteArray> index_blobs;
|
||||
// auto data = binary_set.GetByName("sptag");
|
||||
// MemoryIOReader reader;
|
||||
// reader.total = data->size;
|
||||
// reader.data_ = data->data.get();
|
||||
// size_t len = 0;
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// reader(&len, sizeof(size_t), 1);
|
||||
// assert(len != 0);
|
||||
// auto binary = new uint8_t[len];
|
||||
// reader(binary, len, 1);
|
||||
// index_blobs.emplace_back(SPTAG::ByteArray(binary, len, true));
|
||||
// len = 0;
|
||||
// }
|
||||
// reader(&len, sizeof(size_t), 1);
|
||||
// assert(len != 0);
|
||||
// auto config = new char[len];
|
||||
// reader(config, len, 1);
|
||||
// std::string index_config = config;
|
||||
// delete[] config;
|
||||
|
||||
// std::vector<SPTAG::ByteArray> index_blobs;
|
||||
// auto data = binary_set.GetByName("sptag");
|
||||
// MemoryIOReader reader;
|
||||
// reader.total = data->size;
|
||||
// reader.data_ = data->data.get();
|
||||
// size_t len = 0;
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// if (i == 2) {
|
||||
// auto graph = binary_set.GetByName("graph");
|
||||
// index_blobs.emplace_back(SPTAG::ByteArray(graph->data.get(), graph->size, false));
|
||||
// continue;
|
||||
// }
|
||||
// reader(&len, sizeof(size_t), 1);
|
||||
// assert(len != 0);
|
||||
// auto binary = new uint8_t[len];
|
||||
// reader(binary, len, 1);
|
||||
// index_blobs.emplace_back(SPTAG::ByteArray(binary, len, true));
|
||||
// len = 0;
|
||||
// }
|
||||
// reader(&len, sizeof(size_t), 1);
|
||||
// assert(len != 0);
|
||||
// auto config = new char[len];
|
||||
// reader(config, len, 1);
|
||||
// std::string index_config = config;
|
||||
// delete[] config;
|
||||
index_ptr_->LoadIndex(index_config, index_blobs);
|
||||
}
|
||||
|
||||
// PreprocessorPtr
|
||||
// CPUKDTRNG::BuildPreprocessor(const DatasetPtr &dataset, const Config &config) {
|
||||
// return std::make_shared<NormalizePreprocessor>();
|
||||
//}
|
||||
|
||||
IndexModelPtr
|
||||
CPUSPTAGRNG::Train(const DatasetPtr& origin, const Config& train_config) {
|
||||
SetParameters(train_config);
|
||||
DatasetPtr dataset = origin->Clone();
|
||||
|
||||
// if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
// && preprocessor_) {
|
||||
// preprocessor_->Preprocess(dataset);
|
||||
//}
|
||||
|
||||
auto vectorset = ConvertToVectorSet(dataset);
|
||||
auto metaset = ConvertToMetadataSet(dataset);
|
||||
index_ptr_->BuildIndex(vectorset, metaset);
|
||||
|
||||
// TODO: return IndexModelPtr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
CPUSPTAGRNG::Add(const DatasetPtr& origin, const Config& add_config) {
|
||||
// SetParameters(add_config);
|
||||
// DatasetPtr dataset = origin->Clone();
|
||||
//
|
||||
// // if (index_ptr_->GetDistCalcMethod() == SPTAG::DistCalcMethod::Cosine
|
||||
// // && preprocessor_) {
|
||||
// // preprocessor_->Preprocess(dataset);
|
||||
// //}
|
||||
//
|
||||
// auto vectorset = ConvertToVectorSet(dataset);
|
||||
// auto metaset = ConvertToMetadataSet(dataset);
|
||||
// index_ptr_->AddIndex(vectorset, metaset);
|
||||
}
|
||||
|
||||
void
|
||||
CPUSPTAGRNG::SetParameters(const Config& config) {
|
||||
#define Assign(param_name, str_name) \
|
||||
conf->param_name == INVALID_VALUE ? index_ptr_->SetParameter(str_name, std::to_string(build_cfg->param_name)) \
|
||||
: index_ptr_->SetParameter(str_name, std::to_string(conf->param_name))
|
||||
|
||||
if (index_type_ == SPTAG::IndexAlgoType::KDT) {
|
||||
auto conf = std::dynamic_pointer_cast<KDTCfg>(config);
|
||||
auto build_cfg = SPTAGParameterMgr::GetInstance().GetKDTParameters();
|
||||
|
||||
Assign(kdtnumber, "KDTNumber");
|
||||
Assign(numtopdimensionkdtsplit, "NumTopDimensionKDTSplit");
|
||||
Assign(samples, "Samples");
|
||||
Assign(tptnumber, "TPTNumber");
|
||||
Assign(tptleafsize, "TPTLeafSize");
|
||||
Assign(numtopdimensiontptsplit, "NumTopDimensionTPTSplit");
|
||||
Assign(neighborhoodsize, "NeighborhoodSize");
|
||||
Assign(graphneighborhoodscale, "GraphNeighborhoodScale");
|
||||
Assign(graphcefscale, "GraphCEFScale");
|
||||
Assign(refineiterations, "RefineIterations");
|
||||
Assign(cef, "CEF");
|
||||
Assign(maxcheckforrefinegraph, "MaxCheckForRefineGraph");
|
||||
Assign(numofthreads, "NumberOfThreads");
|
||||
Assign(maxcheck, "MaxCheck");
|
||||
Assign(thresholdofnumberofcontinuousnobetterpropagation, "ThresholdOfNumberOfContinuousNoBetterPropagation");
|
||||
Assign(numberofinitialdynamicpivots, "NumberOfInitialDynamicPivots");
|
||||
Assign(numberofotherdynamicpivots, "NumberOfOtherDynamicPivots");
|
||||
} else {
|
||||
auto conf = std::dynamic_pointer_cast<BKTCfg>(config);
|
||||
auto build_cfg = SPTAGParameterMgr::GetInstance().GetBKTParameters();
|
||||
|
||||
Assign(bktnumber, "BKTNumber");
|
||||
Assign(bktkmeansk, "BKTKMeansK");
|
||||
Assign(bktleafsize, "BKTLeafSize");
|
||||
Assign(samples, "Samples");
|
||||
Assign(tptnumber, "TPTNumber");
|
||||
Assign(tptleafsize, "TPTLeafSize");
|
||||
Assign(numtopdimensiontptsplit, "NumTopDimensionTPTSplit");
|
||||
Assign(neighborhoodsize, "NeighborhoodSize");
|
||||
Assign(graphneighborhoodscale, "GraphNeighborhoodScale");
|
||||
Assign(graphcefscale, "GraphCEFScale");
|
||||
Assign(refineiterations, "RefineIterations");
|
||||
Assign(cef, "CEF");
|
||||
Assign(maxcheckforrefinegraph, "MaxCheckForRefineGraph");
|
||||
Assign(numofthreads, "NumberOfThreads");
|
||||
Assign(maxcheck, "MaxCheck");
|
||||
Assign(thresholdofnumberofcontinuousnobetterpropagation, "ThresholdOfNumberOfContinuousNoBetterPropagation");
|
||||
Assign(numberofinitialdynamicpivots, "NumberOfInitialDynamicPivots");
|
||||
Assign(numberofotherdynamicpivots, "NumberOfOtherDynamicPivots");
|
||||
}
|
||||
}
|
||||
|
||||
DatasetPtr
|
||||
CPUSPTAGRNG::Search(const DatasetPtr& dataset, const Config& config) {
|
||||
SetParameters(config);
|
||||
auto tensor = dataset->tensor()[0];
|
||||
auto p = (float*)tensor->raw_mutable_data();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
for (auto j = 0; j < 10; ++j) {
|
||||
std::cout << p[i * 10 + j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::vector<SPTAG::QueryResult> query_results = ConvertToQueryResult(dataset, config);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (auto i = 0; i < query_results.size(); ++i) {
|
||||
auto target = (float*)query_results[i].GetTarget();
|
||||
std::cout << target[0] << ", " << target[1] << ", " << target[2] << std::endl;
|
||||
index_ptr_->SearchIndex(query_results[i]);
|
||||
}
|
||||
|
||||
return ConvertToDataset(query_results);
|
||||
}
|
||||
|
||||
int64_t
|
||||
CPUSPTAGRNG::Count() {
|
||||
return index_ptr_->GetNumSamples();
|
||||
}
|
||||
|
||||
int64_t
|
||||
CPUSPTAGRNG::Dimension() {
|
||||
return index_ptr_->GetFeatureDim();
|
||||
}
|
||||
|
||||
VectorIndexPtr
|
||||
CPUSPTAGRNG::Clone() {
|
||||
KNOWHERE_THROW_MSG("not support");
|
||||
}
|
||||
|
||||
void
|
||||
CPUSPTAGRNG::Seal() {
|
||||
return; // do nothing
|
||||
}
|
||||
|
||||
BinarySet
|
||||
CPUSPTAGRNGIndexModel::Serialize() {
|
||||
// KNOWHERE_THROW_MSG("not support"); // not support
|
||||
}
|
||||
|
||||
void
|
||||
CPUSPTAGRNGIndexModel::Load(const BinarySet& binary) {
|
||||
// KNOWHERE_THROW_MSG("not support"); // not support
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
@ -18,33 +18,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <SPTAG/AnnService/inc/Core/VectorIndex.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "VectorIndex.h"
|
||||
#include "knowhere/index/IndexModel.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
class CPUKDTRNG : public VectorIndex {
|
||||
class CPUSPTAGRNG : public VectorIndex {
|
||||
public:
|
||||
CPUKDTRNG() {
|
||||
index_ptr_ = SPTAG::VectorIndex::CreateInstance(SPTAG::IndexAlgoType::KDT, SPTAG::VectorValueType::Float);
|
||||
index_ptr_->SetParameter("DistCalcMethod", "L2");
|
||||
}
|
||||
explicit CPUSPTAGRNG(const std::string& IndexType);
|
||||
|
||||
public:
|
||||
BinarySet
|
||||
Serialize() override;
|
||||
|
||||
VectorIndexPtr
|
||||
Clone() override;
|
||||
|
||||
void
|
||||
Load(const BinarySet& index_array) override;
|
||||
|
||||
public:
|
||||
// PreprocessorPtr
|
||||
// BuildPreprocessor(const DatasetPtr &dataset, const Config &config) override;
|
||||
|
||||
int64_t
|
||||
Count() override;
|
||||
|
||||
int64_t
|
||||
Dimension() override;
|
||||
|
||||
@ -56,6 +60,7 @@ class CPUKDTRNG : public VectorIndex {
|
||||
|
||||
DatasetPtr
|
||||
Search(const DatasetPtr& dataset, const Config& config) override;
|
||||
|
||||
void
|
||||
Seal() override;
|
||||
|
||||
@ -66,11 +71,12 @@ class CPUKDTRNG : public VectorIndex {
|
||||
private:
|
||||
PreprocessorPtr preprocessor_;
|
||||
std::shared_ptr<SPTAG::VectorIndex> index_ptr_;
|
||||
SPTAG::IndexAlgoType index_type_;
|
||||
};
|
||||
|
||||
using CPUKDTRNGPtr = std::shared_ptr<CPUKDTRNG>;
|
||||
using CPUSPTAGRNGPtr = std::shared_ptr<CPUSPTAGRNG>;
|
||||
|
||||
class CPUKDTRNGIndexModel : public IndexModel {
|
||||
class CPUSPTAGRNGIndexModel : public IndexModel {
|
||||
public:
|
||||
BinarySet
|
||||
Serialize() override;
|
||||
@ -82,6 +88,6 @@ class CPUKDTRNGIndexModel : public IndexModel {
|
||||
std::shared_ptr<SPTAG::VectorIndex> index_;
|
||||
};
|
||||
|
||||
using CPUKDTRNGIndexModelPtr = std::shared_ptr<CPUKDTRNGIndexModel>;
|
||||
using CPUSPTAGRNGIndexModelPtr = std::shared_ptr<CPUSPTAGRNGIndexModel>;
|
||||
|
||||
} // namespace knowhere
|
||||
@ -34,4 +34,26 @@ GetMetricType(METRICTYPE& type) {
|
||||
KNOWHERE_THROW_MSG("Metric type is invalid");
|
||||
}
|
||||
|
||||
std::stringstream
|
||||
IVFCfg::DumpImpl() {
|
||||
auto ss = Cfg::DumpImpl();
|
||||
ss << ", nlist: " << nlist << ", nprobe: " << nprobe;
|
||||
return ss;
|
||||
}
|
||||
|
||||
std::stringstream
|
||||
IVFSQCfg::DumpImpl() {
|
||||
auto ss = IVFCfg::DumpImpl();
|
||||
ss << ", nbits: " << nbits;
|
||||
return ss;
|
||||
}
|
||||
|
||||
std::stringstream
|
||||
NSGCfg::DumpImpl() {
|
||||
auto ss = IVFCfg::DumpImpl();
|
||||
ss << ", knng: " << knng << ", search_length: " << search_length << ", out_degree: " << out_degree
|
||||
<< ", candidate: " << candidate_pool_size;
|
||||
return ss;
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
|
||||
@ -42,6 +42,32 @@ constexpr int64_t DEFAULT_OUT_DEGREE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_CANDIDATE_SISE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NNG_K = INVALID_VALUE;
|
||||
|
||||
// SPTAG Config
|
||||
constexpr int64_t DEFAULT_SAMPLES = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_TPTNUMBER = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_TPTLEAFSIZE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NUMTOPDIMENSIONTPTSPLIT = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NEIGHBORHOODSIZE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_GRAPHNEIGHBORHOODSCALE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_GRAPHCEFSCALE = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_REFINEITERATIONS = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_CEF = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_MAXCHECKFORREFINEGRAPH = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NUMOFTHREADS = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_MAXCHECK = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_THRESHOLDOFNUMBEROFCONTINUOUSNOBETTERPROPAGATION = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NUMBEROFINITIALDYNAMICPIVOTS = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NUMBEROFOTHERDYNAMICPIVOTS = INVALID_VALUE;
|
||||
|
||||
// KDT Config
|
||||
constexpr int64_t DEFAULT_KDTNUMBER = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_NUMTOPDIMENSIONKDTSPLIT = INVALID_VALUE;
|
||||
|
||||
// BKT Config
|
||||
constexpr int64_t DEFAULT_BKTNUMBER = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_BKTKMEANSK = INVALID_VALUE;
|
||||
constexpr int64_t DEFAULT_BKTLEAFSIZE = INVALID_VALUE;
|
||||
|
||||
struct IVFCfg : public Cfg {
|
||||
int64_t nlist = DEFAULT_NLIST;
|
||||
int64_t nprobe = DEFAULT_NPROBE;
|
||||
@ -53,6 +79,9 @@ struct IVFCfg : public Cfg {
|
||||
|
||||
IVFCfg() = default;
|
||||
|
||||
std::stringstream
|
||||
DumpImpl() override;
|
||||
|
||||
bool
|
||||
CheckValid() override {
|
||||
return true;
|
||||
@ -69,6 +98,9 @@ struct IVFSQCfg : public IVFCfg {
|
||||
: IVFCfg(dim, k, gpu_id, nlist, nprobe, type), nbits(nbits) {
|
||||
}
|
||||
|
||||
std::stringstream
|
||||
DumpImpl() override;
|
||||
|
||||
IVFSQCfg() = default;
|
||||
|
||||
bool
|
||||
@ -119,6 +151,9 @@ struct NSGCfg : public IVFCfg {
|
||||
|
||||
NSGCfg() = default;
|
||||
|
||||
std::stringstream
|
||||
DumpImpl() override;
|
||||
|
||||
bool
|
||||
CheckValid() override {
|
||||
return true;
|
||||
@ -126,8 +161,57 @@ struct NSGCfg : public IVFCfg {
|
||||
};
|
||||
using NSGConfig = std::shared_ptr<NSGCfg>;
|
||||
|
||||
struct KDTCfg : public Cfg {
|
||||
int64_t tptnubmber = -1;
|
||||
struct SPTAGCfg : public Cfg {
|
||||
int64_t samples = DEFAULT_SAMPLES;
|
||||
int64_t tptnumber = DEFAULT_TPTNUMBER;
|
||||
int64_t tptleafsize = DEFAULT_TPTLEAFSIZE;
|
||||
int64_t numtopdimensiontptsplit = DEFAULT_NUMTOPDIMENSIONTPTSPLIT;
|
||||
int64_t neighborhoodsize = DEFAULT_NEIGHBORHOODSIZE;
|
||||
int64_t graphneighborhoodscale = DEFAULT_GRAPHNEIGHBORHOODSCALE;
|
||||
int64_t graphcefscale = DEFAULT_GRAPHCEFSCALE;
|
||||
int64_t refineiterations = DEFAULT_REFINEITERATIONS;
|
||||
int64_t cef = DEFAULT_CEF;
|
||||
int64_t maxcheckforrefinegraph = DEFAULT_MAXCHECKFORREFINEGRAPH;
|
||||
int64_t numofthreads = DEFAULT_NUMOFTHREADS;
|
||||
int64_t maxcheck = DEFAULT_MAXCHECK;
|
||||
int64_t thresholdofnumberofcontinuousnobetterpropagation = DEFAULT_THRESHOLDOFNUMBEROFCONTINUOUSNOBETTERPROPAGATION;
|
||||
int64_t numberofinitialdynamicpivots = DEFAULT_NUMBEROFINITIALDYNAMICPIVOTS;
|
||||
int64_t numberofotherdynamicpivots = DEFAULT_NUMBEROFOTHERDYNAMICPIVOTS;
|
||||
|
||||
SPTAGCfg() = default;
|
||||
|
||||
bool
|
||||
CheckValid() override {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
using SPTAGConfig = std::shared_ptr<SPTAGCfg>;
|
||||
|
||||
struct KDTCfg : public SPTAGCfg {
|
||||
int64_t kdtnumber = DEFAULT_KDTNUMBER;
|
||||
int64_t numtopdimensionkdtsplit = DEFAULT_NUMTOPDIMENSIONKDTSPLIT;
|
||||
|
||||
KDTCfg() = default;
|
||||
|
||||
bool
|
||||
CheckValid() override {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
using KDTConfig = std::shared_ptr<KDTCfg>;
|
||||
|
||||
struct BKTCfg : public SPTAGCfg {
|
||||
int64_t bktnumber = DEFAULT_BKTNUMBER;
|
||||
int64_t bktkmeansk = DEFAULT_BKTKMEANSK;
|
||||
int64_t bktleafsize = DEFAULT_BKTLEAFSIZE;
|
||||
|
||||
BKTCfg() = default;
|
||||
|
||||
bool
|
||||
CheckValid() override {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
using BKTConfig = std::shared_ptr<BKTCfg>;
|
||||
|
||||
} // namespace knowhere
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "knowhere/index/vector_index/helpers/KDTParameterMgr.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
const std::vector<KDTParameter>&
|
||||
KDTParameterMgr::GetKDTParameters() {
|
||||
return kdt_parameters_;
|
||||
}
|
||||
|
||||
KDTParameterMgr::KDTParameterMgr() {
|
||||
kdt_parameters_ = std::vector<KDTParameter>{
|
||||
{"KDTNumber", "1"},
|
||||
{"NumTopDimensionKDTSplit", "5"},
|
||||
{"NumSamplesKDTSplitConsideration", "100"},
|
||||
|
||||
{"TPTNumber", "1"},
|
||||
{"TPTLeafSize", "2000"},
|
||||
{"NumTopDimensionTPTSplit", "5"},
|
||||
|
||||
{"NeighborhoodSize", "32"},
|
||||
{"GraphNeighborhoodScale", "2"},
|
||||
{"GraphCEFScale", "2"},
|
||||
{"RefineIterations", "0"},
|
||||
{"CEF", "1000"},
|
||||
{"MaxCheckForRefineGraph", "10000"},
|
||||
|
||||
{"NumberOfThreads", "1"},
|
||||
|
||||
{"MaxCheck", "8192"},
|
||||
{"ThresholdOfNumberOfContinuousNoBetterPropagation", "3"},
|
||||
{"NumberOfInitialDynamicPivots", "50"},
|
||||
{"NumberOfOtherDynamicPivots", "4"},
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
@ -0,0 +1,75 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "knowhere/index/vector_index/helpers/SPTAGParameterMgr.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
const KDTConfig&
|
||||
SPTAGParameterMgr::GetKDTParameters() {
|
||||
return kdt_config_;
|
||||
}
|
||||
|
||||
const BKTConfig&
|
||||
SPTAGParameterMgr::GetBKTParameters() {
|
||||
return bkt_config_;
|
||||
}
|
||||
|
||||
SPTAGParameterMgr::SPTAGParameterMgr() {
|
||||
kdt_config_ = std::make_shared<KDTCfg>();
|
||||
kdt_config_->kdtnumber = 1;
|
||||
kdt_config_->numtopdimensionkdtsplit = 5;
|
||||
kdt_config_->samples = 100;
|
||||
kdt_config_->tptnumber = 1;
|
||||
kdt_config_->tptleafsize = 2000;
|
||||
kdt_config_->numtopdimensiontptsplit = 5;
|
||||
kdt_config_->neighborhoodsize = 32;
|
||||
kdt_config_->graphneighborhoodscale = 2;
|
||||
kdt_config_->graphcefscale = 2;
|
||||
kdt_config_->refineiterations = 0;
|
||||
kdt_config_->cef = 1000;
|
||||
kdt_config_->maxcheckforrefinegraph = 10000;
|
||||
kdt_config_->numofthreads = 1;
|
||||
kdt_config_->maxcheck = 8192;
|
||||
kdt_config_->thresholdofnumberofcontinuousnobetterpropagation = 3;
|
||||
kdt_config_->numberofinitialdynamicpivots = 50;
|
||||
kdt_config_->numberofotherdynamicpivots = 4;
|
||||
|
||||
bkt_config_ = std::make_shared<BKTCfg>();
|
||||
bkt_config_->bktnumber = 1;
|
||||
bkt_config_->bktkmeansk = 32;
|
||||
bkt_config_->bktleafsize = 8;
|
||||
bkt_config_->samples = 100;
|
||||
bkt_config_->tptnumber = 1;
|
||||
bkt_config_->tptleafsize = 2000;
|
||||
bkt_config_->numtopdimensiontptsplit = 5;
|
||||
bkt_config_->neighborhoodsize = 32;
|
||||
bkt_config_->graphneighborhoodscale = 2;
|
||||
bkt_config_->graphcefscale = 2;
|
||||
bkt_config_->refineiterations = 0;
|
||||
bkt_config_->cef = 1000;
|
||||
bkt_config_->maxcheckforrefinegraph = 10000;
|
||||
bkt_config_->numofthreads = 1;
|
||||
bkt_config_->maxcheck = 8192;
|
||||
bkt_config_->thresholdofnumberofcontinuousnobetterpropagation = 3;
|
||||
bkt_config_->numberofinitialdynamicpivots = 50;
|
||||
bkt_config_->numberofotherdynamicpivots = 4;
|
||||
}
|
||||
|
||||
} // namespace knowhere
|
||||
@ -22,31 +22,40 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <SPTAG/AnnService/inc/Core/Common.h>
|
||||
#include "IndexParameter.h"
|
||||
|
||||
namespace knowhere {
|
||||
|
||||
using KDTParameter = std::pair<std::string, std::string>;
|
||||
using KDTConfig = std::shared_ptr<KDTCfg>;
|
||||
using BKTConfig = std::shared_ptr<BKTCfg>;
|
||||
|
||||
class KDTParameterMgr {
|
||||
class SPTAGParameterMgr {
|
||||
public:
|
||||
const std::vector<KDTParameter>&
|
||||
const KDTConfig&
|
||||
GetKDTParameters();
|
||||
|
||||
const BKTConfig&
|
||||
GetBKTParameters();
|
||||
|
||||
public:
|
||||
static KDTParameterMgr&
|
||||
static SPTAGParameterMgr&
|
||||
GetInstance() {
|
||||
static KDTParameterMgr instance;
|
||||
static SPTAGParameterMgr instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
KDTParameterMgr(const KDTParameterMgr&) = delete;
|
||||
KDTParameterMgr&
|
||||
operator=(const KDTParameterMgr&) = delete;
|
||||
SPTAGParameterMgr(const SPTAGParameterMgr&) = delete;
|
||||
|
||||
SPTAGParameterMgr&
|
||||
operator=(const SPTAGParameterMgr&) = delete;
|
||||
|
||||
private:
|
||||
KDTParameterMgr();
|
||||
SPTAGParameterMgr();
|
||||
|
||||
private:
|
||||
std::vector<KDTParameter> kdt_parameters_;
|
||||
KDTConfig kdt_config_;
|
||||
BKTConfig bkt_config_;
|
||||
};
|
||||
|
||||
} // namespace knowhere
|
||||
@ -195,7 +195,7 @@ namespace SPTAG
|
||||
C = *((DimensionType*)pDataPointsMemFile);
|
||||
pDataPointsMemFile += sizeof(DimensionType);
|
||||
|
||||
Initialize(R, C, (T*)pDataPointsMemFile);
|
||||
Initialize(R, C, (T*)pDataPointsMemFile, false);
|
||||
std::cout << "Load " << name << " (" << R << ", " << C << ") Finish!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,17 +82,17 @@ if (NOT TARGET test_idmap)
|
||||
endif ()
|
||||
target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
|
||||
#<KDT-TEST>
|
||||
set(kdt_srcs
|
||||
#<SPTAG-TEST>
|
||||
set(sptag_srcs
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/adapter/SptagAdapter.cpp
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/index/preprocessor/Normalize.cpp
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/helpers/KDTParameterMgr.cpp
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexKDT.cpp
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/helpers/SPTAGParameterMgr.cpp
|
||||
${INDEX_SOURCE_DIR}/knowhere/knowhere/index/vector_index/IndexSPTAG.cpp
|
||||
)
|
||||
if (NOT TARGET test_kdt)
|
||||
add_executable(test_kdt test_kdt.cpp ${kdt_srcs} ${util_srcs})
|
||||
if (NOT TARGET test_sptag)
|
||||
add_executable(test_sptag test_sptag.cpp ${sptag_srcs} ${util_srcs})
|
||||
endif ()
|
||||
target_link_libraries(test_kdt
|
||||
target_link_libraries(test_sptag
|
||||
SPTAGLibStatic
|
||||
${depend_libs} ${unittest_libs} ${basic_libs})
|
||||
|
||||
@ -106,7 +106,7 @@ endif ()
|
||||
|
||||
install(TARGETS test_ivf DESTINATION unittest)
|
||||
install(TARGETS test_idmap DESTINATION unittest)
|
||||
install(TARGETS test_kdt DESTINATION unittest)
|
||||
install(TARGETS test_sptag DESTINATION unittest)
|
||||
if (KNOWHERE_GPU_VERSION)
|
||||
install(TARGETS test_gpuresource DESTINATION unittest)
|
||||
install(TARGETS test_customized_index DESTINATION unittest)
|
||||
|
||||
@ -1,144 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "knowhere/adapter/SptagAdapter.h"
|
||||
#include "knowhere/adapter/Structure.h"
|
||||
#include "knowhere/common/Exception.h"
|
||||
#include "knowhere/index/vector_index/IndexKDT.h"
|
||||
#include "knowhere/index/vector_index/helpers/Definitions.h"
|
||||
|
||||
#include "unittest/utils.h"
|
||||
|
||||
using ::testing::Combine;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
|
||||
class KDTTest : public DataGen, public ::testing::Test {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
Generate(96, 1000, 10);
|
||||
index_ = std::make_shared<knowhere::CPUKDTRNG>();
|
||||
|
||||
auto tempconf = std::make_shared<knowhere::KDTCfg>();
|
||||
tempconf->tptnubmber = 1;
|
||||
tempconf->k = 10;
|
||||
conf = tempconf;
|
||||
|
||||
Init_with_default();
|
||||
}
|
||||
|
||||
protected:
|
||||
knowhere::Config conf;
|
||||
std::shared_ptr<knowhere::CPUKDTRNG> index_ = nullptr;
|
||||
};
|
||||
|
||||
// TODO(lxj): add test about count() and dimension()
|
||||
TEST_F(KDTTest, kdt_basic) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, conf);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, conf);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, conf);
|
||||
auto result = index_->Search(query_dataset, conf);
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
{
|
||||
// auto ids = result->array()[0];
|
||||
// auto dists = result->array()[1];
|
||||
auto ids = result->ids();
|
||||
auto dists = result->dist();
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *((int64_t*)(ids) + i * k + j) << " ";
|
||||
ss_dist << *((float*)(dists) + i * k + j) << " ";
|
||||
// ss_id << *ids->data()->GetValues<int64_t>(1, i * k + j) << " ";
|
||||
// ss_dist << *dists->data()->GetValues<float>(1, i * k + j) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(zirui): enable test
|
||||
// TEST_F(KDTTest, kdt_serialize) {
|
||||
// assert(!xb.empty());
|
||||
//
|
||||
// auto preprocessor = index_->BuildPreprocessor(base_dataset, conf);
|
||||
// index_->set_preprocessor(preprocessor);
|
||||
//
|
||||
// auto model = index_->Train(base_dataset, conf);
|
||||
// // index_->Add(base_dataset, conf);
|
||||
// auto binaryset = index_->Serialize();
|
||||
// auto new_index = std::make_shared<knowhere::CPUKDTRNG>();
|
||||
// new_index->Load(binaryset);
|
||||
// auto result = new_index->Search(query_dataset, conf);
|
||||
// AssertAnns(result, nq, k);
|
||||
// PrintResult(result, nq, k);
|
||||
// ASSERT_EQ(new_index->Count(), nb);
|
||||
// ASSERT_EQ(new_index->Dimension(), dim);
|
||||
// ASSERT_THROW({ new_index->Clone(); }, knowhere::KnowhereException);
|
||||
// ASSERT_NO_THROW({ new_index->Seal(); });
|
||||
//
|
||||
// {
|
||||
// int fileno = 0;
|
||||
// const std::string& base_name = "/tmp/kdt_serialize_test_bin_";
|
||||
// std::vector<std::string> filename_list;
|
||||
// std::vector<std::pair<std::string, size_t>> meta_list;
|
||||
// for (auto& iter : binaryset.binary_map_) {
|
||||
// const std::string& filename = base_name + std::to_string(fileno);
|
||||
// FileIOWriter writer(filename);
|
||||
// writer(iter.second->data.get(), iter.second->size);
|
||||
//
|
||||
// meta_list.emplace_back(std::make_pair(iter.first, iter.second->size));
|
||||
// filename_list.push_back(filename);
|
||||
// ++fileno;
|
||||
// }
|
||||
//
|
||||
// knowhere::BinarySet load_data_list;
|
||||
// for (int i = 0; i < filename_list.size() && i < meta_list.size(); ++i) {
|
||||
// auto bin_size = meta_list[i].second;
|
||||
// FileIOReader reader(filename_list[i]);
|
||||
//
|
||||
// auto load_data = new uint8_t[bin_size];
|
||||
// reader(load_data, bin_size);
|
||||
// auto data = std::make_shared<uint8_t>();
|
||||
// data.reset(load_data);
|
||||
// load_data_list.Append(meta_list[i].first, data, bin_size);
|
||||
// }
|
||||
//
|
||||
// auto new_index = std::make_shared<knowhere::CPUKDTRNG>();
|
||||
// new_index->Load(load_data_list);
|
||||
// auto result = new_index->Search(query_dataset, conf);
|
||||
// AssertAnns(result, nq, k);
|
||||
// PrintResult(result, nq, k);
|
||||
// }
|
||||
//}
|
||||
154
core/src/index/unittest/test_sptag.cpp
Normal file
154
core/src/index/unittest/test_sptag.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "knowhere/adapter/SptagAdapter.h"
|
||||
#include "knowhere/adapter/Structure.h"
|
||||
#include "knowhere/common/Exception.h"
|
||||
#include "knowhere/index/vector_index/IndexSPTAG.h"
|
||||
#include "knowhere/index/vector_index/helpers/Definitions.h"
|
||||
|
||||
#include "unittest/utils.h"
|
||||
|
||||
using ::testing::Combine;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
|
||||
class SPTAGTest : public DataGen, public TestWithParam<std::string> {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
IndexType = GetParam();
|
||||
Generate(128, 100, 5);
|
||||
index_ = std::make_shared<knowhere::CPUSPTAGRNG>(IndexType);
|
||||
if (IndexType == "KDT") {
|
||||
auto tempconf = std::make_shared<knowhere::KDTCfg>();
|
||||
tempconf->tptnumber = 1;
|
||||
tempconf->k = 10;
|
||||
conf = tempconf;
|
||||
} else {
|
||||
auto tempconf = std::make_shared<knowhere::BKTCfg>();
|
||||
tempconf->tptnumber = 1;
|
||||
tempconf->k = 10;
|
||||
conf = tempconf;
|
||||
}
|
||||
|
||||
Init_with_default();
|
||||
}
|
||||
|
||||
protected:
|
||||
knowhere::Config conf;
|
||||
std::shared_ptr<knowhere::CPUSPTAGRNG> index_ = nullptr;
|
||||
std::string IndexType;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SPTAGParameters, SPTAGTest, Values("KDT", "BKT"));
|
||||
|
||||
// TODO(lxj): add test about count() and dimension()
|
||||
TEST_P(SPTAGTest, sptag_basic) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, conf);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, conf);
|
||||
index_->set_index_model(model);
|
||||
index_->Add(base_dataset, conf);
|
||||
auto result = index_->Search(query_dataset, conf);
|
||||
AssertAnns(result, nq, k);
|
||||
|
||||
{
|
||||
// auto ids = result->array()[0];
|
||||
// auto dists = result->array()[1];
|
||||
auto ids = result->ids();
|
||||
auto dists = result->dist();
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
// ss_id << *ids->data()->GetValues<int64_t>(1, i * k + j) << " ";
|
||||
// ss_dist << *dists->data()->GetValues<float>(1, i * k + j) << " ";
|
||||
ss_id << *((int64_t*)(ids) + i * k + j) << " ";
|
||||
ss_dist << *((float*)(dists) + i * k + j) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
}
|
||||
std::cout << "id\n" << ss_id.str() << std::endl;
|
||||
std::cout << "dist\n" << ss_dist.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SPTAGTest, sptag_serialize) {
|
||||
assert(!xb.empty());
|
||||
|
||||
auto preprocessor = index_->BuildPreprocessor(base_dataset, conf);
|
||||
index_->set_preprocessor(preprocessor);
|
||||
|
||||
auto model = index_->Train(base_dataset, conf);
|
||||
|
||||
index_->Add(base_dataset, conf);
|
||||
auto binaryset = index_->Serialize();
|
||||
auto new_index = std::make_shared<knowhere::CPUSPTAGRNG>(IndexType);
|
||||
new_index->Load(binaryset);
|
||||
auto result = new_index->Search(query_dataset, conf);
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
ASSERT_EQ(new_index->Count(), nb);
|
||||
ASSERT_EQ(new_index->Dimension(), dim);
|
||||
// ASSERT_THROW({ new_index->Clone(); }, knowhere::KnowhereException);
|
||||
// ASSERT_NO_THROW({ new_index->Seal(); });
|
||||
|
||||
{
|
||||
int fileno = 0;
|
||||
const std::string& base_name = "/tmp/sptag_serialize_test_bin_";
|
||||
std::vector<std::string> filename_list;
|
||||
std::vector<std::pair<std::string, size_t>> meta_list;
|
||||
for (auto& iter : binaryset.binary_map_) {
|
||||
const std::string& filename = base_name + std::to_string(fileno);
|
||||
FileIOWriter writer(filename);
|
||||
writer(iter.second->data.get(), iter.second->size);
|
||||
|
||||
meta_list.emplace_back(std::make_pair(iter.first, iter.second->size));
|
||||
filename_list.push_back(filename);
|
||||
++fileno;
|
||||
}
|
||||
|
||||
knowhere::BinarySet load_data_list;
|
||||
for (int i = 0; i < filename_list.size() && i < meta_list.size(); ++i) {
|
||||
auto bin_size = meta_list[i].second;
|
||||
FileIOReader reader(filename_list[i]);
|
||||
|
||||
auto load_data = new uint8_t[bin_size];
|
||||
reader(load_data, bin_size);
|
||||
auto data = std::make_shared<uint8_t>();
|
||||
data.reset(load_data);
|
||||
load_data_list.Append(meta_list[i].first, data, bin_size);
|
||||
}
|
||||
|
||||
auto new_index = std::make_shared<knowhere::CPUSPTAGRNG>(IndexType);
|
||||
new_index->Load(load_data_list);
|
||||
auto result = new_index->Search(query_dataset, conf);
|
||||
AssertAnns(result, nq, k);
|
||||
PrintResult(result, nq, k);
|
||||
}
|
||||
}
|
||||
@ -160,15 +160,17 @@ AssertAnns(const knowhere::DatasetPtr& result, const int& nq, const int& k) {
|
||||
|
||||
void
|
||||
PrintResult(const knowhere::DatasetPtr& result, const int& nq, const int& k) {
|
||||
auto ids = result->array()[0];
|
||||
auto dists = result->array()[1];
|
||||
auto ids = result->ids();
|
||||
auto dists = result->dist();
|
||||
|
||||
std::stringstream ss_id;
|
||||
std::stringstream ss_dist;
|
||||
for (auto i = 0; i < 10; i++) {
|
||||
for (auto i = 0; i < nq; i++) {
|
||||
for (auto j = 0; j < k; ++j) {
|
||||
ss_id << *(ids->data()->GetValues<int64_t>(1, i * k + j)) << " ";
|
||||
ss_dist << *(dists->data()->GetValues<float>(1, i * k + j)) << " ";
|
||||
// ss_id << *(ids->data()->GetValues<int64_t>(1, i * k + j)) << " ";
|
||||
// ss_dist << *(dists->data()->GetValues<float>(1, i * k + j)) << " ";
|
||||
ss_id << *((int64_t*)(ids) + i * k + j) << " ";
|
||||
ss_dist << *((float*)(dists) + i * k + j) << " ";
|
||||
}
|
||||
ss_id << std::endl;
|
||||
ss_dist << std::endl;
|
||||
|
||||
@ -85,7 +85,7 @@ JobMgr::worker_function() {
|
||||
}
|
||||
|
||||
for (auto& task : tasks) {
|
||||
calculate_path(task);
|
||||
calculate_path(res_mgr_, task);
|
||||
}
|
||||
|
||||
// disk resources NEVER be empty.
|
||||
@ -103,8 +103,8 @@ JobMgr::build_task(const JobPtr& job) {
|
||||
}
|
||||
|
||||
void
|
||||
JobMgr::calculate_path(const TaskPtr& task) {
|
||||
if (task->type_ != TaskType::SearchTask) {
|
||||
JobMgr::calculate_path(const ResourceMgrPtr& res_mgr, const TaskPtr& task) {
|
||||
if (task->type_ != TaskType::SearchTask && task->type_ != TaskType::BuildIndexTask) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,9 +114,9 @@ JobMgr::calculate_path(const TaskPtr& task) {
|
||||
|
||||
std::vector<std::string> path;
|
||||
auto spec_label = std::static_pointer_cast<SpecResLabel>(task->label());
|
||||
auto src = res_mgr_->GetDiskResources()[0];
|
||||
auto src = res_mgr->GetDiskResources()[0];
|
||||
auto dest = spec_label->resource();
|
||||
ShortestPath(src.lock(), dest.lock(), res_mgr_, path);
|
||||
ShortestPath(src.lock(), dest.lock(), res_mgr, path);
|
||||
task->path() = Path(path, path.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -59,8 +59,9 @@ class JobMgr : public interface::dumpable {
|
||||
static std::vector<TaskPtr>
|
||||
build_task(const JobPtr& job);
|
||||
|
||||
void
|
||||
calculate_path(const TaskPtr& task);
|
||||
public:
|
||||
static void
|
||||
calculate_path(const ResourceMgrPtr& res_mgr, const TaskPtr& task);
|
||||
|
||||
private:
|
||||
bool running_ = false;
|
||||
|
||||
@ -45,18 +45,6 @@ std::mutex BuildMgrInst::mutex_;
|
||||
|
||||
void
|
||||
load_simple_config() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::string mode;
|
||||
config.GetResourceConfigMode(mode);
|
||||
std::vector<std::string> pool;
|
||||
config.GetResourceConfigSearchResources(pool);
|
||||
|
||||
// get resources
|
||||
auto gpu_ids = get_gpu_pool();
|
||||
|
||||
int32_t build_gpu_id;
|
||||
config.GetResourceConfigIndexBuildDevice(build_gpu_id);
|
||||
|
||||
// create and connect
|
||||
ResMgrInst::GetInstance()->Add(ResourceFactory::Create("disk", "DISK", 0, true, false));
|
||||
|
||||
@ -64,26 +52,46 @@ load_simple_config() {
|
||||
ResMgrInst::GetInstance()->Add(ResourceFactory::Create("cpu", "CPU", 0, true, true));
|
||||
ResMgrInst::GetInstance()->Connect("disk", "cpu", io);
|
||||
|
||||
// get resources
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::vector<int64_t> gpu_ids;
|
||||
config.GetGpuResourceConfigSearchResources(gpu_ids);
|
||||
std::vector<int64_t> build_gpu_ids;
|
||||
config.GetGpuResourceConfigBuildIndexResources(build_gpu_ids);
|
||||
auto pcie = Connection("pcie", 12000);
|
||||
bool find_build_gpu_id = false;
|
||||
for (auto& gpu_id : gpu_ids) {
|
||||
ResMgrInst::GetInstance()->Add(ResourceFactory::Create(std::to_string(gpu_id), "GPU", gpu_id, true, true));
|
||||
ResMgrInst::GetInstance()->Connect("cpu", std::to_string(gpu_id), pcie);
|
||||
if (build_gpu_id == gpu_id) {
|
||||
find_build_gpu_id = true;
|
||||
|
||||
std::vector<int64_t> not_find_build_ids;
|
||||
for (auto& build_id : build_gpu_ids) {
|
||||
bool find_gpu_id = false;
|
||||
for (auto& gpu_id : gpu_ids) {
|
||||
if (gpu_id == build_id) {
|
||||
find_gpu_id = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (not find_gpu_id) {
|
||||
not_find_build_ids.emplace_back(build_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (not find_build_gpu_id) {
|
||||
ResMgrInst::GetInstance()->Add(
|
||||
ResourceFactory::Create(std::to_string(build_gpu_id), "GPU", build_gpu_id, true, true));
|
||||
ResMgrInst::GetInstance()->Connect("cpu", std::to_string(build_gpu_id), pcie);
|
||||
for (auto& gpu_id : gpu_ids) {
|
||||
ResMgrInst::GetInstance()->Add(ResourceFactory::Create(std::to_string(gpu_id), "GPU", gpu_id, true, true));
|
||||
ResMgrInst::GetInstance()->Connect("cpu", std::to_string(gpu_id), pcie);
|
||||
}
|
||||
|
||||
for (auto& not_find_id : not_find_build_ids) {
|
||||
ResMgrInst::GetInstance()->Add(
|
||||
ResourceFactory::Create(std::to_string(not_find_id), "GPU", not_find_id, true, true));
|
||||
ResMgrInst::GetInstance()->Connect("cpu", std::to_string(not_find_id), pcie);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
StartSchedulerService() {
|
||||
load_simple_config();
|
||||
OptimizerInst::GetInstance()->Init();
|
||||
ResMgrInst::GetInstance()->Start();
|
||||
SchedInst::GetInstance()->Start();
|
||||
JobMgrInst::GetInstance()->Start();
|
||||
|
||||
@ -21,10 +21,13 @@
|
||||
#include "JobMgr.h"
|
||||
#include "ResourceMgr.h"
|
||||
#include "Scheduler.h"
|
||||
#include "optimizer/HybridPass.h"
|
||||
#include "optimizer/LargeSQ8HPass.h"
|
||||
#include "optimizer/OnlyCPUPass.h"
|
||||
#include "optimizer/OnlyGPUPass.h"
|
||||
#include "Utils.h"
|
||||
#include "optimizer/BuildIndexPass.h"
|
||||
#include "optimizer/FaissFlatPass.h"
|
||||
#include "optimizer/FaissIVFFlatPass.h"
|
||||
#include "optimizer/FaissIVFSQ8HPass.h"
|
||||
#include "optimizer/FaissIVFSQ8Pass.h"
|
||||
#include "optimizer/FallbackPass.h"
|
||||
#include "optimizer/Optimizer.h"
|
||||
#include "server/Config.h"
|
||||
|
||||
@ -97,21 +100,15 @@ class OptimizerInst {
|
||||
if (instance == nullptr) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (instance == nullptr) {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::vector<std::string> search_resources;
|
||||
bool has_cpu = false;
|
||||
config.GetResourceConfigSearchResources(search_resources);
|
||||
for (auto& resource : search_resources) {
|
||||
if (resource == "cpu") {
|
||||
has_cpu = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<PassPtr> pass_list;
|
||||
pass_list.push_back(std::make_shared<LargeSQ8HPass>());
|
||||
pass_list.push_back(std::make_shared<HybridPass>());
|
||||
pass_list.push_back(std::make_shared<OnlyCPUPass>());
|
||||
pass_list.push_back(std::make_shared<OnlyGPUPass>(has_cpu));
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
pass_list.push_back(std::make_shared<BuildIndexPass>());
|
||||
pass_list.push_back(std::make_shared<FaissFlatPass>());
|
||||
pass_list.push_back(std::make_shared<FaissIVFFlatPass>());
|
||||
pass_list.push_back(std::make_shared<FaissIVFSQ8Pass>());
|
||||
pass_list.push_back(std::make_shared<FaissIVFSQ8HPass>());
|
||||
#endif
|
||||
pass_list.push_back(std::make_shared<FallbackPass>());
|
||||
instance = std::make_shared<Optimizer>(pass_list);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,10 +108,6 @@ Scheduler::OnLoadCompleted(const EventPtr& event) {
|
||||
|
||||
auto task_table_type = load_completed_event->task_table_item_->task->label()->Type();
|
||||
switch (task_table_type) {
|
||||
case TaskLabelType::DEFAULT: {
|
||||
Action::DefaultLabelTaskScheduler(res_mgr_, resource, load_completed_event);
|
||||
break;
|
||||
}
|
||||
case TaskLabelType::SPECIFIED_RESOURCE: {
|
||||
Action::SpecifiedResourceLabelTaskScheduler(res_mgr_, resource, load_completed_event);
|
||||
break;
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "scheduler/TaskCreator.h"
|
||||
#include "SchedInst.h"
|
||||
#include "tasklabel/BroadcastLabel.h"
|
||||
#include "tasklabel/DefaultLabel.h"
|
||||
#include "tasklabel/SpecResLabel.h"
|
||||
|
||||
namespace milvus {
|
||||
@ -47,8 +46,7 @@ std::vector<TaskPtr>
|
||||
TaskCreator::Create(const SearchJobPtr& job) {
|
||||
std::vector<TaskPtr> tasks;
|
||||
for (auto& index_file : job->index_files()) {
|
||||
auto label = std::make_shared<DefaultLabel>();
|
||||
auto task = std::make_shared<XSearchTask>(index_file.second, label);
|
||||
auto task = std::make_shared<XSearchTask>(index_file.second, nullptr);
|
||||
task->job_ = job;
|
||||
tasks.emplace_back(task);
|
||||
}
|
||||
@ -70,12 +68,8 @@ TaskCreator::Create(const DeleteJobPtr& job) {
|
||||
std::vector<TaskPtr>
|
||||
TaskCreator::Create(const BuildIndexJobPtr& job) {
|
||||
std::vector<TaskPtr> tasks;
|
||||
// TODO(yukun): remove "disk" hardcode here
|
||||
ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("disk");
|
||||
|
||||
for (auto& to_index_file : job->to_index_files()) {
|
||||
auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
|
||||
auto task = std::make_shared<XBuildIndexTask>(to_index_file.second, label);
|
||||
auto task = std::make_shared<XBuildIndexTask>(to_index_file.second, nullptr);
|
||||
task->job_ = job;
|
||||
tasks.emplace_back(task);
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/Utils.h"
|
||||
#include "server/Config.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
#include <cuda_runtime.h>
|
||||
@ -46,42 +44,5 @@ get_num_gpu() {
|
||||
return n_devices;
|
||||
}
|
||||
|
||||
std::vector<uint64_t>
|
||||
get_gpu_pool() {
|
||||
std::vector<uint64_t> gpu_pool;
|
||||
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::vector<std::string> pool;
|
||||
Status s = config.GetResourceConfigSearchResources(pool);
|
||||
if (!s.ok()) {
|
||||
SERVER_LOG_ERROR << s.message();
|
||||
}
|
||||
|
||||
std::set<uint64_t> gpu_ids;
|
||||
|
||||
for (auto& resource : pool) {
|
||||
if (resource == "cpu") {
|
||||
continue;
|
||||
} else {
|
||||
if (resource.length() < 4 || resource.substr(0, 3) != "gpu") {
|
||||
// error
|
||||
exit(-1);
|
||||
}
|
||||
auto gpu_id = std::stoi(resource.substr(3));
|
||||
if (gpu_id >= scheduler::get_num_gpu()) {
|
||||
// error
|
||||
exit(-1);
|
||||
}
|
||||
gpu_ids.insert(gpu_id);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& gpu_id : gpu_ids) {
|
||||
gpu_pool.push_back(gpu_id);
|
||||
}
|
||||
|
||||
return gpu_pool;
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
|
||||
@ -27,8 +27,5 @@ get_current_timestamp();
|
||||
uint64_t
|
||||
get_num_gpu();
|
||||
|
||||
std::vector<uint64_t>
|
||||
get_gpu_pool();
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
|
||||
@ -36,10 +36,6 @@ class Action {
|
||||
static void
|
||||
PushTaskToResource(TaskTableItemPtr task_item, const ResourcePtr& dest);
|
||||
|
||||
static void
|
||||
DefaultLabelTaskScheduler(const ResourceMgrPtr& res_mgr, ResourcePtr resource,
|
||||
std::shared_ptr<LoadCompletedEvent> event);
|
||||
|
||||
static void
|
||||
SpecifiedResourceLabelTaskScheduler(const ResourceMgrPtr& res_mgr, ResourcePtr resource,
|
||||
std::shared_ptr<LoadCompletedEvent> event);
|
||||
|
||||
@ -101,110 +101,11 @@ Action::PushTaskToResource(TaskTableItemPtr task_item, const ResourcePtr& dest)
|
||||
dest->task_table().Put(task_item->task, task_item);
|
||||
}
|
||||
|
||||
void
|
||||
Action::DefaultLabelTaskScheduler(const ResourceMgrPtr& res_mgr, ResourcePtr resource,
|
||||
std::shared_ptr<LoadCompletedEvent> event) {
|
||||
if (not resource->HasExecutor() && event->task_table_item_->Move()) {
|
||||
auto task_item = event->task_table_item_;
|
||||
auto task = event->task_table_item_->task;
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
bool moved = false;
|
||||
|
||||
// to support test task, REFACTOR
|
||||
if (resource->type() == ResourceType::CPU) {
|
||||
if (auto index_engine = search_task->index_engine_) {
|
||||
auto location = index_engine->GetLocation();
|
||||
|
||||
for (auto i = 0; i < res_mgr->GetNumGpuResource(); ++i) {
|
||||
auto index = milvus::cache::GpuCacheMgr::GetInstance(i)->GetIndex(location);
|
||||
if (index != nullptr) {
|
||||
moved = true;
|
||||
auto dest_resource = res_mgr->GetResource(ResourceType::GPU, i);
|
||||
PushTaskToResource(event->task_table_item_, dest_resource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (not moved) {
|
||||
PushTaskToNeighbourRandomly(task_item, resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Action::SpecifiedResourceLabelTaskScheduler(const ResourceMgrPtr& res_mgr, ResourcePtr resource,
|
||||
std::shared_ptr<LoadCompletedEvent> event) {
|
||||
auto task_item = event->task_table_item_;
|
||||
auto task = event->task_table_item_->task;
|
||||
if (resource->type() == ResourceType::DISK) {
|
||||
// step 1: calculate shortest path per resource, from disk to compute resource
|
||||
auto compute_resources = res_mgr->GetComputeResources();
|
||||
std::vector<std::vector<std::string>> paths;
|
||||
std::vector<uint64_t> transport_costs;
|
||||
for (auto& res : compute_resources) {
|
||||
std::vector<std::string> path;
|
||||
uint64_t transport_cost = ShortestPath(resource, res, res_mgr, path);
|
||||
transport_costs.push_back(transport_cost);
|
||||
paths.emplace_back(path);
|
||||
}
|
||||
// if (task->job_.lock()->type() == JobType::SEARCH) {
|
||||
// auto label = task->label();
|
||||
// auto spec_label = std::static_pointer_cast<SpecResLabel>(label);
|
||||
// if (spec_label->resource().lock()->type() == ResourceType::CPU) {
|
||||
// std::vector<std::string> spec_path;
|
||||
// spec_path.push_back(spec_label->resource().lock()->name());
|
||||
// spec_path.push_back(resource->name());
|
||||
// task->path() = Path(spec_path, spec_path.size() - 1);
|
||||
// } else {
|
||||
// // step 2: select min cost, cost(resource) = avg_cost * task_to_do + transport_cost
|
||||
// uint64_t min_cost = std::numeric_limits<uint64_t>::max();
|
||||
// uint64_t min_cost_idx = 0;
|
||||
// for (uint64_t i = 0; i < compute_resources.size(); ++i) {
|
||||
// if (compute_resources[i]->TotalTasks() == 0) {
|
||||
// min_cost_idx = i;
|
||||
// break;
|
||||
// }
|
||||
// uint64_t cost = compute_resources[i]->TaskAvgCost() *
|
||||
// compute_resources[i]->NumOfTaskToExec() +
|
||||
// transport_costs[i];
|
||||
// if (min_cost > cost) {
|
||||
// min_cost = cost;
|
||||
// min_cost_idx = i;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // step 3: set path in task
|
||||
// Path task_path(paths[min_cost_idx], paths[min_cost_idx].size() - 1);
|
||||
// task->path() = task_path;
|
||||
// }
|
||||
//
|
||||
// } else
|
||||
if (task->job_.lock()->type() == JobType::BUILD) {
|
||||
// step2: Read device id in config
|
||||
// get build index gpu resource
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
int32_t build_index_gpu;
|
||||
Status stat = config.GetResourceConfigIndexBuildDevice(build_index_gpu);
|
||||
|
||||
bool find_gpu_res = false;
|
||||
if (res_mgr->GetResource(ResourceType::GPU, build_index_gpu) != nullptr) {
|
||||
for (uint64_t i = 0; i < compute_resources.size(); ++i) {
|
||||
if (compute_resources[i]->name() ==
|
||||
res_mgr->GetResource(ResourceType::GPU, build_index_gpu)->name()) {
|
||||
find_gpu_res = true;
|
||||
Path task_path(paths[i], paths[i].size() - 1);
|
||||
task->path() = task_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (not find_gpu_res) {
|
||||
task->path() = Path(paths[0], paths[0].size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resource->name() == task->path().Last()) {
|
||||
resource->WakeupExecutor();
|
||||
|
||||
@ -15,32 +15,38 @@
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/OnlyCPUPass.h"
|
||||
#include "scheduler/optimizer/BuildIndexPass.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/Utils.h"
|
||||
#include "scheduler/task/SearchTask.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
bool
|
||||
OnlyCPUPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask)
|
||||
return false;
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8 &&
|
||||
search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFFLAT) {
|
||||
return false;
|
||||
void
|
||||
BuildIndexPass::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
std::vector<int64_t> build_resources;
|
||||
Status s = config.GetGpuResourceConfigBuildIndexResources(build_resources);
|
||||
if (!s.ok()) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
auto gpu_id = get_gpu_pool();
|
||||
if (not gpu_id.empty())
|
||||
bool
|
||||
BuildIndexPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::BuildIndexTask)
|
||||
return false;
|
||||
|
||||
ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
if (build_gpu_ids_.empty())
|
||||
return false;
|
||||
|
||||
ResourcePtr res_ptr;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, build_gpu_ids_[specified_gpu_id_]);
|
||||
auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
|
||||
task->label() = label;
|
||||
|
||||
specified_gpu_id_ = (specified_gpu_id_ + 1) % build_gpu_ids_.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -32,20 +32,23 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class OnlyGPUPass : public Pass {
|
||||
class BuildIndexPass : public Pass {
|
||||
public:
|
||||
explicit OnlyGPUPass(bool has_cpu);
|
||||
BuildIndexPass() = default;
|
||||
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
|
||||
private:
|
||||
uint64_t specified_gpu_id_ = 0;
|
||||
bool has_cpu_ = false;
|
||||
std::vector<int32_t> build_gpu_ids_;
|
||||
};
|
||||
|
||||
using OnlyGPUPassPtr = std::shared_ptr<OnlyGPUPass>;
|
||||
using BuildIndexPassPtr = std::shared_ptr<BuildIndexPass>;
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -15,7 +15,7 @@
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/LargeSQ8HPass.h"
|
||||
#include "scheduler/optimizer/FaissFlatPass.h"
|
||||
#include "cache/GpuCacheMgr.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/Utils.h"
|
||||
@ -27,57 +27,41 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
LargeSQ8HPass::LargeSQ8HPass() {
|
||||
void
|
||||
FaissFlatPass::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
|
||||
if (!s.ok()) {
|
||||
threshold_ = std::numeric_limits<int32_t>::max();
|
||||
}
|
||||
s = config.GetGpuResourceConfigSearchResources(gpus);
|
||||
if (!s.ok()) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
LargeSQ8HPass::Run(const TaskPtr& task) {
|
||||
FaissFlatPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8H) {
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IDMAP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_job = std::static_pointer_cast<SearchJob>(search_task->job_.lock());
|
||||
|
||||
// TODO: future, Index::IVFSQ8H, if nq < threshold set cpu, else set gpu
|
||||
|
||||
ResourcePtr res_ptr;
|
||||
if (search_job->nq() < threshold_) {
|
||||
return false;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
} else {
|
||||
auto best_device_id = count_ % gpus.size();
|
||||
count_++;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
|
||||
}
|
||||
|
||||
std::vector<uint64_t> gpus = scheduler::get_gpu_pool();
|
||||
// std::vector<int64_t> all_free_mem;
|
||||
// for (auto& gpu : gpus) {
|
||||
// auto cache = cache::GpuCacheMgr::GetInstance(gpu);
|
||||
// auto free_mem = cache->CacheCapacity() - cache->CacheUsage();
|
||||
// all_free_mem.push_back(free_mem);
|
||||
// }
|
||||
//
|
||||
// auto max_e = std::max_element(all_free_mem.begin(), all_free_mem.end());
|
||||
// auto best_index = std::distance(all_free_mem.begin(), max_e);
|
||||
// auto best_device_id = gpus[best_index];
|
||||
auto best_device_id = count_ % gpus.size();
|
||||
count_++;
|
||||
|
||||
ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
|
||||
if (not res_ptr) {
|
||||
SERVER_LOG_ERROR << "GpuResource " << best_device_id << " invalid.";
|
||||
// TODO: throw critical error and exit
|
||||
return false;
|
||||
}
|
||||
|
||||
auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
|
||||
auto label = std::make_shared<SpecResLabel>(res_ptr);
|
||||
task->label() = label;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -33,20 +33,24 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class LargeSQ8HPass : public Pass {
|
||||
class FaissFlatPass : public Pass {
|
||||
public:
|
||||
LargeSQ8HPass();
|
||||
FaissFlatPass() = default;
|
||||
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
|
||||
private:
|
||||
int32_t threshold_ = std::numeric_limits<int32_t>::max();
|
||||
int64_t threshold_ = std::numeric_limits<int64_t>::max();
|
||||
int64_t count_ = 0;
|
||||
std::vector<int64_t> gpus;
|
||||
};
|
||||
|
||||
using LargeSQ8HPassPtr = std::shared_ptr<LargeSQ8HPass>;
|
||||
using FaissFlatPassPtr = std::shared_ptr<FaissFlatPass>;
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
69
core/src/scheduler/optimizer/FaissIVFFlatPass.cpp
Normal file
69
core/src/scheduler/optimizer/FaissIVFFlatPass.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/FaissIVFFlatPass.h"
|
||||
#include "cache/GpuCacheMgr.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/Utils.h"
|
||||
#include "scheduler/task/SearchTask.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
#include "server/Config.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
void
|
||||
FaissIVFFlatPass::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
|
||||
if (!s.ok()) {
|
||||
threshold_ = std::numeric_limits<int32_t>::max();
|
||||
}
|
||||
s = config.GetGpuResourceConfigSearchResources(gpus);
|
||||
if (!s.ok()) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
FaissIVFFlatPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFFLAT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_job = std::static_pointer_cast<SearchJob>(search_task->job_.lock());
|
||||
ResourcePtr res_ptr;
|
||||
if (search_job->nq() < threshold_) {
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
} else {
|
||||
auto best_device_id = count_ % gpus.size();
|
||||
count_++;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
|
||||
}
|
||||
auto label = std::make_shared<SpecResLabel>(res_ptr);
|
||||
task->label() = label;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@ -32,16 +33,24 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class HybridPass : public Pass {
|
||||
class FaissIVFFlatPass : public Pass {
|
||||
public:
|
||||
HybridPass() = default;
|
||||
FaissIVFFlatPass() = default;
|
||||
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
|
||||
private:
|
||||
int64_t threshold_ = std::numeric_limits<int64_t>::max();
|
||||
int64_t count_ = 0;
|
||||
std::vector<int64_t> gpus;
|
||||
};
|
||||
|
||||
using HybridPassPtr = std::shared_ptr<HybridPass>;
|
||||
using FaissIVFFlatPassPtr = std::shared_ptr<FaissIVFFlatPass>;
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -15,39 +15,50 @@
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/OnlyGPUPass.h"
|
||||
#include "scheduler/optimizer/FaissIVFSQ8HPass.h"
|
||||
#include "cache/GpuCacheMgr.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/Utils.h"
|
||||
#include "scheduler/task/SearchTask.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
#include "server/Config.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
OnlyGPUPass::OnlyGPUPass(bool has_cpu) : has_cpu_(has_cpu) {
|
||||
void
|
||||
FaissIVFSQ8HPass::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
|
||||
if (!s.ok()) {
|
||||
threshold_ = std::numeric_limits<int64_t>::max();
|
||||
}
|
||||
s = config.GetGpuResourceConfigSearchResources(gpus);
|
||||
}
|
||||
|
||||
bool
|
||||
OnlyGPUPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask || has_cpu_)
|
||||
return false;
|
||||
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8 &&
|
||||
search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFFLAT &&
|
||||
search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IDMAP) {
|
||||
FaissIVFSQ8HPass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto gpu_id = get_gpu_pool();
|
||||
if (gpu_id.empty())
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8H) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, gpu_id[specified_gpu_id_]);
|
||||
auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
|
||||
auto search_job = std::static_pointer_cast<SearchJob>(search_task->job_.lock());
|
||||
ResourcePtr res_ptr;
|
||||
if (search_job->nq() < threshold_) {
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
} else {
|
||||
auto best_device_id = count_ % gpus.size();
|
||||
count_++;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
|
||||
}
|
||||
auto label = std::make_shared<SpecResLabel>(res_ptr);
|
||||
task->label() = label;
|
||||
|
||||
specified_gpu_id_ = specified_gpu_id_++ % gpu_id.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
56
core/src/scheduler/optimizer/FaissIVFSQ8HPass.h
Normal file
56
core/src/scheduler/optimizer/FaissIVFSQ8HPass.h
Normal file
@ -0,0 +1,56 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Pass.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class FaissIVFSQ8HPass : public Pass {
|
||||
public:
|
||||
FaissIVFSQ8HPass() = default;
|
||||
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
|
||||
private:
|
||||
int64_t threshold_ = std::numeric_limits<int64_t>::max();
|
||||
int64_t count_ = 0;
|
||||
std::vector<int64_t> gpus;
|
||||
};
|
||||
|
||||
using FaissIVFSQ8HPassPtr = std::shared_ptr<FaissIVFSQ8HPass>;
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
69
core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp
Normal file
69
core/src/scheduler/optimizer/FaissIVFSQ8Pass.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/FaissIVFSQ8Pass.h"
|
||||
#include "cache/GpuCacheMgr.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/Utils.h"
|
||||
#include "scheduler/task/SearchTask.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
#include "server/Config.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
void
|
||||
FaissIVFSQ8Pass::Init() {
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
|
||||
if (!s.ok()) {
|
||||
threshold_ = std::numeric_limits<int32_t>::max();
|
||||
}
|
||||
s = config.GetGpuResourceConfigSearchResources(gpus);
|
||||
if (!s.ok()) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
FaissIVFSQ8Pass::Run(const TaskPtr& task) {
|
||||
if (task->Type() != TaskType::SearchTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto search_job = std::static_pointer_cast<SearchJob>(search_task->job_.lock());
|
||||
ResourcePtr res_ptr;
|
||||
if (search_job->nq() < threshold_) {
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
} else {
|
||||
auto best_device_id = count_ % gpus.size();
|
||||
count_++;
|
||||
res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
|
||||
}
|
||||
auto label = std::make_shared<SpecResLabel>(res_ptr);
|
||||
task->label() = label;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@ -32,16 +33,24 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class OnlyCPUPass : public Pass {
|
||||
class FaissIVFSQ8Pass : public Pass {
|
||||
public:
|
||||
OnlyCPUPass() = default;
|
||||
FaissIVFSQ8Pass() = default;
|
||||
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
|
||||
private:
|
||||
int64_t threshold_ = std::numeric_limits<int64_t>::max();
|
||||
int64_t count_ = 0;
|
||||
std::vector<int64_t> gpus;
|
||||
};
|
||||
|
||||
using OnlyCPUPassPtr = std::shared_ptr<OnlyCPUPass>;
|
||||
using FaissIVFSQ8PassPtr = std::shared_ptr<FaissIVFSQ8Pass>;
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
43
core/src/scheduler/optimizer/FallbackPass.cpp
Normal file
43
core/src/scheduler/optimizer/FallbackPass.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/FallbackPass.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
void
|
||||
FallbackPass::Init() {
|
||||
}
|
||||
|
||||
bool
|
||||
FallbackPass::Run(const TaskPtr& task) {
|
||||
auto task_type = task->Type();
|
||||
if (task_type != TaskType::SearchTask && task_type != TaskType::BuildIndexTask) {
|
||||
return false;
|
||||
}
|
||||
// NEVER be empty
|
||||
auto cpu = ResMgrInst::GetInstance()->GetCpuResources()[0];
|
||||
auto label = std::make_shared<SpecResLabel>(cpu);
|
||||
task->label() = label;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -14,23 +14,27 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TaskLabel.h"
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
#include <memory>
|
||||
|
||||
#include "Pass.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
class DefaultLabel : public TaskLabel {
|
||||
class FallbackPass : public Pass {
|
||||
public:
|
||||
DefaultLabel() : TaskLabel(TaskLabelType::DEFAULT) {
|
||||
}
|
||||
};
|
||||
FallbackPass() = default;
|
||||
|
||||
using DefaultLabelPtr = std::shared_ptr<DefaultLabel>;
|
||||
public:
|
||||
void
|
||||
Init() override;
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task) override;
|
||||
};
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -1,43 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "scheduler/optimizer/HybridPass.h"
|
||||
#include "scheduler/SchedInst.h"
|
||||
#include "scheduler/task/SearchTask.h"
|
||||
#include "scheduler/tasklabel/SpecResLabel.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
bool
|
||||
HybridPass::Run(const TaskPtr& task) {
|
||||
// TODO: future, Index::IVFSQ8H, if nq < threshold set cpu, else set gpu
|
||||
if (task->Type() != TaskType::SearchTask)
|
||||
return false;
|
||||
auto search_task = std::static_pointer_cast<XSearchTask>(task);
|
||||
if (search_task->file_->engine_type_ == (int)engine::EngineType::FAISS_IVFSQ8H) {
|
||||
// TODO: remove "cpu" hardcode
|
||||
ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
|
||||
auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
|
||||
task->label() = label;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace scheduler
|
||||
} // namespace milvus
|
||||
@ -20,12 +20,12 @@
|
||||
namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
// void
|
||||
// Optimizer::Init() {
|
||||
// for (auto& pass : pass_list_) {
|
||||
// pass->Init();
|
||||
// }
|
||||
// }
|
||||
void
|
||||
Optimizer::Init() {
|
||||
for (auto& pass : pass_list_) {
|
||||
pass->Init();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Optimizer::Run(const TaskPtr& task) {
|
||||
|
||||
@ -38,8 +38,8 @@ class Optimizer {
|
||||
explicit Optimizer(std::vector<PassPtr> pass_list) : pass_list_(std::move(pass_list)) {
|
||||
}
|
||||
|
||||
// void
|
||||
// Init();
|
||||
void
|
||||
Init();
|
||||
|
||||
bool
|
||||
Run(const TaskPtr& task);
|
||||
|
||||
@ -34,9 +34,8 @@ namespace scheduler {
|
||||
|
||||
class Pass {
|
||||
public:
|
||||
// virtual void
|
||||
// Init() {
|
||||
// }
|
||||
virtual void
|
||||
Init() = 0;
|
||||
|
||||
virtual bool
|
||||
Run(const TaskPtr& task) = 0;
|
||||
|
||||
@ -146,8 +146,7 @@ XBuildIndexTask::Execute() {
|
||||
status = meta_ptr->UpdateTableFile(table_file);
|
||||
ENGINE_LOG_DEBUG << "Failed to update file to index, mark file: " << table_file.file_id_ << " to to_delete";
|
||||
|
||||
std::cout << "ERROR: failed to build index, index file is too large or gpu memory is not enough"
|
||||
<< std::endl;
|
||||
ENGINE_LOG_ERROR << "Failed to build index, index file is too large or gpu memory is not enough";
|
||||
|
||||
build_index_job->BuildIndexDone(to_index_id_);
|
||||
build_index_job->GetStatus() = Status(DB_ERROR, msg);
|
||||
@ -179,8 +178,8 @@ XBuildIndexTask::Execute() {
|
||||
status = meta_ptr->UpdateTableFile(table_file);
|
||||
ENGINE_LOG_DEBUG << "Failed to update file to index, mark file: " << table_file.file_id_ << " to to_delete";
|
||||
|
||||
std::cout << "ERROR: failed to persist index file: " << table_file.location_
|
||||
<< ", possible out of disk space" << std::endl;
|
||||
ENGINE_LOG_ERROR << "Failed to persist index file: " << table_file.location_
|
||||
<< ", possible out of disk space";
|
||||
|
||||
build_index_job->BuildIndexDone(to_index_id_);
|
||||
build_index_job->GetStatus() = Status(DB_ERROR, msg);
|
||||
|
||||
@ -23,7 +23,6 @@ namespace milvus {
|
||||
namespace scheduler {
|
||||
|
||||
enum class TaskLabelType {
|
||||
DEFAULT, // means can be executed in any resource
|
||||
SPECIFIED_RESOURCE, // means must executing in special resource
|
||||
BROADCAST, // means all enable-executor resource must execute task
|
||||
};
|
||||
|
||||
@ -93,6 +93,15 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
std::cout << "CreatePartition function call status: " << stat.message() << std::endl;
|
||||
milvus_sdk::Utils::PrintPartitionParam(partition_param);
|
||||
}
|
||||
|
||||
// show partitions
|
||||
milvus::PartitionList partition_array;
|
||||
stat = conn->ShowPartitions(TABLE_NAME, partition_array);
|
||||
|
||||
std::cout << partition_array.size() << " partitions created:" << std::endl;
|
||||
for (auto& partition : partition_array) {
|
||||
std::cout << "\t" << partition.partition_name << "\t tag = " << partition.partition_tag << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
{ // insert vectors
|
||||
@ -148,6 +157,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
}
|
||||
|
||||
{ // wait unit build index finish
|
||||
milvus_sdk::TimeRecorder rc("Create index");
|
||||
std::cout << "Wait until create all index done" << std::endl;
|
||||
milvus::IndexParam index1 = BuildIndexParam();
|
||||
milvus_sdk::Utils::PrintIndexParam(index1);
|
||||
|
||||
@ -150,6 +150,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
}
|
||||
|
||||
{ // wait unit build index finish
|
||||
milvus_sdk::TimeRecorder rc("Create index");
|
||||
std::cout << "Wait until create all index done" << std::endl;
|
||||
milvus::IndexParam index1 = BuildIndexParam();
|
||||
milvus_sdk::Utils::PrintIndexParam(index1);
|
||||
|
||||
@ -157,18 +157,20 @@ void
|
||||
Utils::PrintSearchResult(const std::vector<std::pair<int64_t, milvus::RowRecord>>& search_record_array,
|
||||
const milvus::TopKQueryResult& topk_query_result) {
|
||||
BLOCK_SPLITER
|
||||
size_t nq = topk_query_result.row_num;
|
||||
size_t topk = topk_query_result.ids.size() / nq;
|
||||
std::cout << "Returned result count: " << nq * topk << std::endl;
|
||||
std::cout << "Returned result count: " << topk_query_result.size() << std::endl;
|
||||
|
||||
int32_t index = 0;
|
||||
for (size_t i = 0; i < nq; i++) {
|
||||
auto search_id = search_record_array[index].first;
|
||||
index++;
|
||||
std::cout << "No." << index << " vector " << search_id << " top " << topk << " search result:" << std::endl;
|
||||
if (topk_query_result.size() != search_record_array.size()) {
|
||||
std::cout << "ERROR: Returned result count dones equal nq" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < topk_query_result.size(); i++) {
|
||||
const milvus::QueryResult& one_result = topk_query_result[i];
|
||||
size_t topk = one_result.ids.size();
|
||||
auto search_id = search_record_array[i].first;
|
||||
std::cout << "No." << i << " vector " << search_id << " top " << topk << " search result:" << std::endl;
|
||||
for (size_t j = 0; j < topk; j++) {
|
||||
size_t idx = i * nq + j;
|
||||
std::cout << "\t" << topk_query_result.ids[idx] << "\t" << topk_query_result.distances[idx] << std::endl;
|
||||
std::cout << "\t" << one_result.ids[j] << "\t" << one_result.distances[j] << std::endl;
|
||||
}
|
||||
}
|
||||
BLOCK_SPLITER
|
||||
@ -178,12 +180,11 @@ void
|
||||
Utils::CheckSearchResult(const std::vector<std::pair<int64_t, milvus::RowRecord>>& search_record_array,
|
||||
const milvus::TopKQueryResult& topk_query_result) {
|
||||
BLOCK_SPLITER
|
||||
size_t nq = topk_query_result.row_num;
|
||||
size_t result_k = topk_query_result.ids.size() / nq;
|
||||
int64_t index = 0;
|
||||
size_t nq = topk_query_result.size();
|
||||
for (size_t i = 0; i < nq; i++) {
|
||||
auto result_id = topk_query_result.ids[i * result_k];
|
||||
auto search_id = search_record_array[index++].first;
|
||||
const milvus::QueryResult& one_result = topk_query_result[i];
|
||||
auto search_id = search_record_array[i].first;
|
||||
int64_t result_id = one_result.ids[0];
|
||||
if (result_id != search_id) {
|
||||
std::cout << "The top 1 result is wrong: " << result_id << " vs. " << search_id << std::endl;
|
||||
} else {
|
||||
@ -198,9 +199,7 @@ Utils::DoSearch(std::shared_ptr<milvus::Connection> conn, const std::string& tab
|
||||
const std::vector<std::string>& partiton_tags, int64_t top_k, int64_t nprobe,
|
||||
const std::vector<std::pair<int64_t, milvus::RowRecord>>& search_record_array,
|
||||
milvus::TopKQueryResult& topk_query_result) {
|
||||
topk_query_result.distances.clear();
|
||||
topk_query_result.ids.clear();
|
||||
topk_query_result.row_num = 0;
|
||||
topk_query_result.clear();
|
||||
|
||||
std::vector<milvus::Range> query_range_array;
|
||||
milvus::Range rg;
|
||||
|
||||
@ -32,6 +32,13 @@ UriCheck(const std::string& uri) {
|
||||
return (index != std::string::npos);
|
||||
}
|
||||
|
||||
void
|
||||
CopyRowRecord(::milvus::grpc::RowRecord* target, const RowRecord& src) {
|
||||
auto vector_data = target->mutable_vector_data();
|
||||
vector_data->Resize(static_cast<int>(src.data.size()), 0.0);
|
||||
memcpy(vector_data->mutable_data(), src.data.data(), src.data.size() * sizeof(float));
|
||||
}
|
||||
|
||||
Status
|
||||
ClientProxy::Connect(const ConnectParam& param) {
|
||||
std::string uri = param.ip_address + ":" + param.port;
|
||||
@ -189,14 +196,16 @@ ClientProxy::Insert(const std::string& table_name, const std::string& partition_
|
||||
|
||||
for (auto& record : record_array) {
|
||||
::milvus::grpc::RowRecord* grpc_record = insert_param.add_row_record_array();
|
||||
grpc_record->add_vector_data(record.data.begin(), record.data.end());
|
||||
CopyRowRecord(grpc_record, record);
|
||||
}
|
||||
|
||||
// Single thread
|
||||
::milvus::grpc::VectorIds vector_ids;
|
||||
if (!id_array.empty()) {
|
||||
/* set user's ids */
|
||||
insert_param.add_row_id_array(id_array.begin(), id_array.end());
|
||||
auto row_ids = insert_param.mutable_row_id_array();
|
||||
row_ids->Resize(static_cast<int>(id_array.size()), -1);
|
||||
memcpy(row_ids->mutable_data(), id_array.data(), id_array.size() * sizeof(int64_t));
|
||||
client_ptr_->Insert(vector_ids, insert_param, status);
|
||||
} else {
|
||||
client_ptr_->Insert(vector_ids, insert_param, status);
|
||||
@ -226,7 +235,7 @@ ClientProxy::Search(const std::string& table_name, const std::vector<std::string
|
||||
}
|
||||
for (auto& record : query_record_array) {
|
||||
::milvus::grpc::RowRecord* row_record = search_param.add_query_record_array();
|
||||
row_record->add_vector_data(record.data.begin(), record.data.end());
|
||||
CopyRowRecord(row_record, record);
|
||||
}
|
||||
|
||||
// step 2: convert range array
|
||||
@ -241,12 +250,17 @@ ClientProxy::Search(const std::string& table_name, const std::vector<std::string
|
||||
Status status = client_ptr_->Search(result, search_param);
|
||||
|
||||
// step 4: convert result array
|
||||
topk_query_result.row_num = result.row_num();
|
||||
topk_query_result.ids.resize(result.ids().size());
|
||||
memcpy(topk_query_result.ids.data(), result.ids().data(), result.ids().size() * sizeof(int64_t));
|
||||
topk_query_result.distances.resize(result.distances().size());
|
||||
memcpy(topk_query_result.distances.data(), result.distances().data(),
|
||||
result.distances().size() * sizeof(float));
|
||||
topk_query_result.reserve(result.row_num());
|
||||
int64_t nq = result.row_num();
|
||||
int64_t topk = result.ids().size() / nq;
|
||||
for (int64_t i = 0; i < result.row_num(); i++) {
|
||||
milvus::QueryResult one_result;
|
||||
one_result.ids.resize(topk);
|
||||
one_result.distances.resize(topk);
|
||||
memcpy(one_result.ids.data(), result.ids().data() + topk * i, topk * sizeof(int64_t));
|
||||
memcpy(one_result.distances.data(), result.distances().data() + topk * i, topk * sizeof(float));
|
||||
topk_query_result.emplace_back(one_result);
|
||||
}
|
||||
|
||||
return status;
|
||||
} catch (std::exception& ex) {
|
||||
|
||||
@ -81,11 +81,11 @@ struct RowRecord {
|
||||
/**
|
||||
* @brief TopK query result
|
||||
*/
|
||||
struct TopKQueryResult {
|
||||
int64_t row_num;
|
||||
struct QueryResult {
|
||||
std::vector<int64_t> ids;
|
||||
std::vector<float> distances;
|
||||
};
|
||||
using TopKQueryResult = std::vector<QueryResult>;
|
||||
|
||||
/**
|
||||
* @brief index parameters
|
||||
|
||||
@ -113,19 +113,19 @@ Config::ValidateConfig() {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t db_archive_disk_threshold;
|
||||
int64_t db_archive_disk_threshold;
|
||||
s = GetDBConfigArchiveDiskThreshold(db_archive_disk_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t db_archive_days_threshold;
|
||||
int64_t db_archive_days_threshold;
|
||||
s = GetDBConfigArchiveDaysThreshold(db_archive_days_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t db_insert_buffer_size;
|
||||
int64_t db_insert_buffer_size;
|
||||
s = GetDBConfigInsertBufferSize(db_insert_buffer_size);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
@ -163,20 +163,6 @@ Config::ValidateConfig() {
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
int64_t cache_gpu_cache_capacity;
|
||||
s = GetCacheConfigGpuCacheCapacity(cache_gpu_cache_capacity);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
float cache_gpu_cache_threshold;
|
||||
s = GetCacheConfigGpuCacheThreshold(cache_gpu_cache_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool cache_insert_data;
|
||||
s = GetCacheConfigCacheInsertData(cache_insert_data);
|
||||
if (!s.ok()) {
|
||||
@ -184,43 +170,57 @@ Config::ValidateConfig() {
|
||||
}
|
||||
|
||||
/* engine config */
|
||||
int32_t engine_use_blas_threshold;
|
||||
int64_t engine_use_blas_threshold;
|
||||
s = GetEngineConfigUseBlasThreshold(engine_use_blas_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t engine_omp_thread_num;
|
||||
int64_t engine_omp_thread_num;
|
||||
s = GetEngineConfigOmpThreadNum(engine_omp_thread_num);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t engine_gpu_search_threshold;
|
||||
int64_t engine_gpu_search_threshold;
|
||||
s = GetEngineConfigGpuSearchThreshold(engine_gpu_search_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
/* resource config */
|
||||
std::string resource_mode;
|
||||
s = GetResourceConfigMode(resource_mode);
|
||||
/* gpu resource config */
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
bool gpu_resource_enable;
|
||||
s = GetGpuResourceConfigEnable(gpu_resource_enable);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<std::string> search_resources;
|
||||
s = GetResourceConfigSearchResources(search_resources);
|
||||
int64_t resource_cache_capacity;
|
||||
s = GetGpuResourceConfigCacheCapacity(resource_cache_capacity);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t resource_index_build_device;
|
||||
s = GetResourceConfigIndexBuildDevice(resource_index_build_device);
|
||||
float resource_cache_threshold;
|
||||
s = GetGpuResourceConfigCacheThreshold(resource_cache_threshold);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<int64_t> search_resources;
|
||||
s = GetGpuResourceConfigSearchResources(search_resources);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<int64_t> index_build_resources;
|
||||
s = GetGpuResourceConfigBuildIndexResources(index_build_resources);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -307,18 +307,6 @@ Config::ResetDefaultConfig() {
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
s = SetCacheConfigGpuCacheCapacity(CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
s = SetCacheConfigGpuCacheThreshold(CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
s = SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
@ -340,22 +328,34 @@ Config::ResetDefaultConfig() {
|
||||
return s;
|
||||
}
|
||||
|
||||
/* resource config */
|
||||
s = SetResourceConfigMode(CONFIG_RESOURCE_MODE_DEFAULT);
|
||||
/* gpu resource config */
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
s = SetGpuResourceConfigEnable(CONFIG_GPU_RESOURCE_ENABLE_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
s = SetResourceConfigSearchResources(CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT);
|
||||
s = SetGpuResourceConfigCacheCapacity(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
s = SetResourceConfigIndexBuildDevice(CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT);
|
||||
s = SetGpuResourceConfigCacheThreshold(CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
s = SetGpuResourceConfigSearchResources(CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
s = SetGpuResourceConfigBuildIndexResources(CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -377,7 +377,7 @@ Config::PrintAll() {
|
||||
PrintConfigSection(CONFIG_CACHE);
|
||||
PrintConfigSection(CONFIG_METRIC);
|
||||
PrintConfigSection(CONFIG_ENGINE);
|
||||
PrintConfigSection(CONFIG_RESOURCE);
|
||||
PrintConfigSection(CONFIG_GPU_RESOURCE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -485,7 +485,7 @@ Config::CheckDBConfigInsertBufferSize(const std::string& value) {
|
||||
". Possible reason: db_config.insert_buffer_size is not a positive integer.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
int64_t buffer_size = std::stoi(value) * GB;
|
||||
int64_t buffer_size = std::stoll(value) * GB;
|
||||
if (buffer_size <= 0) {
|
||||
std::string msg = "Invalid insert buffer size: " + value +
|
||||
". Possible reason: db_config.insert_buffer_size is not a positive integer.";
|
||||
@ -540,7 +540,7 @@ Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
|
||||
". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
int64_t cpu_cache_capacity = std::stoi(value) * GB;
|
||||
int64_t cpu_cache_capacity = std::stoll(value) * GB;
|
||||
if (cpu_cache_capacity <= 0) {
|
||||
std::string msg = "Invalid cpu cache capacity: " + value +
|
||||
". Possible reason: cache_config.cpu_cache_capacity is not a positive integer.";
|
||||
@ -557,7 +557,7 @@ Config::CheckCacheConfigCpuCacheCapacity(const std::string& value) {
|
||||
std::cerr << "WARNING: cpu cache capacity value is too big" << std::endl;
|
||||
}
|
||||
|
||||
int32_t buffer_value;
|
||||
int64_t buffer_value;
|
||||
Status s = GetDBConfigInsertBufferSize(buffer_value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
@ -591,52 +591,6 @@ Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckCacheConfigGpuCacheCapacity(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
|
||||
std::string msg = "Invalid gpu cache capacity: " + value +
|
||||
". Possible reason: cache_config.gpu_cache_capacity is not a positive integer.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
uint64_t gpu_cache_capacity = std::stoi(value) * GB;
|
||||
int device_id;
|
||||
Status s = GetResourceConfigIndexBuildDevice(device_id);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t gpu_memory;
|
||||
if (!ValidationUtil::GetGpuMemory(device_id, gpu_memory).ok()) {
|
||||
std::string msg = "Fail to get GPU memory for GPU device: " + std::to_string(device_id);
|
||||
return Status(SERVER_UNEXPECTED_ERROR, msg);
|
||||
} else if (gpu_cache_capacity >= gpu_memory) {
|
||||
std::string msg = "Invalid gpu cache capacity: " + value +
|
||||
". Possible reason: cache_config.gpu_cache_capacity exceeds GPU memory.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
|
||||
std::cerr << "Warning: gpu cache capacity value is too big" << std::endl;
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckCacheConfigGpuCacheThreshold(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
|
||||
std::string msg = "Invalid gpu cache threshold: " + value +
|
||||
". Possible reason: cache_config.gpu_cache_threshold is not in range (0.0, 1.0].";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
float gpu_cache_threshold = std::stof(value);
|
||||
if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
|
||||
std::string msg = "Invalid gpu cache threshold: " + value +
|
||||
". Possible reason: cache_config.gpu_cache_threshold is not in range (0.0, 1.0].";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckCacheConfigCacheInsertData(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
|
||||
@ -665,10 +619,10 @@ Config::CheckEngineConfigOmpThreadNum(const std::string& value) {
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
int32_t omp_thread = std::stoi(value);
|
||||
uint32_t sys_thread_cnt = 8;
|
||||
int64_t omp_thread = std::stoll(value);
|
||||
int64_t sys_thread_cnt = 8;
|
||||
CommonUtil::GetSystemAvailableThreads(sys_thread_cnt);
|
||||
if (omp_thread > static_cast<int32_t>(sys_thread_cnt)) {
|
||||
if (omp_thread > sys_thread_cnt) {
|
||||
std::string msg = "Invalid omp thread num: " + value +
|
||||
". Possible reason: engine_config.omp_thread_num exceeds system cpu cores.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
@ -687,56 +641,99 @@ Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckResourceConfigMode(const std::string& value) {
|
||||
if (value != "simple") {
|
||||
std::string msg = "Invalid resource mode: " + value + ". Possible reason: resource_config.mode is invalid.";
|
||||
Config::CheckGpuResourceConfigEnable(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
|
||||
std::string msg =
|
||||
"Invalid gpu resource config: " + value + ". Possible reason: gpu_resource_config.enable is not a boolean.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
CheckResource(const std::string& value) {
|
||||
Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
|
||||
std::string msg = "Invalid gpu cache capacity: " + value +
|
||||
". Possible reason: gpu_resource_config.cache_capacity is not a positive integer.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
int64_t gpu_cache_capacity = std::stoll(value) * GB;
|
||||
std::vector<int64_t> gpu_ids;
|
||||
Status s = GetGpuResourceConfigBuildIndexResources(gpu_ids);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
for (int64_t gpu_id : gpu_ids) {
|
||||
size_t gpu_memory;
|
||||
if (!ValidationUtil::GetGpuMemory(gpu_id, gpu_memory).ok()) {
|
||||
std::string msg = "Fail to get GPU memory for GPU device: " + std::to_string(gpu_id);
|
||||
return Status(SERVER_UNEXPECTED_ERROR, msg);
|
||||
} else if (gpu_cache_capacity >= gpu_memory) {
|
||||
std::string msg = "Invalid gpu cache capacity: " + value +
|
||||
". Possible reason: gpu_resource_config.cache_capacity exceeds GPU memory.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
|
||||
std::cerr << "Warning: gpu cache capacity value is too big" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckGpuResourceConfigCacheThreshold(const std::string& value) {
|
||||
if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
|
||||
std::string msg = "Invalid gpu cache threshold: " + value +
|
||||
". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
} else {
|
||||
float gpu_cache_threshold = std::stof(value);
|
||||
if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
|
||||
std::string msg = "Invalid gpu cache threshold: " + value +
|
||||
". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
CheckGpuResource(const std::string& value) {
|
||||
std::string s = value;
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||
|
||||
#ifdef MILVUS_CPU_VERSION
|
||||
if (s != "cpu") {
|
||||
return Status(SERVER_INVALID_ARGUMENT, "Invalid CPU resource: " + s);
|
||||
}
|
||||
#else
|
||||
const std::regex pat("cpu|gpu(\\d+)");
|
||||
const std::regex pat("gpu(\\d+)");
|
||||
std::smatch m;
|
||||
if (!std::regex_match(s, m, pat)) {
|
||||
std::string msg = "Invalid search resource: " + value +
|
||||
". Possible reason: resource_config.search_resources is not in the format of cpux or gpux";
|
||||
std::string msg = "Invalid gpu resource: " + value +
|
||||
". Possible reason: gpu_resource_config is not in the format of cpux or gpux";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
if (s.compare(0, 3, "gpu") == 0) {
|
||||
int32_t gpu_index = std::stoi(s.substr(3));
|
||||
if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
|
||||
std::string msg = "Invalid search resource: " + value +
|
||||
". Possible reason: resource_config.search_resources does not match your hardware.";
|
||||
std::string msg = "Invalid gpu resource: " + value +
|
||||
". Possible reason: gpu_resource_config does not match with the hardware.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value) {
|
||||
Config::CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value) {
|
||||
if (value.empty()) {
|
||||
std::string msg =
|
||||
"Invalid search resource. "
|
||||
"Possible reason: resource_config.search_resources is empty.";
|
||||
"Invalid gpu search resource. "
|
||||
"Possible reason: gpu_resource_config.search_resources is empty.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
for (auto& resource : value) {
|
||||
auto status = CheckResource(resource);
|
||||
auto status = CheckGpuResource(resource);
|
||||
if (!status.ok()) {
|
||||
return Status(SERVER_INVALID_ARGUMENT, status.message());
|
||||
}
|
||||
@ -745,11 +742,21 @@ Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value
|
||||
}
|
||||
|
||||
Status
|
||||
Config::CheckResourceConfigIndexBuildDevice(const std::string& value) {
|
||||
auto status = CheckResource(value);
|
||||
if (!status.ok()) {
|
||||
return Status(SERVER_INVALID_ARGUMENT, status.message());
|
||||
Config::CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value) {
|
||||
if (value.empty()) {
|
||||
std::string msg =
|
||||
"Invalid gpu build index resource. "
|
||||
"Possible reason: gpu_resource_config.build_index_resources is empty.";
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
for (auto& resource : value) {
|
||||
auto status = CheckGpuResource(resource);
|
||||
if (!status.ok()) {
|
||||
return Status(SERVER_INVALID_ARGUMENT, status.message());
|
||||
}
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -848,40 +855,37 @@ Config::GetDBConfigBackendUrl(std::string& value) {
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetDBConfigArchiveDiskThreshold(int32_t& value) {
|
||||
Config::GetDBConfigArchiveDiskThreshold(int64_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, CONFIG_DB_ARCHIVE_DISK_THRESHOLD_DEFAULT);
|
||||
Status s = CheckDBConfigArchiveDiskThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetDBConfigArchiveDaysThreshold(int32_t& value) {
|
||||
Config::GetDBConfigArchiveDaysThreshold(int64_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD_DEFAULT);
|
||||
Status s = CheckDBConfigArchiveDaysThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetDBConfigInsertBufferSize(int32_t& value) {
|
||||
Config::GetDBConfigInsertBufferSize(int64_t& value) {
|
||||
std::string str = GetConfigStr(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, CONFIG_DB_INSERT_BUFFER_SIZE_DEFAULT);
|
||||
Status s = CheckDBConfigInsertBufferSize(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -898,7 +902,6 @@ Config::GetMetricConfigEnableMonitor(bool& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
value = (str == "true" || str == "on" || str == "yes" || str == "1");
|
||||
return Status::OK();
|
||||
@ -924,8 +927,7 @@ Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -937,33 +939,6 @@ Config::GetCacheConfigCpuCacheThreshold(float& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stof(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetCacheConfigGpuCacheCapacity(int64_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_CAPACITY, CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
|
||||
Status s = CheckCacheConfigGpuCacheCapacity(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetCacheConfigGpuCacheThreshold(float& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_THRESHOLD, CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
|
||||
Status s = CheckCacheConfigGpuCacheThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stof(str);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -976,80 +951,148 @@ Config::GetCacheConfigCacheInsertData(bool& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
value = (str == "true" || str == "on" || str == "yes" || str == "1");
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetEngineConfigUseBlasThreshold(int32_t& value) {
|
||||
Config::GetEngineConfigUseBlasThreshold(int64_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
|
||||
Status s = CheckEngineConfigUseBlasThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetEngineConfigOmpThreadNum(int32_t& value) {
|
||||
Config::GetEngineConfigOmpThreadNum(int64_t& value) {
|
||||
std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
|
||||
Status s = CheckEngineConfigOmpThreadNum(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetEngineConfigGpuSearchThreshold(int32_t& value) {
|
||||
Config::GetEngineConfigGpuSearchThreshold(int64_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT);
|
||||
Status s = CheckEngineConfigGpuSearchThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetResourceConfigMode(std::string& value) {
|
||||
value = GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_MODE, CONFIG_RESOURCE_MODE_DEFAULT);
|
||||
return CheckResourceConfigMode(value);
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetResourceConfigSearchResources(std::vector<std::string>& value) {
|
||||
std::string str =
|
||||
GetConfigSequenceStr(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES,
|
||||
CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT);
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, value);
|
||||
return CheckResourceConfigSearchResources(value);
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetResourceConfigIndexBuildDevice(int32_t& value) {
|
||||
std::string str =
|
||||
GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT);
|
||||
Status s = CheckResourceConfigIndexBuildDevice(str);
|
||||
Config::GetGpuResourceConfigEnable(bool& value) {
|
||||
std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, CONFIG_GPU_RESOURCE_ENABLE_DEFAULT);
|
||||
Status s = CheckGpuResourceConfigEnable(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
value = (str == "true" || str == "on" || str == "yes" || str == "1");
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
if (str == "cpu") {
|
||||
value = CPU_DEVICE_ID;
|
||||
} else {
|
||||
value = std::stoi(str.substr(3));
|
||||
Status
|
||||
Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
|
||||
bool gpu_resource_enable = false;
|
||||
Status s = GetGpuResourceConfigEnable(gpu_resource_enable);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (!gpu_resource_enable) {
|
||||
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
|
||||
return Status(SERVER_UNSUPPORTED_ERROR, msg);
|
||||
}
|
||||
std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY,
|
||||
CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT);
|
||||
s = CheckGpuResourceConfigCacheCapacity(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
value = std::stoll(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetGpuResourceConfigCacheThreshold(float& value) {
|
||||
bool gpu_resource_enable = false;
|
||||
Status s = GetGpuResourceConfigEnable(gpu_resource_enable);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (!gpu_resource_enable) {
|
||||
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
|
||||
return Status(SERVER_UNSUPPORTED_ERROR, msg);
|
||||
}
|
||||
std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD,
|
||||
CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT);
|
||||
s = CheckGpuResourceConfigCacheThreshold(str);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
value = std::stof(str);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetGpuResourceConfigSearchResources(std::vector<int64_t>& value) {
|
||||
bool gpu_resource_enable = false;
|
||||
Status s = GetGpuResourceConfigEnable(gpu_resource_enable);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (!gpu_resource_enable) {
|
||||
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
|
||||
return Status(SERVER_UNSUPPORTED_ERROR, msg);
|
||||
}
|
||||
std::string str = GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES,
|
||||
CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT);
|
||||
std::vector<std::string> res_vec;
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
|
||||
s = CheckGpuResourceConfigSearchResources(res_vec);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
for (std::string& res : res_vec) {
|
||||
value.push_back(std::stoll(res.substr(3)));
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value) {
|
||||
bool gpu_resource_enable = false;
|
||||
Status s = GetGpuResourceConfigEnable(gpu_resource_enable);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (!gpu_resource_enable) {
|
||||
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable is set to false.";
|
||||
return Status(SERVER_UNSUPPORTED_ERROR, msg);
|
||||
}
|
||||
std::string str =
|
||||
GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES,
|
||||
CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT);
|
||||
std::vector<std::string> res_vec;
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
|
||||
s = CheckGpuResourceConfigBuildIndexResources(res_vec);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
for (std::string& res : res_vec) {
|
||||
value.push_back(std::stoll(res.substr(3)));
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -1061,7 +1104,6 @@ Config::SetServerConfigAddress(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1072,7 +1114,6 @@ Config::SetServerConfigPort(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1083,7 +1124,6 @@ Config::SetServerConfigDeployMode(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1094,7 +1134,6 @@ Config::SetServerConfigTimeZone(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1106,7 +1145,6 @@ Config::SetDBConfigPrimaryPath(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1117,7 +1155,6 @@ Config::SetDBConfigSecondaryPath(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1128,7 +1165,6 @@ Config::SetDBConfigBackendUrl(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1139,7 +1175,6 @@ Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1150,7 +1185,6 @@ Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1161,7 +1195,6 @@ Config::SetDBConfigInsertBufferSize(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1173,7 +1206,6 @@ Config::SetMetricConfigEnableMonitor(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1184,7 +1216,6 @@ Config::SetMetricConfigCollector(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_COLLECTOR, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1195,7 +1226,6 @@ Config::SetMetricConfigPrometheusPort(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PROMETHEUS_PORT, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1207,7 +1237,6 @@ Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1218,40 +1247,16 @@ Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetCacheConfigGpuCacheCapacity(const std::string& value) {
|
||||
Status s = CheckCacheConfigGpuCacheCapacity(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_CAPACITY, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetCacheConfigGpuCacheThreshold(const std::string& value) {
|
||||
Status s = CheckCacheConfigGpuCacheThreshold(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetCacheConfigCacheInsertData(const std::string& value) {
|
||||
Status s = CheckCacheConfigCacheInsertData(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1263,7 +1268,6 @@ Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1274,7 +1278,6 @@ Config::SetEngineConfigOmpThreadNum(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value);
|
||||
return Status::OK();
|
||||
}
|
||||
@ -1285,47 +1288,64 @@ Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
/* resource config */
|
||||
/* gpu resource config */
|
||||
Status
|
||||
Config::SetResourceConfigMode(const std::string& value) {
|
||||
Status s = CheckResourceConfigMode(value);
|
||||
Config::SetGpuResourceConfigEnable(const std::string& value) {
|
||||
Status s = CheckGpuResourceConfigEnable(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_MODE, value);
|
||||
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetResourceConfigSearchResources(const std::string& value) {
|
||||
Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
|
||||
Status s = CheckGpuResourceConfigCacheCapacity(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetGpuResourceConfigCacheThreshold(const std::string& value) {
|
||||
Status s = CheckGpuResourceConfigCacheThreshold(value);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetGpuResourceConfigSearchResources(const std::string& value) {
|
||||
std::vector<std::string> res_vec;
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, res_vec);
|
||||
|
||||
Status s = CheckResourceConfigSearchResources(res_vec);
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
|
||||
Status s = CheckGpuResourceConfigSearchResources(res_vec);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES, value);
|
||||
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
Config::SetResourceConfigIndexBuildDevice(const std::string& value) {
|
||||
Status s = CheckResourceConfigIndexBuildDevice(value);
|
||||
Config::SetGpuResourceConfigBuildIndexResources(const std::string& value) {
|
||||
std::vector<std::string> res_vec;
|
||||
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
|
||||
Status s = CheckGpuResourceConfigBuildIndexResources(res_vec);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, value);
|
||||
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
|
||||
return Status::OK();
|
||||
}
|
||||
} // namespace server
|
||||
|
||||
} // namespace server
|
||||
} // namespace milvus
|
||||
|
||||
@ -59,12 +59,8 @@ static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table";
|
||||
static const char* CONFIG_CACHE = "cache_config";
|
||||
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
|
||||
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "16";
|
||||
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY = "gpu_cache_capacity";
|
||||
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT = "4";
|
||||
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_mem_threshold";
|
||||
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_cache_threshold";
|
||||
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.85";
|
||||
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD = "gpu_mem_threshold";
|
||||
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT = "0.85";
|
||||
static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data";
|
||||
static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false";
|
||||
|
||||
@ -87,26 +83,23 @@ static const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0";
|
||||
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold";
|
||||
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000";
|
||||
|
||||
/* resource config */
|
||||
static const char* CONFIG_RESOURCE = "resource_config";
|
||||
static const char* CONFIG_RESOURCE_MODE = "mode";
|
||||
static const char* CONFIG_RESOURCE_MODE_DEFAULT = "simple";
|
||||
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES = "search_resources";
|
||||
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER = ",";
|
||||
|
||||
#ifdef MILVUS_CPU_VERSION
|
||||
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT = "cpu";
|
||||
/* gpu resource config */
|
||||
static const char* CONFIG_GPU_RESOURCE = "gpu_resource_config";
|
||||
static const char* CONFIG_GPU_RESOURCE_ENABLE = "enable";
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
static const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "true";
|
||||
#else
|
||||
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT = "cpu,gpu0";
|
||||
static const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "false";
|
||||
#endif
|
||||
|
||||
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE = "index_build_device";
|
||||
#ifdef MILVUS_CPU_VERSION
|
||||
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT = "cpu";
|
||||
#else
|
||||
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT = "gpu0";
|
||||
#endif
|
||||
const int32_t CPU_DEVICE_ID = -1;
|
||||
static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY = "cache_capacity";
|
||||
static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT = "4";
|
||||
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD = "cache_threshold";
|
||||
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT = "0.85";
|
||||
static const char* CONFIG_GPU_RESOURCE_DELIMITER = ",";
|
||||
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES = "search_resources";
|
||||
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT = "gpu0";
|
||||
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES = "build_index_resources";
|
||||
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT = "gpu0";
|
||||
|
||||
class Config {
|
||||
public:
|
||||
@ -170,10 +163,6 @@ class Config {
|
||||
Status
|
||||
CheckCacheConfigCpuCacheThreshold(const std::string& value);
|
||||
Status
|
||||
CheckCacheConfigGpuCacheCapacity(const std::string& value);
|
||||
Status
|
||||
CheckCacheConfigGpuCacheThreshold(const std::string& value);
|
||||
Status
|
||||
CheckCacheConfigCacheInsertData(const std::string& value);
|
||||
|
||||
/* engine config */
|
||||
@ -184,13 +173,17 @@ class Config {
|
||||
Status
|
||||
CheckEngineConfigGpuSearchThreshold(const std::string& value);
|
||||
|
||||
/* resource config */
|
||||
/* gpu resource config */
|
||||
Status
|
||||
CheckResourceConfigMode(const std::string& value);
|
||||
CheckGpuResourceConfigEnable(const std::string& value);
|
||||
Status
|
||||
CheckResourceConfigSearchResources(const std::vector<std::string>& value);
|
||||
CheckGpuResourceConfigCacheCapacity(const std::string& value);
|
||||
Status
|
||||
CheckResourceConfigIndexBuildDevice(const std::string& value);
|
||||
CheckGpuResourceConfigCacheThreshold(const std::string& value);
|
||||
Status
|
||||
CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value);
|
||||
Status
|
||||
CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value);
|
||||
|
||||
std::string
|
||||
GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = "");
|
||||
@ -217,11 +210,11 @@ class Config {
|
||||
Status
|
||||
GetDBConfigBackendUrl(std::string& value);
|
||||
Status
|
||||
GetDBConfigArchiveDiskThreshold(int32_t& value);
|
||||
GetDBConfigArchiveDiskThreshold(int64_t& value);
|
||||
Status
|
||||
GetDBConfigArchiveDaysThreshold(int32_t& value);
|
||||
GetDBConfigArchiveDaysThreshold(int64_t& value);
|
||||
Status
|
||||
GetDBConfigInsertBufferSize(int32_t& value);
|
||||
GetDBConfigInsertBufferSize(int64_t& value);
|
||||
Status
|
||||
GetDBConfigPreloadTable(std::string& value);
|
||||
|
||||
@ -239,27 +232,27 @@ class Config {
|
||||
Status
|
||||
GetCacheConfigCpuCacheThreshold(float& value);
|
||||
Status
|
||||
GetCacheConfigGpuCacheCapacity(int64_t& value);
|
||||
Status
|
||||
GetCacheConfigGpuCacheThreshold(float& value);
|
||||
Status
|
||||
GetCacheConfigCacheInsertData(bool& value);
|
||||
|
||||
/* engine config */
|
||||
Status
|
||||
GetEngineConfigUseBlasThreshold(int32_t& value);
|
||||
GetEngineConfigUseBlasThreshold(int64_t& value);
|
||||
Status
|
||||
GetEngineConfigOmpThreadNum(int32_t& value);
|
||||
GetEngineConfigOmpThreadNum(int64_t& value);
|
||||
Status
|
||||
GetEngineConfigGpuSearchThreshold(int32_t& value);
|
||||
GetEngineConfigGpuSearchThreshold(int64_t& value);
|
||||
|
||||
/* resource config */
|
||||
/* gpu resource config */
|
||||
Status
|
||||
GetResourceConfigMode(std::string& value);
|
||||
GetGpuResourceConfigEnable(bool& value);
|
||||
Status
|
||||
GetResourceConfigSearchResources(std::vector<std::string>& value);
|
||||
GetGpuResourceConfigCacheCapacity(int64_t& value);
|
||||
Status
|
||||
GetResourceConfigIndexBuildDevice(int32_t& value);
|
||||
GetGpuResourceConfigCacheThreshold(float& value);
|
||||
Status
|
||||
GetGpuResourceConfigSearchResources(std::vector<int64_t>& value);
|
||||
Status
|
||||
GetGpuResourceConfigBuildIndexResources(std::vector<int64_t>& value);
|
||||
|
||||
public:
|
||||
/* server config */
|
||||
@ -300,10 +293,6 @@ class Config {
|
||||
Status
|
||||
SetCacheConfigCpuCacheThreshold(const std::string& value);
|
||||
Status
|
||||
SetCacheConfigGpuCacheCapacity(const std::string& value);
|
||||
Status
|
||||
SetCacheConfigGpuCacheThreshold(const std::string& value);
|
||||
Status
|
||||
SetCacheConfigCacheInsertData(const std::string& value);
|
||||
|
||||
/* engine config */
|
||||
@ -314,13 +303,17 @@ class Config {
|
||||
Status
|
||||
SetEngineConfigGpuSearchThreshold(const std::string& value);
|
||||
|
||||
/* resource config */
|
||||
/* gpu resource config */
|
||||
Status
|
||||
SetResourceConfigMode(const std::string& value);
|
||||
SetGpuResourceConfigEnable(const std::string& value);
|
||||
Status
|
||||
SetResourceConfigSearchResources(const std::string& value);
|
||||
SetGpuResourceConfigCacheCapacity(const std::string& value);
|
||||
Status
|
||||
SetResourceConfigIndexBuildDevice(const std::string& value);
|
||||
SetGpuResourceConfigCacheThreshold(const std::string& value);
|
||||
Status
|
||||
SetGpuResourceConfigSearchResources(const std::string& value);
|
||||
Status
|
||||
SetGpuResourceConfigBuildIndexResources(const std::string& value);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
|
||||
|
||||
@ -89,7 +89,7 @@ DBWrapper::StartService() {
|
||||
}
|
||||
|
||||
// engine config
|
||||
int32_t omp_thread;
|
||||
int64_t omp_thread;
|
||||
s = config.GetEngineConfigOmpThreadNum(omp_thread);
|
||||
if (!s.ok()) {
|
||||
std::cerr << s.ToString() << std::endl;
|
||||
@ -100,7 +100,7 @@ DBWrapper::StartService() {
|
||||
omp_set_num_threads(omp_thread);
|
||||
SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread;
|
||||
} else {
|
||||
uint32_t sys_thread_cnt = 8;
|
||||
int64_t sys_thread_cnt = 8;
|
||||
if (CommonUtil::GetSystemAvailableThreads(sys_thread_cnt)) {
|
||||
omp_thread = static_cast<int32_t>(ceil(sys_thread_cnt * 0.5));
|
||||
omp_set_num_threads(omp_thread);
|
||||
@ -108,7 +108,7 @@ DBWrapper::StartService() {
|
||||
}
|
||||
|
||||
// init faiss global variable
|
||||
int32_t use_blas_threshold;
|
||||
int64_t use_blas_threshold;
|
||||
s = config.GetEngineConfigUseBlasThreshold(use_blas_threshold);
|
||||
if (!s.ok()) {
|
||||
std::cerr << s.ToString() << std::endl;
|
||||
@ -119,7 +119,7 @@ DBWrapper::StartService() {
|
||||
|
||||
// set archive config
|
||||
engine::ArchiveConf::CriteriaT criterial;
|
||||
int32_t disk, days;
|
||||
int64_t disk, days;
|
||||
s = config.GetDBConfigArchiveDiskThreshold(disk);
|
||||
if (!s.ok()) {
|
||||
std::cerr << s.ToString() << std::endl;
|
||||
|
||||
@ -51,7 +51,7 @@ CreatePartitionRequest::OnExecute() {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = ValidationUtil::ValidateTableName(partition_param_->partition_name());
|
||||
status = ValidationUtil::ValidatePartitionName(partition_param_->partition_name());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "utils/ValidationUtil.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
@ -38,23 +39,40 @@ DropPartitionRequest::Create(const ::milvus::grpc::PartitionParam* partition_par
|
||||
|
||||
Status
|
||||
DropPartitionRequest::OnExecute() {
|
||||
if (!partition_param_->partition_name().empty()) {
|
||||
auto status = ValidationUtil::ValidateTableName(partition_param_->partition_name());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return DBWrapper::DB()->DropPartition(partition_param_->partition_name());
|
||||
} else {
|
||||
auto status = ValidationUtil::ValidateTableName(partition_param_->table_name());
|
||||
std::string table_name = partition_param_->table_name();
|
||||
std::string partition_name = partition_param_->partition_name();
|
||||
std::string partition_tag = partition_param_->tag();
|
||||
if (!partition_name.empty()) {
|
||||
auto status = ValidationUtil::ValidateTableName(partition_name);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = ValidationUtil::ValidatePartitionTags({partition_param_->tag()});
|
||||
// check partition existence
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = partition_name;
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
if (status.code() == DB_NOT_FOUND) {
|
||||
return Status(SERVER_TABLE_NOT_EXIST,
|
||||
"Table " + table_name + "'s partition " + partition_name + " not found");
|
||||
} else {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return DBWrapper::DB()->DropPartition(partition_name);
|
||||
} else {
|
||||
auto status = ValidationUtil::ValidateTableName(table_name);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return DBWrapper::DB()->DropPartitionByTag(partition_param_->table_name(), partition_param_->tag());
|
||||
|
||||
status = ValidationUtil::ValidatePartitionTags({partition_tag});
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return DBWrapper::DB()->DropPartitionByTag(table_name, partition_tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ SearchRequest::OnExecute() {
|
||||
|
||||
// step 7: construct result array
|
||||
topk_result_->set_row_num(record_count);
|
||||
topk_result_->mutable_ids()->Resize(static_cast<int>(result_ids.size()), 0);
|
||||
topk_result_->mutable_ids()->Resize(static_cast<int>(result_ids.size()), -1);
|
||||
memcpy(topk_result_->mutable_ids()->mutable_data(), result_ids.data(), result_ids.size() * sizeof(int64_t));
|
||||
topk_result_->mutable_distances()->Resize(static_cast<int>(result_distances.size()), 0.0);
|
||||
memcpy(topk_result_->mutable_distances()->mutable_data(), result_distances.data(),
|
||||
|
||||
@ -54,7 +54,7 @@ CommonUtil::GetSystemMemInfo(uint64_t& total_mem, uint64_t& free_mem) {
|
||||
}
|
||||
|
||||
bool
|
||||
CommonUtil::GetSystemAvailableThreads(uint32_t& thread_count) {
|
||||
CommonUtil::GetSystemAvailableThreads(int64_t& thread_count) {
|
||||
// threadCnt = std::thread::hardware_concurrency();
|
||||
thread_count = sysconf(_SC_NPROCESSORS_CONF);
|
||||
thread_count *= THREAD_MULTIPLY_CPU;
|
||||
|
||||
@ -30,7 +30,7 @@ class CommonUtil {
|
||||
static bool
|
||||
GetSystemMemInfo(uint64_t& total_mem, uint64_t& free_mem);
|
||||
static bool
|
||||
GetSystemAvailableThreads(uint32_t& thread_count);
|
||||
GetSystemAvailableThreads(int64_t& thread_count);
|
||||
|
||||
static bool
|
||||
IsFileExist(const std::string& path);
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "utils/ValidationUtil.h"
|
||||
#include "Log.h"
|
||||
#include "db/engine/ExecutionEngine.h"
|
||||
#include "utils/StringHelpFunctions.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
@ -168,11 +169,26 @@ ValidationUtil::ValidateSearchNprobe(int64_t nprobe, const engine::meta::TableSc
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status
|
||||
ValidationUtil::ValidatePartitionName(const std::string& partition_name) {
|
||||
if (partition_name.empty()) {
|
||||
std::string msg = "Partition name should not be empty.";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TABLE_NAME, msg);
|
||||
}
|
||||
|
||||
return ValidateTableName(partition_name);
|
||||
}
|
||||
|
||||
Status
|
||||
ValidationUtil::ValidatePartitionTags(const std::vector<std::string>& partition_tags) {
|
||||
for (auto& tag : partition_tags) {
|
||||
if (tag.empty()) {
|
||||
std::string msg = "Invalid partition tag: " + tag + ". " + "Partition tag should not be empty.";
|
||||
for (const std::string& tag : partition_tags) {
|
||||
// trim side-blank of tag, only compare valid characters
|
||||
// for example: " ab cd " is treated as "ab cd"
|
||||
std::string valid_tag = tag;
|
||||
StringHelpFunctions::TrimStringBlank(valid_tag);
|
||||
if (valid_tag.empty()) {
|
||||
std::string msg = "Invalid partition tag: " + valid_tag + ". " + "Partition tag should not be empty.";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_NPROBE, msg);
|
||||
}
|
||||
@ -182,7 +198,7 @@ ValidationUtil::ValidatePartitionTags(const std::vector<std::string>& partition_
|
||||
}
|
||||
|
||||
Status
|
||||
ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) {
|
||||
ValidationUtil::ValidateGpuIndex(int32_t gpu_index) {
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
int num_devices = 0;
|
||||
auto cuda_err = cudaGetDeviceCount(&num_devices);
|
||||
@ -203,7 +219,7 @@ ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) {
|
||||
}
|
||||
|
||||
Status
|
||||
ValidationUtil::GetGpuMemory(uint32_t gpu_index, size_t& memory) {
|
||||
ValidationUtil::GetGpuMemory(int32_t gpu_index, size_t& memory) {
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
|
||||
cudaDeviceProp deviceProp;
|
||||
|
||||
@ -55,14 +55,17 @@ class ValidationUtil {
|
||||
static Status
|
||||
ValidateSearchNprobe(int64_t nprobe, const engine::meta::TableSchema& table_schema);
|
||||
|
||||
static Status
|
||||
ValidatePartitionName(const std::string& partition_name);
|
||||
|
||||
static Status
|
||||
ValidatePartitionTags(const std::vector<std::string>& partition_tags);
|
||||
|
||||
static Status
|
||||
ValidateGpuIndex(uint32_t gpu_index);
|
||||
ValidateGpuIndex(int32_t gpu_index);
|
||||
|
||||
static Status
|
||||
GetGpuMemory(uint32_t gpu_index, size_t& memory);
|
||||
GetGpuMemory(int32_t gpu_index, size_t& memory);
|
||||
|
||||
static Status
|
||||
ValidateIpAddress(const std::string& ip_address);
|
||||
|
||||
@ -47,7 +47,8 @@ ConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
auto conf = std::make_shared<knowhere::Cfg>();
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
conf->gpu_id = conf->gpu_id;
|
||||
conf->gpu_id = metaconf.gpu_id;
|
||||
conf->k = metaconf.k;
|
||||
MatchBase(conf);
|
||||
return conf;
|
||||
}
|
||||
@ -65,7 +66,7 @@ IVFConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
conf->gpu_id = conf->gpu_id;
|
||||
conf->gpu_id = metaconf.gpu_id;
|
||||
MatchBase(conf);
|
||||
return conf;
|
||||
}
|
||||
@ -114,7 +115,7 @@ IVFSQConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
conf->gpu_id = conf->gpu_id;
|
||||
conf->gpu_id = metaconf.gpu_id;
|
||||
conf->nbits = 8;
|
||||
MatchBase(conf);
|
||||
return conf;
|
||||
@ -126,7 +127,7 @@ IVFPQConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
conf->gpu_id = conf->gpu_id;
|
||||
conf->gpu_id = metaconf.gpu_id;
|
||||
conf->nbits = 8;
|
||||
|
||||
if (!(conf->d % 4))
|
||||
@ -175,21 +176,17 @@ NSGConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
conf->gpu_id = conf->gpu_id;
|
||||
conf->gpu_id = metaconf.gpu_id;
|
||||
conf->k = metaconf.k;
|
||||
|
||||
double factor = metaconf.size / TYPICAL_COUNT;
|
||||
auto scale_factor = round(metaconf.dim / 128.0);
|
||||
scale_factor = scale_factor >= 4 ? 4 : scale_factor;
|
||||
conf->nprobe = conf->nlist > 10000 ? conf->nlist * 0.02 : conf->nlist * 0.1;
|
||||
conf->knng = (100 + 100 * scale_factor) * factor;
|
||||
conf->search_length = (40 + 5 * scale_factor) * factor;
|
||||
conf->out_degree = (50 + 5 * scale_factor) * factor;
|
||||
conf->candidate_pool_size = (200 + 100 * scale_factor) * factor;
|
||||
conf->nprobe = int64_t(conf->nlist * 0.01);
|
||||
conf->knng = 40 + 10 * scale_factor; // the size of knng
|
||||
conf->search_length = 40 + 5 * scale_factor;
|
||||
conf->out_degree = 50 + 5 * scale_factor;
|
||||
conf->candidate_pool_size = 200 + 100 * scale_factor;
|
||||
MatchBase(conf);
|
||||
|
||||
// WRAPPER_LOG_DEBUG << "nlist: " << conf->nlist
|
||||
// << ", gpu_id: " << conf->gpu_id << ", d: " << conf->d
|
||||
// << ", nprobe: " << conf->nprobe << ", knng: " << conf->knng;
|
||||
return conf;
|
||||
}
|
||||
|
||||
@ -204,5 +201,35 @@ NSGConfAdapter::MatchSearch(const TempMetaConf& metaconf, const IndexType& type)
|
||||
return conf;
|
||||
}
|
||||
|
||||
knowhere::Config
|
||||
SPTAGKDTConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
auto conf = std::make_shared<knowhere::KDTCfg>();
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
return conf;
|
||||
}
|
||||
|
||||
knowhere::Config
|
||||
SPTAGKDTConfAdapter::MatchSearch(const TempMetaConf& metaconf, const IndexType& type) {
|
||||
auto conf = std::make_shared<knowhere::KDTCfg>();
|
||||
conf->k = metaconf.k;
|
||||
return conf;
|
||||
}
|
||||
|
||||
knowhere::Config
|
||||
SPTAGBKTConfAdapter::Match(const TempMetaConf& metaconf) {
|
||||
auto conf = std::make_shared<knowhere::BKTCfg>();
|
||||
conf->d = metaconf.dim;
|
||||
conf->metric_type = metaconf.metric_type;
|
||||
return conf;
|
||||
}
|
||||
|
||||
knowhere::Config
|
||||
SPTAGBKTConfAdapter::MatchSearch(const TempMetaConf& metaconf, const IndexType& type) {
|
||||
auto conf = std::make_shared<knowhere::BKTCfg>();
|
||||
conf->k = metaconf.k;
|
||||
return conf;
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
} // namespace milvus
|
||||
|
||||
@ -46,9 +46,6 @@ class ConfAdapter {
|
||||
virtual knowhere::Config
|
||||
MatchSearch(const TempMetaConf& metaconf, const IndexType& type);
|
||||
|
||||
// virtual void
|
||||
// Dump(){}
|
||||
|
||||
protected:
|
||||
static void
|
||||
MatchBase(knowhere::Config conf);
|
||||
@ -97,5 +94,23 @@ class NSGConfAdapter : public IVFConfAdapter {
|
||||
MatchSearch(const TempMetaConf& metaconf, const IndexType& type) final;
|
||||
};
|
||||
|
||||
class SPTAGKDTConfAdapter : public ConfAdapter {
|
||||
public:
|
||||
knowhere::Config
|
||||
Match(const TempMetaConf& metaconf) override;
|
||||
|
||||
knowhere::Config
|
||||
MatchSearch(const TempMetaConf& metaconf, const IndexType& type) override;
|
||||
};
|
||||
|
||||
class SPTAGBKTConfAdapter : public ConfAdapter {
|
||||
public:
|
||||
knowhere::Config
|
||||
Match(const TempMetaConf& metaconf) override;
|
||||
|
||||
knowhere::Config
|
||||
MatchSearch(const TempMetaConf& metaconf, const IndexType& type) override;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
} // namespace milvus
|
||||
|
||||
@ -56,6 +56,9 @@ AdapterMgr::RegisterAdapter() {
|
||||
REGISTER_CONF_ADAPTER(IVFPQConfAdapter, IndexType::FAISS_IVFPQ_MIX, ivfpq_mix);
|
||||
|
||||
REGISTER_CONF_ADAPTER(NSGConfAdapter, IndexType::NSG_MIX, nsg_mix);
|
||||
|
||||
REGISTER_CONF_ADAPTER(SPTAGKDTConfAdapter, IndexType::SPTAG_KDT_RNT_CPU, sptag_kdt);
|
||||
REGISTER_CONF_ADAPTER(SPTAGBKTConfAdapter, IndexType::SPTAG_BKT_RNT_CPU, sptag_bkt);
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
#include "knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h"
|
||||
#endif
|
||||
|
||||
#include "scheduler/Utils.h"
|
||||
#include "server/Config.h"
|
||||
|
||||
#include <map>
|
||||
@ -35,7 +37,6 @@ constexpr int64_t M_BYTE = 1024 * 1024;
|
||||
Status
|
||||
KnowhereResource::Initialize() {
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
|
||||
struct GpuResourceSetting {
|
||||
int64_t pinned_memory = 300 * M_BYTE;
|
||||
int64_t temp_memory = 300 * M_BYTE;
|
||||
@ -47,27 +48,22 @@ KnowhereResource::Initialize() {
|
||||
|
||||
// get build index gpu resource
|
||||
server::Config& config = server::Config::GetInstance();
|
||||
|
||||
int32_t build_index_gpu;
|
||||
s = config.GetResourceConfigIndexBuildDevice(build_index_gpu);
|
||||
std::vector<int64_t> build_index_gpus;
|
||||
s = config.GetGpuResourceConfigBuildIndexResources(build_index_gpus);
|
||||
if (!s.ok())
|
||||
return s;
|
||||
|
||||
gpu_resources.insert(std::make_pair(build_index_gpu, GpuResourceSetting()));
|
||||
for (auto gpu_id : build_index_gpus) {
|
||||
gpu_resources.insert(std::make_pair(gpu_id, GpuResourceSetting()));
|
||||
}
|
||||
|
||||
// get search gpu resource
|
||||
std::vector<std::string> pool;
|
||||
s = config.GetResourceConfigSearchResources(pool);
|
||||
std::vector<int64_t> search_gpus;
|
||||
s = config.GetGpuResourceConfigSearchResources(search_gpus);
|
||||
if (!s.ok())
|
||||
return s;
|
||||
|
||||
std::set<uint64_t> gpu_ids;
|
||||
for (auto& resource : pool) {
|
||||
if (resource.length() < 4 || resource.substr(0, 3) != "gpu") {
|
||||
// invalid
|
||||
continue;
|
||||
}
|
||||
auto gpu_id = std::stoi(resource.substr(3));
|
||||
for (auto& gpu_id : search_gpus) {
|
||||
gpu_resources.insert(std::make_pair(gpu_id, GpuResourceSetting()));
|
||||
}
|
||||
|
||||
|
||||
@ -21,17 +21,19 @@
|
||||
#include "knowhere/index/vector_index/IndexIDMAP.h"
|
||||
#include "utils/Log.h"
|
||||
#include "wrapper/WrapperException.h"
|
||||
#include "wrapper/gpu/GPUVecImpl.h"
|
||||
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
|
||||
#include <src/index/knowhere/knowhere/index/vector_index/IndexGPUIVF.h>
|
||||
#include <src/index/knowhere/knowhere/index/vector_index/helpers/Cloner.h>
|
||||
#include "knowhere/index/vector_index/IndexGPUIVF.h"
|
||||
#include "knowhere/index/vector_index/IndexIVFSQHybrid.h"
|
||||
#include "knowhere/index/vector_index/helpers/Cloner.h"
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* no parameter check in this layer.
|
||||
* only responible for index combination
|
||||
* only responsible for index combination
|
||||
*/
|
||||
|
||||
namespace milvus {
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
#include "knowhere/index/vector_index/IndexIVF.h"
|
||||
#include "knowhere/index/vector_index/IndexIVFPQ.h"
|
||||
#include "knowhere/index/vector_index/IndexIVFSQ.h"
|
||||
#include "knowhere/index/vector_index/IndexKDT.h"
|
||||
#include "knowhere/index/vector_index/IndexNSG.h"
|
||||
#include "knowhere/index/vector_index/IndexSPTAG.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
#ifdef MILVUS_GPU_VERSION
|
||||
@ -128,7 +128,11 @@ GetVecIndexFactory(const IndexType& type, const Config& cfg) {
|
||||
break;
|
||||
}
|
||||
case IndexType::SPTAG_KDT_RNT_CPU: {
|
||||
index = std::make_shared<knowhere::CPUKDTRNG>();
|
||||
index = std::make_shared<knowhere::CPUSPTAGRNG>("KDT");
|
||||
break;
|
||||
}
|
||||
case IndexType::SPTAG_BKT_RNT_CPU: {
|
||||
index = std::make_shared<knowhere::CPUSPTAGRNG>("BKT");
|
||||
break;
|
||||
}
|
||||
case IndexType::FAISS_IVFSQ8_CPU: {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user