Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
8540b356
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,发现更多精彩内容 >>
提交
8540b356
编写于
10月 13, 2019
作者:
W
wxyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SQ8H in GPU part2
Former-commit-id: 4c48987574ed24bf8a543d97520eb3a6b554fca5
上级
e675158b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
24 addition
and
21 deletion
+24
-21
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
...knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
+5
-3
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
...e/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
+1
-2
cpp/src/core/unittest/test_ivf.cpp
cpp/src/core/unittest/test_ivf.cpp
+2
-2
cpp/src/db/engine/ExecutionEngineImpl.cpp
cpp/src/db/engine/ExecutionEngineImpl.cpp
+10
-5
cpp/src/wrapper/VecImpl.cpp
cpp/src/wrapper/VecImpl.cpp
+3
-6
cpp/src/wrapper/VecImpl.h
cpp/src/wrapper/VecImpl.h
+1
-1
cpp/src/wrapper/VecIndex.h
cpp/src/wrapper/VecIndex.h
+2
-2
未找到文件。
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
浏览文件 @
8540b356
...
@@ -180,7 +180,7 @@ IVFSQHybrid::UnsetQuantizer() {
...
@@ -180,7 +180,7 @@ IVFSQHybrid::UnsetQuantizer() {
ivf_index
->
quantizer
=
nullptr
;
ivf_index
->
quantizer
=
nullptr
;
}
}
void
VectorIndexPtr
IVFSQHybrid
::
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
IVFSQHybrid
::
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
auto
quantizer_conf
=
std
::
dynamic_pointer_cast
<
QuantizerCfg
>
(
conf
);
auto
quantizer_conf
=
std
::
dynamic_pointer_cast
<
QuantizerCfg
>
(
conf
);
if
(
quantizer_conf
!=
nullptr
)
{
if
(
quantizer_conf
!=
nullptr
)
{
...
@@ -207,8 +207,10 @@ IVFSQHybrid::LoadData(const knowhere::QuantizerPtr& q, const Config& conf) {
...
@@ -207,8 +207,10 @@ IVFSQHybrid::LoadData(const knowhere::QuantizerPtr& q, const Config& conf) {
index_composition
->
mode
=
quantizer_conf
->
mode
;
// only 2
index_composition
->
mode
=
quantizer_conf
->
mode
;
// only 2
auto
gpu_index
=
faiss
::
gpu
::
index_cpu_to_gpu
(
res
->
faiss_res
.
get
(),
gpu_id_
,
index_composition
,
&
option
);
auto
gpu_index
=
faiss
::
gpu
::
index_cpu_to_gpu
(
res
->
faiss_res
.
get
(),
gpu_id_
,
index_composition
,
&
option
);
index_
.
reset
(
gpu_index
);
std
::
shared_ptr
<
faiss
::
Index
>
new_idx
;
gpu_mode
=
2
;
// all in gpu
new_idx
.
reset
(
gpu_index
);
auto
sq_idx
=
std
::
make_shared
<
IVFSQHybrid
>
(
new_idx
,
gpu_id_
,
res
);
return
sq_idx
;
}
else
{
}
else
{
KNOWHERE_THROW_MSG
(
"CopyCpuToGpu Error, can't get gpu_resource"
);
KNOWHERE_THROW_MSG
(
"CopyCpuToGpu Error, can't get gpu_resource"
);
}
}
...
...
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
浏览文件 @
8540b356
...
@@ -60,8 +60,7 @@ class IVFSQHybrid : public GPUIVFSQ {
...
@@ -60,8 +60,7 @@ class IVFSQHybrid : public GPUIVFSQ {
void
void
UnsetQuantizer
();
UnsetQuantizer
();
// todo(xiaojun): return void => VecIndex
VectorIndexPtr
void
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
);
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
);
IndexModelPtr
IndexModelPtr
...
...
cpp/src/core/unittest/test_ivf.cpp
浏览文件 @
8540b356
...
@@ -253,9 +253,9 @@ TEST_P(IVFTest, hybrid) {
...
@@ -253,9 +253,9 @@ TEST_P(IVFTest, hybrid) {
quantizer_conf
->
gpu_id
=
device_id
;
quantizer_conf
->
gpu_id
=
device_id
;
auto
q
=
hybrid_2_idx
->
LoadQuantizer
(
quantizer_conf
);
auto
q
=
hybrid_2_idx
->
LoadQuantizer
(
quantizer_conf
);
quantizer_conf
->
mode
=
2
;
quantizer_conf
->
mode
=
2
;
hybrid_2_idx
->
LoadData
(
q
,
quantizer_conf
);
auto
gpu_idx
=
hybrid_2_idx
->
LoadData
(
q
,
quantizer_conf
);
auto
result
=
hybrid_2
_idx
->
Search
(
query_dataset
,
conf
);
auto
result
=
gpu
_idx
->
Search
(
query_dataset
,
conf
);
AssertAnns
(
result
,
nq
,
conf
->
k
);
AssertAnns
(
result
,
nq
,
conf
->
k
);
PrintResult
(
result
,
nq
,
k
);
PrintResult
(
result
,
nq
,
k
);
}
}
...
...
cpp/src/db/engine/ExecutionEngineImpl.cpp
浏览文件 @
8540b356
...
@@ -256,11 +256,14 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
...
@@ -256,11 +256,14 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
conf
->
gpu_id
=
device_id
;
conf
->
gpu_id
=
device_id
;
if
(
quantizer
)
{
if
(
quantizer
)
{
std
::
cout
<<
"cache hit"
<<
std
::
endl
;
// cache hit
// cache hit
conf
->
mode
=
2
;
conf
->
mode
=
2
;
index_
->
SetQuantizer
(
quantizer
->
Data
()
);
auto
new_index
=
index_
->
LoadData
(
quantizer
->
Data
(),
conf
);
index_
->
LoadData
(
quantizer
->
Data
(),
conf
)
;
index_
=
new_index
;
}
else
{
}
else
{
std
::
cout
<<
"cache miss"
<<
std
::
endl
;
// cache hit
// cache miss
// cache miss
if
(
index_
==
nullptr
)
{
if
(
index_
==
nullptr
)
{
ENGINE_LOG_ERROR
<<
"ExecutionEngineImpl: index is null, failed to copy to gpu"
;
ENGINE_LOG_ERROR
<<
"ExecutionEngineImpl: index is null, failed to copy to gpu"
;
...
@@ -268,9 +271,9 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
...
@@ -268,9 +271,9 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
}
}
conf
->
mode
=
1
;
conf
->
mode
=
1
;
auto
q
=
index_
->
LoadQuantizer
(
conf
);
auto
q
=
index_
->
LoadQuantizer
(
conf
);
index_
->
SetQuantizer
(
q
);
conf
->
mode
=
2
;
conf
->
mode
=
2
;
index_
->
LoadData
(
q
,
conf
);
auto
new_index
=
index_
->
LoadData
(
q
,
conf
);
index_
=
new_index
;
// cache
// cache
auto
cached_quantizer
=
std
::
make_shared
<
CachedQuantizer
>
(
q
);
auto
cached_quantizer
=
std
::
make_shared
<
CachedQuantizer
>
(
q
);
...
@@ -445,7 +448,9 @@ ExecutionEngineImpl::Search(int64_t n, const float* data, int64_t k, int64_t npr
...
@@ -445,7 +448,9 @@ ExecutionEngineImpl::Search(int64_t n, const float* data, int64_t k, int64_t npr
auto
status
=
index_
->
Search
(
n
,
data
,
distances
,
labels
,
conf
);
auto
status
=
index_
->
Search
(
n
,
data
,
distances
,
labels
,
conf
);
HybridUnset
();
if
(
hybrid
)
{
HybridUnset
();
}
if
(
!
status
.
ok
())
{
if
(
!
status
.
ok
())
{
ENGINE_LOG_ERROR
<<
"Search error"
;
ENGINE_LOG_ERROR
<<
"Search error"
;
...
...
cpp/src/wrapper/VecImpl.cpp
浏览文件 @
8540b356
...
@@ -315,24 +315,21 @@ IVFHybridIndex::UnsetQuantizer() {
...
@@ -315,24 +315,21 @@ IVFHybridIndex::UnsetQuantizer() {
return
Status
::
OK
();
return
Status
::
OK
();
}
}
Status
VecIndexPtr
IVFHybridIndex
::
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
IVFHybridIndex
::
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
try
{
try
{
// TODO(linxj): Hardcode here
// TODO(linxj): Hardcode here
if
(
auto
new_idx
=
std
::
dynamic_pointer_cast
<
knowhere
::
IVFSQHybrid
>
(
index_
))
{
if
(
auto
new_idx
=
std
::
dynamic_pointer_cast
<
knowhere
::
IVFSQHybrid
>
(
index_
))
{
new_idx
->
LoadData
(
q
,
conf
);
return
std
::
make_shared
<
IVFHybridIndex
>
(
new_idx
->
LoadData
(
q
,
conf
),
type
);
}
else
{
}
else
{
WRAPPER_LOG_ERROR
<<
"Hybrid mode not support for index type: "
<<
int
(
type
);
WRAPPER_LOG_ERROR
<<
"Hybrid mode not support for index type: "
<<
int
(
type
);
return
Status
(
KNOWHERE_ERROR
,
"not support"
);
}
}
}
catch
(
knowhere
::
KnowhereException
&
e
)
{
}
catch
(
knowhere
::
KnowhereException
&
e
)
{
WRAPPER_LOG_ERROR
<<
e
.
what
();
WRAPPER_LOG_ERROR
<<
e
.
what
();
return
Status
(
KNOWHERE_UNEXPECTED_ERROR
,
e
.
what
());
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
WRAPPER_LOG_ERROR
<<
e
.
what
();
WRAPPER_LOG_ERROR
<<
e
.
what
();
return
Status
(
KNOWHERE_ERROR
,
e
.
what
());
}
}
return
Status
::
OK
()
;
return
nullptr
;
}
}
}
// namespace engine
}
// namespace engine
...
...
cpp/src/wrapper/VecImpl.h
浏览文件 @
8540b356
...
@@ -106,7 +106,7 @@ class IVFHybridIndex : public IVFMixIndex {
...
@@ -106,7 +106,7 @@ class IVFHybridIndex : public IVFMixIndex {
Status
Status
UnsetQuantizer
()
override
;
UnsetQuantizer
()
override
;
Status
VecIndexPtr
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
override
;
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
override
;
};
};
...
...
cpp/src/wrapper/VecIndex.h
浏览文件 @
8540b356
...
@@ -103,9 +103,9 @@ class VecIndex : public cache::DataObj {
...
@@ -103,9 +103,9 @@ class VecIndex : public cache::DataObj {
return
nullptr
;
return
nullptr
;
}
}
virtual
Status
virtual
VecIndexPtr
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
LoadData
(
const
knowhere
::
QuantizerPtr
&
q
,
const
Config
&
conf
)
{
return
Status
::
OK
()
;
return
nullptr
;
}
}
virtual
Status
virtual
Status
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录