Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
66338652
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看板
提交
66338652
编写于
1月 05, 2023
作者:
M
Megvii Engine Team
提交者:
黄信达
1月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(pass): fix subtensor padding channel
GitOrigin-RevId: c15b86592abb7ec374561c02ae00df3902dbe903
上级
a0f3336a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
1 deletion
+63
-1
src/gopt/impl/padding_channel.cpp
src/gopt/impl/padding_channel.cpp
+8
-1
src/gopt/test/padding_channel.cpp
src/gopt/test/padding_channel.cpp
+55
-0
未找到文件。
src/gopt/impl/padding_channel.cpp
浏览文件 @
66338652
...
...
@@ -114,7 +114,14 @@ void PaddingChannelPass::apply(OptState& opt) const {
auto
rewriter
=
opt
.
graph
().
make_rewriter
();
auto
on_opr
=
[
this
,
&
opt
,
&
rewriter
](
OperatorNodeBase
*
opr
)
{
auto
it
=
m_opr_replace_funcs
.
find
(
opr
->
dyn_typeinfo
());
if
(
it
!=
m_opr_replace_funcs
.
end
())
{
auto
is_skip
=
false
;
//! if the input of the opr is dynamic shape, skip it
for
(
size_t
id
=
0
;
id
<
opr
->
input
().
size
();
id
++
)
{
if
(
0
==
opr
->
input
(
id
)
->
shape
().
ndim
)
{
is_skip
=
true
;
}
}
if
(
it
!=
m_opr_replace_funcs
.
end
()
&&
!
is_skip
)
{
VarNodeArray
new_inp
;
new_inp
.
reserve
(
opr
->
input
().
size
());
for
(
auto
&&
inp
:
opr
->
input
())
{
...
...
src/gopt/test/padding_channel.cpp
浏览文件 @
66338652
...
...
@@ -443,4 +443,59 @@ TEST(TestGoptInference, ChannelPaddingMoreOp) {
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-3
);
}
TEST
(
TestGoptInference
,
DynamicShape
)
{
HostTensorGenerator
<>
gen
;
HostTensorGenerator
<
dtype
::
Int32
>
gen_int
;
auto
cn
=
CompNode
::
load
(
"cpu0"
);
auto
graph
=
ComputingGraph
::
make
();
graph
->
options
().
graph_opt_level
=
0
;
auto
mkcvar
=
[
&
](
const
char
*
name
,
const
TensorShape
&
shp
)
{
return
opr
::
SharedDeviceTensor
::
make
(
*
graph
,
*
gen
(
shp
,
cn
)).
rename
(
name
);
};
auto
host_x
=
gen
({
1
,
4
,
8
,
8
},
cn
);
auto
host_dy
=
gen_int
({
1
},
cn
);
auto
x
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_x
);
auto
dy
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_dy
);
int32_t
*
start
=
host_dy
->
ptr
<
int32_t
>
();
start
[
0
]
=
0
;
dy
=
opr
::
MarkDynamicVar
::
make
(
dy
);
using
AIdx
=
opr
::
indexing
::
AxisIndexer
;
auto
sub
=
opr
::
Subtensor
::
make
(
x
,
{
AIdx
::
make_interval
(
1
,
dy
,
x
.
make_scalar
(
4
),
x
.
make_scalar
(
1
))},
OperatorNodeConfig
(
"sub"
));
//! Hybrid nchw44 mode
opr
::
ConvBias
::
Param
param_conv
;
param_conv
.
pad_h
=
param_conv
.
pad_w
=
1
;
auto
w1
=
mkcvar
(
"w1"
,
{
3
,
4
,
3
,
3
}),
b1
=
mkcvar
(
"w1"
,
{
1
,
3
,
1
,
1
}),
conv1
=
opr
::
ConvBias
::
make
(
sub
,
w1
,
b1
,
param_conv
,
{},
OperatorNodeConfig
(
"conv1"
));
auto
w2
=
mkcvar
(
"w2"
,
{
4
,
3
,
1
,
1
}),
y
=
opr
::
Convolution
::
make
(
conv1
,
w2
,
{},
{},
OperatorNodeConfig
(
"conv2"
));
SymbolVar
y_pad
;
unpack_vector
(
gopt
::
GraphOptimizer
{}
.
add_pass
(
gopt
::
PaddingChannelPass
::
make
(
cg
::
GraphCommonOptimizeOptions
::
LayoutTransform
::
NCHW44
,
true
))
.
apply
({{
y
}})
.
endpoint_vars
(),
y_pad
);
auto
conv1_opt
=
find_opr
<
opr
::
ConvBias
>
(
y_pad
,
"conv1"
);
auto
conv2_opt
=
find_opr
<
opr
::
Convolution
>
(
y_pad
,
"conv2"
);
//! do not padding input tensor
ASSERT_EQ
(
conv1_opt
->
input
(
0
)
->
shape
().
ndim
,
0
);
//! output tensor padding input tensor
ASSERT_EQ
(
conv2_opt
->
input
(
0
)
->
shape
().
ndim
,
0
);
HostTensorND
host_y_opt
,
host_y
;
auto
func
=
graph
->
compile
(
{
make_callback_copy
(
y
,
host_y
),
make_callback_copy
(
y_pad
,
host_y_opt
)});
func
->
execute
();
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-2
);
}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录