Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
9b7df3d0
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9b7df3d0
编写于
8月 21, 2020
作者:
V
VectorSL
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gpu optimize transpose
上级
3449abd7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
5 deletion
+33
-5
mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc
...ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc
+32
-4
mindspore/ccsrc/backend/optimizer/gpu/replace_bn_cast_fusion.cc
...ore/ccsrc/backend/optimizer/gpu/replace_bn_cast_fusion.cc
+1
-1
未找到文件。
mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc
浏览文件 @
9b7df3d0
...
...
@@ -33,7 +33,25 @@ std::vector<int> TransposeAxis(const std::string &src_format, const std::string
}
else
if
((
src_format
==
kOpFormat_NHWC
)
&&
(
dst_format
==
kOpFormat_NCHW
))
{
return
{
0
,
3
,
1
,
2
};
}
else
{
MS_LOG
(
EXCEPTION
)
<<
"Invaild format transform, from "
<<
src_format
<<
" to "
<<
dst_format
;
MS_LOG
(
EXCEPTION
)
<<
"Invalid format transform, from "
<<
src_format
<<
" to "
<<
dst_format
;
}
}
// Transpose can be replaceed by nop reshape in some situations.
// 1. out_shape [x, 1, 1, y] with transpose perm {0, 2, 3, 1}
// 2. out_shape [x, y, 1, 1] with transpose perm {0, 3, 1, 2}
bool
IsFakeTranspose
(
const
std
::
vector
<
size_t
>
&
out_shape
,
const
std
::
vector
<
int
>
&
transpose_perm
)
{
if
(
out_shape
.
size
()
!=
4
)
{
MS_LOG
(
EXCEPTION
)
<<
"Invalid data shape, 4-D data was needed, but get "
<<
out_shape
.
size
()
<<
"-D."
;
}
std
::
vector
<
int
>
perm1
=
{
0
,
2
,
3
,
1
};
std
::
vector
<
int
>
perm2
=
{
0
,
3
,
1
,
2
};
if
(
transpose_perm
==
perm1
)
{
return
(
out_shape
[
1
]
==
1
&&
out_shape
[
2
]
==
1
);
}
else
if
(
transpose_perm
==
perm2
)
{
return
(
out_shape
[
2
]
==
1
&&
out_shape
[
3
]
==
1
);
}
else
{
return
false
;
}
}
...
...
@@ -56,8 +74,16 @@ void SetTransposeOpBuildInfo(const std::string &input_format, const std::string
CNodePtr
InsertTransposeOp
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
,
const
AnfNodePtr
&
used_node
,
int
used_node_index
,
const
std
::
vector
<
int
>
&
transpose_perm
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
// 1.Create a transpose node.
auto
transpose_prim
=
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimTranspose
->
name
());
// 0.Judge whether it is a fake transpose
auto
transed_shape
=
AnfAlgo
::
GetInputDeviceShape
(
used_node
,
used_node_index
);
bool
is_fake
=
IsFakeTranspose
(
transed_shape
,
transpose_perm
);
// 1.Create a transpose node or a fake transpose node:reshape.
mindspore
::
PrimitivePtr
transpose_prim
;
if
(
is_fake
)
{
transpose_prim
=
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimReshape
->
name
());
}
else
{
transpose_prim
=
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimTranspose
->
name
());
}
MS_EXCEPTION_IF_NULL
(
transpose_prim
);
// 2.Set the input of transpose.
std
::
vector
<
AnfNodePtr
>
transpose_input
=
{
NewValueNode
(
transpose_prim
),
node
};
...
...
@@ -66,7 +92,9 @@ CNodePtr InsertTransposeOp(const FuncGraphPtr &graph, const AnfNodePtr &node, co
auto
transpose_type
=
{
AnfAlgo
::
GetPrevNodeOutputInferDataType
(
used_node
,
used_node_index
)};
auto
transpose_shape
=
{
AnfAlgo
::
GetPrevNodeOutputInferShape
(
used_node
,
used_node_index
)};
AnfAlgo
::
SetOutputInferTypeAndShape
(
transpose_type
,
transpose_shape
,
transpose_op
.
get
());
AnfAlgo
::
SetNodeAttr
(
kAttrPerm
,
MakeValue
(
transpose_perm
),
transpose_op
);
if
(
!
is_fake
)
{
AnfAlgo
::
SetNodeAttr
(
kAttrPerm
,
MakeValue
(
transpose_perm
),
transpose_op
);
}
// 4.Set the input of used_node.
MS_LOG
(
DEBUG
)
<<
"Node: "
<<
node
->
fullname_with_scope
()
<<
", used node: "
<<
used_node
->
fullname_with_scope
()
<<
", index: "
<<
used_node_index
;
...
...
mindspore/ccsrc/backend/optimizer/gpu/replace_bn_cast_fusion.cc
浏览文件 @
9b7df3d0
...
...
@@ -57,7 +57,7 @@ const AnfNodePtr ReplaceBNCastFusion::Process(const FuncGraphPtr &graph, const A
if
(
item_idx
==
0
)
{
auto
cast
=
GetRealNodeUsedList
(
graph
,
outlist
->
at
(
i
).
first
);
if
(
AnfAlgo
::
GetCNodeName
(
cast
->
at
(
0
).
first
)
!=
"Cast"
)
{
return
nullptr
;
continue
;
}
manager
->
Replace
(
utils
::
cast
<
CNodePtr
>
(
cast
->
at
(
0
).
first
),
utils
::
cast
<
CNodePtr
>
(
outlist
->
at
(
i
).
first
));
outputs_type
.
push_back
(
kNumberTypeFloat16
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录