Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b06c8028
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看板
提交
b06c8028
编写于
5月 22, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1336 add conv2dbackpropinput eltwise fusion pass
Merge pull request !1336 from Etone.Chan/Resnet50
上级
bd845dd0
391a1fa6
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
282 addition
and
36 deletion
+282
-36
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
.../ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
+14
-10
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.h
...cend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h
...ivate/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc
...ffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc
+76
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.h
...uffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.h
+47
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.cc
...scend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.cc
+69
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.h
...ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.h
+47
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_bnreduce_fusion_pass.h
...activate/ascend/buffer_fusion/conv_bnreduce_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_double_in_fusion_pass.cc
...tivate/ascend/buffer_fusion/conv_double_in_fusion_pass.cc
+0
-13
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_double_in_fusion_pass.h
...ctivate/ascend/buffer_fusion/conv_double_in_fusion_pass.h
+1
-2
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_single_in_fusion_pass.h
...ctivate/ascend/buffer_fusion/conv_single_in_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.h
.../ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/eltwise_fusion_pass.h
...c/pre_activate/ascend/buffer_fusion/eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.cc
...src/pre_activate/ascend/buffer_fusion/fusion_base_pass.cc
+13
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
...csrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
+4
-2
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/matmul_eltwise_fusion_pass.h
...ctivate/ascend/buffer_fusion/matmul_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h
...ctivate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h
...tivate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h
+1
-1
mindspore/ccsrc/pre_activate/common/fusion_id_allocator.h
mindspore/ccsrc/pre_activate/common/fusion_id_allocator.h
+2
-0
未找到文件。
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
浏览文件 @
b06c8028
...
...
@@ -65,6 +65,8 @@
#include "pre_activate/ascend/buffer_fusion/buffer_fusion.h"
#include "pre_activate/ascend/buffer_fusion/ub_pattern_fusion.h"
#include "pre_activate/ascend/buffer_fusion/eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/conv_single_in_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/conv_double_in_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/matmul_eltwise_fusion_pass.h"
...
...
@@ -341,16 +343,18 @@ void AscendBackendUBFusionOptimization(const std::shared_ptr<session::KernelGrap
fusion_id_allocator
->
Init
();
auto
optimizer
=
std
::
make_shared
<
GraphOptimizer
>
();
auto
ub_fusion_pm
=
std
::
make_shared
<
PassManager
>
(
"ub_fusion_pm"
);
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvDoubleInFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvSingleInFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
EltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
MatmulEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnupdateEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
DepthwiseConvEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnupdateEltwiseEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvBnReduceFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ReduceEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
SegmentEltwiseFusionPass
>
(
fusion_id_allocator
.
get
()));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
Conv2DBackpropEltwiseEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
Conv2DBackpropEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvBnReduceFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvSingleInFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnupdateEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnupdateEltwiseEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
MatmulEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConvDoubleInFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
ReduceEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
SegmentEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
EltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
DepthwiseConvEltwiseFusionPass
>
(
fusion_id_allocator
));
ub_fusion_pm
->
AddPass
(
std
::
make_shared
<
UbPatternFusion
>
());
optimizer
->
AddPassManager
(
ub_fusion_pm
);
(
void
)
optimizer
->
Optimize
(
kernel_graph
);
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
BnupdateEltwiseEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
BnupdateEltwiseEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
BnupdateEltwiseEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"BnupdateEltwiseEltwiseFusionPass"
,
idAllocator
)
{}
~
BnupdateEltwiseEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
BnupdateEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
BnupdateEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
BnupdateEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"BnupdateEltwiseFusionPass"
,
idAllocator
)
{}
~
BnupdateEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc
0 → 100644
浏览文件 @
b06c8028
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.h"
#include <vector>
#include <unordered_set>
#include <memory>
#include <string>
#include "kernel/kernel_fusion.h"
#include "debug/anf_ir_dump.h"
#include "session/anf_runtime_algorithm.h"
#include "operator/ops.h"
#include "utils/context/ms_context.h"
#include "pre_activate/common/fusion_id_allocator.h"
namespace
mindspore
{
namespace
opt
{
void
Conv2DBackpropEltwiseEltwiseFusionPass
::
MatchConv2DBackpropInputEltwiseEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
cnode
);
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
auto
manager
=
kernel_graph
.
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
std
::
unordered_set
<
AnfNodePtr
>
record
{
cnode
};
auto
eltwise_input
=
cnode
->
input
(
1
);
if
(
CheckDoubleInEltWiseNode
(
manager
.
get
(),
eltwise_input
))
{
(
void
)
record
.
insert
(
eltwise_input
);
}
else
{
return
;
}
auto
input_cnode
=
eltwise_input
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
input_cnode
);
auto
double_in_eltwise_input
=
input_cnode
->
input
(
1
);
if
(
!
double_in_eltwise_input
->
isa
<
CNode
>
()
||
!
AnfAlgo
::
IsRealCNodeKernel
(
double_in_eltwise_input
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
double_in_eltwise_input
))
{
return
;
}
if
(
AnfAlgo
::
CheckPrimitiveType
(
double_in_eltwise_input
,
prim
::
kPrimConv2DBackpropInput
))
{
(
void
)
record
.
insert
(
double_in_eltwise_input
);
candidate_fusion
->
push_back
(
record
);
SetRecordFusionId
(
record
);
}
}
void
Conv2DBackpropEltwiseEltwiseFusionPass
::
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
for
(
auto
&
node
:
node_list
)
{
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
continue
;
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
AnfAlgo
::
GetKernelType
(
cnode
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
cnode
)
==
kernel
::
FusionType
::
ELEMWISE
&&
(
cnode
->
inputs
().
size
()
==
ELTWISE_INPUT_SIZE
||
cnode
->
inputs
().
size
()
==
ELTWISE_DOUBLE_IN_INPUT_SIZE
))
{
MatchConv2DBackpropInputEltwiseEltwise
(
cnode
,
kernel_graph
,
candidate_fusion
);
}
}
}
}
// namespace opt
}
// namespace mindspore
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.h
0 → 100644
浏览文件 @
b06c8028
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_ELTWISE_FUSION_PASS_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_ELTWISE_FUSION_PASS_H_
#include <unordered_set>
#include <vector>
#include "pre_activate/ascend/buffer_fusion/fusion_base_pass.h"
#include "ir/anf.h"
#include "pre_activate/common/pass.h"
#include "pre_activate/common/fusion_id_allocator.h"
#include "device/kernel_info.h"
#include "kernel/kernel.h"
#include "session/kernel_graph.h"
namespace
mindspore
{
namespace
opt
{
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
class
Conv2DBackpropEltwiseEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
Conv2DBackpropEltwiseEltwiseFusionPass
(
FusionIdAllocatorPtr
idAllocator
)
:
FusionBasePass
(
"Conv2DBackpropEltwiseEltwiseFusionPass"
,
idAllocator
)
{}
~
Conv2DBackpropEltwiseEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
private:
void
MatchConv2DBackpropInputEltwiseEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_ELTWISE_FUSION_PASS_H_
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.cc
0 → 100644
浏览文件 @
b06c8028
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.h"
#include <vector>
#include <unordered_set>
#include <memory>
#include <string>
#include "kernel/kernel_fusion.h"
#include "debug/anf_ir_dump.h"
#include "session/anf_runtime_algorithm.h"
#include "operator/ops.h"
#include "utils/context/ms_context.h"
#include "pre_activate/common/fusion_id_allocator.h"
namespace
mindspore
{
namespace
opt
{
void
Conv2DBackpropEltwiseFusionPass
::
MatchConv2DBackpropInputEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
cnode
);
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
auto
manager
=
kernel_graph
.
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
std
::
unordered_set
<
AnfNodePtr
>
record
{
cnode
};
auto
eltwise_input
=
cnode
->
input
(
1
);
if
(
!
eltwise_input
->
isa
<
CNode
>
()
||
!
AnfAlgo
::
IsRealCNodeKernel
(
eltwise_input
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
eltwise_input
))
{
return
;
}
if
(
AnfAlgo
::
CheckPrimitiveType
(
eltwise_input
,
prim
::
kPrimConv2DBackpropInput
))
{
(
void
)
record
.
insert
(
eltwise_input
);
candidate_fusion
->
push_back
(
record
);
SetRecordFusionId
(
record
);
}
}
void
Conv2DBackpropEltwiseFusionPass
::
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
for
(
auto
&
node
:
node_list
)
{
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
continue
;
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
AnfAlgo
::
GetKernelType
(
cnode
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
cnode
)
==
kernel
::
FusionType
::
ELEMWISE
&&
(
cnode
->
inputs
().
size
()
==
ELTWISE_INPUT_SIZE
||
cnode
->
inputs
().
size
()
==
ELTWISE_DOUBLE_IN_INPUT_SIZE
))
{
MatchConv2DBackpropInputEltwise
(
cnode
,
kernel_graph
,
candidate_fusion
);
}
}
}
}
// namespace opt
}
// namespace mindspore
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv2dbackprop_eltwise_fusion_pass.h
0 → 100644
浏览文件 @
b06c8028
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_FUSION_PASS_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_FUSION_PASS_H_
#include <unordered_set>
#include <vector>
#include "pre_activate/ascend/buffer_fusion/fusion_base_pass.h"
#include "ir/anf.h"
#include "pre_activate/common/pass.h"
#include "pre_activate/common/fusion_id_allocator.h"
#include "device/kernel_info.h"
#include "kernel/kernel.h"
#include "session/kernel_graph.h"
namespace
mindspore
{
namespace
opt
{
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
class
Conv2DBackpropEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
Conv2DBackpropEltwiseFusionPass
(
FusionIdAllocatorPtr
idAllocator
)
:
FusionBasePass
(
"Conv2DBackpropEltwiseFusionPass"
,
idAllocator
)
{}
~
Conv2DBackpropEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
private:
void
MatchConv2DBackpropInputEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_PASS_CONV2DBACKPROP_ELTWISE_FUSION_PASS_H_
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_bnreduce_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
ConvBnReduceFusionPass
:
public
FusionBasePass
{
public:
explicit
ConvBnReduceFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
ConvBnReduceFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"ConvBnReduceFusionPass"
,
idAllocator
)
{}
~
ConvBnReduceFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_double_in_fusion_pass.cc
浏览文件 @
b06c8028
...
...
@@ -27,19 +27,6 @@
namespace
mindspore
{
namespace
opt
{
bool
ConvDoubleInFusionPass
::
CheckDoubleInEltWiseNode
(
FuncGraphManager
*
manager
,
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
manager
);
if
(
!
node
->
isa
<
CNode
>
()
||
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
))
{
return
false
;
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
auto
user_nodes
=
manager
->
node_users
()[
node
];
return
AnfAlgo
::
GetKernelType
(
node
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
node
)
==
kernel
::
FusionType
::
ELEMWISE
&&
user_nodes
.
size
()
==
ELTWISE_USE
&&
cnode
->
inputs
().
size
()
==
ELTWISE_INPUT_SIZE
;
}
void
ConvDoubleInFusionPass
::
MatchConvDoubleInEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
cnode
);
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_double_in_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
ConvDoubleInFusionPass
:
public
FusionBasePass
{
public:
explicit
ConvDoubleInFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
ConvDoubleInFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"ConvDoubleInFusionPass"
,
idAllocator
)
{}
~
ConvDoubleInFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
@@ -41,7 +41,6 @@ class ConvDoubleInFusionPass : public FusionBasePass {
private:
void
MatchConvDoubleInEltwise
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
bool
CheckDoubleInEltWiseNode
(
FuncGraphManager
*
manager
,
const
AnfNodePtr
&
node
);
};
}
// namespace opt
}
// namespace mindspore
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/conv_single_in_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
ConvSingleInFusionPass
:
public
FusionBasePass
{
public:
explicit
ConvSingleInFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
ConvSingleInFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"ConvSingleInFusionPass"
,
idAllocator
)
{}
~
ConvSingleInFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
DepthwiseConvEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
DepthwiseConvEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
DepthwiseConvEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"DepthwiseConvEltwiseFusionPass"
,
idAllocator
)
{}
~
DepthwiseConvEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
EltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
EltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
:
FusionBasePass
(
"EltwiseFusionPass"
,
idAllocator
)
{}
explicit
EltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"EltwiseFusionPass"
,
idAllocator
)
{}
~
EltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.cc
浏览文件 @
b06c8028
...
...
@@ -36,6 +36,19 @@ bool FusionBasePass::CheckEltWiseNode(FuncGraphManager *manager, const AnfNodePt
cnode
->
inputs
().
size
()
==
ELTWISE_INPUT_SIZE
;
}
bool
FusionBasePass
::
CheckDoubleInEltWiseNode
(
FuncGraphManager
*
manager
,
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
manager
);
if
(
!
node
->
isa
<
CNode
>
()
||
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
))
{
return
false
;
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
auto
user_nodes
=
manager
->
node_users
()[
node
];
return
AnfAlgo
::
GetKernelType
(
node
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
node
)
==
kernel
::
FusionType
::
ELEMWISE
&&
user_nodes
.
size
()
==
ELTWISE_USE
&&
cnode
->
inputs
().
size
()
==
ELTWISE_DOUBLE_IN_INPUT_SIZE
;
}
void
FusionBasePass
::
SetRecordFusionId
(
const
std
::
unordered_set
<
AnfNodePtr
>
&
record
)
{
auto
id
=
fusion_id_allocator
->
AllocateFusionId
();
for
(
auto
node
:
record
)
{
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
浏览文件 @
b06c8028
...
...
@@ -32,13 +32,14 @@ namespace opt {
const
int8_t
MAX_ELTWISE_NUM
=
3
;
const
int8_t
MIN_ELTWISE_SIZE
=
2
;
const
int8_t
ELTWISE_INPUT_SIZE
=
2
;
const
int8_t
ELTWISE_DOUBLE_IN_INPUT_SIZE
=
3
;
const
int8_t
ELTWISE_USE
=
1
;
const
int8_t
MAX_ELTWISE_SIZE
=
6
;
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
class
FusionBasePass
:
public
Pass
{
public:
FusionBasePass
(
const
std
::
string
&
name
,
FusionIdAllocator
*
idAllocator
)
FusionBasePass
(
const
std
::
string
&
name
,
FusionIdAllocator
Ptr
idAllocator
)
:
Pass
(
name
),
fusion_id_allocator
(
idAllocator
)
{}
~
FusionBasePass
()
override
=
default
;
bool
Run
(
const
FuncGraphPtr
&
graph
)
override
;
...
...
@@ -49,7 +50,8 @@ class FusionBasePass : public Pass {
FusedNodeRecord
*
candidate_fusion
)
=
0
;
void
SetRecordFusionId
(
const
std
::
unordered_set
<
AnfNodePtr
>
&
record
);
bool
CheckEltWiseNode
(
FuncGraphManager
*
manager
,
const
AnfNodePtr
&
node
);
FusionIdAllocator
*
fusion_id_allocator
;
bool
CheckDoubleInEltWiseNode
(
FuncGraphManager
*
manager
,
const
AnfNodePtr
&
node
);
FusionIdAllocatorPtr
fusion_id_allocator
;
};
}
// namespace opt
}
// namespace mindspore
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/matmul_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
MatmulEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
MatmulEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
MatmulEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"MatmulEltwiseFusionPass"
,
idAllocator
)
{}
~
MatmulEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
ReduceEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
ReduceEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
ReduceEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"ReduceEltwiseFusionPass"
,
idAllocator
)
{}
~
ReduceEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h
浏览文件 @
b06c8028
...
...
@@ -33,7 +33,7 @@ using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
class
SegmentEltwiseFusionPass
:
public
FusionBasePass
{
public:
explicit
SegmentEltwiseFusionPass
(
FusionIdAllocator
*
idAllocator
)
explicit
SegmentEltwiseFusionPass
(
FusionIdAllocator
Ptr
idAllocator
)
:
FusionBasePass
(
"SegmentEltwiseFusionPass"
,
idAllocator
)
{}
~
SegmentEltwiseFusionPass
()
override
=
default
;
void
MatchSingleFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
)
override
;
...
...
mindspore/ccsrc/pre_activate/common/fusion_id_allocator.h
浏览文件 @
b06c8028
...
...
@@ -16,6 +16,7 @@
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_COMMON_FUSION_ID_ALLOCATOR_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_COMMON_FUSION_ID_ALLOCATOR_H_
#include <memory>
#include "ir/base.h"
namespace
mindspore
{
...
...
@@ -36,6 +37,7 @@ class FusionIdAllocator {
private:
int32_t
fusion_id
;
};
using
FusionIdAllocatorPtr
=
std
::
shared_ptr
<
FusionIdAllocator
>
;
}
// namespace opt
}
// namespace mindspore
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录