Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
066f20e7
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看板
提交
066f20e7
编写于
4月 11, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
!169 fix the method to calculate the children graph
Merge pull request !169 from xychow/fix-manager-children-issue
上级
b33687e8
99f22c5b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
61 deletion
+18
-61
mindspore/ccsrc/ir/manager.cc
mindspore/ccsrc/ir/manager.cc
+6
-32
mindspore/ccsrc/ir/manager.h
mindspore/ccsrc/ir/manager.h
+2
-12
tests/ut/python/pynative_mode/test_framstruct.py
tests/ut/python/pynative_mode/test_framstruct.py
+10
-17
未找到文件。
mindspore/ccsrc/ir/manager.cc
浏览文件 @
066f20e7
...
@@ -985,40 +985,14 @@ void ParentComputer::RealRecompute(FuncGraphPtr fg) {
...
@@ -985,40 +985,14 @@ void ParentComputer::RealRecompute(FuncGraphPtr fg) {
}
}
}
}
// children include:
// A. func graphs which use variables in fg as free variables; (child_direct_)
// B. func graphs which call func func graph in A. (all_users_)
FuncGraphSetPtr
ChildrenComputer
::
SeekChildren
(
const
FuncGraphPtr
&
fg
,
const
FuncGraphSetPtr
&
path
)
{
if
(
path
==
nullptr
||
path
->
contains
(
fg
))
{
return
std
::
make_shared
<
FuncGraphSet
>
();
}
std
::
shared_ptr
<
FuncGraphSet
>
children
=
std
::
make_shared
<
FuncGraphSet
>
();
auto
&
deps
=
*
child_direct_
;
auto
&
users
=
*
all_users_
;
MS_LOG
(
DEBUG
)
<<
""
<<
fg
->
ToString
()
<<
" start func graph dep size:"
<<
deps
[
fg
].
size
();
for
(
auto
&
dep
:
deps
[
fg
])
{
FuncGraphPtr
child
=
dep
.
first
;
children
->
add
(
child
);
path
->
add
(
child
);
MS_LOG
(
DEBUG
)
<<
"Child func graph:"
<<
fg
->
ToString
()
<<
" child "
<<
child
->
ToString
();
for
(
auto
&
user
:
users
[
child
])
{
auto
user_func_graph
=
user
.
first
;
MS_LOG
(
DEBUG
)
<<
"Func graph:"
<<
fg
->
ToString
()
<<
" user "
<<
user_func_graph
->
ToString
();
children
->
add
(
user_func_graph
);
path
->
add
(
user_func_graph
);
}
children
->
update
(
SeekChildren
(
child
,
path
));
}
(
void
)
children
->
erase
(
fg
);
MS_LOG
(
DEBUG
)
<<
"End in children: "
<<
children
->
size
();
return
children
;
}
void
ChildrenComputer
::
RealRecompute
(
FuncGraphPtr
fg
)
{
void
ChildrenComputer
::
RealRecompute
(
FuncGraphPtr
fg
)
{
MS_EXCEPTION_IF_NULL
(
manager_
);
MS_EXCEPTION_IF_NULL
(
manager_
);
child_direct_
=
&
manager_
->
func_graph_child_direct
();
auto
used_fg_total
=
manager_
->
func_graphs_used_total
(
fg
);
all_users_
=
&
manager_
->
func_graph_users
();
for
(
auto
&
used_fg
:
used_fg_total
)
{
children_analysis_
[
fg
].
update
(
SeekChildren
(
fg
));
if
(
manager_
->
parent
(
used_fg
)
==
fg
)
{
children_analysis_
[
fg
].
add
(
used_fg
);
}
}
}
}
void
ScopeComputer
::
RealRecompute
(
FuncGraphPtr
fg
)
{
void
ScopeComputer
::
RealRecompute
(
FuncGraphPtr
fg
)
{
...
...
mindspore/ccsrc/ir/manager.h
浏览文件 @
066f20e7
...
@@ -398,11 +398,8 @@ class ParentComputer final : public DepComputer {
...
@@ -398,11 +398,8 @@ class ParentComputer final : public DepComputer {
// graph's children graph except self
// graph's children graph except self
class
ChildrenComputer
final
:
public
DepComputer
{
class
ChildrenComputer
final
:
public
DepComputer
{
public:
public:
explicit
ChildrenComputer
(
const
FuncGraphManager
*
m
)
:
DepComputer
(
m
),
all_users_
(
nullptr
),
child_direct_
(
nullptr
)
{}
explicit
ChildrenComputer
(
const
FuncGraphManager
*
m
)
:
DepComputer
(
m
)
{}
~
ChildrenComputer
()
override
{
~
ChildrenComputer
()
override
=
default
;
all_users_
=
nullptr
;
child_direct_
=
nullptr
;
}
FuncGraphToFuncGraphSetMap
&
children_analysis
()
{
return
children_analysis_
;
}
FuncGraphToFuncGraphSetMap
&
children_analysis
()
{
return
children_analysis_
;
}
...
@@ -414,13 +411,6 @@ class ChildrenComputer final : public DepComputer {
...
@@ -414,13 +411,6 @@ class ChildrenComputer final : public DepComputer {
void
ExtraReset
()
override
{
children_analysis_
.
clear
();
}
void
ExtraReset
()
override
{
children_analysis_
.
clear
();
}
void
RealRecompute
(
FuncGraphPtr
fg
)
override
;
void
RealRecompute
(
FuncGraphPtr
fg
)
override
;
private:
FuncGraphSetPtr
SeekChildren
(
const
FuncGraphPtr
&
fg
,
const
FuncGraphSetPtr
&
path
=
std
::
make_shared
<
FuncGraphSet
>
());
// when SeekChildren calls itself recursively, it can access these variables by class member
// other than pass by formal parameters, it can save 2 parameters for SeekChildren().
FuncGraphToFuncGraphCounterMap
*
all_users_
;
FuncGraphToFuncGraphCounterMap
*
child_direct_
;
};
};
// graph's children graph include self
// graph's children graph include self
...
...
tests/ut/python/pynative_mode/test_framstruct.py
浏览文件 @
066f20e7
...
@@ -38,16 +38,6 @@ def setup_module(module):
...
@@ -38,16 +38,6 @@ def setup_module(module):
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
)
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
)
@
ms_function
def
refactor_fac
(
n
):
""" grad_refactor_fac """
if
n
==
0
:
return
1
return
n
*
refactor_fac
(
n
-
1
)
def
test_refactor
():
res
=
refactor_fac
(
3
)
assert
res
==
6
@
ms_function
@
ms_function
def
while_upper_bound
(
upper
):
def
while_upper_bound
(
upper
):
rval
=
2
rval
=
2
...
@@ -386,16 +376,19 @@ def test_grad_while():
...
@@ -386,16 +376,19 @@ def test_grad_while():
assert
grad_while
(
5
)
==
(
60
,)
assert
grad_while
(
5
)
==
(
60
,)
@
ms_function
@
ms_function
def
fac
(
n
):
def
fac
torial
(
n
):
""" fac """
""" fac
torial
"""
if
n
==
0
:
if
n
==
0
:
return
1
return
1
return
n
*
fac
(
n
-
1
)
return
n
*
factorial
(
n
-
1
)
def
test_factorial
():
res
=
factorial
(
3
)
assert
res
==
6
def
test_fac
():
def
test_grad_factorial
():
""" test_fac """
res
=
C
.
grad
(
factorial
)(
3
)
res
=
fac
(
4
)
assert
res
==
11
assert
res
==
24
def
_for
(
x
):
def
_for
(
x
):
""" _for """
""" _for """
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录