Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
b576bd6f
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,发现更多精彩内容 >>
提交
b576bd6f
编写于
8月 23, 2019
作者:
Y
Yu Kun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify GpuCacheMgr GetInsatnce
Former-commit-id: 7323d4a63e58a6e70f8d47f6b2fbe9566197013c
上级
4b4071f2
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
44 addition
and
59 deletion
+44
-59
cpp/src/cache/Cache.h
cpp/src/cache/Cache.h
+0
-4
cpp/src/cache/CacheMgr.cpp
cpp/src/cache/CacheMgr.cpp
+0
-19
cpp/src/cache/CacheMgr.h
cpp/src/cache/CacheMgr.h
+0
-2
cpp/src/cache/GpuCacheMgr.cpp
cpp/src/cache/GpuCacheMgr.cpp
+22
-16
cpp/src/cache/GpuCacheMgr.h
cpp/src/cache/GpuCacheMgr.h
+9
-3
cpp/src/sdk/examples/grpcsimple/src/ClientTest.cpp
cpp/src/sdk/examples/grpcsimple/src/ClientTest.cpp
+0
-3
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
+12
-11
cpp/unittest/server/cache_test.cpp
cpp/unittest/server/cache_test.cpp
+1
-1
未找到文件。
cpp/src/cache/Cache.h
浏览文件 @
b576bd6f
...
...
@@ -46,9 +46,6 @@ 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_
=
gpu_ids
;
}
std
::
vector
<
uint64_t
>
gpu_ids
()
const
{
return
gpu_ids_
;
}
size_t
size
()
const
;
bool
exists
(
const
std
::
string
&
key
);
...
...
@@ -63,7 +60,6 @@ private:
int64_t
usage_
;
int64_t
capacity_
;
double
freemem_percent_
;
std
::
vector
<
uint64_t
>
gpu_ids_
;
LRU
<
std
::
string
,
CacheObjPtr
>
lru_
;
mutable
std
::
mutex
mutex_
;
...
...
cpp/src/cache/CacheMgr.cpp
浏览文件 @
b576bd6f
...
...
@@ -56,7 +56,6 @@ 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
;
...
...
@@ -131,24 +130,6 @@ 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
浏览文件 @
b576bd6f
...
...
@@ -33,8 +33,6 @@ 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/GpuCacheMgr.cpp
浏览文件 @
b576bd6f
...
...
@@ -4,6 +4,7 @@
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include "utils/Log.h"
#include "GpuCacheMgr.h"
#include "server/ServerConfig.h"
...
...
@@ -18,34 +19,39 @@ std::unordered_map<uint64_t, GpuCacheMgrPtr> GpuCacheMgr::instance_;
namespace
{
constexpr
int64_t
unit
=
1024
*
1024
*
1024
;
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
]
<=
'9'
&&
gpu_ids_str
[
i
]
>=
'0'
)
{
id
=
id
*
10
+
gpu_ids_str
[
i
]
-
'0'
;
++
i
;
}
gpu_ids
.
push_back
(
id
);
}
else
{
++
i
;
std
::
vector
<
uint64_t
>
load
(
)
{
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
;
std
::
stringstream
ss
(
gpu_ids_str
)
;
for
(
int
i
;
ss
>>
i
;)
{
gpu_ids
.
push_back
(
i
);
if
(
ss
.
peek
()
==
','
)
{
ss
.
ignore
()
;
}
}
return
gpu_ids
;
}
}
bool
GpuCacheMgr
::
GpuIdInConfig
(
uint64_t
gpu_id
)
{
static
std
::
vector
<
uint64_t
>
ids
=
load
();
for
(
auto
id
:
ids
)
{
if
(
gpu_id
==
id
)
return
true
;
}
return
false
;
}
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
,
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
浏览文件 @
b576bd6f
...
...
@@ -19,12 +19,18 @@ class GpuCacheMgr : public CacheMgr {
public:
GpuCacheMgr
();
public:
static
bool
GpuIdInConfig
(
uint64_t
gpu_id
);
static
CacheMgr
*
GetInstance
(
uint64_t
gpu_id
)
{
if
(
instance_
.
find
(
gpu_id
)
==
instance_
.
end
())
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
instance_
.
insert
(
std
::
pair
<
uint64_t
,
GpuCacheMgrPtr
>
(
gpu_id
,
std
::
make_shared
<
GpuCacheMgr
>
()));
// instance_[gpu_id] = std::make_shared<GpuCacheMgr>();
if
(
instance_
.
find
(
gpu_id
)
==
instance_
.
end
())
{
if
(
GpuIdInConfig
(
gpu_id
))
{
instance_
.
insert
(
std
::
pair
<
uint64_t
,
GpuCacheMgrPtr
>
(
gpu_id
,
std
::
make_shared
<
GpuCacheMgr
>
()));
}
else
{
return
nullptr
;
}
}
}
return
instance_
[
gpu_id
].
get
();
}
...
...
cpp/src/sdk/examples/grpcsimple/src/ClientTest.cpp
浏览文件 @
b576bd6f
...
...
@@ -263,9 +263,6 @@ ClientTest::Test(const std::string& address, const std::string& port) {
search_record_array
.
push_back
(
std
::
make_pair
(
record_ids
[
SEARCH_TARGET
],
record_array
[
SEARCH_TARGET
]));
}
int64_t
row_count
;
conn
->
CountTable
(
TABLE_NAME
,
row_count
);
std
::
cout
<<
"
\t
"
<<
TABLE_NAME
<<
"("
<<
row_count
<<
" rows)"
<<
std
::
endl
;
}
}
...
...
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
浏览文件 @
b576bd6f
...
...
@@ -448,18 +448,19 @@ InsertTask::OnExecute() {
// TODO: change to one dimension array in protobuf or use multiple-thread to copy the data
for
(
size_t
i
=
0
;
i
<
insert_param_
.
row_record_array_size
();
i
++
)
{
if
(
insert_param_
.
row_record_array
(
i
).
vector_data
().
empty
())
{
return
SetError
(
SERVER_INVALID_ROWRECORD_ARRAY
,
"Row record float array is empty"
);
}
uint64_t
vec_dim
=
insert_param_
.
row_record_array
(
i
).
vector_data
().
size
();
if
(
vec_dim
!=
table_info
.
dimension_
)
{
ServerError
error_code
=
SERVER_INVALID_VECTOR_DIMENSION
;
std
::
string
error_msg
=
"Invalid rowrecord dimension: "
+
std
::
to_string
(
vec_dim
)
+
" vs. table dimension:"
+
std
::
to_string
(
table_info
.
dimension_
);
return
SetError
(
error_code
,
error_msg
);
}
//TODO: use memcpy
for
(
size_t
j
=
0
;
j
<
table_info
.
dimension_
;
j
++
)
{
if
(
insert_param_
.
row_record_array
(
i
).
vector_data
().
empty
())
{
return
SetError
(
SERVER_INVALID_ROWRECORD_ARRAY
,
"Row record float array is empty"
);
}
uint64_t
vec_dim
=
insert_param_
.
row_record_array
(
i
).
vector_data
().
size
();
if
(
vec_dim
!=
table_info
.
dimension_
)
{
ServerError
error_code
=
SERVER_INVALID_VECTOR_DIMENSION
;
std
::
string
error_msg
=
"Invalid rowrecord dimension: "
+
std
::
to_string
(
vec_dim
)
+
" vs. table dimension:"
+
std
::
to_string
(
table_info
.
dimension_
);
return
SetError
(
error_code
,
error_msg
);
}
vec_f
[
i
*
table_info
.
dimension_
+
j
]
=
insert_param_
.
row_record_array
(
i
).
vector_data
(
j
);
}
}
...
...
cpp/unittest/server/cache_test.cpp
浏览文件 @
b576bd6f
...
...
@@ -165,8 +165,8 @@ 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
++
)
{
// TODO: use gpu index to mock
MockVecIndex
*
mock_index
=
new
MockVecIndex
();
mock_index
->
ntotal_
=
1000000
;
//2G
engine
::
VecIndexPtr
index
(
mock_index
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录