Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
be60bd3d
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be60bd3d
编写于
5月 13, 2020
作者:
K
Kang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code refactoring for the static_analysis : modified Infer to Eval.
上级
168dfb25
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
74 addition
and
74 deletion
+74
-74
mindspore/ccsrc/debug/trace.cc
mindspore/ccsrc/debug/trace.cc
+6
-6
mindspore/ccsrc/debug/trace.h
mindspore/ccsrc/debug/trace.h
+6
-6
mindspore/ccsrc/pipeline/pipeline.cc
mindspore/ccsrc/pipeline/pipeline.cc
+2
-2
mindspore/ccsrc/pipeline/static_analysis/abstract_value.h
mindspore/ccsrc/pipeline/static_analysis/abstract_value.h
+1
-1
mindspore/ccsrc/pipeline/static_analysis/analysis_context.cc
mindspore/ccsrc/pipeline/static_analysis/analysis_context.cc
+1
-1
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
+14
-14
mindspore/ccsrc/pipeline/static_analysis/evaluator.h
mindspore/ccsrc/pipeline/static_analysis/evaluator.h
+12
-12
mindspore/ccsrc/pipeline/static_analysis/prim.cc
mindspore/ccsrc/pipeline/static_analysis/prim.cc
+6
-6
mindspore/ccsrc/pipeline/static_analysis/prim.h
mindspore/ccsrc/pipeline/static_analysis/prim.h
+4
-4
mindspore/ccsrc/pipeline/static_analysis/static_analysis.cc
mindspore/ccsrc/pipeline/static_analysis/static_analysis.cc
+7
-7
mindspore/ccsrc/pipeline/static_analysis/static_analysis.h
mindspore/ccsrc/pipeline/static_analysis/static_analysis.h
+2
-2
mindspore/ccsrc/pynative/pynative_execute.cc
mindspore/ccsrc/pynative/pynative_execute.cc
+1
-1
mindspore/ccsrc/utils/log_adapter.cc
mindspore/ccsrc/utils/log_adapter.cc
+2
-2
tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc
...s/ut/cpp/pipeline/static_analysis/static_analysis_test.cc
+10
-10
未找到文件。
mindspore/ccsrc/debug/trace.cc
浏览文件 @
be60bd3d
...
...
@@ -182,7 +182,7 @@ void DumpInferStack(std::ostringstream &oss) {
}
}
void
TraceGraph
Infer
()
{
void
TraceGraph
Eval
()
{
auto
&
infer_stack
=
GetCurrenGraphInferStack
();
std
::
ostringstream
oss
;
if
(
infer_stack
.
empty
())
{
...
...
@@ -296,7 +296,7 @@ void AnalyzedFuncGraphExporter::ExportFuncGraph(const std::string &filename,
ofs
.
close
();
}
void
Get
Infer
StackInfo
(
std
::
ostringstream
&
oss
)
{
void
Get
Eval
StackInfo
(
std
::
ostringstream
&
oss
)
{
MS_LOG
(
INFO
)
<<
"Get graph analysis information begin"
;
auto
stack
=
GetCNodeDebugStack
();
if
(
stack
.
empty
())
{
...
...
@@ -336,7 +336,7 @@ void GetInferStackInfo(std::ostringstream &oss) {
static
std
::
stack
<
std
::
pair
<
abstract
::
EvaluatorPtr
,
abstract
::
AnfNodeConfigPtr
>>
graph_infer_stack
;
// trace the cnode infer debug info
static
std
::
vector
<
abstract
::
AnfNodeConfigPtr
>
cnode_debug_stack
{};
void
TraceGraph
Infer
Enter
(
const
abstract
::
EvaluatorPtr
&
eval
,
const
abstract
::
AnfNodeConfigPtr
&
node
)
{
void
TraceGraph
Eval
Enter
(
const
abstract
::
EvaluatorPtr
&
eval
,
const
abstract
::
AnfNodeConfigPtr
&
node
)
{
if
(
eval
==
nullptr
)
{
MS_LOG
(
EXCEPTION
)
<<
"GraphInferEnter got null eval"
;
}
...
...
@@ -345,7 +345,7 @@ void TraceGraphInferEnter(const abstract::EvaluatorPtr &eval, const abstract::An
}
}
void
TraceGraph
Infer
Leave
(
const
abstract
::
EvaluatorPtr
&
eval
)
{
void
TraceGraph
Eval
Leave
(
const
abstract
::
EvaluatorPtr
&
eval
)
{
if
(
eval
==
nullptr
)
{
MS_LOG
(
EXCEPTION
)
<<
"GraphInferEnter got null eval"
;
}
...
...
@@ -354,9 +354,9 @@ void TraceGraphInferLeave(const abstract::EvaluatorPtr &eval) {
}
}
void
Trace
Infer
CNodeEnter
(
const
abstract
::
AnfNodeConfigPtr
&
node_cfg
)
{
cnode_debug_stack
.
push_back
(
node_cfg
);
}
void
Trace
Eval
CNodeEnter
(
const
abstract
::
AnfNodeConfigPtr
&
node_cfg
)
{
cnode_debug_stack
.
push_back
(
node_cfg
);
}
void
Trace
Infer
CNodeLeave
()
{
cnode_debug_stack
.
pop_back
();
}
void
Trace
Eval
CNodeLeave
()
{
cnode_debug_stack
.
pop_back
();
}
std
::
vector
<
abstract
::
AnfNodeConfigPtr
>
&
GetCNodeDebugStack
()
{
return
cnode_debug_stack
;
}
...
...
mindspore/ccsrc/debug/trace.h
浏览文件 @
be60bd3d
...
...
@@ -35,12 +35,12 @@ std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip = kSourceLi
std
::
string
GetDebugInfo
(
const
DebugInfoPtr
&
info
,
const
std
::
string
&
prefix
,
SourceLineTip
tip
=
kSourceLineTipNextLine
);
DebugInfoPtr
GetSourceCodeDebugInfo
(
const
DebugInfoPtr
&
info
);
void
TraceGraph
Infer
();
void
Get
Infer
StackInfo
(
std
::
ostringstream
&
oss
);
void
TraceGraph
Infer
Enter
(
const
abstract
::
EvaluatorPtr
&
eval
,
const
abstract
::
AnfNodeConfigPtr
&
node
);
void
TraceGraph
Infer
Leave
(
const
abstract
::
EvaluatorPtr
&
eval
);
void
Trace
Infer
CNodeEnter
(
const
abstract
::
AnfNodeConfigPtr
&
node_cfg
);
void
Trace
Infer
CNodeLeave
();
void
TraceGraph
Eval
();
void
Get
Eval
StackInfo
(
std
::
ostringstream
&
oss
);
void
TraceGraph
Eval
Enter
(
const
abstract
::
EvaluatorPtr
&
eval
,
const
abstract
::
AnfNodeConfigPtr
&
node
);
void
TraceGraph
Eval
Leave
(
const
abstract
::
EvaluatorPtr
&
eval
);
void
Trace
Eval
CNodeEnter
(
const
abstract
::
AnfNodeConfigPtr
&
node_cfg
);
void
Trace
Eval
CNodeLeave
();
std
::
vector
<
abstract
::
AnfNodeConfigPtr
>
&
GetCNodeDebugStack
();
std
::
stack
<
std
::
pair
<
abstract
::
EvaluatorPtr
,
abstract
::
AnfNodeConfigPtr
>>
&
GetCurrenGraphInferStack
();
std
::
string
GetAbstractStr
(
const
abstract
::
AbstractBasePtr
&
abs
);
...
...
mindspore/ccsrc/pipeline/pipeline.cc
浏览文件 @
be60bd3d
...
...
@@ -430,8 +430,8 @@ bool ExecutorPy::Compile(const py::object &obj, const py::tuple &args, const py:
}
catch
(
const
py
::
error_already_set
&
ex
)
{
// print function call stack info before release
std
::
ostringstream
oss
;
trace
::
TraceGraph
Infer
();
trace
::
Get
Infer
StackInfo
(
oss
);
trace
::
TraceGraph
Eval
();
trace
::
Get
Eval
StackInfo
(
oss
);
// call py::print to output function call stack to STDOUT, in case of output the log to file, the user can see
// these info from screen, no need to open log file to find these info
py
::
print
(
oss
.
str
());
...
...
mindspore/ccsrc/pipeline/static_analysis/abstract_value.h
浏览文件 @
be60bd3d
...
...
@@ -38,7 +38,7 @@ namespace abstract {
class
AbstractBase
;
using
AbstractBasePtrList
=
std
::
vector
<
AbstractBasePtr
>
;
// The base class for abstract value. The abstract value is used in
inferr
ing
// The base class for abstract value. The abstract value is used in
evaluat
ing
// to express the type, shape, and value of the real value.
class
AbstractBase
:
public
Base
{
public:
...
...
mindspore/ccsrc/pipeline/static_analysis/analysis_context.cc
浏览文件 @
be60bd3d
...
...
@@ -153,7 +153,7 @@ bool AnalysisContext::operator==(const AnalysisContext &other) const {
// free values. In order to decrease the number of cloned graphs, we add this `SpecializeKey` method to control what
// graph can be reused.
// The graph called with different SymbolicKey will be reused. The abstract of SymbolicKey parameter will be joined
// and stored in the intermediate_abstract. The joined SymbolicKey would cause Poly Code in
infer
, thus the reused
// and stored in the intermediate_abstract. The joined SymbolicKey would cause Poly Code in
eval
, thus the reused
// graph with SymbolicKey parameter should be inlined in `opt` pipeline before the next renormalize.
// The graph called with different shape should not be reused, because the combination of `shape` and `Fill` relies
// on correct shape to specialize a tensor constant.
...
...
mindspore/ccsrc/pipeline/static_analysis/evaluator.cc
浏览文件 @
be60bd3d
...
...
@@ -26,8 +26,8 @@
namespace
mindspore
{
namespace
abstract
{
namespace
{
void
Infer
EntryLogging
(
const
EvaluatorPtr
&
evaluator
,
const
AbstractBasePtrList
&
arg_spec_list
,
const
AnfNodeConfigPtr
&
out_conf
)
{
void
Eval
EntryLogging
(
const
EvaluatorPtr
&
evaluator
,
const
AbstractBasePtrList
&
arg_spec_list
,
const
AnfNodeConfigPtr
&
out_conf
)
{
MS_EXCEPTION_IF_NULL
(
evaluator
);
if
(
out_conf
!=
nullptr
)
{
MS_LOG
(
DEBUG
)
<<
"Evaluator "
<<
evaluator
->
ToString
()
<<
" run for "
<<
out_conf
->
node
()
->
scope
()
->
name
();
...
...
@@ -37,7 +37,7 @@ void InferEntryLogging(const EvaluatorPtr &evaluator, const AbstractBasePtrList
}
}
void
Infer
FailLogging
(
const
EvaluatorPtr
&
evaluator
,
const
AbstractBasePtrList
&
,
const
AnfNodeConfigPtr
&
out_conf
)
{
void
Eval
FailLogging
(
const
EvaluatorPtr
&
evaluator
,
const
AbstractBasePtrList
&
,
const
AnfNodeConfigPtr
&
out_conf
)
{
MS_EXCEPTION_IF_NULL
(
evaluator
);
if
(
out_conf
!=
nullptr
)
{
auto
node
=
out_conf
->
node
();
...
...
@@ -89,7 +89,7 @@ static std::vector<AnfNodePtr> FastShadowSort(const AnfNodePtr &ret_node) {
return
sorted_nodes
;
}
AbstractBasePtr
BaseFuncGraphEvaluator
::
Infer
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
{
AbstractBasePtr
BaseFuncGraphEvaluator
::
Eval
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
{
FuncGraphPtr
fg
=
GetFuncGraph
(
engine
,
args_spec_list
);
MS_EXCEPTION_IF_NULL
(
fg
);
std
::
size_t
nargs
=
fg
->
parameters
().
size
();
...
...
@@ -124,7 +124,7 @@ AbstractBasePtr BaseFuncGraphEvaluator::Infer(AnalysisEnginePtr engine, const Ab
}
MS_EXCEPTION_IF_NULL
(
ret_base
);
MS_LOG
(
DEBUG
)
<<
"BaseFuncGraph "
<<
fg
->
ToString
()
<<
"
infer end, inferr
ed abstract: "
<<
ret_base
->
ToString
();
MS_LOG
(
DEBUG
)
<<
"BaseFuncGraph "
<<
fg
->
ToString
()
<<
"
Eval end, evaluat
ed abstract: "
<<
ret_base
->
ToString
();
return
ret_base
;
}
...
...
@@ -155,7 +155,7 @@ AbstractBasePtrList FuncGraphEvaluator::BroadenUndeterminedArgs(const AbstractBa
<<
", context: "
<<
parent_context_
->
ToString
();
auto
last_context
=
parent_context_
->
Filter
(
func_graph_
);
if
(
last_context
&&
last_context
->
func_graph
()
==
func_graph_
)
{
MS_LOG
(
DEBUG
)
<<
"Find last
infer
context: "
<<
last_context
->
ToString
();
MS_LOG
(
DEBUG
)
<<
"Find last
eval
context: "
<<
last_context
->
ToString
();
MS_LOG
(
DEBUG
)
<<
"Current eval args: "
<<
::
mindspore
::
ToString
(
args_spec_list
);
MS_LOG
(
DEBUG
)
<<
"Last eval args: "
<<
::
mindspore
::
ToString
(
last_context
->
args_spec_list
());
// Join the last eval arguments and current arguments to check if there are loop variant.
...
...
@@ -248,26 +248,26 @@ AbstractBasePtr Evaluator::Run(AnalysisEnginePtr engine, const ConfigPtrList &ar
});
args_spec_list
=
NormalizeArgs
(
args_spec_list
);
args_spec_list
=
BroadenUndeterminedArgs
(
args_spec_list
);
trace
::
TraceGraph
Infer
Enter
(
shared_from_base
<
Evaluator
>
(),
out_conf
);
Infer
EntryLogging
(
shared_from_base
<
Evaluator
>
(),
args_spec_list
,
out_conf
);
trace
::
TraceGraph
Eval
Enter
(
shared_from_base
<
Evaluator
>
(),
out_conf
);
Eval
EntryLogging
(
shared_from_base
<
Evaluator
>
(),
args_spec_list
,
out_conf
);
MS_EXCEPTION_IF_NULL
(
cache_
);
auto
iter
=
cache_
->
find
(
args_spec_list
);
if
(
iter
==
cache_
->
end
())
{
MS_LOG
(
DEBUG
)
<<
evaluator_name
<<
" cache miss, call
Infer
()."
;
AbstractBasePtr
ret
=
Infer
(
engine
,
args_spec_list
);
MS_LOG
(
DEBUG
)
<<
evaluator_name
<<
" cache miss, call
Eval
()."
;
AbstractBasePtr
ret
=
Eval
(
engine
,
args_spec_list
);
if
(
ret
==
nullptr
)
{
Infer
FailLogging
(
shared_from_base
<
Evaluator
>
(),
args_spec_list
,
out_conf
);
Eval
FailLogging
(
shared_from_base
<
Evaluator
>
(),
args_spec_list
,
out_conf
);
MS_LOG
(
EXCEPTION
)
<<
"Evaluator "
<<
evaluator_name
<<
" result is nullptr."
;
}
MS_EXCEPTION_IF_NULL
(
ret
);
MS_LOG
(
DEBUG
)
<<
evaluator_name
<<
" set cache. return: "
<<
ret
->
ToString
()
<<
"."
;
(
*
cache_
)[
args_spec_list
]
=
ret
;
trace
::
TraceGraph
Infer
Leave
(
shared_from_base
<
Evaluator
>
());
trace
::
TraceGraph
Eval
Leave
(
shared_from_base
<
Evaluator
>
());
return
ret
;
}
else
{
MS_EXCEPTION_IF_NULL
(
iter
->
second
);
MS_LOG
(
DEBUG
)
<<
evaluator_name
<<
" cache hit. return: "
<<
iter
->
second
->
ToString
()
<<
"."
;
trace
::
TraceGraph
Infer
Leave
(
shared_from_base
<
Evaluator
>
());
trace
::
TraceGraph
Eval
Leave
(
shared_from_base
<
Evaluator
>
());
return
iter
->
second
;
}
}
...
...
@@ -378,7 +378,7 @@ AbstractBasePtr JEvaluator::Run(AnalysisEnginePtr engine, const ConfigPtrList &a
return
jtuple
;
}
AbstractBasePtr
VirtualEvaluator
::
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
args_spec_list
)
{
AbstractBasePtr
VirtualEvaluator
::
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
args_spec_list
)
{
if
(
args_spec_list
.
size
()
!=
args_spec_list_
.
size
())
{
MS_LOG
(
EXCEPTION
)
<<
"Arguments mismatch, parameters no: "
<<
args_spec_list_
.
size
()
<<
", arguments no: "
<<
args_spec_list
.
size
();
...
...
mindspore/ccsrc/pipeline/static_analysis/evaluator.h
浏览文件 @
be60bd3d
...
...
@@ -38,12 +38,12 @@ class Evaluator : public Base {
~
Evaluator
()
override
=
default
;
MS_DECLARE_PARENT
(
Evaluator
,
Base
);
// difference between Run() and
Infer
():
// Run() will be called with ConfigPtrList, but
Infer
() will be called with AbstractBasePtr.
// difference between Run() and
Eval
():
// Run() will be called with ConfigPtrList, but
Eval
() will be called with AbstractBasePtr.
// Run() will modify cache_ member, so it cannot marked as const;
virtual
AbstractBasePtr
Run
(
AnalysisEnginePtr
engine
,
const
ConfigPtrList
&
args_conf_list
,
AnfNodeConfigPtr
out_conf
);
virtual
AbstractBasePtr
Infer
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
=
0
;
virtual
AbstractBasePtr
Eval
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
=
0
;
virtual
AbstractBasePtrList
NormalizeArgs
(
const
AbstractBasePtrList
&
args_spec_list
)
const
{
return
args_spec_list
;
}
...
...
@@ -71,8 +71,8 @@ class PrimEvaluator : public Evaluator {
explicit
PrimEvaluator
(
const
std
::
string
&
id
)
:
Evaluator
(
id
)
{}
~
PrimEvaluator
()
override
=
default
;
MS_DECLARE_PARENT
(
PrimEvaluator
,
Evaluator
);
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
final
{
MS_LOG
(
EXCEPTION
)
<<
"
Infer
() should not be called, Run() method should be called"
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
final
{
MS_LOG
(
EXCEPTION
)
<<
"
Eval
() should not be called, Run() method should be called"
;
}
};
...
...
@@ -113,7 +113,7 @@ class DummyEvaluator : public Evaluator {
DummyEvaluator
()
:
Evaluator
(
"dummy"
)
{}
~
DummyEvaluator
()
override
=
default
;
MS_DECLARE_PARENT
(
DummyEvaluator
,
Evaluator
);
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
return
nullptr
;
}
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
return
nullptr
;
}
};
// Wrap another evaluator to track a subset of uses.
...
...
@@ -139,8 +139,8 @@ class TrackedEvaluator : public Evaluator {
bound_node_
=
AnfNodeWeakPtr
(
node
);
}
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Infer
() should not be called, Run() method should be called"
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Eval
() should not be called, Run() method should be called"
;
}
AbstractBasePtr
Run
(
AnalysisEnginePtr
engine
,
const
ConfigPtrList
&
args_conf_list
,
AnfNodeConfigPtr
out_conf
)
override
;
...
...
@@ -158,7 +158,7 @@ class BaseFuncGraphEvaluator : public Evaluator {
~
BaseFuncGraphEvaluator
()
override
=
default
;
MS_DECLARE_PARENT
(
BaseFuncGraphEvaluator
,
Evaluator
);
AbstractBasePtr
Infer
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
override
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
override
;
virtual
FuncGraphPtr
GetFuncGraph
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
=
0
;
...
...
@@ -238,7 +238,7 @@ class PartialAppEvaluator : public Evaluator {
}
bound_node_
=
AnfNodeWeakPtr
(
node
);
}
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"Should not be called, Run() method should be called"
;
}
...
...
@@ -258,7 +258,7 @@ class VirtualEvaluator : public Evaluator {
~
VirtualEvaluator
()
override
=
default
;
MS_DECLARE_PARENT
(
VirtualEvaluator
,
Evaluator
);
AbstractBasePtr
Infer
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
override
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
engine
,
const
AbstractBasePtrList
&
args_spec_list
)
override
;
std
::
string
ToString
()
const
override
{
return
identifier_
;
}
private:
...
...
@@ -285,7 +285,7 @@ class JEvaluator : public Evaluator {
}
bound_node_
=
AnfNodeWeakPtr
(
node
);
}
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"Should not be called, Run() method should be called"
;
}
AbstractBasePtr
Run
(
AnalysisEnginePtr
engine
,
const
ConfigPtrList
&
args_conf_list
,
...
...
mindspore/ccsrc/pipeline/static_analysis/prim.cc
浏览文件 @
be60bd3d
...
...
@@ -470,16 +470,16 @@ AbstractBasePtr UniformPrimEvaluator::EvalPrim(const AnalysisEnginePtr &, const
}
}
ValuePtr
inferr
ed_value
=
RunImpl
(
value_list
);
if
(
!
(
*
inferr
ed_value
==
*
kAnyValue
))
{
ret_value_type
=
inferr
ed_value
->
type
();
ValuePtr
evaluat
ed_value
=
RunImpl
(
value_list
);
if
(
!
(
*
evaluat
ed_value
==
*
kAnyValue
))
{
ret_value_type
=
evaluat
ed_value
->
type
();
}
// for comparison primitives , return type shall have be specified to be bool.
if
(
specify_out_type_
!=
nullptr
)
{
ret_value_type
=
specify_out_type_
;
}
AbstractScalarPtr
abs_base
=
std
::
make_shared
<
AbstractScalar
>
(
inferr
ed_value
,
ret_value_type
);
AbstractScalarPtr
abs_base
=
std
::
make_shared
<
AbstractScalar
>
(
evaluat
ed_value
,
ret_value_type
);
return
abs_base
;
}
...
...
@@ -997,8 +997,8 @@ class PartialEvaluator : public Evaluator {
return
ret
;
}
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Infer
() should not be called, Run() method should be called"
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Eval
() should not be called, Run() method should be called"
;
}
AbstractBasePtr
HandleDoSignature
(
const
AnalysisEnginePtr
&
engine
,
const
ValuePtr
&
signature_value
,
...
...
mindspore/ccsrc/pipeline/static_analysis/prim.h
浏览文件 @
be60bd3d
...
...
@@ -79,8 +79,8 @@ class DoSignatureEvaluator : public Evaluator {
AbstractBasePtr
Run
(
AnalysisEnginePtr
engine
,
const
ConfigPtrList
&
argrefs
,
AnfNodeConfigPtr
out_config
=
nullptr
)
override
;
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Infer
() should not be called, Run() method should be called"
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Eval
() should not be called, Run() method should be called"
;
}
private:
...
...
@@ -94,8 +94,8 @@ class UnpackGraphEvaluator : public Evaluator {
AbstractBasePtr
Run
(
AnalysisEnginePtr
engine
,
const
ConfigPtrList
&
argrefs
,
AnfNodeConfigPtr
out_config
=
nullptr
)
override
;
AbstractBasePtr
Infer
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Infer
() should not be called, Run() method should be called"
;
AbstractBasePtr
Eval
(
AnalysisEnginePtr
,
const
AbstractBasePtrList
&
)
override
{
MS_LOG
(
EXCEPTION
)
<<
"
Eval
() should not be called, Run() method should be called"
;
}
private:
...
...
mindspore/ccsrc/pipeline/static_analysis/static_analysis.cc
浏览文件 @
be60bd3d
...
...
@@ -183,11 +183,11 @@ AbstractBasePtr AnalysisEngine::Eval(const AnfNodeConfigPtr &conf) {
ret_abstract
=
EvalValueNode
(
value_node
,
conf
);
}
else
if
(
node
->
isa
<
CNode
>
())
{
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
trace
::
Trace
Infer
CNodeEnter
(
conf
);
ret_abstract
=
Infer
CNode
(
cnode
,
conf
);
trace
::
Trace
Infer
CNodeLeave
();
trace
::
Trace
Eval
CNodeEnter
(
conf
);
ret_abstract
=
Eval
CNode
(
cnode
,
conf
);
trace
::
Trace
Eval
CNodeLeave
();
}
else
{
MS_LOG
(
EXCEPTION
)
<<
"Illegal AnfNode for
inferr
ing, "
<<
node
->
DebugString
()
MS_LOG
(
EXCEPTION
)
<<
"Illegal AnfNode for
evaluat
ing, "
<<
node
->
DebugString
()
<<
". NodeInfo: "
<<
trace
::
GetDebugInfo
(
node
->
debug_info
());
}
...
...
@@ -208,7 +208,7 @@ AbstractBasePtr AnalysisEngine::EvalValueNode(const ValueNodePtr &value_node, co
return
ToAbstract
(
value_node
->
value
(),
conf
->
context
(),
conf
);
}
AbstractBasePtr
AnalysisEngine
::
Infer
CNode
(
const
CNodePtr
&
cnode
,
const
AnfNodeConfigPtr
&
conf
)
{
AbstractBasePtr
AnalysisEngine
::
Eval
CNode
(
const
CNodePtr
&
cnode
,
const
AnfNodeConfigPtr
&
conf
)
{
MS_EXCEPTION_IF_NULL
(
conf
);
MS_EXCEPTION_IF_NULL
(
cnode
);
auto
&
inputs
=
cnode
->
inputs
();
...
...
@@ -496,7 +496,7 @@ AbstractBasePtr AnalysisEngine::ExecuteMultipleEvaluators(const std::vector<Eval
auto
current_inf
=
std
::
make_pair
(
eval
,
args_spec_list
);
MS_LOG
(
DEBUG
)
<<
"Check Evaluator "
<<
eval
->
ToString
();
// If current evaluator is under tracing, then skip current evaluator to avoid recursively
inferr
ing.
// If current evaluator is under tracing, then skip current evaluator to avoid recursively
evaluat
ing.
auto
it
=
std
::
find
(
eval_trace_
.
rbegin
(),
eval_trace_
.
rend
(),
current_inf
);
if
(
it
==
eval_trace_
.
rend
())
{
eval_trace_
.
push_back
(
current_inf
);
...
...
@@ -607,7 +607,7 @@ AbstractBasePtr FromValueInside(const ValuePtr &value, bool broaden) {
return
a
;
}
AbstractBasePtr
Infer
OnePrim
(
const
PrimitivePtr
&
primitive
,
const
AbstractBasePtrList
&
arg_specs
)
{
AbstractBasePtr
Eval
OnePrim
(
const
PrimitivePtr
&
primitive
,
const
AbstractBasePtrList
&
arg_specs
)
{
auto
evaluator
=
GetPrimEvaluator
(
primitive
,
nullptr
);
MS_EXCEPTION_IF_NULL
(
evaluator
);
if
(
!
evaluator
->
isa
<
TrivialPrimEvaluator
>
())
{
...
...
mindspore/ccsrc/pipeline/static_analysis/static_analysis.h
浏览文件 @
be60bd3d
...
...
@@ -165,7 +165,7 @@ class AnalysisEngine : public std::enable_shared_from_this<AnalysisEngine> {
EvaluatorPtr
GetEvaluatorFor
(
const
AbstractFunctionPtr
&
fn
);
AbstractBasePtr
EvalValueNode
(
const
ValueNodePtr
&
value_node
,
const
AnfNodeConfigPtr
&
conf
);
AbstractBasePtr
Infer
CNode
(
const
CNodePtr
&
cnode
,
const
AnfNodeConfigPtr
&
conf
);
AbstractBasePtr
Eval
CNode
(
const
CNodePtr
&
cnode
,
const
AnfNodeConfigPtr
&
conf
);
// Infer the result of fn(args).
AbstractBasePtr
Execute
(
const
AbstractFunctionPtr
&
fn
,
const
AbstractBasePtrList
&
args_spec_list
);
void
Clear
();
...
...
@@ -244,7 +244,7 @@ AbstractBasePtr FromValue(const T &value, bool broaden = false) {
return
FromValueInside
(
MakeValue
(
value
),
broaden
);
}
AbstractBasePtr
Infer
OnePrim
(
const
PrimitivePtr
&
p
,
const
AbstractBasePtrList
&
arg_specs
);
AbstractBasePtr
Eval
OnePrim
(
const
PrimitivePtr
&
p
,
const
AbstractBasePtrList
&
arg_specs
);
}
// namespace abstract
}
// namespace mindspore
...
...
mindspore/ccsrc/pynative/pynative_execute.cc
浏览文件 @
be60bd3d
...
...
@@ -116,7 +116,7 @@ void PynativeInfer(const PrimitivePyPtr &prim, const py::tuple &py_args, OpExecI
args_spec_list
.
emplace_back
(
abstract
::
FromValueInside
(
input_value
,
false
));
}
}
AbstractBasePtr
infer_res
=
Infer
OnePrim
(
prim
,
args_spec_list
);
AbstractBasePtr
infer_res
=
Eval
OnePrim
(
prim
,
args_spec_list
);
op_exec_info
->
abstract
=
infer_res
;
}
...
...
mindspore/ccsrc/utils/log_adapter.cc
浏览文件 @
be60bd3d
...
...
@@ -216,8 +216,8 @@ void LogWriter::operator^(const LogStream &stream) const {
}
oss
<<
msg
.
str
();
trace
::
TraceGraph
Infer
();
trace
::
Get
Infer
StackInfo
(
oss
);
trace
::
TraceGraph
Eval
();
trace
::
Get
Eval
StackInfo
(
oss
);
if
(
exception_type_
==
IndexError
)
{
throw
pybind11
::
index_error
(
oss
.
str
());
...
...
tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc
浏览文件 @
be60bd3d
...
...
@@ -396,9 +396,9 @@ TEST_F(TestInferUniform, test_inferred_scalar_add) {
}
class
Test
Infer
OnePrim
:
public
UT
::
Common
{
class
Test
Eval
OnePrim
:
public
UT
::
Common
{
public:
Test
Infer
OnePrim
()
:
getPyFun
(
"gtest_input.pipeline.infer.infer_test"
,
true
),
engine_
(
nullptr
)
{}
Test
Eval
OnePrim
()
:
getPyFun
(
"gtest_input.pipeline.infer.infer_test"
,
true
),
engine_
(
nullptr
)
{}
void
SetUp
();
void
TearDown
();
...
...
@@ -406,37 +406,37 @@ class TestInferOnePrim : public UT::Common {
AnalysisEnginePtr
engine_
;
};
void
Test
Infer
OnePrim
::
SetUp
()
{
engine_
=
SetupAnalysisEngineStub
();
}
void
Test
Eval
OnePrim
::
SetUp
()
{
engine_
=
SetupAnalysisEngineStub
();
}
void
Test
Infer
OnePrim
::
TearDown
()
{
void
Test
Eval
OnePrim
::
TearDown
()
{
// destroy resource
}
TEST_F
(
Test
Infer
OnePrim
,
test_scalar_add
)
{
TEST_F
(
Test
Eval
OnePrim
,
test_scalar_add
)
{
double
x1
=
1.1
;
double
x2
=
1.1
;
double
x3
=
2.2
;
AbstractBasePtr
base1
=
FromValue
(
x1
,
false
);
AbstractBasePtr
base2
=
FromValue
(
x2
,
false
);
AbstractBasePtrList
base_list
=
{
base1
,
base2
};
auto
res
=
Infer
OnePrim
(
std
::
make_shared
<
Primitive
>
(
"scalar_add"
),
base_list
);
auto
res
=
Eval
OnePrim
(
std
::
make_shared
<
Primitive
>
(
"scalar_add"
),
base_list
);
MS_LOG
(
INFO
)
<<
"result spec: "
<<
res
->
ToString
();
AbstractBasePtr
exp
=
FromValue
(
x3
,
false
);
MS_LOG
(
INFO
)
<<
"result exp: "
<<
exp
->
ToString
();
ASSERT_EQ
(
*
res
,
*
exp
);
}
class
TestGraph
Infer
:
public
UT
::
Common
{
class
TestGraph
Eval
:
public
UT
::
Common
{
public:
TestGraph
Infer
()
:
getPyFun
(
"gtest_input.pipeline.infer.infer_test"
,
true
){};
TestGraph
Eval
()
:
getPyFun
(
"gtest_input.pipeline.infer.infer_test"
,
true
){};
void
SetUp
();
void
TearDown
();
AnalysisEnginePtr
engine_
;
UT
::
PyFuncGraphFetcher
getPyFun
;
};
void
TestGraph
Infer
::
SetUp
()
{
engine_
=
SetupAnalysisEngine
();
}
void
TestGraph
Eval
::
SetUp
()
{
engine_
=
SetupAnalysisEngine
();
}
void
TestGraph
Infer
::
TearDown
()
{
void
TestGraph
Eval
::
TearDown
()
{
// destroy resource
engine_
->
ClearEvaluatorCache
();
parse
::
data_converter
::
ClearObjectCache
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录