support vm for space_to_depth

This commit is contained in:
jiangjinsheng 2020-05-13 15:43:05 +08:00
parent f73867222e
commit ba99cb7bcb
5 changed files with 119 additions and 2 deletions

View File

@ -164,6 +164,8 @@ from .avg_pool_grad import _avg_pool_grad_tbe
from .ones_like import _ones_like_tbe from .ones_like import _ones_like_tbe
from .batch_to_space import _batch_to_space_tbe from .batch_to_space import _batch_to_space_tbe
from .space_to_batch import _space_to_batch_tbe from .space_to_batch import _space_to_batch_tbe
from .depth_to_space import _depth_to_space_tbe
from .space_to_depth import _space_to_depth_tbe
from .floor import _floor_tbe from .floor import _floor_tbe
from .log1p import _log1p_tbe from .log1p import _log1p_tbe
from .resize_bilinear import _resize_bilinear_tbe from .resize_bilinear import _resize_bilinear_tbe

View File

@ -0,0 +1,46 @@
# 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.
# ============================================================================
"""DepthToSpace op"""
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
depth_to_space_op_info = TBERegOp("DepthToSpace") \
.fusion_type("OPAQUE") \
.async_flag(False) \
.binfile_name("depth_to_space.so") \
.compute_cost(10) \
.kernel_name("depth_to_space") \
.partial_flag(True) \
.attr("block_size", "required", "int", "all") \
.attr("data_format", "optional", "str", "all") \
.input(0, "x", False, "required", "all") \
.output(0, "y", False, "required", "all") \
.dtype_format(DataType.F16_NHWC, DataType.F16_NHWC) \
.dtype_format(DataType.F32_NHWC, DataType.F32_NHWC) \
.dtype_format(DataType.I8_NHWC, DataType.I8_NHWC) \
.dtype_format(DataType.I16_NHWC, DataType.I16_NHWC) \
.dtype_format(DataType.I32_NHWC, DataType.I32_NHWC) \
.dtype_format(DataType.I64_NHWC, DataType.I64_NHWC) \
.dtype_format(DataType.U8_NHWC, DataType.U8_NHWC) \
.dtype_format(DataType.U16_NHWC, DataType.U16_NHWC) \
.dtype_format(DataType.U32_NHWC, DataType.U32_NHWC) \
.dtype_format(DataType.U64_NHWC, DataType.U64_NHWC) \
.get_op_info()
@op_info_register(depth_to_space_op_info)
def _depth_to_space_tbe():
"""DepthToSpace TBE register"""
return

View File

@ -0,0 +1,46 @@
# 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.
# ============================================================================
"""SpaceToDepth op"""
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
space_to_depth_op_info = TBERegOp("SpaceToDepth") \
.fusion_type("OPAQUE") \
.async_flag(False) \
.binfile_name("space_to_depth.so") \
.compute_cost(10) \
.kernel_name("space_to_depth") \
.partial_flag(True) \
.attr("block_size", "required", "int", "all") \
.attr("data_format", "optional", "str", "all") \
.input(0, "x", False, "required", "all") \
.output(0, "y", False, "required", "all") \
.dtype_format(DataType.F16_NHWC, DataType.F16_NHWC) \
.dtype_format(DataType.F32_NHWC, DataType.F32_NHWC) \
.dtype_format(DataType.I8_NHWC, DataType.I8_NHWC) \
.dtype_format(DataType.I16_NHWC, DataType.I16_NHWC) \
.dtype_format(DataType.I32_NHWC, DataType.I32_NHWC) \
.dtype_format(DataType.I64_NHWC, DataType.I64_NHWC) \
.dtype_format(DataType.U8_NHWC, DataType.U8_NHWC) \
.dtype_format(DataType.U16_NHWC, DataType.U16_NHWC) \
.dtype_format(DataType.U32_NHWC, DataType.U32_NHWC) \
.dtype_format(DataType.U64_NHWC, DataType.U64_NHWC) \
.get_op_info()
@op_info_register(space_to_depth_op_info)
def _space_to_depth_tbe():
"""SpaceToDepth TBE register"""
return

View File

@ -2127,7 +2127,6 @@ class SpaceToDepth(PrimitiveWithInfer):
validator.check_value_type('block_size', block_size, [int], self.name) validator.check_value_type('block_size', block_size, [int], self.name)
validator.check('block_size', block_size, '', 2, Rel.GE) validator.check('block_size', block_size, '', 2, Rel.GE)
self.block_size = block_size self.block_size = block_size
self.add_prim_attr("data_format", "NCHW")
def infer_shape(self, x_shape): def infer_shape(self, x_shape):
validator.check('x dimension', len(x_shape), '', 4, Rel.EQ) validator.check('x dimension', len(x_shape), '', 4, Rel.EQ)
@ -2185,7 +2184,6 @@ class DepthToSpace(PrimitiveWithInfer):
validator.check_value_type('block_size', block_size, [int], self.name) validator.check_value_type('block_size', block_size, [int], self.name)
validator.check('block_size', block_size, '', 2, Rel.GE, self.name) validator.check('block_size', block_size, '', 2, Rel.GE, self.name)
self.block_size = block_size self.block_size = block_size
self.add_prim_attr("data_format", "NCHW")
def infer_shape(self, x_shape): def infer_shape(self, x_shape):
validator.check('x dimension', len(x_shape), '', 4, Rel.EQ) validator.check('x dimension', len(x_shape), '', 4, Rel.EQ)

View File

@ -243,6 +243,25 @@ class UnpackNet(Cell):
def construct(self, x): def construct(self, x):
return self.unpack(x) return self.unpack(x)
class SpaceToDepthNet(Cell):
def __init__(self):
super(SpaceToDepthNet, self).__init__()
block_size = 2
self.space_to_depth = P.SpaceToDepth(block_size)
def construct(self, x):
return self.space_to_depth(x)
class DepthToSpaceNet(Cell):
def __init__(self):
super(DepthToSpaceNet, self).__init__()
block_size = 2
self.depth_to_space = P.DepthToSpace(block_size)
def construct(self, x):
return self.depth_to_space(x)
test_case_array_ops = [ test_case_array_ops = [
('CustNet1', { ('CustNet1', {
@ -272,6 +291,12 @@ test_case_array_ops = [
('UnpackNet', { ('UnpackNet', {
'block': UnpackNet(), 'block': UnpackNet(),
'desc_inputs': [Tensor(np.array([[1, 2], [3, 4]]).astype(np.float16))]}), 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4]]).astype(np.float16))]}),
('SpaceToDepthNet', {
'block': SpaceToDepthNet(),
'desc_inputs': [Tensor(np.random.rand(1,3,2,2).astype(np.float16))]}),
('DepthToSpaceNet', {
'block': DepthToSpaceNet(),
'desc_inputs': [Tensor(np.random.rand(1,12,1,1).astype(np.float16))]}),
] ]
test_case_lists = [test_case_array_ops] test_case_lists = [test_case_array_ops]