Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
3b107731
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3b107731
编写于
10月 10, 2019
作者:
W
wxyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MS-626 Refactor DataObj to support cache any type data
Former-commit-id: 7795e47deb81657c484d4d90acb49adf9ed4501c
上级
6b025329
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
94 addition
and
65 deletion
+94
-65
cpp/CHANGELOG.md
cpp/CHANGELOG.md
+1
-0
cpp/src/cache/Cache.inl
cpp/src/cache/Cache.inl
+6
-6
cpp/src/cache/CpuCacheMgr.cpp
cpp/src/cache/CpuCacheMgr.cpp
+2
-6
cpp/src/cache/CpuCacheMgr.h
cpp/src/cache/CpuCacheMgr.h
+1
-1
cpp/src/cache/DataObj.h
cpp/src/cache/DataObj.h
+2
-32
cpp/src/cache/GpuCacheMgr.cpp
cpp/src/cache/GpuCacheMgr.cpp
+2
-6
cpp/src/cache/GpuCacheMgr.h
cpp/src/cache/GpuCacheMgr.h
+1
-1
cpp/src/db/engine/ExecutionEngineImpl.cpp
cpp/src/db/engine/ExecutionEngineImpl.cpp
+59
-5
cpp/src/db/engine/ExecutionEngineImpl.h
cpp/src/db/engine/ExecutionEngineImpl.h
+3
-0
cpp/src/wrapper/VecIndex.cpp
cpp/src/wrapper/VecIndex.cpp
+5
-0
cpp/src/wrapper/VecIndex.h
cpp/src/wrapper/VecIndex.h
+5
-1
cpp/unittest/scheduler/test_scheduler.cpp
cpp/unittest/scheduler/test_scheduler.cpp
+1
-1
cpp/unittest/server/test_cache.cpp
cpp/unittest/server/test_cache.cpp
+6
-6
未找到文件。
cpp/CHANGELOG.md
浏览文件 @
3b107731
...
...
@@ -28,6 +28,7 @@ Please mark all change in change log and use the ticket from JIRA.
-
MS-609 - Update task construct function
-
MS-611 - Add resources validity check in ResourceMgr
-
MS-619 - Add optimizer class in scheduler
-
MS-626 - Refactor DataObj to support cache any type data
## New Feature
...
...
cpp/src/cache/Cache.inl
浏览文件 @
3b107731
...
...
@@ -86,11 +86,11 @@ Cache<ItemObj>::insert(const std::string &key, const ItemObj &item) {
//if key already exist, subtract old item size
if (lru_.exists(key)) {
const ItemObj &old_item = lru_.get(key);
usage_ -= old_item->
s
ize();
usage_ -= old_item->
S
ize();
}
//plus new item size
usage_ += item->
s
ize();
usage_ += item->
S
ize();
}
//if usage exceed capacity, free some items
...
...
@@ -106,7 +106,7 @@ Cache<ItemObj>::insert(const std::string &key, const ItemObj &item) {
std::lock_guard<std::mutex> lock(mutex_);
lru_.put(key, item);
SERVER_LOG_DEBUG << "Insert " << key << " size:" << item->
s
ize()
SERVER_LOG_DEBUG << "Insert " << key << " size:" << item->
S
ize()
<< " bytes into cache, usage: " << usage_ << " bytes";
}
}
...
...
@@ -120,9 +120,9 @@ Cache<ItemObj>::erase(const std::string &key) {
}
const ItemObj &old_item = lru_.get(key);
usage_ -= old_item->
s
ize();
usage_ -= old_item->
S
ize();
SERVER_LOG_DEBUG << "Erase " << key << " size: " << old_item->
s
ize();
SERVER_LOG_DEBUG << "Erase " << key << " size: " << old_item->
S
ize();
lru_.erase(key);
}
...
...
@@ -160,7 +160,7 @@ Cache<ItemObj>::free_memory() {
auto &obj_ptr = it->second;
key_array.emplace(key);
released_size += obj_ptr->
s
ize();
released_size += obj_ptr->
S
ize();
++it;
}
}
...
...
cpp/src/cache/CpuCacheMgr.cpp
浏览文件 @
3b107731
...
...
@@ -59,14 +59,10 @@ CpuCacheMgr::GetInstance() {
return
&
s_mgr
;
}
engine
::
VecIndex
Ptr
DataObj
Ptr
CpuCacheMgr
::
GetIndex
(
const
std
::
string
&
key
)
{
DataObjPtr
obj
=
GetItem
(
key
);
if
(
obj
!=
nullptr
)
{
return
obj
->
data
();
}
return
nullptr
;
return
obj
;
}
}
// namespace cache
...
...
cpp/src/cache/CpuCacheMgr.h
浏览文件 @
3b107731
...
...
@@ -35,7 +35,7 @@ class CpuCacheMgr : public CacheMgr<DataObjPtr> {
static
CpuCacheMgr
*
GetInstance
();
engine
::
VecIndex
Ptr
DataObj
Ptr
GetIndex
(
const
std
::
string
&
key
);
};
...
...
cpp/src/cache/DataObj.h
浏览文件 @
3b107731
...
...
@@ -17,7 +17,6 @@
#pragma once
#include "src/wrapper/VecIndex.h"
#include <memory>
...
...
@@ -26,38 +25,9 @@ namespace cache {
class
DataObj
{
public:
explicit
DataObj
(
const
engine
::
VecIndexPtr
&
index
)
:
index_
(
index
)
{
}
virtual
int64_t
Size
()
=
0
;
DataObj
(
const
engine
::
VecIndexPtr
&
index
,
int64_t
size
)
:
index_
(
index
),
size_
(
size
)
{
}
engine
::
VecIndexPtr
data
()
{
return
index_
;
}
const
engine
::
VecIndexPtr
&
data
()
const
{
return
index_
;
}
int64_t
size
()
const
{
if
(
index_
==
nullptr
)
{
return
0
;
}
if
(
size_
>
0
)
{
return
size_
;
}
return
index_
->
Count
()
*
index_
->
Dimension
()
*
sizeof
(
float
);
}
private:
engine
::
VecIndexPtr
index_
=
nullptr
;
int64_t
size_
=
0
;
};
using
DataObjPtr
=
std
::
shared_ptr
<
DataObj
>
;
...
...
cpp/src/cache/GpuCacheMgr.cpp
浏览文件 @
3b107731
...
...
@@ -71,14 +71,10 @@ GpuCacheMgr::GetInstance(uint64_t gpu_id) {
}
}
engine
::
VecIndex
Ptr
DataObj
Ptr
GpuCacheMgr
::
GetIndex
(
const
std
::
string
&
key
)
{
DataObjPtr
obj
=
GetItem
(
key
);
if
(
obj
!=
nullptr
)
{
return
obj
->
data
();
}
return
nullptr
;
return
obj
;
}
}
// namespace cache
...
...
cpp/src/cache/GpuCacheMgr.h
浏览文件 @
3b107731
...
...
@@ -35,7 +35,7 @@ class GpuCacheMgr : public CacheMgr<DataObjPtr> {
static
GpuCacheMgr
*
GetInstance
(
uint64_t
gpu_id
);
engine
::
VecIndex
Ptr
DataObj
Ptr
GetIndex
(
const
std
::
string
&
key
);
private:
...
...
cpp/src/db/engine/ExecutionEngineImpl.cpp
浏览文件 @
3b107731
...
...
@@ -91,6 +91,60 @@ ExecutionEngineImpl::CreatetVecIndex(EngineType type) {
return
index
;
}
void
ExecutionEngineImpl
::
HybridLoad
()
{
// if (index_type_ != EngineType::FAISS_IVFSQ8Hybrid) {
// return;
// }
//
// const std::string key = location_ + ".quantizer";
// std::vector<uint64_t> gpus;
//
// // cache hit
// {
// int64_t selected = -1;
// void* quantizer = nullptr;
// for (auto& gpu : gpus) {
// auto cache = cache::GpuCacheMgr::GetInstance(gpu);
// if (auto quan = cache->GetIndex(key)) {
// selected = gpu;
// quantizer = quan;
// }
// }
//
// if (selected != -1) {
// // set quantizer into index;
// return;
// }
// }
//
// // cache miss
// {
// 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 = std::distance(all_free_mem.begin(), max_e);
//
// // load to best device;
// // cache quantizer
// }
//
// // if index_type == Hybrid
//
// // 1. quantizer in which gpu
//
// // 2.1 which gpu cache best
//
// // 2.2 load to that gpu cache
//
// // set quantizer into index
}
Status
ExecutionEngineImpl
::
AddWithIds
(
int64_t
n
,
const
float
*
xdata
,
const
int64_t
*
xids
)
{
auto
status
=
index_
->
Add
(
n
,
xdata
,
xids
);
...
...
@@ -133,7 +187,7 @@ ExecutionEngineImpl::Serialize() {
Status
ExecutionEngineImpl
::
Load
(
bool
to_cache
)
{
index_
=
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
location_
);
index_
=
std
::
static_pointer_cast
<
VecIndex
>
(
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
location_
)
);
bool
already_in_cache
=
(
index_
!=
nullptr
);
if
(
!
already_in_cache
)
{
try
{
...
...
@@ -161,7 +215,7 @@ ExecutionEngineImpl::Load(bool to_cache) {
Status
ExecutionEngineImpl
::
CopyToGpu
(
uint64_t
device_id
)
{
auto
index
=
cache
::
GpuCacheMgr
::
GetInstance
(
device_id
)
->
GetIndex
(
location_
);
auto
index
=
std
::
static_pointer_cast
<
VecIndex
>
(
cache
::
GpuCacheMgr
::
GetInstance
(
device_id
)
->
GetIndex
(
location_
)
);
bool
already_in_cache
=
(
index
!=
nullptr
);
if
(
already_in_cache
)
{
index_
=
index
;
...
...
@@ -189,7 +243,7 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id) {
Status
ExecutionEngineImpl
::
CopyToCpu
()
{
auto
index
=
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
location_
);
auto
index
=
std
::
static_pointer_cast
<
VecIndex
>
(
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
location_
)
);
bool
already_in_cache
=
(
index
!=
nullptr
);
if
(
already_in_cache
)
{
index_
=
index
;
...
...
@@ -322,7 +376,7 @@ ExecutionEngineImpl::Search(int64_t n, const float* data, int64_t k, int64_t npr
Status
ExecutionEngineImpl
::
Cache
()
{
cache
::
DataObjPtr
obj
=
std
::
make_shared
<
cache
::
DataObj
>
(
index_
,
PhysicalSize
()
);
cache
::
DataObjPtr
obj
=
std
::
static_pointer_cast
<
cache
::
DataObj
>
(
index_
);
milvus
::
cache
::
CpuCacheMgr
::
GetInstance
()
->
InsertItem
(
location_
,
obj
);
return
Status
::
OK
();
...
...
@@ -330,7 +384,7 @@ ExecutionEngineImpl::Cache() {
Status
ExecutionEngineImpl
::
GpuCache
(
uint64_t
gpu_id
)
{
cache
::
DataObjPtr
obj
=
std
::
make_shared
<
cache
::
DataObj
>
(
index_
,
PhysicalSize
()
);
cache
::
DataObjPtr
obj
=
std
::
static_pointer_cast
<
cache
::
DataObj
>
(
index_
);
milvus
::
cache
::
GpuCacheMgr
::
GetInstance
(
gpu_id
)
->
InsertItem
(
location_
,
obj
);
return
Status
::
OK
();
...
...
cpp/src/db/engine/ExecutionEngineImpl.h
浏览文件 @
3b107731
...
...
@@ -104,6 +104,9 @@ class ExecutionEngineImpl : public ExecutionEngine {
VecIndexPtr
Load
(
const
std
::
string
&
location
);
void
HybridLoad
();
protected:
VecIndexPtr
index_
=
nullptr
;
EngineType
index_type_
;
...
...
cpp/src/wrapper/VecIndex.cpp
浏览文件 @
3b107731
...
...
@@ -34,6 +34,11 @@
namespace
milvus
{
namespace
engine
{
int64_t
VecIndex
::
Size
()
{
return
Count
()
*
Dimension
()
*
sizeof
(
float
);
}
struct
FileIOReader
{
std
::
fstream
fs
;
std
::
string
name
;
...
...
cpp/src/wrapper/VecIndex.h
浏览文件 @
3b107731
...
...
@@ -20,6 +20,7 @@
#include <memory>
#include <string>
#include "cache/DataObj.h"
#include "knowhere/common/BinarySet.h"
#include "knowhere/common/Config.h"
#include "utils/Status.h"
...
...
@@ -48,7 +49,7 @@ class VecIndex;
using
VecIndexPtr
=
std
::
shared_ptr
<
VecIndex
>
;
class
VecIndex
{
class
VecIndex
:
public
cache
::
DataObj
{
public:
virtual
Status
BuildAll
(
const
int64_t
&
nb
,
const
float
*
xb
,
const
int64_t
*
ids
,
const
Config
&
cfg
,
const
int64_t
&
nt
=
0
,
...
...
@@ -81,6 +82,9 @@ class VecIndex {
virtual
int64_t
Count
()
=
0
;
int64_t
Size
()
override
;
virtual
knowhere
::
BinarySet
Serialize
()
=
0
;
...
...
cpp/unittest/scheduler/test_scheduler.cpp
浏览文件 @
3b107731
...
...
@@ -141,7 +141,7 @@ insert_dummy_index_into_gpu_cache(uint64_t device_id) {
mock_index
->
ntotal_
=
1000
;
engine
::
VecIndexPtr
index
(
mock_index
);
cache
::
DataObjPtr
obj
=
std
::
make_shared
<
cache
::
DataObj
>
(
index
);
cache
::
DataObjPtr
obj
=
std
::
static_pointer_cast
<
cache
::
DataObj
>
(
index
);
cache
::
GpuCacheMgr
::
GetInstance
(
device_id
)
->
InsertItem
(
"location"
,
obj
);
}
...
...
cpp/unittest/server/test_cache.cpp
浏览文件 @
3b107731
...
...
@@ -145,7 +145,7 @@ TEST(CacheTest, CPU_CACHE_TEST) {
for
(
uint64_t
i
=
0
;
i
<
item_count
;
i
++
)
{
//each vector is 1k byte, total size less than 1G
ms
::
engine
::
VecIndexPtr
mock_index
=
std
::
make_shared
<
MockVecIndex
>
(
256
,
1000000
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
ms
::
cache
::
DataObj
>
(
mock_index
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
static_pointer_cast
<
ms
::
cache
::
DataObj
>
(
mock_index
);
cpu_mgr
->
InsertItem
(
"index_"
+
std
::
to_string
(
i
),
data_obj
);
}
ASSERT_LT
(
cpu_mgr
->
ItemCount
(),
g_num
);
...
...
@@ -169,7 +169,7 @@ TEST(CacheTest, CPU_CACHE_TEST) {
//each vector is 1k byte, total size less than 6G
ms
::
engine
::
VecIndexPtr
mock_index
=
std
::
make_shared
<
MockVecIndex
>
(
256
,
6000000
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
ms
::
cache
::
DataObj
>
(
mock_index
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
static_pointer_cast
<
ms
::
cache
::
DataObj
>
(
mock_index
);
cpu_mgr
->
InsertItem
(
"index_6g"
,
data_obj
);
ASSERT_TRUE
(
cpu_mgr
->
ItemExists
(
"index_6g"
));
}
...
...
@@ -183,7 +183,7 @@ TEST(CacheTest, GPU_CACHE_TEST) {
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
//each vector is 1k byte
ms
::
engine
::
VecIndexPtr
mock_index
=
std
::
make_shared
<
MockVecIndex
>
(
256
,
1000
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
ms
::
cache
::
DataObj
>
(
mock_index
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
static_pointer_cast
<
ms
::
cache
::
DataObj
>
(
mock_index
);
gpu_mgr
->
InsertItem
(
"index_"
+
std
::
to_string
(
i
),
data_obj
);
}
...
...
@@ -196,8 +196,8 @@ TEST(CacheTest, GPU_CACHE_TEST) {
// TODO(myh): use gpu index to mock
//each vector is 1k byte, total size less than 2G
ms
::
engine
::
VecIndexPtr
mock_index
=
std
::
make_shared
<
MockVecIndex
>
(
256
,
2000000
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
ms
::
cache
::
DataObj
>
(
mock_index
);
std
::
cout
<<
data_obj
->
s
ize
()
<<
std
::
endl
;
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
static_pointer_cast
<
ms
::
cache
::
DataObj
>
(
mock_index
);
std
::
cout
<<
data_obj
->
S
ize
()
<<
std
::
endl
;
gpu_mgr
->
InsertItem
(
"index_"
+
std
::
to_string
(
i
),
data_obj
);
}
...
...
@@ -227,7 +227,7 @@ TEST(CacheTest, INVALID_TEST) {
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
//each vector is 1k byte
ms
::
engine
::
VecIndexPtr
mock_index
=
std
::
make_shared
<
MockVecIndex
>
(
256
,
2
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
ms
::
cache
::
DataObj
>
(
mock_index
);
ms
::
cache
::
DataObjPtr
data_obj
=
std
::
static_pointer_cast
<
ms
::
cache
::
DataObj
>
(
mock_index
);
mgr
.
InsertItem
(
"index_"
+
std
::
to_string
(
i
),
data_obj
);
}
ASSERT_EQ
(
mgr
.
GetItem
(
"index_0"
),
nullptr
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录