Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
f3041899
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看板
提交
f3041899
编写于
8月 18, 2020
作者:
H
huangdongrun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor bool op parsing to be consistent with pynative mode
add testcase of st
上级
c7b7af6c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
114 addition
and
19 deletion
+114
-19
mindspore/ccsrc/pipeline/jit/parse/parse.cc
mindspore/ccsrc/pipeline/jit/parse/parse.cc
+41
-7
mindspore/ccsrc/pipeline/jit/parse/parse.h
mindspore/ccsrc/pipeline/jit/parse/parse.h
+1
-1
mindspore/ops/composite/multitype_ops/logic_not_impl.py
mindspore/ops/composite/multitype_ops/logic_not_impl.py
+3
-1
tests/st/control/test_ascend_control_sink.py
tests/st/control/test_ascend_control_sink.py
+59
-2
tests/ut/python/ops/test_python_operators.py
tests/ut/python/ops/test_python_operators.py
+5
-5
tests/vm_impl/math_ops_vm_impl.py
tests/vm_impl/math_ops_vm_impl.py
+5
-3
未找到文件。
mindspore/ccsrc/pipeline/jit/parse/parse.cc
浏览文件 @
f3041899
...
...
@@ -737,8 +737,7 @@ AnfNodePtr Parser::ParseCompare(const FunctionBlockPtr &block, const py::object
return
block
->
func_graph
()
->
NewCNode
({
op_node
,
left_node
,
right_node
});
}
AnfNodePtr
Parser
::
ProcessBoolOpValueList
(
const
FunctionBlockPtr
&
block
,
const
py
::
list
&
value_list
,
const
py
::
object
&
op
)
{
AnfNodePtr
Parser
::
ProcessBoolOpValueList
(
const
FunctionBlockPtr
&
block
,
const
py
::
list
&
value_list
,
AstSubType
mode
)
{
// if there is only one bool op now
if
(
value_list
.
size
()
==
1
)
{
AnfNodePtr
first_node
=
ParseExprNode
(
block
,
value_list
[
0
]);
...
...
@@ -749,11 +748,41 @@ AnfNodePtr Parser::ProcessBoolOpValueList(const FunctionBlockPtr &block, const p
for
(
size_t
i
=
1
;
i
<
value_list
.
size
();
i
++
)
{
rest
.
append
(
value_list
[
i
]);
}
MS_EXCEPTION_IF_NULL
(
block
);
TraceManager
::
DebugTrace
(
std
::
make_shared
<
TraceIfExpTrueBranch
>
(
block
->
func_graph
()
->
debug_info
()));
FunctionBlockPtr
true_block
=
MakeFunctionBlock
(
*
this
);
TraceManager
::
EndTrace
();
TraceManager
::
DebugTrace
(
std
::
make_shared
<
TraceIfExpFalseBranch
>
(
block
->
func_graph
()
->
debug_info
()));
FunctionBlockPtr
false_block
=
MakeFunctionBlock
(
*
this
);
TraceManager
::
EndTrace
();
MakeConditionBlocks
(
block
,
true_block
,
false_block
);
FunctionBlockPtr
b1
,
b2
;
// if it is and, we need to process the rest nodes;
// if it is or, we continue to next
if
(
mode
==
AST_SUB_TYPE_AND
)
{
b1
=
true_block
;
b2
=
false_block
;
}
else
if
(
mode
==
AST_SUB_TYPE_OR
)
{
b2
=
true_block
;
b1
=
false_block
;
}
else
{
MS_LOG
(
ERROR
)
<<
"Not supported mode: "
<<
mode
;
return
nullptr
;
}
AnfNodePtr
test_node
=
ParseExprNode
(
block
,
first
);
AnfNodePtr
rest_node
=
ProcessBoolOpValueList
(
b1
,
rest
,
mode
);
b1
->
func_graph
()
->
set_output
(
rest_node
);
b2
->
func_graph
()
->
set_output
(
test_node
);
auto
cond_node
=
block
->
ForceToBoolNode
(
test_node
);
auto
switch_app
=
block
->
func_graph
()
->
NewCNode
({
NewValueNode
(
prim
::
kPrimSwitch
),
cond_node
,
NewValueNode
(
true_block
->
func_graph
()),
NewValueNode
(
false_block
->
func_graph
())});
AnfNodePtr
first_node
=
ParseExprNode
(
block
,
first
);
AnfNodePtr
rest_node
=
ProcessBoolOpValueList
(
block
,
rest
,
op
);
auto
op_node
=
block
->
MakeResolveAstOp
(
op
);
return
block
->
func_graph
()
->
NewCNode
({
op_node
,
first_node
,
rest_node
});
std
::
vector
<
AnfNodePtr
>
call_graph_nodes
{
switch_app
};
auto
switch_app_call
=
block
->
func_graph
()
->
NewCNode
(
call_graph_nodes
);
return
switch_app_call
;
}
}
...
...
@@ -761,8 +790,13 @@ AnfNodePtr Parser::ProcessBoolOpValueList(const FunctionBlockPtr &block, const p
AnfNodePtr
Parser
::
ParseBoolOp
(
const
FunctionBlockPtr
&
block
,
const
py
::
object
&
node
)
{
MS_LOG
(
DEBUG
)
<<
"Process ast BoolOp"
;
py
::
object
op_node
=
python_adapter
::
GetPyObjAttr
(
node
,
"op"
);
AstSubType
op_type
=
ast_
->
GetOpType
(
op_node
);
if
(
op_type
==
AST_SUB_TYPE_UNKNOWN
)
{
MS_LOG
(
WARNING
)
<<
"ProcessBoolOp, got unkown op type"
;
return
nullptr
;
}
py
::
list
op_values
=
python_adapter
::
GetPyObjAttr
(
node
,
"values"
);
return
ProcessBoolOpValueList
(
block
,
op_values
,
op_
nod
e
);
return
ProcessBoolOpValueList
(
block
,
op_values
,
op_
typ
e
);
}
// Process a function def
...
...
mindspore/ccsrc/pipeline/jit/parse/parse.h
浏览文件 @
f3041899
...
...
@@ -206,7 +206,7 @@ class Parser {
void
HandleAssignSubscript
(
const
FunctionBlockPtr
&
block
,
const
py
::
object
&
targ
,
const
AnfNodePtr
&
assigned_node
);
// process a bool operation value list
AnfNodePtr
ProcessBoolOpValueList
(
const
FunctionBlockPtr
&
block
,
const
py
::
list
&
value_list
,
const
py
::
object
&
op
);
AnfNodePtr
ProcessBoolOpValueList
(
const
FunctionBlockPtr
&
block
,
const
py
::
list
&
value_list
,
AstSubType
mode
);
CNodePtr
GenerateIteratorInFor
(
const
FunctionBlockPtr
&
block
,
const
pybind11
::
object
&
node
,
const
AnfNodePtr
&
op_iter
);
...
...
mindspore/ops/composite/multitype_ops/logic_not_impl.py
浏览文件 @
f3041899
...
...
@@ -45,7 +45,9 @@ def _logical_not_tensor(x):
Returns:
Tensor, Return logical not operation result of x.
"""
return
F
.
logical_not
(
x
)
if
F
.
isconstant
(
x
):
return
F
.
bool_not
(
x
.
__bool__
())
return
F
.
logical_not
(
x
.
__bool__
())
@
logical_not
.
register
(
"Tuple"
)
...
...
tests/st/control/test_ascend_control_sink.py
浏览文件 @
f3041899
...
...
@@ -61,8 +61,7 @@ class ControlSimpleIfWithAssign(nn.Cell):
class
ControlIfinIf
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
"""pass"""
def
construct
(
self
,
x
,
y
):
if
x
>
y
:
...
...
@@ -151,6 +150,40 @@ class ControlMixedWhileIf(nn.Cell):
return
out
class
AndOperation
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
self
.
reduce_sum
=
op
.
ReduceSum
()
def
construct
(
self
,
x
,
y
):
x_sum
=
self
.
reduce_sum
(
x
)
y_sum
=
self
.
reduce_sum
(
y
)
out
=
x_sum
and
y_sum
return
out
class
OrOperation
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
self
.
reduce_sum
=
op
.
ReduceSum
()
def
construct
(
self
,
x
,
y
):
x_sum
=
self
.
reduce_sum
(
x
)
y_sum
=
self
.
reduce_sum
(
y
)
out
=
x_sum
or
y_sum
return
out
class
NotOperation
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
self
.
reduce_sum
=
op
.
ReduceSum
()
def
construct
(
self
,
x
):
x_sum
=
self
.
reduce_sum
(
x
)
return
not
x_sum
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
...
...
@@ -248,3 +281,27 @@ def test_mixed_while_if():
output
=
net
(
Tensor
(
x
),
Tensor
(
y
),
Tensor
(
z
),
c2
,
c4
)
expect
=
np
.
array
(
3318
).
astype
(
np
.
int32
)
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_and_or_operation
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
([
0
,
1
]).
astype
(
np
.
float32
)
y
=
np
.
array
([
0
,
0
]).
astype
(
np
.
float32
)
net
=
AndOperation
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
))
expect
=
np
.
sum
(
x
)
and
np
.
sum
(
y
)
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
net
=
OrOperation
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
))
expect
=
np
.
sum
(
x
)
or
np
.
sum
(
y
)
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
net
=
NotOperation
()
output
=
net
(
Tensor
(
x
))
expect
=
not
np
.
sum
(
x
)
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
tests/ut/python/ops/test_python_operators.py
浏览文件 @
f3041899
...
...
@@ -103,15 +103,15 @@ class LogicalTensorOpsNet(nn.Cell):
self
.
const_true
=
Tensor
(
True
,
dtype
=
mstype
.
bool_
)
def
construct
(
self
,
x
,
y
):
ret
=
x
and
y
and
(
y
or
self
.
const_true
)
and
(
not
self
.
const_true
)
ret
=
x
and
y
and
(
y
or
self
.
const_true
)
and
(
not
y
)
return
ret
test_case_ops
=
[
(
'CompareOpsNet'
,
{
'block'
:
ComparisonOpsNet
(),
'desc_inputs'
:
[
Tensor
(
np
.
ones
([
6
,
9
,
10
])
,
dtype
=
mstype
.
float32
),
Tensor
(
np
.
zeros
([
6
,
9
,
10
])
,
dtype
=
mstype
.
float32
)]}),
'desc_inputs'
:
[
Tensor
(
1.0
,
dtype
=
mstype
.
float32
),
Tensor
(
1.0
,
dtype
=
mstype
.
float32
)]}),
(
'MathOpsNet'
,
{
'block'
:
MathOpsNet
(),
'desc_inputs'
:
[
Tensor
(
np
.
ones
([
6
,
9
,
10
]),
dtype
=
mstype
.
float32
),
...
...
@@ -126,8 +126,8 @@ test_case_ops = [
Tensor
(
np
.
zeros
([
6
,
9
,
10
]),
dtype
=
mstype
.
float32
)]}),
(
'LogicalTensorOps'
,
{
'block'
:
LogicalTensorOpsNet
(),
'desc_inputs'
:
[
Tensor
(
np
.
ones
([
6
,
9
,
10
]).
astype
(
np
.
bool_
)
,
dtype
=
mstype
.
bool_
),
Tensor
(
np
.
zeros
([
6
,
9
,
10
]).
astype
(
np
.
bool_
)
,
dtype
=
mstype
.
bool_
)]}),
'desc_inputs'
:
[
Tensor
(
True
,
dtype
=
mstype
.
bool_
),
Tensor
(
False
,
dtype
=
mstype
.
bool_
)]}),
]
test_case_lists
=
[
test_case_ops
]
...
...
tests/vm_impl/math_ops_vm_impl.py
浏览文件 @
f3041899
...
...
@@ -41,10 +41,12 @@ def vm_impl_tensor_add(self):
# pylint: disable=used-before-assignment
@
vm_impl_getters
.
register
(
P
.
LogicalNot
)
def
vm_impl_logical_not
(
self
):
x
=
x
.
asnumpy
()
out
=
vm
.
logical_not
(
x
)
return
Tensor
(
out
)
def
vm_impl
(
x
):
x
=
x
.
asnumpy
()
out
=
vm
.
logical_not
(
x
)
return
Tensor
(
out
)
return
vm_impl
@
vm_impl_getters
.
register
(
P
.
MatMul
)
def
vm_impl_mat_mul
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录