Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
4b08e79d
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b08e79d
编写于
8月 04, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mgb): fix fastrun no_profiling_on_shape_change
GitOrigin-RevId: 27355364248c464089e6fcbbde52dcaf9a26b314
上级
eab6afab
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
15 deletion
+62
-15
src/opr/impl/search_policy/algo_chooser.cpp
src/opr/impl/search_policy/algo_chooser.cpp
+10
-6
src/opr/include/megbrain/opr/search_policy/profiler.h
src/opr/include/megbrain/opr/search_policy/profiler.h
+0
-7
src/opr/test/algo_chooser.cpp
src/opr/test/algo_chooser.cpp
+49
-0
src/opr/test/blas.cpp
src/opr/test/blas.cpp
+3
-2
未找到文件。
src/opr/impl/search_policy/algo_chooser.cpp
浏览文件 @
4b08e79d
...
...
@@ -523,6 +523,15 @@ AlgoChooser<Opr>::AlgoChooserHelper::AlgoChooserHelper(
fastrun_batch_size
);
}
if
(
owner_graph
()
->
options
().
no_profiling_on_shape_change
)
{
for
(
size_t
i
=
0
;
i
<
m_incache_layouts
.
size
();
i
++
)
{
for
(
size_t
j
=
0
;
j
<
m_incache_layouts
.
at
(
i
).
ndim
;
j
++
)
{
m_incache_layouts
.
at
(
i
)[
j
]
=
0
;
m_incache_layouts
.
at
(
i
).
stride
[
j
]
=
0
;
}
}
}
mgb_assert
(
m_fastrun_layouts
.
size
()
==
layouts
.
size
());
static_assert
(
...
...
@@ -582,12 +591,6 @@ AlgoChooser<Opr>::AlgoChooserHelper::choose_by_profile(
if
(
policy
.
algo
.
valid
())
{
return
policy
;
}
if
(
is_matmul
<
Opr
>
())
{
mgb_log_warn
(
"choose algo by heuristic, which may cause performance "
"regression."
);
return
choose_by_heuristic
(
selected_strategy
);
}
}
typename
AlgoChooser
<
Opr
>::
ImplExecutionPolicy
tmp_policy
;
...
...
@@ -1027,6 +1030,7 @@ AlgoChooser<Opr>::AlgoChooserHelper::extract_algo_attribute(
}
//! from graph option
// FIXME: no_profiling_on_shape_change extract USABLE_DEPEND_ON_SHAPE attribute when fixed usable
if
(
owner_graph
()
->
options
().
fast_run_config
.
shared_batch_size
)
{
ret
.
second
|=
AlgoAttribute
::
USABLE_DEPEND_ON_SHAPE
;
}
...
...
src/opr/include/megbrain/opr/search_policy/profiler.h
浏览文件 @
4b08e79d
...
...
@@ -58,13 +58,6 @@ constexpr bool opr_contain_bias() {
return
std
::
is_same
<
Opr
,
megdnn
::
ConvBias
>::
value
;
}
//! matmul and batchedMatrixMul
template
<
typename
Opr
>
constexpr
bool
is_matmul
()
{
return
std
::
is_same
<
Opr
,
megdnn
::
MatrixMul
>::
value
||
std
::
is_same
<
Opr
,
megdnn
::
BatchedMatrixMul
>::
value
;
}
template
<
typename
Opr
,
bool
has_prep
>
struct
PreprocessFilterImpl
{
using
T
=
union
{};
...
...
src/opr/test/algo_chooser.cpp
浏览文件 @
4b08e79d
...
...
@@ -296,6 +296,55 @@ TEST(TestOprDNN, FastrunIgnoreBatchSizeBatchedMatrixMul) {
{
TensorShape
{
4
,
6
,
8
},
TensorShape
{
4
,
8
,
4
}});
}
template
<
typename
MgbOpr
>
void
test_no_profiling_on_shape_change
(
const
TensorShapeArray
&
inps0
,
const
TensorShapeArray
&
inps1
)
{
using
Policy
=
typename
MgbOpr
::
ExecutionPolicy
;
int
nr_set
=
0
;
auto
on_get
=
[](
const
std
::
string
&
,
const
void
*
,
size_t
,
const
void
*
,
size_t
)
{};
auto
on_set
=
[
&
nr_set
](
const
std
::
string
&
,
const
void
*
,
size_t
,
const
void
*
,
size_t
)
{
nr_set
++
;
};
PersistentCacheHook
cache_hook
{
on_get
,
on_set
};
auto
cn
=
CompNode
::
load
(
"xpu0"
);
auto
run
=
[
&
cn
](
const
TensorShapeArray
&
shapes
)
{
auto
graph
=
ComputingGraph
::
make
();
graph
->
options
().
no_profiling_on_shape_change
=
true
;
HostTensorGenerator
<>
gen
;
auto
host_a
=
gen
(
shapes
[
0
],
cn
);
auto
host_b
=
gen
(
shapes
[
1
],
cn
);
HostTensorND
host_out
;
auto
a
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_a
),
b
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_b
);
Policy
policy
;
policy
.
strategy
=
Policy
::
Strategy
::
PROFILE
;
auto
out
=
MgbOpr
::
make
(
a
,
b
,
{},
policy
,
{});
std
::
unique_ptr
<
cg
::
AsyncExecutable
>
func
=
graph
->
compile
({{
out
,
{}}});
func
->
execute
();
};
run
(
inps0
);
int
nr
=
nr_set
;
ASSERT_GT
(
nr
,
0
);
run
(
inps1
);
ASSERT_EQ
(
nr
,
nr_set
);
}
TEST
(
TestOprDNN
,
FastrunNoProfilingOnShapeChange
)
{
REQUIRE_GPU
(
1
);
test_no_profiling_on_shape_change
<
opr
::
Convolution
>
(
{{
12
,
3
,
36
,
36
},
{
4
,
3
,
3
,
3
}},
{{
32
,
3
,
28
,
28
},
{
4
,
3
,
3
,
3
}});
test_no_profiling_on_shape_change
<
opr
::
MatrixMul
>
({{
20
,
30
},
{
30
,
40
}},
{{
30
,
40
},
{
40
,
60
}});
}
#endif // MGB_ENABLE_FASTRUN
#endif // MGB_CUDA
...
...
src/opr/test/blas.cpp
浏览文件 @
4b08e79d
...
...
@@ -916,11 +916,12 @@ TEST(TestOprBlas, MatrixMulExePolicy) {
graph
->
options
().
no_profiling_on_shape_change
=
true
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
matmul
,
host_y
)});
func
->
execute
();
ASSERT_EQ
(
nr_get
,
0
);
ASSERT_GT
(
nr_get
,
0
);
int
nr
=
nr_get
;
graph
->
options
().
no_profiling_on_shape_change
=
false
;
func
=
graph
->
compile
({
make_callback_copy
(
matmul
,
host_y
)});
func
->
execute
();
ASSERT_GT
(
nr_get
,
0
);
ASSERT_GT
(
nr_get
,
nr
);
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录