Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
7b2a668b
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,发现更多精彩内容 >>
提交
7b2a668b
编写于
9月 07, 2019
作者:
J
jinhai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Solve several issues
Former-commit-id: 5845ca6192a563f46d1d3183670b02e32961dcbe
上级
a57e84e0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
7 deletion
+50
-7
cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h
cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h
+7
-0
cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp
cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp
+43
-7
未找到文件。
cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h
浏览文件 @
7b2a668b
...
...
@@ -64,6 +64,13 @@ class FaissGpuResourceMgr {
void
MoveToIdle
(
const
int64_t
&
device_id
,
const
ResPtr
&
res
);
void
Dump
();
protected:
void
RemoveResource
(
const
int64_t
&
device_id
,
const
ResPtr
&
res
,
std
::
map
<
int64_t
,
std
::
vector
<
ResPtr
>>&
resource_pool
);
protected:
bool
is_init
=
false
;
...
...
cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp
浏览文件 @
7b2a668b
...
...
@@ -19,6 +19,7 @@
#include "knowhere/adapter/faiss_adopt.h"
#include "knowhere/index/vector_index/gpu_ivf.h"
#include <algorithm>
namespace
zilliz
{
namespace
knowhere
{
...
...
@@ -33,7 +34,7 @@ IndexModelPtr GPUIVF::Train(const DatasetPtr &dataset, const Config &config) {
auto
temp_resource
=
FaissGpuResourceMgr
::
GetInstance
().
GetRes
(
gpu_device
);
if
(
temp_resource
!=
nullptr
)
{
ResScope
rs
(
gpu_device
,
temp_resource
);
ResScope
rs
(
gpu_device
,
temp_resource
);
faiss
::
gpu
::
GpuIndexIVFFlatConfig
idx_config
;
idx_config
.
device
=
gpu_device
;
faiss
::
gpu
::
GpuIndexIVFFlat
device_index
(
temp_resource
->
faiss_res
.
get
(),
dim
,
nlist
,
metric_type
,
idx_config
);
...
...
@@ -130,9 +131,9 @@ void GPUIVF::search_impl(int64_t n,
int64_t
*
labels
,
const
Config
&
cfg
)
{
// TODO(linxj): allocate mem
if
(
FaissGpuResourceMgr
::
GetInstance
().
GetRes
(
gpu_id_
,
res_
))
{
ResScope
rs
(
gpu_id_
,
res_
);
auto
temp_res
=
FaissGpuResourceMgr
::
GetInstance
().
GetRes
(
gpu_id_
);
if
(
temp_res
)
{
ResScope
rs
(
gpu_id_
,
temp_res
);
if
(
auto
device_index
=
std
::
static_pointer_cast
<
faiss
::
gpu
::
GpuIndexIVF
>
(
index_
))
{
auto
nprobe
=
cfg
.
get_with_default
(
"nprobe"
,
size_t
(
1
));
...
...
@@ -143,7 +144,6 @@ void GPUIVF::search_impl(int64_t n,
}
else
{
KNOWHERE_THROW_MSG
(
"search can't get gpu resource"
);
}
}
VectorIndexPtr
GPUIVF
::
CopyGpuToCpu
(
const
Config
&
config
)
{
...
...
@@ -229,8 +229,7 @@ IndexModelPtr GPUIVFSQ::Train(const DatasetPtr &dataset, const Config &config) {
delete
build_index
;
return
std
::
make_shared
<
IVFIndexModel
>
(
host_index
);
}
else
{
}
else
{
KNOWHERE_THROW_MSG
(
"Build IVFSQ can't get gpu resource"
);
}
}
...
...
@@ -279,6 +278,10 @@ void FaissGpuResourceMgr::InitDevice(int64_t device_id,
}
void
FaissGpuResourceMgr
::
InitResource
()
{
if
(
is_init
)
return
;
is_init
=
true
;
for
(
auto
&
device
:
devices_params_
)
{
auto
&
resource_vec
=
idle_
[
device
.
first
];
...
...
@@ -342,15 +345,29 @@ bool FaissGpuResourceMgr::GetRes(const int64_t &device_id,
void
FaissGpuResourceMgr
::
MoveToInuse
(
const
int64_t
&
device_id
,
const
ResPtr
&
res
)
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex_
);
RemoveResource
(
device_id
,
res
,
idle_
);
in_use_
[
device_id
].
push_back
(
res
);
}
void
FaissGpuResourceMgr
::
MoveToIdle
(
const
int64_t
&
device_id
,
const
ResPtr
&
res
)
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex_
);
RemoveResource
(
device_id
,
res
,
in_use_
);
auto
it
=
idle_
[
device_id
].
begin
();
idle_
[
device_id
].
insert
(
it
,
res
);
}
void
FaissGpuResourceMgr
::
RemoveResource
(
const
int64_t
&
device_id
,
const
ResPtr
&
res
,
std
::
map
<
int64_t
,
std
::
vector
<
ResPtr
>>
&
resource_pool
)
{
if
(
resource_pool
.
find
(
device_id
)
!=
resource_pool
.
end
())
{
std
::
vector
<
ResPtr
>
&
res_array
=
resource_pool
[
device_id
];
res_array
.
erase
(
std
::
remove_if
(
res_array
.
begin
(),
res_array
.
end
(),
[
&
](
ResPtr
&
ptr
)
{
return
ptr
->
id
==
res
->
id
;
}),
res_array
.
end
());
}
}
void
FaissGpuResourceMgr
::
Free
()
{
for
(
auto
&
item
:
in_use_
)
{
auto
&
res_vec
=
item
.
second
;
...
...
@@ -363,6 +380,25 @@ void FaissGpuResourceMgr::Free() {
is_init
=
false
;
}
void
FaissGpuResourceMgr
::
Dump
()
{
std
::
cout
<<
"In used resource"
<<
std
::
endl
;
for
(
auto
&
item
:
in_use_
)
{
std
::
cout
<<
"device_id: "
<<
item
.
first
<<
std
::
endl
;
for
(
auto
&
elem
:
item
.
second
)
{
std
::
cout
<<
"resource_id: "
<<
elem
->
id
<<
std
::
endl
;
}
}
std
::
cout
<<
"Idle resource"
<<
std
::
endl
;
for
(
auto
&
item
:
idle_
)
{
std
::
cout
<<
"device_id: "
<<
item
.
first
<<
std
::
endl
;
for
(
auto
&
elem
:
item
.
second
)
{
std
::
cout
<<
"resource_id: "
<<
elem
->
id
<<
std
::
endl
;
}
}
}
void
GPUIndex
::
SetGpuDevice
(
const
int
&
gpu_id
)
{
gpu_id_
=
gpu_id
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录