Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ref][Core][Opset13] BitwiseAnd, BitwiseOr and BitwiseXor core shell and reference #20058

Merged
Merged
39 changes: 39 additions & 0 deletions src/core/include/openvino/op/bitwise_and.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"
#include "openvino/op/util/binary_elementwise_bitwise.hpp"

namespace ov {
namespace op {
namespace v13 {
/// \brief Elementwise bitwise AND operation.
/// \ingroup ov_ops_cpp_api
class OPENVINO_API BitwiseAnd : public util::BinaryElementwiseBitwise {
public:
OPENVINO_OP("BitwiseAnd", "opset13", util::BinaryElementwiseBitwise);
/// \brief Constructs a bitwise AND operation.
BitwiseAnd() = default;
/// \brief Constructs a bitwise AND operation.
///
/// \param arg0 Output that produces the first input tensor.<br>
/// `[d0, ...]`
/// \param arg1 Output that produces the second input tensor.<br>
/// `[d0, ...]`
/// \param auto_broadcast Auto broadcast specification. Default is Numpy-style
/// implicit broadcasting.
///
/// Output `[d0, ...]`
///
BitwiseAnd(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY));

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace v13
} // namespace op
} // namespace ov
39 changes: 39 additions & 0 deletions src/core/include/openvino/op/bitwise_or.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"
#include "openvino/op/util/binary_elementwise_bitwise.hpp"

namespace ov {
namespace op {
namespace v13 {
/// \brief Elementwise bitwise OR operation.
/// \ingroup ov_ops_cpp_api
class OPENVINO_API BitwiseOr : public util::BinaryElementwiseBitwise {
public:
OPENVINO_OP("BitwiseOr", "opset13", util::BinaryElementwiseBitwise);
/// \brief Constructs a bitwise OR operation.
BitwiseOr() = default;
/// \brief Constructs a bitwise OR operation.
///
/// \param arg0 Output that produces the first input tensor.<br>
/// `[d0, ...]`
/// \param arg1 Output that produces the second input tensor.<br>
/// `[d0, ...]`
/// \param auto_broadcast Auto broadcast specification. Default is Numpy-style
/// implicit broadcasting.
///
/// Output `[d0, ...]`
///
BitwiseOr(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY));

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace v13
} // namespace op
} // namespace ov
39 changes: 39 additions & 0 deletions src/core/include/openvino/op/bitwise_xor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"
#include "openvino/op/util/binary_elementwise_bitwise.hpp"

namespace ov {
namespace op {
namespace v13 {
/// \brief Elementwise bitwise XOR operation.
/// \ingroup ov_ops_cpp_api
class OPENVINO_API BitwiseXor : public util::BinaryElementwiseBitwise {
public:
OPENVINO_OP("BitwiseXor", "opset13", util::BinaryElementwiseBitwise);
/// \brief Constructs a bitwise XOR operation.
BitwiseXor() = default;
/// \brief Constructs a bitwise XOR operation.
///
/// \param arg0 Output that produces the first input tensor.<br>
/// `[d0, ...]`
/// \param arg1 Output that produces the second input tensor.<br>
/// `[d0, ...]`
/// \param auto_broadcast Auto broadcast specification. Default is Numpy-style
/// implicit broadcasting.
///
/// Output `[d0, ...]`
///
BitwiseXor(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY));

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace v13
} // namespace op
} // namespace ov
3 changes: 3 additions & 0 deletions src/core/include/openvino/op/ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include "openvino/op/batch_norm.hpp"
#include "openvino/op/batch_to_space.hpp"
#include "openvino/op/binary_convolution.hpp"
#include "openvino/op/bitwise_and.hpp"
#include "openvino/op/bitwise_not.hpp"
#include "openvino/op/bitwise_or.hpp"
#include "openvino/op/bitwise_xor.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/bucketize.hpp"
#include "openvino/op/ceiling.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"

namespace ov {
namespace op {
namespace util {
class OPENVINO_API BinaryElementwiseBitwise : public Op {
protected:
BinaryElementwiseBitwise();

/// \brief Constructs a binary elementwise bitwise operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
/// \param auto_broadcast Auto broadcast specification. Default is Numpy-style
/// implicit broadcasting.
BinaryElementwiseBitwise(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob = AutoBroadcastSpec());

public:
OPENVINO_OP("BinaryElementwiseBitwise", "util");

void validate_and_infer_types() override;

virtual const AutoBroadcastSpec& get_autob() const override;

void set_autob(const AutoBroadcastSpec& autob);
bool visit_attributes(AttributeVisitor& visitor) override;

private:
AutoBroadcastSpec m_autob = AutoBroadcastType::NUMPY;
};
} // namespace util
} // namespace op
} // namespace ov
3 changes: 3 additions & 0 deletions src/core/include/openvino/opsets/opset13_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,8 @@ _OPENVINO_OP_REG(Pad, ov::op::v12)
_OPENVINO_OP_REG(ScatterElementsUpdate, ov::op::v12)

// New operations added in opset13
_OPENVINO_OP_REG(BitwiseAnd, ov::op::v13)
_OPENVINO_OP_REG(BitwiseNot, ov::op::v13)
_OPENVINO_OP_REG(BitwiseOr, ov::op::v13)
_OPENVINO_OP_REG(BitwiseXor, ov::op::v13)
_OPENVINO_OP_REG(NMSRotated, ov::op::v13)
54 changes: 54 additions & 0 deletions src/core/reference/include/openvino/reference/bitwise_and.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <algorithm>
#include <cstddef>

#include "openvino/reference/autobroadcast_binop.hpp"

namespace ov {
namespace reference {
/**
* @brief Reference implementation of binary elementwise bitwise AND operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
// Check for char datatype used by ov::element::boolean
void bitwise_and(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_and<bool>());
}
/**
* @brief Reference implementation of binary elementwise bitwise AND operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<!std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
void bitwise_and(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_and<T>());
}
} // namespace reference
} // namespace ov
54 changes: 54 additions & 0 deletions src/core/reference/include/openvino/reference/bitwise_or.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <algorithm>
#include <cstddef>

#include "openvino/reference/autobroadcast_binop.hpp"

namespace ov {
namespace reference {
/**
* @brief Reference implementation of binary elementwise bitwise OR operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
// Check for char datatype used by ov::element::boolean
void bitwise_or(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_or<bool>());
}
/**
* @brief Reference implementation of binary elementwise bitwise OR operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<!std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
void bitwise_or(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_or<T>());
}
} // namespace reference
} // namespace ov
54 changes: 54 additions & 0 deletions src/core/reference/include/openvino/reference/bitwise_xor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <algorithm>
#include <cstddef>

#include "openvino/reference/autobroadcast_binop.hpp"

namespace ov {
namespace reference {
/**
* @brief Reference implementation of binary elementwise bitwise XOR operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
// Check for char datatype used by ov::element::boolean
void bitwise_xor(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_xor<bool>());
}
/**
* @brief Reference implementation of binary elementwise bitwise XOR operator.
*
* @param arg0 Pointer to input 0 data.
* @param arg1 Pointer to input 1 data.
* @param out Pointer to output data.
* @param arg_shape0 Input 0 shape.
* @param arg_shape1 Input 1 shape.
* @param broadcast_spec Broadcast specification mode.
*/
template <class T, typename std::enable_if<!std::is_same<typename std::decay<T>::type, char>::value>::type* = nullptr>
void bitwise_xor(const T* arg0,
const T* arg1,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::bit_xor<T>());
}
} // namespace reference
} // namespace ov
25 changes: 25 additions & 0 deletions src/core/src/op/bitwise_and.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/bitwise_and.hpp"

#include "itt.hpp"
#include "openvino/op/op.hpp"

namespace ov {
namespace op {
namespace v13 {
BitwiseAnd::BitwiseAnd(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast)
: BinaryElementwiseBitwise(arg0, arg1, auto_broadcast) {
constructor_validate_and_infer_types();
}

std::shared_ptr<Node> BitwiseAnd::clone_with_new_inputs(const OutputVector& new_args) const {
OV_OP_SCOPE(v13_BitwiseAnd_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<BitwiseAnd>(new_args[0], new_args[1], get_autob());
}

} // namespace v13
} // namespace op
} // namespace ov
1 change: 0 additions & 1 deletion src/core/src/op/bitwise_not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "openvino/op/bitwise_not.hpp"

#include "itt.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/op/op.hpp"

namespace ov {
Expand Down
Loading
Loading