Skip to content

Commit

Permalink
[ONNX] Extend ONNX Frontend with BitwiseAnd-18 operator (openvinotool…
Browse files Browse the repository at this point in the history
  • Loading branch information
rghvsh authored Dec 19, 2023
1 parent 63b23a1 commit a4e8f9d
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/bindings/python/tests_compatibility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):
xfail_issue_47323 = xfail_test(reason="RuntimeError: The plugin does not support FP64")
xfail_issue_73538 = xfail_test(reason="OneHot: Unsupported negative indices, "
"AssertionError: Mismatched elements.")
skip_bitwise_ui64 = pytest.mark.skip(reason="AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07")
xfail_issue_99949 = xfail_test(reason="Bitwise operators are not supported")
xfail_issue_99950 = xfail_test(reason="CenterCropPad func is not supported")
xfail_issue_99952 = xfail_test(reason="Col2Im operator is not supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
xfail_issue_91151,
xfail_issue_91490,
xfail_issue_101965,
skip_bitwise_ui64,
xfail_issue_99949,
xfail_issue_99950,
xfail_issue_99952,
Expand Down Expand Up @@ -521,11 +522,12 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_reduce_sum_square_keepdims_example_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_keepdims_random_expanded_cpu",
),
(
skip_bitwise_ui64,
"OnnxBackendNodeModelTest.test_bitwise_and_ui64_bcast_3v1d_cpu",
),
(
xfail_issue_99949,
"OnnxBackendNodeModelTest.test_bitwise_and_i16_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_and_i32_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_and_ui64_bcast_3v1d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_2d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_not_4d_cpu",
Expand All @@ -535,7 +537,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"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_and_ui8_bcast_4v3d_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_and.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_and.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_and(const Node& node) {
const auto inputs = node.get_ng_inputs();
OPENVINO_ASSERT(inputs.size() == 2);
return {std::make_shared<v13::BitwiseAnd>(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_and.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_and(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 @@ -29,6 +29,7 @@
#include "op/average_pool.hpp"
#include "op/batch_norm.hpp"
#include "op/bitshift.hpp"
#include "op/bitwise_and.hpp"
#include "op/blackmanwindow.hpp"
#include "op/cast.hpp"
#include "op/cast_like.hpp"
Expand Down Expand Up @@ -351,6 +352,7 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("BatchNormalization", 1, batch_norm);
REGISTER_OPERATOR("BatchNormalization", 7, batch_norm);
REGISTER_OPERATOR("BitShift", 1, bitshift);
REGISTER_OPERATOR("BitwiseAnd", 1, bitwise_and);
REGISTER_OPERATOR("BlackmanWindow", 1, blackmanwindow);
REGISTER_OPERATOR("Cast", 1, cast);
REGISTER_OPERATOR("CastLike", 1, cast_like);
Expand Down
1 change: 1 addition & 0 deletions src/frontends/onnx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):
xfail_issue_38706 = xfail_test(reason="RuntimeError: output_3.0 has zero dimension which is not allowed")
xfail_issue_38708 = xfail_test(reason="RuntimeError: While validating ONNX node '<Node(Slice): y>': "
"Axes input must be constant")
skip_bitwise_ui64 = pytest.mark.skip(reason="AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07")
xfail_issue_99949 = xfail_test(reason="Bitwise operators are not supported")
xfail_issue_99950 = xfail_test(reason="CenterCropPad func is not supported")
xfail_issue_99952 = xfail_test(reason="Col2Im operator is not supported")
Expand Down
53 changes: 53 additions & 0 deletions src/frontends/onnx/tests/models/bitwise_and.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: "BitwiseAnd"
}
name: "BitwiseAndGraph"
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: "BitwiseAnd"
}
name: "BitwiseAndGraph"
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 @@ -6117,3 +6117,25 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_greater_or_equal_float) {

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bitwise_and) {
auto model = convert_model("bitwise_and.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}, {1, 0, 1, 4, 5});

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bitwise_and_broadcast_condition) {
auto model = convert_model("bitwise_and_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}, {0, 0, 0, 4, 4});

test_case.run();
}
9 changes: 5 additions & 4 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
xfail_issue_82039,
xfail_issue_90649,
xfail_issue_91151,
skip_bitwise_ui64,
xfail_issue_99949,
xfail_issue_99950,
xfail_issue_99952,
Expand Down Expand Up @@ -390,10 +391,11 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_castlike_FLOAT_to_BFLOAT16_cpu",
),
(
xfail_issue_99949,
"OnnxBackendNodeModelTest.test_bitwise_and_i16_3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_and_i32_2d_cpu",
skip_bitwise_ui64,
"OnnxBackendNodeModelTest.test_bitwise_and_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",
Expand All @@ -403,7 +405,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"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_and_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_or_ui8_bcast_4v3d_cpu",
"OnnxBackendNodeModelTest.test_bitwise_xor_ui64_bcast_3v1d_cpu",
),
Expand Down

0 comments on commit a4e8f9d

Please sign in to comment.