Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
18b0303f
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,发现更多精彩内容 >>
提交
18b0303f
编写于
10月 09, 2019
作者:
J
JinHai-CN
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add one more interface: UnsetQuantizer
Former-commit-id: 34b6b4ac1f9b2841a8af6e5e4166e9ad45a9de1f
上级
2cce8978
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
14 deletion
+63
-14
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
...knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
+24
-7
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
...e/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
+4
-1
cpp/src/wrapper/VecImpl.cpp
cpp/src/wrapper/VecImpl.cpp
+23
-2
cpp/src/wrapper/VecImpl.h
cpp/src/wrapper/VecImpl.h
+7
-2
cpp/src/wrapper/VecIndex.h
cpp/src/wrapper/VecIndex.h
+5
-2
未找到文件。
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.cpp
浏览文件 @
18b0303f
...
...
@@ -27,7 +27,8 @@
namespace
zilliz
{
namespace
knowhere
{
IndexModelPtr
IVFSQHybrid
::
Train
(
const
DatasetPtr
&
dataset
,
const
Config
&
config
)
{
IndexModelPtr
IVFSQHybrid
::
Train
(
const
DatasetPtr
&
dataset
,
const
Config
&
config
)
{
auto
build_cfg
=
std
::
dynamic_pointer_cast
<
IVFSQCfg
>
(
config
);
if
(
build_cfg
!=
nullptr
)
{
build_cfg
->
CheckValid
();
// throw exception
...
...
@@ -58,7 +59,8 @@ IndexModelPtr IVFSQHybrid::Train(const DatasetPtr &dataset, const Config &config
}
}
VectorIndexPtr
IVFSQHybrid
::
CopyGpuToCpu
(
const
Config
&
config
)
{
VectorIndexPtr
IVFSQHybrid
::
CopyGpuToCpu
(
const
Config
&
config
)
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex_
);
if
(
auto
device_idx
=
std
::
dynamic_pointer_cast
<
faiss
::
gpu
::
GpuIndexIVF
>
(
index_
))
{
...
...
@@ -74,7 +76,8 @@ VectorIndexPtr IVFSQHybrid::CopyGpuToCpu(const Config &config) {
}
}
VectorIndexPtr
IVFSQHybrid
::
CopyCpuToGpu
(
const
int64_t
&
device_id
,
const
Config
&
config
)
{
VectorIndexPtr
IVFSQHybrid
::
CopyCpuToGpu
(
const
int64_t
&
device_id
,
const
Config
&
config
)
{
if
(
auto
res
=
FaissGpuResourceMgr
::
GetInstance
().
GetRes
(
device_id
))
{
ResScope
rs
(
res
,
device_id
,
false
);
faiss
::
gpu
::
GpuClonerOptions
option
;
...
...
@@ -95,11 +98,13 @@ VectorIndexPtr IVFSQHybrid::CopyCpuToGpu(const int64_t &device_id, const Config
}
}
void
IVFSQHybrid
::
LoadImpl
(
const
BinarySet
&
index_binary
)
{
void
IVFSQHybrid
::
LoadImpl
(
const
BinarySet
&
index_binary
)
{
FaissBaseIndex
::
LoadImpl
(
index_binary
);
// load on cpu
}
void
IVFSQHybrid
::
search_impl
(
int64_t
n
,
void
IVFSQHybrid
::
search_impl
(
int64_t
n
,
const
float
*
data
,
int64_t
k
,
float
*
distances
,
...
...
@@ -112,7 +117,8 @@ void IVFSQHybrid::search_impl(int64_t n,
}
}
QuantizerPtr
IVFSQHybrid
::
LoadQuantizer
(
const
Config
&
conf
)
{
QuantizerPtr
IVFSQHybrid
::
LoadQuantizer
(
const
Config
&
conf
)
{
auto
quantizer_conf
=
std
::
dynamic_pointer_cast
<
QuantizerCfg
>
(
conf
);
if
(
quantizer_conf
!=
nullptr
)
{
quantizer_conf
->
CheckValid
();
// throw exception
...
...
@@ -140,7 +146,8 @@ QuantizerPtr IVFSQHybrid::LoadQuantizer(const Config &conf) {
}
}
void
IVFSQHybrid
::
SetQuantizer
(
QuantizerPtr
q
)
{
void
IVFSQHybrid
::
SetQuantizer
(
const
QuantizerPtr
&
q
)
{
auto
ivf_quantizer
=
std
::
dynamic_pointer_cast
<
FaissIVFQuantizer
>
(
q
);
if
(
ivf_quantizer
==
nullptr
)
{
KNOWHERE_THROW_MSG
(
"Quantizer type error"
);
...
...
@@ -158,5 +165,15 @@ void IVFSQHybrid::SetQuantizer(QuantizerPtr q) {
}
}
void
IVFSQHybrid
::
UnsetQuantizer
()
{
auto
*
ivf_index
=
dynamic_cast
<
faiss
::
IndexIVF
*>
(
index_
.
get
());
if
(
ivf_index
==
nullptr
)
{
KNOWHERE_THROW_MSG
(
"Index type error"
);
}
ivf_index
->
quantizer
=
nullptr
;
}
}
}
cpp/src/core/knowhere/knowhere/index/vector_index/IndexIVFSQHybrid.h
浏览文件 @
18b0303f
...
...
@@ -49,7 +49,10 @@ class IVFSQHybrid : public GPUIVFSQ {
LoadQuantizer
(
const
Config
&
conf
);
void
SetQuantizer
(
QuantizerPtr
q
);
SetQuantizer
(
const
QuantizerPtr
&
q
);
void
UnsetQuantizer
();
IndexModelPtr
Train
(
const
DatasetPtr
&
dataset
,
const
Config
&
config
)
override
;
...
...
cpp/src/wrapper/VecImpl.cpp
浏览文件 @
18b0303f
...
...
@@ -277,7 +277,8 @@ IVFMixIndex::Load(const zilliz::knowhere::BinarySet &index_binary) {
return
Status
::
OK
();
}
knowhere
::
QuantizerPtr
IVFHybridIndex
::
LoadQuantizer
(
const
Config
&
conf
)
{
knowhere
::
QuantizerPtr
IVFHybridIndex
::
LoadQuantizer
(
const
Config
&
conf
)
{
// TODO(linxj): Hardcode here
if
(
auto
new_idx
=
std
::
dynamic_pointer_cast
<
knowhere
::
IVFSQHybrid
>
(
index_
)){
return
new_idx
->
LoadQuantizer
(
conf
);
...
...
@@ -286,7 +287,8 @@ knowhere::QuantizerPtr IVFHybridIndex::LoadQuantizer(const Config& conf) {
}
}
Status
IVFHybridIndex
::
SetQuantizer
(
knowhere
::
QuantizerPtr
q
)
{
Status
IVFHybridIndex
::
SetQuantizer
(
const
knowhere
::
QuantizerPtr
&
q
)
{
try
{
// TODO(linxj): Hardcode here
if
(
auto
new_idx
=
std
::
dynamic_pointer_cast
<
knowhere
::
IVFSQHybrid
>
(
index_
))
{
...
...
@@ -304,6 +306,25 @@ Status IVFHybridIndex::SetQuantizer(knowhere::QuantizerPtr q) {
}
}
Status
IVFHybridIndex
::
UnsetQuantizer
()
{
try
{
// TODO(linxj): Hardcode here
if
(
auto
new_idx
=
std
::
dynamic_pointer_cast
<
knowhere
::
IVFSQHybrid
>
(
index_
))
{
new_idx
->
UnsetQuantizer
();
}
else
{
WRAPPER_LOG_ERROR
<<
"Hybrid mode not support for index type: "
<<
int
(
type
);
return
Status
(
KNOWHERE_ERROR
,
"not support"
);
}
}
catch
(
knowhere
::
KnowhereException
&
e
)
{
WRAPPER_LOG_ERROR
<<
e
.
what
();
return
Status
(
KNOWHERE_UNEXPECTED_ERROR
,
e
.
what
());
}
catch
(
std
::
exception
&
e
)
{
WRAPPER_LOG_ERROR
<<
e
.
what
();
return
Status
(
KNOWHERE_ERROR
,
e
.
what
());
}
}
}
// namespace engine
}
// namespace milvus
}
// namespace zilliz
cpp/src/wrapper/VecImpl.h
浏览文件 @
18b0303f
...
...
@@ -103,9 +103,14 @@ class IVFMixIndex : public VecIndexImpl {
class
IVFHybridIndex
:
public
IVFMixIndex
{
public:
knowhere
::
QuantizerPtr
LoadQuantizer
(
const
Config
&
conf
)
override
;
knowhere
::
QuantizerPtr
LoadQuantizer
(
const
Config
&
conf
)
override
;
Status
SetQuantizer
(
knowhere
::
QuantizerPtr
q
)
override
;
Status
SetQuantizer
(
const
knowhere
::
QuantizerPtr
&
q
)
override
;
Status
UnsetQuantizer
()
override
;
};
class
BFIndex
:
public
VecIndexImpl
{
...
...
cpp/src/wrapper/VecIndex.h
浏览文件 @
18b0303f
...
...
@@ -105,11 +105,14 @@ class VecIndex {
// TODO(linxj): refactor later
virtual
knowhere
::
QuantizerPtr
LoadQuantizer
(
const
Config
&
conf
)
{}
LoadQuantizer
(
const
Config
&
conf
)
{
return
Status
::
OK
();
}
// TODO(linxj): refactor later
virtual
Status
SetQuantizer
(
knowhere
::
QuantizerPtr
q
)
{}
SetQuantizer
(
const
knowhere
::
QuantizerPtr
&
q
)
{
return
Status
::
OK
();
}
virtual
Status
UnsetQuantizer
()
{
return
Status
::
OK
();
}
};
extern
Status
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录