Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
30b43758
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,发现更多精彩内容 >>
提交
30b43758
编写于
8月 22, 2019
作者:
Y
Yu Kun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add GpuCacheMgr and unittest
Former-commit-id: 57e2a59b5039fca56e10c56ee5474472d87faa9a
上级
a6ef8bec
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
74 addition
and
33 deletion
+74
-33
cpp/src/cache/Cache.h
cpp/src/cache/Cache.h
+2
-1
cpp/src/cache/CacheMgr.cpp
cpp/src/cache/CacheMgr.cpp
+19
-0
cpp/src/cache/CacheMgr.h
cpp/src/cache/CacheMgr.h
+2
-0
cpp/src/cache/CpuCacheMgr.h
cpp/src/cache/CpuCacheMgr.h
+1
-0
cpp/src/cache/GpuCacheMgr.cpp
cpp/src/cache/GpuCacheMgr.cpp
+20
-16
cpp/src/cache/GpuCacheMgr.h
cpp/src/cache/GpuCacheMgr.h
+10
-9
cpp/unittest/db/db_tests.cpp
cpp/unittest/db/db_tests.cpp
+0
-6
cpp/unittest/server/cache_test.cpp
cpp/unittest/server/cache_test.cpp
+20
-1
未找到文件。
cpp/src/cache/Cache.h
浏览文件 @
30b43758
...
...
@@ -46,7 +46,8 @@ public:
double
freemem_percent
()
const
{
return
freemem_percent_
;
};
void
set_freemem_percent
(
double
percent
)
{
freemem_percent_
=
percent
;
}
void
set_gpu_ids
(
std
::
vector
<
uint64_t
>
gpu_ids
)
{
gpu_ids_
.
assign
(
gpu_ids
.
begin
(),
gpu_ids
.
end
());
}
void
set_gpu_ids
(
std
::
vector
<
uint64_t
>&
gpu_ids
)
{
gpu_ids_
=
gpu_ids
;
}
std
::
vector
<
uint64_t
>
gpu_ids
()
const
{
return
gpu_ids_
;
}
size_t
size
()
const
;
...
...
cpp/src/cache/CacheMgr.cpp
浏览文件 @
30b43758
...
...
@@ -56,6 +56,7 @@ engine::VecIndexPtr CacheMgr::GetIndex(const std::string& key) {
}
void
CacheMgr
::
InsertItem
(
const
std
::
string
&
key
,
const
DataObjPtr
&
data
)
{
std
::
cout
<<
"dashalk
\n
"
;
if
(
cache_
==
nullptr
)
{
SERVER_LOG_ERROR
<<
"Cache doesn't exist"
;
return
;
...
...
@@ -130,6 +131,24 @@ void CacheMgr::SetCapacity(int64_t capacity) {
cache_
->
set_capacity
(
capacity
);
}
std
::
vector
<
uint64_t
>
CacheMgr
::
GpuIds
()
const
{
if
(
cache_
==
nullptr
)
{
SERVER_LOG_ERROR
<<
"Cache doesn't exist"
;
std
::
vector
<
uint64_t
>
gpu_ids
;
return
gpu_ids
;
}
return
cache_
->
gpu_ids
();
}
void
CacheMgr
::
SetGpuIds
(
std
::
vector
<
uint64_t
>
gpu_ids
){
if
(
cache_
==
nullptr
)
{
SERVER_LOG_ERROR
<<
"Cache doesn't exist"
;
return
;
}
cache_
->
set_gpu_ids
(
gpu_ids
);
}
}
}
}
cpp/src/cache/CacheMgr.h
浏览文件 @
30b43758
...
...
@@ -33,6 +33,8 @@ public:
int64_t
CacheUsage
()
const
;
int64_t
CacheCapacity
()
const
;
void
SetCapacity
(
int64_t
capacity
);
std
::
vector
<
uint64_t
>
GpuIds
()
const
;
void
SetGpuIds
(
std
::
vector
<
uint64_t
>
gpu_ids
);
protected:
CacheMgr
();
...
...
cpp/src/cache/CpuCacheMgr.h
浏览文件 @
30b43758
...
...
@@ -16,6 +16,7 @@ private:
CpuCacheMgr
();
public:
//TODO: use smart pointer instead
static
CacheMgr
*
GetInstance
()
{
static
CpuCacheMgr
s_mgr
;
return
&
s_mgr
;
...
...
cpp/src/cache/GpuCacheMgr.cpp
浏览文件 @
30b43758
...
...
@@ -13,20 +13,16 @@ namespace milvus {
namespace
cache
{
std
::
mutex
GpuCacheMgr
::
mutex_
;
std
::
unordered_map
<
uint64_t
,
GpuCacheMgr
*
>
GpuCacheMgr
::
instance_
;
std
::
unordered_map
<
uint64_t
,
GpuCacheMgr
Ptr
>
GpuCacheMgr
::
instance_
;
namespace
{
constexpr
int64_t
unit
=
1024
*
1024
*
1024
;
}
GpuCacheMgr
::
GpuCacheMgr
()
{
server
::
ConfigNode
&
config
=
server
::
ServerConfig
::
GetInstance
().
GetConfig
(
server
::
CONFIG_CACHE
);
std
::
string
gpu_ids_str
=
config
.
GetValue
(
server
::
CONFIG_GPU_IDS
,
"0,1"
);
std
::
vector
<
uint64_t
>
gpu_ids
;
void
parse_gpu_ids
(
std
::
string
gpu_ids_str
,
std
::
vector
<
uint64_t
>&
gpu_ids
)
{
for
(
auto
i
=
0
;
i
<
gpu_ids_str
.
length
();
)
{
if
(
gpu_ids_str
[
i
]
!=
','
)
{
int
id
=
0
;
while
(
gpu_ids_str
[
i
]
!=
',
'
)
{
while
(
gpu_ids_str
[
i
]
<=
'9'
&&
gpu_ids_str
[
i
]
>=
'0
'
)
{
id
=
id
*
10
+
gpu_ids_str
[
i
]
-
'0'
;
++
i
;
}
...
...
@@ -35,13 +31,21 @@ GpuCacheMgr::GpuCacheMgr() {
++
i
;
}
}
}
}
cache_
->
set_gpu_ids
(
gpu_ids
);
GpuCacheMgr
::
GpuCacheMgr
()
{
server
::
ConfigNode
&
config
=
server
::
ServerConfig
::
GetInstance
().
GetConfig
(
server
::
CONFIG_CACHE
);
std
::
string
gpu_ids_str
=
config
.
GetValue
(
server
::
CONFIG_GPU_IDS
,
"0,1"
);
int64_t
cap
=
config
.
GetInt64Value
(
server
::
CONFIG_GPU_CACHE_CAPACITY
,
1
);
int64_t
cap
=
config
.
GetInt64Value
(
server
::
CONFIG_GPU_CACHE_CAPACITY
,
2
);
cap
*=
unit
;
cache_
=
std
::
make_shared
<
Cache
>
(
cap
,
1UL
<<
32
);
std
::
vector
<
uint64_t
>
gpu_ids
;
parse_gpu_ids
(
gpu_ids_str
,
gpu_ids
);
cache_
->
set_gpu_ids
(
gpu_ids
);
double
free_percent
=
config
.
GetDoubleValue
(
server
::
GPU_CACHE_FREE_PERCENT
,
0.85
);
if
(
free_percent
>
0.0
&&
free_percent
<=
1.0
)
{
cache_
->
set_freemem_percent
(
free_percent
);
...
...
cpp/src/cache/GpuCacheMgr.h
浏览文件 @
30b43758
...
...
@@ -6,33 +6,34 @@
#include "CacheMgr.h"
#include <unordered_map>
#include <memory>
namespace
zilliz
{
namespace
milvus
{
namespace
cache
{
class
GpuCacheMgr
;
using
GpuCacheMgrPtr
=
std
::
shared_ptr
<
GpuCacheMgr
>
;
class
GpuCacheMgr
:
public
CacheMgr
{
p
rivate
:
p
ublic
:
GpuCacheMgr
();
public:
static
CacheMgr
*
GetInstance
(
uint64_t
gpu_id
)
{
if
(
!
instance_
[
gpu_id
]
)
{
if
(
instance_
.
find
(
gpu_id
)
==
instance_
.
end
()
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
if
(
!
instance_
[
gpu_id
])
{
instance_
.
insert
(
std
::
pair
<
uint64_t
,
GpuCacheMgr
*
>
(
gpu_id
,
new
GpuCacheMgr
()));
}
instance_
.
insert
(
std
::
pair
<
uint64_t
,
GpuCacheMgrPtr
>
(
gpu_id
,
std
::
make_shared
<
GpuCacheMgr
>
()));
// instance_[gpu_id] = std::make_shared<GpuCacheMgr>();
}
return
instance_
.
at
(
gpu_id
);
// static GpuCacheMgr s_mgr;
// return &s_mgr;
return
instance_
[
gpu_id
].
get
();
}
void
InsertItem
(
const
std
::
string
&
key
,
const
DataObjPtr
&
data
)
override
;
private:
static
std
::
mutex
mutex_
;
static
std
::
unordered_map
<
uint64_t
,
GpuCacheMgr
*
>
instance_
;
static
std
::
unordered_map
<
uint64_t
,
GpuCacheMgr
Ptr
>
instance_
;
};
}
...
...
cpp/unittest/db/db_tests.cpp
浏览文件 @
30b43758
...
...
@@ -9,7 +9,6 @@
#include "db/meta/MetaConsts.h"
#include "db/Factories.h"
#include "cache/CpuCacheMgr.h"
#include "cache/GpuCacheMgr.h
#include "utils/CommonUtil.h"
#include <gtest/gtest.h>
...
...
@@ -439,8 +438,3 @@ TEST_F(DBTest2, DELETE_BY_RANGE_TEST) {
db_
->
DeleteTable
(
TABLE_NAME
,
dates
);
}
\ No newline at end of file
TEST_F
(
DBTest
,
GPU_CACHE_MGR_TEST
)
{
std
::
vector
<
uint64_t
>
gpu_ids
=
cache
::
cache
::
CpuCacheMgr
::
GetInstance
()
->
CacheUsage
();
}
\ No newline at end of file
cpp/unittest/server/cache_test.cpp
浏览文件 @
30b43758
...
...
@@ -146,7 +146,7 @@ TEST(CacheTest, CPU_CACHE_TEST) {
}
TEST
(
CacheTest
,
GPU_CACHE_TEST
)
{
cache
::
CacheMgr
*
gpu_mgr
=
cache
::
GpuCacheMgr
::
GetInstance
();
cache
::
CacheMgr
*
gpu_mgr
=
cache
::
GpuCacheMgr
::
GetInstance
(
0
);
const
int
dim
=
256
;
...
...
@@ -164,6 +164,25 @@ TEST(CacheTest, GPU_CACHE_TEST) {
gpu_mgr
->
ClearCache
();
ASSERT_EQ
(
gpu_mgr
->
ItemCount
(),
0
);
gpu_mgr
->
SetCapacity
(
4096000000
);
for
(
auto
i
=
0
;
i
<
3
;
i
++
)
{
MockVecIndex
*
mock_index
=
new
MockVecIndex
();
mock_index
->
ntotal_
=
1000000
;
//2G
engine
::
VecIndexPtr
index
(
mock_index
);
cache
::
DataObjPtr
data_obj
=
std
::
make_shared
<
cache
::
DataObj
>
(
index
);
std
::
cout
<<
data_obj
->
size
()
<<
std
::
endl
;
gpu_mgr
->
InsertItem
(
"index_"
+
std
::
to_string
(
i
),
data_obj
);
}
// ASSERT_EQ(gpu_mgr->ItemCount(), 2);
// auto obj0 = gpu_mgr->GetItem("index_0");
// ASSERT_EQ(obj0, nullptr);
// auto obj1 = gpu_mgr->GetItem("index_1");
// auto obj2 = gpu_mgr->GetItem("index_2");
gpu_mgr
->
ClearCache
();
ASSERT_EQ
(
gpu_mgr
->
ItemCount
(),
0
);
}
TEST
(
CacheTest
,
INVALID_TEST
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录