Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
1b1ad56a
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
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看板
提交
1b1ad56a
编写于
1月 13, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mgb/gopt): fix warp fusion opt pass
GitOrigin-RevId: a40bbcd71929c1b542acc77d7959a1191217bf62
上级
99b17623
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
56 addition
and
5 deletion
+56
-5
src/gopt/impl/fuse_nchw4_int8_preprocess.cpp
src/gopt/impl/fuse_nchw4_int8_preprocess.cpp
+3
-3
src/gopt/test/inference.cpp
src/gopt/test/inference.cpp
+52
-2
src/opr/impl/imgproc.cpp
src/opr/impl/imgproc.cpp
+1
-0
未找到文件。
src/gopt/impl/fuse_nchw4_int8_preprocess.cpp
浏览文件 @
1b1ad56a
...
...
@@ -676,9 +676,9 @@ void FuseWarpPerspectiveDimshufflePass::apply(OptState& opt) const {
auto
on_opr
=
[
&
try_warp_nchw_typecvt
,
&
try_warp_nhwc2nchw_typecvt
,
&
try_warp_nhwc2nchw4_typecvt
,
&
try_warp_nchw2nchw4_typecvt
,
&
rewriter
](
OperatorNodeBase
*
opr
)
{
if
(
!
try_warp_n
chw_typecvt
(
opr
)
&&
!
try_warp_nhwc2nchw
_typecvt
(
opr
)
&&
!
try_warp_n
hwc2nchw4_typecvt
(
opr
)
&&
!
try_warp_nchw
2nchw4
_typecvt
(
opr
))
{
if
(
!
try_warp_n
hwc2nchw4
_typecvt
(
opr
)
&&
!
try_warp_n
chw2nchw4_typecvt
(
opr
)
&&
!
try_warp_nchw
_typecvt
(
opr
)
&&
!
try_warp_nhwc2nchw
_typecvt
(
opr
))
{
rewriter
.
auto_replace_outputs
(
opr
);
}
};
...
...
src/gopt/test/inference.cpp
浏览文件 @
1b1ad56a
...
...
@@ -3723,7 +3723,7 @@ TEST(TestGoptInference, PreProcessCase1) {
ASSERT_TRUE
(
y_opt
.
node
()
->
owner_opr
()
->
same_type
<
opr
::
RelayoutFormat
>
());
}
TEST
(
TestGoptInference
,
WarpAndPreProcessCase
)
{
TEST
(
TestGoptInference
,
WarpAndPreProcessCase
0
)
{
REQUIRE_GPU
(
1
);
HostTensorGenerator
<
dtype
::
Uint8
,
RandomDistribution
::
UNIFORM
>
gen
(
0
,
255
);
auto
cn
=
CompNode
::
load
(
"gpu0"
);
...
...
@@ -3774,7 +3774,57 @@ TEST(TestGoptInference, WarpAndPreProcessCase) {
graph
->
compile
({{
y_opt
,
{}}})
->
to_json
()
->
writeto_fpath
(
output_file
(
"TestGoptInference.WarpAndPreProcessCase.json"
));
"TestGoptInference.WarpAndPreProcessCase0.json"
));
HostTensorND
host_y_opt
,
host_y
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
y
,
host_y
),
make_callback_copy
(
y_opt
,
host_y_opt
)});
func
->
execute
();
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-5
);
}
TEST
(
TestGoptInference
,
WarpAndPreProcessCase1
)
{
REQUIRE_GPU
(
1
);
HostTensorGenerator
<
dtype
::
Uint8
,
RandomDistribution
::
UNIFORM
>
gen
(
0
,
255
);
auto
cn
=
CompNode
::
load
(
"gpu0"
);
auto
graph
=
ComputingGraph
::
make
();
graph
->
options
().
graph_opt_level
=
0
;
size_t
n
=
1
;
size_t
c
=
3
;
size_t
h
=
16
;
size_t
w
=
16
;
auto
host_x1
=
gen
({
n
,
h
,
w
,
c
},
cn
);
auto
x
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_x1
);
auto
mat_host
=
std
::
make_shared
<
HostTensorND
>
(
cn
,
TensorShape
{
n
,
3
,
3
},
dtype
::
Float32
());
warp_perspective_mat_gen
(
*
mat_host
,
n
,
h
,
w
);
auto
mat
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
mat_host
).
rename
(
"mat"
);
opr
::
WarpPerspective
::
Param
warp_param
;
warp_param
.
format
=
opr
::
WarpPerspective
::
Param
::
Format
::
NHWC
;
auto
x_warp
=
opr
::
WarpPerspective
::
make
(
x
,
mat
,
TensorShape
{
h
,
w
},
warp_param
);
auto
x_nchw
=
opr
::
Dimshuffle
::
make
(
x_warp
,
{
0
,
3
,
1
,
2
},
4
,
cn
);
auto
result
=
opr
::
TypeCvt
::
make
(
x_nchw
,
dtype
::
Float32
(),
cn
);
auto
y
=
result
;
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_preprocess
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_TRUE
(
y_opt
.
node
()
->
owner_opr
()
->
same_type
<
opr
::
WarpPerspective
>
());
ASSERT_EQ
(
opr
::
WarpPerspective
::
Param
::
Format
::
NHWC_NCHW
,
find_opr
<
opr
::
WarpPerspective
>
(
y_opt
).
param
().
format
);
graph
->
compile
({{
y_opt
,
{}}})
->
to_json
()
->
writeto_fpath
(
output_file
(
"TestGoptInference.WarpAndPreProcessCase1.json"
));
HostTensorND
host_y_opt
,
host_y
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
y
,
host_y
),
...
...
src/opr/impl/imgproc.cpp
浏览文件 @
1b1ad56a
...
...
@@ -93,6 +93,7 @@ void WarpPerspectiveForward::outshape_by_symvar_do_get_output_shape(
dest
.
shape
[
4
]
=
4
;
break
;
case
Param
::
Format
::
NHWC_NCHW
:
dest
.
ndim
=
4
;
dest
[
0
]
=
matshp
[
0
];
dest
.
shape
[
1
]
=
imgshp
.
shape
[
3
];
dest
.
shape
[
2
]
=
oshp2d
.
shape
[
0
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录