From fa8486dff1628adb874a08cde68c36c61ccd6c6e Mon Sep 17 00:00:00 2001 From: Michal Karzynski Date: Tue, 16 Feb 2021 14:18:10 +0100 Subject: [PATCH 1/2] Add support for BitShift operator --- .../frontend/onnx_import/src/op/bitshift.cpp | 67 +++++++++++++++++++ .../frontend/onnx_import/src/op/bitshift.hpp | 40 +++++++++++ .../frontend/onnx_import/src/ops_bridge.cpp | 2 + ngraph/python/tests/test_onnx/test_backend.py | 9 --- 4 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 ngraph/frontend/onnx_import/src/op/bitshift.cpp create mode 100644 ngraph/frontend/onnx_import/src/op/bitshift.hpp diff --git a/ngraph/frontend/onnx_import/src/op/bitshift.cpp b/ngraph/frontend/onnx_import/src/op/bitshift.cpp new file mode 100644 index 00000000000000..8df73f1b3bff5a --- /dev/null +++ b/ngraph/frontend/onnx_import/src/op/bitshift.cpp @@ -0,0 +1,67 @@ +//***************************************************************************** +// Copyright 2017-2021 Intel Corporation +// +// 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 "op/bitshift.hpp" +#include "default_opset.hpp" +#include "exceptions.hpp" +#include "ngraph/shape.hpp" + +namespace ngraph +{ + namespace onnx_import + { + namespace op + { + namespace set_1 + { + OutputVector bitshift(const Node& node) + { + const Output input_x = node.get_ng_inputs().at(0); + const Output input_y = node.get_ng_inputs().at(1); + + std::string direction = node.get_attribute_value("direction", ""); + + CHECK_VALID_NODE(node, + !direction.empty(), + "Required attribute 'direction' is not specified."); + + CHECK_VALID_NODE(node, + direction == "LEFT" || direction == "RIGHT", + "Only values 'LEFT' and 'RIGHT' are supported for 'direction' " + "attribute. Given: ", + direction); + + auto shift = std::make_shared( + default_opset::Constant::create(input_y.get_element_type(), Shape{1}, {2}), + input_y); + + if (direction == "RIGHT") + { + return {std::make_shared(input_x, shift)}; + } + else + { + return {std::make_shared(input_x, shift)}; + } + } + + } // namespace set_1 + + } // namespace op + + } // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/bitshift.hpp b/ngraph/frontend/onnx_import/src/op/bitshift.hpp new file mode 100644 index 00000000000000..3eac9bbe723fb9 --- /dev/null +++ b/ngraph/frontend/onnx_import/src/op/bitshift.hpp @@ -0,0 +1,40 @@ +//***************************************************************************** +// Copyright 2017-2021 Intel Corporation +// +// 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. +//***************************************************************************** + +#pragma once + +#include + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph +{ + namespace onnx_import + { + namespace op + { + namespace set_1 + { + OutputVector bitshift(const Node& node); + + } // namespace set_1 + + } // namespace op + + } // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index 12c25fddfb3bba..d9085449d3bfa7 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -35,6 +35,7 @@ #include "op/atanh.hpp" #include "op/average_pool.hpp" #include "op/batch_norm.hpp" +#include "op/bitshift.hpp" #include "op/cast.hpp" #include "op/ceil.hpp" #include "op/clip.hpp" @@ -324,6 +325,7 @@ namespace ngraph REGISTER_OPERATOR("Atanh", 1, atanh); REGISTER_OPERATOR("AveragePool", 1, average_pool); REGISTER_OPERATOR("BatchNormalization", 1, batch_norm); + REGISTER_OPERATOR("BitShift", 1, bitshift); REGISTER_OPERATOR("Cast", 1, cast); REGISTER_OPERATOR("Ceil", 1, ceil); REGISTER_OPERATOR("Clip", 1, clip); diff --git a/ngraph/python/tests/test_onnx/test_backend.py b/ngraph/python/tests/test_onnx/test_backend.py index 7fe5075327ac21..f1dc4fe6d0f348 100644 --- a/ngraph/python/tests/test_onnx/test_backend.py +++ b/ngraph/python/tests/test_onnx/test_backend.py @@ -582,15 +582,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None "OnnxBackendNodeModelTest.test_compress_default_axis_cpu", "OnnxBackendNodeModelTest.test_compress_1_cpu", "OnnxBackendNodeModelTest.test_compress_0_cpu"), - (xfail_issue_33515, - "OnnxBackendNodeModelTest.test_bitshift_left_uint8_cpu", - "OnnxBackendNodeModelTest.test_bitshift_right_uint64_cpu", - "OnnxBackendNodeModelTest.test_bitshift_right_uint16_cpu", - "OnnxBackendNodeModelTest.test_bitshift_right_uint32_cpu", - "OnnxBackendNodeModelTest.test_bitshift_right_uint8_cpu", - "OnnxBackendNodeModelTest.test_bitshift_left_uint32_cpu", - "OnnxBackendNodeModelTest.test_bitshift_left_uint16_cpu", - "OnnxBackendNodeModelTest.test_bitshift_left_uint64_cpu"), (xfail_issue_38732, "OnnxBackendNodeModelTest.test_convinteger_with_padding_cpu", "OnnxBackendNodeModelTest.test_basic_convinteger_cpu"), From 7ac888603edb6308507df0ca2bbf42a30d186357 Mon Sep 17 00:00:00 2001 From: Michal Karzynski Date: Tue, 16 Feb 2021 15:57:58 +0100 Subject: [PATCH 2/2] Fix --- ngraph/python/tests/test_onnx/test_backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/python/tests/test_onnx/test_backend.py b/ngraph/python/tests/test_onnx/test_backend.py index f1dc4fe6d0f348..b006c88d28994d 100644 --- a/ngraph/python/tests/test_onnx/test_backend.py +++ b/ngraph/python/tests/test_onnx/test_backend.py @@ -63,7 +63,6 @@ xfail_issue_33512, xfail_issue_33606, xfail_issue_33644, - xfail_issue_33515, xfail_issue_38732, xfail_issue_38734, xfail_issue_38735,