Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
269ab2f6
M
milvus
项目概览
milvus
/
milvus
大约 1 年 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
269ab2f6
编写于
1月 13, 2023
作者:
L
liliu-z
提交者:
GitHub
1月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize some low efficient code (#20529) (#21683)
Signed-off-by:
N
Li Liu
<
li.liu@zilliz.com
>
上级
c700974e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
24 deletion
+33
-24
internal/core/src/segcore/Reduce.cpp
internal/core/src/segcore/Reduce.cpp
+33
-24
未找到文件。
internal/core/src/segcore/Reduce.cpp
浏览文件 @
269ab2f6
...
...
@@ -76,23 +76,24 @@ ReduceHelper::FilterInvalidSearchResult(SearchResult* search_result) {
AssertInfo
(
search_result
->
distances_
.
size
()
==
nq
*
topK
,
"wrong distances size, size = "
+
std
::
to_string
(
search_result
->
distances_
.
size
())
+
", expected size = "
+
std
::
to_string
(
nq
*
topK
));
std
::
vector
<
int64_t
>
real_topks
(
nq
);
std
::
vector
<
float
>
distances
;
std
::
vector
<
int64_t
>
seg_offsets
;
for
(
auto
i
=
0
;
i
<
nq
;
i
++
)
{
real_topks
[
i
]
=
0
;
for
(
auto
j
=
0
;
j
<
topK
;
j
++
)
{
auto
offset
=
i
*
topK
+
j
;
if
(
search_result
->
seg_offsets_
[
offset
]
!=
INVALID_SEG_OFFSET
)
{
std
::
vector
<
int64_t
>
real_topks
(
nq
,
0
);
uint32_t
valid_index
=
0
;
auto
&
offsets
=
search_result
->
seg_offsets_
;
auto
&
distances
=
search_result
->
distances_
;
for
(
auto
i
=
0
;
i
<
nq
;
++
i
)
{
for
(
auto
j
=
0
;
j
<
topK
;
++
j
)
{
auto
index
=
i
*
topK
+
j
;
if
(
offsets
[
index
]
!=
INVALID_SEG_OFFSET
)
{
real_topks
[
i
]
++
;
seg_offsets
.
push_back
(
search_result
->
seg_offsets_
[
offset
]);
distances
.
push_back
(
search_result
->
distances_
[
offset
]);
offsets
[
valid_index
]
=
offsets
[
index
];
distances
[
valid_index
]
=
distances
[
index
];
valid_index
++
;
}
}
}
offsets
.
resize
(
valid_index
);
distances
.
resize
(
valid_index
);
search_result
->
distances_
.
swap
(
distances
);
search_result
->
seg_offsets_
.
swap
(
seg_offsets
);
search_result
->
topk_per_nq_prefix_sum_
.
resize
(
nq
+
1
);
std
::
partial_sum
(
real_topks
.
begin
(),
real_topks
.
end
(),
search_result
->
topk_per_nq_prefix_sum_
.
begin
()
+
1
);
}
...
...
@@ -101,15 +102,16 @@ void
ReduceHelper
::
FillPrimaryKey
()
{
std
::
vector
<
SearchResult
*>
valid_search_results
;
// get primary keys for duplicates removal
for
(
auto
search_result
:
search_results_
)
{
uint32_t
valid_index
=
0
;
for
(
auto
&
search_result
:
search_results_
)
{
FilterInvalidSearchResult
(
search_result
);
if
(
search_result
->
get_total_result_count
()
>
0
)
{
auto
segment
=
static_cast
<
SegmentInterface
*>
(
search_result
->
segment_
);
segment
->
FillPrimaryKeys
(
plan_
,
*
search_result
);
valid_search_results
.
emplace_back
(
search_result
)
;
search_results_
[
valid_index
++
]
=
search_result
;
}
}
search_results_
.
swap
(
valid_search_results
);
search_results_
.
resize
(
valid_index
);
num_segments_
=
search_results_
.
size
();
}
...
...
@@ -119,20 +121,27 @@ ReduceHelper::RefreshSearchResult() {
std
::
vector
<
int64_t
>
real_topks
(
total_nq_
,
0
);
auto
search_result
=
search_results_
[
i
];
if
(
search_result
->
result_offsets_
.
size
()
!=
0
)
{
std
::
vector
<
milvus
::
PkType
>
primary_keys
;
std
::
vector
<
float
>
distances
;
std
::
vector
<
int64_t
>
seg_offsets
;
uint32_t
size
=
0
;
for
(
int
j
=
0
;
j
<
total_nq_
;
j
++
)
{
size
+=
final_search_records_
[
i
][
j
].
size
();
}
std
::
vector
<
milvus
::
PkType
>
primary_keys
(
size
);
std
::
vector
<
float
>
distances
(
size
);
std
::
vector
<
int64_t
>
seg_offsets
(
size
);
uint32_t
index
=
0
;
for
(
int
j
=
0
;
j
<
total_nq_
;
j
++
)
{
for
(
auto
offset
:
final_search_records_
[
i
][
j
])
{
primary_keys
.
push_back
(
search_result
->
primary_keys_
[
offset
]);
distances
.
push_back
(
search_result
->
distances_
[
offset
]);
seg_offsets
.
push_back
(
search_result
->
seg_offsets_
[
offset
]);
primary_keys
[
index
]
=
search_result
->
primary_keys_
[
offset
];
distances
[
index
]
=
search_result
->
distances_
[
offset
];
seg_offsets
[
index
]
=
search_result
->
seg_offsets_
[
offset
];
index
++
;
real_topks
[
j
]
++
;
}
}
search_result
->
primary_keys_
=
std
::
move
(
primary_keys
);
search_result
->
distances_
=
std
::
move
(
distances
);
search_result
->
seg_offsets_
=
std
::
move
(
seg_offsets
);
search_result
->
primary_keys_
.
swap
(
primary_keys
);
search_result
->
distances_
.
swap
(
distances
);
search_result
->
seg_offsets_
.
swap
(
seg_offsets
);
}
std
::
partial_sum
(
real_topks
.
begin
(),
real_topks
.
end
(),
search_result
->
topk_per_nq_prefix_sum_
.
begin
()
+
1
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录