!25000 [feat] [assistant] [I48OFO] Implement dynamic shape for Less

Merge pull request !25000 from 彭涛/op_less
This commit is contained in:
i-robot 2021-10-25 12:37:39 +00:00 committed by Gitee
commit 826cff9499
4 changed files with 49 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 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.
@ -39,15 +39,16 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &
(void)types.emplace("x", input_args[0]->BuildType());
(void)types.emplace("y", input_args[1]->BuildType());
(void)CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name());
return kBool;
return std::make_shared<TensorType>(kBool);
}
} // namespace
AbstractBasePtr LessInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args),
InferShape(primitive, input_args)->shape());
auto shape = InferShape(primitive, input_args);
auto type = InferType(primitive, input_args);
return abstract::MakeAbstract(shape, type);
}
REGISTER_PRIMITIVE_C(kNameLess, Less);
REGISTER_PRIMITIVE_EVAL_IMPL(Less, prim::kPrimLess, LessInfer, nullptr, true);
} // namespace ops
} // namespace mindspore

View File

@ -155,6 +155,7 @@ from .equal import _equal_tbe
from .equal_ds import _equal_ds_tbe
from .lerp import _lerp_tbe
from .less import _less_tbe
from .less_ds import _less_ds_tbe
from .less_equal import _less_equal_tbe
from .logical_and import _logical_and_tbe
from .logical_not import _logical_not_tbe

View File

@ -0,0 +1,42 @@
# Copyright 2021 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.
# ============================================================================
"""Less op"""
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
less_op_info = TBERegOp("Less") \
.fusion_type("OPAQUE") \
.async_flag(False) \
.binfile_name("less.so") \
.compute_cost(10) \
.kernel_name("less") \
.partial_flag(True) \
.dynamic_shape(True) \
.input(0, "x1", False, "required", "all") \
.input(1, "x2", False, "required", "all") \
.output(0, "y", False, "required", "all") \
.op_pattern("broadcast") \
.dtype_format(DataType.I8_None, DataType.I8_None, DataType.BOOL_None) \
.dtype_format(DataType.U8_None, DataType.U8_None, DataType.BOOL_None) \
.dtype_format(DataType.I32_None, DataType.I32_None, DataType.BOOL_None) \
.dtype_format(DataType.F16_None, DataType.F16_None, DataType.BOOL_None) \
.dtype_format(DataType.F32_None, DataType.F32_None, DataType.BOOL_None) \
.get_op_info()
@op_info_register(less_op_info)
def _less_ds_tbe():
"""Less TBE register"""
return

View File

@ -3783,14 +3783,6 @@ class Less(_LogicBinaryOp):
[False False True]
"""
def infer_value(self, x, y):
if x is not None and y is not None:
x = x.asnumpy()
y = y.asnumpy()
out = np.array(np.less(x, y))
return Tensor(out)
return None
class LessEqual(_LogicBinaryOp):
r"""
@ -3834,14 +3826,6 @@ class LessEqual(_LogicBinaryOp):
[ True False True]
"""
def infer_value(self, x, y):
if x is not None and y is not None:
x = x.asnumpy()
y = y.asnumpy()
out = np.array(np.less_equal(x, y))
return Tensor(out)
return None
class LogicalNot(PrimitiveWithInfer):
"""