Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
6fa28139
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看板
提交
6fa28139
编写于
5月 26, 2020
作者:
Z
zhaozhenlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add op BitwiseAnd BitwiseOr BitwiseXor
上级
2eedd321
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
232 addition
and
3 deletion
+232
-3
mindspore/common/dtype.py
mindspore/common/dtype.py
+1
-0
mindspore/ops/_op_impl/tbe/__init__.py
mindspore/ops/_op_impl/tbe/__init__.py
+3
-0
mindspore/ops/_op_impl/tbe/bitwise_and.py
mindspore/ops/_op_impl/tbe/bitwise_and.py
+37
-0
mindspore/ops/_op_impl/tbe/bitwise_or.py
mindspore/ops/_op_impl/tbe/bitwise_or.py
+37
-0
mindspore/ops/_op_impl/tbe/bitwise_xor.py
mindspore/ops/_op_impl/tbe/bitwise_xor.py
+37
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+5
-2
mindspore/ops/operations/math_ops.py
mindspore/ops/operations/math_ops.py
+82
-1
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+30
-0
未找到文件。
mindspore/common/dtype.py
浏览文件 @
6fa28139
...
...
@@ -109,6 +109,7 @@ number_type = (int8,
float64
,)
int_type
=
(
int8
,
int16
,
int32
,
int64
,)
uint_type
=
(
uint8
,
uint16
,
uint32
,
uint64
)
float_type
=
(
float16
,
float32
,
float64
,)
_simple_types
=
{
...
...
mindspore/ops/_op_impl/tbe/__init__.py
浏览文件 @
6fa28139
...
...
@@ -202,3 +202,6 @@ from .scatter_add import _scatter_add_tbe
from
.atan2
import
_atan2_tbe
from
.batch_to_space_nd
import
_batch_to_space_nd_tbe
from
.space_to_batch_nd
import
_space_to_batch_nd_tbe
from
.bitwise_and
import
bitwise_and_op_info
from
.bitwise_or
import
bitwise_or_op_info
from
.bitwise_xor
import
bitwise_xor_op_info
mindspore/ops/_op_impl/tbe/bitwise_and.py
0 → 100644
浏览文件 @
6fa28139
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""BitwiseAnd op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
bitwise_and_op_info
=
TBERegOp
(
"BitwiseAnd"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"bitwise_and.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"bitwise_and"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x1"
,
False
,
"required"
,
"all"
)
\
.
input
(
1
,
"x2"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I16_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
U16_Default
,
DataType
.
U16_Default
,
DataType
.
U16_Default
)
\
.
get_op_info
()
@
op_info_register
(
bitwise_and_op_info
)
def
_bitwise_and_tbe
():
"""BitwiseAnd TBE register"""
return
mindspore/ops/_op_impl/tbe/bitwise_or.py
0 → 100644
浏览文件 @
6fa28139
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""BitwiseOr op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
bitwise_or_op_info
=
TBERegOp
(
"BitwiseOr"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"bitwise_or.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"bitwise_or"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x1"
,
False
,
"required"
,
"all"
)
\
.
input
(
1
,
"x2"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I16_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
U16_Default
,
DataType
.
U16_Default
,
DataType
.
U16_Default
)
\
.
get_op_info
()
@
op_info_register
(
bitwise_or_op_info
)
def
_bitwise_or_tbe
():
"""BitwiseOr TBE register"""
return
mindspore/ops/_op_impl/tbe/bitwise_xor.py
0 → 100644
浏览文件 @
6fa28139
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""BitwiseXor op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
bitwise_xor_op_info
=
TBERegOp
(
"BitwiseXor"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"bitwise_xor.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"bitwise_xor"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x1"
,
False
,
"required"
,
"all"
)
\
.
input
(
1
,
"x2"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I16_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
U16_Default
,
DataType
.
U16_Default
,
DataType
.
U16_Default
)
\
.
get_op_info
()
@
op_info_register
(
bitwise_xor_op_info
)
def
_bitwise_xor_tbe
():
"""BitwiseXor TBE register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
6fa28139
...
...
@@ -39,7 +39,7 @@ from .debug_ops import (ImageSummary, InsertGradientOf, HookBackward, ScalarSumm
TensorSummary
,
HistogramSummary
,
Print
)
from
.control_ops
import
ControlDepend
,
GeSwitch
,
Merge
from
.inner_ops
import
ScalarCast
from
.math_ops
import
(
Abs
,
ACos
,
AddN
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
from
.math_ops
import
(
Abs
,
ACos
,
AddN
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
BitwiseAnd
,
BitwiseOr
,
BitwiseXor
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
Cos
,
Div
,
Equal
,
EqualCount
,
Exp
,
Erf
,
Erfc
,
Floor
,
FloorDiv
,
FloorMod
,
Acosh
,
Greater
,
GreaterEqual
,
Less
,
LessEqual
,
Log
,
Log1p
,
LogicalAnd
,
...
...
@@ -266,7 +266,10 @@ __all__ = [
"ApplyCenteredRMSProp"
,
"SpaceToBatchND"
,
"BatchToSpaceND"
,
"SquareSumAll"
"SquareSumAll"
,
"BitwiseAnd"
,
"BitwiseOr"
,
"BitwiseXor"
]
__all__
.
extend
(
thor_ops
.
__all__
)
...
...
mindspore/ops/operations/math_ops.py
浏览文件 @
6fa28139
...
...
@@ -71,7 +71,7 @@ class _BinaryOp(PrimitiveWithInfer):
@
prim_attr_register
def
__init__
(
self
):
"""init _
Math
BinaryOp"""
"""init _BinaryOp"""
self
.
init_prim_io_names
(
inputs
=
[
'x'
,
'y'
],
outputs
=
[
'output'
])
def
infer_shape
(
self
,
x_shape
,
y_shape
):
...
...
@@ -93,6 +93,27 @@ class _MathBinaryOp(_BinaryOp):
return
_MathBinaryOp
.
do_infer_dtype
(
x_dtype
,
y_dtype
,
mstype
.
number_type
,
self
.
name
)
class
_BitwiseBinaryOp
(
_MathBinaryOp
):
"""
Define bitwise binary operators.
"""
@
prim_attr_register
def
__init__
(
self
):
"""init _BitwiseBinaryOp"""
self
.
init_prim_io_names
(
inputs
=
[
'x1'
,
'x2'
],
outputs
=
[
'y'
])
@
staticmethod
def
_check_bitwise_op_input_type
(
x1_type
,
x2_type
,
prim
):
args
=
{
'x1'
:
x1_type
,
'x2'
:
x2_type
}
valid_types
=
mstype
.
int_type
+
mstype
.
uint_type
validator
.
check_tensor_type_same
(
args
,
valid_types
,
prim
)
return
x1_type
def
infer_dtype
(
self
,
x1_type
,
x2_type
):
return
_BitwiseBinaryOp
.
_check_bitwise_op_input_type
(
x1_type
,
x2_type
,
self
.
name
)
class
TensorAdd
(
_MathBinaryOp
):
"""
Adds two input tensors element-wise.
...
...
@@ -2186,3 +2207,63 @@ class SquareSumAll(PrimitiveWithInfer):
validator
.
check_tensor_type_same
({
'x1_type'
:
x_type
},
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
validator
.
check_tensor_type_same
({
'x2_type'
:
y_type
},
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
return
x_type
,
y_type
class
BitwiseAnd
(
_BitwiseBinaryOp
):
"""
Returns bitwise `and` of two tensors element-wise.
Inputs:
- **input_x1** (Tensor) - The input tensor with int or uint type.
- **input_x2** (Tensor) - The input tensor with same type as the `input_x1`.
Outputs:
- **y** (Tensor) - The same type as the `input_x1`.
Examples:
>>> input_x1 = Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16)
>>> input_x2 = Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)
>>> bitwise_and = P.BitwiseAnd()
>>> bitwise_and(input_x1, input_x2)
[0, 0, 1, -1, 1, 0, 1]
"""
class
BitwiseOr
(
_BitwiseBinaryOp
):
"""
Returns bitwise `or` of two tensors element-wise.
Inputs:
- **input_x1** (Tensor) - The input tensor with int or uint type.
- **input_x2** (Tensor) - The input tensor with same type as the `input_x1`.
Outputs:
- **y** (Tensor) - The same type as the `input_x1`.
Examples:
>>> input_x1 = Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16)
>>> input_x2 = Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)
>>> bitwise_or = P.BitwiseOr()
>>> bitwise_or(input_x1, input_x2)
[0, 1, 1, -1, -1, 3, 3]
"""
class
BitwiseXor
(
_BitwiseBinaryOp
):
"""
Returns bitwise `xor` of two tensors element-wise.
Inputs:
- **input_x1** (Tensor) - The input tensor with int or uint type.
- **input_x2** (Tensor) - The input tensor with same type as the `input_x1`.
Outputs:
- **y** (Tensor) - The same type as the `input_x1`.
Examples:
>>> input_x1 = Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16)
>>> input_x2 = Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)
>>> bitwise_xor = P.BitwiseXor()
>>> bitwise_xor(input_x1, input_x2)
[0, 1, 0, 0, -2, 3, 2]
"""
tests/ut/python/ops/test_ops.py
浏览文件 @
6fa28139
...
...
@@ -242,6 +242,36 @@ class ApplyRMSNet(nn.Cell):
return
out
test_case_math_ops
=
[
(
'BitwiseAnd'
,
{
'block'
:
P
.
BitwiseAnd
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([
0
,
0
,
1
,
-
1
,
1
,
1
,
1
]),
mstype
.
int16
),
Tensor
(
np
.
array
([
0
,
1
,
1
,
-
1
,
-
1
,
2
,
3
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'BitwiseAnd_1'
,
{
'block'
:
P
.
BitwiseAnd
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
-
1
,
-
2
,
-
3
]]),
mstype
.
int16
),
Tensor
(
np
.
array
([
1
,
1
,
1
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'BitwiseOr'
,
{
'block'
:
P
.
BitwiseOr
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([
0
,
0
,
1
,
-
1
,
1
,
1
,
1
]),
mstype
.
int16
),
Tensor
(
np
.
array
([
0
,
1
,
1
,
-
1
,
-
1
,
2
,
3
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'BitwiseOr_1'
,
{
'block'
:
P
.
BitwiseOr
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
-
1
,
-
2
,
-
3
]]),
mstype
.
int16
),
Tensor
(
np
.
array
([
1
,
1
,
1
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'BitwiseXor'
,
{
'block'
:
P
.
BitwiseXor
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([
0
,
0
,
1
,
-
1
,
1
,
1
,
1
]),
mstype
.
int16
),
Tensor
(
np
.
array
([
0
,
1
,
1
,
-
1
,
-
1
,
2
,
3
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'BitwiseXor_1'
,
{
'block'
:
P
.
BitwiseXor
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
-
1
,
-
2
,
-
3
]]),
mstype
.
int16
),
Tensor
(
np
.
array
([
1
,
1
,
1
]),
mstype
.
int16
)],
'skip'
:
[
'backward'
]}),
(
'Neg'
,
{
'block'
:
P
.
Neg
(),
'desc_inputs'
:
[[
1
,
3
,
4
,
4
]],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录