Skip to content

Commit

Permalink
[ONNX] Extend ONNX Frontend with BitwiseOr-18 operator (openvinotoolk…
Browse files Browse the repository at this point in the history
…it#21755)

* Create bitwise_or.hpp
* Update ops_bridge.cpp
* Added protobuf(.prototxt) files via upload.
* Update onnx_import.in.cpp
* Update test_backend.py
* Skip "test_bitwise_or_ui64_bcast_3v1d_cpu"
  • Loading branch information
rghvsh authored Dec 21, 2023
1 parent 0709a35 commit 1a0f0cc
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,20 +549,17 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
),
(
skip_bitwise_ui64,
"OnnxBackendNodeModelTest.test_bitwise_and_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_and_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui64_bcast_3v1d_cpu",
),
(
xfail_issue_99949,
"OnnxBackendNodeModelTest.test_bitwise_not_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_4d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_i16_4d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_i32_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_i16_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_i32_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_ui64_bcast_3v1d_cpu",
),
(
Expand Down
24 changes: 24 additions & 0 deletions src/frontends/onnx/frontend/src/op/bitwise_or.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "op/bitwise_or.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "default_opset.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector bitwise_or(const Node& node) {
const auto inputs = node.get_ng_inputs();
OPENVINO_ASSERT(inputs.size() == 2);
return {std::make_shared<v13::BitwiseOr>(inputs[0], inputs[1])};
}
} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
25 changes: 25 additions & 0 deletions src/frontends/onnx/frontend/src/op/bitwise_or.hpp
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
//

#pragma once

#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector bitwise_or(const Node& node);

} // namespace set_1
} // namespace op

} // namespace onnx_import

} // namespace ngraph
OPENVINO_SUPPRESS_DEPRECATED_END
2 changes: 2 additions & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "op/batch_norm.hpp"
#include "op/bitshift.hpp"
#include "op/bitwise_and.hpp"
#include "op/bitwise_or.hpp"
#include "op/blackmanwindow.hpp"
#include "op/cast.hpp"
#include "op/cast_like.hpp"
Expand Down Expand Up @@ -353,6 +354,7 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("BatchNormalization", 7, batch_norm);
REGISTER_OPERATOR("BitShift", 1, bitshift);
REGISTER_OPERATOR("BitwiseAnd", 1, bitwise_and);
REGISTER_OPERATOR("BitwiseOr", 1, bitwise_or);
REGISTER_OPERATOR("BlackmanWindow", 1, blackmanwindow);
REGISTER_OPERATOR("Cast", 1, cast);
REGISTER_OPERATOR("CastLike", 1, cast_like);
Expand Down
53 changes: 53 additions & 0 deletions src/frontends/onnx/tests/models/bitwise_or.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ir_version: 7
graph {
node {
input: "a"
input: "b"
output: "output"
op_type: "BitwiseOr"
}
name: "BitwiseOrGraph"
input {
name: "a"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 5
}
}
}
}
}
input {
name: "b"
type {
tensor_type {
elem_type:6
shape {
dim {
dim_value: 5
}
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
domain: ""
version: 16
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ir_version: 7
graph {
node {
input: "a"
input: "b"
output: "output"
op_type: "BitwiseOr"
}
name: "BitwiseOrGraph"
input {
name: "a"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 5
}
}
}
}
}
input {
name: "b"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "output"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
domain: ""
version: 16
}
22 changes: 22 additions & 0 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6139,3 +6139,25 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bitwise_and_broadcast_condition) {

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bitwise_or) {
auto model = convert_model("bitwise_or.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<int>(Shape{5}, {1, 2, 3, 4, 5});
test_case.add_input<int>(Shape{5}, {5, 5, 5, 5, 5});
test_case.add_expected_output<int>(Shape{5}, {5, 7, 7, 5, 5});

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bitwise_or_broadcast_condition) {
auto model = convert_model("bitwise_or_broadcast_condition.onnx");

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_input<int>(Shape{5}, {1, 2, 3, 4, 5});
test_case.add_input<int>(Shape{1}, {4});
test_case.add_expected_output<int>(Shape{5}, {5, 6, 7, 4, 5});

test_case.run();
}
5 changes: 1 addition & 4 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,16 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
(
skip_bitwise_ui64,
"OnnxBackendNodeModelTest.test_bitwise_and_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui64_bcast_3v1d_cpu",
),
(
xfail_issue_99949,
"OnnxBackendNodeModelTest.test_bitwise_not_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_4d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_i16_4d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_i32_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_i16_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_i32_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_ui64_bcast_3v1d_cpu",
),
(
Expand Down

0 comments on commit 1a0f0cc

Please sign in to comment.