Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
0f42c662
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看板
提交
0f42c662
编写于
5月 13, 2020
作者:
W
wangcong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DepthwiseConv2d+Eltwise fusion pass
上级
168dfb25
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
2 deletion
+48
-2
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.cc
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.cc
+8
-2
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.h
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.h
+1
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
.../ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
+37
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
...e/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
+2
-0
未找到文件。
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.cc
浏览文件 @
0f42c662
...
...
@@ -38,6 +38,11 @@ constexpr auto kFusionKernelNamePrfix = "te_fusion";
constexpr
auto
kOptional
=
"optional_"
;
constexpr
auto
kOpFormat_FRACTAL_Z
=
"FRACTAL_Z"
;
std
::
map
<
std
::
string
,
std
::
string
>
TbeKernelBuild
::
buffer_fussion_op_map_
=
{
{
"DepthwiseConv2dNative"
,
"DepthwiseConv2D"
},
{
"TensorAdd"
,
"Add"
}
};
std
::
string
NormalizeFullScopeName
(
const
string
&
full_scope_name
)
{
// exp:Default/ReLU-op0 -->Default_ReLU_op0
string
normal_ret
=
full_scope_name
;
...
...
@@ -825,8 +830,9 @@ bool TbeKernelBuild::GenFusionComputeJson(const mindspore::AnfNodePtr &compute_n
(
*
compute_op_str
)[
"output_desc"
]
=
output_desc_list
;
// gen others
auto
type
=
AnfAlgo
::
GetCNodeName
(
cnode
);
if
(
type
==
"TensorAdd"
)
{
type
=
"Add"
;
// replace special op type for buffer fusion op
if
(
buffer_fussion_op_map_
.
find
(
type
)
!=
buffer_fussion_op_map_
.
end
())
{
type
=
buffer_fussion_op_map_
[
type
];
}
(
*
compute_op_str
)[
"type"
]
=
type
;
tbe
::
TbeAdapter
::
NormalizeFuncName
(
&
type
);
...
...
mindspore/ccsrc/kernel/tbe/tbe_kernel_build.h
浏览文件 @
0f42c662
...
...
@@ -76,6 +76,7 @@ class TbeKernelBuild {
std
::
map
<
const
AnfNodePtr
,
FusionDataType
>
*
spec_data_input
);
static
bool
IsDynamicInput
(
const
CNodePtr
&
cnode
);
static
size_t
GetOptionalInput
(
const
CNodePtr
&
cnode
,
bool
is_dynamic_input
);
static
std
::
map
<
std
::
string
,
std
::
string
>
buffer_fussion_op_map_
;
};
class
TbeKernelJsonCreator
{
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
浏览文件 @
0f42c662
...
...
@@ -545,6 +545,39 @@ void BufferFusion::MatchBnupdateAddRelu(const CNodePtr &cnode, const AnfNodePtr
}
}
void
BufferFusion
::
MatchDepthwiseConvRelu
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
,
bool
is_order
)
{
MS_EXCEPTION_IF_NULL
(
cnode
);
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
auto
manager
=
kernel_graph
.
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
if
(
is_order
)
{
// DepthwiseConvolution--->Elemwise
auto
depthwise_conv
=
cnode
->
input
(
1
);
MS_EXCEPTION_IF_NULL
(
depthwise_conv
);
if
(
cnode
->
isa
<
CNode
>
()
&&
AnfAlgo
::
GetCNodeName
(
depthwise_conv
)
==
prim
::
kPrimDepthwiseConv2dNative
->
name
())
{
std
::
vector
<
int
>
output_used_num
{
SizeToInt
(
manager
->
node_users
()[
depthwise_conv
].
size
())};
AnfAlgo
::
SetNodeAttr
(
kAttrOutputUsedNum
,
MakeValue
(
output_used_num
),
depthwise_conv
);
std
::
unordered_set
<
AnfNodePtr
>
record
{
cnode
,
depthwise_conv
};
candidate_fusion
->
push_back
(
record
);
SetRecordFusionId
(
record
);
}
}
else
{
// Elemwise-->DepthwiseConvolution
auto
relu
=
cnode
->
input
(
1
);
MS_EXCEPTION_IF_NULL
(
relu
);
if
(
cnode
->
isa
<
CNode
>
()
&&
AnfAlgo
::
GetCNodeName
(
relu
)
==
prim
::
kPrimRelu
->
name
()
||
AnfAlgo
::
GetCNodeName
()
==
kReluV2OpName
)
{
std
::
vector
<
int
>
output_used_num
{
SizeToInt
(
manager
->
node_users
()[
relu
].
size
())};
AnfAlgo
::
SetNodeAttr
(
kAttrOutputUsedNum
,
MakeValue
(
output_used_num
),
relu
);
std
::
unordered_set
<
AnfNodePtr
>
record
{
cnode
,
relu
};
candidate_fusion
->
push_back
(
record
);
SetRecordFusionId
(
record
);
}
}
}
void
BufferFusion
::
MatchOpNamePattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
...
...
@@ -563,7 +596,11 @@ void BufferFusion::MatchOpNamePattern(const session::KernelGraph &kernel_graph,
MatchBnupdateAddRelu
(
cnode
,
relu_input
,
kernel_graph
,
candidate_fusion
);
}
else
if
(
relu_input
->
isa
<
CNode
>
()
&&
AnfAlgo
::
GetCNodeName
(
relu_input
)
==
prim
::
kPrimTupleGetItem
->
name
())
{
MatchBnupdateRelu
(
cnode
,
relu_input
,
kernel_graph
,
candidate_fusion
);
}
else
if
(
relu_input
->
isa
<
CNode
>
()
&&
AnfAlgo
::
GetCNodeName
(
relu_input
)
==
prim
::
kPrimDepthwiseConv2dNative
->
name
())
{
MatchDepthwiseConvRelu
(
cnode
,
kernel_graph
,
candidate_fusion
,
true
);
}
}
else
if
(
AnfAlgo
::
GetCNodeName
(
cnode
)
==
prim
::
kPrimDepthwiseConv2dNative
->
name
())
{
MatchDepthwiseConvRelu
(
cnode
,
kernel_graph
,
candidate_fusion
,
false
);
}
}
}
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
浏览文件 @
0f42c662
...
...
@@ -51,6 +51,8 @@ class BufferFusion : public Pass {
FusedNodeRecord
*
candidate_fusion
);
void
MatchBnupdateAddRelu
(
const
CNodePtr
&
cnode
,
const
AnfNodePtr
&
relu_input
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
MatchDepthwiseConvRelu
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
,
bool
is_order
);
void
MatchOpNamePattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
MatchFusionTypePattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录