Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
87714b3c
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看板
提交
87714b3c
编写于
4月 10, 2020
作者:
Z
Zhang Qinghua
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the repeats of inferring and optimize the sorting routine.
Total Renormalizes: ----- 69.05010 --> 62.28941 -----
上级
268d358a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
9 deletion
+33
-9
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
+33
-9
未找到文件。
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
浏览文件 @
87714b3c
...
...
@@ -17,6 +17,7 @@
#include "pipeline/static_analysis/evaluator.h"
#include <algorithm>
#include <unordered_set>
#include "ir/func_graph_cloner.h"
#include "pipeline/static_analysis/utils.h"
...
...
@@ -61,6 +62,29 @@ AnalysisContextPtr BaseFuncGraphEvaluator::MakeContext(const AnalysisEnginePtr &
return
context
;
}
static
std
::
vector
<
AnfNodePtr
>
FastShadowSort
(
const
AnfNodePtr
&
ret_node
)
{
std
::
vector
<
AnfNodePtr
>
sorted_nodes
;
std
::
unordered_set
<
AnfNodePtr
>
checked_cnodes
;
std
::
size_t
index
=
0
;
sorted_nodes
.
emplace_back
(
ret_node
);
while
(
index
<
sorted_nodes
.
size
())
{
auto
current
=
sorted_nodes
[
index
];
index
++
;
MS_EXCEPTION_IF_NULL
(
current
);
if
(
current
->
isa
<
CNode
>
())
{
auto
&
inputs
=
current
->
cast
<
CNodePtr
>
()
->
inputs
();
for
(
auto
it
=
inputs
.
begin
();
it
!=
inputs
.
end
();
it
++
)
{
AnfNodePtr
input
=
*
it
;
if
(
input
!=
nullptr
&&
input
->
isa
<
CNode
>
()
&&
checked_cnodes
.
find
(
input
)
==
checked_cnodes
.
end
())
{
sorted_nodes
.
emplace_back
(
input
);
(
void
)
checked_cnodes
.
insert
(
input
);
}
}
}
}
return
sorted_nodes
;
}
AbstractBasePtr
BaseFuncGraphEvaluator
::
Infer
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
{
FuncGraphPtr
fg
=
GetFuncGraph
(
engine
,
args_spec_list
);
MS_EXCEPTION_IF_NULL
(
fg
);
...
...
@@ -86,20 +110,20 @@ AbstractBasePtr BaseFuncGraphEvaluator::Infer(AnalysisEnginePtr engine, const Ab
MS_LOG
(
DEBUG
)
<<
"Analysis FuncGraph begin, func graph: "
<<
fg
->
ToString
()
<<
", context: "
<<
graph_context_
->
ToString
()
<<
", return node: "
<<
func_node
->
DebugString
();
const
std
::
vector
<
AnfNodePtr
>
&
all_nodes
=
TopoSort
(
func_node
);
for
(
const
auto
&
node
:
all_nodes
)
{
AbstractBasePtr
ret_base
=
nullptr
;
std
::
vector
<
AnfNodePtr
>
nodes
=
FastShadowSort
(
func_node
);
for
(
auto
it
=
nodes
.
crbegin
();
it
!=
nodes
.
crend
();
it
++
)
{
const
auto
&
node
=
*
it
;
AnfNodeConfigPtr
node_conf
=
engine
->
MakeConfig
(
node
,
graph_context_
);
MS_LOG
(
DEBUG
)
<<
"Analysis node begin, func graph: "
<<
fg
->
ToString
()
<<
", node_conf: "
<<
node_conf
->
ToString
();
AbstractBasePtr
base
=
engine
->
GetEvaluatedValue
(
node_conf
);
ret_
base
=
engine
->
GetEvaluatedValue
(
node_conf
);
MS_LOG
(
DEBUG
)
<<
"Analysis node end, func graph: "
<<
fg
->
ToString
()
<<
", node_conf: "
<<
node_conf
->
ToString
()
<<
", abstract: "
<<
base
->
ToString
();
<<
", abstract: "
<<
ret_
base
->
ToString
();
}
AnfNodeConfigPtr
ret_conf
=
engine
->
MakeConfig
(
func_node
,
graph_context_
);
AbstractBasePtr
base
=
engine
->
GetEvaluatedValue
(
ret_conf
);
MS_EXCEPTION_IF_NULL
(
base
);
MS_LOG
(
DEBUG
)
<<
"BaseFuncGraph "
<<
fg
->
ToString
()
<<
" infer end, inferred abstract: "
<<
base
->
ToString
();
return
base
;
MS_EXCEPTION_IF_NULL
(
ret_base
);
MS_LOG
(
DEBUG
)
<<
"BaseFuncGraph "
<<
fg
->
ToString
()
<<
" infer end, inferred abstract: "
<<
ret_base
->
ToString
();
return
ret_base
;
}
AbstractBasePtrList
FuncGraphEvaluator
::
NormalizeArgs
(
const
AbstractBasePtrList
&
args_spec_list
)
const
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录