Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
24e53879
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看板
提交
24e53879
编写于
5月 25, 2020
作者:
E
etone-chan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove old buffer fusion pass
上级
aeffccb7
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
53 addition
and
956 deletion
+53
-956
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
.../ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
+2
-3
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
.../ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
+0
-800
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
...e/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
+0
-73
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
...csrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
+7
-0
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc
...tivate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc
+5
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc
...ivate/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc
+5
-1
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/ub_pattern_fusion.h
...src/pre_activate/ascend/buffer_fusion/ub_pattern_fusion.h
+1
-1
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.cc
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.cc
+0
-35
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.h
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.h
+0
-33
tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc
...p/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc
+33
-9
未找到文件。
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
浏览文件 @
24e53879
...
@@ -62,7 +62,6 @@
...
@@ -62,7 +62,6 @@
#include "pre_activate/pass/common_subexpression_elimination.h"
#include "pre_activate/pass/common_subexpression_elimination.h"
#include "pre_activate/ascend/format_type/merge_cast_to_op.h"
#include "pre_activate/ascend/format_type/merge_cast_to_op.h"
#include "pre_activate/ascend/format_type/check_consistency.h"
#include "pre_activate/ascend/format_type/check_consistency.h"
#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/ub_pattern_fusion.h"
#include "pre_activate/ascend/buffer_fusion/eltwise_fusion_pass.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_eltwise_fusion_pass.h"
...
@@ -314,14 +313,14 @@ void AscendBackendOptimization(const std::shared_ptr<session::KernelGraph> &kern
...
@@ -314,14 +313,14 @@ void AscendBackendOptimization(const std::shared_ptr<session::KernelGraph> &kern
optimizer
->
AddPassManager
(
other_pm
);
optimizer
->
AddPassManager
(
other_pm
);
(
void
)
optimizer
->
Optimize
(
kernel_graph
);
(
void
)
optimizer
->
Optimize
(
kernel_graph
);
kernel_graph
->
SetExecOrderByDefault
();
kernel_graph
->
SetExecOrderByDefault
();
// buffer fusion
AscendBackendUBFusionOptimization
(
kernel_graph
);
if
(
save_graphs
)
{
if
(
save_graphs
)
{
std
::
string
file_path
=
std
::
string
file_path
=
save_graphs_path
+
"/"
+
"hwopt_d_end"
+
"_graph_"
+
std
::
to_string
(
kernel_graph
->
graph_id
())
+
".ir"
;
save_graphs_path
+
"/"
+
"hwopt_d_end"
+
"_graph_"
+
std
::
to_string
(
kernel_graph
->
graph_id
())
+
".ir"
;
DumpIR
(
file_path
,
kernel_graph
,
true
);
DumpIR
(
file_path
,
kernel_graph
,
true
);
DumpIRProto
(
kernel_graph
,
"after_hwopt_"
+
std
::
to_string
(
kernel_graph
->
graph_id
()));
DumpIRProto
(
kernel_graph
,
"after_hwopt_"
+
std
::
to_string
(
kernel_graph
->
graph_id
()));
}
}
// buffer fusion
AscendBackendUBFusionOptimization
(
kernel_graph
);
}
}
void
AscendBackendUBFusionOptimization
(
const
std
::
shared_ptr
<
session
::
KernelGraph
>
&
kernel_graph
)
{
void
AscendBackendUBFusionOptimization
(
const
std
::
shared_ptr
<
session
::
KernelGraph
>
&
kernel_graph
)
{
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.cc
已删除
100644 → 0
浏览文件 @
aeffccb7
此差异已折叠。
点击以展开。
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/buffer_fusion.h
已删除
100644 → 0
浏览文件 @
aeffccb7
/**
* Copyright 2019 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_BUFFER_FUSION_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_BUFFER_FUSION_H_
#include <unordered_map>
#include <unordered_set>
#include <vector>
#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
{
struct
BufferFusionInfo_t
{
std
::
vector
<
AnfNodePtr
>
anf_nodes
;
std
::
vector
<
AnfNodePtr
>
inputs_list
;
std
::
vector
<
AnfNodePtr
>
outputs_list
;
kernel
::
KernelBuildInfoPtr
kernel_build_info
;
};
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
class
BufferFusion
:
public
Pass
{
public:
BufferFusion
()
:
Pass
(
"buffer_fusion"
)
{}
~
BufferFusion
()
override
=
default
;
bool
Run
(
const
FuncGraphPtr
&
graph
)
override
;
private:
void
SetRecordFusionId
(
const
std
::
unordered_set
<
AnfNodePtr
>
&
record
);
void
MatchConvBnreduce
(
const
CNodePtr
&
cnode
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
MatchBnupdateRelu
(
const
CNodePtr
&
cnode
,
const
AnfNodePtr
&
relu_input
,
const
session
::
KernelGraph
&
kernel_graph
,
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
MatchMatmulEltwise
(
const
CNodePtr
&
cnode
,
const
AnfNodePtr
&
relu_input
,
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
MatchOpNamePattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
MatchFusionTypePattern
(
const
session
::
KernelGraph
&
kernel_graph
,
FusedNodeRecord
*
candidate_fusion
);
void
GetBufferFusionInfo
(
session
::
KernelGraph
*
kernel_graph
,
std
::
unordered_map
<
int32_t
,
BufferFusionInfo_t
>
*
buffer_fusion_infos
)
const
;
bool
ReplaceFusionOp
(
std
::
unordered_map
<
int32_t
,
BufferFusionInfo_t
>
*
buffer_fusion_infos
,
int32_t
fusion_id
,
const
kernel
::
KernelModPtr
&
kernel_ptr
,
session
::
KernelGraph
*
kernel_graph
)
const
;
bool
MatchBufferFusionPattern
(
const
session
::
KernelGraph
&
kernel_graph
);
bool
FuseBufferFusionPattern
(
session
::
KernelGraph
*
kernel_graph
)
const
;
FusionIdAllocator
fusion_id_allocator
;
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_BUFFER_FUSION_BUFFER_FUSION_H_
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/fusion_base_pass.h
浏览文件 @
24e53879
...
@@ -37,6 +37,13 @@ const int8_t ELTWISE_USE = 1;
...
@@ -37,6 +37,13 @@ const int8_t ELTWISE_USE = 1;
const
int8_t
MAX_ELTWISE_SIZE
=
6
;
const
int8_t
MAX_ELTWISE_SIZE
=
6
;
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
using
FusedNodeRecord
=
std
::
vector
<
std
::
unordered_set
<
AnfNodePtr
>>
;
struct
BufferFusionInfo_t
{
std
::
vector
<
AnfNodePtr
>
anf_nodes
;
std
::
vector
<
AnfNodePtr
>
inputs_list
;
std
::
vector
<
AnfNodePtr
>
outputs_list
;
kernel
::
KernelBuildInfoPtr
kernel_build_info
;
};
class
FusionBasePass
:
public
Pass
{
class
FusionBasePass
:
public
Pass
{
public:
public:
FusionBasePass
(
const
std
::
string
&
name
,
FusionIdAllocatorPtr
idAllocator
)
FusionBasePass
(
const
std
::
string
&
name
,
FusionIdAllocatorPtr
idAllocator
)
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc
浏览文件 @
24e53879
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
*/
*/
#include "pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h"
#include <vector>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_set>
#include <memory>
#include <memory>
#include <string>
#include <string>
...
@@ -51,7 +52,9 @@ void ReduceEltwiseFusionPass::MatchReduceEltwise(const CNodePtr &cnode, const se
...
@@ -51,7 +52,9 @@ void ReduceEltwiseFusionPass::MatchReduceEltwise(const CNodePtr &cnode, const se
if
(
AnfAlgo
::
GetKernelType
(
eltwise_input
)
==
KernelType
::
TBE_KERNEL
&&
if
(
AnfAlgo
::
GetKernelType
(
eltwise_input
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
eltwise_input
)
==
kernel
::
FusionType
::
COMMREDUCE
)
{
AnfAlgo
::
GetFusionType
(
eltwise_input
)
==
kernel
::
FusionType
::
COMMREDUCE
)
{
(
void
)
record
.
insert
(
eltwise_input
);
(
void
)
record
.
insert
(
eltwise_input
);
auto
previous_eltwise_input
=
cnode
->
input
(
1
);
auto
previous_input_cnode
=
eltwise_input
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
previous_input_cnode
);
auto
previous_eltwise_input
=
previous_input_cnode
->
input
(
1
);
auto
previous_size
=
record
.
size
();
auto
previous_size
=
record
.
size
();
while
(
CheckEltWiseNode
(
manager
.
get
(),
previous_eltwise_input
))
{
while
(
CheckEltWiseNode
(
manager
.
get
(),
previous_eltwise_input
))
{
(
void
)
record
.
insert
(
previous_eltwise_input
);
(
void
)
record
.
insert
(
previous_eltwise_input
);
...
@@ -71,6 +74,7 @@ void ReduceEltwiseFusionPass::MatchSingleFusionPattern(const session::KernelGrap
...
@@ -71,6 +74,7 @@ void ReduceEltwiseFusionPass::MatchSingleFusionPattern(const session::KernelGrap
FusedNodeRecord
*
candidate_fusion
)
{
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
std
::
reverse
(
node_list
.
begin
(),
node_list
.
end
());
for
(
auto
&
node
:
node_list
)
{
for
(
auto
&
node
:
node_list
)
{
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc
浏览文件 @
24e53879
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
*/
*/
#include "pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h"
#include <vector>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_set>
#include <memory>
#include <memory>
#include <string>
#include <string>
...
@@ -51,7 +52,9 @@ void SegmentEltwiseFusionPass::MatchSegmentEltwise(const CNodePtr &cnode, const
...
@@ -51,7 +52,9 @@ void SegmentEltwiseFusionPass::MatchSegmentEltwise(const CNodePtr &cnode, const
if
(
AnfAlgo
::
GetKernelType
(
eltwise_input
)
==
KernelType
::
TBE_KERNEL
&&
if
(
AnfAlgo
::
GetKernelType
(
eltwise_input
)
==
KernelType
::
TBE_KERNEL
&&
AnfAlgo
::
GetFusionType
(
eltwise_input
)
==
kernel
::
FusionType
::
SEGMENT
)
{
AnfAlgo
::
GetFusionType
(
eltwise_input
)
==
kernel
::
FusionType
::
SEGMENT
)
{
(
void
)
record
.
insert
(
eltwise_input
);
(
void
)
record
.
insert
(
eltwise_input
);
auto
previous_eltwise_input
=
cnode
->
input
(
1
);
auto
previous_input_cnode
=
eltwise_input
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
previous_input_cnode
);
auto
previous_eltwise_input
=
previous_input_cnode
->
input
(
1
);
auto
previous_size
=
record
.
size
();
auto
previous_size
=
record
.
size
();
while
(
CheckEltWiseNode
(
manager
.
get
(),
previous_eltwise_input
))
{
while
(
CheckEltWiseNode
(
manager
.
get
(),
previous_eltwise_input
))
{
(
void
)
record
.
insert
(
previous_eltwise_input
);
(
void
)
record
.
insert
(
previous_eltwise_input
);
...
@@ -71,6 +74,7 @@ void SegmentEltwiseFusionPass::MatchSingleFusionPattern(const session::KernelGra
...
@@ -71,6 +74,7 @@ void SegmentEltwiseFusionPass::MatchSingleFusionPattern(const session::KernelGra
FusedNodeRecord
*
candidate_fusion
)
{
FusedNodeRecord
*
candidate_fusion
)
{
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
MS_EXCEPTION_IF_NULL
(
candidate_fusion
);
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
std
::
vector
<
AnfNodePtr
>
node_list
=
TopoSort
(
kernel_graph
.
get_return
());
std
::
reverse
(
node_list
.
begin
(),
node_list
.
end
());
for
(
auto
&
node
:
node_list
)
{
for
(
auto
&
node
:
node_list
)
{
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
node
)
||
fusion_id_allocator
->
HasFusionIdAttr
(
node
)
||
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
AnfAlgo
::
CheckPrimitiveType
(
node
,
prim
::
kPrimReturn
))
{
...
...
mindspore/ccsrc/pre_activate/ascend/buffer_fusion/ub_pattern_fusion.h
浏览文件 @
24e53879
...
@@ -19,13 +19,13 @@
...
@@ -19,13 +19,13 @@
#include <unordered_set>
#include <unordered_set>
#include <vector>
#include <vector>
#include "pre_activate/ascend/buffer_fusion/fusion_base_pass.h"
#include "ir/anf.h"
#include "ir/anf.h"
#include "pre_activate/common/pass.h"
#include "pre_activate/common/pass.h"
#include "pre_activate/common/fusion_id_allocator.h"
#include "pre_activate/common/fusion_id_allocator.h"
#include "device/kernel_info.h"
#include "device/kernel_info.h"
#include "kernel/kernel.h"
#include "kernel/kernel.h"
#include "session/kernel_graph.h"
#include "session/kernel_graph.h"
#include "pre_activate/ascend/buffer_fusion/buffer_fusion.h"
namespace
mindspore
{
namespace
mindspore
{
namespace
opt
{
namespace
opt
{
...
...
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.cc
已删除
100644 → 0
浏览文件 @
aeffccb7
/**
* 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/pass/remove_nop_nodes.h"
#include "common/utils.h"
#include "pre_activate/common/helper.h"
namespace
mindspore
{
namespace
opt
{
const
AnfNodePtr
RemoveNopNodes
::
Process
(
const
FuncGraphPtr
&
,
const
AnfNodePtr
&
node
,
const
EquivPtr
&
)
const
{
if
(
node
==
nullptr
||
!
node
->
isa
<
CNode
>
())
{
return
nullptr
;
}
CNodePtr
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
!
IsNopNode
(
node
))
{
return
nullptr
;
}
return
cnode
->
input
(
1
);
}
}
// namespace opt
}
// namespace mindspore
mindspore/ccsrc/pre_activate/pass/remove_nop_nodes.h
已删除
100644 → 0
浏览文件 @
aeffccb7
/**
* 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_PASS_REMOVE_NOP_NODES_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_PASS_REMOVE_NOP_NODES_H_
#include "ir/anf.h"
#include "pre_activate/common/optimizer.h"
namespace
mindspore
{
namespace
opt
{
class
RemoveNopNodes
:
public
PatternProcessPass
{
public:
explicit
RemoveNopNodes
(
bool
multigraph
=
true
)
:
PatternProcessPass
(
"remove_nop_nodes"
,
multigraph
)
{}
~
RemoveNopNodes
()
override
=
default
;
const
BaseRef
DefinePattern
()
const
override
;
const
AnfNodePtr
Process
(
const
FuncGraphPtr
&
,
const
AnfNodePtr
&
,
const
EquivPtr
&
)
const
override
;
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_PASS_REMOVE_NOP_NODES_H_
tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc
浏览文件 @
24e53879
...
@@ -21,7 +21,19 @@
...
@@ -21,7 +21,19 @@
#include "device/kernel_info.h"
#include "device/kernel_info.h"
#include "pre_activate/common/optimizer.h"
#include "pre_activate/common/optimizer.h"
#include "session/anf_runtime_algorithm.h"
#include "session/anf_runtime_algorithm.h"
#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"
#include "pre_activate/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/conv_bnreduce_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/reduce_eltwise_fusion_pass.h"
#include "pre_activate/ascend/buffer_fusion/segment_eltwise_fusion_pass.h"
namespace
mindspore
{
namespace
mindspore
{
namespace
opt
{
namespace
opt
{
...
@@ -79,10 +91,13 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_1) {
...
@@ -79,10 +91,13 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_1) {
cast
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
cast
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder1
.
Build
(),
cast
.
get
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder1
.
Build
(),
cast
.
get
());
auto
fusion_id_allocator
=
std
::
make_shared
<
FusionIdAllocator
>
();
MS_EXCEPTION_IF_NULL
(
fusion_id_allocator
);
fusion_id_allocator
->
Init
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
buffer_fusion_pass
=
std
::
make_shared
<
opt
::
BufferFusion
>
(
);
pm
->
AddPass
(
std
::
make_shared
<
EltwiseFusionPass
>
(
fusion_id_allocator
)
);
pm
->
AddPass
(
buffer_fusion_pass
);
pm
->
AddPass
(
std
::
make_shared
<
UbPatternFusion
>
()
);
optimizer
->
AddPassManager
(
pm
);
optimizer
->
AddPassManager
(
pm
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
...
@@ -168,10 +183,13 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_2) {
...
@@ -168,10 +183,13 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_2) {
biasadd
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
biasadd
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder2
.
Build
(),
biasadd
.
get
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder2
.
Build
(),
biasadd
.
get
());
auto
fusion_id_allocator
=
std
::
make_shared
<
FusionIdAllocator
>
();
MS_EXCEPTION_IF_NULL
(
fusion_id_allocator
);
fusion_id_allocator
->
Init
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
buffer_fusion_pass
=
std
::
make_shared
<
opt
::
BufferFusion
>
(
);
pm
->
AddPass
(
std
::
make_shared
<
ReduceEltwiseFusionPass
>
(
fusion_id_allocator
)
);
pm
->
AddPass
(
buffer_fusion_pass
);
pm
->
AddPass
(
std
::
make_shared
<
UbPatternFusion
>
()
);
optimizer
->
AddPassManager
(
pm
);
optimizer
->
AddPassManager
(
pm
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
...
@@ -255,10 +273,13 @@ TEST_F(TestHWBufferFusion, test_tbe_reduce_eltwise_fusion) {
...
@@ -255,10 +273,13 @@ TEST_F(TestHWBufferFusion, test_tbe_reduce_eltwise_fusion) {
biasaddgrad
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
biasaddgrad
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder2
.
Build
(),
biasaddgrad
.
get
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder2
.
Build
(),
biasaddgrad
.
get
());
auto
fusion_id_allocator
=
std
::
make_shared
<
FusionIdAllocator
>
();
MS_EXCEPTION_IF_NULL
(
fusion_id_allocator
);
fusion_id_allocator
->
Init
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
buffer_fusion_pass
=
std
::
make_shared
<
opt
::
BufferFusion
>
(
);
pm
->
AddPass
(
std
::
make_shared
<
ReduceEltwiseFusionPass
>
(
fusion_id_allocator
)
);
pm
->
AddPass
(
buffer_fusion_pass
);
pm
->
AddPass
(
std
::
make_shared
<
UbPatternFusion
>
()
);
optimizer
->
AddPassManager
(
pm
);
optimizer
->
AddPassManager
(
pm
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
...
@@ -321,10 +342,13 @@ TEST_F(TestHWBufferFusion, test_tbe_matmul_eltwise_fusion) {
...
@@ -321,10 +342,13 @@ TEST_F(TestHWBufferFusion, test_tbe_matmul_eltwise_fusion) {
cast
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
cast
->
set_kernel_info
(
std
::
make_shared
<
device
::
KernelInfo
>
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder1
.
Build
(),
cast
.
get
());
AnfAlgo
::
SetSelectKernelBuildInfo
(
builder1
.
Build
(),
cast
.
get
());
auto
fusion_id_allocator
=
std
::
make_shared
<
FusionIdAllocator
>
();
MS_EXCEPTION_IF_NULL
(
fusion_id_allocator
);
fusion_id_allocator
->
Init
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
auto
buffer_fusion_pass
=
std
::
make_shared
<
opt
::
BufferFusion
>
(
);
pm
->
AddPass
(
std
::
make_shared
<
MatmulEltwiseFusionPass
>
(
fusion_id_allocator
)
);
pm
->
AddPass
(
buffer_fusion_pass
);
pm
->
AddPass
(
std
::
make_shared
<
UbPatternFusion
>
()
);
optimizer
->
AddPassManager
(
pm
);
optimizer
->
AddPassManager
(
pm
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录