forked from mindspore-Ecosystem/mindspore
!26265 [feat] [assistant] [I48O9O] add new BitwiseXor
Merge pull request !26265 from 桂胜楠/bitwisexor
This commit is contained in:
commit
80dee71e60
|
@ -623,6 +623,7 @@ inline const PrimitivePtr kPrimXlogy = std::make_shared<Primitive>("Xlogy");
|
|||
inline const PrimitivePtr kPrimInv = std::make_shared<Primitive>("Inv");
|
||||
inline const PrimitivePtr kPrimBitwiseOr = std::make_shared<Primitive>("BitwiseOr");
|
||||
inline const PrimitivePtr kPrimBitwiseAnd = std::make_shared<Primitive>("BitwiseAnd");
|
||||
inline const PrimitivePtr kPrimBitwiseXor = std::make_shared<Primitive>("BitwiseXor");
|
||||
|
||||
// Image
|
||||
inline const PrimitivePtr kPrimNonMaxSuppressionV3 = std::make_shared<Primitive>("NonMaxSuppressionV3");
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
#include "ops/bitwisexor.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "ops/op_utils.h"
|
||||
#include "utils/check_convert_utils.h"
|
||||
#include "abstract/primitive_infer_map.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace ops {
|
||||
namespace {
|
||||
abstract::ShapePtr BitwiseXorInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
|
||||
MS_EXCEPTION_IF_NULL(primitive);
|
||||
auto prim_name = primitive->name();
|
||||
for (const auto &item : input_args) {
|
||||
MS_EXCEPTION_IF_NULL(item);
|
||||
}
|
||||
return BroadCastInferShape(prim_name, input_args);
|
||||
}
|
||||
|
||||
TypePtr BitwiseXorInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
|
||||
for (const auto &item : input_args) {
|
||||
MS_EXCEPTION_IF_NULL(item);
|
||||
}
|
||||
std::map<std::string, TypePtr> types;
|
||||
(void)types.emplace("x", input_args[0]->BuildType());
|
||||
(void)types.emplace("y", input_args[1]->BuildType());
|
||||
const std::set<TypePtr> valid_types = {kInt8, kInt16, kInt32, kInt64, kUInt8, kUInt16, kUInt32, kUInt64};
|
||||
return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name());
|
||||
}
|
||||
} // namespace
|
||||
AbstractBasePtr BitwiseXorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
|
||||
const std::vector<AbstractBasePtr> &input_args) {
|
||||
auto op_name = primitive->name();
|
||||
const int64_t input_num = 2;
|
||||
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kGreaterEqual, input_num,
|
||||
op_name);
|
||||
auto infer_type = BitwiseXorInferType(primitive, input_args);
|
||||
auto infer_shape = BitwiseXorInferShape(primitive, input_args);
|
||||
return abstract::MakeAbstract(infer_shape, infer_type);
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_EVAL_IMPL(BitwiseXor, prim::kPrimBitwiseXor, BitwiseXorInfer, nullptr, true);
|
||||
} // namespace ops
|
||||
} // namespace mindspore
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CORE_OPS_BitwiseXor_H_
|
||||
#define MINDSPORE_CORE_OPS_BitwiseXor_H_
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "ops/primitive_c.h"
|
||||
#include "abstract/abstract_value.h"
|
||||
#include "utils/check_convert_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace ops {
|
||||
constexpr auto kNameBitwiseXor = "BitwiseXor";
|
||||
class BitwiseXor : public PrimitiveC {
|
||||
public:
|
||||
BitwiseXor() : PrimitiveC(kNameBitwiseXor) { InitIOName({"x1", "x2"}, {"y"}); }
|
||||
explicit BitwiseXor(const std::string k_name) : PrimitiveC(k_name) { InitIOName({"x1", "x2"}, {"y"}); }
|
||||
~BitwiseXor() = default;
|
||||
MS_DECLARE_PARENT(BitwiseXor, PrimitiveC);
|
||||
void Init() {}
|
||||
};
|
||||
AbstractBasePtr BitwiseXorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
|
||||
const std::vector<AbstractBasePtr> &input_args);
|
||||
using kPrimBitwiseXorPtr = std::shared_ptr<BitwiseXor>;
|
||||
} // namespace ops
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CORE_OPS_BitwiseXor_H_
|
|
@ -406,6 +406,7 @@ from .bitwise_and_ds import _bitwise_and_ds_tbe
|
|||
from .bitwise_or import _bitwise_or_tbe
|
||||
from .bitwise_or_ds import _bitwise_or_ds_tbe
|
||||
from .bitwise_xor import _bitwise_xor_tbe
|
||||
from .bitwise_xor_ds import _bitwise_xor_ds_tbe
|
||||
from .reduce_all import _reduce_all_tbe
|
||||
from .reduce_any import _reduce_any_tbe
|
||||
from .sparse_apply_adagrad import _sparse_apply_adagrad_tbe
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# 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.
|
||||
# ============================================================================
|
||||
|
||||
"""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") \
|
||||
.dynamic_shape(True) \
|
||||
.partial_flag(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.I16_None, DataType.I16_None, DataType.I16_None) \
|
||||
.dtype_format(DataType.U16_None, DataType.U16_None, DataType.U16_None) \
|
||||
.dtype_format(DataType.I32_None, DataType.I32_None, DataType.I32_None) \
|
||||
.get_op_info()
|
||||
|
||||
|
||||
@op_info_register(bitwise_xor_op_info)
|
||||
def _bitwise_xor_ds_tbe():
|
||||
"""BitwiseXor TBE register"""
|
||||
return
|
Loading…
Reference in New Issue