Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
f6bd4f59
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
f6bd4f59
编写于
4月 19, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mgb): fix attribute check compatibility when profiling and read_from_cache in fast run
GitOrigin-RevId: b865d467b025a434341237fef85cced71d824cd5
上级
0a86a070
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
41 deletion
+58
-41
src/opr/impl/search_policy/algo_chooser.cpp
src/opr/impl/search_policy/algo_chooser.cpp
+45
-30
src/opr/test/dnn/convolution.cpp
src/opr/test/dnn/convolution.cpp
+13
-11
未找到文件。
src/opr/impl/search_policy/algo_chooser.cpp
浏览文件 @
f6bd4f59
...
...
@@ -299,18 +299,13 @@ void AlgoChooser<Opr>::profile(ExeContext& ctx,
RealTimer
timer
;
for
(
auto
algo
:
ctx
.
get_all_candidates
())
{
Maybe
<
AlgoChooserProfileCache
::
ResultEntry
>
cur_rst
;
std
::
string
msg
=
ssprintf
(
"profiling %s algorithm %s %s"
,
ctx
.
mgb_opr
()
->
dyn_typeinfo
()
->
name
,
algo
.
desc
.
name
.
c_str
(),
layouts_str
.
c_str
());
ImplExecutionPolicy
policy
;
policy
.
algo
=
algo
.
desc
;
ctx
.
construct_execution_policy
(
selected_strategy
,
policy
);
if
(
ctx
.
get_workspace_size_bytes
(
policy
)
>=
workspace_limit
)
{
continue
;
}
//! check negative attribute : skip negative attribute
auto
palgo
=
ctx
.
megdnn_opr
()
->
get_algorithm_from_desc
(
policy
.
algo
);
if
(
!
(
palgo
->
contain_attribute_all
(
target_attr
.
first
)
&&
!
palgo
->
contain_attribute_any
(
target_attr
.
second
)))
{
if
(
palgo
->
contain_attribute_any
(
target_attr
.
second
))
{
mgb_log_debug
(
"skip algo %s with attribute(%s), which is not match the "
"profile strategy required contain attribute(%s) and not "
...
...
@@ -322,6 +317,15 @@ void AlgoChooser<Opr>::profile(ExeContext& ctx,
continue
;
}
//! check workspace limit
ctx
.
construct_execution_policy
(
selected_strategy
,
policy
);
if
(
ctx
.
get_workspace_size_bytes
(
policy
)
>=
workspace_limit
)
{
continue
;
}
std
::
string
msg
=
ssprintf
(
"profiling %s algorithm %s %s"
,
ctx
.
mgb_opr
()
->
dyn_typeinfo
()
->
name
,
algo
.
desc
.
name
.
c_str
(),
layouts_str
.
c_str
());
timer
.
reset
();
MGB_TRY
{
cur_rst
=
ctx
.
profile_single_algo
(
policy
,
cur_timeout
);
}
MGB_CATCH
(
std
::
exception
&
exc
,
{
...
...
@@ -350,11 +354,11 @@ void AlgoChooser<Opr>::profile(ExeContext& ctx,
prof_rst
.
push_back
(
rst
);
}
std
::
string
msg
=
ssprintf
(
"no usable %s algorithm %s with
attribute(%s) and withou
t "
"
attribute(%s
)"
,
"no usable %s algorithm %s with
out attribute(%s) or could not mee
t "
"
workspace limite requirement(%zu
)"
,
ctx
.
mgb_opr
()
->
dyn_typeinfo
()
->
name
,
layouts_str
.
c_str
(),
Algorithm
::
attribute_str
(
target_attr
.
first
).
c_str
(),
Algorithm
::
attribute_str
(
target_attr
.
second
).
c_str
()
);
Algorithm
::
attribute_str
(
target_attr
.
second
).
c_str
(),
workspace_limit
);
mgb_assert
(
!
prof_rst
.
empty
(),
"%s"
,
msg
.
c_str
());
FixedTensorLayouts
origin_layouts
=
ctx
.
layouts
();
...
...
@@ -544,6 +548,7 @@ AlgoChooser<Opr>::ExeContext::get_profile_result_from_cache(
return
{};
auto
target_attr
=
extract_algo_attribute
(
selected_strategy
);
bool
skip_by_negative
=
false
;
for
(
auto
&&
i
:
prof
)
{
auto
attr_of_algo
=
static_cast
<
megdnn
::
Algorithm
::
Attribute
>
(
i
.
attribute
);
...
...
@@ -552,26 +557,36 @@ AlgoChooser<Opr>::ExeContext::get_profile_result_from_cache(
(
attr_of_algo
&
target_attr
.
first
));
bool
contain_attr_any_negative
=
static_cast
<
bool
>
(
attr_of_algo
&
target_attr
.
second
);
if
(
contain_attr_all_positive
&&
!
contain_attr_any_negative
)
{
auto
iter
=
algo_map
.
find
(
i
.
algo
);
mgb_assert
(
iter
!=
algo_map
.
end
(),
"algorithm %s exists in "
"profiling result but not in algo_map; please "
"report this "
"bug; opr: %s{%s}, layouts: %s "
,
i
.
algo
.
c_str
(),
m_base_mgb_opr
->
cname
(),
m_base_mgb_opr
->
dyn_typeinfo
()
->
name
,
format_fixlayouts
<
Opr
>
(
m_layouts
,
arity_in
,
arity_out
)
.
c_str
());
return
iter
->
second
;
if
(
contain_attr_all_positive
)
{
if
(
!
contain_attr_any_negative
)
{
auto
iter
=
algo_map
.
find
(
i
.
algo
);
mgb_assert
(
iter
!=
algo_map
.
end
(),
"algorithm %s exists in profiling result but not in "
"algo_map; please report this bug; opr: %s{%s}, "
"layouts: %s "
,
i
.
algo
.
c_str
(),
m_base_mgb_opr
->
cname
(),
m_base_mgb_opr
->
dyn_typeinfo
()
->
name
,
format_fixlayouts
<
Opr
>
(
m_layouts
,
arity_in
,
arity_out
)
.
c_str
());
return
iter
->
second
;
}
else
{
skip_by_negative
=
true
;
}
}
}
mgb_log_error
(
"algos read from cache could not satisfy attribute with %s and "
"without %s"
,
Algorithm
::
attribute_str
(
target_attr
.
first
).
c_str
(),
Algorithm
::
attribute_str
(
target_attr
.
second
).
c_str
());
if
(
skip_by_negative
)
{
mgb_log_error
(
"No usable algo. Only navie algos are available, but negative "
"stategy is %s."
,
Algorithm
::
attribute_str
(
target_attr
.
second
).
c_str
());
}
else
{
mgb_log_error
(
"No usable algo. algos read from cache could not satisfy "
"attribute with %s"
,
Algorithm
::
attribute_str
(
target_attr
.
first
).
c_str
());
}
mgb_trap
();
MIDOUT_E
...
...
src/opr/test/dnn/convolution.cpp
浏览文件 @
f6bd4f59
...
...
@@ -356,14 +356,7 @@ TEST(TestOprDNN, ConvBiasExePolicy) {
auto
orig_impl
=
PersistentCache
::
set_impl
(
std
::
make_shared
<
InMemoryPersistentCache
>
());
#if MGB_ENABLE_FASTRUN
for
(
auto
strategy
:
SmallVector
<
S
>
{
S
::
PROFILE
,
S
::
HEURISTIC
,
S
::
PROFILE
|
S
::
REPRODUCIBLE
,
S
::
PROFILE
|
S
::
HEURISTIC
})
{
#else
for
(
auto
strategy
:
SmallVector
<
S
>
{
S
:
HEURISTIC
,
S
::
PROFILE
|
S
::
HEURISTIC
})
{
#endif
auto
run
=
[
&
](
S
strategy
)
{
auto
graph
=
ComputingGraph
::
make
();
HostTensorGenerator
<>
gen
;
...
...
@@ -378,10 +371,8 @@ TEST(TestOprDNN, ConvBiasExePolicy) {
auto
x
=
mkvar
(
"x"
,
{
20
,
50
,
50
,
16
},
dtype
::
QuantizedS8
(
2.5
f
));
auto
w
=
mkvar
(
"w"
,
{
24
,
3
,
3
,
16
},
dtype
::
QuantizedS8
(
2.5
f
));
auto
bias
=
mkvar
(
"bias"
,
{
1
,
1
,
1
,
24
},
dtype
::
QuantizedS32
(
6.25
f
));
param
.
nonlineMode
=
Param
::
NonlineMode
::
RELU
;
param
.
format
=
Param
::
Format
::
NHWC
;
Policy
policy
;
policy
.
strategy
=
strategy
;
...
...
@@ -391,10 +382,21 @@ TEST(TestOprDNN, ConvBiasExePolicy) {
HostTensorND
host_y
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
conv_bias
,
host_y
)});
func
->
execute
();
//! set a new cache
PersistentCache
::
set_impl
(
std
::
make_shared
<
InMemoryPersistentCache
>
());
};
#if MGB_ENABLE_FASTRUN
for
(
auto
strategy
:
SmallVector
<
S
>
{
S
::
PROFILE
,
S
::
HEURISTIC
,
S
::
PROFILE
|
S
::
REPRODUCIBLE
,
S
::
PROFILE
|
S
::
HEURISTIC
})
{
#else
for
(
auto
strategy
:
SmallVector
<
S
>
{
S
:
HEURISTIC
,
S
::
PROFILE
|
S
::
HEURISTIC
})
{
#endif
run
(
strategy
);
}
ASSERT_THROW
(
run
(
S
::
OPTIMIZED
|
S
::
PROFILE
),
MegBrainError
);
PersistentCache
::
set_impl
(
orig_impl
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录