Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
b3f91a4f
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,发现更多精彩内容 >>
提交
b3f91a4f
编写于
6月 19, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2295 Optimization for ad
Merge pull request !2295 from Kang/master
上级
91aa1df9
a0d65152
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
60 addition
and
16 deletion
+60
-16
mindspore/ccsrc/ir/primitive_base.h
mindspore/ccsrc/ir/primitive_base.h
+4
-1
mindspore/ccsrc/optimizer/ad/dfunctor.cc
mindspore/ccsrc/optimizer/ad/dfunctor.cc
+4
-4
mindspore/ccsrc/optimizer/ad/dfunctor.h
mindspore/ccsrc/optimizer/ad/dfunctor.h
+29
-3
mindspore/ccsrc/optimizer/ad/grad.cc
mindspore/ccsrc/optimizer/ad/grad.cc
+1
-1
mindspore/ccsrc/optimizer/ad/kprim.cc
mindspore/ccsrc/optimizer/ad/kprim.cc
+2
-2
mindspore/ccsrc/optimizer/irpass.h
mindspore/ccsrc/optimizer/irpass.h
+20
-5
未找到文件。
mindspore/ccsrc/ir/primitive_base.h
浏览文件 @
b3f91a4f
...
...
@@ -141,7 +141,10 @@ struct PrimitiveEqual {
};
struct
PrimitiveHasher
{
std
::
size_t
operator
()(
PrimitivePtr
const
&
prim
)
const
{
return
prim
->
Hash
();
}
std
::
size_t
operator
()(
PrimitivePtr
const
&
prim
)
const
{
MS_EXCEPTION_IF_NULL
(
prim
);
return
prim
->
Hash
();
}
};
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_IR_PRIMITIVE_BASE_H_
mindspore/ccsrc/optimizer/ad/dfunctor.cc
浏览文件 @
b3f91a4f
...
...
@@ -54,8 +54,8 @@ DFunctor::DFunctor(const FuncGraphPtr &primal_graph, const pipeline::ResourceBas
dout_
=
tape_
->
add_parameter
();
}
void
DFunctor
::
Init
(
const
DFunctorPtr
&
functor
,
bool
is_top
)
{
func_graph_to_functor_
[
primal_graph_
]
=
functor
;
void
DFunctor
::
Init
(
bool
is_top
)
{
func_graph_to_functor_
[
primal_graph_
]
=
shared_from_this
()
;
is_top_
=
is_top
;
if
(
is_top
)
{
scope_
=
primal_graph_
->
scope
();
...
...
@@ -371,7 +371,7 @@ FuncGraphPtr DFunctor::KUserDefined(const FuncGraphPtr &primal) {
primal
->
set_flags
(
FUNC_GRAPH_FLAG_DEFER_INLINE
,
false
);
auto
functor
=
std
::
make_shared
<
DFunctor
>
(
primal
,
resources_
);
functor
->
Init
(
functor
);
functor
->
Init
();
functor
->
k_graph_
=
fg
;
return
fg
;
...
...
@@ -394,7 +394,7 @@ AnfNodePtr DFunctor::MapToK(const FuncGraphPtr &primal) {
}
auto
functor
=
std
::
make_shared
<
DFunctor
>
(
primal
,
resources_
);
functor
->
Init
(
functor
);
functor
->
Init
();
functor
->
MapObject
();
functor
->
MapMorphism
();
...
...
mindspore/ccsrc/optimizer/ad/dfunctor.h
浏览文件 @
b3f91a4f
...
...
@@ -35,14 +35,40 @@
namespace
mindspore
{
namespace
ad
{
using
Registry
=
std
::
unordered_map
<
PrimitivePtr
,
FuncGraphPtr
>
;
struct
PrimitiveTotalEqual
{
bool
operator
()(
PrimitivePtr
const
&
t1
,
PrimitivePtr
const
&
t2
)
const
{
if
(
t1
->
name
()
!=
t2
->
name
())
{
return
false
;
}
auto
const
&
attrs1
=
t1
->
attrs
();
auto
const
&
attrs2
=
t2
->
attrs
();
if
(
attrs1
.
size
()
!=
attrs2
.
size
())
{
return
false
;
}
for
(
auto
&
attr
:
attrs1
)
{
if
(
!
t2
->
HasAttr
(
attr
.
first
))
{
return
false
;
}
if
(
!
(
*
(
attr
.
second
)
==
*
(
t2
->
GetAttr
(
attr
.
first
))))
{
return
false
;
}
}
return
true
;
}
};
using
Registry
=
std
::
unordered_map
<
PrimitivePtr
,
FuncGraphPtr
,
PrimitiveHasher
,
PrimitiveTotalEqual
>
;
class
KPrim
;
extern
KPrim
g_k_prims
;
class
DFunctor
;
using
DFunctorPtr
=
std
::
shared_ptr
<
DFunctor
>
;
// D Functor's rules to map closure object and morphisms.
class
DFunctor
{
class
DFunctor
:
public
std
::
enable_shared_from_this
<
DFunctor
>
{
public:
DFunctor
(
const
FuncGraphPtr
&
primal_graph
,
const
pipeline
::
ResourceBasePtr
&
resources
);
~
DFunctor
()
=
default
;
...
...
@@ -54,7 +80,7 @@ class DFunctor {
// Construct user defined k object.
FuncGraphPtr
KUserDefined
(
const
FuncGraphPtr
&
primal
);
// Register functor objects to form a global view.
void
Init
(
const
DFunctorPtr
&
functor
,
bool
is_top
=
false
);
void
Init
(
bool
is_top
=
false
);
bool
IsInScope
(
const
AnfNodePtr
&
node
);
// Clear resources.
...
...
mindspore/ccsrc/optimizer/ad/grad.cc
浏览文件 @
b3f91a4f
...
...
@@ -51,7 +51,7 @@ FuncGraphPtr Grad(const FuncGraphPtr &func_graph, const pipeline::ResourceBasePt
}
return
user_defined
;
}
f
->
Init
(
f
,
is_top
);
f
->
Init
(
is_top
);
f
->
MapObject
();
f
->
MapMorphism
();
auto
ret
=
f
->
k_graph
();
...
...
mindspore/ccsrc/optimizer/ad/kprim.cc
浏览文件 @
b3f91a4f
...
...
@@ -82,7 +82,7 @@ MetaFuncGraphPtr KPrim::KMetaFuncGraph(const PrimitivePtr &prim) {
return
iter
->
second
;
}
if
(
prim
->
name
()
==
"make_tuple"
)
{
if
(
prim
->
Hash
()
==
prim
::
kPrimMakeTuple
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimMakeTuple
->
name
()
)
{
MetaFuncGraphPtr
meta
=
std
::
make_shared
<
prim
::
MakeTupleGradient
>
(
"make_tuple_gradient"
);
bprop_registry_meta_
[
prim
::
kPrimMakeTuple
]
=
meta
;
return
meta
;
...
...
@@ -111,7 +111,7 @@ FuncGraphPtr KPrim::KPrimitive(const ValueNodePtr &value_node, const pipeline::R
return
fprop
;
}
if
(
prim
->
name
()
==
"make_tuple"
)
{
if
(
prim
->
Hash
()
==
prim
::
kPrimMakeTuple
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimMakeTuple
->
name
()
)
{
return
nullptr
;
}
...
...
mindspore/ccsrc/optimizer/irpass.h
浏览文件 @
b3f91a4f
...
...
@@ -113,15 +113,30 @@ class InferenceOptPrepareLib {
// predicate functions
inline
bool
IsNode
(
const
AnfNodePtr
&
)
{
return
true
;
}
inline
bool
IsCNode
(
const
AnfNodePtr
&
node
)
{
return
node
->
isa
<
CNode
>
();
}
inline
bool
IsCNode
(
const
AnfNodePtr
&
node
)
{
if
(
node
!=
nullptr
)
{
return
node
->
isa
<
CNode
>
();
}
return
false
;
}
inline
bool
IsVNode
(
const
AnfNodePtr
&
node
)
{
return
node
->
isa
<
ValueNode
>
();
}
inline
bool
IsVNode
(
const
AnfNodePtr
&
node
)
{
if
(
node
!=
nullptr
)
{
return
node
->
isa
<
ValueNode
>
();
}
return
false
;
}
inline
bool
IsParam
(
const
AnfNodePtr
&
node
)
{
return
node
->
isa
<
Parameter
>
();
}
inline
bool
IsParam
(
const
AnfNodePtr
&
node
)
{
if
(
node
!=
nullptr
)
{
return
node
->
isa
<
Parameter
>
();
}
return
false
;
}
// Check if CNode Input 0 is Func Graph
inline
bool
IsCNodeGraph
(
const
AnfNodePtr
&
node
)
{
if
(
!
node
->
isa
<
CNode
>
())
{
if
(
node
==
nullptr
||
!
node
->
isa
<
CNode
>
())
{
return
false
;
}
...
...
@@ -131,7 +146,7 @@ inline bool IsCNodeGraph(const AnfNodePtr &node) {
// Check if CNode Input 0 is CNode
inline
bool
IsCNodeDup
(
const
AnfNodePtr
&
node
)
{
if
(
!
node
->
isa
<
CNode
>
())
{
if
(
node
==
nullptr
||
!
node
->
isa
<
CNode
>
())
{
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录