From ecb1344b4bc73ac3ff10c15a9abd6cd0670dcf62 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 30 Jul 2020 16:26:31 +0300 Subject: [PATCH] Removed v0 builders (#1528) --- .../convert_opset1_to_legacy/reshape_fc_fusion.hpp | 1 + .../convert_opset1_to_legacy/conv_bias_fusion.cpp | 3 +- .../convert_opset1_to_legacy/fc_bias_fusion.cpp | 3 +- ngraph/src/ngraph/CMakeLists.txt | 11 --- ngraph/src/ngraph/builder/autobroadcast.cpp | 59 ------------ ngraph/src/ngraph/builder/autobroadcast.hpp | 24 ----- ngraph/src/ngraph/builder/dequantize_builder.cpp | 58 ------------ ngraph/src/ngraph/builder/dequantize_builder.hpp | 36 ------- ngraph/src/ngraph/builder/numpy_transpose.cpp | 82 ---------------- ngraph/src/ngraph/builder/numpy_transpose.hpp | 53 ----------- ngraph/src/ngraph/builder/quantize_builder.cpp | 59 ------------ ngraph/src/ngraph/builder/quantize_builder.hpp | 37 -------- .../src/ngraph/builder/quantized_dot_builder.cpp | 69 -------------- .../src/ngraph/builder/quantized_dot_builder.hpp | 45 --------- ngraph/src/ngraph/builder/tensor_mask.hpp | 103 -------------------- ngraph/src/ngraph/ngraph.hpp | 6 -- ngraph/src/ngraph/runtime/reference/matmul.hpp | 1 + ngraph/test/backend/broadcast.in.cpp | 1 + .../test/backend/builder_reduce_ops_opset1.in.cpp | 2 + ngraph/test/backend/fused_op.in.cpp | 1 + ngraph/test/backend/matmul.in.cpp | 1 + ngraph/test/backend/reduce_sum.in.cpp | 1 + ngraph/test/backend/reshape.in.cpp | 1 + ngraph/test/backend/strided_slice.in.cpp | 2 + ngraph/test/backend/sum.in.cpp | 1 + ngraph/test/builder.cpp | 49 ---------- ngraph/test/builder_autobroadcast.cpp | 104 --------------------- ngraph/test/coordinate.cpp | 1 + ngraph/test/onnx/onnx_import_convpool.in.cpp | 1 + ngraph/test/onnx/onnx_import_quant.in.cpp | 1 + ngraph/test/provenance.cpp | 30 ------ 31 files changed, 19 insertions(+), 827 deletions(-) delete mode 100644 ngraph/src/ngraph/builder/dequantize_builder.cpp delete mode 100644 ngraph/src/ngraph/builder/dequantize_builder.hpp delete mode 100644 ngraph/src/ngraph/builder/numpy_transpose.cpp delete mode 100644 ngraph/src/ngraph/builder/numpy_transpose.hpp delete mode 100644 ngraph/src/ngraph/builder/quantize_builder.cpp delete mode 100644 ngraph/src/ngraph/builder/quantize_builder.hpp delete mode 100644 ngraph/src/ngraph/builder/quantized_dot_builder.cpp delete mode 100644 ngraph/src/ngraph/builder/quantized_dot_builder.hpp delete mode 100644 ngraph/src/ngraph/builder/tensor_mask.hpp diff --git a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp index e347556..58842e0 100644 --- a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp index 4a67b6a..4b4e708 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp @@ -5,6 +5,7 @@ #include "transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp" #include +#include #include #include @@ -120,4 +121,4 @@ ngraph::pass::DeconvAddFusion::DeconvAddFusion() { auto m = std::make_shared(add, "DeconvAddFusion"); register_matcher(m, callback); -} \ No newline at end of file +} diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp index 9d7bda6..01511de 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp @@ -5,6 +5,7 @@ #include "transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp" #include +#include #include #include @@ -71,4 +72,4 @@ ngraph::pass::FullyConnectedBiasFusion::FullyConnectedBiasFusion() { auto m = std::make_shared(add, "FullyConnectedBiasFusion"); this->register_matcher(m, callback); -} \ No newline at end of file +} diff --git a/ngraph/src/ngraph/CMakeLists.txt b/ngraph/src/ngraph/CMakeLists.txt index 4c904ec..ac35f31 100644 --- a/ngraph/src/ngraph/CMakeLists.txt +++ b/ngraph/src/ngraph/CMakeLists.txt @@ -27,21 +27,11 @@ set (SRC axis_vector.hpp builder/autobroadcast.cpp builder/autobroadcast.hpp - builder/dequantize_builder.cpp - builder/dequantize_builder.hpp builder/make_constant.hpp builder/matmul_factory.cpp builder/matmul_factory.hpp builder/norm.cpp builder/norm.hpp - builder/numpy_transpose.cpp - builder/numpy_transpose.hpp - builder/quantize_builder.cpp - builder/quantize_builder.hpp - builder/quantized_concat_builder.cpp - builder/quantized_concat_builder.hpp - builder/quantized_dot_builder.cpp - builder/quantized_dot_builder.hpp builder/quantization_utils.hpp builder/quantization_utils.cpp builder/reduce_ops.cpp @@ -50,7 +40,6 @@ set (SRC builder/reshape.hpp builder/split.cpp builder/split.hpp - builder/tensor_mask.hpp check.hpp chrome_trace.cpp chrome_trace.hpp diff --git a/ngraph/src/ngraph/builder/autobroadcast.cpp b/ngraph/src/ngraph/builder/autobroadcast.cpp index 06a215e..82bd614 100644 --- a/ngraph/src/ngraph/builder/autobroadcast.cpp +++ b/ngraph/src/ngraph/builder/autobroadcast.cpp @@ -319,65 +319,6 @@ namespace ngraph numpy_broadcast_node(right, right_output_shape, right_full_shape)}; } - OutputVector legacy_broadcast_for_binary_operation(const Output& left, - const Output& right, - size_t start_match_axis) - { - const auto& left_shape = left.get_shape(); - const auto& right_shape = right.get_shape(); - - bool dimensions_identical = (left_shape == right_shape); - if (dimensions_identical) - { - return {left, right}; - } - - // Prepare new shape of right operand for broadcasting - // Remove dimensions with length=1 from back - auto new_right_shape = right_shape; - for (int dimension = new_right_shape.size() - 1; dimension >= 0; --dimension) - { - if (new_right_shape[dimension] == 1) - { - new_right_shape.pop_back(); - } - else - { - break; - } - } - - // Find first dimensions at front with length different from 1 - size_t num_ones = 0; - for (size_t dimension : new_right_shape) - { - if (dimension == 1) - { - ++num_ones; - } - else - { - break; - } - } - - // Remove dimensions with length=1 from front - new_right_shape.erase(begin(new_right_shape), next(begin(new_right_shape), num_ones)); - - auto reshape_right = - make_shared(right, get_default_order(right_shape), new_right_shape); - - // Move broadcast start axis parameter to right - start_match_axis += num_ones; - - auto broadcast_right = make_shared( - reshape_right, - left_shape, - calculate_broadcast_axes(left_shape, new_right_shape, start_match_axis)); - - return {left, broadcast_right}; - } - OutputVector pdpd_broadcast(const OutputVector& inputs, int64_t axis) { if (inputs.size() <= 1) diff --git a/ngraph/src/ngraph/builder/autobroadcast.hpp b/ngraph/src/ngraph/builder/autobroadcast.hpp index 41664af..457b145 100644 --- a/ngraph/src/ngraph/builder/autobroadcast.hpp +++ b/ngraph/src/ngraph/builder/autobroadcast.hpp @@ -152,30 +152,6 @@ namespace ngraph operand1, shaped_op2_op3.first, shaped_op2_op3.second); } - /// - /// \brief Cast shape of two outputs to make them compatible for an element-wise binary - /// operation. - /// - /// \note If necessary the right-hand-side argument will be broadcast to match the - /// shape of left-hand-side argument. The starting of the mutually equal shape - /// is specified by the argument "start_match_axis", and if it is not set suffix - /// matching is assumed. - /// - /// \note This style of broadcast was used in ONNX Op sets prior to version 7, where - /// it was replaced by NumPy style auto-broadcasting mechanism. - /// - /// \param left Node which contain input of binary op. - /// \param right Node which contain input of binary op. - /// \param start_match_axis Position in shape denoting start of the mutually equal - /// shape - /// - /// \return Left and right node after broadcasting. - /// - NGRAPH_API - OutputVector legacy_broadcast_for_binary_operation(const Output& left, - const Output& right, - size_t start_match_axis); - /// \brief Broadcast shape of two nodes to make them compatible for a matrix /// multiplication. /// diff --git a/ngraph/src/ngraph/builder/dequantize_builder.cpp b/ngraph/src/ngraph/builder/dequantize_builder.cpp deleted file mode 100644 index dff1201..0000000 --- a/ngraph/src/ngraph/builder/dequantize_builder.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 - -#include "ngraph/builder/dequantize_builder.hpp" - -using namespace std; -using namespace ngraph; - -namespace ngraph -{ - namespace builder - { - shared_ptr DequantizeBuilder(const Output& input, - const Output& min, - const Output& max, - const ngraph::element::Type& real_type, - const ngraph::AxisSet& axes) - { - auto quant_type = input.get_element_type(); - - if (min.get_element_type() != real_type) - { - throw ngraph_error("DequantizeBuilder: min must match input type"); - } - - if (max.get_element_type() != real_type) - { - throw ngraph_error("DequantizeBuilder: max must match input type"); - } - - auto shape = min.get_shape(); - if (shape != max.get_shape()) - { - throw ngraph_error("DequantizeBuilder: min and max must have same shape"); - } - - auto zero = make_constant(quant_type, shape, 0); - auto scale = quantization_utils::get_scale(min, max, quant_type); - return make_shared(input, scale, zero, real_type, axes) - ->add_provenance_group_members_above({input, min, max}); - } - } -} diff --git a/ngraph/src/ngraph/builder/dequantize_builder.hpp b/ngraph/src/ngraph/builder/dequantize_builder.hpp deleted file mode 100644 index 1d6132f..0000000 --- a/ngraph/src/ngraph/builder/dequantize_builder.hpp +++ /dev/null @@ -1,36 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 "ngraph/builder/make_constant.hpp" -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/dequantize.hpp" -#include "quantization_utils.hpp" - -namespace ngraph -{ - namespace builder - { - NGRAPH_API - std::shared_ptr DequantizeBuilder(const Output& input, - const Output& min, - const Output& max, - const ngraph::element::Type& real_type, - const ngraph::AxisSet& axes); - } -} diff --git a/ngraph/src/ngraph/builder/numpy_transpose.cpp b/ngraph/src/ngraph/builder/numpy_transpose.cpp deleted file mode 100644 index 75cdb69..0000000 --- a/ngraph/src/ngraph/builder/numpy_transpose.cpp +++ /dev/null @@ -1,82 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 - -#include "ngraph/axis_vector.hpp" -#include "ngraph/builder/numpy_transpose.hpp" -#include "ngraph/except.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/util.hpp" - -namespace ngraph -{ - [[noreturn]] void numpy_transpose_error(const AxisVector& order, const Shape& in_shape) - { - std::ostringstream os; - os << "The axes order "; - os << "[ " << ngraph::join(order) << " ]"; - os << " is incompatible with the input shape "; - os << "[ " << ngraph::join(in_shape) << " ]"; - os << " during numpy_transpose."; - throw ngraph_error(os.str()); - } - - namespace builder - { - std::shared_ptr numpy_transpose(const Output& value, AxisVector order) - { - auto in_shape = value.get_shape(); - // default, reverse the order of the axes - if (order.size() == 0) - { - auto n = in_shape.size(); - order = AxisVector(n); - std::generate(order.begin(), order.end(), [&n]() { return --n; }); - } - else if (order.size() == in_shape.size()) - { - // validate that the axes order is valid, i.e., unique and the right size - std::unordered_set axes; - for (auto o : order) - { - if (o < in_shape.size() && !axes.count(o)) - { - axes.insert(o); - } - else - { - numpy_transpose_error(order, in_shape); - } - } - } - else - { - numpy_transpose_error(order, in_shape); - } - - // create output shape - Shape out_shape; - for (size_t i = 0; i < in_shape.size(); ++i) - out_shape.push_back(in_shape[order[i]]); - - // do the reshaping with the order - return std::make_shared(value, order, out_shape) - ->add_provenance_group_members_above({value}); - } - - } // namespace builder -} // namespace ngraph diff --git a/ngraph/src/ngraph/builder/numpy_transpose.hpp b/ngraph/src/ngraph/builder/numpy_transpose.hpp deleted file mode 100644 index fb67dd0..0000000 --- a/ngraph/src/ngraph/builder/numpy_transpose.hpp +++ /dev/null @@ -1,53 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 "ngraph/axis_vector.hpp" -#include "ngraph/node.hpp" - -namespace ngraph -{ - namespace builder - { - // clang-format off - /// \brief Implement's Numpy's multidimensional transpose op. Doubles as DimShuffle. - /// - /// If `order` is empty, the vector is transposed by reversing it's axes, i.e. - /// - /// shape [1,2,4] becomes shape [4,2,1] - /// - /// If `order` is provided, it should be a vector of unique axis positions ranging - /// from 0 to N-1, when N is the length of the input shape. In this case, numpy_transpose - /// acts like dimshuffle, so - /// - /// shape [1,2,4] with order [1,2,0] becomes shape [2,4,1] - /// - /// | | Type | Description | - /// | ---------------- | ------------------------------------- | ------------------------------------------------------- | - /// | `node` | \f$E[d_0,\dots,d_{n-1}]~(n \geq 0)\f$ | An input tensor of any shape | - /// | `order` | AxisVector (empty default) | The axes to eliminate through reduction (0 indexed). | - /// - /// ## Output - /// - /// | Type | Description | - /// | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | - /// | \f$E[d_{n-1},\dots,d_0)]\textit{ or }E[d_{order[0]},\dots,d_{order[n-1]}]\f$ | The tensor \f$T\f$, where \f$T\f$ is the input tensor with the axes reordered via Numpy Transpose rules | - // clang-format on - NGRAPH_API - std::shared_ptr numpy_transpose(const Output& value, AxisVector order = {}); - } // namespace builder -} // namespace ngraph diff --git a/ngraph/src/ngraph/builder/quantize_builder.cpp b/ngraph/src/ngraph/builder/quantize_builder.cpp deleted file mode 100644 index e6db656..0000000 --- a/ngraph/src/ngraph/builder/quantize_builder.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 - -#include "ngraph/builder/quantize_builder.hpp" - -using namespace std; -using namespace ngraph; - -namespace ngraph -{ - namespace builder - { - shared_ptr QuantizeBuilder(const Output& input, - const Output& min, - const Output& max, - const ngraph::element::Type& quant_type, - const ngraph::AxisSet& axes, - op::Quantize::RoundMode round_mode) - { - auto real_type = input.get_element_type(); - - if (min.get_element_type() != real_type) - { - throw ngraph_error("QuantizeBuilder: min must match input type"); - } - - if (max.get_element_type() != real_type) - { - throw ngraph_error("QuantizeBuilder: max must match input type"); - } - - auto shape = min.get_shape(); - if (shape != max.get_shape()) - { - throw ngraph_error("QuantizeBuilder: min and max must have same shape"); - } - - auto zero = make_constant(quant_type, shape, 0); - auto scale = quantization_utils::get_scale(min, max, quant_type, true); - return make_shared(input, scale, zero, quant_type, axes, round_mode) - ->add_provenance_group_members_above({input, min, max}); - } - } -} diff --git a/ngraph/src/ngraph/builder/quantize_builder.hpp b/ngraph/src/ngraph/builder/quantize_builder.hpp deleted file mode 100644 index b1c54c3..0000000 --- a/ngraph/src/ngraph/builder/quantize_builder.hpp +++ /dev/null @@ -1,37 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 "ngraph/builder/make_constant.hpp" -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/quantize.hpp" -#include "quantization_utils.hpp" - -namespace ngraph -{ - namespace builder - { - NGRAPH_API - std::shared_ptr QuantizeBuilder(const Output& input, - const Output& min, - const Output& max, - const ngraph::element::Type& quant_type, - const ngraph::AxisSet& axes, - op::Quantize::RoundMode round_mode); - } -} diff --git a/ngraph/src/ngraph/builder/quantized_dot_builder.cpp b/ngraph/src/ngraph/builder/quantized_dot_builder.cpp deleted file mode 100644 index 13c4764..0000000 --- a/ngraph/src/ngraph/builder/quantized_dot_builder.cpp +++ /dev/null @@ -1,69 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 - -#include "ngraph/builder/quantized_dot_builder.hpp" - -using namespace std; -using namespace ngraph; - -namespace ngraph -{ - namespace builder - { - shared_ptr QuantizedDotBuilder(const Output& input0, - const Output& input1, - const size_t reduction_axes_count, - const Output& min_input0, - const Output& max_input0, - const Output& min_input1, - const Output& max_input1, - const Output& min_output, - const Output& max_output, - const ngraph::element::Type& output_type, - const ngraph::AxisSet& input0_axes, - const ngraph::AxisSet& input1_axes, - const ngraph::AxisSet& output_axes) - { - auto input0_scale = - quantization_utils::get_scale(min_input0, max_input0, input0.get_element_type()); - auto input1_scale = - quantization_utils::get_scale(min_input1, max_input1, input1.get_element_type()); - auto output_scale = quantization_utils::get_scale(min_output, max_output, output_type); - - // For Builders the zero point is assumed to be zero (for now) - auto input0_zero_point = op::Constant::create(input0.get_element_type(), Shape{}, {0}); - auto input1_zero_point = op::Constant::create(input1.get_element_type(), Shape{}, {0}); - auto output_zero_point = op::Constant::create(output_type, Shape{}, {0}); - - return make_shared(input0, - input1, - reduction_axes_count, - input0_scale, - input0_zero_point, - input1_scale, - input1_zero_point, - output_scale, - output_zero_point, - output_type, - input0_axes, - input1_axes, - output_axes) - ->add_provenance_group_members_above({input0, input1}); - } - } -} diff --git a/ngraph/src/ngraph/builder/quantized_dot_builder.hpp b/ngraph/src/ngraph/builder/quantized_dot_builder.hpp deleted file mode 100644 index 13bd686..0000000 --- a/ngraph/src/ngraph/builder/quantized_dot_builder.hpp +++ /dev/null @@ -1,45 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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 "ngraph/coordinate_diff.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/quantize.hpp" -#include "ngraph/op/quantized_dot.hpp" -#include "quantization_utils.hpp" - -namespace ngraph -{ - namespace builder - { - NGRAPH_API - std::shared_ptr QuantizedDotBuilder(const Output& input0, - const Output& input1, - const size_t reduction_axes_count, - const Output& min_input0, - const Output& max_input0, - const Output& min_input1, - const Output& max_input1, - const Output& min_output, - const Output& max_output, - const ngraph::element::Type& output_type, - const ngraph::AxisSet& input0_axes, - const ngraph::AxisSet& input1_axes, - const ngraph::AxisSet& output_axes); - } -} diff --git a/ngraph/src/ngraph/builder/tensor_mask.hpp b/ngraph/src/ngraph/builder/tensor_mask.hpp deleted file mode 100644 index e3383b4..0000000 --- a/ngraph/src/ngraph/builder/tensor_mask.hpp +++ /dev/null @@ -1,103 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 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/axis_set.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/convert.hpp" -#include "ngraph/op/less.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/shape.hpp" -#include "ngraph/util.hpp" - -namespace ngraph -{ - namespace builder - { - // batch_size = mask_shape on the batch_axis - // max_sequence_length = mask_shape on the sequence_axis - // sequence_lengths = list of lengths < max_sequence_length of shape batch_size - // a mask is created by... - // 1. creating a sequence starting at sequence_begin of shape max_sequence_length - // 2. broadcasting that sequence along all non-sequence axes to mask_shape - // 3. broadcasting sequence_lengths along all non-batch axes to mask_shape - // 4. returning the specified binary element-wise operation T #2 and #3 - template - std::shared_ptr tensor_mask(const std::shared_ptr& sequence_lengths, - size_t sequence_axis, - size_t batch_axis, - ngraph::Shape mask_shape, - uint32_t sequence_begin) - { - if (sequence_axis >= mask_shape.size()) - { - throw ngraph_error("Sequence axis must be in range 0..mask_shape rank"); - } - - if (batch_axis >= mask_shape.size()) - { - throw ngraph_error("Sequence axis must be in range 0..mask_shape rank"); - } - - // all axes except the sequence axis - ngraph::AxisSet non_sequence_axes; - // all axes except the batch axis - ngraph::AxisSet non_batch_axes; - - for (size_t axis = 0; axis < mask_shape.size(); ++axis) - { - if (axis != sequence_axis) - { - non_sequence_axes.insert(axis); - } - if (axis != batch_axis) - { - non_batch_axes.insert(axis); - } - } - - // broadcast sequence lengths to mask shape along all non-batch axes - auto broadcast_sequence_lengths = std::make_shared( - sequence_lengths, mask_shape, non_batch_axes); - - // create sequence data [0, ..., max_sequence_length] - auto max_sequence_length = mask_shape[sequence_axis]; - std::vector sequence_data(max_sequence_length); - std::iota(sequence_data.begin(), sequence_data.end(), sequence_begin); - - // create sequence constant - auto sequence = std::make_shared( - element::u32, Shape{max_sequence_length}, sequence_data); - - // convert sequence to input type - auto convert_sequence = std::make_shared( - sequence, sequence_lengths->get_element_type()); - - // broadcast sequence to mask shape along all non-sequence axes - auto broadcast_sequence = std::make_shared( - convert_sequence, mask_shape, non_sequence_axes); - - // mask = sequence_length < sequence - return std::make_shared(broadcast_sequence, broadcast_sequence_lengths) - ->add_provenance_group_members_above({sequence_lengths}); - } - } -} diff --git a/ngraph/src/ngraph/ngraph.hpp b/ngraph/src/ngraph/ngraph.hpp index 5f414a7..2ec215d 100644 --- a/ngraph/src/ngraph/ngraph.hpp +++ b/ngraph/src/ngraph/ngraph.hpp @@ -68,14 +68,8 @@ namespace ngraph #include "ngraph/attribute_adapter.hpp" #include "ngraph/attribute_visitor.hpp" #include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/dequantize_builder.hpp" -#include "ngraph/builder/numpy_transpose.hpp" -#include "ngraph/builder/quantize_builder.hpp" -#include "ngraph/builder/quantized_concat_builder.hpp" -#include "ngraph/builder/quantized_dot_builder.hpp" #include "ngraph/builder/reduce_ops.hpp" #include "ngraph/builder/reshape.hpp" -#include "ngraph/builder/tensor_mask.hpp" #include "ngraph/coordinate_transform.hpp" #include "ngraph/descriptor/input.hpp" #include "ngraph/descriptor/layout/dense_tensor_layout.hpp" diff --git a/ngraph/src/ngraph/runtime/reference/matmul.hpp b/ngraph/src/ngraph/runtime/reference/matmul.hpp index ce27d11..7f8c5df 100644 --- a/ngraph/src/ngraph/runtime/reference/matmul.hpp +++ b/ngraph/src/ngraph/runtime/reference/matmul.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include diff --git a/ngraph/test/backend/broadcast.in.cpp b/ngraph/test/backend/broadcast.in.cpp index 1513ea2..d90d5c0 100644 --- a/ngraph/test/backend/broadcast.in.cpp +++ b/ngraph/test/backend/broadcast.in.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/backend/builder_reduce_ops_opset1.in.cpp b/ngraph/test/backend/builder_reduce_ops_opset1.in.cpp index 1eb5794..d2f16a4 100644 --- a/ngraph/test/backend/builder_reduce_ops_opset1.in.cpp +++ b/ngraph/test/backend/builder_reduce_ops_opset1.in.cpp @@ -14,6 +14,8 @@ // limitations under the License. //***************************************************************************** +#include + #include "ngraph/ngraph.hpp" #include "util/engine/test_engines.hpp" #include "util/test_case.hpp" diff --git a/ngraph/test/backend/fused_op.in.cpp b/ngraph/test/backend/fused_op.in.cpp index 441a2e8..6e3f4f4 100644 --- a/ngraph/test/backend/fused_op.in.cpp +++ b/ngraph/test/backend/fused_op.in.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/backend/matmul.in.cpp b/ngraph/test/backend/matmul.in.cpp index 767f78e..cfb67bf 100644 --- a/ngraph/test/backend/matmul.in.cpp +++ b/ngraph/test/backend/matmul.in.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/backend/reduce_sum.in.cpp b/ngraph/test/backend/reduce_sum.in.cpp index a04c098..9d49ae6 100644 --- a/ngraph/test/backend/reduce_sum.in.cpp +++ b/ngraph/test/backend/reduce_sum.in.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/backend/reshape.in.cpp b/ngraph/test/backend/reshape.in.cpp index e00ada1..2517009 100644 --- a/ngraph/test/backend/reshape.in.cpp +++ b/ngraph/test/backend/reshape.in.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/backend/strided_slice.in.cpp b/ngraph/test/backend/strided_slice.in.cpp index 61cf3d8..192a0f5 100644 --- a/ngraph/test/backend/strided_slice.in.cpp +++ b/ngraph/test/backend/strided_slice.in.cpp @@ -14,6 +14,8 @@ // limitations under the License. //***************************************************************************** +#include + #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" #include "ngraph/runtime/tensor.hpp" diff --git a/ngraph/test/backend/sum.in.cpp b/ngraph/test/backend/sum.in.cpp index 42b8caa..0ed5d7a 100644 --- a/ngraph/test/backend/sum.in.cpp +++ b/ngraph/test/backend/sum.in.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/ngraph/test/builder.cpp b/ngraph/test/builder.cpp index 20a252d..a86b570 100644 --- a/ngraph/test/builder.cpp +++ b/ngraph/test/builder.cpp @@ -106,52 +106,3 @@ TEST(builder, variance) result = make_reduce_result_true(builder::variance); ASSERT_TRUE(test::all_close((vector{4, 4}), read_vector(result))); } - -TEST(builder, numpy_transpose) -{ - // 2D Transpose - Shape shape{2, 4}; - auto param = make_shared(element::f32, shape); - auto transposed = as_type_ptr(builder::numpy_transpose(param)); - EXPECT_EQ(Shape({4, 2}), transposed->get_output_shape(0)); - - // Multidimensional Transpose - shape = Shape{2, 4, 8}; - param = make_shared(element::f32, shape); - transposed = as_type_ptr(builder::numpy_transpose(param)); - EXPECT_EQ(Shape({8, 4, 2}), transposed->get_output_shape(0)); - - // Dimshuffle - shape = Shape{2, 4, 8}; - param = make_shared(element::f32, shape); - transposed = as_type_ptr(builder::numpy_transpose(param, AxisVector{2, 0, 1})); - EXPECT_EQ(Shape({8, 2, 4}), transposed->get_output_shape(0)); - - // Bad Orders - EXPECT_ANY_THROW(as_type_ptr(builder::numpy_transpose(param, AxisVector{2}))); - EXPECT_ANY_THROW( - as_type_ptr(builder::numpy_transpose(param, AxisVector{2, 2, 1}))); -} - -TEST(builder, tensor_mask) -{ - Shape max_sequence_length{3}; - auto sequence_lengths = make_shared(element::u32, max_sequence_length); - - Shape mask_shape{3, 5}; - auto f = - make_shared(builder::tensor_mask(sequence_lengths, 1, 0, mask_shape, 0), - ParameterVector{sequence_lengths}); - - auto backend = runtime::Backend::create("INTERPRETER"); - - auto sequence_lengths_data = backend->create_tensor(element::u32, max_sequence_length); - copy_data(sequence_lengths_data, vector{1, 3, 2}); - auto result = backend->create_tensor(element::boolean, mask_shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {sequence_lengths_data}); - vector expected{1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0}; - - EXPECT_EQ(expected, read_vector(result)); -} diff --git a/ngraph/test/builder_autobroadcast.cpp b/ngraph/test/builder_autobroadcast.cpp index bf4a1cc..7c45052 100644 --- a/ngraph/test/builder_autobroadcast.cpp +++ b/ngraph/test/builder_autobroadcast.cpp @@ -273,110 +273,6 @@ TEST(autobroadcast, numpy_broadcast_for_matmul_op_nop) EXPECT_EQ(result.at(1).get_shape(), (Shape{6, 5})); } -TEST(autobroadcast, legacy_broadcast_scalar) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{}; - size_t start_match_axis{3}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_1elem_tensor) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{1, 1, 1}; - size_t start_match_axis{1}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_1d) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{5}; - size_t start_match_axis{3}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_2d) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{4, 5}; - size_t start_match_axis{2}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_2d_inside) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{3, 4}; - size_t start_match_axis{1}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_1d_left) -{ - const Shape lhs{2, 3, 4, 5}; - const Shape rhs{2}; - size_t start_match_axis{0}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, rhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - -TEST(autobroadcast, legacy_broadcast_identical) -{ - const Shape lhs{2, 3, 4, 5}; - size_t start_match_axis{0}; - const auto lhs_node = make_shared(element::f32, lhs); - const auto rhs_node = make_shared(element::f32, lhs); - - const OutputVector result = - builder::legacy_broadcast_for_binary_operation(lhs_node, rhs_node, start_match_axis); - - EXPECT_EQ(result.at(0).get_shape(), lhs); - EXPECT_EQ(result.at(1).get_shape(), lhs); -} - TEST(autobroadcast, opset1_legacy_broadcast_scalar) { const Shape lhs{2, 3, 4, 5}; diff --git a/ngraph/test/coordinate.cpp b/ngraph/test/coordinate.cpp index 10bc0b4..78af9d9 100644 --- a/ngraph/test/coordinate.cpp +++ b/ngraph/test/coordinate.cpp @@ -15,6 +15,7 @@ //***************************************************************************** #include +#include #include #include "gtest/gtest.h" diff --git a/ngraph/test/onnx/onnx_import_convpool.in.cpp b/ngraph/test/onnx/onnx_import_convpool.in.cpp index b393bfd..2bc414a 100644 --- a/ngraph/test/onnx/onnx_import_convpool.in.cpp +++ b/ngraph/test/onnx/onnx_import_convpool.in.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/ngraph/test/onnx/onnx_import_quant.in.cpp b/ngraph/test/onnx/onnx_import_quant.in.cpp index 8bcc120..9b1cd2d 100644 --- a/ngraph/test/onnx/onnx_import_quant.in.cpp +++ b/ngraph/test/onnx/onnx_import_quant.in.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/ngraph/test/provenance.cpp b/ngraph/test/provenance.cpp index fcc1b5c..fd573f4 100644 --- a/ngraph/test/provenance.cpp +++ b/ngraph/test/provenance.cpp @@ -513,36 +513,6 @@ TEST(provenance, empty_group) } } -TEST(provenance, scaled_quantize_concat_unsigned) -{ - ngraph::Shape shape_a{2, 2}; - auto A = make_shared(ngraph::element::u8, shape_a); - auto An = make_shared(ngraph::element::f32, ngraph::Shape{1}); - auto Ax = make_shared(ngraph::element::f32, ngraph::Shape{1}); - A->add_provenance_tag("in0"); - An->add_provenance_tag("in1"); - Ax->add_provenance_tag("in2"); - ngraph::Shape shape_r{2, 2}; - auto QConcat = ngraph::builder::QuantizedConcatBuilder({A}, 0, {An}, {Ax}); - auto f = make_shared(ngraph::OutputVector{QConcat}, - ngraph::ParameterVector{A, An, Ax}); - QConcat->add_provenance_tag("hello"); - auto check_if_result = [](shared_ptr n) { - // Pointer will cast to nullptr if this node is not a Result - auto ng_node = dynamic_pointer_cast(n); - bool is_result = (ng_node != nullptr); - return is_result; - }; - - for (auto n : f->get_ordered_ops()) - { - if (!check_if_result(n)) - { - ASSERT_EQ(n->get_provenance_tags().size(), 1); - } - } -} - TEST(provenance, opset1_upgrade_pass_topk) { test::ProvenanceEnabler provenance_enabler; -- 2.7.4