From 82f4b8d02e68d35876986fe88835f00e4e81282c Mon Sep 17 00:00:00 2001 From: Patryk Elszkowski Date: Mon, 19 Apr 2021 08:30:54 +0200 Subject: [PATCH 01/78] Constant op backend test and fix for memory size calculation (#5231) * Fix memory size calculation in Tensor and HostTensor * Backend test for Constant operator * `read_raw_data` in constant.in.cpp yet another formula to calculate memory size in bytes Co-authored-by: Patryk Elszkowski --- ngraph/core/include/ngraph/op/constant.hpp | 30 ++++--- ngraph/core/src/descriptor/tensor.cpp | 6 ++ ngraph/core/src/runtime/host_tensor.cpp | 2 +- ngraph/test/backend/constant.in.cpp | 79 +++++++++++++++++++ .../test/runtime/dynamic/dynamic_backend.cpp | 2 + ngraph/test/runtime/ie/unit_test.manifest | 8 ++ 6 files changed, 115 insertions(+), 12 deletions(-) diff --git a/ngraph/core/include/ngraph/op/constant.hpp b/ngraph/core/include/ngraph/op/constant.hpp index 860a6979965..c5000dce48f 100644 --- a/ngraph/core/include/ngraph/op/constant.hpp +++ b/ngraph/core/include/ngraph/op/constant.hpp @@ -217,12 +217,11 @@ namespace ngraph /// \param shape The shape of the tensor constant. /// \param values A vector of values to use as the constant data. template - static std::shared_ptr - create(const element::Type& type, Shape shape, const std::vector values) + static std::shared_ptr create(const element::Type& type, + const Shape& shape, + const std::vector& values) { - auto result = std::make_shared(type, shape, values); - result->validate_and_infer_types(); - return result; + return std::make_shared(type, shape, values); } /// \brief Wrapper around constructing a shared_ptr of a Constant @@ -231,13 +230,22 @@ namespace ngraph /// \param shape The shape of the tensor constant. /// \param values An initializer_list of values to use as the constant data. template - static std::shared_ptr - create(const element::Type& type, Shape shape, std::initializer_list values) + static std::shared_ptr create(const element::Type& type, + const Shape& shape, + std::initializer_list values) { - auto result = - std::make_shared(type, shape, std::vector{values}); - result->validate_and_infer_types(); - return result; + return std::make_shared(type, shape, std::vector{values}); + } + + /// \brief Wrapper around constructing a shared_ptr of a Constant + /// + /// \param type The element type of the tensor constant. + /// \param shape The shape of the tensor constant. + /// \param memory An continues memory chunk which contains the constant data. + static std::shared_ptr + create(const element::Type& type, const Shape& shape, const void* memory) + { + return std::make_shared(type, shape, memory); } virtual std::shared_ptr diff --git a/ngraph/core/src/descriptor/tensor.cpp b/ngraph/core/src/descriptor/tensor.cpp index 9799bd83435..081fcbcf8be 100644 --- a/ngraph/core/src/descriptor/tensor.cpp +++ b/ngraph/core/src/descriptor/tensor.cpp @@ -93,6 +93,12 @@ const Shape& descriptor::Tensor::get_shape() const size_t descriptor::Tensor::size() const { + const bool bitwidth_less_than_byte = m_element_type.bitwidth() < 8; + if (bitwidth_less_than_byte) + { + // TODO consider caching this value + return ceil((1.0 * shape_size(get_shape()) * m_element_type.bitwidth()) / 8); + } return shape_size(get_shape()) * m_element_type.size(); } diff --git a/ngraph/core/src/runtime/host_tensor.cpp b/ngraph/core/src/runtime/host_tensor.cpp index e6b00155917..f1440640dd5 100644 --- a/ngraph/core/src/runtime/host_tensor.cpp +++ b/ngraph/core/src/runtime/host_tensor.cpp @@ -68,7 +68,7 @@ void runtime::HostTensor::allocate_buffer() NGRAPH_CHECK(get_element_type().is_static(), "Attempt to allocate buffer for tensor with dynamic type: ", get_element_type()); - m_buffer_size = shape_size(m_descriptor->get_shape()) * get_element_type().size(); + m_buffer_size = m_descriptor->size(); if (m_memory_pointer != nullptr) { m_aligned_buffer_pool = m_memory_pointer; diff --git a/ngraph/test/backend/constant.in.cpp b/ngraph/test/backend/constant.in.cpp index d60dc91345d..8666bd5cd92 100644 --- a/ngraph/test/backend/constant.in.cpp +++ b/ngraph/test/backend/constant.in.cpp @@ -176,3 +176,82 @@ NGRAPH_TEST(${BACKEND_NAME}, constant_equality_bool) handle->call_with_validate({result}, {}); EXPECT_EQ((vector{true, false, true, false}), read_vector(result)); } + +namespace +{ + std::vector read_raw_data(std::shared_ptr tv) + { + const size_t mem_size = tv->get_size_in_bytes(); + std::vector rc(mem_size); + tv->read(rc.data(), mem_size); + return rc; + } + + void run_constant_equality_for_low_precision(const Shape& shape, + const std::vector& data, + element::Type element_type) + { + const void* raw_data = data.data(); + auto A = op::Constant::create(element_type, shape, raw_data); + + const auto constant_raw_data = static_cast(A->get_data_ptr()); + EXPECT_EQ(std::memcmp(raw_data, constant_raw_data, data.size()), 0) + << "wrong data hold in Constant"; + + auto f = make_shared(A, ParameterVector{}); + + auto backend = runtime::Backend::create("${BACKEND_NAME}"); + + // Create some tensors for input/output + auto result = backend->create_tensor(element_type, shape); + + auto handle = backend->compile(f); + handle->call_with_validate({result}, {}); + EXPECT_EQ(data, read_raw_data(result)); + } +} + +NGRAPH_TEST(${BACKEND_NAME}, constant_equality_u4_2x2x3) +{ + const Shape shape{2, 2, 3}; + const std::vector data{0x12, 0x34, 0x56, 0x78, 0x9a, 0xFF}; + constexpr auto element_type = element::u4; + + run_constant_equality_for_low_precision(shape, data, element_type); +} + +NGRAPH_TEST(${BACKEND_NAME}, constant_equality_u4_1x3) +{ + const Shape shape{1, 3}; + const std::vector data{0x12, 0x34}; // last 8 bits constains rubbish + constexpr auto element_type = element::u4; + + run_constant_equality_for_low_precision(shape, data, element_type); +} + +NGRAPH_TEST(${BACKEND_NAME}, constant_equality_u4_1x10) +{ + const Shape shape{1, 10}; + const std::vector data{0x12, 0x34}; // last 6 bits constains rubbish + constexpr auto element_type = element::u1; + + run_constant_equality_for_low_precision(shape, data, element_type); +} + +NGRAPH_TEST(${BACKEND_NAME}, constant_equality_i4_2x2x3) +{ + const Shape shape{2, 2, 3}; + const std::vector data{0x12, 0x34, 0x56, 0x78, 0x9a, 0xFF}; + constexpr auto element_type = element::i4; + + run_constant_equality_for_low_precision(shape, data, element_type); +} + +NGRAPH_TEST(${BACKEND_NAME}, constant_equality_i4_1x3) +{ + const Shape shape{1, 3}; + const std::vector data{0x12, 0x34}; // last 8 bits constains rubbish + constexpr auto element_type = element::i4; + + run_constant_equality_for_low_precision(shape, data, element_type); +} diff --git a/ngraph/test/runtime/dynamic/dynamic_backend.cpp b/ngraph/test/runtime/dynamic/dynamic_backend.cpp index d70a111e6c6..c7efd915b9e 100644 --- a/ngraph/test/runtime/dynamic/dynamic_backend.cpp +++ b/ngraph/test/runtime/dynamic/dynamic_backend.cpp @@ -313,6 +313,8 @@ size_t runtime::dynamic::DynamicTensor::get_size_in_bytes() const { NGRAPH_CHECK(m_wrapped_tensor != nullptr, "asked for size in bytes of a dynamic tensor with no allocated storage"); + // TODO expand size calculation for type with bitwidth less than 8 like: + // m_wrapped_tensor->get_size_in_bytes() return get_element_count() * get_element_type().size(); } diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 394f63f487c..5bc3e7769f5 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -901,6 +901,14 @@ divide_python_rounding_int32 convert_int32_bool lesseq_int32 +# Constant and Low Precision +constant_equality_u4_2x2x3 +constant_equality_u4_1x3 +constant_equality_u4_1x10 +constant_equality_i4_2x2x3 +constant_equality_i4_1x3 + + # Uncategorized convolution_2d_1item convolution_2d_1item_padded_1_1x1_1 From 211c5773fcbe00bf9ff827119f06df430877dae4 Mon Sep 17 00:00:00 2001 From: Egor Shulman Date: Mon, 19 Apr 2021 10:15:59 +0300 Subject: [PATCH 02/78] [CPU] BatchToSpace, SpaceToBatch layers optimizations (#4029) * BatchToSpace, SpaceToBatch layers optimizations * Fix according to review * Fix tests for oneDNN (v1.6) * Fix of support BF16 * Fix in/out config * Add support of Blocked layout * Fix of support U8 * Add support for in/out channels of different sizes * Removed xfail * Removed xfail_issue_34327 * BatchToSpace, SpaceToBatch layers optimizations * Fix according to review * Fix according to review * 3 different implementations -> 1 implementation * Fix THROW * Fix Exception * Revert Batch_to_Space to parallel_for * Fix remarks * parallel_for -> parallel_nt * Fix remarks * Fix data separation * Fix according to review --- .../mkldnn_plugin/nodes/batch_to_space.cpp | 361 ++++++++--------- .../mkldnn_plugin/nodes/space_to_batch.cpp | 362 ++++++++++-------- .../cpu/single_layer_tests/batch_to_space.cpp | 179 +++++++++ .../cpu/single_layer_tests/space_to_batch.cpp | 164 ++++++++ ngraph/python/tests/__init__.py | 2 - .../tests/test_ngraph/test_ops_fused.py | 5 +- 6 files changed, 730 insertions(+), 343 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_batch.cpp diff --git a/inference-engine/src/mkldnn_plugin/nodes/batch_to_space.cpp b/inference-engine/src/mkldnn_plugin/nodes/batch_to_space.cpp index 40df2a1e35d..b33a9cbaee7 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/batch_to_space.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/batch_to_space.cpp @@ -3,13 +3,12 @@ // #include "base.hpp" +#include "ie_parallel.hpp" #include #include #include -#include #include -#include "ie_parallel.hpp" namespace InferenceEngine { namespace Extensions { @@ -17,205 +16,225 @@ namespace Cpu { class BatchToSpaceImpl: public ExtLayerBase { public: - explicit BatchToSpaceImpl(const CNNLayer* layer) { + explicit BatchToSpaceImpl(const CNNLayer *layer) { try { const auto batchToSpaceLayer = dynamic_cast(layer); if (!batchToSpaceLayer) - IE_THROW() << "'" << layer->name << "' layer is not instance of BatchToSpaceLayer class"; + IE_THROW() << "BatchToSpace layer with name '" << layer->name << "' isn't instance of BatchToSpaceLayer class"; - if (batchToSpaceLayer->insData.size() != 4 || batchToSpaceLayer->outData.size() != 1) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has incorrect number of input or output edges!"; + if (batchToSpaceLayer->insData.size() != 4) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has incorrect number of input edges"; - auto inData = batchToSpaceLayer->insData[0].lock(); - if (inData == nullptr) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has nullable input data"; + if (batchToSpaceLayer->outData.size() != 1) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has incorrect number of output edges"; - if (inData->getLayout() != NCHW && inData->getLayout() != NCDHW) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has unsupported layout: " << inData->getLayout(); + auto data = batchToSpaceLayer->insData[0].lock(); + if (!data) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has nullable input data"; - const auto precision = inData->getTensorDesc().getPrecision(); + inDims = data->getTensorDesc().getDims(); + if (inDims.size() < 4) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' doesn't support dimensions with rank less than 4"; + + if (inDims.size() > 5) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' doesn't support dimensions with rank greater than 5"; + + outDims = batchToSpaceLayer->outData[0]->getTensorDesc().getDims(); + if (inDims.size() != outDims.size()) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has incorrect number of input/output dimensions"; + + const auto precision = data->getTensorDesc().getPrecision(); const std::set supported_precision_sizes = {1, 2, 4, 8}; if (supported_precision_sizes.find(precision.size()) == supported_precision_sizes.end()) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has unsupported precision: " << precision.name(); + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has unsupported precision: " << precision.name(); - const SizeVector& in_dims = inData->getTensorDesc().getDims(); - const SizeVector& out_dims = layer->outData[0]->getTensorDesc().getDims(); - if (in_dims[1] != out_dims[1]) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has different IN and OUT channels number"; + blockShapeIn = batchToSpaceLayer->_block_shape; + cropsBeginIn = batchToSpaceLayer->_crops_begin; - _block_shape = batchToSpaceLayer->_block_shape; - _crops_begin = batchToSpaceLayer->_crops_begin; - _crops_end = batchToSpaceLayer->_crops_end; + auto createConfig = [&](Layout layout) { + LayerConfig config; + // TODO: remove Const layers + for (int i = 0; i < batchToSpaceLayer->insData.size(); i++) { + auto inData = batchToSpaceLayer->insData[i].lock(); + if (!inData) + IE_THROW() << "BatchToSpace layer with name '" << batchToSpaceLayer->name << "' has nullable input data"; + DataConfig inConfig; + if (i == 0) + inConfig.desc = TensorDesc(precision, inData->getTensorDesc().getDims(), layout); + else + inConfig.desc = TensorDesc(inData->getPrecision(), inData->getTensorDesc().getDims(), inData->getTensorDesc().getLayout()); + config.inConfs.push_back(inConfig); + } - LayerConfig config; - config.inConfs.resize(batchToSpaceLayer->insData.size()); - // TODO: remove Const layers - for (int i = 0; i < batchToSpaceLayer->insData.size(); i++) { - auto inData = batchToSpaceLayer->insData[i].lock(); - if (inData == nullptr) - IE_THROW() << "'" << batchToSpaceLayer->name << "' layer has nullable input data"; - config.inConfs[i].desc = TensorDesc(precision, - inData->getTensorDesc().getDims(), - inData->getTensorDesc().getLayout()); + DataConfig outConfig; + outConfig.desc = TensorDesc(precision, outDims, layout); + config.outConfs.push_back(outConfig); + + config.dynBatchSupport = false; + confs.push_back(config); + }; + + createConfig(inDims.size() == 4 ? NHWC : NDHWC); + createConfig(TensorDesc::getLayoutByDims(inDims)); + + std::vector> blockConfs { }; + if (inDims[1] % 8 == 0) blockConfs.push_back({ConfLayout::BLK8, ConfLayout::BLK8}); + if (inDims[1] % 16 == 0) blockConfs.push_back({ConfLayout::BLK16, ConfLayout::BLK16}); + for (auto conf : blockConfs) { + addConfig(layer, {DataConfigurator(conf.first, precision), + DataConfigurator(ConfLayout::PLN, batchToSpaceLayer->insData[1].lock()->getPrecision()), + DataConfigurator(ConfLayout::PLN, batchToSpaceLayer->insData[2].lock()->getPrecision()), + DataConfigurator(ConfLayout::PLN, batchToSpaceLayer->insData[3].lock()->getPrecision())}, + {DataConfigurator(conf.second, precision)}); } - - DataConfig outConfig; - outConfig.desc = TensorDesc(precision, - out_dims, - layer->outData[0]->getTensorDesc().getLayout()); - config.outConfs.push_back(outConfig); - config.dynBatchSupport = false; - confs.push_back(config); } catch (InferenceEngine::Exception &ex) { errorMsg = ex.what(); } } - - StatusCode execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept override { + StatusCode execute(std::vector &inputs, std::vector &outputs, ResponseDesc *resp) noexcept override { switch (inputs[0]->getTensorDesc().getPrecision().size()) { - case 1: { - process_data::value_type>(inputs, outputs); - break; - } - case 2: { - process_data::value_type>(inputs, outputs); - break; - } - case 4: { - process_data::value_type>(inputs, outputs); - break; - } - case 8: { - process_data::value_type>(inputs, outputs); - break; - } + case 1: batchToSpaceKernel::value_type> (inputs, outputs); break; + case 2: batchToSpaceKernel::value_type>(inputs, outputs); break; + case 4: batchToSpaceKernel::value_type>(inputs, outputs); break; default: { if (resp) { std::string errorMsg = "BatchToSpace layer does not support precision '" - + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; + + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); + return GENERAL_ERROR; } } } - return OK; } - template - void process_data(std::vector& inputs, std::vector& outputs) noexcept { - const T* src_data = inputs[0]->cbuffer().as() + - inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - T* dst_data = outputs[0]->buffer().as() + - outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - - const auto& inDims = inputs[0]->getTensorDesc().getDims(); - const size_t dims_size = inDims.size(); - const auto layout = inputs[0]->getTensorDesc().getLayout(); - - const size_t IB = inDims[0]; - const size_t IC = inDims[1]; - const size_t ID = layout == NCDHW ? inDims[dims_size - 3] : 1lu; - const size_t IH = inDims[dims_size - 2]; - const size_t IW = inDims[dims_size - 1]; - - const auto& outDims = outputs[0]->getTensorDesc().getDims(); - - const size_t OB = outDims[0]; - const size_t OC = outDims[1]; - const size_t OD = layout == NCDHW ? outDims[dims_size - 3] : 1lu; - const size_t OH = outDims[dims_size - 2]; - const size_t OW = outDims[dims_size - 1]; - - const int64_t cBSD = layout == NCDHW ? _block_shape[dims_size - 3] : 1lu; // Do not use name BSD. It affects MacOS build - const int64_t BSH = _block_shape[dims_size - 2]; - const int64_t BSW = _block_shape[dims_size - 1]; - - const size_t crop_front = layout == NCDHW ? _crops_begin[dims_size - 3] : 0lu; - const size_t crop_top = _crops_begin[dims_size - 2]; - const size_t crop_left = _crops_begin[dims_size - 1]; - - const size_t OH_OW = OH * OW; - const size_t OD_OH_OW = OD * OH_OW; - const size_t OC_OD_OH_OW = OC * OD_OH_OW; - const size_t IH_IW = IH * IW; - - const size_t work_amount = IB*IC*ID*IH*IW; - - auto thread_body = [&](const int ithr, const int nthr) { - size_t start(0lu), end(0lu); - splitter(work_amount, nthr, ithr, start, end); - if (start >= end) - return; - int64_t ib(0), ic(0), id(0), ih(0), iw(0); - parallel_it_init(start, ib, IB, ic, IC, id, ID, ih, IH, iw, IW); - - for (; ib < IB; ib++) { - const size_t ob = ib % OB; - const size_t ob_k = ob * OC_OD_OH_OW; - int64_t b_idx = ib / OB; - const int64_t ow_add = b_idx % BSW - crop_left; - b_idx /= BSW; - const int64_t oh_add = (layout == NCDHW ? b_idx % BSH : b_idx) - crop_top; - const int64_t od_add = layout == NCDHW ? (b_idx / BSH - crop_front) : 0; - for (; ic < IC; ic++) { - const size_t oc_k = ob_k + ic * OD_OH_OW; - for (; id < ID; id++) { - const int64_t od = id * cBSD + od_add; - if (od < 0 || od >= OD) { - start += IH_IW; - if (start >= end) - break; - continue; - } - const size_t od_k = oc_k + od * OH_OW; - for (; ih < IH; ih++) { - const int64_t oh = ih * BSH + oh_add; - if (oh < 0 || oh >= OH) { - start += IW; - if (start >= end) - break; - continue; - } - const size_t oh_k = od_k + oh * OW; - for (; iw < IW; iw++) { - const int64_t ow = iw * BSW + ow_add; - if (ow < 0 || ow >= OW) { - start++; - if (start >= end) - break; - continue; - } - const size_t dst_idx = oh_k + ow; - dst_data[dst_idx] = src_data[start]; - start++; - if (start >= end) - break; - } - if (start >= end) - break; - iw = 0; - } - if (start >= end) - break; - ih = 0; - } - if (start >= end) - break; - id = 0; - } - if (start >= end) - break; - ic = 0; - } - }; - - parallel_nt(0, thread_body); +private: + std::vector getShape5D(const SizeVector &shape) { + std::vector shape5D(5, 1); + for (int i = 0; i < 2; i++) { + shape5D[i] = shape[i]; + shape5D[4 - i] = shape[shape.size() - 1 - i]; + } + shape5D[2] = shape.size() == 5 ? shape[2] : shape5D[2]; + return shape5D; } -private: - std::vector _block_shape; - std::vector _crops_begin; - std::vector _crops_end; + template + void batchToSpaceKernel(std::vector &inputs, std::vector &outputs) noexcept { + const T *srcData = inputs[0]->cbuffer().as() + inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + T *dstData = outputs[0]->buffer().as() + outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + + const auto layout = inputs[0]->getTensorDesc().getLayout(); + const bool blocked = layout != NCHW && layout != NCDHW && layout != NHWC && layout != NDHWC; + const auto dimsSize = inDims.size(); + + auto inShape5D = getShape5D(inDims); + auto outShape5D = getShape5D(outDims); + auto blockShape = getShape5D(blockShapeIn); + + if (layout == NHWC || layout == NDHWC) { + inShape5D.push_back(inShape5D[1]); + inShape5D.erase(inShape5D.begin() + 1); + outShape5D.push_back(outShape5D[1]); + outShape5D.erase(outShape5D.begin() + 1); + blockShape.push_back(blockShape[1]); + blockShape.erase(blockShape.begin() + 1); + } + + const size_t blockSize = blocked ? outputs[0]->getTensorDesc().getBlockingDesc().getBlockDims().back() : 1lu; + const size_t blockCountInput = inputs[0]->getTensorDesc().getBlockingDesc().getBlockDims()[1]; + const size_t blockCountOutput = outputs[0]->getTensorDesc().getBlockingDesc().getBlockDims()[1]; + const auto blockRemainder = inShape5D[1] % blockSize; + const auto lastBlock = blockRemainder == 0 ? blockSize : blockRemainder; + + const size_t inSpatialStep = inShape5D[2] * inShape5D[3] * inShape5D[4]; + const size_t inBatchStep = (blocked ? blockSize * blockCountInput : inShape5D[1]) * inSpatialStep; + + const size_t outSpatialStep = outShape5D[2] * outShape5D[3] * outShape5D[4]; + const size_t outBatchStep = (blocked ? blockSize * blockCountOutput : outShape5D[1]) * outSpatialStep; + + size_t channels = (inShape5D[1] / blockSize); + channels = channels == 0 ? 1 : channels; + const size_t workAmount = inShape5D[0] * channels; + + parallel_nt(0, [&](const int ithr, const int nthr) { + size_t start(0lu), end(0lu); + splitter(workAmount, nthr, ithr, start, end); + std::vector indxStart(2, 0); + std::vector indxEnd(2, 0); + parallel_it_init(start, indxStart[0], inShape5D[0], indxStart[1], channels); + parallel_it_init((end - 1), indxEnd[0], inShape5D[0], indxEnd[1], channels); + std::vector oAdd(5, 1); + std::vector begin(5, 0); + std::vector finish(5, 1); + for (size_t i0 = indxStart[0]; i0 < indxEnd[0] + 1; ++i0) { + int64_t bIdx = i0 / outShape5D[0]; + const size_t srcIdx0 = i0 * inBatchStep; + const size_t dstIdx0 = (i0 - (bIdx * outShape5D[0])) * outBatchStep; + oAdd[4] = bIdx % blockShapeIn[dimsSize - 1] - cropsBeginIn[dimsSize - 1]; + bIdx /= blockShapeIn[dimsSize - 1]; + oAdd[3] = bIdx % blockShapeIn[dimsSize - 2] - cropsBeginIn[dimsSize - 2]; + bIdx /= blockShapeIn[dimsSize - 2]; + oAdd[2] = dimsSize == 5 ? bIdx % blockShapeIn[2] - cropsBeginIn[2] : 0lu; + bIdx = dimsSize == 5 ? bIdx / blockShapeIn[2] : bIdx; + oAdd[1] = bIdx % blockShapeIn[1] - cropsBeginIn[1]; + if (layout == NHWC || layout == NDHWC) { + oAdd.push_back(oAdd[1]); + oAdd.erase(oAdd.begin() + 1); + } + begin[1] = (blockShape[1] - 1 - oAdd[1]) / blockShape[1] / blockSize; + finish[1] = (outShape5D[1] - 1 - oAdd[1]) / blockShape[1] / blockSize; + begin[2] = (blockShape[2] - 1 - oAdd[2]) / blockShape[2]; + finish[2] = (outShape5D[2] - 1 - oAdd[2]) / blockShape[2]; + begin[3] = (blockShape[3] - 1 - oAdd[3]) / blockShape[3]; + finish[3] = (outShape5D[3] - 1 - oAdd[3]) / blockShape[3]; + begin[4] = (blockShape[4] - 1 - oAdd[4]) / blockShape[4]; + finish[4] = (outShape5D[4] - 1 - oAdd[4]) / blockShape[4]; + const int64_t addTmpOC = blocked ? 0lu : oAdd[1]; + const int64_t addTmpOc = blocked ? oAdd[1] : 0lu; + indxStart[1] = begin[1] > indxStart[1] ? begin[1] : indxStart[1]; + const size_t lastI1 = i0 == indxEnd[0] ? (indxEnd[1] > finish[1] ? finish[1] : indxEnd[1]) : finish[1]; + for (; indxStart[1] < lastI1 + 1; ++indxStart[1]) { + const size_t block = indxStart[1] == finish[1] ? lastBlock : blockSize; + const int64_t tmpOC = indxStart[1] * blockShape[1] + addTmpOC; + const size_t srcIdx1 = srcIdx0 + indxStart[1] * inSpatialStep * blockSize; + const size_t dstIdx1 = dstIdx0 + tmpOC * outSpatialStep * blockSize; + const size_t itEnd = blocked ? ((block - 1) * blockShape[1] + oAdd[1]) / blockSize : 0lu; + for (size_t i2 = begin[2]; i2 < finish[2] + 1; ++i2) { + const int64_t tmpOd = i2 * blockShape[2] + oAdd[2]; + const size_t srcIdx2 = srcIdx1 + i2 * inShape5D[3] * inShape5D[4] * blockSize; + const size_t dstIdx2 = dstIdx1 + tmpOd * outShape5D[3] * outShape5D[4] * blockSize; + for (size_t i3 = begin[3]; i3 < finish[3] + 1; ++i3) { + const int64_t tmpOh = i3 * blockShape[3] + oAdd[3]; + const size_t srcIdx3 = srcIdx2 + i3 * inShape5D[4] * blockSize; + const size_t dstIdx3 = dstIdx2 + tmpOh * outShape5D[4] * blockSize; + for (size_t i4 = begin[4]; i4 < finish[4] + 1; ++i4) { + const int64_t tmpOw = i4 * blockShape[4] + oAdd[4]; + const size_t srcIdx4 = srcIdx3 + i4 * blockSize; + const size_t dstIdx4 = dstIdx3 + tmpOw * blockSize; + for (size_t it = 0; it < itEnd + 1; ++it) { + const size_t i5Begin = it == 0 ? 0 : (it * blockSize - 1 - oAdd[1]) / blockShape[1] + 1; + const size_t i5End = it == itEnd ? (block - 1) : ((it + 1) * blockSize - 1 - oAdd[1]) / blockShape[1]; + for (size_t i5 = i5Begin; i5 < i5End + 1; ++i5) { + const int64_t tmpOc = i5 * blockShape[1] + addTmpOc; + const size_t srcIdx5 = srcIdx4 + i5; + const size_t dstIdx5 = dstIdx4 + it * outSpatialStep * blockSize + (tmpOc - it * blockSize); + dstData[dstIdx5] = srcData[srcIdx5]; + } + } + } + } + } + } + indxStart[1] = 0lu; + } + }); + } + + SizeVector inDims; + SizeVector outDims; + std::vector blockShapeIn; + std::vector cropsBeginIn; }; REG_FACTORY_FOR(BatchToSpaceImpl, BatchToSpace); diff --git a/inference-engine/src/mkldnn_plugin/nodes/space_to_batch.cpp b/inference-engine/src/mkldnn_plugin/nodes/space_to_batch.cpp index d3721b02595..24038d430bf 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/space_to_batch.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/space_to_batch.cpp @@ -9,7 +9,6 @@ #include #include #include -#include namespace InferenceEngine { namespace Extensions { @@ -21,47 +20,73 @@ public: try { auto spaceToBatchLayer = dynamic_cast(layer); if (!spaceToBatchLayer) - IE_THROW() << "'" << layer->name << "' layer is not instance of SpaceToBatchLayer class"; + IE_THROW() << "SpaceToBatch layer with name '" << layer->name << "' isn't instance of SpaceToBatchLayer class"; - if (spaceToBatchLayer->insData.size() != 4 || spaceToBatchLayer->outData.size() != 1) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has incorrect number of input or output edges!"; + if (spaceToBatchLayer->insData.size() != 4) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has incorrect number of input edges"; - auto inData = spaceToBatchLayer->insData[0].lock(); - if (inData == nullptr) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has nullable input data"; + if (spaceToBatchLayer->outData.size() != 1) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has incorrect number of output edges"; - if (inData->getLayout() != NCHW && inData->getLayout() != NCDHW) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has unsupported layout: " << inData->getLayout(); + auto data = spaceToBatchLayer->insData[0].lock(); + if (!data) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has nullable input data"; - const auto precision = inData->getTensorDesc().getPrecision(); + inDims = data->getTensorDesc().getDims(); + if (inDims.size() < 4) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' doesn't support dimensions with rank less than 4"; + + if (inDims.size() > 5) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' doesn't support dimensions with rank greater than 5"; + + outDims = spaceToBatchLayer->outData[0]->getTensorDesc().getDims(); + if (inDims.size() != outDims.size()) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has incorrect number of input/output dimensions"; + + const auto precision = data->getTensorDesc().getPrecision(); const std::set supported_precision_sizes = {1, 2, 4, 8}; if (supported_precision_sizes.find(precision.size()) == supported_precision_sizes.end()) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has unsupported precision: " << precision.name(); + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has unsupported precision: " << precision.name(); - const SizeVector& in_dims = inData->getTensorDesc().getDims(); - const SizeVector& out_dims = layer->outData[0]->getTensorDesc().getDims(); - if (in_dims[1] != out_dims[1]) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has different IN and OUT channels number"; + blockShapeIn = spaceToBatchLayer->_block_shape; + padsBeginIn = spaceToBatchLayer->_pads_begin; - _block_shape = spaceToBatchLayer->_block_shape; - _pads_begin = spaceToBatchLayer->_pads_begin; - _pads_end = spaceToBatchLayer->_pads_end; + auto createConfig = [&](Layout layout) { + LayerConfig config; + // TODO: remove Const layers + for (int i = 0; i < spaceToBatchLayer->insData.size(); i++) { + auto inData = spaceToBatchLayer->insData[i].lock(); + if (!inData) + IE_THROW() << "SpaceToBatch layer with name '" << spaceToBatchLayer->name << "' has nullable input data"; + DataConfig inConfig; + if (i == 0) + inConfig.desc = TensorDesc(precision, inData->getTensorDesc().getDims(), layout); + else + inConfig.desc = TensorDesc(inData->getPrecision(), inData->getTensorDesc().getDims(), inData->getTensorDesc().getLayout()); + config.inConfs.push_back(inConfig); + } - LayerConfig config; - config.inConfs.resize(spaceToBatchLayer->insData.size()); - // TODO: remove Const layers - for (int i = 0; i < spaceToBatchLayer->insData.size(); i++) { - auto inData = spaceToBatchLayer->insData[i].lock(); - if (inData == nullptr) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has nullable input data"; - config.inConfs[i].desc = TensorDesc(precision, inData->getTensorDesc().getDims(), inData->getTensorDesc().getLayout()); + DataConfig outConfig; + outConfig.desc = TensorDesc(precision, outDims, layout); + config.outConfs.push_back(outConfig); + + config.dynBatchSupport = false; + confs.push_back(config); + }; + + createConfig(inDims.size() == 4 ? NHWC : NDHWC); + createConfig(TensorDesc::getLayoutByDims(inDims)); + + std::vector> blockConfs { }; + if (inDims[1] % 8 == 0) blockConfs.push_back({ConfLayout::BLK8, ConfLayout::BLK8}); + if (inDims[1] % 16 == 0) blockConfs.push_back({ConfLayout::BLK16, ConfLayout::BLK16}); + for (auto conf : blockConfs) { + addConfig(layer, {DataConfigurator(conf.first, precision), + DataConfigurator(ConfLayout::PLN, spaceToBatchLayer->insData[1].lock()->getPrecision()), + DataConfigurator(ConfLayout::PLN, spaceToBatchLayer->insData[2].lock()->getPrecision()), + DataConfigurator(ConfLayout::PLN, spaceToBatchLayer->insData[3].lock()->getPrecision())}, + {DataConfigurator(conf.second, precision)}); } - - DataConfig outConfig; - outConfig.desc = TensorDesc(precision, out_dims, layer->outData[0]->getTensorDesc().getLayout()); - config.outConfs.push_back(outConfig); - config.dynBatchSupport = false; - confs.push_back(config); } catch (InferenceEngine::Exception &ex) { errorMsg = ex.what(); } @@ -69,27 +94,16 @@ public: StatusCode execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept override { switch (inputs[0]->getTensorDesc().getPrecision().size()) { - case 1: { - process_data::value_type>(inputs, outputs); - break; - } - case 2: { - process_data::value_type>(inputs, outputs); - break; - } - case 4: { - process_data::value_type>(inputs, outputs); - break; - } - case 8: { - process_data::value_type>(inputs, outputs); - break; - } + case 1: spaceToBatchKernel::value_type> (inputs, outputs); break; + case 2: spaceToBatchKernel::value_type>(inputs, outputs); break; + case 4: spaceToBatchKernel::value_type>(inputs, outputs); break; default: { if (resp) { - std::string errorMsg = "SpaceToBatch layer does not support precision '" - + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; + std::string errorMsg = "SpaceToBatch layer with name does not support precision '" + + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); + + return GENERAL_ERROR; } } } @@ -97,124 +111,139 @@ public: return OK; } - template - void process_data(std::vector& inputs, std::vector& outputs) noexcept { - const T* src_data = inputs[0]->cbuffer().as() + - inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - T* dst_data = outputs[0]->buffer().as() + - outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - - const auto& inDims = inputs[0]->getTensorDesc().getDims(); - const size_t dims_size = inDims.size(); - const auto layout = inputs[0]->getTensorDesc().getLayout(); - - const int64_t IB = inDims[0]; - const int64_t IC = inDims[1]; - const int64_t ID = layout == NCDHW ? inDims[dims_size - 3] : 1lu; - const int64_t IH = inDims[dims_size - 2]; - const int64_t IW = inDims[dims_size - 1]; - - const auto& outDims = outputs[0]->getTensorDesc().getDims(); - - const size_t OB = outDims[0]; - const size_t OC = outDims[1]; - const size_t OD = layout == NCDHW ? outDims[dims_size - 3] : 1lu; - const size_t OH = outDims[dims_size - 2]; - const size_t OW = outDims[dims_size - 1]; - - const int64_t cBSD = layout == NCDHW ? _block_shape[dims_size - 3] : 1lu; // Do not use name BSD. It affects MacOS build - const int64_t BSH = _block_shape[dims_size - 2]; - const int64_t BSW = _block_shape[dims_size - 1]; - - const int64_t PF = layout == NCDHW ? _pads_begin[dims_size - 3] : 0; - const int64_t PT = _pads_begin[dims_size - 2]; - const int64_t PL = _pads_begin[dims_size - 1]; - - const size_t OH_OW = OH * OW; - const size_t IH_IW = IH * IW; - const size_t ID_IH_IW = ID * IH_IW; - const size_t IC_ID_IH_IW = IC * ID_IH_IW; - - const size_t work_amount = OB*OC*OD*OH*OW; - - auto thread_body = [&](const int ithr, const int nthr) { - size_t start(0lu), end(0lu); - splitter(work_amount, nthr, ithr, start, end); - if (start >= end) - return; - int64_t ob(0), oc(0), od(0), oh(0), ow(0); - parallel_it_init(start, ob, OB, oc, OC, od, OD, oh, OH, ow, OW); - - for (; ob < OB; ob++) { - const int64_t ib = ob % IB; - const int64_t ib_k = ib * IC_ID_IH_IW; - int64_t bi = ob / IB; - const int64_t shift_w = bi % BSW - PL; - bi /= BSW; - const int64_t shift_h = (layout == NCDHW ? bi % BSH : bi) - PT; - const int64_t shift_d = layout == NCDHW ? (bi / BSH - PF) : 0; - for (; oc < OC; oc++) { - const int64_t ic_k = ib_k + oc * ID_IH_IW; - for (; od < OD; od++) { - const int64_t id = od * cBSD + shift_d; - if (id < 0 || id >= ID) { - std::fill(dst_data + start, dst_data + start + OH_OW, T(0)); - start += OH_OW; - if (start >= end) - break; - continue; - } - const int64_t id_k = ic_k + id * IH_IW; - for (; oh < OH; oh++) { - const int64_t ih = oh * BSH + shift_h; - if (ih < 0 || ih >= IH) { - std::fill(dst_data + start, dst_data + start + OW, T(0)); - start += OW; - if (start >= end) - break; - continue; - } - const int64_t ih_k = id_k + ih * IW; - for (; ow < OW; ow++) { - const int64_t iw = ow * BSW + shift_w; - if (iw < 0 || iw >= IW) { - dst_data[start] = T(0); - start++; - if (start >= end) - break; - continue; - } - const int64_t src_idx = ih_k + iw; - dst_data[start] = src_data[src_idx]; - start++; - if (start >= end) - break; - } - if (start >= end) - break; - ow = 0; - } - if (start >= end) - break; - oh = 0; - } - if (start >= end) - break; - od = 0; - } - if (start >= end) - break; - oc = 0; - } - }; - - parallel_nt(0, thread_body); +private: + std::vector getShape5D(const SizeVector &shape) { + std::vector shape5D(5, 1); + for (int i = 0; i < 2; i++) { + shape5D[i] = shape[i]; + shape5D[4 - i] = shape[shape.size() - 1 - i]; + } + shape5D[2] = shape.size() == 5 ? shape[2] : shape5D[2]; + return shape5D; } -private: - std::vector _block_shape; - std::vector _pads_begin; - std::vector _pads_end; + template + void spaceToBatchKernel(std::vector& inputs, std::vector& outputs) noexcept { + const T *srcData = inputs[0]->cbuffer().as() + inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + T *dstData = outputs[0]->buffer().as() + outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + + const auto layout = inputs[0]->getTensorDesc().getLayout(); + const bool blocked = layout != NCHW && layout != NCDHW && layout != NHWC && layout != NDHWC; + const auto dimsSize = inDims.size(); + + auto inShape5D = getShape5D(outDims); + auto outShape5D = getShape5D(inDims); + auto blockShape = getShape5D(blockShapeIn); + + if (layout == NHWC || layout == NDHWC) { + inShape5D.push_back(inShape5D[1]); + inShape5D.erase(inShape5D.begin() + 1); + outShape5D.push_back(outShape5D[1]); + outShape5D.erase(outShape5D.begin() + 1); + blockShape.push_back(blockShape[1]); + blockShape.erase(blockShape.begin() + 1); + } + + const size_t blockSize = blocked ? outputs[0]->getTensorDesc().getBlockingDesc().getBlockDims().back() : 1lu; + const size_t blockCountInput = outputs[0]->getTensorDesc().getBlockingDesc().getBlockDims()[1]; + const size_t blockCountOutput = inputs[0]->getTensorDesc().getBlockingDesc().getBlockDims()[1]; + const auto blockRemainder = inShape5D[1] % blockSize; + const auto lastBlock = blockRemainder == 0 ? blockSize : blockRemainder; + + const size_t inSpatialStep = inShape5D[2] * inShape5D[3] * inShape5D[4]; + const size_t inBatchStep = (blocked ? blockSize * blockCountInput : inShape5D[1]) * inSpatialStep; + + const size_t outSpatialStep = outShape5D[2] * outShape5D[3] * outShape5D[4]; + const size_t outBatchStep = (blocked ? blockSize * blockCountOutput : outShape5D[1]) * outSpatialStep; + + parallel_nt(0, [&](const int ithr, const int nthr) { + size_t start(0lu), end(0lu); + splitter(inShape5D[0] * inBatchStep, nthr, ithr, start, end); + std::fill(dstData + start, dstData + end, T(0)); + }); + + size_t channels = (inShape5D[1] / blockSize); + channels = channels == 0 ? 1 : channels; + const size_t workAmount = inShape5D[0] * channels; + + parallel_nt(0, [&](const int ithr, const int nthr) { + size_t start(0lu), end(0lu); + splitter(workAmount, nthr, ithr, start, end); + std::vector indxStart(2, 0); + std::vector indxEnd(2, 0); + parallel_it_init(start, indxStart[0], inShape5D[0], indxStart[1], channels); + parallel_it_init((end - 1), indxEnd[0], inShape5D[0], indxEnd[1], channels); + std::vector oAdd(5, 1); + std::vector begin(5, 0); + std::vector finish(5, 1); + for (size_t i0 = indxStart[0]; i0 < indxEnd[0] + 1; ++i0) { + int64_t bIdx = i0 / outShape5D[0]; + const size_t srcIdx0 = (i0 - (bIdx * outShape5D[0])) * outBatchStep; + const size_t dstIdx0 = i0 * inBatchStep; + oAdd[4] = bIdx % blockShapeIn[dimsSize - 1] - padsBeginIn[dimsSize - 1]; + bIdx /= blockShapeIn[dimsSize - 1]; + oAdd[3] = bIdx % blockShapeIn[dimsSize - 2] - padsBeginIn[dimsSize - 2]; + bIdx /= blockShapeIn[dimsSize - 2]; + oAdd[2] = dimsSize == 5 ? bIdx % blockShapeIn[2] - padsBeginIn[2] : 0lu; + bIdx = dimsSize == 5 ? bIdx / blockShapeIn[2] : bIdx; + oAdd[1] = bIdx % blockShapeIn[1] - padsBeginIn[1]; + if (layout == NHWC || layout == NDHWC) { + oAdd.push_back(oAdd[1]); + oAdd.erase(oAdd.begin() + 1); + } + begin[1] = (blockShape[1] - 1 - oAdd[1]) / blockShape[1] / blockSize; + finish[1] = (outShape5D[1] - 1 - oAdd[1]) / blockShape[1] / blockSize; + begin[2] = (blockShape[2] - 1 - oAdd[2]) / blockShape[2]; + finish[2] = (outShape5D[2] - 1 - oAdd[2]) / blockShape[2]; + begin[3] = (blockShape[3] - 1 - oAdd[3]) / blockShape[3]; + finish[3] = (outShape5D[3] - 1 - oAdd[3]) / blockShape[3]; + begin[4] = (blockShape[4] - 1 - oAdd[4]) / blockShape[4]; + finish[4] = (outShape5D[4] - 1 - oAdd[4]) / blockShape[4]; + const int64_t addTmpOC = blocked ? 0lu : oAdd[1]; + const int64_t addTmpOc = blocked ? oAdd[1] : 0lu; + indxStart[1] = begin[1] > indxStart[1] ? begin[1] : indxStart[1]; + const size_t lastI1 = i0 == indxEnd[0] ? (indxEnd[1] > finish[1] ? finish[1] : indxEnd[1]) : finish[1]; + for (; indxStart[1] < lastI1 + 1; ++indxStart[1]) { + const size_t block = indxStart[1] == finish[1] ? lastBlock : blockSize; + const int64_t tmpOC = indxStart[1] * blockShape[1] + addTmpOC; + const size_t srcIdx1 = srcIdx0 + tmpOC * outSpatialStep * blockSize; + const size_t dstIdx1 = dstIdx0 + indxStart[1] * inSpatialStep * blockSize; + const size_t itEnd = blocked ? ((block - 1) * blockShape[1] + oAdd[1]) / blockSize : 0lu; + for (size_t i2 = begin[2]; i2 < finish[2] + 1; ++i2) { + const int64_t tmpOd = i2 * blockShape[2] + oAdd[2]; + const size_t srcIdx2 = srcIdx1 + tmpOd * outShape5D[3] * outShape5D[4] * blockSize; + const size_t dstIdx2 = dstIdx1 + i2 * inShape5D[3] * inShape5D[4] * blockSize; + for (size_t i3 = begin[3]; i3 < finish[3] + 1; ++i3) { + const int64_t tmpOh = i3 * blockShape[3] + oAdd[3]; + const size_t srcIdx3 = srcIdx2 + tmpOh * outShape5D[4] * blockSize; + const size_t dstIdx3 = dstIdx2 + i3 * inShape5D[4] * blockSize; + for (size_t i4 = begin[4]; i4 < finish[4] + 1; ++i4) { + const int64_t tmpOw = i4 * blockShape[4] + oAdd[4]; + const size_t srcIdx4 = srcIdx3 + tmpOw * blockSize; + const size_t dstIdx4 = dstIdx3 + i4 * blockSize; + for (size_t it = 0; it < itEnd + 1; ++it) { + const size_t i5Begin = it == 0 ? 0 : (it * blockSize - 1 - oAdd[1]) / blockShape[1] + 1; + const size_t i5End = it == itEnd ? (block - 1) : ((it + 1) * blockSize - 1 - oAdd[1]) / blockShape[1]; + for (size_t i5 = i5Begin; i5 < i5End + 1; ++i5) { + const int64_t tmpOc = i5 * blockShape[1] + addTmpOc; + const size_t srcIdx5 = srcIdx4 + it * outSpatialStep * blockSize + (tmpOc - it * blockSize); + const size_t dstIdx5 = dstIdx4 + i5; + dstData[dstIdx5] = srcData[srcIdx5]; + } + } + } + } + } + } + indxStart[1] = 0lu; + } + }); + } + + SizeVector inDims; + SizeVector outDims; + std::vector blockShapeIn; + std::vector padsBeginIn; }; REG_FACTORY_FOR(SpaceToBatchImpl, SpaceToBatch); @@ -222,3 +251,4 @@ REG_FACTORY_FOR(SpaceToBatchImpl, SpaceToBatch); } // namespace Cpu } // namespace Extensions } // namespace InferenceEngine + diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp new file mode 100644 index 00000000000..425090ad5bf --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/batch_to_space.cpp @@ -0,0 +1,179 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "ngraph_functions/builders.hpp" +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::opset3; + +namespace CPULayerTestsDefinitions { + +typedef std::tuple< + LayerTestsDefinitions::batchToSpaceParamsTuple, + CPUSpecificParams> BatchToSpaceLayerCPUTestParamSet; + +class BatchToSpaceCPULayerTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + LayerTestsDefinitions::batchToSpaceParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = obj.param; + std::ostringstream result; + result << LayerTestsDefinitions::BatchToSpaceLayerTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + return result.str(); + } + +protected: + void SetUp() override { + LayerTestsDefinitions::batchToSpaceParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::vector inputShape; + std::vector blockShape, cropsBegin, cropsEnd; + InferenceEngine::Precision netPrecision; + std::tie(blockShape, cropsBegin, cropsEnd, inputShape, netPrecision, inPrc, outPrc, inLayout, outLayout, targetDevice) = basicParamsSet; + inPrc = outPrc = netPrecision; + + if (strcmp(netPrecision.name(), "U8") == 0) + selectedType = std::string("unknown_") + "I8"; + else + selectedType = std::string("unknown_") + netPrecision.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + auto paramOuts = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(params)); + auto b2s = ngraph::builder::makeBatchToSpace(paramOuts[0], ngPrc, blockShape, cropsBegin, cropsEnd); + b2s->get_rt_info() = getCPUInfo(); + ngraph::ResultVector results{std::make_shared(b2s)}; + function = std::make_shared(results, params, "BatchToSpace"); + } +}; + +TEST_P(BatchToSpaceCPULayerTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "BatchToSpace"); +}; + +namespace { + +const std::vector precisions = { + Precision::U8, + Precision::I8, + Precision::I32, + Precision::FP32, + Precision::BF16 +}; + +const std::vector> blockShape4D1 = {{1, 1, 1, 2}, {1, 2, 2, 1}, {1, 1, 2, 2}, {1, 2, 1, 2}}; +const std::vector> cropsBegin4D1 = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 2, 0}, {0, 0, 3, 3}}; +const std::vector> cropsEnd4D1 = {{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {0, 0, 1, 1}}; +const std::vector> inputShapes4D1 = {{4, 32, 15, 15}, {8, 16, 10, 10}, {16, 64, 13, 16}, {16, 16, 16, 10}}; + +const std::vector> blockShape4D2 = {{1, 2, 3, 4}, {1, 3, 4, 2}, {1, 4, 2, 3}}; +const std::vector> cropsBegin4D2 = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 2}}; +const std::vector> cropsEnd4D2 = {{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 3, 1}}; +const std::vector> inputShapes4D2 = {{48, 16, 7, 8}, {24, 32, 6, 6}, {24, 64, 9, 5}}; + +const std::vector cpuParams_4D = { + CPUSpecificParams({nChw16c}, {nChw16c}, {}, {}), + CPUSpecificParams({nChw8c}, {nChw8c}, {}, {}), + CPUSpecificParams({nhwc}, {nhwc}, {}, {}), + CPUSpecificParams({nchw}, {nchw}, {}, {}) +}; + +const auto batchToSpaceParamsSet4D1 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(std::vector>({blockShape4D1})), + ::testing::ValuesIn(std::vector>({cropsBegin4D1})), + ::testing::ValuesIn(std::vector>({cropsEnd4D1})), + ::testing::ValuesIn(std::vector> ({inputShapes4D1})), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(cpuParams_4D)); + +const auto batchToSpaceParamsSet4D2 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(std::vector>({blockShape4D2})), + ::testing::ValuesIn(std::vector>({cropsBegin4D2})), + ::testing::ValuesIn(std::vector>({cropsEnd4D2})), + ::testing::ValuesIn(std::vector> ({inputShapes4D2})), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(cpuParams_4D)); + +INSTANTIATE_TEST_CASE_P(smoke_BatchToSpaceCPULayerTestCase1_4D, BatchToSpaceCPULayerTest, + batchToSpaceParamsSet4D1, BatchToSpaceCPULayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_BatchToSpaceCPULayerTestCase2_4D, BatchToSpaceCPULayerTest, + batchToSpaceParamsSet4D2, BatchToSpaceCPULayerTest::getTestCaseName); + +const std::vector> blockShape5D1 = {{1, 1, 1, 1, 2}, {1, 1, 2, 2, 1}, {1, 1, 1, 2, 2}, {1, 2, 1, 1, 2}}; +const std::vector> cropsBegin5D1 = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 1}, {0, 0, 1, 2, 0}, {0, 0, 2, 3, 3}}; +const std::vector> cropsEnd5D1 = {{0, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 1}, {0, 0, 2, 1, 1}}; +const std::vector> inputShapes5D1 = {{4, 32, 8, 10, 8}, {8, 16, 5, 10, 10}, {16, 32, 6, 12, 12}, {16, 16, 10, 8, 12}}; + +const std::vector> blockShape5D2 = {{1, 2, 4, 3, 1}, {1, 2, 1, 3, 4}, {1, 1, 2, 4, 3}}; +const std::vector> cropsBegin5D2 = {{0, 0, 0, 0, 0}, {0, 0, 1, 2, 0}, {0, 0, 1, 0, 1}}; +const std::vector> cropsEnd5D2 = {{0, 0, 0, 0, 0}, {0, 0, 1, 0, 1}, {0, 0, 1, 1, 1}}; +const std::vector> inputShapes5D2 = {{48, 16, 3, 3, 3}, {24, 32, 5, 3, 5}, {24, 16, 7, 6, 4}}; + +const std::vector cpuParams_5D = { + CPUSpecificParams({nCdhw16c}, {nCdhw16c}, {}, {}), + CPUSpecificParams({nCdhw8c}, {nCdhw8c}, {}, {}), + CPUSpecificParams({ndhwc}, {ndhwc}, {}, {}), + CPUSpecificParams({ncdhw}, {ncdhw}, {}, {}) +}; + +const auto batchToSpaceParamsSet5D1 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(blockShape5D1), + ::testing::ValuesIn(cropsBegin5D1), + ::testing::ValuesIn(cropsEnd5D1), + ::testing::ValuesIn(inputShapes5D1), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(cpuParams_5D)); + +const auto batchToSpaceParamsSet5D2 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(blockShape5D2), + ::testing::ValuesIn(cropsBegin5D2), + ::testing::ValuesIn(cropsEnd5D2), + ::testing::ValuesIn(inputShapes5D2), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(cpuParams_5D)); + +INSTANTIATE_TEST_CASE_P(smoke_BatchToSpaceCPULayerTestCase1_5D, BatchToSpaceCPULayerTest, + batchToSpaceParamsSet5D1, BatchToSpaceCPULayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_BatchToSpaceCPULayerTestCase2_5D, BatchToSpaceCPULayerTest, + batchToSpaceParamsSet5D2, BatchToSpaceCPULayerTest::getTestCaseName); + +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_batch.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_batch.cpp new file mode 100644 index 00000000000..3677b889bfb --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_batch.cpp @@ -0,0 +1,164 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "ngraph_functions/builders.hpp" +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::opset3; + +namespace CPULayerTestsDefinitions { + +typedef std::tuple< + LayerTestsDefinitions::spaceToBatchParamsTuple, + CPUSpecificParams> SpaceToBatchLayerCPUTestParamSet; + +class SpaceToBatchCPULayerTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + LayerTestsDefinitions::spaceToBatchParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::SpaceToBatchLayerTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + + result << CPUTestsBase::getTestCaseName(cpuParams); + + return result.str(); + } + +protected: + void SetUp() override { + LayerTestsDefinitions::spaceToBatchParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = this->GetParam(); + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + + std::vector inputShape; + std::vector blockShape, padsBegin, padsEnd; + InferenceEngine::Precision netPrecision; + std::tie(blockShape, padsBegin, padsEnd, inputShape, netPrecision, inPrc, outPrc, inLayout, outLayout, targetDevice) = basicParamsSet; + inPrc = outPrc = netPrecision; + + if (strcmp(netPrecision.name(), "U8") == 0) + selectedType = std::string("unknown_") + "I8"; + else + selectedType = std::string("unknown_") + netPrecision.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + auto paramOuts = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(params)); + auto s2b = ngraph::builder::makeSpaceToBatch(paramOuts[0], ngPrc, blockShape, padsBegin, padsEnd); + s2b->get_rt_info() = getCPUInfo(); + ngraph::ResultVector results{std::make_shared(s2b)}; + function = std::make_shared(results, params, "SpaceToBatch"); + } +}; + +TEST_P(SpaceToBatchCPULayerTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "SpaceToBatch"); +}; + +namespace { + +const std::vector precisions = { + Precision::U8, + Precision::I8, + Precision::I32, + Precision::FP32, + Precision::BF16 +}; + +const std::vector> blockShape4D1 = {{1, 2, 1, 2}, {1, 1, 2, 2}, {1, 2, 2, 1}, {1, 2, 2, 2}}; +const std::vector> cropsBegin4D1 = {{0, 0, 0, 1}, {0, 0, 2, 1}, {0, 0, 4, 1}, {0, 0, 4, 3}}; +const std::vector> cropsEnd4D1 = {{0, 0, 0, 1}, {0, 0, 2, 1}, {0, 0, 4, 1}, {0, 0, 2, 3}}; +const std::vector> inputShapes4D1 = {{1, 16, 8, 12}, {1, 32, 8, 8}, {1, 16, 4, 4}, {2, 32, 16, 8}}; + +const std::vector> blockShape4D2 = {{1, 2, 4, 1}, {1, 2, 4, 3}, {1, 4, 4, 1}}; +const std::vector> cropsBegin4D2 = {{0, 0, 0, 0}, {0, 0, 4, 3}, {0, 0, 0, 3}}; +const std::vector> cropsEnd4D2 = {{0, 0, 0, 0}, {0, 0, 4, 0}, {0, 0, 4, 3} }; +const std::vector> inputShapes4D2 = {{1, 16, 8, 12}, {1, 16, 12, 15}, {1, 32, 4, 9} }; + +const std::vector cpuParams_4D = { + CPUSpecificParams({nChw16c}, {nChw16c}, {}, {}), + CPUSpecificParams({nChw8c}, {nChw8c}, {}, {}), + CPUSpecificParams({nhwc}, {nhwc}, {}, {}), + CPUSpecificParams({nchw}, {nchw}, {}, {}) +}; + +const auto spaceToBatchParamsSet4D1 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(blockShape4D1), + ::testing::ValuesIn(cropsBegin4D1), + ::testing::ValuesIn(cropsEnd4D1), + ::testing::ValuesIn(inputShapes4D1), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(cpuParams_4D)); + +const auto spaceToBatchParamsSet4D2 = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(blockShape4D2), + ::testing::ValuesIn(cropsBegin4D2), + ::testing::ValuesIn(cropsEnd4D2), + ::testing::ValuesIn(inputShapes4D2), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(cpuParams_4D)); + +INSTANTIATE_TEST_CASE_P(smoke_SpaceToBatchCPULayerTestCase1_4D, SpaceToBatchCPULayerTest, + spaceToBatchParamsSet4D1, SpaceToBatchCPULayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_SpaceToBatchCPULayerTestCase2_4D, SpaceToBatchCPULayerTest, + spaceToBatchParamsSet4D2, SpaceToBatchCPULayerTest::getTestCaseName); + +const std::vector> blockShape5D = {{1, 1, 4, 3, 1}, {1, 1, 2, 1, 3}, {1, 2, 4, 1, 1}, {1, 2, 2, 3, 3}}; +const std::vector> cropsBegin5D = {{0, 0, 1, 0, 0}, {0, 0, 1, 0, 3}, {0, 0, 5, 3, 3}, {0, 0, 5, 6, 3}}; +const std::vector> cropsEnd5D = {{0, 0, 1, 0, 0}, {0, 0, 1, 0, 3}, {0, 0, 5, 3, 3}, {0, 0, 5, 6, 3}}; +const std::vector> inputShapes5D = {{2, 16, 6, 6, 12}, {2, 16, 10, 9, 9}, {1, 32, 10, 6, 6}, {1, 32, 6, 9, 6}}; + +const std::vector cpuParams_5D = { + CPUSpecificParams({nCdhw16c}, {nCdhw16c}, {}, {}), + CPUSpecificParams({nCdhw8c}, {nCdhw8c}, {}, {}), + CPUSpecificParams({ndhwc}, {ndhwc}, {}, {}), + CPUSpecificParams({ncdhw}, {ncdhw}, {}, {}) +}; + +const auto spaceToBatchParamsSet5D = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(blockShape5D), + ::testing::ValuesIn(cropsBegin5D), + ::testing::ValuesIn(cropsEnd5D), + ::testing::ValuesIn(inputShapes5D), + ::testing::ValuesIn(precisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(cpuParams_5D)); + +INSTANTIATE_TEST_CASE_P(smoke_SpaceToBatchCPULayerTestCase1_5D, SpaceToBatchCPULayerTest, + spaceToBatchParamsSet5D, SpaceToBatchCPULayerTest::getTestCaseName); + +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/ngraph/python/tests/__init__.py b/ngraph/python/tests/__init__.py index 1ccfdb7cf61..11a10eb505b 100644 --- a/ngraph/python/tests/__init__.py +++ b/ngraph/python/tests/__init__.py @@ -46,8 +46,6 @@ xfail_issue_33644 = xfail_test(reason="RuntimeError: nGraph does not support the "Compress") xfail_issue_33651 = xfail_test(reason="RuntimeError: nGraph does not support the following ONNX operations:" "TfIdfVectorizer") -xfail_issue_34327 = xfail_test(reason="RuntimeError: '' layer has different " - "IN and OUT channels number") xfail_issue_33581 = xfail_test(reason="RuntimeError: nGraph does not support the following ONNX operations:" "GatherElements") xfail_issue_33633 = xfail_test(reason="MaxPool: dilations unsupported") diff --git a/ngraph/python/tests/test_ngraph/test_ops_fused.py b/ngraph/python/tests/test_ngraph/test_ops_fused.py index 121cae2b157..40d92a24bd2 100644 --- a/ngraph/python/tests/test_ngraph/test_ops_fused.py +++ b/ngraph/python/tests/test_ngraph/test_ops_fused.py @@ -6,8 +6,7 @@ import pytest import ngraph as ng from tests.runtime import get_runtime -from tests import (xfail_issue_34327, - xfail_issue_36485, +from tests import (xfail_issue_36485, xfail_issue_36486, xfail_issue_36487, xfail_issue_44976) @@ -135,7 +134,6 @@ def test_depth_to_space(): assert np.allclose(result, expected) -@xfail_issue_34327 def test_space_to_batch(): runtime = get_runtime() @@ -172,7 +170,6 @@ def test_space_to_batch(): assert np.allclose(result, expected) -@xfail_issue_34327 def test_batch_to_space(): runtime = get_runtime() From b751683c826acc12cd454cebf3f9844559250b00 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Mon, 19 Apr 2021 10:24:26 +0300 Subject: [PATCH 03/78] Fixed macOS compilation (#5283) * Fixed macOS compilation * Added -Wno-undef --- ngraph/python/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph/python/CMakeLists.txt b/ngraph/python/CMakeLists.txt index ff54b570bce..abb1078689f 100644 --- a/ngraph/python/CMakeLists.txt +++ b/ngraph/python/CMakeLists.txt @@ -66,9 +66,9 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options(-Wno-error=attributes) endif() -if(CMAKE_COMPILER_IS_GNUCXX AND Python_VERSION VERSION_GREATER_EQUAL "3.9") +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND Python_VERSION VERSION_GREATER_EQUAL "3.9") # for proper fix need to update pybind to version which does not use PyEval_InitThreads() - add_compile_options(-Wno-deprecated-declarations) + add_compile_options(-Wno-deprecated-declarations -Wno-undef) endif() # create target From b92fa8f303146f50ba6ad70f4be9dbfac9941248 Mon Sep 17 00:00:00 2001 From: Sergey Lyubimtsev Date: Mon, 19 Apr 2021 12:50:57 +0300 Subject: [PATCH 04/78] Add benchmark app to openvino-dev package (#5135) * Add openvino-tools package (benchmark_app) * Add openvino-tools package (benchmark_app) * entry point for benchmark_app * use find_namespace_packages to search * Add progress package in openvino-dev requirements list * Define Apache Software License license, add openvino to install_requires * remove unused module --- .../wheel/meta/openvino-dev.requirements.txt | 1 + .../python/wheel/meta/openvino-dev.setup.cfg | 1 + .../ie_bridges/python/wheel/setup.py | 8 ++-- tools/setup.py | 47 +++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tools/setup.py diff --git a/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.requirements.txt b/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.requirements.txt index 487eac4ce12..bc34674c2bd 100644 --- a/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.requirements.txt +++ b/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.requirements.txt @@ -25,3 +25,4 @@ fast-ctc-decode>=0.2 rawpy>=0.15 nltk>=3.5 opencv-python>=4.4 +progress==1.5 diff --git a/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.setup.cfg b/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.setup.cfg index 77c423416ba..d62a5f35939 100644 --- a/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.setup.cfg +++ b/inference-engine/ie_bridges/python/wheel/meta/openvino-dev.setup.cfg @@ -17,6 +17,7 @@ console_scripts = pot=app.run:main accuracy_check=accuracy_checker.main:main convert_annotation=accuracy_checker.annotation_converters.convert:main + benchmark_app=openvino.tools.benchmark.main:main [metadata] license_files = diff --git a/inference-engine/ie_bridges/python/wheel/setup.py b/inference-engine/ie_bridges/python/wheel/setup.py index 6f03554ffeb..3da64391d26 100644 --- a/inference-engine/ie_bridges/python/wheel/setup.py +++ b/inference-engine/ie_bridges/python/wheel/setup.py @@ -11,7 +11,7 @@ from distutils.command.install import install from distutils.command.build import build from distutils.errors import DistutilsSetupError from distutils.file_util import copy_file -from setuptools import setup, find_packages, Extension +from setuptools import setup, find_namespace_packages, Extension from setuptools.command.build_ext import build_ext from setuptools.command.build_clib import build_clib from decouple import config @@ -225,10 +225,10 @@ def set_rpath(rpath, executable): rpath_tool = "" if sys.platform == "linux": rpath_tool = "patchelf" - cmd = [rpath_tool, "--set-rpath", rpath, executable] + cmd = [rpath_tool, "--set-rpath", rpath, executable] elif sys.platform == "darwin": rpath_tool = "install_name_tool" - cmd = [rpath_tool, "-add_rpath", rpath, executable] + cmd = [rpath_tool, "-add_rpath", rpath, executable] else: sys.exit(f"Unsupported platform: {sys.platform}") @@ -316,7 +316,7 @@ package_license = config('WHEEL_LICENSE', '') if os.path.exists(package_license): copyfile(package_license, "LICENSE") -packages = find_packages(','.join(get_dir_list(PY_INSTALL_CFG))) +packages = find_namespace_packages(','.join(get_dir_list(PY_INSTALL_CFG))) package_data = {} setup( diff --git a/tools/setup.py b/tools/setup.py new file mode 100644 index 00000000000..87b00e23dba --- /dev/null +++ b/tools/setup.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +""" +Use this script to create a wheel with OpenVINO™ Python* tools: + +$ python setup.py sdist bdist_wheel +""" +from setuptools import setup, find_packages + +with open('README.md', 'r', encoding='utf-8') as f: + long_description = f.read() + +with open('benchmark/requirements.txt') as f: + required = f.read().splitlines() +required.extend(['openvino']) + +pkgs = find_packages() +NAMESPACE = 'openvino.tools' + +setup( + name='openvino-tools', + version='0.0.0', + author='Intel® Corporation', + license='OSI Approved :: Apache Software License', + author_email='openvino_pushbot@intel.com', + url='https://github.com/openvinotoolkit/openvino', + description='OpenVINO™ Python* tools package', + long_description=long_description, + long_description_content_type='text/markdown', + entry_points={ + 'console_scripts': [ + 'benchmark_app = openvino.tools.benchmark.main:main'], + }, + classifiers=[ + 'Programming Language :: Python :: 3', + 'OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + ], + package_dir={''.join((NAMESPACE, '.', pkg)) : pkg.replace('.', '/') + for pkg in pkgs}, + packages=[''.join((NAMESPACE, '.', pkg)) for pkg in pkgs], + install_requires=required, + python_requires='>=3.6', +) From ef70e5187c3374a92616f1ff9a985e89a960238f Mon Sep 17 00:00:00 2001 From: Jozef Daniecki Date: Mon, 19 Apr 2021 13:12:09 +0200 Subject: [PATCH 05/78] Deformable convolution (#4312) * Add deformable_convolution unit tests * add 2D unit test * Add unit-tests for 3D deformable_convolution * create shared test class for deformable_convolution * create single layer test for cpu plugin * create single layer test for serialization * add deformable_convolution to opset1 * create empty evaluate method * add group and deformable_group to parameters * Create impl for generateInput method * add deformable_val to deformable_conv paramset * create additional unit-tests * Remove 3D single layer tests * Update GenerateInput and SetUp method * Update parameters values for SLT * Update GenerateInput method and create Validate method * Create additional parameters set for cpu plugin SLT * Create unit-test with padding and add it to disabled * add interpreter unit tests to manifest * style-apply * create file for reference impl * Update year of copyright and make Validate an override method * Update parameters names for serialization single layer tests * Update parameters names for functional single layer tests * add failing unit tests for interpreter to manifest * make tests parameters more readable * style-apply * Include deformable_convolution inside evaluates_map * add support for groups parameter for reference impl * style-apply * remove DeformableConvolutionParams struct * fix bug with filter * fix bug with offset type * Update interpreter manifest * impl evalute method * style-apply * Update year * Update test names * add utils func for deformable convolution operation * fix filter group count * add calculation of index of offset * Update offsets in unit test * add support for multiple input channels * add padding tests * add padding support * style apply * update copyright year * create validation check helper * Update convolve function name * update copyright year * style-apply * remove integer type from serialize layer tests * add tests for deformable_groups * fix bug with group > 1 * style-apply * add group unit test * create additional group tests * fix bug with groups attribute * Enhance dynamic shape inference of validate and infer types method * Add type_prop unit tests * Fix broken op create test in python api * fix bug with shapes in group tests * update deformable_convolution method * add unit test with 2 groups and 2 defromable groups * Fix code style. * Update UT manifests with current test status. * Refactored backend test: names, removed duplication, add TOODs * Add missing test cases in 'integral offsets' group. * Fixed group attribute. * Update interprer manifest to disable tests with integer offsets. * Fix style. * Remove changes in operator class. * Revert "Enhance dynamic shape inference of validate and infer types method" This reverts commit 2f9ce2ccd4e9a7b1143ebe497015972c0922e8aa. * Revert "Add type_prop unit tests" This reverts commit 944af98b8c5f4a5055c26f7585b93b34dc74055e. * Revert "Fix broken op create test in python api" This reverts commit 72fbfc29679fd719b0f3cad74701d443a1ee51bb. * Fix op class. * Convert implementation to 2D. * Simplify implementation. * Fix centos build. * Reimplemented offsets handling. * Fixed integral offsets test cases. * Fixed deformable group attribute. * Add bilinear interpolation. * Refactoring regarding tolerance_bits. * Fix groups & def_groups test case. * Add more unit tests for group & defgroup attribute. * Remove debug code. * Minor refactoring. * Add integer types to SLT. * Revert "Add integer types to SLT." This reverts commit 2fefe8926da65171f64a2dc679ab548415736213. * Add tests with real number offsets. * Refactored bilinear_interpolation(). * Turned on SLT. Additionally refactored and offset input set to range <0,2>. * Update headers with short version. * Fix SLT offests generation with int offsets. * Add integer types to SLT. * Fix grup + def_group test case. * Add ticket to address IE_CPU backend test failures * Enable real resolution for deformable values * Add op to list of trusted operations in python script * Fix comparison of integer expressions of different signedness compilation error * Add comment with closing namespace and empty lines Co-authored-by: pszmel Co-authored-by: ggalieroc --- .../single_layer/deformable_convolution.cpp | 68 + .../deformable_convolution.cpp | 92 + .../deformable_convolution.hpp | 15 + .../single_layer/deformable_convolution.hpp | 53 + .../single_layer/deformable_convolution.cpp | 84 + .../layer_tests_summary/summarize.py | 1 + .../reference/deformable_convolution.hpp | 234 ++ ngraph/core/src/op/deformable_convolution.cpp | 9 +- ngraph/test/CMakeLists.txt | 1 + .../backend/deformable_convolution.in.cpp | 2622 +++++++++++++++++ ngraph/test/runtime/ie/unit_test.manifest | 11 + .../runtime/interpreter/evaluates_map.cpp | 32 + .../runtime/interpreter/opset_int_tbl.hpp | 1 + ngraph/test/type_prop/convolution.cpp | 80 - .../test/type_prop/deformable_convolution.cpp | 88 +- 15 files changed, 3305 insertions(+), 86 deletions(-) create mode 100644 inference-engine/tests/functional/inference_engine/serialization/single_layer/deformable_convolution.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/deformable_convolution.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/deformable_convolution.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/src/single_layer/deformable_convolution.cpp create mode 100644 ngraph/core/reference/include/ngraph/runtime/reference/deformable_convolution.hpp create mode 100644 ngraph/test/backend/deformable_convolution.in.cpp diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/deformable_convolution.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/deformable_convolution.cpp new file mode 100644 index 00000000000..99b6f398d5f --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/deformable_convolution.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "shared_test_classes/single_layer/deformable_convolution.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +TEST_P(DeformableConvolutionLayerTest, Serialize) { + Serialize(); +} + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16, + InferenceEngine::Precision::I32, InferenceEngine::Precision::I16}; +const std::vector> offsets = {{1, 18, 28, 28}}; +const std::vector> filters = {{1, 1, 3, 3}}; +const std::vector> strides = {{1, 1}}; +const std::vector> padBegins = {{0, 0}}; +const std::vector> padEnds ={{0, 0}}; +const std::vector> dilations = {{1, 1}}; +const std::vector groups = {1}; +const std::vector defor_groups = {1}; +const std::vector numOutChannels = {1}; + +const auto conv2DParams_ExplicitPadding = ::testing::Combine( + ::testing::ValuesIn(offsets), ::testing::ValuesIn(filters), + ::testing::ValuesIn(strides), ::testing::ValuesIn(padBegins), + ::testing::ValuesIn(padEnds), ::testing::ValuesIn(dilations), + ::testing::ValuesIn(groups), ::testing::ValuesIn(defor_groups), + ::testing::ValuesIn(numOutChannels), + ::testing::Values(ngraph::op::PadType::EXPLICIT)); +const auto conv2DParams_AutoPadValid = ::testing::Combine( + ::testing::ValuesIn(offsets), ::testing::ValuesIn(filters), + ::testing::ValuesIn(strides), + ::testing::Values(std::vector({0, 0})), + ::testing::Values(std::vector({0, 0})), + ::testing::ValuesIn(dilations), ::testing::ValuesIn(groups), + ::testing::ValuesIn(defor_groups), ::testing::ValuesIn(numOutChannels), + ::testing::Values(ngraph::op::PadType::VALID)); + +INSTANTIATE_TEST_CASE_P( + smoke_DeformableConvolution2D_Serialization_ExplicitPadding, DeformableConvolutionLayerTest, + ::testing::Combine( + conv2DParams_ExplicitPadding, ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 1, 28, 28})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + DeformableConvolutionLayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P( + smoke_DeformableConvolution2D__Serialization_AutoPadValid, DeformableConvolutionLayerTest, + ::testing::Combine( + conv2DParams_AutoPadValid, ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 1, 28, 28})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + DeformableConvolutionLayerTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp new file mode 100644 index 00000000000..e54812fe516 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/deformable_convolution.cpp @@ -0,0 +1,92 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "common_test_utils/test_constants.hpp" +#include "single_layer_tests/deformable_convolution.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16, + InferenceEngine::Precision::I32, InferenceEngine::Precision::I16}; + +/* ============= 2D DeformableConvolution ============= */ +const std::vector> deformable_vals = {{1, 18, 28, 28}}; +const std::vector> kernels = {{1, 1, 3, 3}}; +const std::vector> strides = {{1, 1}}; +const std::vector> padBegins = {{0, 0}}; +const std::vector> padEnds ={{0, 0}}; +const std::vector> dilations = {{1, 1}}; +const std::vector groups = {1}; +const std::vector defor_groups = {1}; +const std::vector numOutChannels = {1, 5}; +const std::vector multiple_defor_groups = {4}; +const std::vector> deform_vals = {{1, 200, 220, 220}}; +const std::vector> kernel = {{64, 4, 5, 5}}; + +const auto deformableConv2DParams_ExplicitPadding = ::testing::Combine( + ::testing::ValuesIn(deformable_vals), + ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), + ::testing::ValuesIn(padBegins), ::testing::ValuesIn(padEnds), + ::testing::ValuesIn(dilations), ::testing::ValuesIn(groups), + ::testing::ValuesIn(defor_groups), ::testing::ValuesIn(numOutChannels), + ::testing::Values(ngraph::op::PadType::EXPLICIT)); +const auto deformableConv2DParams_AutoPadValid = ::testing::Combine( + ::testing::ValuesIn(deformable_vals), + ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), + ::testing::Values(std::vector({0, 0})), + ::testing::Values(std::vector({0, 0})), + ::testing::ValuesIn(dilations), ::testing::ValuesIn(groups), + ::testing::ValuesIn(defor_groups), ::testing::ValuesIn(numOutChannels), + ::testing::Values(ngraph::op::PadType::VALID)); + +const auto deformableConv2DParams_DeformableGroups_AutoPadExplicit = ::testing::Combine( + ::testing::ValuesIn(deform_vals), + ::testing::ValuesIn(kernel), ::testing::ValuesIn(strides), + ::testing::Values(std::vector({0, 0})), + ::testing::Values(std::vector({0, 0})), + ::testing::ValuesIn(dilations), ::testing::ValuesIn(groups), + ::testing::ValuesIn(multiple_defor_groups), ::testing::ValuesIn(numOutChannels), + ::testing::Values(ngraph::op::PadType::EXPLICIT)); + +INSTANTIATE_TEST_CASE_P( + smoke_DeformableConvolution2D_ExplicitPadding, DeformableConvolutionLayerTest, + ::testing::Combine( + deformableConv2DParams_ExplicitPadding, ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 1, 30, 30})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + DeformableConvolutionLayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P( + smoke_DeformableConvolution2D_AutoPadValid, DeformableConvolutionLayerTest, + ::testing::Combine( + deformableConv2DParams_AutoPadValid, ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 1, 30, 30})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + DeformableConvolutionLayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P( + smoke_DeformableConvolution2D_DeformableGroups_ExplicitPadding, DeformableConvolutionLayerTest, + ::testing::Combine( + deformableConv2DParams_DeformableGroups_AutoPadExplicit, ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 4, 224, 224})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + DeformableConvolutionLayerTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/deformable_convolution.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/deformable_convolution.hpp new file mode 100644 index 00000000000..f67e8a12364 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/deformable_convolution.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_layer/deformable_convolution.hpp" + +namespace LayerTestsDefinitions { + +TEST_P(DeformableConvolutionLayerTest, CompareWithRefs) { + Run(); +} + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/deformable_convolution.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/deformable_convolution.hpp new file mode 100644 index 00000000000..bc7a614a106 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/deformable_convolution.hpp @@ -0,0 +1,53 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LayerTestsDefinitions { + +// ! [test_convolution:definition] +typedef std::tuple< + InferenceEngine::SizeVector, // Deformable values size + InferenceEngine::SizeVector, // Kernel size + InferenceEngine::SizeVector, // Strides + std::vector, // Pad begin + std::vector, // Pad end + InferenceEngine::SizeVector, // Dilation + size_t, // Groups + size_t, // Deformable groups + size_t, // Num out channels + ngraph::op::PadType // Padding type +> deformableConvSpecificParams; +typedef std::tuple< + deformableConvSpecificParams, + InferenceEngine::Precision, // Net precision + InferenceEngine::Precision, // Input precision + InferenceEngine::Precision, // Output precision + InferenceEngine::Layout, // Input layout + InferenceEngine::Layout, // Output layout + InferenceEngine::SizeVector, // Input shapes + LayerTestsUtils::TargetDevice // Device name +> deformableConvLayerTestParamsSet; + +class DeformableConvolutionLayerTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; + +protected: + void SetUp() override; +}; +// ! [test_convolution:definition] + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/deformable_convolution.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/deformable_convolution.cpp new file mode 100644 index 00000000000..c902e5a9ba1 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/deformable_convolution.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/deformable_convolution.hpp" + +namespace LayerTestsDefinitions { + +std::string DeformableConvolutionLayerTest::getTestCaseName(testing::TestParamInfo obj) { + deformableConvSpecificParams convParams; + InferenceEngine::Precision netPrecision; + InferenceEngine::Precision inPrc, outPrc; + InferenceEngine::Layout inLayout, outLayout; + InferenceEngine::SizeVector inputShapes; + std::string targetDevice; + std::tie(convParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShapes, targetDevice) = + obj.param; + ngraph::op::PadType padType; + InferenceEngine::SizeVector offsets, filter, stride, dilation; + std::vector padBegin, padEnd; + size_t groups, deformable_groups, convOutChannels; + std::tie(offsets, filter, stride, padBegin, padEnd, dilation, groups, deformable_groups, convOutChannels, padType) = convParams; + + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_"; + result << "DV" << CommonTestUtils::vec2str(offsets) << "_"; + result << "K" << CommonTestUtils::vec2str(filter) << "_"; + result << "S" << CommonTestUtils::vec2str(stride) << "_"; + result << "PB" << CommonTestUtils::vec2str(padBegin) << "_"; + result << "PE" << CommonTestUtils::vec2str(padEnd) << "_"; + result << "D=" << CommonTestUtils::vec2str(dilation) << "_"; + result << "G=" << groups << "_"; + result << "DG=" << deformable_groups << "_"; + result << "O=" << convOutChannels << "_"; + result << "AP=" << padType << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "inPRC=" << inPrc.name() << "_"; + result << "outPRC=" << outPrc.name() << "_"; + result << "inL=" << inLayout << "_"; + result << "outL=" << outLayout << "_"; + result << "trgDev=" << targetDevice; + return result.str(); +} + +InferenceEngine::Blob::Ptr DeformableConvolutionLayerTest::GenerateInput(const InferenceEngine::InputInfo &info) const { + InferenceEngine::Blob::Ptr blobPtr; + const std::string& name = info.name(); + if (name == "a_data") { + blobPtr = LayerTestsUtils::LayerTestsCommon::GenerateInput(info); + } else if (name == "b_offset_vals") { + blobPtr = FuncTestUtils::createAndFillBlobFloat(info.getTensorDesc(), 2, 0, 10); + } else if (name == "c_filter_vals") { + blobPtr = LayerTestsUtils::LayerTestsCommon::GenerateInput(info); + } + return blobPtr; +} + +void DeformableConvolutionLayerTest::SetUp() { + deformableConvSpecificParams convParams; + std::vector inputShape; + InferenceEngine::Precision netPrecision; + std::tie(convParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetDevice) = + this->GetParam(); + ngraph::op::PadType padType; + InferenceEngine::SizeVector offsets, filter, stride, dilation; + std::vector padBegin, padEnd; + size_t groups, deformable_groups, convOutChannels; + std::tie(offsets, filter, stride, padBegin, padEnd, dilation, groups, deformable_groups, convOutChannels, padType) = convParams; + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape, offsets, filter}); + auto paramOuts = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(params)); + auto data = std::make_shared(ngPrc, ngraph::Shape(inputShape)); + data->set_friendly_name("a_data"); + auto offset_vals = std::make_shared(ngPrc, ngraph::Shape(offsets)); + offset_vals->set_friendly_name("b_offset_vals"); + auto filter_vals = std::make_shared(ngPrc, ngraph::Shape(filter)); + filter_vals->set_friendly_name("c_filter_vals"); + auto deformable_conv = std::make_shared(data, offset_vals, filter_vals, + stride, padBegin, padEnd, dilation, padType, groups, deformable_groups); + ngraph::ResultVector results{std::make_shared(deformable_conv)}; + function = std::make_shared(results, ngraph::ParameterVector{data, offset_vals, filter_vals}, "deformable_convolution"); +} +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index 0c85fb0991f..edb0c5fab9d 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -38,6 +38,7 @@ verified_operations = [ 'Concat-0', 'ConvertLike-1', 'Convolution-1', + 'DeformableConvolution-1', 'DetectionOutput-0', 'Divide-1', 'ExperimentalDetectronDetectionOutput-6', diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/deformable_convolution.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/deformable_convolution.hpp new file mode 100644 index 00000000000..d2a9e867f8e --- /dev/null +++ b/ngraph/core/reference/include/ngraph/runtime/reference/deformable_convolution.hpp @@ -0,0 +1,234 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/runtime/reference/convolution.hpp" + +namespace ngraph +{ + namespace runtime + { + namespace reference + { + namespace def_conv_impl + { + inline void validate_params(const Shape& in_shape, + const Shape& o_shape, + const Shape& f_shape, + const Strides& strides, + const Strides& dilations, + const CoordinateDiff& pads_begin, + const CoordinateDiff& pads_end) + { + // this implementation supports 2D deformable convolutions + NGRAPH_CHECK(in_shape.size() == 4, "Unsupported input rank: ", in_shape); + + NGRAPH_CHECK(o_shape.size() == 4, "Unsupported offset rank: ", o_shape); + + NGRAPH_CHECK(f_shape.size() == 4, "Unsupported kernel rank: ", f_shape); + + const auto spatial_dims = in_shape.size() - 2; + NGRAPH_CHECK(strides.size() == spatial_dims, + "Strides not definied for all and only spatial dimensions"); + + NGRAPH_CHECK(dilations.size() == spatial_dims, + "Dilations not defined for all and only spatial dimensions"); + + NGRAPH_CHECK((pads_begin.size() == pads_end.size()) && + (pads_begin.size() == spatial_dims), + "Pads not defined for all and only spatial dimensions"); + } + + inline Shape shape_reduce(const Shape& s) { return Shape(++s.begin(), s.end()); } + + inline Shape shape_scale(Shape s, size_t groups) + { + s[0] /= groups; + return s; + } + + template + inline float bilinear_interpolation(const inputType* data, + const float x_idx, + const float y_idx, + const int x_size, + const int y_size) + { + const int x1 = std::max(static_cast(std::floor(x_idx)), 0); + const int x2 = std::min(static_cast(std::ceil(x_idx)), x_size - 1); + const int y1 = std::max(static_cast(std::floor(y_idx)), 0); + const int y2 = std::min(static_cast(std::ceil(y_idx)), y_size - 1); + + const float distX = x_idx - x1; + const float distY = y_idx - y1; + + const float value11 = data[y1 * x_size + x1]; + const float value12 = data[y2 * x_size + x1]; + const float value21 = data[y1 * x_size + x2]; + const float value22 = data[y2 * x_size + x2]; + + const float value = (1 - distX) * (1 - distY) * value11 + + (1 - distX) * distY * value12 + + distX * (1 - distY) * value21 + distX * distY * value22; + return value; + } + + template + void convolve_2D_channels(const ConvolutionParams& p, + const int64_t deformable_groups, + const T* batch, + const Shape& batch_shape, + const T* offsets, + const Shape& offset_shape, + const T* filter, + const Shape& filter_shape, + T* out) + { + const int input_size_y = batch_shape[1]; + const int input_size_x = batch_shape[2]; + const int filter_size_y = filter_shape[1]; + const int filter_size_x = filter_shape[2]; + const int dilated_filter_size_y = + filter_size_y + (filter_size_y - 1) * (p.dilation[0] - 1); + const int dilated_filter_size_x = + filter_size_x + (filter_size_x - 1) * (p.dilation[1] - 1); + + const int input_channel_size = shape_size(shape_reduce(batch_shape)); + const int filter_channel_size = shape_size(shape_reduce(filter_shape)); + const int offsets_size = shape_size(offset_shape); + const int offsets_spatial_size = shape_size(shape_reduce(offset_shape)); + const int offsets_channel_size = 2 * offsets_spatial_size; + const int filter_channels_count = filter_shape[0]; + + int out_idx = 0; + for (int i_y = -p.pads_begin[0]; + i_y <= (p.pads_end[0] + input_size_y - dilated_filter_size_y); + i_y += p.strides[0]) + { + for (int i_x = -p.pads_begin[1]; + i_x <= (p.pads_end[1] + input_size_x - dilated_filter_size_x); + i_x += p.strides[1]) + { + auto input_channel = batch; + auto filter_channel = filter; + T sum = 0; + auto group_offsets_channel = offsets; + for (int dg = 0; dg < deformable_groups; dg++) + { + for (int fc = 0; fc < filter_channels_count / deformable_groups; + fc++) + { + auto offsets_channel = group_offsets_channel; + for (int f_y = 0; f_y < filter_size_y; ++f_y) + { + for (int f_x = 0; f_x < filter_size_x; ++f_x) + { + T y_offset = offsets_channel[out_idx]; + T x_offset = + offsets_channel[offsets_spatial_size + out_idx]; + T rel_i_y = i_y + (f_y * p.dilation[0]) + y_offset; + T rel_i_x = i_x + (f_x * p.dilation[1]) + x_offset; + + offsets_channel += offsets_channel_size; + bool padding = !(in_range(rel_i_x, {0, input_size_x}) && + in_range(rel_i_y, {0, input_size_y})); + if (padding) + continue; + + int f_buf_idx = (f_y * filter_size_x) + f_x; + sum += bilinear_interpolation(input_channel, + rel_i_x, + rel_i_y, + input_size_x, + input_size_y) * + filter_channel[f_buf_idx]; + } + } + input_channel += input_channel_size; + filter_channel += filter_channel_size; + } + group_offsets_channel += offsets_size / deformable_groups; + } + out[out_idx++] = sum; + } + } + } + + } // namespace def_conv_impl + template + void deformable_convolution(const T* in, + const T* offsets, + const T* filters, + T* out, + const Shape& in_shape, + const Shape& o_shape, + const Shape& f_shape, + const Shape& out_shape, + const Strides& strides, + const Strides& dilation, + const CoordinateDiff& pads_begin, + const CoordinateDiff& pads_end, + const int64_t groups, + const int64_t deformable_groups) + + { + using namespace def_conv_impl; + + validate_params( + in_shape, o_shape, f_shape, strides, dilation, pads_begin, pads_end); + + // here we are converting all param types to int's to avoid arithmetic issues + // (e.g signed + unsigned) in indexes calculation later + ConvolutionParams params{strides, dilation, pads_begin, pads_end}; + const size_t groups_count = static_cast(groups); + + const size_t batches_count = in_shape[in_batch_axis]; + const Shape group_in_shape = shape_scale(shape_reduce(in_shape), groups); + const size_t group_in_size = shape_size(group_in_shape); + + const Shape group_offset_shape = shape_scale(shape_reduce(o_shape), groups); + const size_t group_offset_size = shape_size(group_offset_shape); + const size_t group_offset_batch_size = shape_size(shape_reduce(o_shape)); + const size_t deformable_groups_per_group = + std::ceil(static_cast(deformable_groups) / static_cast(groups)); + + const size_t group_filters_count = f_shape[filter_out_ch_axis] / groups; + const Shape group_filter_shape = shape_reduce(f_shape); + const size_t group_filter_size = shape_size(group_filter_shape); + + const size_t out_ch_size = shape_size(shape_reduce(shape_reduce(out_shape))); + + for (size_t batch_idx = 0; batch_idx < batches_count; ++batch_idx) + { + const T* group_filters = filters; + const T* group_offsets = offsets; + for (size_t group_idx = 0; group_idx < groups_count; ++group_idx) + { + for (size_t f_idx = 0; f_idx < group_filters_count; ++f_idx) + { + convolve_2D_channels(params, + deformable_groups_per_group, + in, + group_in_shape, + group_offsets, + group_offset_shape, + group_filters, + group_filter_shape, + out); + group_filters += group_filter_size; + out += out_ch_size; + } + in += group_in_size; + if (deformable_groups > 1) + { + group_offsets += (deformable_groups_per_group * group_offset_size); + } + } + offsets += group_offset_batch_size; + } + } + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/src/op/deformable_convolution.cpp b/ngraph/core/src/op/deformable_convolution.cpp index bdfd057ce8f..eb5071af7de 100644 --- a/ngraph/core/src/op/deformable_convolution.cpp +++ b/ngraph/core/src/op/deformable_convolution.cpp @@ -171,13 +171,18 @@ void op::v1::DeformableConvolution::validate_and_infer_types() return; } } - + // adjust filter shape to reuse regular infer_convolution_forward() + const auto new_filters_pshape = [&](int groups) { + auto new_shape(filters_shape); + new_shape[1] *= groups; + return new_shape; + }(m_group); result_shape = infer_convolution_forward(this, data_batch_shape, Strides(m_strides.size(), 1), // dummy data dilations m_pads_begin, m_pads_end, - filters_shape, + new_filters_pshape, m_strides, m_dilations); diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 53076ef28c1..b158eb7c77b 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -325,6 +325,7 @@ set(MULTI_TEST_SRC backend/detection_output.in.cpp backend/dft.in.cpp backend/divide.in.cpp + backend/deformable_convolution.in.cpp backend/dyn_reshape.in.cpp backend/strided_slice.in.cpp backend/dynamic.in.cpp diff --git a/ngraph/test/backend/deformable_convolution.in.cpp b/ngraph/test/backend/deformable_convolution.in.cpp new file mode 100644 index 00000000000..a26c704e40c --- /dev/null +++ b/ngraph/test/backend/deformable_convolution.in.cpp @@ -0,0 +1,2622 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "ngraph/runtime/tensor.hpp" +#include "runtime/backend.hpp" +#include "util/all_close.hpp" +#include "util/all_close_f.hpp" +#include "util/engine/test_engines.hpp" +#include "util/known_element_types.hpp" +#include "util/ndarray.hpp" +#include "util/test_case.hpp" +#include "util/test_control.hpp" +#include "util/test_tools.hpp" + +using namespace std; +using namespace ngraph; + +static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); + +static void DeformableConvolutionTest(const std::vector& inputs, + const Shape inputs_shape, + const std::vector& offsets, + const Shape offsets_shape, + const std::vector& filter, + const Shape filter_shape, + const std::vector& outputs, + const Shape outputs_shape, + const Strides& strides, + const CoordinateDiff& padding, + const Strides& dilations, + const int64_t group = 1, + const int64_t deformable_group = 1, + const size_t tolerance_bits = 2) +{ + const CoordinateDiff pads_begin{padding}; + const CoordinateDiff pads_end{padding}; + const op::PadType auto_pad{op::PadType::EXPLICIT}; + auto inputs_param = make_shared(element::f32, inputs_shape); + auto offsets_param = make_shared(element::f32, offsets_shape); + auto filter_param = make_shared(element::f32, filter_shape); + auto conv = make_shared(inputs_param, + offsets_param, + filter_param, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + group, + deformable_group); + auto f = + make_shared(conv, ParameterVector{inputs_param, offsets_param, filter_param}); + auto test_case = test::TestCase(f); + test_case.add_input(inputs); + test_case.add_input(offsets); + test_case.add_input(filter); + test_case.add_expected_output(outputs_shape, outputs); + test_case.run(tolerance_bits); +} +// clang-format off + +// regular convolution attributes (zeroed offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_default) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + -1.0f, -2.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{-12.0f, -12.0f, -12.0f, + -12.0f, -12.0f, -12.0f, + -12.0f, -12.0f, -12.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_padding) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{1, 1}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 3, 3}; + const std::vector inputs{1.0f, 3.0f, 5.0f, + 7.0f, 5.0f, 3.0f, + 1.0f, 3.0f, 5.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + 0.0f, 1.0f}; + + const Shape offsets_shape{1, 8, 4, 4}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{1.0f, 3.0f, 5.0f, 0.0f, + 9.0f, 12.0f, 16.0f, 5.0f, + 15.0f, 20.0f, 16.0f, 3.0f, + 2.0f, 7.0f, 13.0f, 5.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_stride) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 5, 5}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, + 7.0f, 5.0f, 3.0f, 1.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 1.0f, + 3.0f, 2.0f, 1.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{57.0f, 94.0f, + 66.0f, 102.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_dilation) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{2, 2}; + + const Shape inputs_shape{1, 1, 7, 7}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 0.0f, + 3.0f, 1.0f, 2.0f}; + + const Shape offsets_shape{1, 18, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{78.0f, 106.0f, 134.0f, + 44.0f, 16.0f, -12.0f, + 80.0f, 84.0f, 88.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_padding_strides_dilation) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{2, 2}; + const Strides dilations{2, 2}; + + const Shape inputs_shape{1, 1, 7, 7}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 0.0f, + 3.0f, 1.0f, 2.0f}; + + const Shape offsets_shape{1, 18, 4, 4}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{15.0f, 38.0f, 70.0f, 66.0f, + 33.0f, 78.0f, 134.0f, 103.0f, + 40.0f, 80.0f, 88.0f, 58.0f, + 30.0f, 56.0f, 72.0f, 34.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_input_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{ + // channel 1 + 1.0f, 3.0f, 5.0f, 7.0f, + 7.0f, 5.0f, 3.0f, 1.0f, + 2.0f, 4.0f, 6.0f, 8.0f, + 8.0f, 6.0f, 4.0f, 2.0f, + // channel 2 + -1.0f, 3.0f, -5.0f, 7.0f, + 7.0f, -5.0f, 3.0f, -1.0f, + -2.0f, 4.0f, -6.0f, 8.0f, + 8.0f, -6.0f, 4.0f, -2.0f}; + + const Shape filter_shape{1, 2, 3, 3}; + const std::vector filter{ + // channel 1 + 5.0f, 3.0f, 5.0f, + 1.0f, 3.0f, 1.0f, + 4.0f, 2.0f, 4.0f, + // channel 2 + -5.0f, 3.0f, 5.0f, + 1.0f, -3.0f, 1.0f, + 4.0f, 2.0f, -4.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{142.0f, 102.0f, + 94.0f, 160.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_output_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{ + 1.0f, 3.0f, 5.0f, 7.0f, + 7.0f, 5.0f, 3.0f, 1.0f, + 2.0f, 4.0f, 6.0f, 8.0f, + 8.0f, 6.0f, 4.0f, 2.0f}; + + const Shape filter_shape{2, 1, 3, 3}; + const std::vector filter{ + // channel 1 + 5.0f, 3.0f, 5.0f, + 1.0f, 3.0f, 1.0f, + 4.0f, 2.0f, 4.0f, + // channel 2 + -5.0f, 3.0f, 5.0f, + 1.0f, -3.0f, 1.0f, + 4.0f, 2.0f, -4.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{ + // channel 1 + 104.0f, 140.0f, + 145.0f, 109.0f, + // channel 2 + 16.0f, 28.0f, + 19.0f, 7.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_batch) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{2, 1, 4, 4}; + const std::vector inputs{ + // batch 1 + 1.0f, 3.0f, 2.0f, 1.0f, + 1.0f, 3.0f, 3.0f, 1.0f, + 2.0f, 1.0f, 1.0f, 3.0f, + 3.0f, 2.0f, 3.0f, 3.0f, + // batch 2 + -1.0f, 3.0f, 2.0f, -1.0f, + 1.0f, 3.0f, -3.0f, 1.0f, + -2.0f, -1.0f, 1.0f, 3.0f, + 3.0f, 2.0f, 3.0f, -3.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{-5.0f, 3.0f, 5.0f, + 1.0f, -3.0f, 1.0f, + 4.0f, 2.0f, -4.0f}; + + const Shape offsets_shape{2, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{2, 1, 2, 2}; + const std::vector outputs{ + // batch 1 + 15.0f, -15.0f, + 23.0f, 2.0f, + // batch 2 + -1.0f, -15.0f, + -5.0f, 6.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +// group & deformable_group attributes (zeroed offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_groups_basic) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 2 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{ // channel 1 + 356.0f, 392.0f, + 464.0f, 500.0f, + // channel 2 + -1004.0f, -1040.0f, + -1112.0f, -1148.0f}; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, dilations, group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_groups_complex) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 4; + + const Shape inputs_shape{1, 8, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f, + // channel 5 + 37.0f, 38.0f, 39.0f, + 40.0f, 41.0f, 42.0f, + 43.0f, 44.0f, 45.0f, + // channel 6 + 46.0f, 47.0f, 48.0f, + 49.0f, 50.0f, 51.0f, + 52.0f, 53.0f, 54.0f, + // channel 7 + 55.0f, 56.0f, 57.0f, + 58.0f, 59.0f, 60.0f, + 61.0f, 62.0f, 63.0f, + // channel 8 + 64.0f, 65.0f, 66.0f, + 67.0f, 68.0f, 69.0f, + 70.0f, 71.0f, 72.0f,}; + + const Shape filter_shape{4, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + 9.0f, 10.0f, + 11.0f, 12.0f, + // filter 2 channel 2 + 13.0f, 14.0f, + 15.0f, 16.0f, + // filter 3 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 3 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // filter 4 channel 1 + -9.0f, -10.0f, + -11.0f, -12.0f, + // filter 4 channel 2 + -13.0f, -14.0f, + -15.0f, -16.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 4, 2, 2}; + const std::vector outputs{ // channel 1 + 356.0f, 392.0f, + 464.0f, 500.0f, + // channel 2 + 2636.0f, 2736.0f, + 2936.0f, 3036.0f, + // channel 3 + -1652.0f, -1688.0f, + -1760.0f, -1796.0f, + // channel 4 + -6236.0f, -6336.0f, + -6536.0f, -6636.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, dilations, group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_deforgroup) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{1, 2, 2, 2}; + const std::vector filter{// channel 1 + 1.0f, 2.0f, + -1.0f, -2.0f, + // channel 2 + 3.0f, 4.0f, + -3.0f, -4.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{-40.0f, -40.0f, -40.0f, + -40.0f, -40.0f, -40.0f, + -40.0f, -40.0f, -40.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_zeroed_offsets_groups_and_deforgroups) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{1.0f, 2.0f, + 3.0f, 4.0f, + 5.0f, 6.0f, + 7.0f, 8.0f, + -1.0f, -2.0f, + -3.0f, -4.0f, + -5.0f, -6.0f, + -7.0f, -8.0f, + }; + + const Shape offsets_shape{1, 16, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 0); + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{356.0f, 392.0f, + 464.0f, 500.0f, + -1004.0f, -1040.0f, + -1112.0f, -1148.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group); +} + +// deformable convolution atrributes (integral offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_default) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + -1.0f, -2.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets{// window 1 (Y=0, X=0) -> Y coordinate + 1.0f, 1.0f, 1.0f, // out1 .. out 3 + 1.0f, 1.0f, 1.0f, // out4 .. out 6 + 1.0f, 1.0f, 1.0f, // out7 .. out 9 + // window 1 (Y=0, X=0) -> X coordinate + 1.0f, 1.0f, 1.0f, // out1 .. out 3 + 1.0f, 1.0f, 1.0f, // out4 .. out 6 + 1.0f, 1.0f, 1.0f, // out7 .. out 9 + // window 2 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // window 2 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // window 3 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // window 3 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // window 4 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // window 4 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + }; + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{-12.0f, -12.0f, -4.0f, + -12.0f, -12.0f, -4.0f, + 44.0f, 47.0f, 16.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_padding) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{1, 1}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 3.0f, 7.0f, 7.0f, + 7.0f, 6.0f, 3.0f, 1.0f, + 4.0f, 4.0f, 2.0f, 8.0f, + 1.0f, 1.0f, 1.0f, 2.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 0.0f, 1.0f, 0.0f, + 3.0f, 2.0f, 1.0f}; + + const Shape offsets_shape{1, 18, 4, 4}; + const std::vector offsets{1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f}; + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{56.0f, 39.0f, 44.0f, 18.0f, + 38.0f, 56.0f, 65.0f, 0.0f, + 19.0f, 38.0f, 20.0f, 20.0f, + 6.0f, 19.0f, 33.0f, 0.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_stride) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 5, 5}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, + 7.0f, 5.0f, 3.0f, 1.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 1.0f, + 3.0f, 2.0f, 1.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets{0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f, + 0.0f, 2.0f, + 1.0f, 0.0f}; + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{57.0f, 40.0f, + 38.0f, 102.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_dilation) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{2, 2}; + + const Shape inputs_shape{1, 1, 7, 7}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 0.0f, + 3.0f, 1.0f, 2.0f}; + + const Shape offsets_shape{1, 18, 3, 3}; + const std::vector offsets{1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f, + 1.0f, 2.0f, 0.0f, + 0.0f, 2.0f, 0.0f, + 1.0f, 0.0f, 1.0f}; + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{16.0f, -2.0f, 134.0f, + 44.0f, -4.0f, -12.0f, + 10.0f, 84.0f, -4.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_padding_stride_dilation) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{2, 2}; + const Strides dilations{2, 2}; + + const Shape inputs_shape{1, 1, 7, 7}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 0.0f, + 3.0f, 1.0f, 2.0f}; + + const Shape offsets_shape{1, 18, 4, 4}; + const std::vector offsets{1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 2.0f}; + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{15.0f, 38.0f, 2.0f, 66.0f, + 26.0f, 78.0f, 134.0f, 16.0f, + 23.0f, 80.0f, -4.0f, 58.0f, + 13.0f, 56.0f, 72.0f, -4.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_input_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{ + // channel 1 + 1.0f, 3.0f, 5.0f, 7.0f, + 7.0f, 5.0f, 3.0f, 1.0f, + 2.0f, 4.0f, 6.0f, 8.0f, + 8.0f, 6.0f, 4.0f, 2.0f, + // channel 2 + -1.0f, 3.0f, -5.0f, 7.0f, + 7.0f, -5.0f, 3.0f, -1.0f, + -2.0f, 4.0f, -6.0f, 8.0f, + 8.0f, -6.0f, 4.0f, -2.0f}; + + const Shape filter_shape{1, 2, 3, 3}; + const std::vector filter{ + // channel 1 + 5.0f, 3.0f, 5.0f, + 1.0f, 3.0f, 1.0f, + 4.0f, 2.0f, 4.0f, + // channel 2 + -5.0f, 3.0f, 5.0f, + 1.0f, -3.0f, 1.0f, + 4.0f, 2.0f, -4.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets{1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f, + 1.0f, 1.0f, + 0.0f, 2.0f}; + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{160.0f, 32.0f, + 94.0f, 20.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_output_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + const Shape filter_shape{2, 1, 2, 2}; + const std::vector filter{ // filter 1 + 1.0f, 2.0f, + -1.0f, -2.0f, + // filter 2 + 3.0f, 4.0f, + -3.0f, -4.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets{//channel 1: Y offsets + 1.0f, 1.0f, 1.0f, // out1 .. out 3 + 1.0f, 1.0f, 1.0f, // out4 .. out 6 + 1.0f, 1.0f, 1.0f, // out7 .. out 9 + //channel 1: X offsets + 1.0f, 1.0f, 1.0f, // out1 .. out 3 + 1.0f, 1.0f, 1.0f, // out4 .. out 6 + 1.0f, 1.0f, 1.0f, // out7 .. out 9 + //channel 2: Y offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + //channel 2: X offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + //channel 3: Y offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + //channel 3: X offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + //channel 4: Y offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + //channel 4: X offsets + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + }; + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{ + // output 1 + -12.0f, -12.0f, -4.0f, + -12.0f, -12.0f, -4.0f, + 44.0f, 47.0f, 16.0f, + // output 2 + -28.0f, -28.0f, -12.0f, + -28.0f, -28.0f, -12.0f, + 102.0f, 109.0f, 48.0f, }; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_batch) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + + const Shape inputs_shape{2, 1, 4, 4}; + const std::vector inputs{//batch 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + //batch 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + -1.0f, -2.0f}; + + const Shape offsets_shape{2, 8, 3, 3}; + const std::vector offsets{// batch1 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // batch2 + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + }; + + const Shape outputs_shape{2, 1, 3, 3}; + const std::vector outputs{// batch 1 + -12.0f, -12.0f, -4.0f, + -12.0f, -12.0f, -4.0f, + 44.0f, 47.0f, 16.0f, + // batch 2 + -12.0f, -12.0f, -12.0f, + -12.0f, -12.0f, -12.0f, + -12.0f, -12.0f, -12.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, dilations); +} +// group & deformable_group attributes (integral offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_groups_basic) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 2 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets { + // window 1 (F_Y=0, F_X=0) -> I_Y coordinate + 1.0f, 0.0f, 2.0f, 1.0f, // out1 .. out 4 + // window 1 (F_Y=0, F_X=0) -> I_X coordinate + 0.0f, 1.0f, 1.0f, 2.0f, // out1 .. out 4 + // window 2 (F_Y=0, F_X=1) -> I_Y coordinate + 1.0f, 1.0f, 1.0f, 1.0f, // out1 .. out 4 + // window 2 (F_Y=0, F_X=1) -> I_X coordinate + 1.0f, 1.0f, 1.0f, 1.0f, // out1 .. out 4 + // window 3 (F_Y=1, F_X=0) -> I_Y coordinate + 2.0f, 2.0f, 2.0f, 2.0f, // out1 .. out 4 + // window 3 (F_Y=1, F_X=0) -> I_X coordinate + 2.0f, 2.0f, 2.0f, 2.0f, // out1 .. out 4 + // window 4 (F_Y=1, F_X=1) -> I_Y coordinate + 2.0f, 2.0f, 2.0f, 2.0f, // out1 .. out 4 + // window 4 (F_Y=1, F_X=1) -> I_X coordinate + 2.0f, 2.0f, 2.0f, 2.0f}; // out1 .. out 4 + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{ // channel 1 + 171.0f, 63.0f, + 126.0f, 0.0f, + // channel 2 + -423.0f, -171.0f, + -270.0f, 0.0f}; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, dilations, group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_groups_complex) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 4; + + const Shape inputs_shape{1, 8, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f, + // channel 5 + 37.0f, 38.0f, 39.0f, + 40.0f, 41.0f, 42.0f, + 43.0f, 44.0f, 45.0f, + // channel 6 + 46.0f, 47.0f, 48.0f, + 49.0f, 50.0f, 51.0f, + 52.0f, 53.0f, 54.0f, + // channel 7 + 55.0f, 56.0f, 57.0f, + 58.0f, 59.0f, 60.0f, + 61.0f, 62.0f, 63.0f, + // channel 8 + 64.0f, 65.0f, 66.0f, + 67.0f, 68.0f, 69.0f, + 70.0f, 71.0f, 72.0f,}; + + const Shape filter_shape{4, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + 9.0f, 10.0f, + 11.0f, 12.0f, + // filter 2 channel 2 + 13.0f, 14.0f, + 15.0f, 16.0f, + // filter 3 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 3 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // filter 4 channel 1 + -9.0f, -10.0f, + -11.0f, -12.0f, + // filter 4 channel 2 + -13.0f, -14.0f, + -15.0f, -16.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets {1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f}; + + const Shape outputs_shape{1, 4, 2, 2}; + const std::vector outputs{ // channel 1 + 500.0f, 234.0f, + 219.0f, 99.0f, + // channel 2 + 3036.0f, 1482.0f, + 1463.0f, 711.0f, + // channel 3 + -1796.0f, -810.0f, + -723.0f, -315.0f, + // channel 4 + -6636.0f, -3210.0f, + -3119.0f, -1503.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, dilations, group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_deforgroup_basic) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 16, 3, 3}; + const std::vector offsets{// defgroup 1 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // defgroup 2 + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + }; + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 610.0f, 646.0f, 612.0f, + 754.0f, 790.0f, 732.0f, + 768.0f, 797.0f, 792.0f, + // output 2 + -610.0f, -646.0f, -612.0f, + -754.0f, -790.0f, -732.0f, + -768.0f, -797.0f, -792.0f, + }; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_deforgroup_complex1) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 4; + + const Shape inputs_shape{1, 4, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f, + // channel 3 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 4 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 4, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f1: channel 3 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 4 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // f2: channel 3 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 4 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 32, 3, 3}; + const std::vector offsets{// defgroup 1 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // defgroup 2 + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + // defgroup 3 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // defgroup 4 + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + }; + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 1220.0f, 1292.0f, 1224.0f, + 1508.0f, 1580.0f, 1464.0f, + 1536.0f, 1594.0f, 1584.0f, + // output 2 + -1220.0f, -1292.0f, -1224.0f, + -1508.0f, -1580.0f, -1464.0f, + -1536.0f, -1594.0f, -1584.0f, + }; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_deforgroup_complex2) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 4, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f, + // channel 3 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 4 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 4, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f1: channel 3 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 4 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // f2: channel 3 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 4 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 16, 3, 3}; + const std::vector offsets{// defgroup 1 + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + // defgroup 2 + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + }; + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 1300.0f, 1372.0f, 992.0f, + 1588.0f, 1660.0f, 1200.0f, + 1228.0f, 1278.0f, 1096.0f, + // output 2 + -1300.0f, -1372.0f, -992.0f, + -1588.0f, -1660.0f, -1200.0f, + -1228.0f, -1278.0f, -1096.0f, + }; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_integral_offsets_groups_and_deforgroups) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{1.0f, 2.0f, + 3.0f, 4.0f, + 5.0f, 6.0f, + 7.0f, 8.0f, + -1.0f, -2.0f, + -3.0f, -4.0f, + -5.0f, -6.0f, + -7.0f, -8.0f, + }; + + const Shape offsets_shape{1, 16, 2, 2}; + const std::vector offsets{// defgroup 1 + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + // defgroup 2 + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + }; + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{500.0f, 234.0f, + 219.0f, 99.0f, + -1004.0f, -1040.0f, + -1112.0f, -1148.0f}; + + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group); +} + +// deformable convolution atrributes (real offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_default) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + -1.0f, -2.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 1, 3, 3}; + const std::vector outputs{-11.999998f, -11.999999f, -4.000000f, + -10.799999f, -10.800001f, -3.600004f, + 44.300000f, 47.100000f, 16.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_padding) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{1, 1}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 3.0f, 7.0f, 7.0f, + 7.0f, 6.0f, 3.0f, 1.0f, + 4.0f, 4.0f, 2.0f, 8.0f, + 1.0f, 1.0f, 1.0f, 2.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 0.0f, 1.0f, 0.0f, + 3.0f, 2.0f, 1.0f}; + + const Shape offsets_shape{1, 18, 4, 4}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{54.870006f, 61.630001f, 43.230003f, 28.600002f, + 35.590000f, 25.819999f, 20.880001f, 7.700000f, + 19.089998f, 31.719999f, 19.250000f, 7.399999f, + 6.299999f, 9.199999f, 5.099999f, 2.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_stride) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 1, 5, 5}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, + 7.0f, 5.0f, 3.0f, 1.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 1.0f, + 3.0f, 2.0f, 1.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{61.229999f, 29.509998f, + 39.640003f, 22.640003f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_padding_stride_dilation) +{ + const Strides strides{2, 2}; + const CoordinateDiff padding{2, 2}; + const Strides dilations{2, 2}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 1, 7, 7}; + const std::vector inputs{1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, + 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, + 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, + 8.0f, 6.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + + const Shape filter_shape{1, 1, 3, 3}; + const std::vector filter{1.0f, 2.0f, 3.0f, + 1.0f, 1.0f, 0.0f, + 3.0f, 1.0f, 2.0f}; + + const Shape offsets_shape{1, 18, 4, 4}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 1, 4, 4}; + const std::vector outputs{15.260000f, 24.119997f, 6.439994f, -3.940005f, + 26.440002f, 20.319999f, -0.500001f, -11.720002f, + 23.500003f, 14.040000f, -1.279998f, -3.860000f, + 12.500000f, -2.599999f, -5.299999f, -3.099999f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_input_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{ + // channel 1 + 1.0f, 3.0f, 5.0f, 7.0f, + 7.0f, 5.0f, 3.0f, 1.0f, + 2.0f, 4.0f, 6.0f, 8.0f, + 8.0f, 6.0f, 4.0f, 2.0f, + // channel 2 + -1.0f, 3.0f, -5.0f, 7.0f, + 7.0f, -5.0f, 3.0f, -1.0f, + -2.0f, 4.0f, -6.0f, 8.0f, + 8.0f, -6.0f, 4.0f, -2.0f}; + + const Shape filter_shape{1, 2, 3, 3}; + const std::vector filter{ + // channel 1 + 5.0f, 3.0f, 5.0f, + 1.0f, 3.0f, 1.0f, + 4.0f, 2.0f, 4.0f, + // channel 2 + -5.0f, 3.0f, 5.0f, + 1.0f, -3.0f, 1.0f, + 4.0f, 2.0f, -4.0f}; + + const Shape offsets_shape{1, 18, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 1, 2, 2}; + const std::vector outputs{148.000000f, 43.259998f, + 91.279998f, 111.199996f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_output_channels) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 1, 4, 4}; + const std::vector inputs{1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + const Shape filter_shape{2, 1, 2, 2}; + const std::vector filter{ // filter 1 + 1.0f, 2.0f, + -1.0f, -2.0f, + // filter 2 + 3.0f, 4.0f, + -3.0f, -4.0f}; + + const Shape offsets_shape{1, 8, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{ + // output 1 + -12.000000f, -12.000000f, -4.000000f, + -10.799999f, -10.799995f, -3.600000f, + 44.299999f, 47.099998f, 16.000000f, + // output 2 + -28.000000f, -28.000000f, -12.000000f, + -25.200000f, -25.199993f, -10.800003f, + 102.699996f, 109.300003f, 48.000000f, }; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_batch) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 1; + + const Shape inputs_shape{2, 1, 4, 4}; + const std::vector inputs{//batch 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + //batch 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{1, 1, 2, 2}; + const std::vector filter{1.0f, 2.0f, + -1.0f, -2.0f}; + + const Shape offsets_shape{2, 8, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{2, 1, 3, 3}; + const std::vector outputs{// batch 1 + -12.000000f, -12.000000f, -4.000000f, + -10.799999f, -10.799995f, -3.600000f, + 44.299999f, 47.099998f, 16.000000f, + // batch 2 + -12.000000f, -12.000000f, -4.000000f, + -10.799999f, -10.799995f, -3.600000f, + 92.300003f, 95.099998f, 32.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +// group & deformable_group attributes (real offsets) +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_groups_basic) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 2 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{ // channel 1 + 505.800020f, 235.800000f, + 219.600000f, 99.000000f, + // channel 2 + -1153.800000f, -523.800000f, + -471.600000f, -207.0000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_groups_complex) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 4; + const int64_t deformable_group = 1; + + const Shape inputs_shape{1, 8, 3, 3}; + const std::vector inputs{ // channel 1 + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + // channel 2 + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + // channel 3 + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + // channel 4 + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f, + // channel 5 + 37.0f, 38.0f, 39.0f, + 40.0f, 41.0f, 42.0f, + 43.0f, 44.0f, 45.0f, + // channel 6 + 46.0f, 47.0f, 48.0f, + 49.0f, 50.0f, 51.0f, + 52.0f, 53.0f, 54.0f, + // channel 7 + 55.0f, 56.0f, 57.0f, + 58.0f, 59.0f, 60.0f, + 61.0f, 62.0f, 63.0f, + // channel 8 + 64.0f, 65.0f, 66.0f, + 67.0f, 68.0f, 69.0f, + 70.0f, 71.0f, 72.0f,}; + + const Shape filter_shape{4, 2, 2, 2}; + const std::vector filter{ // filter 1 channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // filter 1 channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // filter 2 channel 1 + 9.0f, 10.0f, + 11.0f, 12.0f, + // filter 2 channel 2 + 13.0f, 14.0f, + 15.0f, 16.0f, + // filter 3 channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // filter 3 channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // filter 4 channel 1 + -9.0f, -10.0f, + -11.0f, -12.0f, + // filter 4 channel 2 + -13.0f, -14.0f, + -15.0f, -16.0f}; + + const Shape offsets_shape{1, 8, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 4, 2, 2}; + const std::vector outputs{ // channel 1 + 505.800020f, 235.800000f, + 219.600000f, 99.000000f, + // channel 2 + 3054.600000f, 1488.600000f, + 1465.200100f, 711.000000f, + // channel 3 + -1801.799900f, -811.80000f, + -723.600000f, -315.000000f, + // channel 4 + -6654.600000f, -3216.600000f, + -3121.200000f, -1503.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_deforgroup_basic) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 2, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 16, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 758.000000f, 792.000000f, 366.399993f, + 893.200012f, 927.200012f, 426.399993f, + 381.399993f, 394.600006f, 176.000000f, + // output 2 + -758.000000f, -792.000000f, -366.399993f, + -893.200012f, -927.200012f, -426.399993f, + -381.399993f, -394.600006f, -176.000000f, + }; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_deforgroup_complex1) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 4; + + const Shape inputs_shape{1, 4, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f, + // channel 3 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 4 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 4, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f1: channel 3 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 4 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // f2: channel 3 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 4 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 32, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 1516.000000f, 1583.999877f, 732.799987f, + 1786.400146f, 1854.400024f, 852.799987f, + 762.799987f, 789.200012f, 352.000000f, + // output 2 + -1516.000000f, -1583.999877f, -732.799987f, + -1786.400146f, -1854.400024f, -852.799987f, + -762.799987f, -789.200012f, -352.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_deforgroup_complex2) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 1; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 4, 4, 4}; + const std::vector inputs{// channel 1 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 2 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f, + // channel 3 + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f, + // channel 4 + 17.0f, 18.0f, 19.0f, 20.0f, + 21.0f, 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, 28.0f, + 29.0f, 30.0f, 31.0f, 32.0f}; + + const Shape filter_shape{2, 4, 2, 2}; + const std::vector filter{// f1: channel 1 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 2 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f1: channel 3 + 1.0f, 2.0f, + 3.0f, 4.0f, + // f1: channel 4 + 5.0f, 6.0f, + 7.0f, 8.0f, + // f2: channel 1 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 2 + -5.0f, -6.0f, + -7.0f, -8.0f, + // f2: channel 3 + -1.0f, -2.0f, + -3.0f, -4.0f, + // f2: channel 4 + -5.0f, -6.0f, + -7.0f, -8.0f}; + + const Shape offsets_shape{1, 16, 3, 3}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 3, 3}; + const std::vector outputs{// output 1 + 1516.000000f, 1583.999877f, 732.799987f, + 1786.400146f, 1854.400024f, 852.799987f, + 762.799987f, 789.200012f, 352.000000f, + // output 2 + -1516.000000f, -1583.999877f, -732.799987f, + -1786.400146f, -1854.400024f, -852.799987f, + -762.799987f, -789.200012f, -352.000000f, + }; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape,strides, padding, + dilations, group, deformable_group, tolerance_bits); +} + +NGRAPH_TEST(${BACKEND_NAME}, deformable_convolution_2D_real_offsets_groups_and_deforgroups) +{ + const Strides strides{1, 1}; + const CoordinateDiff padding{0, 0}; + const Strides dilations{1, 1}; + const int64_t group = 2; + const int64_t deformable_group = 2; + + const Shape inputs_shape{1, 4, 3, 3}; + const std::vector inputs{1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, + 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, + 16.0f, 17.0f, 18.0f, + 19.0f, 20.0f, 21.0f, + 22.0f, 23.0f, 24.0f, + 25.0f, 26.0f, 27.0f, + 28.0f, 29.0f, 30.0f, + 31.0f, 32.0f, 33.0f, + 34.0f, 35.0f, 36.0f}; + + const Shape filter_shape{2, 2, 2, 2}; + const std::vector filter{1.0f, 2.0f, + 3.0f, 4.0f, + 5.0f, 6.0f, + 7.0f, 8.0f, + -1.0f, -2.0f, + -3.0f, -4.0f, + -5.0f, -6.0f, + -7.0f, -8.0f, + }; + + const Shape offsets_shape{1, 16, 2, 2}; + const std::vector offsets(ngraph::shape_size(offsets_shape), 1.1f); + + const Shape outputs_shape{1, 2, 2, 2}; + const std::vector outputs{505.800020f, 235.800000f, + 219.600000f, 99.000000f, + -1153.800000f, -523.800000f, + -471.600000f, -207.000000f}; + + const size_t tolerance_bits = 6; + DeformableConvolutionTest(inputs, inputs_shape, offsets, offsets_shape, filter, + filter_shape, outputs, outputs_shape, strides, padding, + dilations, group, deformable_group, tolerance_bits); +} diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 5bc3e7769f5..ea2955000d6 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1669,3 +1669,14 @@ onnx_upsample6_dynamic # random values returned from the plugin: ticket 51762 onnx_model_deformable_conv_2d + +# DeformableConvolution groups attribute: ticket 53312 +IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_basic +IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_complex +IE_CPU.deformable_convolution_2D_zeroed_offsets_groups_and_deforgroups +IE_CPU.deformable_convolution_2D_integral_offsets_groups_basic +IE_CPU.deformable_convolution_2D_integral_offsets_groups_complex +IE_CPU.deformable_convolution_2D_integral_offsets_groups_and_deforgroups +IE_CPU.deformable_convolution_2D_real_offsets_groups_basic +IE_CPU.deformable_convolution_2D_real_offsets_groups_complex +IE_CPU.deformable_convolution_2D_real_offsets_groups_and_deforgroups diff --git a/ngraph/test/runtime/interpreter/evaluates_map.cpp b/ngraph/test/runtime/interpreter/evaluates_map.cpp index 321c7bb7e0e..8e711c29dcb 100644 --- a/ngraph/test/runtime/interpreter/evaluates_map.cpp +++ b/ngraph/test/runtime/interpreter/evaluates_map.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -331,6 +332,37 @@ namespace return true; } + template + bool evaluate(const shared_ptr& op, + const HostTensorVector& outputs, + const HostTensorVector& inputs) + { + const auto in_data_ptr = inputs[0]->get_data_ptr(); + const auto offset_data_ptr = inputs[1]->get_data_ptr(); + const auto filter_data_ptr = inputs[2]->get_data_ptr(); + auto out_data_ptr = outputs[0]->get_data_ptr(); + const auto& out_shape = outputs[0]->get_shape(); + const auto& in_shape = inputs[0]->get_shape(); + const auto& offset_shape = inputs[1]->get_shape(); + const auto& filter_shape = inputs[2]->get_shape(); + runtime::reference::deformable_convolution::value_type>( + in_data_ptr, + offset_data_ptr, + filter_data_ptr, + out_data_ptr, + in_shape, + offset_shape, + filter_shape, + out_shape, + op->get_strides(), + op->get_dilations(), + op->get_pads_begin(), + op->get_pads_end(), + op->get_group(), + op->get_deformable_group()); + return true; + } + namespace cum_sum_v0 { template diff --git a/ngraph/test/runtime/interpreter/opset_int_tbl.hpp b/ngraph/test/runtime/interpreter/opset_int_tbl.hpp index 2eb25b7b0ec..abf494d55d3 100644 --- a/ngraph/test/runtime/interpreter/opset_int_tbl.hpp +++ b/ngraph/test/runtime/interpreter/opset_int_tbl.hpp @@ -43,6 +43,7 @@ NGRAPH_OP(Convolution, ngraph::op::v1) NGRAPH_OP(ConvolutionBackpropData, ngraph::op::v1) NGRAPH_OP(GroupConvolution, ngraph::op::v1) NGRAPH_OP(GroupConvolutionBackpropData, ngraph::op::v1) +NGRAPH_OP(DeformableConvolution, ngraph::op::v1) NGRAPH_OP(LessEqual, op::v1) NGRAPH_OP(LogicalAnd, op::v1) NGRAPH_OP(LogicalOr, op::v1) diff --git a/ngraph/test/type_prop/convolution.cpp b/ngraph/test/type_prop/convolution.cpp index afd26ff71e7..1e72cf391b5 100644 --- a/ngraph/test/type_prop/convolution.cpp +++ b/ngraph/test/type_prop/convolution.cpp @@ -2702,83 +2702,3 @@ TEST(type_prop, conv_bprop_v1_partial_auto_padding_lower) ASSERT_EQ(conv->get_pads_begin(), (CoordinateDiff{0, 0})); ASSERT_EQ(conv->get_pads_end(), (CoordinateDiff{0, 0})); } - -TEST(type_prop, deformable_conv_incorrect_group) -{ - const PartialShape data_batch_shape{1, 3, 96, 96}; - const PartialShape deformable_values_shape{1, 50, 5, 5}; - const PartialShape filters_shape{4, 3, 5, 5}; - - auto param0 = make_shared(element::f32, data_batch_shape); - auto param1 = make_shared(element::f32, deformable_values_shape); - auto param2 = make_shared(element::f32, filters_shape); - - try - { - make_shared(param0, - param1, - param2, - Strides{}, - CoordinateDiff{}, - CoordinateDiff{}, - Strides{}, - op::PadType::EXPLICIT, - 2); - - FAIL() << "DeformableConvolution created with incorrect 'group' value"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), "input data shape must be evenly divisible"); - } - - try - { - make_shared(param0, - param1, - param2, - Strides{}, - CoordinateDiff{}, - CoordinateDiff{}, - Strides{}, - op::PadType::EXPLICIT, - 3); - - FAIL() << "DeformableConvolution created with incorrect 'group' value"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), "weights shape must be evenly divisible"); - } -} - -TEST(type_prop, deformable_conv_incorrect_deformable_group) -{ - const PartialShape data_batch_shape{1, 3, 96, 96}; - const PartialShape deformable_values_shape{1, 50, 5, 5}; - const PartialShape filters_shape{3, 3, 5, 5}; - - auto param0 = make_shared(element::f32, data_batch_shape); - auto param1 = make_shared(element::f32, deformable_values_shape); - auto param2 = make_shared(element::f32, filters_shape); - - try - { - make_shared(param0, - param1, - param2, - Strides{}, - CoordinateDiff{}, - CoordinateDiff{}, - Strides{}, - op::PadType::EXPLICIT, - 1, - 7); - - FAIL() << "DeformableConvolution created with incorrect 'deformable group' value"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), "deformable values input must be evenly divisible"); - } -} diff --git a/ngraph/test/type_prop/deformable_convolution.cpp b/ngraph/test/type_prop/deformable_convolution.cpp index 3b1935967cb..ee5d94ceec7 100644 --- a/ngraph/test/type_prop/deformable_convolution.cpp +++ b/ngraph/test/type_prop/deformable_convolution.cpp @@ -11,9 +11,9 @@ using namespace ngraph; TEST(type_prop, deformable_conv_v1_partial_auto_padding_same) { - const PartialShape data_batch_shape{1, 4, 5, 5}; + const PartialShape data_batch_shape{1, 8, 5, 5}; const PartialShape deformable_shape{1, 4, 3, 3}; - const PartialShape filters_shape{4, 4, 3, 3}; + const PartialShape filters_shape{4, 2, 3, 3}; Strides strides{1, 1}; CoordinateDiff pads_begin{0, 0}; CoordinateDiff pads_end{0, 0}; @@ -112,9 +112,9 @@ TEST(type_prop, deformable_conv_v1_partial_auto_padding_same_nc_dims_dynamic_sam TEST(type_prop, deformable_conv_v1_partial_auto_padding_same_spatial_dims_dynamic) { - const PartialShape data_batch_shape{1, 4, Dimension::dynamic(), 5}; + const PartialShape data_batch_shape{1, 8, Dimension::dynamic(), 5}; const PartialShape deformable_shape{1, 4, 3, 3}; - const PartialShape filters_shape{4, 4, 3, 3}; + const PartialShape filters_shape{4, 2, 3, 3}; Strides strides{1, 1}; CoordinateDiff pads_begin{0, 0}; CoordinateDiff pads_end{0, 0}; @@ -143,3 +143,83 @@ TEST(type_prop, deformable_conv_v1_partial_auto_padding_same_spatial_dims_dynami ASSERT_EQ(deformable_conv->get_pads_begin(), (CoordinateDiff{0, 1})); ASSERT_EQ(deformable_conv->get_pads_end(), (CoordinateDiff{0, 1})); } + +TEST(type_prop, deformable_conv_incorrect_group) +{ + const PartialShape data_batch_shape{1, 3, 96, 96}; + const PartialShape deformable_values_shape{1, 50, 5, 5}; + const PartialShape filters_shape{4, 3, 5, 5}; + + auto param0 = make_shared(element::f32, data_batch_shape); + auto param1 = make_shared(element::f32, deformable_values_shape); + auto param2 = make_shared(element::f32, filters_shape); + + try + { + make_shared(param0, + param1, + param2, + Strides{}, + CoordinateDiff{}, + CoordinateDiff{}, + Strides{}, + op::PadType::EXPLICIT, + 2); + + FAIL() << "DeformableConvolution created with incorrect 'group' value"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "input data shape must be evenly divisible"); + } + + try + { + make_shared(param0, + param1, + param2, + Strides{}, + CoordinateDiff{}, + CoordinateDiff{}, + Strides{}, + op::PadType::EXPLICIT, + 3); + + FAIL() << "DeformableConvolution created with incorrect 'group' value"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "weights shape must be evenly divisible"); + } +} + +TEST(type_prop, deformable_conv_incorrect_deformable_group) +{ + const PartialShape data_batch_shape{1, 3, 96, 96}; + const PartialShape deformable_values_shape{1, 50, 5, 5}; + const PartialShape filters_shape{3, 3, 5, 5}; + + auto param0 = make_shared(element::f32, data_batch_shape); + auto param1 = make_shared(element::f32, deformable_values_shape); + auto param2 = make_shared(element::f32, filters_shape); + + try + { + make_shared(param0, + param1, + param2, + Strides{}, + CoordinateDiff{}, + CoordinateDiff{}, + Strides{}, + op::PadType::EXPLICIT, + 1, + 7); + + FAIL() << "DeformableConvolution created with incorrect 'deformable group' value"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "deformable values input must be evenly divisible"); + } +} From 46987def54052189321796e275afb1920fbd8a9e Mon Sep 17 00:00:00 2001 From: Anton Pankratv Date: Mon, 19 Apr 2021 15:16:47 +0300 Subject: [PATCH 06/78] Merged internal Infer Request implementation (#5125) --- docs/IE_PLUGIN_DG/InferRequest.md | 6 +- docs/snippets/example_async_infer_request.cpp | 2 +- docs/snippets/movidius-programming-guide.cpp | 2 +- .../src/template_async_infer_request.hpp | 2 +- .../src/template_executable_network.cpp | 9 +- .../src/template_executable_network.hpp | 4 +- .../src/template_infer_request.cpp | 6 +- .../src/template_infer_request.hpp | 5 +- docs/template_plugin/src/template_plugin.cpp | 1 + .../include/cpp/ie_executable_network.hpp | 2 +- .../include/cpp/ie_infer_request.hpp | 282 ++++-------- .../include/ie_iinfer_request.hpp | 4 +- .../cldnn_async_infer_request.cpp | 2 +- .../cldnn_engine/cldnn_async_infer_request.h | 4 +- .../src/cldnn_engine/cldnn_engine.cpp | 1 + .../cldnn_engine/cldnn_executable_network.cpp | 7 +- .../cldnn_engine/cldnn_executable_network.h | 6 +- .../src/cldnn_engine/cldnn_infer_request.cpp | 4 +- .../src/cldnn_engine/cldnn_infer_request.h | 3 +- .../src/gna_plugin/gna_executable_network.hpp | 11 +- .../src/gna_plugin/gna_infer_request.hpp | 22 +- .../hetero_async_infer_request.cpp | 6 +- .../hetero_async_infer_request.hpp | 4 +- .../hetero_executable_network.cpp | 6 +- .../hetero_executable_network.hpp | 4 +- .../hetero_plugin/hetero_infer_request.cpp | 4 +- .../hetero_plugin/hetero_infer_request.hpp | 5 +- .../src/inference_engine/CMakeLists.txt | 1 + .../cpp/ie_executable_network.cpp | 2 +- .../inference_engine/cpp/ie_infer_request.cpp | 209 +++++++++ .../interface/ie_iinfer_request_internal.cpp | 325 ++++++++++++++ .../src/inference_engine/ie_common.cpp | 34 +- .../mkldnn_async_infer_request.cpp | 2 +- .../mkldnn_async_infer_request.h | 4 +- .../src/mkldnn_plugin/mkldnn_exec_network.cpp | 4 +- .../src/mkldnn_plugin/mkldnn_exec_network.h | 4 +- .../mkldnn_plugin/mkldnn_infer_request.cpp | 4 +- .../src/mkldnn_plugin/mkldnn_infer_request.h | 10 +- .../multi_device_async_infer_request.hpp | 2 +- .../multi_device_exec_network.cpp | 16 +- .../multi_device_exec_network.hpp | 6 +- .../multi_device_infer_request.cpp | 6 +- .../multi_device_infer_request.hpp | 7 +- .../src/multi_device/multi_device_plugin.cpp | 1 + .../base/ie_executable_network_base.hpp | 3 +- .../base/ie_infer_async_request_base.hpp | 106 ++++- .../cpp_interfaces/exception2status.hpp | 56 +-- .../impl/ie_executable_network_internal.hpp | 26 +- ...cutable_network_thread_safe_async_only.hpp | 59 --- ...executable_network_thread_safe_default.hpp | 23 +- .../impl/ie_infer_async_request_internal.hpp | 82 ---- ...nfer_async_request_thread_safe_default.hpp | 77 +--- .../impl/ie_infer_request_internal.hpp | 422 ------------------ .../ie_iexecutable_network_internal.hpp | 6 +- .../ie_iinfer_async_request_internal.hpp | 66 --- .../interface/ie_iinfer_request_internal.hpp | 165 ++++++- .../myriad_async_infer_request.h | 2 +- .../myriad_plugin/myriad_executable_network.h | 9 +- .../myriad_plugin/myriad_infer_request.cpp | 2 +- .../vpu/myriad_plugin/myriad_infer_request.h | 3 +- .../async_infer_request_test.cpp | 7 +- .../inference_engine/caching_test.cpp | 14 +- .../behavior/infer_request_callback.hpp | 20 +- .../include/behavior/infer_request_output.hpp | 4 +- .../ie_test_utils/unit_test_utils/empty.cpp | 4 - .../impl/mock_async_infer_request_default.hpp | 4 +- .../mock_async_infer_request_internal.hpp | 37 -- .../impl/mock_executable_network_internal.hpp | 5 +- ...mock_executable_thread_safe_async_only.hpp | 23 - .../mock_executable_thread_safe_default.hpp | 2 +- .../impl/mock_infer_request_internal.hpp | 27 -- .../mock_iasync_infer_request_internal.hpp | 32 -- .../mock_iexecutable_network_internal.hpp | 4 +- .../mock_iinfer_request_internal.hpp | 20 +- .../interface/mock_iinference_plugin.hpp | 5 +- .../ie_executable_network_base_test.cpp | 81 +--- .../ie_infer_async_request_base_test.cpp | 218 ++++----- ...async_request_thread_safe_default_test.cpp | 70 +-- .../ie_memory_state_internal_test.cpp | 67 +-- .../cpp_interfaces/ie_plugin_test.cpp | 81 ++-- .../inference_engine/ie_exception_test.cpp | 9 - .../ie_executable_network_test.cpp | 41 +- .../unit/engines/gna/gna_matcher.cpp | 1 + .../graph/structure/graph_structure_test.cpp | 82 ++-- 84 files changed, 1312 insertions(+), 1704 deletions(-) create mode 100644 inference-engine/src/inference_engine/cpp/ie_infer_request.cpp create mode 100644 inference-engine/src/inference_engine/cpp_interfaces/interface/ie_iinfer_request_internal.cpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_async_only.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_internal.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_internal.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp delete mode 100644 inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp delete mode 100644 inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp delete mode 100644 inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp delete mode 100644 inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp diff --git a/docs/IE_PLUGIN_DG/InferRequest.md b/docs/IE_PLUGIN_DG/InferRequest.md index d5798988980..c512f42c551 100644 --- a/docs/IE_PLUGIN_DG/InferRequest.md +++ b/docs/IE_PLUGIN_DG/InferRequest.md @@ -8,7 +8,7 @@ `InferRequest` Class ------------------------ -Inference Engine Plugin API provides the helper InferenceEngine::InferRequestInternal class recommended +Inference Engine Plugin API provides the helper InferenceEngine::IInferRequestInternal class recommended to use as a base class for a synchronous inference request implementation. Based of that, a declaration of a synchronous request class can look as follows: @@ -46,7 +46,7 @@ Decrements a number of created inference requests: ### `InferImpl()` -**Implementation details:** Base InferRequestInternal class implements the public InferenceEngine::InferRequestInternal::Infer method as following: +**Implementation details:** Base IInferRequestInternal class implements the public InferenceEngine::IInferRequestInternal::Infer method as following: - Checks blobs set by users - Calls the `InferImpl` method defined in a derived class to call actual pipeline stages synchronously @@ -59,7 +59,7 @@ Below is the code of the the `inferPreprocess` method to demonstrate Inference E @snippet src/template_infer_request.cpp infer_request:infer_preprocess **Details:** -* `InferImpl` must call the InferenceEngine::InferRequestInternal::execDataPreprocessing function, which executes common Inference Engine preprocessing step (for example, applies resize or color conversion operations) if it is set by the user. The output dimensions, layout and precision matches the input information set via InferenceEngine::CNNNetwork::getInputsInfo. +* `InferImpl` must call the InferenceEngine::IInferRequestInternal::execDataPreprocessing function, which executes common Inference Engine preprocessing step (for example, applies resize or color conversion operations) if it is set by the user. The output dimensions, layout and precision matches the input information set via InferenceEngine::CNNNetwork::getInputsInfo. * If `inputBlob` passed by user differs in terms of precisions from precision expected by plugin, `blobCopy` is performed which does actual precision conversion. #### 2. `startPipeline` diff --git a/docs/snippets/example_async_infer_request.cpp b/docs/snippets/example_async_infer_request.cpp index b8b2146ff10..782182f5caa 100644 --- a/docs/snippets/example_async_infer_request.cpp +++ b/docs/snippets/example_async_infer_request.cpp @@ -8,7 +8,7 @@ using namespace InferenceEngine; -class AcceleratorSyncRequest : public InferRequestInternal { +class AcceleratorSyncRequest : public IInferRequestInternal { public: using Ptr = std::shared_ptr; diff --git a/docs/snippets/movidius-programming-guide.cpp b/docs/snippets/movidius-programming-guide.cpp index c0213615f6c..ffd25c8b6cf 100644 --- a/docs/snippets/movidius-programming-guide.cpp +++ b/docs/snippets/movidius-programming-guide.cpp @@ -2,7 +2,7 @@ int main() { InferenceEngine::Core core; -InferenceEngine::IInferRequest::CompletionCallback callback; +InferenceEngine::IInferRequest::CompletionCallback callback = nullptr; int numRequests = 42; int i = 1; auto network = core.ReadNetwork("sample.xml"); diff --git a/docs/template_plugin/src/template_async_infer_request.hpp b/docs/template_plugin/src/template_async_infer_request.hpp index f3fa7f8d47a..51221f908ee 100644 --- a/docs/template_plugin/src/template_async_infer_request.hpp +++ b/docs/template_plugin/src/template_async_infer_request.hpp @@ -18,7 +18,7 @@ public: const InferenceEngine::ITaskExecutor::Ptr& waitExecutor, const InferenceEngine::ITaskExecutor::Ptr& callbackExecutor); - ~TemplateAsyncInferRequest() override; + ~TemplateAsyncInferRequest(); private: TemplateInferRequest::Ptr _inferRequest; diff --git a/docs/template_plugin/src/template_executable_network.cpp b/docs/template_plugin/src/template_executable_network.cpp index b20eb939b71..07d6ca2459d 100644 --- a/docs/template_plugin/src/template_executable_network.cpp +++ b/docs/template_plugin/src/template_executable_network.cpp @@ -131,21 +131,18 @@ void TemplatePlugin::ExecutableNetwork::InitExecutor() { // ! [executable_network:create_infer_request_impl] -InferenceEngine::InferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, +InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) { return std::make_shared(networkInputs, networkOutputs, std::static_pointer_cast(shared_from_this())); } // ! [executable_network:create_infer_request_impl] // ! [executable_network:create_infer_request] -InferenceEngine::IInferRequest::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequest() { +InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequest() { InferenceEngine::IInferRequest::Ptr asyncRequest; auto internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs); - auto asyncThreadSafeImpl = std::make_shared(std::static_pointer_cast(internalRequest), + return std::make_shared(std::static_pointer_cast(internalRequest), _taskExecutor, _plugin->_waitExecutor, _callbackExecutor); - asyncRequest.reset(new InferenceEngine::InferRequestBase(asyncThreadSafeImpl)); - asyncThreadSafeImpl->SetPointerToPublicInterface(asyncRequest); - return asyncRequest; } // ! [executable_network:create_infer_request] diff --git a/docs/template_plugin/src/template_executable_network.hpp b/docs/template_plugin/src/template_executable_network.hpp index b1d0d3b0958..d2fb8629000 100644 --- a/docs/template_plugin/src/template_executable_network.hpp +++ b/docs/template_plugin/src/template_executable_network.hpp @@ -36,9 +36,9 @@ public: // Methods from a base class ExecutableNetworkThreadSafeDefault void ExportImpl(std::ostream& model) override; - InferenceEngine::InferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) override; - InferenceEngine::IInferRequest::Ptr CreateInferRequest() override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::Parameter GetMetric(const std::string &name) const override; InferenceEngine::Parameter GetConfig(const std::string &name) const override; diff --git a/docs/template_plugin/src/template_infer_request.cpp b/docs/template_plugin/src/template_infer_request.cpp index 6394fe491d3..58ea5fe40d7 100644 --- a/docs/template_plugin/src/template_infer_request.cpp +++ b/docs/template_plugin/src/template_infer_request.cpp @@ -33,7 +33,7 @@ using Time = std::chrono::high_resolution_clock; TemplateInferRequest::TemplateInferRequest(const InferenceEngine::InputsDataMap& networkInputs, const InferenceEngine::OutputsDataMap& networkOutputs, const std::shared_ptr& executableNetwork) : - InferRequestInternal(networkInputs, networkOutputs), + IInferRequestInternal(networkInputs, networkOutputs), _executableNetwork(executableNetwork) { // TODO: allocate infer request device and host buffers if needed, fill actual list of profiling tasks @@ -178,9 +178,9 @@ static void blobCopy(const Blob::Ptr& src, const Blob::Ptr& dst) { void TemplateInferRequest::inferPreprocess() { OV_ITT_SCOPED_TASK(itt::domains::TemplatePlugin, _profilingTask[Preprocess]); auto start = Time::now(); - // NOTE: After InferRequestInternal::execDataPreprocessing call + // NOTE: After IInferRequestInternal::execDataPreprocessing call // input can points to other memory region than it was allocated in constructor. - InferRequestInternal::execDataPreprocessing(_deviceInputs); + IInferRequestInternal::execDataPreprocessing(_deviceInputs); for (auto&& networkInput : _deviceInputs) { auto index = _executableNetwork->_inputIndex[networkInput.first]; const auto& parameter = _parameters[index]; diff --git a/docs/template_plugin/src/template_infer_request.hpp b/docs/template_plugin/src/template_infer_request.hpp index a6956be4a6a..41232f20c9c 100644 --- a/docs/template_plugin/src/template_infer_request.hpp +++ b/docs/template_plugin/src/template_infer_request.hpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -27,14 +26,14 @@ namespace TemplatePlugin { class ExecutableNetwork; // ! [infer_request:header] -class TemplateInferRequest : public InferenceEngine::InferRequestInternal { +class TemplateInferRequest : public InferenceEngine::IInferRequestInternal { public: typedef std::shared_ptr Ptr; TemplateInferRequest(const InferenceEngine::InputsDataMap& networkInputs, const InferenceEngine::OutputsDataMap& networkOutputs, const std::shared_ptr& executableNetwork); - ~TemplateInferRequest() override; + ~TemplateInferRequest(); void InferImpl() override; std::map GetPerformanceCounts() const override; diff --git a/docs/template_plugin/src/template_plugin.cpp b/docs/template_plugin/src/template_plugin.cpp index ca3dbbdacfe..d9a8af3c8e2 100644 --- a/docs/template_plugin/src/template_plugin.cpp +++ b/docs/template_plugin/src/template_plugin.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 367b43966a5..19f3970de55 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -4,7 +4,7 @@ /** * @brief A header file that provides ExecutableNetwork class - * + * * @file ie_executable_network.hpp */ diff --git a/inference-engine/include/cpp/ie_infer_request.hpp b/inference-engine/include/cpp/ie_infer_request.hpp index 9650cbb9dea..fc8b5d13a63 100644 --- a/inference-engine/include/cpp/ie_infer_request.hpp +++ b/inference-engine/include/cpp/ie_infer_request.hpp @@ -18,44 +18,13 @@ #include "ie_iinfer_request.hpp" #include "details/ie_so_loader.h" #include "ie_blob.h" +#include "ie_iinfer_request.hpp" namespace InferenceEngine { - namespace details { - -class ICompletionCallbackWrapper { -public: - virtual ~ICompletionCallbackWrapper() = default; - - virtual void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept = 0; -}; - -template -class CompletionCallbackWrapper : public ICompletionCallbackWrapper { - T lambda; - -public: - explicit CompletionCallbackWrapper(const T& lambda): lambda(lambda) {} - - void call(InferenceEngine::IInferRequest::Ptr /*request*/, InferenceEngine::StatusCode /*code*/) const - noexcept override { - lambda(); - } -}; - -template <> -class CompletionCallbackWrapper : public ICompletionCallbackWrapper { - IInferRequest::CompletionCallback callBack; - -public: - explicit CompletionCallbackWrapper(const IInferRequest::CompletionCallback& callBack): callBack(callBack) {} - - void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept override { - callBack(request, code); - } -}; - -} // namespace details +class SharedObjectLoader; +} +class IInferRequestInternal; /** * @copybrief IInferRequest @@ -63,42 +32,41 @@ public: * Wraps IInferRequest * It can throw exceptions safely for the application, where it is properly handled. */ -class InferRequest { - IInferRequest::Ptr actual; - InferenceEngine::details::SharedObjectLoader::Ptr plg; - std::shared_ptr callback; +class INFERENCE_ENGINE_API_CLASS(InferRequest) { + std::shared_ptr _impl; + std::shared_ptr _so; - static void callWrapper(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) { - details::ICompletionCallbackWrapper* pWrapper = nullptr; - ResponseDesc dsc; - request->GetUserData(reinterpret_cast(&pWrapper), &dsc); - pWrapper->call(request, code); - } + explicit InferRequest(const std::shared_ptr& impl, + const std::shared_ptr& so); + + friend class ExecutableNetwork; public: + /** + * @enum WaitMode + * @brief Enumeration to hold wait mode for IInferRequest + */ + enum WaitMode : int64_t { + /** Wait until inference result becomes available */ + RESULT_READY = -1, + /** IInferRequest doesn't block or interrupt current thread and immediately returns inference status */ + STATUS_ONLY = 0, + }; + + /** + * @brief A smart pointer to the InferRequest object + */ + using Ptr = std::shared_ptr; + /** * @brief Default constructor */ InferRequest() = default; - /** - * constructs InferRequest from the initialized shared_pointer - * @param request Initialized shared pointer to IInferRequest interface - * @param splg Plugin to use. This is required to ensure that InferRequest can work properly even if plugin object is destroyed. - */ - explicit InferRequest(IInferRequest::Ptr request, - InferenceEngine::details::SharedObjectLoader::Ptr splg = {}): - actual(request), plg(splg) { - // plg can be null, but not the actual - if (actual == nullptr) IE_THROW() << "InferRequest was not initialized."; - } - /** * @brief Destructor */ - ~InferRequest() { - actual = nullptr; - } + ~InferRequest(); /** * @brief Sets input/output data to infer @@ -108,27 +76,16 @@ public: * @param data Reference to input or output blob. The type of a blob must match the network input precision and * size. */ - void SetBlob(const std::string& name, const Blob::Ptr& data) { - CALL_STATUS_FNC(SetBlob, name.c_str(), data); - } + void SetBlob(const std::string& name, const Blob::Ptr& data); /** - * @copybrief IInferRequest::GetBlob + * @brief Gets input/output data for inference * - * Wraps IInferRequest::GetBlob + * @note Memory allocation does not happen * @param name A name of Blob to get * @return A shared pointer to a Blob with a name @p name. If a blob is not found, an exception is thrown. */ - Blob::Ptr GetBlob(const std::string& name) { - Blob::Ptr data; - CALL_STATUS_FNC(GetBlob, name.c_str(), data); - std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; - auto blobPtr = data.get(); - const bool remoteBlobPassed = blobPtr->is(); - if (blobPtr == nullptr) IE_THROW() << error; - if (!remoteBlobPassed && blobPtr->buffer() == nullptr) IE_THROW() << error; - return data; - } + Blob::Ptr GetBlob(const std::string& name); /** * @brief Sets blob with a pre-process information @@ -137,51 +94,37 @@ public: * @param data A reference to input. The type of Blob must correspond to the network input precision and size. * @param info Preprocess info for blob. */ - void SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) { - CALL_STATUS_FNC(SetBlob, name.c_str(), data, info); - } + void SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info); /** * @brief Gets pre-process for input data * @param name Name of input blob. * @return pointer to pre-process info of blob with name */ - const PreProcessInfo& GetPreProcess(const std::string& name) const { - const PreProcessInfo* info = nullptr; - CALL_STATUS_FNC(GetPreProcess, name.c_str(), &info); - return *info; - } + const PreProcessInfo& GetPreProcess(const std::string& name) const; /** - * @copybrief IInferRequest::Infer + * @brief Infers specified input(s) in synchronous mode + * * @note blocks all methods of InferRequest while request is ongoing (running or waiting in queue) * - * Wraps IInferRequest::Infer */ - void Infer() { - CALL_STATUS_FNC_NO_ARGS(Infer); - } + void Infer(); /** - * @copybrief IInferRequest::Cancel - * - * Wraps IInferRequest::Cancel + * @brief Cancel inference request + * @param name Name of input blob. + * @return pointer to pre-process info of blob with name */ - void Cancel() { - CALL_STATUS_FNC_NO_ARGS(Cancel); - } + void Cancel(); /** - * @copybrief IInferRequest::GetPerformanceCounts + * @brief Queries performance measures per layer to get feedback of what is the most time consuming layer * - * Wraps IInferRequest::GetPerformanceCounts + * @note not all plugins provide meaningful data * @return Map of layer names to profiling information for that layer */ - std::map GetPerformanceCounts() const { - std::map perfMap; - CALL_STATUS_FNC(GetPerformanceCounts, perfMap); - return perfMap; - } + std::map GetPerformanceCounts() const; /** * @brief Sets input data to infer @@ -190,11 +133,7 @@ public: * @param inputs A reference to a map of input blobs accessed by input names. * The type of Blob must correspond to the network input precision and size. */ - void SetInput(const BlobMap& inputs) { - for (auto&& input : inputs) { - CALL_STATUS_FNC(SetBlob, input.first.c_str(), input.second); - } - } + void SetInput(const BlobMap& inputs); /** * @brief Sets data that will contain result of the inference @@ -203,34 +142,27 @@ public: * @param results - a reference to a map of result blobs accessed by output names. * The type of Blob must correspond to the network output precision and size. */ - void SetOutput(const BlobMap& results) { - for (auto&& result : results) { - CALL_STATUS_FNC(SetBlob, result.first.c_str(), result.second); - } - } + void SetOutput(const BlobMap& results); /** * @brief Sets new batch size when dynamic batching is enabled in executable network that created this request. * * @param batch new batch size to be used by all the following inference calls for this request. */ - void SetBatch(const int batch) { - CALL_STATUS_FNC(SetBatch, batch); - } + void SetBatch(const int batch); /** * @brief Start inference of specified input(s) in asynchronous mode * * @note It returns immediately. Inference starts also immediately. */ - void StartAsync() { - CALL_STATUS_FNC_NO_ARGS(StartAsync); - } + void StartAsync(); /** - * @copybrief IInferRequest::Wait + * @brief Waits for the result to become available. Blocks until specified millis_timeout has elapsed or the result + * becomes available, whichever comes first. + * * - * Wraps IInferRequest::Wait * @param millis_timeout Maximum duration in milliseconds to block for * @note There are special cases when millis_timeout is equal some value of the WaitMode enum: * * STATUS_ONLY - immediately returns inference status (IInferRequest::RequestStatus). It does not block or @@ -238,105 +170,69 @@ public: * * RESULT_READY - waits until inference result becomes available * @return A status code of operation */ - StatusCode Wait(int64_t millis_timeout) { - ResponseDesc resp; - if (actual == nullptr) IE_THROW() << "InferRequest was not initialized."; - auto res = actual->Wait(millis_timeout, &resp); - if (res != OK && res != RESULT_NOT_READY && - res != INFER_NOT_STARTED && res != INFER_CANCELLED) { - IE_EXCEPTION_SWITCH(res, ExceptionType, - InferenceEngine::details::ThrowNow{} - <<= std::stringstream{} << IE_LOCATION << resp.msg) - } - return res; - } + StatusCode Wait(int64_t millis_timeout = RESULT_READY); +private: + void SetCompletionCallbackImpl(std::function); + void SetCompletionCallbackImpl(std::function); + void SetCompletionCallbackImpl(IInferRequest::CompletionCallback); + template + struct SetCallback { + void operator()(std::function f) {_this.SetCompletionCallbackImpl(std::move(f));} + InferRequest& _this; + }; + +public: /** - * @copybrief IInferRequest::SetCompletionCallback + * @brief Sets a callback function that will be called on success or failure of asynchronous request * - * Wraps IInferRequest::SetCompletionCallback - * - * @param callbackToSet Lambda callback object which will be called on processing finish. + * @param callbackToSet callback object which will be called on when inference finish. */ - template - void SetCompletionCallback(const T& callbackToSet) { - callback.reset(new details::CompletionCallbackWrapper(callbackToSet)); - CALL_STATUS_FNC(SetUserData, callback.get()); - actual->SetCompletionCallback(callWrapper); + template + void SetCompletionCallback(F callbackToSet) { + return SetCallback{*this}(std::move(callbackToSet)); } + /** - * @copybrief IExecutableNetwork::QueryState + * @brief Gets state control interface for given infer request. * - * Wraps IExecutableNetwork::QueryState + * State control essential for recurrent networks * @return A vector of Memory State objects */ - std::vector QueryState() { - IE_SUPPRESS_DEPRECATED_START - if (actual == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; - IVariableState::Ptr pState = nullptr; - auto res = OK; - std::vector controller; - for (size_t idx = 0; res == OK; ++idx) { - ResponseDesc resp; - res = actual->QueryState(pState, idx, &resp); - if (res != OK && res != OUT_OF_BOUNDS) { - IE_THROW() << resp.msg; - } - if (res != OUT_OF_BOUNDS) { - controller.push_back(VariableState(pState, plg)); - } - } - IE_SUPPRESS_DEPRECATED_END - - return controller; - } + std::vector QueryState(); /** * @brief IInferRequest pointer to be used directly in CreateInferRequest functions - * @return A shared pointer to underlying IInferRequest interface + * @return A shared pointer to IInferRequest interface */ - operator IInferRequest::Ptr&() { - if (actual == nullptr) IE_THROW() << "InferRequest was not initialized."; - return actual; - } + INFERENCE_ENGINE_DEPRECATED("Will be removed") + operator std::shared_ptr (); /** * @brief Checks if current InferRequest object is not initialized * @return true if current InferRequest object is not initialized, false - otherwise */ - bool operator!() const noexcept { - return !actual; - } + bool operator!() const noexcept; /** * @brief Checks if current InferRequest object is initialized * @return true if current InferRequest object is initialized, false - otherwise */ - explicit operator bool() const noexcept { - return !!actual; - } - - /** - * @brief A smart pointer to the InferRequest object - */ - using Ptr = std::shared_ptr; + explicit operator bool() const noexcept; }; - -namespace details { - -template <> -class CompletionCallbackWrapper> : public ICompletionCallbackWrapper { - std::function lambda; - -public: - explicit CompletionCallbackWrapper(const std::function& lambda) - : lambda(lambda) {} - - void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept override { - lambda(InferRequest(request), code); +template<> +struct InferRequest::SetCallback> { + void operator()(std::function f) { + _this.SetCompletionCallbackImpl(std::move(f)); } + InferRequest& _this; +}; +template<> +struct InferRequest::SetCallback { + void operator()(IInferRequest::CompletionCallback f) { + _this.SetCompletionCallbackImpl(std::move(f)); + } + InferRequest& _this; }; - -} // namespace details } // namespace InferenceEngine diff --git a/inference-engine/include/ie_iinfer_request.hpp b/inference-engine/include/ie_iinfer_request.hpp index a7b61a1f635..658b6d03e54 100644 --- a/inference-engine/include/ie_iinfer_request.hpp +++ b/inference-engine/include/ie_iinfer_request.hpp @@ -25,7 +25,8 @@ namespace InferenceEngine { * @brief This is an interface of asynchronous infer request * */ -class IInferRequest : public std::enable_shared_from_this { +IE_SUPPRESS_DEPRECATED_START +class INFERENCE_ENGINE_DEPRECATED("Do not use IInferRequest API") IInferRequest : public std::enable_shared_from_this { public: /** * @enum WaitMode @@ -201,5 +202,6 @@ public: protected: ~IInferRequest() = default; }; +IE_SUPPRESS_DEPRECATED_END } // namespace InferenceEngine \ No newline at end of file diff --git a/inference-engine/src/cldnn_engine/cldnn_async_infer_request.cpp b/inference-engine/src/cldnn_engine/cldnn_async_infer_request.cpp index 9f9f4dd61ea..c5d96b5e37e 100644 --- a/inference-engine/src/cldnn_engine/cldnn_async_infer_request.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_async_infer_request.cpp @@ -5,7 +5,7 @@ #include "cldnn_async_infer_request.h" #include -CLDNNPlugin::CLDNNAsyncInferRequest::CLDNNAsyncInferRequest(const InferenceEngine::InferRequestInternal::Ptr &inferRequest, +CLDNNPlugin::CLDNNAsyncInferRequest::CLDNNAsyncInferRequest(const InferenceEngine::IInferRequestInternal::Ptr &inferRequest, const InferenceEngine::ITaskExecutor::Ptr &taskExecutor, const InferenceEngine::ITaskExecutor::Ptr &callbackExecutor) : InferenceEngine::AsyncInferRequestThreadSafeDefault(inferRequest, taskExecutor, callbackExecutor) diff --git a/inference-engine/src/cldnn_engine/cldnn_async_infer_request.h b/inference-engine/src/cldnn_engine/cldnn_async_infer_request.h index ce97695cf11..1b5fd3769cf 100644 --- a/inference-engine/src/cldnn_engine/cldnn_async_infer_request.h +++ b/inference-engine/src/cldnn_engine/cldnn_async_infer_request.h @@ -13,13 +13,13 @@ namespace CLDNNPlugin { class CLDNNAsyncInferRequest : public InferenceEngine::AsyncInferRequestThreadSafeDefault { public: - CLDNNAsyncInferRequest(const InferenceEngine::InferRequestInternal::Ptr &inferRequest, + CLDNNAsyncInferRequest(const InferenceEngine::IInferRequestInternal::Ptr &inferRequest, const InferenceEngine::ITaskExecutor::Ptr &taskExecutor, const InferenceEngine::ITaskExecutor::Ptr &callbackExecutor); void Infer_ThreadUnsafe() override; - ~CLDNNAsyncInferRequest() override; + ~CLDNNAsyncInferRequest(); }; } // namespace CLDNNPlugin diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index c4ea12d757a..5ce4654dca0 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/inference-engine/src/cldnn_engine/cldnn_executable_network.cpp b/inference-engine/src/cldnn_engine/cldnn_executable_network.cpp index 70080c6b95b..c2289fa9fb0 100644 --- a/inference-engine/src/cldnn_engine/cldnn_executable_network.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_executable_network.cpp @@ -26,6 +26,7 @@ #include "cldnn_executable_network.h" #include "threading/ie_cpu_streams_executor.hpp" +#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" using namespace InferenceEngine; @@ -62,8 +63,8 @@ CLDNNExecNetwork::CLDNNExecNetwork(InferenceEngine::CNNNetwork &network, RemoteC } } -InferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, - OutputsDataMap networkOutputs) { +IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, + OutputsDataMap networkOutputs) { OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequestImpl"); if (m_graphs.empty()) { IE_THROW(NetworkNotLoaded); @@ -91,7 +92,7 @@ InferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMap return ptr; } -IInferRequest::Ptr CLDNNExecNetwork::CreateInferRequest() { +IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequest() { OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequest"); return CreateAsyncInferRequestFromSync(); } diff --git a/inference-engine/src/cldnn_engine/cldnn_executable_network.h b/inference-engine/src/cldnn_engine/cldnn_executable_network.h index 904d7196500..60c886a3fe7 100644 --- a/inference-engine/src/cldnn_engine/cldnn_executable_network.h +++ b/inference-engine/src/cldnn_engine/cldnn_executable_network.h @@ -26,9 +26,9 @@ public: CLDNNExecNetwork(InferenceEngine::CNNNetwork &network, InferenceEngine::RemoteContext::Ptr context, Config config); InferenceEngine::CNNNetwork GetExecGraphInfo() override; - InferenceEngine::IInferRequest::Ptr CreateInferRequest() override; - InferenceEngine::InferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, + InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::Parameter GetMetric(const std::string &name) const override; InferenceEngine::Parameter GetConfig(const std::string &name) const override; diff --git a/inference-engine/src/cldnn_engine/cldnn_infer_request.cpp b/inference-engine/src/cldnn_engine/cldnn_infer_request.cpp index e08c3e43713..23f9895970d 100644 --- a/inference-engine/src/cldnn_engine/cldnn_infer_request.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_infer_request.cpp @@ -12,6 +12,8 @@ #include "cldnn_remote_context.h" #include "cldnn_executable_network.h" #include "cldnn_itt.h" +#include +#include using namespace InferenceEngine; @@ -812,7 +814,7 @@ void CLDNNInferRequest::SetBatch(int new_batch) { CLDNNInferRequest::CLDNNInferRequest(InputsDataMap networkInputs, OutputsDataMap networkOutputs, const CLDNNExecNetwork::Ptr& execNetwork) - : InferRequestInternal(networkInputs, networkOutputs) + : IInferRequestInternal(networkInputs, networkOutputs) , m_useProfiling(false) , m_useStreams(false) { IE_ASSERT(nullptr != execNetwork); diff --git a/inference-engine/src/cldnn_engine/cldnn_infer_request.h b/inference-engine/src/cldnn_engine/cldnn_infer_request.h index b5068ebd789..f9ec4d94db5 100644 --- a/inference-engine/src/cldnn_engine/cldnn_infer_request.h +++ b/inference-engine/src/cldnn_engine/cldnn_infer_request.h @@ -9,7 +9,6 @@ #include #include #include -#include #include "cldnn_graph.h" #include @@ -22,7 +21,7 @@ struct buf_info { class CLDNNExecNetwork; -class CLDNNInferRequest : public InferenceEngine::InferRequestInternal { +class CLDNNInferRequest : public InferenceEngine::IInferRequestInternal { public: // make sure all blobs and cldnn::memory objects // are in place and valid diff --git a/inference-engine/src/gna_plugin/gna_executable_network.hpp b/inference-engine/src/gna_plugin/gna_executable_network.hpp index 76d3432f999..e929ad7ad79 100644 --- a/inference-engine/src/gna_plugin/gna_executable_network.hpp +++ b/inference-engine/src/gna_plugin/gna_executable_network.hpp @@ -8,16 +8,15 @@ #include #include -#include #include "gna_infer_request.hpp" #include "gna_plugin.hpp" #include #include -#include +#include namespace GNAPluginNS { -class GNAExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSafeAsyncOnly { +class GNAExecutableNetwork : public InferenceEngine::ExecutableNetworkInternal { std::shared_ptr plg; public: @@ -53,9 +52,9 @@ class GNAExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSafe : GNAExecutableNetwork(network, std::make_shared(config)) { } - InferenceEngine::AsyncInferRequestInternal::Ptr - CreateAsyncInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override { + InferenceEngine::IInferRequestInternal::Ptr + CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, + InferenceEngine::OutputsDataMap networkOutputs) override { return std::make_shared(plg, networkInputs, networkOutputs); } diff --git a/inference-engine/src/gna_plugin/gna_infer_request.hpp b/inference-engine/src/gna_plugin/gna_infer_request.hpp index 6ba7757a6c0..672e9fc4944 100644 --- a/inference-engine/src/gna_plugin/gna_infer_request.hpp +++ b/inference-engine/src/gna_plugin/gna_infer_request.hpp @@ -8,13 +8,12 @@ #include #include -#include "cpp_interfaces/impl/ie_infer_async_request_internal.hpp" -#include "cpp_interfaces/impl/ie_infer_request_internal.hpp" +#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" #include "gna_plugin.hpp" namespace GNAPluginNS { -class GNAInferRequest : public InferenceEngine::AsyncInferRequestInternal { +class GNAInferRequest : public InferenceEngine::IInferRequestInternal { protected: std::shared_ptr plg; uint32_t inferRequestIdx = -1; @@ -23,7 +22,7 @@ class GNAInferRequest : public InferenceEngine::AsyncInferRequestInternal { GNAInferRequest(const std::shared_ptr& plg, InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) - : InferenceEngine::AsyncInferRequestInternal(networkInputs, networkOutputs), plg(plg) { + : InferenceEngine::IInferRequestInternal(networkInputs, networkOutputs), plg(plg) { // TODO: internal connection API - better to generalize if (networkOutputs.empty()) { THROW_GNA_EXCEPTION << "GNAInferRequest :: network has zero outputs"; @@ -78,10 +77,19 @@ class GNAInferRequest : public InferenceEngine::AsyncInferRequestInternal { inferRequestIdx = plg->QueueInference(_inputs, _outputs); // workaround to unblock callback-based flows if (_callback) { - auto infer_request = _publicInterface.lock(); - IE_ASSERT(infer_request != nullptr); auto res = Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); - _callback(infer_request, res); + std::exception_ptr exceptionPtr; + if (res != InferenceEngine::StatusCode::OK) { + try { + IE_EXCEPTION_SWITCH(res, ExceptionType, + InferenceEngine::details::ThrowNow{} + <<= std::stringstream{} << IE_LOCATION + << InferenceEngine::details::ExceptionTraits::string()); + } catch (...) { + exceptionPtr = std::current_exception(); + } + } + _callback(exceptionPtr); } } diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp index 464ee56dda1..e797183059a 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp @@ -9,9 +9,9 @@ using namespace HeteroPlugin; using namespace InferenceEngine; -HeteroAsyncInferRequest::HeteroAsyncInferRequest(const InferRequestInternal::Ptr& request, - const ITaskExecutor::Ptr& taskExecutor, - const ITaskExecutor::Ptr& callbackExecutor) : +HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Ptr& request, + const ITaskExecutor::Ptr& taskExecutor, + const ITaskExecutor::Ptr& callbackExecutor) : AsyncInferRequestThreadSafeDefault(request, taskExecutor, callbackExecutor), _heteroInferRequest(std::static_pointer_cast(request)), _statusCodes{_heteroInferRequest->_inferRequests.size(), StatusCode::OK} { diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp index d3563e68fa7..7cbe6a32644 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp @@ -19,10 +19,10 @@ namespace HeteroPlugin { class HeteroAsyncInferRequest : public InferenceEngine::AsyncInferRequestThreadSafeDefault { public: using Ptr = std::shared_ptr; - HeteroAsyncInferRequest(const InferenceEngine::InferRequestInternal::Ptr& request, + HeteroAsyncInferRequest(const InferenceEngine::IInferRequestInternal::Ptr& request, const InferenceEngine::ITaskExecutor::Ptr& taskExecutor, const InferenceEngine::ITaskExecutor::Ptr& callbackExecutor); - ~HeteroAsyncInferRequest() override; + ~HeteroAsyncInferRequest(); void StartAsync_ThreadUnsafe() override; InferenceEngine::StatusCode Wait(int64_t millis_timeout) override; diff --git a/inference-engine/src/hetero_plugin/hetero_executable_network.cpp b/inference-engine/src/hetero_plugin/hetero_executable_network.cpp index 6582b5ccadc..83f8a57156c 100644 --- a/inference-engine/src/hetero_plugin/hetero_executable_network.cpp +++ b/inference-engine/src/hetero_plugin/hetero_executable_network.cpp @@ -24,9 +24,11 @@ #include "transformations/serialize.hpp" #include "ie_ngraph_utils.hpp" #include "ie_plugin_config.hpp" +#include "ie_algorithm.hpp" #include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" #include "hetero/hetero_plugin_config.hpp" #include "hetero_plugin.hpp" +#include #include #include @@ -638,7 +640,7 @@ void HeteroExecutableNetwork::ExportImpl(std::ostream& heteroModel) { } } -InferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl( +IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl( InputsDataMap networkInputs, OutputsDataMap networkOutputs) { HeteroInferRequest::SubRequestsList inferRequests; @@ -655,7 +657,7 @@ InferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl( _blobNameMap); } -IInferRequest::Ptr HeteroExecutableNetwork::CreateInferRequest() { +IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequest() { return CreateAsyncInferRequestFromSync(); } diff --git a/inference-engine/src/hetero_plugin/hetero_executable_network.hpp b/inference-engine/src/hetero_plugin/hetero_executable_network.hpp index 7cb0a2ac8b3..323cafbeb1e 100644 --- a/inference-engine/src/hetero_plugin/hetero_executable_network.hpp +++ b/inference-engine/src/hetero_plugin/hetero_executable_network.hpp @@ -49,10 +49,10 @@ public: ~HeteroExecutableNetwork() override = default; - InferenceEngine::InferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) override; - InferenceEngine::IInferRequest::Ptr CreateInferRequest() override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::Parameter GetConfig(const std::string &name) const override; diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp index 83a5d15a8db..998a36f224d 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp @@ -20,7 +20,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp InferenceEngine::OutputsDataMap networkOutputs, const SubRequestsList& inferRequests, const std::unordered_map& subgraphInputToOutputBlobNames) : - InferRequestInternal(networkInputs, networkOutputs), + IInferRequestInternal(networkInputs, networkOutputs), _inferRequests(inferRequests) { if (_networkOutputs.empty() || _networkInputs.empty()) { IE_THROW() << "Internal error: no information about network's output/input"; @@ -65,7 +65,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp } void HeteroInferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) { - InferenceEngine::InferRequestInternal::SetBlob(name, data); + InferenceEngine::IInferRequestInternal::SetBlob(name, data); assert(!_inferRequests.empty()); for (auto &&desc : _inferRequests) { auto &r = desc._request; diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp index fd9dc591ab0..9c5fd280dd3 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp @@ -15,14 +15,15 @@ #include #include #include -#include +#include #include #include #include +#include namespace HeteroPlugin { -class HeteroInferRequest : public InferenceEngine::InferRequestInternal { +class HeteroInferRequest : public InferenceEngine::IInferRequestInternal { public: typedef std::shared_ptr Ptr; diff --git a/inference-engine/src/inference_engine/CMakeLists.txt b/inference-engine/src/inference_engine/CMakeLists.txt index 338100ee5a6..debd364bebe 100644 --- a/inference-engine/src/inference_engine/CMakeLists.txt +++ b/inference-engine/src/inference_engine/CMakeLists.txt @@ -9,6 +9,7 @@ file (GLOB LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/cpp/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/threading/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cpp/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cpp_interfaces/interface/*.cpp ) # TODO: WA for OneHot pass usage in reshape diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index 1e508d4ce51..d10cefbeeed 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -54,7 +54,7 @@ InferRequest ExecutableNetwork::CreateInferRequest() { } InferRequest::Ptr ExecutableNetwork::CreateInferRequestPtr() { - CALL_STATEMENT(return std::make_shared(_impl->CreateInferRequest(), _so)); + CALL_STATEMENT(return std::make_shared(InferRequest{_impl->CreateInferRequest(), _so})); } void ExecutableNetwork::Export(const std::string& modelFileName) { diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp new file mode 100644 index 00000000000..96454cf3bb5 --- /dev/null +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -0,0 +1,209 @@ +// Copyright (C) 2018-2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include + +#include "cpp/ie_infer_request.hpp" +#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" +#include "cpp_interfaces/base/ie_infer_async_request_base.hpp" +#include "ie_remote_context.hpp" + +namespace InferenceEngine { + +#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;} + +#define CATCH_IE_EXCEPTIONS \ + CATCH_IE_EXCEPTION(GeneralError) \ + CATCH_IE_EXCEPTION(NotImplemented) \ + CATCH_IE_EXCEPTION(NetworkNotLoaded) \ + CATCH_IE_EXCEPTION(ParameterMismatch) \ + CATCH_IE_EXCEPTION(NotFound) \ + CATCH_IE_EXCEPTION(OutOfBounds) \ + CATCH_IE_EXCEPTION(Unexpected) \ + CATCH_IE_EXCEPTION(RequestBusy) \ + CATCH_IE_EXCEPTION(ResultNotReady) \ + CATCH_IE_EXCEPTION(NotAllocated) \ + CATCH_IE_EXCEPTION(InferNotStarted) \ + CATCH_IE_EXCEPTION(NetworkNotRead) \ + CATCH_IE_EXCEPTION(InferCancelled) + +#define CALL_STATEMENT(...) \ + if (_impl == nullptr) IE_THROW() << "Inference Requst is not initialized"; \ + try { \ + __VA_ARGS__ \ + } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ + IE_THROW() << ex.what(); \ + } catch (...) { \ + IE_THROW(Unexpected); \ + } + +InferRequest::InferRequest(const std::shared_ptr& impl, + const std::shared_ptr& so) : + _impl{impl}, + _so{so} { + if (_impl == nullptr) IE_THROW() << "Inference Requst is not initialized"; +} + +InferRequest::~InferRequest() { + _impl = {}; +} + +void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) { + CALL_STATEMENT(_impl->SetBlob(name, data);) +} + +Blob::Ptr InferRequest::GetBlob(const std::string& name) { + Blob::Ptr blobPtr; + CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) + std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; + const bool remoteBlobPassed = blobPtr->is(); + if (blobPtr == nullptr) IE_THROW() << error; + if (!remoteBlobPassed && blobPtr->buffer() == nullptr) IE_THROW() << error; + return blobPtr; +} + +void InferRequest::SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) { + CALL_STATEMENT(_impl->SetBlob(name, data, info);) +} + +const PreProcessInfo& InferRequest::GetPreProcess(const std::string& name) const { + CALL_STATEMENT(return _impl->GetPreProcess(name);) +} + +void InferRequest::Infer() { + CALL_STATEMENT(_impl->Infer();) +} + +void InferRequest::Cancel() { + CALL_STATEMENT(_impl->Cancel();) +} + +std::map InferRequest::GetPerformanceCounts() const { + CALL_STATEMENT(return _impl->GetPerformanceCounts();) +} + +void InferRequest::SetInput(const BlobMap& inputs) { + CALL_STATEMENT( + for (auto&& input : inputs) { + _impl->SetBlob(input.first, input.second); + } + ) +} + +void InferRequest::SetOutput(const BlobMap& results) { + CALL_STATEMENT( + for (auto&& result : results) { + _impl->SetBlob(result.first, result.second); + } + ) +} + +void InferRequest::SetBatch(const int batch) { + CALL_STATEMENT(_impl->SetBatch(batch);) +} + +void InferRequest::StartAsync() { + CALL_STATEMENT(_impl->StartAsync();) +} + + +StatusCode InferRequest::Wait(int64_t millis_timeout) { + CALL_STATEMENT(return _impl->Wait(millis_timeout);) +} + +void InferRequest::SetCompletionCallbackImpl(std::function callback) { + CALL_STATEMENT( + _impl->SetCallback([callback] (std::exception_ptr) { + callback(); + }); + ) +} + + +#define CATCH_IE_EXCEPTION_RETURN(StatusCode, ExceptionType) catch (const ExceptionType&) {return StatusCode;} + +#define CATCH_IE_EXCEPTIONS_RETURN \ + CATCH_IE_EXCEPTION_RETURN(GENERAL_ERROR, GeneralError) \ + CATCH_IE_EXCEPTION_RETURN(NOT_IMPLEMENTED, NotImplemented) \ + CATCH_IE_EXCEPTION_RETURN(NETWORK_NOT_LOADED, NetworkNotLoaded) \ + CATCH_IE_EXCEPTION_RETURN(PARAMETER_MISMATCH, ParameterMismatch) \ + CATCH_IE_EXCEPTION_RETURN(NOT_FOUND, NotFound) \ + CATCH_IE_EXCEPTION_RETURN(OUT_OF_BOUNDS, OutOfBounds) \ + CATCH_IE_EXCEPTION_RETURN(UNEXPECTED, Unexpected) \ + CATCH_IE_EXCEPTION_RETURN(REQUEST_BUSY, RequestBusy) \ + CATCH_IE_EXCEPTION_RETURN(RESULT_NOT_READY, ResultNotReady) \ + CATCH_IE_EXCEPTION_RETURN(NOT_ALLOCATED, NotAllocated) \ + CATCH_IE_EXCEPTION_RETURN(INFER_NOT_STARTED, InferNotStarted) \ + CATCH_IE_EXCEPTION_RETURN(NETWORK_NOT_READ, NetworkNotRead) \ + CATCH_IE_EXCEPTION_RETURN(INFER_CANCELLED, InferCancelled) + + +void InferRequest::SetCompletionCallbackImpl(std::function callback) { + CALL_STATEMENT( + auto weakThis = InferRequest{std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}, _so}; + _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + StatusCode statusCode = StatusCode::OK; + if (exceptionPtr != nullptr) { + statusCode = [&] { + try { + std::rethrow_exception(exceptionPtr); + } CATCH_IE_EXCEPTIONS_RETURN catch (const std::exception& ex) { + return GENERAL_ERROR; + } catch (...) { + return UNEXPECTED; + } + } (); + } + callback(weakThis, statusCode); + }); + ) +} + +void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback callback) { + CALL_STATEMENT( + IInferRequest::Ptr weakThis = InferRequest{std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}, _so}; + _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + StatusCode statusCode = StatusCode::OK; + if (exceptionPtr != nullptr) { + statusCode = [&] { + try { + std::rethrow_exception(exceptionPtr); + } CATCH_IE_EXCEPTIONS_RETURN catch (const std::exception& ex) { + return GENERAL_ERROR; + } catch (...) { + return UNEXPECTED; + } + } (); + } + callback(weakThis, statusCode); + }); + ) +} + +std::vector InferRequest::QueryState() { + std::vector controller; + CALL_STATEMENT( + for (auto&& state : _impl->QueryState()) { + controller.emplace_back(std::make_shared(state), _so); + } + ) + return controller; +} + +InferRequest::operator IInferRequest::Ptr () { + CALL_STATEMENT( + return std::make_shared(_impl); + ) +} + +bool InferRequest::operator!() const noexcept { + return !_impl; +} + +InferRequest::operator bool() const noexcept { + return !!_impl; +} +} // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp_interfaces/interface/ie_iinfer_request_internal.cpp b/inference-engine/src/inference_engine/cpp_interfaces/interface/ie_iinfer_request_internal.cpp new file mode 100644 index 00000000000..a857a13f28c --- /dev/null +++ b/inference-engine/src/inference_engine/cpp_interfaces/interface/ie_iinfer_request_internal.cpp @@ -0,0 +1,325 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace InferenceEngine { + +IInferRequestInternal::~IInferRequestInternal() {} + +IInferRequestInternal::IInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs) { + // // We should copy maps since they can be overriden in SetBlob with preprocess + copyInputOutputInfo(networkInputs, networkOutputs, _networkInputs, _networkOutputs); +} + +void IInferRequestInternal::Infer() { + checkBlobs(); + InferImpl(); +} + +void IInferRequestInternal::InferImpl() { + IE_THROW(NotImplemented); +} + +void IInferRequestInternal::Cancel() { + IE_THROW(NotImplemented); +} + +std::map IInferRequestInternal::GetPerformanceCounts() const { + IE_THROW(NotImplemented); +} + +void IInferRequestInternal::SetBlob(const std::string& name, const Blob::Ptr& userBlob) { + OV_ITT_SCOPED_TASK(itt::domains::Plugin, "SetBlob"); + if (name.empty()) { + IE_THROW(NotFound) << "Failed to set blob with empty name"; + } + if (!userBlob) IE_THROW(NotAllocated) << "Failed to set empty blob with name: \'" << name << "\'"; + const bool compoundBlobPassed = userBlob->is(); + const bool remoteBlobPassed = userBlob->is(); + if (!compoundBlobPassed && !remoteBlobPassed && userBlob->buffer() == nullptr) + IE_THROW(NotAllocated) << "Input data was not allocated. Input name: \'" << name << "\'"; + if (userBlob->size() == 0) { + IE_THROW() << "Input data is empty. Input name: \'" << name << "\'"; + } + + InputInfo::Ptr foundInput; + DataPtr foundOutput; + size_t dataSize = userBlob->size(); + if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { + if (foundInput->getPrecision() != userBlob->getTensorDesc().getPrecision()) { + IE_THROW(ParameterMismatch) << "Failed to set Blob with precision not corresponding to user input precision"; + } + + auto& devBlob = _deviceInputs[name]; + const bool preProcRequired = preProcessingRequired(foundInput, userBlob, devBlob); + if (compoundBlobPassed && !preProcRequired) { + IE_THROW(NotImplemented) << "cannot set compound blob: supported only for input pre-processing"; + } + + if (preProcRequired) { + addInputPreProcessingFor(name, userBlob, devBlob ? devBlob : _inputs[name]); + } else { + size_t inputSize = foundInput->getTensorDesc().getLayout() != InferenceEngine::Layout::SCALAR + ? InferenceEngine::details::product(foundInput->getTensorDesc().getDims()) + : 1; + if (dataSize != inputSize) { + IE_THROW() << "Input blob size is not equal network input size (" << dataSize << "!=" << inputSize << ")."; + } + _inputs[name] = userBlob; + devBlob = userBlob; + } + } else { + if (compoundBlobPassed) { + IE_THROW(NotImplemented) << "cannot set compound blob: supported only for input pre-processing"; + } + size_t outputSize = foundOutput->getTensorDesc().getLayout() != InferenceEngine::Layout::SCALAR + ? details::product(foundOutput->getTensorDesc().getDims()) : + 1; + if (dataSize != outputSize) { + IE_THROW() << "Output blob size is not equal network output size (" << dataSize << "!=" << outputSize << ")."; + } + if (foundOutput->getPrecision() != userBlob->getTensorDesc().getPrecision()) { + IE_THROW(ParameterMismatch) << "Failed to set Blob with precision not corresponding to user output precision"; + } + _outputs[name] = userBlob; + } +} + +Blob::Ptr IInferRequestInternal::GetBlob(const std::string& name) { + OV_ITT_SCOPED_TASK(itt::domains::Plugin, "GetBlob"); + Blob::Ptr data; + InputInfo::Ptr foundInput; + DataPtr foundOutput; + const SizeVector oneVector = { 1 }; + if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { + // ROI blob is returned only if it was set previously. Otherwise default blob is returned. + auto it = _preProcData.find(name); + if (it != _preProcData.end()) { + data = it->second->getRoiBlob(); + } else { + data = _inputs[name]; + checkBlob(data, name, true, + foundInput->getTensorDesc().getLayout() != SCALAR + ? foundInput->getTensorDesc().getDims() + : oneVector); + + auto& devBlob = _deviceInputs[name]; + if (preProcessingRequired(foundInput, data, devBlob)) { + // if no devBlob, performs inplace + addInputPreProcessingFor(name, data, devBlob ? devBlob : _inputs[name]); + } + } + } else { + data = _outputs[name]; + checkBlob(data, name, false, + foundOutput->getTensorDesc().getLayout() != SCALAR + ? foundOutput->getTensorDesc().getDims() + : oneVector); + } + return data; +} + +void IInferRequestInternal::SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info) { + InputInfo::Ptr foundInput; + DataPtr foundOutput; + if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { + copyPreProcess(info, foundInput->getPreProcess()); + } else { + IE_THROW() << "Pre-process can't be set to output blob"; + } + + SetBlob(name, data); +} + +const PreProcessInfo& IInferRequestInternal::GetPreProcess(const std::string& name) const { + InputInfo::Ptr foundInput; + DataPtr foundOutput; + if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { + return foundInput->getPreProcess(); + } else { + IE_THROW() << "Output blob can't have pre-processing"; + } +} + +void IInferRequestInternal::SetBatch(int batch) { + IE_THROW(NotImplemented); +} + +std::vector> IInferRequestInternal::QueryState() { + IE_THROW(NotImplemented); +} + +void IInferRequestInternal::StartAsync() { + checkBlobs(); + StartAsyncImpl(); +} + +void IInferRequestInternal::StartAsyncImpl() { + IE_THROW(NotImplemented); +} + +StatusCode IInferRequestInternal::Wait(int64_t millis_timeout) { + IE_THROW(NotImplemented); +} + +void IInferRequestInternal::SetCallback(Callback callback) { + _callback = std::move(callback); +} + +void IInferRequestInternal::execDataPreprocessing(InferenceEngine::BlobMap& preprocessedBlobs, bool serial) { + for (auto& input : preprocessedBlobs) { + // If there is a pre-process entry for an input then it must be pre-processed + // using preconfigured resize algorithm. + auto it = _preProcData.find(input.first); + if (it != _preProcData.end()) { + it->second->execute(input.second, _networkInputs[input.first]->getPreProcess(), serial, m_curBatch); + } + } +} + +bool IInferRequestInternal::findInputAndOutputBlobByName(const std::string& name, InputInfo::Ptr& foundInput, DataPtr& foundOutput) const { + foundInput = nullptr; + foundOutput = nullptr; + if (_networkOutputs.empty()) { + IE_THROW() << "Internal error: network outputs is not set"; + } + auto foundInputPair = std::find_if(std::begin(_networkInputs), std::end(_networkInputs), + [&](const std::pair& pair) { + return pair.first == name; + }); + auto foundOutputPair = std::find_if(std::begin(_networkOutputs), std::end(_networkOutputs), + [&](const std::pair& pair) { + return pair.first == name; + }); + if (foundOutputPair == std::end(_networkOutputs) && (foundInputPair == std::end(_networkInputs))) { + IE_THROW(NotFound) << "Failed to find input or output with name: \'" << name << "\'"; + } + if (foundInputPair != std::end(_networkInputs)) { + foundInput = foundInputPair->second; + return true; + } else { + foundOutput = foundOutputPair->second; + return false; + } +} + +void IInferRequestInternal::checkBlob(const Blob::Ptr& blob, const std::string& name, bool isInput, const SizeVector& refDims) const { + std::string bType = isInput ? "Input" : "Output"; + std::string sType = isInput ? "input" : "output"; + std::string strNotAllocated(bType + " data was not allocated."); + std::string strNotMatched("The " + sType + " blob size is not equal to the network " + sType + " size"); + + if (!blob) { + IE_THROW(NotAllocated) << strNotAllocated; + } + size_t refSize; + if (refDims.empty()) { + SizeVector dims; + if (isInput) { + auto foundInputPair = std::find_if(std::begin(_networkInputs), std::end(_networkInputs), + [&](const std::pair& pair) { + return pair.first == name; + }); + if (foundInputPair == std::end(_networkInputs)) { + IE_THROW(NotFound) << "Failed to find input with name: \'" << name << "\'"; + } + dims = foundInputPair->second->getTensorDesc().getDims(); + refSize = foundInputPair->second->getTensorDesc().getLayout() != SCALAR + ? details::product(dims) + : 1; + } else { + auto foundOutputPair = std::find_if(std::begin(_networkOutputs), std::end(_networkOutputs), + [&](const std::pair& pair) { + return pair.first == name; + }); + if (foundOutputPair == std::end(_networkOutputs)) { + IE_THROW(NotFound) << "Failed to find output with name: \'" << name << "\'"; + } + dims = foundOutputPair->second->getTensorDesc().getDims(); + refSize = foundOutputPair->second->getTensorDesc().getLayout() != SCALAR + ? details::product(dims) + : 1; + } + } else { + refSize = details::product(refDims); + } + + if (refSize != blob->size()) { + IE_THROW() << strNotMatched + ": got " << blob->size() << " expecting " << refSize; + } + const bool remoteBlobPassed = blob->is(); + if (!remoteBlobPassed && blob->buffer() == nullptr) IE_THROW() << strNotAllocated; +} + +void IInferRequestInternal::checkBlobs() { + for (auto const& input : _inputs) { + checkBlob(input.second, input.first, true); + } + for (auto const& output : _outputs) { + checkBlob(output.second, output.first, false); + } +} + +void IInferRequestInternal::setPointerToExecutableNetworkInternal(const std::shared_ptr& exeNetwork) { + _exeNetwork = exeNetwork; +} + +bool IInferRequestInternal::preProcessingRequired(const InputInfo::Ptr& info, const Blob::Ptr& userBlob, const Blob::Ptr& deviceBlob) { + // pre-processing is required if: + // 1. resize algorithm is specified (resize required) + // 2. color format specified: + // 2.a. color format is not equal to network's expected (color conversion required) + // 2.b. network's layout != blob's layout (reorder required) + // 3. precision conversion is required + + const auto& preProcessInfo = info->getPreProcess(); + const auto inputColorFormat = preProcessInfo.getColorFormat(); + // FIXME: support other network's input formats once the API is ready. Assuming input is in + // the BGR format by default + const auto networkColorFormat = ColorFormat::BGR; + const bool colorFormatSpecified = inputColorFormat != ColorFormat::RAW; + + auto blob_layout = [](const Blob::Ptr& b) { return b->getTensorDesc().getLayout(); }; + auto blob_prec = [](const Blob::Ptr& b) { return b->getTensorDesc().getPrecision();}; + + auto dst_layout = deviceBlob ? blob_layout(deviceBlob) : info->getLayout(); + auto dst_prec = deviceBlob ? blob_prec(deviceBlob) : info->getPrecision(); + + //FIXME: remove the first part to allow any needed conversion? + const bool need_layout_conv = (colorFormatSpecified || deviceBlob) && + (blob_layout(userBlob) != dst_layout); + + return preProcessInfo.getResizeAlgorithm() != ResizeAlgorithm::NO_RESIZE || + (colorFormatSpecified && inputColorFormat != networkColorFormat) || + need_layout_conv || + (blob_prec(userBlob) != dst_prec); +} + +void IInferRequestInternal::addInputPreProcessingFor(const std::string& name, Blob::Ptr const& from, const Blob::Ptr& to) { + auto ppDataIt = _preProcData.find(name); + if (ppDataIt == _preProcData.end()) { + ppDataIt = (_preProcData.emplace(name, CreatePreprocDataHelper())).first; + } + + auto& preproc_ptr = ppDataIt->second; + preproc_ptr->isApplicable(from, to); + // Stores the given blob as ROI blob. It will be used to fill in network input + // during pre-processing + preproc_ptr->setRoiBlob(from); +} +} // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/ie_common.cpp b/inference-engine/src/inference_engine/ie_common.cpp index 9fb105c0fd8..e35fdb7ab9c 100644 --- a/inference-engine/src/inference_engine/ie_common.cpp +++ b/inference-engine/src/inference_engine/ie_common.cpp @@ -57,42 +57,38 @@ namespace details { IE_SUPPRESS_DEPRECATED_START StatusCode InferenceEngineException::getStatus() const { - return ExceptionToStatus(dynamic_cast(*this)); -} -} // namespace details -IE_SUPPRESS_DEPRECATED_END - -INFERENCE_ENGINE_API_CPP(StatusCode) ExceptionToStatus(const Exception& exception) { - if (dynamic_cast(&exception) != nullptr) { + if (dynamic_cast(this) != nullptr) { return GENERAL_ERROR; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return NOT_IMPLEMENTED; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return NETWORK_NOT_LOADED; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return PARAMETER_MISMATCH; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return NOT_FOUND; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return OUT_OF_BOUNDS; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return UNEXPECTED; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return REQUEST_BUSY; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return RESULT_NOT_READY; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return NOT_ALLOCATED; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return INFER_NOT_STARTED; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return NETWORK_NOT_READ; - } else if (dynamic_cast(&exception) != nullptr) { + } else if (dynamic_cast(this) != nullptr) { return INFER_CANCELLED; } else { assert(!"Unreachable"); return OK; } } +} // namespace details +IE_SUPPRESS_DEPRECATED_END // // ie_parameter.hpp diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.cpp index ea25b2dce04..25b3c3e17e9 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.cpp @@ -5,7 +5,7 @@ #include "mkldnn_async_infer_request.h" #include -MKLDNNPlugin::MKLDNNAsyncInferRequest::MKLDNNAsyncInferRequest(const InferenceEngine::InferRequestInternal::Ptr& inferRequest, +MKLDNNPlugin::MKLDNNAsyncInferRequest::MKLDNNAsyncInferRequest(const InferenceEngine::IInferRequestInternal::Ptr& inferRequest, const InferenceEngine::ITaskExecutor::Ptr& taskExecutor, const InferenceEngine::ITaskExecutor::Ptr& callbackExecutor) : InferenceEngine::AsyncInferRequestThreadSafeDefault(inferRequest, taskExecutor, callbackExecutor) { diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.h b/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.h index 299a9b0833b..9bd8e47df01 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_async_infer_request.h @@ -13,10 +13,10 @@ namespace MKLDNNPlugin { class MKLDNNAsyncInferRequest : public InferenceEngine::AsyncInferRequestThreadSafeDefault { public: - MKLDNNAsyncInferRequest(const InferenceEngine::InferRequestInternal::Ptr &inferRequest, + MKLDNNAsyncInferRequest(const InferenceEngine::IInferRequestInternal::Ptr &inferRequest, const InferenceEngine::ITaskExecutor::Ptr &taskExecutor, const InferenceEngine::ITaskExecutor::Ptr &callbackExecutor); - ~MKLDNNAsyncInferRequest() override; + ~MKLDNNAsyncInferRequest(); }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp index 0fcac236356..f7f02a57615 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp @@ -29,7 +29,7 @@ using namespace MKLDNNPlugin; using namespace InferenceEngine; using namespace InferenceEngine::details; -InferenceEngine::InferRequestInternal::Ptr +InferenceEngine::IInferRequestInternal::Ptr MKLDNNExecNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) { return std::make_shared(networkInputs, networkOutputs, std::static_pointer_cast(shared_from_this())); @@ -323,7 +323,7 @@ void MKLDNNExecNetwork::setProperty(const std::map &pr } } -InferenceEngine::IInferRequest::Ptr MKLDNNExecNetwork::CreateInferRequest() { +InferenceEngine::IInferRequestInternal::Ptr MKLDNNExecNetwork::CreateInferRequest() { return CreateAsyncInferRequestFromSync(); } diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.h b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.h index 84e376a2a00..9696f73aad3 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.h @@ -23,11 +23,11 @@ class MKLDNNExecNetwork: public InferenceEngine::ExecutableNetworkThreadSafeDefa public: typedef std::shared_ptr Ptr; - InferenceEngine::InferRequestInternal::Ptr + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) override; - InferenceEngine::IInferRequest::Ptr CreateInferRequest() override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; MKLDNNExecNetwork(const InferenceEngine::CNNNetwork &network, const Config &cfg, const MKLDNNExtensionManager::Ptr &extMgr, NumaNodesWeights &weightsSharing); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp index 24e1a3a144b..439b5c85d28 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp @@ -19,11 +19,13 @@ #include "nodes/mkldnn_memory_node.hpp" #include "nodes/common/cpu_memcpy.h" #include "mkldnn_async_infer_request.h" +#include + MKLDNNPlugin::MKLDNNInferRequest::MKLDNNInferRequest(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs, MKLDNNExecNetwork::Ptr execNetwork_) -: InferRequestInternal(networkInputs, networkOutputs) +: IInferRequestInternal(networkInputs, networkOutputs) , execNetwork(execNetwork_) { auto id = (execNetwork->_numRequests)++; profilingTask = openvino::itt::handle("MKLDNN_INFER_" + execNetwork->_name + "_" + std::to_string(id)); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.h b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.h index 21d9a3b6dfb..f99c42cc7e8 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.h @@ -8,21 +8,21 @@ #include #include #include -#include +#include namespace MKLDNNPlugin { class MKLDNNExecNetwork; class MKLDNNAsyncInferRequest; -class MKLDNNInferRequest : public InferenceEngine::InferRequestInternal { +class MKLDNNInferRequest : public InferenceEngine::IInferRequestInternal { public: typedef std::shared_ptr Ptr; explicit MKLDNNInferRequest(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs, std::shared_ptr execNetwork); - ~MKLDNNInferRequest() override; + ~MKLDNNInferRequest(); void InferImpl() override; @@ -34,7 +34,7 @@ public: void SetBatch(int batch = -1) override; - std::vector QueryState() override; + std::vector> QueryState() override; /** * @brief Sets the pointer to asynchronous inference request that holds this request @@ -59,7 +59,7 @@ private: MKLDNNGraph* graph = nullptr; std::map externalPtr; openvino::itt::handle_t profilingTask; - std::vector memoryStates; + std::vector> memoryStates; MKLDNNAsyncInferRequest* _asyncRequest = nullptr; }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/multi_device/multi_device_async_infer_request.hpp b/inference-engine/src/multi_device/multi_device_async_infer_request.hpp index 60abf50ab82..f8d59170392 100644 --- a/inference-engine/src/multi_device/multi_device_async_infer_request.hpp +++ b/inference-engine/src/multi_device/multi_device_async_infer_request.hpp @@ -27,7 +27,7 @@ public: const InferenceEngine::ITaskExecutor::Ptr& callbackExecutor); void Infer_ThreadUnsafe() override; std::map GetPerformanceCounts() const override; - ~MultiDeviceAsyncInferRequest() override; + ~MultiDeviceAsyncInferRequest(); protected: MultiDeviceExecutableNetwork::Ptr _multiDeviceExecutableNetwork; diff --git a/inference-engine/src/multi_device/multi_device_exec_network.cpp b/inference-engine/src/multi_device/multi_device_exec_network.cpp index d1a8dde5ae5..2edf0c89234 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.cpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.cpp @@ -174,7 +174,7 @@ RemoteContext::Ptr MultiDeviceExecutableNetwork::GetContext() const { << " Current list of devices allowed via the DEVICE_PRIORITIES config: " << devices_names; } -InferenceEngine::InferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, +InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs) { auto num = _numRequestsCreated++; size_t sum = 0; @@ -192,17 +192,13 @@ InferenceEngine::InferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateI return std::make_shared(networkInputs, networkOutputs, request_to_share_blobs_with); } -IInferRequest::Ptr MultiDeviceExecutableNetwork::CreateInferRequest() { - IInferRequest::Ptr asyncRequest; +IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequest() { auto syncRequestImpl = CreateInferRequestImpl(_networkInputs, _networkOutputs); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); - auto asyncTreadSafeImpl = std::make_shared(std::static_pointer_cast(syncRequestImpl), - _needPerfCounters, - std::static_pointer_cast(shared_from_this()), - _callbackExecutor); - asyncRequest.reset(new InferRequestBase(asyncTreadSafeImpl)); - asyncTreadSafeImpl->SetPointerToPublicInterface(asyncRequest); - return asyncRequest; + return std::make_shared(std::static_pointer_cast(syncRequestImpl), + _needPerfCounters, + std::static_pointer_cast(shared_from_this()), + _callbackExecutor); } void MultiDeviceExecutableNetwork::SetConfig(const std::map &config) { diff --git a/inference-engine/src/multi_device/multi_device_exec_network.hpp b/inference-engine/src/multi_device/multi_device_exec_network.hpp index 0991f8666cc..dce26006b05 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.hpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.hpp @@ -114,9 +114,9 @@ public: InferenceEngine::Parameter GetConfig(const std::string &name) const override; InferenceEngine::Parameter GetMetric(const std::string &name) const override; void run(InferenceEngine::Task inferTask) override; - InferenceEngine::IInferRequest::Ptr CreateInferRequest() override; - InferenceEngine::InferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; + InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, + InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::RemoteContext::Ptr GetContext() const override; ~MultiDeviceExecutableNetwork() override; diff --git a/inference-engine/src/multi_device/multi_device_infer_request.cpp b/inference-engine/src/multi_device/multi_device_infer_request.cpp index 97fc1c3296b..3cf4f2a7f1f 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.cpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.cpp @@ -5,6 +5,10 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #include "multi_device_infer_request.hpp" +#include +#include +#include +#include namespace MultiDevicePlugin { using namespace InferenceEngine; @@ -12,7 +16,7 @@ namespace MultiDevicePlugin { MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs, InferRequest request_to_share_blobs_with) - : InferRequestInternal(networkInputs, networkOutputs) { + : IInferRequestInternal(networkInputs, networkOutputs) { if (request_to_share_blobs_with) { // borrow device-friendly blobs from the request for (const auto &it : _networkInputs) diff --git a/inference-engine/src/multi_device/multi_device_infer_request.hpp b/inference-engine/src/multi_device/multi_device_infer_request.hpp index 33e339a938a..3284b985054 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.hpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.hpp @@ -14,12 +14,13 @@ #include #include #include - -#include +#include +#include +#include namespace MultiDevicePlugin { -class MultiDeviceInferRequest : public InferenceEngine::InferRequestInternal { +class MultiDeviceInferRequest : public InferenceEngine::IInferRequestInternal { public: using Ptr = std::shared_ptr; explicit MultiDeviceInferRequest(const InferenceEngine::InputsDataMap& networkInputs, diff --git a/inference-engine/src/multi_device/multi_device_plugin.cpp b/inference-engine/src/multi_device/multi_device_plugin.cpp index d01fa7dabb4..15b25b59ad0 100644 --- a/inference-engine/src/multi_device/multi_device_plugin.cpp +++ b/inference-engine/src/multi_device/multi_device_plugin.cpp @@ -15,6 +15,7 @@ #include #include #include "multi_device_plugin.hpp" +#include // ------------------------------MultiDeviceInferencePlugin---------------------------- namespace MultiDevicePlugin { diff --git a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp index 1f6c9aaa8bb..6a544f22eb4 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp @@ -20,6 +20,7 @@ #include #include "cpp_interfaces/exception2status.hpp" +#include "cpp_interfaces/base/ie_infer_async_request_base.hpp" namespace InferenceEngine { @@ -53,7 +54,7 @@ public: } StatusCode CreateInferRequest(IInferRequest::Ptr& req, ResponseDesc* resp) noexcept override { - TO_STATUS(req = _impl->CreateInferRequest()); + TO_STATUS(req = std::make_shared(_impl->CreateInferRequest())); } StatusCode Export(const std::string& modelFileName, ResponseDesc* resp) noexcept override { diff --git a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp index 52e15a27eb9..a444648e184 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp @@ -11,25 +11,92 @@ #include "cpp_interfaces/exception2status.hpp" #include "cpp_interfaces/plugin_itt.hpp" #include -#include +#include #include "ie_iinfer_request.hpp" #include "ie_preprocess.hpp" namespace InferenceEngine { +#define CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(StatusCode, ExceptionType) catch (const ExceptionType& ex) { \ + return InferenceEngine::DescriptionBuffer(StatusCode) << ex.what(); \ +} + +#define CATCH_IE_EXCEPTIONS_TO_STATUS_NO_RESP \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(GENERAL_ERROR, GeneralError) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(NOT_IMPLEMENTED, NotImplemented) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(NETWORK_NOT_LOADED, NetworkNotLoaded) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(PARAMETER_MISMATCH, ParameterMismatch) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(NOT_FOUND, NotFound) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(OUT_OF_BOUNDS, OutOfBounds) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(UNEXPECTED, Unexpected) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(REQUEST_BUSY, RequestBusy) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(RESULT_NOT_READY, ResultNotReady) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(NOT_ALLOCATED, NotAllocated) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(INFER_NOT_STARTED, InferNotStarted) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(NETWORK_NOT_READ, NetworkNotRead) \ + CATCH_IE_EXCEPTION_TO_STATUS_NO_RESP(INFER_CANCELLED, InferCancelled) + /** - * @brief Inference request `noexcept` wrapper which accepts IAsyncInferRequestInternal derived instance which can throw exceptions - * @ingroup ie_dev_api_async_infer_request_api + * @def TO_STATUS_NO_RESP(x) + * @brief Converts C++ exceptioned function call into a status code. Does not work with a ResponseDesc object + * @ingroup ie_dev_api_error_debug + */ +#define TO_STATUS_NO_RESP(x) \ + try { \ + x; \ + return OK; \ + } CATCH_IE_EXCEPTIONS_TO_STATUS_NO_RESP catch (const std::exception& ex) { \ + return InferenceEngine::DescriptionBuffer(GENERAL_ERROR) << ex.what(); \ + } catch (...) { \ + return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ + } + +#define CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(StatusCode, ExceptionType) catch (const ExceptionType& ex) { \ + return InferenceEngine::DescriptionBuffer(StatusCode, resp) << ex.what(); \ +} + +#define CATCH_IE_EXCEPTIONS_CALL_RETURN_STATUS \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(GENERAL_ERROR, GeneralError) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(NOT_IMPLEMENTED, NotImplemented) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(NETWORK_NOT_LOADED, NetworkNotLoaded) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(PARAMETER_MISMATCH, ParameterMismatch) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(NOT_FOUND, NotFound) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(OUT_OF_BOUNDS, OutOfBounds) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(UNEXPECTED, Unexpected) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(REQUEST_BUSY, RequestBusy) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(RESULT_NOT_READY, ResultNotReady) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(NOT_ALLOCATED, NotAllocated) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(INFER_NOT_STARTED, InferNotStarted) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(NETWORK_NOT_READ, NetworkNotRead) \ + CATCH_IE_EXCEPTION_CALL_RETURN_STATUS(INFER_CANCELLED, InferCancelled) + +/** + * @def NO_EXCEPT_CALL_RETURN_STATUS(x) + * @brief Returns a status code of a called function, handles exeptions and converts to a status code. + * @ingroup ie_dev_api_error_debug + */ +#define NO_EXCEPT_CALL_RETURN_STATUS(x) \ + try { \ + return x; \ + } CATCH_IE_EXCEPTIONS_CALL_RETURN_STATUS catch (const std::exception& ex) { \ + return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); \ + } catch (...) { \ + return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ + } + +/** + * @brief Inference request `noexcept` wrapper which accepts IInferRequestInternal derived instance which can throw exceptions + * @ingroup ie_dev_api_infer_request_api */ class InferRequestBase : public IInferRequest { - std::shared_ptr _impl; + std::shared_ptr _impl; public: /** * @brief Constructor with actual underlying implementation. - * @param impl Underlying implementation of type IAsyncInferRequestInternal + * @param impl Underlying implementation of type IInferRequestInternal */ - explicit InferRequestBase(std::shared_ptr impl): _impl(impl) {} + explicit InferRequestBase(std::shared_ptr impl): _impl(impl) {} StatusCode Infer(ResponseDesc* resp) noexcept override { OV_ITT_SCOPED_TASK(itt::domains::Plugin, "Infer"); @@ -73,15 +140,30 @@ public: } StatusCode SetCompletionCallback(CompletionCallback callback) noexcept override { - TO_STATUS_NO_RESP(_impl->SetCompletionCallback(callback)); + TO_STATUS_NO_RESP(_impl->SetCallback([callback, this] (std::exception_ptr exceptionPtr) { + StatusCode statusCode = [&] ()-> StatusCode { + if (exceptionPtr) { + TO_STATUS_NO_RESP(std::rethrow_exception(exceptionPtr)); + } else { + return OK; + } + } (); + callback(std::shared_ptr{this, [](InferRequestBase*){}}, statusCode); + })); } - StatusCode GetUserData(void** data, ResponseDesc* resp) noexcept override { - TO_STATUS(_impl->GetUserData(data)); + StatusCode GetUserData(void** data, ResponseDesc*) noexcept override { + if (data != nullptr) { + *data = _data; + return OK; + } else { + return GENERAL_ERROR; + } } - StatusCode SetUserData(void* data, ResponseDesc* resp) noexcept override { - TO_STATUS(_impl->SetUserData(data)); + StatusCode SetUserData(void* data, ResponseDesc*) noexcept override { + _data = data; + return OK; } StatusCode SetBatch(int batch_size, ResponseDesc* resp) noexcept override { @@ -104,6 +186,8 @@ public: } } IE_SUPPRESS_DEPRECATED_END + + void* _data = nullptr; }; } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/exception2status.hpp b/inference-engine/src/plugin_api/cpp_interfaces/exception2status.hpp index 04e0c8132d1..8c9e41e2a54 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/exception2status.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/exception2status.hpp @@ -13,8 +13,24 @@ #include "description_buffer.hpp" namespace InferenceEngine { +#define CATCH_IE_EXCEPTION_TO_STATUS(StatusCode, ExceptionType) catch (const ExceptionType& ex) { \ + return InferenceEngine::DescriptionBuffer(StatusCode, resp) << ex.what(); \ +} -INFERENCE_ENGINE_API_CPP(StatusCode) ExceptionToStatus(const Exception& exception); +#define CATCH_IE_EXCEPTIONS_TO_STATUS \ + CATCH_IE_EXCEPTION_TO_STATUS(GENERAL_ERROR, GeneralError) \ + CATCH_IE_EXCEPTION_TO_STATUS(NOT_IMPLEMENTED, NotImplemented) \ + CATCH_IE_EXCEPTION_TO_STATUS(NETWORK_NOT_LOADED, NetworkNotLoaded) \ + CATCH_IE_EXCEPTION_TO_STATUS(PARAMETER_MISMATCH, ParameterMismatch) \ + CATCH_IE_EXCEPTION_TO_STATUS(NOT_FOUND, NotFound) \ + CATCH_IE_EXCEPTION_TO_STATUS(OUT_OF_BOUNDS, OutOfBounds) \ + CATCH_IE_EXCEPTION_TO_STATUS(UNEXPECTED, Unexpected) \ + CATCH_IE_EXCEPTION_TO_STATUS(REQUEST_BUSY, RequestBusy) \ + CATCH_IE_EXCEPTION_TO_STATUS(RESULT_NOT_READY, ResultNotReady) \ + CATCH_IE_EXCEPTION_TO_STATUS(NOT_ALLOCATED, NotAllocated) \ + CATCH_IE_EXCEPTION_TO_STATUS(INFER_NOT_STARTED, InferNotStarted) \ + CATCH_IE_EXCEPTION_TO_STATUS(NETWORK_NOT_READ, NetworkNotRead) \ + CATCH_IE_EXCEPTION_TO_STATUS(INFER_CANCELLED, InferCancelled) /** * @def TO_STATUS(x) @@ -25,42 +41,7 @@ INFERENCE_ENGINE_API_CPP(StatusCode) ExceptionToStatus(const Exception& exceptio try { \ x; \ return OK; \ - } catch (const ::InferenceEngine::Exception& iex) { \ - return InferenceEngine::DescriptionBuffer(InferenceEngine::ExceptionToStatus(iex), resp) << iex.what(); \ - } catch (const std::exception& ex) { \ - return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); \ - } catch (...) { \ - return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ - } - -/** - * @def TO_STATUS_NO_RESP(x) - * @brief Converts C++ exceptioned function call into a status code. Does not work with a ResponseDesc object - * @ingroup ie_dev_api_error_debug - */ -#define TO_STATUS_NO_RESP(x) \ - try { \ - x; \ - return OK; \ - } catch (const ::InferenceEngine::Exception& iex) { \ - return InferenceEngine::DescriptionBuffer(InferenceEngine::ExceptionToStatus(iex)) << iex.what(); \ - } catch (const std::exception& ex) { \ - return InferenceEngine::DescriptionBuffer(GENERAL_ERROR) << ex.what(); \ - } catch (...) { \ - return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ - } - -/** - * @def NO_EXCEPT_CALL_RETURN_STATUS(x) - * @brief Returns a status code of a called function, handles exeptions and converts to a status code. - * @ingroup ie_dev_api_error_debug - */ -#define NO_EXCEPT_CALL_RETURN_STATUS(x) \ - try { \ - return x; \ - } catch (const ::InferenceEngine::Exception& iex) { \ - return InferenceEngine::DescriptionBuffer(InferenceEngine::ExceptionToStatus(iex), resp) << iex.what(); \ - } catch (const std::exception& ex) { \ + } CATCH_IE_EXCEPTIONS_TO_STATUS catch (const std::exception& ex) { \ return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); \ } catch (...) { \ return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ @@ -82,5 +63,4 @@ INFERENCE_ENGINE_API_CPP(StatusCode) ExceptionToStatus(const Exception& exceptio CATCH_IE_EXCEPTION(InferNotStarted) \ CATCH_IE_EXCEPTION(NetworkNotRead) \ CATCH_IE_EXCEPTION(InferCancelled) - } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp index 107f088e86f..d91d24e3e06 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp @@ -11,8 +11,6 @@ #include #include -#include "cpp_interfaces/impl/ie_infer_async_request_internal.hpp" -#include "cpp_interfaces/impl/ie_infer_request_internal.hpp" #include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" @@ -118,7 +116,29 @@ public: IE_THROW(NotImplemented); } + + /** + * @brief Creates an inference request public implementation. + * @return The request public implementation + */ + IInferRequestInternal::Ptr CreateInferRequest() override { + auto asyncRequestImpl = this->CreateInferRequestImpl(_networkInputs, _networkOutputs); + asyncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); + return asyncRequestImpl; + } + protected: + /** + * @brief Creates an asynchronous inference request internal implementation. + * @note The method is called by ExecutableNetworkInternal::CreateInferRequest as + * plugin-specific implementation. + * @param[in] networkInputs The network inputs + * @param[in] networkOutputs The network outputs + * @return A shared pointer to asynchnous inference request object. + */ + virtual IInferRequestInternal::Ptr CreateInferRequestImpl(InputsDataMap networkInputs, + OutputsDataMap networkOutputs) = 0; + /** * @brief Exports an internal hardware-dependent model to a stream. * @note The function is called from ExecutableNetworkInternal::Export(std::ostream&), @@ -130,7 +150,7 @@ protected: IE_THROW(NotImplemented); } - InferenceEngine::InputsDataMap _networkInputs; //!< Holds infromation about network inputs info + InferenceEngine::InputsDataMap _networkInputs; //!< Holds information about network inputs info InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data /** diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_async_only.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_async_only.hpp deleted file mode 100644 index 08020629779..00000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_async_only.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include - -#include "cpp_interfaces/base/ie_infer_async_request_base.hpp" -#include "cpp_interfaces/impl/ie_executable_network_internal.hpp" -#include "cpp_interfaces/impl/ie_infer_async_request_internal.hpp" -#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" -#include "cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp" - -namespace InferenceEngine { - -/** - * @brief This class describes an executable network thread safe asynchronous only implementation. - * @ingroup ie_dev_api_exec_network_api - */ -class ExecutableNetworkThreadSafeAsyncOnly : public ExecutableNetworkInternal { -public: - /** - * @brief A shared pointer to a ExecutableNetworkThreadSafeAsyncOnly object - */ - typedef std::shared_ptr Ptr; - - /** - * @brief Creates an asynchronous inference request public implementation. - * @return The asynchronous request public implementation - */ - IInferRequest::Ptr CreateInferRequest() override { - IInferRequest::Ptr asyncRequest; - auto asyncRequestImpl = this->CreateAsyncInferRequestImpl(_networkInputs, _networkOutputs); - asyncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); - - asyncRequest.reset(new InferRequestBase(asyncRequestImpl)); - asyncRequestImpl->SetPointerToPublicInterface(asyncRequest); - return asyncRequest; - } - -protected: - /** - * @brief Creates an asynchronous inference request internal implementation. - * @note The method is called by ExecutableNetworkThreadSafeAsyncOnly::CreateInferRequest as - * plugin-specific implementation. - * @param[in] networkInputs The network inputs - * @param[in] networkOutputs The network outputs - * @return A shared pointer to asynchnous inference request object. - */ - virtual AsyncInferRequestInternal::Ptr CreateAsyncInferRequestImpl(InputsDataMap networkInputs, - OutputsDataMap networkOutputs) = 0; -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_default.hpp index 28a5e0fbf9b..93e71701a9f 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_thread_safe_default.hpp @@ -12,7 +12,6 @@ #include "cpp_interfaces/base/ie_infer_async_request_base.hpp" #include "cpp_interfaces/impl/ie_executable_network_internal.hpp" #include "cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp" -#include "cpp_interfaces/impl/ie_infer_request_internal.hpp" #include "threading/ie_cpu_streams_executor.hpp" namespace InferenceEngine { @@ -49,7 +48,7 @@ public: * need for it to be implemented by plugin * @return shared_ptr for the created asynchronous inference request */ - IInferRequest::Ptr CreateInferRequest() override { + IInferRequestInternal::Ptr CreateInferRequest() override { return CreateAsyncInferRequestFromSync(); } @@ -60,28 +59,12 @@ protected: * @return A shared pointer to an asynchronous inference request */ template - IInferRequest::Ptr CreateAsyncInferRequestFromSync() { + IInferRequestInternal::Ptr CreateAsyncInferRequestFromSync() { auto syncRequestImpl = this->CreateInferRequestImpl(_networkInputs, _networkOutputs); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); - - auto asyncThreadSafeImpl = std::make_shared( - syncRequestImpl, _taskExecutor, _callbackExecutor); - IInferRequest::Ptr asyncRequest = std::make_shared(asyncThreadSafeImpl); - asyncThreadSafeImpl->SetPointerToPublicInterface(asyncRequest); - - return asyncRequest; + return std::make_shared(syncRequestImpl, _taskExecutor, _callbackExecutor); } - /** - * @brief Creates a synchronous inference request object used to infer the network - * @note Used by ExecutableNetworkThreadSafeDefault::CreateInferRequest as a plugin-specific implementation - * @param networkInputs An input info map needed to create input blobs - * @param networkOutputs An output data map needed to create output blobs - * @return Synchronous inference request object - */ - virtual InferRequestInternal::Ptr CreateInferRequestImpl(InputsDataMap networkInputs, - OutputsDataMap networkOutputs) = 0; - ITaskExecutor::Ptr _taskExecutor = nullptr; //!< Holds a task executor ITaskExecutor::Ptr _callbackExecutor = nullptr; //!< Holds a callback executor }; diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_internal.hpp deleted file mode 100644 index 1fb8009db66..00000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_internal.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "cpp_interfaces/impl/ie_infer_request_internal.hpp" -#include "cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp" - -namespace InferenceEngine { - -#if defined(_MSC_VER) -#pragma warning(disable : 4250) -#endif - -/** - * @brief minimum API to be implemented by plugin, which is used in InferRequestBase forwarding mechanism - * @ingroup ie_dev_api_async_infer_request_api - */ -class AsyncInferRequestInternal : public IAsyncInferRequestInternal, public InferRequestInternal { -public: - /** - * @brief A shared pointer to a AsyncInferRequestInternal implementation - */ - typedef std::shared_ptr Ptr; - - /** - * @brief Constructs a new instance. - * @param[in] networkInputs The network inputs info - * @param[in] networkOutputs The network outputs data - */ - AsyncInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs) - : InferRequestInternal(networkInputs, networkOutputs), _callback(nullptr), _userData(nullptr) {} - - void SetCompletionCallback(IInferRequest::CompletionCallback callback) override { - _callback = callback; - } - - void GetUserData(void** data) override { - if (data == nullptr) IE_THROW(NotAllocated); - *data = _userData; - } - - void SetUserData(void* data) override { - _userData = data; - } - - /** - * @brief Set weak pointer to the corresponding public interface: IInferRequest. This allow to pass it to - * IInferRequest::CompletionCallback - * @param ptr A weak pointer to InferRequestBase - */ - void SetPointerToPublicInterface(IInferRequest::Ptr ptr) { - _publicInterface = ptr; - } - - void StartAsync() override { - checkBlobs(); - StartAsyncImpl(); - }; - -protected: - /** - * @brief The minimal asynchronous inference function to be implemented by plugins. - * It starts inference of specified input(s) in asynchronous mode - * @note - * * The methos is used in AsyncInferRequestInternal::StartAsync which performs common steps first and - * calls plugin dependent implementation of this method after. - * * It returns immediately. Inference starts also immediately. - */ - virtual void StartAsyncImpl() = 0; - - IInferRequest::WeakPtr _publicInterface; //!< A weak pointer to a IInferRequest interface for callback calling - InferenceEngine::IInferRequest::CompletionCallback _callback; //!< A callback - void* _userData; //!< A callback user data -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index ea931a518d5..76f2152925e 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -8,10 +8,10 @@ #include #include -#include -#include +#include #include #include +#include #include #include @@ -40,12 +40,12 @@ namespace InferenceEngine { * * @snippet example_async_infer_request.cpp async_infer_request:define_pipeline */ -class AsyncInferRequestThreadSafeDefault : public IAsyncInferRequestInternal { +class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { enum InferState {Idle, Busy, Canceled, Stop}; using Futures = std::vector>; using Promise = std::shared_ptr>; enum Stage_e : std::uint8_t { executor, task }; - InferRequestInternal::Ptr _syncRequest; + IInferRequestInternal::Ptr _syncRequest; friend struct DisableCallbackGuard; struct DisableCallbackGuard { @@ -59,7 +59,7 @@ class AsyncInferRequestThreadSafeDefault : public IAsyncInferRequestInternal { _this->_callback = _callback; } AsyncInferRequestThreadSafeDefault* _this = nullptr; - IInferRequest::CompletionCallback _callback = nullptr; + Callback _callback; }; struct ImmediateStreamsExecutor : public InferenceEngine::ITaskExecutor { @@ -132,15 +132,15 @@ public: using Ptr = std::shared_ptr; /** - * @brief Wraps a InferRequestInternal::Ptr implementation and constructs a - * AsyncInferRequestThreadSafeDefault::_pipeline where `taskExecutor` is used to run InferRequestInternal::Infer + * @brief Wraps a IInferRequestInternal::Ptr implementation and constructs a + * AsyncInferRequestThreadSafeDefault::_pipeline where `taskExecutor` is used to run IInferRequestInternal::Infer * asynchronously. * * @param[in] request The synchronous request * @param[in] taskExecutor The task executor * @param[in] callbackExecutor The callback executor */ - AsyncInferRequestThreadSafeDefault(const InferRequestInternal::Ptr& request, + AsyncInferRequestThreadSafeDefault(const IInferRequestInternal::Ptr& request, const ITaskExecutor::Ptr& taskExecutor, const ITaskExecutor::Ptr& callbackExecutor) : _syncRequest {request}, @@ -245,32 +245,13 @@ public: _syncRequest->SetBatch(batch); }; - void GetUserData(void** data) override { + void SetCallback(Callback callback) override { CheckState(); - if (data == nullptr) IE_THROW(NotAllocated); - *data = _userData; + _callback = std::move(callback); } - void SetUserData(void* data) override { + std::vector> QueryState() override { CheckState(); - _userData = data; - } - - void SetCompletionCallback(IInferRequest::CompletionCallback callback) override { - CheckState(); - _callback = callback; - } - - /** - * @brief Sets the pointer to public interface. - * @note Needed to correctly handle ownership between objects - * @param[in] ptr A shared pointer to a public IInferRequest interface. - */ - void SetPointerToPublicInterface(InferenceEngine::IInferRequest::Ptr ptr) { - _publicInterface = std::shared_ptr(ptr.get(), [](IInferRequest*) {}); - } - - std::vector QueryState() override { return _syncRequest->QueryState(); } @@ -319,13 +300,13 @@ protected: * pipeline tasks */ void StopAndWait() { - _callback = nullptr; Futures futures; InferState state = InferState::Idle; { std::lock_guard lock{_mutex}; state = _state; if (state != InferState::Stop) { + _callback = {}; _state = InferState::Stop; futures = std::move(_futures); } @@ -385,51 +366,44 @@ private: Task MakeNextStageTask(const Pipeline::iterator itStage, const Pipeline::iterator itEndStage, const ITaskExecutor::Ptr callbackExecutor) { return std::bind([this, itStage, itEndStage](ITaskExecutor::Ptr& callbackExecutor) mutable { - StatusCode requestStatus = StatusCode::OK; - std::exception_ptr localCurrentException = nullptr; + std::exception_ptr currentException = nullptr; auto& thisStage = *itStage; auto itNextStage = itStage + 1; - try { auto& stageTask = std::get(thisStage); IE_ASSERT(nullptr != stageTask); stageTask(); - if (itEndStage != itNextStage) { + if (itEndStage != itNextStage) { auto& nextStage = *itNextStage; auto& nextStageExecutor = std::get(nextStage); IE_ASSERT(nullptr != nextStageExecutor); nextStageExecutor->run(MakeNextStageTask(itNextStage, itEndStage, std::move(callbackExecutor))); } - } catch (InferenceEngine::Exception& ie_ex) { - requestStatus = ExceptionToStatus(ie_ex); - localCurrentException = std::current_exception(); } catch (...) { - requestStatus = StatusCode::GENERAL_ERROR; - localCurrentException = std::current_exception(); + currentException = std::current_exception(); } - if ((itEndStage == itNextStage) || (nullptr != localCurrentException)) { - auto lastStageTask = [this, requestStatus, localCurrentException]() mutable { + if ((itEndStage == itNextStage) || (nullptr != currentException)) { + auto lastStageTask = [this, currentException]() mutable { auto promise = std::move(_promise); - IInferRequest::CompletionCallback callback = nullptr; + Callback callback; { std::lock_guard lock{_mutex}; _state = InferState::Idle; callback = _callback; } - if (nullptr != callback) { - InferenceEngine::CurrentException() = localCurrentException; + if (callback) { try { - callback(_publicInterface, requestStatus); + auto local_callback = std::move(callback); + local_callback(currentException); } catch (...) { - localCurrentException = std::current_exception(); + currentException = std::current_exception(); } - InferenceEngine::CurrentException() = nullptr; } - if (nullptr == localCurrentException) { + if (nullptr == currentException) { promise.set_value(); } else { - promise.set_exception(localCurrentException); + promise.set_exception(currentException); } }; @@ -442,9 +416,6 @@ private: }, std::move(callbackExecutor)); } - void* _userData = nullptr; - IInferRequest::CompletionCallback _callback = nullptr; - IInferRequest::Ptr _publicInterface; std::promise _promise; mutable std::mutex _mutex; Futures _futures; diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_internal.hpp deleted file mode 100644 index 6ac53add48a..00000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_internal.hpp +++ /dev/null @@ -1,422 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "cpp_interfaces/exception2status.hpp" -#include "cpp_interfaces/plugin_itt.hpp" -#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" -#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" -#include "debug.h" -#include "ie_compound_blob.h" -#include "ie_memcpy.h" -#include "ie_preprocess_data.hpp" - -namespace InferenceEngine { - -class IExecutableNetworkInternal; - -/** - * @brief An optimal implementation of IInferRequestInternal interface to avoid duplication in all plugins - * This base class is recommended to be used as a base class for plugin synchronous inference request implementation. - * @ingroup ie_dev_api_infer_request_api - */ -class InferRequestInternal : virtual public IInferRequestInternal { -public: - /** - * @brief A shared pointer to a InferRequestInternal implementation. - */ - typedef std::shared_ptr Ptr; - - /** - * @brief Constructs a new instance. - * @param[in] networkInputs The network inputs info - * @param[in] networkOutputs The network outputs data - */ - InferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs): m_curBatch(-1) { - // // We should copy maps since they can be overriden in SetBlob with preprocess - copyInputOutputInfo(networkInputs, networkOutputs, _networkInputs, _networkOutputs); - } - - /** - * @brief The minimal infer function to be implemented by plugins. It infers specified input(s) in synchronous mode - * @note - * * This method is used in InferRequestInternal::Infer, which calls the common code first and after uses this - * plugin dependent implementation. - * * Blocks all method of IInferRequest while request is ongoing (running or waiting in queue) - */ - virtual void InferImpl() = 0; - - /** - * @brief Default common implementation for all plugins with checking input and output blobs before inference - */ - void Infer() override { - checkBlobs(); - InferImpl(); - } - - /** - * @brief Default common implementation for all plugins - */ - void Cancel() override { - IE_THROW(NotImplemented); - } - - /** - * @brief Given optional implementation of setting blob to avoid need for it to be implemented by plugin - * @param name - a name of input or output blob. - * @param data - a reference to input or output blob. The type of Blob must correspond to the network input - * precision and size. - */ - void SetBlob(const std::string& name, const Blob::Ptr& userBlob) override { - OV_ITT_SCOPED_TASK(itt::domains::Plugin, "SetBlob"); - if (name.empty()) { - IE_THROW(NotFound) << "Failed to set blob with empty name"; - } - if (!userBlob) IE_THROW(NotAllocated) << "Failed to set empty blob with name: \'" << name << "\'"; - const bool compoundBlobPassed = userBlob->is(); - const bool remoteBlobPassed = userBlob->is(); - if (!compoundBlobPassed && !remoteBlobPassed && userBlob->buffer() == nullptr) - IE_THROW(NotAllocated) << "Input data was not allocated. Input name: \'" << name << "\'"; - if (userBlob->size() == 0) { - IE_THROW() << "Input data is empty. Input name: \'" << name << "\'"; - } - - InputInfo::Ptr foundInput; - DataPtr foundOutput; - size_t dataSize = userBlob->size(); - if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - if (foundInput->getPrecision() != userBlob->getTensorDesc().getPrecision()) { - IE_THROW(ParameterMismatch) - << "Failed to set Blob with precision not corresponding to user input precision"; - } - - auto& devBlob = _deviceInputs[name]; - const bool preProcRequired = preProcessingRequired(foundInput, userBlob, devBlob); - if (compoundBlobPassed && !preProcRequired) { - IE_THROW(NotImplemented) - << "cannot set compound blob: supported only for input pre-processing"; - } - - if (preProcRequired) { - addInputPreProcessingFor(name, userBlob, devBlob ? devBlob : _inputs[name]); - } else { - size_t inputSize = foundInput->getTensorDesc().getLayout() != InferenceEngine::Layout::SCALAR - ? InferenceEngine::details::product(foundInput->getTensorDesc().getDims()) - : 1; - if (dataSize != inputSize) { - IE_THROW() << "Input blob size is not equal network input size (" << dataSize - << "!=" << inputSize << ")."; - } - _inputs[name] = userBlob; - devBlob = userBlob; - } - } else { - if (compoundBlobPassed) { - IE_THROW(NotImplemented) - << "cannot set compound blob: supported only for input pre-processing"; - } - size_t outputSize = foundOutput->getTensorDesc().getLayout() != InferenceEngine::Layout::SCALAR - ? details::product(foundOutput->getTensorDesc().getDims()) : - 1; - if (dataSize != outputSize) { - IE_THROW() << "Output blob size is not equal network output size (" << dataSize - << "!=" << outputSize << ")."; - } - if (foundOutput->getPrecision() != userBlob->getTensorDesc().getPrecision()) { - IE_THROW(ParameterMismatch) - << "Failed to set Blob with precision not corresponding to user output precision"; - } - _outputs[name] = userBlob; - } - } - - /** - * @brief Given optional implementation of getting blob to avoid need for it to be implemented by plugin - * @param name - a name of input or output blob. - * @return Returns input or output blob. The type of Blob must correspond to the network input - * precision and size. - * @note if ROI blob was previously set it is returned (without dimensions checks) instead of default blob. - */ - Blob::Ptr GetBlob(const std::string& name) override { - OV_ITT_SCOPED_TASK(itt::domains::Plugin, "GetBlob"); - Blob::Ptr data; - InputInfo::Ptr foundInput; - DataPtr foundOutput; - const SizeVector oneVector = { 1 }; - if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - // ROI blob is returned only if it was set previously. Otherwise default blob is returned. - auto it = _preProcData.find(name); - if (it != _preProcData.end()) { - data = it->second->getRoiBlob(); - } else { - data = _inputs[name]; - checkBlob(data, name, true, - foundInput->getTensorDesc().getLayout() != SCALAR - ? foundInput->getTensorDesc().getDims() - : oneVector); - - auto& devBlob = _deviceInputs[name]; - if (preProcessingRequired(foundInput, data, devBlob)) { - // if no devBlob, performs inplace - addInputPreProcessingFor(name, data, devBlob ? devBlob : _inputs[name]); - } - } - } else { - data = _outputs[name]; - checkBlob(data, name, false, - foundOutput->getTensorDesc().getLayout() != SCALAR - ? foundOutput->getTensorDesc().getDims() - : oneVector); - } - return data; - } - - /** - * @brief Sets pre-process for input data - * @param name Name of input blob. - * @param data - a reference to input or output blob. The type of Blob must correspond to the network input precision and size. - * @param info Preprocess info for blob. - */ - void SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info) override { - InputInfo::Ptr foundInput; - DataPtr foundOutput; - if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - copyPreProcess(info, foundInput->getPreProcess()); - } else { - IE_THROW() << "Pre-process can't be set to output blob"; - } - - SetBlob(name, data); - } - - /** - * @brief Gets pre-process for input data - * @param name Name of input blob. - * @return Returns constant reference to PreProcessInfo structure - */ - const PreProcessInfo& GetPreProcess(const std::string& name) const override { - InputInfo::Ptr foundInput; - DataPtr foundOutput; - if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - return foundInput->getPreProcess(); - } else { - IE_THROW() << "Output blob can't have pre-processing"; - } - } - - void SetBatch(int batch) override { - (void)batch; - IE_THROW() << "Dynamic batch is not supported"; - }; - - /** - * @brief Sets the pointer to executable network internal. - * @note Needed to correctly handle ownership between objects. - * @param[in] exeNetwork The executable network - */ - void setPointerToExecutableNetworkInternal(std::shared_ptr exeNetwork) { - _exeNetwork = exeNetwork; - } - - /** - * @brief Checks that both inputs and outputs blob are valid. Throws an exception if they are not. - */ - virtual void checkBlobs() { - for (auto const& input : _inputs) { - checkBlob(input.second, input.first, true); - } - for (auto const& output : _outputs) { - checkBlob(output.second, output.first, false); - } - } - - std::vector QueryState() override { - // meaning base plugin reports as no state available - plugin owners need to create proper override of this - IE_THROW() << "Plugin doesn't override QueryState"; - return {}; - } - -protected: - InferenceEngine::InputsDataMap _networkInputs; //!< Holds information about network inputs info - InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data - InferenceEngine::BlobMap _inputs; //!< A map of user passed blobs for network inputs - InferenceEngine::BlobMap _deviceInputs; //!< A map of actual network inputs, in plugin specific format - InferenceEngine::BlobMap _outputs; //!< A map of user passed blobs for network outputs - std::map _preProcData; //!< A map of pre-process data per input - int m_curBatch; //!< Current batch value used in dynamic batching - - /** - * @brief A shared pointer to ExecutableNetworkInternal interface - * @note Needed to correctly handle ownership between objects. - */ - std::shared_ptr _exeNetwork; - /** - * @brief Checks and executes input data pre-processing if needed. - * @param inputs Inputs blobs to perform preprocessing on - * @param serial Whether to use multiple threads to execute the step - */ - void execDataPreprocessing(InferenceEngine::BlobMap& preprocessedBlobs, bool serial = false) { - for (auto& input : preprocessedBlobs) { - // If there is a pre-process entry for an input then it must be pre-processed - // using preconfigured resize algorithm. - auto it = _preProcData.find(input.first); - if (it != _preProcData.end()) { - _preProcData[input.first]->execute(input.second, _networkInputs[input.first]->getPreProcess(), serial, - m_curBatch); - } - } - } - /** - * @brief Helper function to find input or output blob by name - * @param name A name of input or output blob. - * @param foundInput A pointer to input information if found. - * @param foundOutput A pointer to output DataPtr if found. - * @return `True` - if loaded network has input with provided name, - * `false` - if loaded network has output with provided name - * @throws [parameter_mismatch] exception if input and output has the same name - * @throws [not_found] exception if there is no input and output layers with given name - */ - bool findInputAndOutputBlobByName(const std::string& name, InputInfo::Ptr& foundInput, DataPtr& foundOutput) const { - foundInput = nullptr; - foundOutput = nullptr; - if (_networkOutputs.empty()) { - IE_THROW() << "Internal error: network outputs is not set"; - } - auto foundInputPair = std::find_if(std::begin(_networkInputs), std::end(_networkInputs), - [&](const std::pair& pair) { - return pair.first == name; - }); - auto foundOutputPair = std::find_if(std::begin(_networkOutputs), std::end(_networkOutputs), - [&](const std::pair& pair) { - return pair.first == name; - }); - if (foundOutputPair == std::end(_networkOutputs) && (foundInputPair == std::end(_networkInputs))) { - IE_THROW(NotFound) << "Failed to find input or output with name: \'" << name << "\'"; - } - if (foundInputPair != std::end(_networkInputs)) { - foundInput = foundInputPair->second; - return true; - } else { - foundOutput = foundOutputPair->second; - return false; - } - } - - /** - * @brief Check that @p blob is valid. Throws an exception if it's not. - * - * @param[in] blob The blob to check - * @param[in] name The name of input or output depending of if the @p blob is input or output - * @param[in] isInput Indicates if @p is input - * @param[in] refDims The reference dims, empty if not specified - */ - void checkBlob(const Blob::Ptr& blob, const std::string& name, bool isInput, const SizeVector& refDims = {}) const { - std::string bType = isInput ? "Input" : "Output"; - std::string sType = isInput ? "input" : "output"; - std::string strNotAllocated(bType + " data was not allocated."); - std::string strNotMatched("The " + sType + " blob size is not equal to the network " + sType + " size"); - - if (!blob) { - IE_THROW() << strNotAllocated; - } - size_t refSize; - if (refDims.empty()) { - SizeVector dims; - if (isInput) { - auto foundInputPair = std::find_if(std::begin(_networkInputs), std::end(_networkInputs), - [&](const std::pair& pair) { - return pair.first == name; - }); - if (foundInputPair == std::end(_networkInputs)) { - IE_THROW(NotFound) << "Failed to find input with name: \'" << name << "\'"; - } - dims = foundInputPair->second->getTensorDesc().getDims(); - refSize = foundInputPair->second->getTensorDesc().getLayout() != SCALAR - ? details::product(dims) - : 1; - } else { - auto foundOutputPair = std::find_if(std::begin(_networkOutputs), std::end(_networkOutputs), - [&](const std::pair& pair) { - return pair.first == name; - }); - if (foundOutputPair == std::end(_networkOutputs)) { - IE_THROW(NotFound) << "Failed to find output with name: \'" << name << "\'"; - } - dims = foundOutputPair->second->getTensorDesc().getDims(); - refSize = foundOutputPair->second->getTensorDesc().getLayout() != SCALAR - ? details::product(dims) - : 1; - } - } else { - refSize = details::product(refDims); - } - - if (refSize != blob->size()) { - IE_THROW() << strNotMatched + ": got " << blob->size() << " expecting " << refSize; - } - const bool remoteBlobPassed = blob->is(); - if (!remoteBlobPassed && blob->buffer() == nullptr) IE_THROW() << strNotAllocated; - } - - /** - * @brief Checks whether pre-processing step is required for a given input - * @param info InputInfo corresponding to input blob - * @param userBlob Input Blob object corresponding to input info - * @param deviceBlob Blob object in plugin's desired format - * @return `True` if pre-processing is required, `false` otherwise - */ - bool preProcessingRequired(const InputInfo::Ptr& info, const Blob::Ptr& userBlob, const Blob::Ptr& deviceBlob = nullptr) { - // pre-processing is required if: - // 1. resize algorithm is specified (resize required) - // 2. color format specified: - // 2.a. color format is not equal to network's expected (color conversion required) - // 2.b. network's layout != blob's layout (reorder required) - // 3. precision conversion is required - - const auto& preProcessInfo = info->getPreProcess(); - const auto inputColorFormat = preProcessInfo.getColorFormat(); - // FIXME: support other network's input formats once the API is ready. Assuming input is in - // the BGR format by default - const auto networkColorFormat = ColorFormat::BGR; - const bool colorFormatSpecified = inputColorFormat != ColorFormat::RAW; - - auto blob_layout = [](const Blob::Ptr& b) { return b->getTensorDesc().getLayout(); }; - auto blob_prec = [](const Blob::Ptr& b) { return b->getTensorDesc().getPrecision();}; - - auto dst_layout = deviceBlob ? blob_layout(deviceBlob) : info->getLayout(); - auto dst_prec = deviceBlob ? blob_prec(deviceBlob) : info->getPrecision(); - - //FIXME: remove the first part to allow any needed conversion? - const bool need_layout_conv = (colorFormatSpecified || deviceBlob) && - (blob_layout(userBlob) != dst_layout); - - return preProcessInfo.getResizeAlgorithm() != ResizeAlgorithm::NO_RESIZE || - (colorFormatSpecified && inputColorFormat != networkColorFormat) || - need_layout_conv || - (blob_prec(userBlob) != dst_prec); - } - - void addInputPreProcessingFor(const std::string& name, Blob::Ptr const& from, const Blob::Ptr& to) { - auto ppDataIt = _preProcData.find(name); - if (ppDataIt == _preProcData.end()) { - ppDataIt = (_preProcData.emplace(name, CreatePreprocDataHelper())).first; - } - - auto& preproc_ptr = ppDataIt->second; - preproc_ptr->isApplicable(from, to); - // Stores the given blob as ROI blob. It will be used to fill in network input - // during pre-processingstd::map - preproc_ptr->setRoiBlob(from); - } -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp index 6868277331f..b88f77021ed 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -11,9 +12,10 @@ #include #include #include +#include namespace InferenceEngine { - +class IInferRequestInternal; /** * @interface IExecutableNetworkInternal * @brief An internal API of executable network to be implemented by plugin, @@ -52,7 +54,7 @@ public: * Note: the returned request will have allocated input and output blobs (that can be changed later) * @return shared_ptr for the created request */ - virtual IInferRequest::Ptr CreateInferRequest() = 0; + virtual std::shared_ptr CreateInferRequest() = 0; /** * @deprecated Use IExecutableNetworkInternal::Export(std::ostream& networkModel) diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp deleted file mode 100644 index 06d15191648..00000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "ie_iinfer_request_internal.hpp" - -namespace InferenceEngine { - -/** - * @interface IAsyncInferRequestInternal - * @ingroup ie_dev_api_async_infer_request_api - * @brief An internal API of asynchronous inference request to be implemented by plugin, - * which is used in InferRequestBase forwarding mechanism - */ -class IAsyncInferRequestInternal : virtual public IInferRequestInternal { -public: - /** - * @brief A shared pointer to IAsyncInferRequestInternal interface - */ - typedef std::shared_ptr Ptr; - - /** - * @brief Start inference of specified input(s) in asynchronous mode - * @note The method returns immediately. Inference starts also immediately. - */ - virtual void StartAsync() = 0; - - /** - * @brief Waits for the result to become available. Blocks until specified millis_timeout has elapsed or the result - * becomes available, whichever comes first. - * @param millis_timeout - maximum duration in milliseconds to block for - * @note There are special cases when millis_timeout is equal some value of WaitMode enum: - * * STATUS_ONLY - immediately returns request status (IInferRequest::RequestStatus). It doesn't block or interrupt - * current thread. - * * RESULT_READY - waits until inference result becomes available - * @return A status code - */ - virtual StatusCode Wait(int64_t millis_timeout) = 0; - - /** - * @brief Get arbitrary data for the request - * @param data A pointer to a pointer to arbitrary data - */ - virtual void GetUserData(void** data) = 0; - - /** - * @brief Set arbitrary data for the request - * @param data A pointer to a pointer to arbitrary data - */ - virtual void SetUserData(void* data) = 0; - - /** - * @brief Set callback function which will be called on success or failure of asynchronous request - * @param callback - function to be called with the following description: - */ - virtual void SetCompletionCallback(IInferRequest::CompletionCallback callback) = 0; -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp index 8409e82a218..616d4d8ada1 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp @@ -4,52 +4,67 @@ #pragma once -#include #include #include -#include +#include +#include +#include #include #include #include namespace InferenceEngine { - +class IExecutableNetworkInternal; +class IVariableStateInternal; /** * @interface IInferRequestInternal * @brief An internal API of synchronous inference request to be implemented by plugin, * which is used in InferRequestBase forwarding mechanism * @ingroup ie_dev_api_infer_request_api */ -class IInferRequestInternal { +class INFERENCE_ENGINE_API_CLASS(IInferRequestInternal) : public std::enable_shared_from_this { public: /** * @brief A shared pointer to a IInferRequestInternal interface */ - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; + + IInferRequestInternal() = default; /** - * @brief Destroys the object. + * @brief Constructs a new instance. + * @param[in] networkInputs The network inputs info + * @param[in] networkOutputs The network outputs data */ - virtual ~IInferRequestInternal() = default; + IInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs); /** * @brief Infers specified input(s) in synchronous mode * @note blocks all method of IInferRequest while request is ongoing (running or waiting in queue) */ - virtual void Infer() = 0; + virtual void Infer(); + + /** + * @brief The minimal infer function to be implemented by plugins. It infers specified input(s) in synchronous mode + * @note + * * This method is used in IInferRequestInternal::Infer, which calls the common code first and after uses this + * plugin dependent implementation. + * * Blocks all method of IInferRequest while request is ongoing (running or waiting in queue) + */ + virtual void InferImpl(); /** * @brief Cancel current inference request execution */ - virtual void Cancel() = 0; + virtual void Cancel(); /** * @brief Queries performance measures per layer to get feedback of what is the most time consuming layer. * Note: not all plugins may provide meaningful data - * @return Returns a map of layer names to profiling information for that layer. + * @return - a map of layer names to profiling information for that layer. */ - virtual std::map GetPerformanceCounts() const = 0; + virtual std::map GetPerformanceCounts() const; /** * @brief Set input/output data to infer @@ -58,16 +73,16 @@ public: * @param data - a reference to input or output blob. The type of Blob must correspond to the network input * precision and size. */ - virtual void SetBlob(const std::string& name, const Blob::Ptr& data) = 0; + virtual void SetBlob(const std::string& name, const Blob::Ptr& data); /** * @brief Get input/output data to infer * @note Memory allocation doesn't happen * @param name - a name of input or output blob. - * @return Returns input or output blob. The type of Blob must correspond to the network input + * @param data - a reference to input or output blob. The type of Blob must correspond to the network input * precision and size. */ - virtual Blob::Ptr GetBlob(const std::string& name) = 0; + virtual Blob::Ptr GetBlob(const std::string& name); /** * @brief Sets pre-process for input data @@ -75,26 +90,138 @@ public: * @param data - a reference to input or output blob. The type of Blob must correspond to the network input precision and size. * @param info Preprocess info for blob. */ - virtual void SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info) = 0; + virtual void SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info); /** * @brief Gets pre-process for input data * @param name Name of input blob. - * @return Returns constant reference to PreProcessInfo structure + * @param info pointer to a pointer to PreProcessInfo structure */ - virtual const PreProcessInfo& GetPreProcess(const std::string& name) const = 0; + virtual const PreProcessInfo& GetPreProcess(const std::string& name) const; /** * @brief Sets new batch size when dynamic batching is enabled in executable network that created this request. * @param batch - new batch size to be used by all the following inference calls for this request. */ - virtual void SetBatch(int batch) = 0; + virtual void SetBatch(int batch); /** * @brief Queries memory states. * @return Returns memory states */ - virtual std::vector QueryState() = 0; + virtual std::vector> QueryState(); + + /** + * @brief Start inference of specified input(s) in asynchronous mode + * @note The method returns immediately. Inference starts also immediately. + */ + virtual void StartAsync(); + + /** + * @brief The minimal asynchronous inference function to be implemented by plugins. + * It starts inference of specified input(s) in asynchronous mode + * @note + * * The methos is used in AsyncInferRequestInternal::StartAsync which performs common steps first and + * calls plugin dependent implementation of this method after. + * * It returns immediately. Inference starts also immediately. + */ + virtual void StartAsyncImpl(); + + /** + * @brief Waits for the result to become available. Blocks until specified millis_timeout has elapsed or the result + * becomes available, whichever comes first. + * @param millis_timeout - maximum duration in milliseconds to block for + * @note There are special cases when millis_timeout is equal some value of WaitMode enum: + * * STATUS_ONLY - immediately returns request status (IInferRequest::RequestStatus). It doesn't block or interrupt + * current thread. + * * RESULT_READY - waits until inference result becomes available + * @return A status code + */ + virtual StatusCode Wait(int64_t millis_timeout); + + /** + * @brief Alias for callback type + */ + using Callback = std::function; + + /** + * @brief Set callback function which will be called on success or failure of asynchronous request + * @param callback - function to be called with the following description: + */ + virtual void SetCallback(Callback callback); + + /** + * @brief Check that @p blob is valid. Throws an exception if it's not. + * + * @param[in] blob The blob to check + * @param[in] name The name of input or output depending of if the @p blob is input or output + * @param[in] isInput Indicates if @p is input + * @param[in] refDims The reference dims, empty if not specified + */ + void checkBlob(const Blob::Ptr& blob, const std::string& name, bool isInput, const SizeVector& refDims = {}) const; + + /** + * @brief Check that all of the blobs is valid. Throws an exception if it's not. + */ + virtual void checkBlobs(); + + /** + * @brief Sets the pointer to executable network internal. + * @note Needed to correctly handle ownership between objects. + * @param[in] exeNetwork The executable network + */ + void setPointerToExecutableNetworkInternal(const std::shared_ptr& exeNetwork); + +protected: + /** + * @brief Checks and executes input data pre-processing if needed. + * @param inputs Inputs blobs to perform preprocessing on + * @param serial Whether to use multiple threads to execute the step + */ + void execDataPreprocessing(InferenceEngine::BlobMap& preprocessedBlobs, bool serial = false); + + /** + * @brief Helper function to find input or output blob by name + * @param name A name of input or output blob. + * @param foundInput A pointer to input information if found. + * @param foundOutput A pointer to output DataPtr if found. + * @return `True` - if loaded network has input with provided name, + * `false` - if loaded network has output with provided name + * @throws [parameter_mismatch] exception if input and output has the same name + * @throws [not_found] exception if there is no input and output layers with given name + */ + bool findInputAndOutputBlobByName(const std::string& name, InputInfo::Ptr& foundInput, DataPtr& foundOutput) const; + + /** + * @brief Checks whether pre-processing step is required for a given input + * @param info InputInfo corresponding to input blob + * @param userBlob Input Blob object corresponding to input info + * @param deviceBlob Blob object in plugin's desired format + * @return `True` if pre-processing is required, `false` otherwise + */ + bool preProcessingRequired(const InputInfo::Ptr& info, const Blob::Ptr& userBlob, const Blob::Ptr& deviceBlob = nullptr); + + void addInputPreProcessingFor(const std::string& name, Blob::Ptr const& from, const Blob::Ptr& to); + + InferenceEngine::InputsDataMap _networkInputs; //!< Holds information about network inputs info + InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data + InferenceEngine::BlobMap _inputs; //!< A map of user passed blobs for network inputs + InferenceEngine::BlobMap _deviceInputs; //!< A map of actual network inputs, in plugin specific format + InferenceEngine::BlobMap _outputs; //!< A map of user passed blobs for network outputs + std::map _preProcData; //!< A map of pre-process data per input + int m_curBatch = -1; //!< Current batch value used in dynamic batching + + /** + * @brief A shared pointer to ExecutableNetworkInternal interface + * @note Needed to correctly handle ownership between objects. + */ + std::shared_ptr _exeNetwork; + Callback _callback; //!< A callback + + /** + * @brief Destroys the object. + */ + ~IInferRequestInternal(); }; } // namespace InferenceEngine diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_async_infer_request.h b/inference-engine/src/vpu/myriad_plugin/myriad_async_infer_request.h index 4ef9fe4f812..cdf3f3bb95e 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_async_infer_request.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_async_infer_request.h @@ -17,7 +17,7 @@ public: const InferenceEngine::ITaskExecutor::Ptr &callbackExecutor, const InferenceEngine::ITaskExecutor::Ptr &taskExecutorGetResult); - ~MyriadAsyncInferRequest() override; + ~MyriadAsyncInferRequest(); private: MyriadInferRequest::Ptr _request; InferenceEngine::ITaskExecutor::Ptr _taskExecutorGetResult; diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h index 312d7ff3b21..48d3f87e3cd 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h @@ -61,7 +61,7 @@ public: } } - ie::InferRequestInternal::Ptr CreateInferRequestImpl(ie::InputsDataMap networkInputs, + ie::IInferRequestInternal::Ptr CreateInferRequestImpl(ie::InputsDataMap networkInputs, ie::OutputsDataMap networkOutputs) override { if (_device == nullptr || !_device->isBooted()) { IE_THROW() << "Can not create infer request: there is no available devices with platform " @@ -73,7 +73,7 @@ public: _graphMetaData.stagesMeta, _config, _log, _executor); } - ie::IInferRequest::Ptr CreateInferRequest() override { + ie::IInferRequestInternal::Ptr CreateInferRequest() override { ie::IInferRequest::Ptr asyncRequest; if (_device == nullptr || !_device->isBooted()) { IE_THROW() << "Can not create infer request: there is no available devices with platform " @@ -86,11 +86,8 @@ public: _executor); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); auto taskExecutorGetResult = getNextTaskExecutor(); - auto asyncThreadSafeImpl = std::make_shared( + return std::make_shared( syncRequestImpl, _taskExecutor, _callbackExecutor, taskExecutorGetResult); - asyncRequest.reset(new ie::InferRequestBase(asyncThreadSafeImpl)); - asyncThreadSafeImpl->SetPointerToPublicInterface(asyncRequest); - return asyncRequest; } void Export(std::ostream& model) override { diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp index f24ade4100b..b143e78c121 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp @@ -33,7 +33,7 @@ MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc, const MyriadConfig& myriadConfig, const Logger::Ptr &log, const MyriadExecutorPtr &executor) : - InferRequestInternal(networkInputs, networkOutputs), _executor(executor), + IInferRequestInternal(networkInputs, networkOutputs), _executor(executor), _log(log), _stagesMetaData(blobMetaData), _config(myriadConfig), _inputInfo(compilerInputsInfo), _outputInfo(compilerOutputsInfo), _graphDesc(graphDesc) { diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.h b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.h index ec41206109b..4055c64033e 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.h @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -22,7 +21,7 @@ namespace vpu { namespace MyriadPlugin { -class MyriadInferRequest : public InferenceEngine::InferRequestInternal { +class MyriadInferRequest : public InferenceEngine::IInferRequestInternal { MyriadExecutorPtr _executor; Logger::Ptr _log; std::vector _stagesMetaData; diff --git a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp index 5f3983a0a63..cdbdcd0b14b 100644 --- a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp +++ b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp @@ -13,11 +13,6 @@ using namespace InferenceEngine; using namespace InferenceEngine::details; -TEST(InferRequestCPPTests, throwsOnInitWithNull) { - IInferRequest::Ptr nlptr = nullptr; - ASSERT_THROW(InferRequest req(nlptr), InferenceEngine::Exception); -} - TEST(InferRequestCPPTests, throwsOnUninitializedSetBlob) { InferRequest req; ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::Exception); @@ -81,7 +76,7 @@ TEST(InferRequestCPPTests, throwsOnUninitializedSetCompletionCallback) { TEST(InferRequestCPPTests, throwsOnUninitializedCast) { InferRequest req; - ASSERT_THROW((void)static_cast(req), InferenceEngine::Exception); + ASSERT_THROW((void)static_cast(req), InferenceEngine::Exception); } TEST(InferRequestCPPTests, throwsOnUninitializedQueryState) { diff --git a/inference-engine/tests/functional/inference_engine/caching_test.cpp b/inference-engine/tests/functional/inference_engine/caching_test.cpp index 78204382898..8902468b974 100644 --- a/inference-engine/tests/functional/inference_engine/caching_test.cpp +++ b/inference-engine/tests/functional/inference_engine/caching_test.cpp @@ -98,11 +98,12 @@ class MockExecutableNetwork : public ExecutableNetworkInternal { public: MockExecutableNetwork() {} MOCK_METHOD1(ExportImpl, void(std::ostream& networkModel)); - MOCK_METHOD0(CreateInferRequest, IInferRequest::Ptr()); + MOCK_METHOD0(CreateInferRequest, IInferRequestInternal::Ptr()); MOCK_CONST_METHOD0(GetInputsInfo, ConstInputsDataMap()); MOCK_CONST_METHOD0(GetOutputsInfo, ConstOutputsDataMap()); MOCK_CONST_METHOD1(GetConfig, Parameter(const std::string& name)); MOCK_CONST_METHOD1(GetMetric, Parameter(const std::string& name)); + MOCK_METHOD2(CreateInferRequestImpl, IInferRequestInternal::Ptr(InputsDataMap, OutputsDataMap)); }; //------------------------------------------------------ @@ -251,9 +252,8 @@ public: EXPECT_CALL(*mock, GetOutputsInfo()).Times(AnyNumber()).WillRepeatedly(Return(ConstOutputsDataMap{})); EXPECT_CALL(*mock, GetConfig(PluginConfigParams::KEY_PERF_COUNT)).Times(AnyNumber()).WillRepeatedly(Return(Parameter{PluginConfigParams::NO})); EXPECT_CALL(*mock, GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS))).Times(AnyNumber()).WillRepeatedly(Return(Parameter{1u})); - auto ptr = std::make_shared(); - EXPECT_CALL(*ptr, SetCompletionCallback(_)).Times(AnyNumber()).WillRepeatedly(Return(OK)); - EXPECT_CALL(*ptr, SetUserData(_, _)).Times(AnyNumber()).WillRepeatedly(Return(OK)); + auto ptr = std::make_shared(); + EXPECT_CALL(*ptr, SetCallback(_)).Times(AnyNumber()); EXPECT_CALL(*mock, CreateInferRequest()).Times(AnyNumber()).WillRepeatedly(Return(ptr)); return mock; } @@ -345,10 +345,8 @@ private: })); EXPECT_CALL(*net, CreateInferRequest()).Times(AnyNumber()) .WillRepeatedly(Invoke([&]() { - std::vector res; - auto inferReq = std::make_shared(); - EXPECT_CALL(*inferReq, SetCompletionCallback(_)).Times(AnyNumber()).WillRepeatedly(Return(OK)); - EXPECT_CALL(*inferReq, SetUserData(_, _)).Times(AnyNumber()).WillRepeatedly(Return(OK)); + auto inferReq = std::make_shared(); + EXPECT_CALL(*inferReq, SetCallback(_)).Times(AnyNumber()); return inferReq; })); } diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp index 2dfb4bd4835..83a4bf24677 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp @@ -122,20 +122,12 @@ TEST_P(CallbackTests, returnGeneralErrorIfCallbackThrowException) { // Load CNNNetwork to target plugins auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration); // Create InferRequest - InferenceEngine::IInferRequest::Ptr req = static_cast(execNet.CreateInferRequest()); - req->SetCompletionCallback( - [](InferenceEngine::IInferRequest::Ptr, InferenceEngine::StatusCode status) { - IE_THROW() << "returnGeneralErrorIfCallbackThrowException"; - }); + auto req = execNet.CreateInferRequest(); + req.SetCompletionCallback([] { + IE_THROW(GeneralError); + }); - InferenceEngine::ResponseDesc resp; - req->StartAsync(&resp); - InferenceEngine::StatusCode waitStatus = InferenceEngine::StatusCode::INFER_NOT_STARTED; - while (InferenceEngine::StatusCode::RESULT_NOT_READY == waitStatus || - InferenceEngine::StatusCode::INFER_NOT_STARTED == waitStatus) { - waitStatus = req->Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY, &resp); - } - ASSERT_EQ(InferenceEngine::StatusCode::GENERAL_ERROR, waitStatus); - ASSERT_NE(std::string(resp.msg).find("returnGeneralErrorIfCallbackThrowException"), std::string::npos); + ASSERT_NO_THROW(req.StartAsync()); + ASSERT_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY), InferenceEngine::GeneralError); } } // namespace BehaviorTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_output.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_output.hpp index 8132f3cc32e..60a56f1adeb 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_output.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_output.hpp @@ -131,11 +131,9 @@ TEST_P(InferRequestOutputTests, canStartAsyncInferWithGetInOut) { InferenceEngine::InferRequest req; ASSERT_NO_THROW(req = execNet.CreateInferRequest()); InferenceEngine::Blob::Ptr inputBlob = req.GetBlob(cnnNet.getInputsInfo().begin()->first); - InferenceEngine::StatusCode sts; ASSERT_NO_THROW(req.Infer()); ASSERT_NO_THROW(req.StartAsync()); - sts = req.Wait(500); - ASSERT_EQ(InferenceEngine::StatusCode::OK, sts); + ASSERT_NO_THROW(req.Wait()); InferenceEngine::Blob::Ptr outputBlob = req.GetBlob(cnnNet.getOutputsInfo().begin()->first); } } // namespace BehaviorTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp b/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp index 58f2bfc78c1..538e6b03942 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp @@ -12,14 +12,10 @@ #include "unit_test_utils/mocks/cpp_interfaces/mock_task_executor.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp" diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp index a4bfc297f4e..2a1df11648f 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp @@ -12,13 +12,11 @@ #include -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" - using namespace InferenceEngine; class MockAsyncInferRequestDefault : public AsyncInferRequestThreadSafeDefault { public: - MockAsyncInferRequestDefault(InferRequestInternal::Ptr request, + MockAsyncInferRequestDefault(IInferRequestInternal::Ptr request, const ITaskExecutor::Ptr &taskExecutor, const ITaskExecutor::Ptr &callbackExecutor) : AsyncInferRequestThreadSafeDefault(request, taskExecutor, callbackExecutor) {} diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp deleted file mode 100644 index 29148ad90ab..00000000000 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include - -#include - -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" - -using namespace InferenceEngine; - -class MockAsyncInferRequestInternal : public AsyncInferRequestInternal { -public: - using AsyncInferRequestInternal::SetBlob; - MockAsyncInferRequestInternal(InputsDataMap networkInputs, OutputsDataMap networkOutputs) - : AsyncInferRequestInternal(networkInputs, networkOutputs) {} - - MOCK_METHOD0(StartAsyncImpl, void()); - MOCK_METHOD1(Wait, InferenceEngine::StatusCode(int64_t)); - MOCK_METHOD1(GetUserData, void(void **)); - MOCK_METHOD1(SetUserData, void(void *)); - MOCK_METHOD0(InferImpl, void()); - MOCK_CONST_METHOD0(GetPerformanceCounts, std::map()); - MOCK_METHOD1(setNetworkInputs, void(InputsDataMap)); - MOCK_METHOD1(setNetworkOutputs, void(OutputsDataMap)); - MOCK_METHOD1(GetBlob, Blob::Ptr(const std::string&)); - MOCK_METHOD1(SetCompletionCallback, void(IInferRequest::CompletionCallback)); - MOCK_METHOD0(Cancel, void()); - MOCK_METHOD0(Cancel_ThreadUnsafe, void()); -}; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp index 82c914b076e..22324ad364c 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp @@ -13,12 +13,10 @@ #include "ie_iexecutable_network.hpp" #include -#include #include #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" using namespace InferenceEngine; @@ -26,7 +24,7 @@ class MockExecutableNetworkInternal : public ExecutableNetworkInternal { public: MOCK_METHOD1(setNetworkInputs, void(InputsDataMap)); MOCK_METHOD1(setNetworkOutputs, void(OutputsDataMap)); - MOCK_METHOD0(CreateInferRequest, IInferRequest::Ptr(void)); + MOCK_METHOD0(CreateInferRequest, IInferRequestInternal::Ptr(void)); MOCK_METHOD1(Export, void(const std::string &)); MOCK_METHOD0(GetExecGraphInfo, CNNNetwork(void)); void WrapOstreamExport(std::ostream& networkModel) { @@ -36,4 +34,5 @@ public: void ExportImpl(std::ostream& networkModel) override { networkModel << exportString << std::endl; } + MOCK_METHOD2(CreateInferRequestImpl, IInferRequestInternal::Ptr(InputsDataMap, OutputsDataMap)); }; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp deleted file mode 100644 index 912233e1d9a..00000000000 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "ie_iexecutable_network.hpp" -#include -#include -#include -#include - -using namespace InferenceEngine; - -class MockExecutableNetworkThreadSafeAsyncOnly : public ExecutableNetworkThreadSafeAsyncOnly { -public: - MOCK_METHOD2(CreateAsyncInferRequestImpl, - AsyncInferRequestInternal::Ptr(InputsDataMap networkInputs, OutputsDataMap networkOutputs)); - MOCK_METHOD1(Export, void(const std::string &)); - void Export(std::ostream&) override {} -}; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp index 088d23b4855..05304d7bb0c 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp @@ -15,7 +15,7 @@ using namespace InferenceEngine; class MockExecutableNetworkThreadSafe : public ExecutableNetworkThreadSafeDefault { public: MOCK_METHOD2(CreateInferRequestImpl, - std::shared_ptr(InputsDataMap networkInputs, OutputsDataMap networkOutputs)); + std::shared_ptr(InputsDataMap networkInputs, OutputsDataMap networkOutputs)); MOCK_METHOD1(Export, void(const std::string &)); void Export(std::ostream &) override {} }; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp deleted file mode 100644 index 12cddf27f42..00000000000 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "ie_iexecutable_network.hpp" -#include -#include -#include -#include - -using namespace InferenceEngine; - -class MockInferRequestInternal : public InferRequestInternal { -public: - MockInferRequestInternal(InputsDataMap networkInputs, OutputsDataMap networkOutputs) - : InferRequestInternal(networkInputs, networkOutputs) {} - using InferRequestInternal::SetBlob; - using InferRequestInternal::GetBlob; - MOCK_METHOD0(InferImpl, void()); - MOCK_CONST_METHOD0(GetPerformanceCounts, std::map()); - MOCK_METHOD0(checkBlobs, void()); - MOCK_METHOD0(Cancel, void()); -}; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp deleted file mode 100644 index 79a97d9d4be..00000000000 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include -#include - -class MockIAsyncInferRequestInternal : public InferenceEngine::IAsyncInferRequestInternal { -public: - MOCK_METHOD0(StartAsync, void()); - MOCK_METHOD1(Wait, InferenceEngine::StatusCode(int64_t)); - MOCK_METHOD1(GetUserData, void(void **)); - MOCK_METHOD1(SetUserData, void(void *)); - MOCK_METHOD0(Infer, void()); - MOCK_CONST_METHOD0(GetPerformanceCounts, std::map()); - MOCK_METHOD2(SetBlob, void(const std::string&, const InferenceEngine::Blob::Ptr &)); - MOCK_METHOD1(GetBlob, InferenceEngine::Blob::Ptr(const std::string&)); - MOCK_METHOD3(SetBlob, void(const std::string&, const InferenceEngine::Blob::Ptr &, const InferenceEngine::PreProcessInfo&)); - MOCK_CONST_METHOD1(GetPreProcess, const InferenceEngine::PreProcessInfo&(const std::string&)); - MOCK_METHOD1(SetCompletionCallback, void(InferenceEngine::IInferRequest::CompletionCallback)); - MOCK_METHOD1(SetBatch, void(int)); - MOCK_METHOD0(QueryState, std::vector()); - MOCK_METHOD0(Cancel, void()); -}; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp index 71e9ad381df..7c6265485dd 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp @@ -14,10 +14,8 @@ #include "ie_icnn_network.hpp" #include "ie_iexecutable_network.hpp" #include -#include #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" using namespace InferenceEngine; @@ -25,7 +23,7 @@ class MockIExecutableNetworkInternal : public IExecutableNetworkInternal { public: MOCK_CONST_METHOD0(GetOutputsInfo, ConstOutputsDataMap(void)); MOCK_CONST_METHOD0(GetInputsInfo, ConstInputsDataMap(void)); - MOCK_METHOD0(CreateInferRequest, IInferRequest::Ptr(void)); + MOCK_METHOD0(CreateInferRequest, IInferRequestInternal::Ptr(void)); MOCK_METHOD1(Export, void(const std::string &)); void Export(std::ostream &) override {}; MOCK_METHOD0(QueryState, std::vector(void)); diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp index bba158bd0c4..a5c1ada89d5 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp @@ -10,16 +10,24 @@ #include #include -#include #include class MockIInferRequestInternal : public InferenceEngine::IInferRequestInternal { public: + using InferenceEngine::IInferRequestInternal::IInferRequestInternal; + MOCK_METHOD0(StartAsync, void()); + MOCK_METHOD1(Wait, InferenceEngine::StatusCode(int64_t)); MOCK_METHOD0(Infer, void()); - MOCK_CONST_METHOD1(GetPerformanceCounts, void(std::map &)); - MOCK_METHOD2(SetBlob, void(const char *name, const InferenceEngine::Blob::Ptr &)); - MOCK_METHOD2(GetBlob, void(const char *name, InferenceEngine::Blob::Ptr &)); - MOCK_METHOD3(SetBlob, void(const char*, const InferenceEngine::Blob::Ptr&, const InferenceEngine::PreProcessInfo&)); - MOCK_METHOD2(GetPreProcess, void(const char*, const InferenceEngine::PreProcessInfo**)); + MOCK_CONST_METHOD0(GetPerformanceCounts, std::map()); + MOCK_METHOD2(SetBlob, void(const std::string&, const InferenceEngine::Blob::Ptr &)); + MOCK_METHOD1(GetBlob, InferenceEngine::Blob::Ptr(const std::string&)); + MOCK_METHOD3(SetBlob, void(const std::string&, const InferenceEngine::Blob::Ptr &, const InferenceEngine::PreProcessInfo&)); + MOCK_CONST_METHOD1(GetPreProcess, const InferenceEngine::PreProcessInfo&(const std::string&)); + MOCK_METHOD1(SetCallback, void(std::function)); + MOCK_METHOD1(SetBatch, void(int)); MOCK_METHOD0(QueryState, std::vector()); + MOCK_METHOD0(Cancel, void()); + MOCK_METHOD0(StartAsyncImpl, void()); + MOCK_METHOD0(InferImpl, void()); + MOCK_METHOD0(checkBlobs, void()); }; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp index 73208737707..a36e1edcf93 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp @@ -14,7 +14,7 @@ class MockIInferencePlugin : public InferenceEngine::IInferencePlugin { public: MOCK_METHOD1(AddExtension, void(InferenceEngine::IExtensionPtr)); MOCK_METHOD2(LoadNetwork, std::shared_ptr( - const CNNNetwork&, const std::map&)); + const InferenceEngine::CNNNetwork&, const std::map&)); MOCK_METHOD2(ImportNetwork, std::shared_ptr( const std::string&, const std::map&)); MOCK_METHOD1(SetConfig, void(const std::map &)); @@ -38,4 +38,7 @@ public: MOCK_METHOD3(ImportNetwork, std::shared_ptr( std::istream&, const InferenceEngine::RemoteContext::Ptr&, const std::map&)); + MOCK_QUALIFIED_METHOD2(QueryNetwork, const, + InferenceEngine::QueryNetworkResult(const InferenceEngine::CNNNetwork&, + const std::map&)); }; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp index 02a5e9792a7..a0f39b7f987 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp @@ -7,9 +7,8 @@ #include -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_async_only.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" using namespace ::testing; using namespace std; @@ -18,85 +17,11 @@ using namespace InferenceEngine::details; IE_SUPPRESS_DEPRECATED_START -class ExecutableNetworkThreadSafeAsyncOnlyTests : public ::testing::Test { -protected: - shared_ptr mockExeNetwork; - shared_ptr mockAsyncInferRequestInternal; - shared_ptr exeNetwork; - ResponseDesc dsc; - StatusCode sts; - - virtual void TearDown() { - EXPECT_TRUE(Mock::VerifyAndClearExpectations(mockAsyncInferRequestInternal.get())); - EXPECT_TRUE(Mock::VerifyAndClearExpectations(mockExeNetwork.get())); - } - - virtual void SetUp() { - mockExeNetwork = make_shared(); - exeNetwork = std::make_shared(mockExeNetwork); - InputsDataMap networkInputs; - OutputsDataMap networkOutputs; - mockAsyncInferRequestInternal = make_shared(networkInputs, networkOutputs); - } -}; - -TEST_F(ExecutableNetworkThreadSafeAsyncOnlyTests, createAsyncInferRequestCallsThreadSafeImplAndSetNetworkIO) { - IInferRequest::Ptr req; - EXPECT_CALL(*mockExeNetwork.get(), CreateAsyncInferRequestImpl(_, _)).WillOnce( - Return(mockAsyncInferRequestInternal)); - EXPECT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); - auto threadSafeReq = dynamic_pointer_cast(req); - ASSERT_NE(threadSafeReq, nullptr); -} - -TEST_F(ExecutableNetworkThreadSafeAsyncOnlyTests, returnErrorIfInferThrowsException) { - IInferRequest::Ptr req; - EXPECT_CALL(*mockExeNetwork.get(), CreateAsyncInferRequestImpl(_, _)).WillOnce( - Return(mockAsyncInferRequestInternal)); - EXPECT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::runtime_error(""))); - EXPECT_NO_THROW(sts = req->Infer(&dsc)); - ASSERT_EQ(StatusCode::GENERAL_ERROR, sts) << dsc.msg; -} - -TEST_F(ExecutableNetworkThreadSafeAsyncOnlyTests, returnErrorIfStartAsyncThrowsException) { - IInferRequest::Ptr req; - EXPECT_CALL(*mockExeNetwork.get(), CreateAsyncInferRequestImpl(_, _)).WillOnce( - Return(mockAsyncInferRequestInternal)); - EXPECT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), StartAsyncImpl()).WillOnce(Throw(std::runtime_error(""))); - EXPECT_NO_THROW(sts = req->StartAsync(&dsc)); - ASSERT_EQ(StatusCode::GENERAL_ERROR, sts) << dsc.msg; -} - -TEST_F(ExecutableNetworkThreadSafeAsyncOnlyTests, canForwardStartAsyncAndInfer) { - IInferRequest::Ptr req; - EXPECT_CALL(*mockExeNetwork.get(), CreateAsyncInferRequestImpl(_, _)).WillOnce( - Return(mockAsyncInferRequestInternal)); - EXPECT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), StartAsyncImpl()).Times(1); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), InferImpl()).Times(1); - - EXPECT_NO_THROW(req->StartAsync(&dsc)) << dsc.msg; - EXPECT_NO_THROW(req->Infer(&dsc)) << dsc.msg; -} - -TEST_F(ExecutableNetworkThreadSafeAsyncOnlyTests, canForwardInferAndStartAsync) { - IInferRequest::Ptr req; - EXPECT_CALL(*mockExeNetwork.get(), CreateAsyncInferRequestImpl(_, _)).WillOnce( - Return(mockAsyncInferRequestInternal)); - EXPECT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), StartAsyncImpl()).Times(1); - EXPECT_CALL(*mockAsyncInferRequestInternal.get(), InferImpl()).Times(1); - EXPECT_NO_THROW(req->Infer(&dsc)) << dsc.msg; - EXPECT_NO_THROW(req->StartAsync(&dsc)) << dsc.msg; -} - class ExecutableNetworkThreadSafeTests : public ::testing::Test { protected: shared_ptr mockExeNetwork; shared_ptr exeNetwork; - shared_ptr mockInferRequestInternal; + shared_ptr mockInferRequestInternal; ResponseDesc dsc; StatusCode sts; @@ -110,7 +35,7 @@ protected: exeNetwork = std::make_shared(mockExeNetwork); InputsDataMap networkInputs; OutputsDataMap networkOutputs; - mockInferRequestInternal = make_shared(networkInputs, networkOutputs); + mockInferRequestInternal = make_shared(networkInputs, networkOutputs); } }; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp index 08af204bdab..22797de486a 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp @@ -7,13 +7,16 @@ #include #include +#include +#include #include #include +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" #include "unit_test_utils/mocks/mock_iinfer_request.hpp" #include "unit_test_utils/mocks/mock_not_empty_icnn_network.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" using namespace ::testing; using namespace std; @@ -25,7 +28,7 @@ constexpr const char* MockNotEmptyICNNNetwork::OUTPUT_BLOB_NAME; class InferRequestBaseTests : public ::testing::Test { protected: - std::shared_ptr mock_impl; + std::shared_ptr mock_impl; shared_ptr request; ResponseDesc dsc; @@ -33,7 +36,7 @@ protected: } virtual void SetUp() { - mock_impl.reset(new MockIAsyncInferRequestInternal()); + mock_impl.reset(new MockIInferRequestInternal()); request = std::make_shared(mock_impl); } }; @@ -55,42 +58,6 @@ TEST_F(InferRequestBaseTests, canCatchUnknownErrorInStartAsync) { ASSERT_EQ(UNEXPECTED, request->StartAsync(nullptr)); } -// GetUserData -TEST_F(InferRequestBaseTests, canForwardGetUserData) { - void **data = nullptr; - EXPECT_CALL(*mock_impl.get(), GetUserData(data)).Times(1); - ASSERT_EQ(OK, request->GetUserData(data, &dsc)); -} - -TEST_F(InferRequestBaseTests, canReportErrorInGetUserData) { - EXPECT_CALL(*mock_impl.get(), GetUserData(_)).WillOnce(Throw(std::runtime_error("compare"))); - ASSERT_NE(request->GetUserData(nullptr, &dsc), OK); - ASSERT_STREQ(dsc.msg, "compare"); -} - -TEST_F(InferRequestBaseTests, canCatchUnknownErrorInGetUserData) { - EXPECT_CALL(*mock_impl.get(), GetUserData(_)).WillOnce(Throw(5)); - ASSERT_EQ(UNEXPECTED, request->GetUserData(nullptr, nullptr)); -} - -// SetUserData -TEST_F(InferRequestBaseTests, canForwardSetUserData) { - void *data = nullptr; - EXPECT_CALL(*mock_impl.get(), SetUserData(data)).Times(1); - ASSERT_EQ(OK, request->SetUserData(data, &dsc)); -} - -TEST_F(InferRequestBaseTests, canReportErrorInSetUserData) { - EXPECT_CALL(*mock_impl.get(), SetUserData(_)).WillOnce(Throw(std::runtime_error("compare"))); - ASSERT_NE(request->SetUserData(nullptr, &dsc), OK); - ASSERT_STREQ(dsc.msg, "compare"); -} - -TEST_F(InferRequestBaseTests, canCatchUnknownErrorInSetUserData) { - EXPECT_CALL(*mock_impl.get(), SetUserData(_)).WillOnce(Throw(5)); - ASSERT_EQ(UNEXPECTED, request->SetUserData(nullptr, nullptr)); -} - // Wait TEST_F(InferRequestBaseTests, canForwardWait) { int64_t ms = 0; @@ -192,23 +159,27 @@ TEST_F(InferRequestBaseTests, canCatchUnknownErrorInSetBlob) { // SetCompletionCallback TEST_F(InferRequestBaseTests, canForwardSetCompletionCallback) { InferenceEngine::IInferRequest::CompletionCallback callback = nullptr; - EXPECT_CALL(*mock_impl.get(), SetCompletionCallback(callback)).Times(1); + EXPECT_CALL(*mock_impl.get(), SetCallback(_)).Times(1); ASSERT_NO_THROW(request->SetCompletionCallback(callback)); } TEST_F(InferRequestBaseTests, canReportErrorInSetCompletionCallback) { - EXPECT_CALL(*mock_impl.get(), SetCompletionCallback(_)).WillOnce(Throw(std::runtime_error("compare"))); - ASSERT_NO_THROW(request->SetCompletionCallback(nullptr)); + EXPECT_CALL(*mock_impl.get(), SetCallback(_)).WillOnce(Throw(std::runtime_error("compare"))); + ASSERT_NE(request->SetCompletionCallback(nullptr), OK); } class InferRequestTests : public ::testing::Test { protected: - std::shared_ptr mock_request; - InferRequest::Ptr requestWrapper; + std::shared_ptr mock_request; + InferRequest request; ResponseDesc dsc; - shared_ptr mockInferRequestInternal; + std::shared_ptr mockIExeNet; + InferenceEngine::ExecutableNetwork exeNetwork; + MockIInferencePlugin* mockIPlugin; + InferencePlugin plugin; + shared_ptr mockInferRequestInternal; MockNotEmptyICNNNetwork mockNotEmptyNet; std::string _incorrectName; std::string _inputName; @@ -216,15 +187,21 @@ protected: std::string _inputDataNotAllocatedError; std::string _inputDataIsEmptyError; - virtual void TearDown() { + void TearDown() override { EXPECT_TRUE(Mock::VerifyAndClearExpectations(mockInferRequestInternal.get())); EXPECT_TRUE(Mock::VerifyAndClearExpectations(mock_request.get())); - EXPECT_TRUE(Mock::VerifyAndClearExpectations(requestWrapper.get())); + request = {}; } - virtual void SetUp() { - mock_request = make_shared(); - requestWrapper = make_shared(mock_request); + void SetUp() override { + mock_request = make_shared(); + mockIExeNet = std::make_shared(); + ON_CALL(*mockIExeNet, CreateInferRequest()).WillByDefault(Return(mock_request)); + std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + ON_CALL(*mockIPluginPtr, LoadNetwork(_, _)).WillByDefault(Return(mockIExeNet)); + plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + exeNetwork = plugin.LoadNetwork({}, {}); + request = exeNetwork.CreateInferRequest(); _incorrectName = "incorrect_name"; _inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; _failedToFindInOutError = @@ -235,15 +212,20 @@ protected: + _inputName + "\'"; } - InferRequest::Ptr getInferRequestWithMockImplInside() { + InferRequest getInferRequestWithMockImplInside() { IInferRequest::Ptr inferRequest; InputsDataMap inputsInfo; mockNotEmptyNet.getInputsInfo(inputsInfo); OutputsDataMap outputsInfo; mockNotEmptyNet.getOutputsInfo(outputsInfo); - mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); - inferRequest = std::make_shared(mockInferRequestInternal); - return make_shared(inferRequest); + mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); + auto mockIExeNet = std::make_shared(); + ON_CALL(*mockIExeNet, CreateInferRequest()).WillByDefault(Return(mockInferRequestInternal)); + std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + ON_CALL(*mockIPluginPtr, LoadNetwork(_, _)).WillByDefault(Return(mockIExeNet)); + auto plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + auto exeNetwork = plugin.LoadNetwork({}, {}); + return exeNetwork.CreateInferRequest(); } std::string getExceptionMessage(std::function function) { @@ -274,60 +256,52 @@ protected: } }; -// constructor tests -TEST_F(InferRequestTests, constructorsTests) { - // construction from the non-null should not throw - ASSERT_NO_THROW(InferRequest req(mock_request)); - IInferRequest::Ptr tmp; - // InferRequest's "actual" is nullptr, let's check it throws on construction - ASSERT_THROW(InferRequest req(tmp), Exception); -} // StartAsync TEST_F(InferRequestTests, canForwardStartAsync) { - EXPECT_CALL(*mock_request.get(), StartAsync(_)).WillOnce(Return(OK)); - ASSERT_NO_THROW(requestWrapper->StartAsync()); + EXPECT_CALL(*mock_request.get(), StartAsync()); + ASSERT_NO_THROW(request.StartAsync()); } TEST_F(InferRequestTests, throwsIfStartAsyncReturnNotOK) { - EXPECT_CALL(*mock_request.get(), StartAsync(_)).WillOnce(Return(GENERAL_ERROR)); - ASSERT_THROW(requestWrapper->StartAsync(), Exception); + EXPECT_CALL(*mock_request.get(), StartAsync()).WillOnce(Throw(GeneralError{""})); + ASSERT_THROW(request.StartAsync(), Exception); } // Wait TEST_F(InferRequestTests, canForwardWait) { int64_t ms = 0; - EXPECT_CALL(*mock_request.get(), Wait(ms, _)).WillOnce(Return(OK)); - ASSERT_TRUE(OK == requestWrapper->Wait(ms)); + EXPECT_CALL(*mock_request.get(), Wait(_)).WillOnce(Return(OK)); + ASSERT_TRUE(OK == request.Wait(ms)); } TEST_F(InferRequestTests, canForwardStatusFromWait) { - EXPECT_CALL(*mock_request.get(), Wait(_, _)).WillOnce(Return(RESULT_NOT_READY)); - ASSERT_EQ(requestWrapper->Wait(0), RESULT_NOT_READY); + EXPECT_CALL(*mock_request.get(), Wait(_)).WillOnce(Return(RESULT_NOT_READY)); + ASSERT_EQ(request.Wait(0), RESULT_NOT_READY); } // Infer TEST_F(InferRequestTests, canForwardInfer) { - EXPECT_CALL(*mock_request.get(), Infer(_)).WillOnce(Return(OK)); - ASSERT_NO_THROW(requestWrapper->Infer()); + EXPECT_CALL(*mock_request.get(), Infer()); + ASSERT_NO_THROW(request.Infer()); } TEST_F(InferRequestTests, throwsIfInferReturnNotOK) { - EXPECT_CALL(*mock_request.get(), Infer(_)).WillOnce(Return(GENERAL_ERROR)); - ASSERT_THROW(requestWrapper->Infer(), Exception); + EXPECT_CALL(*mock_request.get(), Infer()).WillOnce(Throw(GeneralError{""})); + ASSERT_THROW(request.Infer(), Exception); } // GetPerformanceCounts TEST_F(InferRequestTests, canForwardGetPerformanceCounts) { std::map info; - EXPECT_CALL(*mock_request.get(), GetPerformanceCounts(_, _)).WillOnce(Return(OK)); - ASSERT_NO_THROW(info = requestWrapper->GetPerformanceCounts()); + EXPECT_CALL(*mock_request.get(), GetPerformanceCounts()).WillOnce(Return(info)); + ASSERT_NO_THROW(info = request.GetPerformanceCounts()); } TEST_F(InferRequestTests, throwsIfGetPerformanceCountsReturnNotOK) { std::map info; - EXPECT_CALL(*mock_request.get(), GetPerformanceCounts(_, _)).WillOnce(Return(GENERAL_ERROR)); - ASSERT_THROW(info = requestWrapper->GetPerformanceCounts(), Exception); + EXPECT_CALL(*mock_request.get(), GetPerformanceCounts()).WillOnce(Throw(GeneralError{""})); + ASSERT_THROW(info = request.GetPerformanceCounts(), Exception); } MATCHER_P(blob_in_map_pointer_is_same, ref_blob, "") { @@ -343,15 +317,15 @@ TEST_F(InferRequestTests, getInputCallsSetBlob) { BlobMap blobMap{{blobName1, inblob}, {blobName2, inblob}}; - EXPECT_CALL(*mock_request.get(), SetBlob(StrEq(blobName1.c_str()), inblob, _)).WillOnce(Return(OK)); - EXPECT_CALL(*mock_request.get(), SetBlob(StrEq(blobName2.c_str()), inblob, _)).WillOnce(Return(OK)); - ASSERT_NO_THROW(requestWrapper->SetInput(blobMap)); + EXPECT_CALL(*mock_request.get(), SetBlob(blobName1, inblob)); + EXPECT_CALL(*mock_request.get(), SetBlob(blobName2, inblob)); + ASSERT_NO_THROW(request.SetInput(blobMap)); } TEST_F(InferRequestTests, throwsIfSetInputReturnNotOK) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _, _)).WillOnce(Return(GENERAL_ERROR)); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); BlobMap blobMap{{{}, {}}}; - ASSERT_THROW(requestWrapper->SetInput(blobMap), Exception); + ASSERT_THROW(request.SetInput(blobMap), Exception); } // SetOutput @@ -362,9 +336,9 @@ TEST_F(InferRequestTests, getOutputCallsSetBlob) { BlobMap blobMap{{blobName1, inblob}, {blobName2, inblob}}; - EXPECT_CALL(*mock_request.get(), SetBlob(StrEq(blobName1.c_str()), inblob, _)).WillOnce(Return(OK)); - EXPECT_CALL(*mock_request.get(), SetBlob(StrEq(blobName2.c_str()), inblob, _)).WillOnce(Return(OK)); - ASSERT_NO_THROW(requestWrapper->SetOutput(blobMap)); + EXPECT_CALL(*mock_request.get(), SetBlob(blobName1, inblob)); + EXPECT_CALL(*mock_request.get(), SetBlob(blobName2, inblob)); + ASSERT_NO_THROW(request.SetOutput(blobMap)); } // GetBlob @@ -373,16 +347,16 @@ TEST_F(InferRequestTests, canForwardGetBlob) { blob->allocate(); std::string name = "blob1"; - EXPECT_CALL(*mock_request.get(), GetBlob(StrEq(name.c_str()), _, _)).WillOnce(DoAll(SetArgReferee<1>(blob), Return(OK))); - ASSERT_NO_THROW(requestWrapper->GetBlob(name)); + EXPECT_CALL(*mock_request.get(), GetBlob(_)).WillOnce(Return(blob)); + ASSERT_NO_THROW(request.GetBlob(name)); } TEST_F(InferRequestTests, throwsIfGetBlobReturnNotOK) { Blob::Ptr blob; std::string name = "blob1"; - EXPECT_CALL(*mock_request.get(), GetBlob(_, _, _)).WillOnce(Return(GENERAL_ERROR)); - ASSERT_THROW(blob = requestWrapper->GetBlob(name), Exception); + EXPECT_CALL(*mock_request.get(), GetBlob(_)).WillOnce(Throw(GeneralError{""})); + ASSERT_THROW(blob = request.GetBlob(name), Exception); } // SetBlob @@ -390,79 +364,49 @@ TEST_F(InferRequestTests, canForwardSetBlob) { Blob::Ptr blob; std::string name = "blob1"; - EXPECT_CALL(*mock_request.get(), SetBlob(StrEq(name.c_str()), blob, _)).WillOnce(Return(OK)); - ASSERT_NO_THROW(requestWrapper->SetBlob(name, blob)); + EXPECT_CALL(*mock_request.get(), SetBlob(name, blob)); + ASSERT_NO_THROW(request.SetBlob(name, blob)); } TEST_F(InferRequestTests, throwsIfSetBlobReturnNotOK) { Blob::Ptr blob; std::string name = "blob1"; - EXPECT_CALL(*mock_request.get(), SetBlob(_, _, _)).WillOnce(Return(GENERAL_ERROR)); - ASSERT_THROW(requestWrapper->SetBlob(name, blob), Exception); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); + ASSERT_THROW(request.SetBlob(name, blob), Exception); } TEST_F(InferRequestTests, throwsIfSetOutputReturnNotOK) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _, _)).WillOnce(Return(GENERAL_ERROR)); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); BlobMap blobMap{{{}, {}}}; - ASSERT_THROW(requestWrapper->SetOutput(blobMap), Exception); -} - -// SetCompletionCallback API -void callme(InferenceEngine::IInferRequest::Ptr p, InferenceEngine::StatusCode) { - void *data = nullptr; - p->GetUserData(&data, nullptr); - ASSERT_NE(nullptr, data); -} - -TEST_F(InferRequestTests, canForwardCompletionCallback) { - void *data = nullptr; - EXPECT_CALL(*mock_request.get(), SetCompletionCallback(_)).WillOnce( - DoAll(InvokeArgument<0>(static_pointer_cast(mock_request), OK), Return(OK))); - EXPECT_CALL(*mock_request.get(), GetUserData(_, _)).WillRepeatedly( - DoAll(Invoke([&](void **pData, ResponseDesc *resp) { - *pData = data; - }), Return(OK))); - EXPECT_CALL(*mock_request.get(), SetUserData(_, _)).WillOnce(DoAll(SaveArg<0>(&data), Return(OK))); - ASSERT_NO_THROW(requestWrapper->SetCompletionCallback(&callme)); + ASSERT_THROW(request.SetOutput(blobMap), Exception); } TEST_F(InferRequestTests, canForwardAnyCallback) { - void *data = nullptr; - EXPECT_CALL(*mock_request.get(), SetCompletionCallback(_)).WillOnce( - DoAll(InvokeArgument<0>(static_pointer_cast(mock_request), OK), Return(OK))); - EXPECT_CALL(*mock_request.get(), GetUserData(_, _)).WillRepeatedly( - DoAll(Invoke([&](void **pData, ResponseDesc *resp) { - *pData = data; - }), Return(OK))); - EXPECT_CALL(*mock_request.get(), SetUserData(_, _)).WillOnce(DoAll(SaveArg<0>(&data), Return(OK))); - - ASSERT_NO_THROW(requestWrapper->SetCompletionCallback([&]() { - // data used to store callback pointer - ASSERT_NE(data, nullptr); - })); + EXPECT_CALL(*mock_request.get(), SetCallback(_)); + ASSERT_NO_THROW(request.SetCompletionCallback([] {})); } TEST_F(InferRequestTests, failToSetInputWithInCorrectName) { - auto InferRequest = getInferRequestWithMockImplInside(); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotFound{""})); auto blobMap = getBlobMapWithIncorrectName(); - ASSERT_THROW(InferRequest->SetInput(blobMap), NotFound); + ASSERT_THROW(request.SetInput(blobMap), NotFound); } TEST_F(InferRequestTests, failToSetOutputWithInCorrectName) { - auto InferRequest = getInferRequestWithMockImplInside(); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotFound{""})); auto blobMap = getBlobMapWithIncorrectName(); - ASSERT_THROW(InferRequest->SetOutput(blobMap), NotFound); + ASSERT_THROW(request.SetOutput(blobMap), NotFound); } TEST_F(InferRequestTests, failToSetInputWithNotAllocatedInput) { - auto InferRequest = getInferRequestWithMockImplInside(); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotAllocated{""})); auto blobMap = getBlobMapWithNotAllocatedInput(); - ASSERT_THROW(InferRequest->SetInput(blobMap), NotAllocated); + ASSERT_THROW(request.SetInput(blobMap), NotAllocated); } TEST_F(InferRequestTests, failToSetInputWithEmptyDimensions) { - auto InferRequest = getInferRequestWithMockImplInside(); + EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); auto blobMap = getBlobMapWithEmptyDimensions(); - ASSERT_THROW(InferRequest->SetInput(blobMap), GeneralError); + ASSERT_THROW(request.SetInput(blobMap), GeneralError); } diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp index 8404dc74e88..4a6c2622b27 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp @@ -13,7 +13,7 @@ #include #include "unit_test_utils/mocks/cpp_interfaces/mock_task_executor.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_infer_request_internal.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp" using namespace ::testing; @@ -52,7 +52,7 @@ protected: shared_ptr testRequest; ResponseDesc dsc; - shared_ptr mockInferRequestInternal; + shared_ptr mockInferRequestInternal; MockTaskExecutor::Ptr mockTaskExecutor; @@ -63,7 +63,7 @@ protected: InputsDataMap inputsInfo; OutputsDataMap outputsInfo; mockTaskExecutor = make_shared(); - mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); + mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); testRequest = make_shared(mockInferRequestInternal, mockTaskExecutor, mockTaskExecutor); } }; @@ -90,26 +90,6 @@ TEST_F(InferRequestThreadSafeDefaultTests, canResetBusyStatusIfStartAsyncFails) taskExecutor->executeAll(); } -// GetUserData -TEST_F(InferRequestThreadSafeDefaultTests, returnRequestBusyOnGetUserData) { - auto taskExecutor = std::make_shared(); - testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); - EXPECT_CALL(*mockInferRequestInternal, InferImpl()).Times(1).WillOnce(Return()); - ASSERT_NO_THROW(testRequest->StartAsync()); - ASSERT_THROW(testRequest->GetUserData(nullptr), RequestBusy); - taskExecutor->executeAll(); -} - -// SetUserData -TEST_F(InferRequestThreadSafeDefaultTests, returnRequestBusyOnSetUserData) { - auto taskExecutor = std::make_shared(); - testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); - EXPECT_CALL(*mockInferRequestInternal, InferImpl()).Times(1).WillOnce(Return()); - ASSERT_NO_THROW(testRequest->StartAsync()); - ASSERT_THROW(testRequest->SetUserData(nullptr), RequestBusy); - taskExecutor->executeAll(); -} - // Wait TEST_F(InferRequestThreadSafeDefaultTests, returnInferNotStartedOnWait) { int64_t ms = 0; @@ -175,58 +155,42 @@ TEST_F(InferRequestThreadSafeDefaultTests, returnRequestBusyOnSetCompletionCallb testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); EXPECT_CALL(*mockInferRequestInternal, InferImpl()).Times(1).WillOnce(Return()); ASSERT_NO_THROW(testRequest->StartAsync()); - ASSERT_THROW(testRequest->SetCompletionCallback({}), RequestBusy); + ASSERT_THROW(testRequest->SetCallback({}), RequestBusy); taskExecutor->executeAll(); } TEST_F(InferRequestThreadSafeDefaultTests, callbackTakesOKIfAsyncRequestWasOK) { - auto taskExecutor = std::make_shared(); + auto taskExecutor = std::make_shared(); testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); - - IInferRequest::Ptr asyncRequest; - asyncRequest.reset(new InferRequestBase(testRequest)); - testRequest->SetPointerToPublicInterface(asyncRequest); - - testRequest->SetCompletionCallback([](InferenceEngine::IInferRequest::Ptr request, StatusCode status) { - ASSERT_EQ((int) StatusCode::OK, status); + std::exception_ptr exceptionPtr; + testRequest->SetCallback([&](std::exception_ptr exceptionPtr_) { + exceptionPtr = exceptionPtr_; }); EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).Times(1); - testRequest->StartAsync(); + taskExecutor->executeAll(); testRequest->Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + ASSERT_EQ(nullptr, exceptionPtr); } TEST_F(InferRequestThreadSafeDefaultTests, callbackIsCalledIfAsyncRequestFailed) { - auto taskExecutor = std::make_shared(); + auto taskExecutor = std::make_shared(); testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); - IInferRequest::Ptr asyncRequest; - asyncRequest.reset(new InferRequestBase(testRequest)); - testRequest->SetPointerToPublicInterface(asyncRequest); - - bool wasCalled = false; - InferRequest cppRequest(asyncRequest); - std::function callback = - [&](InferRequest request, StatusCode status) { - wasCalled = true; - ASSERT_EQ(StatusCode::GENERAL_ERROR, status); - }; - cppRequest.SetCompletionCallback(callback); + std::exception_ptr exceptionPtr; + testRequest->SetCallback([&](std::exception_ptr exceptionPtr_) { + exceptionPtr = exceptionPtr_; + }); EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::exception())); - testRequest->StartAsync(); + taskExecutor->executeAll(); EXPECT_THROW(testRequest->Wait(IInferRequest::WaitMode::RESULT_READY), std::exception); - ASSERT_TRUE(wasCalled); + ASSERT_NE(nullptr, exceptionPtr); } TEST_F(InferRequestThreadSafeDefaultTests, canCatchExceptionIfAsyncRequestFailedAndNoCallback) { auto taskExecutor = std::make_shared(); testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); - IInferRequest::Ptr asyncRequest; - asyncRequest.reset(new InferRequestBase(testRequest)); - testRequest->SetPointerToPublicInterface(asyncRequest); - EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::exception())); - testRequest->StartAsync(); EXPECT_THROW(testRequest->Wait(IInferRequest::WaitMode::RESULT_READY), std::exception); } diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp index a998f9b758f..ef2d75587d4 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp @@ -11,7 +11,6 @@ #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iasync_infer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" #include "ie_plugin_cpp.hpp" @@ -20,43 +19,32 @@ using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; -template -inline typename InferenceEngine::InferRequest make_infer_request(std::shared_ptr impl) { - typename InferRequestBase::Ptr req(new InferRequestBase(impl)); - return InferenceEngine::InferRequest(req); -} - class VariableStateTests : public ::testing::Test { protected: shared_ptr mockExeNetworkInternal; - shared_ptr mockInferRequestInternal; + shared_ptr mockInferRequestInternal; shared_ptr mockVariableStateInternal; - - struct TestPluginInternal : public MockIInferencePlugin { - TestPluginInternal(const std::shared_ptr& mockIExeNet_) : mockIExeNet{mockIExeNet_} {} - std::shared_ptr LoadNetwork(const CNNNetwork&, const std::map&) override { - return mockIExeNet; - } - QueryNetworkResult QueryNetwork(const CNNNetwork&, const std::map&) const override {return {};} - std::shared_ptr mockIExeNet; - }; - struct TestPlugin : public InferenceEngine::InferencePlugin { - TestPlugin(std::shared_ptr mockIExeNet) : - InferenceEngine::InferencePlugin(InferenceEngine::details::SOPointer{ - new TestPluginInternal{mockIExeNet}}) {} - }; + MockIInferencePlugin* mockIPlugin; + InferencePlugin plugin; + ExecutableNetwork net; + InferRequest req; virtual void SetUp() { mockExeNetworkInternal = make_shared(); - mockInferRequestInternal = make_shared(); + mockInferRequestInternal = make_shared(); mockVariableStateInternal = make_shared(); + ON_CALL(*mockExeNetworkInternal, CreateInferRequest()).WillByDefault(Return(mockInferRequestInternal)); + std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + ON_CALL(*mockIPluginPtr, LoadNetwork(_, _)).WillByDefault(Return(mockExeNetworkInternal)); + plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + net = plugin.LoadNetwork({}, {}); + req = net.CreateInferRequest(); } }; TEST_F(VariableStateTests, ExecutableNetworkCanConvertOneVariableStateFromCppToAPI) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn(1); toReturn[0] = mockVariableStateInternal; @@ -69,7 +57,6 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvertOneVariableStateFromCppToA TEST_F(VariableStateTests, ExecutableNetworkCanConvertZeroVariableStateFromCppToAPI) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).WillOnce(Return(toReturn)); @@ -81,7 +68,6 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvertZeroVariableStateFromCppTo TEST_F(VariableStateTests, ExecutableNetworkCanConvert2VariableStatesFromCPPtoAPI) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); toReturn.push_back(mockVariableStateInternal); @@ -95,7 +81,6 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvert2VariableStatesFromCPPtoAP TEST_F(VariableStateTests, VariableStatePropagatesReset) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -109,7 +94,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesReset) { TEST_F(VariableStateTests, VariableStatePropagatesExceptionsFromReset) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -123,7 +107,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesExceptionsFromReset) { TEST_F(VariableStateTests, VariableStatePropagatesGetName) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -137,7 +120,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetName) { TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithZeroLen) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -152,7 +134,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithZeroLen) { TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfOne) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -168,7 +149,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfOne) { TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfTwo) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -184,7 +164,6 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfTwo) { TEST_F(VariableStateTests, VariableStateCanPropagateSetState) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; Blob::Ptr saver; toReturn.push_back(mockVariableStateInternal); @@ -204,7 +183,6 @@ TEST_F(VariableStateTests, VariableStateCanPropagateSetState) { TEST_F(VariableStateTests, VariableStateCanPropagateGetLastState) { IE_SUPPRESS_DEPRECATED_START - auto net = TestPlugin{mockExeNetworkInternal}.LoadNetwork({}, {}); std::vector toReturn; float data[] = {123, 124, 125}; @@ -269,18 +247,16 @@ TEST_F(VariableStateTests, VariableStateInternalCanSaveStateByReference) { // Tests for InferRequest::QueryState TEST_F(VariableStateTests, InferRequestCanConvertOneVariableStateFromCppToAPI) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn(1); toReturn[0] = mockVariableStateInternal; - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(2).WillRepeatedly(Return(toReturn)); + EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); auto state = req.QueryState(); ASSERT_EQ(state.size(), 1); } TEST_F(VariableStateTests, InferRequestCanConvertZeroVariableStateFromCppToAPI) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).WillOnce(Return(toReturn)); @@ -290,23 +266,21 @@ TEST_F(VariableStateTests, InferRequestCanConvertZeroVariableStateFromCppToAPI) } TEST_F(VariableStateTests, InferRequestCanConvert2VariableStatesFromCPPtoAPI) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); toReturn.push_back(mockVariableStateInternal); - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(3).WillRepeatedly(Return(toReturn)); + EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); auto state = req.QueryState(); ASSERT_EQ(state.size(), 2); } TEST_F(VariableStateTests, InfReqVariableStatePropagatesReset) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(2).WillRepeatedly(Return(toReturn)); + EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).Times(1); auto state = req.QueryState(); @@ -314,11 +288,10 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesReset) { } TEST_F(VariableStateTests, InfReqVariableStatePropagatesExceptionsFromReset) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(2).WillRepeatedly(Return(toReturn)); + EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).WillOnce(Throw(std::logic_error("some error"))); auto state = req.QueryState(); @@ -326,11 +299,10 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesExceptionsFromReset) { } TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetName) { -auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(2).WillRepeatedly(Return(toReturn)); + EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); auto state = req.QueryState(); @@ -339,7 +311,6 @@ auto req = make_infer_request(mockInferRequestInternal); TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithZeroLen) { IE_SUPPRESS_DEPRECATED_START - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -356,7 +327,6 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithZeroLen) { TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfOne) { IE_SUPPRESS_DEPRECATED_START - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -374,7 +344,6 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfOne) { TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfTwo) { IE_SUPPRESS_DEPRECATED_START - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; toReturn.push_back(mockVariableStateInternal); @@ -391,7 +360,6 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfTwo) { } TEST_F(VariableStateTests, InfReqVariableStateCanPropagateSetState) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; Blob::Ptr saver; toReturn.push_back(mockVariableStateInternal); @@ -409,7 +377,6 @@ TEST_F(VariableStateTests, InfReqVariableStateCanPropagateSetState) { } TEST_F(VariableStateTests, InfReqVariableStateCanPropagateGetLastState) { - auto req = make_infer_request(mockInferRequestInternal); std::vector toReturn; float data[] = {123, 124, 125}; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp index f76806b2193..fcc0f8b5ed9 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp @@ -27,7 +27,7 @@ protected: shared_ptr mock_plugin_impl; shared_ptr mockExeNetworkInternal; shared_ptr mockExeNetworkTS; - shared_ptr mockInferRequestInternal; + shared_ptr mockInferRequestInternal; std::shared_ptr mockNotEmptyNet = std::make_shared(); std::string pluginId; @@ -50,13 +50,13 @@ protected: mockExeNetworkInternal->SetPointerToPlugin(mock_plugin_impl); } - void getInferRequestWithMockImplInside(IInferRequest::Ptr &request) { + void getInferRequestWithMockImplInside(IInferRequestInternal::Ptr &request) { IExecutableNetworkInternal::Ptr exeNetwork; InputsDataMap inputsInfo; mockNotEmptyNet->getInputsInfo(inputsInfo); OutputsDataMap outputsInfo; mockNotEmptyNet->getOutputsInfo(outputsInfo); - mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); + mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); mockExeNetworkTS = make_shared(); EXPECT_CALL(*mock_plugin_impl.get(), LoadExeNetworkImpl(_, _)).WillOnce(Return(mockExeNetworkTS)); EXPECT_CALL(*mockExeNetworkTS.get(), CreateInferRequestImpl(_, _)).WillOnce(Return(mockInferRequestInternal)); @@ -74,14 +74,15 @@ TEST_F(InferenceEnginePluginInternalTest, failToSetBlobWithInCorrectName) { inBlob->allocate(); string inputName = "not_input"; std::string refError = "[ NOT_FOUND ] Failed to find input or output with name: \'" + inputName + "\'"; - IInferRequest::Ptr inferRequest; + IInferRequestInternal::Ptr inferRequest; getInferRequestWithMockImplInside(inferRequest); - - ASSERT_NO_THROW(sts = inferRequest->SetBlob(inputName.c_str(), inBlob, &dsc)); - ASSERT_EQ(StatusCode::NOT_FOUND, sts); - ASSERT_TRUE(std::string{dsc.msg}.find(refError) != std::string::npos) - << "\tExpected: " << refError - << "\n\tActual: " << dsc.msg; + try { + inferRequest->SetBlob(inputName, inBlob); + } catch(InferenceEngine::NotFound& ex) { + ASSERT_TRUE(std::string{ex.what()}.find(refError) != std::string::npos) + << "\tExpected: " << refError + << "\n\tActual: " << ex.what(); + } } TEST_F(InferenceEnginePluginInternalTest, failToSetBlobWithEmptyName) { @@ -89,56 +90,60 @@ TEST_F(InferenceEnginePluginInternalTest, failToSetBlobWithEmptyName) { inBlob->allocate(); string inputName = "not_input"; std::string refError = "[ NOT_FOUND ] Failed to set blob with empty name"; - IInferRequest::Ptr inferRequest; + IInferRequestInternal::Ptr inferRequest; getInferRequestWithMockImplInside(inferRequest); - - ASSERT_NO_THROW(sts = inferRequest->SetBlob("", inBlob, &dsc)); - ASSERT_EQ(StatusCode::NOT_FOUND, sts); - ASSERT_TRUE(std::string{dsc.msg}.find(refError) != std::string::npos) - << "\tExpected: " << refError - << "\n\tActual: " << dsc.msg; + try { + inferRequest->SetBlob(inputName, inBlob); + } catch(InferenceEngine::NotFound& ex) { + ASSERT_TRUE(std::string{ex.what()}.find(refError) != std::string::npos) + << "\tExpected: " << refError + << "\n\tActual: " << ex.what(); + } } TEST_F(InferenceEnginePluginInternalTest, failToSetNullPtr) { string inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; std::string refError = "[ NOT_ALLOCATED ] Failed to set empty blob with name: \'" + inputName + "\'"; - IInferRequest::Ptr inferRequest; + IInferRequestInternal::Ptr inferRequest; getInferRequestWithMockImplInside(inferRequest); Blob::Ptr inBlob = nullptr; - - ASSERT_NO_THROW(sts = inferRequest->SetBlob(inputName.c_str(), inBlob, &dsc)); - ASSERT_EQ(StatusCode::NOT_ALLOCATED, sts); - ASSERT_TRUE(std::string{dsc.msg}.find(refError) != std::string::npos) - << "\tExpected: " << refError - << "\n\tActual: " << dsc.msg; + try { + inferRequest->SetBlob(inputName, inBlob); + } catch(InferenceEngine::NotAllocated& ex) { + ASSERT_TRUE(std::string{ex.what()}.find(refError) != std::string::npos) + << "\tExpected: " << refError + << "\n\tActual: " << ex.what(); + } } TEST_F(InferenceEnginePluginInternalTest, failToSetEmptyBlob) { Blob::Ptr inBlob; string inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; std::string refError = "[ NOT_ALLOCATED ] Failed to set empty blob with name: \'" + inputName + "\'"; - IInferRequest::Ptr inferRequest; + IInferRequestInternal::Ptr inferRequest; getInferRequestWithMockImplInside(inferRequest); - - ASSERT_NO_THROW(sts = inferRequest->SetBlob(inputName.c_str(), inBlob, &dsc)); - ASSERT_EQ(StatusCode::NOT_ALLOCATED, sts); - ASSERT_TRUE(std::string{dsc.msg}.find(refError) != std::string::npos) - << "\tExpected: " << refError - << "\n\tActual: " << dsc.msg; + try { + inferRequest->SetBlob(inputName, inBlob); + } catch(InferenceEngine::NotAllocated& ex) { + ASSERT_TRUE(std::string{ex.what()}.find(refError) != std::string::npos) + << "\tExpected: " << refError + << "\n\tActual: " << ex.what(); + } } TEST_F(InferenceEnginePluginInternalTest, failToSetNotAllocatedBlob) { string inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; std::string refError = "[ NOT_ALLOCATED ] Input data was not allocated. Input name: \'" + inputName + "\'"; - IInferRequest::Ptr inferRequest; + IInferRequestInternal::Ptr inferRequest; getInferRequestWithMockImplInside(inferRequest); Blob::Ptr blob = make_shared_blob({ Precision::FP32, {}, NCHW }); - - ASSERT_NO_THROW(sts = inferRequest->SetBlob(inputName.c_str(), blob, &dsc)); - ASSERT_EQ(StatusCode::NOT_ALLOCATED, sts); - ASSERT_TRUE(std::string{dsc.msg}.find(refError) != std::string::npos) - << "\tExpected: " << refError - << "\n\tActual: " << dsc.msg; + try { + inferRequest->SetBlob(inputName, blob); + } catch(InferenceEngine::NotAllocated& ex) { + ASSERT_TRUE(std::string{ex.what()}.find(refError) != std::string::npos) + << "\tExpected: " << refError + << "\n\tActual: " << ex.what(); + } } TEST_F(InferenceEnginePluginInternalTest, executableNetworkInternalExportsMagicAndName) { diff --git a/inference-engine/tests/unit/inference_engine/ie_exception_test.cpp b/inference-engine/tests/unit/inference_engine/ie_exception_test.cpp index f0440fd81d1..5a08a4f81a0 100644 --- a/inference-engine/tests/unit/inference_engine/ie_exception_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_exception_test.cpp @@ -58,15 +58,6 @@ TEST(ExceptionTests, ExceptionCanBeCaughtAsStandard) { ASSERT_THROW(IE_THROW(), std::exception); } -TEST(ExceptionTests, CanThrowStatusCode) { - try { - IE_THROW(InferNotStarted); - } - catch (const InferenceEngine::InferNotStarted& iex) { - ASSERT_EQ(InferenceEngine::ExceptionToStatus(iex), InferenceEngine::StatusCode::INFER_NOT_STARTED); - } -} - #ifdef NDEBUG // disabled for debug as macros calls assert() TEST(ExceptionTests, ExceptionWithAssertThrowsNothingIfTrue) { ASSERT_NO_THROW(IE_ASSERT(true) << "shouldn't assert if true"); diff --git a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp index d8bd5abce57..489fc8ab52a 100644 --- a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp @@ -39,31 +39,22 @@ class ExecutableNetworkTests : public ::testing::Test { protected: std::shared_ptr mockIExeNet; InferenceEngine::ExecutableNetwork exeNetwork; + MockIInferencePlugin* mockIPlugin; + InferencePlugin plugin; - struct TestPluginInternal : public MockIInferencePlugin { - TestPluginInternal(const std::shared_ptr& mockIExeNet_) : mockIExeNet{mockIExeNet_} {} - std::shared_ptr LoadNetwork(const CNNNetwork&, const std::map&) override { - return mockIExeNet; - } - QueryNetworkResult QueryNetwork(const CNNNetwork&, const std::map&) const override { - IE_THROW(NotImplemented); - } - std::shared_ptr mockIExeNet; - }; - struct TestPlugin : public InferenceEngine::InferencePlugin { - TestPlugin(std::shared_ptr mockIExeNet) : - InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{ - new TestPluginInternal{mockIExeNet}}} {} - }; virtual void TearDown() { mockIExeNet.reset(); exeNetwork = {}; + plugin = {}; } virtual void SetUp() { mockIExeNet = std::make_shared(); - exeNetwork = TestPlugin{mockIExeNet}.LoadNetwork({}, {}); + std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + ON_CALL(*mockIPluginPtr, LoadNetwork(_, _)).WillByDefault(Return(mockIExeNet)); + plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + exeNetwork = plugin.LoadNetwork({}, {}); } }; @@ -126,7 +117,7 @@ IE_SUPPRESS_DEPRECATED_END class ExecutableNetworkWithIInferReqTests : public ExecutableNetworkTests { protected: - std::shared_ptr mockIInferReq_p; + std::shared_ptr mockIInferReq_p; virtual void TearDown() { ExecutableNetworkTests::TearDown(); @@ -135,7 +126,7 @@ protected: virtual void SetUp() { ExecutableNetworkTests::SetUp(); - mockIInferReq_p = std::make_shared(); + mockIInferReq_p = std::make_shared(); } }; @@ -143,7 +134,6 @@ TEST_F(ExecutableNetworkWithIInferReqTests, CanCreateInferRequest) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); InferRequest actualInferReq; ASSERT_NO_THROW(actualInferReq = exeNetwork.CreateInferRequest()); - ASSERT_EQ(mockIInferReq_p, static_cast(actualInferReq)); } TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfReturnNotOK) { @@ -153,16 +143,14 @@ TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfReturnNotO TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfSetRequestToNullptr) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()) - .WillOnce(Return(std::shared_ptr{})); + .WillOnce(Return(std::shared_ptr{})); ASSERT_THROW(exeNetwork.CreateInferRequest(), InferenceEngine::Exception); } // CreateInferRequestPtr TEST_F(ExecutableNetworkWithIInferReqTests, CanCreateInferRequestPtr) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); - InferRequest::Ptr actualInferReq; - ASSERT_NO_THROW(actualInferReq = exeNetwork.CreateInferRequestPtr()); - ASSERT_EQ(mockIInferReq_p, static_cast(*actualInferReq.get())); + ASSERT_NO_THROW(exeNetwork.CreateInferRequest()); } TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfReturnNotOK) { @@ -171,7 +159,7 @@ TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfReturnN } TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfSetRequestToNullptr) { - EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(std::shared_ptr{})); + EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(std::shared_ptr{})); ASSERT_THROW(exeNetwork.CreateInferRequestPtr(), InferenceEngine::Exception); } @@ -194,9 +182,10 @@ protected: // CreateInferRequest TEST_F(ExecutableNetworkBaseTests, canForwardCreateInferRequest) { + auto inferReqInternal = std::make_shared(); + EXPECT_CALL(*mock_impl.get(), CreateInferRequest()).Times(1).WillRepeatedly(Return(inferReqInternal)); IInferRequest::Ptr req; - EXPECT_CALL(*mock_impl.get(), CreateInferRequest()).Times(1).WillRepeatedly(Return(req)); - ASSERT_EQ(OK, exeNetwork->CreateInferRequest(req, &dsc)); + ASSERT_NO_THROW(exeNetwork->CreateInferRequest(req, &dsc)); } TEST_F(ExecutableNetworkBaseTests, canReportErrorInCreateInferRequest) { diff --git a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp index 38f0a877ba9..70f8c2d7ef0 100644 --- a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp +++ b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp @@ -18,6 +18,7 @@ #include "matchers/fill_with_data.hpp" #include "matchers/weights_matcher.hpp" #include +#include #include #include "gmock/gmock.h" diff --git a/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/structure/graph_structure_test.cpp b/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/structure/graph_structure_test.cpp index bdfc4d62633..80f894d0657 100644 --- a/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/structure/graph_structure_test.cpp +++ b/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/structure/graph_structure_test.cpp @@ -1202,7 +1202,7 @@ TEST_F(MKLDNNGraphStructureTests, TestOutputAfterInplacePlusConcat) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc(InferenceEngine::Precision::FP32, {1, 3, 2, 2}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src = InferenceEngine::make_shared_blob(desc); @@ -1211,8 +1211,7 @@ TEST_F(MKLDNNGraphStructureTests, TestOutputAfterInplacePlusConcat) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("data", src, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("data", src)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -1222,11 +1221,8 @@ TEST_F(MKLDNNGraphStructureTests, TestOutputAfterInplacePlusConcat) { output = InferenceEngine::make_shared_blob(item.second->getTensorDesc()); output->allocate(); - sts = inferRequest->SetBlob(item.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; - - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(item.first, output)); + ASSERT_NO_THROW(inferRequest->Infer()); compare(*output, *src); } @@ -1717,7 +1713,7 @@ TEST_F(MKLDNNGraphStructureTests, TestResnetPart) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc(InferenceEngine::Precision::FP32, {1, 3, 224, 224}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src = InferenceEngine::make_shared_blob(desc); @@ -1726,8 +1722,7 @@ TEST_F(MKLDNNGraphStructureTests, TestResnetPart) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("input", src, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("input", src)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -1737,18 +1732,16 @@ TEST_F(MKLDNNGraphStructureTests, TestResnetPart) { output = InferenceEngine::make_shared_blob(item.second->getTensorDesc()); output->allocate(); - sts = inferRequest->SetBlob(item.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(item.first.c_str(), output)); - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->Infer()); } TEST_F(MKLDNNGraphStructureTests, TestConcatAfterConcat) { std::string model = R"V0G0N( - + 1 @@ -1866,7 +1859,7 @@ TEST_F(MKLDNNGraphStructureTests, TestConcatAfterConcat) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc1(InferenceEngine::Precision::FP32, {1, 3, 20, 20}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src1 = InferenceEngine::make_shared_blob(desc1); @@ -1885,10 +1878,9 @@ TEST_F(MKLDNNGraphStructureTests, TestConcatAfterConcat) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("data1", src1, &resp); - sts = inferRequest->SetBlob("data2", src2, &resp); - sts = inferRequest->SetBlob("data3", src3, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("data1", src1)); + ASSERT_NO_THROW(inferRequest->SetBlob("data2", src2)); + ASSERT_NO_THROW(inferRequest->SetBlob("data3", src3)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -1898,11 +1890,9 @@ TEST_F(MKLDNNGraphStructureTests, TestConcatAfterConcat) { output = InferenceEngine::make_shared_blob(item.second->getTensorDesc()); output->allocate(); - sts = inferRequest->SetBlob(item.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(item.first, output)); - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->Infer()); // compare(*output, *src); } @@ -2046,7 +2036,7 @@ TEST_F(MKLDNNGraphStructureTests, Test2ConcatFromConcat) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc1(InferenceEngine::Precision::FP32, {1, 3, 2, 2}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src1 = InferenceEngine::make_shared_blob(desc1); @@ -2070,14 +2060,10 @@ TEST_F(MKLDNNGraphStructureTests, Test2ConcatFromConcat) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("data1", src1, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; - sts = inferRequest->SetBlob("data2", src2, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; - sts = inferRequest->SetBlob("data3", src3, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; - sts = inferRequest->SetBlob("data4", src4, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("data1", src1)); + ASSERT_NO_THROW(inferRequest->SetBlob("data2", src2)); + ASSERT_NO_THROW(inferRequest->SetBlob("data3", src3)); + ASSERT_NO_THROW(inferRequest->SetBlob("data4", src4)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -2127,12 +2113,10 @@ TEST_F(MKLDNNGraphStructureTests, Test2ConcatFromConcat) { } refOutputs.push_back(refOutput); - sts = inferRequest->SetBlob(it.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(it.first, output)); } - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->Infer()); for (size_t i = 0; i < outputs.size(); i++) { compare(*outputs[i], *refOutputs[i]); @@ -2376,7 +2360,7 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithConstLayer) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc1(InferenceEngine::Precision::FP32, {1, 3, 20, 20}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src1 = InferenceEngine::make_shared_blob(desc1); @@ -2385,8 +2369,7 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithConstLayer) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("data", src1, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("data", src1)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -2396,11 +2379,9 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithConstLayer) { output = InferenceEngine::make_shared_blob(item.second->getTensorDesc()); output->allocate(); - sts = inferRequest->SetBlob(item.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(item.first.c_str(), output)); - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->Infer()); } TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithEltwiseBeforeConcat) { @@ -2523,7 +2504,7 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithEltwiseBeforeConcat) { InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); execNetwork->setNetworkInputs(_networkInputs); execNetwork->setNetworkOutputs(_networkOutputs); - InferenceEngine::IInferRequest::Ptr inferRequest = execNetwork->CreateInferRequest(); + InferenceEngine::IInferRequestInternal::Ptr inferRequest = execNetwork->CreateInferRequest(); InferenceEngine::TensorDesc desc1(InferenceEngine::Precision::FP32, {1, 3, 20, 20}, InferenceEngine::NCHW); InferenceEngine::Blob::Ptr src1 = InferenceEngine::make_shared_blob(desc1); @@ -2535,8 +2516,7 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithEltwiseBeforeConcat) { InferenceEngine::ResponseDesc resp; - InferenceEngine::StatusCode sts = inferRequest->SetBlob("data", src1, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob("data", src1)); InferenceEngine::OutputsDataMap out = network.getOutputsInfo(); @@ -2546,11 +2526,9 @@ TEST_F(MKLDNNGraphStructureTests, TestLoadTopologyWithEltwiseBeforeConcat) { output = InferenceEngine::make_shared_blob(item.second->getTensorDesc()); output->allocate(); - sts = inferRequest->SetBlob(item.first.c_str(), output, &resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->SetBlob(item.first.c_str(), output)); - sts = inferRequest->Infer(&resp); - ASSERT_EQ(InferenceEngine::OK, sts) << resp.msg; + ASSERT_NO_THROW(inferRequest->Infer()); auto *res_ptr = output->buffer().as(); size_t res_size = output->size(); From a42ad606cb6fab9c2ff0eaf96b0ca0a9a93dcc3b Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 19 Apr 2021 17:01:11 +0300 Subject: [PATCH 07/78] Fixed unity build (#5309) --- .../cpp/ie_executable_network.cpp | 26 +++++++------- .../inference_engine/cpp/ie_infer_request.cpp | 36 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index d10cefbeeed..b671fdebecb 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -11,7 +11,7 @@ namespace InferenceEngine { -#define CALL_STATEMENT(...) \ +#define EXEC_NET_CALL_STATEMENT(...) \ if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ try { \ __VA_ARGS__; \ @@ -32,11 +32,11 @@ ExecutableNetwork::~ExecutableNetwork() { } ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { - CALL_STATEMENT(return _impl->GetOutputsInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetOutputsInfo()); } ConstInputsDataMap ExecutableNetwork::GetInputsInfo() const { - CALL_STATEMENT(return _impl->GetInputsInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetInputsInfo()); } void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { @@ -50,19 +50,19 @@ void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { } InferRequest ExecutableNetwork::CreateInferRequest() { - CALL_STATEMENT(return InferRequest{_impl->CreateInferRequest(), _so}); + EXEC_NET_CALL_STATEMENT(return InferRequest{_impl->CreateInferRequest(), _so}); } InferRequest::Ptr ExecutableNetwork::CreateInferRequestPtr() { - CALL_STATEMENT(return std::make_shared(InferRequest{_impl->CreateInferRequest(), _so})); + EXEC_NET_CALL_STATEMENT(return std::make_shared(InferRequest{_impl->CreateInferRequest(), _so})); } void ExecutableNetwork::Export(const std::string& modelFileName) { - CALL_STATEMENT(return _impl->Export(modelFileName)); + EXEC_NET_CALL_STATEMENT(return _impl->Export(modelFileName)); } void ExecutableNetwork::Export(std::ostream& networkModel) { - CALL_STATEMENT(return _impl->Export(networkModel)); + EXEC_NET_CALL_STATEMENT(return _impl->Export(networkModel)); } ExecutableNetwork::operator IExecutableNetwork::Ptr() { @@ -71,13 +71,13 @@ ExecutableNetwork::operator IExecutableNetwork::Ptr() { CNNNetwork ExecutableNetwork::GetExecGraphInfo() { IE_SUPPRESS_DEPRECATED_START - CALL_STATEMENT(return _impl->GetExecGraphInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetExecGraphInfo()); } IE_SUPPRESS_DEPRECATED_START std::vector ExecutableNetwork::QueryState() { std::vector controller; - CALL_STATEMENT( + EXEC_NET_CALL_STATEMENT( for (auto&& state : _impl->QueryState()) { controller.emplace_back(std::make_shared(state), _so); }); @@ -86,19 +86,19 @@ std::vector ExecutableNetwork::QueryState() { IE_SUPPRESS_DEPRECATED_END void ExecutableNetwork::SetConfig(const std::map& config) { - CALL_STATEMENT(_impl->SetConfig(config)); + EXEC_NET_CALL_STATEMENT(_impl->SetConfig(config)); } Parameter ExecutableNetwork::GetConfig(const std::string& name) const { - CALL_STATEMENT(return _impl->GetConfig(name)); + EXEC_NET_CALL_STATEMENT(return _impl->GetConfig(name)); } Parameter ExecutableNetwork::GetMetric(const std::string& name) const { - CALL_STATEMENT(return _impl->GetMetric(name)); + EXEC_NET_CALL_STATEMENT(return _impl->GetMetric(name)); } RemoteContext::Ptr ExecutableNetwork::GetContext() const { - CALL_STATEMENT(return _impl->GetContext()); + EXEC_NET_CALL_STATEMENT(return _impl->GetContext()); } bool ExecutableNetwork::operator!() const noexcept { diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index 96454cf3bb5..7a56515402f 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -30,7 +30,7 @@ namespace InferenceEngine { CATCH_IE_EXCEPTION(NetworkNotRead) \ CATCH_IE_EXCEPTION(InferCancelled) -#define CALL_STATEMENT(...) \ +#define INFER_REQ_CALL_STATEMENT(...) \ if (_impl == nullptr) IE_THROW() << "Inference Requst is not initialized"; \ try { \ __VA_ARGS__ \ @@ -52,12 +52,12 @@ InferRequest::~InferRequest() { } void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) { - CALL_STATEMENT(_impl->SetBlob(name, data);) + INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data);) } Blob::Ptr InferRequest::GetBlob(const std::string& name) { Blob::Ptr blobPtr; - CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) + INFER_REQ_CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; const bool remoteBlobPassed = blobPtr->is(); if (blobPtr == nullptr) IE_THROW() << error; @@ -66,27 +66,27 @@ Blob::Ptr InferRequest::GetBlob(const std::string& name) { } void InferRequest::SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) { - CALL_STATEMENT(_impl->SetBlob(name, data, info);) + INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data, info);) } const PreProcessInfo& InferRequest::GetPreProcess(const std::string& name) const { - CALL_STATEMENT(return _impl->GetPreProcess(name);) + INFER_REQ_CALL_STATEMENT(return _impl->GetPreProcess(name);) } void InferRequest::Infer() { - CALL_STATEMENT(_impl->Infer();) + INFER_REQ_CALL_STATEMENT(_impl->Infer();) } void InferRequest::Cancel() { - CALL_STATEMENT(_impl->Cancel();) + INFER_REQ_CALL_STATEMENT(_impl->Cancel();) } std::map InferRequest::GetPerformanceCounts() const { - CALL_STATEMENT(return _impl->GetPerformanceCounts();) + INFER_REQ_CALL_STATEMENT(return _impl->GetPerformanceCounts();) } void InferRequest::SetInput(const BlobMap& inputs) { - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( for (auto&& input : inputs) { _impl->SetBlob(input.first, input.second); } @@ -94,7 +94,7 @@ void InferRequest::SetInput(const BlobMap& inputs) { } void InferRequest::SetOutput(const BlobMap& results) { - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( for (auto&& result : results) { _impl->SetBlob(result.first, result.second); } @@ -102,20 +102,20 @@ void InferRequest::SetOutput(const BlobMap& results) { } void InferRequest::SetBatch(const int batch) { - CALL_STATEMENT(_impl->SetBatch(batch);) + INFER_REQ_CALL_STATEMENT(_impl->SetBatch(batch);) } void InferRequest::StartAsync() { - CALL_STATEMENT(_impl->StartAsync();) + INFER_REQ_CALL_STATEMENT(_impl->StartAsync();) } StatusCode InferRequest::Wait(int64_t millis_timeout) { - CALL_STATEMENT(return _impl->Wait(millis_timeout);) + INFER_REQ_CALL_STATEMENT(return _impl->Wait(millis_timeout);) } void InferRequest::SetCompletionCallbackImpl(std::function callback) { - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( _impl->SetCallback([callback] (std::exception_ptr) { callback(); }); @@ -142,7 +142,7 @@ void InferRequest::SetCompletionCallbackImpl(std::function callback) { void InferRequest::SetCompletionCallbackImpl(std::function callback) { - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( auto weakThis = InferRequest{std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}, _so}; _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; @@ -163,7 +163,7 @@ void InferRequest::SetCompletionCallbackImpl(std::function{_impl.get(), [](IInferRequestInternal*){}}, _so}; _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; @@ -185,7 +185,7 @@ void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback c std::vector InferRequest::QueryState() { std::vector controller; - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( for (auto&& state : _impl->QueryState()) { controller.emplace_back(std::make_shared(state), _so); } @@ -194,7 +194,7 @@ std::vector InferRequest::QueryState() { } InferRequest::operator IInferRequest::Ptr () { - CALL_STATEMENT( + INFER_REQ_CALL_STATEMENT( return std::make_shared(_impl); ) } From 9488bb0b0064de5e2f0078e7ab5932055897f25e Mon Sep 17 00:00:00 2001 From: Yufei Wu Date: Mon, 19 Apr 2021 23:35:32 +0800 Subject: [PATCH 08/78] %~dp0 can't handle path which include Space (#5274) * %~dp0 can't handle path which include Space The default OpenVINO install directory is C:\\Program file(86)\\Intel\\..., which contains space. So when users run this script, the path is wrong. To handle this issue, I modify two part: one is the python_command, use a local var to store this path. The other is the errorlevel, just add double quotation marks * fix python_command path issue * delete unused blank line --- .../install_prerequisites/install_prerequisites.bat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/model-optimizer/install_prerequisites/install_prerequisites.bat b/model-optimizer/install_prerequisites/install_prerequisites.bat index ec6405372b3..ac756ad4905 100644 --- a/model-optimizer/install_prerequisites/install_prerequisites.bat +++ b/model-optimizer/install_prerequisites/install_prerequisites.bat @@ -70,7 +70,7 @@ IF /I "%1%" EQU "" ( pip3 install --user -r ..\requirements%postfix%.txt :: Chek MO version -set python_command='python %~dp0..\mo\utils\extract_release_version.py' +set python_command='python "%~dp0..\mo\utils\extract_release_version.py"' FOR /F "delims=" %%i IN (%python_command%) DO set mo_release_version=%%i IF "%mo_release_version%" == "None.None" ( set mo_is_custom="true" @@ -80,7 +80,7 @@ IF "%mo_release_version%" == "None.None" ( :: Check if existing IE Python bindings satisfy requirements set errorlevel= -python %~dp0..\mo\utils\find_ie_version.py +python "%~dp0..\mo\utils\find_ie_version.py" IF %errorlevel% EQU 0 goto ie_search_end :: Check if OV already installed via pip @@ -119,7 +119,7 @@ IF %errorlevel% NEQ 0 ( ) set errorlevel= -python %~dp0..\mo\utils\find_ie_version.py +python "%~dp0..\mo\utils\find_ie_version.py" IF %errorlevel% EQU 0 goto ie_search_end echo [ WARNING ] The installed OpenVINO ^(TM^) toolkit version %mo_release_version% does not work as expected. Uninstalling... @@ -137,7 +137,7 @@ IF %errorlevel% NEQ 0 ( ) set errorlevel= -python %~dp0..\mo\utils\find_ie_version.py +python "%~dp0..\mo\utils\find_ie_version.py" IF %errorlevel% EQU 0 goto ie_search_end echo [ WARNING ] The installed highest OpenVINO ^(TM^) toolkit version doesn't work as expected. Uninstalling... From 40eba6a2efa6218918b414659c9c321ab6c09db8 Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Mon, 19 Apr 2021 20:19:17 +0300 Subject: [PATCH 09/78] Feature/merge 2021 3 to master (#5307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Feature/azaytsev/cldnn doc fixes (#4600) * Legal fixes, removed the Generating docs section * Removed info regarding generating docs Co-authored-by: Trawinski, Dariusz * Feature/azaytsev/gna model link fixes (#4599) * Added info on DockerHub CI Framework * Feature/azaytsev/change layout (#3295) * Changes according to feedback comments * Replaced @ref's with html links * Fixed links, added a title page for installing from repos and images, fixed formatting issues * Added links * minor fix * Added DL Streamer to the list of components installed by default * Link fixes * Link fixes * ovms doc fix (#2988) * added OpenVINO Model Server * ovms doc fixes Co-authored-by: Trawinski, Dariusz * Updated openvino_docs.xml * Link Fixes Co-authored-by: Trawinski, Dariusz * Fix for broken CC in CPU plugin (#4595) * Azure CI: Add "ref: releases/2021/3" * Fixed clone rt info (#4597) * [.ci/azure] Enable CC build (#4619) * Formula fix (#4624) * Fixed transformation to pull constants into Loop body (cherry-pick of PR 4591) (#4607) * Cherry-pick of PR 4591 * Fixed typo * Moved a check into the parameter_unchanged_after_iteration function * Fixed KW hits (#4638) * [CPU] Supported ANY layout for inputs in inferRequest (#4621) * [.ci/azure] Add windows_conditional_compilation.yml (#4648) (#4655) * Fix for MKLDNN constant layers execution (#4642) * Fix for MKLDNN constant layers execution * Single mkldnn::engine for all MKLDNN graphs * Add workaround for control edges to support TF 2.4 RNN (#4634) Signed-off-by: Roman Kazantsev * Corrected PyYAML dependency (#4598) (#4620) 5.4.2 is absent on PyPI * [CPU] Statically analyzed issues. (#4637) * Docs api (#4657) * Updated API changes document * Comment for CVS-49440 * Add documentation on how to convert QuartzNet model (#4664) * Add documentation on how to convert QuartzNet model (#4422) * Add documentation on how to convert QuartzNet model * Apply review feedback * Small fix * Apply review feedback * Apply suggestions from code review Co-authored-by: Anastasiya Ageeva Co-authored-by: Anastasiya Ageeva * Add reference to file Co-authored-by: Anastasiya Ageeva * Fixed bug in assign elimination transformation. (#4644) * [doc] Updated PyPI support OSes (#4643) (#4662) * [doc] Updated PyPI support OSes (#4643) * Updated PyPI support OSes * Added python versions for win and mac * Update pypi-openvino-dev.md * Update pypi-openvino-dev.md * Update pypi-openvino-rt.md * Update pypi-openvino-dev.md Co-authored-by: Andrey Zaytsev * [IE][VPU]: Fix empty output of CTCGreedyDecoderSeqLen (#4653) * Allow the second output of CTCGreedyDecoderSeqLen to be nullptr in cases when it is not used but calculated in the Myriad plugin. In this case, parse the second output as FakeData * It is a cherry-pick of #4652 * Update the firmware to release version * [VPU] WA for Segmentation fault on dlclose() issue (#4645) * Document TensorFlow 2* Update: Layers Support and Remove Beta Status (#4474) (#4711) * Document TensorFlow 2* Update: Layers Support and Remove Beta Status Signed-off-by: Roman Kazantsev * Update documentation based on latest test results and feedback Signed-off-by: Roman Kazantsev * Remove ConvLSTM2D from supported layers list Signed-off-by: Roman Kazantsev * Document Dot layer without limitation Signed-off-by: Roman Kazantsev * Address feedback upon DenseFeatures and RNN operations Signed-off-by: Roman Kazantsev * Do a grammar correction Signed-off-by: Roman Kazantsev * Do a grammar correction based on feedback Signed-off-by: Roman Kazantsev * Updated nGraph custom op documentation (#4604) * Updated nGraph custom op documentation * Fixed comments * [IE CLDNN] Fix missing variable initializations and types (#4669) * Fix NormalizeL2 creation in QueryNetwork (cherry pick from master PR 4310) (#4651) * Updated documentation about the supported YOLOv3 model from ONNX (#4722) (#4726) * Restored folded Operations for QueryNetwork (#4685) * Restored folded Operations for QueryNetwork * Fixed comment * Add unfolded constant operations to supported layers map * Add STN to list of supported models (#4728) * Fix python API for Loop/TensorIterator/Assign/ReadValue operations * Catch std::except in fuzz tests (#4695) Fuzz tests must catch all expected exceptions from IE. IE is using C++ std library which may raise standard exceptions which IE pass through. * Docs update (#4626) * Updated latency case desc to cover multi-socket machines * updated opt guide a bit * avoiding '#' which is interpreted as ref * Update CPU.md * Update docs/optimization_guide/dldt_optimization_guide.md Co-authored-by: Alina Alborova * Update docs/optimization_guide/dldt_optimization_guide.md Co-authored-by: Alina Alborova * Update docs/optimization_guide/dldt_optimization_guide.md Co-authored-by: Alina Alborova * Update docs/optimization_guide/dldt_optimization_guide.md Co-authored-by: Alina Alborova * Update docs/optimization_guide/dldt_optimization_guide.md Co-authored-by: Alina Alborova Co-authored-by: Alina Alborova * Blocked dims hwc 2021/3 (#4729) * Fix for BlockedDims * Added test for HWC layout * [GNA] Update documentation regarding splits and concatenations support (#4740) * Added mo.py to wheel packages (#4731) * Inserted a disclaimer (#4760) * Fixed some klockwork issues in C API samples (#4767) * Feature/vpu doc fixes 2021 3 (#4635) * Documentation fixes and updates for VPU * minor correction * minor correction * Fixed links * updated supported layers list for vpu * [DOCS] added iname/oname (#4735) * [VPU] Limit dlclose() WA to be used for Ubuntu only (#4806) * Fixed wrong link (#4817) * MKLDNN weights cache key calculation algorithm changed (#4790) * Updated PIP install instructions (#4821) * Document YOLACT support (#4749) * Document YOLACT support * Add preprocessing section * Apply suggestions from code review Co-authored-by: Tatiana Savina Co-authored-by: Tatiana Savina * Add documentation on how to convert F3Net model (#4863) * Add instruction for F3Net model pytorch->onnx conversion * Fix style * Fixed dead lock in telemetry (#4873) * Fixed dead lock in telemetry * Refactored TelemetrySender.send function * Refactored send function implementation to avoid deadlocks * Unit tests for telemetry sender function * Added legal header * avladimi/cvs-31369: Documented packages content to YUM/APT IGs (#4839) * Documented runtime/dev packages content * Minor formatting fixes * Implemented review comments * Update installing-openvino-apt.md Co-authored-by: Andrey Zaytsev * [DOC] Low-Precision 8-bit Integer Inference (#4834) * [DOC] Low-Precision 8-bit Integer Inference * [DOC] Low-Precision 8-bit Integer Inference: comment fixes * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * Update docs/IE_DG/Int8Inference.md Co-authored-by: Anastasiya Ageeva * [DOC] LPT comments fix * [DOC] LPT comments fix: absolute links are updated to relative * Update Int8Inference.md * Update Int8Inference.md Co-authored-by: Anastasiya Ageeva Co-authored-by: Andrey Zaytsev * Avladimi/cherry pick from master (#4892) * Fixed CVS-48061 * Reviewed and edited the Customization instructions * Fixed broken links in the TOC * Fixed links * Fixed formatting in the IG for Raspberry * Feature/benchmarks 2021 3 (#4910) * added new topics, changed the intro text * updated * Updates * Updates * Updates * Updates * Updates * Added yolo-v4-tf and unet-camvid-onnx graphs * Date for pricing is updated to March 15th * Feature/omz link changes (#4911) * Changed labels for demos and model downloader * Changed links to models and tools * Changed links to models and tools * Changed links to demos * [cherry-pick] Extensibility docs review (#4915) * Feature/ovsa docs 2021 3 (#4914) * Updated to 2021-3, fixed formatting issues * Fixed formatting issues * Fixed formatting issues * Fixed formatting issues * Update ovsa_get_started.md * Clarification of Low Latency Transformation and State API documentation (#4877) * Assign/ReadValue, LowLatency and StateAPI clarifications * Apply suggestions from code review: spelling mistakes Co-authored-by: Anastasiya Ageeva * fixed wording * cherry-pick missing commit to release branch: low latency documentation * Resolve review remarks Co-authored-by: Anastasiya Ageeva Co-authored-by: Svetlana Dolinina * DevCloud call outs (#4904) * [README.md] change latest release to 2021.3 * [49342] Update recommended CMake version on install guide in documentation (#4763) * Inserted a disclaimer * Another disclaimer * Update installing-openvino-windows.md * Update installing-openvino-windows.md * Update installing-openvino-windows.md * Feature/doc fixes 2021 3 (#4971) * Made changes for CVS-50424 * Changes for CVS-49349 * Minor change for CVS-49349 * Changes for CVS-49343 * Cherry-pick #PR4254 * Replaced /opt/intel/openvino/ with /opt/intel/openvino_2021/ as the default target directory * (CVS-50786) Added a new section Reference IMplementations to keep Speech Library and Speech Recognition Demos * Doc fixes * Replaced links to inference_engine_intro.md with Deep_Learning_Inference_Engine_DevGuide.md, fixed links * Fixed link * Fixes * Fixes * Reemoved Intel® Xeon® processor E family * fixes for graphs (#5057) * compression.configs.hardware config to package_data (#5066) * update OpenCV version to 4.5.2 (#5069) * update OpenCV version to 4.5.2 * Enable mo.front.common.extractors module (#5038) * Enable mo.front.common.extractors module (#5018) * Enable mo.front.common.extractors module * Update package_BOM.txt * Test MO wheel content * fix doc iframe issue - 2021.3 (#5090) * wrap with htmlonly * wrap with htmlonly * Add specification for ExperimentalDetectron* oprations (#5128) * Feature/benchmarks 2021 3 ehl (#5191) * Added EHL config * Updated graphs * improve table formatting * Wrap +\endhtmlonly + +## Further Reading + +For more details on the Inference Engine API, refer to the [Integrating Inference Engine in Your Application](Integrate_with_customer_application_new_API.md) documentation. diff --git a/docs/IE_DG/Int8Inference.md b/docs/IE_DG/Int8Inference.md index 1443800f307..1f580bbd4e2 100644 --- a/docs/IE_DG/Int8Inference.md +++ b/docs/IE_DG/Int8Inference.md @@ -2,61 +2,18 @@ ## Disclaimer -Inference Engine with low-precision 8-bit integer inference requires the following prerequisites to be satisfied: -- Inference Engine [CPU Plugin](supported_plugins/CPU.md) must be built with the Intel® Math Kernel Library (Intel® MKL) dependency. In the Intel® Distribution of OpenVINO™ it is - satisfied by default, this is mostly the requirement if you are using OpenVINO™ available in open source, because [open source version of OpenVINO™](https://github.com/openvinotoolkit/openvino) can be built with OpenBLAS* that is unacceptable if you want to use 8-bit integer inference. -- Intel® platforms that support at least one extension to x86 instruction set from the following list: +Low-precision 8-bit inference is optimized for: +- Intel® architecture processors with the following instruction set architecture extensions: + - Intel® Advanced Vector Extensions 512 Vector Neural Network Instructions (Intel® AVX-512 VNNI) - Intel® Advanced Vector Extensions 512 (Intel® AVX-512) - Intel® Advanced Vector Extensions 2.0 (Intel® AVX2) - Intel® Streaming SIMD Extensions 4.2 (Intel® SSE4.2) -- A model must be quantized. To quantize the model, you can use the [Post-Training Optimization Tool](@ref pot_README) delivered with the Intel® Distribution of OpenVINO™ toolkit release package. - -The 8-bit inference feature was validated on the following topologies: -* **Classification models:** - * Caffe\* DenseNet-121, DenseNet-161, DenseNet-169, DenseNet-201 - * Caffe Inception v1, Inception v2, Inception v3, Inception v4 - * Caffe YOLO v1 tiny, YOLO v3 - * Caffe ResNet-50 v1, ResNet-101 v1, ResNet-152 v1, ResNet-269 v1 - * Caffe ResNet-18 - * Caffe MobileNet, MobileNet v2 - * Caffe SE ResNeXt-50 - * Caffe SqueezeNet v1.0, SqueezeNet v1.1 - * Caffe VGG16, VGG19 - * TensorFlow\* DenseNet-121, DenseNet-169 - * TensorFlow Inception v1, Inception v2, Inception v3, Inception v4, Inception ResNet v2 - * TensorFlow Lite Inception v1, Inception v2, Inception v3, Inception v4, Inception ResNet v2 - * TensorFlow Lite MobileNet v1, MobileNet v2 - * TensorFlow MobileNet v1, MobileNet v2 - * TensorFlow ResNet-50 v1.5, ResNet-50 v1, ResNet-101 v1, ResNet-152 v1, ResNet-50 v2, ResNet-101 v2, ResNet-152 v2 - * TensorFlow VGG16, VGG19 - * TensorFlow YOLO v3 - * MXNet\* CaffeNet - * MXNet DenseNet-121, DenseNet-161, DenseNet-169, DenseNet-201 - * MXNet Inception v3, inception_v4 - * MXNet Mobilenet, Mobilenet v2 - * MXNet ResNet-101 v1, ResNet-152 v1, ResNet-101 v2, ResNet-152 v2 - * MXNet ResNeXt-101 - * MXNet SqueezeNet v1.1 - * MXNet VGG16, VGG19 - - -* **Object detection models:** - * Caffe SSD GoogLeNet - * Caffe SSD MobileNet - * Caffe SSD SqueezeNet - * Caffe SSD VGG16 300, SSD VGG16 512 - * TensorFlow SSD MobileNet v1, SSD MobileNet v2 - * MXNet SSD Inception v3 512 - * MXNet SSD MobileNet 512 - * MXNet SSD ResNet-50 512 - * MXNet SSD VGG16 300 - * ONNX\* SSD ResNet 34 - -* **Semantic segmentation models:** - * Unet2D - -* **Recommendation system models:** - * NCF +- Intel® processor graphics: + - Intel® Iris® Xe Graphics + - Intel® Iris® Xe MAX Graphics +- A model must be quantized. You can use a quantized model from [OpenVINO™ Toolkit Intel's Pre-Trained Models](@ref omz_models_group_intel) or quantize a model yourself. For quantization, you can use the: + - [Post-Training Optimization Tool](@ref pot_README) delivered with the Intel® Distribution of OpenVINO™ toolkit release package. + - [Neural Network Compression Framework](https://www.intel.com/content/www/us/en/artificial-intelligence/posts/openvino-nncf.html) available on GitHub: https://github.com/openvinotoolkit/nncf ## Introduction @@ -65,63 +22,62 @@ A lot of investigation was made in the field of deep learning with the idea of u 8-bit computations (referred to as `int8`) offer better performance compared to the results of inference in higher precision (for example, `fp32`), because they allow loading more data into a single processor instruction. Usually the cost for significant boost is a reduced accuracy. However, it is proved that an accuracy drop can be negligible and depends on task requirements, so that the application engineer can set up the maximum accuracy drop that is acceptable. -Current Inference Engine solution for low-precision inference uses Intel MKL-DNN and supports inference of the following layers in 8-bit integer computation mode: -* Convolution -* FullyConnected -* ReLU -* ReLU6 -* Reshape -* Permute -* Pooling -* Squeeze -* Eltwise -* Concat -* Resample -* MVN -This means that 8-bit inference can only be performed with the CPU plugin on the layers listed above. All other layers are executed in the format supported by the CPU plugin: 32-bit floating point format (`fp32`). +Let's explore quantized [TensorFlow* implementation of ResNet-50](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/resnet-50-tf) model. Use [Model Downloader](@ref omz_tools_downloader) tool to download the `fp16` model from [OpenVINO™ Toolkit - Open Model Zoo repository](https://github.com/openvinotoolkit/open_model_zoo): +```sh +./downloader.py --name resnet-50-tf --precisions FP16-INT8 +``` +After that you should quantize model by [Model Quantizer](@ref omz_tools_downloader) tool. +```sh +./quantizer.py --model_dir public/resnet-50-tf --dataset_dir --precisions=FP16-INT8 +``` +The simplest way to infer the model and collect performance counters is [C++ Benchmark Application](../../inference-engine/samples/benchmark_app/README.md). +```sh +./benchmark_app -m resnet-50-tf.xml -d CPU -niter 1 -api sync -report_type average_counters -report_folder pc_report_dir +``` +If you infer the model in the OpenVINO™ CPU plugin and collect performance counters, all operations (except last not quantized SoftMax) are executed in INT8 precision. ## Low-Precision 8-bit Integer Inference Workflow -For 8-bit integer computations, a model must be quantized. If the model is not quantized then you can use the [Post-Training Optimization Tool](@ref pot_README) to quantize the model. The quantization process adds `FakeQuantize` layers on activations and weights for most layers. Read more about mathematical computations under the hood in the [white paper](https://intel.github.io/mkl-dnn/ex_int8_simplenet.html). +For 8-bit integer computations, a model must be quantized. Quantized models can be downloaded from [Overview of OpenVINO™ Toolkit Intel's Pre-Trained Models](@ref omz_models_group_intel). If the model is not quantized, you can use the [Post-Training Optimization Tool](@ref pot_README) to quantize the model. The quantization process adds [FakeQuantize](../ops/quantization/FakeQuantize_1.md) layers on activations and weights for most layers. Read more about mathematical computations in the [Uniform Quantization with Fine-Tuning](https://github.com/openvinotoolkit/nncf/blob/develop/docs/compression_algorithms/Quantization.md). 8-bit inference pipeline includes two stages (also refer to the figure below): -1. *Offline stage*, or *model quantization*. During this stage, `FakeQuantize` layers are added before most layers to have quantized tensors before layers in a way that low-precision accuracy drop for 8-bit integer inference satisfies the specified threshold. The output of this stage is a quantized model. Quantized model precision is not changed, quantized tensors are in original precision range (`fp32`). `FakeQuantize` layer has `Quantization Levels` attribute which defines quants count. Quants count defines precision which is used during inference. For `int8` range `Quantization Levels` attribute value has to be 255 or 256. +1. *Offline stage*, or *model quantization*. During this stage, [FakeQuantize](../ops/quantization/FakeQuantize_1.md) layers are added before most layers to have quantized tensors before layers in a way that low-precision accuracy drop for 8-bit integer inference satisfies the specified threshold. The output of this stage is a quantized model. Quantized model precision is not changed, quantized tensors are in original precision range (`fp32`). `FakeQuantize` layer has `levels` attribute which defines quants count. Quants count defines precision which is used during inference. For `int8` range `levels` attribute value has to be 255 or 256. To quantize the model, you can use the [Post-Training Optimization Tool](@ref pot_README) delivered with the Intel® Distribution of OpenVINO™ toolkit release package. + + When you pass the quantized IR to the OpenVINO™ plugin, the plugin automatically recognizes it as a quantized model and performs 8-bit inference. Note, if you pass a quantized model to another plugin that does not support 8-bit inference but supports all operations from the model, the model is inferred in precision that this plugin supports. + +2. *Run-time stage*. This stage is an internal procedure of the OpenVINO™ plugin. During this stage, the quantized model is loaded to the plugin. The plugin uses `Low Precision Transformation` component to update the model to infer it in low precision: + - Update `FakeQuantize` layers to have quantized output tensors in low precision range and add dequantization layers to compensate the update. Dequantization layers are pushed through as many layers as possible to have more layers in low precision. After that, most layers have quantized input tensors in low precision range and can be inferred in low precision. Ideally, dequantization layers should be fused in the next `FakeQuantize` layer. + - Weights are quantized and stored in `Constant` layers. -2. *Run-time stage*. This stage is an internal procedure of the [CPU Plugin](supported_plugins/CPU.md). During this stage, the quantized model is loaded to the plugin. The plugin updates each `FakeQuantize` layer on activations and weights to have `FakeQuantize` output tensor values in low precision range. ![int8_flow] -### Offline Stage: Model Quantization - -To infer a layer in low precision and get maximum performance, the input tensor for the layer has to be quantized and each value has to be in the target low precision range. For this purpose, `FakeQuantize` layer is used in the OpenVINO™ intermediate representation file (IR). To quantize the model, you can use the [Post-Training Optimization Tool](@ref pot_README) delivered with the Intel® Distribution of OpenVINO™ toolkit release package. - -When you pass the calibrated IR to the [CPU plugin](supported_plugins/CPU.md), the plugin automatically recognizes it as a quantized model and performs 8-bit inference. Note, if you pass a quantized model to another plugin that does not support 8-bit inference, the model is inferred in precision that this plugin supports. - -### Run-Time Stage: Quantization - -This is the second stage of the 8-bit integer inference. After you load the quantized model IR to a plugin, the pluing uses the `Low Precision Transformation` component to update the model to infer it in low precision: -* Updates `FakeQuantize` layers to have quantized output tensors in low precision range and add dequantization layers to compensate the update. Dequantization layers are pushed through as many layers as possible to have more layers in low precision. After that, most layers have quantized input tensors in low precision range and can be inferred in low precision. Ideally, dequantization layers should be fused in next `FakeQuantize` or `ScaleShift` layers. -* Weights are quantized and stored in `Const` layers. -* Biases are updated to avoid shifts in dequantization layers. - ## Performance Counters Information about layer precision is stored in the performance counters that are -available from the Inference Engine API. The layers have the following marks: -* Suffix `I8` for layers that had 8-bit data type input and were computed in 8-bit precision -* Suffix `FP32` for layers computed in 32-bit precision +available from the Inference Engine API. For example, the part of performance counters table for quantized [TensorFlow* implementation of ResNet-50](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/resnet-50-tf) model inference on [CPU Plugin](supported_plugins/CPU.md) looks as follows: -For example, the performance counters table for the Inception model can look as follows: -``` -inception_5b/5x5_reduce EXECUTED layerType: Convolution realTime: 417 cpu: 417 execType: gemm_blas_I8 -inception_5b/output EXECUTED layerType: Concat realTime: 34 cpu: 34 execType: ref_I8 -inception_5b/output_U8_nhw... EXECUTED layerType: Reorder realTime: 33092 cpu: 33092 execType: reorder_I8 -inception_5b/output_oScale... EXECUTED layerType: ScaleShift realTime: 1390 cpu: 1390 execType: jit_avx2_FP32 -inception_5b/output_oScale... EXECUTED layerType: Reorder realTime: 143 cpu: 143 execType: reorder_FP32 -inception_5b/pool EXECUTED layerType: Pooling realTime: 59301 cpu: 59301 execType: ref_any_I8 -``` +| layerName | execStatus | layerType | execType | realTime (ms) | cpuTime (ms) | +| --------------------------------------------------------- | ---------- | ------------ | -------------------- | ------------- | ------------ | +| resnet\_model/batch\_normalization\_15/FusedBatchNorm/Add | EXECUTED | Convolution | jit\_avx512\_1x1\_I8 | 0.377 | 0.377 | +| resnet\_model/conv2d\_16/Conv2D/fq\_input\_0 | NOT\_RUN | FakeQuantize | undef | 0 | 0 | +| resnet\_model/batch\_normalization\_16/FusedBatchNorm/Add | EXECUTED | Convolution | jit\_avx512\_I8 | 0.499 | 0.499 | +| resnet\_model/conv2d\_17/Conv2D/fq\_input\_0 | NOT\_RUN | FakeQuantize | undef | 0 | 0 | +| resnet\_model/batch\_normalization\_17/FusedBatchNorm/Add | EXECUTED | Convolution | jit\_avx512\_1x1\_I8 | 0.399 | 0.399 | +| resnet\_model/add\_4/fq\_input\_0 | NOT\_RUN | FakeQuantize | undef | 0 | 0 | +| resnet\_model/add\_4 | NOT\_RUN | Eltwise | undef | 0 | 0 | +| resnet\_model/add\_5/fq\_input\_1 | NOT\_RUN | FakeQuantize | undef | 0 | 0 | -The `execType` column of the table includes inference primitives with specific suffixes. -[int8_flow]: img/cpu_int8_flow.png \ No newline at end of file +> The `exeStatus` column of the table includes possible values: +> - `EXECUTED` - layer was executed by standalone primitive, +> - `NOT_RUN` - layer was not executed by standalone primitive or was fused with another operation and executed in another layer primitive. +> +> The `execType` column of the table includes inference primitives with specific suffixes. The layers have the following marks: +> * Suffix `I8` for layers that had 8-bit data type input and were computed in 8-bit precision +> * Suffix `FP32` for layers computed in 32-bit precision + +All `Convolution` layers are executed in int8 precision. Rest layers are fused into Convolutions using post operations optimization technique, which is described in [Internal CPU Plugin Optimizations](supported_plugins/CPU.md). + +[int8_flow]: img/cpu_int8_flow.png diff --git a/docs/IE_DG/Intro_to_Performance.md b/docs/IE_DG/Intro_to_Performance.md index 12913c5811c..6dbdd35cef4 100644 --- a/docs/IE_DG/Intro_to_Performance.md +++ b/docs/IE_DG/Intro_to_Performance.md @@ -29,7 +29,7 @@ Refer to the [Benchmark App](../../inference-engine/samples/benchmark_app/README ## Using Async API To gain better performance on accelerators, such as VPU, the Inference Engine uses the asynchronous approach (see [Integrating Inference Engine in Your Application (current API)](Integrate_with_customer_application_new_API.md)). -The point is amortizing the costs of data transfers, by pipe-lining, see [Async API explained](@ref omz_demos_object_detection_demo_ssd_async_README). +The point is amortizing the costs of data transfers, by pipe-lining, see [Async API explained](@ref omz_demos_object_detection_demo_cpp). Since the pipe-lining relies on the availability of the parallel slack, running multiple inference requests in parallel is essential. Refer to the [Benchmark App](../../inference-engine/samples/benchmark_app/README.md) sample, which enables running a number of inference requests in parallel. Specifying different number of request produces different throughput measurements. diff --git a/docs/IE_DG/Samples_Overview.md b/docs/IE_DG/Samples_Overview.md index b59d5a576ae..8243fc7f7d6 100644 --- a/docs/IE_DG/Samples_Overview.md +++ b/docs/IE_DG/Samples_Overview.md @@ -47,7 +47,7 @@ To run the sample applications, you can use images and videos from the media fil ## Samples that Support Pre-Trained Models -To run the sample, you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +To run the sample, you can use [public](@ref omz_models_group_public) or [Intel's](@ref omz_models_group_intel) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader). ## Build the Sample Applications @@ -209,7 +209,7 @@ vi /.bashrc 2. Add this line to the end of the file: ```sh -source /opt/intel/openvino/bin/setupvars.sh +source /opt/intel/openvino_2021/bin/setupvars.sh ``` 3. Save and close the file: press the **Esc** key, type `:wq` and press the **Enter** key. @@ -246,4 +246,4 @@ sample, read the sample documentation by clicking the sample name in the samples list above. ## See Also -* [Introduction to Inference Engine](inference_engine_intro.md) +* [Inference Engine Developer Guide](Deep_Learning_Inference_Engine_DevGuide.md) diff --git a/docs/IE_DG/ShapeInference.md b/docs/IE_DG/ShapeInference.md index ea86911ff39..93b27c621b5 100644 --- a/docs/IE_DG/ShapeInference.md +++ b/docs/IE_DG/ShapeInference.md @@ -66,8 +66,8 @@ Shape collision during shape propagation may be a sign that a new shape does not Changing the model input shape may result in intermediate operations shape collision. Examples of such operations: -- [`Reshape` operation](../ops/shape/Reshape_1.md) with a hard-coded output shape value -- [`MatMul` operation](../ops/matrix/MatMul_1.md) with the `Const` second input cannot be resized by spatial dimensions due to operation semantics +- [Reshape](../ops/shape/Reshape_1.md) operation with a hard-coded output shape value +- [MatMul](../ops/matrix/MatMul_1.md) operation with the `Const` second input cannot be resized by spatial dimensions due to operation semantics Model structure and logic should not change significantly after model reshaping. - The Global Pooling operation is commonly used to reduce output feature map of classification models output. @@ -100,7 +100,7 @@ Here is a code example: @snippet snippets/ShapeInference.cpp part0 -Shape Inference feature is used in [Smart classroom sample](@ref omz_demos_smart_classroom_demo_README). +Shape Inference feature is used in [Smart Classroom Demo](@ref omz_demos_smart_classroom_demo_cpp). ## Extensibility diff --git a/docs/IE_DG/Tools_Overview.md b/docs/IE_DG/Tools_Overview.md index 6600554785b..f0741105387 100644 --- a/docs/IE_DG/Tools_Overview.md +++ b/docs/IE_DG/Tools_Overview.md @@ -6,9 +6,9 @@ The OpenVINO™ toolkit installation includes the following tools: |Tool | Location in the Installation Directory| |-----------------------------------------------------------------------------|---------------------------------------| -|[Accuracy Checker Tool](@ref omz_tools_accuracy_checker_README) | `/deployment_tools/tools/open_model_zoo/tools/accuracy_checker`| +|[Accuracy Checker Tool](@ref omz_tools_accuracy_checker) | `/deployment_tools/tools/open_model_zoo/tools/accuracy_checker`| |[Post-Training Optimization Tool](@ref pot_README) | `/deployment_tools/tools/post_training_optimization_toolkit`| -|[Model Downloader](@ref omz_tools_downloader_README) | `/deployment_tools/tools/model_downloader`| +|[Model Downloader](@ref omz_tools_downloader) | `/deployment_tools/tools/model_downloader`| |[Cross Check Tool](../../inference-engine/tools/cross_check_tool/README.md) | `/deployment_tools/tools/cross_check_tool`| |[Compile Tool](../../inference-engine/tools/compile_tool/README.md) | `/deployment_tools/inference_engine/lib/intel64/`| diff --git a/docs/IE_DG/img/cpu_int8_flow.png b/docs/IE_DG/img/cpu_int8_flow.png index 130e54ceafa..794430126b2 100644 --- a/docs/IE_DG/img/cpu_int8_flow.png +++ b/docs/IE_DG/img/cpu_int8_flow.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3965f4830c45518ee1dc169c2b1760cae83f8a8819023770a28893c6cef558c2 -size 68441 +oid sha256:83bcd7888d3843ddfd9a601288627e98f5874290c00b9988bf1beac9209f2e8d +size 79741 diff --git a/docs/IE_DG/inference_engine_intro.md b/docs/IE_DG/inference_engine_intro.md index d23f168ba51..c262436d101 100644 --- a/docs/IE_DG/inference_engine_intro.md +++ b/docs/IE_DG/inference_engine_intro.md @@ -1,5 +1,11 @@ -Introduction to Inference Engine {#openvino_docs_IE_DG_inference_engine_intro} -================================ +# Introduction to Inference Engine {#openvino_docs_IE_DG_inference_engine_intro} + +> **NOTE:** [Intel® System Studio](https://software.intel.com/en-us/system-studio) is an all-in-one, cross-platform tool suite, purpose-built to simplify system bring-up and improve system and IoT device application performance on Intel® platforms. If you are using the Intel® Distribution of OpenVINO™ with Intel® System Studio, go to [Get Started with Intel® System Studio](https://software.intel.com/en-us/articles/get-started-with-openvino-and-intel-system-studio-2019). + +This Guide provides an overview of the Inference Engine describing the typical workflow for performing +inference of a pre-trained and optimized deep learning model and a set of sample applications. + +> **NOTE:** Before you perform inference with the Inference Engine, your models should be converted to the Inference Engine format using the Model Optimizer or built directly in run-time using nGraph API. To learn about how to use Model Optimizer, refer to the [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). To learn about the pre-trained and optimized models delivered with the OpenVINO™ toolkit, refer to [Pre-Trained Models](@ref omz_models_intel_index). After you have used the Model Optimizer to create an Intermediate Representation (IR), use the Inference Engine to infer the result for a given input data. diff --git a/docs/IE_DG/protecting_model_guide.md b/docs/IE_DG/protecting_model_guide.md index 2074d223014..78fe08b3318 100644 --- a/docs/IE_DG/protecting_model_guide.md +++ b/docs/IE_DG/protecting_model_guide.md @@ -58,5 +58,5 @@ should be called with `weights` passed as an empty `Blob`. - Model Optimizer Developer Guide: [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) - Inference Engine Developer Guide: [Inference Engine Developer Guide](Deep_Learning_Inference_Engine_DevGuide.md) - For more information on Sample Applications, see the [Inference Engine Samples Overview](Samples_Overview.md) -- For information on a set of pre-trained models, see the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index) +- For information on a set of pre-trained models, see the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel) - For IoT Libraries and Code Samples see the [Intel® IoT Developer Kit](https://github.com/intel-iot-devkit). diff --git a/docs/IE_DG/supported_plugins/MULTI.md b/docs/IE_DG/supported_plugins/MULTI.md index a6b4aaefc9f..f20443ca4c2 100644 --- a/docs/IE_DG/supported_plugins/MULTI.md +++ b/docs/IE_DG/supported_plugins/MULTI.md @@ -92,11 +92,20 @@ Notice that until R2 you had to calculate number of requests in your application Notice that every OpenVINO sample that supports "-d" (which stays for "device") command-line option transparently accepts the multi-device. The [Benchmark Application](../../../inference-engine/samples/benchmark_app/README.md) is the best reference to the optimal usage of the multi-device. As discussed multiple times earlier, you don't need to setup number of requests, CPU streams or threads as the application provides optimal out of the box performance. Below is example command-line to evaluate HDDL+GPU performance with that: -```bash -$ ./benchmark_app –d MULTI:HDDL,GPU –m -i -niter 1000 + +```sh +./benchmark_app –d MULTI:HDDL,GPU –m -i -niter 1000 ``` Notice that you can use the FP16 IR to work with multi-device (as CPU automatically upconverts it to the fp32) and rest of devices support it naturally. Also notice that no demos are (yet) fully optimized for the multi-device, by means of supporting the OPTIMAL_NUMBER_OF_INFER_REQUESTS metric, using the GPU streams/throttling, and so on. +## Video: MULTI Plugin +[![](https://img.youtube.com/vi/xbORYFEmrqU/0.jpg)](https://www.youtube.com/watch?v=xbORYFEmrqU) +\htmlonly + +\endhtmlonly + ## See Also * [Supported Devices](Supported_Devices.md) + + diff --git a/docs/IE_DG/supported_plugins/Supported_Devices.md b/docs/IE_DG/supported_plugins/Supported_Devices.md index c687e4ae602..514b4bd58a7 100644 --- a/docs/IE_DG/supported_plugins/Supported_Devices.md +++ b/docs/IE_DG/supported_plugins/Supported_Devices.md @@ -16,6 +16,8 @@ The Inference Engine provides unique capabilities to infer deep learning models |[Multi-Device plugin](MULTI.md) |Multi-Device plugin enables simultaneous inference of the same network on several Intel® devices in parallel | |[Heterogeneous plugin](HETERO.md) |Heterogeneous plugin enables automatic inference splitting between several Intel® devices (for example if a device doesn't [support certain layers](#supported-layers)). | +Devices similar to the ones we have used for benchmarking can be accessed using [Intel® DevCloud for the Edge](https://devcloud.intel.com/edge/), a remote development environment with access to Intel® hardware and the latest versions of the Intel® Distribution of the OpenVINO™ Toolkit. [Learn more](https://devcloud.intel.com/edge/get_started/devcloud/) or [Register here](https://inteliot.force.com/DevcloudForEdge/s/). + ## Supported Configurations The Inference Engine can inference models in different formats with various input and output formats. diff --git a/docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md b/docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md index 3b657f52a35..d21ab41bd5e 100644 --- a/docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md +++ b/docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md @@ -115,3 +115,22 @@ Model Optimizer produces an Intermediate Representation (IR) of the network, whi * [Known Issues](Known_Issues_Limitations.md) **Typical Next Step:** [Preparing and Optimizing your Trained Model with Model Optimizer](prepare_model/Prepare_Trained_Model.md) + +## Video: Model Optimizer Concept + +[![](https://img.youtube.com/vi/Kl1ptVb7aI8/0.jpg)](https://www.youtube.com/watch?v=Kl1ptVb7aI8) +\htmlonly + +\endhtmlonly + +## Video: Model Optimizer Basic Operation +[![](https://img.youtube.com/vi/BBt1rseDcy0/0.jpg)](https://www.youtube.com/watch?v=BBt1rseDcy0) +\htmlonly + +\endhtmlonly + +## Video: Choosing the Right Precision +[![](https://img.youtube.com/vi/RF8ypHyiKrY/0.jpg)](https://www.youtube.com/watch?v=RF8ypHyiKrY) +\htmlonly + +\endhtmlonly diff --git a/docs/MO_DG/prepare_model/convert_model/Convert_Model_From_TensorFlow.md b/docs/MO_DG/prepare_model/convert_model/Convert_Model_From_TensorFlow.md index 97f801bd06b..275b8e786d0 100644 --- a/docs/MO_DG/prepare_model/convert_model/Convert_Model_From_TensorFlow.md +++ b/docs/MO_DG/prepare_model/convert_model/Convert_Model_From_TensorFlow.md @@ -404,6 +404,11 @@ Refer to [Supported Framework Layers ](../Supported_Frameworks_Layers.md) for th The Model Optimizer provides explanatory messages if it is unable to run to completion due to issues like typographical errors, incorrectly used options, or other issues. The message describes the potential cause of the problem and gives a link to the [Model Optimizer FAQ](../Model_Optimizer_FAQ.md). The FAQ has instructions on how to resolve most issues. The FAQ also includes links to relevant sections in the Model Optimizer Developer Guide to help you understand what went wrong. +## Video: Converting a TensorFlow Model +[![](https://img.youtube.com/vi/QW6532LtiTc/0.jpg)](https://www.youtube.com/watch?v=QW6532LtiTc) +\htmlonly + +\endhtmlonly ## Summary In this document, you learned: diff --git a/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_Object_Detection_API_Models.md b/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_Object_Detection_API_Models.md index e2886e272e0..6683d6b9b8a 100644 --- a/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_Object_Detection_API_Models.md +++ b/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_Object_Detection_API_Models.md @@ -106,7 +106,7 @@ Models with `keep_aspect_ratio_resizer` were trained to recognize object in real Inference Engine comes with a number of samples that use Object Detection API models including: * [Object Detection for SSD Sample](../../../../../inference-engine/samples/object_detection_sample_ssd/README.md) --- for RFCN, SSD and Faster R-CNNs -* [Mask R-CNN Sample for TensorFlow* Object Detection API Models](@ref omz_demos_mask_rcnn_demo_README) --- for Mask R-CNNs +* [Mask R-CNN Sample for TensorFlow* Object Detection API Models](@ref omz_demos_mask_rcnn_demo_cpp) --- for Mask R-CNNs There are a number of important notes about feeding input images to the samples: @@ -1047,4 +1047,4 @@ The Mask R-CNN models are cut at the end with the sub-graph replacer `ObjectDete ```SecondStageBoxPredictor_1/Conv_3/BiasAdd|SecondStageBoxPredictor_1/Conv_1/BiasAdd``` -One of these two nodes produces output mask tensors. The child nodes of these nodes are related to post-processing which is implemented in the [Mask R-CNN demo](@ref omz_demos_mask_rcnn_demo_README) and should be cut off. +One of these two nodes produces output mask tensors. The child nodes of these nodes are related to post-processing which is implemented in the [Mask R-CNN demo](@ref omz_demos_mask_rcnn_demo_cpp) and should be cut off. diff --git a/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_YOLO_From_Tensorflow.md b/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_YOLO_From_Tensorflow.md index 99748b7b18f..109714dcea6 100644 --- a/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_YOLO_From_Tensorflow.md +++ b/docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_YOLO_From_Tensorflow.md @@ -110,7 +110,7 @@ where: > **NOTE:** The color channel order (RGB or BGR) of an input data should match the channel order of the model training dataset. If they are different, perform the `RGB<->BGR` conversion specifying the command-line parameter: `--reverse_input_channels`. Otherwise, inference results may be incorrect. For more information about the parameter, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../Converting_Model_General.md). -OpenVINO™ toolkit provides a demo that uses YOLOv3 model. For more information, refer to [Object Detection C++ Demo](@ref omz_demos_object_detection_demo_ssd_async_README). +OpenVINO™ toolkit provides a demo that uses YOLOv3 model. For more information, refer to [Object Detection C++ Demo](@ref omz_demos_object_detection_demo_cpp). ## Convert YOLOv1 and YOLOv2 Models to the IR diff --git a/docs/MO_DG/prepare_model/customize_model_optimizer/Customize_Model_Optimizer.md b/docs/MO_DG/prepare_model/customize_model_optimizer/Customize_Model_Optimizer.md index 73e439d83fe..99b4cd703c1 100644 --- a/docs/MO_DG/prepare_model/customize_model_optimizer/Customize_Model_Optimizer.md +++ b/docs/MO_DG/prepare_model/customize_model_optimizer/Customize_Model_Optimizer.md @@ -1,53 +1,53 @@ # Model Optimizer Extensibility {#openvino_docs_MO_DG_prepare_model_customize_model_optimizer_Customize_Model_Optimizer} -* [Model Representation in Memory](#model-representation-in-memory) -* [Model Conversion Pipeline](#model-conversion-pipeline) - * [Model Loading](#model-loading) - * [Operations Attributes Extracting](#operations-attributes-extracting) - * [Front Phase](#front-phase) - * [Partial Inference](#partial-inference) - * [Middle Phase](#middle-phase) - * [NHWC to NCHW Layout Change](#layout-change) - * [Back Phase](#back-phase) - * [Intermediate Representation Emitting](#ir-emitting) -* [Graph Traversal and Modification Using `Port`s and `Connection`s](#graph-ports-and-conneсtions) - * [Ports](#intro-ports) - * [Connections](#intro-connections) -* [Model Optimizer Extensions](#extensions) - * [Model Optimizer Operation](#extension-operation) - * [Operation Extractor](#operation-extractor) - * [Graph Transformation Extensions](#graph-transformations) - * [Front Phase Transformations](#front-phase-transformations) - * [Pattern-Defined Front Phase Transformations](#pattern-defined-front-phase-transformations) - * [Specific Operation Front Phase Transformations](#specific-operation-front-phase-transformations) - * [Generic Front Phase Transformations](#generic-front-phase-transformations) - * [Node Name Pattern Front Phase Transformations](#node-name-pattern-front-phase-transformations) - * [Front Phase Transformations Using Start and End Points](#start-end-points-front-phase-transformations) - * [Generic Front Phase Transformations Enabled with Transformations Configuration File](#generic-transformations-config-front-phase-transformations) - * [Middle Phase Transformations](#middle-phase-transformations) - * [Pattern-Defined Middle Phase Transformations](#pattern-defined-middle-phase-transformations) - * [Generic Middle Phase Transformations](#generic-middle-phase-transformations) - * [Back Phase Transformations](#back-phase-transformations) - * [Pattern-Defined Back Phase Transformations](#pattern-defined-back-phase-transformations) - * [Generic Back Phase Transformations](#generic-back-phase-transformations) +- Model Representation in Memory +- Model Conversion Pipeline + - Model Loading + - Operations Attributes Extracting + - Front Phase + - Partial Inference + - Middle Phase + - NHWC to NCHW Layout Change + - Back Phase + - Intermediate Representation Emitting +- Graph Traversal and Modification Using Ports and Connections + - Ports + - Connections +- Model Optimizer Extensions + - Model Optimizer Operation + - Operation Extractor + - Graph Transformation Extensions + - Front Phase Transformations + - Pattern-Defined Front Phase Transformations + - Specific Operation Front Phase Transformations + - Generic Front Phase Transformations + - Node Name Pattern Front Phase Transformations + - Front Phase Transformations Using Start and End Points + - Generic Front Phase Transformations Enabled with Transformations Configuration File + - Middle Phase Transformations + - Pattern-Defined Middle Phase Transformations + - Generic Middle Phase Transformations + - Back Phase Transformations + - Pattern-Defined Back Phase Transformations + - Generic Back Phase Transformations +- See Also -Model Optimizer extensibility mechanism allows to support new operations and custom transformations to generate the -optimized Intermediate Representation (IR) as described in the +Model Optimizer extensibility mechanism enables support of new operations and custom transformations to generate the +optimized intermediate representation (IR) as described in the [Deep Learning Network Intermediate Representation and Operation Sets in OpenVINO™](../../IR_and_opsets.md). This -mechanism is a core part of the Model Optimizer and the Model Optimizer uses it under the hood, so the Model Optimizer -itself is a huge set of examples on how to add custom logic to support your model. +mechanism is a core part of the Model Optimizer. The Model Optimizer itself uses it under the hood, being a huge set of examples on how to add custom logic to support your model. There are several cases when the customization is needed: * A model contains operation(s) not known for the Model Optimizer, but these operation(s) could be expressed as a -combination of supported operations. In this case a custom transformation should be implemented to replace unsupported +combination of supported operations. In this case, a custom transformation should be implemented to replace unsupported operation(s) with supported ones. -* A model contains sub-graph of operations which can be replaced with a smaller number of operations to get the better +* A model contains sub-graph of operations that can be replaced with a smaller number of operations to get the better performance. This example corresponds to so called fusing transformations. For example, replace a sub-graph performing the following calculation \f$x / (1.0 + e^{-(beta * x)})\f$ with a single operation of type [Swish](../../../ops/activation/Swish_4.md). -* A model contains a custom framework operation (the operation which is not a part of an official operation set of the -framework) which was developed using the framework extensibility mechanism. In this case the Model Optimizer should know +* A model contains a custom framework operation (the operation that is not a part of an official operation set of the +framework) that was developed using the framework extensibility mechanism. In this case, the Model Optimizer should know how to handle the operation and generate a corresponding section in an IR for it. It is necessary to figure out how the Model Optimizer represents a model in a memory and converts it to an IR before @@ -61,14 +61,13 @@ The model can be represented as a directed graph where nodes are operations and producer operation (node) to a consumer operation (node). Model Optimizer uses Python class `mo.graph.graph.Graph` instance to represent the computation graph in memory during -the model conversion. This class is inherited from `networkx.MultiDiGraph` class of the standard `networkx` Python +the model conversion. This class is inherited from the `networkx.MultiDiGraph` class of the standard `networkx` Python library and provides many convenient methods to traverse and modify the graph. Refer to the `mo/graph/graph.py` file for the examples. -Model Optimizer keeps all necessary information about the operation in a node attributes. Model Optimizer uses class -`mo.graph.graph.Node` defined in the `mo/graph/graph.py` file which is a wrapper on top of a `networkx` node attributes -dictionary and provides many convenient methods to work with the node. For example, the node `my_node` attribute with a -name `'my_attr'` can be retrieved from the node with the following code `my_node.my_attr` which is equivalent to obtaining +Model Optimizer keeps all necessary information about the operation in node attributes. Model Optimizer uses the `mo.graph.graph.Node` class defined in the `mo/graph/graph.py` file, which is a wrapper on top of a `networkx` node attributes +dictionary, and provides many convenient methods to work with the node. For example, the node `my_node` attribute with a +name `'my_attr'` can be retrieved from the node with the following code `my_node.my_attr`, which is equivalent to obtaining attribute with name `'my_attr'` in the `graph.node['my_node']` dictionary. Refer to the `mo/graph/graph.py` for the class implementation details. @@ -76,12 +75,12 @@ An operation may have several inputs and outputs. For example, operation [Split] two inputs: data to split and axis to split along, and variable number of outputs depending on a value of attribute `num_splits`. Each input data to the operation is passed to a specific operation **input port**. An operation produces an output data from an **output port**. Input and output ports are numbered from 0 independently. Model Optimizer uses -classes `mo.graph.port.Port` and `mo.graph.connection.Connection` which are useful abstraction to perform graph -modifications like nodes connecting/re-connecting and a graph traversing. These classes are widely used in the Model +classes `mo.graph.port.Port` and `mo.graph.connection.Connection`, which are useful abstraction to perform graph +modifications like nodes connecting/re-connecting and graph traversing. These classes are widely used in the Model Optimizer code so it is easy to find a lot of usage examples. There is no dedicated class corresponding to an edge, so low-level graph manipulation is needed to get access to -edge attributes if needed. Meanwhile most manipulations with nodes connections should be done with help of +edge attributes if needed. Meanwhile, most manipulations with nodes connections should be done with help of the `mo.graph.connection.Connection` and `mo.graph.port.Port` classes. Thus, low-level graph manipulation is error prone and is strongly not recommended. @@ -94,19 +93,19 @@ A model conversion pipeline can be represented with the following diagram: ![Model Conversion pipeline](../../../img/MO_conversion_pipeline.png) -Lets review each conversion step in details. +Each conversion step is reviewed in details below. ### Model Loading -Model Optimizer gets as input a trained model file. The model loader component of the Model Optimizer reads a model file +Model Optimizer gets a trained model file as an input. The model loader component of the Model Optimizer reads a model file using Python bindings provided with the framework and builds an in-memory representation of a computation graph. There is a separate loader for each supported framework. These loaders are implemented in the `extensions/load//loader.py` files of the Model Optimizer. -> **NOTE**: Model Optimizer uses a special parser for Caffe\* models built on top of `caffe.proto` file. In case of a +> **NOTE**: Model Optimizer uses a special parser for Caffe\* models built on top of the `caffe.proto` file. In case of a > model loading failure, the Model Optimizer throws an error and requests to prepare the parser that can read the model. > For more information on how to prepare the custom Caffe\* parser, refer to the [Model Optimizer Frequently Asked Questions #1](../Model_Optimizer_FAQ.md). -The result of a model loading step is a `Graph` object which can be depicted like in the following example: +The result of a model loading step is a `Graph` object, which can be depicted like in the following example: ![Graph After Load](../../../img/MO_graph_after_loader.png) @@ -114,16 +113,16 @@ Model Optimizer loader saves an operation instance framework description (usuall attribute usually with a name `pb` for each operation of an input model. It is important that this is a **framework-specific** description of an operation. This means that an operation, for example, [Convolution](../../../ops/convolution/Convolution_1.md) may be represented differently in, for example, Caffe\* and -TensorFlow\* frameworks but perform exactly the same calculations from a mathematical point of view. +TensorFlow\* frameworks but performs the same calculations from a mathematical point of view. -In the example above the "Operation 2" has one input and two outputs. The tensor produced from the output port 0 is +In the example above, the "Operation 2" has one input and two outputs. The tensor produced from the output port 0 is consumed with the "Operation 5" (the input port 0) and "Operation 3" (the input port 1). The tensor produced from the output port 1 is consumed with the "Operation 4" (the input port 0). Each edge has two attributes `in` and `out` containing the input port number of the consumer node and the output port -number of the producer node. These attribute describe the fact that nodes are operations consuming some input tensors +number of the producer node. These attributes describe the fact that nodes are operations consuming some input tensors and producing some output tensors. But nodes themselves are "black boxes" from the Model Optimizer perspective because -they don't contain required information about the operation they perform. +they do not contain required information about the operation they perform. ### Operations Attributes Extracting The next step is to parse framework-dependent operation representation saved in a node attribute and update the node @@ -159,22 +158,22 @@ document). Detailed list of common node attributes and their values is provided [Model Optimizer Operation](#extension-operation). ### Front Phase -Due to legacy reasons an user must specify shapes for all not fully-defined inputs of the model. In contrast, other -machine learning frameworks like TensorFlow\* let user create a model with undefined or partially defined input shapes. +For legacy reasons, you must specify shapes for all not fully-defined inputs of the model. In contrast, other +machine learning frameworks like TensorFlow\* let you create a model with undefined or partially defined input shapes. As an example, undefined dimension is marked with an integer value `-1` in a TensorFlow\* model or has some string name in an ONNX\* model. -During the front phase the Model Optimizer knows shape of the model inputs and constants only and does not know shapes +During the front phase, the Model Optimizer knows shape of the model inputs and constants only and does not know shapes (and even ranks) of the intermediate tensors. But information about shapes may not be needed to implement particular transformation. For example, the transformation `extensions/front/TopKNormalize.py` removes an attribute `k` from a `TopK` node and adds an input constant with the value `k`. The transformation is needed to convert a `TopK` operation -which comes from frameworks where a number of output elements is defined as an attribute of the operation to the -OpenVINO™ [TopK](../../../ops/sort/TopK_3.md) operation semantic which requires this value to be a separate input. +that comes from frameworks where a number of output elements is defined as an attribute of the operation to the +OpenVINO™ [TopK](../../../ops/sort/TopK_3.md) operation semantic, which requires this value to be a separate input. -It is important to mention that sometimes it seems like a transformation cannot be implemented during the front phase +It is important to mention that sometimes it seems like transformation cannot be implemented during the front phase because the actual values of inputs or shapes are needed. But in fact shapes or values manipulations can be implemented -using operations which are added to the graph. Consider the transformation -`extensions/front/onnx/flattenONNX_to_reshape.py` which replaces an ONNX\* operation +using operations that are added to the graph. Consider the +`extensions/front/onnx/flattenONNX_to_reshape.py` transformation, which replaces an ONNX\* operation [Flatten](https://github.com/onnx/onnx/blob/master/docs/Operators.md#Flatten) with a sub-graph of operations performing the following (for the case when `axis` is not equal to 0 and 1): @@ -185,14 +184,14 @@ the following (for the case when `axis` is not equal to 0 and 1): [Reshape](../../../ops/shape/Reshape_1.md) specification for an explanation of this value). 4. Use the concatenated value as the second input to the `Reshape` operation. -It is highly recommended to write shape-agnostic transformations to avoid model reshape-ability issues. Refer to +It is highly recommended that you write shape-agnostic transformations to avoid model reshape-ability issues. Refer to [Using Shape Inference](../../../IE_DG/ShapeInference.md) for more information related to the reshaping of a model. More information on how to develop front phase transformations and dedicated API description is provided in the [Front Phase Transformations](#front-phase-transformations). ### Partial Inference -Model Optimizer performs a partial inference of a model during a model conversion. This procedure includes output shapes +Model Optimizer performs a partial inference of a model during model conversion. This procedure includes output shapes calculation of all operations in a model and constant folding (value calculation for constant sub-graphs). The constant folding is needed for the shape inference because in some cases evaluation of constant sub-graph is needed to calculate output shapes. For example, the output shape for the [Reshape](../../../ops/shape/Reshape_1.md) operation may be @@ -213,22 +212,22 @@ files. > [Const](../../../ops/infrastructure/Constant_1.md) operations defined with respective operation attributes. Model Optimizer inserts "data" nodes to the computation graph before starting the partial inference phase. The data node -corresponds to the specific tensor produced with the operation. Each data node contains two attributes: `shape` -containing the shape of the tensor and `value` which may contain the actual value of the tensor. The value for a `value` +corresponds to the specific tensor produced with the operation. Each data node contains two attributes: `shape`, +containing the shape of the tensor, and `value`, which may contain the actual value of the tensor. The value for a `value` attribute is equal to `None` if this tensor value cannot be calculated. This happens in two cases: when a tensor value depends on a values passed to the [Parameter](../../../ops/infrastructure/Parameter_1.md) operation of a model or the Model Optimizer does not have value propagation implementation for the operation. -The graph before running the partial inference can be depicted like in the following example: +Before running partial inference, the graph can be depicted like in the following example: ![Graph Before Partial Inference](../../../img/MO_graph_before_partial_inference.png) The difference in a graph structure with a graph during the front phase is not only in the data nodes, but also in the -edge attributes. Note, that an `out` attribute is specified for edges **from operation** nodes only, while an `in` +edge attributes. Note that an `out` attribute is specified for edges **from operation** nodes only, while an `in` attribute is specified for edges **from data** nodes only. This corresponds to the fact that a tensor (data node) is produced from a specific output port of an operation and is consumed with a specific input port of an operation. Also, a unique data node is created for each output port of an operation and may be used as an input node for several -operation nodes, like the data node "data2_0" which is consumed with the input port 1 of the operation "Operation 3" and +operation nodes, like the data node "data2_0", which is consumed with the input port 1 of the operation "Operation 3" and input port 0 of the operation "Operation 5". Now consider how the Model Optimizer performs shape and value propagation. Model Optimizer performs graph nodes @@ -236,13 +235,13 @@ topological sort. An error message is thrown if a graph contains a cycle. Then s each node in the graph according to the topological order. Each node of the graph must have an attribute called `infer` with a shape inference function, which is a function with one parameter – an instance of the `Node` class. The `infer` attribute is usually set in the operation extractor or when a node is added in some transformation using the Model -Optimizer operation class inherited from `mo.pos.Op` class. Refer to the [Model Optimizer Operation](#extension-operation) +Optimizer operation class inherited from the `mo.pos.Op` class. Refer to the [Model Optimizer Operation](#extension-operation) and [Operation Extractor](#operation-extractor) for more information on how to specify a shape inference function. A shape inference function should calculate an operation (node) output shape(s) based on input shape(s) and operation (node) attribute(s) and update `shape` and optionally `value` attributes of the corresponding data node(s). A simplified example of the shape infer function for the [Reshape](../../../ops/shape/Reshape_1.md) operation (the full version is -available in the file `mo/ops/reshape.py`): +available in the `mo/ops/reshape.py` file): ```py @staticmethod @@ -273,12 +272,12 @@ them. > **NOTE**: There is a legacy approach to read data node attribute like `input_shape = op_node.in_node(0).shape` and > modify data nodes attributes like `op_node.out_node(0).shape = some_value`. This approach is still used in the Model -> Optimizer code but is not recommended. Instead use approach described in the [Ports](#intro-ports). +> Optimizer code but is not recommended. Instead, use the approach described in the [Ports](#intro-ports). ### Middle Phase -The middle phase starts after the partial inference. At this phase a graph contains data nodes and output shapes of all -operations in the graph have been calculated. Any transformation implemented at this stage must update `shape` -attribute for all newly added operations. It is highly recommended to use API desribed in the +The middle phase starts after partial inference. At this phase, a graph contains data nodes and output shapes of all +operations in the graph have been calculated. Any transformation implemented at this stage must update the `shape` +attribute for all newly added operations. It is highly recommended to use API described in the [Graph Traversal and Modification Using `Port`s and `Connection`s](#graph-ports-and-conneсtions) because modification of a graph using this API causes automatic re-inference of affected nodes as well as necessary data nodes creation. @@ -290,10 +289,10 @@ There are several middle transformations responsible for changing model layout f are triggered by default for TensorFlow\* models only because it is the only framework with Convolution operations in NHWC layout. -> **NOTE**: If a TensorFlow\* model is in NCHW layout then an user should specify `--disable_nhwc_to_nchw` command line +> **NOTE**: If a TensorFlow\* model is in NCHW layout, you should specify the `--disable_nhwc_to_nchw` command line > parameter to disable these transformations. -The layout change is a complex problem and detailed explanation of it is out of scope of this document. A very brief +The layout change is a complex problem and detailed explanation of it is out of this document scope. A very brief explanation of this process is provided below: 1. Model Optimizer changes output shapes of most of operations producing 4D and 5D (four dimensional and five @@ -313,11 +312,11 @@ Refer to the source code of these transformations for more details on how the la ### Back Phase The back phase starts after the layout change to NCHW. This phase contains mostly the following transformations: -1. Transformations which should be working with a graph in the NCHW layout and thus cannot be implemented in the middle +1. Transformations that should work with a graph in the NCHW layout and thus cannot be implemented in the middle phase. -2. Transformations which replace nodes corresponding to internal Model Optimizer operations with nodes corresponding to +2. Transformations that replace nodes corresponding to internal Model Optimizer operations with nodes corresponding to the [opset](@ref openvino_docs_ops_opset) operations. -3. Transformations which normalize operations inputs according to the specification. +3. Transformations that normalize operations inputs according to the specification. 4. Final optimization transformations. A graph structure during the back phase is the same as during the middle phase. There is no difference in writing middle @@ -330,30 +329,30 @@ More information on how to develop back transformations and dedicated API descri The last phase of a model conversion is the Intermediate Representation emitting. Model Optimizer performs the following steps: -1. Iterates over all operation nodes in the graph and checks that all nodes have attribute `type` set. This attribute -defines the operation type and used in the Inference Engine to instantiate proper operation from the +1. Iterates over all operation nodes in the graph and checks that all nodes have the `type` attribute set. This attribute +defines the operation type and is used in the Inference Engine to instantiate proper operation from the [opset](@ref openvino_docs_ops_opset) specified in the `version` attribute of the node. If some node does not have -attribute `type` or its values is equal to `None` then the Model Optimizer exits with an error. +attribute `type` or its values is equal to `None`, the Model Optimizer exits with an error. 2. Performs type inference of graph operations similar to the shape inference. Inferred data types are saved to a port attributes in the IR. 3. Performs topological sort of the graph and changes `id` attribute of all operation nodes to be sequential integer values starting from 0. 4. Saves all Constants values to the `.bin` file. Constants with the same value are shared among different operations. -5. Generates `.xml` file defining a graph structure. The information about operation inputs and outputs are prepared -uniformly for all operations regardless of their type. A list of attributes to be saved to an `.xml` file is defined +5. Generates an `.xml` file defining a graph structure. The information about operation inputs and outputs are prepared +uniformly for all operations regardless of their type. A list of attributes to be saved to the `.xml` file is defined with the `backend_attrs()` or `supported_attrs()` of the `Op` class used for a graph node instantiation. For more -information on how the operation attributes are saved to XML refer to the function `prepare_emit_ir()` in +information on how the operation attributes are saved to XML, refer to the function `prepare_emit_ir()` in the `mo/pipeline/common.py` file and [Model Optimizer Operation](#extension-operation). ## Graph Traversal and Modification Using `Port`s and `Connection`s There are three APIs for a graph traversal and transformation used in the Model Optimizer: -1. The API provided with the `networkx` Python library for the `networkx.MultiDiGraph` class which is the base class for +1. The API provided with the `networkx` Python library for the `networkx.MultiDiGraph` class, which is the base class for the `mo.graph.graph.Graph` object. Refer to the [Model Representation in Memory](#model-representation-in-memory) for more details. For example, the following methods belong to this API level: `graph.add_edges_from([list])`, `graph.add_node(x, attrs)`, `graph.out_edges(node_id)` etc where `graph` is a an instance of the `networkx.MultiDiGraph` class. **This is the lowest-level API and its usage should be avoided in the Model Optimizer transformations**. 2. The API built around the `mo.graph.graph.Node` class. The `Node` class is the primary class to work with graph nodes -and their attributes. **There are some `Node` class methods not recommended to use and some functions defined in the +and their attributes. **There are some `Node` class methods not recommended for use and some functions defined in the `mo.graph.graph` have been deprecated**. Examples of such methods and functions are: `node.in_node(y)`, `node.out_node(x)`, `node.get_outputs()`, `node.insert_node_after(n1, y)`, `create_edge(n1, n2)` etc. Refer to the `mo/graph/graph.py` for more details. @@ -364,24 +363,24 @@ Refer to the `mo/graph/graph.py` for more details. transformations and operations implementation**. The main benefit of using Model Optimizer Graph API is that it hides some internal implementation details (the fact that -the graph contains data nodes), provides API to perform safe and predictable graph manipulations and adds operation +the graph contains data nodes), provides API to perform safe and predictable graph manipulations, and adds operation semantic to the graph. This is achieved with introduction of concepts of ports and connections. This chapter is dedicated to the Model Optimizer Graph API and does not cover other two non-recommended APIs. ### Ports -An operation semantic describes how many inputs and outputs the operation have. For example, operations +An operation semantic describes how many inputs and outputs the operation has. For example, operations [Parameter](../../../ops/infrastructure/Parameter_1.md) and [Const](../../../ops/infrastructure/Constant_1.md) have no inputs and have one output, operation [ReLU](../../../ops/activation/ReLU_1.md) has one input and one output, operation [Split](../../../ops/movement/Split_1.md) has 2 inputs and variable number of outputs depending on the value of the attribute `num_splits`. Each operation node in the graph (an instance of the `Node` class) has 0 or more input and output ports (instances of -the `mo.graph.port.Port` class). `Port` object has several attributes: +the `mo.graph.port.Port` class). The `Port` object has several attributes: * `node` - the instance of the `Node` object the port belongs to. -* `idx` - the port number. Input and output ports are numbered independently starting from `0`. Thus operation +* `idx` - the port number. Input and output ports are numbered independently starting from `0`. Thus, operation [ReLU](../../../ops/activation/ReLU_1.md) has one input port (with index `0`) and one output port (with index `0`). * `type` - the type of the port. Could be equal to either `"in"` or `"out"`. -* `data` - the object which should be used to get attributes of the corresponding data node. This object has methods +* `data` - the object that should be used to get attributes of the corresponding data node. This object has methods `get_shape()` / `set_shape()` and `get_value()` / `set_value()` to get/set shape/value of the corresponding data node. For example, `in_port.data.get_shape()` returns an input shape of a tensor connected to input port `in_port` (`in_port.type == 'in'`), `out_port.data.get_value()` returns a value of a tensor produced from output port `out_port` @@ -398,42 +397,42 @@ input/output port. Attributes `in_ports_count` and `out_ports_count` of the `Op` class instance define default number of input and output ports to be created for the `Node` . However, additional input/output ports can be added using methods -`add_input_port()` and `add_output_port()`. Port also can be removed using `delete_input_port()` and +`add_input_port()` and `add_output_port()`. Port also can be removed using the `delete_input_port()` and `delete_output_port()` methods. -The `Port` class is just an abstraction which works with edges incoming/outgoing to/from a specific `Node` instance. For +The `Port` class is just an abstraction that works with edges incoming/outgoing to/from a specific `Node` instance. For example, output port with `idx = 1` corresponds to the outgoing edge of a node with an attribute `out = 1`, the input port with `idx = 2` corresponds to the incoming edge of a node with an attribute `in = 2`. -Consider an example of a graph part with 4 operation nodes "Op1", "Op2", "Op3" and "Op4" and a number of data nodes +Consider the example of a graph part with 4 operation nodes "Op1", "Op2", "Op3", and "Op4" and a number of data nodes depicted with light green boxes. ![Ports example 1](../../../img/MO_ports_example_1.png) Operation nodes have input ports (yellow squares) and output ports (light purple squares). Input port may not be connected. For example, the input port 2 of node "Op1" does not have incoming edge, while output port always has an -associated data node (after the partial inference when the data nodes are added to the graph) which may have no +associated data node (after the partial inference when the data nodes are added to the graph), which may have no consumers. Ports can be used to traverse a graph. The method `get_source()` of an input port returns an output port producing the -tensor the input port consumes. It is important that the method works the same during front, middle and back phases of a -model conversion even though the graph structure changes (there is no data nodes in the graph during the front phase). +tensor consumed by the input port. It is important that the method works the same during front, middle and back phases of a +model conversion even though the graph structure changes (there are no data nodes in the graph during the front phase). -Let's assume that there are 4 instances of `Node` object `op1, op2, op3` and `op4` corresponding to nodes "Op1", "Op2", -"Op3" and "Op4" correspondingly. The result of `op2.in_port(0).get_source()` and `op4.in_port(1).get_source()` is the +Let's assume that there are 4 instances of `Node` object `op1, op2, op3`, and `op4` corresponding to nodes "Op1", "Op2", +"Op3", and "Op4", respectively. The result of `op2.in_port(0).get_source()` and `op4.in_port(1).get_source()` is the same object `op1.out_port(1)` of type `Port`. The method `get_destination()` of an output port returns the input port of the node consuming this tensor. If there are -multiple consumers of this tensor then the error is raised. The method `get_destinations()` of an output port returns a +multiple consumers of this tensor, the error is raised. The method `get_destinations()` of an output port returns a list of input ports consuming the tensor. The method `disconnect()` removes a node incoming edge corresponding to the specific input port. The method removes several edges if it is applied during the front phase for a node output port connected with multiple nodes. The method `port.connect(another_port)` connects output port `port` and input port `another_port`. The method handles -situations when the graph contains data nodes (middle and back phases) and not just creates an edge between two nodes -but also automatically creates data node or re-uses existing data node. If the method is used during the front phase and -data nodes do not exist the method creates edge and properly sets `in` and `out` edge attributes. +situations when the graph contains data nodes (middle and back phases) and does not create an edge between two nodes +but also automatically creates data node or reuses existing data node. If the method is used during the front phase and +data nodes do not exist, the method creates edge and properly sets `in` and `out` edge attributes. For example, applying the following two methods to the graph above will result in the graph depicted below: @@ -454,16 +453,16 @@ and source output port producing data. So each port is connected with one or mor Model Optimizer uses the `mo.graph.connection.Connection` class to represent a connection. There is only one method `get_connection()` of the `Port` class to get the instance of the corresponding `Connection` -object. If the port is not connected then the returned value is `None`. +object. If the port is not connected, the returned value is `None`. -For example, the method `op3.out_port(0).get_connection()` returns a `Connection` object encapsulating edges from node +For example, the `op3.out_port(0).get_connection()` method returns a `Connection` object encapsulating edges from node "Op3" to data node "data_3_0" and two edges from data node "data_3_0" to two ports of the node "Op4". The `Connection` class provides methods to get source and destination(s) ports the connection corresponds to: * `connection.get_source()` - returns an output `Port` object producing the tensor. * `connection.get_destinations()` - returns a list of input `Port`s consuming the data. -* `connection.get_destination()` - returns a single input `Port` consuming the data. If there are multiple consumers -then the exception is raised. +* `connection.get_destination()` - returns a single input `Port` consuming the data. If there are multiple consumers, +the exception is raised. The `Connection` class provides methods to modify a graph by changing a source or destination(s) of a connection. For example, the function call `op3.out_port(0).get_connection().set_source(op1.out_port(0))` changes source port of edges @@ -472,22 +471,22 @@ below: ![Connection example 1](../../../img/MO_connection_example_1.png) -Another example is the method `connection.set_destination(dest_port)`. It disconnects `dest_port` and all input ports -the connection is currently connected to and connects the connection source port to the `dest_port`. +Another example is the method `connection.set_destination(dest_port)`. It disconnects `dest_port` and all input ports to which +the connection is currently connected and connects the connection source port to `dest_port`. -Note that connection work seamlessly during front, middle and back phases and hides the fact that the graph structure is +Note that connection works seamlessly during front, middle, and back phases and hides the fact that the graph structure is different. > **NOTE**: Refer to the `Connection` class implementation in the `mo/graph/connection.py` for a full list of available methods. ## Model Optimizer Extensions -Model Optimizer extensions allow to inject some logic to the model conversion pipeline without changing the Model +Model Optimizer extensions enable you to inject some logic to the model conversion pipeline without changing the Model Optimizer core code. There are three types of the Model Optimizer extensions: 1. Model Optimizer operation. 2. A framework operation extractor. -3. A model transformation which can be executed during front, middle or back phase of the model conversion. +3. A model transformation, which can be executed during front, middle or back phase of the model conversion. An extension is just a plain text file with a Python code. The file should contain a class (or classes) inherited from one of extension base classes. Extension files should be saved to a directory with the following structure: @@ -509,11 +508,11 @@ Model Optimizer uses the same layout internally to keep built-in extensions. The > **NOTE**: The name of a root directory with extensions should not be equal to "extensions" because it will result in a > name collision with the built-in Model Optimizer extensions. -> **NOTE**: Model Optimizer itself is built using these extensions so there are huge number of examples on how to use +> **NOTE**: Model Optimizer itself is built using these extensions so there is a huge number of examples on how to use > them in the Model Optimizer code. ### Model Optimizer Operation -Model Optimizer defines a class `mo.ops.Op` (`Op` will be used later in the document to be short) which is a base class +Model Optimizer defines a class `mo.ops.Op` (`Op` will be used later in the document to be short), which is a base class for an operation used in the Model Optimizer. The instance of the `Op` class serves several purposes: 1. Stores the operation attributes. @@ -525,7 +524,7 @@ graph. It is important to mention that there is no connection between the instance of the `Op` class and the `Node` object created from it. The `Op` class is just an attributes container describing the operation. Model Optimizer uses the `Op` -class during a model conversion to create node of the graph with attributes copied from the `Op` class instance. Graph +class during a model conversion to create a node of the graph with attributes copied from the `Op` class instance. Graph manipulations are performed with graph `Node`s and their attributes and does not involve `Op`s. There are a number of common attributes used in the operations. Here is the list of these attributes with description. @@ -536,19 +535,19 @@ There are a number of common attributes used in the operations. Here is the list * `type` — type of the operation according to the [opset specification](@ref openvino_docs_ops_opset). For the internal Model Optimizer operations this attribute should be set to `None`. The model conversion fails if an operation with `type` equal to `None` comes to the IR emitting phase. **Mandatory**. -* `version` — the operation set (opset) name the operation belongs to. If not specified then the Model Optimizer sets it +* `version` — the operation set (opset) name the operation belongs to. If not specified, the Model Optimizer sets it equal to `experimental`. Refer to [nGraph Basic Concepts](@ref openvino_docs_nGraph_DG_basic_concepts) for more information about operation sets. **Mandatory**. -* `op` — Model Optimizer type of the operation. In many cases the value of `type` is equal to the value of `op`. But -when the Model Optimizer cannot instantiate opset operation during model loading it creates an instance of an internal +* `op` — Model Optimizer type of the operation. In many cases, the value of `type` is equal to the value of `op`. But +when the Model Optimizer cannot instantiate the opset operation during model loading, it creates an instance of an internal operation and the attribute `op` is used as a type of this internal operation. Later in the pipeline the node created from an internal operation will be replaced during front, middle or back phase with node(s) created from the opset. * `infer` — the attribute defines a function calculating output tensor(s) shape and optionally value(s). The attribute may be set to `None` for internal Model Optimizer operations used during the front phase only. Refer to the [Partial Inference](#partial-inference) for more information about the shape inference function. * `type_infer` — the attribute defines a function calculating output tensor(s) data type. If the attribute is not -defined then the default function is used. The function checks if the node attribute `data_type` is set and then -propagates this type to the output tensor from the port 0, otherwise it propagates the data type of the tensor coming +defined, the default function is used. The function checks if the node attribute `data_type` is set and then +propagates this type to the output tensor from the port 0; otherwise, it propagates the data type of the tensor coming into the input port 0 to the output tensor from the port 0. * `in_ports_count` — default number of input ports to be created for the operation. Additional ports can be created or redundant ports can be removed using dedicated `Node` class API methods. @@ -556,7 +555,7 @@ redundant ports can be removed using dedicated `Node` class API methods. redundant ports can be removed using dedicated `Node` class API methods. Here is an example of the Model Optimizer class for the operation [SoftMax](../../../ops/activation/SoftMax_1.md) from -the file `mo/ops/softmax.py` with the in code comments. +the `mo/ops/softmax.py` file with the comments in code. ```py class Softmax(Op): @@ -564,7 +563,7 @@ class Softmax(Op): # "Op.get_op_class_by_name()" static method op = 'SoftMax' - # the operation works as an extractor by default. This is a legacy behaviour not recommended for using currently, + # the operation works as an extractor by default. This is a legacy behavior not recommended for use currently, # thus "enabled" class attribute is set to False. The recommended approach is to use dedicated extractor extension enabled = False @@ -611,14 +610,14 @@ example from the `mo/ops/pooling.py` file: ``` The `backend_attrs()` function returns a list of records. A record can be of one of the following formats: -1. A string defining the attribute to be saved to the IR. If the value of the attribute is `None` then the attribute is -not saved. Example of this case are `rounding_type` and `auto_pad`. +1. A string defining the attribute to be saved to the IR. If the value of the attribute is `None`, the attribute is +not saved. Examples of this case are `rounding_type` and `auto_pad`. 2. A tuple where the first element is a string defining the name of the attribute as it will appear in the IR and the second element is a function to produce the value for this attribute. The function gets an instance of the `Node` as the -only parameter and returns a string with the value to be saved to the IR. Example of this case are `strides`, `kernel`, +only parameter and returns a string with the value to be saved to the IR. Examples of this case are `strides`, `kernel`, `pads_begin` and `pads_end`. 3. A tuple where the first element is a string defining the name of the attribute as it will appear in the IR and the -second element is the name of tha `Node` attribute to get the value from. Example of this case are `pool-method` and +second element is the name of the `Node` attribute to get the value from. Examples of this case are `pool-method` and `exclude-pad`. ### Operation Extractor @@ -626,7 +625,7 @@ Model Optimizer runs specific extractor for each operation in the model during t [operations-attributes-extracting](#operations-attributes-extracting) for more information about this process. There are several types of Model Optimizer extractor extensions: -1. The generic one which is described in this section. +1. The generic one, which is described in this section. 2. The special extractor for Caffe\* models with Python layers. This kind of extractor is described in the [Extending the Model Optimizer with Caffe* Python Layers](Extending_Model_Optimizer_with_Caffe_Python_Layers.md). 3. The special extractor for MXNet\* models with custom operations. This kind of extractor is described in the @@ -634,9 +633,9 @@ There are several types of Model Optimizer extractor extensions: 4. The special extractor and fallback to Caffe\* for shape inference is described in the [Legacy Mode for Caffe* Custom Layers](Legacy_Mode_for_Caffe_Custom_Layers.md). -This chapter is focused on the option #1 which provides a generic mechanism for the operation extractor applicable for -all frameworks. Model Optimizer provides class `mo.front.extractor.FrontExtractorOp` as a base class to implement the -extractor. It has a class method `extract` which gets the only parameter `Node` which corresponds to the graph node to +This chapter is focused on the option #1, which provides a generic mechanism for the operation extractor applicable for +all frameworks. Model Optimizer provides the `mo.front.extractor.FrontExtractorOp` class as a base class to implement the +extractor. It has a class method `extract`, which gets the only parameter `Node`, which corresponds to the graph node to extract data from. The operation description in the original framework format is stored in the attribute `pb` of the node. The extractor goal is to parse this attribute and save necessary attributes to the corresponding node of the graph. Consider the extractor for the TensorFlow\* operation `Const` (refer to the file @@ -716,7 +715,7 @@ used to parse operation attributes encoded with a framework-specific representat A common practice is to use `update_node_stat()` method of the dedicated `Op` class to update the node attributes. This method does the following: -1. Sets values for common attributes like `op`, `type`, `infer`, `in_ports_count`, `out_ports_count`, `version` etc to +1. Sets values for common attributes like `op`, `type`, `infer`, `in_ports_count`, `out_ports_count`, `version` to values specific to the dedicated operation (`Const` operation in this case). 2. Uses methods `supported_attrs()` and `backend_attrs()` defined in the `Op` class to update specific node attribute `IE`. The IR emitter uses the value stored in the `IE` attribute to pre-process attribute values and save them to IR. @@ -728,11 +727,11 @@ these attributes are parsed from the particular instance of the operation. ### Graph Transformation Extensions Model Optimizer provides various base classes to implement [Front Phase Transformations](#front-phase-transformations), -[Middle Phase Transformations](#middle-phase-transformations) and [Back Phase Transformations](#back-phase-transformations). +[Middle Phase Transformations](#middle-phase-transformations), and [Back Phase Transformations](#back-phase-transformations). All classes have the following common class attributes and methods: 1. Attribute `enabled` specifies whether the transformation is enabled or not. The value can be changed during runtime to enable or disable execution of the transformation during a model conversion. Default value is `True`. -2. Attribute `id` specifies a unique transformation string identifier. This transformation identified can be used to +2. Attribute `id` specifies a unique transformation string identifier. This transformation identifier can be used to enable (disable) the transformation by setting environment variable `MO_ENABLED_TRANSFORMS` (`MO_DISABLED_TRANSFORMS`) with a comma separated list of `id`s. The environment variables override the value of the `enabled` attribute of the transformation. Instead of using `id` attribute value you can add fully defined class name to `MO_ENABLED_TRANSFORMS` @@ -747,21 +746,21 @@ graph cleanup removes nodes of the graph not reachable from the model inputs. De input(s) were changed during the transformation or developer can set this attribute manually in the transformation for the specific nodes. Default value is `False`. 5. Attribute `graph_condition` specifies a list of functions with one parameter -- `Graph` object. The transformation -is executed if and only if all functions return `True`. If the attribute is not set then no check is performed. -7. Method `run_before()` returns a list of transformation classes which this transformation should be executed before. -8. Method `run_after()` returns a list of transformation classes which this transformation should be executed after. +is executed if and only if all functions return `True`. If the attribute is not set, no check is performed. +1. Method `run_before()` returns a list of transformation classes which this transformation should be executed before. +2. Method `run_after()` returns a list of transformation classes which this transformation should be executed after. -> **NOTE**: Some of the transformation types have specific class attributes and methods which are explained in the +> **NOTE**: Some of the transformation types have specific class attributes and methods, which are explained in the > corresponding sections of this document. Model Optimizer builds a graph of dependencies between registered transformations and executes them in the topological -order. In order to execute the transformation during a proper model conversion phase the Model Optimizer defines several -anchor transformations which does nothing. All transformations are ordered with respect to these anchor transformations. +order. To execute the transformation during a proper model conversion phase, the Model Optimizer defines several +anchor transformations that do nothing. All transformations are ordered with respect to these anchor transformations. The diagram below shows anchor transformations, some of built-in transformations and dependencies between them: ![Transformations Graph](../../../img/MO_transformations_graph.png) -User defined transformations are executed after corresponding `Start` and before corresponding `Finish` anchor +User-defined transformations are executed after the corresponding `Start` and before the corresponding `Finish` anchor transformations by default (if `run_before()` and `run_after()` methods have not been overridden). > **NOTE**: The `PreMiddleStart` and `PostMiddleStart` anchors were introduced due to historical reasons to refactor @@ -801,10 +800,10 @@ works differently: The sub-graph pattern is defined in the `pattern()` function. This function should return a dictionary with two keys: `nodes` and `edges`: * The value for the `nodes` key is a list of tuples with two elements. - * The first element is an alias name for a node which will be used to define edges between nodes and in the + * The first element is an alias name for a node that will be used to define edges between nodes and in the transformation function. - * The second element is a dictionary with attributes. The key is a name of an attribute which should exist in the - node. The value for the attribute can be some specific value to match or a function which gets a single parameter - + * The second element is a dictionary with attributes. The key is a name of an attribute that should exist in the + node. The value for the attribute can be some specific value to match or a function that gets a single parameter - the attribute value from the node. The function should return the result of attribute comparison with a dedicated value. * The value for the `edges` key is a list of tuples with two or three elements. @@ -871,7 +870,7 @@ class MishFusion(FrontReplacementSubgraph): This type of transformation is implemented using `mo.front.common.replacement.FrontReplacementOp` as base class and works the following way. 1. Developer defines an operation type to trigger the transformation. -2. Model Optimizer search for all nodes in the graph with the attribute `op` equal to the specified value. +2. Model Optimizer searches for all nodes in the graph with the attribute `op` equal to the specified value. 3. Model Optimizer executes developer-defined function performing graph transformation for each instance of a matched node. Developer can override different functions in the base transformation class and the Model Optimizer works differently: @@ -921,7 +920,7 @@ class Pack(FrontReplacementOp): ``` ##### Generic Front Phase Transformations -Model Optimizer provides mechanism to implement generic front phase transformation. This type of transformation is +Model Optimizer provides a mechanism to implement generic front phase transformation. This type of transformation is implemented using `mo.front.common.replacement.FrontReplacementSubgraph` or `mo.front.common.replacement.FrontReplacementPattern` as base classes. The only condition to execute the transformation is to check that it is enabled. Then the Model Optimizer executes the method `find_and_replace_pattern(self, graph)` and @@ -968,7 +967,7 @@ class SqueezeNormalize(FrontReplacementPattern): 'attribute'.format(squeeze_node.soft_get('name'))) ``` -Refer to the `mo/front/common/replacement.py` for the implementation details on how these front phase transformations +Refer to `mo/front/common/replacement.py` for the implementation details on how these front phase transformations work. ##### Node Name Pattern Front Phase Transformations @@ -1104,10 +1103,10 @@ for more examples of this type of transformation. ##### Front Phase Transformations Using Start and End Points This type of transformation is implemented using `mo.front.tf.replacement.FrontReplacementFromConfigFileSubGraph` as a base class and works the following way. -1. Developer prepares a JSON configuration file which defines the sub-graph to match using two lists of node names: +1. Developer prepares a JSON configuration file that defines the sub-graph to match using two lists of node names: "start" and "end" nodes. -2. Model Optimizer executes developer-defined transformation **only** when an user specifies the path to the -configuration file using the command line parameter `--transformations_config`.Model Optimizer performs the following +2. Model Optimizer executes developer-defined transformation **only** when a user specifies the path to the +configuration file using the command line parameter `--transformations_config`. Model Optimizer performs the following steps to match the sub-graph: 1. Starts a graph traversal from every start node following the direction of the graph edges. The search stops in an end node or in case of a node without consumers. All visited nodes are added to the matched sub-graph. @@ -1115,9 +1114,9 @@ steps to match the sub-graph: "start" list. In this step the edges are traversed in the opposite edge direction. All newly visited nodes are added to the matched sub-graph. This step is needed to add nodes required for calculation values of internal nodes of the matched sub-graph. - 3. Checks that all "end" nodes were reached from "start" nodes. If no then exit with error. + 3. Checks that all "end" nodes were reached from "start" nodes. If no, exits with an error. 4. Check that there are no [Parameter](../../../ops/infrastructure/Parameter_1.md) operations among added nodes. If - they exist then the sub-graph depends on the inputs of the model. Such configuration is considered incorrect so the + they exist, the sub-graph depends on the inputs of the model. Such configuration is considered incorrect so the Model Optimizer exits with an error. This algorithm finds all nodes "between" start and end nodes and nodes needed for calculation of non-input nodes of the @@ -1160,7 +1159,7 @@ The example of a JSON configuration file for a transformation with start and end The format of the file is similar to the one provided as an example in the [Node Name Pattern Front Phase Transformations](#node-name-pattern-front-phase-transformations). There difference is in -the value of the `match_kind` parameter which should be equal to `points` and the format of the `instances` parameter +the value of the `match_kind` parameter, which should be equal to `points` and the format of the `instances` parameter which should be a dictionary with two keys `start_points` and `end_points` defining start and end node names correspondingly. @@ -1168,7 +1167,7 @@ correspondingly. > always equal to `true`. > **NOTE**: This sub-graph match algorithm has a limitation that each start node must have only one input. Therefore, it -> is not possible to specify, for example, [Convolution](../../../ops/convolution/Convolution_1.md) node as input +> is not possible to specify, for example, the [Convolution](../../../ops/convolution/Convolution_1.md) node as input > because it has two inputs: data tensor and tensor with weights. For other examples of transformations with points, please refer to the @@ -1259,7 +1258,7 @@ graph structure changes. Refer to the `extensions/middle/L2NormToNorm.py` for the example of a pattern-defined middle transformation. ##### Generic Middle Phase Transformations -Model Optimizer provides mechanism to implement generic middle phase transformations. This type of transformation is +Model Optimizer provides a mechanism to implement generic middle phase transformations. This type of transformation is implemented using `mo.middle.replacement.MiddleReplacementPattern` as a base class and works similarly to the [Generic Front Phase Transformations](#generic-front-phase-transformations). The only difference is that the transformation entry function name is `find_and_replace_pattern(self, graph: Graph)`. @@ -1290,7 +1289,7 @@ implemented using `mo.back.replacement.BackReplacementPattern` as a base class a Refer to the `extensions/back/GatherNormalizer.py` for the example of a such type of transformation. -## See Also +## See Also * [Deep Learning Network Intermediate Representation and Operation Sets in OpenVINO™](../../IR_and_opsets.md) * [Converting a Model to Intermediate Representation (IR)](../convert_model/Converting_Model.md) * [nGraph Basic Concepts](@ref openvino_docs_nGraph_DG_basic_concepts) diff --git a/docs/benchmarks/performance_benchmarks.md b/docs/benchmarks/performance_benchmarks.md index 169c83c9bea..7969b2929ff 100644 --- a/docs/benchmarks/performance_benchmarks.md +++ b/docs/benchmarks/performance_benchmarks.md @@ -1,261 +1,12 @@ -# Get a Deep Learning Model Performance Boost with Intel® Platforms {#openvino_docs_performance_benchmarks} +# Performance Benchmarks {#openvino_docs_performance_benchmarks} -## Increase Performance for Deep Learning Inference +The [Intel® Distribution of OpenVINO™ toolkit](https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html) helps accelerate deep learning inference across a variety of Intel® processors and accelerators. -The [Intel® Distribution of OpenVINO™ toolkit](https://software.intel.com/en-us/openvino-toolkit) helps accelerate deep learning inference across a variety of Intel® processors and accelerators. Rather than a one-size-fits-all solution, Intel offers a powerful portfolio of scalable hardware and software solutions, powered by the Intel® Distribution of OpenVINO™ toolkit, to meet the various performance, power, and price requirements of any use case. The benchmarks below demonstrate high performance gains on several public neural networks for a streamlined, quick deployment on **Intel® CPU and VPU** platforms. Use this data to help you decide which hardware is best for your applications and solutions, or to plan your AI workload on the Intel computing already included in your solutions. +The benchmarks below demonstrate high performance gains on several public neural networks on multiple Intel® CPUs, GPUs and VPUs covering a broad performance range. Use this data to help you decide which hardware is best for your applications and solutions, or to plan your AI workload on the Intel computing already included in your solutions. -Measuring inference performance involves many variables and is extremely use-case and application dependent. We use the below four parameters for measurements, which are key elements to consider for a successful deep learning inference application: +Use the links below to review the benchmarking results for each alternative: -1. **Throughput** - Measures the number of inferences delivered within a latency threshold. (for example, number of Frames Per Second - FPS). When deploying a system with deep learning inference, select the throughput that delivers the best trade-off between latency and power for the price and performance that meets your requirements. -2. **Value** - While throughput is important, what is more critical in edge AI deployments is the performance efficiency or performance-per-cost. Application performance in throughput per dollar of system cost is the best measure of value. -3. **Efficiency** - System power is a key consideration from the edge to the data center. When selecting deep learning solutions, power efficiency (throughput/watt) is a critical factor to consider. Intel designs provide excellent power efficiency for running deep learning workloads. -4. **Latency** - This measures the synchronous execution of inference requests and is reported in milliseconds. Each inference request (for example: preprocess, infer, postprocess) is allowed to complete before the next is started. This performance metric is relevant in usage scenarios where a single image input needs to be acted upon as soon as possible. An example would be the healthcare sector where medical personnel only request analysis of a single ultra sound scanning image or in real-time or near real-time applications for example an industrial robot's response to actions in its environment or obstacle avoidance for autonomous vehicles. +* [Intel® Distribution of OpenVINO™ toolkit Benchmark Results](performance_benchmarks_openvino.md) +* [OpenVINO™ Model Server Benchmark Results](performance_benchmarks_ovms.md) -\htmlonly - - - - - - - - - - -\endhtmlonly - - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - - -\htmlonly - -\endhtmlonly - -\htmlonly - -\endhtmlonly - - -## Platform Configurations - -Intel® Distribution of OpenVINO™ toolkit performance benchmark numbers are based on release 2021.2. - -Intel technologies’ features and benefits depend on system configuration and may require enabled hardware, software or service activation. Learn more at intel.com, or from the OEM or retailer. Performance results are based on testing as of December 9, 2020 and may not reflect all publicly available updates. See configuration disclosure for details. No product can be absolutely secure. - -Performance varies by use, configuration and other factors. Learn more at [www.intel.com/PerformanceIndex](https://www.intel.com/PerformanceIndex). - -Your costs and results may vary. - -© Intel Corporation. Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others. - -Intel optimizations, for Intel compilers or other products, may not optimize to the same degree for non-Intel products. - -Testing by Intel done on: see test date for each HW platform below. - -**CPU Inference Engines** - -| | Intel® Xeon® E-2124G | Intel® Xeon® W1290P | Intel® Xeon® Silver 4216R | -| ------------------------------- | ---------------------- | --------------------------- | ---------------------------- | -| Motherboard | ASUS* WS C246 PRO | ASUS* WS W480-ACE | Intel® Server Board S2600STB | -| CPU | Intel® Xeon® E-2124G CPU @ 3.40GHz | Intel® Xeon® W-1290P CPU @ 3.70GHz | Intel® Xeon® Silver 4216R CPU @ 2.20GHz | -| Hyper Threading | OFF | ON | ON | -| Turbo Setting | ON | ON | ON | -| Memory | 2 x 16 GB DDR4 2666MHz | 4 x 16 GB DDR4 @ 2666MHz |12 x 32 GB DDR4 2666MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.3.0-24-generic | -| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc. | Intel Corporation | -| BIOS Version | 0904 | 607 | SE5C620.86B.02.01.
0009.092820190230 | -| BIOS Release | April 12, 2019 | May 29, 2020 | September 28, 2019 | -| BIOS Settings | Select optimized default settings,
save & exit | Select optimized default settings,
save & exit | Select optimized default settings,
change power policy
to "performance",
save & exit | -| Batch size | 1 | 1 | 1 -| Precision | INT8 | INT8 | INT8 -| Number of concurrent inference requests | 4 | 5 | 32 -| Test Date | December 9, 2020 | December 9, 2020 | December 9, 2020 -| Power dissipation, TDP in Watt | [71](https://ark.intel.com/content/www/us/en/ark/products/134854/intel-xeon-e-2124g-processor-8m-cache-up-to-4-50-ghz.html#tab-blade-1-0-1) | [125](https://ark.intel.com/content/www/us/en/ark/products/199336/intel-xeon-w-1290p-processor-20m-cache-3-70-ghz.html) | [125](https://ark.intel.com/content/www/us/en/ark/products/193394/intel-xeon-silver-4216-processor-22m-cache-2-10-ghz.html#tab-blade-1-0-1) | -| CPU Price on September 29, 2020, USD
Prices may vary | [213](https://ark.intel.com/content/www/us/en/ark/products/134854/intel-xeon-e-2124g-processor-8m-cache-up-to-4-50-ghz.html) | [539](https://ark.intel.com/content/www/us/en/ark/products/199336/intel-xeon-w-1290p-processor-20m-cache-3-70-ghz.html) |[1,002](https://ark.intel.com/content/www/us/en/ark/products/193394/intel-xeon-silver-4216-processor-22m-cache-2-10-ghz.html) | - -**CPU Inference Engines (continue)** - -| | Intel® Xeon® Gold 5218T | Intel® Xeon® Platinum 8270 | -| ------------------------------- | ---------------------------- | ---------------------------- | -| Motherboard | Intel® Server Board S2600STB | Intel® Server Board S2600STB | -| CPU | Intel® Xeon® Gold 5218T CPU @ 2.10GHz | Intel® Xeon® Platinum 8270 CPU @ 2.70GHz | -| Hyper Threading | ON | ON | -| Turbo Setting | ON | ON | -| Memory | 12 x 32 GB DDR4 2666MHz | 12 x 32 GB DDR4 2933MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | -| BIOS Vendor | Intel Corporation | Intel Corporation | -| BIOS Version | SE5C620.86B.02.01.
0009.092820190230 | SE5C620.86B.02.01.
0009.092820190230 | -| BIOS Release | September 28, 2019 | September 28, 2019 | -| BIOS Settings | Select optimized default settings,
change power policy to "performance",
save & exit | Select optimized default settings,
change power policy to "performance",
save & exit | -| Batch size | 1 | 1 | -| Precision | INT8 | INT8 | -| Number of concurrent inference requests |32 | 52 | -| Test Date | December 9, 2020 | December 9, 2020 | -| Power dissipation, TDP in Watt | [105](https://ark.intel.com/content/www/us/en/ark/products/193953/intel-xeon-gold-5218t-processor-22m-cache-2-10-ghz.html#tab-blade-1-0-1) | [205](https://ark.intel.com/content/www/us/en/ark/products/192482/intel-xeon-platinum-8270-processor-35-75m-cache-2-70-ghz.html#tab-blade-1-0-1) | -| CPU Price on September 29, 2020, USD
Prices may vary | [1,349](https://ark.intel.com/content/www/us/en/ark/products/193953/intel-xeon-gold-5218t-processor-22m-cache-2-10-ghz.html) | [7,405](https://ark.intel.com/content/www/us/en/ark/products/192482/intel-xeon-platinum-8270-processor-35-75m-cache-2-70-ghz.html) | - - -**CPU Inference Engines (continue)** - -| | Intel® Core™ i7-8700T | Intel® Core™ i9-10920X | Intel® Core™ i9-10900TE
(iEi Flex BX210AI)| 11th Gen Intel® Core™ i7-1185G7 | -| -------------------- | ----------------------------------- |--------------------------------------| ---------------------------------------------|---------------------------------| -| Motherboard | GIGABYTE* Z370M DS3H-CF | ASUS* PRIME X299-A II | iEi / B595 | Intel Corporation
internal/Reference
Validation Platform | -| CPU | Intel® Core™ i7-8700T CPU @ 2.40GHz | Intel® Core™ i9-10920X CPU @ 3.50GHz | Intel® Core™ i9-10900TE CPU @ 1.80GHz | 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz | -| Hyper Threading | ON | ON | ON | ON | -| Turbo Setting | ON | ON | ON | ON | -| Memory | 4 x 16 GB DDR4 2400MHz | 4 x 16 GB DDR4 2666MHz | 2 x 8 GB DDR4 @ 2400MHz | 2 x 8 GB DDR4 3200MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.8.0-05-generic | 5.8.0-05-generic | -| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | American Megatrends Inc.* | Intel Corporation | -| BIOS Version | F11 | 505 | Z667AR10 | TGLSFWI1.R00.3425.
A00.2010162309 | -| BIOS Release | March 13, 2019 | December 17, 2019 | July 15, 2020 | October 16, 2020 | -| BIOS Settings | Select optimized default settings,
set OS type to "other",
save & exit | Default Settings | Default Settings | Default Settings | -| Batch size | 1 | 1 | 1 | 1 | -| Precision | INT8 | INT8 | INT8 | INT8 | -| Number of concurrent inference requests |4 | 24 | 5 | 4 | -| Test Date | December 9, 2020 | December 9, 2020 | December 9, 2020 | December 9, 2020 | -| Power dissipation, TDP in Watt | [35](https://ark.intel.com/content/www/us/en/ark/products/129948/intel-core-i7-8700t-processor-12m-cache-up-to-4-00-ghz.html#tab-blade-1-0-1) | [165](https://ark.intel.com/content/www/us/en/ark/products/198012/intel-core-i9-10920x-x-series-processor-19-25m-cache-3-50-ghz.html) | [35](https://ark.intel.com/content/www/us/en/ark/products/203901/intel-core-i9-10900te-processor-20m-cache-up-to-4-60-ghz.html) | [28](https://ark.intel.com/content/www/us/en/ark/products/208664/intel-core-i7-1185g7-processor-12m-cache-up-to-4-80-ghz-with-ipu.html#tab-blade-1-0-1) | -| CPU Price on September 29, 2020, USD
Prices may vary | [303](https://ark.intel.com/content/www/us/en/ark/products/129948/intel-core-i7-8700t-processor-12m-cache-up-to-4-00-ghz.html) | [700](https://ark.intel.com/content/www/us/en/ark/products/198012/intel-core-i9-10920x-x-series-processor-19-25m-cache-3-50-ghz.html) | [444](https://ark.intel.com/content/www/us/en/ark/products/203901/intel-core-i9-10900te-processor-20m-cache-up-to-4-60-ghz.html) | [426](https://ark.intel.com/content/www/us/en/ark/products/208664/intel-core-i7-1185g7-processor-12m-cache-up-to-4-80-ghz-with-ipu.html#tab-blade-1-0-0) | - - -**CPU Inference Engines (continue)** - -| | Intel® Core™ i5-8500 | Intel® Core™ i5-10500TE | Intel® Core™ i5-10500TE
(iEi Flex-BX210AI)| -| -------------------- | ---------------------------------- | ----------------------------------- |-------------------------------------- | -| Motherboard | ASUS* PRIME Z370-A | GIGABYTE* Z490 AORUS PRO AX | iEi / B595 | -| CPU | Intel® Core™ i5-8500 CPU @ 3.00GHz | Intel® Core™ i5-10500TE CPU @ 2.30GHz | Intel® Core™ i5-10500TE CPU @ 2.30GHz | -| Hyper Threading | OFF | ON | ON | -| Turbo Setting | ON | ON | ON | -| Memory | 2 x 16 GB DDR4 2666MHz | 2 x 16 GB DDR4 @ 2666MHz | 1 x 8 GB DDR4 @ 2400MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.3.0-24-generic | -| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | American Megatrends Inc.* | -| BIOS Version | 2401 | F3 | Z667AR10 | -| BIOS Release | July 12, 2019 | March 25, 2020 | July 17, 2020 | -| BIOS Settings | Select optimized default settings,
save & exit | Select optimized default settings,
set OS type to "other",
save & exit | Default Settings | -| Batch size | 1 | 1 | 1 | -| Precision | INT8 | INT8 | INT8 | -| Number of concurrent inference requests | 3 | 4 | 4 | -| Test Date | December 9, 2020 | December 9, 2020 | December 9, 2020 | -| Power dissipation, TDP in Watt | [65](https://ark.intel.com/content/www/us/en/ark/products/129939/intel-core-i5-8500-processor-9m-cache-up-to-4-10-ghz.html#tab-blade-1-0-1)| [35](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | [35](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | -| CPU Price on September 29, 2020, USD
Prices may vary | [192](https://ark.intel.com/content/www/us/en/ark/products/129939/intel-core-i5-8500-processor-9m-cache-up-to-4-10-ghz.html) | [195](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | [195](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | - - -**CPU Inference Engines (continue)** - -| | Intel Atom® x5-E3940 | Intel® Core™ i3-8100 | -| -------------------- | ---------------------------------- |----------------------------------- | -| Motherboard | | GIGABYTE* Z390 UD | -| CPU | Intel Atom® Processor E3940 @ 1.60GHz | Intel® Core™ i3-8100 CPU @ 3.60GHz | -| Hyper Threading | OFF | OFF | -| Turbo Setting | ON | OFF | -| Memory | 1 x 8 GB DDR3 1600MHz | 4 x 8 GB DDR4 2400MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | -| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | -| BIOS Version | 5.12 | F8 | -| BIOS Release | September 6, 2017 | May 24, 2019 | -| BIOS Settings | Default settings | Select optimized default settings,
set OS type to "other",
save & exit | -| Batch size | 1 | 1 | -| Precision | INT8 | INT8 | -| Number of concurrent inference requests | 4 | 4 | -| Test Date | December 9, 2020 | December 9, 2020 | -| Power dissipation, TDP in Watt | [9.5](https://ark.intel.com/content/www/us/en/ark/products/96485/intel-atom-x5-e3940-processor-2m-cache-up-to-1-80-ghz.html) | [65](https://ark.intel.com/content/www/us/en/ark/products/126688/intel-core-i3-8100-processor-6m-cache-3-60-ghz.html#tab-blade-1-0-1)| -| CPU Price on September 29, 2020, USD
Prices may vary | [34](https://ark.intel.com/content/www/us/en/ark/products/96485/intel-atom-x5-e3940-processor-2m-cache-up-to-1-80-ghz.html) | [117](https://ark.intel.com/content/www/us/en/ark/products/126688/intel-core-i3-8100-processor-6m-cache-3-60-ghz.html) | - - - -**Accelerator Inference Engines** - -| | Intel® Neural Compute Stick 2 | Intel® Vision Accelerator Design
with Intel® Movidius™ VPUs (Mustang-V100-MX8) | -| --------------------------------------- | ------------------------------------- | ------------------------------------- | -| VPU | 1 X Intel® Movidius™ Myriad™ X MA2485 | 8 X Intel® Movidius™ Myriad™ X MA2485 | -| Connection | USB 2.0/3.0 | PCIe X4 | -| Batch size | 1 | 1 | -| Precision | FP16 | FP16 | -| Number of concurrent inference requests | 4 | 32 | -| Power dissipation, TDP in Watt | 2.5 | [30](https://www.mouser.com/ProductDetail/IEI/MUSTANG-V100-MX8-R10?qs=u16ybLDytRaZtiUUvsd36w%3D%3D) | -| CPU Price, USD
Prices may vary | [69](https://ark.intel.com/content/www/us/en/ark/products/140109/intel-neural-compute-stick-2.html) (from December 9, 2020) | [214](https://www.arrow.com/en/products/mustang-v100-mx8-r10/iei-technology?gclid=Cj0KCQiA5bz-BRD-ARIsABjT4ng1v1apmxz3BVCPA-tdIsOwbEjTtqnmp_rQJGMfJ6Q2xTq6ADtf9OYaAhMUEALw_wcB) (from December 9, 2020) | -| Host Computer | Intel® Core™ i7 | Intel® Core™ i5 | -| Motherboard | ASUS* Z370-A II | Uzelinfo* / US-E1300 | -| CPU | Intel® Core™ i7-8700 CPU @ 3.20GHz | Intel® Core™ i5-6600 CPU @ 3.30GHz | -| Hyper Threading | ON | OFF | -| Turbo Setting | ON | ON | -| Memory | 4 x 16 GB DDR4 2666MHz | 2 x 16 GB DDR4 2400MHz | -| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | -| Kernel Version | 5.0.0-23-generic | 5.0.0-23-generic | -| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | -| BIOS Version | 411 | 5.12 | -| BIOS Release | September 21, 2018 | September 21, 2018 | -| Test Date | December 9, 2020 | December 9, 2020 | - -Please follow this link for more detailed configuration descriptions: [Configuration Details](https://docs.openvinotoolkit.org/resources/benchmark_files/system_configurations_2021.2.html) - -\htmlonly - -
-

-\endhtmlonly -Results may vary. For workloads and configurations visit: [www.intel.com/PerformanceIndex](https://www.intel.com/PerformanceIndex) and [Legal Information](../Legal_Information.md). -\htmlonly -

-
-\endhtmlonly +Performance for a particular application can also be evaluated virtually using [Intel® DevCloud for the Edge](https://devcloud.intel.com/edge/), a remote development environment with access to Intel® hardware and the latest versions of the Intel® Distribution of the OpenVINO™ Toolkit. [Learn more](https://devcloud.intel.com/edge/get_started/devcloud/) or [Register here](https://inteliot.force.com/DevcloudForEdge/s/). diff --git a/docs/benchmarks/performance_benchmarks_faq.md b/docs/benchmarks/performance_benchmarks_faq.md index 9b26dd57366..f48c3cf38fd 100644 --- a/docs/benchmarks/performance_benchmarks_faq.md +++ b/docs/benchmarks/performance_benchmarks_faq.md @@ -39,8 +39,10 @@ The image size used in the inference depends on the network being benchmarked. T | [squeezenet1.1-CF](https://github.com/opencv/open_model_zoo/tree/master/models/public/squeezenet1.1) | SqueezeNet_v1.1_ILSVRC-2012_Caffe | classification | 227x227 | | [ssd300-CF](https://github.com/opencv/open_model_zoo/tree/master/models/public/ssd300) | SSD (VGG-16)_VOC-2007_Caffe | object detection | 300x300 | | [yolo_v3-TF](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/yolo-v3-tf) | TF Keras YOLO v3 Modelset | object detection | 300x300 | +| [yolo_v4-TF](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/yolo-v4-tf) | Yolo-V4 TF | object detection | 608x608 | | [ssd_mobilenet_v1_coco-TF](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/ssd_mobilenet_v1_coco) | ssd_mobilenet_v1_coco | object detection | 300x300 | | [ssdlite_mobilenet_v2-TF](https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/ssdlite_mobilenet_v2) | ssd_mobilenet_v2 | object detection | 300x300 | +| [unet-camvid-onnx-0001](https://github.com/openvinotoolkit/open_model_zoo/blob/master/models/intel/unet-camvid-onnx-0001/description/unet-camvid-onnx-0001.md) | U-Net | semantic segmentation | 368x480 | #### 7. Where can I purchase the specific hardware used in the benchmarking? Intel partners with various vendors all over the world. Visit the [Intel® AI: In Production Partners & Solutions Catalog](https://www.intel.com/content/www/us/en/internet-of-things/ai-in-production/partners-solutions-catalog.html) for a list of Equipment Makers and the [Supported Devices](../IE_DG/supported_plugins/Supported_Devices.md) documentation. You can also remotely test and run models before purchasing any hardware by using [Intel® DevCloud for the Edge](http://devcloud.intel.com/edge/). diff --git a/docs/benchmarks/performance_benchmarks_openvino.md b/docs/benchmarks/performance_benchmarks_openvino.md new file mode 100644 index 00000000000..456f593db14 --- /dev/null +++ b/docs/benchmarks/performance_benchmarks_openvino.md @@ -0,0 +1,272 @@ +# Intel® Distribution of OpenVINO™ toolkit Benchmark Results {#openvino_docs_performance_benchmarks_openvino} + +This benchmark setup includes a single machine on which both the benchmark application and the OpenVINO™ installation reside. + +The benchmark application loads the Inference Engine (SW) at run time and executes inferences on the specified hardware inference engine, (CPU, GPU or VPU). The benchmark application measures the time spent on actual inferencing (excluding any pre or post processing) and then reports on the inferences per second (or Frames Per Second). For more information on the benchmark application, please also refer to the entry 5 of the [FAQ section](performance_benchmarks_faq.md). + +Devices similar to the ones we have used for benchmarking can be accessed using [Intel® DevCloud for the Edge](https://devcloud.intel.com/edge/), a remote development environment with access to Intel® hardware and the latest versions of the Intel® Distribution of the OpenVINO™ Toolkit. [Learn more](https://devcloud.intel.com/edge/get_started/devcloud/) or [Register here](https://inteliot.force.com/DevcloudForEdge/s/). + +Measuring inference performance involves many variables and is extremely use-case and application dependent. We use the below four parameters for measurements, which are key elements to consider for a successful deep learning inference application: + +- **Throughput** - Measures the number of inferences delivered within a latency threshold. (for example, number of Frames Per Second - FPS). When deploying a system with deep learning inference, select the throughput that delivers the best trade-off between latency and power for the price and performance that meets your requirements. +- **Value** - While throughput is important, what is more critical in edge AI deployments is the performance efficiency or performance-per-cost. Application performance in throughput per dollar of system cost is the best measure of value. +- **Efficiency** - System power is a key consideration from the edge to the data center. When selecting deep learning solutions, power efficiency (throughput/watt) is a critical factor to consider. Intel designs provide excellent power efficiency for running deep learning workloads. +- **Latency** - This measures the synchronous execution of inference requests and is reported in milliseconds. Each inference request (for example: preprocess, infer, postprocess) is allowed to complete before the next is started. This performance metric is relevant in usage scenarios where a single image input needs to be acted upon as soon as possible. An example would be the healthcare sector where medical personnel only request analysis of a single ultra sound scanning image or in real-time or near real-time applications for example an industrial robot's response to actions in its environment or obstacle avoidance for autonomous vehicles. + + +\htmlonly + + + + + + + + + + +\endhtmlonly + + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + +\htmlonly + +\endhtmlonly + + +## Platform Configurations + +Intel® Distribution of OpenVINO™ toolkit performance benchmark numbers are based on release 2021.3. + +Intel technologies’ features and benefits depend on system configuration and may require enabled hardware, software or service activation. Learn more at intel.com, or from the OEM or retailer. Performance results are based on testing as of March 15, 2021 and may not reflect all publicly available updates. See configuration disclosure for details. No product can be absolutely secure. + +Performance varies by use, configuration and other factors. Learn more at [www.intel.com/PerformanceIndex](https://www.intel.com/PerformanceIndex). + +Your costs and results may vary. + +© Intel Corporation. Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others. + +Intel optimizations, for Intel compilers or other products, may not optimize to the same degree for non-Intel products. + +Testing by Intel done on: see test date for each HW platform below. + +**CPU Inference Engines** + +| | Intel® Xeon® E-2124G | Intel® Xeon® W1290P | Intel® Xeon® Silver 4216R | +| ------------------------------- | ---------------------- | --------------------------- | ---------------------------- | +| Motherboard | ASUS* WS C246 PRO | ASUS* WS W480-ACE | Intel® Server Board S2600STB | +| CPU | Intel® Xeon® E-2124G CPU @ 3.40GHz | Intel® Xeon® W-1290P CPU @ 3.70GHz | Intel® Xeon® Silver 4216R CPU @ 2.20GHz | +| Hyper Threading | OFF | ON | ON | +| Turbo Setting | ON | ON | ON | +| Memory | 2 x 16 GB DDR4 2666MHz | 4 x 16 GB DDR4 @ 2666MHz |12 x 32 GB DDR4 2666MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.3.0-24-generic | +| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc. | Intel Corporation | +| BIOS Version | 0904 | 607 | SE5C620.86B.02.01.
0009.092820190230 | +| BIOS Release | April 12, 2019 | May 29, 2020 | September 28, 2019 | +| BIOS Settings | Select optimized default settings,
save & exit | Select optimized default settings,
save & exit | Select optimized default settings,
change power policy
to "performance",
save & exit | +| Batch size | 1 | 1 | 1 +| Precision | INT8 | INT8 | INT8 +| Number of concurrent inference requests | 4 | 5 | 32 +| Test Date | March 15, 2021 | March 15, 2021 | March 15, 2021 +| Power dissipation, TDP in Watt | [71](https://ark.intel.com/content/www/us/en/ark/products/134854/intel-xeon-e-2124g-processor-8m-cache-up-to-4-50-ghz.html#tab-blade-1-0-1) | [125](https://ark.intel.com/content/www/us/en/ark/products/199336/intel-xeon-w-1290p-processor-20m-cache-3-70-ghz.html) | [125](https://ark.intel.com/content/www/us/en/ark/products/193394/intel-xeon-silver-4216-processor-22m-cache-2-10-ghz.html#tab-blade-1-0-1) | +| CPU Price on Mach 15th, 2021, USD
Prices may vary | [213](https://ark.intel.com/content/www/us/en/ark/products/134854/intel-xeon-e-2124g-processor-8m-cache-up-to-4-50-ghz.html) | [539](https://ark.intel.com/content/www/us/en/ark/products/199336/intel-xeon-w-1290p-processor-20m-cache-3-70-ghz.html) |[1,002](https://ark.intel.com/content/www/us/en/ark/products/193394/intel-xeon-silver-4216-processor-22m-cache-2-10-ghz.html) | + +**CPU Inference Engines (continue)** + +| | Intel® Xeon® Gold 5218T | Intel® Xeon® Platinum 8270 | Intel® Xeon® Platinum 8380 | +| ------------------------------- | ---------------------------- | ---------------------------- | -----------------------------------------| +| Motherboard | Intel® Server Board S2600STB | Intel® Server Board S2600STB | Intel Corporation / WilsonCity | +| CPU | Intel® Xeon® Gold 5218T CPU @ 2.10GHz | Intel® Xeon® Platinum 8270 CPU @ 2.70GHz | Intel® Xeon® Platinum 8380 CPU @ 2.30GHz | +| Hyper Threading | ON | ON | ON | +| Turbo Setting | ON | ON | ON | +| Memory | 12 x 32 GB DDR4 2666MHz | 12 x 32 GB DDR4 2933MHz | 16 x 16 GB DDR4 3200MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.3.0-24-generic | +| BIOS Vendor | Intel Corporation | Intel Corporation | Intel Corporation | +| BIOS Version | SE5C620.86B.02.01.
0009.092820190230 | SE5C620.86B.02.01.
0009.092820190230 | WLYDCRB1.SYS.0020.
P86.2103050636 | +| BIOS Release | September 28, 2019 | September 28, 2019 | March 5, 2021 | +| BIOS Settings | Select optimized default settings,
change power policy to "performance",
save & exit | Select optimized default settings,
change power policy to "performance",
save & exit | Select optimized default settings,
change power policy to "performance",
save & exit | +| Batch size | 1 | 1 | 1 | +| Precision | INT8 | INT8 | INT8 | +| Number of concurrent inference requests |32 | 52 | 80 | +| Test Date | March 15, 2021 | March 15, 2021 | March 22, 2021 | +| Power dissipation, TDP in Watt | [105](https://ark.intel.com/content/www/us/en/ark/products/193953/intel-xeon-gold-5218t-processor-22m-cache-2-10-ghz.html#tab-blade-1-0-1) | [205](https://ark.intel.com/content/www/us/en/ark/products/192482/intel-xeon-platinum-8270-processor-35-75m-cache-2-70-ghz.html#tab-blade-1-0-1) | [270](https://ark.intel.com/content/www/us/en/ark/products/212287/intel-xeon-platinum-8380-processor-60m-cache-2-30-ghz.html) | +| CPU Price, USD
Prices may vary | [1,349](https://ark.intel.com/content/www/us/en/ark/products/193953/intel-xeon-gold-5218t-processor-22m-cache-2-10-ghz.html) (on Mach 15th, 2021) | [7,405](https://ark.intel.com/content/www/us/en/ark/products/192482/intel-xeon-platinum-8270-processor-35-75m-cache-2-70-ghz.html) (on Mach 15th, 2021) | [8,099](https://ark.intel.com/content/www/us/en/ark/products/212287/intel-xeon-platinum-8380-processor-60m-cache-2-30-ghz.html) (on March 26th, 2021) | + + +**CPU Inference Engines (continue)** + +| | Intel® Core™ i7-8700T | Intel® Core™ i9-10920X | 11th Gen Intel® Core™ i7-1185G7 | +| -------------------- | ----------------------------------- |--------------------------------------| --------------------------------| +| Motherboard | GIGABYTE* Z370M DS3H-CF | ASUS* PRIME X299-A II | Intel Corporation
internal/Reference
Validation Platform | +| CPU | Intel® Core™ i7-8700T CPU @ 2.40GHz | Intel® Core™ i9-10920X CPU @ 3.50GHz | 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz | +| Hyper Threading | ON | ON | ON | +| Turbo Setting | ON | ON | ON | +| Memory | 4 x 16 GB DDR4 2400MHz | 4 x 16 GB DDR4 2666MHz | 2 x 8 GB DDR4 3200MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | 5.8.0-05-generic | +| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | Intel Corporation | +| BIOS Version | F11 | 505 | TGLSFWI1.R00.3425.
A00.2010162309 | +| BIOS Release | March 13, 2019 | December 17, 2019 | October 16, 2020 | +| BIOS Settings | Select optimized default settings,
set OS type to "other",
save & exit | Default Settings | Default Settings | +| Batch size | 1 | 1 | 1 | +| Precision | INT8 | INT8 | INT8 | +| Number of concurrent inference requests |4 | 24 | 4 | +| Test Date | March 15, 2021 | March 15, 2021 | March 15, 2021 | +| Power dissipation, TDP in Watt | [35](https://ark.intel.com/content/www/us/en/ark/products/129948/intel-core-i7-8700t-processor-12m-cache-up-to-4-00-ghz.html#tab-blade-1-0-1) | [165](https://ark.intel.com/content/www/us/en/ark/products/198012/intel-core-i9-10920x-x-series-processor-19-25m-cache-3-50-ghz.html) | [28](https://ark.intel.com/content/www/us/en/ark/products/208664/intel-core-i7-1185g7-processor-12m-cache-up-to-4-80-ghz-with-ipu.html#tab-blade-1-0-1) | +| CPU Price on Mach 15th, 2021, USD
Prices may vary | [303](https://ark.intel.com/content/www/us/en/ark/products/129948/intel-core-i7-8700t-processor-12m-cache-up-to-4-00-ghz.html) | [700](https://ark.intel.com/content/www/us/en/ark/products/198012/intel-core-i9-10920x-x-series-processor-19-25m-cache-3-50-ghz.html) | [426](https://ark.intel.com/content/www/us/en/ark/products/208664/intel-core-i7-1185g7-processor-12m-cache-up-to-4-80-ghz-with-ipu.html#tab-blade-1-0-0) | + + +**CPU Inference Engines (continue)** + +| | Intel® Core™ i5-8500 | Intel® Core™ i5-10500TE | +| -------------------- | ---------------------------------- | ----------------------------------- | +| Motherboard | ASUS* PRIME Z370-A | GIGABYTE* Z490 AORUS PRO AX | +| CPU | Intel® Core™ i5-8500 CPU @ 3.00GHz | Intel® Core™ i5-10500TE CPU @ 2.30GHz | +| Hyper Threading | OFF | ON | +| Turbo Setting | ON | ON | +| Memory | 2 x 16 GB DDR4 2666MHz | 2 x 16 GB DDR4 @ 2666MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.3.0-24-generic | 5.3.0-24-generic | +| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | +| BIOS Version | 2401 | F3 | +| BIOS Release | July 12, 2019 | March 25, 2020 | +| BIOS Settings | Select optimized default settings,
save & exit | Select optimized default settings,
set OS type to "other",
save & exit | +| Batch size | 1 | 1 | +| Precision | INT8 | INT8 | +| Number of concurrent inference requests | 3 | 4 | +| Test Date | March 15, 2021 | March 15, 2021 | +| Power dissipation, TDP in Watt | [65](https://ark.intel.com/content/www/us/en/ark/products/129939/intel-core-i5-8500-processor-9m-cache-up-to-4-10-ghz.html#tab-blade-1-0-1)| [35](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | +| CPU Price on Mach 15th, 2021, USD
Prices may vary | [192](https://ark.intel.com/content/www/us/en/ark/products/129939/intel-core-i5-8500-processor-9m-cache-up-to-4-10-ghz.html) | [195](https://ark.intel.com/content/www/us/en/ark/products/203891/intel-core-i5-10500te-processor-12m-cache-up-to-3-70-ghz.html) | + + +**CPU Inference Engines (continue)** + +| | Intel Atom® x5-E3940 | Intel Atom® x6425RE | Intel® Core™ i3-8100 | +| -------------------- | --------------------------------------|------------------------------- |----------------------------------- | +| Motherboard | | Intel Corporation /
ElkhartLake LPDDR4x T3 CRB | GIGABYTE* Z390 UD | +| CPU | Intel Atom® Processor E3940 @ 1.60GHz | Intel Atom® x6425RE
Processor @ 1.90GHz | Intel® Core™ i3-8100 CPU @ 3.60GHz | +| Hyper Threading | OFF | OFF | OFF | +| Turbo Setting | ON | ON | OFF | +| Memory | 1 x 8 GB DDR3 1600MHz | 2 x 4GB DDR4 3200 MHz | 4 x 8 GB DDR4 2400MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.3.0-24-generic | 5.8.0-050800-generic | 5.3.0-24-generic | +| BIOS Vendor | American Megatrends Inc.* | Intel Corporation | American Megatrends Inc.* | +| BIOS Version | 5.12 | EHLSFWI1.R00.2463.
A03.2011200425 | F8 | +| BIOS Release | September 6, 2017 | November 22, 2020 | May 24, 2019 | +| BIOS Settings | Default settings | Default settings | Select optimized default settings,
set OS type to "other",
save & exit | +| Batch size | 1 | 1 | 1 | +| Precision | INT8 | INT8 | INT8 | +| Number of concurrent inference requests | 4 | 4 | 4 | +| Test Date | March 15, 2021 | March 15, 2021 | March 15, 2021 | +| Power dissipation, TDP in Watt | [9.5](https://ark.intel.com/content/www/us/en/ark/products/96485/intel-atom-x5-e3940-processor-2m-cache-up-to-1-80-ghz.html) | [12](https://ark.intel.com/content/www/us/en/ark/products/207899/intel-atom-x6425re-processor-1-5m-cache-1-90-ghz.html) | [65](https://ark.intel.com/content/www/us/en/ark/products/126688/intel-core-i3-8100-processor-6m-cache-3-60-ghz.html#tab-blade-1-0-1)| +| CPU Price, USD
Prices may vary | [34](https://ark.intel.com/content/www/us/en/ark/products/96485/intel-atom-x5-e3940-processor-2m-cache-up-to-1-80-ghz.html) (on March 15th, 2021) | [59](https://ark.intel.com/content/www/us/en/ark/products/207899/intel-atom-x6425re-processor-1-5m-cache-1-90-ghz.html) (on March 26th, 2021) | [117](https://ark.intel.com/content/www/us/en/ark/products/126688/intel-core-i3-8100-processor-6m-cache-3-60-ghz.html) (on March 15th, 2021) | + + + +**Accelerator Inference Engines** + +| | Intel® Neural Compute Stick 2 | Intel® Vision Accelerator Design
with Intel® Movidius™ VPUs (Mustang-V100-MX8) | +| --------------------------------------- | ------------------------------------- | ------------------------------------- | +| VPU | 1 X Intel® Movidius™ Myriad™ X MA2485 | 8 X Intel® Movidius™ Myriad™ X MA2485 | +| Connection | USB 2.0/3.0 | PCIe X4 | +| Batch size | 1 | 1 | +| Precision | FP16 | FP16 | +| Number of concurrent inference requests | 4 | 32 | +| Power dissipation, TDP in Watt | 2.5 | [30](https://www.arrow.com/en/products/mustang-v100-mx8-r10/iei-technology?gclid=Cj0KCQiA5bz-BRD-ARIsABjT4ng1v1apmxz3BVCPA-tdIsOwbEjTtqnmp_rQJGMfJ6Q2xTq6ADtf9OYaAhMUEALw_wcB) | +| CPU Price, USD
Prices may vary | [69](https://ark.intel.com/content/www/us/en/ark/products/140109/intel-neural-compute-stick-2.html) (from March 15, 2021) | [1180](https://www.arrow.com/en/products/mustang-v100-mx8-r10/iei-technology?gclid=Cj0KCQiA5bz-BRD-ARIsABjT4ng1v1apmxz3BVCPA-tdIsOwbEjTtqnmp_rQJGMfJ6Q2xTq6ADtf9OYaAhMUEALw_wcB) (from March 15, 2021) | +| Host Computer | Intel® Core™ i7 | Intel® Core™ i5 | +| Motherboard | ASUS* Z370-A II | Uzelinfo* / US-E1300 | +| CPU | Intel® Core™ i7-8700 CPU @ 3.20GHz | Intel® Core™ i5-6600 CPU @ 3.30GHz | +| Hyper Threading | ON | OFF | +| Turbo Setting | ON | ON | +| Memory | 4 x 16 GB DDR4 2666MHz | 2 x 16 GB DDR4 2400MHz | +| Operating System | Ubuntu* 18.04 LTS | Ubuntu* 18.04 LTS | +| Kernel Version | 5.0.0-23-generic | 5.0.0-23-generic | +| BIOS Vendor | American Megatrends Inc.* | American Megatrends Inc.* | +| BIOS Version | 411 | 5.12 | +| BIOS Release | September 21, 2018 | September 21, 2018 | +| Test Date | March 15, 2021 | March 15, 2021 | + +Please follow this link for more detailed configuration descriptions: [Configuration Details](https://docs.openvinotoolkit.org/resources/benchmark_files/system_configurations_2021.3.html) + +\htmlonly + +
+

+\endhtmlonly +Results may vary. For workloads and configurations visit: [www.intel.com/PerformanceIndex](https://www.intel.com/PerformanceIndex) and [Legal Information](../Legal_Information.md). +\htmlonly +

+
+\endhtmlonly diff --git a/docs/benchmarks/performance_benchmarks_ovms.md b/docs/benchmarks/performance_benchmarks_ovms.md new file mode 100644 index 00000000000..604a68438ed --- /dev/null +++ b/docs/benchmarks/performance_benchmarks_ovms.md @@ -0,0 +1,376 @@ +# OpenVINO™ Model Server Benchmark Results {#openvino_docs_performance_benchmarks_ovms} + +OpenVINO™ Model Server is an open-source, production-grade inference platform that exposes a set of models via a convenient inference API over gRPC or HTTP/REST. It employs the inference engine libraries for from the Intel® Distribution of OpenVINO™ toolkit to extend workloads across Intel® hardware including CPU, GPU and others. + +![OpenVINO™ Model Server](../img/performance_benchmarks_ovms_01.png) + +## Measurement Methodology + +OpenVINO™ Model Server is measured in multiple-client-single-server configuration using two hardware platforms connected by ethernet network. The network bandwidth depends on the platforms as well as models under investigation and it is set to not be a bottleneck for workload intensity. This connection is dedicated only to the performance measurements. The benchmark setup is consists of four main parts: + +![OVMS Benchmark Setup Diagram](../img/performance_benchmarks_ovms_02.png) + +* **OpenVINO™ Model Server** is launched as a docker container on the server platform and it listens (and answers on) requests from clients. OpenVINO™ Model Server is run on the same machine as the OpenVINO™ toolkit benchmark application in corresponding benchmarking. Models served by OpenVINO™ Model Server are located in a local file system mounted into the docker container. The OpenVINO™ Model Server instance communicates with other components via ports over a dedicated docker network. + +* **Clients** are run in separated physical machine referred to as client platform. Clients are implemented in Python3 programming language based on TensorFlow* API and they work as parallel processes. Each client waits for a response from OpenVINO™ Model Server before it will send a new next request. The role played by the clients is also verification of responses. + +* **Load balancer** works on the client platform in a docker container. HAProxy is used for this purpose. Its main role is counting of requests forwarded from clients to OpenVINO™ Model Server, estimating its latency, and sharing this information by Prometheus service. The reason of locating the load balancer on the client site is to simulate real life scenario that includes impact of physical network on reported metrics. + +* **Execution Controller** is launched on the client platform. It is responsible for synchronization of the whole measurement process, downloading metrics from the load balancer, and presenting the final report of the execution. + +## 3D U-Net (FP32) +![](../img/throughput_ovms_3dunet.png) +## resnet-50-TF (INT8) +![](../img/throughput_ovms_resnet50_int8.png) +## resnet-50-TF (FP32) +![](../img/throughput_ovms_resnet50_fp32.png) +## bert-large-uncased-whole-word-masking-squad-int8-0001 (INT8) +![](../img/throughput_ovms_bertlarge_int8.png) + +## bert-large-uncased-whole-word-masking-squad-0001 (FP32) +![](../img/throughput_ovms_bertlarge_fp32.png) +## Platform Configurations + +OpenVINO™ Model Server performance benchmark numbers are based on release 2021.3. Performance results are based on testing as of March 15, 2021 and may not reflect all publicly available updates. + +**Platform with Intel® Xeon® Gold 6252** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server PlatformClient Platform
MotherboardIntel® Server Board S2600WF H48104-872Inspur YZMB-00882-104 NF5280M5
MemoryHynix 16 x 16GB @ 2666 MT/s DDR4Samsung 16 x 16GB @ 2666 MT/s DDR4
CPUIntel® Xeon® Gold 6252 CPU @ 2.10GHzIntel® Xeon® Platinum 8260M CPU @ 2.40GHz
Selected CPU FlagsHyper Threading, Turbo Boost, DL BoostHyper Threading, Turbo Boost, DL Boost
CPU Thermal Design Power150 W162 W
Operating SystemUbuntu 20.04.2 LTSUbuntu 20.04.2 LTS
Kernel Version5.4.0-65-generic5.4.0-54-generic
BIOS VendorIntel® CorporationAmerican Megatrends Inc.
BIOS Version and Release DateSE5C620.86B.02.01, date: 03/26/20204.1.16, date: 06/23/2020
Docker Version20.10.320.10.3
Network Speed40 Gb/s
+ +**Platform with Intel® Core™ i9-10920X** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server PlatformClient Platform
MotherboardASUSTeK COMPUTER INC. PRIME X299-A IIASUSTeK COMPUTER INC. PRIME Z370-P
MemoryCorsair 4 x 16GB @ 2666 MT/s DDR4Corsair 4 x 16GB @ 2133 MT/s DDR4
CPUIntel® Core™ i9-10920X CPU @ 3.50GHzIntel® Core™ i7-8700T CPU @ 2.40GHz
Selected CPU FlagsHyper Threading, Turbo Boost, DL BoostHyper Threading, Turbo Boost
CPU Thermal Design Power165 W35 W
Operating SystemUbuntu 20.04.1 LTSUbuntu 20.04.1 LTS
Kernel Version5.4.0-52-generic5.4.0-56-generic
BIOS VendorAmerican Megatrends Inc.American Megatrends Inc.
BIOS Version and Release Date0603, date: 03/05/20202401, date: 07/15/2019
Docker Version19.03.1319.03.14
Network Speed10 Gb/s
+ +**Platform with Intel® Core™ i7-8700T** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server PlatformClient Platform
MotherboardASUSTeK COMPUTER INC. PRIME Z370-PASUSTeK COMPUTER INC. PRIME X299-A II
MemoryCorsair 4 x 16GB @ 2133 MT/s DDR4Corsair 4 x 16GB @ 2666 MT/s DDR4
CPUIntel® Core™ i7-8700T CPU @ 2.40GHzIntel® Core™ i9-10920X CPU @ 3.50GHz
Selected CPU FlagsHyper Threading, Turbo BoostHyper Threading, Turbo Boost, DL Boost
CPU Thermal Design Power35 W165 W
Operating SystemUbuntu 20.04.1 LTSUbuntu 20.04.1 LTS
Kernel Version5.4.0-56-generic5.4.0-52-generic
BIOS VendorAmerican Megatrends Inc.American Megatrends Inc.
BIOS Version and Release Date2401, date: 07/15/20190603, date: 03/05/2020
Docker Version19.03.1419.03.13
Network Speed10 Gb/s
+ +**Platform with Intel® Core™ i5-8500** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server PlatformClient Platform
MotherboardASUSTeK COMPUTER INC. PRIME Z370-AGigabyte Technology Co., Ltd. Z390 UD
MemoryCorsair 2 x 16GB @ 2133 MT/s DDR4029E 4 x 8GB @ 2400 MT/s DDR4
CPUIntel® Core™ i5-8500 CPU @ 3.00GHzIntel® Core™ i3-8100 CPU @ 3.60GHz
Selected CPU FlagsTurbo Boost-
CPU Thermal Design Power65 W65 W
Operating SystemUbuntu 20.04.1 LTSUbuntu 20.04.1 LTS
Kernel Version5.4.0-52-generic5.4.0-52-generic
BIOS VendorAmerican Megatrends Inc.American Megatrends Inc.
BIOS Version and Release Date2401, date: 07/12/2019F10j, date: 09/16/2020
Docker Version19.03.1320.10.0
Network Speed40 Gb/s
+ +**Platform with Intel® Core™ i3-8100** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Server PlatformClient Platform
MotherboardGigabyte Technology Co., Ltd. Z390 UDASUSTeK COMPUTER INC. PRIME Z370-A
Memory029E 4 x 8GB @ 2400 MT/s DDR4Corsair 2 x 16GB @ 2133 MT/s DDR4
CPUIntel® Core™ i3-8100 CPU @ 3.60GHzIntel® Core™ i5-8500 CPU @ 3.00GHz
Selected CPU Flags-Turbo Boost
CPU Thermal Design Power65 W65 W
Operating SystemUbuntu 20.04.1 LTSUbuntu 20.04.1 LTS
Kernel Version5.4.0-52-generic5.4.0-52-generic
BIOS VendorAmerican Megatrends Inc.American Megatrends Inc.
BIOS Version and Release DateF10j, date: 09/16/20202401, date: 07/12/2019
Docker Version20.10.019.03.13
Network Speed40 Gb/s
+ + +\htmlonly + +
+

+\endhtmlonly +Results may vary. For workloads and configurations visit: [www.intel.com/PerformanceIndex](https://www.intel.com/PerformanceIndex) and [Legal Information](../Legal_Information.md). +\htmlonly +

+
+\endhtmlonly + diff --git a/docs/benchmarks/performance_int8_vs_fp32.md b/docs/benchmarks/performance_int8_vs_fp32.md index 42dd26b9cce..35be3673e1a 100644 --- a/docs/benchmarks/performance_int8_vs_fp32.md +++ b/docs/benchmarks/performance_int8_vs_fp32.md @@ -7,9 +7,9 @@ The table below illustrates the speed-up factor for the performance gain by swit Intel® Core™
i7-8700T - Intel® Xeon®
Gold
5218T - Intel® Xeon®
Platinum
8270 Intel® Core™
i7-1185G7 + Intel® Xeon®
W-1290P + Intel® Xeon®
Platinum
8270 OpenVINO
benchmark
model name @@ -20,161 +20,177 @@ The table below illustrates the speed-up factor for the performance gain by swit bert-large-
uncased-whole-word-
masking-squad-0001 SQuAD 1.6 - 2.7 - 2.0 - 2.6 + 3.0 + 1.6 + 2.3 brain-tumor-
segmentation-
0001-MXNET BraTS - 1.5 + 1.6 1.9 1.7 - 1.8 + 1.7 deeplabv3-TF VOC 2012
Segmentation - 1.5 - 2.4 - 2.8 + 2.1 3.1 + 3.1 + 3.0 densenet-121-TF ImageNet - 1.6 - 3.2 - 3.2 - 3.2 + 1.8 + 3.5 + 1.9 + 3.8 facenet-
20180408-
102900-TF LFW 2.0 3.6 - 3.5 - 3.4 + 2.2 + 3.7 faster_rcnn_
resnet50_coco-TF MS COCO - 1.7 - 3.4 - 3.4 - 3.4 + 1.9 + 3.8 + 2.0 + 3.5 googlenet-v1-TF ImageNet 1.8 3.6 - 3.7 - 3.5 + 2.0 + 3.9 inception-v3-TF ImageNet - 1.8 + 1.9 3.8 + 2.0 4.0 - 3.5 mobilenet-
ssd-CF VOC2012 - 1.5 + 1.7 3.1 + 1.8 3.6 - 3.1 mobilenet-v1-1.0-
224-TF ImageNet - 1.5 - 3.2 - 4.1 + 1.7 3.1 + 1.8 + 4.1 mobilenet-v2-1.0-
224-TF ImageNet - 1.3 - 2.7 - 4.3 - 2.5 + 1.5 + 2.4 + 1.8 + 3.9 mobilenet-v2-
pytorch ImageNet - 1.4 - 2.8 - 4.6 + 1.6 2.4 + 1.9 + 3.9 resnet-18-
pytorch ImageNet 1.9 3.7 - 3.8 - 3.6 + 2.1 + 4.2 resnet-50-
pytorch ImageNet - 1.8 - 3.6 + 1.9 + 3.7 + 2.0 3.9 - 3.4 resnet-50-
TF ImageNet - 1.8 + 1.9 3.6 + 2.0 3.9 - 3.4 squeezenet1.1-
CF ImageNet - 1.6 - 2.9 - 3.4 + 1.7 3.2 + 1.8 + 3.4 ssd_mobilenet_
v1_coco-tf VOC2012 - 1.6 - 3.1 - 3.7 + 1.7 3.0 + 1.9 + 3.6 ssd300-CF MS COCO 1.8 - 3.7 - 3.7 - 3.8 + 4.4 + 1.9 + 3.9 ssdlite_
mobilenet_
v2-TF MS COCO - 1.4 - 2.3 - 3.9 + 1.7 2.5 + 2.2 + 3.4 yolo_v3-TF MS COCO 1.8 - 3.8 + 4.0 + 1.9 3.9 - 3.6 + + + yolo_v4-TF + MS COCO + 1.7 + 3.4 + 1.7 + 2.8 + + + unet-camvid-onnx-0001 + MS COCO + 1.6 + 3.8 + 1.6 + 3.7 @@ -187,7 +203,7 @@ The following table shows the absolute accuracy drop that is calculated as the d Intel® Core™
i9-10920X CPU
@ 3.50GHZ (VNNI) Intel® Core™
i9-9820X CPU
@ 3.30GHz (AVX512) - Intel® Core™
i7-6700 CPU
@ 4.0GHz (AVX2) + Intel® Core™
i7-6700K CPU
@ 4.0GHz (AVX2) Intel® Core™
i7-1185G7 CPU
@ 4.0GHz (TGL VNNI) @@ -196,176 +212,203 @@ The following table shows the absolute accuracy drop that is calculated as the d Metric Name Absolute Accuracy Drop, % + + bert-large-uncased-whole-word-masking-squad-0001 + SQuAD + F1 + 0.62 + 0.88 + 0.52 + 0.62 + brain-tumor-
segmentation-
0001-MXNET BraTS Dice-index@
Mean@
Overall Tumor - 0.08 - 0.08 - 0.08 - 0.08 + 0.09 + 0.10 + 0.11 + 0.09 deeplabv3-TF VOC 2012
Segmentation mean_iou - 0.73 - 1.10 - 1.10 - 0.73 + 0.09 + 0.41 + 0.41 + 0.09 densenet-121-TF ImageNet acc@top-1 - 0.73 - 0.72 - 0.72 - 0.73 + 0.54 + 0.57 + 0.57 + 0.54 facenet-
20180408-
102900-TF LFW pairwise_
accuracy
_subsets - 0.02 - 0.02 - 0.02 - 0.47 + 0.05 + 0.12 + 0.12 + 0.05 faster_rcnn_
resnet50_coco-TF MS COCO coco_
precision - 0.21 - 0.20 - 0.20 - 0.21 + 0.04 + 0.04 + 0.04 + 0.04 googlenet-v1-TF ImageNet acc@top-1 - 0.03 0.01 + 0.00 + 0.00 0.01 - 0.03 inception-v3-TF ImageNet acc@top-1 - 0.03 - 0.01 - 0.01 - 0.03 + 0.04 + 0.00 + 0.00 + 0.04 mobilenet-
ssd-CF VOC2012 mAP - 0.35 - 0.34 - 0.34 - 0.35 + 0.77 + 0.77 + 0.77 + 0.77 mobilenet-v1-1.0-
224-TF ImageNet acc@top-1 - 0.27 - 0.20 - 0.20 - 0.27 + 0.26 + 0.28 + 0.28 + 0.26 mobilenet-v2-1.0-
224-TF ImageNet acc@top-1 - 0.44 - 0.92 - 0.92 - 0.44 + 0.40 + 0.76 + 0.76 + 0.40 mobilenet-v2-
PYTORCH ImageNet acc@top-1 - 0.25 - 7.42 - 7.42 - 0.25 + 0.36 + 0.52 + 0.52 + 0.36 resnet-18-
pytorch ImageNet acc@top-1 - 0.26 0.25 0.25 - 0.26 + 0.25 + 0.25 resnet-50-
PYTORCH ImageNet acc@top-1 - 0.18 0.19 + 0.21 + 0.21 0.19 - 0.18 resnet-50-
TF ImageNet acc@top-1 - 0.15 - 0.11 - 0.11 - 0.15 + 0.10 + 0.08 + 0.08 + 0.10 squeezenet1.1-
CF ImageNet acc@top-1 + 0.63 0.66 - 0.64 - 0.64 0.66 + 0.63 ssd_mobilenet_
v1_coco-tf VOC2012 COCO mAp - 0.24 - 3.07 - 3.07 - 0.24 + 0.18 + 3.06 + 3.06 + 0.18 ssd300-CF MS COCO COCO mAp - 0.06 0.05 0.05 - 0.06 + 0.05 + 0.05 ssdlite_
mobilenet_
v2-TF MS COCO COCO mAp - 0.14 + 0.11 0.43 0.43 - 0.14 + 0.11 yolo_v3-TF MS COCO COCO mAp - 0.12 - 0.35 - 0.35 - 0.12 + 0.11 + 0.24 + 0.24 + 0.11 + + + yolo_v4-TF + MS COCO + COCO mAp + 0.01 + 0.09 + 0.09 + 0.01 + + + unet-camvid-
onnx-0001 + MS COCO + COCO mAp + 0.31 + 0.31 + 0.31 + 0.31 diff --git a/docs/doxygen/ie_docs.xml b/docs/doxygen/ie_docs.xml index 010d7cac724..8ca6ff2588e 100644 --- a/docs/doxygen/ie_docs.xml +++ b/docs/doxygen/ie_docs.xml @@ -270,7 +270,6 @@ limitations under the License. - diff --git a/docs/doxygen/openvino_docs.xml b/docs/doxygen/openvino_docs.xml index 0ca1c093271..92238645a05 100644 --- a/docs/doxygen/openvino_docs.xml +++ b/docs/doxygen/openvino_docs.xml @@ -100,11 +100,14 @@ limitations under the License. - - - - - + + + + + + + + @@ -166,6 +169,7 @@ limitations under the License. + @@ -181,7 +185,15 @@ limitations under the License. - + + + + + + + + + diff --git a/docs/gapi/face_beautification.md b/docs/gapi/face_beautification.md index 539b0ca9b7e..25619ae8e0b 100644 --- a/docs/gapi/face_beautification.md +++ b/docs/gapi/face_beautification.md @@ -12,11 +12,11 @@ This sample requires: * PC with GNU/Linux* or Microsoft Windows* (Apple macOS* is supported but was not tested) * OpenCV 4.2 or higher built with [Intel® Distribution of OpenVINO™ Toolkit](https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html) (building with [Intel® TBB](https://www.threadingbuildingblocks.org/intel-tbb-tutorial) is a plus) -* The following pre-trained models from the [Open Model Zoo](@ref omz_models_intel_index) - * [face-detection-adas-0001](@ref omz_models_intel_face_detection_adas_0001_description_face_detection_adas_0001) - * [facial-landmarks-35-adas-0002](@ref omz_models_intel_facial_landmarks_35_adas_0002_description_facial_landmarks_35_adas_0002) +* The following pre-trained models from the [Open Model Zoo](@ref omz_models_group_intel) + * [face-detection-adas-0001](@ref omz_models_model_face_detection_adas_0001) + * [facial-landmarks-35-adas-0002](@ref omz_models_model_facial_landmarks_35_adas_0002) -To download the models from the Open Model Zoo, use the [Model Downloader](@ref omz_tools_downloader_README) tool. +To download the models from the Open Model Zoo, use the [Model Downloader](@ref omz_tools_downloader) tool. ## Face Beautification Algorithm We will implement a simple face beautification algorithm using a combination of modern Deep Learning techniques and traditional Computer Vision. The general idea behind the algorithm is to make face skin smoother while preserving face features like eyes or a mouth contrast. The algorithm identifies parts of the face using a DNN inference, applies different filters to the parts found, and then combines it into the final result using basic image arithmetics: diff --git a/docs/gapi/gapi_face_analytics_pipeline.md b/docs/gapi/gapi_face_analytics_pipeline.md index 83dcf4594ca..6b544485668 100644 --- a/docs/gapi/gapi_face_analytics_pipeline.md +++ b/docs/gapi/gapi_face_analytics_pipeline.md @@ -11,12 +11,12 @@ This sample requires: * PC with GNU/Linux* or Microsoft Windows* (Apple macOS* is supported but was not tested) * OpenCV 4.2 or higher built with [Intel® Distribution of OpenVINO™ Toolkit](https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html) (building with [Intel® TBB](https://www.threadingbuildingblocks.org/intel-tbb-tutorial) -* The following pre-trained models from the [Open Model Zoo](@ref omz_models_intel_index): - * [face-detection-adas-0001](@ref omz_models_intel_face_detection_adas_0001_description_face_detection_adas_0001) - * [age-gender-recognition-retail-0013](@ref omz_models_intel_age_gender_recognition_retail_0013_description_age_gender_recognition_retail_0013) - * [emotions-recognition-retail-0003](@ref omz_models_intel_emotions_recognition_retail_0003_description_emotions_recognition_retail_0003) +* The following pre-trained models from the [Open Model Zoo](@ref omz_models_group_intel): + * [face-detection-adas-0001](@ref omz_models_model_face_detection_adas_0001) + * [age-gender-recognition-retail-0013](@ref omz_models_model_age_gender_recognition_retail_0013) + * [emotions-recognition-retail-0003](@ref omz_models_model_emotions_recognition_retail_0003) -To download the models from the Open Model Zoo, use the [Model Downloader](@ref omz_tools_downloader_README) tool. +To download the models from the Open Model Zoo, use the [Model Downloader](@ref omz_tools_downloader) tool. ## Introduction: Why G-API Many computer vision algorithms run on a video stream rather than on individual images. Stream processing usually consists of multiple steps – like decode, preprocessing, detection, tracking, classification (on detected objects), and visualization – forming a *video processing pipeline*. Moreover, many these steps of such pipeline can run in parallel – modern platforms have different hardware blocks on the same chip like decoders and GPUs, and extra accelerators can be plugged in as extensions, like Intel® Movidius™ Neural Compute Stick for deep learning offload. @@ -26,7 +26,7 @@ Given all this manifold of options and a variety in video analytics algorithms, Starting with version 4.2, OpenCV offers a solution to this problem. OpenCV G-API now can manage Deep Learning inference (a cornerstone of any modern analytics pipeline) with a traditional Computer Vision as well as video capturing/decoding, all in a single pipeline. G-API takes care of pipelining itself – so if the algorithm or platform changes, the execution model adapts to it automatically. ## Pipeline Overview -Our sample application is based on [Interactive Face Detection](omz_demos_interactive_face_detection_demo_README) demo from Open Model Zoo. A simplified pipeline consists of the following steps: +Our sample application is based on [Interactive Face Detection](@ref omz_demos_interactive_face_detection_demo_cpp) demo from Open Model Zoo. A simplified pipeline consists of the following steps: 1. Image acquisition and decode 2. Detection with preprocessing diff --git a/docs/get_started/get_started_dl_workbench.md b/docs/get_started/get_started_dl_workbench.md index 52f36c5b80a..795767f3c73 100644 --- a/docs/get_started/get_started_dl_workbench.md +++ b/docs/get_started/get_started_dl_workbench.md @@ -9,13 +9,13 @@ In this guide, you will: [DL Workbench](@ref workbench_docs_Workbench_DG_Introduction) is a web-based graphical environment that enables you to easily use various sophisticated OpenVINO™ toolkit components: -* [Model Downloader](@ref omz_tools_downloader_README) to download models from the [Intel® Open Model Zoo](@ref omz_models_intel_index) +* [Model Downloader](@ref omz_tools_downloader) to download models from the [Intel® Open Model Zoo](@ref omz_models_group_intel) with pretrained models for a range of different tasks * [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) to transform models into the Intermediate Representation (IR) format * [Post-Training Optimization toolkit](@ref pot_README) to calibrate a model and then execute it in the INT8 precision -* [Accuracy Checker](@ref omz_tools_accuracy_checker_README) to determine the accuracy of a model +* [Accuracy Checker](@ref omz_tools_accuracy_checker) to determine the accuracy of a model * [Benchmark Tool](@ref openvino_inference_engine_samples_benchmark_app_README) to estimate inference performance on supported devices ![](./dl_workbench_img/DL_Workbench.jpg) @@ -70,10 +70,10 @@ The simplified OpenVINO™ DL Workbench workflow is: ## Run Baseline Inference -This section illustrates a sample use case of how to infer a pretrained model from the [Intel® Open Model Zoo](@ref omz_models_intel_index) with an autogenerated noise dataset on a CPU device. - +This section illustrates a sample use case of how to infer a pretrained model from the [Intel® Open Model Zoo](@ref omz_models_group_intel) with an autogenerated noise dataset on a CPU device. +\htmlonly - +\endhtmlonly Once you log in to the DL Workbench, create a project, which is a combination of a model, a dataset, and a target device. Follow the steps below: diff --git a/docs/get_started/get_started_linux.md b/docs/get_started/get_started_linux.md index a01d5a11c67..3aa945a05a1 100644 --- a/docs/get_started/get_started_linux.md +++ b/docs/get_started/get_started_linux.md @@ -18,7 +18,7 @@ In addition, demo scripts, code samples and demo applications are provided to he * **[Code Samples](../IE_DG/Samples_Overview.md)** - Small console applications that show you how to: * Utilize specific OpenVINO capabilities in an application * Perform specific tasks, such as loading a model, running inference, querying specific device capabilities, and more. -* **[Demo Applications](@ref omz_demos_README)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. +* **[Demo Applications](@ref omz_demos)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. ## Intel® Distribution of OpenVINO™ toolkit Installation and Deployment Tools Directory Structure This guide assumes you completed all Intel® Distribution of OpenVINO™ toolkit installation and configuration steps. If you have not yet installed and configured the toolkit, see [Install Intel® Distribution of OpenVINO™ toolkit for Linux*](../install_guides/installing-openvino-linux.md). @@ -46,9 +46,9 @@ The primary tools for deploying your models and applications are installed to th |       `samples/` | Inference Engine samples. Contains source code for C++ and Python* samples and build scripts. See the [Inference Engine Samples Overview](../IE_DG/Samples_Overview.md). | |       `src/` | Source files for CPU extensions.| | `model_optimizer/` | Model Optimizer directory. Contains configuration scripts, scripts to run the Model Optimizer and other files. See the [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). -| `open_model_zoo/` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_intel_index) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| +| `open_model_zoo/` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_group_intel) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| |       `demos/` | Demo applications for inference scenarios. Also includes documentation and build scripts.| -|       `intel_models/` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index).| +|       `intel_models/` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel).| |       `tools/` | Model Downloader and Accuracy Checker tools. | | `tools/` | Contains a symbolic link to the Model Downloader folder and auxiliary tools to work with your models: Calibration tool, Benchmark and Collect Statistics tools.| @@ -197,7 +197,7 @@ Each demo and code sample is a separate application, but they use the same behav * [Code Samples](../IE_DG/Samples_Overview.md) - Small console applications that show how to utilize specific OpenVINO capabilities within an application and execute specific tasks such as loading a model, running inference, querying specific device capabilities, and more. -* [Demo Applications](@ref omz_demos_README) - Console applications that provide robust application templates to support developers in implementing specific deep learning scenarios. They may also involve more complex processing pipelines that gather analysis from several models that run inference simultaneously. For example concurrently detecting a person in a video stream and detecting attributes such as age, gender and/or emotions. +* [Demo Applications](@ref omz_demos) - Console applications that provide robust application templates to support developers in implementing specific deep learning scenarios. They may also involve more complex processing pipelines that gather analysis from several models that run inference simultaneously. For example concurrently detecting a person in a video stream and detecting attributes such as age, gender and/or emotions. Inputs you'll need to specify: - **A compiled OpenVINO™ code sample or demo application** that runs inferencing against a model that has been run through the Model Optimizer, resulting in an IR, using the other inputs you provide. @@ -209,7 +209,7 @@ Inputs you'll need to specify: To perform sample inference, run the Image Classification code sample and Security Barrier Camera demo application that were automatically compiled when you ran the Image Classification and Inference Pipeline demo scripts. The binary files are in the `~/inference_engine_cpp_samples_build/intel64/Release` and `~/inference_engine_demos_build/intel64/Release` directories, respectively. -To run other sample code or demo applications, build them from the source files delivered as part of the OpenVINO toolkit. To learn how to build these, see the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos_README) sections. +To run other sample code or demo applications, build them from the source files delivered as part of the OpenVINO toolkit. To learn how to build these, see the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos) sections. ### Step 1: Download the Models @@ -219,7 +219,7 @@ You must have a model that is specific for you inference task. Example model typ - Custom (Often based on SSD) Options to find a model suitable for the OpenVINO™ toolkit are: -- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader_README). +- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader). - Download from GitHub*, Caffe* Zoo, TensorFlow* Zoo, etc. - Train your own model. @@ -449,7 +449,7 @@ Throughput: 375.3339402 FPS ### Step 5: Run the Security Barrier Camera Demo Application -> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you ran the Inference Pipeline demo scripts. If you want to build it manually, see the [Demo Applications Overview](@ref omz_demos_README) section. +> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you ran the Inference Pipeline demo scripts. If you want to build it manually, see the [Demo Applications Overview](@ref omz_demos) section. To run the **Security Barrier Camera Demo Application** using an input image on the prepared IRs: diff --git a/docs/get_started/get_started_macos.md b/docs/get_started/get_started_macos.md index 14456171d60..980b02d0be2 100644 --- a/docs/get_started/get_started_macos.md +++ b/docs/get_started/get_started_macos.md @@ -18,7 +18,7 @@ In addition, demo scripts, code samples and demo applications are provided to he * **[Code Samples](../IE_DG/Samples_Overview.md)** - Small console applications that show you how to: * Utilize specific OpenVINO capabilities in an application. * Perform specific tasks, such as loading a model, running inference, querying specific device capabilities, and more. -* **[Demo Applications](@ref omz_demos_README)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. +* **[Demo Applications](@ref omz_demos)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. ## Intel® Distribution of OpenVINO™ toolkit Installation and Deployment Tools Directory Structure This guide assumes you completed all Intel® Distribution of OpenVINO™ toolkit installation and configuration steps. If you have not yet installed and configured the toolkit, see [Install Intel® Distribution of OpenVINO™ toolkit for macOS*](../install_guides/installing-openvino-macos.md). @@ -48,9 +48,9 @@ The primary tools for deploying your models and applications are installed to th | `~intel_models/` | Symbolic link to the `intel_models` subfolder of the `open_model_zoo` folder.| | `model_optimizer/` | Model Optimizer directory. Contains configuration scripts, scripts to run the Model Optimizer and other files. See the [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md).| | `ngraph/` | nGraph directory. Includes the nGraph header and library files. | -| `open_model_zoo/` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_intel_index) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| +| `open_model_zoo/` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_group_intel) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| |       `demos/` | Demo applications for inference scenarios. Also includes documentation and build scripts.| -|       `intel_models/` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index).| +|       `intel_models/` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel).| |       `models` | Intel's trained and public models that can be obtained with Model Downloader.| |       `tools/` | Model Downloader and Accuracy Checker tools. | | `tools/` | Contains a symbolic link to the Model Downloader folder and auxiliary tools to work with your models: Calibration tool, Benchmark and Collect Statistics tools.| @@ -200,7 +200,7 @@ Inputs you need to specify when using a code sample or demo application: To perform sample inference, run the Image Classification code sample and Security Barrier Camera demo application that are automatically compiled when you run the Image Classification and Inference Pipeline demo scripts. The binary files are in the `~/inference_engine_samples_build/intel64/Release` and `~/inference_engine_demos_build/intel64/Release` directories, respectively. -You can also build all available sample code and demo applications from the source files delivered with the OpenVINO toolkit. To learn how to do this, see the instructions in the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos_README) sections. +You can also build all available sample code and demo applications from the source files delivered with the OpenVINO toolkit. To learn how to do this, see the instructions in the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos) sections. ### Step 1: Download the Models @@ -210,7 +210,7 @@ You must have a model that is specific for you inference task. Example model typ - Custom (Often based on SSD) Options to find a model suitable for the OpenVINO™ toolkit are: -- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader_README). +- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader). - Download from GitHub*, Caffe* Zoo, TensorFlow* Zoo, and other resources. - Train your own model. @@ -422,7 +422,7 @@ classid probability label ### Step 5: Run the Security Barrier Camera Demo Application -> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you run the Inference Pipeline demo scripts. If you want to build it manually, see the instructions in the [Demo Applications Overview](@ref omz_demos_README) section. +> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you run the Inference Pipeline demo scripts. If you want to build it manually, see the instructions in the [Demo Applications Overview](@ref omz_demos) section. To run the **Security Barrier Camera Demo Application** using an input image on the prepared IRs: diff --git a/docs/get_started/get_started_raspbian.md b/docs/get_started/get_started_raspbian.md index afb821debec..5f3baf87d2f 100644 --- a/docs/get_started/get_started_raspbian.md +++ b/docs/get_started/get_started_raspbian.md @@ -43,8 +43,8 @@ The primary tools for deploying your models and applications are installed to th The OpenVINO™ workflow on Raspbian* OS is as follows: 1. **Get a pre-trained model** for your inference task. If you want to use your model for inference, the model must be converted to the `.bin` and `.xml` Intermediate Representation (IR) files, which are used as input by Inference Engine. On Raspberry PI, OpenVINO™ toolkit includes only the Inference Engine module. The Model Optimizer is not supported on this platform. To get the optimized models you can use one of the following options: - * Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader_README). -
For more information on pre-trained models, see [Pre-Trained Models Documentation](@ref omz_models_intel_index) + * Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader). +
For more information on pre-trained models, see [Pre-Trained Models Documentation](@ref omz_models_group_intel) * Convert a model using the Model Optimizer from a full installation of Intel® Distribution of OpenVINO™ toolkit on one of the supported platforms. Installation instructions are available: * [Installation Guide for macOS*](../install_guides/installing-openvino-macos.md) @@ -62,10 +62,10 @@ Follow the steps below to run pre-trained Face Detection network using Inference ``` 2. Build the Object Detection Sample with the following command: ```sh - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples/cpp + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino_2021/deployment_tools/inference_engine/samples/cpp make -j2 object_detection_sample_ssd ``` -3. Download the pre-trained Face Detection model with the [Model Downloader tool](@ref omz_tools_downloader_README): +3. Download the pre-trained Face Detection model with the [Model Downloader tool](@ref omz_tools_downloader): ```sh git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo cd open_model_zoo/tools/downloader diff --git a/docs/get_started/get_started_windows.md b/docs/get_started/get_started_windows.md index 0255a1bb396..c8c7ee23d1f 100644 --- a/docs/get_started/get_started_windows.md +++ b/docs/get_started/get_started_windows.md @@ -19,7 +19,7 @@ In addition, demo scripts, code samples and demo applications are provided to he * **[Code Samples](../IE_DG/Samples_Overview.md)** - Small console applications that show you how to: * Utilize specific OpenVINO capabilities in an application. * Perform specific tasks, such as loading a model, running inference, querying specific device capabilities, and more. -* **[Demo Applications](@ref omz_demos_README)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. +* **[Demo Applications](@ref omz_demos)** - Console applications that provide robust application templates to help you implement specific deep learning scenarios. These applications involve increasingly complex processing pipelines that gather analysis data from several models that run inference simultaneously, such as detecting a person in a video stream along with detecting the person's physical attributes, such as age, gender, and emotional state. ## Intel® Distribution of OpenVINO™ toolkit Installation and Deployment Tools Directory Structure This guide assumes you completed all Intel® Distribution of OpenVINO™ toolkit installation and configuration steps. If you have not yet installed and configured the toolkit, see [Install Intel® Distribution of OpenVINO™ toolkit for Windows*](../install_guides/installing-openvino-windows.md). @@ -45,9 +45,9 @@ The primary tools for deploying your models and applications are installed to th | `~intel_models\` | Symbolic link to the `intel_models` subfolder of the `open_model_zoo` folder. | | `model_optimizer\` | Model Optimizer directory. Contains configuration scripts, scripts to run the Model Optimizer and other files. See the [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). | | `ngraph\` | nGraph directory. Includes the nGraph header and library files. | -| `open_model_zoo\` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_intel_index) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| +| `open_model_zoo\` | Open Model Zoo directory. Includes the Model Downloader tool to download [pre-trained OpenVINO](@ref omz_models_group_intel) and public models, OpenVINO models documentation, demo applications and the Accuracy Checker tool to evaluate model accuracy.| |       `demos\` | Demo applications for inference scenarios. Also includes documentation and build scripts.| -|       `intel_models\` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index).| +|       `intel_models\` | Pre-trained OpenVINO models and associated documentation. See the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel).| |       `models` | Intel's trained and public models that can be obtained with Model Downloader.| |       `tools\` | Model Downloader and Accuracy Checker tools. | | `tools\` | Contains a symbolic link to the Model Downloader folder and auxiliary tools to work with your models: Calibration tool, Benchmark and Collect Statistics tools.| @@ -199,7 +199,7 @@ Inputs you need to specify when using a code sample or demo application: To perform sample inference, run the Image Classification code sample and Security Barrier Camera demo application that are automatically compiled when you run the Image Classification and Inference Pipeline demo scripts. The binary files are in the `C:\Users\\Intel\OpenVINO\inference_engine_cpp_samples_build\intel64\Release` and `C:\Users\\Intel\OpenVINO\inference_engine_demos_build\intel64\Release` directories, respectively. -You can also build all available sample code and demo applications from the source files delivered with the OpenVINO™ toolkit. To learn how to do this, see the instruction in the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos_README) sections. +You can also build all available sample code and demo applications from the source files delivered with the OpenVINO™ toolkit. To learn how to do this, see the instruction in the [Inference Engine Code Samples Overview](../IE_DG/Samples_Overview.md) and [Demo Applications Overview](@ref omz_demos) sections. ### Step 1: Download the Models @@ -209,7 +209,7 @@ You must have a model that is specific for you inference task. Example model typ - Custom (Often based on SSD) Options to find a model suitable for the OpenVINO™ toolkit are: -- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using the [Model Downloader tool](@ref omz_tools_downloader_README). +- Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using the [Model Downloader tool](@ref omz_tools_downloader). - Download from GitHub*, Caffe* Zoo, TensorFlow* Zoo, and other resources. - Train your own model. @@ -425,7 +425,7 @@ classid probability label ### Step 5: Run the Security Barrier Camera Demo Application -> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you run the Inference Pipeline demo scripts. If you want to build it manually, see the instructions in the [Demo Applications Overview](@ref omz_demos_README) section. +> **NOTE**: The Security Barrier Camera Demo Application is automatically compiled when you run the Inference Pipeline demo scripts. If you want to build it manually, see the instructions in the [Demo Applications Overview](@ref omz_demos) section. To run the **Security Barrier Camera Demo Application** using an input image on the prepared IRs: diff --git a/docs/how_tos/how-to-links.md b/docs/how_tos/how-to-links.md index 2f1840690ba..f263f22b5d2 100644 --- a/docs/how_tos/how-to-links.md +++ b/docs/how_tos/how-to-links.md @@ -44,7 +44,6 @@ To learn about what is *custom operation* and how to work with them in the Deep [![](https://img.youtube.com/vi/Kl1ptVb7aI8/0.jpg)](https://www.youtube.com/watch?v=Kl1ptVb7aI8) - ## Computer Vision with Intel [![](https://img.youtube.com/vi/FZZD4FCvO9c/0.jpg)](https://www.youtube.com/watch?v=FZZD4FCvO9c) diff --git a/docs/img/int8vsfp32.png b/docs/img/int8vsfp32.png index b4889ea2252..9ecbdc8be7b 100644 --- a/docs/img/int8vsfp32.png +++ b/docs/img/int8vsfp32.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0109b9cbc2908f786f6593de335c725f8ce5c800f37a7d79369408cc47eb8471 -size 25725 +oid sha256:e14f77f61f12c96ccf302667d51348a1e03579679155199910e3ebdf7d6adf06 +size 37915 diff --git a/docs/img/performance_benchmarks_ovms_01.png b/docs/img/performance_benchmarks_ovms_01.png new file mode 100644 index 00000000000..54473efc5b1 --- /dev/null +++ b/docs/img/performance_benchmarks_ovms_01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d86125db1e295334c04e92d0645c773f679d21bf52e25dce7c887fdf972b7a28 +size 19154 diff --git a/docs/img/performance_benchmarks_ovms_02.png b/docs/img/performance_benchmarks_ovms_02.png new file mode 100644 index 00000000000..1a39e7fbff6 --- /dev/null +++ b/docs/img/performance_benchmarks_ovms_02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf8b156026d35b023e57c5cb3ea9136c93a819c1e2aa77be57d1619db4151065 +size 373890 diff --git a/docs/img/throughput_ovms_3dunet.png b/docs/img/throughput_ovms_3dunet.png new file mode 100644 index 00000000000..261310190a5 --- /dev/null +++ b/docs/img/throughput_ovms_3dunet.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5a472a62de53998194bc1471539139807e00cbb75fd9edc605e7ed99b5630af +size 18336 diff --git a/docs/img/throughput_ovms_bertlarge_fp32.png b/docs/img/throughput_ovms_bertlarge_fp32.png new file mode 100644 index 00000000000..8fb4e484e17 --- /dev/null +++ b/docs/img/throughput_ovms_bertlarge_fp32.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f7c58da93fc7966e154bdade48d408401b097f4b0306b7c85aa4256ad72b59d +size 18118 diff --git a/docs/img/throughput_ovms_bertlarge_int8.png b/docs/img/throughput_ovms_bertlarge_int8.png new file mode 100644 index 00000000000..90e6e3a9426 --- /dev/null +++ b/docs/img/throughput_ovms_bertlarge_int8.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:104d8cd5eac2d1714db85df9cba5c2cfcc113ec54d428cd6e979e75e10473be6 +size 17924 diff --git a/docs/img/throughput_ovms_resnet50_fp32.png b/docs/img/throughput_ovms_resnet50_fp32.png new file mode 100644 index 00000000000..324acaf22ec --- /dev/null +++ b/docs/img/throughput_ovms_resnet50_fp32.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ad19ace847da73176f20f21052f9dd23fd65779f4e1027b2debdaf8fc772c00 +size 18735 diff --git a/docs/img/throughput_ovms_resnet50_int8.png b/docs/img/throughput_ovms_resnet50_int8.png new file mode 100644 index 00000000000..fdd92852fa9 --- /dev/null +++ b/docs/img/throughput_ovms_resnet50_int8.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32116d6d1acc20d8cb2fa10e290e052e3146ba1290f1c5e4aaf16a85388b6ec6 +size 19387 diff --git a/docs/index.md b/docs/index.md index 17fe2451d3f..ee0739a1e1e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,7 +19,7 @@ The following diagram illustrates the typical OpenVINO™ workflow (click to see ### Model Preparation, Conversion and Optimization You can use your framework of choice to prepare and train a Deep Learning model or just download a pretrained model from the Open Model Zoo. The Open Model Zoo includes Deep Learning solutions to a variety of vision problems, including object recognition, face recognition, pose estimation, text detection, and action recognition, at a range of measured complexities. -Several of these pretrained models are used also in the [code samples](IE_DG/Samples_Overview.md) and [application demos](@ref omz_demos_README). To download models from the Open Model Zoo, the [Model Downloader](@ref omz_tools_downloader_README) tool is used. +Several of these pretrained models are used also in the [code samples](IE_DG/Samples_Overview.md) and [application demos](@ref omz_demos). To download models from the Open Model Zoo, the [Model Downloader](@ref omz_tools_downloader) tool is used. One of the core component of the OpenVINO™ toolkit is the [Model Optimizer](MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) a cross-platform command-line tool that converts a trained neural network from its source framework to an open-source, nGraph-compatible [Intermediate Representation (IR)](MO_DG/IR_and_opsets.md) for use in inference operations. The Model Optimizer imports models trained in popular frameworks such as Caffe*, TensorFlow*, MXNet*, Kaldi*, and ONNX* and performs a few optimizations to remove excess layers and group operations when possible into simpler, faster graphs. @@ -27,16 +27,17 @@ tool that converts a trained neural network from its source framework to an open If your neural network model contains layers that are not in the list of known layers for supported frameworks, you can adjust the conversion and optimization process through use of [Custom Layers](HOWTO/Custom_Layers_Guide.md). -Run the [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README) either against source topologies or against the output representation to evaluate the accuracy of inference. The Accuracy Checker is also part of the [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction), an integrated web-based performance analysis studio. +Run the [Accuracy Checker utility](@ref omz_tools_accuracy_checker) either against source topologies or against the output representation to evaluate the accuracy of inference. The Accuracy Checker is also part of the [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction), an integrated web-based performance analysis studio. Useful documents for model optimization: * [Model Optimizer Developer Guide](MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) * [Intermediate Representation and Opsets](MO_DG/IR_and_opsets.md) * [Custom Layers Guide](HOWTO/Custom_Layers_Guide.md) -* [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README) +* [Accuracy Checker utility](@ref omz_tools_accuracy_checker) * [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction) -* [Model Downloader](@ref omz_tools_downloader_README) utility -* [Pretrained Models (Open Model Zoo)](@ref omz_models_public_index) +* [Model Downloader](@ref omz_tools_downloader) utility +* [Intel's Pretrained Models (Open Model Zoo)](@ref omz_models_group_intel) +* [Public Pretrained Models (Open Model Zoo)](@ref omz_models_group_public) ### Running and Tuning Inference The other core component of OpenVINO™ is the [Inference Engine](IE_DG/Deep_Learning_Inference_Engine_DevGuide.md), which manages the loading and compiling of the optimized neural network model, runs inference operations on input data, and outputs the results. Inference Engine can execute synchronously or asynchronously, and its plugin architecture manages the appropriate compilations for execution on multiple Intel® devices, including both workhorse CPUs and specialized graphics and video processing platforms (see below, Packaging and Deployment). @@ -46,7 +47,7 @@ You can use OpenVINO™ Tuning Utilities with the Inference Engine to trial and For a full browser-based studio integrating these other key tuning utilities, try the [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction). ![](img/OV-diagram-step3.png) -OpenVINO™ toolkit includes a set of [inference code samples](IE_DG/Samples_Overview.md) and [application demos](@ref omz_demos_README) showing how inference is run and output processed for use in retail environments, classrooms, smart camera applications, and other solutions. +OpenVINO™ toolkit includes a set of [inference code samples](IE_DG/Samples_Overview.md) and [application demos](@ref omz_demos) showing how inference is run and output processed for use in retail environments, classrooms, smart camera applications, and other solutions. OpenVINO also makes use of open-Source and Intel™ tools for traditional graphics processing and performance management. Intel® Media SDK supports accelerated rich-media processing, including transcoding. OpenVINO™ optimizes calls to the rich OpenCV and OpenVX libraries for processing computer vision workloads. And the new DL Streamer integration further accelerates video pipelining and performance. @@ -54,7 +55,7 @@ Useful documents for inference tuning: * [Inference Engine Developer Guide](IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) * [Inference Engine API References](./api_references.html) * [Inference Code Samples](IE_DG/Samples_Overview.md) -* [Application Demos](@ref omz_demos_README) +* [Application Demos](@ref omz_demos) * [Post-Training Optimization Tool Guide](@ref pot_README) * [Deep Learning Workbench Guide](@ref workbench_docs_Workbench_DG_Introduction) * [Intel Media SDK](https://github.com/Intel-Media-SDK/MediaSDK) @@ -82,15 +83,15 @@ The Inference Engine's plug-in architecture can be extended to meet other specia Intel® Distribution of OpenVINO™ toolkit includes the following components: - [Deep Learning Model Optimizer](MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) - A cross-platform command-line tool for importing models and preparing them for optimal execution with the Inference Engine. The Model Optimizer imports, converts, and optimizes models, which were trained in popular frameworks, such as Caffe*, TensorFlow*, MXNet*, Kaldi*, and ONNX*. -- [Deep Learning Inference Engine](IE_DG/inference_engine_intro.md) - A unified API to allow high performance inference on many hardware types including Intel® CPU, Intel® Integrated Graphics, Intel® Neural Compute Stick 2, Intel® Vision Accelerator Design with Intel® Movidius™ vision processing unit (VPU). +- [Deep Learning Inference Engine](IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) - A unified API to allow high performance inference on many hardware types including Intel® CPU, Intel® Integrated Graphics, Intel® Neural Compute Stick 2, Intel® Vision Accelerator Design with Intel® Movidius™ vision processing unit (VPU). - [Inference Engine Samples](IE_DG/Samples_Overview.md) - A set of simple console applications demonstrating how to use the Inference Engine in your applications. - [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction) - A web-based graphical environment that allows you to easily use various sophisticated OpenVINO™ toolkit components. - [Post-Training Optimization tool](@ref pot_README) - A tool to calibrate a model and then execute it in the INT8 precision. - Additional Tools - A set of tools to work with your models including [Benchmark App](../inference-engine/tools/benchmark_tool/README.md), [Cross Check Tool](../inference-engine/tools/cross_check_tool/README.md), [Compile tool](../inference-engine/tools/compile_tool/README.md). -- [Open Model Zoo](@ref omz_models_intel_index) - - [Demos](@ref omz_demos_README) - Console applications that provide robust application templates to help you implement specific deep learning scenarios. - - Additional Tools - A set of tools to work with your models including [Accuracy Checker Utility](@ref omz_tools_accuracy_checker_README) and [Model Downloader](@ref omz_tools_downloader_README). - - [Documentation for Pretrained Models](@ref omz_models_intel_index) - Documentation for pretrained models that are available in the [Open Model Zoo repository](https://github.com/opencv/open_model_zoo). +- [Open Model Zoo](@ref omz_models_group_intel) + - [Demos](@ref omz_demos) - Console applications that provide robust application templates to help you implement specific deep learning scenarios. + - Additional Tools - A set of tools to work with your models including [Accuracy Checker Utility](@ref omz_tools_accuracy_checker) and [Model Downloader](@ref omz_tools_downloader). + - [Documentation for Pretrained Models](@ref omz_models_group_intel) - Documentation for pretrained models that are available in the [Open Model Zoo repository](https://github.com/opencv/open_model_zoo). - Deep Learning Streamer (DL Streamer) – Streaming analytics framework, based on GStreamer, for constructing graphs of media analytics components. DL Streamer can be installed by the Intel® Distribution of OpenVINO™ toolkit installer. Its open source version is available on [GitHub](https://github.com/opencv/gst-video-analytics). For the DL Streamer documentation, see: - [DL Streamer Samples](@ref gst_samples_README) - [API Reference](https://openvinotoolkit.github.io/dlstreamer_gst/) diff --git a/docs/install_guides/installing-openvino-apt.md b/docs/install_guides/installing-openvino-apt.md index 812c6195f2c..66518696991 100644 --- a/docs/install_guides/installing-openvino-apt.md +++ b/docs/install_guides/installing-openvino-apt.md @@ -6,6 +6,31 @@ This guide provides installation steps for Intel® Distribution of OpenVINO™ t > **NOTE**: Intel® Graphics Compute Runtime for OpenCL™ is not a part of OpenVINO™ APT distribution. You can install it from the [Intel® Graphics Compute Runtime for OpenCL™ GitHub repo](https://github.com/intel/compute-runtime). +## Included with Runtime Package + +The following components are installed with the OpenVINO runtime package: + +| Component | Description| +|-----------|------------| +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md)| The engine that runs a deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +| [OpenCV*](https://docs.opencv.org/master/) | OpenCV* community version compiled for Intel® hardware. | +| Deep Learning Streamer (DL Streamer) | Streaming analytics framework, based on GStreamer, for constructing graphs of media analytics components. For the DL Streamer documentation, see [DL Streamer Samples](@ref gst_samples_README), [API Reference](https://openvinotoolkit.github.io/dlstreamer_gst/), [Elements](https://github.com/opencv/gst-video-analytics/wiki/Elements), [Tutorial](https://github.com/opencv/gst-video-analytics/wiki/DL%20Streamer%20Tutorial). | + +## Included with Developer Package + +The following components are installed with the OpenVINO developer package: + +| Component | Description| +|-----------|------------| +| [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) | This tool imports, converts, and optimizes models that were trained in popular frameworks to a format usable by Intel tools, especially the Inference Engine. 
Popular frameworks include Caffe\*, TensorFlow\*, MXNet\*, and ONNX\*. | +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) | The engine that runs a deep learning model. It includes a set of libraries for an easy inference integration into your applications.| +| [OpenCV*](https://docs.opencv.org/master/) | OpenCV\* community version compiled for Intel® hardware | +| [Sample Applications](../IE_DG/Samples_Overview.md) | A set of simple console applications demonstrating how to use the Inference Engine in your applications. | +| [Demo Applications](@ref omz_demos) | A set of console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use cases. | +| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader) and other | +| [Documentation for Pre-Trained Models ](@ref omz_models_group_intel) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo). | +| Deep Learning Streamer (DL Streamer) | Streaming analytics framework, based on GStreamer\*, for constructing graphs of media analytics components. For the DL Streamer documentation, see [DL Streamer Samples](@ref gst_samples_README), [API Reference](https://openvinotoolkit.github.io/dlstreamer_gst/), [Elements](https://github.com/opencv/gst-video-analytics/wiki/Elements), [Tutorial](https://github.com/opencv/gst-video-analytics/wiki/DL%20Streamer%20Tutorial). | + ## Set up the Repository ### Install the GPG key for the repository @@ -76,7 +101,7 @@ apt-cache search openvino ## Install the runtime or developer packages using the APT Package Manager Intel® OpenVINO will be installed in: `/opt/intel/openvino_..` -A symlink will be created: `/opt/intel/openvino` +A symlink will be created: `/opt/intel/openvino_` --- ### To Install a specific version diff --git a/docs/install_guides/installing-openvino-docker-linux.md b/docs/install_guides/installing-openvino-docker-linux.md index 7f301c5f795..12eeb0c2831 100644 --- a/docs/install_guides/installing-openvino-docker-linux.md +++ b/docs/install_guides/installing-openvino-docker-linux.md @@ -10,8 +10,8 @@ This guide provides the steps for creating a Docker* image with Intel® Distribu - Ubuntu\* 18.04 long-term support (LTS), 64-bit - Ubuntu\* 20.04 long-term support (LTS), 64-bit -- CentOS\* 7 -- RHEL\* 8 +- CentOS\* 7.6 +- Red Hat* Enterprise Linux* 8.2 (64 bit) **Host Operating Systems** @@ -144,7 +144,7 @@ RUN /bin/mkdir -p '/usr/local/lib' && \ WORKDIR /opt/libusb-1.0.22/ RUN /usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \ - cp /opt/intel/openvino/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \ + cp /opt/intel/openvino_2021/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \ ldconfig ``` - **CentOS 7**: @@ -175,11 +175,11 @@ RUN /bin/mkdir -p '/usr/local/lib' && \ /bin/mkdir -p '/usr/local/include/libusb-1.0' && \ /usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0' && \ /bin/mkdir -p '/usr/local/lib/pkgconfig' && \ - printf "\nexport LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/local/lib\n" >> /opt/intel/openvino/bin/setupvars.sh + printf "\nexport LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/local/lib\n" >> /opt/intel/openvino_2021/bin/setupvars.sh WORKDIR /opt/libusb-1.0.22/ RUN /usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \ - cp /opt/intel/openvino/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \ + cp /opt/intel/openvino_2021/deployment_tools/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/ && \ ldconfig ``` 2. Run the Docker* image: diff --git a/docs/install_guides/installing-openvino-linux-ivad-vpu.md b/docs/install_guides/installing-openvino-linux-ivad-vpu.md index ab2962542d8..cd86804307c 100644 --- a/docs/install_guides/installing-openvino-linux-ivad-vpu.md +++ b/docs/install_guides/installing-openvino-linux-ivad-vpu.md @@ -11,9 +11,9 @@ For Intel® Vision Accelerator Design with Intel® Movidius™ VPUs, the followi 1. Set the environment variables: ```sh -source /opt/intel/openvino/bin/setupvars.sh +source /opt/intel/openvino_2021/bin/setupvars.sh ``` -> **NOTE**: The `HDDL_INSTALL_DIR` variable is set to `/deployment_tools/inference_engine/external/hddl`. If you installed the Intel® Distribution of OpenVINO™ to the default install directory, the `HDDL_INSTALL_DIR` was set to `/opt/intel/openvino//deployment_tools/inference_engine/external/hddl`. +> **NOTE**: The `HDDL_INSTALL_DIR` variable is set to `/deployment_tools/inference_engine/external/hddl`. If you installed the Intel® Distribution of OpenVINO™ to the default install directory, the `HDDL_INSTALL_DIR` was set to `/opt/intel/openvino_2021//deployment_tools/inference_engine/external/hddl`. 2. Install dependencies: ```sh @@ -52,7 +52,7 @@ E: [ncAPI] [ 965618] [MainThread] ncDeviceOpen:677 Failed to find a device, ```sh kill -9 $(pidof hddldaemon autoboot) pidof hddldaemon autoboot # Make sure none of them is alive -source /opt/intel/openvino/bin/setupvars.sh +source /opt/intel/openvino_2021/bin/setupvars.sh ${HDDL_INSTALL_DIR}/bin/bsl_reset ``` diff --git a/docs/install_guides/installing-openvino-linux.md b/docs/install_guides/installing-openvino-linux.md index df4c0413152..955a50a0bae 100644 --- a/docs/install_guides/installing-openvino-linux.md +++ b/docs/install_guides/installing-openvino-linux.md @@ -22,24 +22,24 @@ The Intel® Distribution of OpenVINO™ toolkit for Linux\*: | Component | Description | |-----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) | This tool imports, converts, and optimizes models that were trained in popular frameworks to a format usable by Intel tools, especially the Inference Engine. 
Popular frameworks include Caffe\*, TensorFlow\*, MXNet\*, and ONNX\*. | -| [Inference Engine](../IE_DG/inference_engine_intro.md) | This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) | This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | | Intel® Media SDK | Offers access to hardware accelerated video codecs and frame processing | | [OpenCV](https://docs.opencv.org/master/) | OpenCV\* community version compiled for Intel® hardware | | [Inference Engine Code Samples](../IE_DG/Samples_Overview.md) | A set of simple console applications demonstrating how to utilize specific OpenVINO capabilities in an application and how to perform specific tasks, such as loading a model, running inference, querying specific device capabilities, and more. | -| [Demo Applications](@ref omz_demos_README) | A set of simple console applications that provide robust application templates to help you implement specific deep learning scenarios. | -| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader_README) and other | -| [Documentation for Pre-Trained Models ](@ref omz_models_intel_index) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo). | +| [Demo Applications](@ref omz_demos) | A set of simple console applications that provide robust application templates to help you implement specific deep learning scenarios. | +| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader) and other | +| [Documentation for Pre-Trained Models ](@ref omz_models_group_intel) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo). | | Deep Learning Streamer (DL Streamer) | Streaming analytics framework, based on GStreamer, for constructing graphs of media analytics components. For the DL Streamer documentation, see [DL Streamer Samples](@ref gst_samples_README), [API Reference](https://openvinotoolkit.github.io/dlstreamer_gst/), [Elements](https://github.com/opencv/gst-video-analytics/wiki/Elements), [Tutorial](https://github.com/opencv/gst-video-analytics/wiki/DL%20Streamer%20Tutorial). | **Could Be Optionally Installed** [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction) (DL Workbench) is a platform built upon OpenVINO™ and provides a web-based graphical environment that enables you to optimize, fine-tune, analyze, visualize, and compare performance of deep learning models on various Intel® architecture configurations. In the DL Workbench, you can use most of OpenVINO™ toolkit components: -* [Model Downloader](@ref omz_tools_downloader_README) -* [Intel® Open Model Zoo](@ref omz_models_intel_index) +* [Model Downloader](@ref omz_tools_downloader) +* [Intel® Open Model Zoo](@ref omz_models_group_intel) * [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) * [Post-training Optimization Tool](@ref pot_README) -* [Accuracy Checker](@ref omz_tools_accuracy_checker_README) +* [Accuracy Checker](@ref omz_tools_accuracy_checker) * [Benchmark Tool](../../inference-engine/samples/benchmark_app/README.md) Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_Install_from_Docker_Hub) to get started. @@ -49,7 +49,6 @@ Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_I **Hardware** * 6th to 11th generation Intel® Core™ processors and Intel® Xeon® processors -* Intel® Xeon® processor E family (formerly code named Sandy Bridge, Ivy Bridge, Haswell, and Broadwell) * 3rd generation Intel® Xeon® Scalable processor (formerly code named Cooper Lake) * Intel® Xeon® Scalable processor (formerly Skylake and Cascade Lake) * Intel Atom® processor with support for Intel® Streaming SIMD Extensions 4.1 (Intel® SSE4.1) @@ -67,6 +66,7 @@ Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_I **Operating Systems** - Ubuntu 18.04.x long-term support (LTS), 64-bit +- Ubuntu 20.04.0 long-term support (LTS), 64-bit - CentOS 7.6, 64-bit (for target only) - Yocto Project v3.0, 64-bit (for target only and requires modifications) @@ -415,7 +415,7 @@ trusted-host = mirrors.aliyun.com - [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). - [Inference Engine Developer Guide](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md). - For more information on Sample Applications, see the [Inference Engine Samples Overview](../IE_DG/Samples_Overview.md). -- For information on a set of pre-trained models, see the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index) +- For information on a set of pre-trained models, see the [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel) - For IoT Libraries and Code Samples see the [Intel® IoT Developer Kit](https://github.com/intel-iot-devkit). To learn more about converting models, go to: diff --git a/docs/install_guides/installing-openvino-macos.md b/docs/install_guides/installing-openvino-macos.md index 9489d3a3732..0797d625ca8 100644 --- a/docs/install_guides/installing-openvino-macos.md +++ b/docs/install_guides/installing-openvino-macos.md @@ -24,22 +24,22 @@ The following components are installed by default: | Component | Description | | :-------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) | This tool imports, converts, and optimizes models, which were trained in popular frameworks, to a format usable by Intel tools, especially the Inference Engine.
Popular frameworks include Caffe*, TensorFlow*, MXNet\*, and ONNX\*. | -| [Inference Engine](../IE_DG/inference_engine_intro.md) | This is the engine that runs a deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) | This is the engine that runs a deep learning model. It includes a set of libraries for an easy inference integration into your applications. | | [OpenCV\*](https://docs.opencv.org/master/) | OpenCV\* community version compiled for Intel® hardware | | [Sample Applications](../IE_DG/Samples_Overview.md) | A set of simple console applications demonstrating how to use the Inference Engine in your applications. | -| [Demos](@ref omz_demos_README) | A set of console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases | -| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader_README) and other | -| [Documentation for Pre-Trained Models ](@ref omz_models_intel_index) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo) | +| [Demos](@ref omz_demos) | A set of console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases | +| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader) and other | +| [Documentation for Pre-Trained Models ](@ref omz_models_group_intel) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo) | **Could Be Optionally Installed** [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction) (DL Workbench) is a platform built upon OpenVINO™ and provides a web-based graphical environment that enables you to optimize, fine-tune, analyze, visualize, and compare performance of deep learning models on various Intel® architecture configurations. In the DL Workbench, you can use most of OpenVINO™ toolkit components: -* [Model Downloader](@ref omz_tools_downloader_README) -* [Intel® Open Model Zoo](@ref omz_models_intel_index) +* [Model Downloader](@ref omz_tools_downloader) +* [Intel® Open Model Zoo](@ref omz_models_group_intel) * [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) * [Post-training Optimization Tool](@ref pot_README) -* [Accuracy Checker](@ref omz_tools_accuracy_checker_README) +* [Accuracy Checker](@ref omz_tools_accuracy_checker) * [Benchmark Tool](../../inference-engine/samples/benchmark_app/README.md) Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_Install_from_Docker_Hub) to get started. @@ -53,7 +53,6 @@ The development and target platforms have the same requirements, but you can sel > **NOTE**: The current version of the Intel® Distribution of OpenVINO™ toolkit for macOS* supports inference on Intel CPUs and Intel® Neural Compute Sticks 2 only. * 6th to 11th generation Intel® Core™ processors and Intel® Xeon® processors -* Intel® Xeon® processor E family (formerly code named Sandy Bridge, Ivy Bridge, Haswell, and Broadwell) * 3rd generation Intel® Xeon® Scalable processor (formerly code named Cooper Lake) * Intel® Xeon® Scalable processor (formerly Skylake and Cascade Lake) * Intel® Neural Compute Stick 2 @@ -280,7 +279,7 @@ Follow the steps below to uninstall the Intel® Distribution of OpenVINO™ Tool - To learn more about the verification applications, see `README.txt` in `/opt/intel/openvino_2021/deployment_tools/demo/`. -- For detailed description of the pre-trained models, go to the [Overview of OpenVINO toolkit Pre-Trained Models](@ref omz_models_intel_index) page. +- For detailed description of the pre-trained models, go to the [Overview of OpenVINO toolkit Pre-Trained Models](@ref omz_models_group_intel) page. - More information on [sample applications](../IE_DG/Samples_Overview.md). diff --git a/docs/install_guides/installing-openvino-raspbian.md b/docs/install_guides/installing-openvino-raspbian.md index eade02a472d..0695ef9e772 100644 --- a/docs/install_guides/installing-openvino-raspbian.md +++ b/docs/install_guides/installing-openvino-raspbian.md @@ -18,7 +18,7 @@ The OpenVINO toolkit for Raspbian OS is an archive with pre-installed header fil | Component | Description | | :-------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Inference Engine](../IE_DG/inference_engine_intro.md) | This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) | This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | | [OpenCV\*](https://docs.opencv.org/master/) | OpenCV\* community version compiled for Intel® hardware. | | [Sample Applications](../IE_DG/Samples_Overview.md) | A set of simple console applications demonstrating how to use Intel's Deep Learning Inference Engine in your applications. | @@ -94,12 +94,12 @@ CMake is installed. Continue to the next section to set the environment variable You must update several environment variables before you can compile and run OpenVINO toolkit applications. Run the following script to temporarily set the environment variables: ```sh -source /opt/intel/openvino/bin/setupvars.sh +source /opt/intel/openvino_2021/bin/setupvars.sh ``` **(Optional)** The OpenVINO environment variables are removed when you close the shell. As an option, you can permanently set the environment variables as follows: ```sh -echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bashrc +echo "source /opt/intel/openvino_2021/bin/setupvars.sh" >> ~/.bashrc ``` To test your change, open a new terminal. You will see the following: @@ -118,11 +118,11 @@ Continue to the next section to add USB rules for Intel® Neural Compute Stick 2 Log out and log in for it to take effect. 2. If you didn't modify `.bashrc` to permanently set the environment variables, run `setupvars.sh` again after logging in: ```sh - source /opt/intel/openvino/bin/setupvars.sh + source /opt/intel/openvino_2021/bin/setupvars.sh ``` 3. To perform inference on the Intel® Neural Compute Stick 2, install the USB rules running the `install_NCS_udev_rules.sh` script: ```sh - sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh + sh /opt/intel/openvino_2021/install_dependencies/install_NCS_udev_rules.sh ``` 4. Plug in your Intel® Neural Compute Stick 2. @@ -138,14 +138,13 @@ Follow the next steps to run pre-trained Face Detection network using Inference ``` 2. Build the Object Detection Sample: ```sh - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples/cpp + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino_2021/deployment_tools/inference_engine/samples/cpp ``` - ```sh make -j2 object_detection_sample_ssd ``` 3. Download the pre-trained Face Detection model with the Model Downloader or copy it from the host machine: - ```sh + ```sh git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo cd open_model_zoo/tools/downloader python3 -m pip install -r requirements.in @@ -165,9 +164,9 @@ Read the next topic if you want to learn more about OpenVINO workflow for Raspbe If you want to use your model for inference, the model must be converted to the .bin and .xml Intermediate Representation (IR) files that are used as input by Inference Engine. OpenVINO™ toolkit support on Raspberry Pi only includes the Inference Engine module of the Intel® Distribution of OpenVINO™ toolkit. The Model Optimizer is not supported on this platform. To get the optimized models you can use one of the following options: -* Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader_README). +* Download public and Intel's pre-trained models from the [Open Model Zoo](https://github.com/opencv/open_model_zoo) using [Model Downloader tool](@ref omz_tools_downloader). - For more information on pre-trained models, see [Pre-Trained Models Documentation](@ref omz_models_intel_index) + For more information on pre-trained models, see [Pre-Trained Models Documentation](@ref omz_models_group_intel) * Convert the model using the Model Optimizer from a full installation of Intel® Distribution of OpenVINO™ toolkit on one of the supported platforms. Installation instructions are available: diff --git a/docs/install_guides/installing-openvino-windows.md b/docs/install_guides/installing-openvino-windows.md index 8de98761d15..56e963d1ea4 100644 --- a/docs/install_guides/installing-openvino-windows.md +++ b/docs/install_guides/installing-openvino-windows.md @@ -16,11 +16,10 @@ Your installation is complete when these are all completed: 2. Install the dependencies: - - [Microsoft Visual Studio* with C++ **2019 or 2017** with MSBuild](http://visualstudio.microsoft.com/downloads/) - - [CMake **3.10 or higher** 64-bit](https://cmake.org/download/) - > **NOTE**: If you want to use Microsoft Visual Studio 2019, you are required to install CMake 3.14. + - [Microsoft Visual Studio* 2019 with MSBuild](http://visualstudio.microsoft.com/downloads/) + - [CMake 3.14 or higher 64-bit](https://cmake.org/download/) - [Python **3.6** - **3.8** 64-bit](https://www.python.org/downloads/windows/) - > **IMPORTANT**: As part of this installation, make sure you click the option to add the application to your `PATH` environment variable. + > **IMPORTANT**: As part of this installation, make sure you click the option **[Add Python 3.x to PATH](https://docs.python.org/3/using/windows.html#installation-steps)** to add Python to your `PATH` environment variable. 3. Set Environment Variables @@ -58,22 +57,22 @@ The following components are installed by default: | Component | Description | |:---------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |[Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) |This tool imports, converts, and optimizes models that were trained in popular frameworks to a format usable by Intel tools, especially the Inference Engine.
NOTE: Popular frameworks include such frameworks as Caffe\*, TensorFlow\*, MXNet\*, and ONNX\*. | -|[Inference Engine](../IE_DG/inference_engine_intro.md) |This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +|[Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) |This is the engine that runs the deep learning model. It includes a set of libraries for an easy inference integration into your applications. | |[OpenCV\*](https://docs.opencv.org/master/) |OpenCV* community version compiled for Intel® hardware | |[Inference Engine Samples](../IE_DG/Samples_Overview.md) |A set of simple console applications demonstrating how to use Intel's Deep Learning Inference Engine in your applications. | -| [Demos](@ref omz_demos_README) | A set of console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases | -| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader_README) and other | -| [Documentation for Pre-Trained Models ](@ref omz_models_intel_index) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo) | +| [Demos](@ref omz_demos) | A set of console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases | +| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader) and other | +| [Documentation for Pre-Trained Models ](@ref omz_models_group_intel) | Documentation for the pre-trained models available in the [Open Model Zoo repo](https://github.com/opencv/open_model_zoo) | **Could Be Optionally Installed** [Deep Learning Workbench](@ref workbench_docs_Workbench_DG_Introduction) (DL Workbench) is a platform built upon OpenVINO™ and provides a web-based graphical environment that enables you to optimize, fine-tune, analyze, visualize, and compare performance of deep learning models on various Intel® architecture configurations. In the DL Workbench, you can use most of OpenVINO™ toolkit components: -* [Model Downloader](@ref omz_tools_downloader_README) -* [Intel® Open Model Zoo](@ref omz_models_intel_index) +* [Model Downloader](@ref omz_tools_downloader) +* [Intel® Open Model Zoo](@ref omz_models_group_intel) * [Model Optimizer](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) * [Post-training Optimization Tool](@ref pot_README) -* [Accuracy Checker](@ref omz_tools_accuracy_checker_README) +* [Accuracy Checker](@ref omz_tools_accuracy_checker) * [Benchmark Tool](../../inference-engine/samples/benchmark_app/README.md) Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_Install_from_Docker_Hub) to get started. @@ -83,7 +82,6 @@ Proceed to an [easy installation from Docker](@ref workbench_docs_Workbench_DG_I **Hardware** * 6th to 11th generation Intel® Core™ processors and Intel® Xeon® processors -* Intel® Xeon® processor E family (formerly code named Sandy Bridge, Ivy Bridge, Haswell, and Broadwell) * 3rd generation Intel® Xeon® Scalable processor (formerly code named Cooper Lake) * Intel® Xeon® Scalable processor (formerly Skylake and Cascade Lake) * Intel Atom® processor with support for Intel® Streaming SIMD Extensions 4.1 (Intel® SSE4.1) @@ -134,12 +132,9 @@ The screen example below indicates you are missing two dependencies: You must update several environment variables before you can compile and run OpenVINO™ applications. Open the Command Prompt, and run the `setupvars.bat` batch file to temporarily set your environment variables: ```sh -cd C:\Program Files (x86)\Intel\openvino_2021\bin\ -``` - -```sh -setupvars.bat +"C:\Program Files (x86)\Intel\openvino_2021\bin\setupvars.bat" ``` +> **IMPORTANT**: Windows PowerShell* is not recommended to run the configuration commands, please use the Command Prompt instead. (Optional): OpenVINO toolkit environment variables are removed when you close the Command Prompt window. As an option, you can permanently set the environment variables manually. @@ -314,7 +309,7 @@ Use these steps to update your Windows `PATH` if a command you execute returns a 5. If you need to add CMake to the `PATH`, browse to the directory in which you installed CMake. The default directory is `C:\Program Files\CMake`. -6. If you need to add Python to the `PATH`, browse to the directory in which you installed Python. The default directory is `C:\Users\\AppData\Local\Programs\Python\Python36\Python`. +6. If you need to add Python to the `PATH`, browse to the directory in which you installed Python. The default directory is `C:\Users\\AppData\Local\Programs\Python\Python36\Python`. Note that the `AppData` folder is hidden by default. To view hidden files and folders, see the [Windows 10 instructions](https://support.microsoft.com/en-us/windows/view-hidden-files-and-folders-in-windows-10-97fbc472-c603-9d90-91d0-1166d1d9f4b5). 7. Click **OK** repeatedly to close each screen. @@ -350,11 +345,11 @@ To learn more about converting deep learning models, go to: - [Intel Distribution of OpenVINO Toolkit home page](https://software.intel.com/en-us/openvino-toolkit) - [OpenVINO™ Release Notes](https://software.intel.com/en-us/articles/OpenVINO-RelNotes) -- [Introduction to Inference Engine](../IE_DG/inference_engine_intro.md) +- [Introduction to Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) - [Inference Engine Developer Guide](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md) - [Model Optimizer Developer Guide](../MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) - [Inference Engine Samples Overview](../IE_DG/Samples_Overview.md) -- [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_intel_index) +- [Overview of OpenVINO™ Toolkit Pre-Trained Models](@ref omz_models_group_intel) - [Intel® Neural Compute Stick 2 Get Started](https://software.intel.com/en-us/neural-compute-stick/get-started) diff --git a/docs/install_guides/installing-openvino-yum.md b/docs/install_guides/installing-openvino-yum.md index 5fc6143ae51..27e464d1b84 100644 --- a/docs/install_guides/installing-openvino-yum.md +++ b/docs/install_guides/installing-openvino-yum.md @@ -6,6 +6,18 @@ This guide provides installation steps for the Intel® Distribution of OpenVINO > **NOTE**: Intel® Graphics Compute Runtime for OpenCL™ is not a part of OpenVINO™ YUM distribution. You can install it from the [Intel® Graphics Compute Runtime for OpenCL™ GitHub repo](https://github.com/intel/compute-runtime). +> **NOTE**: Only runtime packages are available via the YUM repository. + +## Included with Runtime Package + +The following components are installed with the OpenVINO runtime package: + +| Component | Description| +|-----------|------------| +| [Inference Engine](../IE_DG/Deep_Learning_Inference_Engine_DevGuide.md)| The engine that runs a deep learning model. It includes a set of libraries for an easy inference integration into your applications. | +| [OpenCV*](https://docs.opencv.org/master/) | OpenCV* community version compiled for Intel® hardware. | +| Deep Learning Stream (DL Streamer) | Streaming analytics framework, based on GStreamer, for constructing graphs of media analytics components. For the DL Streamer documentation, see [DL Streamer Samples](@ref gst_samples_README), [API Reference](https://openvinotoolkit.github.io/dlstreamer_gst/), [Elements](https://github.com/opencv/gst-video-analytics/wiki/Elements), [Tutorial](https://github.com/opencv/gst-video-analytics/wiki/DL%20Streamer%20Tutorial). | + ## Set up the Repository > **NOTE:** You must be logged in as root to set up and install the repository. @@ -61,7 +73,7 @@ Results: intel-openvino-2021 Intel(R) Distribution of OpenVINO 2021 ``` -### To list the available OpenVINO packages +### To list available OpenVINO packages Use the following command: ```sh yum list intel-openvino* @@ -69,11 +81,11 @@ yum list intel-openvino* --- -## Install the runtime packages Using the YUM Package Manager +## Install Runtime Packages Using the YUM Package Manager Intel® OpenVINO will be installed in: `/opt/intel/openvino_..`
-A symlink will be created: `/opt/intel/openvino` +A symlink will be created: `/opt/intel/openvino_` --- diff --git a/docs/install_guides/movidius-setup-guide.md b/docs/install_guides/movidius-setup-guide.md index 421dfbab402..c26ebbda38d 100644 --- a/docs/install_guides/movidius-setup-guide.md +++ b/docs/install_guides/movidius-setup-guide.md @@ -46,7 +46,7 @@ The `hddldaemon` is a system service, a binary executable that is run to manage `` refers to the following default OpenVINO™ Inference Engine directories: - **Linux:** ``` - /opt/intel/openvino/inference_engine + /opt/intel/openvino_2021/inference_engine ``` - **Windows:** ``` diff --git a/docs/install_guides/pypi-openvino-dev.md b/docs/install_guides/pypi-openvino-dev.md index 3da7e3c1088..b8c3dcc3e52 100644 --- a/docs/install_guides/pypi-openvino-dev.md +++ b/docs/install_guides/pypi-openvino-dev.md @@ -13,7 +13,7 @@ OpenVINO™ toolkit is a comprehensive toolkit for quickly developing applicatio | Component | Description | |-----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Model Optimizer](https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html) | This tool imports, converts, and optimizes models that were trained in popular frameworks to a format usable by Intel tools, especially the Inference Engine. 
Popular frameworks include Caffe\*, TensorFlow\*, MXNet\*, and ONNX\*. | -| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](https://docs.openvinotoolkit.org/latest/omz_tools_accuracy_checker_README.html), [Post-Training Optimization Tool](https://docs.openvinotoolkit.org/latest/pot_README.html) | +| Additional Tools | A set of tools to work with your models including [Accuracy Checker utility](https://docs.openvinotoolkit.org/latest/omz_tools_accuracy_checker.html), [Post-Training Optimization Tool](https://docs.openvinotoolkit.org/latest/pot_README.html) | **The Runtime Package Includes the Following Components Installed by Dependency:** diff --git a/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md b/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md index 69411e3f31f..48450817c5b 100644 --- a/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md +++ b/docs/ops/detection/ExperimentalDetectronDetectionOutput_6.md @@ -97,7 +97,7 @@ tensor elements. * *class_agnostic_box_regression* - * **Description**: *class_agnostic_box_regression* attribute ia a flag specifies whether to delete background + * **Description**: *class_agnostic_box_regression* attribute is a flag that specifies whether to delete background classes or not. * **Range of values**: * `true` means background classes should be deleted diff --git a/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md b/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md index 407c4301dc4..2eb40fd6978 100644 --- a/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md +++ b/docs/ops/detection/ExperimentalDetectronROIFeatureExtractor_6.md @@ -136,4 +136,4 @@ must be the same as for 1 input: `[number_of_ROIs, 4]`.
-``` \ No newline at end of file +``` diff --git a/docs/optimization_guide/dldt_optimization_guide.md b/docs/optimization_guide/dldt_optimization_guide.md index 2c13d91d206..87fb3d26b4d 100644 --- a/docs/optimization_guide/dldt_optimization_guide.md +++ b/docs/optimization_guide/dldt_optimization_guide.md @@ -445,7 +445,7 @@ There are important performance caveats though: for example, the tasks that run Also, if the inference is performed on the graphics processing unit (GPU), it can take little gain to do the encoding, for instance, of the resulting video, on the same GPU in parallel, because the device is already busy. -Refer to the [Object Detection SSD Demo](@ref omz_demos_object_detection_demo_ssd_async_README) (latency-oriented Async API showcase) and [Benchmark App Sample](../../inference-engine/samples/benchmark_app/README.md) (which has both latency and throughput-oriented modes) for complete examples of the Async API in action. +Refer to the [Object Detection SSD Demo](@ref omz_demos_object_detection_demo_cpp) (latency-oriented Async API showcase) and [Benchmark App Sample](../../inference-engine/samples/benchmark_app/README.md) (which has both latency and throughput-oriented modes) for complete examples of the Async API in action. ## Using Tools diff --git a/docs/ovsa/ovsa_get_started.md b/docs/ovsa/ovsa_get_started.md index e9062dc7670..19678297eb7 100644 --- a/docs/ovsa/ovsa_get_started.md +++ b/docs/ovsa/ovsa_get_started.md @@ -20,7 +20,7 @@ The OpenVINO™ Security Add-on consists of three components that run in Kernel- - The Model Developer generates a access controlled model from the OpenVINO™ toolkit output. The access controlled model uses the model's Intermediate Representation (IR) files to create a access controlled output file archive that are distributed to Model Users. The Developer can also put the archive file in long-term storage or back it up without additional security. -- The Model Developer uses the OpenVINO™ Security Add-on Tool(`ovsatool`) to generate and manage cryptographic keys and related collateral for the access controlled models. Cryptographic material is only available in a virtual machine (VM) environment. The OpenVINO™ Security Add-on key management system lets the Model Developer to get external Certificate Authorities to generate certificates to add to a key-store. +- The Model Developer uses the OpenVINO™ Security Add-on Tool (ovsatool) to generate and manage cryptographic keys and related collateral for the access controlled models. Cryptographic material is only available in a virtual machine (VM) environment. The OpenVINO™ Security Add-on key management system lets the Model Developer to get external Certificate Authorities to generate certificates to add to a key-store. - The Model Developer generates user-specific licenses in a JSON format file for the access controlled model. The Model Developer can define global or user-specific licenses and attach licensing policies to the licenses. For example, the Model Developer can add a time limit for a model or limit the number of times a user can run a model. @@ -31,7 +31,7 @@ The OpenVINO™ Security Add-on consists of three components that run in Kernel- - The Independent Software Vendor hosts the OpenVINO™ Security Add-on License Service, which responds to license validation requests when a user attempts to load a access controlled model in a model server. The licenses are registered with the OpenVINO™ Security Add-on License Service. -- When a user loads the model, the OpenVINO™ Security Add-on Runtime contacts the License Service to make sure the license is valid and within the parameters that the Model Developer defined with the OpenVINO™ Security Add-on Tool(`ovsatool`). The user must be able to reach the Independent Software Vendor's License Service over the Internet. +- When a user loads the model, the OpenVINO™ Security Add-on Runtime contacts the License Service to make sure the license is valid and within the parameters that the Model Developer defined with the OpenVINO™ Security Add-on Tool (ovsatool). The user must be able to reach the Independent Software Vendor's License Service over the Internet. @@ -51,6 +51,8 @@ After the license is successfully validated, the OpenVINO™ Model Server loads ![Security Add-on Diagram](ovsa_diagram.png) +The binding between SWTPM (vTPM used in guest VM) and HW TPM (TPM on the host) is explained in [this document](https://github.com/openvinotoolkit/security_addon/blob/release_2021_3/docs/fingerprint-changes.md) + ## About the Installation The Model Developer, Independent Software Vendor, and User each must prepare one physical hardware machine and one Kernel-based Virtual Machine (KVM). In addition, each person must prepare a Guest Virtual Machine (Guest VM) for each role that person plays. @@ -248,8 +250,12 @@ See the QEMU documentation for more information about the QEMU network configura Networking is set up on the Host Machine. Continue to the Step 3 to prepare a Guest VM for the combined role of Model Developer and Independent Software Vendor. - -### Step 3: Set Up one Guest VM for the combined roles of Model Developer and Independent Software Vendor +### Step 3: Clone the OpenVINO™ Security Add-on + +Download the [OpenVINO™ Security Add-on](https://github.com/openvinotoolkit/security_addon). + + +### Step 4: Set Up one Guest VM for the combined roles of Model Developer and Independent Software Vendor. For each separate role you play, you must prepare a virtual machine, called a Guest VM. Because in this release, the Model Developer and Independent Software Vendor roles are combined, these instructions guide you to set up one Guest VM, named `ovsa_isv`. @@ -299,15 +305,28 @@ As an option, you can use `virsh` and the virtual machine manager to create and Installation information is at https://github.com/tpm2-software/tpm2-tools/blob/master/INSTALL.md 4. Install the [Docker packages](https://docs.docker.com/engine/install/ubuntu/) 5. Shut down the Guest VM.
-9. On the host, create a directory to support the virtual TPM device. Only `root` should have read/write permission to this directory: +9. On the host, create a directory to support the virtual TPM device and provision its certificates. Only `root` should have read/write permission to this directory: ```sh sudo mkdir -p /var/OVSA/ sudo mkdir /var/OVSA/vtpm sudo mkdir /var/OVSA/vtpm/vtpm_isv_dev + + export XDG_CONFIG_HOME=~/.config + /usr/share/swtpm/swtpm-create-user-config-files + swtpm_setup --tpmstate /var/OVSA/vtpm/vtpm_isv_dev --create-ek-cert --create-platform-cert --overwrite --tpm2 --pcr-banks - ``` **NOTE**: For steps 10 and 11, you can copy and edit the script named `start_ovsa_isv_dev_vm.sh` in the `Scripts/reference` directory in the OpenVINO™ Security Add-on repository instead of manually running the commands. If using the script, select the script with `isv` in the file name regardless of whether you are playing the role of the Model Developer or the role of the Independent Software Vendor. Edit the script to point to the correct directory locations and increment `vnc` for each Guest VM. -10. Start the vTPM on Host: +10. Start the vTPM on Host, write the HW TPM data into its NVRAM and restart the vTPM for QEMU: ```sh + sudo swtpm socket --tpm2 --server port=8280 \ + --ctrl type=tcp,port=8281 \ + --flags not-need-init --tpmstate dir=/var/OVSA/vtpm/vtpm_isv_dev & + + sudo tpm2_startup --clear -T swtpm:port=8280 + sudo tpm2_startup -T swtpm:port=8280 + python3 /Scripts/host/OVSA_write_hwquote_swtpm_nvram.py 8280 + sudo pkill -f vtpm_isv_dev + swtpm socket --tpmstate dir=/var/OVSA/vtpm/vtpm_isv_dev \ --tpm2 \ --ctrl type=unixio,path=/var/OVSA/vtpm/vtpm_isv_dev/swtpm-sock \ @@ -335,9 +354,9 @@ As an option, you can use `virsh` and the virtual machine manager to create and 12. Use a VNC client to log on to the Guest VM at `:1` -### Step 4: Set Up one Guest VM for the User role +### Step 5: Set Up one Guest VM for the User role -1. Choose ONE of these options to create a Guest VM for the User role:
+1. Choose **ONE** of these options to create a Guest VM for the User role:
**Option 1: Copy and Rename the `ovsa_isv_dev_vm_disk.qcow2` disk image** 1. Copy the `ovsa_isv_dev_vm_disk.qcow2` disk image to a new image named `ovsa_runtime_vm_disk.qcow2`. You created the `ovsa_isv_dev_vm_disk.qcow2` disk image in Step 3. 2. Boot the new image. @@ -383,7 +402,7 @@ As an option, you can use `virsh` and the virtual machine manager to create and -netdev tap,id=hostnet1,script=/virbr0-qemu-ifup, downscript=/virbr0-qemu-ifdown \ -vnc :2 ``` - 7. Choose ONE of these options to install additional required software: + 7. Choose **ONE** of these options to install additional required software: **Option 1: Use a script to install additional software** 1. Copy the script `install_guest_deps.sh` from the `Scripts/reference` directory of the OVSA repository to the Guest VM @@ -400,19 +419,32 @@ As an option, you can use `virsh` and the virtual machine manager to create and 4. Install the [Docker packages](https://docs.docker.com/engine/install/ubuntu/) 5. Shut down the Guest VM.

-2. Create a directory to support the virtual TPM device. Only `root` should have read/write permission to this directory: +2. Create a directory to support the virtual TPM device and provision its certificates. Only `root` should have read/write permission to this directory: ```sh sudo mkdir /var/OVSA/vtpm/vtpm_runtime + + export XDG_CONFIG_HOME=~/.config + /usr/share/swtpm/swtpm-create-user-config-files + swtpm_setup --tpmstate /var/OVSA/vtpm/vtpm_runtime --create-ek-cert --create-platform-cert --overwrite --tpm2 --pcr-banks - ``` - **NOTE**: For steps 3 and 4, you can copy and edit the script named `start_ovsa_runtime_vm.sh` in the scripts directory in the OpenVINO™ Security Add-on repository instead of manually running the commands. Edit the script to point to the correct directory locations and increment `vnc` for each Guest VM. This means that if you are creating a third Guest VM on the same Host Machine, change `-vnc :2` to `-vnc :3` -3. Start the vTPM: + **NOTE**: For steps 3 and 4, you can copy and edit the script named `start_ovsa_runtime_vm.sh` in the `Scripts/reference` directory in the OpenVINO™ Security Add-on repository instead of manually running the commands. Edit the script to point to the correct directory locations and increment `vnc` for each Guest VM. This means that if you are creating a third Guest VM on the same Host Machine, change `-vnc :2` to `-vnc :3` +3. Start the vTPM, write the HW TPM data into its NVRAM and restart the vTPM for QEMU: ```sh + sudo swtpm socket --tpm2 --server port=8380 \ + --ctrl type=tcp,port=8381 \ + --flags not-need-init --tpmstate dir=/var/OVSA/vtpm/vtpm_runtime & + + sudo tpm2_startup --clear -T swtpm:port=8380 + sudo tpm2_startup -T swtpm:port=8380 + python3 /Scripts/host/OVSA_write_hwquote_swtpm_nvram.py 8380 + sudo pkill -f vtpm_runtime + swtpm socket --tpmstate dir=/var/OVSA/vtpm/vtpm_runtime \ --tpm2 \ --ctrl type=unixio,path=/var/OVSA/vtpm/vtpm_runtime/swtpm-sock \ --log level=20 ``` -4. Start the Guest VM in a new terminal. To do so, either copy and edit the script named `start_ovsa_runtime_vm.sh` in the scripts directory in the OpenVINO™ Security Add-on repository or manually run the command: +4. Start the Guest VM in a new terminal: ```sh sudo qemu-system-x86_64 \ -cpu host \ @@ -450,13 +482,11 @@ Building OpenVINO™ Security Add-on depends on OpenVINO™ Model Server docker This step is for the combined role of Model Developer and Independent Software Vendor, and the User -1. Download the [OpenVINO™ Security Add-on](https://github.com/openvinotoolkit/security_addon) - -2. Go to the top-level OpenVINO™ Security Add-on source directory. +1. Go to the top-level OpenVINO™ Security Add-on source directory cloned earlier. ```sh cd security_addon ``` -3. Build the OpenVINO™ Security Add-on: +2. Build the OpenVINO™ Security Add-on: ```sh make clean all sudo make package @@ -559,7 +589,7 @@ The Model Hosting components install the OpenVINO™ Security Add-on Runtime Doc This section requires interactions between the Model Developer/Independent Software vendor and the User. All roles must complete all applicable set up steps and installation steps before beginning this section. -This document uses the [face-detection-retail-0004](@ref omz_models_intel_face_detection_retail_0004_description_face_detection_retail_0004) model as an example. +This document uses the [face-detection-retail-0004](@ref omz_models_model_face_detection_retail_0044) model as an example. The following figure describes the interactions between the Model Developer, Independent Software Vendor, and User. @@ -577,7 +607,7 @@ The Model Developer creates model, defines access control and creates the user l ```sh sudo -s cd //OVSA/artefacts - export OVSA_RUNTIME_ARTEFACTS=$PWD + export OVSA_DEV_ARTEFACTS=$PWD source /opt/ovsa/scripts/setupvars.sh ``` 2. Create files to request a certificate:
@@ -622,7 +652,7 @@ This example uses `curl` to download the `face-detection-retail-004` model from ``` 3. Define and enable the model access control and master license: ```sh - /opt/ovsa/bin/ovsatool protect -i model/face-detection-retail-0004.xml model/face-detection-retail-0004.bin -n "face detection" -d "face detection retail" -v 0004 -p face_detection_model.dat -m face_detection_model.masterlic -k isv_keystore -g + /opt/ovsa/bin/ovsatool controlAccess -i model/face-detection-retail-0004.xml model/face-detection-retail-0004.bin -n "face detection" -d "face detection retail" -v 0004 -p face_detection_model.dat -m face_detection_model.masterlic -k isv_keystore -g ``` The Intermediate Representation files for the `face-detection-retail-0004` model are encrypted as `face_detection_model.dat` and a master license is generated as `face_detection_model.masterlic`. @@ -703,6 +733,7 @@ This example uses scp to share data between the ovsa_runtime and ovsa_dev Guest cd $OVSA_RUNTIME_ARTEFACTS scp custkeystore.csr.crt username@://OVSA/artefacts ``` + #### Step 3: Receive and load the access controlled model into the OpenVINO™ Model Server 1. Receive the model as files named * `face_detection_model.dat` @@ -736,14 +767,15 @@ This example uses scp to share data between the ovsa_runtime and ovsa_dev Guest "model_config_list":[ { "config":{ - "name":"protected-model", + "name":"controlled-access-model", "base_path":"/sampleloader/model/fd", - "custom_loader_options": {"loader_name": "ovsa", "keystore": "custkeystore", "protected_file": "face_detection_model"} + "custom_loader_options": {"loader_name": "ovsa", "keystore": "custkeystore", "controlled_access_file": "face_detection_model"} } } ] } ``` + #### Step 4: Start the NGINX Model Server The NGINX Model Server publishes the access controlled model. ```sh @@ -773,11 +805,12 @@ For information about the NGINX interface, see https://github.com/openvinotoolki ```sh curl --create-dirs https://raw.githubusercontent.com/openvinotoolkit/model_server/master/example_client/images/people/people1.jpeg -o images/people1.jpeg ``` + #### Step 6: Run Inference Run the `face_detection.py` script: ```sh -python3 face_detection.py --grpc_port 3335 --batch_size 1 --width 300 --height 300 --input_images_dir images --output_dir results --tls --server_cert server.pem --client_cert client.pem --client_key client.key --model_name protected-model +python3 face_detection.py --grpc_port 3335 --batch_size 1 --width 300 --height 300 --input_images_dir images --output_dir results --tls --server_cert server.pem --client_cert client.pem --client_key client.key --model_name controlled-access-model ``` ## Summary diff --git a/docs/resources/introduction.md b/docs/resources/introduction.md index 6a3c4ccfaa4..4a62ebef562 100644 --- a/docs/resources/introduction.md +++ b/docs/resources/introduction.md @@ -8,14 +8,14 @@ ## Demos -- [Demos](@ref omz_demos_README) +- [Demos](@ref omz_demos) ## Additional Tools -- A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker_README), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader_README) and other +- A set of tools to work with your models including [Accuracy Checker utility](@ref omz_tools_accuracy_checker), [Post-Training Optimization Tool Guide](@ref pot_README), [Model Downloader](@ref omz_tools_downloader) and other ## Pre-Trained Models -- [Intel's Pre-trained Models from Open Model Zoo](@ref omz_models_intel_index) -- [Public Pre-trained Models Available with OpenVINO™ from Open Model Zoo](@ref omz_models_public_index) \ No newline at end of file +- [Intel's Pre-trained Models from Open Model Zoo](@ref omz_models_group_intel) +- [Public Pre-trained Models Available with OpenVINO™ from Open Model Zoo](@ref omz_models_group_public) \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/hello_classification/README.md b/inference-engine/ie_bridges/python/sample/hello_classification/README.md index 730d6a2f0e7..c02725ebd7d 100644 --- a/inference-engine/ie_bridges/python/sample/hello_classification/README.md +++ b/inference-engine/ie_bridges/python/sample/hello_classification/README.md @@ -118,4 +118,4 @@ The sample application logs each step in a standard output stream and outputs to [DataPtr.precision]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1DataPtr.html#data_fields [IECore.load_network]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html#ac9a2e043d14ccfa9c6bbf626cfd69fcc [InputInfoPtr.input_data.shape]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1InputInfoPtr.html#data_fields -[ExecutableNetwork.infer]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1ExecutableNetwork.html#aea96e8e534c8e23d8b257bad11063519 \ No newline at end of file +[ExecutableNetwork.infer]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1ExecutableNetwork.html#aea96e8e534c8e23d8b257bad11063519 diff --git a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md index 4845f031079..2c5dac57b23 100644 --- a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md +++ b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md @@ -117,4 +117,4 @@ The sample application logs each step in a standard output stream and creates an [DataPtr.precision]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1DataPtr.html#data_fields [IECore.load_network]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html#ac9a2e043d14ccfa9c6bbf626cfd69fcc [IENetwork.reshape]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IENetwork.html#a6683f0291db25f908f8d6720ab2f221a -[ExecutableNetwork.infer]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1ExecutableNetwork.html#aea96e8e534c8e23d8b257bad11063519 \ No newline at end of file +[ExecutableNetwork.infer]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1ExecutableNetwork.html#aea96e8e534c8e23d8b257bad11063519 diff --git a/inference-engine/samples/benchmark_app/README.md b/inference-engine/samples/benchmark_app/README.md index d3aa8b5e489..49154897462 100644 --- a/inference-engine/samples/benchmark_app/README.md +++ b/inference-engine/samples/benchmark_app/README.md @@ -128,7 +128,7 @@ If a model has only image input(s), please provide a folder with images or a pat If a model has some specific input(s) (not images), please prepare a binary file(s) that is filled with data of appropriate precision and provide a path to them as input. If a model has mixed input types, input folder should contain all required files. Image inputs are filled with image files one by one. Binary inputs are filled with binary inputs one by one. -To run the tool, you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +To run the tool, you can use [public](@ref omz_models_group_public) or [Intel's](@ref omz_models_group_intel) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader). > **NOTE**: Before running the tool with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > @@ -200,4 +200,4 @@ Below are fragments of sample output for CPU and FPGA devices: ## See Also * [Using Inference Engine Samples](../../../docs/IE_DG/Samples_Overview.md) * [Model Optimizer](../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) -* [Model Downloader](@ref omz_tools_downloader_README) +* [Model Downloader](@ref omz_tools_downloader) diff --git a/inference-engine/tools/benchmark_tool/README.md b/inference-engine/tools/benchmark_tool/README.md index 1c213f67f1f..1eacb8f56ad 100644 --- a/inference-engine/tools/benchmark_tool/README.md +++ b/inference-engine/tools/benchmark_tool/README.md @@ -145,7 +145,7 @@ If a model has only image input(s), please a provide folder with images or a pat If a model has some specific input(s) (not images), please prepare a binary file(s), which is filled with data of appropriate precision and provide a path to them as input. If a model has mixed input types, input folder should contain all required files. Image inputs are filled with image files one by one. Binary inputs are filled with binary inputs one by one. -To run the tool, you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +To run the tool, you can use [public](@ref omz_models_group_public) or [Intel's](@ref omz_models_group_intel) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader). > **NOTE**: Before running the tool with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). @@ -213,4 +213,4 @@ Below are fragments of sample output for CPU and FPGA devices: ## See Also * [Using Inference Engine Samples](../../../docs/IE_DG/Samples_Overview.md) * [Model Optimizer](../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) -* [Model Downloader](@ref omz_tools_downloader_README) +* [Model Downloader](@ref omz_tools_downloader) diff --git a/tools/benchmark/README.md b/tools/benchmark/README.md index 215d16bb47a..280b7a0ef53 100644 --- a/tools/benchmark/README.md +++ b/tools/benchmark/README.md @@ -151,7 +151,7 @@ If a model has only image input(s), please a provide folder with images or a pat If a model has some specific input(s) (not images), please prepare a binary file(s), which is filled with data of appropriate precision and provide a path to them as input. If a model has mixed input types, input folder should contain all required files. Image inputs are filled with image files one by one. Binary inputs are filled with binary inputs one by one. -To run the tool, you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +To run the tool, you can use [public](@ref omz_models_group_public) or [Intel's](@ref omz_models_group_intel) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader). > **NOTE**: Before running the demo with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](./docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). From 068229c8151338f448c29f00ccbc82ce5b42e006 Mon Sep 17 00:00:00 2001 From: Anna Khakimova Date: Mon, 19 Apr 2021 21:11:58 +0300 Subject: [PATCH 10/78] Improve performance of the Resize 3c/3p and Resize 8UC1 (#4945) * scratch buffer * Refactoring horizontal path * * Refactoring horizontal pass. Step2 * * Refactoring horizontal pass. Step 3 * * Refactoring vertical pass. Step2 * Refactoring horizontal pass. Step4 * * Clean * Applied comments. * * Applied comments. Part 2 --- .../ie_preprocess_gapi_kernels_neon.cpp | 232 ++++++++---------- .../ie_preprocess_gapi_kernels.cpp | 6 +- .../ie_preprocess_gapi_kernels_simd_impl.hpp | 145 +++++------ .../thirdparty/ocv/opencv_hal_neon.hpp | 18 ++ 4 files changed, 196 insertions(+), 205 deletions(-) diff --git a/inference-engine/src/preprocessing/arm_neon/ie_preprocess_gapi_kernels_neon.cpp b/inference-engine/src/preprocessing/arm_neon/ie_preprocess_gapi_kernels_neon.cpp index 493ed365e45..779db927c32 100644 --- a/inference-engine/src/preprocessing/arm_neon/ie_preprocess_gapi_kernels_neon.cpp +++ b/inference-engine/src/preprocessing/arm_neon/ie_preprocess_gapi_kernels_neon.cpp @@ -228,20 +228,90 @@ CV_ALWAYS_INLINE void horizontal_anyLPI(std::array, chan } } +CV_ALWAYS_INLINE void vertical_4LPI(const uint8_t* src0[], const uint8_t* src1[], + uchar tmp[], const short beta[], const int length) { + constexpr int nlanes = static_cast(v_uint8::nlanes); + constexpr int half_nlanes = nlanes / 2; + GAPI_Assert(length >= half_nlanes); + + v_int16 b0 = vx_setall_s16(beta[0]); + v_int16 b1 = vx_setall_s16(beta[1]); + v_int16 b2 = vx_setall_s16(beta[2]); + v_int16 b3 = vx_setall_s16(beta[3]); + + v_int16 lo1, hi1, lo2, hi2; + v_int32 res1_s32, res2_s32; + int w = 0; + for (;;) { + for (; w <= length - half_nlanes; w += half_nlanes) { + v_int16 val0_0 = v_reinterpret_as_s16(vx_load_expand(&src0[0][w])); + v_int16 val0_1 = v_reinterpret_as_s16(vx_load_expand(&src0[1][w])); + v_int16 val0_2 = v_reinterpret_as_s16(vx_load_expand(&src0[2][w])); + v_int16 val0_3 = v_reinterpret_as_s16(vx_load_expand(&src0[3][w])); + + v_int16 val1_0 = v_reinterpret_as_s16(vx_load_expand(&src1[0][w])); + v_int16 val1_1 = v_reinterpret_as_s16(vx_load_expand(&src1[1][w])); + v_int16 val1_2 = v_reinterpret_as_s16(vx_load_expand(&src1[2][w])); + v_int16 val1_3 = v_reinterpret_as_s16(vx_load_expand(&src1[3][w])); + + v_int16 t0 = v_mulhrs(v_sub_wrap(val0_0, val1_0), b0); + v_int16 t1 = v_mulhrs(v_sub_wrap(val0_1, val1_1), b1); + v_int16 t2 = v_mulhrs(v_sub_wrap(val0_2, val1_2), b2); + v_int16 t3 = v_mulhrs(v_sub_wrap(val0_3, val1_3), b3); + + v_int16 r0 = v_add_wrap(val1_0, t0); + v_int16 r1 = v_add_wrap(val1_1, t1); + v_int16 r2 = v_add_wrap(val1_2, t2); + v_int16 r3 = v_add_wrap(val1_3, t3); + + v_interleave(r0, r1, lo1, hi1); + v_interleave(r2, r3, lo2, hi2); + + v_int32 lo1_s32 = v_reinterpret_as_s32(lo1); + v_int32 hi1_s32 = v_reinterpret_as_s32(hi1); + v_int32 lo2_s32 = v_reinterpret_as_s32(lo2); + v_int32 hi2_s32 = v_reinterpret_as_s32(hi2); + + v_interleave(lo1_s32, lo2_s32, res1_s32, res2_s32); + + v_int16 res1 = v_reinterpret_as_s16(res1_s32); + v_int16 res2 = v_reinterpret_as_s16(res2_s32); + + v_pack_u_store(&tmp[4 * w + 0], res1); + v_pack_u_store(&tmp[4 * w + half_nlanes], res2); + + v_interleave(hi1_s32, hi2_s32, res1_s32, res2_s32); + + v_int16 res3 = v_reinterpret_as_s16(res1_s32); + v_int16 res4 = v_reinterpret_as_s16(res2_s32); + + v_pack_u_store(&tmp[4 * w + 2*half_nlanes], res3); + v_pack_u_store(&tmp[4 * w + 3*half_nlanes], res4); + } + + if (w < length) { + w = length - half_nlanes; + continue; + } + break; + } +} + template CV_ALWAYS_INLINE void horizontal_4LPI(std::array, chanNum>& dst, - const uchar* tmp, const short mapsx[], - const short clone[], const int length) { + const uchar* tmp, const short mapsx[], const uchar _mask_horizontal[], + const short clone[], + const int length) { constexpr int nlanes = static_cast(v_uint8::nlanes); - const int half_nlanes = nlanes / 2; + constexpr int half_nlanes = nlanes / 2; GAPI_Assert(length >= half_nlanes); const int shift = static_cast(half_nlanes / 4); - uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, 1, 5, 9, 13, 3, 7, 11, 15 }; v_uint8 hmask = vx_load(_mask_horizontal); v_uint8 val_0, val_1, val_2, val_3; + int x = 0; for (;;) { for (; x <= length - half_nlanes && x >= 0; x += half_nlanes) { @@ -315,71 +385,19 @@ CV_ALWAYS_INLINE void calcRowLinear_8UC_Impl_(std::array static_assert(v_uint8::nlanes == 16, "The wide of NEON vector is 128 bits, so one vector contains 16 uchars"); constexpr int nlanes = static_cast(v_uint8::nlanes); - constexpr int half_nlanes = nlanes / 2; bool xRatioEq = inSz.width == outSz.width; bool yRatioEq = inSz.height == outSz.height; if (!xRatioEq && !yRatioEq) { + uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, + 1, 5, 9, 13, 3, 7, 11, 15 }; if (4 == lpi) { // vertical pass - int inLength = inSz.width * chanNum; - GAPI_Assert(inLength >= half_nlanes); - - v_int16 b0 = vx_setall_s16(beta[0]); - v_int16 b1 = vx_setall_s16(beta[1]); - v_int16 b2 = vx_setall_s16(beta[2]); - v_int16 b3 = vx_setall_s16(beta[3]); - - uchar _mask_vertical[nlanes] = { 0, 8, 4, 12, 1, 9, 5, 13, - 2, 10, 6, 14, 3, 11, 7, 15 }; - v_uint8 vmask = vx_load(_mask_vertical); - - int w = 0; - for (;;) { - for (; w <= inLength - half_nlanes && w >= 0; w += half_nlanes) { - v_int16 val0_0 = v_reinterpret_as_s16(vx_load_expand(&src0[0][w])); - v_int16 val0_1 = v_reinterpret_as_s16(vx_load_expand(&src0[1][w])); - v_int16 val0_2 = v_reinterpret_as_s16(vx_load_expand(&src0[2][w])); - v_int16 val0_3 = v_reinterpret_as_s16(vx_load_expand(&src0[3][w])); - - v_int16 val1_0 = v_reinterpret_as_s16(vx_load_expand(&src1[0][w])); - v_int16 val1_1 = v_reinterpret_as_s16(vx_load_expand(&src1[1][w])); - v_int16 val1_2 = v_reinterpret_as_s16(vx_load_expand(&src1[2][w])); - v_int16 val1_3 = v_reinterpret_as_s16(vx_load_expand(&src1[3][w])); - - v_int16 t0 = v_mulhrs(v_sub_wrap(val0_0, val1_0), b0); - v_int16 t1 = v_mulhrs(v_sub_wrap(val0_1, val1_1), b1); - v_int16 t2 = v_mulhrs(v_sub_wrap(val0_2, val1_2), b2); - v_int16 t3 = v_mulhrs(v_sub_wrap(val0_3, val1_3), b3); - - v_int16 r0 = v_add_wrap(val1_0, t0); - v_int16 r1 = v_add_wrap(val1_1, t1); - v_int16 r2 = v_add_wrap(val1_2, t2); - v_int16 r3 = v_add_wrap(val1_3, t3); - - v_uint8 q0 = v_pack_u(r0, r1); - v_uint8 q1 = v_pack_u(r2, r3); - - v_uint8 q2 = v_blend<0xCC /*0b11001100*/>(q0, v_shift_left<4>(q1)); - v_uint8 q3 = v_blend<0xCC /*0b11001100*/>(v_shift_right<4>(q0), q1); - - v_uint8 q4 = v_shuffle(q2, vmask); - v_uint8 q5 = v_shuffle(q3, vmask); - - vx_store(&tmp[4 * w + 0], q4); - vx_store(&tmp[4 * w + 2 * half_nlanes], q5); - } - - if (w < inLength) { - w = inLength - half_nlanes; - continue; - } - break; - } + vertical_4LPI(src0, src1, tmp, beta, inSz.width * chanNum); // horizontal pass - horizontal_4LPI(dst, tmp, mapsx, clone, outSz.width); + horizontal_4LPI(dst, tmp, mapsx, _mask_horizontal, clone, outSz.width); } else { // if any lpi int inLength = inSz.width * chanNum; @@ -397,6 +415,8 @@ CV_ALWAYS_INLINE void calcRowLinear_8UC_Impl_(std::array } } else if (!xRatioEq) { GAPI_DbgAssert(yRatioEq); + uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, + 1, 5, 9, 13, 3, 7, 11, 15 }; if (4 == lpi) { int inLength = inSz.width * chanNum; @@ -422,7 +442,7 @@ CV_ALWAYS_INLINE void calcRowLinear_8UC_Impl_(std::array } // horizontal pass - horizontal_4LPI(dst, tmp, mapsx, clone, outSz.width); + horizontal_4LPI(dst, tmp, mapsx, _mask_horizontal, clone, outSz.width); } else { // any LPI for (int l = 0; l < lpi; ++l) { const uchar* src = src0[l]; @@ -469,9 +489,8 @@ void calcRowLinear_8U(C3, std::array, 3>& dst, const Size& inSz, const Size& outSz, const int lpi) { - constexpr int chanNum = 3; - calcRowLinear_8UC_Impl_(dst, src0, src1, alpha, clone, mapsx, - beta, tmp, inSz, outSz, lpi); + calcRowLinear_8UC_Impl_<3>(dst, src0, src1, alpha, clone, mapsx, + beta, tmp, inSz, outSz, lpi); } // Resize (bi-linear, 8UC4) @@ -486,20 +505,18 @@ void calcRowLinear_8U(C4, std::array, 4>& dst, const Size& inSz, const Size& outSz, const int lpi) { - constexpr int chanNum = 4; - calcRowLinear_8UC_Impl_(dst, src0, src1, alpha, clone, mapsx, - beta, tmp, inSz, outSz, lpi); + calcRowLinear_8UC_Impl_<4>(dst, src0, src1, alpha, clone, mapsx, + beta, tmp, inSz, outSz, lpi); } CV_ALWAYS_INLINE void horizontal_4LPI(uint8_t* dst[], const uchar* tmp, const short mapsx[], + const uchar _mask_horizontal[], const short clone[], const int length) { constexpr int nlanes = static_cast(v_uint8::nlanes); - const int half_nlanes = nlanes / 2; + constexpr int half_nlanes = nlanes / 2; GAPI_Assert(length >= half_nlanes); - uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, - 1, 5, 9, 13, 3, 7, 11, 15 }; v_uint8 hmask = vx_load(_mask_horizontal); int x = 0; for (;;) { @@ -557,12 +574,11 @@ CV_ALWAYS_INLINE void horizontal_4LPI(uint8_t* dst[], } } -CV_ALWAYS_INLINE void horizontal_anyLPI(uint8_t* dst[], +CV_ALWAYS_INLINE void horizontal_anyLPI(uint8_t* dst, const uchar* src, const short mapsx[], - const short alpha[], const int length, - const int line) { + const short alpha[], const int length) { constexpr int nlanes = static_cast(v_uint8::nlanes); - const int half_nlanes = nlanes / 2; + constexpr int half_nlanes = nlanes / 2; GAPI_Assert(length >= half_nlanes); v_int16 t0, t1; int x = 0; @@ -573,7 +589,7 @@ CV_ALWAYS_INLINE void horizontal_anyLPI(uint8_t* dst[], v_deinterleave_expand(t, t0, t1); v_int16 d = v_mulhrs(t0 - t1, a0) + t1; - v_pack_u_store(&dst[line][x], d); + v_pack_u_store(&dst[x], d); } if (x < length) { @@ -608,79 +624,34 @@ void calcRowLinear_8UC1(uint8_t* dst[], if (!xRatioEq && !yRatioEq) { GAPI_Assert(inSz.width >= half_nlanes); + uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, + 1, 5, 9, 13, 3, 7, 11, 15 }; if (4 == lpi) { // vertical pass - v_int16 b0 = vx_setall_s16(beta[0]); - v_int16 b1 = vx_setall_s16(beta[1]); - v_int16 b2 = vx_setall_s16(beta[2]); - v_int16 b3 = vx_setall_s16(beta[3]); - - uchar _mask_vertical[nlanes] = { 0, 8, 4, 12, 1, 9, 5, 13, - 2, 10, 6, 14, 3, 11, 7, 15 }; - v_uint8 vmask = vx_load(_mask_vertical); - - int w = 0; - for (;;) { - for (; w <= inSz.width - half_nlanes; w += half_nlanes) { - v_int16 val0_0 = v_reinterpret_as_s16(vx_load_expand(&src0[0][w])); - v_int16 val0_1 = v_reinterpret_as_s16(vx_load_expand(&src0[1][w])); - v_int16 val0_2 = v_reinterpret_as_s16(vx_load_expand(&src0[2][w])); - v_int16 val0_3 = v_reinterpret_as_s16(vx_load_expand(&src0[3][w])); - - v_int16 val1_0 = v_reinterpret_as_s16(vx_load_expand(&src1[0][w])); - v_int16 val1_1 = v_reinterpret_as_s16(vx_load_expand(&src1[1][w])); - v_int16 val1_2 = v_reinterpret_as_s16(vx_load_expand(&src1[2][w])); - v_int16 val1_3 = v_reinterpret_as_s16(vx_load_expand(&src1[3][w])); - - v_int16 t0 = v_mulhrs(v_sub_wrap(val0_0, val1_0), b0); - v_int16 t1 = v_mulhrs(v_sub_wrap(val0_1, val1_1), b1); - v_int16 t2 = v_mulhrs(v_sub_wrap(val0_2, val1_2), b2); - v_int16 t3 = v_mulhrs(v_sub_wrap(val0_3, val1_3), b3); - - v_int16 r0 = v_add_wrap(val1_0, t0); - v_int16 r1 = v_add_wrap(val1_1, t1); - v_int16 r2 = v_add_wrap(val1_2, t2); - v_int16 r3 = v_add_wrap(val1_3, t3); - - v_uint8 q0 = v_pack_u(r0, r1); - v_uint8 q1 = v_pack_u(r2, r3); - - v_uint8 q2 = v_blend<0xCC /*0b11001100*/>(q0, v_shift_left<4>(q1)); - v_uint8 q3 = v_blend<0xCC /*0b11001100*/>(v_shift_right<4>(q0), q1); - - v_uint8 q4 = v_shuffle(q2, vmask); - v_uint8 q5 = v_shuffle(q3, vmask); - - vx_store(&tmp[4 * w + 0], q4); - vx_store(&tmp[4 * w + 2 * half_nlanes], q5); - } - - if (w < inSz.width) { - w = inSz.width - half_nlanes; - continue; - } - break; - } + vertical_4LPI(src0, src1, tmp, beta, inSz.width); // horizontal pass - horizontal_4LPI(dst, tmp, mapsx, clone, outSz.width); + horizontal_4LPI(dst, tmp, mapsx, _mask_horizontal, clone, outSz.width); } else { // if any lpi for (int l = 0; l < lpi; ++l) { short beta0 = beta[l]; const uchar* s0 = src0[l]; const uchar* s1 = src1[l]; + uchar* _dst = dst[l]; // vertical pass vertical_anyLPI(s0, s1, tmp, inSz.width, beta0); // horizontal pass - horizontal_anyLPI(dst, tmp, mapsx, alpha, outSz.width, l); + horizontal_anyLPI(_dst, tmp, mapsx, alpha, outSz.width); } } // if lpi == 4 } else if (!xRatioEq) { GAPI_DbgAssert(yRatioEq); GAPI_Assert(inSz.width >= nlanes); + uchar _mask_horizontal[nlanes] = { 0, 4, 8, 12, 2, 6, 10, 14, + 1, 5, 9, 13, 3, 7, 11, 15 }; if (4 == lpi) { // vertical pass @@ -702,14 +673,15 @@ void calcRowLinear_8UC1(uint8_t* dst[], } // horizontal pass - horizontal_4LPI(dst, tmp, mapsx, clone, outSz.width); + horizontal_4LPI(dst, tmp, mapsx, _mask_horizontal, clone, outSz.width); } else { // any LPI GAPI_Assert(outSz.width >= half_nlanes); for (int l = 0; l < lpi; ++l) { const uchar* src = src0[l]; + uchar* _dst = dst[l]; // horizontal pass - horizontal_anyLPI(dst, src, mapsx, alpha, outSz.width, l); + horizontal_anyLPI(_dst, src, mapsx, alpha, outSz.width); } } diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp index 0e49f4116ec..2b4c53f4d9a 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp @@ -895,7 +895,7 @@ struct linearScratchDesc { tmp = reinterpret_cast (mapsy + outH*2); } - static int bufSize(int inW, int inH, int outW, int outH, int lpi) { + static int bufSize(int inW, int /*inH*/, int outW, int outH, int lpi) { auto size = outW * sizeof(alpha_t) + outW * sizeof(alpha_t) * 4 + // alpha clones // previous alpha is redundant? outW * sizeof(index_t) + @@ -910,7 +910,7 @@ struct linearScratchDesc { template static void initScratchLinear(const cv::GMatDesc& in, const Size& outSz, - cv::gapi::fluid::Buffer& scratch, + cv::gapi::fluid::Buffer& scratch, int lpi) { using alpha_type = typename Mapper::alpha_type; static const auto unity = Mapper::unity; @@ -1171,7 +1171,7 @@ static void calcRowLinear(const cv::gapi::fluid::View & in, template static void calcRowLinearC(const cv::gapi::fluid::View & in, std::array, numChan>& out, - cv::gapi::fluid::Buffer& scratch) { + cv::gapi::fluid::Buffer& scratch) { using alpha_type = typename Mapper::alpha_type; auto inSz = in.meta().size; diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_simd_impl.hpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_simd_impl.hpp index 3a68bd4a980..a59111b86b6 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_simd_impl.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_simd_impl.hpp @@ -18,12 +18,12 @@ namespace gapi { namespace kernels { -inline void mergeRow_8UC2_Impl(const uint8_t in0[], const uint8_t in1[], - uint8_t out[], int length) { +CV_ALWAYS_INLINE void mergeRow_8UC2_Impl(const uint8_t in0[], const uint8_t in1[], + uint8_t out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -46,12 +46,12 @@ inline void mergeRow_8UC2_Impl(const uint8_t in0[], const uint8_t in1[], } } -inline void mergeRow_8UC3_Impl(const uint8_t in0[], const uint8_t in1[], - const uint8_t in2[], uint8_t out[], int length) { +CV_ALWAYS_INLINE void mergeRow_8UC3_Impl(const uint8_t in0[], const uint8_t in1[], + const uint8_t in2[], uint8_t out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -75,12 +75,13 @@ inline void mergeRow_8UC3_Impl(const uint8_t in0[], const uint8_t in1[], } } -inline void mergeRow_8UC4_Impl(const uint8_t in0[], const uint8_t in1[], const uint8_t in2[], - const uint8_t in3[], uint8_t out[], int length) { +CV_ALWAYS_INLINE void mergeRow_8UC4_Impl(const uint8_t in0[], const uint8_t in1[], + const uint8_t in2[], const uint8_t in3[], + uint8_t out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -106,12 +107,12 @@ inline void mergeRow_8UC4_Impl(const uint8_t in0[], const uint8_t in1[], const u } } -inline void mergeRow_32FC2_Impl(const float in0[], const float in1[], - float out[], int length) { +CV_ALWAYS_INLINE void mergeRow_32FC2_Impl(const float in0[], const float in1[], + float out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -133,12 +134,12 @@ inline void mergeRow_32FC2_Impl(const float in0[], const float in1[], } } -inline void mergeRow_32FC3_Impl(const float in0[], const float in1[], const float in2[], - float out[], int length) { +CV_ALWAYS_INLINE void mergeRow_32FC3_Impl(const float in0[], const float in1[], const float in2[], + float out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -162,13 +163,13 @@ inline void mergeRow_32FC3_Impl(const float in0[], const float in1[], const floa } } -inline void mergeRow_32FC4_Impl(const float in0[], const float in1[], - const float in2[], const float in3[], - float out[], int length) { +CV_ALWAYS_INLINE void mergeRow_32FC4_Impl(const float in0[], const float in1[], + const float in2[], const float in3[], + float out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -196,12 +197,12 @@ inline void mergeRow_32FC4_Impl(const float in0[], const float in1[], //------------------------------------------------------------------------------ -inline void splitRow_8UC2_Impl(const uint8_t in[], uint8_t out0[], - uint8_t out1[], int length) { +CV_ALWAYS_INLINE void splitRow_8UC2_Impl(const uint8_t in[], uint8_t out0[], + uint8_t out1[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -223,12 +224,12 @@ inline void splitRow_8UC2_Impl(const uint8_t in[], uint8_t out0[], } } -inline void splitRow_8UC3_Impl(const uint8_t in[], uint8_t out0[], - uint8_t out1[], uint8_t out2[], int length) { +CV_ALWAYS_INLINE void splitRow_8UC3_Impl(const uint8_t in[], uint8_t out0[], + uint8_t out1[], uint8_t out2[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -252,12 +253,12 @@ inline void splitRow_8UC3_Impl(const uint8_t in[], uint8_t out0[], } } -inline void splitRow_8UC4_Impl(const uint8_t in[], uint8_t out0[], uint8_t out1[], - uint8_t out2[], uint8_t out3[], int length) { +CV_ALWAYS_INLINE void splitRow_8UC4_Impl(const uint8_t in[], uint8_t out0[], uint8_t out1[], + uint8_t out2[], uint8_t out3[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -283,12 +284,12 @@ inline void splitRow_8UC4_Impl(const uint8_t in[], uint8_t out0[], uint8_t out1[ } } -inline void splitRow_32FC2_Impl(const float in[], float out0[], +CV_ALWAYS_INLINE void splitRow_32FC2_Impl(const float in[], float out0[], float out1[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -311,12 +312,12 @@ inline void splitRow_32FC2_Impl(const float in[], float out0[], } } -inline void splitRow_32FC3_Impl(const float in[], float out0[], float out1[], - float out2[], int length) { +CV_ALWAYS_INLINE void splitRow_32FC3_Impl(const float in[], float out0[], float out1[], + float out2[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -340,12 +341,12 @@ inline void splitRow_32FC3_Impl(const float in[], float out0[], float out1[], } } -inline void splitRow_32FC4_Impl(const float in[], float out0[], float out1[], - float out2[], float out3[], int length) { +CV_ALWAYS_INLINE void splitRow_32FC4_Impl(const float in[], float out0[], float out1[], + float out2[], float out3[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; cycle: for (; l <= length - nlanes; l += nlanes) { @@ -380,7 +381,7 @@ static const int ITUR_BT_601_CVG = -852492; static const int ITUR_BT_601_CVR = 1673527; static const int ITUR_BT_601_SHIFT = 20; -static inline void uvToRGBuv(const uchar u, const uchar v, int& ruv, int& guv, int& buv) { +CV_ALWAYS_INLINE void uvToRGBuv(const uchar u, const uchar v, int& ruv, int& guv, int& buv) { int uu, vv; uu = static_cast(u) - 128; vv = static_cast(v) - 128; @@ -390,9 +391,9 @@ static inline void uvToRGBuv(const uchar u, const uchar v, int& ruv, int& guv, i buv = (1 << (ITUR_BT_601_SHIFT - 1)) + ITUR_BT_601_CUB * uu; } -static inline void uvToRGBuv(const v_uint8& u, const v_uint8& v, - v_int32 (&ruv)[4], v_int32 (&guv)[4], - v_int32 (&buv)[4]) { +CV_ALWAYS_INLINE void uvToRGBuv(const v_uint8& u, const v_uint8& v, + v_int32 (&ruv)[4], v_int32 (&guv)[4], + v_int32 (&buv)[4]) { v_uint8 v128 = vx_setall_u8(128); v_int8 su = v_reinterpret_as_s8(v_sub_wrap(u, v128)); v_int8 sv = v_reinterpret_as_s8(v_sub_wrap(v, v128)); @@ -417,8 +418,8 @@ static inline void uvToRGBuv(const v_uint8& u, const v_uint8& v, } } -static inline void yRGBuvToRGB(const uchar vy, const int ruv, const int guv, const int buv, - uchar& r, uchar& g, uchar& b) { +CV_ALWAYS_INLINE void yRGBuvToRGB(const uchar vy, const int ruv, const int guv, + const int buv, uchar& r, uchar& g, uchar& b) { int yy = static_cast(vy); int y = std::max(0, yy - 16) * ITUR_BT_601_CY; r = saturate_cast((y + ruv) >> ITUR_BT_601_SHIFT); @@ -426,11 +427,11 @@ static inline void yRGBuvToRGB(const uchar vy, const int ruv, const int guv, con b = saturate_cast((y + buv) >> ITUR_BT_601_SHIFT); } -static inline void yRGBuvToRGB(const v_uint8& vy, - const v_int32 (&ruv)[4], - const v_int32 (&guv)[4], - const v_int32 (&buv)[4], - v_uint8& rr, v_uint8& gg, v_uint8& bb) { +CV_ALWAYS_INLINE void yRGBuvToRGB(const v_uint8& vy, + const v_int32 (&ruv)[4], + const v_int32 (&guv)[4], + const v_int32 (&buv)[4], + v_uint8& rr, v_uint8& gg, v_uint8& bb) { v_uint8 v16 = vx_setall_u8(16); v_uint8 posY = vy - v16; v_uint16 yy0, yy1; @@ -463,15 +464,14 @@ static inline void yRGBuvToRGB(const v_uint8& vy, bb = v_pack_u(b0, b1); } -inline void calculate_nv12_to_rgb_impl(const uchar **srcY, - const uchar *srcUV, - uchar **dstRGBx, - int width) { +CV_ALWAYS_INLINE void calculate_nv12_to_rgb_impl(const uchar **srcY, + const uchar *srcUV, + uchar **dstRGBx, + int width) { int i = 0; #if MANUAL_SIMD - - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; for ( ; i <= width - 2*nlanes; i += 2*nlanes) { v_uint8 u, v; @@ -535,14 +535,13 @@ inline void calculate_nv12_to_rgb_impl(const uchar **srcY, } } -inline void calculate_i420_to_rgb_impl(const uchar **srcY, const uchar *srcU, - const uchar *srcV, uchar **dstRGBx, - int width) { +CV_ALWAYS_INLINE void calculate_i420_to_rgb_impl(const uchar **srcY, const uchar *srcU, + const uchar *srcV, uchar **dstRGBx, + int width) { int i = 0; #if MANUAL_SIMD - - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; for ( ; i <= width - 2*nlanes; i += 2*nlanes) { v_uint8 u = vx_load(srcU + i/2); @@ -610,8 +609,8 @@ inline void calculate_i420_to_rgb_impl(const uchar **srcY, const uchar *srcU, // vertical pass template -static inline void downy(const T *src[], int inWidth, const MapperUnit& ymap, A yalpha, - W vbuf[]) { +CV_ALWAYS_INLINE void downy(const T *src[], int inWidth, const MapperUnit& ymap, + A yalpha, W vbuf[]) { int y_1st = ymap.index0; int ylast = ymap.index1 - 1; @@ -619,7 +618,7 @@ static inline void downy(const T *src[], int inWidth, const MapperUnit& ym GAPI_DbgAssert(y_1st < ylast); #if MANUAL_SIMD - const int nlanes = v_uint16::nlanes; + constexpr int nlanes = v_uint16::nlanes; #endif // 1st and last rows @@ -667,8 +666,8 @@ static inline void downy(const T *src[], int inWidth, const MapperUnit& ym // horizontal pass template -static inline void downx(T dst[], int outWidth, int xmaxdf, const I xindex[], - const A xalpha[], const W vbuf[]) { +CV_ALWAYS_INLINE void downx(T dst[], int outWidth, int xmaxdf, const I xindex[], + const A xalpha[], const W vbuf[]) { // TO DO: try lambda here #define HSUM(xmaxdf) \ for (int x = 0; x < outWidth; x++) { \ @@ -704,9 +703,11 @@ static inline void downx(T dst[], int outWidth, int xmaxdf, const I xindex[], } template -static void calcRowArea_impl(T dst[], const T *src[], const Size& inSz, const Size& outSz, - A yalpha, const MapperUnit& ymap, int xmaxdf, const I xindex[], const A xalpha[], - W vbuf[]) { +CV_ALWAYS_INLINE void calcRowArea_impl(T dst[], const T *src[], const Size& inSz, + const Size& outSz, A yalpha, + const MapperUnit& ymap, int xmaxdf, + const I xindex[], const A xalpha[], + W vbuf[]) { bool xRatioEq1 = inSz.width == outSz.width; bool yRatioEq1 = inSz.height == outSz.height; @@ -738,18 +739,18 @@ static void calcRowArea_impl(T dst[], const T *src[], const Size& inSz, const Si #if MANUAL_SIMD template -void copyRow_impl(const T in[], T out[], int l) { +CV_ALWAYS_INLINE void copyRow_impl(const T in[], T out[], int l) { VecT r; r = vx_load(&in[l]); vx_store(&out[l], r); } #endif -inline void copyRow_8U_impl(const uint8_t in[], uint8_t out[], int length) { +CV_ALWAYS_INLINE void copyRow_8U_impl(const uint8_t in[], uint8_t out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_uint8::nlanes; + constexpr int nlanes = v_uint8::nlanes; for (; l <= length - nlanes; l += nlanes) { copyRow_impl(in, out, l); @@ -766,11 +767,11 @@ inline void copyRow_8U_impl(const uint8_t in[], uint8_t out[], int length) { } } -inline void copyRow_32F_impl(const float in[], float out[], int length) { +CV_ALWAYS_INLINE void copyRow_32F_impl(const float in[], float out[], int length) { int l = 0; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; for (; l <= length - nlanes; l += nlanes) { copyRow_impl(in, out, l); @@ -801,7 +802,7 @@ CV_ALWAYS_INLINE void calcRowLinear_32FC1(float *dst[], bool yRatioEq1 = inSz.height == outSz.height; #if MANUAL_SIMD - const int nlanes = v_float32::nlanes; + constexpr int nlanes = v_float32::nlanes; #endif if (!xRatioEq1 && !yRatioEq1) { diff --git a/inference-engine/thirdparty/ocv/opencv_hal_neon.hpp b/inference-engine/thirdparty/ocv/opencv_hal_neon.hpp index 9c005626572..83d561d2115 100644 --- a/inference-engine/thirdparty/ocv/opencv_hal_neon.hpp +++ b/inference-engine/thirdparty/ocv/opencv_hal_neon.hpp @@ -2606,6 +2606,24 @@ CV_ALWAYS_INLINE v_uint8x16 v_interleave_high(const v_uint8x16& a, const v_uint8 return v_uint8x16(v); } +CV_ALWAYS_INLINE void v_interleave(const v_int16x8& a, const v_int16x8& b, + v_int16x8& v1, v_int16x8& v2) +{ + int16x8x2_t p = vzipq_s16(a.val, b.val); + v1.val = p.val[0]; + v2.val = p.val[1]; + return; +} + +CV_ALWAYS_INLINE void v_interleave(const v_int32x4& a, const v_int32x4& b, + v_int32x4& v1, v_int32x4& v2) +{ + int32x4x2_t p = vzipq_s32(a.val, b.val); + v1.val = p.val[0]; + v2.val = p.val[1]; + return; +} + template CV_ALWAYS_INLINE v_uint8x16 v_slli_si128(const v_uint8x16& a) { From ce0e2881c75f98e89636b205fcd40f614a6d3128 Mon Sep 17 00:00:00 2001 From: Vladislav Volkov Date: Mon, 19 Apr 2021 22:17:44 +0300 Subject: [PATCH 11/78] [CPU] Fix for memory leak in oneDNN gemm implementation (#5285) --- inference-engine/thirdparty/mkl-dnn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/thirdparty/mkl-dnn b/inference-engine/thirdparty/mkl-dnn index 1225fbbaef7..0813c00df75 160000 --- a/inference-engine/thirdparty/mkl-dnn +++ b/inference-engine/thirdparty/mkl-dnn @@ -1 +1 @@ -Subproject commit 1225fbbaef7a1c743cdb15dd45046975bdce0452 +Subproject commit 0813c00df7558bc9b858d3a73c725bab2ce1b1eb From e0187da0097cec144f1218097628b74e73a02333 Mon Sep 17 00:00:00 2001 From: Alexey Varyzgin Date: Mon, 19 Apr 2021 23:39:37 +0300 Subject: [PATCH 12/78] [CPU] An input 'sequence_length' values check was added to CTCGreedyDecoderSeqLen (#5284) --- .../nodes/ctc_greedy_decoder_seq_len.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/mkldnn_plugin/nodes/ctc_greedy_decoder_seq_len.cpp b/inference-engine/src/mkldnn_plugin/nodes/ctc_greedy_decoder_seq_len.cpp index 80b044a1ec7..69a97b2483f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/ctc_greedy_decoder_seq_len.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/ctc_greedy_decoder_seq_len.cpp @@ -15,7 +15,7 @@ namespace Cpu { class CTCGreedyDecoderSeqLenImpl: public ExtLayerBase { public: explicit CTCGreedyDecoderSeqLenImpl(const CNNLayer* layer) : mergeRepeated_(true) { - std::string errPrefix = "CTCGreedyDecoderSeqLen layer with name '" + layer->name + "' "; + errPrefix = "CTCGreedyDecoderSeqLen layer with name '" + layer->name + "' "; if (layer->insData.size() < 2 || layer->insData.size() > 3) IE_THROW() << errPrefix << "has invalid number of input edges: " << layer->insData.size(); if (layer->outData.size() != 2) @@ -75,6 +75,16 @@ public: size_t workAmount = 0; for (size_t b = 0; b < B; b++) { + if (sequenceLengths[b] > T) { + if (resp) { + std::string errorMsg = errPrefix + + ". Sequence length " + std::to_string(sequenceLengths[b]) + + " cannot be greater than according decoded classes dimension size " + + std::to_string(outputs[DECODED_CLASSES_INDEX]->getTensorDesc().getDims()[1]); + errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); + } + return PARAMETER_MISMATCH; + } workAmount += sequenceLengths[b]; } // Parallelization could not be made directly by T due to output index depends on merged classes and @@ -153,6 +163,7 @@ private: const size_t DECODED_CLASSES_INDEX = 0lu; const size_t DECODED_CLASSES_LENGTH_INDEX = 1lu; bool mergeRepeated_; + std::string errPrefix; }; REG_FACTORY_FOR(CTCGreedyDecoderSeqLenImpl, CTCGreedyDecoderSeqLen); From 1f0b55be048518cc50f15dab165f9364ace5b8f3 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Tue, 20 Apr 2021 06:58:26 +0300 Subject: [PATCH 13/78] fixed error with PerfCounters (#5300) --- ngraph/core/src/pass/graph_rewrite.cpp | 4 ++-- ngraph/core/src/pass/manager.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ngraph/core/src/pass/graph_rewrite.cpp b/ngraph/core/src/pass/graph_rewrite.cpp index 75798fcec8e..5c92e9760e9 100644 --- a/ngraph/core/src/pass/graph_rewrite.cpp +++ b/ngraph/core/src/pass/graph_rewrite.cpp @@ -62,7 +62,7 @@ namespace ngraph { namespace { - PerfCounters& perf_counters() + PerfCounters& perf_counters_graph_rewrite() { static PerfCounters counters; return counters; @@ -410,7 +410,7 @@ void ngraph::pass::MatcherPass::register_matcher(const std::shared_ptr node) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, pass::perf_counters()[get_type_info()]); + OV_ITT_SCOPED_TASK(itt::domains::nGraph, pass::perf_counters_graph_rewrite()[get_type_info()]); m_new_nodes.clear(); if (m_handler) return m_handler(node); diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index aefcb51d77d..b5b1a460aa5 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -31,7 +31,7 @@ namespace ngraph { namespace { - PerfCounters& perf_counters() + PerfCounters& perf_counters_manager() { static PerfCounters counters; return counters; @@ -73,7 +73,7 @@ void pass::Manager::run_passes(shared_ptr func) } OV_ITT_SCOPED_TASK(itt::domains::nGraphPass_LT, - pass::perf_counters()[pass->get_type_info()]); + pass::perf_counters_manager()[pass->get_type_info()]); pass_timer.start(); From f2306adf98c74fc6aa06aafdee9015e0008e43cc Mon Sep 17 00:00:00 2001 From: Bartosz Lesniewski Date: Tue, 20 Apr 2021 07:01:48 +0200 Subject: [PATCH 14/78] Squeeze operator class refactoring (#5065) * Revise Squeeze op class * code style fix * Move backend tests from fused_op.in.cpp to a separate file * Add missing newline * added axes input range and type validation * add validation checks for the second input rank and type * style fix * remove axes input type checks * add support for a single input squeeze op * remove output static rank assignment in validate_and_infer_types * Improve shape propagation for partial shape inputs with static ranks --- ngraph/core/include/ngraph/op/squeeze.hpp | 14 ++- ngraph/core/src/op/squeeze.cpp | 124 ++++++++++++++++------ ngraph/test/CMakeLists.txt | 1 + ngraph/test/backend/fused_op.in.cpp | 49 --------- ngraph/test/backend/squeeze.in.cpp | 61 +++++++++++ ngraph/test/type_prop/squeeze.cpp | 118 +++++++++++++++++++- 6 files changed, 278 insertions(+), 89 deletions(-) create mode 100644 ngraph/test/backend/squeeze.in.cpp diff --git a/ngraph/core/include/ngraph/op/squeeze.hpp b/ngraph/core/include/ngraph/op/squeeze.hpp index 28cd28afa34..1ae837cc6f6 100644 --- a/ngraph/core/include/ngraph/op/squeeze.hpp +++ b/ngraph/core/include/ngraph/op/squeeze.hpp @@ -9,9 +9,6 @@ #include "ngraph/axis_vector.hpp" #include "ngraph/node.hpp" #include "ngraph/op/op.hpp" -#include "ngraph/op/util/fused_op.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -19,17 +16,17 @@ namespace ngraph { namespace v0 { - class NGRAPH_API Squeeze : public ngraph::op::util::FusedOp + class NGRAPH_API Squeeze : public ngraph::op::Op { public: NGRAPH_RTTI_DECLARATION; Squeeze(); Squeeze(const Output& data, const Output& axes); + Squeeze(const Output& data); bool visit_attributes(AttributeVisitor& visitor) override; - virtual OutputVector decompose_op() const override; - virtual void pre_validate_and_infer_types() override; + void validate_and_infer_types() override; bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; bool evaluate_lower(const HostTensorVector& outputs) const override; @@ -41,10 +38,11 @@ namespace ngraph clone_with_new_inputs(const OutputVector& new_args) const override; bool is_dynamic() const override; + + private: + Output get_default_axes_input() const; }; } using v0::Squeeze; } } - -NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/src/op/squeeze.cpp b/ngraph/core/src/op/squeeze.cpp index 0b2095f257c..f5094f9406b 100644 --- a/ngraph/core/src/op/squeeze.cpp +++ b/ngraph/core/src/op/squeeze.cpp @@ -18,30 +18,52 @@ using namespace std; using namespace ngraph; -NGRAPH_SUPPRESS_DEPRECATED_START - NGRAPH_RTTI_DEFINITION(op::v0::Squeeze, "Squeeze", 0); op::Squeeze::Squeeze() - : FusedOp() + : Op() { } op::Squeeze::Squeeze(const Output& data, const Output& axes) - : FusedOp({data, axes}) + : Op({data, axes}) { constructor_validate_and_infer_types(); } -void op::Squeeze::pre_validate_and_infer_types() +op::Squeeze::Squeeze(const Output& data) + : Op({data}) { - auto data = input_value(0); - auto axes_node = input_value(1).get_node_shared_ptr(); + constructor_validate_and_infer_types(); +} +void op::Squeeze::validate_and_infer_types() +{ + NGRAPH_OP_SCOPE(v0_Squeeze_validate_and_infer_types); + auto data = input_value(0); bool data_has_dynamic_rank = data.get_partial_shape().rank().is_dynamic(); bool data_has_dynamic_shape = data.get_partial_shape().is_dynamic(); + auto data_partial_shape = data.get_partial_shape(); + + std::shared_ptr axes_constant; + if (get_input_size() == 1) + { + // Handling the case when Squeeze op is created with a single input - data. + // This way the following code (validation, shape inference) can be used in both cases. + axes_constant = make_shared(element::i64, Shape{0}, vector{}); + } + else + { + auto axes_node = input_value(1).get_node_shared_ptr(); + auto axes_pshape = get_input_partial_shape(1); + axes_constant = get_constant_from_source(axes_node); + + NODE_VALIDATION_CHECK(this, + axes_pshape.rank().compatible(0) || axes_pshape.rank().compatible(1), + "Second input (axes) should not be of rank higher than 1. Got: ", + axes_pshape.rank().get_length()); + } - auto axes_constant = get_constant_from_source(axes_node); bool axes_is_empty_constant = (axes_constant && axes_constant->get_data_ptr() != nullptr) ? axes_constant->cast_vector().empty() : false; @@ -49,11 +71,32 @@ void op::Squeeze::pre_validate_and_infer_types() if (data_has_dynamic_rank || !axes_constant || !axes_constant->get_data_ptr() || (data_has_dynamic_shape && axes_is_empty_constant)) { + // If data has a static rank despite being dynamic, it's possible none + // of the dimensions will be equal to 1. If so, the input shape can be + // propagated at this point to the output shape. + if (!data_has_dynamic_rank && axes_is_empty_constant) + { + bool no_squeezable_dimension_present = true; + uint64_t data_rank = data_partial_shape.rank().get_length(); + for (uint64_t idx = 0; idx < data_rank; ++idx) + { + if (data_partial_shape[idx].compatible(1)) + { + no_squeezable_dimension_present = false; + break; + } + } + if (no_squeezable_dimension_present) + { + set_output_type(0, get_input_element_type(0), data_partial_shape); + return; + } + } + set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); return; } - auto data_partial_shape = data.get_partial_shape(); uint64_t data_rank = data_partial_shape.rank().get_length(); // Get value of axes from Constant @@ -61,7 +104,7 @@ void op::Squeeze::pre_validate_and_infer_types() normalize_axes(this->description(), axes_constant->cast_vector(), data_rank); // Prepare set of unique axes marked to be removed from input data. - vector axes_to_squeeze(data_rank); + vector axes_to_squeeze(data_rank, false); if (axes_is_empty_constant) { auto data_shape = data.get_shape(); @@ -72,10 +115,6 @@ void op::Squeeze::pre_validate_and_infer_types() { axes_to_squeeze.at(idx) = true; } - else - { - axes_to_squeeze.at(idx) = false; - } } } else @@ -112,28 +151,22 @@ bool ngraph::op::v0::Squeeze::visit_attributes(AttributeVisitor& visitor) return true; } -OutputVector op::Squeeze::decompose_op() const -{ - NODE_VALIDATION_CHECK( - this, - (get_output_partial_shape(0).is_static()), - "output shape was not calculated during pre_validate_and_infer_types. Can not decompose."); - auto data = input_value(0); - auto output_data_shape = get_output_shape(0); - return {make_shared( - data, - op::Constant::create(element::u64, {output_data_shape.size()}, output_data_shape), - false)}; -} - shared_ptr op::Squeeze::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v0_Squeeze_clone_with_new_inputs); - if (new_args.size() != 2) + check_new_args_count(this, new_args); + if (new_args.size() == 1) + { + return make_shared(new_args.at(0)); + } + else if (new_args.size() == 2) + { + return make_shared(new_args.at(0), new_args.at(1)); + } + else { throw ngraph_error("Incorrect number of new arguments"); } - return make_shared(new_args.at(0), new_args.at(1)); } namespace squeeze @@ -174,6 +207,20 @@ namespace squeeze return true; } + bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out) + { + auto out_shape = arg0->get_shape(); + + out_shape.erase(remove(out_shape.begin(), out_shape.end(), 1), out_shape.end()); + + out->set_shape(out_shape); + + runtime::reference::copy(arg0->get_data_ptr(), + out->get_data_ptr(), + shape_size(out_shape) * out->get_element_type().size()); + return true; + } + bool evaluate_squeeze(const HostTensorPtr& arg0, const HostTensorPtr& arg1, const HostTensorPtr& out) @@ -195,21 +242,33 @@ namespace squeeze } return rc; } + + bool evaluate_squeeze(const HostTensorPtr& arg0, const HostTensorPtr& out) + { + return evaluate(arg0, out); + } } bool op::v0::Squeeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v0_Squeeze_evaluate); - // TODO: change the behaviour after the support of Squeeze with one input NGRAPH_CHECK(validate_host_tensor_vector(inputs, inputs.size())); NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + + if (inputs.size() == 1) + { + return squeeze::evaluate_squeeze(inputs[0], outputs[0]); + } + return squeeze::evaluate_squeeze(inputs[0], inputs[1], outputs[0]); } bool op::v0::Squeeze::evaluate_lower(const HostTensorVector& output_values) const { + NGRAPH_OP_SCOPE(v0_Squeeze_evaluate_lower); NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + if (inputs().size() > 1 && !input_value(1).get_tensor().has_and_set_bound()) return false; return default_lower_bound_evaluator(this, output_values); @@ -217,7 +276,9 @@ bool op::v0::Squeeze::evaluate_lower(const HostTensorVector& output_values) cons bool op::v0::Squeeze::evaluate_upper(const HostTensorVector& output_values) const { + NGRAPH_OP_SCOPE(v0_Squeeze_evaluate_upper); NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + if (inputs().size() > 1 && !input_value(1).get_tensor().has_and_set_bound()) return false; return default_upper_bound_evaluator(this, output_values); @@ -225,6 +286,7 @@ bool op::v0::Squeeze::evaluate_upper(const HostTensorVector& output_values) cons bool op::v0::Squeeze::constant_fold(OutputVector& output_values, const OutputVector& inputs_values) { + NGRAPH_OP_SCOPE(v0_Squeeze_constant_fold); if (get_output_partial_shape(0).is_dynamic()) { return false; diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index b158eb7c77b..30b5a01ddf1 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -398,6 +398,7 @@ set(MULTI_TEST_SRC backend/split.in.cpp backend/sqrt.in.cpp backend/squared_difference.in.cpp + backend/squeeze.in.cpp backend/subtract.in.cpp backend/tan.in.cpp backend/tanh.in.cpp diff --git a/ngraph/test/backend/fused_op.in.cpp b/ngraph/test/backend/fused_op.in.cpp index ff70b22e1b1..c1fe5a35797 100644 --- a/ngraph/test/backend/fused_op.in.cpp +++ b/ngraph/test/backend/fused_op.in.cpp @@ -720,55 +720,6 @@ NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_float) test_case.run(); } -NGRAPH_TEST(${BACKEND_NAME}, squeeze) -{ - const auto data_node = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); - const auto axes_node = - make_shared(element::i64, Shape{2}, vector{0, 2}); - const auto squeeze = make_shared(data_node, axes_node); - - const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_node}); - auto test_case = test::TestCase(function); - - const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; - test_case.add_input(data); - test_case.add_expected_output(Shape{4, 1, 2}, data); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squeeze_default_axes) -{ - const auto data_node = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); - const auto axes_node = - make_shared(element::i64, Shape{0}, vector{}); - const auto squeeze = make_shared(data_node, axes_node); - - const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_node}); - auto test_case = test::TestCase(function); - - const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; - test_case.add_input(data); - test_case.add_expected_output(Shape{4, 2}, data); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squeeze_dynamic) -{ - const auto data_param = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); - const auto axes_param = make_shared(element::i64, Shape{2}); - - const auto squeeze = make_shared(data_param, axes_param); - - const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_param, axes_param}); - auto test_case = test::TestCase(function); - - const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; - test_case.add_input(data); - test_case.add_input(vector{0, 2}); - test_case.add_expected_output(Shape{4, 1, 2}, data); - test_case.run(); -} - // TODO: Issue: 37534 NGRAPH_TEST(${BACKEND_NAME}, DISABLED_squared_difference) { diff --git a/ngraph/test/backend/squeeze.in.cpp b/ngraph/test/backend/squeeze.in.cpp new file mode 100644 index 00000000000..4fc6ca61a60 --- /dev/null +++ b/ngraph/test/backend/squeeze.in.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" +#include "util/test_control.hpp" + +using namespace std; +using namespace ngraph; + +static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); + +NGRAPH_TEST(${BACKEND_NAME}, squeeze) +{ + const auto data_node = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); + const auto axes_node = + make_shared(element::i64, Shape{2}, vector{0, 2}); + const auto squeeze = make_shared(data_node, axes_node); + + const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_node}); + auto test_case = test::TestCase(function); + + const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; + test_case.add_input(data); + test_case.add_expected_output(Shape{4, 1, 2}, data); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, squeeze_default_axes) +{ + const auto data_node = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); + const auto axes_node = + make_shared(element::i64, Shape{0}, vector{}); + const auto squeeze = make_shared(data_node, axes_node); + + const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_node}); + auto test_case = test::TestCase(function); + + const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; + test_case.add_input(data); + test_case.add_expected_output(Shape{4, 2}, data); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, squeeze_no_axes) +{ + const auto data_node = make_shared(element::f32, Shape{1, 4, 1, 1, 2}); + const auto squeeze = make_shared(data_node); + + const auto function = make_shared(NodeVector{squeeze}, ParameterVector{data_node}); + auto test_case = test::TestCase(function); + + const auto data = vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; + test_case.add_input(data); + test_case.add_expected_output(Shape{4, 2}, data); + test_case.run(); +} diff --git a/ngraph/test/type_prop/squeeze.cpp b/ngraph/test/type_prop/squeeze.cpp index 01fd146ce5e..0af95ce658a 100644 --- a/ngraph/test/type_prop/squeeze.cpp +++ b/ngraph/test/type_prop/squeeze.cpp @@ -26,7 +26,32 @@ TEST(type_prop, squeeze) ASSERT_EQ(squeeze_default_axes->get_shape(), (Shape{4, 4, 8})); } -TEST(type_prop, squeeze_dynamic) +TEST(type_prop, squeeze_unsqueezable_no_axes) +{ + auto param = make_shared(element::f32, PartialShape{Dimension(2, 5), Dimension(3, 4), 6}); + auto squeeze = make_shared(param); + + ASSERT_EQ(squeeze->get_element_type(), element::f32); + EXPECT_TRUE(squeeze->get_output_partial_shape(0).same_scheme( + PartialShape{Dimension(2, 5), Dimension(3, 4), 6})); +} + +TEST(type_prop, squeeze_no_axes) +{ + auto param = make_shared(element::f32, Shape{1, 4, 1, 4, 1, 8}); + auto squeeze = make_shared(param); + + ASSERT_EQ(squeeze->get_element_type(), element::f32); + ASSERT_EQ(squeeze->get_shape(), (Shape{4, 4, 8})); + + auto axes_node = make_shared(element::u64, Shape{0}, vector{}); + auto squeeze_default_axes = make_shared(param, axes_node); + + ASSERT_EQ(squeeze_default_axes->get_element_type(), element::f32); + ASSERT_EQ(squeeze_default_axes->get_shape(), (Shape{4, 4, 8})); +} + +TEST(type_prop, squeeze_dynamic_static_rank) { auto param = make_shared(element::f32, PartialShape::dynamic(6)); auto axes_node = @@ -45,6 +70,36 @@ TEST(type_prop, squeeze_dynamic) squeeze_default_axes->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); } +TEST(type_prop, squeeze_dynamic_dynamic_rank) +{ + auto param = make_shared(element::f32, PartialShape::dynamic()); + auto axes_node = + make_shared(element::u64, Shape{2}, vector{0, 2}); + auto squeeze = make_shared(param, axes_node); + + ASSERT_EQ(squeeze->get_element_type(), element::f32); + + EXPECT_TRUE(squeeze->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); + + axes_node = make_shared(element::u64, Shape{0}, vector{}); + auto squeeze_default_axes = make_shared(param, axes_node); + + ASSERT_EQ(squeeze_default_axes->get_element_type(), element::f32); + EXPECT_TRUE( + squeeze_default_axes->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); +} + +TEST(type_prop, squeeze_axes_dynamic) +{ + auto param = make_shared(element::f32, Shape{1, 4, 1, 4, 1, 8}); + auto axes_node = + make_shared(element::u64, PartialShape::dynamic()); + auto squeeze = make_shared(param, axes_node); + + ASSERT_EQ(squeeze->get_element_type(), element::f32); + ASSERT_TRUE(squeeze->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); +} + TEST(type_prop, squeeze_axes_invalid_value) { auto param = make_shared(element::f32, Shape{1, 2, 3, 4}); @@ -66,3 +121,64 @@ TEST(type_prop, squeeze_axes_invalid_value) FAIL() << "Deduced type check failed for unexpected reason"; } } + +TEST(type_prop, squeeze_axes_invalid_rank) +{ + auto param = make_shared(element::f32, Shape{1, 2, 3, 4}); + auto axes_node = + make_shared(element::i32, Shape{2, 1}, vector{0, 2}); + + try + { + auto squeeze = make_shared(param, axes_node); + FAIL() << "Squeeze axis invalid rank not detected"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + "Second input (axes) should not be of rank higher than 1."); + } + catch (...) + { + FAIL() << "Deduced type check failed for unexpected reason"; + } +} + +TEST(type_prop, squeeze_negative_axes) +{ + auto param = make_shared(element::f32, Shape{1, 4, 1, 4, 1, 8}); + auto axes_node = + make_shared(element::i64, Shape{2}, vector{-6, -4}); + auto squeeze = make_shared(param, axes_node); + + ASSERT_EQ(squeeze->get_element_type(), element::f32); + ASSERT_EQ(squeeze->get_shape(), (Shape{4, 4, 1, 8})); + + axes_node = make_shared(element::u64, Shape{0}, vector{}); + auto squeeze_default_axes = make_shared(param, axes_node); + + ASSERT_EQ(squeeze_default_axes->get_element_type(), element::f32); + ASSERT_EQ(squeeze_default_axes->get_shape(), (Shape{4, 4, 8})); +} + + +TEST(type_prop, squeeze_incorrect_negative_axes) +{ + auto param = make_shared(element::f32, Shape{1, 4, 1, 4, 1, 8}); + auto axes_node = + make_shared(element::i64, Shape{2}, vector{-6, -10}); + + try + { + auto squeeze = make_shared(param, axes_node); + FAIL() << "Squeeze axis invalid value not detected"; + } + catch (ngraph_error &error) + { + EXPECT_HAS_SUBSTRING(error.what(), "Parameter axis -10 out of the tensor rank range"); + } + catch (...) + { + FAIL() << "Deduced type check failed for unexpected reason"; + } +} \ No newline at end of file From 41bdec12dfe573788b096eb4892f69188f85f567 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Tue, 20 Apr 2021 10:27:48 +0300 Subject: [PATCH 15/78] [nGraph] Gather v7 v1 up down transformations (#5118) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * v7->v1 works fine * gather v1->v7 works fine * changed op::v7 -> opset7, op:v1 -> opset1 * bumped to gather7 in all transformations * applied review comments * fixed pre-commit failures * disabled incorrect unit-test, fixed f32->i32 * added comments why AddConvertToReorderTest was disabled * Revert "bumped to gather7 in all transformations" This reverts commit 965dc295 * fixed typos in v1->v7, v7->v1 * added GatherBase, redefined pattern in eliminate_unsqueeze gather, turned on Gather downgrading transformation * resolved conflicts and build errors * 🚀 finally EliminateUnsqueezeGather works: added inheritance of RTTI info from GatherBase * fixed pre-commit failurer * removed redundant debug code * reverted f32 for Gather-1 indices in unit-tests and transformations * relaxed restrictions for indices and axis type for v1::Gather * corrected op scope * moved type_check to validation_util.cpp * removed type checks from Gather, removed upgrading transformation * applied review coments * fixed minor typos --- .../convert_gather_v7_to_gather_v1.hpp | 27 + .../algebraic_simplification.cpp | 8 +- .../common_optimizations.cpp | 3 + .../eliminate_unsqueeze_gather.cpp | 2 +- .../convert_gather_v7_to_gather_v1.cpp | 43 ++ .../convert_gather_v7_to_gather_v1_test.cpp | 51 ++ .../eliminate_unsqueeze_gather.cpp | 1 - ngraph/core/include/ngraph/op/gather.hpp | 48 +- .../include/ngraph/op/util/gather_base.hpp | 50 ++ ngraph/core/src/op/gather.cpp | 553 +----------------- ngraph/core/src/op/util/gather_base.cpp | 393 +++++++++++++ ngraph/test/type_prop/gather.cpp | 108 +++- 12 files changed, 699 insertions(+), 588 deletions(-) create mode 100644 inference-engine/src/transformations/include/transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp create mode 100644 inference-engine/src/transformations/src/transformations/op_conversions/convert_gather_v7_to_gather_v1.cpp create mode 100644 inference-engine/tests/functional/inference_engine/transformations/convert_gather_v7_to_gather_v1_test.cpp create mode 100644 ngraph/core/include/ngraph/op/util/gather_base.hpp create mode 100644 ngraph/core/src/op/util/gather_base.cpp diff --git a/inference-engine/src/transformations/include/transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp b/inference-engine/src/transformations/include/transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp new file mode 100644 index 00000000000..757d20390d3 --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include + +namespace ngraph { +namespace pass { + +class TRANSFORMATIONS_API ConvertGather7ToGather1; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief ConvertGather7ToGather1 covert v7::Gather into v1::Gather. + */ +class ngraph::pass::ConvertGather7ToGather1 : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + ConvertGather7ToGather1(); +}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/algebraic_simplification.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/algebraic_simplification.cpp index 9e36bb8c8f0..4800121b0dd 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/algebraic_simplification.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/algebraic_simplification.cpp @@ -37,12 +37,12 @@ static bool simplify_gather(std::shared_ptr node) { return false; } - auto axis = gather->get_axis(); - if (axis == opset3::Gather::AXIS_NOT_SET_VALUE) { + if (!gather->is_axis_set()) { NGRAPH_DEBUG << "axis value not set"; return false; } + auto axis = gather->get_axis(); // case_1 : if the input tensor is of shape (4, 1, 4) // and axis = 1, then the gather would be simply @@ -85,12 +85,12 @@ static bool simplify_gather_shapeof(shared_ptr node) { } auto gather_in_rank = gather->get_input_partial_shape(0).rank(); auto indices_rank = gather->get_input_partial_shape(1).rank(); - auto axis = gather->get_axis(); if (gather_in_rank.is_dynamic() || indices_rank.is_dynamic() || - axis == opset3::Gather::AXIS_NOT_SET_VALUE) { + !gather->is_axis_set()) { NGRAPH_DEBUG << gather << " cannot simplify gather->shapeof"; return false; } + auto axis = gather->get_axis(); auto zero_axis = opset3::Constant::create(element::i64, Shape{}, {0}); NodeVector new_ops; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 244cc6e0847..47e9f789ea6 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -42,6 +42,7 @@ #include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" #include "transformations/op_conversions/convert_pad_to_group_conv.hpp" #include "transformations/op_conversions/convert_divide.hpp" +#include "transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp" #include "transformations/op_conversions/convert_mod.hpp" #include "transformations/op_conversions/convert_minimum_to_power_and_max.hpp" #include "transformations/op_conversions/convert_negative.hpp" @@ -156,6 +157,8 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptrset_name("ngraph::pass::ConvFusions"); manager.register_pass(); + // need to convert to Gather-1 until plugins do not support Gather-7 + manager.register_pass(); auto fq_fusions = manager.register_pass(); fq_fusions->add_matcher(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp index f5b1062e2b2..fae3b71ac1e 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp @@ -19,7 +19,7 @@ ngraph::pass::EliminateUnsqueezeGather::EliminateUnsqueezeGather() { const auto unsqueeze = ngraph::pattern::wrap_type({unsqueezeInput, unsqueezeAxis}, pattern::consumers_count(1)); const auto gatherIndices = ngraph::opset6::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); const auto gatherAxis = ngraph::pattern::any_input(); - const auto gather = ngraph::pattern::wrap_type({unsqueeze, gatherIndices, gatherAxis}); + const auto gather = ngraph::pattern::wrap_type({unsqueeze, gatherIndices, gatherAxis}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto& patternValue = m.get_pattern_value_map(); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_gather_v7_to_gather_v1.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_gather_v7_to_gather_v1.cpp new file mode 100644 index 00000000000..67d5c0ebc1c --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_gather_v7_to_gather_v1.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/op_conversions/convert_gather_v7_to_gather_v1.hpp" +#include +#include +#include +#include + +#include "itt.hpp" + +NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertGather7ToGather1, "ConvertGather7ToGather1", 0); + +ngraph::pass::ConvertGather7ToGather1::ConvertGather7ToGather1() { + MATCHER_SCOPE(ConvertGather7ToGather1); + + auto gather_v7 = pattern::wrap_type(); + + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { + auto gather_v7_node = std::dynamic_pointer_cast(m.get_match_root()); + if (!gather_v7_node) + return false; + + int64_t batch_dims = 0; + if (gather_v7_node->is_axis_set()) + batch_dims = gather_v7_node->get_batch_dims(); + if (batch_dims != 0) + return false; + auto data_input = gather_v7_node->input_value(0); + auto indices_input = gather_v7_node->input_value(1); + auto axis_input = gather_v7_node->input_value(2); + + auto gather_v1 = std::make_shared(data_input, indices_input, axis_input); + gather_v1->set_friendly_name(gather_v7_node->get_friendly_name()); + ngraph::copy_runtime_info(gather_v7_node, gather_v1); + ngraph::replace_node(gather_v7_node, gather_v1); + return true; + }; + + auto m = std::make_shared(gather_v7, matcher_name); + register_matcher(m, callback); +} diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_gather_v7_to_gather_v1_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_gather_v7_to_gather_v1_test.cpp new file mode 100644 index 00000000000..b409ac16738 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_gather_v7_to_gather_v1_test.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +using namespace testing; + +TEST(TransformationTests, ConvertGather7toGather1) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3}); + auto indices = std::make_shared(ngraph::element::i32, ngraph::Shape{2, 2}); + auto axis = ngraph::opset1::Constant::create(ngraph::element::i32, ngraph::Shape{1}, {0}); + + auto gather_v7 = std::make_shared(data, indices, axis, 0); + + f = std::make_shared(ngraph::NodeVector{gather_v7}, ngraph::ParameterVector{data, indices}); + + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3}); + auto indices = std::make_shared(ngraph::element::i32, ngraph::Shape{2, 2}); + auto axis = ngraph::opset1::Constant::create(ngraph::element::i32, ngraph::Shape{1}, {0}); + + auto gather_v1 = std::make_shared(data, indices, axis); + + f_ref = std::make_shared(ngraph::NodeVector{gather_v1}, ngraph::ParameterVector{data, indices}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} diff --git a/inference-engine/tests/functional/inference_engine/transformations/eliminate_unsqueeze_gather.cpp b/inference-engine/tests/functional/inference_engine/transformations/eliminate_unsqueeze_gather.cpp index 1733d7291df..526695879d8 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/eliminate_unsqueeze_gather.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/eliminate_unsqueeze_gather.cpp @@ -6,7 +6,6 @@ #include #include - #include #include diff --git a/ngraph/core/include/ngraph/op/gather.hpp b/ngraph/core/include/ngraph/op/gather.hpp index 6a1c096f04f..a165e5ddac4 100644 --- a/ngraph/core/include/ngraph/op/gather.hpp +++ b/ngraph/core/include/ngraph/op/gather.hpp @@ -4,7 +4,7 @@ #pragma once -#include "ngraph/op/op.hpp" +#include "ngraph/op/util/gather_base.hpp" namespace ngraph { @@ -13,12 +13,10 @@ namespace ngraph namespace v1 { /// \brief Gather slices from axis of params according to indices - class NGRAPH_API Gather : public Op + class NGRAPH_API Gather : public op::util::GatherBase { public: - static const int64_t AXIS_NOT_SET_VALUE = std::numeric_limits::max(); - static constexpr NodeTypeInfo type_info{"Gather", 1}; - const NodeTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; Gather() = default; /// \param params The tensor from which slices are gathered /// \param indices Tensor with indexes to gather @@ -28,35 +26,16 @@ namespace ngraph const Output& axis); bool visit_attributes(AttributeVisitor& visitor) override; - int64_t get_axis() const; - void validate_and_infer_types() override; - - virtual std::shared_ptr + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - bool evaluate(const HostTensorVector& outputs, - const HostTensorVector& inputs) const override; - bool evaluate_lower(const HostTensorVector& outputs) const override; - bool evaluate_upper(const HostTensorVector& outputs) const override; - - bool constant_fold(OutputVector& output_values, - const OutputVector& inputs_values) override; - - private: - static const int PARAMS; - static const int INDICES; - static const int AXIS; - - bool evaluate_gather(const HostTensorVector& outputs, - const HostTensorVector& inputs) const; }; } // namespace v1 namespace v7 { /// \brief Gather slices from axis of params according to indices - class NGRAPH_API Gather : public Op + class NGRAPH_API Gather : public op::util::GatherBase { public: NGRAPH_RTTI_DECLARATION; @@ -76,23 +55,6 @@ namespace ngraph std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - int64_t get_batch_dims() const; - int64_t get_axis() const; - bool is_axis_set() const; - - bool evaluate_gather(const HostTensorVector& outputs, - const HostTensorVector& inputs) const; - bool evaluate(const HostTensorVector& outputs, - const HostTensorVector& inputs) const override; - bool evaluate_lower(const HostTensorVector& outputs) const override; - bool evaluate_upper(const HostTensorVector& outputs) const override; - - bool constant_fold(OutputVector& output_values, - const OutputVector& inputs_values) override; - - private: - int64_t m_batch_dims = 0; }; } // namespace v7 } // namespace op diff --git a/ngraph/core/include/ngraph/op/util/gather_base.hpp b/ngraph/core/include/ngraph/op/util/gather_base.hpp new file mode 100644 index 00000000000..e6bd909731d --- /dev/null +++ b/ngraph/core/include/ngraph/op/util/gather_base.hpp @@ -0,0 +1,50 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/op/op.hpp" + +namespace ngraph +{ + namespace op + { + namespace util + { + /// \brief GatherBase basic class for Gather v1 and v7 + class NGRAPH_API GatherBase : public Op + { + public: + NGRAPH_RTTI_DECLARATION; + GatherBase() = default; + + /// \param data The tensor from which slices are gathered + /// \param indices Tensor with indexes to gather + /// \param axis The tensor is a dimension index to gather data from + /// \param batch_dims The number of batch dimension in data and indices tensors + GatherBase(const Output& data, + const Output& indices, + const Output& axis, + const int64_t batch_dims = 0); + + void validate_and_infer_types() override; + int64_t get_batch_dims() const; + int64_t get_axis() const; + bool is_axis_set() const; + + bool evaluate(const HostTensorVector& outputs, + const HostTensorVector& inputs) const override; + + bool evaluate_lower(const HostTensorVector& outputs) const override; + bool evaluate_upper(const HostTensorVector& outputs) const override; + + bool constant_fold(OutputVector& output_values, + const OutputVector& inputs_values) override; + + protected: + int64_t m_batch_dims = 0; + }; + } // namespace utils + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/src/op/gather.cpp b/ngraph/core/src/op/gather.cpp index 522ce299e35..f68a7a9491a 100644 --- a/ngraph/core/src/op/gather.cpp +++ b/ngraph/core/src/op/gather.cpp @@ -3,30 +3,19 @@ // #include "ngraph/op/gather.hpp" -#include "itt.hpp" -#include "ngraph/op/concat.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/squeeze.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/runtime/reference/gather.hpp" -#include "ngraph/shape.hpp" - #include +#include "itt.hpp" +#include "ngraph/shape.hpp" using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::v1::Gather::type_info; -const int64_t op::v1::Gather::AXIS_NOT_SET_VALUE; - -const int op::v1::Gather::PARAMS = 0; -const int op::v1::Gather::INDICES = 1; -const int op::v1::Gather::AXIS = 2; +NGRAPH_RTTI_DEFINITION(op::v1::Gather, "Gather", 1, op::util::GatherBase); op::v1::Gather::Gather(const Output& params, const Output& indices, const Output& axes) - : Op({params, indices, axes}) + : GatherBase(params, indices, axes) { constructor_validate_and_infer_types(); } @@ -37,107 +26,38 @@ bool ngraph::op::v1::Gather::visit_attributes(AttributeVisitor& visitor) return true; } -void op::v1::Gather::validate_and_infer_types() -{ - NGRAPH_OP_SCOPE(v1_Gather_validate_and_infer_types); - const auto& input_rank = get_input_partial_shape(PARAMS).rank(); - const auto& axis_shape = get_input_partial_shape(AXIS); - const auto& axis_rank = axis_shape.rank(); - - if (axis_rank.is_static() && axis_shape.is_static()) - { - const auto axis_is_scalar = axis_rank.get_length() == 0; - const auto axis_has_one_elem = - axis_rank.get_length() == 1 && axis_shape[0].get_length() == 1; - NODE_VALIDATION_CHECK(this, - axis_is_scalar || axis_has_one_elem, - "Axes input must be scalar or have 1 element (shape: ", - axis_shape, - ")."); - } - - int64_t axis = get_axis(); - if (input_rank.is_static() && axis != AXIS_NOT_SET_VALUE) - { - NODE_VALIDATION_CHECK(this, - axis < input_rank.get_length(), - "The axis must => 0 and <= input_rank (axis: ", - axis, - ")."); - } - - element::Type result_et = get_input_element_type(PARAMS); - - const PartialShape& params_shape = get_input_partial_shape(PARAMS); - const PartialShape& indices_shape = get_input_partial_shape(INDICES); - - PartialShape result_shape; - if (params_shape.rank().is_static() && indices_shape.rank().is_static() && - axis != AXIS_NOT_SET_VALUE) - { - std::vector result_dims(params_shape.rank().get_length() + - indices_shape.rank().get_length() - 1); - int64_t i = 0; - for (; i < axis; i++) - { - result_dims[i] = params_shape[i]; - } - for (int64_t j = 0; j < indices_shape.rank().get_length(); i++, j++) - { - result_dims[i] = indices_shape[j]; - } - for (int64_t j = axis + 1; j < params_shape.rank().get_length(); i++, j++) - { - result_dims[i] = params_shape[j]; - } - - result_shape = PartialShape(result_dims); - } - else - { - result_shape = PartialShape::dynamic(); - } - - set_output_type(0, result_et, result_shape); -} - -int64_t op::v1::Gather::get_axis() const -{ - int64_t axis = AXIS_NOT_SET_VALUE; - if (const auto& const_op = get_constant_from_source(input_value(AXIS))) - { - axis = const_op->cast_vector()[0]; - } - if (axis < 0) - { - const auto& input_rank = get_input_partial_shape(PARAMS).rank(); - if (input_rank.is_static()) - { - axis += input_rank.get_length(); - } - } - return axis; -} - shared_ptr op::v1::Gather::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v1_Gather_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(PARAMS), new_args.at(INDICES), new_args.at(AXIS)); + return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } -NGRAPH_RTTI_DEFINITION(op::v7::Gather, "Gather", 7); +NGRAPH_RTTI_DEFINITION(op::v7::Gather, "Gather", 7, op::util::GatherBase); op::v7::Gather::Gather(const Output& data, const Output& indices, const Output& axis, const int64_t batch_dims) - : Op({data, indices, axis}) - , m_batch_dims(batch_dims) + : GatherBase(data, indices, axis, batch_dims) { constructor_validate_and_infer_types(); } +void op::v7::Gather::validate_and_infer_types() +{ + NGRAPH_OP_SCOPE(v7_Gather_validate_and_infer_types); + NODE_VALIDATION_CHECK(this, + get_input_element_type(1).is_integral_number(), + "Indices element type must be of an integral number type."); + + NODE_VALIDATION_CHECK(this, + get_input_element_type(2).is_integral_number(), + "Axis element type must be of an integral number type."); + + op::util::GatherBase::validate_and_infer_types(); +} + bool ngraph::op::v7::Gather::visit_attributes(AttributeVisitor& visitor) { NGRAPH_OP_SCOPE(v7_Gather_visit_attributes); @@ -145,440 +65,9 @@ bool ngraph::op::v7::Gather::visit_attributes(AttributeVisitor& visitor) return true; } -void op::v7::Gather::validate_and_infer_types() -{ - NGRAPH_OP_SCOPE(v7_Gather_validate_and_infer_types); - const auto& data_type = get_input_element_type(0); - const auto& indices_type = get_input_element_type(1); - - NODE_VALIDATION_CHECK(this, - indices_type == element::Type_t::i32 || - indices_type == element::Type_t::i64, - "indices must be of int32 or int64 type. But instead got: ", - indices_type); - - const auto& data_pshape = get_input_partial_shape(0); - const auto& indices_pshape = get_input_partial_shape(1); - const auto& axis_pshape = get_input_partial_shape(2); - auto data_rank = data_pshape.rank(); - auto indices_rank = indices_pshape.rank(); - auto axis_rank = axis_pshape.rank(); - - if (axis_rank.is_static() && axis_pshape.is_static()) - { - const auto axis_is_scalar = axis_rank.get_length() == 0; - const auto axis_has_one_elem = - axis_rank.get_length() == 1 && axis_pshape[0].get_length() == 1; - NODE_VALIDATION_CHECK( - this, - axis_is_scalar || axis_has_one_elem, - "Axes input must be scalar or have 1 element. But instead got axis_shape = ", - axis_pshape); - } - - int64_t batch_dims = get_batch_dims(); // will not be converted to positive if axis is not set - if (is_axis_set()) - { - int64_t axis = get_axis(); - NODE_VALIDATION_CHECK(this, - batch_dims <= axis, - "The batch_dims <= axis. But instead got: batch_dims = ", - batch_dims, - ", axis = ", - axis); - - if (data_rank.is_static()) - { - NODE_VALIDATION_CHECK(this, - axis >= 0 && axis < data_rank.get_length(), - "The axis must be => 0 and < data_rank. But instead got axis = ", - axis, - " data_rank = ", - data_rank.get_length()); - } - } - - if (indices_rank.is_static() && batch_dims >= 0) - { - NODE_VALIDATION_CHECK( - this, - batch_dims <= indices_rank.get_length(), - "The batch_dims must be <= indices_rank. But instead got: batch_dims = ", - batch_dims, - ", indices_rank = ", - indices_rank.get_length()); - } - - if (data_rank.is_static() && indices_rank.is_static()) - { - if (batch_dims >= 0) - { - auto out_rank = data_rank.get_length() + indices_rank.get_length() - 1 - batch_dims; - PartialShape output_pshape = PartialShape::dynamic(out_rank); - - // implementation of out_shape formula - // data.shape[:batch_dims] + data.shape[batch_dims:axis] + indices.shape[batch_dims:] + - // data.shape[axis + 1:] - int i = 0; - for (; i < batch_dims; i++) - { - NODE_VALIDATION_CHECK(this, - data_pshape[i].compatible(indices_pshape[i]), - "Shapes ", - data_pshape, - " and ", - indices_pshape, - " are not consistent. data and indices must have equal or " - "intersecting sizes until batch_dims"); - - output_pshape[i] = data_pshape[i] & indices_pshape[i]; - } - - if (is_axis_set()) - { - int64_t axis = get_axis(); - for (; i < axis; i++) - { - output_pshape[i] = data_pshape[i]; - } - for (; i < axis + indices_rank.get_length() - batch_dims; i++) - { - output_pshape[i] = indices_pshape[batch_dims - axis + i]; - } - for (; i < out_rank; i++) - { - output_pshape[i] = data_pshape[batch_dims + 1 - indices_rank.get_length() + i]; - } - } - - set_output_type(0, data_type, output_pshape); - } - else if (batch_dims < 0) - { - // batch_dims < 0 could be only if axis is not set - // as soon as axis value will arrive negative batch_dims should be resolved - // batch_dims value will be within [0, data_rank] && [0, indices_rank] - int64_t max_rank = data_rank.get_length() + indices_rank.get_length() - 1; - int64_t min_rank = max_rank - max(data_rank.get_length(), indices_rank.get_length()); - - set_output_type(0, data_type, PartialShape::dynamic(Dimension(min_rank, max_rank))); - } - } - else - { - set_output_type(0, data_type, PartialShape::dynamic()); - } -} - -int64_t op::v7::Gather::get_axis() const -{ - const auto& const_op = get_constant_from_source(input_value(2)); - int64_t axis = const_op->cast_vector()[0]; - if (axis < 0) - { - const auto& data_rank = get_input_partial_shape(0).rank(); - if (data_rank.is_static()) - { - axis += data_rank.get_length(); - } - } - return axis; -} - -int64_t op::v7::Gather::get_batch_dims() const -{ - if (m_batch_dims < 0 && is_axis_set()) - return get_axis() + m_batch_dims; - else - return m_batch_dims; -} - -bool op::v7::Gather::is_axis_set() const -{ - const auto& axes_constant = get_constant_from_source(input_value(2)); - if (axes_constant) - return true; - else - return false; -} - shared_ptr op::v7::Gather::clone_with_new_inputs(const OutputVector& new_args) const { NGRAPH_OP_SCOPE(v7_Gather_clone_with_new_inputs); check_new_args_count(this, new_args); return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_batch_dims); } - -namespace gather -{ - template - bool evaluate(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - size_t axis, - size_t batch_dims) - { - using T = typename element_type_traits::value_type; - Shape params_shape = arg0->get_shape(); - Shape indices_shape = arg1->get_shape(); - Shape out_shape(params_shape.size() + indices_shape.size() - 1 - batch_dims); - uint64_t i = 0; - for (; i < axis; i++) - { - out_shape[i] = params_shape[i]; - } - for (uint64_t j = batch_dims; j < indices_shape.size(); i++, j++) - { - out_shape[i] = indices_shape[j]; - } - for (uint64_t j = axis + 1; j < params_shape.size(); i++, j++) - { - out_shape[i] = params_shape[j]; - } - - out->set_shape(out_shape); - - if (arg1->get_element_type() == element::i64) - { - runtime::reference::gather(arg0->get_data_ptr(), - arg1->get_data_ptr(), - out->get_data_ptr(), - arg0->get_shape(), - arg1->get_shape(), - out->get_shape(), - axis, - batch_dims); - } - else if (arg1->get_element_type() == element::i32) - { - runtime::reference::gather(arg0->get_data_ptr(), - arg1->get_data_ptr(), - out->get_data_ptr(), - arg0->get_shape(), - arg1->get_shape(), - out->get_shape(), - axis, - batch_dims); - } - else - { - throw ngraph_error("Unexpected type"); - } - - return true; - } - - bool evaluate_gather(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - size_t axis, - size_t batch_dims = 0) - { - bool rc = true; - - switch (out->get_element_type()) - { - NGRAPH_TYPE_CASE(evaluate_gather, i32, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, i64, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, u32, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, u64, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, f16, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, f32, arg0, arg1, out, axis, batch_dims); - NGRAPH_TYPE_CASE(evaluate_gather, boolean, arg0, arg1, out, axis, batch_dims); - default: rc = false; break; - } - return rc; - } - - bool cf_gather_with_subgraph(OutputVector& output_values, - const OutputVector& input_values, - const PartialShape& gather_ps) - { - if (gather_ps.is_dynamic() || input_values.size() != 3) - { - return false; - } - - const auto concat = - std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr()); - const auto indices = - std::dynamic_pointer_cast(input_values[1].get_node_shared_ptr()); - const auto axis = - std::dynamic_pointer_cast(input_values[2].get_node_shared_ptr()); - - if (!concat || !indices || !axis) - { - return false; - } - - // only along axis=0 - if (axis->cast_vector()[0] != 0 || concat->get_axis() != 0) - { - return false; - } - // only single indices are accepted - const auto indices_shape = indices->get_shape(); - if (indices_shape.size() > 1 || (indices_shape.size() == 1 && indices_shape[0] > 1)) - { - return false; - } - // concat inputs are 1D and their count is equal to Concat output shape - if (concat->get_output_partial_shape(0).is_dynamic()) - { - return false; - } - const auto concat_inputs = concat->inputs(); - // concat inputs must be single elements - if (concat_inputs.size() != shape_size(concat->get_shape())) - { - return false; - } - - const int64_t rank = concat->get_shape()[0]; - const int64_t raw_index = indices->cast_vector()[0]; - const int64_t positive_index = raw_index < 0 ? rank + raw_index : raw_index; - NGRAPH_CHECK(positive_index >= 0 && positive_index < rank); - - // gather takes exactly one element out of the Concat output - const auto gathered_concat_input = - concat_inputs[positive_index].get_source_output().get_node_shared_ptr(); - // Concat inputs are 1D, resulting tensor shape depends on Gather indices - auto gathered = gathered_concat_input; - if (indices_shape.empty()) - { - // gathering a scalar - const auto axes = op::Constant::create(element::i64, Shape{1}, {0}); - gathered = make_shared(gathered_concat_input, axes); - } - - output_values[0] = gathered; - - return true; - } -} // namespace gather - -bool op::v1::Gather::evaluate_gather(const HostTensorVector& outputs, - const HostTensorVector& inputs) const -{ - int64_t axis = 0; - switch (inputs[2]->get_element_type()) - { - case element::Type_t::i8: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::i16: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::i32: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::i64: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::u8: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::u16: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::u32: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::u64: axis = inputs[2]->get_data_ptr()[0]; break; - default: throw ngraph_error("axis element type is not integral data type"); - } - - if (axis < 0) - { - const auto& input_rank = get_input_partial_shape(PARAMS).rank(); - if (input_rank.is_static()) - { - axis += input_rank.get_length(); - } - } - return gather::evaluate_gather(inputs[0], inputs[1], outputs[0], axis); -} - -bool op::v1::Gather::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const -{ - NGRAPH_OP_SCOPE(v1_Gather_evaluate); - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 3)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); - return evaluate_gather(outputs, inputs); -} - -bool op::v1::Gather::evaluate_lower(const HostTensorVector& output_values) const -{ - if (!input_value(INDICES).get_tensor().has_and_set_bound() || - !input_value(AXIS).get_tensor().has_and_set_bound()) - return false; - return default_lower_bound_evaluator(this, output_values); -} - -bool op::v1::Gather::evaluate_upper(const HostTensorVector& output_values) const -{ - if (!input_value(INDICES).get_tensor().has_and_set_bound() || - !input_value(AXIS).get_tensor().has_and_set_bound()) - return false; - return default_upper_bound_evaluator(this, output_values); -} - -bool op::v1::Gather::constant_fold(OutputVector& output_values, const OutputVector& input_values) -{ - // try the regular constant folding just for the Gather node - if (Node::constant_fold(output_values, input_values)) - { - return true; - } - else - { - return gather::cf_gather_with_subgraph( - output_values, input_values, get_output_partial_shape(0)); - } -} - -bool op::v7::Gather::evaluate_gather(const HostTensorVector& outputs, - const HostTensorVector& inputs) const -{ - int64_t axis = 0; - switch (inputs[2]->get_element_type()) - { - case element::Type_t::i32: axis = inputs[2]->get_data_ptr()[0]; break; - case element::Type_t::i64: axis = inputs[2]->get_data_ptr()[0]; break; - default: throw ngraph_error("axis must be of int32 or int64 type."); - } - - if (axis < 0) - { - const auto& input_rank = get_input_partial_shape(0).rank(); - if (input_rank.is_static()) - { - axis += input_rank.get_length(); - } - } - return gather::evaluate_gather(inputs[0], inputs[1], outputs[0], axis, get_batch_dims()); -} - -bool op::v7::Gather::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const -{ - NGRAPH_OP_SCOPE(v7_Gather_evaluate); - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 3)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); - return evaluate_gather(outputs, inputs); -} - -bool op::v7::Gather::evaluate_lower(const HostTensorVector& output_values) const -{ - if (!input_value(1).get_tensor().has_and_set_bound() || - !input_value(2).get_tensor().has_and_set_bound()) - return false; - return default_lower_bound_evaluator(this, output_values); -} - -bool op::v7::Gather::evaluate_upper(const HostTensorVector& output_values) const -{ - if (!input_value(1).get_tensor().has_and_set_bound() || - !input_value(2).get_tensor().has_and_set_bound()) - return false; - return default_upper_bound_evaluator(this, output_values); -} - -bool op::v7::Gather::constant_fold(OutputVector& output_values, const OutputVector& input_values) -{ - // try the regular constant folding just for the Gather node - if (Node::constant_fold(output_values, input_values)) - { - return true; - } - else - { - return gather::cf_gather_with_subgraph( - output_values, input_values, get_output_partial_shape(0)); - } -} diff --git a/ngraph/core/src/op/util/gather_base.cpp b/ngraph/core/src/op/util/gather_base.cpp new file mode 100644 index 00000000000..efc5e476c53 --- /dev/null +++ b/ngraph/core/src/op/util/gather_base.cpp @@ -0,0 +1,393 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph/op/util/gather_base.hpp" +#include "itt.hpp" +#include "ngraph/op/concat.hpp" +#include "ngraph/op/constant.hpp" +#include "ngraph/op/squeeze.hpp" +#include "ngraph/runtime/host_tensor.hpp" +#include "ngraph/runtime/reference/gather.hpp" +#include "ngraph/shape.hpp" + +#include + +using namespace std; +using namespace ngraph; + +NGRAPH_RTTI_DEFINITION(op::util::GatherBase, "GatherBase", 7); + +op::util::GatherBase::GatherBase(const Output& data, + const Output& indices, + const Output& axis, + const int64_t batch_dims) + : Op({data, indices, axis}) + , m_batch_dims(batch_dims) +{ + constructor_validate_and_infer_types(); +} + +void op::util::GatherBase::validate_and_infer_types() +{ + NGRAPH_OP_SCOPE(util_GatherBase_validate_and_infer_types); + const auto& data_type = get_input_element_type(0); + + const auto& data_pshape = get_input_partial_shape(0); + const auto& indices_pshape = get_input_partial_shape(1); + const auto& axis_pshape = get_input_partial_shape(2); + auto data_rank = data_pshape.rank(); + auto indices_rank = indices_pshape.rank(); + auto axis_rank = axis_pshape.rank(); + + if (axis_rank.is_static() && axis_pshape.is_static()) + { + const auto axis_is_scalar = axis_rank.get_length() == 0; + const auto axis_has_one_elem = + axis_rank.get_length() == 1 && axis_pshape[0].get_length() == 1; + NODE_VALIDATION_CHECK( + this, + axis_is_scalar || axis_has_one_elem, + "Axis input must be scalar or have 1 element. But instead got axis_shape = ", + axis_pshape); + } + + int64_t batch_dims = get_batch_dims(); // will not be converted to positive if axis is not set + if (is_axis_set()) + { + int64_t axis = get_axis(); + NODE_VALIDATION_CHECK(this, + batch_dims <= axis, + "The batch_dims <= axis. But instead got: batch_dims = ", + batch_dims, + ", axis = ", + axis); + + if (data_rank.is_static()) + { + NODE_VALIDATION_CHECK(this, + axis >= 0 && axis < data_rank.get_length(), + "The axis must be >= 0 and < data_rank. But instead got axis = ", + axis, + " data_rank = ", + data_rank.get_length()); + } + } + + if (indices_rank.is_static() && batch_dims >= 0) + { + NODE_VALIDATION_CHECK( + this, + batch_dims <= indices_rank.get_length(), + "The batch_dims must be <= indices_rank. But instead got: batch_dims = ", + batch_dims, + ", indices_rank = ", + indices_rank.get_length()); + } + + if (data_rank.is_static() && indices_rank.is_static()) + { + if (batch_dims >= 0) + { + auto out_rank = data_rank.get_length() + indices_rank.get_length() - 1 - batch_dims; + PartialShape output_pshape = PartialShape::dynamic(out_rank); + + // implementation of out_shape formula + // data.shape[:batch_dims] + data.shape[batch_dims:axis] + indices.shape[batch_dims:] + + // data.shape[axis + 1:] + int i = 0; + for (; i < batch_dims; i++) + { + NODE_VALIDATION_CHECK(this, + data_pshape[i].compatible(indices_pshape[i]), + "Shapes ", + data_pshape, + " and ", + indices_pshape, + " are not consistent. data and indices must have equal or " + "intersecting sizes until batch_dims"); + + output_pshape[i] = data_pshape[i] & indices_pshape[i]; + } + + if (is_axis_set()) + { + int64_t axis = get_axis(); + for (; i < axis; i++) + { + output_pshape[i] = data_pshape[i]; + } + for (; i < axis + indices_rank.get_length() - batch_dims; i++) + { + output_pshape[i] = indices_pshape[batch_dims - axis + i]; + } + for (; i < out_rank; i++) + { + output_pshape[i] = data_pshape[batch_dims + 1 - indices_rank.get_length() + i]; + } + } + + set_output_type(0, data_type, output_pshape); + } + else if (batch_dims < 0) + { + // batch_dims < 0 could be only if axis is not set + // as soon as axis value will arrive negative batch_dims should be resolved + // batch_dims value will be within [0, data_rank] && [0, indices_rank] + int64_t max_rank = data_rank.get_length() + indices_rank.get_length() - 1; + int64_t min_rank = max_rank - max(data_rank.get_length(), indices_rank.get_length()); + + set_output_type(0, data_type, PartialShape::dynamic(Dimension(min_rank, max_rank))); + } + } + else + { + set_output_type(0, data_type, PartialShape::dynamic()); + } +} + +int64_t op::util::GatherBase::get_axis() const +{ + const auto& const_op = get_constant_from_source(input_value(2)); + if (!const_op) + throw ngraph_error("axis value is not set"); + + int64_t axis = const_op->cast_vector()[0]; + if (axis < 0) + { + const auto& data_rank = get_input_partial_shape(0).rank(); + if (data_rank.is_static()) + { + axis += data_rank.get_length(); + } + } + return axis; +} + +int64_t op::util::GatherBase::get_batch_dims() const +{ + if (m_batch_dims < 0 && is_axis_set()) + return get_axis() + m_batch_dims; + else + return m_batch_dims; +} + +bool op::util::GatherBase::is_axis_set() const +{ + const auto& axis_constant = get_constant_from_source(input_value(2)); + if (axis_constant) + return true; + else + return false; +} + +namespace gather +{ + template + bool evaluate(const HostTensorPtr& arg0, + const HostTensorPtr& arg1, + const HostTensorPtr& out, + size_t axis, + size_t batch_dims) + { + using T = typename element_type_traits::value_type; + Shape params_shape = arg0->get_shape(); + Shape indices_shape = arg1->get_shape(); + Shape out_shape(params_shape.size() + indices_shape.size() - 1 - batch_dims); + uint64_t i = 0; + for (; i < axis; i++) + { + out_shape[i] = params_shape[i]; + } + for (uint64_t j = batch_dims; j < indices_shape.size(); i++, j++) + { + out_shape[i] = indices_shape[j]; + } + for (uint64_t j = axis + 1; j < params_shape.size(); i++, j++) + { + out_shape[i] = params_shape[j]; + } + + out->set_shape(out_shape); + + if (arg1->get_element_type() == element::i64) + { + runtime::reference::gather(arg0->get_data_ptr(), + arg1->get_data_ptr(), + out->get_data_ptr(), + arg0->get_shape(), + arg1->get_shape(), + out->get_shape(), + axis, + batch_dims); + } + else if (arg1->get_element_type() == element::i32) + { + runtime::reference::gather(arg0->get_data_ptr(), + arg1->get_data_ptr(), + out->get_data_ptr(), + arg0->get_shape(), + arg1->get_shape(), + out->get_shape(), + axis, + batch_dims); + } + else + { + throw ngraph_error("Unexpected type"); + } + + return true; + } + + bool evaluate_gather(const HostTensorPtr& arg0, + const HostTensorPtr& arg1, + const HostTensorPtr& out, + size_t axis, + size_t batch_dims = 0) + { + bool rc = true; + + switch (out->get_element_type()) + { + NGRAPH_TYPE_CASE(evaluate_gather, i32, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, i64, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, u32, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, u64, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, f16, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, f32, arg0, arg1, out, axis, batch_dims); + NGRAPH_TYPE_CASE(evaluate_gather, boolean, arg0, arg1, out, axis, batch_dims); + default: rc = false; break; + } + return rc; + } + + bool cf_gather_with_subgraph(OutputVector& output_values, + const OutputVector& input_values, + const PartialShape& gather_ps) + { + if (gather_ps.is_dynamic() || input_values.size() != 3) + { + return false; + } + + const auto concat = + std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr()); + const auto indices = + std::dynamic_pointer_cast(input_values[1].get_node_shared_ptr()); + const auto axis = + std::dynamic_pointer_cast(input_values[2].get_node_shared_ptr()); + + if (!concat || !indices || !axis) + { + return false; + } + + // only along axis=0 + if (axis->cast_vector()[0] != 0 || concat->get_axis() != 0) + { + return false; + } + // only single indices are accepted + const auto indices_shape = indices->get_shape(); + if (indices_shape.size() > 1 || (indices_shape.size() == 1 && indices_shape[0] > 1)) + { + return false; + } + // concat inputs are 1D and their count is equal to Concat output shape + if (concat->get_output_partial_shape(0).is_dynamic()) + { + return false; + } + const auto concat_inputs = concat->inputs(); + // concat inputs must be single elements + if (concat_inputs.size() != shape_size(concat->get_shape())) + { + return false; + } + + const int64_t rank = concat->get_shape()[0]; + const int64_t raw_index = indices->cast_vector()[0]; + const int64_t positive_index = raw_index < 0 ? rank + raw_index : raw_index; + NGRAPH_CHECK(positive_index >= 0 && positive_index < rank); + + // gather takes exactly one element out of the Concat output + const auto gathered_concat_input = + concat_inputs[positive_index].get_source_output().get_node_shared_ptr(); + // Concat inputs are 1D, resulting tensor shape depends on Gather indices + auto gathered = gathered_concat_input; + if (indices_shape.empty()) + { + // gathering a scalar + const auto axis_const = op::Constant::create(element::i64, Shape{1}, {0}); + gathered = make_shared(gathered_concat_input, axis_const); + } + + output_values[0] = gathered; + + return true; + } +} // namespace gather + +bool op::util::GatherBase::evaluate(const HostTensorVector& outputs, + const HostTensorVector& inputs) const +{ + NGRAPH_OP_SCOPE(util_GatherBase_evaluate); + NGRAPH_CHECK(validate_host_tensor_vector(inputs, 3)); + NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + + int64_t axis = 0; + switch (inputs[2]->get_element_type()) + { + case element::Type_t::i32: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::i64: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::i8: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::i16: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::u8: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::u16: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::u32: axis = inputs[2]->get_data_ptr()[0]; break; + case element::Type_t::u64: axis = inputs[2]->get_data_ptr()[0]; break; + default: throw ngraph_error("axis must be of integral data type."); + } + + if (axis < 0) + { + const auto& input_rank = get_input_partial_shape(0).rank(); + if (input_rank.is_static()) + { + axis += input_rank.get_length(); + } + } + return gather::evaluate_gather(inputs[0], inputs[1], outputs[0], axis, get_batch_dims()); +} + +bool op::util::GatherBase::evaluate_lower(const HostTensorVector& output_values) const +{ + if (!input_value(1).get_tensor().has_and_set_bound() || + !input_value(2).get_tensor().has_and_set_bound()) + return false; + return default_lower_bound_evaluator(this, output_values); +} + +bool op::util::GatherBase::evaluate_upper(const HostTensorVector& output_values) const +{ + if (!input_value(1).get_tensor().has_and_set_bound() || + !input_value(2).get_tensor().has_and_set_bound()) + return false; + return default_upper_bound_evaluator(this, output_values); +} + +bool op::util::GatherBase::constant_fold(OutputVector& output_values, + const OutputVector& input_values) +{ + // try the regular constant folding just for the Gather node + if (Node::constant_fold(output_values, input_values)) + { + return true; + } + else + { + return gather::cf_gather_with_subgraph( + output_values, input_values, get_output_partial_shape(0)); + } +} diff --git a/ngraph/test/type_prop/gather.cpp b/ngraph/test/type_prop/gather.cpp index e74b809f416..35bd4215e7d 100644 --- a/ngraph/test/type_prop/gather.cpp +++ b/ngraph/test/type_prop/gather.cpp @@ -27,6 +27,40 @@ TEST(type_prop, gather_axis_0) ASSERT_EQ(G->get_axis(), 0); } +TEST(type_prop, gather_7_uint8) +{ + // Gather_1 must allow even if indices is not int32/int64 + PartialShape data_shape{3, 2}; + PartialShape indices_shape{2, 2}; + PartialShape out_shape{2, 2, 2}; + + auto D = make_shared(element::f32, data_shape); + auto I = make_shared(element::u8, indices_shape); + auto A = op::Constant::create(element::i64, Shape{}, {0}); + auto G = make_shared(D, I, A); + + ASSERT_EQ(G->get_element_type(), element::f32); + ASSERT_EQ(G->get_output_partial_shape(0), out_shape); + ASSERT_EQ(G->get_axis(), 0); +} + +TEST(type_prop, gather_7_float32) +{ + // Gather_1 should allow non int32/int64 indices + PartialShape data_shape{3, 2}; + PartialShape indices_shape{2, 2}; + PartialShape out_shape{2, 2, 2}; + + auto D = make_shared(element::f32, data_shape); + auto I = make_shared(element::f32, indices_shape); + auto A = op::Constant::create(element::i64, Shape{}, {0}); + auto G = make_shared(D, I, A); + + ASSERT_EQ(G->get_element_type(), element::f32); + ASSERT_EQ(G->get_output_partial_shape(0), out_shape); + ASSERT_EQ(G->get_axis(), 0); +} + TEST(type_prop, gather_axis_1) { Shape params_shape{3, 3}; @@ -55,7 +89,7 @@ TEST(type_prop, gather_v1_incorrect_axis_shape) catch (const NodeValidationFailure& error) { EXPECT_HAS_SUBSTRING(error.what(), - std::string("Axes input must be scalar or have 1 element (shape:")); + std::string("Axis input must be scalar or have 1 element")); } catch (...) { @@ -77,7 +111,7 @@ TEST(type_prop, gather_v1_axis_out_of_input_rank) catch (const NodeValidationFailure& error) { EXPECT_HAS_SUBSTRING(error.what(), - std::string("The axis must => 0 and <= input_rank (axis:")); + std::string("The axis must be >= 0 and < data_rank. But instead got axis")); } catch (...) { @@ -241,7 +275,7 @@ TEST(type_prop, gather_7_axis_not_set) auto D = make_shared(element::f32, data_shape); auto I = make_shared(element::i64, indices_shape); - auto A = make_shared(element::f32, Shape{1}); + auto A = make_shared(element::i32, Shape{1}); auto G = make_shared(D, I, A); ASSERT_EQ(G->get_element_type(), element::f32); @@ -260,7 +294,7 @@ TEST(type_prop, gather_7_axis_not_set_positive_batch_dims) auto D = make_shared(element::f32, data_shape); auto I = make_shared(element::i64, indices_shape); - auto A = make_shared(element::f32, Shape{1}); + auto A = make_shared(element::i32, Shape{1}); auto G = make_shared(D, I, A, batch_dims); ASSERT_EQ(G->get_element_type(), element::f32); @@ -279,7 +313,7 @@ TEST(type_prop, gather_7_axis_not_set_negative_batch) auto D = make_shared(element::f32, data_shape); auto I = make_shared(element::i64, indices_shape); - auto A = make_shared(element::f32, Shape{1}); + auto A = make_shared(element::i32, Shape{1}); auto G = make_shared(D, I, A, batch_dims); ASSERT_EQ(G->get_element_type(), element::f32); @@ -303,7 +337,7 @@ TEST(type_prop, gather_7_incorrect_axis_shape) catch (const NodeValidationFailure& error) { EXPECT_HAS_SUBSTRING(error.what(), - std::string("Axes input must be scalar or have 1 element")); + std::string("Axis input must be scalar or have 1 element")); } catch (...) { @@ -326,7 +360,7 @@ TEST(type_prop, gather_7_axis_out_of_input_rank) catch (const NodeValidationFailure& error) { EXPECT_HAS_SUBSTRING( - error.what(), std::string("The axis must be => 0 and < data_rank. But instead got")); + error.what(), std::string("The axis must be >= 0 and < data_rank. But instead got")); } catch (...) { @@ -420,3 +454,63 @@ TEST(type_prop, gather_7_batch_dims_less_indices_rank_check) FAIL() << "Deduced type check failed for unexpected reason"; } } + +// disabled until decision of type constrains for gather +TEST(type_prop, DISABLED_gather_7_indices_type_check) +{ + PartialShape data_shape{1, 20, 20, 22, 22}; + PartialShape indices_shape{1, 3}; + + auto D = make_shared(element::f32, data_shape); + auto I = make_shared(element::f32, indices_shape); + int64_t axis = 4; + auto A = make_shared(element::i64, Shape{1}, vector{axis}); + int64_t batch_dims = 0; + + try + { + auto G = make_shared(D, I, A, batch_dims); + // Should have thrown, so fail if it didn't + FAIL() << "indices element_type check failed"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Indices element type must be of an integral number type")); + } + catch (...) + { + FAIL() << "Deduced type check failed for unexpected reason"; + } +} + +// disabled until decision of type constrains for gather +TEST(type_prop, DISABLED_gather_7_axis_type_check) +{ + PartialShape data_shape{1, 20, 20, 22, 22}; + PartialShape indices_shape{1, 3}; + + auto D = make_shared(element::f32, data_shape); + auto I = make_shared(element::i32, indices_shape); + int64_t axis = 4; + auto A = make_shared(element::f32, Shape{1}, vector{axis}); + int64_t batch_dims = 0; + + try + { + auto G = make_shared(D, I, A, batch_dims); + // Should have thrown, so fail if it didn't + FAIL() << "axis element_type check failed"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Axis element type must be of an integral number type")); + } + catch (...) + { + FAIL() << "Deduced type check failed for unexpected reason"; + } +} From a359fe9f3789a64b33b0dbb7f5a3494f61099e16 Mon Sep 17 00:00:00 2001 From: Szymon Irzabek Date: Tue, 20 Apr 2021 09:40:00 +0200 Subject: [PATCH 16/78] [GNA] Add basic low precision support for more layer types (#5138) * [GNA] Add basic low precision support for more layer types, add simple test * [GNA] Fix test * [GNA] Make divisor const, add more clarity to some conditions --- .../src/gna_plugin/backend/make_pwl.cpp | 58 +++++------ .../gna_plugin/frontend/scale_factor_calc.hpp | 2 +- .../src/gna_plugin/gna_graph_compiler.cpp | 95 ++++++++++++------- .../single_layer_tests/low_precision.cpp | 67 +++++++++++++ .../single_layer_tests/low_precision.hpp | 15 +++ .../single_layer/low_precision.hpp | 34 +++++++ .../src/single_layer/low_precision.cpp | 79 +++++++++++++++ 7 files changed, 285 insertions(+), 65 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/low_precision.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/low_precision.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/low_precision.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/src/single_layer/low_precision.cpp diff --git a/inference-engine/src/gna_plugin/backend/make_pwl.cpp b/inference-engine/src/gna_plugin/backend/make_pwl.cpp index 6190a89540f..f4b71c0f0c0 100644 --- a/inference-engine/src/gna_plugin/backend/make_pwl.cpp +++ b/inference-engine/src/gna_plugin/backend/make_pwl.cpp @@ -21,6 +21,8 @@ void make_gna_pwl(const DnnActivation fun, const bool low_precision, std::vector &gna_pwl) { pwl_gna_slope_scale_t s; + const int16_t y_min = low_precision ? INT8_MIN : INT16_MIN; + const int16_t y_max = low_precision ? INT8_MAX : INT16_MAX; uint32_t pwl_size = static_cast(pwl.size()); gnalog() << "make_gna_pwl\n"; gnalog() << " in_scale " << in_scale << "\n"; @@ -35,7 +37,7 @@ void make_gna_pwl(const DnnActivation fun, gna_pwl[0].xBase = static_cast (INT32_MIN & XBASEMASK); // zero out the 2 lsb if (fun == kActSigmoid) { gnalog() << "=========================== Sigmoid Segments ===========================\n"; - auto minVal = fun.fqParams.set? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale): 0; + auto minVal = fun.fqParams.set ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : 0; gna_pwl[0].yBase = gna_pwl[1].yBase = minVal; gna_pwl[1].xBase = (static_cast (in_scale * (-pwl[0].b / pwl[0].m))) & XBASEMASK; } else if (fun == kActTanh) { @@ -130,8 +132,8 @@ void make_gna_pwl(const DnnActivation fun, } // insert extra segment for xvalues > u_bound gna_pwl[n_segments - 1].xBase = - ((uint32_t)(in_scale * (INT16_MAX/out_scale - pwl[pwl_size - 2].b) / pwl[pwl_size - 2].m)) & XBASEMASK; - gna_pwl[n_segments - 1].yBase = INT16_MAX; + ((uint32_t)(in_scale * (y_max/out_scale - pwl[pwl_size - 2].b) / pwl[pwl_size - 2].m)) & XBASEMASK; + gna_pwl[n_segments - 1].yBase = y_max; gna_pwl[n_segments - 1].slope = 0; gnalog() << (gna_pwl[n_segments - 1].xBase / in_scale) @@ -146,7 +148,7 @@ void make_gna_pwl(const DnnActivation fun, // insert extra segment for x values < l_bound gna_pwl[0].xBase = static_cast (INT32_MIN & XBASEMASK); // zero out the 2 lsb gnalog() << "=========================== Log Segments ===========================\n"; - gna_pwl[0].yBase = gna_pwl[1].yBase = INT16_MIN; + gna_pwl[0].yBase = gna_pwl[1].yBase = y_min; gna_pwl[1].xBase = (static_cast (1 + ~XBASEMASK)); // smallest representable value gna_pwl[0].slope = 0; @@ -188,7 +190,7 @@ void make_gna_pwl(const DnnActivation fun, gnalog() << "=========================== NegHalfLog Segments ===========================\n"; else gnalog() << "=========================== NegLog Segments ===========================\n"; - gna_pwl[0].yBase = gna_pwl[1].yBase = INT16_MAX; + gna_pwl[0].yBase = gna_pwl[1].yBase = y_max; gna_pwl[1].xBase = (static_cast (1 + ~XBASEMASK)); // smallest representable value gna_pwl[0].slope = 0; @@ -231,8 +233,8 @@ void make_gna_pwl(const DnnActivation fun, gnalog() << "=========================== LeakyReLU Segments ======================\n"; int32_t x_lower = INT32_MIN; int32_t x_upper = INT32_MAX; - int16_t y_lower = low_precision ? INT8_MIN : INT16_MIN; - int16_t y_upper = INT16_MAX; + int16_t y_lower = y_min; + int16_t y_upper = y_max; if (fun.fqParams.set) { x_lower = FLOAT_TO_INT32(*fun.fqParams.input_low * 1.25 * in_scale); x_upper = FLOAT_TO_INT32(*fun.fqParams.input_high * 1.25 * in_scale); @@ -314,8 +316,8 @@ void make_gna_pwl(const DnnActivation fun, case kActFakeQuantize: { int32_t x_lower = INT32_MIN; int32_t x_upper = INT32_MAX; - int16_t y_lower = INT16_MIN; - int16_t y_upper = INT16_MAX; + int16_t y_lower = y_min; + int16_t y_upper = y_max; if (fun == kActFakeQuantize && fun.fqParams.set) { x_lower = *fun.fqParams.input_low * in_scale; x_upper = *fun.fqParams.input_high * in_scale; @@ -383,7 +385,7 @@ void make_gna_pwl(const DnnActivation fun, } case kActAbs: { int32_t x_upper = INT32_MAX; - int16_t y_upper = INT16_MAX; + int16_t y_upper = y_max; int32_t i = 0; auto n_segments = 2; @@ -392,11 +394,11 @@ void make_gna_pwl(const DnnActivation fun, if (x_upper > y_upper * in_scale / out_scale) x_upper = FLOAT_TO_INT32(y_upper * in_scale / out_scale); gnalog() << "=========================== Abs Segments ===========================\n"; - if (y_upper == INT16_MAX) { // saturation at ends - need one more segment + if (y_upper == y_max) { // saturation at ends - need one more segment n_segments += 1; gna_pwl.resize(n_segments); gna_pwl[i].xBase = INT32_MIN & XBASEMASK; // zero out the 2 lsb - gna_pwl[i].yBase = INT16_MAX; + gna_pwl[i].yBase = y_max; gna_pwl[i].slope = 0; i++; } else { @@ -430,8 +432,8 @@ void make_gna_pwl(const DnnActivation fun, float pow_offset = fun.args.pow.offset; int32_t x_lower = INT32_MIN; int32_t x_upper = INT32_MAX; - int16_t y_lower = INT16_MIN; - int16_t y_upper = INT16_MAX; + int16_t y_lower = y_min; + int16_t y_upper = y_max; auto n_segments = 2; if (pow_exponent == 0.0f) { @@ -472,27 +474,27 @@ void make_gna_pwl(const DnnActivation fun, int32_t y_upper_new = FLOAT_TO_INT32((y_upper / out_scale + pow_offset) * out_scale); y_lower = static_cast(y_lower_new); y_upper = static_cast(y_upper_new); - if (y_lower_new < INT16_MIN) { - int32_t offset_lower = abs(y_lower_new - INT16_MIN) / out_scale * in_scale; - y_lower = INT16_MIN; + if (y_lower_new < y_min) { + int32_t offset_lower = abs(y_lower_new - y_min) / out_scale * in_scale; + y_lower = y_min; x_lower = x_lower + offset_lower; } - if (y_lower_new > INT16_MAX) { - int32_t offset_lower = (y_lower_new - INT16_MAX) / out_scale * in_scale; - y_lower = INT16_MAX; + if (y_lower_new > y_max) { + int32_t offset_lower = (y_lower_new - y_max) / out_scale * in_scale; + y_lower = y_max; x_upper = x_upper + offset_lower; } - if (y_upper_new > INT16_MAX) { - int32_t offset_upper = (y_upper_new - INT16_MAX) / out_scale * in_scale; - y_upper = INT16_MAX; + if (y_upper_new > y_max) { + int32_t offset_upper = (y_upper_new - y_max) / out_scale * in_scale; + y_upper = y_max; x_upper = x_upper - offset_upper; } - if (y_upper_new < INT16_MIN) { - int32_t offset_upper = abs(y_upper_new - INT16_MAX) / out_scale * in_scale; - y_upper = INT16_MIN; + if (y_upper_new < y_min) { + int32_t offset_upper = abs(y_upper_new - y_max) / out_scale * in_scale; + y_upper = y_min; x_lower = x_lower - offset_upper; } } @@ -567,8 +569,8 @@ void make_gna_pwl(const DnnActivation fun, } // insert extra segment for xvalues > u_bound gna_pwl[n_segments - 1].xBase = - ((uint32_t)(in_scale * (INT16_MAX / out_scale - pwl[pwl_size - 2].b) / pwl[pwl_size - 2].m)) & XBASEMASK; - gna_pwl[n_segments - 1].yBase = INT16_MAX; + ((uint32_t)(in_scale * (y_max / out_scale - pwl[pwl_size - 2].b) / pwl[pwl_size - 2].m)) & XBASEMASK; + gna_pwl[n_segments - 1].yBase = y_max; gna_pwl[n_segments - 1].slope = 0; gnalog() << (gna_pwl[n_segments - 1].xBase / in_scale) diff --git a/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp b/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp index a2bfaccc00f..2c9e7ecfa76 100644 --- a/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp +++ b/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp @@ -264,7 +264,7 @@ class ScaleFactorPerLayer { auto input_min_value = static_cast(std::numeric_limits::min()); auto input_max_value = static_cast(std::numeric_limits::max()); - auto output_max_value = static_cast(std::numeric_limits::max()); + auto output_max_value = static_cast((inputsSize == 2) ? std::numeric_limits::max() : std::numeric_limits::max()); auto x_min = fp32eq(fmod(powerLayer->power, 1.0), 0) ? input_min_value / quantizedParams->_src_quant.GetScale() : 0.0; x_min = std::max(x_min, -pow_domain); diff --git a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp index 03f901eea27..c6324485cf7 100644 --- a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp +++ b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp @@ -694,10 +694,12 @@ void GNAGraphCompiler::PowerPrimitive(InferenceEngine::CNNLayerPtr layer) { auto outputs = *layer->outData.begin(); auto reshaped_dims = Get2DReshapedData(input, 8)->getDims(); + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; uint32_t num_rows_in = reshaped_dims[1]; uint32_t num_columns_in = reshaped_dims[0]; uint32_t num_rows_out = num_rows_in; - uint32_t num_padding = ALIGN(num_rows_in, 8) - num_rows_in; + uint32_t num_padding = ALIGN(num_rows_in, noOfInputsDivisor) - num_rows_in; size_t num_data_bytes_out = InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())) * outputs->getPrecision().size(); @@ -720,8 +722,8 @@ void GNAGraphCompiler::PowerPrimitive(InferenceEngine::CNNLayerPtr layer) { input->getPrecision().size(), outputs->getPrecision().size(), // TODO: only fp32 and Int16 tested - quantized == nullptr ? input->getPrecision().size() : 2, - quantized == nullptr ? input->getPrecision().size() : 4, + quantized == nullptr ? input->getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 2), + quantized == nullptr ? input->getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 4), quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), ptr_inputs, @@ -739,12 +741,21 @@ void GNAGraphCompiler::PowerPrimitive(InferenceEngine::CNNLayerPtr layer) { gnamem->readonly().push_value(ptr_biases, power.offset, num_rows_out, 64); } else { IE_ASSERT(quantized != nullptr); - auto quantizedScale = FLOAT_TO_INT16(std::min(quantized->_weights_quant.GetScale() * power.scale, - static_cast(INT16_MAX))); - auto quantizedOffset = FLOAT_TO_INT32(std::min(quantized->_dst_quant.GetScale() * power.offset, - static_cast(INT32_MAX))); - gnamem->readonly().push_value(ptr_weights, quantizedScale, num_rows_out, 64); - gnamem->readonly().push_value(ptr_biases, quantizedOffset, num_rows_out, 64); + if (!gnaFlags->input_low_precision) { + auto quantizedScale = FLOAT_TO_INT16(std::min(quantized->_weights_quant.GetScale() * power.scale, + static_cast(INT16_MAX))); + auto quantizedOffset = FLOAT_TO_INT32(std::min(quantized->_dst_quant.GetScale() * power.offset, + static_cast(INT32_MAX))); + gnamem->readonly().push_value(ptr_weights, quantizedScale, num_rows_out, 64); + gnamem->readonly().push_value(ptr_biases, quantizedOffset, num_rows_out, 64); + } else { + auto quantizedScale = FLOAT_TO_INT8(std::min(quantized->_weights_quant.GetScale() * power.scale, + static_cast(INT8_MAX))); + auto quantizedOffset = FLOAT_TO_INT8(std::min(quantized->_dst_quant.GetScale() * power.offset, + static_cast(INT8_MAX))); + gnamem->readonly().push_value(ptr_weights, quantizedScale, num_rows_out, 64); + gnamem->readonly().push_value(ptr_biases, quantizedOffset, num_rows_out, 64); + } } } else { //use PWL to calculate power @@ -1041,10 +1052,12 @@ void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { << axis.size() << "."; } - auto quantized = InferenceEngine::getInjectedData(layer); size_t cropOffset = offset.front() * cropLayer->precision.size(); size_t cropOutputSize = dim.front() * cropLayer->precision.size(); + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; + // fix for crop on tensor dim > 2D for (int n = axis[0]+1; n < cropLayer->dim.size(); n++) { cropOffset *= cropLayer->dim[n]; @@ -1088,7 +1101,7 @@ void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { uint32_t num_columns_in = 1; uint32_t num_rows_out = GetDataDimSize(outputs, inputs->getDims().size() - axis.front()); - uint32_t num_padding = ALIGN(num_rows_in, 8) - num_rows_in; + uint32_t num_padding = ALIGN(num_rows_in, noOfInputsDivisor) - num_rows_in; void* ptr_inputs = nullptr; void* ptr_outputs = nullptr; @@ -1102,9 +1115,9 @@ void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { num_columns_in, num_rows_out, inputs->getPrecision().size(), - 4, - quantized == nullptr ? inputs->getPrecision().size() : 2, - 4, + outputs->getPrecision().size(), + quantized == nullptr ? inputs->getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 2), + gnaFlags->input_low_precision ? 1 : 4, quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), ptr_inputs, @@ -1118,7 +1131,7 @@ void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { begin(outputs->getDims()), end(outputs->getDims())) * 4; size_t num_data_bytes_in = num_columns_in * - ALIGN(num_rows_in, 8) * inputs->getPrecision().size(); + ALIGN(num_rows_in, noOfInputsDivisor) * inputs->getPrecision().size(); connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 0); connectOutput(layer, ptr_outputs, num_data_bytes_out); @@ -1142,8 +1155,8 @@ void GNAGraphCompiler::SlicePrimitive(InferenceEngine::CNNLayerPtr layer) { void GNAGraphCompiler::EltwisePrimitive(InferenceEngine::CNNLayerPtr layer) { auto& eltwise = dynamic_cast(*layer.get()); auto quantized = InferenceEngine::getInjectedData(layer); - uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? - GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; // for eltwise sum/sub in 16-bit precision one input should be 4 bytes and one 2 bytes - detecting that below // the names of variables are left for clarity although not always reflecting the real precision/size @@ -1231,8 +1244,8 @@ void GNAGraphCompiler::EltwisePrimitive(InferenceEngine::CNNLayerPtr layer) { inputs2Bytes->getPrecision().size(), outputs->getPrecision().size(), // TODO: only fp32 and Int16 tested - quantized == nullptr ? inputs2Bytes->getPrecision().size() : (!gnaFlags->input_low_precision ? 2 : 1), - quantized == nullptr ? inputs4Bytes->getPrecision().size() : (!gnaFlags->input_low_precision ? 4 : 1), + quantized == nullptr ? inputs2Bytes->getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 2), + quantized == nullptr ? inputs4Bytes->getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 4), quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), ptr_inputs, @@ -1340,8 +1353,9 @@ void GNAGraphCompiler::AffinePrimitive(InferenceEngine::CNNLayerPtr layer, bool void* ptr_weights = nullptr; void* ptr_biases = nullptr; - // TODO: questionable why for biases that are no in Model we inventing precision - auto biasPrecision = weightable._biases ? weightable._biases->getTensorDesc().getPrecision() : outputs->getPrecision(); + // TODO: questionable why for biases that are not in IR we inventing precision + auto biasPrecisionSize = weightable._biases ? + weightable._biases->getTensorDesc().getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 4); // layer without biases might be connected to functional layer without activations auto prevLayer = CNNNetPrevLayer(layer); @@ -1365,7 +1379,7 @@ void GNAGraphCompiler::AffinePrimitive(InferenceEngine::CNNLayerPtr layer, bool inputPrecision.size(), outputs->getPrecision().size(), weightable._weights->getTensorDesc().getPrecision().size(), - biasPrecision.size(), + biasPrecisionSize, quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), ptr_inputs, @@ -1518,10 +1532,12 @@ void GNAGraphCompiler::ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr l auto outputs = *layer->outData.begin(); auto inputs = layer->insData.begin()->lock(); + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; uint32_t num_columns_in = GetDataDimSize(inputs, 2); uint32_t num_rows_out = GetDataDimSize(outputs, 1); uint32_t num_rows_in = filterLayer->_weights->size() / num_rows_out; - uint32_t num_padding = ALIGN(num_rows_in, 8) - num_rows_in; + uint32_t num_padding = ALIGN(num_rows_in, noOfInputsDivisor) - num_rows_in; auto numRowsPadded = filterLayer->GetParamAsInt("num_rows_padded"); // number of rows we handled by inserting copy layer @@ -1568,8 +1584,9 @@ void GNAGraphCompiler::ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr l } filterLayer->params["rows_copied_offset"] = std::to_string(num_rows_copied * inputs->getPrecision().size()); - - auto biasPrecision = filterLayer->_biases ? filterLayer->_biases->getTensorDesc().getPrecision() : outputs->getPrecision(); + // TODO: questionable why for biases that are not in IR we inventing precision + auto biasPrecisionSize = filterLayer->_biases ? + filterLayer->_biases->getTensorDesc().getPrecision().size() : (gnaFlags->input_low_precision ? 1 : 4); auto& currentComponent = dnnComponents.addComponent(layer->name, "affine"); dnn->InitAffineComponent(currentComponent, @@ -1579,7 +1596,7 @@ void GNAGraphCompiler::ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr l inputs->getPrecision().size(), outputs->getPrecision().size(), filterLayer->_weights->getTensorDesc().getPrecision().size(), - biasPrecision.size(), + biasPrecisionSize, quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), ptr_inputs, @@ -1590,7 +1607,7 @@ void GNAGraphCompiler::ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr l size_t num_data_bytes_out = num_rows_out * num_columns_in * outputs->getPrecision().size(); size_t num_data_bytes_in = num_columns_in * - ALIGN(num_rows_in, 8) * inputs->getPrecision().size(); + ALIGN(num_rows_in, noOfInputsDivisor) * inputs->getPrecision().size(); connectInput(layer, ptr_inputs, num_data_bytes_in, num_rows_copied * inputs->getPrecision().size(), 0); connectOutput(layer, ptr_outputs, num_data_bytes_out); @@ -1641,7 +1658,7 @@ void GNAGraphCompiler::AffineFilterPrimitive(InferenceEngine::CNNLayerPtr layer) auto prevLayer = CNNNetPrevLayer(layer.get(), 0); if (!LayerInfo(prevLayer).isSplit() && !LayerInfo(prevLayer).isSlice()) { - THROW_GNA_EXCEPTION << "Case with Affine Aligning Filter for not Split/Slice layers is not implemented yet!"; + THROW_GNA_EXCEPTION << "Case with Affine Aligning Filter for not Split/Slice layers is not implemented yet!"; } void* ptr_inputs = nullptr; @@ -1654,11 +1671,13 @@ void GNAGraphCompiler::AffineFilterPrimitive(InferenceEngine::CNNLayerPtr layer) auto outputs = *layer->outData.begin(); auto inputs = layer->insData.begin()->lock(); + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; uint32_t num_columns_in = GetDataDimSize(inputs, 2); uint32_t num_rows_out = GetDataDimSize(outputs, 1); uint32_t num_rows_in = filterLayer->_weights->size() / num_rows_out; - uint32_t num_padding = ALIGN(num_rows_in, 8) - num_rows_in; + uint32_t num_padding = ALIGN(num_rows_in, noOfInputsDivisor) - num_rows_in; auto biasPrecision = filterLayer->_biases ? filterLayer->_biases->getTensorDesc().getPrecision() : outputs->getPrecision(); auto& currentComponent = dnnComponents.addComponent(layer->name, "affine"); @@ -1683,7 +1702,7 @@ void GNAGraphCompiler::AffineFilterPrimitive(InferenceEngine::CNNLayerPtr layer) begin(outputs->getDims()), end(outputs->getDims())) * 4; size_t num_data_bytes_in = num_columns_in * - ALIGN(num_rows_in, 8) * inputs->getPrecision().size(); + ALIGN(num_rows_in, noOfInputsDivisor) * inputs->getPrecision().size(); connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 0); connectOutput(layer, ptr_outputs, num_data_bytes_out); @@ -1983,10 +2002,13 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { << std::min(squeezedInputOrder[0], squeezedInputOrder[1]) << " > 8)"; } + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; + // now this can be run on GNA if (squeezedInputOrder[0] < squeezedInputOrder[1]) { // interleave case - if (ALIGN(squeezedInputOrder[1], 8) != squeezedInputOrder[1]) { - THROW_GNA_LAYER_EXCEPTION(layer) << "unsupported permute (row size not a multiple of 8)"; + if (ALIGN(squeezedInputOrder[1], noOfInputsDivisor) != squeezedInputOrder[1]) { + THROW_GNA_LAYER_EXCEPTION(layer) << "unsupported permute (row size not a multiple of " << noOfInputsDivisor << ")"; } else { auto& currentComponent = dnnComponents.addComponent(layer->name, "interleave"); dnn->InitInterleaveComponent(currentComponent, @@ -2000,8 +2022,8 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { } } else { // deinterleave case - if (ALIGN(squeezedInputOrder[0], 8) != squeezedInputOrder[0]) { - THROW_GNA_LAYER_EXCEPTION(layer) << "[GNA plugin] unsupported permute (column size not a multiple of 8)"; + if (ALIGN(squeezedInputOrder[0], noOfInputsDivisor) != squeezedInputOrder[0]) { + THROW_GNA_LAYER_EXCEPTION(layer) << "[GNA plugin] unsupported permute (column size not a multiple of " << noOfInputsDivisor << ")"; } else { auto& currentComponent = dnnComponents.addComponent(layer->name, "deinterleave"); dnn->InitDeinterleaveComponent(currentComponent, @@ -2016,7 +2038,7 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { } size_t num_data_bytes_out = ALIGN(InferenceEngine::details::product( - begin(outputs->getDims()), end(outputs->getDims())), 8) + begin(outputs->getDims()), end(outputs->getDims())), noOfInputsDivisor) * outputs->getPrecision().size(); size_t num_data_bytes_in = squeezedInputOrder[0] * squeezedInputOrder[1] * inputs->getPrecision().size(); @@ -2277,7 +2299,8 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, // if request for allocation less that realTensorInput - we need to extend request auto minInput = inputDesc->minBytesRequiredForStoreInput(prevLayer); if (num_data_bytes_in < minInput) { - uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; + const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? + GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; gnalog() << "[INPUT] : requested bytes: " << num_data_bytes_in << ", extended to" << ALIGN(minInput, noOfInputsDivisor); num_data_bytes_in = ALIGN(minInput, noOfInputsDivisor); } diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/low_precision.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/low_precision.cpp new file mode 100644 index 00000000000..04853e09860 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/single_layer_tests/low_precision.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "single_layer_tests/low_precision.hpp" +#include "common_test_utils/test_constants.hpp" +#include "../skip_tests_check.hpp" + +using namespace LowPrecisionTestDefinitions; + +namespace { + +class GnaLowPrecisionTest : public LowPrecisionTest, GnaLayerTestCheck { +protected: + void Run() override { + GnaLayerTestCheck::SkipTestCheck(); + + if (!GnaLayerTestCheck::skipTest) { + LowPrecisionTest::Run(); + } + } + + void SetUp() override { + LowPrecisionTest::SetUp(); + } +}; + +TEST_P(GnaLowPrecisionTest, CompareWithRefs) { + Run(); +} + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::map config_fp32 = { + {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, +}; + +const std::map config_i16 = { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "1"}, + {"GNA_PRECISION", "I16"}, +}; + +const std::map config_i8 = { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "1"}, + {"GNA_PRECISION", "I8"}, +}; + +const std::vector>> configs = { + {"sw_fp32", config_fp32}, + {"sw_exact_i16", config_i16}, + {"sw_exact_i8", config_i8}, +}; + +INSTANTIATE_TEST_CASE_P(DISABLED_smoke_LowPrecision, GnaLowPrecisionTest, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(configs)), + GnaLowPrecisionTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/low_precision.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/low_precision.hpp new file mode 100644 index 00000000000..b66d35bb5b7 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/low_precision.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_layer/low_precision.hpp" + +namespace LowPrecisionTestDefinitions { + + TEST_P(LowPrecisionTest, CompareWithRefs) { + Run(); + } + +} // namespace LowPrecisionTestDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/low_precision.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/low_precision.hpp new file mode 100644 index 00000000000..d45b6d605d9 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/low_precision.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LowPrecisionTestDefinitions { + +typedef std::tuple< + InferenceEngine::Precision, // Net precision + LayerTestsUtils::TargetDevice, // Device name + std::pair> // Configuration +> lowPrecisionTestParamsSet; + +class LowPrecisionTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; +}; +// ! [test_low_precision:definition] + +} // namespace LowPrecisionTestDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/low_precision.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/low_precision.cpp new file mode 100644 index 00000000000..bc4ad3f3f08 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/low_precision.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2019-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/low_precision.hpp" +#include "ngraph_functions/builders.hpp" + +namespace LowPrecisionTestDefinitions { + +std::string LowPrecisionTest::getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + std::string targetDevice; + std::pair> config; + std::tie(netPrecision, targetDevice, config) = obj.param; + + std::ostringstream result; + result << "netPRC=" << netPrecision.name() << "_"; + result << "trgDev=" << targetDevice; + if (!config.first.empty()) { + result << "_targetConfig=" << config.first; + } + return result.str(); +} + +void LowPrecisionTest::SetUp() { + InferenceEngine::Precision netPrecision; + std::pair> config; + std::tie(netPrecision, targetDevice, config) = this->GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto inputShape = ngraph::Shape{ 1, 16 }; + auto weights1Shape = ngraph::Shape{ 16, 16 }; + auto weights2Shape = ngraph::Shape{ 128, 32 }; + + // fully connected 1 + auto input = std::make_shared(ngPrc, inputShape); + std::vector weights1Data(ngraph::shape_size(weights1Shape), 0.0f); + + for (size_t i = 0; i < 16; i++) { + weights1Data[i * 17] = 10.0f + i; + } + + auto weights1 = ngraph::builder::makeConstant(ngPrc, weights1Shape, weights1Data); + auto fc1 = std::make_shared(input, weights1); + fc1->set_friendly_name("FullyConnected_1"); + + // bias 1 + std::vector bias1Data(ngraph::shape_size(inputShape), 0.0f); + auto bias1 = ngraph::builder::makeConstant(ngPrc, inputShape, bias1Data); + auto add1 = std::make_shared(fc1, bias1); + add1->set_friendly_name("Add_1"); +#if 0 + // ReLU 1 + auto relu1 = std::make_shared(add1); + relu1->set_friendly_name("Relu_1"); + + //// fully connected 2 + std::vector weights2Data(ngraph::shape_size(weights2Shape), 0.0f); + std::fill(weights2Data.begin(), weights2Data.end(), 0.0001f); + auto weights2 = ngraph::builder::makeConstant(ngPrc, weights2Shape, weights2Data); + auto fc2 = std::make_shared(relu1, weights2); + fc2->set_friendly_name("FullyConnected_2"); + + //// bias 2 + std::vector bias2Data(ngraph::shape_size(weights2Shape), 0.0f); + auto bias2 = ngraph::builder::makeConstant(ngPrc, weights2Shape, bias2Data); + auto add2 = std::make_shared(fc2, bias2); + add2->set_friendly_name("Add_2"); + + //// ReLU 2 + auto relu2 = std::make_shared(add2); + relu2->set_friendly_name("Relu_2"); +#endif + configuration = config.second; + function = std::make_shared(ngraph::ResultVector{std::make_shared(add1)}, + ngraph::ParameterVector{input}, + "LowPrecisionTest"); +} + +} // namespace LowPrecisionTestDefinitions From 7a500e185b0a42f9589bb578fd5d67ab12a35610 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Tue, 20 Apr 2021 11:04:38 +0300 Subject: [PATCH 17/78] Specify Einsum-7 operation (#5145) * Specify Einsum-7 operation Signed-off-by: Roman Kazantsev * Finalize specification for Einsum-7 operation Signed-off-by: Roman Kazantsev * Remove duplicate example Signed-off-by: Roman Kazantsev * Update doc headers with Einsum operation Signed-off-by: Roman Kazantsev * Apply comments after the first review: grammar corrections and sentence rephrase Signed-off-by: Roman Kazantsev * Apply feedback from tech-writers and online review Signed-off-by: Roman Kazantsev * Make additional grammar corrections Signed-off-by: Roman Kazantsev * Correct documentation: optimize some sentences, links and examples Signed-off-by: Roman Kazantsev * Support capital letters in equation and implicit mode Signed-off-by: Roman Kazantsev --- docs/doxygen/ie_docs.xml | 1 + docs/ops/matrix/Einsum_7.md | 242 ++++++++++++++++++++++++++++++++++++ docs/ops/opset7.md | 1 + 3 files changed, 244 insertions(+) create mode 100644 docs/ops/matrix/Einsum_7.md diff --git a/docs/doxygen/ie_docs.xml b/docs/doxygen/ie_docs.xml index 8ca6ff2588e..0b6af577c97 100644 --- a/docs/doxygen/ie_docs.xml +++ b/docs/doxygen/ie_docs.xml @@ -132,6 +132,7 @@ limitations under the License. + diff --git a/docs/ops/matrix/Einsum_7.md b/docs/ops/matrix/Einsum_7.md new file mode 100644 index 00000000000..ab8057dfcee --- /dev/null +++ b/docs/ops/matrix/Einsum_7.md @@ -0,0 +1,242 @@ +## Einsum {#openvino_docs_ops_matrix_Einsum_7} + +**Versioned name**: *Einsum-7* + +**Category**: Matrix multiplication + +**Short description**: *Einsum* performs the Einstein summation convention on the operands. + +**Detailed description**: *Einsum* can represent many common multidimensional linear algebraic tensor operations: matrix multiplication; +inner (or dot), outer and cross products; transpose; trace and diagonal extraction. +Also, a single *Einsum* operation can express complex combination of these common linear algebraic tensor operations on multiple operands, +for example, a dot product of a diagonal, extracted from a tensor with shape `[5, 5]`, and 5D vector is performed by single Einsum operation. +The Einstein summation convention on input tensors is defined by `equation`, which is a mandatory attribute of *Einsum* operation. +The operation supports `equation` in explicit and implicit modes. The formats of `equation` in both modes are described below. + +In explicit mode, the einsum `equation` has the output subscript separated from the input subscripts by `->`, and has the following format for `n` operands: +`, , ..., -> `. +Each input subscript `` contains a sequence of labels (alphabetic letters `['A',...,'Z','a',...,'z']`), +where each label refers to a dimension of the corresponsing operand. Labels are case sensitive and capital letters precede lowercase letters in alphabetical sort. +Labels do not need to appear in a subscript in alphabetical order. +The subscript for a scalar input is empty. The input subscripts are separated with a comma `,`. +The output subscript `` represents a sequence of labels (alphabetic letters `['A',...,'Z','a',...,'z']`). +The length of an input subscript matches a rank of the input. The input subscript is empty for a scalar input. + +*Einsum* operation on multiple inputs can be treated as several consecutive *Einsum* operations. In the first step, *Einsum* applies the first two inputs. +In the second step, it operates on the result of the first step and the third input, and so forth. +*Einsum* operates on two operands similar to element-wise multiplication by all pairs of batches from both operands. +The batch dimensions are defined with labels belonging to only one of the two input subscripts. + +For example, the intermediate result after the first step for *Einsum* with three inputs of shapes `[2, 5]`, `[5, 3, 6]` and `[5, 3]`, +and `equation` equal to `ab,bcd,bc->ca` will be a tensor of shape `[2, 5, 3, 6]` with a subscript `abcd`, +where batch dimensions for the first input and the second input are represented with label sequences `a` and `cd`. +The next step performs the same logic on input tensors of shapes `[2, 5, 3, 6]` and `[5, 3]` with subscripts `abcd` and `bc`, and +outputs a tensor of shape `[2, 5, 3, 6]` with a subscript `abcd`. +Lastly, the output subscript defines the order of output dimensions, and sum-reduced dimensions. +Dimensions corresponding to absent labels in the output subscript are sum-reduced. The final result for the considered example is of shape equal to `[3,2]`, +where dimensions with labels `b` and `d` are reduced, and the transpose is applied to get output layout `ca`. + +**NOTE**: *Einsum* operation can perform on a single operand. In this case, the operation can transpose the input and reduce its dimensions. + +**NOTE**: Input ranks must be equal to the length of corresponding subscripts. Dimensions with the same corresponding labels in input subscripts +must be equal in size. + +**NOTE**: A label can be repeated in the same input subscript, for example, `equation` equal to `aac,abd,ddde`. In this case, the corresponding dimensions +must match in size, and the operand is replaced by its diagonal along these dimensions. +For example, *Einsum* operation on the single 3D tensor of shape `[2, 4, 5, 4]` with `equation` equal to `ijkj->ij`. + +**NOTE**: The specification considers the primitive algorithm for *Einsum* operation for better understanding of the operation +and does not recommend it for implementation. + +**NOTE**: The described algorithm can be improved by immediate dimension sum-reduction of the intermediate results if the corresponding labels are absent +in the input subscripts of subsequent inputs and the output subscript. It can significantly boost performance and reduce memory costs. +In the considered example, after the first step you can reduce the dimension corresponding to the label `d`. + +The output shape is computed by concatenation of dimension sizes to which labels in the output subscript correspond in the specified order. + +Example 1 shows how *Einsum* computes inner product of two 1D tensors: + +``` +a1 = [1.0, 2.0, 3.0] +a2 = [4.0, 5.0, 6.0] +equation = "i,i->" +output = 32.0 +``` + +Example 2 shows how *Einsum* computes matrix-vector multiplication: + +``` +A = [[1.0, 2.0, 3.0], + [1.0, 2.0, 3.0]] +b = [4.0, 5.0, 6.0] +equation = "ij,j->i" +output = [32.0, 32.0] +``` + +Example 3 shows how *Einsum* computes a trace for each batch object: + +``` +A = [[[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, 9.0]], + [[2.0, 4.0, 6.0], + [8.0, 10.0, 12.0], + [14.0, 16.0, 18.0]]] +equation = "kii->k" +output = [15.0, 30.0] +``` + +Example 4 shows how *Einsum* extracts a diagonal for each batch object: + +``` +A = [[[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, 9.0]], + [[2.0, 4.0, 6.0], + [8.0, 10.0, 12.0], + [14.0, 16.0, 18.0]]] +equation = "kii->ki" +output = [[1.0, 5.0, 9.0], + [2.0, 10.0, 18.0]] +``` + +Example 5 shows how *Einsum* transposes input tensor: + +``` +A = [[[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, 9.0]]] +equation = "ijk->kij" +output = [[[1.0, 4.0, 7.0]], + [[2.0, 5.0, 8.0]], + [[3.0, 6.0, 9.0]]] +``` + +In addition to an alphabetic label, ellipsis `...` can be used as a label in a subscript to cover broadcasted dimensions. +Each input subscript can contain at most one ellipsis. For example, the ellipsis in input subscript `a...bc` for five rank tensor covers +the second and third dimensions. In case input subscripts contain ellipsis for several operands, the dimensions covered by the ellipsis +must be broadcastable to satisfy numpy broadcasting (or multidirectional broadcasting) rules available in +[Broadcast Rules For Elementwise Operations](../broadcast_rules.md). +If at least one input subscript contains an ellipsis, the output subscript must always contain one ellipsis. +For example, *Einsum* operation on two inputs of shapes `[9, 1, 4, 3]` and `[3, 11, 7, 1]` with `equation="a...b,b...->a..."` +has ellipsis for both operands covering dimensions with sizes `[1, 4]` and `[11, 7, 1]` that are broadcasted to `[11, 7, 4]`. +The resulted shape of *Einsum* operation will be `[9, 11, 7, 4]` since the dimension labeled with `a` is left with broadcasted dimensions. + +Example 6 shows how *Einsum* operates on the single input with an equation containing ellipsis: + +``` +A = [[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, 9.0]] +equation = "a...->..." +output = [12.0, 15.0, 18.0] +``` + +Example 7 shows how *Einsum* operates with broadcasting two operands: + +``` +A = [[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, 9.0]] +B = [0.5] +equation = "a...,...->a..." +output = [[0.5, 1.0, 1.5], + [2.0, 2.5, 3.0], + [3.5, 4.0, 4.5]] +``` + +In implicit mode (a classical form of Einstein summation), the equation does not have the output subscript and has the following format: +`, , ..., `. +The equation in implicit mode consists of only input subscripts for each operand. +The output subscript can be recovered as a sequence of alphabetically sorted labels that are not repeated in the left-hand side of the equation. +For example, `equation = "dbbc,ca"` in implicit mode is equivalent to `equation = "dbbc,ca->ad"` in explicit mode. +The equation in implicit mode can set up only subset of Einstein summation conventions. For example, `equation = "kii->i"` cannot be represented in implicit mode. +In case ellipsis label is in the left-hand side of the equation in implicit mode, the ellipsis comes first in the output subscript for the recovery. + +Example 8 shows how *Einsum* operates with an equation containing both capital and lowercase letters in implicit mode +`equation = "AbC"` that is the same as `equation = "AbC->ACb"`: + +``` +A = [[[1.0, 2.0, 3.0], + [4.0, 5.0, 6.0]]] +equation = "AbC" +output = [[[1.0, 4.0], + [2.0, 5.0], + [3.0, 6.0]]] +``` + +**NOTE**: The equation in both modes can contain blank space characters (U+0020) at any positions that can be removed without losing equivalence. + +**Attributes**: + +* *equation* + + * **Description**: it defines Einstein summation convention on input operands. The equation must be in either explicit or implicit mode. + * **Range of values**: the equation format is described above + * **Type**: string + * **Required**: *yes* + +**Inputs**: + +* **Multiple inputs**: Tensors of type *T* and different shapes. + +**Output**: + +* **1**: Tensor of type *T* and shape is computed based on the output subscript of the equation. + +**Types** + +* *T*: any numeric type. + +**Examples** + +```xml + + + + + 2 + 64 + + + 2 + 64 + + + + + 2 + + + +``` + +```xml + + + + + 2 + 3 + 4 + + + 2 + 7 + 1 + + + 2 + 4 + 7 + + + + + 4 + 3 + 7 + + + +``` diff --git a/docs/ops/opset7.md b/docs/ops/opset7.md index c04b90e81a0..c00935b9451 100644 --- a/docs/ops/opset7.md +++ b/docs/ops/opset7.md @@ -44,6 +44,7 @@ declared in `namespace opset7`. * [DetectionOutput](detection/DetectionOutput_1.md) * [DFT](signals/DFT_7.md) * [Divide](arithmetic/Divide_1.md) +* [Einsum](matrix/Einsum_7.md) * [Elu](activation/Elu_1.md) * [EmbeddingBagOffsetsSum](sparse/EmbeddingBagOffsetsSum_3.md) * [EmbeddingBagPackedSum](sparse/EmbeddingBagPackedSum_3.md) From 49dceb281064c55a419254f4f8b275ac1e01517b Mon Sep 17 00:00:00 2001 From: Alexander Zhogov Date: Tue, 20 Apr 2021 13:00:43 +0300 Subject: [PATCH 18/78] Azure: Add install setuptools on Linux (#5299) * Azure: Add install setuptools on Linux * Add upgrade pip --- .ci/azure/linux.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ci/azure/linux.yml b/.ci/azure/linux.yml index 3469e976718..d0dbf890e64 100644 --- a/.ci/azure/linux.yml +++ b/.ci/azure/linux.yml @@ -79,6 +79,9 @@ jobs: - script: | sudo apt --assume-yes install libusb-1.0-0-dev + # For opencv-python: setuptools and upgrade + sudo apt-get install python3-setuptools + python3 -m pip install --upgrade pip python3 -m pip install -r $(REPO_DIR)/inference-engine/ie_bridges/python/requirements.txt # For running Python API tests python3 -m pip install -r $(REPO_DIR)/inference-engine/ie_bridges/python/src/requirements-dev.txt From 7963dc93ed743203d28675dabdefa16ef2c78cac Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Tue, 20 Apr 2021 14:43:33 +0300 Subject: [PATCH 19/78] [IE TESTS] Small refactoring of conformance suite (#5123) * TEST * test * tmp * c * Workaround fro unsaved report * d * e * tmp * test * Timeout + fix for summarize * Fixes * Remove debug coe --- .../conformance/subgraphs_dumper/src/main.cpp | 13 ++---- .../test_runner/include/gflag_config.hpp | 4 ++ .../conformance/test_runner/src/main.cpp | 15 ++----- .../functional/plugin/shared/src/main.cpp | 13 +++++- .../common_test_utils/file_utils.hpp | 3 +- .../layer_test_utils/summary.hpp | 5 +++ .../layer_tests_summary/merge_xmls.py | 10 +++-- .../layer_tests_summary/summarize.py | 40 ++++++++++++++++--- .../src/layer_test_utils/summary.cpp | 9 ++++- 9 files changed, 77 insertions(+), 35 deletions(-) diff --git a/inference-engine/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp b/inference-engine/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp index dc19cce8dbd..4d1f787f6ed 100644 --- a/inference-engine/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp +++ b/inference-engine/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp @@ -21,15 +21,9 @@ int main(int argc, char *argv[]) { showUsage(); return 0; } - std::vector input_folder_content; std::vector dirs = CommonTestUtils::splitStringByDelimiter(FLAGS_input_folders); - for (const auto &dir : dirs) { - if (!CommonTestUtils::directoryExists(dir)) { - std::string msg = "Input directory (" + dir + ") doesn't not exist!"; - throw std::runtime_error(msg); - } - CommonTestUtils::directoryFileListRecursive(dir, input_folder_content); - } + std::vector input_folder_content = + CommonTestUtils::getFileListByPatternRecursive(dirs, std::regex(R"(.*\.xml)")); if (!CommonTestUtils::directoryExists(FLAGS_output_folder)) { std::string msg = "Output directory (" + FLAGS_output_folder + ") doesn't not exist!"; @@ -39,10 +33,9 @@ int main(int argc, char *argv[]) { auto ie = InferenceEngine::Core(); auto cache = SubgraphsDumper::OPCache::make_cache(); - auto xml_regex = std::regex(R"(.*\.xml)"); for (const auto &file : input_folder_content) { try { - if (CommonTestUtils::fileExists(file) && std::regex_match(file, xml_regex)) { + if (CommonTestUtils::fileExists(file)) { std::cout << "Processing model: " << file << std::endl; std::string bin_file = CommonTestUtils::replaceExt(file, "bin"); if (!CommonTestUtils::fileExists(bin_file)) { diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp b/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp index a5c184768cc..68cefe44450 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp @@ -20,11 +20,14 @@ static const char input_folders_message[] = "Required. Paths to the input folder static const char output_folder_message[] = "Optional. Paths to the output folder to save report. Default value is \".\""; static const char report_unique_name_message[] = "Optional. Allow to save report with unique name (report_pid_timestamp.xml). " "Mutually exclusive with --extend_report. Default value is false"; +static const char save_report_timeout_message[] = "Optional. Allow to try to save report in cycle using timeout (in seconds). " + "Default value is 60 seconds"; DEFINE_bool(h, false, help_message); DEFINE_string(device, "CPU", target_device_message); DEFINE_string(input_folders, ".", input_folders_message); DEFINE_string(output_folder, ".", output_folder_message); +DEFINE_uint32(save_report_timeout, 60, save_report_timeout_message); DEFINE_bool(disable_test_config, true, disable_test_config_message); DEFINE_bool(extend_report, false, extend_report_config_message); DEFINE_bool(report_unique_name, false, report_unique_name_message); @@ -41,6 +44,7 @@ static void showUsage() { std::cout << " --disable_test_config " << disable_test_config_message << std::endl; std::cout << " --extend_report " << extend_report_config_message << std::endl; std::cout << " --report_unique_name " << extend_report_config_message << std::endl; + std::cout << " --save_report_timeout " << extend_report_config_message << std::endl; std::cout << " --device " << target_device_message << std::endl; std::cout << " --input_folders \"\" " << input_folders_message << std::endl; std::cout << " --output_folder \"\" " << output_folder_message << std::endl; diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp index b079df3f1ed..3172d66a42c 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp @@ -4,22 +4,12 @@ #include "gtest/gtest.h" +#include "common_test_utils/file_utils.hpp" #include "shared_test_classes/base/layer_test_utils.hpp" #include "gflag_config.hpp" #include "conformance.hpp" -static std::vector splitStringByDelimiter(std::string str, const std::string& delimiter = ",") { - size_t delimiterPos; - std::vector irPaths; - while ((delimiterPos = str.find(delimiter)) != std::string::npos) { - irPaths.push_back(str.substr(0, delimiterPos)); - str = str.substr(delimiterPos + 1); - } - irPaths.push_back(str); - return irPaths; -} - int main(int argc, char* argv[]) { // Workaround for Gtest + Gflag std::vector argv_gflags_vec; @@ -54,10 +44,11 @@ int main(int argc, char* argv[]) { LayerTestsUtils::Summary::setSaveReportWithUniqueName(true); } LayerTestsUtils::Summary::setOutputFolder(FLAGS_output_folder); + LayerTestsUtils::Summary::setSaveReportTimeout(FLAGS_save_report_timeout); // ---------------------------Initialization of Gtest env ----------------------------------------------- ConformanceTests::targetDevice = FLAGS_device.c_str(); - ConformanceTests::IRFolderPaths = splitStringByDelimiter(FLAGS_input_folders); + ConformanceTests::IRFolderPaths = CommonTestUtils::splitStringByDelimiter(FLAGS_input_folders); ::testing::InitGoogleTest(&argc, argv); ::testing::AddGlobalTestEnvironment(new LayerTestsUtils::TestEnvironment); diff --git a/inference-engine/tests/functional/plugin/shared/src/main.cpp b/inference-engine/tests/functional/plugin/shared/src/main.cpp index c1e629d23ce..daca9d9b121 100644 --- a/inference-engine/tests/functional/plugin/shared/src/main.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/main.cpp @@ -23,6 +23,14 @@ int main(int argc, char *argv[]) { std::string(argv[i]).substr(std::string("--output_folder").length() + 1)); } else if (std::string(argv[i]).find("--report_unique_name") != std::string::npos) { LayerTestsUtils::Summary::setSaveReportWithUniqueName(true); + } else if (std::string(argv[i]).find("--save_report_timeout") != std::string::npos) { + size_t timeout; + try { + timeout = std::stoi(std::string(argv[i]).substr(std::string("--save_report_timeout").length() + 1)); + } catch (...) { + throw std::runtime_error("Incorrect value of \"--save_report_timeout\" argument"); + } + LayerTestsUtils::Summary::setSaveReportTimeout(timeout); } } @@ -40,13 +48,14 @@ int main(int argc, char *argv[]) { std::cout << " --report_unique_name" << std::endl; std::cout << " Allow to save report with unique name (report_pid_timestamp.xml). " << "Mutually exclusive with --extend_report." << std::endl; + std::cout << " --save_report_timeout" << std::endl; + std::cout << " Allow to try to save report in cycle using timeout (in seconds). " << std::endl; std::cout << std::endl; } if (LayerTestsUtils::Summary::getSaveReportWithUniqueName() && LayerTestsUtils::Summary::getExtendReport()) { - std::cout << "Using mutually exclusive arguments: --extend_report and --report_unique_name" << std::endl; - return -1; + throw std::runtime_error("Using mutually exclusive arguments: --extend_report and --report_unique_name"); } ::testing::InitGoogleTest(&argc, argv); diff --git a/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.hpp b/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.hpp index 1e5534c7d8f..34aa4c75c44 100644 --- a/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.hpp +++ b/inference-engine/tests/ie_test_utils/common_test_utils/file_utils.hpp @@ -211,7 +211,8 @@ inline std::vector getFileListByPatternRecursive(const std::vector< std::vector result; for (auto &&folderPath : folderPaths) { if (!CommonTestUtils::directoryExists(folderPath)) { - continue; + std::string msg = "Input directory (" + folderPath + ") doesn't not exist!"; + throw std::runtime_error(msg); } auto fileListByPattern = getFileListByPattern(folderPath); result.insert(result.end(), fileListByPattern.begin(), fileListByPattern.end()); diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp b/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp index b2beb4313fd..ba3d1d06a8b 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp @@ -64,6 +64,7 @@ private: std::map opsStats = {}; std::string deviceName; bool isReported = false; + static size_t saveReportTimeout; static bool extendReport; static bool saveReportWithUniqueName; static const char* outputFolder; @@ -100,6 +101,10 @@ public: static bool getSaveReportWithUniqueName() { return saveReportWithUniqueName; } + static void setSaveReportTimeout(size_t val) { saveReportTimeout = val; } + + static size_t getSaveReportTimeout() { return saveReportTimeout; } + static void setOutputFolder(const std::string &val) { outputFolder = val.c_str(); } }; diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py index 6c93a383477..3746663b68c 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py @@ -21,6 +21,8 @@ def parse_arguments(): parser.add_argument("-i", "--input_folders", help=input_folders_help, nargs="*", required=True) parser.add_argument("-o", "--output_folder", help=output_folders_help, default="") + parser.add_argument("-f", "--output_filename", help=output_folders_help, default="report") + return parser.parse_args() @@ -57,6 +59,8 @@ def aggregate_test_results(results: ET.SubElement, xml_reports: list): if device_results.find(op.tag) is not None: entry = device_results.find(op.tag) for attr_name in device_results.find(op.tag).attrib: + if attr_name == "passrate": + continue xml_value = int(op.attrib.get(attr_name)) aggregated_value = int(entry.attrib.get(attr_name)) device_results.find(entry.tag).set(attr_name, str(xml_value + aggregated_value)) @@ -65,7 +69,7 @@ def aggregate_test_results(results: ET.SubElement, xml_reports: list): return timestamp -def merge_xml(input_folder_paths: list, output_folder_paths: str): +def merge_xml(input_folder_paths: list, output_folder_paths: str, output_filename: str): logger.info(f" Processing is finished") summary = ET.Element("report") @@ -94,7 +98,7 @@ def merge_xml(input_folder_paths: list, output_folder_paths: str): if not os.path.exists(output_folder_paths): os.mkdir(output_folder_paths) - out_file_path = os.path.join(output_folder_paths, "report.xml") + out_file_path = os.path.join(output_folder_paths, f'{output_filename}.xml') with open(out_file_path, "w") as xml_file: xml_file.write(ET.tostring(summary).decode('utf8')) logger.info(f" Final report is saved to file: '{out_file_path}'") @@ -102,4 +106,4 @@ def merge_xml(input_folder_paths: list, output_folder_paths: str): if __name__ == "__main__": arguments = parse_arguments() - merge_xml(arguments.input_folders, arguments.output_folder) + merge_xml(arguments.input_folders, arguments.output_folder, arguments.output_filename) diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index edb0c5fab9d..f263907ab6b 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -101,12 +101,28 @@ verified_operations = [ 'TopK-1', 'TopK-3' ] + pass_rate_avg = dict() general_pass_rate = dict() general_test_count = dict() general_passed_tests = dict() +def update_passrates(results: ET.SubElement): + for device in results: + for op in device: + passed_tests = 0 + total_tests = 0 + for attrib in op.attrib: + if attrib == "passrate": + continue + if attrib == "passed": + passed_tests = int(op.attrib.get(attrib)) + total_tests += int(op.attrib.get(attrib)) + passrate = float(passed_tests * 100 / total_tests) if passed_tests < total_tests else 100 + op.set("passrate", str(round(passrate, 1))) + + def merge_xmls(xmls: list): if len(xmls) == 1: return xmls[0] @@ -124,16 +140,28 @@ def merge_xmls(xmls: list): results.append(device) else: for entry in device: - if device_results.find(entry.tag) is not None: - current_timestamp = datetime.strptime(xml.attrib["timestamp"], "%d-%m-%Y %H:%M:%S") - base_timestamp = datetime.strptime(summary.attrib["timestamp"], "%d-%m-%Y %H:%M:%S") - if current_timestamp > base_timestamp: - device_results.find(entry.tag).attrib = entry.attrib + res_summary = device_results.find(entry.tag) + if res_summary is not None: + # workaround for unsaved reports + total_tests_count_xml, total_tests_count_summary = (0, 0) + for attr_name in device_results.find(entry.tag).attrib: + if attr_name == "passrate": + continue + else: + total_tests_count_xml += int(entry.attrib.get(attr_name)) + total_tests_count_summary += int(res_summary.attrib.get(attr_name)) + if total_tests_count_xml > total_tests_count_summary: + for attr_name in device_results.find(entry.tag).attrib: + if attr_name == "passrate": + continue + else: + xml_value = int(entry.attrib.get(attr_name)) + device_results.find(res_summary.tag).set(attr_name, str(xml_value)) else: device_results.append(entry) + update_passrates(results) return summary - xmls = [] for xml in args.xml: try: diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp b/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp index ecf1274a7e4..7acc445fdd6 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp @@ -11,6 +11,7 @@ using namespace LayerTestsUtils; Summary *Summary::p_instance = nullptr; bool Summary::extendReport = false; bool Summary::saveReportWithUniqueName = false; +size_t Summary::saveReportTimeout = 0; const char* Summary::outputFolder = "."; SummaryDestroyer Summary::destroyer; @@ -233,7 +234,13 @@ void Summary::saveReport() { } } } - bool result = doc.save_file(outputFilePath.c_str()); + + auto exitTime = std::chrono::system_clock::now() + std::chrono::seconds(saveReportTimeout); + bool result = false; + do { + result = doc.save_file(outputFilePath.c_str()); + } while (!result && std::chrono::system_clock::now() < exitTime); + if (!result) { std::string errMessage = "Failed to write report to " + outputFilePath; throw std::runtime_error(errMessage); From f3d1aa649040416b03da67552890b46904bc6c16 Mon Sep 17 00:00:00 2001 From: Evgeny Lazarev Date: Tue, 20 Apr 2021 14:47:18 +0300 Subject: [PATCH 20/78] Moved MO unit test files to a separate directory (#5312) * Removed test-generator from all MO requirement files except the dev one * Moved all MO unit tests files to a separate directory * Added __init__.py files to the tests directory. Fixed importing paths for some unit tests * Fixed imports in all unit tests. Moved all unit test related files from the MO code to the dedicated directory * Renamed directory with unit test utils * Updated imports in unit tests --- model-optimizer/requirements.txt | 1 - model-optimizer/requirements_caffe.txt | 1 - model-optimizer/requirements_kaldi.txt | 1 - model-optimizer/requirements_mxnet.txt | 1 - model-optimizer/requirements_onnx.txt | 1 - model-optimizer/requirements_tf.txt | 1 - model-optimizer/requirements_tf2.txt | 1 - .../telemetry/utils/sender_test.py | 68 ------------------ model-optimizer/unit_tests/__init__.py | 0 .../unit_tests/extensions/__init__.py | 0 .../analysis/Iterator_get_next_test.py | 2 +- .../extensions/analysis/__init__.py | 0 .../extensions/back/ClampNormalizer_test.py | 2 +- .../back/ConvolutionNormalizer_test.py | 2 +- .../extensions/back/CutMemory_test.py | 2 +- .../back/FakeOutputResolver_test.py | 2 +- .../back/FuseTransposesSequence_test.py | 3 +- .../back/InterpolateReshape_test.py | 3 +- .../back/LayoutChangeForGatherND_test.py | 2 +- .../back/MarkNodesWithShapeValues_test.py | 18 +++-- .../extensions/back/MatMulNormalizer_test.py | 4 +- .../OptimizeTransposeReshapeSequence_test.py | 0 .../back/ReduceTransposeDimensions_test.py | 0 .../extensions/back/ResultRename_test.py | 2 +- .../ShuffleChannelPatternOptimization_test.py | 2 +- .../back/ShufflenetReLUReorder_test.py | 2 +- .../back/SpecialNodesFinalization_test.py | 2 +- .../back/TransposeReduceFusing_test.py | 2 +- .../unit_tests/extensions/back/__init__.py | 0 .../back/compress_quantized_weights_test.py | 2 +- ...sert_compatibility_l2normalization_test.py | 2 +- .../back/kaldi_remove_memory_output_test.py | 2 +- .../back/remove_last_softmax_test.py | 2 +- .../front/ATenToEmbeddingBag_test.py | 3 +- .../front/AttributedClampNormalizer_test.py | 2 +- .../front/AttributedPadToPad_test.py | 2 +- .../front/AttributedRollToRoll_test.py | 2 +- .../DropoutWithRandomUniformReplacer_test.py | 2 +- .../extensions/front/GeLUMerger_Erf_test.py | 2 +- .../extensions/front/GeLUMerger_Tanh_test.py | 2 +- .../extensions/front/HSigmoid_fusion_test.py | 2 +- .../extensions/front/HSwish_fusing_test.py | 2 +- .../extensions/front/LayerNorm_test.py | 2 +- .../extensions/front/Log1p_test.py | 2 +- .../extensions/front/Mish_fusion_test.py | 2 +- .../front/OneHotDepthNormalizer_test.py | 2 +- .../extensions/front/Pack_test.py | 2 +- .../front/RollWithEmptyAxesReplacer_test.py | 2 +- .../extensions/front/Softplus_fusion_test.py | 2 +- .../extensions/front/Swish_fusion_test.py | 2 +- .../ThresholdedReluDecomposition_test.py | 2 +- .../unit_tests/extensions/front/__init__.py | 0 .../binary_quantize_normalization_test.py | 2 +- .../front/broadcast_with_range_test.py | 2 +- .../front/caffe/MVNCaffeToMVN_test.py | 2 +- .../extensions/front/caffe/__init__.py | 0 .../extensions/front/caffe/accum_ext_test.py | 4 +- .../extensions/front/caffe/argmax_ext_test.py | 4 +- .../extensions/front/caffe/axpy_test.py | 2 +- .../extensions/front/caffe/bn_test.py | 4 +- .../extensions/front/caffe/conv_ext_test.py | 2 +- .../front/caffe/correlation_ext_test.py | 4 +- .../extensions/front/caffe/crop_ext_test.py | 4 +- .../front/caffe/ctcgreedydecoder_ext_test.py | 4 +- .../front/caffe/data_augmentation_ext_test.py | 4 +- .../front/caffe/elementwise_ext_test.py | 4 +- .../front/caffe/eltwise_add_normalize_test.py | 2 +- .../extensions/front/caffe/elu_test.py | 4 +- .../extensions/front/caffe/grn_ext_test.py | 4 +- .../front/caffe/normalize_ext_test.py | 4 +- .../front/caffe/pooling_ext_test.py | 2 +- .../front/caffe/power_file_ext_test.py | 4 +- .../extensions/front/caffe/prelu_ext_test.py | 4 +- .../caffe/priorbox_clustered_ext_test.py | 4 +- .../front/caffe/priorbox_ext_test.py | 4 +- .../front/caffe/proposal_ext_test.py | 4 +- .../front/caffe/proposal_python_ext_test.py | 4 +- .../front/caffe/regionyolo_ext_test.py | 4 +- .../front/caffe/reorgyolo_ext_test.py | 4 +- .../front/caffe/simplernms_ext_test.py | 4 +- .../caffe/spatial_transformer_ext_test.py | 4 +- .../extensions/front/div_test.py | 2 +- .../extensions/front/eltwise_n_test.py | 2 +- .../front/freeze_placeholder_value_test.py | 2 +- .../extensions/front/image_scaler_test.py | 2 +- .../front/instance_normalization_test.py | 2 +- .../front/interpolate_reshape_test.py | 2 +- .../extensions/front/kaldi/__init__.py | 0 .../add_permute_after_convolution_test.py | 2 +- .../front/kaldi/apply_counts_test.py | 2 +- .../kaldi/memory_offset_adjustment_test.py | 2 +- .../kaldi/replace_lstm_nonlinearity_test.py | 2 +- .../front/kaldi/sigmoid_ext_test.py | 2 +- .../extensions/front/kaldi/tanh_ext_test.py | 2 +- .../kaldi/tdnn_component_replacer_test.py | 2 +- .../extensions/front/mxnet/RNN_ext_test.py | 2 +- .../extensions/front/mxnet/__init__.py | 0 .../extensions/front/mxnet/activation_test.py | 2 +- .../add_input_data_to_prior_boxes_test.py | 2 +- .../mxnet/check_softmax_node_inputs_test.py | 2 +- .../extensions/front/mxnet/conv_ext_test.py | 2 +- .../extensions/front/mxnet/crop_ext_test.py | 2 +- .../extensions/front/mxnet/custom_test.py | 2 +- .../extensions/front/mxnet/gather_test.py | 2 +- .../front/mxnet/gluoncv_ssd_anchors_test.py | 2 +- .../extensions/front/mxnet/leaky_relu_test.py | 2 +- .../front/mxnet/multibox_detection_test.py | 2 +- .../front/mxnet/mx_reshape_reverse_test.py | 2 +- .../front/mxnet/mx_reshape_to_reshape_test.py | 2 +- .../front/mxnet/pooling_ext_test.py | 2 +- .../extensions/front/mxnet/sigmoid_test.py | 2 +- ...pattern_flatten_softmax_activation_test.py | 2 +- .../mxnet/ssd_pattern_remove_flatten_test.py | 2 +- .../mxnet/ssd_pattern_remove_reshape_test.py | 2 +- .../ssd_pattern_remove_transpose_test.py | 2 +- .../ssd_reorder_detection_out_inputs_test.py | 2 +- .../front/onnx/AttributedSliceToSlice_test.py | 2 +- .../front/onnx/MvnOnnxToMvn_test.py | 4 +- .../extensions/front/onnx/__init__.py | 0 .../front/onnx/activation_ext_test.py | 4 +- .../extensions/front/onnx/affine_ext_test.py | 2 +- .../extensions/front/onnx/conv_ext_test.py | 2 +- .../extensions/front/onnx/crop_ext_test.py | 2 +- .../onnx/dequantize_linear_resolver_test.py | 3 +- .../front/onnx/detection_output_test.py | 2 +- .../extensions/front/onnx/gru_ext_test.py | 2 +- .../front/onnx/image_scaler_ext_test.py | 2 +- .../onnx/instance_normalization_ext_test.py | 2 +- .../extensions/front/onnx/lstm_ext_test.py | 2 +- .../front/onnx/normalize_ext_test.py | 2 +- .../front/onnx/pad_converter_test.py | 2 +- .../extensions/front/onnx/pad_ext_test.py | 4 +- .../front/onnx/priorbox_clustered_ext_test.py | 2 +- .../front/onnx/priorbox_ext_test.py | 2 +- .../onnx/quantize_dequantize_linear_test.py | 3 +- .../onnx/quantize_linear_resolver_test.py | 3 +- .../extensions/front/onnx/rnn_ext_test.py | 2 +- .../extensions/front/onnx/squeeze_ext_test.py | 2 +- .../front/onnx/transpose_ext_test.py | 2 +- .../front/onnx/unsqueeze_ext_test.py | 2 +- .../front/onnx/upsample_ext_test.py | 4 +- .../extensions/front/output_cut_test.py | 2 +- .../extensions/front/rank_decomposer_test.py | 2 +- .../extensions/front/reciprocal_test.py | 2 +- .../front/reduce_axis_normalizer_test.py | 2 +- .../front/scatter_normalizer_test.py | 2 +- .../front/softsign_replacer_test.py | 2 +- .../extensions/front/split_normalizer_test.py | 2 +- .../extensions/front/sub_test.py | 2 +- .../tf/CTCGreedyDecoderReplacement_test.py | 4 +- .../front/tf/CTCLossReplacement_test.py | 2 +- ...nConstBeginStridedSliceReplacement_test.py | 2 +- .../front/tf/ObjectDetectionAPI_test.py | 2 +- .../front/tf/SwitchMergeOptimization_test.py | 2 +- .../front/tf/TFSliceToSlice_test.py | 2 +- .../front/tf/WhereDecomposition_test.py | 2 +- .../extensions/front/tf/__init__.py | 0 .../extensions/front/tf/concat_ext_test.py | 2 +- .../extensions/front/tf/concat_test.py | 2 +- .../extensions/front/tf/conv_ext_test.py | 2 +- .../extensions/front/tf/deconv_ext_test.py | 2 +- .../front/tf/embedding_segments_sum_test.py | 2 +- .../extensions/front/tf/fifo_replacer_test.py | 2 +- .../extensions/front/tf/floor_div_test.py | 2 +- .../front/tf/identityN_to_identity_test.py | 2 +- .../extensions/front/tf/mvn_unrolled_test.py | 2 +- .../front/tf/next_iteration_ext_test.py | 2 +- .../extensions/front/tf/pad_tf_to_pad_test.py | 2 +- .../extensions/front/tf/size_replacer_test.py | 2 +- .../front/tf/sparse_to_dense_replacer_test.py | 3 +- .../middle/AddIsCyclicAttribute_test.py | 2 +- .../middle/AddMeanScaleValues_test.py | 2 +- .../extensions/middle/CheckForCycle_test.py | 2 +- .../middle/ConcatOptimization_test.py | 2 +- .../middle/ConvertGroupedStridedSlice_test.py | 2 +- .../CutInputHavingZeroDimFromConcat_test.py | 2 +- .../middle/EltwiseInputReshape_test.py | 2 +- .../middle/FakeSplitOutputs_test.py | 2 +- .../middle/FusedBatchNormTraining_test.py | 2 +- .../extensions/middle/GroupNorm_test.py | 4 +- .../extensions/middle/InsertSelect_test.py | 2 +- .../InterpolateSequenceToInterpolate_test.py | 2 +- .../extensions/middle/L2NormFusing_test.py | 2 +- .../middle/LeakyReluPattern_test.py | 2 +- .../extensions/middle/MXTileReplacer_test.py | 2 +- .../middle/MakeKaldiConstReshapable_test.py | 2 +- .../extensions/middle/MulQuantizeFuse_test.py | 2 +- .../middle/PoolV2ToAttributedPool_test.py | 2 +- .../middle/ReluQuantizeFuse_test.py | 2 +- .../middle/RemoveDuplicationMemory_test.py | 2 +- .../middle/RemoveUselessConcatSplit_test.py | 2 +- .../middle/RemoveUselessCrops_test.py | 2 +- .../middle/RemoveUselessPad_test.py | 2 +- .../ReplaceMemoryOffsetWithSplice_test.py | 2 +- .../middle/ReplacePNormNodePattern_test.py | 2 +- .../middle/ReplaceSpliceNodePattern_test.py | 2 +- .../middle/SequenceLenthToMask_test.py | 2 +- .../middle/SharedWeightsDuplication_test.py | 2 +- .../extensions/middle/SliceConverter_test.py | 2 +- .../middle/SliceLikeToStridedSlice_test.py | 2 +- .../SplitConcatPairToInterpolate_test.py | 2 +- .../middle/StridedSliceNormalizer_test.py | 2 +- .../middle/TensorIteratorBackEdge_test.py | 2 +- .../middle/TensorIteratorCondition_test.py | 2 +- .../middle/TensorIteratorInput_test.py | 2 +- .../middle/TensorIteratorOutput_test.py | 2 +- ...ueezeTileReshapeBlockToInterpolate_test.py | 2 +- .../middle/UpsampleToResample_test.py | 2 +- .../unit_tests/extensions/middle/__init__.py | 0 .../extensions/middle/quantize_fuses_test.py | 2 +- .../extensions/middle/sparse_reshape_test.py | 2 +- .../ops/ExtractImagePatches_test.py | 2 +- .../extensions/ops/LookupTableInsert_test.py | 2 +- .../extensions/ops/MatMul_test.py | 2 +- .../ops/MatMul_value_propagation_test.py | 2 +- .../extensions/ops/ONNXResize11_test.py | 2 +- .../extensions/ops/ReduceOps_test.py | 2 +- .../extensions/ops/Reverse_test.py | 2 +- .../unit_tests/extensions/ops/__init__.py | 0 .../extensions/ops/accum_test.py | 2 +- .../extensions/ops/activation_test.py | 2 +- .../extensions/ops/argmax_test.py | 2 +- .../extensions/ops/assert_test.py | 2 +- .../extensions/ops/bucketize_test.py | 2 +- .../extensions/ops/cast_test.py | 6 +- .../extensions/ops/correlation_test.py | 2 +- .../extensions/ops/ctc_greedy_decoder_test.py | 2 +- .../extensions/ops/ctc_loss_test.py | 2 +- .../extensions/ops/cumsum_test.py | 2 +- .../extensions/ops/data_augmentation_test.py | 2 +- .../extensions/ops/depth_to_space_test.py | 2 +- .../ops/div_value_propagation_test.py | 2 +- .../extensions/ops/elementwise_test.py | 2 +- .../extensions/ops/embedding_bag_test.py | 3 +- .../extensions/ops/gather_test.py | 2 +- .../extensions/ops/gatherelements_test.py | 2 +- .../extensions/ops/gathernd_test.py | 2 +- .../extensions/ops/grn_test.py | 2 +- .../ops/instance_normalization_test.py | 0 .../extensions/ops/interpolate_test.py | 2 +- .../extensions/ops/merge_test.py | 2 +- .../ops/non_max_suppression_test.py | 2 +- .../extensions/ops/normalize_test.py | 2 +- .../extensions/ops/one_hot_test.py | 2 +- .../extensions/ops/priorbox_clustered_test.py | 2 +- .../extensions/ops/priorbox_test.py | 2 +- .../extensions/ops/proposal_test.py | 2 +- .../extensions/ops/psroipooling_test.py | 2 +- .../extensions/ops/quantize_test.py | 2 +- .../extensions/ops/regionyolo_test.py | 2 +- .../extensions/ops/reorgyolo_test.py | 2 +- .../extensions/ops/scatter_test.py | 3 +- .../extensions/ops/scatternd_test.py | 2 +- .../extensions/ops/select_test.py | 2 +- .../extensions/ops/simplernms_test.py | 2 +- .../extensions/ops/slice_like_test.py | 2 +- .../extensions/ops/space_to_depth_test.py | 2 +- .../ops/sparse_fill_empty_rows_test.py | 2 +- .../extensions/ops/sparse_reshape_test.py | 2 +- .../ops/sparse_segment_mean_test.py | 2 +- .../ops/sparse_segment_sqrtn_test.py | 2 +- .../extensions/ops/sparse_segment_sum_test.py | 2 +- .../ops/spatial_transformer_test.py | 2 +- .../extensions/ops/split_test.py | 2 +- .../extensions/ops/switch_test.py | 2 +- .../extensions/ops/topk_test.py | 2 +- .../extensions/ops/transpose_test.py | 2 +- .../extensions/ops/unique_test.py | 2 +- .../extensions/ops/upsample_test.py | 4 +- model-optimizer/unit_tests/mo/__init__.py | 0 .../unit_tests/mo/back/__init__.py | 0 .../mo/back/ie_ir_ver_2/__init__.py | 0 .../mo/back/ie_ir_ver_2/emitter_test.py | 0 .../{ => unit_tests}/mo/bom_test.py | 11 +-- .../unit_tests/mo/front/__init__.py | 0 .../unit_tests/mo/front/caffe/__init__.py | 0 .../front/caffe/custom_layers_mapping_test.py | 0 .../mo/front/caffe/extractor_test.py | 4 +- .../mo/front/caffe/extractors/__init__.py | 0 .../mo/front/caffe/extractors/utils_test.py | 2 +- .../mo/front/caffe/loader_test.py | 0 .../caffe/python_layer_extractor_test.py | 4 +- .../unit_tests/mo/front/common/__init__.py | 0 .../mo/front/common/layout_test.py | 0 .../mo/front/common/partial_infer/__init__.py | 0 .../partial_infer/caffe_fallback_test.py | 4 +- .../front/common/partial_infer/concat_test.py | 2 +- .../front/common/partial_infer/crop_test.py | 2 +- .../common/partial_infer/elemental_test.py | 0 .../common/partial_infer/eltwise_test.py | 2 +- .../partial_infer/multi_box_detection_test.py | 2 +- .../partial_infer/multi_box_prior_test.py | 2 +- .../common/partial_infer/roipooling_test.py | 2 +- .../mo/front/extractor_test.py | 4 +- .../unit_tests/mo/front/kaldi/__init__.py | 0 .../mo/front/kaldi/extractors/__init__.py | 0 .../kaldi/extractors/add_shift_ext_test.py | 4 +- .../extractors/affine_component_ext_test.py | 4 +- .../extractors/affine_transform_ext_test.py | 4 +- .../batchnorm_component_ext_test.py | 4 +- .../extractors/bias_component_ext_test.py | 4 +- .../front/kaldi/extractors/common_ext_test.py | 4 +- .../front/kaldi/extractors/concat_ext_test.py | 2 +- .../convolutional_component_ext_test.py | 4 +- .../fixed_affine_component_ext_test.py | 4 +- .../kaldi/extractors/max_pooling_ext_test.py | 5 +- .../kaldi/extractors/memoryoffset_ext_test.py | 2 +- .../normalize_component_ext_test.py | 4 +- .../extractors/pnorm_component_ext_test.py | 4 +- .../kaldi/extractors/rescale_ext_test.py | 4 +- .../extractors/scale_component_ext_test.py | 4 +- .../mo/front/kaldi/loader/__init__.py | 0 .../mo/front/kaldi/loader/loader_test.py | 2 +- .../mo/front/kaldi/loader/utils_test.py | 0 .../unit_tests/mo/front/mxnet/__init__.py | 0 .../mo/front/mxnet/extractors/__init__.py | 0 .../mxnet/extractors/multibox_prior_test.py | 0 .../mo/front/mxnet/extractors/relu_test.py | 2 +- .../front/mxnet/extractors/slice_axis_test.py | 2 +- .../mo/front/mxnet/extractors/utils_test.py | 0 .../mo/front/mxnet/loader_test.py | 0 .../unit_tests/mo/front/tf/__init__.py | 0 .../mo/front/tf/extractors/__init__.py | 0 .../mo/front/tf/extractors/concat_test.py | 2 +- .../mo/front/tf/extractors/identity_test.py | 2 +- .../mo/front/tf/extractors/utils_test.py | 2 +- .../mo/front/tf/loader_test.py | 0 .../unit_tests/mo/graph/__init__.py | 0 .../mo/graph/connection_test.py | 2 +- .../{ => unit_tests}/mo/graph/graph_test.py | 5 +- .../{ => unit_tests}/mo/graph/port_test.py | 2 +- .../{ => unit_tests}/mo/main_test.py | 0 .../unit_tests/mo/middle/__init__.py | 0 .../unit_tests/mo/middle/passes/__init__.py | 0 .../middle/passes/convert_data_type_test.py | 2 +- .../mo/middle/passes/eliminate_test.py | 2 +- .../mo/middle/passes/fusing/__init__.py | 0 .../passes/fusing/decomposition_test.py | 2 +- .../passes/fusing/fuse_linear_ops_test.py | 2 +- .../passes/fusing/fuse_linear_seq_test.py | 2 +- .../mo/middle/passes/fusing/helpers_test.py | 2 +- .../passes/fusing/mark_unfused_nodes_test.py | 2 +- .../passes/fusing/resnet_optimization_test.py | 2 +- .../mo/middle/passes/infer_test.py | 2 +- model-optimizer/unit_tests/mo/ops/__init__.py | 0 .../{ => unit_tests}/mo/ops/broadcast_test.py | 2 +- .../{ => unit_tests}/mo/ops/concat_test.py | 2 +- .../mo/ops/convolution_test.py | 4 +- .../{ => unit_tests}/mo/ops/crop_test.py | 2 +- .../mo/ops/expand_dims_test.py | 2 +- .../{ => unit_tests}/mo/ops/pad_test.py | 2 +- .../{ => unit_tests}/mo/ops/pooling_test.py | 2 +- .../{ => unit_tests}/mo/ops/slice_test.py | 2 +- .../{ => unit_tests}/mo/ops/squeeze_test.py | 2 +- .../mo/ops/strided_slice_test.py | 6 +- .../{ => unit_tests}/mo/ops/tile_test.py | 2 +- .../{ => unit_tests}/mo/ops/unsqueeze_test.py | 2 +- .../unit_tests/mo/pipeline/__init__.py | 0 .../mo/pipeline/common_test.py | 2 +- .../unit_tests/mo/utils/__init__.py | 0 .../mo/utils/broadcasting_test.py | 10 +-- .../mo/utils/cli_parser_test.py | 0 .../{ => unit_tests}/mo/utils/error_test.py | 0 .../{ => unit_tests}/mo/utils/graph_test.py | 0 .../unit_tests/mo/utils/ir_engine/__init__.py | 0 .../mo/utils/ir_engine/ir_engine_test.py | 10 +-- .../unit_tests/mo/utils/ir_reader/__init__.py | 0 .../mo/utils/ir_reader/layer_to_class_test.py | 2 +- .../mo/utils/pipeline_config_test.py | 0 .../mo/utils/simple_proto_parser_test.py | 0 .../mo/utils/summarize_graph_test.py | 0 .../{ => unit_tests}/mo/utils/utils_test.py | 0 .../{ => unit_tests}/mo/utils/version_test.py | 0 .../mo/utils/versions_checker_test.py | 0 model-optimizer/unit_tests/utils/__init__.py | 0 .../utils}/extractors.py | 0 .../unittest => unit_tests/utils}/graph.py | 0 ..._synthetic_gru_bidirectional_FP16_1_v6.bin | Bin ..._synthetic_gru_bidirectional_FP16_1_v6.xml | 0 ...c_gru_bidirectional_FP16_1_v6_negative.xml | 0 380 files changed, 374 insertions(+), 471 deletions(-) delete mode 100644 model-optimizer/telemetry/utils/sender_test.py create mode 100644 model-optimizer/unit_tests/__init__.py create mode 100644 model-optimizer/unit_tests/extensions/__init__.py rename model-optimizer/{ => unit_tests}/extensions/analysis/Iterator_get_next_test.py (96%) create mode 100644 model-optimizer/unit_tests/extensions/analysis/__init__.py rename model-optimizer/{ => unit_tests}/extensions/back/ClampNormalizer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/back/ConvolutionNormalizer_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/back/CutMemory_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/back/FakeOutputResolver_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/back/FuseTransposesSequence_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/back/InterpolateReshape_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/back/LayoutChangeForGatherND_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/back/MarkNodesWithShapeValues_test.py (84%) rename model-optimizer/{ => unit_tests}/extensions/back/MatMulNormalizer_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/back/OptimizeTransposeReshapeSequence_test.py (100%) rename model-optimizer/{ => unit_tests}/extensions/back/ReduceTransposeDimensions_test.py (100%) rename model-optimizer/{ => unit_tests}/extensions/back/ResultRename_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/back/ShuffleChannelPatternOptimization_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/back/ShufflenetReLUReorder_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/back/SpecialNodesFinalization_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/back/TransposeReduceFusing_test.py (99%) create mode 100644 model-optimizer/unit_tests/extensions/back/__init__.py rename model-optimizer/{ => unit_tests}/extensions/back/compress_quantized_weights_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/back/insert_compatibility_l2normalization_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/back/kaldi_remove_memory_output_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/back/remove_last_softmax_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/ATenToEmbeddingBag_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/AttributedClampNormalizer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/AttributedPadToPad_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/AttributedRollToRoll_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/DropoutWithRandomUniformReplacer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/GeLUMerger_Erf_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/GeLUMerger_Tanh_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/HSigmoid_fusion_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/HSwish_fusing_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/LayerNorm_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/Log1p_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/Mish_fusion_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/OneHotDepthNormalizer_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/Pack_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/RollWithEmptyAxesReplacer_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/Softplus_fusion_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/Swish_fusion_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/ThresholdedReluDecomposition_test.py (97%) create mode 100644 model-optimizer/unit_tests/extensions/front/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/binary_quantize_normalization_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/broadcast_with_range_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/MVNCaffeToMVN_test.py (96%) create mode 100644 model-optimizer/unit_tests/extensions/front/caffe/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/caffe/accum_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/argmax_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/axpy_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/bn_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/conv_ext_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/correlation_ext_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/crop_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/ctcgreedydecoder_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/data_augmentation_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/elementwise_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/eltwise_add_normalize_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/elu_test.py (89%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/grn_ext_test.py (92%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/normalize_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/pooling_ext_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/power_file_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/prelu_ext_test.py (92%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/priorbox_clustered_ext_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/priorbox_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/proposal_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/proposal_python_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/regionyolo_ext_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/reorgyolo_ext_test.py (92%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/simplernms_ext_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/caffe/spatial_transformer_ext_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/div_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/eltwise_n_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/freeze_placeholder_value_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/image_scaler_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/instance_normalization_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/interpolate_reshape_test.py (98%) create mode 100644 model-optimizer/unit_tests/extensions/front/kaldi/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/add_permute_after_convolution_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/apply_counts_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/memory_offset_adjustment_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/replace_lstm_nonlinearity_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/sigmoid_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/tanh_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/extensions/front/kaldi/tdnn_component_replacer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/RNN_ext_test.py (97%) create mode 100644 model-optimizer/unit_tests/extensions/front/mxnet/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/activation_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/check_softmax_node_inputs_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/conv_ext_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/crop_ext_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/custom_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/gather_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/gluoncv_ssd_anchors_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/leaky_relu_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/multibox_detection_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/mx_reshape_reverse_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/mx_reshape_to_reshape_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/pooling_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/sigmoid_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/AttributedSliceToSlice_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/MvnOnnxToMvn_test.py (92%) create mode 100644 model-optimizer/unit_tests/extensions/front/onnx/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/onnx/activation_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/affine_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/conv_ext_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/crop_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/dequantize_linear_resolver_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/detection_output_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/gru_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/image_scaler_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/instance_normalization_ext_test.py (91%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/lstm_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/normalize_ext_test.py (93%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/pad_converter_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/pad_ext_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/priorbox_clustered_ext_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/priorbox_ext_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/quantize_dequantize_linear_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/quantize_linear_resolver_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/rnn_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/squeeze_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/transpose_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/unsqueeze_ext_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/onnx/upsample_ext_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/output_cut_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/rank_decomposer_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/reciprocal_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/reduce_axis_normalizer_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/front/scatter_normalizer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/softsign_replacer_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/split_normalizer_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/sub_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/CTCGreedyDecoderReplacement_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/CTCLossReplacement_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/ObjectDetectionAPI_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/SwitchMergeOptimization_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/TFSliceToSlice_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/WhereDecomposition_test.py (98%) create mode 100644 model-optimizer/unit_tests/extensions/front/tf/__init__.py rename model-optimizer/{ => unit_tests}/extensions/front/tf/concat_ext_test.py (88%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/concat_test.py (94%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/conv_ext_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/deconv_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/embedding_segments_sum_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/fifo_replacer_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/floor_div_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/identityN_to_identity_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/mvn_unrolled_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/next_iteration_ext_test.py (86%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/pad_tf_to_pad_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/size_replacer_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/front/tf/sparse_to_dense_replacer_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/middle/AddIsCyclicAttribute_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/middle/AddMeanScaleValues_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/CheckForCycle_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/ConcatOptimization_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/ConvertGroupedStridedSlice_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/CutInputHavingZeroDimFromConcat_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/EltwiseInputReshape_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/FakeSplitOutputs_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/FusedBatchNormTraining_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/GroupNorm_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/middle/InsertSelect_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/InterpolateSequenceToInterpolate_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/L2NormFusing_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/LeakyReluPattern_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/middle/MXTileReplacer_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/MakeKaldiConstReshapable_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/MulQuantizeFuse_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/PoolV2ToAttributedPool_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/middle/ReluQuantizeFuse_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/RemoveDuplicationMemory_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/RemoveUselessConcatSplit_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/RemoveUselessCrops_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/RemoveUselessPad_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/ReplacePNormNodePattern_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/ReplaceSpliceNodePattern_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/SequenceLenthToMask_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/SharedWeightsDuplication_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/middle/SliceConverter_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/SliceLikeToStridedSlice_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/SplitConcatPairToInterpolate_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/StridedSliceNormalizer_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/TensorIteratorBackEdge_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/TensorIteratorCondition_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/middle/TensorIteratorInput_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/TensorIteratorOutput_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/UpsampleToResample_test.py (99%) create mode 100644 model-optimizer/unit_tests/extensions/middle/__init__.py rename model-optimizer/{ => unit_tests}/extensions/middle/quantize_fuses_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/middle/sparse_reshape_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/ExtractImagePatches_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/LookupTableInsert_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/MatMul_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/MatMul_value_propagation_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/ONNXResize11_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/ReduceOps_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/ops/Reverse_test.py (97%) create mode 100644 model-optimizer/unit_tests/extensions/ops/__init__.py rename model-optimizer/{ => unit_tests}/extensions/ops/accum_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/activation_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/argmax_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/assert_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/bucketize_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/cast_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/correlation_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/ops/ctc_greedy_decoder_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/ctc_loss_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/cumsum_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/data_augmentation_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/ops/depth_to_space_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/div_value_propagation_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/elementwise_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/embedding_bag_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/gather_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/gatherelements_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/gathernd_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/grn_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/instance_normalization_test.py (100%) rename model-optimizer/{ => unit_tests}/extensions/ops/interpolate_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/merge_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/non_max_suppression_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/normalize_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/one_hot_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/ops/priorbox_clustered_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/priorbox_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/proposal_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/psroipooling_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/quantize_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/regionyolo_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/reorgyolo_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/ops/scatter_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/ops/scatternd_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/select_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/simplernms_test.py (97%) rename model-optimizer/{ => unit_tests}/extensions/ops/slice_like_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/space_to_depth_test.py (95%) rename model-optimizer/{ => unit_tests}/extensions/ops/sparse_fill_empty_rows_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/sparse_reshape_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/sparse_segment_mean_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/sparse_segment_sqrtn_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/sparse_segment_sum_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/spatial_transformer_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/split_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/switch_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/topk_test.py (96%) rename model-optimizer/{ => unit_tests}/extensions/ops/transpose_test.py (98%) rename model-optimizer/{ => unit_tests}/extensions/ops/unique_test.py (99%) rename model-optimizer/{ => unit_tests}/extensions/ops/upsample_test.py (98%) create mode 100644 model-optimizer/unit_tests/mo/__init__.py create mode 100644 model-optimizer/unit_tests/mo/back/__init__.py create mode 100644 model-optimizer/unit_tests/mo/back/ie_ir_ver_2/__init__.py rename model-optimizer/{ => unit_tests}/mo/back/ie_ir_ver_2/emitter_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/bom_test.py (93%) create mode 100644 model-optimizer/unit_tests/mo/front/__init__.py create mode 100644 model-optimizer/unit_tests/mo/front/caffe/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/caffe/custom_layers_mapping_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/front/caffe/extractor_test.py (97%) create mode 100644 model-optimizer/unit_tests/mo/front/caffe/extractors/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/caffe/extractors/utils_test.py (97%) rename model-optimizer/{ => unit_tests}/mo/front/caffe/loader_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/front/caffe/python_layer_extractor_test.py (94%) create mode 100644 model-optimizer/unit_tests/mo/front/common/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/common/layout_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/front/common/partial_infer/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/caffe_fallback_test.py (96%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/concat_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/crop_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/elemental_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/eltwise_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/multi_box_detection_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/multi_box_prior_test.py (97%) rename model-optimizer/{ => unit_tests}/mo/front/common/partial_infer/roipooling_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/front/extractor_test.py (99%) create mode 100644 model-optimizer/unit_tests/mo/front/kaldi/__init__.py create mode 100644 model-optimizer/unit_tests/mo/front/kaldi/extractors/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/add_shift_ext_test.py (90%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/affine_component_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/affine_transform_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/batchnorm_component_ext_test.py (92%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/bias_component_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/common_ext_test.py (97%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/concat_ext_test.py (84%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/convolutional_component_ext_test.py (92%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py (87%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/max_pooling_ext_test.py (89%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/memoryoffset_ext_test.py (90%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/normalize_component_ext_test.py (86%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/pnorm_component_ext_test.py (85%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/rescale_ext_test.py (89%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/extractors/scale_component_ext_test.py (87%) create mode 100644 model-optimizer/unit_tests/mo/front/kaldi/loader/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/kaldi/loader/loader_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/front/kaldi/loader/utils_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/front/mxnet/__init__.py create mode 100644 model-optimizer/unit_tests/mo/front/mxnet/extractors/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/mxnet/extractors/multibox_prior_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/front/mxnet/extractors/relu_test.py (95%) rename model-optimizer/{ => unit_tests}/mo/front/mxnet/extractors/slice_axis_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/front/mxnet/extractors/utils_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/front/mxnet/loader_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/front/tf/__init__.py create mode 100644 model-optimizer/unit_tests/mo/front/tf/extractors/__init__.py rename model-optimizer/{ => unit_tests}/mo/front/tf/extractors/concat_test.py (90%) rename model-optimizer/{ => unit_tests}/mo/front/tf/extractors/identity_test.py (89%) rename model-optimizer/{ => unit_tests}/mo/front/tf/extractors/utils_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/front/tf/loader_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/graph/__init__.py rename model-optimizer/{ => unit_tests}/mo/graph/connection_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/graph/graph_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/graph/port_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/main_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/middle/__init__.py create mode 100644 model-optimizer/unit_tests/mo/middle/passes/__init__.py rename model-optimizer/{ => unit_tests}/mo/middle/passes/convert_data_type_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/eliminate_test.py (99%) create mode 100644 model-optimizer/unit_tests/mo/middle/passes/fusing/__init__.py rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/decomposition_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/fuse_linear_ops_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/fuse_linear_seq_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/helpers_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/mark_unfused_nodes_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/fusing/resnet_optimization_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/middle/passes/infer_test.py (99%) create mode 100644 model-optimizer/unit_tests/mo/ops/__init__.py rename model-optimizer/{ => unit_tests}/mo/ops/broadcast_test.py (96%) rename model-optimizer/{ => unit_tests}/mo/ops/concat_test.py (95%) rename model-optimizer/{ => unit_tests}/mo/ops/convolution_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/ops/crop_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/ops/expand_dims_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/ops/pad_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/ops/pooling_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/ops/slice_test.py (98%) rename model-optimizer/{ => unit_tests}/mo/ops/squeeze_test.py (97%) rename model-optimizer/{ => unit_tests}/mo/ops/strided_slice_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/ops/tile_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/ops/unsqueeze_test.py (98%) create mode 100644 model-optimizer/unit_tests/mo/pipeline/__init__.py rename model-optimizer/{ => unit_tests}/mo/pipeline/common_test.py (99%) create mode 100644 model-optimizer/unit_tests/mo/utils/__init__.py rename model-optimizer/{ => unit_tests}/mo/utils/broadcasting_test.py (92%) rename model-optimizer/{ => unit_tests}/mo/utils/cli_parser_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/error_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/graph_test.py (100%) create mode 100644 model-optimizer/unit_tests/mo/utils/ir_engine/__init__.py rename model-optimizer/{ => unit_tests}/mo/utils/ir_engine/ir_engine_test.py (94%) create mode 100644 model-optimizer/unit_tests/mo/utils/ir_reader/__init__.py rename model-optimizer/{ => unit_tests}/mo/utils/ir_reader/layer_to_class_test.py (99%) rename model-optimizer/{ => unit_tests}/mo/utils/pipeline_config_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/simple_proto_parser_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/summarize_graph_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/utils_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/version_test.py (100%) rename model-optimizer/{ => unit_tests}/mo/utils/versions_checker_test.py (100%) create mode 100644 model-optimizer/unit_tests/utils/__init__.py rename model-optimizer/{mo/utils/unittest => unit_tests/utils}/extractors.py (100%) rename model-optimizer/{mo/utils/unittest => unit_tests/utils}/graph.py (100%) rename model-optimizer/{mo/utils/unittest => unit_tests/utils}/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.bin (100%) rename model-optimizer/{mo/utils/unittest => unit_tests/utils}/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml (100%) rename model-optimizer/{mo/utils/unittest => unit_tests/utils}/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml (100%) diff --git a/model-optimizer/requirements.txt b/model-optimizer/requirements.txt index 366dd9131d5..f4690746c79 100644 --- a/model-optimizer/requirements.txt +++ b/model-optimizer/requirements.txt @@ -5,7 +5,6 @@ networkx>=1.11 numpy>=1.14.0,<1.19.0 protobuf>=3.6.1 onnx>=1.1.2 -test-generator==0.1.1 defusedxml>=0.5.0 urllib3>=1.25.9 requests>=2.20.0 diff --git a/model-optimizer/requirements_caffe.txt b/model-optimizer/requirements_caffe.txt index 12f84ce9f05..037f0a838f6 100644 --- a/model-optimizer/requirements_caffe.txt +++ b/model-optimizer/requirements_caffe.txt @@ -1,6 +1,5 @@ networkx>=1.11 numpy>=1.14.0 protobuf>=3.6.1 -test-generator==0.1.1 defusedxml>=0.5.0 requests>=2.20.0 diff --git a/model-optimizer/requirements_kaldi.txt b/model-optimizer/requirements_kaldi.txt index 5104a2b1798..b027c76c594 100644 --- a/model-optimizer/requirements_kaldi.txt +++ b/model-optimizer/requirements_kaldi.txt @@ -1,5 +1,4 @@ networkx>=1.11 numpy>=1.14.0 -test-generator==0.1.1 defusedxml>=0.5.0 requests>=2.20.0 diff --git a/model-optimizer/requirements_mxnet.txt b/model-optimizer/requirements_mxnet.txt index 228cb06c426..8877c2b499e 100644 --- a/model-optimizer/requirements_mxnet.txt +++ b/model-optimizer/requirements_mxnet.txt @@ -1,7 +1,6 @@ mxnet>=1.0.0,<=1.7.0 networkx>=1.11 numpy>=1.14.0 -test-generator==0.1.1 defusedxml>=0.5.0 urllib3>=1.25.9 requests>=2.20.0 diff --git a/model-optimizer/requirements_onnx.txt b/model-optimizer/requirements_onnx.txt index 4f4d54b4b2f..29730df249b 100644 --- a/model-optimizer/requirements_onnx.txt +++ b/model-optimizer/requirements_onnx.txt @@ -1,6 +1,5 @@ onnx>=1.1.2 networkx>=1.11 numpy>=1.14.0 -test-generator==0.1.1 defusedxml>=0.5.0 requests>=2.20.0 diff --git a/model-optimizer/requirements_tf.txt b/model-optimizer/requirements_tf.txt index 531b03c3a80..3a83569827d 100644 --- a/model-optimizer/requirements_tf.txt +++ b/model-optimizer/requirements_tf.txt @@ -2,6 +2,5 @@ tensorflow>=1.15.2,<2.0; python_version < "3.8" tensorflow>=2.2; python_version >= "3.8" networkx>=1.11 numpy>=1.14.0,<1.19.0 -test-generator==0.1.1 defusedxml>=0.5.0 requests>=2.20.0 diff --git a/model-optimizer/requirements_tf2.txt b/model-optimizer/requirements_tf2.txt index bd6fc777b1f..94497c8a32a 100644 --- a/model-optimizer/requirements_tf2.txt +++ b/model-optimizer/requirements_tf2.txt @@ -1,6 +1,5 @@ tensorflow>=2.2 networkx>=1.11 numpy>=1.14.0 -test-generator==0.1.1 defusedxml>=0.5.0 requests>=2.20.0 diff --git a/model-optimizer/telemetry/utils/sender_test.py b/model-optimizer/telemetry/utils/sender_test.py deleted file mode 100644 index 4dca81e3f27..00000000000 --- a/model-optimizer/telemetry/utils/sender_test.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import unittest -import time - -from telemetry.utils.sender import TelemetrySender - - -class FakeTelemetryBackend: - def send(self, param): - pass - - -class FakeTelemetryBackendWithSleep: - def send(self, param): - time.sleep(1) - - -class TelemetrySenderStress(unittest.TestCase): - def test_stress(self): - """ - Stress tests to schedule a lot of threads which works super fast (do nothing) with sending messages." - """ - tm = TelemetrySender() - fake_backend = FakeTelemetryBackend() - for _ in range(1000000): - tm.send(fake_backend, None) - - def test_check_shutdown(self): - """ - Stress test to schedule many threads taking 1 second and then ask to force shutdown. Make sure that the elapsed - time is small. - """ - tm = TelemetrySender() - fake_backend = FakeTelemetryBackendWithSleep() - # schedule many requests which just wait 1 second - for _ in range(100000): - tm.send(fake_backend, None) - - start_time = time.time() - # ask to shutdown with timeout of 1 second - tm.force_shutdown(1) - while len(tm.executor._threads): - pass - # check that no more than 3 seconds spent - self.assertTrue(time.time() - start_time < 3) - - def test_check_shutdown_negative(self): - """ - Test to check that without forcing shutdown total execution time is expected. - """ - tm = TelemetrySender(1) # only one worker thread - fake_backend = FakeTelemetryBackendWithSleep() - start_time = time.time() - # schedule 5 requests which totally should work more than 4 seconds - for _ in range(5): - tm.send(fake_backend, None) - - try: - # wait until all threads finish their work. We use internal ThreadPoolExecutor attribute _work_queue to make - # sure that all workers completed their work, so the whole code is wrapped to try/except to avoid exceptions - # if internal implementation is changed in the future - while tm.executor._work_queue.qsize(): - pass - self.assertTrue(time.time() - start_time > 4.0) - except: - pass diff --git a/model-optimizer/unit_tests/__init__.py b/model-optimizer/unit_tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/extensions/__init__.py b/model-optimizer/unit_tests/extensions/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/analysis/Iterator_get_next_test.py b/model-optimizer/unit_tests/extensions/analysis/Iterator_get_next_test.py similarity index 96% rename from model-optimizer/extensions/analysis/Iterator_get_next_test.py rename to model-optimizer/unit_tests/extensions/analysis/Iterator_get_next_test.py index 9d5a54bcd0a..801873bdbb9 100644 --- a/model-optimizer/extensions/analysis/Iterator_get_next_test.py +++ b/model-optimizer/unit_tests/extensions/analysis/Iterator_get_next_test.py @@ -5,7 +5,7 @@ import unittest from extensions.analysis.inputs import InputsAnalysis from mo.front.common.partial_infer.utils import int64_array -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs class IteratorGetNextAnalysisTest(unittest.TestCase): diff --git a/model-optimizer/unit_tests/extensions/analysis/__init__.py b/model-optimizer/unit_tests/extensions/analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/back/ClampNormalizer_test.py b/model-optimizer/unit_tests/extensions/back/ClampNormalizer_test.py similarity index 97% rename from model-optimizer/extensions/back/ClampNormalizer_test.py rename to model-optimizer/unit_tests/extensions/back/ClampNormalizer_test.py index bd7746eed4b..f09be16e8ce 100644 --- a/model-optimizer/extensions/back/ClampNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/back/ClampNormalizer_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.back.ClampNormalizer import ClampNormalizer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect class AttributedClampNormalizerTests(unittest.TestCase): diff --git a/model-optimizer/extensions/back/ConvolutionNormalizer_test.py b/model-optimizer/unit_tests/extensions/back/ConvolutionNormalizer_test.py similarity index 98% rename from model-optimizer/extensions/back/ConvolutionNormalizer_test.py rename to model-optimizer/unit_tests/extensions/back/ConvolutionNormalizer_test.py index fb4b15cae34..d7a2f4809fc 100644 --- a/model-optimizer/extensions/back/ConvolutionNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/back/ConvolutionNormalizer_test.py @@ -11,7 +11,7 @@ from extensions.ops.fakequantize import FakeQuantize from mo.front.common.partial_infer.utils import int64_array from mo.ops.reshape import Reshape from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, regular_op_with_empty_data, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, regular_op_with_empty_data, \ valued_const_with_data, connect diff --git a/model-optimizer/extensions/back/CutMemory_test.py b/model-optimizer/unit_tests/extensions/back/CutMemory_test.py similarity index 98% rename from model-optimizer/extensions/back/CutMemory_test.py rename to model-optimizer/unit_tests/extensions/back/CutMemory_test.py index 4edb90e6f7e..a3c5403bc89 100644 --- a/model-optimizer/extensions/back/CutMemory_test.py +++ b/model-optimizer/unit_tests/extensions/back/CutMemory_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.back.CutMemory import CutMemoryInput, CutMemoryOutput from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class CutMemoryTest(unittest.TestCase): diff --git a/model-optimizer/extensions/back/FakeOutputResolver_test.py b/model-optimizer/unit_tests/extensions/back/FakeOutputResolver_test.py similarity index 96% rename from model-optimizer/extensions/back/FakeOutputResolver_test.py rename to model-optimizer/unit_tests/extensions/back/FakeOutputResolver_test.py index 64baebc8d2c..82020d36f4f 100644 --- a/model-optimizer/extensions/back/FakeOutputResolver_test.py +++ b/model-optimizer/unit_tests/extensions/back/FakeOutputResolver_test.py @@ -6,7 +6,7 @@ import unittest from extensions.back.FakeOutputResolver import FakeOutputResolver from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_empty_data, connect, empty_data, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_empty_data, connect, empty_data, \ valued_const_with_data diff --git a/model-optimizer/extensions/back/FuseTransposesSequence_test.py b/model-optimizer/unit_tests/extensions/back/FuseTransposesSequence_test.py similarity index 98% rename from model-optimizer/extensions/back/FuseTransposesSequence_test.py rename to model-optimizer/unit_tests/extensions/back/FuseTransposesSequence_test.py index 0614a90e9f4..ed174be2883 100644 --- a/model-optimizer/extensions/back/FuseTransposesSequence_test.py +++ b/model-optimizer/unit_tests/extensions/back/FuseTransposesSequence_test.py @@ -2,13 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 import unittest -from argparse import Namespace import numpy as np from extensions.back.FuseTransposesSequence import FuseTransposesSequence -from mo.middle.passes.eliminate_test import build_graph from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph # The dictionary with nodes attributes used to build various graphs. A key is the name of the node and the value is the # dictionary with node attributes. diff --git a/model-optimizer/extensions/back/InterpolateReshape_test.py b/model-optimizer/unit_tests/extensions/back/InterpolateReshape_test.py similarity index 94% rename from model-optimizer/extensions/back/InterpolateReshape_test.py rename to model-optimizer/unit_tests/extensions/back/InterpolateReshape_test.py index 0ab62e5d754..e81b0611a77 100644 --- a/model-optimizer/extensions/back/InterpolateReshape_test.py +++ b/model-optimizer/unit_tests/extensions/back/InterpolateReshape_test.py @@ -2,13 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 import unittest -from argparse import Namespace import numpy as np from extensions.back.InterpolateReshape import InterpolateReshapeWA, InterpolateConcat from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ connect_data nodes = { diff --git a/model-optimizer/extensions/back/LayoutChangeForGatherND_test.py b/model-optimizer/unit_tests/extensions/back/LayoutChangeForGatherND_test.py similarity index 99% rename from model-optimizer/extensions/back/LayoutChangeForGatherND_test.py rename to model-optimizer/unit_tests/extensions/back/LayoutChangeForGatherND_test.py index 7d517fe3c13..652f40180b9 100644 --- a/model-optimizer/extensions/back/LayoutChangeForGatherND_test.py +++ b/model-optimizer/unit_tests/extensions/back/LayoutChangeForGatherND_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.back.LayoutChangeForGatherND import LayoutChangeForGatherND from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/back/MarkNodesWithShapeValues_test.py b/model-optimizer/unit_tests/extensions/back/MarkNodesWithShapeValues_test.py similarity index 84% rename from model-optimizer/extensions/back/MarkNodesWithShapeValues_test.py rename to model-optimizer/unit_tests/extensions/back/MarkNodesWithShapeValues_test.py index 0d33f7b6e21..83ef22d24e7 100644 --- a/model-optimizer/extensions/back/MarkNodesWithShapeValues_test.py +++ b/model-optimizer/unit_tests/extensions/back/MarkNodesWithShapeValues_test.py @@ -9,9 +9,8 @@ from extensions.back.MarkNodesWithShapeValues import MarkNodesWithShapeValues from mo.front.common.partial_infer.utils import int64_array, float32_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph -from mo.utils.unittest.graph import result, regular_op_with_empty_data, \ - shaped_const_with_data, connect, regular_op +from unit_tests.utils.graph import build_graph, result, regular_op_with_empty_data, shaped_const_with_data, connect, \ + regular_op class TestMarkDataTypeInShapeOfSubgraphs(unittest.TestCase): @@ -24,7 +23,7 @@ class TestMarkDataTypeInShapeOfSubgraphs(unittest.TestCase): **shaped_const_with_data('input', int64_array(inp_shape)), **regular_op_with_empty_data('shape', {'type': 'ShapeOf'}), **regular_op_with_empty_data('cast_to_float', {'type': 'Cast', 'dst_type': dst_type}), - **regular_op('mul_const', {'op': 'Const'}), + **regular_op('mul_const', {'op': 'Const'}), **{'mul_const_d': {'kind': 'data', 'value': float32_array([1., 1., 1., 100.])}}, **regular_op_with_empty_data('mul', {'type': 'Mul'}), **regular_op_with_empty_data('cast_to_int', {'type': 'Cast', 'dst_type': np.int64}), @@ -38,7 +37,7 @@ class TestMarkDataTypeInShapeOfSubgraphs(unittest.TestCase): **regular_op_with_empty_data('cast_to_float', {'type': 'Cast', 'dst_type': dst_type, 'returns_shape_value': True}), **regular_op_with_empty_data('mul', {'type': 'Mul', 'returns_shape_value': True}), - **regular_op('mul_const', {'op': 'Const', 'returns_shape_value': True}), + **regular_op('mul_const', {'op': 'Const', 'returns_shape_value': True}), **{'mul_const_d': {'kind': 'data', 'value': float32_array([1., 1., 1., 100.]), 'correct_data_type': True}}, **regular_op_with_empty_data('cast_to_int', {'type': 'Cast', 'dst_type': np.int64, @@ -69,21 +68,20 @@ class TestMarkDataTypeInShapeOfSubgraphs(unittest.TestCase): def test_run_with_const_input(self): inp_shape = (1, 3, 1000, 1000) - dst_type = np.float32 nodes = { **shaped_const_with_data('input', int64_array(inp_shape)), - **regular_op('sizes_const', {'op': 'Const'}), + **regular_op('sizes_const', {'op': 'Const'}), **{'sizes_const_d': {'kind': 'data', 'value': float32_array([1., 1., 1., 100.])}}, - **regular_op_with_empty_data('interpolate', {'type': 'Interpolate', 'shape_calculation_model': 'scales'}), + **regular_op_with_empty_data('interpolate', {'type': 'Interpolate', 'shape_calculation_model': 'scales'}), **result('res'), } nodes_ref = { **shaped_const_with_data('input', int64_array(inp_shape)), - **regular_op('sizes_const', {'op': 'Const', 'returns_shape_value': True}), + **regular_op('sizes_const', {'op': 'Const', 'returns_shape_value': True}), **{'sizes_const_d': {'kind': 'data', 'value': float32_array([1., 1., 1., 100.])}}, - **regular_op_with_empty_data('interpolate', {'type': 'Interpolate', 'shape_calculation_model': 'scales'}), + **regular_op_with_empty_data('interpolate', {'type': 'Interpolate', 'shape_calculation_model': 'scales'}), **result('res'), } diff --git a/model-optimizer/extensions/back/MatMulNormalizer_test.py b/model-optimizer/unit_tests/extensions/back/MatMulNormalizer_test.py similarity index 96% rename from model-optimizer/extensions/back/MatMulNormalizer_test.py rename to model-optimizer/unit_tests/extensions/back/MatMulNormalizer_test.py index ab5d5942821..1d019526fcc 100644 --- a/model-optimizer/extensions/back/MatMulNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/back/MatMulNormalizer_test.py @@ -11,9 +11,9 @@ from extensions.ops.MatMul import MatMul from mo.front.common.partial_infer.utils import int64_array from mo.ops.reshape import Reshape from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, \ result, connect -from mo.utils.unittest.graph import regular_op_with_empty_data as op_with_empty_data +from unit_tests.utils.graph import regular_op_with_empty_data as op_with_empty_data @generator diff --git a/model-optimizer/extensions/back/OptimizeTransposeReshapeSequence_test.py b/model-optimizer/unit_tests/extensions/back/OptimizeTransposeReshapeSequence_test.py similarity index 100% rename from model-optimizer/extensions/back/OptimizeTransposeReshapeSequence_test.py rename to model-optimizer/unit_tests/extensions/back/OptimizeTransposeReshapeSequence_test.py diff --git a/model-optimizer/extensions/back/ReduceTransposeDimensions_test.py b/model-optimizer/unit_tests/extensions/back/ReduceTransposeDimensions_test.py similarity index 100% rename from model-optimizer/extensions/back/ReduceTransposeDimensions_test.py rename to model-optimizer/unit_tests/extensions/back/ReduceTransposeDimensions_test.py diff --git a/model-optimizer/extensions/back/ResultRename_test.py b/model-optimizer/unit_tests/extensions/back/ResultRename_test.py similarity index 97% rename from model-optimizer/extensions/back/ResultRename_test.py rename to model-optimizer/unit_tests/extensions/back/ResultRename_test.py index 1c70c3995e8..b38937fa624 100644 --- a/model-optimizer/extensions/back/ResultRename_test.py +++ b/model-optimizer/unit_tests/extensions/back/ResultRename_test.py @@ -6,7 +6,7 @@ import unittest from extensions.back.ResultRename import ResultRename from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op, result +from unit_tests.utils.graph import build_graph, regular_op, result nodes = { **regular_op('Op1', {'type': 'Op1', 'kind': 'op', 'op': 'Op1'}), diff --git a/model-optimizer/extensions/back/ShuffleChannelPatternOptimization_test.py b/model-optimizer/unit_tests/extensions/back/ShuffleChannelPatternOptimization_test.py similarity index 99% rename from model-optimizer/extensions/back/ShuffleChannelPatternOptimization_test.py rename to model-optimizer/unit_tests/extensions/back/ShuffleChannelPatternOptimization_test.py index 8469c32c734..c4a91950c54 100644 --- a/model-optimizer/extensions/back/ShuffleChannelPatternOptimization_test.py +++ b/model-optimizer/unit_tests/extensions/back/ShuffleChannelPatternOptimization_test.py @@ -14,7 +14,7 @@ from extensions.ops.transpose import Transpose from mo.front.common.partial_infer.utils import int64_array from mo.ops.reshape import Reshape from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, \ valued_const_with_data, connect, regular_op_with_empty_data diff --git a/model-optimizer/extensions/back/ShufflenetReLUReorder_test.py b/model-optimizer/unit_tests/extensions/back/ShufflenetReLUReorder_test.py similarity index 99% rename from model-optimizer/extensions/back/ShufflenetReLUReorder_test.py rename to model-optimizer/unit_tests/extensions/back/ShufflenetReLUReorder_test.py index 38dab3464af..5b154f22c9d 100644 --- a/model-optimizer/extensions/back/ShufflenetReLUReorder_test.py +++ b/model-optimizer/unit_tests/extensions/back/ShufflenetReLUReorder_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.back.ShufflenetReLUReorder import ShufflenetReLUReorder from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # The dictionary with nodes attributes used to build various graphs. A key is the name of the node and the value is the # dictionary with node attributes. diff --git a/model-optimizer/extensions/back/SpecialNodesFinalization_test.py b/model-optimizer/unit_tests/extensions/back/SpecialNodesFinalization_test.py similarity index 99% rename from model-optimizer/extensions/back/SpecialNodesFinalization_test.py rename to model-optimizer/unit_tests/extensions/back/SpecialNodesFinalization_test.py index ea6516adbc3..efcc9042b30 100644 --- a/model-optimizer/extensions/back/SpecialNodesFinalization_test.py +++ b/model-optimizer/unit_tests/extensions/back/SpecialNodesFinalization_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.back.SpecialNodesFinalization import CreateConstNodesReplacement, RemoveConstToResult from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class CreateConstNodesReplacementTest(unittest.TestCase): diff --git a/model-optimizer/extensions/back/TransposeReduceFusing_test.py b/model-optimizer/unit_tests/extensions/back/TransposeReduceFusing_test.py similarity index 99% rename from model-optimizer/extensions/back/TransposeReduceFusing_test.py rename to model-optimizer/unit_tests/extensions/back/TransposeReduceFusing_test.py index fa7ec2c1cc8..54ecf80bdfd 100644 --- a/model-optimizer/extensions/back/TransposeReduceFusing_test.py +++ b/model-optimizer/unit_tests/extensions/back/TransposeReduceFusing_test.py @@ -6,7 +6,7 @@ import unittest from extensions.back.TransposeReduceFusing import TransposeReduce from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { # op diff --git a/model-optimizer/unit_tests/extensions/back/__init__.py b/model-optimizer/unit_tests/extensions/back/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/back/compress_quantized_weights_test.py b/model-optimizer/unit_tests/extensions/back/compress_quantized_weights_test.py similarity index 98% rename from model-optimizer/extensions/back/compress_quantized_weights_test.py rename to model-optimizer/unit_tests/extensions/back/compress_quantized_weights_test.py index 251b9be4c69..73ca749d016 100644 --- a/model-optimizer/extensions/back/compress_quantized_weights_test.py +++ b/model-optimizer/unit_tests/extensions/back/compress_quantized_weights_test.py @@ -13,7 +13,7 @@ from extensions.ops.elementwise import Sub, Mul from extensions.ops.fakequantize import FakeQuantize from mo.front.common.partial_infer.eltwise import eltwise_infer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect, \ shaped_const_with_data diff --git a/model-optimizer/extensions/back/insert_compatibility_l2normalization_test.py b/model-optimizer/unit_tests/extensions/back/insert_compatibility_l2normalization_test.py similarity index 96% rename from model-optimizer/extensions/back/insert_compatibility_l2normalization_test.py rename to model-optimizer/unit_tests/extensions/back/insert_compatibility_l2normalization_test.py index 5c88dfba0b6..559eb2e4075 100644 --- a/model-optimizer/extensions/back/insert_compatibility_l2normalization_test.py +++ b/model-optimizer/unit_tests/extensions/back/insert_compatibility_l2normalization_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from extensions.back.insert_compatibility_l2normalization import CompatibilityL2NormalizationPattern -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class CompatibilityL2NormalizationPatternTest(unittest.TestCase): diff --git a/model-optimizer/extensions/back/kaldi_remove_memory_output_test.py b/model-optimizer/unit_tests/extensions/back/kaldi_remove_memory_output_test.py similarity index 96% rename from model-optimizer/extensions/back/kaldi_remove_memory_output_test.py rename to model-optimizer/unit_tests/extensions/back/kaldi_remove_memory_output_test.py index b0adddcddbe..e9c42a0ddca 100644 --- a/model-optimizer/extensions/back/kaldi_remove_memory_output_test.py +++ b/model-optimizer/unit_tests/extensions/back/kaldi_remove_memory_output_test.py @@ -4,7 +4,7 @@ import unittest from extensions.back.kaldi_remove_memory_output import KaldiRemoveMemoryOutputBackReplacementPattern -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class KaldiRemoveMemoryOutputTest(unittest.TestCase): diff --git a/model-optimizer/extensions/back/remove_last_softmax_test.py b/model-optimizer/unit_tests/extensions/back/remove_last_softmax_test.py similarity index 98% rename from model-optimizer/extensions/back/remove_last_softmax_test.py rename to model-optimizer/unit_tests/extensions/back/remove_last_softmax_test.py index d9165097617..a3a8ba19c71 100644 --- a/model-optimizer/extensions/back/remove_last_softmax_test.py +++ b/model-optimizer/unit_tests/extensions/back/remove_last_softmax_test.py @@ -6,7 +6,7 @@ import unittest from extensions.back.remove_last_softmax_pattern import RemoveLastSoftMaxPattern, RemoveLastLogSoftMaxPattern from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class KaldiRemoveLastSoftMaxTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/ATenToEmbeddingBag_test.py b/model-optimizer/unit_tests/extensions/front/ATenToEmbeddingBag_test.py similarity index 98% rename from model-optimizer/extensions/front/ATenToEmbeddingBag_test.py rename to model-optimizer/unit_tests/extensions/front/ATenToEmbeddingBag_test.py index 31436a037d7..178811dac09 100644 --- a/model-optimizer/extensions/front/ATenToEmbeddingBag_test.py +++ b/model-optimizer/unit_tests/extensions/front/ATenToEmbeddingBag_test.py @@ -8,8 +8,7 @@ import numpy as np from extensions.front.ATenToEmbeddingBag import AtenToEmbeddingBag from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, \ - regular_op, const +from unit_tests.utils.graph import build_graph, result, regular_op, const class AtenToEmbeddingBagTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/AttributedClampNormalizer_test.py b/model-optimizer/unit_tests/extensions/front/AttributedClampNormalizer_test.py similarity index 97% rename from model-optimizer/extensions/front/AttributedClampNormalizer_test.py rename to model-optimizer/unit_tests/extensions/front/AttributedClampNormalizer_test.py index ba7aa09e51a..086ebf2a183 100644 --- a/model-optimizer/extensions/front/AttributedClampNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/front/AttributedClampNormalizer_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.AttributedClampNormalizer import AttributedClampNormalizer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'placeholder': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/AttributedPadToPad_test.py b/model-optimizer/unit_tests/extensions/front/AttributedPadToPad_test.py similarity index 98% rename from model-optimizer/extensions/front/AttributedPadToPad_test.py rename to model-optimizer/unit_tests/extensions/front/AttributedPadToPad_test.py index 6a878c3daba..0c9efd97b8c 100644 --- a/model-optimizer/extensions/front/AttributedPadToPad_test.py +++ b/model-optimizer/unit_tests/extensions/front/AttributedPadToPad_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.AttributedPadToPad import AttributedPadToPad from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'placeholder': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/AttributedRollToRoll_test.py b/model-optimizer/unit_tests/extensions/front/AttributedRollToRoll_test.py similarity index 97% rename from model-optimizer/extensions/front/AttributedRollToRoll_test.py rename to model-optimizer/unit_tests/extensions/front/AttributedRollToRoll_test.py index 95d2e1460dd..60f0ecccd4f 100644 --- a/model-optimizer/extensions/front/AttributedRollToRoll_test.py +++ b/model-optimizer/unit_tests/extensions/front/AttributedRollToRoll_test.py @@ -7,7 +7,7 @@ from extensions.front.AttributedRollToRoll import AttributedRollToRoll from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, result, regular_op +from unit_tests.utils.graph import build_graph, const, result, regular_op nodes_attributes = { **regular_op('placeholder', {'type': 'Parameter'}), diff --git a/model-optimizer/extensions/front/DropoutWithRandomUniformReplacer_test.py b/model-optimizer/unit_tests/extensions/front/DropoutWithRandomUniformReplacer_test.py similarity index 97% rename from model-optimizer/extensions/front/DropoutWithRandomUniformReplacer_test.py rename to model-optimizer/unit_tests/extensions/front/DropoutWithRandomUniformReplacer_test.py index 77f9f9c5284..a95557cf84d 100644 --- a/model-optimizer/extensions/front/DropoutWithRandomUniformReplacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/DropoutWithRandomUniformReplacer_test.py @@ -7,7 +7,7 @@ import unittest from extensions.front.DropoutWithRandomUniformReplacer import DropoutWithRandomUniformReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op +from unit_tests.utils.graph import build_graph, result, regular_op class DropoutWithRandomUniformReplacerTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/GeLUMerger_Erf_test.py b/model-optimizer/unit_tests/extensions/front/GeLUMerger_Erf_test.py similarity index 97% rename from model-optimizer/extensions/front/GeLUMerger_Erf_test.py rename to model-optimizer/unit_tests/extensions/front/GeLUMerger_Erf_test.py index 8b855226762..cf637cff998 100644 --- a/model-optimizer/extensions/front/GeLUMerger_Erf_test.py +++ b/model-optimizer/unit_tests/extensions/front/GeLUMerger_Erf_test.py @@ -7,7 +7,7 @@ from math import sqrt from extensions.front.GeLUMerger_Erf import GeLUMergerErf from mo.front.common.partial_infer.utils import float_array, int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, regular_op, result, build_graph +from unit_tests.utils.graph import const, regular_op, result, build_graph ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('gelu', {'type': 'Gelu', 'approximation_mode': 'erf', 'name': 'final_mul'}), diff --git a/model-optimizer/extensions/front/GeLUMerger_Tanh_test.py b/model-optimizer/unit_tests/extensions/front/GeLUMerger_Tanh_test.py similarity index 98% rename from model-optimizer/extensions/front/GeLUMerger_Tanh_test.py rename to model-optimizer/unit_tests/extensions/front/GeLUMerger_Tanh_test.py index 9c29feb9856..412dfba9f87 100644 --- a/model-optimizer/extensions/front/GeLUMerger_Tanh_test.py +++ b/model-optimizer/unit_tests/extensions/front/GeLUMerger_Tanh_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.GeLUMerger_Tanh import GeLUMergerTanh from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes_erf = { 'inp': {'kind': 'op', 'op': 'AnyOp'}, diff --git a/model-optimizer/extensions/front/HSigmoid_fusion_test.py b/model-optimizer/unit_tests/extensions/front/HSigmoid_fusion_test.py similarity index 99% rename from model-optimizer/extensions/front/HSigmoid_fusion_test.py rename to model-optimizer/unit_tests/extensions/front/HSigmoid_fusion_test.py index 3edb80f86ee..e2a3b68223a 100644 --- a/model-optimizer/extensions/front/HSigmoid_fusion_test.py +++ b/model-optimizer/unit_tests/extensions/front/HSigmoid_fusion_test.py @@ -7,7 +7,7 @@ from extensions.front.HSigmoid_fusion import HSigmoidWithClamp, HSigmoidWithMinM HSigmoidWithReluMul from mo.front.common.partial_infer.utils import float_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('hsigmoid', {'type': 'HSigmoid', 'name': 'final_mul'}), diff --git a/model-optimizer/extensions/front/HSwish_fusing_test.py b/model-optimizer/unit_tests/extensions/front/HSwish_fusing_test.py similarity index 98% rename from model-optimizer/extensions/front/HSwish_fusing_test.py rename to model-optimizer/unit_tests/extensions/front/HSwish_fusing_test.py index 912ea92ee51..33f9722d51a 100644 --- a/model-optimizer/extensions/front/HSwish_fusing_test.py +++ b/model-optimizer/unit_tests/extensions/front/HSwish_fusing_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.HSwish_fusion import HSwishWithClamp, HSwishWithMinMax from mo.front.common.partial_infer.utils import float_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('hswish', {'type': 'HSwish', 'name': 'final_mul'}), diff --git a/model-optimizer/extensions/front/LayerNorm_test.py b/model-optimizer/unit_tests/extensions/front/LayerNorm_test.py similarity index 98% rename from model-optimizer/extensions/front/LayerNorm_test.py rename to model-optimizer/unit_tests/extensions/front/LayerNorm_test.py index 85127c9edc7..6c75e73bb01 100644 --- a/model-optimizer/extensions/front/LayerNorm_test.py +++ b/model-optimizer/unit_tests/extensions/front/LayerNorm_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.LayerNorm import LayerNorm from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestMVNPatternReplacement(unittest.TestCase): diff --git a/model-optimizer/extensions/front/Log1p_test.py b/model-optimizer/unit_tests/extensions/front/Log1p_test.py similarity index 97% rename from model-optimizer/extensions/front/Log1p_test.py rename to model-optimizer/unit_tests/extensions/front/Log1p_test.py index 4fab1fd5948..8cbc91cceca 100644 --- a/model-optimizer/extensions/front/Log1p_test.py +++ b/model-optimizer/unit_tests/extensions/front/Log1p_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.Log1p import Log1p from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder': {'shape': np.array([4, 5, 6]), 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/Mish_fusion_test.py b/model-optimizer/unit_tests/extensions/front/Mish_fusion_test.py similarity index 96% rename from model-optimizer/extensions/front/Mish_fusion_test.py rename to model-optimizer/unit_tests/extensions/front/Mish_fusion_test.py index 8febc581acd..10e48daefad 100644 --- a/model-optimizer/extensions/front/Mish_fusion_test.py +++ b/model-optimizer/unit_tests/extensions/front/Mish_fusion_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.Mish_fusion import MishFusion from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op, result, build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph, regular_op, result, build_graph_with_edge_attrs ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('mish', {'type': 'Mish', 'name': 'final_mul'}), diff --git a/model-optimizer/extensions/front/OneHotDepthNormalizer_test.py b/model-optimizer/unit_tests/extensions/front/OneHotDepthNormalizer_test.py similarity index 96% rename from model-optimizer/extensions/front/OneHotDepthNormalizer_test.py rename to model-optimizer/unit_tests/extensions/front/OneHotDepthNormalizer_test.py index 159c4f2d512..6d99744d5d8 100644 --- a/model-optimizer/extensions/front/OneHotDepthNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/front/OneHotDepthNormalizer_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.OneHotDepthNormalizer import OneHotDepthNormalizer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, \ +from unit_tests.utils.graph import build_graph, result, \ regular_op, const diff --git a/model-optimizer/extensions/front/Pack_test.py b/model-optimizer/unit_tests/extensions/front/Pack_test.py similarity index 98% rename from model-optimizer/extensions/front/Pack_test.py rename to model-optimizer/unit_tests/extensions/front/Pack_test.py index 21185302f5d..91763dd1136 100644 --- a/model-optimizer/extensions/front/Pack_test.py +++ b/model-optimizer/unit_tests/extensions/front/Pack_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.front.Pack import Pack from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_0': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/RollWithEmptyAxesReplacer_test.py b/model-optimizer/unit_tests/extensions/front/RollWithEmptyAxesReplacer_test.py similarity index 96% rename from model-optimizer/extensions/front/RollWithEmptyAxesReplacer_test.py rename to model-optimizer/unit_tests/extensions/front/RollWithEmptyAxesReplacer_test.py index 3010644a058..e172737f15e 100644 --- a/model-optimizer/extensions/front/RollWithEmptyAxesReplacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/RollWithEmptyAxesReplacer_test.py @@ -7,7 +7,7 @@ from extensions.front.RollWithEmptyAxesReplacer import RollWithEmptyAxesReplacer from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, result, regular_op +from unit_tests.utils.graph import build_graph, const, result, regular_op nodes_attributes = { **regular_op('placeholder', {'type': 'Parameter'}), diff --git a/model-optimizer/extensions/front/Softplus_fusion_test.py b/model-optimizer/unit_tests/extensions/front/Softplus_fusion_test.py similarity index 95% rename from model-optimizer/extensions/front/Softplus_fusion_test.py rename to model-optimizer/unit_tests/extensions/front/Softplus_fusion_test.py index 1adcd8022ae..0dd93f8d95c 100644 --- a/model-optimizer/extensions/front/Softplus_fusion_test.py +++ b/model-optimizer/unit_tests/extensions/front/Softplus_fusion_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.Softplus_fusion import SoftplusFusion from mo.front.common.partial_infer.utils import float_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph, const, regular_op, result, build_graph_with_edge_attrs ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('softplus', {'type': 'SoftPlus', 'name': 'final_log'}), diff --git a/model-optimizer/extensions/front/Swish_fusion_test.py b/model-optimizer/unit_tests/extensions/front/Swish_fusion_test.py similarity index 98% rename from model-optimizer/extensions/front/Swish_fusion_test.py rename to model-optimizer/unit_tests/extensions/front/Swish_fusion_test.py index f4620e3b139..ccf9985536b 100644 --- a/model-optimizer/extensions/front/Swish_fusion_test.py +++ b/model-optimizer/unit_tests/extensions/front/Swish_fusion_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.Swish_fusion import SwishWithSigmoidWithoutBeta, SwishWithSigmoidWithBeta from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op, result, build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph, regular_op, result, build_graph_with_edge_attrs ref_nodes = {**regular_op('input', {'type': 'Parameter'}), **regular_op('swish', {'type': 'Swish', 'name': 'final_mul'}), diff --git a/model-optimizer/extensions/front/ThresholdedReluDecomposition_test.py b/model-optimizer/unit_tests/extensions/front/ThresholdedReluDecomposition_test.py similarity index 97% rename from model-optimizer/extensions/front/ThresholdedReluDecomposition_test.py rename to model-optimizer/unit_tests/extensions/front/ThresholdedReluDecomposition_test.py index 2dc592feeb3..e550b724dcf 100644 --- a/model-optimizer/extensions/front/ThresholdedReluDecomposition_test.py +++ b/model-optimizer/unit_tests/extensions/front/ThresholdedReluDecomposition_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.ThresholdedReluDecomposition import ThresholdedReluDecomposition from mo.front.common.partial_infer.utils import float_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'parameter': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/unit_tests/extensions/front/__init__.py b/model-optimizer/unit_tests/extensions/front/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/binary_quantize_normalization_test.py b/model-optimizer/unit_tests/extensions/front/binary_quantize_normalization_test.py similarity index 97% rename from model-optimizer/extensions/front/binary_quantize_normalization_test.py rename to model-optimizer/unit_tests/extensions/front/binary_quantize_normalization_test.py index 2b64e1993fa..a0b36dda99a 100644 --- a/model-optimizer/extensions/front/binary_quantize_normalization_test.py +++ b/model-optimizer/unit_tests/extensions/front/binary_quantize_normalization_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.binary_quantize_normalization import BinaryFakeQuantizeNormalization from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_nodes = { '0': {'name': 'input', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/broadcast_with_range_test.py b/model-optimizer/unit_tests/extensions/front/broadcast_with_range_test.py similarity index 95% rename from model-optimizer/extensions/front/broadcast_with_range_test.py rename to model-optimizer/unit_tests/extensions/front/broadcast_with_range_test.py index 9c1bfb1b5f6..ca5cd19f3e2 100644 --- a/model-optimizer/extensions/front/broadcast_with_range_test.py +++ b/model-optimizer/unit_tests/extensions/front/broadcast_with_range_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.broadcast_with_range import ExpandRangeConstant from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ regular_op_with_empty_data, connect_data diff --git a/model-optimizer/extensions/front/caffe/MVNCaffeToMVN_test.py b/model-optimizer/unit_tests/extensions/front/caffe/MVNCaffeToMVN_test.py similarity index 96% rename from model-optimizer/extensions/front/caffe/MVNCaffeToMVN_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/MVNCaffeToMVN_test.py index 76fe876fff9..68f77631bb7 100644 --- a/model-optimizer/extensions/front/caffe/MVNCaffeToMVN_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/MVNCaffeToMVN_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.caffe.MVNCaffeToMVN import MVNCaffeToMVN from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, const, connect_front +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front nodes = { **regular_op_with_empty_data('input', {'type': 'Parameter'}), diff --git a/model-optimizer/unit_tests/extensions/front/caffe/__init__.py b/model-optimizer/unit_tests/extensions/front/caffe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/caffe/accum_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/accum_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/accum_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/accum_ext_test.py index 6c5477cd585..603a1449f07 100644 --- a/model-optimizer/extensions/front/caffe/accum_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/accum_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.accum_ext import AccumFrontExtractor from extensions.ops.accum import AccumOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeAccumProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/argmax_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/argmax_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/argmax_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/argmax_ext_test.py index 0f55d526e2b..e48572d84e4 100644 --- a/model-optimizer/extensions/front/caffe/argmax_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/argmax_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.argmax_ext import ArgMaxFrontExtractor from extensions.ops.argmax import ArgMaxOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeArgMaxProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/axpy_test.py b/model-optimizer/unit_tests/extensions/front/caffe/axpy_test.py similarity index 95% rename from model-optimizer/extensions/front/caffe/axpy_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/axpy_test.py index e1ca7df5fbc..2225890c45d 100644 --- a/model-optimizer/extensions/front/caffe/axpy_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/axpy_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.caffe.axpy import AxpyToSSandAdd from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs class TestAxpyReplacer(unittest.TestCase): diff --git a/model-optimizer/extensions/front/caffe/bn_test.py b/model-optimizer/unit_tests/extensions/front/caffe/bn_test.py similarity index 94% rename from model-optimizer/extensions/front/caffe/bn_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/bn_test.py index 6ea6ed0f0ff..398e384d128 100644 --- a/model-optimizer/extensions/front/caffe/bn_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/bn_test.py @@ -7,8 +7,8 @@ import unittest from extensions.front.caffe.bn import BNToScaleShift from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.extractors import FakeParam -from mo.utils.unittest.graph import build_graph_with_edge_attrs, build_graph_with_attrs +from unit_tests.utils.extractors import FakeParam +from unit_tests.utils.graph import build_graph_with_edge_attrs, build_graph_with_attrs class FakeBNProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/conv_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/conv_ext_test.py similarity index 99% rename from model-optimizer/extensions/front/caffe/conv_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/conv_ext_test.py index eb1e368e8c7..d3680d0b586 100644 --- a/model-optimizer/extensions/front/caffe/conv_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/conv_ext_test.py @@ -9,7 +9,7 @@ import numpy as np from extensions.front.caffe.conv_ext import ConvFrontExtractor, DeconvFrontExtractor, conv_create_attrs, conv_set_params from mo.front.caffe.extractors.utils import get_list_from_container from mo.utils.error import Error -from mo.utils.unittest.extractors import PB, FakeParam, FakeMultiParam +from unit_tests.utils.extractors import PB, FakeParam, FakeMultiParam class FakeConvProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/correlation_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/correlation_ext_test.py similarity index 94% rename from model-optimizer/extensions/front/caffe/correlation_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/correlation_ext_test.py index d526dace338..577d9ba084a 100644 --- a/model-optimizer/extensions/front/caffe/correlation_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/correlation_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.correlation_ext import CorrelationFrontExtractor from extensions.ops.correlation import CorrelationOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeCorrProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/crop_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/crop_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/crop_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/crop_ext_test.py index 295ff6932f4..cc9407ab212 100644 --- a/model-optimizer/extensions/front/caffe/crop_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/crop_ext_test.py @@ -8,8 +8,8 @@ from extensions.front.caffe.crop_ext import CropFrontExtractor from mo.front.common.partial_infer.crop import crop_infer from mo.ops.crop import Crop from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeCropProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/ctcgreedydecoder_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/ctcgreedydecoder_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/ctcgreedydecoder_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/ctcgreedydecoder_ext_test.py index 46f1532ddd8..0434f040c03 100644 --- a/model-optimizer/extensions/front/caffe/ctcgreedydecoder_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/ctcgreedydecoder_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.ctcgreedydecoder_ext import CTCGreedyDecoderFrontExtractor from extensions.ops.ctc_greedy_decoder import CTCGreedyDecoderOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeCTCGreedyDecoderProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/data_augmentation_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/data_augmentation_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/caffe/data_augmentation_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/data_augmentation_ext_test.py index facf87ea3ad..0bbbf2cdb53 100644 --- a/model-optimizer/extensions/front/caffe/data_augmentation_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/data_augmentation_ext_test.py @@ -9,8 +9,8 @@ import numpy as np from extensions.front.caffe.data_augmentation_ext import DataAugmentationFrontExtractor from extensions.ops.data_augmentation import DataAugmentationOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeDAProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/elementwise_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/elementwise_ext_test.py similarity index 87% rename from model-optimizer/extensions/front/caffe/elementwise_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/elementwise_ext_test.py index 59b83363ed1..d8914f0a4da 100644 --- a/model-optimizer/extensions/front/caffe/elementwise_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/elementwise_ext_test.py @@ -5,8 +5,8 @@ import unittest from unittest.mock import patch from extensions.front.caffe.elementwise_ext import BiasToAdd -from mo.utils.unittest.extractors import FakeModelLayer, FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeModelLayer, FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeBiasProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/eltwise_add_normalize_test.py b/model-optimizer/unit_tests/extensions/front/caffe/eltwise_add_normalize_test.py similarity index 99% rename from model-optimizer/extensions/front/caffe/eltwise_add_normalize_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/eltwise_add_normalize_test.py index d347693fec3..a570c6b26b8 100644 --- a/model-optimizer/extensions/front/caffe/eltwise_add_normalize_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/eltwise_add_normalize_test.py @@ -7,8 +7,8 @@ import numpy as np from extensions.front.caffe.eltwise_add_normalize import EltwiseAddNormalize from mo.front.common.partial_infer.utils import int64_array -from mo.middle.passes.eliminate_test import build_graph from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph input_shape = int64_array([1, 4, 10]) const_1_value = np.array([2.0]) diff --git a/model-optimizer/extensions/front/caffe/elu_test.py b/model-optimizer/unit_tests/extensions/front/caffe/elu_test.py similarity index 89% rename from model-optimizer/extensions/front/caffe/elu_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/elu_test.py index b5cebf6cc97..c2077ad87a6 100644 --- a/model-optimizer/extensions/front/caffe/elu_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/elu_test.py @@ -5,8 +5,8 @@ import unittest from unittest.mock import patch from extensions.front.caffe.elu import ELUFrontExtractor -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/grn_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/grn_ext_test.py similarity index 92% rename from model-optimizer/extensions/front/caffe/grn_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/grn_ext_test.py index dc8f1d6d99f..7d62f8029db 100644 --- a/model-optimizer/extensions/front/caffe/grn_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/grn_ext_test.py @@ -8,8 +8,8 @@ from extensions.front.caffe.grn_ext import GRNFrontExtractor from extensions.ops.grn import GRNOp from mo.front.common.partial_infer.elemental import copy_shape_infer from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeGRNProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/normalize_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/normalize_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/normalize_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/normalize_ext_test.py index be2041cc03e..8383e79f83e 100644 --- a/model-optimizer/extensions/front/caffe/normalize_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/normalize_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.normalize_ext import NormalizeFrontExtractor from extensions.ops.normalize import NormalizeOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeNormalizeProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/pooling_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/pooling_ext_test.py similarity index 98% rename from model-optimizer/extensions/front/caffe/pooling_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/pooling_ext_test.py index 2fff102e876..7787b66fb12 100644 --- a/model-optimizer/extensions/front/caffe/pooling_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/pooling_ext_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.caffe.pooling_ext import PoolingFrontExtractor from mo.front.common.extractors.utils import layout_attrs from mo.ops.pooling import Pooling -from mo.utils.unittest.extractors import PB, FakeMultiParam +from unit_tests.utils.extractors import PB, FakeMultiParam class FakeProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/power_file_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/power_file_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/power_file_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/power_file_ext_test.py index 7984735f6ea..1aebaebc020 100644 --- a/model-optimizer/extensions/front/caffe/power_file_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/power_file_ext_test.py @@ -8,8 +8,8 @@ from extensions.front.caffe.power_file_ext import PowerFileFrontExtractor from extensions.ops.power_file import PowerFileOp from mo.front.common.partial_infer.elemental import copy_shape_infer from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakePowerFileProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/prelu_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/prelu_ext_test.py similarity index 92% rename from model-optimizer/extensions/front/caffe/prelu_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/prelu_ext_test.py index 3aacb165d03..00733445044 100644 --- a/model-optimizer/extensions/front/caffe/prelu_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/prelu_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.prelu_ext import PreluFrontExtractor from extensions.ops.prelu import PReLU from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakePReLUProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/priorbox_clustered_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/priorbox_clustered_ext_test.py similarity index 95% rename from model-optimizer/extensions/front/caffe/priorbox_clustered_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/priorbox_clustered_ext_test.py index a5081500389..269183402d6 100644 --- a/model-optimizer/extensions/front/caffe/priorbox_clustered_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/priorbox_clustered_ext_test.py @@ -9,8 +9,8 @@ import numpy as np from extensions.front.caffe.priorbox_clustered_ext import PriorBoxClusteredFrontExtractor from extensions.ops.priorbox_clustered import PriorBoxClusteredOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakePriorBoxClusteredProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/priorbox_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/priorbox_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/caffe/priorbox_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/priorbox_ext_test.py index a3a12b680d9..5754aa084bb 100644 --- a/model-optimizer/extensions/front/caffe/priorbox_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/priorbox_ext_test.py @@ -9,8 +9,8 @@ import numpy as np from extensions.front.caffe.priorbox_ext import PriorBoxFrontExtractor from extensions.ops.priorbox import PriorBoxOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam, FakeParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam, FakeParam +from unit_tests.utils.graph import FakeNode class FakeMultiParamListFields(FakeMultiParam): diff --git a/model-optimizer/extensions/front/caffe/proposal_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/proposal_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/caffe/proposal_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/proposal_ext_test.py index 8a5ea3285f6..f80215562fd 100644 --- a/model-optimizer/extensions/front/caffe/proposal_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/proposal_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.proposal_ext import ProposalFrontExtractor from extensions.ops.proposal import ProposalOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode, FakeAttr +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeProposalProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/proposal_python_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/proposal_python_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/caffe/proposal_python_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/proposal_python_ext_test.py index fb496bd7f75..aae2203b009 100644 --- a/model-optimizer/extensions/front/caffe/proposal_python_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/proposal_python_ext_test.py @@ -6,8 +6,8 @@ import unittest from extensions.front.caffe.proposal_python_ext import ProposalPythonFrontExtractor from extensions.ops.proposal import ProposalOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode, FakeAttr +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeProposalPythonProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/regionyolo_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/regionyolo_ext_test.py similarity index 94% rename from model-optimizer/extensions/front/caffe/regionyolo_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/regionyolo_ext_test.py index 6400b70055f..226747e6135 100644 --- a/model-optimizer/extensions/front/caffe/regionyolo_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/regionyolo_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.regionyolo_ext import RegionYoloFrontExtractor from extensions.ops.regionyolo import RegionYoloOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeRegionYoloProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/reorgyolo_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/reorgyolo_ext_test.py similarity index 92% rename from model-optimizer/extensions/front/caffe/reorgyolo_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/reorgyolo_ext_test.py index 2f3cfde2627..b466dd55f27 100644 --- a/model-optimizer/extensions/front/caffe/reorgyolo_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/reorgyolo_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.reorgyolo_ext import ReorgYoloFrontExtractor from extensions.ops.reorgyolo import ReorgYoloOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeReorgYoloProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/simplernms_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/simplernms_ext_test.py similarity index 94% rename from model-optimizer/extensions/front/caffe/simplernms_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/simplernms_ext_test.py index af7420d4c5f..e716ee5fa7e 100644 --- a/model-optimizer/extensions/front/caffe/simplernms_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/simplernms_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.simplernms_ext import SimplerNMSFrontExtractor from extensions.ops.simplernms import SimplerNMSOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeSimplerNMSProtoLayer: diff --git a/model-optimizer/extensions/front/caffe/spatial_transformer_ext_test.py b/model-optimizer/unit_tests/extensions/front/caffe/spatial_transformer_ext_test.py similarity index 95% rename from model-optimizer/extensions/front/caffe/spatial_transformer_ext_test.py rename to model-optimizer/unit_tests/extensions/front/caffe/spatial_transformer_ext_test.py index 059903cbd1f..4e90bb317d6 100644 --- a/model-optimizer/extensions/front/caffe/spatial_transformer_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/caffe/spatial_transformer_ext_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from extensions.front.caffe.spatial_transformer_ext import SpatialTransformFrontExtractor from extensions.ops.spatial_transformer import SpatialTransformOp from mo.ops.op import Op -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakeSpatialTransformProtoLayer: diff --git a/model-optimizer/extensions/front/div_test.py b/model-optimizer/unit_tests/extensions/front/div_test.py similarity index 96% rename from model-optimizer/extensions/front/div_test.py rename to model-optimizer/unit_tests/extensions/front/div_test.py index 9d32f1d2da7..f72d3e497e4 100644 --- a/model-optimizer/extensions/front/div_test.py +++ b/model-optimizer/unit_tests/extensions/front/div_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.div import Div from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ connect_data nodes = { diff --git a/model-optimizer/extensions/front/eltwise_n_test.py b/model-optimizer/unit_tests/extensions/front/eltwise_n_test.py similarity index 99% rename from model-optimizer/extensions/front/eltwise_n_test.py rename to model-optimizer/unit_tests/extensions/front/eltwise_n_test.py index 46705e2c8b4..9d2bc4af9f7 100644 --- a/model-optimizer/extensions/front/eltwise_n_test.py +++ b/model-optimizer/unit_tests/extensions/front/eltwise_n_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.eltwise_n import EltwiseNReplacement from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/freeze_placeholder_value_test.py b/model-optimizer/unit_tests/extensions/front/freeze_placeholder_value_test.py similarity index 98% rename from model-optimizer/extensions/front/freeze_placeholder_value_test.py rename to model-optimizer/unit_tests/extensions/front/freeze_placeholder_value_test.py index 421d566fa3e..2f236ca861c 100644 --- a/model-optimizer/extensions/front/freeze_placeholder_value_test.py +++ b/model-optimizer/unit_tests/extensions/front/freeze_placeholder_value_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from extensions.front.freeze_placeholder_value import FreezePlaceholderValue -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_bool = { '0': {'name': 'input1', 'kind': 'op', 'op': 'Parameter', 'data_type': bool, 'shape': np.array([])}, diff --git a/model-optimizer/extensions/front/image_scaler_test.py b/model-optimizer/unit_tests/extensions/front/image_scaler_test.py similarity index 99% rename from model-optimizer/extensions/front/image_scaler_test.py rename to model-optimizer/unit_tests/extensions/front/image_scaler_test.py index 521e2ccb1cf..9fb23144c79 100644 --- a/model-optimizer/extensions/front/image_scaler_test.py +++ b/model-optimizer/unit_tests/extensions/front/image_scaler_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.image_scaler import ImageScaler from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/instance_normalization_test.py b/model-optimizer/unit_tests/extensions/front/instance_normalization_test.py similarity index 98% rename from model-optimizer/extensions/front/instance_normalization_test.py rename to model-optimizer/unit_tests/extensions/front/instance_normalization_test.py index b8d0fdd30d5..189b3a37555 100644 --- a/model-optimizer/extensions/front/instance_normalization_test.py +++ b/model-optimizer/unit_tests/extensions/front/instance_normalization_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.instance_normalization import InstanceNormalization from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, diff --git a/model-optimizer/extensions/front/interpolate_reshape_test.py b/model-optimizer/unit_tests/extensions/front/interpolate_reshape_test.py similarity index 98% rename from model-optimizer/extensions/front/interpolate_reshape_test.py rename to model-optimizer/unit_tests/extensions/front/interpolate_reshape_test.py index 0fc090f8897..77fe1df6b77 100644 --- a/model-optimizer/extensions/front/interpolate_reshape_test.py +++ b/model-optimizer/unit_tests/extensions/front/interpolate_reshape_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.front.interpolate_reshape import InterpolateWithConcat from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ connect_data nodes = { diff --git a/model-optimizer/unit_tests/extensions/front/kaldi/__init__.py b/model-optimizer/unit_tests/extensions/front/kaldi/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/kaldi/add_permute_after_convolution_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/add_permute_after_convolution_test.py similarity index 98% rename from model-optimizer/extensions/front/kaldi/add_permute_after_convolution_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/add_permute_after_convolution_test.py index 28017a2509a..f883cbb4a23 100644 --- a/model-optimizer/extensions/front/kaldi/add_permute_after_convolution_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/add_permute_after_convolution_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.kaldi.add_permute_after_convolution import ReplaceConvolutionTranspose from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ReplaceConvolutionTransposeTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/kaldi/apply_counts_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/apply_counts_test.py similarity index 98% rename from model-optimizer/extensions/front/kaldi/apply_counts_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/apply_counts_test.py index 153d85d96cd..ae7274dcda0 100644 --- a/model-optimizer/extensions/front/kaldi/apply_counts_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/apply_counts_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.kaldi.apply_counts import apply_biases_to_last_layer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestKaldiPipeline(unittest.TestCase): diff --git a/model-optimizer/extensions/front/kaldi/memory_offset_adjustment_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/memory_offset_adjustment_test.py similarity index 99% rename from model-optimizer/extensions/front/kaldi/memory_offset_adjustment_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/memory_offset_adjustment_test.py index 85137a2c057..20039e209d8 100644 --- a/model-optimizer/extensions/front/kaldi/memory_offset_adjustment_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/memory_offset_adjustment_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.kaldi.memory_offset_adjustment import MemoryOffsetAdjustment from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class MemoruOffsetAdjustmentTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/kaldi/replace_lstm_nonlinearity_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/replace_lstm_nonlinearity_test.py similarity index 98% rename from model-optimizer/extensions/front/kaldi/replace_lstm_nonlinearity_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/replace_lstm_nonlinearity_test.py index 8b875b2f72c..73f25afd339 100644 --- a/model-optimizer/extensions/front/kaldi/replace_lstm_nonlinearity_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/replace_lstm_nonlinearity_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.kaldi.replace_lstm_nonlinearity import ReplaceLstmNonLinearityPattern from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ReplaceLstmNonlinearityTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/kaldi/sigmoid_ext_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/sigmoid_ext_test.py similarity index 87% rename from model-optimizer/extensions/front/kaldi/sigmoid_ext_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/sigmoid_ext_test.py index b4b003d0a08..d39b0d0d5db 100644 --- a/model-optimizer/extensions/front/kaldi/sigmoid_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/sigmoid_ext_test.py @@ -3,7 +3,7 @@ from extensions.front.kaldi.sigmoid_ext import SigmoidFrontExtractor from extensions.ops.activation_ops import Sigmoid -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.ops.op import Op diff --git a/model-optimizer/extensions/front/kaldi/tanh_ext_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/tanh_ext_test.py similarity index 87% rename from model-optimizer/extensions/front/kaldi/tanh_ext_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/tanh_ext_test.py index c75cf66c68b..9c42e5c36bd 100644 --- a/model-optimizer/extensions/front/kaldi/tanh_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/tanh_ext_test.py @@ -3,7 +3,7 @@ from extensions.front.kaldi.tanh_component_ext import TanhFrontExtractor from extensions.ops.activation_ops import Tanh -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.ops.op import Op diff --git a/model-optimizer/extensions/front/kaldi/tdnn_component_replacer_test.py b/model-optimizer/unit_tests/extensions/front/kaldi/tdnn_component_replacer_test.py similarity index 97% rename from model-optimizer/extensions/front/kaldi/tdnn_component_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/kaldi/tdnn_component_replacer_test.py index 17ef9cb9f2f..0233e862d31 100644 --- a/model-optimizer/extensions/front/kaldi/tdnn_component_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/kaldi/tdnn_component_replacer_test.py @@ -8,7 +8,7 @@ from generator import generator, generate from extensions.front.kaldi.tdnn_component_replacer import TdnnComponentReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op, result, connect_front, const +from unit_tests.utils.graph import build_graph, regular_op, result, connect_front, const @generator diff --git a/model-optimizer/extensions/front/mxnet/RNN_ext_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/RNN_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/RNN_ext_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/RNN_ext_test.py index d016a0a7e4b..a3d1bec6f4b 100644 --- a/model-optimizer/extensions/front/mxnet/RNN_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/RNN_ext_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.mxnet.RNN_ext import RNNFrontExtractor from mo.utils.error import Error -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class RNNFrontExtractorTest(unittest.TestCase): diff --git a/model-optimizer/unit_tests/extensions/front/mxnet/__init__.py b/model-optimizer/unit_tests/extensions/front/mxnet/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/mxnet/activation_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/activation_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/activation_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/activation_test.py index 50e53ebb371..945e4fa61ee 100644 --- a/model-optimizer/extensions/front/mxnet/activation_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/activation_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.activation import ActivationFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestActivationFrontExtractorOp(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py index aff09d11766..c2e3756b88a 100644 --- a/model-optimizer/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/add_input_data_to_prior_boxes_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.mxnet.add_input_data_to_prior_boxes import AddInputDataToPriorBoxes from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestMxnetPipeline(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/check_softmax_node_inputs_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/check_softmax_node_inputs_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/check_softmax_node_inputs_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/check_softmax_node_inputs_test.py index 859f4f65b02..20850a089b5 100644 --- a/model-optimizer/extensions/front/mxnet/check_softmax_node_inputs_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/check_softmax_node_inputs_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.check_softmax_node_inputs import CheckSoftmaxNodeInputs from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestCheckSoftmaxNodeInputs(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/conv_ext_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/conv_ext_test.py similarity index 99% rename from model-optimizer/extensions/front/mxnet/conv_ext_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/conv_ext_test.py index afc5402dd7b..792964eceea 100644 --- a/model-optimizer/extensions/front/mxnet/conv_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/conv_ext_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from extensions.front.mxnet.conv_ext import DeconvFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestDeconvShapesParsing(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/crop_ext_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/crop_ext_test.py similarity index 94% rename from model-optimizer/extensions/front/mxnet/crop_ext_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/crop_ext_test.py index d9a23ee539a..725120444ff 100644 --- a/model-optimizer/extensions/front/mxnet/crop_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/crop_ext_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.crop_ext import CropFrontExtractor from mo.ops.crop import Crop -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestCropExt(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/custom_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/custom_test.py similarity index 96% rename from model-optimizer/extensions/front/mxnet/custom_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/custom_test.py index e0493f4eb74..d52d0154d62 100644 --- a/model-optimizer/extensions/front/mxnet/custom_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/custom_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.mxnet.custom import CustomFrontExtractorOp from mo.front.extractor import FrontExtractorOp, MXNetCustomFrontExtractorOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph attrs = {'test_attr': 1} diff --git a/model-optimizer/extensions/front/mxnet/gather_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/gather_test.py similarity index 98% rename from model-optimizer/extensions/front/mxnet/gather_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/gather_test.py index 49edba0c53a..f53f08fc1c5 100644 --- a/model-optimizer/extensions/front/mxnet/gather_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/gather_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.mxnet.gather import GatherFrontReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class GatherTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/gluoncv_ssd_anchors_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/gluoncv_ssd_anchors_test.py similarity index 99% rename from model-optimizer/extensions/front/mxnet/gluoncv_ssd_anchors_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/gluoncv_ssd_anchors_test.py index 0a839f37aa6..71c4dbb82c3 100644 --- a/model-optimizer/extensions/front/mxnet/gluoncv_ssd_anchors_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/gluoncv_ssd_anchors_test.py @@ -7,7 +7,7 @@ import unittest from extensions.front.mxnet.gluoncv_ssd_anchors import SsdAnchorsReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'slice_like': {'kind': 'op', 'op': 'slice_like'}, diff --git a/model-optimizer/extensions/front/mxnet/leaky_relu_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/leaky_relu_test.py similarity index 98% rename from model-optimizer/extensions/front/mxnet/leaky_relu_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/leaky_relu_test.py index 8bcba1cd3a7..37895fe0835 100644 --- a/model-optimizer/extensions/front/mxnet/leaky_relu_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/leaky_relu_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.mxnet.leaky_relu import LeakyReLUFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestLeakyReLUFrontExtractorOp(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/multibox_detection_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/multibox_detection_test.py similarity index 98% rename from model-optimizer/extensions/front/mxnet/multibox_detection_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/multibox_detection_test.py index e34fa088287..83a5ec0f7da 100644 --- a/model-optimizer/extensions/front/mxnet/multibox_detection_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/multibox_detection_test.py @@ -4,7 +4,7 @@ import unittest from extensions.front.mxnet.multibox_detection_ext import MultiBoxDetectionOutputExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestMultiBoxDetection_Parsing(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/mx_reshape_reverse_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_reverse_test.py similarity index 99% rename from model-optimizer/extensions/front/mxnet/mx_reshape_reverse_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_reverse_test.py index deaf30ffa90..11bf62bcc8d 100644 --- a/model-optimizer/extensions/front/mxnet/mx_reshape_reverse_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_reverse_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.mx_reshape_reverse import MXReshapeReverse from mo.front.common.partial_infer.utils import int64_array -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestMXReshapeReverseTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/mx_reshape_to_reshape_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_to_reshape_test.py similarity index 98% rename from model-optimizer/extensions/front/mxnet/mx_reshape_to_reshape_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_to_reshape_test.py index 74c618655fc..50c6a315bfe 100644 --- a/model-optimizer/extensions/front/mxnet/mx_reshape_to_reshape_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/mx_reshape_to_reshape_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.mx_reshape_to_reshape import MXReshapeToReshape from mo.front.common.partial_infer.utils import int64_array -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestMXReshapeToReshape(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/pooling_ext_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/pooling_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/mxnet/pooling_ext_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/pooling_ext_test.py index 14be1089582..4759b5a1680 100644 --- a/model-optimizer/extensions/front/mxnet/pooling_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/pooling_ext_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from extensions.front.mxnet.pooling_ext import PoolingFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestPoolingShapesParsing(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/sigmoid_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/sigmoid_test.py similarity index 95% rename from model-optimizer/extensions/front/mxnet/sigmoid_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/sigmoid_test.py index 9fc9a30c7e4..34d078a4e76 100644 --- a/model-optimizer/extensions/front/mxnet/sigmoid_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/sigmoid_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.sigmoid import SigmoidFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSigmoidFrontExtractorOp(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py index a5585382bd8..a86d4a6fa95 100644 --- a/model-optimizer/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_flatten_softmax_activation_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.ssd_pattern_flatten_softmax_activation import SsdPatternFlattenSoftmaxActivation from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSsdPatternFlattenSoftmaxActivation(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py similarity index 96% rename from model-optimizer/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py index a27da1cc877..1e19c5c20ad 100644 --- a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_flatten_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.ssd_pattern_remove_flatten import SsdPatternRemoveFlatten from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSsdPatternRemoveFlatten(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py similarity index 98% rename from model-optimizer/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py index e8c66412aba..d3c8ec623a6 100644 --- a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_reshape_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.ssd_pattern_remove_reshape import SsdPatternRemoveReshape from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSsdPatternRemoveReshape(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py index 4ec408f77a5..81c5b3ff900 100644 --- a/model-optimizer/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_pattern_remove_transpose_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.mxnet.ssd_pattern_remove_transpose import SsdPatternRemoveTranspose from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSsdPatternRemoveTranspose(unittest.TestCase): diff --git a/model-optimizer/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py similarity index 97% rename from model-optimizer/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py rename to model-optimizer/unit_tests/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py index d3f37e138fc..0a51c344f16 100644 --- a/model-optimizer/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py +++ b/model-optimizer/unit_tests/extensions/front/mxnet/ssd_reorder_detection_out_inputs_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.mxnet.ssd_reorder_detection_out_inputs import SsdReorderDetectionOutInputs from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSsdReorderDetectionOutInputs(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/AttributedSliceToSlice_test.py b/model-optimizer/unit_tests/extensions/front/onnx/AttributedSliceToSlice_test.py similarity index 94% rename from model-optimizer/extensions/front/onnx/AttributedSliceToSlice_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/AttributedSliceToSlice_test.py index 9420dc384c1..b7c5239f0e5 100644 --- a/model-optimizer/extensions/front/onnx/AttributedSliceToSlice_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/AttributedSliceToSlice_test.py @@ -8,7 +8,7 @@ from generator import generator, generate from extensions.front.onnx.AttributedSliceToSlice import AttributedSliceToSliceReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, const, connect_front +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front @generator diff --git a/model-optimizer/extensions/front/onnx/MvnOnnxToMvn_test.py b/model-optimizer/unit_tests/extensions/front/onnx/MvnOnnxToMvn_test.py similarity index 92% rename from model-optimizer/extensions/front/onnx/MvnOnnxToMvn_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/MvnOnnxToMvn_test.py index 70f722e5210..77a798f1bf9 100644 --- a/model-optimizer/extensions/front/onnx/MvnOnnxToMvn_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/MvnOnnxToMvn_test.py @@ -3,12 +3,10 @@ import unittest -import numpy as np - from extensions.front.onnx.MvnOnnxToMvn import MvnOnnxToMvn from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, const, connect_front +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front nodes = { **regular_op_with_empty_data('input', {'type': 'Parameter'}), diff --git a/model-optimizer/unit_tests/extensions/front/onnx/__init__.py b/model-optimizer/unit_tests/extensions/front/onnx/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/onnx/activation_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/activation_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/onnx/activation_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/activation_ext_test.py index 58e9e3a7499..a2e5f07db80 100644 --- a/model-optimizer/extensions/front/onnx/activation_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/activation_ext_test.py @@ -11,8 +11,8 @@ import extensions.front.onnx.activation_ext as extractors from extensions.ops.activation_ops import Elu from mo.graph.graph import Node from mo.ops.op import Op -from mo.utils.unittest.extractors import PB -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.extractors import PB +from unit_tests.utils.graph import build_graph @generator diff --git a/model-optimizer/extensions/front/onnx/affine_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/affine_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/affine_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/affine_ext_test.py index 705a3e81c59..1f362f46750 100644 --- a/model-optimizer/extensions/front/onnx/affine_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/affine_ext_test.py @@ -8,7 +8,7 @@ import onnx from extensions.front.onnx.affine_ext import AffineFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class AffineONNXExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/conv_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/conv_ext_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/conv_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/conv_ext_test.py index 27f5c2460ea..f5b6ab0622e 100644 --- a/model-optimizer/extensions/front/onnx/conv_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/conv_ext_test.py @@ -9,7 +9,7 @@ import onnx from extensions.front.onnx.conv_ext import ConvTransposeFrontExtractor from mo.graph.graph import Node from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ConvTransposeONNXExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/crop_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/crop_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/crop_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/crop_ext_test.py index e1d8e7ed080..b194e98f7e9 100644 --- a/model-optimizer/extensions/front/onnx/crop_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/crop_ext_test.py @@ -8,7 +8,7 @@ import onnx from extensions.front.onnx.crop_ext import CropFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class CropONNXExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/dequantize_linear_resolver_test.py b/model-optimizer/unit_tests/extensions/front/onnx/dequantize_linear_resolver_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/dequantize_linear_resolver_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/dequantize_linear_resolver_test.py index 63ca7bde34b..c305ec57ca3 100644 --- a/model-optimizer/extensions/front/onnx/dequantize_linear_resolver_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/dequantize_linear_resolver_test.py @@ -2,13 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 import unittest -from argparse import Namespace import numpy as np from extensions.front.onnx.dequantize_linear_resolver import DequantizeLinearResolver from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, diff --git a/model-optimizer/extensions/front/onnx/detection_output_test.py b/model-optimizer/unit_tests/extensions/front/onnx/detection_output_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/detection_output_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/detection_output_test.py index 4dae8079528..2a0fe9116d3 100644 --- a/model-optimizer/extensions/front/onnx/detection_output_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/detection_output_test.py @@ -9,7 +9,7 @@ import onnx from extensions.front.onnx.detection_output import DetectionOutputFrontExtractor from extensions.ops.DetectionOutput import DetectionOutput from mo.ops.op import Op -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestDetectionOutputExt(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/gru_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/gru_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/gru_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/gru_ext_test.py index e00cdc76d05..0506ed44a21 100644 --- a/model-optimizer/extensions/front/onnx/gru_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/gru_ext_test.py @@ -7,7 +7,7 @@ import numpy as np import onnx from extensions.front.onnx.gru_ext import GRUFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class GRUExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/image_scaler_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/image_scaler_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/onnx/image_scaler_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/image_scaler_ext_test.py index 710929a610d..773d4f6ffff 100644 --- a/model-optimizer/extensions/front/onnx/image_scaler_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/image_scaler_ext_test.py @@ -7,7 +7,7 @@ import numpy as np import onnx from extensions.front.onnx.image_scaler_ext import ImageScalerFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestImageScalerONNXExt(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/instance_normalization_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/instance_normalization_ext_test.py similarity index 91% rename from model-optimizer/extensions/front/onnx/instance_normalization_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/instance_normalization_ext_test.py index 9881ba39731..86ebbb3e763 100644 --- a/model-optimizer/extensions/front/onnx/instance_normalization_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/instance_normalization_ext_test.py @@ -4,7 +4,7 @@ import onnx from extensions.front.onnx.instance_normalization_ext import InstanceNormalizationExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class TestInstanceNormalization(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/onnx/lstm_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/lstm_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/lstm_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/lstm_ext_test.py index 60c8568b6d9..12940a22168 100644 --- a/model-optimizer/extensions/front/onnx/lstm_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/lstm_ext_test.py @@ -7,7 +7,7 @@ import numpy as np import onnx from extensions.front.onnx.lstm_ext import LSTMFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class LSTMExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/normalize_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/normalize_ext_test.py similarity index 93% rename from model-optimizer/extensions/front/onnx/normalize_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/normalize_ext_test.py index 0324b49e9d6..ffc13a3975e 100644 --- a/model-optimizer/extensions/front/onnx/normalize_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/normalize_ext_test.py @@ -4,7 +4,7 @@ import onnx from extensions.front.onnx.normalize_ext import NormalizeFrontExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class TestNormalize(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/onnx/pad_converter_test.py b/model-optimizer/unit_tests/extensions/front/onnx/pad_converter_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/pad_converter_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/pad_converter_test.py index a43ec3681de..18330784909 100644 --- a/model-optimizer/extensions/front/onnx/pad_converter_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/pad_converter_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.onnx.pad_converter import ONNXPadToPad from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'placeholder': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/onnx/pad_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/pad_ext_test.py similarity index 95% rename from model-optimizer/extensions/front/onnx/pad_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/pad_ext_test.py index c67e831bdd4..c56d09bf175 100644 --- a/model-optimizer/extensions/front/onnx/pad_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/pad_ext_test.py @@ -1,13 +1,11 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from argparse import Namespace - import onnx from extensions.front.onnx.pad_ext import PadFrontExtractor from mo.graph.graph import Graph -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class TestPad(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/onnx/priorbox_clustered_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/priorbox_clustered_ext_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/priorbox_clustered_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/priorbox_clustered_ext_test.py index 06f3ae8ea00..bd40d1eac35 100644 --- a/model-optimizer/extensions/front/onnx/priorbox_clustered_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/priorbox_clustered_ext_test.py @@ -9,7 +9,7 @@ import onnx from extensions.front.onnx.priorbox_clustered_ext import PriorBoxClusteredFrontExtractor from extensions.ops.priorbox_clustered import PriorBoxClusteredOp from mo.ops.op import Op -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestPriorBoxClusteredExt(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/priorbox_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/priorbox_ext_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/priorbox_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/priorbox_ext_test.py index f5e2be7061c..2971defd3c9 100644 --- a/model-optimizer/extensions/front/onnx/priorbox_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/priorbox_ext_test.py @@ -9,7 +9,7 @@ import onnx from extensions.front.onnx.priorbox_ext import PriorBoxFrontExtractor from extensions.ops.priorbox import PriorBoxOp from mo.ops.op import Op -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class TestPriorBoxExt(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/quantize_dequantize_linear_test.py b/model-optimizer/unit_tests/extensions/front/onnx/quantize_dequantize_linear_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/quantize_dequantize_linear_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/quantize_dequantize_linear_test.py index c97f6722be4..3d07eb06236 100644 --- a/model-optimizer/extensions/front/onnx/quantize_dequantize_linear_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/quantize_dequantize_linear_test.py @@ -2,13 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 import unittest -from argparse import Namespace import numpy as np from extensions.front.onnx.quantize_dequantize_linear import QuantizeDequantizeLinear from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # quantize and dequantize share tensors with scale/zp nodes0_attributes = { diff --git a/model-optimizer/extensions/front/onnx/quantize_linear_resolver_test.py b/model-optimizer/unit_tests/extensions/front/onnx/quantize_linear_resolver_test.py similarity index 98% rename from model-optimizer/extensions/front/onnx/quantize_linear_resolver_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/quantize_linear_resolver_test.py index e90d6c71442..2209f87e0d4 100644 --- a/model-optimizer/extensions/front/onnx/quantize_linear_resolver_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/quantize_linear_resolver_test.py @@ -2,13 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 import unittest -from argparse import Namespace import numpy as np from extensions.front.onnx.quantize_linear_resolver import QuantizeLinearResolver from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, diff --git a/model-optimizer/extensions/front/onnx/rnn_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/rnn_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/rnn_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/rnn_ext_test.py index 36d031e21d7..3b506c15387 100644 --- a/model-optimizer/extensions/front/onnx/rnn_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/rnn_ext_test.py @@ -7,7 +7,7 @@ import numpy as np import onnx from extensions.front.onnx.rnn_ext import RNNFrontExtractor -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class RNNExtractorTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/onnx/squeeze_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/squeeze_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/squeeze_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/squeeze_ext_test.py index ee943eba26b..68b84f55cc0 100644 --- a/model-optimizer/extensions/front/onnx/squeeze_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/squeeze_ext_test.py @@ -10,7 +10,7 @@ from generator import generator, generate from extensions.front.onnx.squeeze_ext import SqueezeFrontExtractor from mo.ops.op import Op from mo.ops.squeeze import Squeeze -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB @generator diff --git a/model-optimizer/extensions/front/onnx/transpose_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/transpose_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/onnx/transpose_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/transpose_ext_test.py index cb4e8075af6..39b01288c9a 100644 --- a/model-optimizer/extensions/front/onnx/transpose_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/transpose_ext_test.py @@ -11,7 +11,7 @@ from generator import generator, generate from extensions.front.onnx.transpose_ext import TransposeFrontExtractor from extensions.ops.transpose import Transpose from mo.ops.op import Op -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB @generator diff --git a/model-optimizer/extensions/front/onnx/unsqueeze_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/unsqueeze_ext_test.py similarity index 96% rename from model-optimizer/extensions/front/onnx/unsqueeze_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/unsqueeze_ext_test.py index f631aa8351d..d98e3fcc7a4 100644 --- a/model-optimizer/extensions/front/onnx/unsqueeze_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/unsqueeze_ext_test.py @@ -10,7 +10,7 @@ from generator import generator, generate from extensions.front.onnx.unsqueeze_ext import UnsqueezeFrontExtractor from mo.ops.op import Op from mo.ops.unsqueeze import Unsqueeze -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB @generator diff --git a/model-optimizer/extensions/front/onnx/upsample_ext_test.py b/model-optimizer/unit_tests/extensions/front/onnx/upsample_ext_test.py similarity index 95% rename from model-optimizer/extensions/front/onnx/upsample_ext_test.py rename to model-optimizer/unit_tests/extensions/front/onnx/upsample_ext_test.py index bb1684b8192..e048780b05b 100644 --- a/model-optimizer/extensions/front/onnx/upsample_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/onnx/upsample_ext_test.py @@ -6,8 +6,8 @@ import onnx from extensions.front.onnx.upsample_ext import UpsampleFrontExtractor from mo.graph.graph import Node from mo.utils.error import Error -from mo.utils.unittest.extractors import BaseExtractorsTestingClass -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.extractors import BaseExtractorsTestingClass +from unit_tests.utils.graph import build_graph class UpsampleONNXExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/output_cut_test.py b/model-optimizer/unit_tests/extensions/front/output_cut_test.py similarity index 98% rename from model-optimizer/extensions/front/output_cut_test.py rename to model-optimizer/unit_tests/extensions/front/output_cut_test.py index 8d662250176..ff660917206 100644 --- a/model-optimizer/extensions/front/output_cut_test.py +++ b/model-optimizer/unit_tests/extensions/front/output_cut_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.output_cut import OutputCut from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op +from unit_tests.utils.graph import build_graph, regular_op nodes = { **regular_op('Parameter1', {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}), diff --git a/model-optimizer/extensions/front/rank_decomposer_test.py b/model-optimizer/unit_tests/extensions/front/rank_decomposer_test.py similarity index 95% rename from model-optimizer/extensions/front/rank_decomposer_test.py rename to model-optimizer/unit_tests/extensions/front/rank_decomposer_test.py index d6fea7f3476..99d86464eb3 100644 --- a/model-optimizer/extensions/front/rank_decomposer_test.py +++ b/model-optimizer/unit_tests/extensions/front/rank_decomposer_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.front.rank_decomposer import RankDecomposer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, connect, \ +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, \ valued_const_with_data nodes = lambda output_type: { diff --git a/model-optimizer/extensions/front/reciprocal_test.py b/model-optimizer/unit_tests/extensions/front/reciprocal_test.py similarity index 98% rename from model-optimizer/extensions/front/reciprocal_test.py rename to model-optimizer/unit_tests/extensions/front/reciprocal_test.py index 738c47404ae..dd2f09a09ae 100644 --- a/model-optimizer/extensions/front/reciprocal_test.py +++ b/model-optimizer/unit_tests/extensions/front/reciprocal_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.reciprocal import ReciprocalReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/reduce_axis_normalizer_test.py b/model-optimizer/unit_tests/extensions/front/reduce_axis_normalizer_test.py similarity index 96% rename from model-optimizer/extensions/front/reduce_axis_normalizer_test.py rename to model-optimizer/unit_tests/extensions/front/reduce_axis_normalizer_test.py index d459f52e648..11800d84ac8 100644 --- a/model-optimizer/extensions/front/reduce_axis_normalizer_test.py +++ b/model-optimizer/unit_tests/extensions/front/reduce_axis_normalizer_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.reduce_axis_normalizer import ReduceAxisNormalizer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, connect_front, regular_op +from unit_tests.utils.graph import build_graph, result, connect_front, regular_op nodes = { **regular_op('parameter', {'type': 'Parameter'}), diff --git a/model-optimizer/extensions/front/scatter_normalizer_test.py b/model-optimizer/unit_tests/extensions/front/scatter_normalizer_test.py similarity index 97% rename from model-optimizer/extensions/front/scatter_normalizer_test.py rename to model-optimizer/unit_tests/extensions/front/scatter_normalizer_test.py index 0c873d7eca6..db05730e359 100644 --- a/model-optimizer/extensions/front/scatter_normalizer_test.py +++ b/model-optimizer/unit_tests/extensions/front/scatter_normalizer_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.scatter_normalizer import ScatterNormalizer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, connect, \ +from unit_tests.utils.graph import build_graph, result, connect, \ regular_op_with_empty_data nodes = { diff --git a/model-optimizer/extensions/front/softsign_replacer_test.py b/model-optimizer/unit_tests/extensions/front/softsign_replacer_test.py similarity index 97% rename from model-optimizer/extensions/front/softsign_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/softsign_replacer_test.py index 60f9e701f99..82cc52d3e81 100644 --- a/model-optimizer/extensions/front/softsign_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/softsign_replacer_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.softsign_replacer import SoftSign from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter', 'shape': np.array([1, 227, 227, 3])}, diff --git a/model-optimizer/extensions/front/split_normalizer_test.py b/model-optimizer/unit_tests/extensions/front/split_normalizer_test.py similarity index 98% rename from model-optimizer/extensions/front/split_normalizer_test.py rename to model-optimizer/unit_tests/extensions/front/split_normalizer_test.py index 0c4e96a2de6..1bc841f8bb2 100644 --- a/model-optimizer/extensions/front/split_normalizer_test.py +++ b/model-optimizer/unit_tests/extensions/front/split_normalizer_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.split_normalizer import SqueezeAxis from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'placeholder': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/sub_test.py b/model-optimizer/unit_tests/extensions/front/sub_test.py similarity index 95% rename from model-optimizer/extensions/front/sub_test.py rename to model-optimizer/unit_tests/extensions/front/sub_test.py index 1cc1956e975..3c3e50ee8dd 100644 --- a/model-optimizer/extensions/front/sub_test.py +++ b/model-optimizer/unit_tests/extensions/front/sub_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.sub import Sub from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, valued_const_with_data, connect, \ connect_data nodes = { diff --git a/model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement_test.py b/model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement_test.py rename to model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py index 1b5c6895974..c4d1d467df4 100644 --- a/model-optimizer/extensions/front/tf/CTCGreedyDecoderReplacement_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/CTCGreedyDecoderReplacement_test.py @@ -3,12 +3,10 @@ import unittest -import numpy as np - from extensions.front.tf.CTCGreedyDecoderReplacement import CTCGreedyDecoderReplacement, CTCGreedyDecoderWithSparseToDenseShapeReplacement from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const class CTCGreedyDecoderReplacementTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/CTCLossReplacement_test.py b/model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py similarity index 99% rename from model-optimizer/extensions/front/tf/CTCLossReplacement_test.py rename to model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py index 25aabc9b927..f173ec15c17 100644 --- a/model-optimizer/extensions/front/tf/CTCLossReplacement_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/CTCLossReplacement_test.py @@ -8,7 +8,7 @@ from argparse import Namespace from extensions.front.tf.CTCLossReplacement import CTCLossReplacement from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const class CTCLossFrontReplacementTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py b/model-optimizer/unit_tests/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py similarity index 99% rename from model-optimizer/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py rename to model-optimizer/unit_tests/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py index 6e6709f213b..457fa6c7fd8 100644 --- a/model-optimizer/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/NonConstBeginStridedSliceReplacement_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.tf.NonConstBeginStridedSliceReplacement import NonConstBeginStridedSliceReplacement from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const class NonConstBeginStridedSliceReplacementTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/ObjectDetectionAPI_test.py b/model-optimizer/unit_tests/extensions/front/tf/ObjectDetectionAPI_test.py similarity index 99% rename from model-optimizer/extensions/front/tf/ObjectDetectionAPI_test.py rename to model-optimizer/unit_tests/extensions/front/tf/ObjectDetectionAPI_test.py index 20d7a1c2d42..338f77b8c3c 100644 --- a/model-optimizer/extensions/front/tf/ObjectDetectionAPI_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/ObjectDetectionAPI_test.py @@ -14,7 +14,7 @@ from mo.graph.graph import Graph from mo.utils.custom_replacement_config import CustomReplacementDescriptor from mo.utils.error import Error from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import const, regular_op, result, build_graph, connect_front +from unit_tests.utils.graph import const, regular_op, result, build_graph, connect_front class FakePipelineConfig: diff --git a/model-optimizer/extensions/front/tf/SwitchMergeOptimization_test.py b/model-optimizer/unit_tests/extensions/front/tf/SwitchMergeOptimization_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/SwitchMergeOptimization_test.py rename to model-optimizer/unit_tests/extensions/front/tf/SwitchMergeOptimization_test.py index 7370e7bcbda..7c8f1d02e05 100644 --- a/model-optimizer/extensions/front/tf/SwitchMergeOptimization_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/SwitchMergeOptimization_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.tf.SwitchMergeOptimization import SwitchMergeOptimization from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class SwitchMergeOptimizationTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/TFSliceToSlice_test.py b/model-optimizer/unit_tests/extensions/front/tf/TFSliceToSlice_test.py similarity index 97% rename from model-optimizer/extensions/front/tf/TFSliceToSlice_test.py rename to model-optimizer/unit_tests/extensions/front/tf/TFSliceToSlice_test.py index a19fe319241..94204b0129f 100644 --- a/model-optimizer/extensions/front/tf/TFSliceToSlice_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/TFSliceToSlice_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.tf.TFSliceToSlice import TFSliceToSliceReplacer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, const, connect_front +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front nodes = { **regular_op_with_empty_data('input', {'type': 'Parameter'}), diff --git a/model-optimizer/extensions/front/tf/WhereDecomposition_test.py b/model-optimizer/unit_tests/extensions/front/tf/WhereDecomposition_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/WhereDecomposition_test.py rename to model-optimizer/unit_tests/extensions/front/tf/WhereDecomposition_test.py index e3ba84140cb..590727ec705 100644 --- a/model-optimizer/extensions/front/tf/WhereDecomposition_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/WhereDecomposition_test.py @@ -10,7 +10,7 @@ from generator import generator, generate from extensions.front.tf.WhereDecomposition import WhereDecomposition from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs = { diff --git a/model-optimizer/unit_tests/extensions/front/tf/__init__.py b/model-optimizer/unit_tests/extensions/front/tf/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/front/tf/concat_ext_test.py b/model-optimizer/unit_tests/extensions/front/tf/concat_ext_test.py similarity index 88% rename from model-optimizer/extensions/front/tf/concat_ext_test.py rename to model-optimizer/unit_tests/extensions/front/tf/concat_ext_test.py index bda6c35447b..405a8cd1866 100644 --- a/model-optimizer/extensions/front/tf/concat_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/concat_ext_test.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from extensions.front.tf.concat_ext import ConcatFrontExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class ConcatExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/tf/concat_test.py b/model-optimizer/unit_tests/extensions/front/tf/concat_test.py similarity index 94% rename from model-optimizer/extensions/front/tf/concat_test.py rename to model-optimizer/unit_tests/extensions/front/tf/concat_test.py index 41cee96ca71..822b1333f57 100644 --- a/model-optimizer/extensions/front/tf/concat_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/concat_test.py @@ -4,7 +4,7 @@ import unittest from extensions.front.tf.concat import Concat -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs class TestConcatEdgesReshuffler(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/conv_ext_test.py b/model-optimizer/unit_tests/extensions/front/tf/conv_ext_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/conv_ext_test.py rename to model-optimizer/unit_tests/extensions/front/tf/conv_ext_test.py index 230bef5dc67..aa880e27ff7 100644 --- a/model-optimizer/extensions/front/tf/conv_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/conv_ext_test.py @@ -4,7 +4,7 @@ import numpy as np from extensions.front.tf.conv_ext import Conv2DFrontExtractor, DepthwiseConv2dNativeFrontExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class ConvExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/tf/deconv_ext_test.py b/model-optimizer/unit_tests/extensions/front/tf/deconv_ext_test.py similarity index 97% rename from model-optimizer/extensions/front/tf/deconv_ext_test.py rename to model-optimizer/unit_tests/extensions/front/tf/deconv_ext_test.py index 8b97f0b3f97..8099bc7361e 100644 --- a/model-optimizer/extensions/front/tf/deconv_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/deconv_ext_test.py @@ -4,7 +4,7 @@ import numpy as np from extensions.front.tf.deconv_ext import Conv2DBackpropInputFrontExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class DeconvolutionExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/tf/embedding_segments_sum_test.py b/model-optimizer/unit_tests/extensions/front/tf/embedding_segments_sum_test.py similarity index 99% rename from model-optimizer/extensions/front/tf/embedding_segments_sum_test.py rename to model-optimizer/unit_tests/extensions/front/tf/embedding_segments_sum_test.py index 1b41e033dc2..8e02480942e 100644 --- a/model-optimizer/extensions/front/tf/embedding_segments_sum_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/embedding_segments_sum_test.py @@ -6,7 +6,7 @@ import unittest from extensions.front.tf.embedding_segments_sum import EmbeddingSegmentsSumFrontReplacer, EmbeddingSegmentsSumFrontReplacer2 from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const class EmbeddingSegmentsSumFrontReplacerFrontReplacersTest(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/fifo_replacer_test.py b/model-optimizer/unit_tests/extensions/front/tf/fifo_replacer_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/fifo_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/tf/fifo_replacer_test.py index d3b639f1541..23d4c9956da 100644 --- a/model-optimizer/extensions/front/tf/fifo_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/fifo_replacer_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from extensions.front.tf.fifo_replacer import FIFOQueue -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs class TestFIFOQueueReplacement(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/floor_div_test.py b/model-optimizer/unit_tests/extensions/front/tf/floor_div_test.py similarity index 97% rename from model-optimizer/extensions/front/tf/floor_div_test.py rename to model-optimizer/unit_tests/extensions/front/tf/floor_div_test.py index 57a48d4c194..49b8673ec3f 100644 --- a/model-optimizer/extensions/front/tf/floor_div_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/floor_div_test.py @@ -5,7 +5,7 @@ import unittest from extensions.front.tf.floor_div_decomposition import FloorDivDecomposition from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, connect, \ +from unit_tests.utils.graph import build_graph, result, connect, \ connect_data, regular_op_with_empty_data nodes = { diff --git a/model-optimizer/extensions/front/tf/identityN_to_identity_test.py b/model-optimizer/unit_tests/extensions/front/tf/identityN_to_identity_test.py similarity index 97% rename from model-optimizer/extensions/front/tf/identityN_to_identity_test.py rename to model-optimizer/unit_tests/extensions/front/tf/identityN_to_identity_test.py index f05fbf46ac3..b6f39f52fd2 100644 --- a/model-optimizer/extensions/front/tf/identityN_to_identity_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/identityN_to_identity_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.front.tf.identityN_to_identity import IdentityN_to_Identity from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import result, regular_op_with_shaped_data, \ +from unit_tests.utils.graph import result, regular_op_with_shaped_data, \ regular_op_with_empty_data, build_graph, connect, empty_data nodes = { diff --git a/model-optimizer/extensions/front/tf/mvn_unrolled_test.py b/model-optimizer/unit_tests/extensions/front/tf/mvn_unrolled_test.py similarity index 98% rename from model-optimizer/extensions/front/tf/mvn_unrolled_test.py rename to model-optimizer/unit_tests/extensions/front/tf/mvn_unrolled_test.py index 28df8ae474e..76740795979 100644 --- a/model-optimizer/extensions/front/tf/mvn_unrolled_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/mvn_unrolled_test.py @@ -7,7 +7,7 @@ from extensions.front.tf.mvn_unrolled import MVNUnrolled from extensions.ops.mvn import MVN from mo.ops.op import Op from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class MVNUnrolledMatchingTests(unittest.TestCase): diff --git a/model-optimizer/extensions/front/tf/next_iteration_ext_test.py b/model-optimizer/unit_tests/extensions/front/tf/next_iteration_ext_test.py similarity index 86% rename from model-optimizer/extensions/front/tf/next_iteration_ext_test.py rename to model-optimizer/unit_tests/extensions/front/tf/next_iteration_ext_test.py index eaf5f06c52c..b2884865574 100644 --- a/model-optimizer/extensions/front/tf/next_iteration_ext_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/next_iteration_ext_test.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from extensions.front.tf.next_iteration_ext import NextIterationExtractor -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class TestNextIteration(BaseExtractorsTestingClass): diff --git a/model-optimizer/extensions/front/tf/pad_tf_to_pad_test.py b/model-optimizer/unit_tests/extensions/front/tf/pad_tf_to_pad_test.py similarity index 99% rename from model-optimizer/extensions/front/tf/pad_tf_to_pad_test.py rename to model-optimizer/unit_tests/extensions/front/tf/pad_tf_to_pad_test.py index ea017d17e9a..ed63d797f60 100644 --- a/model-optimizer/extensions/front/tf/pad_tf_to_pad_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/pad_tf_to_pad_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.front.tf.pad_tf_to_pad import PadTFToPad from mo.front.common.partial_infer.utils import int64_array, float_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const nodes_attributes = { 'placeholder': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/front/tf/size_replacer_test.py b/model-optimizer/unit_tests/extensions/front/tf/size_replacer_test.py similarity index 95% rename from model-optimizer/extensions/front/tf/size_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/tf/size_replacer_test.py index 446bc20f1e9..c6f075b7084 100644 --- a/model-optimizer/extensions/front/tf/size_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/size_replacer_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.front.tf.SizeReplacer import SizeFrontReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, connect, \ +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, \ valued_const_with_data nodes = lambda output_type: { diff --git a/model-optimizer/extensions/front/tf/sparse_to_dense_replacer_test.py b/model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py similarity index 96% rename from model-optimizer/extensions/front/tf/sparse_to_dense_replacer_test.py rename to model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py index b1ac8426c7f..4e624dfd069 100644 --- a/model-optimizer/extensions/front/tf/sparse_to_dense_replacer_test.py +++ b/model-optimizer/unit_tests/extensions/front/tf/sparse_to_dense_replacer_test.py @@ -6,8 +6,7 @@ import unittest from extensions.front.tf.sparse_to_dense_replacer import SparseToDenseReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph -from mo.utils.unittest.graph import build_graph, const +from unit_tests.utils.graph import build_graph, const class SparseToDenseFrontReplacersTest(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/AddIsCyclicAttribute_test.py b/model-optimizer/unit_tests/extensions/middle/AddIsCyclicAttribute_test.py similarity index 95% rename from model-optimizer/extensions/middle/AddIsCyclicAttribute_test.py rename to model-optimizer/unit_tests/extensions/middle/AddIsCyclicAttribute_test.py index 865ed9e5841..9f5162f43aa 100644 --- a/model-optimizer/extensions/middle/AddIsCyclicAttribute_test.py +++ b/model-optimizer/unit_tests/extensions/middle/AddIsCyclicAttribute_test.py @@ -4,7 +4,7 @@ import unittest from extensions.middle.AddIsCyclicAttribute import AddIsCyclicAttribute -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class AddIsCyclicAttributeTest(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/AddMeanScaleValues_test.py b/model-optimizer/unit_tests/extensions/middle/AddMeanScaleValues_test.py similarity index 99% rename from model-optimizer/extensions/middle/AddMeanScaleValues_test.py rename to model-optimizer/unit_tests/extensions/middle/AddMeanScaleValues_test.py index a73f55e1074..440e8798020 100644 --- a/model-optimizer/extensions/middle/AddMeanScaleValues_test.py +++ b/model-optimizer/unit_tests/extensions/middle/AddMeanScaleValues_test.py @@ -11,7 +11,7 @@ from extensions.middle.ScaleInput import ScaleInput from mo.graph.graph import Graph, Node from mo.utils.cli_parser import get_mean_scale_dictionary, parse_tuple_pairs from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, result, connect, connect_data, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, result, connect, connect_data, \ valued_const_with_data nodes = { diff --git a/model-optimizer/extensions/middle/CheckForCycle_test.py b/model-optimizer/unit_tests/extensions/middle/CheckForCycle_test.py similarity index 98% rename from model-optimizer/extensions/middle/CheckForCycle_test.py rename to model-optimizer/unit_tests/extensions/middle/CheckForCycle_test.py index d9c2e2a043e..8e1f1b4f702 100644 --- a/model-optimizer/extensions/middle/CheckForCycle_test.py +++ b/model-optimizer/unit_tests/extensions/middle/CheckForCycle_test.py @@ -5,7 +5,7 @@ import unittest from extensions.middle.CheckForCycle import CheckForCycle from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'value': None, 'kind': 'op'}, 'node_1_data': {'value': None, 'kind': 'data', 'data_type': None}, diff --git a/model-optimizer/extensions/middle/ConcatOptimization_test.py b/model-optimizer/unit_tests/extensions/middle/ConcatOptimization_test.py similarity index 98% rename from model-optimizer/extensions/middle/ConcatOptimization_test.py rename to model-optimizer/unit_tests/extensions/middle/ConcatOptimization_test.py index b2211c5fb03..341dde05045 100644 --- a/model-optimizer/extensions/middle/ConcatOptimization_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ConcatOptimization_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.ConcatOptimization import ConcatOdInputEraserAndPortsReconnect from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, shaped_const_with_data, connect +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, shaped_const_with_data, connect class ConcatOdInputEraserAndPortsReconnectTest(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/ConvertGroupedStridedSlice_test.py b/model-optimizer/unit_tests/extensions/middle/ConvertGroupedStridedSlice_test.py similarity index 99% rename from model-optimizer/extensions/middle/ConvertGroupedStridedSlice_test.py rename to model-optimizer/unit_tests/extensions/middle/ConvertGroupedStridedSlice_test.py index 0b36ff77839..32fe29884b0 100644 --- a/model-optimizer/extensions/middle/ConvertGroupedStridedSlice_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ConvertGroupedStridedSlice_test.py @@ -10,7 +10,7 @@ from extensions.middle.ConvertGroupedStridedSlice import ConvertGroupedStridedSl from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/middle/CutInputHavingZeroDimFromConcat_test.py b/model-optimizer/unit_tests/extensions/middle/CutInputHavingZeroDimFromConcat_test.py similarity index 99% rename from model-optimizer/extensions/middle/CutInputHavingZeroDimFromConcat_test.py rename to model-optimizer/unit_tests/extensions/middle/CutInputHavingZeroDimFromConcat_test.py index ea008ff61a6..639ae74cbf5 100644 --- a/model-optimizer/extensions/middle/CutInputHavingZeroDimFromConcat_test.py +++ b/model-optimizer/unit_tests/extensions/middle/CutInputHavingZeroDimFromConcat_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.CutInputHavingZeroDimFromConcat import CutInputHavingZeroDimFromConcat from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph node_attrs_for_the_case_when_there_are_no_zero_shape_constants = { 'const0': { diff --git a/model-optimizer/extensions/middle/EltwiseInputReshape_test.py b/model-optimizer/unit_tests/extensions/middle/EltwiseInputReshape_test.py similarity index 99% rename from model-optimizer/extensions/middle/EltwiseInputReshape_test.py rename to model-optimizer/unit_tests/extensions/middle/EltwiseInputReshape_test.py index 9f451a43247..db5d7607fc8 100644 --- a/model-optimizer/extensions/middle/EltwiseInputReshape_test.py +++ b/model-optimizer/unit_tests/extensions/middle/EltwiseInputReshape_test.py @@ -7,8 +7,8 @@ import numpy as np from extensions.middle.EltwiseInputReshape import normalize_eltwise_inputs from mo.front.common.partial_infer.utils import int64_array -from mo.middle.passes.eliminate_test import build_graph from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph # The dictionary with nodes attributes used to build various graphs. A key is the name of the node and the value is the # dictionary with node attributes. diff --git a/model-optimizer/extensions/middle/FakeSplitOutputs_test.py b/model-optimizer/unit_tests/extensions/middle/FakeSplitOutputs_test.py similarity index 98% rename from model-optimizer/extensions/middle/FakeSplitOutputs_test.py rename to model-optimizer/unit_tests/extensions/middle/FakeSplitOutputs_test.py index 2c2e4e58ce2..2ce3b6e729d 100644 --- a/model-optimizer/extensions/middle/FakeSplitOutputs_test.py +++ b/model-optimizer/unit_tests/extensions/middle/FakeSplitOutputs_test.py @@ -9,7 +9,7 @@ from extensions.middle.FakeSplitOutputs import AddFakeOutputsToSplit, AddFakeOut from mo.front.common.partial_infer.elemental import copy_shape_infer from mo.graph.graph import Node from mo.middle.passes.eliminate import graph_clean_up -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter', 'shape': np.array([1, 227, 227, 3])}, diff --git a/model-optimizer/extensions/middle/FusedBatchNormTraining_test.py b/model-optimizer/unit_tests/extensions/middle/FusedBatchNormTraining_test.py similarity index 99% rename from model-optimizer/extensions/middle/FusedBatchNormTraining_test.py rename to model-optimizer/unit_tests/extensions/middle/FusedBatchNormTraining_test.py index 23c56554eef..d7a4c4a3e39 100644 --- a/model-optimizer/extensions/middle/FusedBatchNormTraining_test.py +++ b/model-optimizer/unit_tests/extensions/middle/FusedBatchNormTraining_test.py @@ -9,8 +9,8 @@ from generator import generator, generate from extensions.middle.FusedBatchNormTraining import FusedBatchNormTraining from mo.front.common.partial_infer.utils import int64_array from mo.middle.passes.eliminate import shape_inference -from mo.middle.passes.eliminate_test import build_graph from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder': {'value': None, 'shape': int64_array([3, 10, 11, 5]), 'type': 'Parameter', 'kind': 'op', diff --git a/model-optimizer/extensions/middle/GroupNorm_test.py b/model-optimizer/unit_tests/extensions/middle/GroupNorm_test.py similarity index 97% rename from model-optimizer/extensions/middle/GroupNorm_test.py rename to model-optimizer/unit_tests/extensions/middle/GroupNorm_test.py index 00e3fd2ded9..38d84d83e67 100644 --- a/model-optimizer/extensions/middle/GroupNorm_test.py +++ b/model-optimizer/unit_tests/extensions/middle/GroupNorm_test.py @@ -6,8 +6,8 @@ import unittest from extensions.middle.GroupNorm import GroupNormToMVN from mo.front.common.partial_infer.utils import float_array, int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, build_graph_with_edge_attrs, connect, \ - regular_op_with_shaped_data, valued_const_with_data, connect_data +from unit_tests.utils.graph import build_graph, result, connect, \ + regular_op_with_shaped_data, valued_const_with_data shape = int64_array([1, 3, 5, 2]) nodes = {**regular_op_with_shaped_data('input', shape, {'type': 'Parameter', 'op': 'Parameter'}), diff --git a/model-optimizer/extensions/middle/InsertSelect_test.py b/model-optimizer/unit_tests/extensions/middle/InsertSelect_test.py similarity index 99% rename from model-optimizer/extensions/middle/InsertSelect_test.py rename to model-optimizer/unit_tests/extensions/middle/InsertSelect_test.py index db783576de9..03efaf262b5 100644 --- a/model-optimizer/extensions/middle/InsertSelect_test.py +++ b/model-optimizer/unit_tests/extensions/middle/InsertSelect_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.InsertSelect import AddSelectBeforeMemoryNodePattern from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class InsertSelectTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/InterpolateSequenceToInterpolate_test.py b/model-optimizer/unit_tests/extensions/middle/InterpolateSequenceToInterpolate_test.py similarity index 99% rename from model-optimizer/extensions/middle/InterpolateSequenceToInterpolate_test.py rename to model-optimizer/unit_tests/extensions/middle/InterpolateSequenceToInterpolate_test.py index e9f95811485..aa3002122c2 100644 --- a/model-optimizer/extensions/middle/InterpolateSequenceToInterpolate_test.py +++ b/model-optimizer/unit_tests/extensions/middle/InterpolateSequenceToInterpolate_test.py @@ -7,7 +7,7 @@ import unittest from extensions.middle.InterpolateSequenceToInterpolate import InterpolateSequenceToInterpolate from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs_for_2d_case_1_opset4_case = { 'placeholder': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/middle/L2NormFusing_test.py b/model-optimizer/unit_tests/extensions/middle/L2NormFusing_test.py similarity index 99% rename from model-optimizer/extensions/middle/L2NormFusing_test.py rename to model-optimizer/unit_tests/extensions/middle/L2NormFusing_test.py index 82395c818b6..bfd96dd42d9 100644 --- a/model-optimizer/extensions/middle/L2NormFusing_test.py +++ b/model-optimizer/unit_tests/extensions/middle/L2NormFusing_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.middle.L2NormFusing import L2NormToNorm from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs # A list with nodes attributes used to build various graphs. nodes = [ diff --git a/model-optimizer/extensions/middle/LeakyReluPattern_test.py b/model-optimizer/unit_tests/extensions/middle/LeakyReluPattern_test.py similarity index 97% rename from model-optimizer/extensions/middle/LeakyReluPattern_test.py rename to model-optimizer/unit_tests/extensions/middle/LeakyReluPattern_test.py index 50ce990b56e..9c88a29da8d 100644 --- a/model-optimizer/extensions/middle/LeakyReluPattern_test.py +++ b/model-optimizer/unit_tests/extensions/middle/LeakyReluPattern_test.py @@ -8,7 +8,7 @@ from mo.front.common.partial_infer.utils import float_array, int64_array from mo.graph.graph import Node from mo.ops.result import Result from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, build_graph_with_edge_attrs, connect, \ +from unit_tests.utils.graph import build_graph, result, build_graph_with_edge_attrs, connect, \ regular_op_with_shaped_data, valued_const_with_data, connect_data shape = int64_array([1, 3, 5, 2]) diff --git a/model-optimizer/extensions/middle/MXTileReplacer_test.py b/model-optimizer/unit_tests/extensions/middle/MXTileReplacer_test.py similarity index 98% rename from model-optimizer/extensions/middle/MXTileReplacer_test.py rename to model-optimizer/unit_tests/extensions/middle/MXTileReplacer_test.py index b4f6b470928..98d55e33aaa 100644 --- a/model-optimizer/extensions/middle/MXTileReplacer_test.py +++ b/model-optimizer/unit_tests/extensions/middle/MXTileReplacer_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.MXTileReplacer import MXTileReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder': {'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/middle/MakeKaldiConstReshapable_test.py b/model-optimizer/unit_tests/extensions/middle/MakeKaldiConstReshapable_test.py similarity index 98% rename from model-optimizer/extensions/middle/MakeKaldiConstReshapable_test.py rename to model-optimizer/unit_tests/extensions/middle/MakeKaldiConstReshapable_test.py index db038982932..73eafab8c03 100644 --- a/model-optimizer/extensions/middle/MakeKaldiConstReshapable_test.py +++ b/model-optimizer/unit_tests/extensions/middle/MakeKaldiConstReshapable_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.MakeKaldiConstReshapable import MakeKaldiConstReshapable from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, result, regular_op_with_shaped_data, connect +from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_data, connect nodes = { **regular_op_with_shaped_data('placeholder_1', [1, 13], {'kind': 'op', 'op': 'Parameter', 'shape': [1, 13]}), diff --git a/model-optimizer/extensions/middle/MulQuantizeFuse_test.py b/model-optimizer/unit_tests/extensions/middle/MulQuantizeFuse_test.py similarity index 99% rename from model-optimizer/extensions/middle/MulQuantizeFuse_test.py rename to model-optimizer/unit_tests/extensions/middle/MulQuantizeFuse_test.py index 49503987caa..34b3fccf810 100644 --- a/model-optimizer/extensions/middle/MulQuantizeFuse_test.py +++ b/model-optimizer/unit_tests/extensions/middle/MulQuantizeFuse_test.py @@ -6,8 +6,8 @@ import unittest import numpy as np from extensions.middle.MulFakeQuantizeFuse import MulFakeQuantizeFuse -from mo.middle.passes.eliminate_test import build_graph from mo.utils.ir_engine.compare_graphs import compare_graphs +from unit_tests.utils.graph import build_graph # The dictionary with nodes attributes used to build various graphs. A key is the name of the node and the value is the # dictionary with node attributes. diff --git a/model-optimizer/extensions/middle/PoolV2ToAttributedPool_test.py b/model-optimizer/unit_tests/extensions/middle/PoolV2ToAttributedPool_test.py similarity index 95% rename from model-optimizer/extensions/middle/PoolV2ToAttributedPool_test.py rename to model-optimizer/unit_tests/extensions/middle/PoolV2ToAttributedPool_test.py index 2a239fe9b39..2dc7b7a594b 100644 --- a/model-optimizer/extensions/middle/PoolV2ToAttributedPool_test.py +++ b/model-optimizer/unit_tests/extensions/middle/PoolV2ToAttributedPool_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.PoolV2ToAttributedPool import PoolV2ToAttributedPool from mo.utils.ir_engine.compare_graphs import compare_graphs from mo.utils.shape import int64_array -from mo.utils.unittest.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ +from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ connect, shaped_const_with_data, result diff --git a/model-optimizer/extensions/middle/ReluQuantizeFuse_test.py b/model-optimizer/unit_tests/extensions/middle/ReluQuantizeFuse_test.py similarity index 99% rename from model-optimizer/extensions/middle/ReluQuantizeFuse_test.py rename to model-optimizer/unit_tests/extensions/middle/ReluQuantizeFuse_test.py index c12ceb592fd..5972070bead 100644 --- a/model-optimizer/extensions/middle/ReluQuantizeFuse_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ReluQuantizeFuse_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.ReluQuantizeFuse import ReluQuantizeFuse, ReluFakeQuantizeMark from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { # input diff --git a/model-optimizer/extensions/middle/RemoveDuplicationMemory_test.py b/model-optimizer/unit_tests/extensions/middle/RemoveDuplicationMemory_test.py similarity index 99% rename from model-optimizer/extensions/middle/RemoveDuplicationMemory_test.py rename to model-optimizer/unit_tests/extensions/middle/RemoveDuplicationMemory_test.py index a18ea20f40f..7fe4ff166b7 100644 --- a/model-optimizer/extensions/middle/RemoveDuplicationMemory_test.py +++ b/model-optimizer/unit_tests/extensions/middle/RemoveDuplicationMemory_test.py @@ -5,7 +5,7 @@ import unittest from extensions.middle.RemoveDuplicationMemory import RemoveMemoryDuplicationPattern, MergeNeighborSplicePattern from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class RemoveMemoryDuplicationPatternTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/RemoveUselessConcatSplit_test.py b/model-optimizer/unit_tests/extensions/middle/RemoveUselessConcatSplit_test.py similarity index 99% rename from model-optimizer/extensions/middle/RemoveUselessConcatSplit_test.py rename to model-optimizer/unit_tests/extensions/middle/RemoveUselessConcatSplit_test.py index d3ebd71ef43..4ec3516310e 100644 --- a/model-optimizer/extensions/middle/RemoveUselessConcatSplit_test.py +++ b/model-optimizer/unit_tests/extensions/middle/RemoveUselessConcatSplit_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.RemoveUselessConcatSplit import RemoveUselessConcatSplitPattern from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class RemoveUselessConcatSplitTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/RemoveUselessCrops_test.py b/model-optimizer/unit_tests/extensions/middle/RemoveUselessCrops_test.py similarity index 99% rename from model-optimizer/extensions/middle/RemoveUselessCrops_test.py rename to model-optimizer/unit_tests/extensions/middle/RemoveUselessCrops_test.py index e629154285a..e51dab87b56 100644 --- a/model-optimizer/extensions/middle/RemoveUselessCrops_test.py +++ b/model-optimizer/unit_tests/extensions/middle/RemoveUselessCrops_test.py @@ -5,7 +5,7 @@ import unittest from extensions.middle.RemoveUselessCrops import RemoveUselessCropsPattern from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class RemoveUselessCropsPatternTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/RemoveUselessPad_test.py b/model-optimizer/unit_tests/extensions/middle/RemoveUselessPad_test.py similarity index 96% rename from model-optimizer/extensions/middle/RemoveUselessPad_test.py rename to model-optimizer/unit_tests/extensions/middle/RemoveUselessPad_test.py index 53059492f00..42af9272603 100644 --- a/model-optimizer/extensions/middle/RemoveUselessPad_test.py +++ b/model-optimizer/unit_tests/extensions/middle/RemoveUselessPad_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.RemoveUselessPad import RemoveUselessPad from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect, \ connect_data diff --git a/model-optimizer/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py b/model-optimizer/unit_tests/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py similarity index 99% rename from model-optimizer/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py rename to model-optimizer/unit_tests/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py index 81c9223a9f6..aa62e185fff 100644 --- a/model-optimizer/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ReplaceMemoryOffsetWithSplice_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.ReplaceMemoryOffsetWithSplice import ReplaceMemoryOffsetNodePattern from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ReplaceMemoryOffsetNodePatternTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/ReplacePNormNodePattern_test.py b/model-optimizer/unit_tests/extensions/middle/ReplacePNormNodePattern_test.py similarity index 98% rename from model-optimizer/extensions/middle/ReplacePNormNodePattern_test.py rename to model-optimizer/unit_tests/extensions/middle/ReplacePNormNodePattern_test.py index c26f65265ea..6fcd529db77 100644 --- a/model-optimizer/extensions/middle/ReplacePNormNodePattern_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ReplacePNormNodePattern_test.py @@ -5,7 +5,7 @@ import unittest from extensions.middle.ReplacePNorm import ReplacePNormNodePattern from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ReplacePNormNodePatternTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/ReplaceSpliceNodePattern_test.py b/model-optimizer/unit_tests/extensions/middle/ReplaceSpliceNodePattern_test.py similarity index 99% rename from model-optimizer/extensions/middle/ReplaceSpliceNodePattern_test.py rename to model-optimizer/unit_tests/extensions/middle/ReplaceSpliceNodePattern_test.py index ec5985196a4..ee0a5136932 100644 --- a/model-optimizer/extensions/middle/ReplaceSpliceNodePattern_test.py +++ b/model-optimizer/unit_tests/extensions/middle/ReplaceSpliceNodePattern_test.py @@ -7,7 +7,7 @@ from extensions.middle.ReplaceSpliceNodePattern import ReplaceSpliceNodePattern from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class ReplaceSpliceNodePatternTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/SequenceLenthToMask_test.py b/model-optimizer/unit_tests/extensions/middle/SequenceLenthToMask_test.py similarity index 98% rename from model-optimizer/extensions/middle/SequenceLenthToMask_test.py rename to model-optimizer/unit_tests/extensions/middle/SequenceLenthToMask_test.py index 1f9b5698282..33ddeae4a12 100644 --- a/model-optimizer/extensions/middle/SequenceLenthToMask_test.py +++ b/model-optimizer/unit_tests/extensions/middle/SequenceLenthToMask_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.SequenceLengthToMask import SequenceLengthToMask from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'logits': {'shape': int64_array([5, 3, 30]), 'type': 'Parameter', 'kind': 'op', diff --git a/model-optimizer/extensions/middle/SharedWeightsDuplication_test.py b/model-optimizer/unit_tests/extensions/middle/SharedWeightsDuplication_test.py similarity index 97% rename from model-optimizer/extensions/middle/SharedWeightsDuplication_test.py rename to model-optimizer/unit_tests/extensions/middle/SharedWeightsDuplication_test.py index 9c97f9f5eb3..dc3d9b96397 100644 --- a/model-optimizer/extensions/middle/SharedWeightsDuplication_test.py +++ b/model-optimizer/unit_tests/extensions/middle/SharedWeightsDuplication_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.SharedWeightsDuplication import SharedWeightsDuplication from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'const': {'shape': None, 'type': 'Const', 'kind': 'op', 'op': 'Const'}, diff --git a/model-optimizer/extensions/middle/SliceConverter_test.py b/model-optimizer/unit_tests/extensions/middle/SliceConverter_test.py similarity index 99% rename from model-optimizer/extensions/middle/SliceConverter_test.py rename to model-optimizer/unit_tests/extensions/middle/SliceConverter_test.py index bfaeefa55cb..f0266d0c7d7 100644 --- a/model-optimizer/extensions/middle/SliceConverter_test.py +++ b/model-optimizer/unit_tests/extensions/middle/SliceConverter_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.SliceConverter import ConvertSlice from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, \ regular_op_with_empty_data, result, connect, connect_data nodes_attributes = { diff --git a/model-optimizer/extensions/middle/SliceLikeToStridedSlice_test.py b/model-optimizer/unit_tests/extensions/middle/SliceLikeToStridedSlice_test.py similarity index 99% rename from model-optimizer/extensions/middle/SliceLikeToStridedSlice_test.py rename to model-optimizer/unit_tests/extensions/middle/SliceLikeToStridedSlice_test.py index 855a3b741ad..391d9de58ba 100644 --- a/model-optimizer/extensions/middle/SliceLikeToStridedSlice_test.py +++ b/model-optimizer/unit_tests/extensions/middle/SliceLikeToStridedSlice_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.SliceLikeToStridedSlice import SliceLikeToStridedSlice from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'input': {'kind': 'op', 'op': 'Const'}, diff --git a/model-optimizer/extensions/middle/SplitConcatPairToInterpolate_test.py b/model-optimizer/unit_tests/extensions/middle/SplitConcatPairToInterpolate_test.py similarity index 99% rename from model-optimizer/extensions/middle/SplitConcatPairToInterpolate_test.py rename to model-optimizer/unit_tests/extensions/middle/SplitConcatPairToInterpolate_test.py index f9358816cad..e7742941cb3 100644 --- a/model-optimizer/extensions/middle/SplitConcatPairToInterpolate_test.py +++ b/model-optimizer/unit_tests/extensions/middle/SplitConcatPairToInterpolate_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.SplitConcatPairToInterpolate import SplitConcatPairToInterpolate from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs_for_2d_spatial_case = { 'placeholder': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/middle/StridedSliceNormalizer_test.py b/model-optimizer/unit_tests/extensions/middle/StridedSliceNormalizer_test.py similarity index 99% rename from model-optimizer/extensions/middle/StridedSliceNormalizer_test.py rename to model-optimizer/unit_tests/extensions/middle/StridedSliceNormalizer_test.py index 9cb8c6f6dcd..5216f37478f 100644 --- a/model-optimizer/extensions/middle/StridedSliceNormalizer_test.py +++ b/model-optimizer/unit_tests/extensions/middle/StridedSliceNormalizer_test.py @@ -15,7 +15,7 @@ from mo.graph.graph import Node from mo.middle.passes.infer import partial_infer from mo.ops.strided_slice import StridedSlice from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ +from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ connect, regular_op, empty_data, regular_op_with_shaped_data edges = ( diff --git a/model-optimizer/extensions/middle/TensorIteratorBackEdge_test.py b/model-optimizer/unit_tests/extensions/middle/TensorIteratorBackEdge_test.py similarity index 98% rename from model-optimizer/extensions/middle/TensorIteratorBackEdge_test.py rename to model-optimizer/unit_tests/extensions/middle/TensorIteratorBackEdge_test.py index 370c819637f..d6aaf04721a 100644 --- a/model-optimizer/extensions/middle/TensorIteratorBackEdge_test.py +++ b/model-optimizer/unit_tests/extensions/middle/TensorIteratorBackEdge_test.py @@ -5,7 +5,7 @@ import unittest from extensions.middle.TensorIteratorBackEdge import BackEdgesMatching from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class BackEdgesMatchingTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/TensorIteratorCondition_test.py b/model-optimizer/unit_tests/extensions/middle/TensorIteratorCondition_test.py similarity index 98% rename from model-optimizer/extensions/middle/TensorIteratorCondition_test.py rename to model-optimizer/unit_tests/extensions/middle/TensorIteratorCondition_test.py index 6c4d27899fb..ac7183d641a 100644 --- a/model-optimizer/extensions/middle/TensorIteratorCondition_test.py +++ b/model-optimizer/unit_tests/extensions/middle/TensorIteratorCondition_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.TensorIteratorCondition import LoopConditionMatcher from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class TensorIteratorConditionTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/TensorIteratorInput_test.py b/model-optimizer/unit_tests/extensions/middle/TensorIteratorInput_test.py similarity index 99% rename from model-optimizer/extensions/middle/TensorIteratorInput_test.py rename to model-optimizer/unit_tests/extensions/middle/TensorIteratorInput_test.py index 34e46734936..86e93217504 100644 --- a/model-optimizer/extensions/middle/TensorIteratorInput_test.py +++ b/model-optimizer/unit_tests/extensions/middle/TensorIteratorInput_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.TensorIteratorInput import SmartInputMatcher, SimpleInputMatcher, BackEdgeSimpleInputMatcher from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class SmartInputMatcherTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/TensorIteratorOutput_test.py b/model-optimizer/unit_tests/extensions/middle/TensorIteratorOutput_test.py similarity index 96% rename from model-optimizer/extensions/middle/TensorIteratorOutput_test.py rename to model-optimizer/unit_tests/extensions/middle/TensorIteratorOutput_test.py index 10792c775ae..9ab550e2d45 100644 --- a/model-optimizer/extensions/middle/TensorIteratorOutput_test.py +++ b/model-optimizer/unit_tests/extensions/middle/TensorIteratorOutput_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.TensorIteratorOutput import SmartOutputMatcher from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class SmartOutputMatcherTests(unittest.TestCase): diff --git a/model-optimizer/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py b/model-optimizer/unit_tests/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py similarity index 99% rename from model-optimizer/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py rename to model-optimizer/unit_tests/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py index 69f9a15ef7f..f6fdf932186 100644 --- a/model-optimizer/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py +++ b/model-optimizer/unit_tests/extensions/middle/UnsqueezeTileReshapeBlockToInterpolate_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.middle.UnsqueezeTileReshapeBlockToInterpolate import UnsqueezeTileReshapeBlockToInterpolate from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs = { 'placeholder': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/extensions/middle/UpsampleToResample_test.py b/model-optimizer/unit_tests/extensions/middle/UpsampleToResample_test.py similarity index 99% rename from model-optimizer/extensions/middle/UpsampleToResample_test.py rename to model-optimizer/unit_tests/extensions/middle/UpsampleToResample_test.py index 4b27f954225..d75ced8168f 100644 --- a/model-optimizer/extensions/middle/UpsampleToResample_test.py +++ b/model-optimizer/unit_tests/extensions/middle/UpsampleToResample_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.middle.UpsampleToResample import UpsampleToResample from mo.front.common.partial_infer.utils import int64_array, float32_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs = { 'placeholder': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/unit_tests/extensions/middle/__init__.py b/model-optimizer/unit_tests/extensions/middle/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/middle/quantize_fuses_test.py b/model-optimizer/unit_tests/extensions/middle/quantize_fuses_test.py similarity index 99% rename from model-optimizer/extensions/middle/quantize_fuses_test.py rename to model-optimizer/unit_tests/extensions/middle/quantize_fuses_test.py index ec7da4b0802..3605cba6fa2 100644 --- a/model-optimizer/extensions/middle/quantize_fuses_test.py +++ b/model-optimizer/unit_tests/extensions/middle/quantize_fuses_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.middle.quantize_fuses import FakeQuantizeFuse from mo.front.common.partial_infer.eltwise import eltwise_infer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { 'placeholder': {'kind': 'op', 'op': 'Placeholder'}, diff --git a/model-optimizer/extensions/middle/sparse_reshape_test.py b/model-optimizer/unit_tests/extensions/middle/sparse_reshape_test.py similarity index 99% rename from model-optimizer/extensions/middle/sparse_reshape_test.py rename to model-optimizer/unit_tests/extensions/middle/sparse_reshape_test.py index fbccf744d56..f1c5f443a89 100644 --- a/model-optimizer/extensions/middle/sparse_reshape_test.py +++ b/model-optimizer/unit_tests/extensions/middle/sparse_reshape_test.py @@ -6,7 +6,7 @@ import unittest from extensions.middle.sparse_reshape import SparseReshapeMiddleReplacer from mo.front.common.partial_infer.utils import int64_array from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class SparseReshapeMiddleReplacerTests(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/ExtractImagePatches_test.py b/model-optimizer/unit_tests/extensions/ops/ExtractImagePatches_test.py similarity index 98% rename from model-optimizer/extensions/ops/ExtractImagePatches_test.py rename to model-optimizer/unit_tests/extensions/ops/ExtractImagePatches_test.py index 490cb82f8a0..12ffa2ed9a1 100644 --- a/model-optimizer/extensions/ops/ExtractImagePatches_test.py +++ b/model-optimizer/unit_tests/extensions/ops/ExtractImagePatches_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.ExtractImagePatches import ExtractImagePatches from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { 'input': {'op': 'Parameter', 'kind': 'op', 'shape': None}, diff --git a/model-optimizer/extensions/ops/LookupTableInsert_test.py b/model-optimizer/unit_tests/extensions/ops/LookupTableInsert_test.py similarity index 98% rename from model-optimizer/extensions/ops/LookupTableInsert_test.py rename to model-optimizer/unit_tests/extensions/ops/LookupTableInsert_test.py index 49f40a37564..598aed1c799 100644 --- a/model-optimizer/extensions/ops/LookupTableInsert_test.py +++ b/model-optimizer/unit_tests/extensions/ops/LookupTableInsert_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.LookupTableInsert import LookupTableInsert from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'table': {'kind': 'op'}, 'table_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/MatMul_test.py b/model-optimizer/unit_tests/extensions/ops/MatMul_test.py similarity index 98% rename from model-optimizer/extensions/ops/MatMul_test.py rename to model-optimizer/unit_tests/extensions/ops/MatMul_test.py index 9424a26489c..1706880eaf1 100644 --- a/model-optimizer/extensions/ops/MatMul_test.py +++ b/model-optimizer/unit_tests/extensions/ops/MatMul_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.MatMul import MatMul from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs @generator diff --git a/model-optimizer/extensions/ops/MatMul_value_propagation_test.py b/model-optimizer/unit_tests/extensions/ops/MatMul_value_propagation_test.py similarity index 98% rename from model-optimizer/extensions/ops/MatMul_value_propagation_test.py rename to model-optimizer/unit_tests/extensions/ops/MatMul_value_propagation_test.py index fe60eec84bc..2cbe836d4fd 100644 --- a/model-optimizer/extensions/ops/MatMul_value_propagation_test.py +++ b/model-optimizer/unit_tests/extensions/ops/MatMul_value_propagation_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.MatMul import MatMul, transpose from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_nodes_attrs = { 'A': {'type': 'Const', 'op': 'Const', 'kind': 'op', 'shape': None, 'value': None}, diff --git a/model-optimizer/extensions/ops/ONNXResize11_test.py b/model-optimizer/unit_tests/extensions/ops/ONNXResize11_test.py similarity index 99% rename from model-optimizer/extensions/ops/ONNXResize11_test.py rename to model-optimizer/unit_tests/extensions/ops/ONNXResize11_test.py index c19ca15d4e7..b38773b8279 100644 --- a/model-optimizer/extensions/ops/ONNXResize11_test.py +++ b/model-optimizer/unit_tests/extensions/ops/ONNXResize11_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.ONNXResize11 import ONNXResize11Op from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs_sizes = { diff --git a/model-optimizer/extensions/ops/ReduceOps_test.py b/model-optimizer/unit_tests/extensions/ops/ReduceOps_test.py similarity index 95% rename from model-optimizer/extensions/ops/ReduceOps_test.py rename to model-optimizer/unit_tests/extensions/ops/ReduceOps_test.py index 9ca82cc9ccd..507b2cd584f 100644 --- a/model-optimizer/extensions/ops/ReduceOps_test.py +++ b/model-optimizer/unit_tests/extensions/ops/ReduceOps_test.py @@ -9,7 +9,7 @@ from generator import generate, generator from extensions.ops.ReduceOps import reduce_infer from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, result, connect, valued_const_with_data +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, result, connect, valued_const_with_data nodes_attributes = { **regular_op_with_shaped_data('data', [1, 3, 224, 224], {'type': 'Parameter', 'value': None, diff --git a/model-optimizer/extensions/ops/Reverse_test.py b/model-optimizer/unit_tests/extensions/ops/Reverse_test.py similarity index 97% rename from model-optimizer/extensions/ops/Reverse_test.py rename to model-optimizer/unit_tests/extensions/ops/Reverse_test.py index 892885629d9..0d2364e483f 100644 --- a/model-optimizer/extensions/ops/Reverse_test.py +++ b/model-optimizer/unit_tests/extensions/ops/Reverse_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.Reverse import Reverse from mo.front.common.extractors.utils import layout_attrs from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'node_1_data': {'type': 'Identity', 'kind': 'data', 'value': np.array([[1, 3, 227, 227]])}, diff --git a/model-optimizer/unit_tests/extensions/ops/__init__.py b/model-optimizer/unit_tests/extensions/ops/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/extensions/ops/accum_test.py b/model-optimizer/unit_tests/extensions/ops/accum_test.py similarity index 99% rename from model-optimizer/extensions/ops/accum_test.py rename to model-optimizer/unit_tests/extensions/ops/accum_test.py index c08f0615a71..6b573d7ec9f 100644 --- a/model-optimizer/extensions/ops/accum_test.py +++ b/model-optimizer/unit_tests/extensions/ops/accum_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.accum import AccumOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph wrong_attrs_graph = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'accum': {'type': 'Accum', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/activation_test.py b/model-optimizer/unit_tests/extensions/ops/activation_test.py similarity index 98% rename from model-optimizer/extensions/ops/activation_test.py rename to model-optimizer/unit_tests/extensions/ops/activation_test.py index 49d59637ab6..2342df9173d 100644 --- a/model-optimizer/extensions/ops/activation_test.py +++ b/model-optimizer/unit_tests/extensions/ops/activation_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.activation_ops import Elu, SoftPlus, Mish from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestActivationOp(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/argmax_test.py b/model-optimizer/unit_tests/extensions/ops/argmax_test.py similarity index 99% rename from model-optimizer/extensions/ops/argmax_test.py rename to model-optimizer/unit_tests/extensions/ops/argmax_test.py index e1f0d42ef08..13361760f01 100644 --- a/model-optimizer/extensions/ops/argmax_test.py +++ b/model-optimizer/unit_tests/extensions/ops/argmax_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.argmax import ArgMaxOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'argmax': {'op': 'ArgMax', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/assert_test.py b/model-optimizer/unit_tests/extensions/ops/assert_test.py similarity index 96% rename from model-optimizer/extensions/ops/assert_test.py rename to model-optimizer/unit_tests/extensions/ops/assert_test.py index d786b7638e9..847ea5e3df7 100644 --- a/model-optimizer/extensions/ops/assert_test.py +++ b/model-optimizer/unit_tests/extensions/ops/assert_test.py @@ -6,7 +6,7 @@ from unittest.mock import Mock from extensions.ops.assert_op import Assert from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs class TestAssert(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/bucketize_test.py b/model-optimizer/unit_tests/extensions/ops/bucketize_test.py similarity index 98% rename from model-optimizer/extensions/ops/bucketize_test.py rename to model-optimizer/unit_tests/extensions/ops/bucketize_test.py index 6334d362dd5..f4e9c9fcc39 100644 --- a/model-optimizer/extensions/ops/bucketize_test.py +++ b/model-optimizer/unit_tests/extensions/ops/bucketize_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.bucketize import Bucketize from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'input_tensor': {'shape': None, 'value': None, 'kind': 'data'}, 'input_buckets': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/cast_test.py b/model-optimizer/unit_tests/extensions/ops/cast_test.py similarity index 96% rename from model-optimizer/extensions/ops/cast_test.py rename to model-optimizer/unit_tests/extensions/ops/cast_test.py index dc0f6449c99..0fb025756de 100644 --- a/model-optimizer/extensions/ops/cast_test.py +++ b/model-optimizer/unit_tests/extensions/ops/cast_test.py @@ -1,16 +1,16 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import numpy as np import unittest + +import numpy as np from generator import generator, generate from extensions.ops.Cast import Cast from mo.middle.passes.convert_data_type import packed_U4, packed_I4 from mo.middle.passes.infer import partial_infer from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import valued_const_with_data, regular_op_with_empty_data, \ - result, build_graph, connect +from unit_tests.utils.graph import valued_const_with_data, regular_op_with_empty_data, result, build_graph, connect nodes = lambda value, dst_type: { **valued_const_with_data('value', np.array(value)), diff --git a/model-optimizer/extensions/ops/correlation_test.py b/model-optimizer/unit_tests/extensions/ops/correlation_test.py similarity index 97% rename from model-optimizer/extensions/ops/correlation_test.py rename to model-optimizer/unit_tests/extensions/ops/correlation_test.py index d28835cbc42..d2a60da82c6 100644 --- a/model-optimizer/extensions/ops/correlation_test.py +++ b/model-optimizer/unit_tests/extensions/ops/correlation_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.correlation import CorrelationOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'node_2': {'type': 'Identity', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/ctc_greedy_decoder_test.py b/model-optimizer/unit_tests/extensions/ops/ctc_greedy_decoder_test.py similarity index 98% rename from model-optimizer/extensions/ops/ctc_greedy_decoder_test.py rename to model-optimizer/unit_tests/extensions/ops/ctc_greedy_decoder_test.py index 6e445ce4ac6..69e17f11642 100644 --- a/model-optimizer/extensions/ops/ctc_greedy_decoder_test.py +++ b/model-optimizer/unit_tests/extensions/ops/ctc_greedy_decoder_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.ctc_greedy_decoder_seq_len import CTCGreedyDecoderSeqLenOp from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'logits': {'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/ctc_loss_test.py b/model-optimizer/unit_tests/extensions/ops/ctc_loss_test.py similarity index 98% rename from model-optimizer/extensions/ops/ctc_loss_test.py rename to model-optimizer/unit_tests/extensions/ops/ctc_loss_test.py index 66562b60d68..aea851673f0 100644 --- a/model-optimizer/extensions/ops/ctc_loss_test.py +++ b/model-optimizer/unit_tests/extensions/ops/ctc_loss_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.ctc_loss import CTCLoss from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'logits': {'kind': 'op'}, 'logits_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/cumsum_test.py b/model-optimizer/unit_tests/extensions/ops/cumsum_test.py similarity index 98% rename from model-optimizer/extensions/ops/cumsum_test.py rename to model-optimizer/unit_tests/extensions/ops/cumsum_test.py index c44517e96bf..4ab0e63d375 100644 --- a/model-optimizer/extensions/ops/cumsum_test.py +++ b/model-optimizer/unit_tests/extensions/ops/cumsum_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.cumsum import CumSum from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, valued_const_with_data, regular_op_with_shaped_data, result, connect +from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_op_with_shaped_data, result, connect nodes_attributes = { **regular_op_with_shaped_data('data', [1, 3, 224, 224], {'type': 'Parameter', 'value': None, diff --git a/model-optimizer/extensions/ops/data_augmentation_test.py b/model-optimizer/unit_tests/extensions/ops/data_augmentation_test.py similarity index 97% rename from model-optimizer/extensions/ops/data_augmentation_test.py rename to model-optimizer/unit_tests/extensions/ops/data_augmentation_test.py index c67fc888b8c..4d2fc8250bc 100644 --- a/model-optimizer/extensions/ops/data_augmentation_test.py +++ b/model-optimizer/unit_tests/extensions/ops/data_augmentation_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.data_augmentation import DataAugmentationOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'node_1': {'type': 'Identity', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/depth_to_space_test.py b/model-optimizer/unit_tests/extensions/ops/depth_to_space_test.py similarity index 98% rename from model-optimizer/extensions/ops/depth_to_space_test.py rename to model-optimizer/unit_tests/extensions/ops/depth_to_space_test.py index c6f3a2fba97..784d07a8f34 100644 --- a/model-optimizer/extensions/ops/depth_to_space_test.py +++ b/model-optimizer/unit_tests/extensions/ops/depth_to_space_test.py @@ -6,7 +6,7 @@ import numpy as np from extensions.ops.depth_to_space import DepthToSpaceOp from mo.graph.graph import Node from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { 'in_data_node': {'value': None, 'kind': 'data', 'shape': np.array([1, 1024, 576, 256])}, diff --git a/model-optimizer/extensions/ops/div_value_propagation_test.py b/model-optimizer/unit_tests/extensions/ops/div_value_propagation_test.py similarity index 98% rename from model-optimizer/extensions/ops/div_value_propagation_test.py rename to model-optimizer/unit_tests/extensions/ops/div_value_propagation_test.py index 6ae15b02b06..3caa72e1c2e 100644 --- a/model-optimizer/extensions/ops/div_value_propagation_test.py +++ b/model-optimizer/unit_tests/extensions/ops/div_value_propagation_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.elementwise import Div from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_nodes_attrs = { 'A': {'type': 'Const', 'op': 'Const', 'kind': 'op', 'shape': None, 'value': None}, diff --git a/model-optimizer/extensions/ops/elementwise_test.py b/model-optimizer/unit_tests/extensions/ops/elementwise_test.py similarity index 98% rename from model-optimizer/extensions/ops/elementwise_test.py rename to model-optimizer/unit_tests/extensions/ops/elementwise_test.py index 36e54000f44..4811e0a76c6 100644 --- a/model-optimizer/extensions/ops/elementwise_test.py +++ b/model-optimizer/unit_tests/extensions/ops/elementwise_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.elementwise import Round from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph def round_test_graph(nodes_attributes, value, mode: str): graph = build_graph(nodes_attributes, diff --git a/model-optimizer/extensions/ops/embedding_bag_test.py b/model-optimizer/unit_tests/extensions/ops/embedding_bag_test.py similarity index 96% rename from model-optimizer/extensions/ops/embedding_bag_test.py rename to model-optimizer/unit_tests/extensions/ops/embedding_bag_test.py index ae04e526356..293c94cdfa8 100644 --- a/model-optimizer/extensions/ops/embedding_bag_test.py +++ b/model-optimizer/unit_tests/extensions/ops/embedding_bag_test.py @@ -8,8 +8,7 @@ import numpy as np from extensions.ops.embedding_bag import EmbeddingBagOffsetsSum, EmbeddingBagPackedSum, EmbeddingSegmentsSum from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, \ - connect, FakeAttr +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect nodes = { **valued_const_with_data('data', np.random.randn(3000, 8)), diff --git a/model-optimizer/extensions/ops/gather_test.py b/model-optimizer/unit_tests/extensions/ops/gather_test.py similarity index 98% rename from model-optimizer/extensions/ops/gather_test.py rename to model-optimizer/unit_tests/extensions/ops/gather_test.py index bf0b3375ed0..d71445936b0 100644 --- a/model-optimizer/extensions/ops/gather_test.py +++ b/model-optimizer/unit_tests/extensions/ops/gather_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.gather import Gather from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestGatherPartialInfer(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/gatherelements_test.py b/model-optimizer/unit_tests/extensions/ops/gatherelements_test.py similarity index 96% rename from model-optimizer/extensions/ops/gatherelements_test.py rename to model-optimizer/unit_tests/extensions/ops/gatherelements_test.py index f3bae01f83a..2d668de0df5 100644 --- a/model-optimizer/extensions/ops/gatherelements_test.py +++ b/model-optimizer/unit_tests/extensions/ops/gatherelements_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.gatherelements import GatherElements from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, connect, \ +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, \ valued_const_with_data diff --git a/model-optimizer/extensions/ops/gathernd_test.py b/model-optimizer/unit_tests/extensions/ops/gathernd_test.py similarity index 99% rename from model-optimizer/extensions/ops/gathernd_test.py rename to model-optimizer/unit_tests/extensions/ops/gathernd_test.py index 8a4f52d8ac2..74217e26e53 100644 --- a/model-optimizer/extensions/ops/gathernd_test.py +++ b/model-optimizer/unit_tests/extensions/ops/gathernd_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.gathernd import GatherND from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'data': {'kind': 'op'}, 'data_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/grn_test.py b/model-optimizer/unit_tests/extensions/ops/grn_test.py similarity index 96% rename from model-optimizer/extensions/ops/grn_test.py rename to model-optimizer/unit_tests/extensions/ops/grn_test.py index 977560977a8..01b3ead0994 100644 --- a/model-optimizer/extensions/ops/grn_test.py +++ b/model-optimizer/unit_tests/extensions/ops/grn_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.elemental import copy_shape_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'grn': {'type': 'GRN', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/instance_normalization_test.py b/model-optimizer/unit_tests/extensions/ops/instance_normalization_test.py similarity index 100% rename from model-optimizer/extensions/ops/instance_normalization_test.py rename to model-optimizer/unit_tests/extensions/ops/instance_normalization_test.py diff --git a/model-optimizer/extensions/ops/interpolate_test.py b/model-optimizer/unit_tests/extensions/ops/interpolate_test.py similarity index 99% rename from model-optimizer/extensions/ops/interpolate_test.py rename to model-optimizer/unit_tests/extensions/ops/interpolate_test.py index 59f1f7f1c85..e89761d00c3 100644 --- a/model-optimizer/extensions/ops/interpolate_test.py +++ b/model-optimizer/unit_tests/extensions/ops/interpolate_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.interpolate import Interpolate from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph graph_node_attrs_without_axes = { diff --git a/model-optimizer/extensions/ops/merge_test.py b/model-optimizer/unit_tests/extensions/ops/merge_test.py similarity index 98% rename from model-optimizer/extensions/ops/merge_test.py rename to model-optimizer/unit_tests/extensions/ops/merge_test.py index bb7e3ce30dd..8a395cc178b 100644 --- a/model-optimizer/extensions/ops/merge_test.py +++ b/model-optimizer/unit_tests/extensions/ops/merge_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.merge import Merge from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs class TestMerge(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/non_max_suppression_test.py b/model-optimizer/unit_tests/extensions/ops/non_max_suppression_test.py similarity index 96% rename from model-optimizer/extensions/ops/non_max_suppression_test.py rename to model-optimizer/unit_tests/extensions/ops/non_max_suppression_test.py index 9e167c64f95..7c48e1d267f 100644 --- a/model-optimizer/extensions/ops/non_max_suppression_test.py +++ b/model-optimizer/unit_tests/extensions/ops/non_max_suppression_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.non_max_suppression import NonMaxSuppression from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect class TestNonMaxSuppressionInfer(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/normalize_test.py b/model-optimizer/unit_tests/extensions/ops/normalize_test.py similarity index 96% rename from model-optimizer/extensions/ops/normalize_test.py rename to model-optimizer/unit_tests/extensions/ops/normalize_test.py index 67bcb25f970..d4868296b3d 100644 --- a/model-optimizer/extensions/ops/normalize_test.py +++ b/model-optimizer/unit_tests/extensions/ops/normalize_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.elemental import copy_shape_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'norm': {'type': 'Normalize', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/one_hot_test.py b/model-optimizer/unit_tests/extensions/ops/one_hot_test.py similarity index 95% rename from model-optimizer/extensions/ops/one_hot_test.py rename to model-optimizer/unit_tests/extensions/ops/one_hot_test.py index d712d4e059a..973a540ff24 100644 --- a/model-optimizer/extensions/ops/one_hot_test.py +++ b/model-optimizer/unit_tests/extensions/ops/one_hot_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.one_hot import OneHot from mo.front.common.partial_infer.utils import int64_array, float_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, connect +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, connect def generate_nodes(data, axis=-1, depth=4, on_value=1., off_value=0.): diff --git a/model-optimizer/extensions/ops/priorbox_clustered_test.py b/model-optimizer/unit_tests/extensions/ops/priorbox_clustered_test.py similarity index 98% rename from model-optimizer/extensions/ops/priorbox_clustered_test.py rename to model-optimizer/unit_tests/extensions/ops/priorbox_clustered_test.py index b28759bb524..7a8df5aa8ed 100644 --- a/model-optimizer/extensions/ops/priorbox_clustered_test.py +++ b/model-optimizer/unit_tests/extensions/ops/priorbox_clustered_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.priorbox_clustered import PriorBoxClusteredOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'value': None, 'kind': 'data'}, 'node_2': {'type': 'Identity', 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/priorbox_test.py b/model-optimizer/unit_tests/extensions/ops/priorbox_test.py similarity index 99% rename from model-optimizer/extensions/ops/priorbox_test.py rename to model-optimizer/unit_tests/extensions/ops/priorbox_test.py index a0a7010fd77..a5b7601d7bd 100644 --- a/model-optimizer/extensions/ops/priorbox_test.py +++ b/model-optimizer/unit_tests/extensions/ops/priorbox_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.priorbox import PriorBoxOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'value': None, 'kind': 'data'}, 'pb': {'type': 'PriorBox', 'value': None, 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/proposal_test.py b/model-optimizer/unit_tests/extensions/ops/proposal_test.py similarity index 98% rename from model-optimizer/extensions/ops/proposal_test.py rename to model-optimizer/unit_tests/extensions/ops/proposal_test.py index a4feb8f6f94..e3a197ef3b3 100644 --- a/model-optimizer/extensions/ops/proposal_test.py +++ b/model-optimizer/unit_tests/extensions/ops/proposal_test.py @@ -7,7 +7,7 @@ from extensions.ops.proposal import ProposalOp from mo.front.common.extractors.utils import layout_attrs from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'proposal_input': {'kind': 'data', 'shape': None, 'value': None}, 'proposal': {'type': 'Proposal', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/psroipooling_test.py b/model-optimizer/unit_tests/extensions/ops/psroipooling_test.py similarity index 98% rename from model-optimizer/extensions/ops/psroipooling_test.py rename to model-optimizer/unit_tests/extensions/ops/psroipooling_test.py index 2b9cad7838d..6f552752316 100644 --- a/model-optimizer/extensions/ops/psroipooling_test.py +++ b/model-optimizer/unit_tests/extensions/ops/psroipooling_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.psroipooling import PSROIPoolingOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'node_2': {'type': 'Identity', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/quantize_test.py b/model-optimizer/unit_tests/extensions/ops/quantize_test.py similarity index 99% rename from model-optimizer/extensions/ops/quantize_test.py rename to model-optimizer/unit_tests/extensions/ops/quantize_test.py index 65d4f2dd336..18630f95c70 100644 --- a/model-optimizer/extensions/ops/quantize_test.py +++ b/model-optimizer/unit_tests/extensions/ops/quantize_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.fakequantize import FakeQuantize, broadcastable from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestBroadcastable(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/regionyolo_test.py b/model-optimizer/unit_tests/extensions/ops/regionyolo_test.py similarity index 99% rename from model-optimizer/extensions/ops/regionyolo_test.py rename to model-optimizer/unit_tests/extensions/ops/regionyolo_test.py index 9ebd2045b1f..64409535dac 100644 --- a/model-optimizer/extensions/ops/regionyolo_test.py +++ b/model-optimizer/unit_tests/extensions/ops/regionyolo_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.regionyolo import RegionYoloOp from mo.front.common.extractors.utils import layout_attrs from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'region': {'type': 'RegionYolo', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/reorgyolo_test.py b/model-optimizer/unit_tests/extensions/ops/reorgyolo_test.py similarity index 97% rename from model-optimizer/extensions/ops/reorgyolo_test.py rename to model-optimizer/unit_tests/extensions/ops/reorgyolo_test.py index b21a9336281..1a3f077dfa9 100644 --- a/model-optimizer/extensions/ops/reorgyolo_test.py +++ b/model-optimizer/unit_tests/extensions/ops/reorgyolo_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.reorgyolo import ReorgYoloOp from mo.front.common.extractors.utils import layout_attrs from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'reorg': {'type': 'ReorgYolo', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/scatter_test.py b/model-optimizer/unit_tests/extensions/ops/scatter_test.py similarity index 95% rename from model-optimizer/extensions/ops/scatter_test.py rename to model-optimizer/unit_tests/extensions/ops/scatter_test.py index a653140d9bb..6d80ec443cd 100644 --- a/model-optimizer/extensions/ops/scatter_test.py +++ b/model-optimizer/unit_tests/extensions/ops/scatter_test.py @@ -9,8 +9,7 @@ from generator import generator, generate from extensions.ops.scatter import ScatterElementsUpdate from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, connect, \ - valued_const_with_data +from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, valued_const_with_data @generator diff --git a/model-optimizer/extensions/ops/scatternd_test.py b/model-optimizer/unit_tests/extensions/ops/scatternd_test.py similarity index 99% rename from model-optimizer/extensions/ops/scatternd_test.py rename to model-optimizer/unit_tests/extensions/ops/scatternd_test.py index a53b020202c..f3f5a92bac0 100644 --- a/model-optimizer/extensions/ops/scatternd_test.py +++ b/model-optimizer/unit_tests/extensions/ops/scatternd_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.scatternd import ScatterNDUpdate from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'input': {'shape': None, 'value': None, 'kind': 'data'}, 'indices': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/select_test.py b/model-optimizer/unit_tests/extensions/ops/select_test.py similarity index 99% rename from model-optimizer/extensions/ops/select_test.py rename to model-optimizer/unit_tests/extensions/ops/select_test.py index 516dcaa71d7..fb12477f033 100644 --- a/model-optimizer/extensions/ops/select_test.py +++ b/model-optimizer/unit_tests/extensions/ops/select_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.select import Select from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_attrs @generator diff --git a/model-optimizer/extensions/ops/simplernms_test.py b/model-optimizer/unit_tests/extensions/ops/simplernms_test.py similarity index 97% rename from model-optimizer/extensions/ops/simplernms_test.py rename to model-optimizer/unit_tests/extensions/ops/simplernms_test.py index eabb6f09c1e..1301a7532cb 100644 --- a/model-optimizer/extensions/ops/simplernms_test.py +++ b/model-optimizer/unit_tests/extensions/ops/simplernms_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.simplernms import SimplerNMSOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'SimplerNMS_1': {'type': 'SimplerNMS', 'kind': 'op'}, 'node_1': {'type': 'Identity', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/slice_like_test.py b/model-optimizer/unit_tests/extensions/ops/slice_like_test.py similarity index 98% rename from model-optimizer/extensions/ops/slice_like_test.py rename to model-optimizer/unit_tests/extensions/ops/slice_like_test.py index 92ffa057d79..d178a488b4c 100644 --- a/model-optimizer/extensions/ops/slice_like_test.py +++ b/model-optimizer/unit_tests/extensions/ops/slice_like_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.slice_like import SliceLike from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'input': {'kind': 'op', 'op': 'Const'}, diff --git a/model-optimizer/extensions/ops/space_to_depth_test.py b/model-optimizer/unit_tests/extensions/ops/space_to_depth_test.py similarity index 95% rename from model-optimizer/extensions/ops/space_to_depth_test.py rename to model-optimizer/unit_tests/extensions/ops/space_to_depth_test.py index 7f9c4716ee2..db8da1268ff 100644 --- a/model-optimizer/extensions/ops/space_to_depth_test.py +++ b/model-optimizer/unit_tests/extensions/ops/space_to_depth_test.py @@ -6,7 +6,7 @@ import numpy as np from extensions.ops.space_to_depth import SpaceToDepth from mo.graph.graph import Node from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { 'in_data_node': {'value': None, 'kind': 'data', 'shape': np.array([1, 2048, 1152, 64])}, diff --git a/model-optimizer/extensions/ops/sparse_fill_empty_rows_test.py b/model-optimizer/unit_tests/extensions/ops/sparse_fill_empty_rows_test.py similarity index 99% rename from model-optimizer/extensions/ops/sparse_fill_empty_rows_test.py rename to model-optimizer/unit_tests/extensions/ops/sparse_fill_empty_rows_test.py index 14fa6d26735..ea26404983e 100644 --- a/model-optimizer/extensions/ops/sparse_fill_empty_rows_test.py +++ b/model-optimizer/unit_tests/extensions/ops/sparse_fill_empty_rows_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.sparse_fill_empty_rows import SparseFillEmptyRows from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'input_indices': {'shape': None, 'value': None, 'kind': 'data'}, 'input_values': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/sparse_reshape_test.py b/model-optimizer/unit_tests/extensions/ops/sparse_reshape_test.py similarity index 98% rename from model-optimizer/extensions/ops/sparse_reshape_test.py rename to model-optimizer/unit_tests/extensions/ops/sparse_reshape_test.py index 26927ae7153..7f16d842397 100644 --- a/model-optimizer/extensions/ops/sparse_reshape_test.py +++ b/model-optimizer/unit_tests/extensions/ops/sparse_reshape_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.sparse_reshape import SparseReshape from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'input_indices': {'shape': None, 'value': None, 'kind': 'data'}, 'input_shape': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/sparse_segment_mean_test.py b/model-optimizer/unit_tests/extensions/ops/sparse_segment_mean_test.py similarity index 98% rename from model-optimizer/extensions/ops/sparse_segment_mean_test.py rename to model-optimizer/unit_tests/extensions/ops/sparse_segment_mean_test.py index 44de3a95f76..d847d52cc26 100644 --- a/model-optimizer/extensions/ops/sparse_segment_mean_test.py +++ b/model-optimizer/unit_tests/extensions/ops/sparse_segment_mean_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.sparse_segment_mean import SparseSegmentMean from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # graph 1 nodes_attributes1 = {'input_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/sparse_segment_sqrtn_test.py b/model-optimizer/unit_tests/extensions/ops/sparse_segment_sqrtn_test.py similarity index 98% rename from model-optimizer/extensions/ops/sparse_segment_sqrtn_test.py rename to model-optimizer/unit_tests/extensions/ops/sparse_segment_sqrtn_test.py index fd7c23577e8..01db696441f 100644 --- a/model-optimizer/extensions/ops/sparse_segment_sqrtn_test.py +++ b/model-optimizer/unit_tests/extensions/ops/sparse_segment_sqrtn_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.sparse_segment_sqrtn import SparseSegmentSqrtN from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # graph 1 nodes_attributes1 = {'input_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/sparse_segment_sum_test.py b/model-optimizer/unit_tests/extensions/ops/sparse_segment_sum_test.py similarity index 98% rename from model-optimizer/extensions/ops/sparse_segment_sum_test.py rename to model-optimizer/unit_tests/extensions/ops/sparse_segment_sum_test.py index b28b83b12af..d42fd398a8f 100644 --- a/model-optimizer/extensions/ops/sparse_segment_sum_test.py +++ b/model-optimizer/unit_tests/extensions/ops/sparse_segment_sum_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.sparse_segment_sum import SparseSegmentSum from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # graph 1 nodes_attributes1 = {'input_data': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/spatial_transformer_test.py b/model-optimizer/unit_tests/extensions/ops/spatial_transformer_test.py similarity index 98% rename from model-optimizer/extensions/ops/spatial_transformer_test.py rename to model-optimizer/unit_tests/extensions/ops/spatial_transformer_test.py index 2c48b9edb99..93b6f282163 100644 --- a/model-optimizer/extensions/ops/spatial_transformer_test.py +++ b/model-optimizer/unit_tests/extensions/ops/spatial_transformer_test.py @@ -7,7 +7,7 @@ import numpy as np from extensions.ops.spatial_transformer import SpatialTransformOp from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'node_2': {'type': 'Identity', 'kind': 'op'}, diff --git a/model-optimizer/extensions/ops/split_test.py b/model-optimizer/unit_tests/extensions/ops/split_test.py similarity index 99% rename from model-optimizer/extensions/ops/split_test.py rename to model-optimizer/unit_tests/extensions/ops/split_test.py index c5673e93575..0ab4f40d0e3 100644 --- a/model-optimizer/extensions/ops/split_test.py +++ b/model-optimizer/unit_tests/extensions/ops/split_test.py @@ -9,7 +9,7 @@ from extensions.ops.split import AttributedSplit, AttributedVariadicSplit from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestSplitOp(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/switch_test.py b/model-optimizer/unit_tests/extensions/ops/switch_test.py similarity index 99% rename from model-optimizer/extensions/ops/switch_test.py rename to model-optimizer/unit_tests/extensions/ops/switch_test.py index ad7a66861b7..68c196685f4 100644 --- a/model-optimizer/extensions/ops/switch_test.py +++ b/model-optimizer/unit_tests/extensions/ops/switch_test.py @@ -9,7 +9,7 @@ import numpy as np from extensions.ops.switch import Switch from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph_with_edge_attrs, build_graph_with_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs, build_graph_with_attrs class TestSwitch(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/topk_test.py b/model-optimizer/unit_tests/extensions/ops/topk_test.py similarity index 96% rename from model-optimizer/extensions/ops/topk_test.py rename to model-optimizer/unit_tests/extensions/ops/topk_test.py index a403f133e59..b1123686453 100644 --- a/model-optimizer/extensions/ops/topk_test.py +++ b/model-optimizer/unit_tests/extensions/ops/topk_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.topk import TopK from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect class TestTopKInfer(unittest.TestCase): diff --git a/model-optimizer/extensions/ops/transpose_test.py b/model-optimizer/unit_tests/extensions/ops/transpose_test.py similarity index 98% rename from model-optimizer/extensions/ops/transpose_test.py rename to model-optimizer/unit_tests/extensions/ops/transpose_test.py index dce4ec91fbf..35e4beab719 100644 --- a/model-optimizer/extensions/ops/transpose_test.py +++ b/model-optimizer/unit_tests/extensions/ops/transpose_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from extensions.ops.transpose import Transpose from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph input_shape = np.array([1, 3, 224, 224]) diff --git a/model-optimizer/extensions/ops/unique_test.py b/model-optimizer/unit_tests/extensions/ops/unique_test.py similarity index 99% rename from model-optimizer/extensions/ops/unique_test.py rename to model-optimizer/unit_tests/extensions/ops/unique_test.py index 459bd2824f7..6452a50cc74 100644 --- a/model-optimizer/extensions/ops/unique_test.py +++ b/model-optimizer/unit_tests/extensions/ops/unique_test.py @@ -8,7 +8,7 @@ import numpy as np from extensions.ops.unique import Unique from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph # graph 1 with two outputs: uniques and indices nodes_attributes = {'input': {'shape': None, 'value': None, 'kind': 'data'}, diff --git a/model-optimizer/extensions/ops/upsample_test.py b/model-optimizer/unit_tests/extensions/ops/upsample_test.py similarity index 98% rename from model-optimizer/extensions/ops/upsample_test.py rename to model-optimizer/unit_tests/extensions/ops/upsample_test.py index 215c3c4cd68..2284463a7b5 100644 --- a/model-optimizer/extensions/ops/upsample_test.py +++ b/model-optimizer/unit_tests/extensions/ops/upsample_test.py @@ -4,11 +4,11 @@ import unittest import numpy as np +from generator import generator, generate from extensions.ops.upsample import UpsampleOp -from generator import generator, generate from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'upsample': {'type': 'Upsample', 'kind': 'op'}, diff --git a/model-optimizer/unit_tests/mo/__init__.py b/model-optimizer/unit_tests/mo/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/back/__init__.py b/model-optimizer/unit_tests/mo/back/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/back/ie_ir_ver_2/__init__.py b/model-optimizer/unit_tests/mo/back/ie_ir_ver_2/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/back/ie_ir_ver_2/emitter_test.py b/model-optimizer/unit_tests/mo/back/ie_ir_ver_2/emitter_test.py similarity index 100% rename from model-optimizer/mo/back/ie_ir_ver_2/emitter_test.py rename to model-optimizer/unit_tests/mo/back/ie_ir_ver_2/emitter_test.py diff --git a/model-optimizer/mo/bom_test.py b/model-optimizer/unit_tests/mo/bom_test.py similarity index 93% rename from model-optimizer/mo/bom_test.py rename to model-optimizer/unit_tests/mo/bom_test.py index a9325edbaf5..0bb7118e2a0 100644 --- a/model-optimizer/mo/bom_test.py +++ b/model-optimizer/unit_tests/mo/bom_test.py @@ -8,15 +8,11 @@ import unittest from itertools import islice dir_patterns_to_skip = ['.*__pycache__.*'] -file_patterns_to_skip = ['.*_test\\.py$', - '.*\\.DS_Store$', +file_patterns_to_skip = ['.*\\.DS_Store$', '.*\\.swp', '.*\\.pyc$'] -full_name_patterns_to_skip = ['^mo/utils/unittest/.*\.py$', - '^mo/utils/convert.py$', +full_name_patterns_to_skip = ['^mo/utils/convert.py$', '^extensions/front/caffe/CustomLayersMapping.xml$', - '^mo/utils/unittest/test_data/.*\.xml$', - '^mo/utils/unittest/test_data/.*\.bin$', ] if platform.system() == 'Windows': full_name_patterns_to_skip = [i.replace('/', '\\\\') for i in full_name_patterns_to_skip] @@ -32,7 +28,7 @@ class TestBOMFile(unittest.TestCase): def setUpClass(cls): cls.existing_files = [] cur_path = os.path.join(os.path.realpath(__file__), os.pardir) - cls.output_dir = os.path.abspath(os.path.join(cur_path, os.pardir)) + cls.output_dir = os.path.abspath(os.path.join(cur_path, os.pardir, os.pardir)) with open(os.path.join(cls.output_dir, 'automation', 'package_BOM.txt'), 'r') as bom_file: if platform.system() == 'Windows': cls.existing_files = [name.rstrip().replace('/', '\\') for name in bom_file.readlines()] @@ -72,7 +68,6 @@ class TestBOMFile(unittest.TestCase): def test_bom_does_not_contain_unittest_files(self): for file_name in self.existing_files: self.assertFalse(file_name.endswith('_test.py'), 'BOM file contains test file {}'.format(file_name)) - def test_deleted_files_still_stored_in_bom(self): deleted = list() diff --git a/model-optimizer/unit_tests/mo/front/__init__.py b/model-optimizer/unit_tests/mo/front/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/front/caffe/__init__.py b/model-optimizer/unit_tests/mo/front/caffe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/caffe/custom_layers_mapping_test.py b/model-optimizer/unit_tests/mo/front/caffe/custom_layers_mapping_test.py similarity index 100% rename from model-optimizer/mo/front/caffe/custom_layers_mapping_test.py rename to model-optimizer/unit_tests/mo/front/caffe/custom_layers_mapping_test.py diff --git a/model-optimizer/mo/front/caffe/extractor_test.py b/model-optimizer/unit_tests/mo/front/caffe/extractor_test.py similarity index 97% rename from model-optimizer/mo/front/caffe/extractor_test.py rename to model-optimizer/unit_tests/mo/front/caffe/extractor_test.py index 23bff3237dc..f2183535b63 100644 --- a/model-optimizer/mo/front/caffe/extractor_test.py +++ b/model-optimizer/unit_tests/mo/front/caffe/extractor_test.py @@ -7,8 +7,8 @@ from unittest.mock import patch from mo.front.caffe.extractor import check_phase, register_caffe_python_extractor from mo.front.extractor import CaffePythonFrontExtractorOp from mo.graph.graph import Node -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, 'node_2': {'type': 'Identity', 'kind': 'op'}} diff --git a/model-optimizer/unit_tests/mo/front/caffe/extractors/__init__.py b/model-optimizer/unit_tests/mo/front/caffe/extractors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/caffe/extractors/utils_test.py b/model-optimizer/unit_tests/mo/front/caffe/extractors/utils_test.py similarity index 97% rename from model-optimizer/mo/front/caffe/extractors/utils_test.py rename to model-optimizer/unit_tests/mo/front/caffe/extractors/utils_test.py index fe420f267b2..8f73aa15b20 100644 --- a/model-optimizer/mo/front/caffe/extractors/utils_test.py +++ b/model-optimizer/unit_tests/mo/front/caffe/extractors/utils_test.py @@ -7,7 +7,7 @@ from unittest.mock import patch, call import numpy as np from mo.front.caffe.extractors.utils import weights_biases, embed_input, get_canonical_axis_index -from mo.utils.unittest.extractors import FakeModelLayer +from unit_tests.utils.extractors import FakeModelLayer class TestWeightsBiases(unittest.TestCase): diff --git a/model-optimizer/mo/front/caffe/loader_test.py b/model-optimizer/unit_tests/mo/front/caffe/loader_test.py similarity index 100% rename from model-optimizer/mo/front/caffe/loader_test.py rename to model-optimizer/unit_tests/mo/front/caffe/loader_test.py diff --git a/model-optimizer/mo/front/caffe/python_layer_extractor_test.py b/model-optimizer/unit_tests/mo/front/caffe/python_layer_extractor_test.py similarity index 94% rename from model-optimizer/mo/front/caffe/python_layer_extractor_test.py rename to model-optimizer/unit_tests/mo/front/caffe/python_layer_extractor_test.py index 78afb932afd..057faaacce4 100644 --- a/model-optimizer/mo/front/caffe/python_layer_extractor_test.py +++ b/model-optimizer/unit_tests/mo/front/caffe/python_layer_extractor_test.py @@ -6,8 +6,8 @@ import unittest from mo.front.caffe.python_layer_extractor import PythonFrontExtractorOp from mo.front.extractor import CaffePythonFrontExtractorOp from mo.graph.graph import Node -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import FakeNode +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import FakeNode class FakePythonProtoLayer: diff --git a/model-optimizer/unit_tests/mo/front/common/__init__.py b/model-optimizer/unit_tests/mo/front/common/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/common/layout_test.py b/model-optimizer/unit_tests/mo/front/common/layout_test.py similarity index 100% rename from model-optimizer/mo/front/common/layout_test.py rename to model-optimizer/unit_tests/mo/front/common/layout_test.py diff --git a/model-optimizer/unit_tests/mo/front/common/partial_infer/__init__.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/common/partial_infer/caffe_fallback_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/caffe_fallback_test.py similarity index 96% rename from model-optimizer/mo/front/common/partial_infer/caffe_fallback_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/caffe_fallback_test.py index a1a9646e548..c1c434f236d 100644 --- a/model-optimizer/mo/front/common/partial_infer/caffe_fallback_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/caffe_fallback_test.py @@ -7,8 +7,8 @@ from unittest.mock import MagicMock import numpy as np from mo.front.common.partial_infer.caffe_fallback import build_net -from mo.utils.unittest.extractors import FakeMultiParam, FakeValue -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.extractors import FakeMultiParam, FakeValue +from unit_tests.utils.graph import build_graph class Net: diff --git a/model-optimizer/mo/front/common/partial_infer/concat_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/concat_test.py similarity index 98% rename from model-optimizer/mo/front/common/partial_infer/concat_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/concat_test.py index 4caa598ef43..a5a2fa0d78a 100644 --- a/model-optimizer/mo/front/common/partial_infer/concat_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/concat_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.concat import concat_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'kind': 'data', 'value': None}, 'node_2': {'kind': 'data', 'value': None}, diff --git a/model-optimizer/mo/front/common/partial_infer/crop_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/crop_test.py similarity index 99% rename from model-optimizer/mo/front/common/partial_infer/crop_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/crop_test.py index 4f7f902aff0..00d43fa20aa 100644 --- a/model-optimizer/mo/front/common/partial_infer/crop_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/crop_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.crop import crop_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'value': None, 'kind': 'data'}, 'node_2': {'value': None, 'kind': 'data'}, diff --git a/model-optimizer/mo/front/common/partial_infer/elemental_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/elemental_test.py similarity index 100% rename from model-optimizer/mo/front/common/partial_infer/elemental_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/elemental_test.py diff --git a/model-optimizer/mo/front/common/partial_infer/eltwise_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/eltwise_test.py similarity index 99% rename from model-optimizer/mo/front/common/partial_infer/eltwise_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/eltwise_test.py index 755509b8ec5..8734433115f 100644 --- a/model-optimizer/mo/front/common/partial_infer/eltwise_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/eltwise_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.eltwise import eltwise_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'value': 2, 'kind': 'data'}, 'node_2': {'value': 3, 'kind': 'data'}, diff --git a/model-optimizer/mo/front/common/partial_infer/multi_box_detection_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_detection_test.py similarity index 99% rename from model-optimizer/mo/front/common/partial_infer/multi_box_detection_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_detection_test.py index b96e1b02744..fcaa9f6cdaf 100644 --- a/model-optimizer/mo/front/common/partial_infer/multi_box_detection_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_detection_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.multi_box_detection import multi_box_detection_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'value': None, 'kind': 'data'}, 'node_2': {'value': None, 'kind': 'data'}, diff --git a/model-optimizer/mo/front/common/partial_infer/multi_box_prior_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_prior_test.py similarity index 97% rename from model-optimizer/mo/front/common/partial_infer/multi_box_prior_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_prior_test.py index 10adde2eaba..42604c2c34f 100644 --- a/model-optimizer/mo/front/common/partial_infer/multi_box_prior_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/multi_box_prior_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.multi_box_prior import multi_box_prior_infer_mxnet from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'value': None, 'kind': 'data'}, 'node_2': {'value': None, 'kind': 'data'}, diff --git a/model-optimizer/mo/front/common/partial_infer/roipooling_test.py b/model-optimizer/unit_tests/mo/front/common/partial_infer/roipooling_test.py similarity index 98% rename from model-optimizer/mo/front/common/partial_infer/roipooling_test.py rename to model-optimizer/unit_tests/mo/front/common/partial_infer/roipooling_test.py index fc21b6c32ef..2f6c83979db 100644 --- a/model-optimizer/mo/front/common/partial_infer/roipooling_test.py +++ b/model-optimizer/unit_tests/mo/front/common/partial_infer/roipooling_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.roipooling import roipooling_infer from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'kind': 'data'}, 'node_2': {'kind': 'data'}, diff --git a/model-optimizer/mo/front/extractor_test.py b/model-optimizer/unit_tests/mo/front/extractor_test.py similarity index 99% rename from model-optimizer/mo/front/extractor_test.py rename to model-optimizer/unit_tests/mo/front/extractor_test.py index 463d344d991..c7fdbc5079c 100644 --- a/model-optimizer/mo/front/extractor_test.py +++ b/model-optimizer/unit_tests/mo/front/extractor_test.py @@ -13,8 +13,8 @@ from mo.front.extractor import spatial_attr_getter, add_input_ops, attr_getter, from mo.graph.graph import Node from mo.utils.error import Error from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.extractors import FakeMultiParam -from mo.utils.unittest.graph import build_graph, build_graph_with_edge_attrs, build_graph_with_attrs +from unit_tests.utils.extractors import FakeMultiParam +from unit_tests.utils.graph import build_graph, build_graph_with_edge_attrs, build_graph_with_attrs class FakePythonParam: diff --git a/model-optimizer/unit_tests/mo/front/kaldi/__init__.py b/model-optimizer/unit_tests/mo/front/kaldi/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/front/kaldi/extractors/__init__.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/kaldi/extractors/add_shift_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/add_shift_ext_test.py similarity index 90% rename from model-optimizer/mo/front/kaldi/extractors/add_shift_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/add_shift_ext_test.py index 8e58a1095fd..4d04112d8b4 100644 --- a/model-optimizer/mo/front/kaldi/extractors/add_shift_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/add_shift_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from mo.front.kaldi.extractors.add_shift_ext import AddShiftFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.scale_shift import ScaleShiftOp +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class AddShiftFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/affine_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_component_ext_test.py similarity index 87% rename from model-optimizer/mo/front/kaldi/extractors/affine_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_component_ext_test.py index 032d22c954d..cbe7bb4f2d8 100644 --- a/model-optimizer/mo/front/kaldi/extractors/affine_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_component_ext_test.py @@ -5,9 +5,9 @@ import numpy as np from extensions.ops.MatMul import FullyConnected from mo.front.kaldi.extractors.affine_transform_ext import AffineTransformFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class AffineComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/affine_transform_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_transform_ext_test.py similarity index 87% rename from model-optimizer/mo/front/kaldi/extractors/affine_transform_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_transform_ext_test.py index 8c2cb06e955..41acd914cf6 100644 --- a/model-optimizer/mo/front/kaldi/extractors/affine_transform_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/affine_transform_ext_test.py @@ -5,9 +5,9 @@ import numpy as np from extensions.ops.MatMul import FullyConnected from mo.front.kaldi.extractors.affine_transform_ext import AffineTransformFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class AffineTransformFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/batchnorm_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/batchnorm_component_ext_test.py similarity index 92% rename from model-optimizer/mo/front/kaldi/extractors/batchnorm_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/batchnorm_component_ext_test.py index 380bdd341cf..25b05a02a7d 100644 --- a/model-optimizer/mo/front/kaldi/extractors/batchnorm_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/batchnorm_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from mo.front.kaldi.extractors.batchnorm_component_ext import BatchNormComponentFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.scale_shift import ScaleShiftOp +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class BatchNormComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/bias_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/bias_component_ext_test.py similarity index 87% rename from model-optimizer/mo/front/kaldi/extractors/bias_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/bias_component_ext_test.py index c604dc75033..e8fd9a5e9cc 100644 --- a/model-optimizer/mo/front/kaldi/extractors/bias_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/bias_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from mo.front.kaldi.extractors.bias_component_ext import FixedBiasComponentFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.scale_shift import ScaleShiftOp +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class FixedBiasComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/common_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/common_ext_test.py similarity index 97% rename from model-optimizer/mo/front/kaldi/extractors/common_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/common_ext_test.py index 188b755e38b..c27170bcb07 100644 --- a/model-optimizer/mo/front/kaldi/extractors/common_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/common_ext_test.py @@ -5,9 +5,9 @@ import unittest import numpy as np -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.graph.graph import Node, Graph -from mo.utils.unittest.graph import build_graph +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading +from unit_tests.utils.graph import build_graph class KaldiFrontExtractorTest(unittest.TestCase): diff --git a/model-optimizer/mo/front/kaldi/extractors/concat_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/concat_ext_test.py similarity index 84% rename from model-optimizer/mo/front/kaldi/extractors/concat_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/concat_ext_test.py index 52ce5fca247..f5055048b4c 100644 --- a/model-optimizer/mo/front/kaldi/extractors/concat_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/concat_ext_test.py @@ -1,10 +1,10 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.concat_ext import ConcatFrontExtractor from mo.ops.convolution import Convolution from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest class ConcatFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/convolutional_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/convolutional_component_ext_test.py similarity index 92% rename from model-optimizer/mo/front/kaldi/extractors/convolutional_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/convolutional_component_ext_test.py index 5bc1e5763d7..ea236da6cb8 100644 --- a/model-optimizer/mo/front/kaldi/extractors/convolutional_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/convolutional_component_ext_test.py @@ -3,11 +3,11 @@ import numpy as np -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.convolutional_component_ext import ConvolutionalComponentFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.convolution import Convolution from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class ConvolutionalComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py similarity index 87% rename from model-optimizer/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py index ec2dac8080d..18e1ac25a17 100644 --- a/model-optimizer/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/fixed_affine_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from extensions.ops.MatMul import FullyConnected -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.fixed_affine_component_ext import FixedAffineComponentFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class FixedAffineComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/max_pooling_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/max_pooling_ext_test.py similarity index 89% rename from model-optimizer/mo/front/kaldi/extractors/max_pooling_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/max_pooling_ext_test.py index a139ad330f0..fdc6b9cb627 100644 --- a/model-optimizer/mo/front/kaldi/extractors/max_pooling_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/max_pooling_ext_test.py @@ -1,12 +1,11 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest - from mo.front.kaldi.extractors.max_pooling_ext import MaxPoolingComponentFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.pooling import Pooling +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class MaxPoolingComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/memoryoffset_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/memoryoffset_ext_test.py similarity index 90% rename from model-optimizer/mo/front/kaldi/extractors/memoryoffset_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/memoryoffset_ext_test.py index a95ea9b4773..cd6c9fef981 100644 --- a/model-optimizer/mo/front/kaldi/extractors/memoryoffset_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/memoryoffset_ext_test.py @@ -1,10 +1,10 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.memoryoffset_ext import MemoryOffsetFrontExtractor from mo.ops.memoryoffset import MemoryOffset from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest class MemoryOffsetFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/normalize_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/normalize_component_ext_test.py similarity index 86% rename from model-optimizer/mo/front/kaldi/extractors/normalize_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/normalize_component_ext_test.py index 8f2732d9a32..544d700c7e9 100644 --- a/model-optimizer/mo/front/kaldi/extractors/normalize_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/normalize_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from extensions.ops.normalize import NormalizeOp -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.normalize_component_ext import NormalizeComponentFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class NormalizeComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/pnorm_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/pnorm_component_ext_test.py similarity index 85% rename from model-optimizer/mo/front/kaldi/extractors/pnorm_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/pnorm_component_ext_test.py index 2abcda4491e..819f2d51b32 100644 --- a/model-optimizer/mo/front/kaldi/extractors/pnorm_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/pnorm_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from extensions.ops.pnorm import PNormOp -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.pnorm_component_ext import PNormComponentFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class PNormComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/rescale_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/rescale_ext_test.py similarity index 89% rename from model-optimizer/mo/front/kaldi/extractors/rescale_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/rescale_ext_test.py index 28edd99b9dd..ba98d6582e7 100644 --- a/model-optimizer/mo/front/kaldi/extractors/rescale_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/rescale_ext_test.py @@ -3,11 +3,11 @@ import numpy as np -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest from mo.front.kaldi.extractors.rescale_ext import RescaleFrontExtractor -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.scale_shift import ScaleShiftOp +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class RescaleFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/mo/front/kaldi/extractors/scale_component_ext_test.py b/model-optimizer/unit_tests/mo/front/kaldi/extractors/scale_component_ext_test.py similarity index 87% rename from model-optimizer/mo/front/kaldi/extractors/scale_component_ext_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/extractors/scale_component_ext_test.py index eb7b022c8f6..86aed2ac1ab 100644 --- a/model-optimizer/mo/front/kaldi/extractors/scale_component_ext_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/extractors/scale_component_ext_test.py @@ -4,10 +4,10 @@ import numpy as np from mo.front.kaldi.extractors.scale_component_ext import FixedScaleComponentFrontExtractor -from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest -from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading from mo.ops.op import Op from mo.ops.scale_shift import ScaleShiftOp +from unit_tests.mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest +from unit_tests.mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading class FixedScaleComponentFrontExtractorTest(KaldiFrontExtractorTest): diff --git a/model-optimizer/unit_tests/mo/front/kaldi/loader/__init__.py b/model-optimizer/unit_tests/mo/front/kaldi/loader/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/kaldi/loader/loader_test.py b/model-optimizer/unit_tests/mo/front/kaldi/loader/loader_test.py similarity index 99% rename from model-optimizer/mo/front/kaldi/loader/loader_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/loader/loader_test.py index 43b20f2ea36..1504017fc02 100644 --- a/model-optimizer/mo/front/kaldi/loader/loader_test.py +++ b/model-optimizer/unit_tests/mo/front/kaldi/loader/loader_test.py @@ -10,7 +10,7 @@ import numpy as np from mo.front.kaldi.loader.loader import load_topology_map, load_components from mo.graph.graph import Graph, Node from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestKaldiModelsLoading(unittest.TestCase): diff --git a/model-optimizer/mo/front/kaldi/loader/utils_test.py b/model-optimizer/unit_tests/mo/front/kaldi/loader/utils_test.py similarity index 100% rename from model-optimizer/mo/front/kaldi/loader/utils_test.py rename to model-optimizer/unit_tests/mo/front/kaldi/loader/utils_test.py diff --git a/model-optimizer/unit_tests/mo/front/mxnet/__init__.py b/model-optimizer/unit_tests/mo/front/mxnet/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/front/mxnet/extractors/__init__.py b/model-optimizer/unit_tests/mo/front/mxnet/extractors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/mxnet/extractors/multibox_prior_test.py b/model-optimizer/unit_tests/mo/front/mxnet/extractors/multibox_prior_test.py similarity index 100% rename from model-optimizer/mo/front/mxnet/extractors/multibox_prior_test.py rename to model-optimizer/unit_tests/mo/front/mxnet/extractors/multibox_prior_test.py diff --git a/model-optimizer/mo/front/mxnet/extractors/relu_test.py b/model-optimizer/unit_tests/mo/front/mxnet/extractors/relu_test.py similarity index 95% rename from model-optimizer/mo/front/mxnet/extractors/relu_test.py rename to model-optimizer/unit_tests/mo/front/mxnet/extractors/relu_test.py index df903c894e4..743210b17bf 100644 --- a/model-optimizer/mo/front/mxnet/extractors/relu_test.py +++ b/model-optimizer/unit_tests/mo/front/mxnet/extractors/relu_test.py @@ -5,7 +5,7 @@ import unittest from mo.front.mxnet.extractors.relu import ReLUFrontExtractor from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestReluFrontExtractorOp(unittest.TestCase): diff --git a/model-optimizer/mo/front/mxnet/extractors/slice_axis_test.py b/model-optimizer/unit_tests/mo/front/mxnet/extractors/slice_axis_test.py similarity index 98% rename from model-optimizer/mo/front/mxnet/extractors/slice_axis_test.py rename to model-optimizer/unit_tests/mo/front/mxnet/extractors/slice_axis_test.py index 78596bc7066..ee91b638f19 100644 --- a/model-optimizer/mo/front/mxnet/extractors/slice_axis_test.py +++ b/model-optimizer/unit_tests/mo/front/mxnet/extractors/slice_axis_test.py @@ -9,7 +9,7 @@ from mo.front.mxnet.extractors.slice_axis import mxnet_slice_axis_infer from mo.front.mxnet.extractors.slice_axis import slice_axis_ext from mo.front.mxnet.extractors.utils import AttrDictionary from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestMXNetSliceAxisExtractorOp(unittest.TestCase): diff --git a/model-optimizer/mo/front/mxnet/extractors/utils_test.py b/model-optimizer/unit_tests/mo/front/mxnet/extractors/utils_test.py similarity index 100% rename from model-optimizer/mo/front/mxnet/extractors/utils_test.py rename to model-optimizer/unit_tests/mo/front/mxnet/extractors/utils_test.py diff --git a/model-optimizer/mo/front/mxnet/loader_test.py b/model-optimizer/unit_tests/mo/front/mxnet/loader_test.py similarity index 100% rename from model-optimizer/mo/front/mxnet/loader_test.py rename to model-optimizer/unit_tests/mo/front/mxnet/loader_test.py diff --git a/model-optimizer/unit_tests/mo/front/tf/__init__.py b/model-optimizer/unit_tests/mo/front/tf/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/front/tf/extractors/__init__.py b/model-optimizer/unit_tests/mo/front/tf/extractors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/front/tf/extractors/concat_test.py b/model-optimizer/unit_tests/mo/front/tf/extractors/concat_test.py similarity index 90% rename from model-optimizer/mo/front/tf/extractors/concat_test.py rename to model-optimizer/unit_tests/mo/front/tf/extractors/concat_test.py index 576de3f2dfa..3ce99dd40b9 100644 --- a/model-optimizer/mo/front/tf/extractors/concat_test.py +++ b/model-optimizer/unit_tests/mo/front/tf/extractors/concat_test.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from mo.front.tf.extractors.concat import tf_concat_ext -from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass +from unit_tests.utils.extractors import PB, BaseExtractorsTestingClass class ConcatExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/mo/front/tf/extractors/identity_test.py b/model-optimizer/unit_tests/mo/front/tf/extractors/identity_test.py similarity index 89% rename from model-optimizer/mo/front/tf/extractors/identity_test.py rename to model-optimizer/unit_tests/mo/front/tf/extractors/identity_test.py index 022c49f2596..5ff3a0b6869 100644 --- a/model-optimizer/mo/front/tf/extractors/identity_test.py +++ b/model-optimizer/unit_tests/mo/front/tf/extractors/identity_test.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from mo.front.tf.extractors.identity import tf_identity_ext -from mo.utils.unittest.extractors import BaseExtractorsTestingClass +from unit_tests.utils.extractors import BaseExtractorsTestingClass class IdentityExtractorTest(BaseExtractorsTestingClass): diff --git a/model-optimizer/mo/front/tf/extractors/utils_test.py b/model-optimizer/unit_tests/mo/front/tf/extractors/utils_test.py similarity index 99% rename from model-optimizer/mo/front/tf/extractors/utils_test.py rename to model-optimizer/unit_tests/mo/front/tf/extractors/utils_test.py index 8024491fd4c..b2ba651fba2 100644 --- a/model-optimizer/mo/front/tf/extractors/utils_test.py +++ b/model-optimizer/unit_tests/mo/front/tf/extractors/utils_test.py @@ -8,7 +8,7 @@ import numpy as np from mo.front.common.partial_infer.utils import int64_array from mo.front.tf.extractors.utils import collect_tf_attrs, tf_tensor_content -from mo.utils.unittest.extractors import PB +from unit_tests.utils.extractors import PB class AttrParsingTest(unittest.TestCase): diff --git a/model-optimizer/mo/front/tf/loader_test.py b/model-optimizer/unit_tests/mo/front/tf/loader_test.py similarity index 100% rename from model-optimizer/mo/front/tf/loader_test.py rename to model-optimizer/unit_tests/mo/front/tf/loader_test.py diff --git a/model-optimizer/unit_tests/mo/graph/__init__.py b/model-optimizer/unit_tests/mo/graph/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/graph/connection_test.py b/model-optimizer/unit_tests/mo/graph/connection_test.py similarity index 99% rename from model-optimizer/mo/graph/connection_test.py rename to model-optimizer/unit_tests/mo/graph/connection_test.py index 067012252aa..ca22e3def70 100644 --- a/model-optimizer/mo/graph/connection_test.py +++ b/model-optimizer/unit_tests/mo/graph/connection_test.py @@ -5,7 +5,7 @@ import unittest from mo.graph.graph import Node, Graph from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph, regular_op +from unit_tests.utils.graph import build_graph, regular_op nodes = { **regular_op('input', {'type': 'Parameter'}), diff --git a/model-optimizer/mo/graph/graph_test.py b/model-optimizer/unit_tests/mo/graph/graph_test.py similarity index 99% rename from model-optimizer/mo/graph/graph_test.py rename to model-optimizer/unit_tests/mo/graph/graph_test.py index 8d82c0a06f1..4d8e5f4813c 100644 --- a/model-optimizer/mo/graph/graph_test.py +++ b/model-optimizer/unit_tests/mo/graph/graph_test.py @@ -6,11 +6,12 @@ import unittest import numpy as np from generator import generator, generate -from mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, set_edge_attribute_between_nodes +from mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, \ + set_edge_attribute_between_nodes from mo.ops.const import Const from mo.utils.error import Error from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes = { '0': {'name': 'input1', 'type': 'Identity', 'value': None, 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/mo/graph/port_test.py b/model-optimizer/unit_tests/mo/graph/port_test.py similarity index 98% rename from model-optimizer/mo/graph/port_test.py rename to model-optimizer/unit_tests/mo/graph/port_test.py index 2064eb77248..524e38dd33e 100644 --- a/model-optimizer/mo/graph/port_test.py +++ b/model-optimizer/unit_tests/mo/graph/port_test.py @@ -4,7 +4,7 @@ import unittest from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph, regular_op, valued_const_with_data, result, connect +from unit_tests.utils.graph import build_graph, regular_op, valued_const_with_data, result, connect nodes = { **regular_op('input', {'type': 'Parameter'}), diff --git a/model-optimizer/mo/main_test.py b/model-optimizer/unit_tests/mo/main_test.py similarity index 100% rename from model-optimizer/mo/main_test.py rename to model-optimizer/unit_tests/mo/main_test.py diff --git a/model-optimizer/unit_tests/mo/middle/__init__.py b/model-optimizer/unit_tests/mo/middle/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/unit_tests/mo/middle/passes/__init__.py b/model-optimizer/unit_tests/mo/middle/passes/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/middle/passes/convert_data_type_test.py b/model-optimizer/unit_tests/mo/middle/passes/convert_data_type_test.py similarity index 98% rename from model-optimizer/mo/middle/passes/convert_data_type_test.py rename to model-optimizer/unit_tests/mo/middle/passes/convert_data_type_test.py index 34ddaa1a86f..87fca118406 100644 --- a/model-optimizer/mo/middle/passes/convert_data_type_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/convert_data_type_test.py @@ -8,7 +8,7 @@ import numpy as np from mo.front.common.partial_infer.utils import int64_array from mo.middle.passes.convert_data_type import convert_blobs, SUPPORTED_DATA_TYPES from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'data_node': {'kind': 'data', 'value': None, 'shape': int64_array([5])}, 'op_node': { 'kind': 'op', 'op': 'Result'}} diff --git a/model-optimizer/mo/middle/passes/eliminate_test.py b/model-optimizer/unit_tests/mo/middle/passes/eliminate_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/eliminate_test.py rename to model-optimizer/unit_tests/mo/middle/passes/eliminate_test.py index 4d935609565..30ccfe9e19c 100644 --- a/model-optimizer/mo/middle/passes/eliminate_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/eliminate_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.graph.graph import Node from mo.middle.passes.eliminate import mark_output_reachable_nodes, mark_const_producer_nodes -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'placeholder_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, 'placeholder_2': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/unit_tests/mo/middle/passes/fusing/__init__.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/middle/passes/fusing/decomposition_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/decomposition_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/decomposition_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/decomposition_test.py index 8217fe12a3a..3d4050ec096 100644 --- a/model-optimizer/mo/middle/passes/fusing/decomposition_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/decomposition_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.middle.passes.fusing.decomposition import convert_scale_shift_to_mul_add, convert_batch_norm from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/mo/middle/passes/fusing/fuse_linear_ops_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_ops_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/fuse_linear_ops_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_ops_test.py index a85bedd9336..6626d61dba0 100644 --- a/model-optimizer/mo/middle/passes/fusing/fuse_linear_ops_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_ops_test.py @@ -9,7 +9,7 @@ from mo.front.common.partial_infer.eltwise import eltwise_infer from mo.graph.graph import Node from mo.middle.passes.fusing.fuse_linear_ops import _fuse_mul, fuse_linear_ops from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/mo/middle/passes/fusing/fuse_linear_seq_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_seq_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/fuse_linear_seq_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_seq_test.py index 8d10884a504..fa4012227aa 100644 --- a/model-optimizer/mo/middle/passes/fusing/fuse_linear_seq_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/fuse_linear_seq_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.middle.passes.fusing.fuse_linear_seq import fuse_mul_add_sequence from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/mo/middle/passes/fusing/helpers_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/helpers_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/helpers_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/helpers_test.py index 1cd97681abb..a95f25d5eb2 100644 --- a/model-optimizer/mo/middle/passes/fusing/helpers_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/helpers_test.py @@ -6,7 +6,7 @@ import unittest from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.middle.passes.fusing.helpers import forward_bfs, backward_bfs, get_next_operation, common_bfs -from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, connect, const, result, \ +from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, connect, result, \ valued_const_with_data, connect_data nodes_attributes = { diff --git a/model-optimizer/mo/middle/passes/fusing/mark_unfused_nodes_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/mark_unfused_nodes_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/mark_unfused_nodes_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/mark_unfused_nodes_test.py index 148863bcb04..b93f75a936f 100644 --- a/model-optimizer/mo/middle/passes/fusing/mark_unfused_nodes_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/mark_unfused_nodes_test.py @@ -6,7 +6,7 @@ import unittest import numpy as np from mo.middle.passes.fusing.mark_unfused_nodes import mark_unfused_nodes -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'placeholder_1': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'}, diff --git a/model-optimizer/mo/middle/passes/fusing/resnet_optimization_test.py b/model-optimizer/unit_tests/mo/middle/passes/fusing/resnet_optimization_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/fusing/resnet_optimization_test.py rename to model-optimizer/unit_tests/mo/middle/passes/fusing/resnet_optimization_test.py index db51878bb98..b7129db0b3a 100644 --- a/model-optimizer/mo/middle/passes/fusing/resnet_optimization_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/fusing/resnet_optimization_test.py @@ -11,7 +11,7 @@ from mo.middle.passes.fusing.resnet_optimization import stride_optimization from mo.ops.convolution import Convolution from mo.ops.pooling import Pooling from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph max_elt_lambda = lambda node: eltwise_infer(node, lambda a, b: np.maximum(a, b)) diff --git a/model-optimizer/mo/middle/passes/infer_test.py b/model-optimizer/unit_tests/mo/middle/passes/infer_test.py similarity index 99% rename from model-optimizer/mo/middle/passes/infer_test.py rename to model-optimizer/unit_tests/mo/middle/passes/infer_test.py index 1745e651775..02b48357f6a 100644 --- a/model-optimizer/mo/middle/passes/infer_test.py +++ b/model-optimizer/unit_tests/mo/middle/passes/infer_test.py @@ -9,7 +9,7 @@ from mo.front.common.partial_infer.concat import concat_infer from mo.graph.graph import Node from mo.middle.passes.infer import override_placeholder_shapes, partial_infer from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'type': 'Identity', 'value': None, 'kind': 'op'}, 'node_1_data': {'value': None, 'kind': 'data', 'data_type': None}, diff --git a/model-optimizer/unit_tests/mo/ops/__init__.py b/model-optimizer/unit_tests/mo/ops/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/ops/broadcast_test.py b/model-optimizer/unit_tests/mo/ops/broadcast_test.py similarity index 96% rename from model-optimizer/mo/ops/broadcast_test.py rename to model-optimizer/unit_tests/mo/ops/broadcast_test.py index cbca711ebbb..5b0bc5e6060 100644 --- a/model-optimizer/mo/ops/broadcast_test.py +++ b/model-optimizer/unit_tests/mo/ops/broadcast_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.broadcast import Broadcast -from mo.utils.unittest.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ +from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_op_with_empty_data, \ shaped_data diff --git a/model-optimizer/mo/ops/concat_test.py b/model-optimizer/unit_tests/mo/ops/concat_test.py similarity index 95% rename from model-optimizer/mo/ops/concat_test.py rename to model-optimizer/unit_tests/mo/ops/concat_test.py index db92343f10d..d6fa631a31c 100644 --- a/model-optimizer/mo/ops/concat_test.py +++ b/model-optimizer/unit_tests/mo/ops/concat_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.front.common.partial_infer.concat import concat_infer from mo.ops.concat import Concat -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestConcatOp(unittest.TestCase): diff --git a/model-optimizer/mo/ops/convolution_test.py b/model-optimizer/unit_tests/mo/ops/convolution_test.py similarity index 99% rename from model-optimizer/mo/ops/convolution_test.py rename to model-optimizer/unit_tests/mo/ops/convolution_test.py index 2f555c1d42a..68a1d5f6bca 100644 --- a/model-optimizer/mo/ops/convolution_test.py +++ b/model-optimizer/unit_tests/mo/ops/convolution_test.py @@ -9,8 +9,8 @@ from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.convolution import Convolution from mo.utils.error import Error -from mo.utils.unittest.extractors import FakeValue -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.extractors import FakeValue +from unit_tests.utils.graph import build_graph nodes_attributes = {'conv_input': {'value': None, 'kind': 'data'}, 'conv_node': {'type': 'Convolution', 'kind': 'op'}, diff --git a/model-optimizer/mo/ops/crop_test.py b/model-optimizer/unit_tests/mo/ops/crop_test.py similarity index 99% rename from model-optimizer/mo/ops/crop_test.py rename to model-optimizer/unit_tests/mo/ops/crop_test.py index 4f87b6b5e4f..8a7336ffe0e 100644 --- a/model-optimizer/mo/ops/crop_test.py +++ b/model-optimizer/unit_tests/mo/ops/crop_test.py @@ -8,7 +8,7 @@ import numpy as np from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.crop import Crop -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestCropPartialInfer(unittest.TestCase): diff --git a/model-optimizer/mo/ops/expand_dims_test.py b/model-optimizer/unit_tests/mo/ops/expand_dims_test.py similarity index 98% rename from model-optimizer/mo/ops/expand_dims_test.py rename to model-optimizer/unit_tests/mo/ops/expand_dims_test.py index af0de5a490e..b31620997d7 100644 --- a/model-optimizer/mo/ops/expand_dims_test.py +++ b/model-optimizer/unit_tests/mo/ops/expand_dims_test.py @@ -8,7 +8,7 @@ from generator import generator, generate from mo.graph.graph import Node from mo.ops.expand_dims import ExpandDims -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'data_1': { diff --git a/model-optimizer/mo/ops/pad_test.py b/model-optimizer/unit_tests/mo/ops/pad_test.py similarity index 98% rename from model-optimizer/mo/ops/pad_test.py rename to model-optimizer/unit_tests/mo/ops/pad_test.py index 3f63d509b9f..efef1d6beb7 100644 --- a/model-optimizer/mo/ops/pad_test.py +++ b/model-optimizer/unit_tests/mo/ops/pad_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.graph.graph import Node from mo.ops.pad import Pad, AttributedPad -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph class TestPadOps(unittest.TestCase): diff --git a/model-optimizer/mo/ops/pooling_test.py b/model-optimizer/unit_tests/mo/ops/pooling_test.py similarity index 99% rename from model-optimizer/mo/ops/pooling_test.py rename to model-optimizer/unit_tests/mo/ops/pooling_test.py index 057963c8ef8..ec378e5565a 100644 --- a/model-optimizer/mo/ops/pooling_test.py +++ b/model-optimizer/unit_tests/mo/ops/pooling_test.py @@ -7,8 +7,8 @@ import numpy as np from mo.graph.graph import Node from mo.ops.pooling import Pooling -from mo.utils.unittest.graph import build_graph from mo.utils.error import Error +from unit_tests.utils.graph import build_graph nodes_attributes = {'node_1': {'value': None, 'kind': 'data'}, 'pool': {'type': 'Pooling', 'value': None, 'kind': 'op'}, diff --git a/model-optimizer/mo/ops/slice_test.py b/model-optimizer/unit_tests/mo/ops/slice_test.py similarity index 98% rename from model-optimizer/mo/ops/slice_test.py rename to model-optimizer/unit_tests/mo/ops/slice_test.py index eb6454d7a6c..b56c9274196 100644 --- a/model-optimizer/mo/ops/slice_test.py +++ b/model-optimizer/unit_tests/mo/ops/slice_test.py @@ -10,7 +10,7 @@ from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.slice import Slice from mo.utils.error import Error -from mo.utils.unittest.graph import build_graph, valued_const_with_data, valued_data, regular_op_with_empty_data, \ +from unit_tests.utils.graph import build_graph, valued_const_with_data, valued_data, regular_op_with_empty_data, \ connect, shaped_data, shaped_const_with_data diff --git a/model-optimizer/mo/ops/squeeze_test.py b/model-optimizer/unit_tests/mo/ops/squeeze_test.py similarity index 97% rename from model-optimizer/mo/ops/squeeze_test.py rename to model-optimizer/unit_tests/mo/ops/squeeze_test.py index 4961aa6bbb7..440763e674c 100644 --- a/model-optimizer/mo/ops/squeeze_test.py +++ b/model-optimizer/unit_tests/mo/ops/squeeze_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.graph.graph import Node from mo.ops.squeeze import Squeeze -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'data': { diff --git a/model-optimizer/mo/ops/strided_slice_test.py b/model-optimizer/unit_tests/mo/ops/strided_slice_test.py similarity index 99% rename from model-optimizer/mo/ops/strided_slice_test.py rename to model-optimizer/unit_tests/mo/ops/strided_slice_test.py index 3db5e041f0c..c61f30b5d7d 100644 --- a/model-optimizer/mo/ops/strided_slice_test.py +++ b/model-optimizer/unit_tests/mo/ops/strided_slice_test.py @@ -3,15 +3,13 @@ import unittest -import numpy as np import numpy.testing as npt from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.strided_slice import StridedSlice -from mo.utils.unittest.graph import build_graph -from mo.utils.unittest.graph import valued_const_with_data, result, regular_op_with_empty_data, shaped_const_with_data, \ - connect +from unit_tests.utils.graph import build_graph, valued_const_with_data, result, regular_op_with_empty_data, \ + shaped_const_with_data, connect class TestStridedSliceInfer(unittest.TestCase): diff --git a/model-optimizer/mo/ops/tile_test.py b/model-optimizer/unit_tests/mo/ops/tile_test.py similarity index 99% rename from model-optimizer/mo/ops/tile_test.py rename to model-optimizer/unit_tests/mo/ops/tile_test.py index 4e4be81d7a4..1810acb7a27 100644 --- a/model-optimizer/mo/ops/tile_test.py +++ b/model-optimizer/unit_tests/mo/ops/tile_test.py @@ -7,7 +7,7 @@ import numpy as np from mo.graph.graph import Node from mo.ops.tile import Tile, AttributedTile -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph nodes_attributes = { 'op': {'kind': 'op'}, diff --git a/model-optimizer/mo/ops/unsqueeze_test.py b/model-optimizer/unit_tests/mo/ops/unsqueeze_test.py similarity index 98% rename from model-optimizer/mo/ops/unsqueeze_test.py rename to model-optimizer/unit_tests/mo/ops/unsqueeze_test.py index 75de9de2717..2368ffa603f 100644 --- a/model-optimizer/mo/ops/unsqueeze_test.py +++ b/model-optimizer/unit_tests/mo/ops/unsqueeze_test.py @@ -10,7 +10,7 @@ from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.unsqueeze import Unsqueeze from mo.utils.ir_engine.compare_graphs import compare_graphs -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph @generator diff --git a/model-optimizer/unit_tests/mo/pipeline/__init__.py b/model-optimizer/unit_tests/mo/pipeline/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/pipeline/common_test.py b/model-optimizer/unit_tests/mo/pipeline/common_test.py similarity index 99% rename from model-optimizer/mo/pipeline/common_test.py rename to model-optimizer/unit_tests/mo/pipeline/common_test.py index 466be2a3c43..60fe74a0d46 100644 --- a/model-optimizer/mo/pipeline/common_test.py +++ b/model-optimizer/unit_tests/mo/pipeline/common_test.py @@ -7,7 +7,7 @@ from generator import generator, generate from mo.graph.graph import Node from mo.pipeline.common import determined_sort, get_fw_tensor_debug_info, get_sorted_outputs -from mo.utils.unittest.graph import build_graph_with_edge_attrs +from unit_tests.utils.graph import build_graph_with_edge_attrs @generator diff --git a/model-optimizer/unit_tests/mo/utils/__init__.py b/model-optimizer/unit_tests/mo/utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/utils/broadcasting_test.py b/model-optimizer/unit_tests/mo/utils/broadcasting_test.py similarity index 92% rename from model-optimizer/mo/utils/broadcasting_test.py rename to model-optimizer/unit_tests/mo/utils/broadcasting_test.py index a82bfda615c..34000193f35 100644 --- a/model-optimizer/mo/utils/broadcasting_test.py +++ b/model-optimizer/unit_tests/mo/utils/broadcasting_test.py @@ -1,12 +1,14 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from mo.front.common.partial_infer.utils import int64_array -from mo.utils.broadcasting import bi_directional_broadcasting, bi_directional_shape_broadcasting, uni_directional_broadcasting, uni_directional_shape_broadcasting -from generator import generator, generate -import numpy as np import unittest +import numpy as np +from generator import generator, generate + +from mo.front.common.partial_infer.utils import int64_array +from mo.utils.broadcasting import uni_directional_broadcasting, uni_directional_shape_broadcasting + @generator class TestingBroadcasting(unittest.TestCase): diff --git a/model-optimizer/mo/utils/cli_parser_test.py b/model-optimizer/unit_tests/mo/utils/cli_parser_test.py similarity index 100% rename from model-optimizer/mo/utils/cli_parser_test.py rename to model-optimizer/unit_tests/mo/utils/cli_parser_test.py diff --git a/model-optimizer/mo/utils/error_test.py b/model-optimizer/unit_tests/mo/utils/error_test.py similarity index 100% rename from model-optimizer/mo/utils/error_test.py rename to model-optimizer/unit_tests/mo/utils/error_test.py diff --git a/model-optimizer/mo/utils/graph_test.py b/model-optimizer/unit_tests/mo/utils/graph_test.py similarity index 100% rename from model-optimizer/mo/utils/graph_test.py rename to model-optimizer/unit_tests/mo/utils/graph_test.py diff --git a/model-optimizer/unit_tests/mo/utils/ir_engine/__init__.py b/model-optimizer/unit_tests/mo/utils/ir_engine/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/utils/ir_engine/ir_engine_test.py b/model-optimizer/unit_tests/mo/utils/ir_engine/ir_engine_test.py similarity index 94% rename from model-optimizer/mo/utils/ir_engine/ir_engine_test.py rename to model-optimizer/unit_tests/mo/utils/ir_engine/ir_engine_test.py index 85d17b6fbba..74f386a38fe 100644 --- a/model-optimizer/mo/utils/ir_engine/ir_engine_test.py +++ b/model-optimizer/unit_tests/mo/utils/ir_engine/ir_engine_test.py @@ -19,10 +19,10 @@ log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.DEBUG, stream= class TestFunction(unittest.TestCase): def setUp(self): path, _ = os.path.split(os.path.dirname(__file__)) - self.xml = os.path.join(path, - "unittest", "test_data", "mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml") - self.xml_negative = os.path.join(path, - "unittest", "test_data", + self.xml = os.path.join(path, os.pardir, os.pardir, + "utils", "test_data", "mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml") + self.xml_negative = os.path.join(path, os.pardir, os.pardir, + "utils", "test_data", "mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml") self.bin = os.path.splitext(self.xml)[0] + '.bin' self.assertTrue(os.path.exists(self.xml), 'XML file not found: {}'.format(self.xml)) @@ -85,7 +85,7 @@ class TestFunction(unittest.TestCase): @unittest.mock.patch('numpy.savez_compressed') def test_generate_bin_hashes_file_custom_directory(self, numpy_savez): # Generate bin_hashes file in custom directory - directory_for_file = os.path.join(os.path.split(os.path.dirname(__file__))[0], "unittest", "test_data", + directory_for_file = os.path.join(os.path.split(os.path.dirname(__file__))[0], "utils", "test_data", "bin_hash") self.IR.generate_bin_hashes_file(path_for_file=directory_for_file) numpy_savez.assert_called_once() diff --git a/model-optimizer/unit_tests/mo/utils/ir_reader/__init__.py b/model-optimizer/unit_tests/mo/utils/ir_reader/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/utils/ir_reader/layer_to_class_test.py b/model-optimizer/unit_tests/mo/utils/ir_reader/layer_to_class_test.py similarity index 99% rename from model-optimizer/mo/utils/ir_reader/layer_to_class_test.py rename to model-optimizer/unit_tests/mo/utils/ir_reader/layer_to_class_test.py index 123b2ba2e95..b2f602c5de4 100644 --- a/model-optimizer/mo/utils/ir_reader/layer_to_class_test.py +++ b/model-optimizer/unit_tests/mo/utils/ir_reader/layer_to_class_test.py @@ -9,7 +9,7 @@ from generator import generator, generate from mo.graph.graph import Node from mo.utils.ir_engine.compare_graphs import compare_graphs from mo.utils.ir_reader.layer_to_class import groupconv_to_conv, restore_tensor_names -from mo.utils.unittest.graph import build_graph +from unit_tests.utils.graph import build_graph @generator diff --git a/model-optimizer/mo/utils/pipeline_config_test.py b/model-optimizer/unit_tests/mo/utils/pipeline_config_test.py similarity index 100% rename from model-optimizer/mo/utils/pipeline_config_test.py rename to model-optimizer/unit_tests/mo/utils/pipeline_config_test.py diff --git a/model-optimizer/mo/utils/simple_proto_parser_test.py b/model-optimizer/unit_tests/mo/utils/simple_proto_parser_test.py similarity index 100% rename from model-optimizer/mo/utils/simple_proto_parser_test.py rename to model-optimizer/unit_tests/mo/utils/simple_proto_parser_test.py diff --git a/model-optimizer/mo/utils/summarize_graph_test.py b/model-optimizer/unit_tests/mo/utils/summarize_graph_test.py similarity index 100% rename from model-optimizer/mo/utils/summarize_graph_test.py rename to model-optimizer/unit_tests/mo/utils/summarize_graph_test.py diff --git a/model-optimizer/mo/utils/utils_test.py b/model-optimizer/unit_tests/mo/utils/utils_test.py similarity index 100% rename from model-optimizer/mo/utils/utils_test.py rename to model-optimizer/unit_tests/mo/utils/utils_test.py diff --git a/model-optimizer/mo/utils/version_test.py b/model-optimizer/unit_tests/mo/utils/version_test.py similarity index 100% rename from model-optimizer/mo/utils/version_test.py rename to model-optimizer/unit_tests/mo/utils/version_test.py diff --git a/model-optimizer/mo/utils/versions_checker_test.py b/model-optimizer/unit_tests/mo/utils/versions_checker_test.py similarity index 100% rename from model-optimizer/mo/utils/versions_checker_test.py rename to model-optimizer/unit_tests/mo/utils/versions_checker_test.py diff --git a/model-optimizer/unit_tests/utils/__init__.py b/model-optimizer/unit_tests/utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/model-optimizer/mo/utils/unittest/extractors.py b/model-optimizer/unit_tests/utils/extractors.py similarity index 100% rename from model-optimizer/mo/utils/unittest/extractors.py rename to model-optimizer/unit_tests/utils/extractors.py diff --git a/model-optimizer/mo/utils/unittest/graph.py b/model-optimizer/unit_tests/utils/graph.py similarity index 100% rename from model-optimizer/mo/utils/unittest/graph.py rename to model-optimizer/unit_tests/utils/graph.py diff --git a/model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.bin b/model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.bin similarity index 100% rename from model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.bin rename to model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.bin diff --git a/model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml b/model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml similarity index 100% rename from model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml rename to model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6.xml diff --git a/model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml b/model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml similarity index 100% rename from model-optimizer/mo/utils/unittest/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml rename to model-optimizer/unit_tests/utils/test_data/mxnet_synthetic_gru_bidirectional_FP16_1_v6_negative.xml From 7a634490dc12be83995e08f4ef7c56f833570b87 Mon Sep 17 00:00:00 2001 From: Jan Iwaszkiewicz Date: Tue, 20 Apr 2021 14:34:55 +0200 Subject: [PATCH 21/78] Add GELU fusion (#5067) * GeLU fusion * Fix matcher and sqrt(2) value * Replace with math constant * Correct comments in header file * Add tests for transformations * Add define of math constants in tests * refactor code and add checks for nullptr * Extend tests with failing examples * change tests --- .../common_optimizations/gelu_fusion.hpp | 68 ++++++ .../common_optimizations.cpp | 2 + .../common_optimizations/gelu_fusion.cpp | 229 ++++++++++++++++++ .../transformations/gelu_fusion.cpp | 212 ++++++++++++++++ 4 files changed, 511 insertions(+) create mode 100644 inference-engine/src/transformations/include/transformations/common_optimizations/gelu_fusion.hpp create mode 100644 inference-engine/src/transformations/src/transformations/common_optimizations/gelu_fusion.cpp create mode 100644 inference-engine/tests/functional/inference_engine/transformations/gelu_fusion.cpp diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/gelu_fusion.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/gelu_fusion.hpp new file mode 100644 index 00000000000..38983a3a017 --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/gelu_fusion.hpp @@ -0,0 +1,68 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +namespace ngraph { +namespace pass { + +class TRANSFORMATIONS_API GeluFusion; +class TRANSFORMATIONS_API GeluFusionWithErfOne; +class TRANSFORMATIONS_API GeluFusionWithErfTwo; +class TRANSFORMATIONS_API GeluFusionWithErfThree; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief GeluFusion transformation replaces a sub-graph + * (0.5 * x) * (1 + erf(x / sqrt(2))) with a Gelu op. + */ +class ngraph::pass::GeluFusionWithErfOne : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + GeluFusionWithErfOne(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief GeluFusion transformation replaces a sub-graph + * 0.5 * (x * (1 + erf(x / sqrt(2))) with a Gelu op. + */ +class ngraph::pass::GeluFusionWithErfTwo : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + GeluFusionWithErfTwo(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief GeluFusion transformation replaces a sub-graph + * x * (0.5 * (1 + erf(x / sqrt(2))) with a Gelu op. + */ +class ngraph::pass::GeluFusionWithErfThree : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + GeluFusionWithErfThree(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief GeluFusion transformation replaces various sub-graphs with a Gelu op. + */ +class ngraph::pass::GeluFusion : public ngraph::pass::GraphRewrite { +public: + NGRAPH_RTTI_DECLARATION; + GeluFusion() { + add_matcher(); + add_matcher(); + add_matcher(); + } +}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 47e9f789ea6..2df73b3a6a7 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -13,6 +13,7 @@ #include "transformations/common_optimizations/conv_mul_fusion.hpp" #include "transformations/common_optimizations/fq_mul_fusion.hpp" #include "transformations/common_optimizations/fq_reshape_fusion.hpp" +#include "transformations/common_optimizations/gelu_fusion.hpp" #include "transformations/common_optimizations/depth_to_space_fusion.hpp" #include "transformations/common_optimizations/optimize_strided_slice.hpp" #include "transformations/common_optimizations/softplus_fusion.hpp" @@ -113,6 +114,7 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptradd_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); + common_fusions->add_matcher(); common_fusions->set_name("ngraph::pass::CommonFusions"); manager.register_pass(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/gelu_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/gelu_fusion.cpp new file mode 100644 index 00000000000..ddf3f92f5f6 --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/gelu_fusion.cpp @@ -0,0 +1,229 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#define _USE_MATH_DEFINES + +#include "transformations/common_optimizations/gelu_fusion.hpp" + +#include + +#include +#include +#include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" + +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusion, "GeluFusion", 0); + +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfOne, + "GeluFusionWithErfOne", 0); + +ngraph::pass::GeluFusionWithErfOne::GeluFusionWithErfOne() { + MATCHER_SCOPE(GeluFusionWithErfOne); + // Replaces a sub-graph with a Gelu op + // Shared by every pattern: (1 + erf(x / sqrt(2))) + auto input = ngraph::pattern::any_input(); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type( + {input, div_constant}); + auto erf = ngraph::pattern::wrap_type({div}); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = + ngraph::pattern::wrap_type({add_constant, erf}); + auto mul_constant = ngraph::pattern::wrap_type(); + + // (0.5 * x) * (1 + erf(x / sqrt(2)) + auto mul_first = ngraph::pattern::wrap_type( + {input, mul_constant}); + auto mul = + ngraph::pattern::wrap_type({mul_first, add}); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + auto &pattern_to_output = m.get_pattern_value_map(); + auto x_output = pattern_to_output.at(input); + + auto div_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); + + if (!div_const_value || !add_const_value || !mul_const_value) { + return false; + } + + bool valid_constant_values = + op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); + + if (!valid_constant_values) { + return false; + } + + auto gelu = std::make_shared(x_output); + + gelu->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info( + { + pattern_to_output.at(div).get_node_shared_ptr(), + pattern_to_output.at(erf).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(mul_first).get_node_shared_ptr(), + pattern_to_output.at(mul).get_node_shared_ptr(), + }, + gelu); + ngraph::replace_node(m.get_match_root(), gelu); + return true; + }; + + auto m = std::make_shared(mul, matcher_name); + register_matcher(m, callback); +} + +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfTwo, + "GeluFusionWithErfTwo", 0); + +ngraph::pass::GeluFusionWithErfTwo::GeluFusionWithErfTwo() { + MATCHER_SCOPE(GeluFusionWithErfTwo); + // Replaces a sub-graph with a Gelu op + // Shared by every pattern: (1 + erf(x / sqrt(2))) + auto input = ngraph::pattern::any_input(); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type( + {input, div_constant}); + auto erf = ngraph::pattern::wrap_type({div}); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = + ngraph::pattern::wrap_type({add_constant, erf}); + auto mul_constant = ngraph::pattern::wrap_type(); + + // 0.5 * (x * (1 + erf(x / sqrt(2))) + auto mul_first = + ngraph::pattern::wrap_type({input, add}); + auto mul = ngraph::pattern::wrap_type( + {mul_constant, mul_first}); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + auto &pattern_to_output = m.get_pattern_value_map(); + auto x_output = pattern_to_output.at(input); + + auto div_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); + + if (!div_const_value || !add_const_value || !mul_const_value) { + return false; + } + + bool valid_constant_values = + op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); + + if (!valid_constant_values) { + return false; + } + + auto gelu = std::make_shared(x_output); + + gelu->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info( + { + pattern_to_output.at(div).get_node_shared_ptr(), + pattern_to_output.at(erf).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(mul_first).get_node_shared_ptr(), + pattern_to_output.at(mul).get_node_shared_ptr(), + }, + gelu); + ngraph::replace_node(m.get_match_root(), gelu); + return true; + }; + + auto m = std::make_shared(mul, matcher_name); + register_matcher(m, callback); +} + +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfThree, + "GeluFusionWithErfThree", 0); + +ngraph::pass::GeluFusionWithErfThree::GeluFusionWithErfThree() { + MATCHER_SCOPE(GeluFusionWithErfThree); + // Replaces a sub-graph with a Gelu op + // Shared by every pattern: (1 + erf(x / sqrt(2))) + auto input = ngraph::pattern::any_input(); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type( + {input, div_constant}); + auto erf = ngraph::pattern::wrap_type({div}); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = + ngraph::pattern::wrap_type({add_constant, erf}); + auto mul_constant = ngraph::pattern::wrap_type(); + + // x * (0.5 * (1 + erf(x / sqrt(2))) + auto mul_first = ngraph::pattern::wrap_type( + {add, mul_constant}); + auto mul = ngraph::pattern::wrap_type( + {input, mul_first}); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + auto &pattern_to_output = m.get_pattern_value_map(); + auto x_output = pattern_to_output.at(input); + + auto div_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = + std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); + + if (!div_const_value || !add_const_value || !mul_const_value) { + return false; + } + + bool valid_constant_values = + op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); + + if (!valid_constant_values) { + return false; + } + + auto gelu = std::make_shared(x_output); + + gelu->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info( + { + pattern_to_output.at(div).get_node_shared_ptr(), + pattern_to_output.at(erf).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(mul_first).get_node_shared_ptr(), + pattern_to_output.at(mul).get_node_shared_ptr(), + }, + gelu); + ngraph::replace_node(m.get_match_root(), gelu); + return true; + }; + + auto m = std::make_shared(mul, matcher_name); + register_matcher(m, callback); +} diff --git a/inference-engine/tests/functional/inference_engine/transformations/gelu_fusion.cpp b/inference-engine/tests/functional/inference_engine/transformations/gelu_fusion.cpp new file mode 100644 index 00000000000..6107ae494e7 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/gelu_fusion.cpp @@ -0,0 +1,212 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#define _USE_MATH_DEFINES + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +using namespace testing; +using namespace ngraph; + +TEST(TransformationTests, GeluFusionPatternOne) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + + auto div_const = + opset7::Constant::create(element::f32, Shape{1}, {M_SQRT2}); + auto add_const = + opset7::Constant::create(element::f32, Shape{1}, {1.0}); + auto mul_const = + opset7::Constant::create(element::f32, Shape{1}, {0.5}); + + auto div = std::make_shared(data, div_const); + auto erf = std::make_shared(div); + auto add = std::make_shared(erf, add_const); + auto mul_first = std::make_shared(data, mul_const); + auto mul = std::make_shared(mul_first, add); + + f = std::make_shared(NodeVector{mul}, ParameterVector{data}); + + pass::Manager m; + m.register_pass(); + m.register_pass(); + m.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + auto gelu = std::make_shared(data); + f_ref = + std::make_shared(NodeVector{gelu}, ParameterVector{data}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, GeluFusionPatternTwo) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + + auto div_const = + opset7::Constant::create(element::f32, Shape{1}, {M_SQRT2}); + auto add_const = + opset7::Constant::create(element::f32, Shape{1}, {1.0}); + auto mul_const = + opset7::Constant::create(element::f32, Shape{1}, {0.5}); + + auto div = std::make_shared(data, div_const); + auto erf = std::make_shared(div); + auto add = std::make_shared(erf, add_const); + auto mul_first = std::make_shared(data, add); + auto mul = std::make_shared(mul_first, mul_const); + + f = std::make_shared(NodeVector{mul}, ParameterVector{data}); + + pass::Manager m; + m.register_pass(); + m.register_pass(); + m.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + auto gelu = std::make_shared(data); + f_ref = + std::make_shared(NodeVector{gelu}, ParameterVector{data}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, GeluFusionPatternThree) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + + auto div_const = + opset7::Constant::create(element::f32, Shape{1}, {M_SQRT2}); + auto add_const = + opset7::Constant::create(element::f32, Shape{1}, {1.0}); + auto mul_const = + opset7::Constant::create(element::f32, Shape{1}, {0.5}); + + auto div = std::make_shared(data, div_const); + auto erf = std::make_shared(div); + auto add = std::make_shared(erf, add_const); + auto mul_first = std::make_shared(add, mul_const); + auto mul = std::make_shared(data, mul_first); + + f = std::make_shared(NodeVector{mul}, ParameterVector{data}); + + pass::Manager m; + m.register_pass(); + m.register_pass(); + m.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + auto gelu = std::make_shared(data); + f_ref = + std::make_shared(NodeVector{gelu}, ParameterVector{data}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, GeluFusionPatternIncorrectDivConstValue) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + + auto div_const = + opset7::Constant::create(element::f32, Shape{1}, {1.4149}); + auto add_const = + opset7::Constant::create(element::f32, Shape{1}, {1.0}); + auto mul_const = + opset7::Constant::create(element::f32, Shape{1}, {0.5}); + + auto div = std::make_shared(data, div_const); + auto erf = std::make_shared(div); + auto add = std::make_shared(erf, add_const); + auto mul_first = std::make_shared(data, add); + auto mul = std::make_shared(mul_first, mul_const); + + f = std::make_shared(NodeVector{mul}, ParameterVector{data}); + f_ref = + std::make_shared(NodeVector{mul}, ParameterVector{data}); + + pass::Manager m; + m.register_pass(); + m.register_pass(); + m.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, GeluFusionPatternTooShortDivConstValue) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto data = + std::make_shared(element::f32, Shape{2, 2}); + + auto div_const = + opset7::Constant::create(element::f32, Shape{1}, {1.4142}); + auto add_const = + opset7::Constant::create(element::f32, Shape{1}, {1.0}); + auto mul_const = + opset7::Constant::create(element::f32, Shape{1}, {0.5}); + + auto div = std::make_shared(data, div_const); + auto erf = std::make_shared(div); + auto add = std::make_shared(erf, add_const); + auto mul_first = std::make_shared(data, add); + auto mul = std::make_shared(mul_first, mul_const); + + f = std::make_shared(NodeVector{mul}, ParameterVector{data}); + f_ref = + std::make_shared(NodeVector{mul}, ParameterVector{data}); + + pass::Manager m; + m.register_pass(); + m.register_pass(); + m.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} From 76fd7913632646a2e0f32fc170d39fca4c0fb8ac Mon Sep 17 00:00:00 2001 From: Mikhail Treskin Date: Tue, 20 Apr 2021 22:33:52 +0300 Subject: [PATCH 22/78] Define OP version in report by first occurrence in opset instead of type_info (#5177) --- .../src/base/layer_test_utils.cpp | 6 +-- .../layer_test_utils/summary.hpp | 7 +++- .../src/layer_test_utils/summary.cpp | 37 ++++++++++++------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp index f9d5ff50fe0..d527bb61985 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp @@ -27,9 +27,6 @@ LayerTestsCommon::LayerTestsCommon() : threshold(1e-2f) { } void LayerTestsCommon::Run() { - auto &s = Summary::getInstance(); - s.setDeviceName(targetDevice); - auto crashHandler = [](int errCode) { auto &s = Summary::getInstance(); s.saveReport(); @@ -38,6 +35,9 @@ void LayerTestsCommon::Run() { }; signal(SIGSEGV, crashHandler); + auto &s = Summary::getInstance(); + s.setDeviceName(targetDevice); + if (FuncTestUtils::SkipTestsConfig::currentTestIsDisabled()) { s.updateOPsStats(function, PassRate::Statuses::SKIPPED); GTEST_SKIP() << "Disabled test due to configuration" << std::endl; diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp b/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp index ba3d1d06a8b..05c5843b895 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/include/functional_test_utils/layer_test_utils/summary.hpp @@ -67,12 +67,15 @@ private: static size_t saveReportTimeout; static bool extendReport; static bool saveReportWithUniqueName; - static const char* outputFolder; + static const char *outputFolder; + std::vector opsets; friend class SummaryDestroyer; + std::string getOpVersion(const ngraph::NodeTypeInfo &type_info); + protected: - Summary() = default; + Summary(); ~Summary() = default; diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp b/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp index 7acc445fdd6..1f203eb8622 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/src/layer_test_utils/summary.cpp @@ -23,6 +23,16 @@ void SummaryDestroyer::initialize(Summary *p) { p_instance = p; } +Summary::Summary() { + opsets.push_back(ngraph::get_opset1()); + opsets.push_back(ngraph::get_opset2()); + opsets.push_back(ngraph::get_opset3()); + opsets.push_back(ngraph::get_opset4()); + opsets.push_back(ngraph::get_opset5()); + opsets.push_back(ngraph::get_opset6()); + opsets.push_back(ngraph::get_opset7()); +} + Summary &Summary::getInstance() { if (!p_instance) { p_instance = new Summary(); @@ -69,6 +79,15 @@ void Summary::updateOPsStats(const ngraph::NodeTypeInfo &op, const PassRate::Sta } } +std::string Summary::getOpVersion(const ngraph::NodeTypeInfo &type_info) { + for (size_t i = 0; i < opsets.size(); i++) { + if (opsets[i].contains_type(type_info)) { + return std::to_string(i+1); + } + } + return "undefined"; +} + std::map Summary::getOpStatisticFromReport() { pugi::xml_document doc; @@ -138,14 +157,6 @@ void Summary::saveReport() { std::string outputFilePath = outputFolder + std::string(CommonTestUtils::FileSeparator) + filename; - std::vector opsets; - opsets.push_back(ngraph::get_opset1()); - opsets.push_back(ngraph::get_opset2()); - opsets.push_back(ngraph::get_opset3()); - opsets.push_back(ngraph::get_opset4()); - opsets.push_back(ngraph::get_opset5()); - opsets.push_back(ngraph::get_opset6()); - opsets.push_back(ngraph::get_opset7()); std::set opsInfo; for (const auto &opset : opsets) { const auto &type_info_set = opset.get_type_info_set(); @@ -165,7 +176,7 @@ void Summary::saveReport() { char timeNow[80]; time(&rawtime); - // cpplint require to use localtime_r instead which is not available in C++14 + // cpplint require to use localtime_r instead which is not available in C++11 timeinfo = localtime(&rawtime); // NOLINT strftime(timeNow, sizeof(timeNow), "%d-%m-%Y %H:%M:%S", timeinfo); @@ -188,16 +199,16 @@ void Summary::saveReport() { pugi::xml_node opsNode = root.append_child("ops_list"); for (const auto &op : opsInfo) { - std::string name = std::string(op.name) + "-" + std::to_string(op.version); + std::string name = std::string(op.name) + "-" + getOpVersion(op); pugi::xml_node entry = opsNode.append_child(name.c_str()); - (void)entry; + (void) entry; } pugi::xml_node resultsNode = root.child("results"); pugi::xml_node currentDeviceNode = resultsNode.append_child(summary.deviceName.c_str()); std::unordered_set opList; for (const auto &it : stats) { - std::string name = std::string(it.first.name) + "-" + std::to_string(it.first.version); + std::string name = std::string(it.first.name) + "-" + getOpVersion(it.first); opList.insert(name); pugi::xml_node entry = currentDeviceNode.append_child(name.c_str()); entry.append_attribute("passed").set_value(it.second.passed); @@ -209,7 +220,7 @@ void Summary::saveReport() { if (extendReport && file) { auto opStataFromReport = summary.getOpStatisticFromReport(); - for (auto& item : opStataFromReport) { + for (auto &item : opStataFromReport) { pugi::xml_node entry; if (opList.find(item.first) == opList.end()) { entry = currentDeviceNode.append_child(item.first.c_str()); From 0f2569fad9e64960abe0a721efe37501d1faacef Mon Sep 17 00:00:00 2001 From: Bartek Szmelczynski Date: Wed, 21 Apr 2021 07:58:55 +0200 Subject: [PATCH 23/78] Revise exp (#5236) * refactor exp class * add backend and type_prop tests * add SLT for exp operator * add SLT for serialzation for activation type ops * remove redundant files --- .../serialization/single_layer/activation.cpp | 109 ++++++++++++++++++ ngraph/core/include/ngraph/op/exp.hpp | 4 +- ngraph/core/src/op/exp.cpp | 2 +- ngraph/test/backend/exp.in.cpp | 45 ++++++++ ngraph/test/type_prop/unary_ops.cpp | 2 +- 5 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 inference-engine/tests/functional/inference_engine/serialization/single_layer/activation.cpp diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/activation.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/activation.cpp new file mode 100644 index 00000000000..ff6a32786c8 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/activation.cpp @@ -0,0 +1,109 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "shared_test_classes/single_layer/activation.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; +using namespace ngraph::helpers; +namespace { +TEST_P(ActivationLayerTest, Serialize) { + Serialize(); +} +// Common params +const std::vector inputPrecisions = { + InferenceEngine::Precision::FP32 + // TODO: Fix Issue-27390 + // InferenceEngine::Precision::I16, + // InferenceEngine::Precision::U8 +}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::map>> activationTypes = { + {Sigmoid, {}}, + {Tanh, {}}, + {Relu, {}}, + {Exp, {}}, + {Log, {}}, + {Sign, {}}, + {Abs, {}}, + {Clamp, {{-2.0f, 2.0f}}}, + {Negative, {}}, + {Acos, {}}, + {Asin, {}}, + {Atan, {}}, + {Cos, {}}, + {Cosh, {}}, + {Floor, {}}, + {Sin, {}}, + {Sinh, {}}, + {Sqrt, {}}, + {Tan, {}}, + {Elu, {{0.1f}}}, + {Erf, {}}, + {HardSigmoid, {{0.2f, 0.5f}}}, + {Selu, {{1.6732f, 1.0507f}}}, + {Ceiling, {}}, + {Mish, {}}, + {HSwish, {}}, + {SoftPlus, {}}, + {HSigmoid, {}}, + {RoundHalfToEven, {}}, + {RoundHalfAwayFromZero, {}}, + {Erf, {}}, + {GeluErf, {}}, + {GeluTanh, {}} +}; + +const std::map>> activationParamTypes = { + {PReLu, {{-0.01f}}}, + {LeakyRelu, {{0.01f}}} +}; + +std::map, std::vector>> basic = { + {{1, 50}, {{}}}, + {{1, 128}, {{}}}, +}; + +std::map, std::vector>> preluBasic = { + {{1, 50}, {{1}, {50}}}, + {{1, 128}, {{1}, {128}}}, +}; + +const auto basicCases = ::testing::Combine( + ::testing::ValuesIn(CommonTestUtils::combineParams(activationTypes)), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(CommonTestUtils::combineParams(basic)), + ::testing::Values(CommonTestUtils::DEVICE_CPU) +); + +const auto basicPreluCases = ::testing::Combine( + ::testing::ValuesIn(CommonTestUtils::combineParams(activationParamTypes)), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(CommonTestUtils::combineParams(preluBasic)), + ::testing::Values(CommonTestUtils::DEVICE_CPU) +); + + +INSTANTIATE_TEST_CASE_P(smoke_Activation_Basic, ActivationLayerTest, basicCases, ActivationLayerTest::getTestCaseName); +INSTANTIATE_TEST_CASE_P(smoke_Activation_Basic_Prelu, ActivationLayerTest, basicPreluCases, ActivationLayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Activation_Basic, ActivationParamLayerTest, basicPreluCases, ActivationLayerTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Activation_Basic, ActivationDynamicLayerTest, basicCases, ActivationLayerTest::getTestCaseName); + +} // namespace diff --git a/ngraph/core/include/ngraph/op/exp.hpp b/ngraph/core/include/ngraph/op/exp.hpp index 0c48b27c8ea..bbaf0647f8e 100644 --- a/ngraph/core/include/ngraph/op/exp.hpp +++ b/ngraph/core/include/ngraph/op/exp.hpp @@ -16,8 +16,8 @@ namespace ngraph class NGRAPH_API Exp : public util::UnaryElementwiseArithmetic { public: - static constexpr NodeTypeInfo type_info{"Exp", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; + /// \brief Constructs an exponential operation. Exp() = default; /// \brief Constructs an exponential operation. diff --git a/ngraph/core/src/op/exp.cpp b/ngraph/core/src/op/exp.cpp index 27d9a2beba2..19c50392fe6 100644 --- a/ngraph/core/src/op/exp.cpp +++ b/ngraph/core/src/op/exp.cpp @@ -13,7 +13,7 @@ using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::Exp::type_info; +NGRAPH_RTTI_DEFINITION(op::Exp, "Exp", 0, UnaryElementwiseArithmetic); op::Exp::Exp(const Output& arg) : UnaryElementwiseArithmetic(arg) diff --git a/ngraph/test/backend/exp.in.cpp b/ngraph/test/backend/exp.in.cpp index 9cdfd1c0a5f..71142473923 100644 --- a/ngraph/test/backend/exp.in.cpp +++ b/ngraph/test/backend/exp.in.cpp @@ -43,3 +43,48 @@ NGRAPH_TEST(${BACKEND_NAME}, exp) shape, {expf(-4), expf(-3), expf(-2), expf(-1), expf(0), expf(1), expf(2), expf(3)}); test_case.run(); } + + +NGRAPH_TEST(${BACKEND_NAME}, exp_negative) +{ + Shape shape{5}; + auto A = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A), ParameterVector{A}); + + auto test_case = test::TestCase(f); + test_case.add_input({-4, -3, -2, -1, -5}); + test_case.add_expected_output( + shape, {expf(-4), expf(-3), expf(-2), expf(-1), expf(-5)}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, exp_scalar) +{ + Shape shape{}; + auto A = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A), ParameterVector{A}); + + vector a{13}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {expf(13)}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, exp_in_place) +{ + Shape shape{2}; + auto A = make_shared(element::f32, shape);; + auto T = make_shared(A); + auto T2 = make_shared(T); + + auto f = make_shared(T2, ParameterVector{A}); + + vector a{1, 3}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {expf(expf(1)), expf(expf(3))}); + test_case.run(); +} \ No newline at end of file diff --git a/ngraph/test/type_prop/unary_ops.cpp b/ngraph/test/type_prop/unary_ops.cpp index 99db29e0612..c0b500bf717 100644 --- a/ngraph/test/type_prop/unary_ops.cpp +++ b/ngraph/test/type_prop/unary_ops.cpp @@ -96,6 +96,6 @@ REGISTER_TYPED_TEST_CASE_P(UnaryOperator, dynamic_rank_input_shape_3D, dynamic_rank_input_shape_full); -using Types = ::testing::Types; +using Types = ::testing::Types; INSTANTIATE_TYPED_TEST_CASE_P(type_prop, UnaryOperator, Types); From a8e154b189c4b2a20ce1b5fe22dceb1cb8b66bd4 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Wed, 21 Apr 2021 09:00:09 +0300 Subject: [PATCH 24/78] Added out of bounds check for output ports (#5305) * Added out of bounds check for output ports * Corrected if condition * Updated exception message * Added functional test * Verified particular type of exception --- .../cnn_network_ngraph_impl.cpp | 5 +++ .../cnn_network/cnn_ngraph_impl_tests.cpp | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp b/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp index 9504d94a432..41e040489b2 100644 --- a/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp +++ b/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp @@ -213,6 +213,11 @@ StatusCode CNNNetworkNGraphImpl::addOutput(const std::string& layerName, size_t for (const auto & layer : _ngraph_function->get_ops()) { // Result can have the same name as previous operation if (layer->get_friendly_name() == layerName && !std::dynamic_pointer_cast(layer)) { + // Check that output port exists + if (layer->outputs().size() <= outputIndex) { + return DescriptionBuffer(OUT_OF_BOUNDS, resp) + << "port index " << outputIndex << " exceeds the number of layer outputs " << layer->outputs().size(); + } std::string outputName = layerName; if (layer->outputs().size() != 1) { outputName += "." + std::to_string(outputIndex); diff --git a/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp b/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp index aa1b92d96e9..ac041eb1a35 100644 --- a/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp @@ -312,6 +312,43 @@ TEST(CNNNGraphImplTests, TestAddOutput) { ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); } +TEST(CNNNGraphImplTests, TestAddOutputWithPort) { + const std::string testLayerName = "testReLU"; + std::shared_ptr ngraph; + { + ngraph::PartialShape shape({1, 3, 22, 22}); + ngraph::element::Type type(ngraph::element::Type_t::f32); + auto param = std::make_shared(type, shape); + auto relu = std::make_shared(param); + relu->set_friendly_name(testLayerName); + auto relu2 = std::make_shared(relu); + relu2->set_friendly_name("relu2"); + auto result = std::make_shared(relu2); + + ngraph::ParameterVector params = {param}; + ngraph::ResultVector results = {result}; + + ngraph = std::make_shared(results, params); + } + + InferenceEngine::CNNNetwork cnnNet(ngraph); + ASSERT_NE(nullptr, cnnNet.getFunction()); + ASSERT_EQ(4, cnnNet.layerCount()); + + cnnNet.addOutput(testLayerName, 0); + ASSERT_NE(nullptr, cnnNet.getFunction()); + ASSERT_EQ(5, cnnNet.layerCount()); + + EXPECT_THROW(cnnNet.addOutput(testLayerName, 1), OutOfBounds); + ASSERT_NE(nullptr, cnnNet.getFunction()); + ASSERT_EQ(5, cnnNet.layerCount()); + + auto outputs = cnnNet.getOutputsInfo(); + ASSERT_EQ(2, outputs.size()); + ASSERT_TRUE(outputs.find("relu2") != outputs.end()); + ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); +} + TEST(CNNNGraphImplTests, TestAddOutputTwoTimes) { const std::string testLayerName = "testReLU"; std::shared_ptr ngraph; From b718de0cee8770baf003e123c004e8e56c8b53b8 Mon Sep 17 00:00:00 2001 From: Dmitrii Khurtin Date: Wed, 21 Apr 2021 10:34:45 +0300 Subject: [PATCH 25/78] [GNA] Update GNA library (#5228) * [GNA] Update GNA library to 1191 version * append symlink to libgna.so * append selective unpacking of the archive * changed the criterion for checking the unpacking process (exit code) * remove tabs * add equalToReferenceWithDelta_1191 * removed equalToReferenceWithDelta_1191 * master -> update_gna_library --- .../download/dependency_solver.cmake | 13 ++++--- .../download/download_and_extract.cmake | 39 ++++++++++--------- .../developer_package/download/extract.cmake | 14 ++++--- inference-engine/cmake/dependencies.cmake | 13 ++++++- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/cmake/developer_package/download/dependency_solver.cmake b/cmake/developer_package/download/dependency_solver.cmake index 7a5fc13ca90..2f2ab192d3e 100644 --- a/cmake/developer_package/download/dependency_solver.cmake +++ b/cmake/developer_package/download/dependency_solver.cmake @@ -4,7 +4,7 @@ include (download/download) -function (resolve_archive_dependency VAR COMPONENT ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC ARCHIVE_ANDROID TARGET_PATH FOLDER ENVIRONMENT SHA256) +function (resolve_archive_dependency VAR COMPONENT ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC ARCHIVE_ANDROID TARGET_PATH FOLDER ENVIRONMENT SHA256 FILES_TO_EXTRACT) if (ENVIRONMENT AND (DEFINED ${ENVIRONMENT} OR DEFINED ENV{${ENVIRONMENT}})) set(HAS_ENV "TRUE") endif() @@ -12,9 +12,9 @@ function (resolve_archive_dependency VAR COMPONENT ARCHIVE ARCHIVE_UNIFIED ARCHI if (NOT DEFINED HAS_ENV) if (ARCHIVE) #TODO: check whether this is platform specific binary with same name per or it is in common folder - DownloadAndExtract(${COMPONENT} ${ARCHIVE} ${TARGET_PATH} result_path ${FOLDER} ${SHA256}) + DownloadAndExtract(${COMPONENT} ${ARCHIVE} ${TARGET_PATH} result_path ${FOLDER} ${SHA256} ${FILES_TO_EXTRACT}) else() - DownloadAndExtractPlatformSpecific(${COMPONENT} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${ARCHIVE_ANDROID} ${TARGET_PATH} result_path ${FOLDER} ${SHA256}) + DownloadAndExtractPlatformSpecific(${COMPONENT} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${ARCHIVE_ANDROID} ${TARGET_PATH} result_path ${FOLDER} ${SHA256} ${FILES_TO_EXTRACT}) endif() set (${VAR} ${result_path} PARENT_SCOPE) @@ -53,7 +53,7 @@ endfunction(read_version) function (RESOLVE_DEPENDENCY NAME_OF_CMAKE_VAR) list(REMOVE_AT ARGV 0) - set(SUPPORTED_ARGS FOLDER ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC ARCHIVE_ANDROID TARGET_PATH ENVIRONMENT GITHUB_PULL_REQUEST VERSION_REGEX SHA256) + set(SUPPORTED_ARGS FOLDER ARCHIVE ARCHIVE_UNIFIED ARCHIVE_WIN ARCHIVE_LIN ARCHIVE_MAC ARCHIVE_ANDROID TARGET_PATH ENVIRONMENT GITHUB_PULL_REQUEST VERSION_REGEX SHA256 FILES_TO_EXTRACT) #unnecessary vars @@ -116,6 +116,9 @@ function (RESOLVE_DEPENDENCY NAME_OF_CMAKE_VAR) message(FATAL_ERROR "SHA is not specified for: " ${NAME_OF_CMAKE_VAR}) endif() + if (NOT DEFINED FILES_TO_EXTRACT) + set (FILES_TO_EXTRACT FALSE) + endif() #for each dependency type have to do separate things if (ARCHIVE_WIN OR ARCHIVE_LIN OR ARCHIVE_MAC OR ARCHIVE_ANDROID OR ARCHIVE OR ARCHIVE_UNIFIED) @@ -123,7 +126,7 @@ function (RESOLVE_DEPENDENCY NAME_OF_CMAKE_VAR) message(FATAL_ERROR "TARGET_PATH should be defined for every dependency") endif() - resolve_archive_dependency(RESULT ${NAME_OF_CMAKE_VAR} ${ARCHIVE} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${ARCHIVE_ANDROID} ${TARGET_PATH} ${FOLDER} ${ENVIRONMENT} ${SHA256}) + resolve_archive_dependency(RESULT ${NAME_OF_CMAKE_VAR} ${ARCHIVE} ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${ARCHIVE_ANDROID} ${TARGET_PATH} ${FOLDER} ${ENVIRONMENT} ${SHA256} ${FILES_TO_EXTRACT}) set(${NAME_OF_CMAKE_VAR} ${RESULT} PARENT_SCOPE) if (VERSION_REGEX) GetNameAndUrlToDownload(archive RELATIVE_URL ${ARCHIVE_UNIFIED} ${ARCHIVE_WIN} ${ARCHIVE_LIN} ${ARCHIVE_MAC} ${ARCHIVE_ANDROID}) diff --git a/cmake/developer_package/download/download_and_extract.cmake b/cmake/developer_package/download/download_and_extract.cmake index 20f7e8cacdc..eda73be1ef1 100644 --- a/cmake/developer_package/download/download_and_extract.cmake +++ b/cmake/developer_package/download/download_and_extract.cmake @@ -42,25 +42,26 @@ function (DownloadAndExtractPlatformSpecific unpacked_path result_path folder - sha256) + sha256 + files_to_extract) GetNameAndUrlToDownload(archive_name RELATIVE_URL ${archive_name_unified} ${archive_name_win} ${archive_name_lin} ${archive_name_mac} ${archive_name_android} ) if (NOT archive_name OR NOT RELATIVE_URL) return() endif() - CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} TRUE FALSE TRUE ${sha256}) + CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} TRUE FALSE TRUE ${sha256} ${files_to_extract}) set (${result_path} ${result_path2} PARENT_SCOPE) endfunction(DownloadAndExtractPlatformSpecific) #download from common folder -function (DownloadAndExtract component archive_name unpacked_path result_path folder sha256) +function (DownloadAndExtract component archive_name unpacked_path result_path folder sha256 files_to_extract) set (RELATIVE_URL "${archive_name}") set(fattal TRUE) - CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} ${fattal} result TRUE ${sha256}) + CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} ${fattal} result TRUE ${sha256} ${files_to_extract}) if (NOT ${result}) - DownloadAndExtractPlatformSpecific(${component} ${archive_name} ${archive_name} ${archive_name} ${unpacked_path} ${result_path2} ${folder}) + DownloadAndExtractPlatformSpecific(${component} ${archive_name} ${archive_name} ${archive_name} ${unpacked_path} ${result_path2} ${folder} ${sha256} ${files_to_extract}) endif() set (${result_path} ${result_path2} PARENT_SCOPE) @@ -68,7 +69,7 @@ function (DownloadAndExtract component archive_name unpacked_path result_path fo endfunction(DownloadAndExtract) -function (DownloadAndExtractInternal URL archive_path unpacked_path folder fattal resultExt sha256) +function (DownloadAndExtractInternal URL archive_path unpacked_path folder fattal resultExt sha256 files_to_extract) set (status "ON") DownloadAndCheck(${URL} ${archive_path} ${fattal} result1 ${sha256}) if ("${result1}" STREQUAL "ARCHIVE_DOWNLOAD_FAIL") @@ -83,17 +84,17 @@ function (DownloadAndExtractInternal URL archive_path unpacked_path folder fatt endif() if("${status}" STREQUAL "ON") - ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result) + ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result ${files_to_extract}) endif() set (${resultExt} ${status} PARENT_SCOPE) endfunction(DownloadAndExtractInternal) -function (ExtractWithVersion URL archive_path unpacked_path folder result) +function (ExtractWithVersion URL archive_path unpacked_path folder result files_to_extract) - debug_message("ExtractWithVersion : ${archive_path} : ${unpacked_path}") - extract(${archive_path} ${unpacked_path} ${folder} status) + debug_message("ExtractWithVersion : ${archive_path} : ${unpacked_path} : ${folder} : ${files_to_extract}") + extract(${archive_path} ${unpacked_path} ${folder} ${files_to_extract} status) #dont need archive actually after unpacking file(REMOVE_RECURSE "${archive_path}") if (${status}) @@ -106,20 +107,20 @@ function (ExtractWithVersion URL archive_path unpacked_path folder result) set (${result} ${status} PARENT_SCOPE) endfunction (ExtractWithVersion) -function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal resultExt sha256) +function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal resultExt sha256 files_to_extract) debug_message("checking wether archive downloaded : ${archive_path}") set (downloadStatus "NOTOK") if (NOT EXISTS ${archive_path}) - DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256}) + DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256} ${files_to_extract}) if (${result}) set (downloadStatus "OK") endif() else() if (ENABLE_UNSAFE_LOCATIONS) - ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result) + ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result ${files_to_extract}) if(NOT ${result}) - DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256}) + DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256} ${files_to_extract}) if (${result}) set (downloadStatus "OK") endif() @@ -127,7 +128,7 @@ function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal else() debug_message("archive found on FS : ${archive_path}, however we cannot check it's checksum and think that it is invalid") file(REMOVE_RECURSE "${archive_path}") - DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256}) + DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result ${sha256} ${files_to_extract}) if (${result}) set (downloadStatus "OK") endif() @@ -147,7 +148,7 @@ endfunction(DownloadOrExtractInternal) file(REMOVE ${CMAKE_BINARY_DIR}/dependencies_64.txt) -function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked_path result_path folder fattal resultExt use_alternatives sha256) +function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked_path result_path folder fattal resultExt use_alternatives sha256 files_to_extract) set (archive_path ${TEMP}/download/${archive_name}) set (status "ON") @@ -169,7 +170,7 @@ function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked debug_message ("checking that unpacked directory exist: ${unpacked_path}") if (NOT EXISTS ${unpacked_path}) - DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status ${sha256}) + DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status ${sha256} ${files_to_extract}) else(NOT EXISTS ${unpacked_path}) #path exists, so we would like to check what was unpacked version set (version_file ${unpacked_path}/ie_dependency.info) @@ -200,12 +201,12 @@ function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} archive_path ${archive_path}) debug_message("dependency different: use local path for fetching updated version: ${alternative_path}") - CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} ${result_path} ${folder} ${fattal} ${resultExt} FALSE ${sha256}) + CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} ${result_path} ${folder} ${fattal} ${resultExt} FALSE ${sha256} ${files_to_extract}) else() debug_message("dependency updated: download it again") file(REMOVE_RECURSE "${unpacked_path}") - DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status ${sha256}) + DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status ${sha256} ${files_to_extract}) endif() endif () endif() diff --git a/cmake/developer_package/download/extract.cmake b/cmake/developer_package/download/extract.cmake index 26fc5f7209a..f0a7f3e90b8 100644 --- a/cmake/developer_package/download/extract.cmake +++ b/cmake/developer_package/download/extract.cmake @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -function (extract archive_path unpacked_path folder result) +function (extract archive_path unpacked_path folder files_to_extract result) # Slurped from a generated extract-TARGET.cmake file. get_filename_component(unpacked_dir ${unpacked_path} DIRECTORY) @@ -24,20 +24,24 @@ function (extract archive_path unpacked_path folder result) message("unpacked_dir= ${unpacked_dir}") endif() - message(STATUS "extracting... [tar xfz]") - execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${archive_path} + string(REGEX REPLACE ";" " " list_files_to_extract "${${files_to_extract}}") + message(STATUS "extracting... [tar xfz] ${list_files_to_extract}") + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${archive_path} ${${files_to_extract}} WORKING_DIRECTORY ${unpacked_dir} RESULT_VARIABLE rv ERROR_VARIABLE err) - if (NOT (err STREQUAL "")) + if (NOT (rv EQUAL 0)) message(STATUS "error: extract of '${archive_path}' failed: ${err}") #invalid archive file(REMOVE_RECURSE "${unpacked_path}") file(REMOVE_RECURSE "${archive_path}") set(${result} 0 PARENT_SCOPE) else() + if (NOT (err STREQUAL "")) + message(STATUS "${err}") + endif() set(${result} 1 PARENT_SCOPE) endif() -endfunction (extract) \ No newline at end of file +endfunction (extract) diff --git a/inference-engine/cmake/dependencies.cmake b/inference-engine/cmake/dependencies.cmake index 8dd7d3e164d..b4c3f947761 100644 --- a/inference-engine/cmake/dependencies.cmake +++ b/inference-engine/cmake/dependencies.cmake @@ -307,13 +307,22 @@ if (ENABLE_GNA) set(GNA_HASH "cc954e67525006bf8bd353a6682e38bf208f6d74e973e0fc292850e721f17452") endif() if(GNA_LIBRARY_VERSION STREQUAL "GNA2") - set(GNA_VERSION "02.00.00.1047.1") - set(GNA_HASH "20820e07392a1e876cf5577430c1c4c74b924d8f34cc17bfa3e36e641555e05d") + set(GNA_VERSION "02.00.00.1191.0") + set(GNA_HASH "a61b4a9133549b0a9f0b46d069f72906ced28bcbbe7d5c361e687645f53a1c8b") endif() + + set(FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/include) + if (WIN32) + LIST(APPEND FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/win64) + else() + LIST(APPEND FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/linux) + endif() + RESOLVE_DEPENDENCY(GNA ARCHIVE_UNIFIED "GNA/GNA_${GNA_VERSION}.zip" TARGET_PATH "${TEMP}/gna_${GNA_VERSION}" VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+.[0-9]+).*" + FILES_TO_EXTRACT FILES_TO_EXTRACT_LIST SHA256 ${GNA_HASH}) endif() update_deps_cache(GNA "${GNA}" "Path to GNA root folder") From 6910a737e023b1dfb05b5c945a8fc882aaab41dc Mon Sep 17 00:00:00 2001 From: Piotr Szmelczynski Date: Wed, 21 Apr 2021 10:33:48 +0200 Subject: [PATCH 26/78] Revise floor mod (#5058) * add floor_mod type prop test to CMakeList * create floor_mod type prop tests * create op_eval tests for floor mod * Update copyright * add op to summarize.py * update copyright * remove unused variable * add tests for int64 and int32 * clear unit test file * Change second input generation of single layer test of cpu plugin to also generate negative numbers for floorMod * Update test results and remove one test * fix bug with secondaryInput shape * add backend tests * add new line * create additional backend tests * Update backend tests --- .../plugin/cpu/single_layer_tests/eltwise.cpp | 10 +- .../layer_tests_summary/summarize.py | 1 + ngraph/test/CMakeLists.txt | 2 + ngraph/test/backend/floor_mod.in.cpp | 118 +++++++++++++ ngraph/test/op_eval/floor_mod.cpp | 159 +++++++++++++----- ngraph/test/type_prop/floor_mod.cpp | 9 + 6 files changed, 259 insertions(+), 40 deletions(-) create mode 100644 ngraph/test/backend/floor_mod.in.cpp create mode 100644 ngraph/test/type_prop/floor_mod.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/eltwise.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/eltwise.cpp index 9d5e4f1bf11..2079dd7945a 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/eltwise.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/eltwise.cpp @@ -77,11 +77,19 @@ protected: std::shared_ptr secondaryInput; if (eltwiseType == ngraph::helpers::EltwiseTypes::DIVIDE || - eltwiseType == ngraph::helpers::EltwiseTypes::FLOOR_MOD || eltwiseType == ngraph::helpers::EltwiseTypes::MOD) { std::vector data(ngraph::shape_size(shape_input_secondary)); data = NGraphFunctions::Utils::generateVector(ngraph::shape_size(shape_input_secondary), 10, 2); secondaryInput = ngraph::builder::makeConstant(ngPrc, shape_input_secondary, data); + } else if (eltwiseType == ngraph::helpers::EltwiseTypes::FLOOR_MOD) { + int negative_data_size = ngraph::shape_size(shape_input_secondary) / 2; + int positive_data_size = ngraph::shape_size(shape_input_secondary) - negative_data_size; + std::vector negative_data(negative_data_size); + std::vector data(positive_data_size); + negative_data = NGraphFunctions::Utils::generateVector(negative_data_size, -10, -2); + data = NGraphFunctions::Utils::generateVector(positive_data_size, 10, 2); + data.insert(data.end(), negative_data.begin(), negative_data.end()); + secondaryInput = ngraph::builder::makeConstant(ngPrc, shape_input_secondary, data); } else { secondaryInput = ngraph::builder::makeInputLayer(ngPrc, secondaryInputType, shape_input_secondary); if (secondaryInputType == ngraph::helpers::InputLayerType::PARAMETER) { diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index f263907ab6b..472f9ea0bef 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -46,6 +46,7 @@ verified_operations = [ 'ExperimentalDetectronPriorGridGenerator-6', 'ExperimentalDetectronROIFeatureExtractor-6', 'ExperimentalDetectronTopKROIs-6', + 'FloorMod-1' 'GRUSequence-5', 'Gather-1', 'GatherElements-6', diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 30b5a01ddf1..cde5f42462e 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -127,6 +127,7 @@ set(SRC type_prop/embeddingbag_packedsum.cpp type_prop/embedding_segments_sum.cpp type_prop/fake_quantize.cpp + type_prop/floor_mod.cpp type_prop/gather.cpp type_prop/gather_elements.cpp type_prop/gather_nd.cpp @@ -332,6 +333,7 @@ set(MULTI_TEST_SRC backend/erf.in.cpp backend/exp.in.cpp backend/floor.in.cpp + backend/floor_mod.in.cpp backend/function_name.in.cpp backend/fused_op.in.cpp backend/gather.in.cpp diff --git a/ngraph/test/backend/floor_mod.in.cpp b/ngraph/test/backend/floor_mod.in.cpp new file mode 100644 index 00000000000..c845fd466d8 --- /dev/null +++ b/ngraph/test/backend/floor_mod.in.cpp @@ -0,0 +1,118 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include +#include + +// clang-format off +#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS +#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS +#endif + +#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS +#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS +#endif +// clang-format on + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" +#include "util/test_control.hpp" + +using namespace std; +using namespace ngraph; + +static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); + +NGRAPH_TEST(${BACKEND_NAME}, floor_mod_int32) +{ + Shape shape{4}; + + auto A = make_shared(element::i32, shape); + auto B = make_shared(element::i32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{7, -7, 7, -7}; + std::vector b{3, 3, -3, -3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -2, -1}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, floor_mod_int64) +{ + Shape shape{4}; + + auto A = make_shared(element::i32, shape); + auto B = make_shared(element::i32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{7, -7, 7, -7}; + std::vector b{3, 3, -3, -3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -2, -1}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, floor_mod_float) +{ + Shape shape{4}; + + auto A = make_shared(element::f32, shape); + auto B = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{7, -7, 7, -7}; + std::vector b{3, 3, -3, -3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -2, -1}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, floor_mod_broadcasted) +{ + Shape shape_a{2, 1, 2}; + Shape shape_b{2, 1}; + Shape shape_r{2, 2, 2}; + + auto A = make_shared(element::f32, shape_a); + auto B = make_shared(element::f32, shape_b); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{1, 2, 3, 4}; + std::vector b{2, 3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape_r, {1.0f, 0.0f, 1.0f, 2.0f, + 1.0f, 0.0f, 0.0f, 1.0f}); + test_case.run(); +} +NGRAPH_TEST(${BACKEND_NAME}, floor_mod_scalars) +{ + Shape shape{}; + auto A = make_shared(element::f32, shape); + auto B = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{2}; + std::vector b{4}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {2.0f}); + test_case.run(); +} diff --git a/ngraph/test/op_eval/floor_mod.cpp b/ngraph/test/op_eval/floor_mod.cpp index cc1ffdc102d..99ab29eb533 100644 --- a/ngraph/test/op_eval/floor_mod.cpp +++ b/ngraph/test/op_eval/floor_mod.cpp @@ -5,57 +5,138 @@ #include #include -#include "gtest/gtest.h" - #include "ngraph/op/floor_mod.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" -#include "runtime/backend.hpp" -#include "util/test_tools.hpp" +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "util/engine/interpreter_engine.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" +#include "util/test_control.hpp" using namespace std; using namespace ngraph; TEST(op_eval, floor_mod) { - auto a = make_shared(element::f32, Shape{4}); - auto b = make_shared(element::f32, Shape{4}); - auto floor_mod = make_shared(a, b); - auto fun = make_shared(OutputVector{floor_mod}, ParameterVector{a, b}); + Shape shape{4}; - std::vector a_value{5.1, -5.1, 5.1, -5.1}; - std::vector b_value{3.0, 3.0, -3.0, -3.0}; - std::vector expected_result{2.1, 0.9, -0.9, -2.1}; + auto A = make_shared(element::f32, shape); + auto B = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto result = make_shared(); - ASSERT_TRUE(fun->evaluate({result}, - {make_host_tensor(Shape{4}, a_value), - make_host_tensor(Shape{4}, b_value)})); - EXPECT_EQ(result->get_element_type(), element::f32); - EXPECT_EQ(result->get_shape(), Shape{4}); - auto result_data = read_vector(result); - for (size_t i = 0; i < expected_result.size(); i++) - EXPECT_NEAR(result_data[i], expected_result[i], 0.000001); + std::vector a{5.1, -5.1, 5.1, -5.1}; + std::vector b{3.0, 3.0, -3.0, -3.0}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {2.1, 0.9, -0.9, -2.1}); + test_case.run(); } -TEST(op_eval, floor_mod_i32) +TEST(op_eval, floor_mod_broadcasted) { - auto a = make_shared(element::i32, Shape{6}); - auto b = make_shared(element::i32, Shape{6}); - auto floor_mod = make_shared(a, b); - auto fun = make_shared(OutputVector{floor_mod}, ParameterVector{a, b}); + Shape shape_a{2, 1, 2}; + Shape shape_b{2, 1}; + Shape shape_r{2, 2, 2}; - std::vector a_value{-4, 7, 5, 4, -7, 8}; - std::vector b_value{2, -3, 8, -2, 3, 5}; - std::vector expected_result{0, -2, 5, 0, 2, 3}; + auto A = make_shared(element::f32, shape_a); + auto B = make_shared(element::f32, shape_b); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto result = make_shared(); - ASSERT_TRUE(fun->evaluate({result}, - {make_host_tensor(Shape{6}, a_value), - make_host_tensor(Shape{6}, b_value)})); - EXPECT_EQ(result->get_element_type(), element::i32); - EXPECT_EQ(result->get_shape(), Shape{6}); - auto result_data = read_vector(result); - for (size_t i = 0; i < expected_result.size(); i++) - EXPECT_NEAR(result_data[i], expected_result[i], 0.000001); + std::vector a{1, 2, 3, 4}; + std::vector b{2, 3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape_r, {1.0f, 0.0f, 1.0f, 2.0f, + 1.0f, 0.0f, 0.0f, 1.0f}); + test_case.run(); +} + +TEST(op_eval, floor_mod_scalars) +{ + Shape shape{}; + auto A = make_shared(element::f32, shape); + auto B = make_shared(element::f32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{2}; + std::vector b{3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {2.0f}); + test_case.run(); +} + +TEST(op_eval, floor_mod_vector_scalar) +{ + Shape shape_a{2, 2}; + Shape shape_b{}; + + auto A = make_shared(element::f32, shape_a); + auto B = make_shared(element::f32, shape_b); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{2, 3, 4, 5}; + std::vector b{2}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape_a, {0.0f, 1.0f, 0.0f, 1.0f}); + test_case.run(); +} + +TEST(op_eval, floor_mod_int64) +{ + Shape shape{4}; + + auto A = make_shared(element::i64, shape); + auto B = make_shared(element::i64, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{5, -5, 5, -5}; + std::vector b{3, 3, -3, -3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {2, 1, -1, -2}); + test_case.run(); +} + +TEST(op_eval, floor_mod_broadcasted_int64) +{ + Shape shape_a{2, 1, 2}; + Shape shape_b{2, 1}; + Shape shape_r{2, 2, 2}; + + auto A = make_shared(element::i64, shape_a); + auto B = make_shared(element::i64, shape_b); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{1, 2, 3, 4}; + std::vector b{2, 3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape_r, {1, 0, 1, 2, + 1, 0, 0, 1}); + test_case.run(); +} + +TEST(op_eval, floor_mod_int32) +{ + Shape shape{4}; + + auto A = make_shared(element::i32, shape); + auto B = make_shared(element::i32, shape); + auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); + + std::vector a{5, -5, 5, -5}; + std::vector b{3, 3, -3, -3}; + + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {2, 1, -1, -2}); + test_case.run(); } diff --git a/ngraph/test/type_prop/floor_mod.cpp b/ngraph/test/type_prop/floor_mod.cpp new file mode 100644 index 00000000000..243e6f3c6e8 --- /dev/null +++ b/ngraph/test/type_prop/floor_mod.cpp @@ -0,0 +1,9 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_floormod, ArithmeticOperator, Type); From f3ef302114d2c5a4345c431d63d90c83262c73ce Mon Sep 17 00:00:00 2001 From: Piotr Szmelczynski Date: Wed, 21 Apr 2021 10:34:03 +0200 Subject: [PATCH 27/78] Revise maximum (#5086) * add floor_mode type_prop tests to CMakeList * create type_prop tests * create additional unit tests * add maximum to summarize.py --- .../layer_tests_summary/summarize.py | 1 + ngraph/test/CMakeLists.txt | 1 + ngraph/test/backend/maximum.in.cpp | 62 +++++++------------ ngraph/test/type_prop/maximum.cpp | 9 +++ 4 files changed, 32 insertions(+), 41 deletions(-) create mode 100644 ngraph/test/type_prop/maximum.cpp diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index 472f9ea0bef..5f84a57cfe0 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -65,6 +65,7 @@ verified_operations = [ 'LogSoftmax-5', 'Loop-5', 'MVN-6', + 'Maximum-1', 'MaxPool-1', 'Mish-4', 'Multiply-1', diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index cde5f42462e..6ac7d9c7fe4 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -147,6 +147,7 @@ set(SRC type_prop/lstm_sequence.cpp type_prop/loop.cpp type_prop/matmul.cpp + type_prop/maximum.cpp type_prop/max_pool.cpp type_prop/minimum.cpp type_prop/mish.cpp diff --git a/ngraph/test/backend/maximum.in.cpp b/ngraph/test/backend/maximum.in.cpp index 1a49269f79c..521d272a311 100644 --- a/ngraph/test/backend/maximum.in.cpp +++ b/ngraph/test/backend/maximum.in.cpp @@ -20,19 +20,16 @@ // clang-format on #include "gtest/gtest.h" -#include "runtime/backend.hpp" -#include "ngraph/runtime/tensor.hpp" #include "ngraph/ngraph.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" -#include "util/test_tools.hpp" using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); NGRAPH_TEST(${BACKEND_NAME}, maximum) { @@ -41,19 +38,13 @@ NGRAPH_TEST(${BACKEND_NAME}, maximum) auto B = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 8, -8, 17, -0.5, 0.5, 2, 1}; + std::vector b{1, 2, 4, 8, 0, 0, 1, 1.5}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 8, -8, 17, -0.5, 0.5, 2, 1}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8, 0, 0, 1, 1.5}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{1, 8, 4, 17, 0, 0.5, 2, 1.5}), - read_vector(result))); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 8, 4, 17, 0, 0.5, 2, 1.5}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, maximum_int32) @@ -63,18 +54,13 @@ NGRAPH_TEST(${BACKEND_NAME}, maximum_int32) auto B = make_shared(element::i32, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{0x40000140, 0x40000001, -8, 17}; + std::vector b{0x40000170, 0x40000000, 4, 8}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{0x40000140, 0x40000001, -8, 17}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{0x40000170, 0x40000000, 4, 8}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{0x40000170, 0x40000001, 4, 17}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {0x40000170, 0x40000001, 4, 17}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, maximum_int64) @@ -84,17 +70,11 @@ NGRAPH_TEST(${BACKEND_NAME}, maximum_int64) auto B = make_shared(element::i64, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 8, -8, 17, -5, 67635216, 2, 17179887632}; + std::vector b{1, 2, 4, 8, 0, 18448, 1, 280592}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i64, shape); - copy_data(a, vector{1, 8, -8, 17, -5, 67635216, 2, 17179887632}); - auto b = backend->create_tensor(element::i64, shape); - copy_data(b, vector{1, 2, 4, 8, 0, 18448, 1, 280592}); - auto result = backend->create_tensor(element::i64, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{1, 8, 4, 17, 0, 67635216, 2, 17179887632}), - read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 8, 4, 17, 0, 67635216, 2, 17179887632}); + test_case.run(); } diff --git a/ngraph/test/type_prop/maximum.cpp b/ngraph/test/type_prop/maximum.cpp new file mode 100644 index 00000000000..51ac0a79858 --- /dev/null +++ b/ngraph/test/type_prop/maximum.cpp @@ -0,0 +1,9 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_maximum, ArithmeticOperator, Type); From 9e6d3bf40a6e4cf3e4934b0bd7e0890e878f971f Mon Sep 17 00:00:00 2001 From: Vladimir Zinoviev Date: Wed, 21 Apr 2021 12:53:49 +0300 Subject: [PATCH 28/78] [CPU] Plugin fuse negative and denormal scales in FQ (#5159) [LPT] Not fuse inf resulted scales in FQ --- .../src/fake_quantize.cpp | 42 +++--- .../mkldnn_plugin/mkldnn_graph_optimizer.cpp | 38 ++++-- .../src/fuse_scaleshift_and_fakequantize.cpp | 121 ++++++++++++++++++ .../runtime_precision.cpp | 2 +- 4 files changed, 167 insertions(+), 36 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/subgraph_tests/src/fuse_scaleshift_and_fakequantize.cpp diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp index d57fcb6b419..8edf710623a 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize.cpp @@ -115,7 +115,8 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis const std::shared_ptr eltwise = fakeQuantize->get_input_node_shared_ptr(0); std::shared_ptr inputLowConst_f32 = fold(fakeQuantize->get_input_node_shared_ptr(1), deqPrecision); - std::shared_ptr inputHightConst_f32 = fold(fakeQuantize->get_input_node_shared_ptr(2), deqPrecision); + std::shared_ptr inputHighConst_f32 = fold(fakeQuantize->get_input_node_shared_ptr(2), deqPrecision); + std::shared_ptr constant = fq::getConstant(eltwise); if (is_type(eltwise) && checkElementwise(eltwise)) { @@ -124,42 +125,29 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis fold(constant, deqPrecision); const auto valueVec = as_type_ptr(value)->cast_vector(); - // TODO: temporary fix for GPU Plugin (inverted intervals) - for (const float& val : valueVec) { - if (val < 0) { - return nullptr; - } - } - // avoid division by zero - if (std::any_of(valueVec.cbegin(), valueVec.cend(), [](const float value) { return (value == 0.f) || (std::abs(value) < 1.e-32); })) { + if (std::any_of(valueVec.cbegin(), valueVec.cend(), [](const float value) { return value <= 0.f; })) { return nullptr; } - inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_shape(0)); - inputHightConst_f32 = fq::updateShape(fold(inputHightConst_f32, value), fakeQuantize->get_output_shape(0)); - } else if (is_type(eltwise) && checkElementwise(eltwise)) { - const auto value = constant->get_output_element_type(0) == deqPrecision ? - constant : - fold(constant, deqPrecision); - - const auto valueVec = as_type_ptr(value)->cast_vector(); - // TODO: temporary fix for GPU Plugin (inverted intervals) - for (const float& val : valueVec) { - if (val < 0) { - return nullptr; - } + inputLowConst_f32 = fold(inputLowConst_f32, value); + inputHighConst_f32 = fold(inputHighConst_f32, value); + const auto resultLow = as_type_ptr(inputLowConst_f32)->cast_vector(); + const auto resultHigh = as_type_ptr(inputHighConst_f32)->cast_vector(); + if (std::any_of(resultLow.begin(), resultLow.end(), [](const float value){ return std::isinf(value); }) || + std::any_of(resultHigh.begin(), resultHigh.end(), [](const float value){ return std::isinf(value); })) { + return nullptr; } - inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_shape(0)); - inputHightConst_f32 = fq::updateShape(fold(inputHightConst_f32, value), fakeQuantize->get_output_shape(0)); + inputLowConst_f32 = fq::updateShape(inputLowConst_f32, fakeQuantize->get_output_shape(0)); + inputHighConst_f32 = fq::updateShape(inputHighConst_f32, fakeQuantize->get_output_shape(0)); } else if (is_type(eltwise) && checkElementwise(eltwise)) { const auto value = constant->get_output_element_type(0) == deqPrecision ? constant : fold(constant, deqPrecision); inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_shape(0)); - inputHightConst_f32 = fq::updateShape(fold(inputHightConst_f32, value), fakeQuantize->get_output_shape(0)); + inputHighConst_f32 = fq::updateShape(fold(inputHighConst_f32, value), fakeQuantize->get_output_shape(0)); } else if (is_type(eltwise) && checkElementwise(eltwise)) { if (is_type(fq::getData(eltwise)) || is_type(fq::getData(eltwise))) { @@ -171,7 +159,7 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis fold(constant, deqPrecision); inputLowConst_f32 = fq::updateShape(fold(inputLowConst_f32, value), fakeQuantize->get_output_shape(0)); - inputHightConst_f32 = fq::updateShape(fold(inputHightConst_f32, value), fakeQuantize->get_output_shape(0)); + inputHighConst_f32 = fq::updateShape(fold(inputHighConst_f32, value), fakeQuantize->get_output_shape(0)); } else if (is_type(eltwise)) { // issue #40611 if ((eltwise->input(0).get_element_type() == element::i32) && @@ -187,7 +175,7 @@ std::shared_ptr FakeQuantizeTransformation::fuseElementwis std::shared_ptr newFakeQuantize = as_type_ptr(fakeQuantize->clone_with_new_inputs({ data->output(outputIdx), inputLowConst_f32, - inputHightConst_f32, + inputHighConst_f32, fold(fakeQuantize->input_value(3), deqPrecision), fold(fakeQuantize->input_value(4), deqPrecision) })); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp index 73c353960a1..cb339748695 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp @@ -2052,7 +2052,7 @@ void MKLDNNGraphOptimizer::FuseScaleShiftAndQuantize(MKLDNNGraph &graph) { return false; for (int i = 0; i < scalesBlob->size(); i++) - if (scalesBufferPtr[i] <= 0.f) + if (scalesBufferPtr[i] == 0.f) return false; const std::vector& cropLowData = quantizeNode->getCropLow(); @@ -2067,27 +2067,49 @@ void MKLDNNGraphOptimizer::FuseScaleShiftAndQuantize(MKLDNNGraph &graph) { for (int i = 0; i < newCropLow.size(); i++) { float cl = cropLowData.size() == 1 ? cropLowData[0] : cropLowData[i]; - - newCropLow[i] = (cl - shiftsBufferPtr[i]) / scalesBufferPtr[i]; - } - - for (int i = 0; i < newCropHigh.size(); i++) { float ch = cropHighData.size() == 1 ? cropHighData[0] : cropHighData[i]; - newCropHigh[i] = (ch - shiftsBufferPtr[i]) / scalesBufferPtr[i]; + float newCL = (cl - shiftsBufferPtr[i]) / scalesBufferPtr[i]; + float newCH = (ch - shiftsBufferPtr[i]) / scalesBufferPtr[i]; + + newCropLow[i] = std::min(newCL, newCH); + newCropHigh[i] = std::max(newCL, newCH); + if (std::isinf(newCropLow[i])) { + newCropLow[i] = std::numeric_limits::lowest(); + } + if (std::isinf(newCropHigh[i])) { + newCropHigh[i] = std::numeric_limits::max(); + } } + std::vector zeroShift(newInputScale.size(), 0.f); + for (int i = 0; i < newInputScale.size(); i++) { float isc = inputScaleData.size() == 1 ? inputScaleData[0] : inputScaleData[i]; newInputScale[i] = isc * scalesBufferPtr[i]; + if (std::abs(newInputScale[i]) < std::numeric_limits::min()) { + newInputScale[i] = 0.f; + // zero value have to be shifted if it's not in input range + float cl = cropLowData.size() == 1 ? cropLowData[0] : cropLowData[i]; + float ch = cropHighData.size() == 1 ? cropHighData[0] : cropHighData[i]; + if (0.f < cl) { + zeroShift[i] = isc * cl; + } + if (ch < 0.f) { + zeroShift[i] = isc * ch; + } + } } for (int i = 0; i < newInputShift.size(); i++) { float isc = inputScaleData.size() == 1 ? inputScaleData[0] : inputScaleData[i]; float ish = inputShiftData.size() == 1 ? inputShiftData[0] : inputShiftData[i]; - newInputShift[i] = ish + shiftsBufferPtr[i] * isc; + newInputShift[i] = ish + shiftsBufferPtr[i] * isc + zeroShift[i]; + if (std::abs(newInputShift[i]) < std::numeric_limits::min()) { + newInputShift[i] = 0.f; + } } quantizeNode->setCropLow(newCropLow); diff --git a/inference-engine/tests/functional/plugin/cpu/subgraph_tests/src/fuse_scaleshift_and_fakequantize.cpp b/inference-engine/tests/functional/plugin/cpu/subgraph_tests/src/fuse_scaleshift_and_fakequantize.cpp new file mode 100644 index 00000000000..871d93ab688 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/subgraph_tests/src/fuse_scaleshift_and_fakequantize.cpp @@ -0,0 +1,121 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "low_precision/common/dequantization_op.hpp" + +using namespace ngraph; +using FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc; + +namespace CPUSubgraphTestsDefinitions { +typedef std::tuple< + Shape, // Input shape + element::Type, // Input precision + std::pair, std::vector>, // ScaleShift scales and shifts + std::vector>, // Quantize intervals + std::string // Device name +> FuseScaleShiftAndQuantizeTuple; + +class FuseScaleShiftAndFakeQuantizeTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + Shape inputShape; + element::Type inputPrecision; + std::pair, std::vector> scaleShift; + std::vector> quantizeIntervals; + std::string targetName; + std::tie(inputShape, inputPrecision, scaleShift, quantizeIntervals, targetName) = obj.param; + std::ostringstream results; + + results << "IS=" << inputShape + << "_InPRC=" << inputPrecision + << "_Scale=" << vector_to_string(scaleShift.first) + << "_Shift=" << vector_to_string(scaleShift.second) + << "_Intervals="; + for (const auto vecInt : quantizeIntervals) { + results << vector_to_string(vecInt) << ","; + } + + results << "targetDevice=" << targetName; + + return results.str(); + } + +protected: + void SetUp() { + threshold = 0.1f; + + Shape inputShape; + element::Type inputPrecision; + std::pair, std::vector> scaleShift; + std::vector> quantizeIntervals; + std::tie(inputShape, inputPrecision, scaleShift, quantizeIntervals, targetDevice) = this->GetParam(); + + const auto param = std::make_shared(inputPrecision, inputShape); + Shape constShape = Shape(inputShape.size(), 1); + constShape[1] = scaleShift.second.size(); + const auto subtract = std::make_shared( + param, + std::make_shared(inputPrecision, constShape, scaleShift.second)); + const auto multiply = std::make_shared( + param, + std::make_shared(inputPrecision, constShape, scaleShift.first)); + Shape inConstShape = Shape(inputShape.size(), 1); + inConstShape[1] = quantizeIntervals[0].size(); + const auto quantize = builder::makeFakeQuantize( + multiply, + inputPrecision, + 256, + inConstShape, + quantizeIntervals[0], + quantizeIntervals[1], + quantizeIntervals[2], + quantizeIntervals[3]); + ngraph::ResultVector results{std::make_shared(quantize)}; + function = std::make_shared(results, ngraph::ParameterVector{param}, "FuseScaleShiftAndQuantize"); + } +}; + +TEST_P(FuseScaleShiftAndFakeQuantizeTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); +} + +namespace { +std::vector inputShapes { + {1, 4, 16, 16}, {8, 4, 16, 16}, + {1, 4, 16, 16, 16}, {8, 4, 16, 16, 16}, + {1, 4, 16, 16, 16, 16}, {8, 4, 16, 16, 16, 16} +}; + +std::vector, std::vector>> scaleShifts { + { {30.f}, {17.f} }, // actually fused in LPT + { {-30.f}, {0.f} }, // fused with crop bound invert + { {-17.f}, {12.f} }, // fused with crop bound invert + { {-1.23e-44}, {0.f} }, // fused with denormal handling + { {0.f}, {0.f} }, // not fused + { {0.f}, {18.f} }, // not fused +}; + +std::vector>> quantizes { + { {-1.f}, {5.f}, {-5.f}, {1.f} }, + { {2.f}, {4.f}, {-4.f}, {-2.f} }, + { {-1.28f}, {1.27f}, {-1.28f}, {1.27f} }, + { {0.f}, {2.55f}, {0.f}, {2.55f} }, +}; + +INSTANTIATE_TEST_CASE_P(smoke_FuseScaleShiftAndFakeQuantize, FuseScaleShiftAndFakeQuantizeTest, + ::testing::Combine( + ::testing::ValuesIn(inputShapes), + ::testing::Values(element::f32), + ::testing::ValuesIn(scaleShifts), + ::testing::ValuesIn(quantizes), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + FuseScaleShiftAndFakeQuantizeTest::getTestCaseName); +} // namespace +} // namespace CPUSubgraphTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/execution_graph_tests/runtime_precision.cpp b/inference-engine/tests/functional/plugin/shared/src/execution_graph_tests/runtime_precision.cpp index 3802d27a9b4..607d6217e7e 100644 --- a/inference-engine/tests/functional/plugin/shared/src/execution_graph_tests/runtime_precision.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/execution_graph_tests/runtime_precision.cpp @@ -127,7 +127,7 @@ TEST_P(ExecGraphRuntimePrecision, CheckRuntimePrecision) { if (expectedPrc.second.name() != rtPrecisionPtr->get()) FAIL() << "`" << expectedPrc.first << "' node runtime precision mismatch: actual = " << - expectedPrc.second.name() << ", expected = " << rtPrecisionPtr->get(); + rtPrecisionPtr->get() << ", expected = " << expectedPrc.second.name(); } fnPtr.reset(); From 0cbcc519edbf559da2fdf834df2e14b49fa5fbee Mon Sep 17 00:00:00 2001 From: Bartosz Sledz Date: Wed, 21 Apr 2021 12:07:47 +0200 Subject: [PATCH 29/78] Change ONNX Operator GroupNorm to use 4D input for MVN (#5324) --- .../src/op/org.openvinotoolkit/group_norm.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp index 3e91c6ca4c1..30076dafc8d 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp @@ -25,7 +25,7 @@ namespace ngraph // This function creates a shape to which we need to reshape the input // before normalization. // If data shape is [N,C,H,W], the function returns - // [N, num_groups, C // num_groups, H, W] + // [N * num_groups, C // num_groups, H, W] std::shared_ptr create_group_norm_shape(const Output& data, size_t num_groups) { @@ -38,9 +38,11 @@ namespace ngraph auto splits = builder::opset1::split(shape, rank_size); auto num_groups_const = default_opset::Constant::create(element::i64, Shape{1}, {num_groups}); + // The 4D shape: [N * num_groups, C // num_groups, H, W] is created + // instead of 5D shape: [N, num_groups, C // num_groups, H, W]. + // The reason is the lack of support for 5D MVN input by some plugins. ngraph::OutputVector new_shape{ - splits[0], - num_groups_const, + std::make_shared(splits[0], num_groups_const), std::make_shared(splits[1], num_groups_const)}; for (size_t i = 2; i < rank_size; i++) @@ -73,7 +75,7 @@ namespace ngraph auto data_reshaped = std::make_shared( data, detail::create_group_norm_shape(data, num_groups), true); const auto reduction_axes = - common::get_monotonic_range_along_node_rank(data_reshaped, 2); + common::get_monotonic_range_along_node_rank(data_reshaped, 1); auto mvn = std::make_shared(data_reshaped, From e44f0cb2ac423265f55042bf6316668361599842 Mon Sep 17 00:00:00 2001 From: Tomasz Socha Date: Wed, 21 Apr 2021 13:08:40 +0200 Subject: [PATCH 30/78] Switch ONNX Importer to gather v7 (#5084) --- ngraph/frontend/onnx_import/src/default_opset.hpp | 4 ++-- ngraph/frontend/onnx_import/src/op/gather.hpp | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/default_opset.hpp b/ngraph/frontend/onnx_import/src/default_opset.hpp index c06c5124276..52736fe6d15 100644 --- a/ngraph/frontend/onnx_import/src/default_opset.hpp +++ b/ngraph/frontend/onnx_import/src/default_opset.hpp @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/opsets/opset6.hpp" +#include "ngraph/opsets/opset7.hpp" namespace ngraph { namespace onnx_import { - namespace default_opset = ngraph::opset6; + namespace default_opset = ngraph::opset7; } } diff --git a/ngraph/frontend/onnx_import/src/op/gather.hpp b/ngraph/frontend/onnx_import/src/op/gather.hpp index b593ccced7b..3eb2fa0746c 100644 --- a/ngraph/frontend/onnx_import/src/op/gather.hpp +++ b/ngraph/frontend/onnx_import/src/op/gather.hpp @@ -25,13 +25,11 @@ namespace ngraph auto data = ng_inputs.at(0); auto indices = ng_inputs.at(1); auto axis = node.get_attribute_value("axis", 0); - const auto valid_axis = ngraph::normalize_axis( - node.get_description(), axis, data.get_partial_shape().rank()); return {std::make_shared( data, indices, - default_opset::Constant::create(element::i64, Shape{}, {valid_axis}))}; + default_opset::Constant::create(element::i64, Shape{}, {axis}))}; } } // namespace set_1 From b65003ac592d6f265acb85be4a596fb1efed3bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Wed, 21 Apr 2021 13:16:01 +0200 Subject: [PATCH 31/78] Preserve the input names when extracting subgraphs (#5207) --- .../src/detail/subgraph_extraction.cpp | 8 +++---- ...aph__linear_model_deeper_head_cut.prototxt | 4 ++-- .../subgraph__linear_model_head_cut.prototxt | 4 ++-- ngraph/test/onnx/onnx_editor.cpp | 23 ++++++++++++++++++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp b/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp index 079c566fd2e..9bd2692e082 100644 --- a/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp +++ b/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp @@ -159,8 +159,6 @@ namespace edge.m_node_idx, ". Cannot append a new graph input to this node."); - const std::string new_input_name = target_node.output(0) + ":" + edge.m_tensor_name; - // if an edge is connected to an initializer, the initializer is removed and substituted // with an input if (is_graph_initializer(graph, edge.m_tensor_name)) @@ -173,10 +171,10 @@ namespace auto& new_input = *(graph.add_input()); // copy the intermediate tensor properties to the newly created input new_input.MergeFrom(find_tensor_descriptor(graph, edge.m_tensor_name)); - *(new_input.mutable_name()) = new_input_name; + *(new_input.mutable_name()) = edge.m_tensor_name; // attach the new graph input to the target node's input - *target_input = new_input_name; - return {true, InputEdge{edge.m_node_idx, new_input_name}}; + *target_input = edge.m_tensor_name; + return {true, InputEdge{edge.m_node_idx, edge.m_tensor_name}}; } } diff --git a/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_deeper_head_cut.prototxt b/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_deeper_head_cut.prototxt index 6c718ff0b39..bbd569818b2 100644 --- a/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_deeper_head_cut.prototxt +++ b/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_deeper_head_cut.prototxt @@ -4,7 +4,7 @@ doc_string: "This model contains the first few nodes of the ONNX Inception V1 mo graph { name: "Inception V1 fragment" node { - input: "pool1/3x3_s2_1:conv1/7x7_s2_2" + input: "conv1/7x7_s2_2" output: "pool1/3x3_s2_1" name: "" op_type: "MaxPool" @@ -31,7 +31,7 @@ graph { } input { - name: "pool1/3x3_s2_1:conv1/7x7_s2_2" + name: "conv1/7x7_s2_2" type { tensor_type { elem_type: 1 diff --git a/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_head_cut.prototxt b/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_head_cut.prototxt index 46c5056cb63..41984db10ea 100644 --- a/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_head_cut.prototxt +++ b/ngraph/test/models/onnx/model_editor/reference/subgraph__linear_model_head_cut.prototxt @@ -4,7 +4,7 @@ doc_string: "This model contains the first few nodes of the ONNX Inception V1 mo graph { name: "Inception V1 fragment" node { - input: "conv1/7x7_s2_2:conv1/7x7_s2_1" + input: "conv1/7x7_s2_1" output: "conv1/7x7_s2_2" name: "" op_type: "Relu" @@ -37,7 +37,7 @@ graph { } input { - name: "conv1/7x7_s2_2:conv1/7x7_s2_1" + name: "conv1/7x7_s2_1" type { tensor_type { elem_type: 1 diff --git a/ngraph/test/onnx/onnx_editor.cpp b/ngraph/test/onnx/onnx_editor.cpp index defcf6745ba..84aa9333b3c 100644 --- a/ngraph/test/onnx/onnx_editor.cpp +++ b/ngraph/test/onnx/onnx_editor.cpp @@ -655,7 +655,7 @@ NGRAPH_TEST(onnx_editor, subgraph__inputs_getter) editor.cut_graph_fragment({{InputEdge(1, "conv1/7x7_s2_1")}}, {}); - EXPECT_EQ(editor.model_inputs(), (std::vector{"conv1/7x7_s2_2:conv1/7x7_s2_1"})); + EXPECT_EQ(editor.model_inputs(), (std::vector{"conv1/7x7_s2_1"})); } using TestEngine = test::INTERPRETER_Engine; @@ -771,3 +771,24 @@ NGRAPH_TEST(onnx_editor, values__append_two_initializers_mixed_types) test_case.add_expected_output(Shape{2, 2, 1}, {1, 4, 5, 8}); test_case.run(); } + +NGRAPH_TEST(onnx_editor, combined__cut_and_replace_shape) +{ + ONNXModelEditor editor{file_util::path_join( + SERIALIZED_ZOO, "onnx/model_editor/subgraph__inception_head.prototxt")}; + + const auto new_shape = PartialShape({1, 64, 112, 112}); + editor.cut_graph_fragment({{InputEdge(1, "conv1/7x7_s2_1")}}, {}); + editor.set_input_shapes({{"conv1/7x7_s2_1", new_shape}}); + + const auto ref_model = file_util::path_join( + SERIALIZED_ZOO, "onnx/model_editor/reference/subgraph__linear_model_head_cut.prototxt"); + + const auto result = compare_onnx_models(editor.model_string(), ref_model); + + EXPECT_TRUE(result.is_ok) << result.error_message; + + const auto graph_inputs = editor.get_function()->get_parameters(); + EXPECT_TRUE( + find_input(graph_inputs, "conv1/7x7_s2_1")->get_partial_shape().same_scheme(new_shape)); +} From 02bc98a03fd23fbb8227a2452c59e75ac6a3ef61 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 21 Apr 2021 16:05:30 +0300 Subject: [PATCH 32/78] Removed suppressions for IInferRequest deprecation (#5310) * Removed suppressions for IInferRequest deprecation * Fixed Windows * More fixes for Windows * Fixed compilation on Windows * Fixed comment in documentatipn * Fixes for Andorid * Fixes for old gcc 4.8 * WA for cross-compilations * Fixed compilation * Fixed HETERO plugin compilation for old compilers * Flags Co-authored-by: lab_ddpqa --- .ci/azure/linux_onnxruntime.yml | 2 +- docs/IE_DG/Glossary.md | 6 +- ...grate_with_customer_application_new_API.md | 4 +- docs/IE_DG/inference_engine_intro.md | 2 +- docs/IE_PLUGIN_DG/Doxyfile | 6 +- docs/doxygen/ie_docs.config | 13 +-- docs/doxygen/ie_plugin_api.config | 6 +- docs/snippets/GPU_RemoteBlob_API2.cpp | 34 ++++---- ...rate_with_customer_application_new_API.cpp | 2 +- docs/snippets/movidius-programming-guide.cpp | 9 +-- .../src/template_executable_network.cpp | 1 - .../openvino/inference_engine/CMakeLists.txt | 2 + .../include/cpp/ie_executable_network.hpp | 80 ++++++++++--------- .../include/cpp/ie_infer_request.hpp | 19 +++-- inference-engine/include/ie_api.h | 16 +++- .../include/ie_iexecutable_network.hpp | 9 +++ .../include/ie_iinfer_request.hpp | 16 +++- .../benchmark_app/infer_request_wrap.hpp | 2 +- .../samples/speech_sample/main.cpp | 2 +- .../src/gna_plugin/gna_infer_request.hpp | 6 +- .../hetero_async_infer_request.cpp | 12 +-- .../hetero_async_infer_request.hpp | 5 -- .../hetero_plugin/hetero_infer_request.cpp | 26 +++--- .../hetero_plugin/hetero_infer_request.hpp | 7 +- .../cpp/ie_executable_network.cpp | 5 +- .../inference_engine/cpp/ie_infer_request.cpp | 16 ++-- .../src/legacy_api/include/legacy/ie_layers.h | 12 +-- .../base/ie_executable_network_base.hpp | 14 ++-- .../base/ie_infer_async_request_base.hpp | 4 + ...nfer_async_request_thread_safe_default.hpp | 13 ++- .../ie_iexecutable_network_internal.hpp | 8 +- .../interface/ie_iinfer_request_internal.hpp | 7 +- .../interface/ie_iplugin_internal.hpp | 1 - .../myriad_plugin/myriad_executable_network.h | 1 - .../async_infer_request_test.cpp | 4 + .../inference_engine/caching_test.cpp | 1 - .../inference_engine/executable_network.cpp | 1 - .../cldnn_remote_blob_tests.cpp | 2 +- .../multi/gpu_remote_blob_tests.cpp | 4 +- .../shared/include/behavior/infer_request.hpp | 34 ++++---- .../behavior/infer_request_callback.hpp | 15 ++-- .../behavior/infer_request_cancellation.hpp | 8 +- .../include/multi/multi_remote_blob_tests.hpp | 4 +- .../impl/mock_async_infer_request_default.hpp | 1 - .../impl/mock_executable_network_internal.hpp | 1 - .../impl/mock_inference_plugin_internal.hpp | 1 - .../mock_iexecutable_network_internal.hpp | 1 - .../ie_executable_network_base_test.cpp | 3 +- .../ie_infer_async_request_base_test.cpp | 2 + ...async_request_thread_safe_default_test.cpp | 6 +- .../ie_executable_network_test.cpp | 10 +-- .../include/classification_matcher.hpp | 1 - .../ie_tests/src/custom_matcher.cpp | 3 +- .../functional/ie_tests/src/raw_matcher.cpp | 2 +- .../io_blob_tests/cropResize_tests.hpp | 16 ++-- .../vpu/common/myriad_hw_network_tests.hpp | 2 +- .../tools/vpu/vpu_perfcheck/main.cpp | 30 ++----- 57 files changed, 273 insertions(+), 247 deletions(-) diff --git a/.ci/azure/linux_onnxruntime.yml b/.ci/azure/linux_onnxruntime.yml index 37173a4560f..5cf4950f333 100644 --- a/.ci/azure/linux_onnxruntime.yml +++ b/.ci/azure/linux_onnxruntime.yml @@ -114,7 +114,7 @@ jobs: - script: | source $(INSTALL_DIR)/bin/setupvars.sh echo "2021.2" > $(INSTALL_DIR)/deployment_tools/inference_engine/version.txt - ./build.sh --config RelWithDebInfo --use_openvino CPU_FP32 --build_shared_lib --parallel --skip_tests --build_dir $(ONNXRUNTIME_BUILD_DIR) + CXXFLAGS="-Wno-error=deprecated-declarations" ./build.sh --config RelWithDebInfo --use_openvino CPU_FP32 --build_shared_lib --parallel --skip_tests --build_dir $(ONNXRUNTIME_BUILD_DIR) workingDirectory: $(ONNXRUNTIME_REPO_DIR) displayName: 'Build ONNX Runtime' diff --git a/docs/IE_DG/Glossary.md b/docs/IE_DG/Glossary.md index 5a05757977a..41e2b1b1dab 100644 --- a/docs/IE_DG/Glossary.md +++ b/docs/IE_DG/Glossary.md @@ -66,9 +66,9 @@ Glossary of terms used in the Inference Engine | Blob | Memory container used for storing inputs, outputs of the network, weights and biases of the layers | | Device (Affinitity) | A preferred Intel(R) hardware device to run the inference (CPU, GPU, etc.) | | Extensibility mechanism, Custom layers | The mechanism that provides you with capabilities to extend the Inference Engine and Model Optimizer so that they can work with topologies containing layers that are not yet supported | -| ICNNNetwork | An Interface of the Convolutional Neural Network that Inference Engine reads from IR. Consists of topology, weights and biases | -| IExecutableNetwork | An instance of the loaded network which allows the Inference Engine to request (several) infer requests and perform inference synchronously or asynchronously | -| IInferRequest | Interface that represents the end point of inference on the model loaded to the plugin and represented by executable network. Inputs are set here, outputs should be requested from this interface as well | +| CNNNetwork | A class of the Convolutional Neural Network that Inference Engine reads from IR. Consists of topology, weights and biases | +| ExecutableNetwork | An instance of the loaded network which allows the Inference Engine to request (several) infer requests and perform inference synchronously or asynchronously | +| InferRequest | A class that represents the end point of inference on the model loaded to the plugin and represented by executable network. Inputs are set here, outputs should be requested from this interface as well | | InferenceEngineProfileInfo | Represents basic inference profiling information per layer | | Inference Engine | A C++ library with a set of classes that you can use in your application to infer input data (images) and get the result | | Inference Engine API | The basic default API for all supported devices, which allows you to load a model from Intermediate Representation, set input and output formats and execute the model on various devices | diff --git a/docs/IE_DG/Integrate_with_customer_application_new_API.md b/docs/IE_DG/Integrate_with_customer_application_new_API.md index 108c7cd06f3..27cc6b7e32e 100644 --- a/docs/IE_DG/Integrate_with_customer_application_new_API.md +++ b/docs/IE_DG/Integrate_with_customer_application_new_API.md @@ -170,8 +170,8 @@ Call `Wait` for waiting result to become available for asynchronous request. There are three ways to use it: * specify maximum duration in milliseconds to block for. The method is blocked until the specified timeout has elapsed, or the result becomes available, whichever comes first. -* `InferenceEngine::IInferRequest::WaitMode::RESULT_READY` - waits until inference result becomes available -* `InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY` - immediately returns request status.It does not +* `InferenceEngine::InferRequest::WaitMode::RESULT_READY` - waits until inference result becomes available +* `InferenceEngine::InferRequest::WaitMode::STATUS_ONLY` - immediately returns request status.It does not block or interrupts current thread. Both requests are thread-safe: can be called from different threads without fearing corruption and failures. diff --git a/docs/IE_DG/inference_engine_intro.md b/docs/IE_DG/inference_engine_intro.md index c262436d101..717813cdf76 100644 --- a/docs/IE_DG/inference_engine_intro.md +++ b/docs/IE_DG/inference_engine_intro.md @@ -111,7 +111,7 @@ The common workflow contains the following steps: * Synchronously - `InferenceEngine::InferRequest::Infer()` method. Blocks until inference is completed. * Asynchronously - `InferenceEngine::InferRequest::StartAsync()` method. Check status with the `InferenceEngine::InferRequest::Wait()` method (0 timeout), wait, or specify a completion callback. -7. **Get the output** - After inference is completed, get the output memory or read the memory you provided earlier. Do this with the `InferenceEngine::IInferRequest::GetBlob()` method. +7. **Get the output** - After inference is completed, get the output memory or read the memory you provided earlier. Do this with the `InferenceEngine::InferRequest::GetBlob()` method. Further Reading diff --git a/docs/IE_PLUGIN_DG/Doxyfile b/docs/IE_PLUGIN_DG/Doxyfile index e2c4baf4d79..f19c746c7eb 100644 --- a/docs/IE_PLUGIN_DG/Doxyfile +++ b/docs/IE_PLUGIN_DG/Doxyfile @@ -2052,8 +2052,10 @@ PREDEFINED = INFERENCE_PLUGIN_API \ INFERENCE_ENGINE_DEPRECATED \ IE_SUPPRESS_DEPRECATED_START \ IE_SUPPRESS_DEPRECATED_END \ - IE_SUPPRESS_DEPRECATED_START_WIN \ - IE_SUPPRESS_DEPRECATED_END_WIN \ + _IE_SUPPRESS_DEPRECATED_START_MSVC \ + _IE_SUPPRESS_DEPRECATED_END_MSVC \ + _IE_SUPPRESS_DEPRECATED_START_GCC \ + _IE_SUPPRESS_DEPRECATED_END_GCC \ IE_THREAD=IE_THREAD_TBB \ TRANSFORMATIONS_API diff --git a/docs/doxygen/ie_docs.config b/docs/doxygen/ie_docs.config index f6e980fdc26..db424ce7adc 100644 --- a/docs/doxygen/ie_docs.config +++ b/docs/doxygen/ie_docs.config @@ -931,9 +931,10 @@ EXCLUDE_SYMBOLS = InferenceEngine::details \ INFERENCE_ENGINE_DEPRECATED \ IE_SUPPRESS_DEPRECATED_START \ IE_SUPPRESS_DEPRECATED_END \ - IE_SUPPRESS_DEPRECATED_START_WIN \ - IE_SUPPRESS_DEPRECATED_END_WIN \ - IE_SUPPRESS_DEPRECATED_END_WIN \ + _IE_SUPPRESS_DEPRECATED_START_MSVC \ + _IE_SUPPRESS_DEPRECATED_END_MSVC \ + _IE_SUPPRESS_DEPRECATED_START_GCC \ + _IE_SUPPRESS_DEPRECATED_END_GCC \ INFERENCE_ENGINE_INTERNAL \ IE_DO_PRAGMA \ parallel_* \ @@ -2215,8 +2216,10 @@ PREDEFINED = "INFERENCE_ENGINE_API_CLASS=" \ "INFERENCE_ENGINE_DEPRECATED(x)=" \ "IE_SUPPRESS_DEPRECATED_START=" \ "IE_SUPPRESS_DEPRECATED_END=" \ - "IE_SUPPRESS_DEPRECATED_START_WIN=" \ - "IE_SUPPRESS_DEPRECATED_END_WIN=" \ + "_IE_SUPPRESS_DEPRECATED_START_MSVC=" \ + "_IE_SUPPRESS_DEPRECATED_END_MSVC=" \ + "_IE_SUPPRESS_DEPRECATED_START_GCC=" \ + "_IE_SUPPRESS_DEPRECATED_END_GCC=" \ "INFERENCE_ENGINE_NN_BUILDER_API_CLASS=" \ "INFERENCE_ENGINE_NN_BUILDER_DEPRECATED(x)=" \ "INFERENCE_ENGINE_INTERNAL(x)=" \ diff --git a/docs/doxygen/ie_plugin_api.config b/docs/doxygen/ie_plugin_api.config index 08a1381fbcd..8eec3762fb5 100644 --- a/docs/doxygen/ie_plugin_api.config +++ b/docs/doxygen/ie_plugin_api.config @@ -69,8 +69,10 @@ PREDEFINED = "INFERENCE_ENGINE_API=" \ "NGRAPH_HELPER_DLL_IMPORT=" \ "IE_SUPPRESS_DEPRECATED_START=" \ "IE_SUPPRESS_DEPRECATED_END=" \ - "IE_SUPPRESS_DEPRECATED_START_WIN=" \ - "IE_SUPPRESS_DEPRECATED_END_WIN=" \ + "_IE_SUPPRESS_DEPRECATED_START_MSVC=" \ + "_IE_SUPPRESS_DEPRECATED_END_MSVC=" \ + "_IE_SUPPRESS_DEPRECATED_START_GCC=" \ + "_IE_SUPPRESS_DEPRECATED_END_GCC=" \ "IE_THREAD=IE_THREAD_TBB" \ "NGRAPH_RTTI_DECLARATION=" diff --git a/docs/snippets/GPU_RemoteBlob_API2.cpp b/docs/snippets/GPU_RemoteBlob_API2.cpp index da94818d97e..7938b4befb4 100644 --- a/docs/snippets/GPU_RemoteBlob_API2.cpp +++ b/docs/snippets/GPU_RemoteBlob_API2.cpp @@ -27,27 +27,27 @@ VADisplay disp = get_VA_Device(); auto shared_va_context = gpu::make_shared_context(ie, "GPU", disp); // compile network within a shared context ExecutableNetwork executable_network = ie.LoadNetwork(network, - shared_va_context, - { { CLDNNConfigParams::KEY_CLDNN_NV12_TWO_INPUTS, - PluginConfigParams::YES } }); + shared_va_context, + { { CLDNNConfigParams::KEY_CLDNN_NV12_TWO_INPUTS, + PluginConfigParams::YES } }); // decode/inference loop for (int i = 0; i < nframes; i++) { -// ... - // execute decoding and obtain decoded surface handle - decoder.DecodeFrame(); - VASurfaceID va_surface = decoder.get_VA_output_surface(); -// ... - //wrap decoder output into RemoteBlobs and set it as inference input - auto nv12_blob = gpu::make_shared_blob_nv12(ieInHeight, - ieInWidth, - shared_va_context, - va_surface - ); - inferRequests[currentFrame].SetBlob(input_name, nv12_blob); - inferRequests[currentFrame].StartAsync(); - inferRequests[prevFrame].Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); +// ... + // execute decoding and obtain decoded surface handle + decoder.DecodeFrame(); + VASurfaceID va_surface = decoder.get_VA_output_surface(); +// ... + //wrap decoder output into RemoteBlobs and set it as inference input + auto nv12_blob = gpu::make_shared_blob_nv12(ieInHeight, + ieInWidth, + shared_va_context, + va_surface + ); + inferRequests[currentFrame].SetBlob(input_name, nv12_blob); + inferRequests[currentFrame].StartAsync(); + inferRequests[prevFrame].Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); } //! [part2] return 0; diff --git a/docs/snippets/Integrate_with_customer_application_new_API.cpp b/docs/snippets/Integrate_with_customer_application_new_API.cpp index 8793caff157..964e1736953 100644 --- a/docs/snippets/Integrate_with_customer_application_new_API.cpp +++ b/docs/snippets/Integrate_with_customer_application_new_API.cpp @@ -107,7 +107,7 @@ for (auto & item : input_info) { //! [part12] infer_request.StartAsync(); -infer_request.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); +infer_request.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); //! [part12] auto sync_infer_request = executable_network.CreateInferRequest(); diff --git a/docs/snippets/movidius-programming-guide.cpp b/docs/snippets/movidius-programming-guide.cpp index ffd25c8b6cf..78cc72ef919 100644 --- a/docs/snippets/movidius-programming-guide.cpp +++ b/docs/snippets/movidius-programming-guide.cpp @@ -2,14 +2,13 @@ int main() { InferenceEngine::Core core; -InferenceEngine::IInferRequest::CompletionCallback callback = nullptr; int numRequests = 42; int i = 1; auto network = core.ReadNetwork("sample.xml"); auto executable_network = core.LoadNetwork(network, "CPU"); //! [part0] struct Request { - InferenceEngine::InferRequest::Ptr inferRequest; + InferenceEngine::InferRequest inferRequest; int frameidx; }; //! [part0] @@ -21,16 +20,16 @@ std::vector request(numRequests); //! [part2] // initialize infer request pointer – Consult IE API for more detail. -request[i].inferRequest = executable_network.CreateInferRequestPtr(); +request[i].inferRequest = executable_network.CreateInferRequest(); //! [part2] //! [part3] // Run inference -request[i].inferRequest->StartAsync(); +request[i].inferRequest.StartAsync(); //! [part3] //! [part4] -request[i].inferRequest->SetCompletionCallback(callback); +request[i].inferRequest.SetCompletionCallback([] () {}); //! [part4] return 0; diff --git a/docs/template_plugin/src/template_executable_network.cpp b/docs/template_plugin/src/template_executable_network.cpp index 07d6ca2459d..91c1917e5ac 100644 --- a/docs/template_plugin/src/template_executable_network.cpp +++ b/docs/template_plugin/src/template_executable_network.cpp @@ -139,7 +139,6 @@ InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::C // ! [executable_network:create_infer_request] InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequest() { - InferenceEngine::IInferRequest::Ptr asyncRequest; auto internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs); return std::make_shared(std::static_pointer_cast(internalRequest), _taskExecutor, _plugin->_waitExecutor, _callbackExecutor); diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt index 78f22b6500c..a2297ad197b 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt @@ -17,6 +17,8 @@ set_source_files_properties(${SOURCE} PROPERTIES CYTHON_IS_CXX ON) # create target +disable_deprecated_warnings() + cython_add_module(${TARGET_NAME} ${SOURCE}) set(INSTALLED_TARGETS ${TARGET_NAME}) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 19f3970de55..19136fee575 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -73,16 +73,6 @@ public: */ ConstInputsDataMap GetInputsInfo() const; - /** - * @deprecated The method Will be removed - * @brief reset owned object to new pointer. - * - * Essential for cases when simultaneously loaded networks not expected. - * @param newActual actual pointed object - */ - INFERENCE_ENGINE_DEPRECATED("The method will be removed") - void reset(std::shared_ptr newActual); - /** * @brief Creates an inference request object used to infer the network. * @@ -92,16 +82,6 @@ public: */ InferRequest CreateInferRequest(); - /** - * @deprecated Use ExecutableNetwork::CreateInferRequest - * @copybrief IExecutableNetwork::CreateInferRequest - * - * Wraps IExecutableNetwork::CreateInferRequest. - * @return shared pointer on InferenceEngine::InferRequest object - */ - INFERENCE_ENGINE_DEPRECATED("Use ExecutableNetwork::CreateInferRequest instead") - InferRequest::Ptr CreateInferRequestPtr(); - /** * @brief Exports the current executable network. * @@ -120,14 +100,6 @@ public: */ void Export(std::ostream& networkModel); - /** - * @deprecated Will be removed. Use operator bool - * @brief cast operator is used when this wrapper initialized by LoadNetwork - * @return A shared pointer to IExecutableNetwork interface. - */ - INFERENCE_ENGINE_DEPRECATED("The method will be removed. Use operator bool") - operator std::shared_ptr(); - /** * @copybrief IExecutableNetwork::GetExecGraphInfo * @@ -136,17 +108,6 @@ public: */ CNNNetwork GetExecGraphInfo(); - /** - * @deprecated Use InferRequest::QueryState instead - * @brief Gets state control interface for given executable network. - * - * State control essential for recurrent networks - * - * @return A vector of Memory State objects - */ - INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") - std::vector QueryState(); - /** * @brief Sets configuration for current executable network * @@ -196,6 +157,47 @@ public: * @return true if current ExecutableNetwork object is initialized, false - otherwise */ explicit operator bool() const noexcept; + + IE_SUPPRESS_DEPRECATED_START + /** + * @deprecated The method Will be removed + * @brief reset owned object to new pointer. + * + * Essential for cases when simultaneously loaded networks not expected. + * @param newActual actual pointed object + */ + INFERENCE_ENGINE_DEPRECATED("The method will be removed") + void reset(std::shared_ptr newActual); + + /** + * @deprecated Will be removed. Use operator bool + * @brief cast operator is used when this wrapper initialized by LoadNetwork + * @return A shared pointer to IExecutableNetwork interface. + */ + INFERENCE_ENGINE_DEPRECATED("The method will be removed. Use operator bool") + operator std::shared_ptr(); + + /** + * @deprecated Use ExecutableNetwork::CreateInferRequest + * @copybrief IExecutableNetwork::CreateInferRequest + * + * Wraps IExecutableNetwork::CreateInferRequest. + * @return shared pointer on InferenceEngine::InferRequest object + */ + INFERENCE_ENGINE_DEPRECATED("Use ExecutableNetwork::CreateInferRequest instead") + InferRequest::Ptr CreateInferRequestPtr(); + + /** + * @deprecated Use InferRequest::QueryState instead + * @brief Gets state control interface for given executable network. + * + * State control essential for recurrent networks + * + * @return A vector of Memory State objects + */ + INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") + std::vector QueryState(); + IE_SUPPRESS_DEPRECATED_END }; } // namespace InferenceEngine diff --git a/inference-engine/include/cpp/ie_infer_request.hpp b/inference-engine/include/cpp/ie_infer_request.hpp index fc8b5d13a63..fd70469ad5f 100644 --- a/inference-engine/include/cpp/ie_infer_request.hpp +++ b/inference-engine/include/cpp/ie_infer_request.hpp @@ -18,9 +18,9 @@ #include "ie_iinfer_request.hpp" #include "details/ie_so_loader.h" #include "ie_blob.h" -#include "ie_iinfer_request.hpp" namespace InferenceEngine { + namespace details { class SharedObjectLoader; } @@ -112,9 +112,7 @@ public: void Infer(); /** - * @brief Cancel inference request - * @param name Name of input blob. - * @return pointer to pre-process info of blob with name + * @brief Cancels inference request */ void Cancel(); @@ -175,7 +173,10 @@ public: private: void SetCompletionCallbackImpl(std::function); void SetCompletionCallbackImpl(std::function); + IE_SUPPRESS_DEPRECATED_START void SetCompletionCallbackImpl(IInferRequest::CompletionCallback); + IE_SUPPRESS_DEPRECATED_END + template struct SetCallback { void operator()(std::function f) {_this.SetCompletionCallbackImpl(std::move(f));} @@ -193,7 +194,6 @@ public: return SetCallback{*this}(std::move(callbackToSet)); } - /** * @brief Gets state control interface for given infer request. * @@ -202,12 +202,14 @@ public: */ std::vector QueryState(); + IE_SUPPRESS_DEPRECATED_START /** * @brief IInferRequest pointer to be used directly in CreateInferRequest functions * @return A shared pointer to IInferRequest interface */ INFERENCE_ENGINE_DEPRECATED("Will be removed") operator std::shared_ptr (); + IE_SUPPRESS_DEPRECATED_END /** * @brief Checks if current InferRequest object is not initialized @@ -221,6 +223,7 @@ public: */ explicit operator bool() const noexcept; }; + template<> struct InferRequest::SetCallback> { void operator()(std::function f) { @@ -228,6 +231,9 @@ struct InferRequest::SetCallback> } InferRequest& _this; }; + +IE_SUPPRESS_DEPRECATED_START + template<> struct InferRequest::SetCallback { void operator()(IInferRequest::CompletionCallback f) { @@ -235,4 +241,7 @@ struct InferRequest::SetCallback { } InferRequest& _this; }; + +IE_SUPPRESS_DEPRECATED_END + } // namespace InferenceEngine diff --git a/inference-engine/include/ie_api.h b/inference-engine/include/ie_api.h index f640bfaac75..2f64b23313a 100644 --- a/inference-engine/include/ie_api.h +++ b/inference-engine/include/ie_api.h @@ -81,11 +81,19 @@ #endif #ifdef _WIN32 -# define IE_SUPPRESS_DEPRECATED_START_WIN IE_SUPPRESS_DEPRECATED_START -# define IE_SUPPRESS_DEPRECATED_END_WIN IE_SUPPRESS_DEPRECATED_END +# define _IE_SUPPRESS_DEPRECATED_START_MSVC IE_SUPPRESS_DEPRECATED_START +# define _IE_SUPPRESS_DEPRECATED_END_MSVC IE_SUPPRESS_DEPRECATED_END #else -# define IE_SUPPRESS_DEPRECATED_START_WIN -# define IE_SUPPRESS_DEPRECATED_END_WIN +# define _IE_SUPPRESS_DEPRECATED_START_MSVC +# define _IE_SUPPRESS_DEPRECATED_END_MSVC +#endif + +#if defined __GNUC__ && (__GNUC__ <= 4 || defined __i386__ || defined __arm__ || defined __aarch64__) +# define _IE_SUPPRESS_DEPRECATED_START_GCC IE_SUPPRESS_DEPRECATED_START +# define _IE_SUPPRESS_DEPRECATED_END_GCC IE_SUPPRESS_DEPRECATED_END +#else +# define _IE_SUPPRESS_DEPRECATED_START_GCC +# define _IE_SUPPRESS_DEPRECATED_END_GCC #endif #ifndef ENABLE_UNICODE_PATH_SUPPORT diff --git a/inference-engine/include/ie_iexecutable_network.hpp b/inference-engine/include/ie_iexecutable_network.hpp index 16c1e9d971e..526ce8fda81 100644 --- a/inference-engine/include/ie_iexecutable_network.hpp +++ b/inference-engine/include/ie_iexecutable_network.hpp @@ -23,16 +23,21 @@ #include "ie_remote_context.hpp" namespace InferenceEngine { + +_IE_SUPPRESS_DEPRECATED_START_GCC + /** * @brief This is an interface of an executable network */ class INFERENCE_ENGINE_DEPRECATED("Use InferenceEngine::ExecutableNetwork instead") IExecutableNetwork : public std::enable_shared_from_this { public: + IE_SUPPRESS_DEPRECATED_START /** * @brief A smart pointer to the current IExecutableNetwork object */ using Ptr = std::shared_ptr; + IE_SUPPRESS_DEPRECATED_END /** * @brief Gets the Executable network output Data node information. @@ -60,6 +65,7 @@ public: */ virtual StatusCode GetInputsInfo(ConstInputsDataMap& inputs, ResponseDesc* resp) const noexcept = 0; + IE_SUPPRESS_DEPRECATED_START /** * @brief Creates an inference request object used to infer the network. * @@ -70,6 +76,7 @@ public: * @return Status code of the operation: InferenceEngine::OK (0) for success */ virtual StatusCode CreateInferRequest(IInferRequest::Ptr& req, ResponseDesc* resp) noexcept = 0; + IE_SUPPRESS_DEPRECATED_END /** * @brief Exports the current executable network. @@ -173,4 +180,6 @@ protected: ~IExecutableNetwork() = default; }; +_IE_SUPPRESS_DEPRECATED_END_GCC + } // namespace InferenceEngine diff --git a/inference-engine/include/ie_iinfer_request.hpp b/inference-engine/include/ie_iinfer_request.hpp index 658b6d03e54..aa3c355d6f9 100644 --- a/inference-engine/include/ie_iinfer_request.hpp +++ b/inference-engine/include/ie_iinfer_request.hpp @@ -21,11 +21,12 @@ namespace InferenceEngine { +_IE_SUPPRESS_DEPRECATED_START_GCC + /** * @brief This is an interface of asynchronous infer request * */ -IE_SUPPRESS_DEPRECATED_START class INFERENCE_ENGINE_DEPRECATED("Do not use IInferRequest API") IInferRequest : public std::enable_shared_from_this { public: /** @@ -38,6 +39,9 @@ public: /** IInferRequest doesn't block or interrupt current thread and immediately returns inference status */ STATUS_ONLY = 0, }; + + IE_SUPPRESS_DEPRECATED_START + /** * @brief A shared pointer to the IInferRequest object */ @@ -47,6 +51,8 @@ public: */ using WeakPtr = std::weak_ptr; + IE_SUPPRESS_DEPRECATED_END + /** * @brief Sets input/output data to infer * @@ -139,6 +145,8 @@ public: */ virtual StatusCode StartAsync(ResponseDesc* resp) noexcept = 0; + IE_SUPPRESS_DEPRECATED_START + /** * @brief Completion callback definition as pointer to a function * @@ -147,6 +155,8 @@ public: */ typedef void (*CompletionCallback)(InferenceEngine::IInferRequest::Ptr context, InferenceEngine::StatusCode code); + IE_SUPPRESS_DEPRECATED_END + /** * @brief Sets a callback function that will be called on success or failure of asynchronous request * @@ -198,10 +208,12 @@ public: * given index */ virtual StatusCode QueryState(IVariableState::Ptr& pState, size_t idx, ResponseDesc* resp) noexcept = 0; + IE_SUPPRESS_DEPRECATED_END protected: ~IInferRequest() = default; }; -IE_SUPPRESS_DEPRECATED_END + +_IE_SUPPRESS_DEPRECATED_END_GCC } // namespace InferenceEngine \ No newline at end of file diff --git a/inference-engine/samples/benchmark_app/infer_request_wrap.hpp b/inference-engine/samples/benchmark_app/infer_request_wrap.hpp index c003064c144..85d6f679d8a 100644 --- a/inference-engine/samples/benchmark_app/infer_request_wrap.hpp +++ b/inference-engine/samples/benchmark_app/infer_request_wrap.hpp @@ -47,7 +47,7 @@ public: } void wait() { - _request.Wait(InferenceEngine::IInferRequest::RESULT_READY); + _request.Wait(InferenceEngine::InferRequest::RESULT_READY); } void infer() { diff --git a/inference-engine/samples/speech_sample/main.cpp b/inference-engine/samples/speech_sample/main.cpp index 734e4162f2c..98ddc192ec8 100644 --- a/inference-engine/samples/speech_sample/main.cpp +++ b/inference-engine/samples/speech_sample/main.cpp @@ -1086,7 +1086,7 @@ int main(int argc, char *argv[]) { /* waits until inference result becomes available */ if (inferRequest.frameIndex != -1) { StatusCode code = inferRequest.inferRequest.Wait( - InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + InferenceEngine::InferRequest::WaitMode::RESULT_READY); if (code != StatusCode::OK) { if (!useHetero) continue; diff --git a/inference-engine/src/gna_plugin/gna_infer_request.hpp b/inference-engine/src/gna_plugin/gna_infer_request.hpp index 672e9fc4944..e0256b32f2b 100644 --- a/inference-engine/src/gna_plugin/gna_infer_request.hpp +++ b/inference-engine/src/gna_plugin/gna_infer_request.hpp @@ -41,7 +41,7 @@ class GNAInferRequest : public InferenceEngine::IInferRequestInternal { } /** * @brief Infers specified input(s) in synchronous mode - * @note blocks all method of IInferRequest while request is ongoing (running or waiting in queue) + * @note blocks all method of InferRequest while request is ongoing (running or waiting in queue) */ void InferImpl() override { // execute input pre-processing. @@ -77,7 +77,7 @@ class GNAInferRequest : public InferenceEngine::IInferRequestInternal { inferRequestIdx = plg->QueueInference(_inputs, _outputs); // workaround to unblock callback-based flows if (_callback) { - auto res = Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + auto res = Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); std::exception_ptr exceptionPtr; if (res != InferenceEngine::StatusCode::OK) { try { @@ -101,7 +101,7 @@ class GNAInferRequest : public InferenceEngine::IInferRequestInternal { IE_THROW(ParameterMismatch); } - if (millis_timeout == InferenceEngine::IInferRequest::WaitMode::RESULT_READY) { + if (millis_timeout == InferenceEngine::InferRequest::WaitMode::RESULT_READY) { millis_timeout = MAX_TIMEOUT; } const auto waitStatus = plg->WaitFor(inferRequestIdx, millis_timeout); diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp index e797183059a..cdd3c54ae17 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp @@ -18,8 +18,8 @@ HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Pt _pipeline.clear(); for (std::size_t requestId = 0; requestId < _heteroInferRequest->_inferRequests.size(); ++requestId) { struct RequestExecutor : ITaskExecutor { - explicit RequestExecutor(InferRequest* inferRequest) : _inferRequest{inferRequest} { - _inferRequest->SetCompletionCallback>( + explicit RequestExecutor(InferRequest & inferRequest) : _inferRequest(inferRequest) { + _inferRequest.SetCompletionCallback>( [this] (InferRequest, StatusCode sts) mutable { _status = sts; auto capturedTask = std::move(_task); @@ -28,14 +28,14 @@ HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Pt } void run(Task task) override { _task = std::move(task); - _inferRequest->StartAsync(); + _inferRequest.StartAsync(); }; - InferRequest* _inferRequest = nullptr; + InferRequest & _inferRequest; StatusCode _status = StatusCode::OK; Task _task; }; - auto requestExecutor = std::make_shared(_heteroInferRequest->_inferRequests[requestId]._request.get()); + auto requestExecutor = std::make_shared(_heteroInferRequest->_inferRequests[requestId]._request); _pipeline.emplace_back(requestExecutor, [requestExecutor] { if (StatusCode::OK != requestExecutor->_status) { IE_EXCEPTION_SWITCH(requestExecutor->_status, ExceptionType, @@ -58,7 +58,7 @@ StatusCode HeteroAsyncInferRequest::Wait(int64_t millis_timeout) { waitStatus = AsyncInferRequestThreadSafeDefault::Wait(millis_timeout); } catch(...) { for (auto&& requestDesc : _heteroInferRequest->_inferRequests) { - requestDesc._request->Wait(IInferRequest::RESULT_READY); + requestDesc._request.Wait(InferRequest::RESULT_READY); } throw; } diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp index 7cbe6a32644..1a36f8724be 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp @@ -2,11 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -/** - * @brief a header file for IInferRequest interface - * @file ie_iinfer_request.hpp - */ - #pragma once #include diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp index 998a36f224d..e6fb139daa1 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp @@ -26,7 +26,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp IE_THROW() << "Internal error: no information about network's output/input"; } - auto requestBlob([&](const std::string& blobName, InferenceEngine::InferRequest::Ptr r) { + auto requestBlob([&](const std::string& blobName, InferenceEngine::InferRequest & r) { std::string intermediateBlobName = blobName; auto itName = subgraphInputToOutputBlobNames.find(blobName); if (itName != subgraphInputToOutputBlobNames.end()) { @@ -36,20 +36,20 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp bool emplaced = false; std::tie(itBlob, emplaced) = _blobs.emplace(intermediateBlobName, Blob::Ptr{}); if (emplaced) { - itBlob->second = r->GetBlob(blobName); + itBlob->second = r.GetBlob(blobName); if (InferenceEngine::details::contains(networkInputs, blobName)) { _inputs[blobName] = itBlob->second; } else if (InferenceEngine::details::contains(networkOutputs, blobName)) { _outputs[blobName] = itBlob->second; } } else { - r->SetBlob(blobName, itBlob->second); + r.SetBlob(blobName, itBlob->second); } }); // go over all subnet and create requests for (auto&& desc : _inferRequests) { - desc._request = desc._network.CreateInferRequestPtr(); + desc._request = desc._network.CreateInferRequest(); // go over all inputs and get blobs from subnet infer requests for (auto&& outputInfo : desc._network.GetOutputsInfo()) { requestBlob(outputInfo.first, desc._request); @@ -69,13 +69,13 @@ void HeteroInferRequest::SetBlob(const std::string& name, const InferenceEngine: assert(!_inferRequests.empty()); for (auto &&desc : _inferRequests) { auto &r = desc._request; - assert(nullptr != r); + assert(r); InputInfo::Ptr foundInput; DataPtr foundOutput; try { // if `name` is input blob if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - r->SetBlob(name, data, foundInput->getPreProcess()); + r.SetBlob(name, data, foundInput->getPreProcess()); } } catch (const InferenceEngine::NotFound& ex) {} } @@ -86,15 +86,15 @@ void HeteroInferRequest::InferImpl() { for (auto &&desc : _inferRequests) { OV_ITT_SCOPED_TASK(itt::domains::HeteroPlugin, desc._profilingTask); auto &r = desc._request; - assert(nullptr != r); - r->Infer(); + assert(r); + r.Infer(); } } std::map HeteroInferRequest::GetPerformanceCounts() const { std::map perfMap; for (size_t i = 0; i < _inferRequests.size(); i++) { - auto perfMapRequest = _inferRequests[i]._request->GetPerformanceCounts(); + auto perfMapRequest = _inferRequests[i]._request.GetPerformanceCounts(); for (auto &&r : perfMapRequest) { perfMap[std::string("subgraph") + std::to_string(i) + ": " + r.first] = r.second; } @@ -107,7 +107,7 @@ void HeteroInferRequest::updateInOutIfNeeded() { assert(!_inferRequests.empty()); for (auto &&desc : _inferRequests) { auto &r = desc._request; - assert(nullptr != r); + assert(r); for (auto&& inputInfo : desc._network.GetInputsInfo()) { auto& ioname = inputInfo.first; auto iti = _inputs.find(ioname); @@ -115,12 +115,12 @@ void HeteroInferRequest::updateInOutIfNeeded() { auto it = _preProcData.find(ioname); if (it != _preProcData.end()) { if (it->second->getRoiBlob() != _blobs[ioname]) { - r->SetBlob(ioname.c_str(), it->second->getRoiBlob()); + r.SetBlob(ioname.c_str(), it->second->getRoiBlob()); _blobs[ioname] = iti->second; } } else { if (iti->second != _blobs[ioname]) { - r->SetBlob(ioname.c_str(), iti->second); + r.SetBlob(ioname.c_str(), iti->second); _blobs[ioname] = iti->second; } } @@ -131,7 +131,7 @@ void HeteroInferRequest::updateInOutIfNeeded() { auto ito = _outputs.find(ioname); if (ito != _outputs.end()) { if (ito->second != _blobs[ioname]) { - r->SetBlob(ioname.c_str(), ito->second); + r.SetBlob(ioname.c_str(), ito->second); _blobs[ioname] = ito->second; } } diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp index 9c5fd280dd3..9f13e57a817 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp @@ -2,11 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -/** - * @brief a header file for IInferRequest interface - * @file ie_iinfer_request.hpp - */ - #pragma once #include @@ -29,7 +24,7 @@ public: struct SubRequestDesc { InferenceEngine::ExecutableNetwork _network; - InferenceEngine::InferRequest::Ptr _request; + InferenceEngine::InferRequest _request; openvino::itt::handle_t _profilingTask; }; using SubRequestsList = std::vector; diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index b671fdebecb..45d66da3403 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -6,7 +6,6 @@ #include "ie_common.h" #include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" #include "cpp_interfaces/exception2status.hpp" -#include "ie_iexecutable_network.hpp" #include "cpp_interfaces/base/ie_executable_network_base.hpp" namespace InferenceEngine { @@ -39,6 +38,8 @@ ConstInputsDataMap ExecutableNetwork::GetInputsInfo() const { EXEC_NET_CALL_STATEMENT(return _impl->GetInputsInfo()); } +IE_SUPPRESS_DEPRECATED_START + void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; if (newActual == nullptr) IE_THROW() << "ExecutableNetwork wrapper used for reset was not initialized."; @@ -49,6 +50,8 @@ void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { this->_impl.swap(newImpl); } +IE_SUPPRESS_DEPRECATED_END + InferRequest ExecutableNetwork::CreateInferRequest() { EXEC_NET_CALL_STATEMENT(return InferRequest{_impl->CreateInferRequest(), _so}); } diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index 7a56515402f..54f8f533eab 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -162,6 +162,8 @@ void InferRequest::SetCompletionCallbackImpl(std::function{_impl.get(), [](IInferRequestInternal*){}}, _so}; @@ -183,6 +185,14 @@ void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback c ) } +InferRequest::operator IInferRequest::Ptr () { + INFER_REQ_CALL_STATEMENT( + return std::make_shared(_impl); + ) +} + +IE_SUPPRESS_DEPRECATED_END + std::vector InferRequest::QueryState() { std::vector controller; INFER_REQ_CALL_STATEMENT( @@ -193,12 +203,6 @@ std::vector InferRequest::QueryState() { return controller; } -InferRequest::operator IInferRequest::Ptr () { - INFER_REQ_CALL_STATEMENT( - return std::make_shared(_impl); - ) -} - bool InferRequest::operator!() const noexcept { return !_impl; } diff --git a/inference-engine/src/legacy_api/include/legacy/ie_layers.h b/inference-engine/src/legacy_api/include/legacy/ie_layers.h index f1ce4598e85..e7ea32467a0 100644 --- a/inference-engine/src/legacy_api/include/legacy/ie_layers.h +++ b/inference-engine/src/legacy_api/include/legacy/ie_layers.h @@ -133,9 +133,9 @@ public: /** * @brief If suggested to fuse - a pointer to the layer which needs to be fused with this layer */ - IE_SUPPRESS_DEPRECATED_START_WIN + _IE_SUPPRESS_DEPRECATED_START_MSVC Ptr _fusedWith; - IE_SUPPRESS_DEPRECATED_END_WIN + _IE_SUPPRESS_DEPRECATED_END_MSVC /** * @brief Convenience user values to store in this object as extra data @@ -182,11 +182,11 @@ public: * * @param layer Reference to the layer to be fused with */ - IE_SUPPRESS_DEPRECATED_START_WIN + _IE_SUPPRESS_DEPRECATED_START_MSVC void fuse(Ptr& layer) { _fusedWith = layer; } - IE_SUPPRESS_DEPRECATED_END_WIN + _IE_SUPPRESS_DEPRECATED_END_MSVC /** * @brief Returns the first element of the input data for this layer @@ -429,7 +429,7 @@ INFERENCE_ENGINE_API_CPP(CNNLayerWeakPtr&) getCreatorLayer(const DataPtr & data) INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(const DataPtr & data); INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(Data * data); -IE_SUPPRESS_DEPRECATED_START_WIN +_IE_SUPPRESS_DEPRECATED_START_MSVC /** * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 @@ -2212,6 +2212,6 @@ public: virtual ~ExperimentalDetectronGenerateProposalsSingleImageLayer(); }; -IE_SUPPRESS_DEPRECATED_END_WIN +_IE_SUPPRESS_DEPRECATED_END_MSVC } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp index 6a544f22eb4..fbbf77ebe76 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_executable_network_base.hpp @@ -9,22 +9,22 @@ #pragma once -#include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include #include "cpp_interfaces/exception2status.hpp" #include "cpp_interfaces/base/ie_infer_async_request_base.hpp" namespace InferenceEngine { -IE_SUPPRESS_DEPRECATED_START_WIN +IE_SUPPRESS_DEPRECATED_START /** * @brief Executable network `noexcept` wrapper which accepts IExecutableNetworkInternal derived instance which can throw exceptions * @ingroup ie_dev_api_exec_network_api @@ -110,6 +110,6 @@ public: return _impl; } }; -IE_SUPPRESS_DEPRECATED_END_WIN +IE_SUPPRESS_DEPRECATED_END } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp index a444648e184..5775c912b08 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_infer_async_request_base.hpp @@ -84,6 +84,8 @@ namespace InferenceEngine { return InferenceEngine::DescriptionBuffer(UNEXPECTED); \ } +IE_SUPPRESS_DEPRECATED_START + /** * @brief Inference request `noexcept` wrapper which accepts IInferRequestInternal derived instance which can throw exceptions * @ingroup ie_dev_api_infer_request_api @@ -190,4 +192,6 @@ public: void* _data = nullptr; }; +IE_SUPPRESS_DEPRECATED_END + } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index 76f2152925e..11ca5ce2e74 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -164,14 +163,14 @@ public: /** * @brief Waits for completion of all pipeline stages * If the pipeline raises an exception it will be rethrown here - * @param millis_timeout A timeout is `ms` to wait or special enum value of IInferRequest::WaitMode + * @param millis_timeout A timeout is `ms` to wait or special enum value of InferRequest::WaitMode * @return A status code */ StatusCode Wait(int64_t millis_timeout) override { - if (millis_timeout < IInferRequest::WaitMode::RESULT_READY) { + if (millis_timeout < InferRequest::WaitMode::RESULT_READY) { IE_THROW(ParameterMismatch) << " Timeout can't be less " - << IInferRequest::WaitMode::RESULT_READY << " for InferRequest::Wait\n"; + << InferRequest::WaitMode::RESULT_READY << " for InferRequest::Wait\n"; } auto status = std::future_status::deferred; @@ -186,11 +185,11 @@ public: } switch (millis_timeout) { - case IInferRequest::WaitMode::RESULT_READY: { + case InferRequest::WaitMode::RESULT_READY: { future.wait(); status = std::future_status::ready; } break; - case IInferRequest::WaitMode::STATUS_ONLY: { + case InferRequest::WaitMode::STATUS_ONLY: { status = future.wait_for(std::chrono::milliseconds {0}); } break; default: { @@ -213,7 +212,7 @@ public: void Infer() override { DisableCallbackGuard disableCallbackGuard{this}; InferImpl([&] {Infer_ThreadUnsafe();}); - Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); } std::map GetPerformanceCounts() const override { diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp index b88f77021ed..fb1b961109d 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp @@ -4,15 +4,15 @@ #pragma once -#include -#include -#include -#include #include #include #include #include + +#include +#include #include +#include namespace InferenceEngine { class IInferRequestInternal; diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp index 616d4d8ada1..b4f7feb6129 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ public: /** * @brief Infers specified input(s) in synchronous mode - * @note blocks all method of IInferRequest while request is ongoing (running or waiting in queue) + * @note blocks all method of InferRequest while request is ongoing (running or waiting in queue) */ virtual void Infer(); @@ -50,7 +51,7 @@ public: * @note * * This method is used in IInferRequestInternal::Infer, which calls the common code first and after uses this * plugin dependent implementation. - * * Blocks all method of IInferRequest while request is ongoing (running or waiting in queue) + * * Blocks all method of InferRequest while request is ongoing (running or waiting in queue) */ virtual void InferImpl(); @@ -132,7 +133,7 @@ public: * becomes available, whichever comes first. * @param millis_timeout - maximum duration in milliseconds to block for * @note There are special cases when millis_timeout is equal some value of WaitMode enum: - * * STATUS_ONLY - immediately returns request status (IInferRequest::RequestStatus). It doesn't block or interrupt + * * STATUS_ONLY - immediately returns request status (InferRequest::StatusCode). It doesn't block or interrupt * current thread. * * RESULT_READY - waits until inference result becomes available * @return A status code diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp index 1eecf462c63..e34d55b02a2 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h index 48d3f87e3cd..8a6c42c4e97 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.h @@ -74,7 +74,6 @@ public: } ie::IInferRequestInternal::Ptr CreateInferRequest() override { - ie::IInferRequest::Ptr asyncRequest; if (_device == nullptr || !_device->isBooted()) { IE_THROW() << "Can not create infer request: there is no available devices with platform " << _device->_platform; diff --git a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp index cdbdcd0b14b..359cbbfeda9 100644 --- a/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp +++ b/inference-engine/tests/functional/inference_engine/async_infer_request_test.cpp @@ -74,11 +74,15 @@ TEST(InferRequestCPPTests, throwsOnUninitializedSetCompletionCallback) { ASSERT_THROW(req.SetCompletionCallback(f), InferenceEngine::Exception); } +IE_SUPPRESS_DEPRECATED_START + TEST(InferRequestCPPTests, throwsOnUninitializedCast) { InferRequest req; ASSERT_THROW((void)static_cast(req), InferenceEngine::Exception); } +IE_SUPPRESS_DEPRECATED_END + TEST(InferRequestCPPTests, throwsOnUninitializedQueryState) { InferRequest req; ASSERT_THROW(req.QueryState(), InferenceEngine::Exception); diff --git a/inference-engine/tests/functional/inference_engine/caching_test.cpp b/inference-engine/tests/functional/inference_engine/caching_test.cpp index 8902468b974..5edba7e94a8 100644 --- a/inference-engine/tests/functional/inference_engine/caching_test.cpp +++ b/inference-engine/tests/functional/inference_engine/caching_test.cpp @@ -14,7 +14,6 @@ #include "ngraph/function.hpp" #include "details/ie_so_loader.h" #include "ie_metric_helpers.hpp" -#include "ie_iexecutable_network.hpp" #include "cpp_interfaces/impl/ie_executable_network_internal.hpp" #include "cpp_interfaces/impl/ie_plugin_internal.hpp" diff --git a/inference-engine/tests/functional/inference_engine/executable_network.cpp b/inference-engine/tests/functional/inference_engine/executable_network.cpp index 16af81dd7b2..ea8af6c1d21 100644 --- a/inference-engine/tests/functional/inference_engine/executable_network.cpp +++ b/inference-engine/tests/functional/inference_engine/executable_network.cpp @@ -4,7 +4,6 @@ #include #include -#include using namespace ::testing; using namespace std; diff --git a/inference-engine/tests/functional/plugin/gpu/remote_blob_tests/cldnn_remote_blob_tests.cpp b/inference-engine/tests/functional/plugin/gpu/remote_blob_tests/cldnn_remote_blob_tests.cpp index 3a664878ae6..a3ce2442247 100644 --- a/inference-engine/tests/functional/plugin/gpu/remote_blob_tests/cldnn_remote_blob_tests.cpp +++ b/inference-engine/tests/functional/plugin/gpu/remote_blob_tests/cldnn_remote_blob_tests.cpp @@ -337,7 +337,7 @@ TEST_P(TwoNets_Test, canInferTwoExecNets) { } for (auto ir : irs) { - ir.Wait(IInferRequest::RESULT_READY); + ir.Wait(InferRequest::RESULT_READY); } } diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/multi/gpu_remote_blob_tests.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/multi/gpu_remote_blob_tests.cpp index db91ba9598d..b8c6a6392fa 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/multi/gpu_remote_blob_tests.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/multi/gpu_remote_blob_tests.cpp @@ -40,10 +40,10 @@ TEST_P(MultiDevice_Test, cannotInferRemoteBlobIfNotInitializedForDevice) { return; } InferRequest req = exec_net_multi.CreateInferRequest(); - ASSERT_NE((std::shared_ptr)req, nullptr); + ASSERT_TRUE(req); ASSERT_NO_THROW(req.SetBlob(first_input_name, rblob)); ASSERT_NO_THROW(req.StartAsync()); - ASSERT_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY), InferenceEngine::Exception); + ASSERT_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY), InferenceEngine::Exception); } const std::vector device_names_and_support_for_remote_blobs2 { diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request.hpp index 20fceb40d7d..ac0998d53b9 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request.hpp @@ -398,7 +398,7 @@ TEST_P(InferRequestTests, CorrectOneAsyncInferWithGetInOutWithInfWait) { req.Infer(); req.StartAsync(); InferenceEngine::StatusCode sts; - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(InferenceEngine::StatusCode::OK, sts); ASSERT_NO_THROW(blob = req.GetBlob(cnnNet.getOutputsInfo().begin()->first)); } @@ -420,7 +420,7 @@ TEST_P(InferRequestTests, canStartAsyncInferWithGetInOutWithStatusOnlyWait) { req.Infer(); req.StartAsync(); InferenceEngine::StatusCode sts; - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::STATUS_ONLY); ASSERT_TRUE(sts == InferenceEngine::StatusCode::OK || sts == InferenceEngine::StatusCode::RESULT_NOT_READY); } @@ -479,13 +479,13 @@ TEST_P(InferRequestTests, canRun3AsyncRequestsConsistentlyWithWait) { auto req3 = execNet.CreateInferRequest(); req1.StartAsync(); - ASSERT_NO_THROW(req1.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req1.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); req2.Infer(); - ASSERT_NO_THROW(req2.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req2.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); req3.Infer(); - ASSERT_NO_THROW(req3.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req3.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); } TEST_P(InferRequestTests, canRun3AsyncRequestsConsistentlyFromThreadsWithoutWait) { @@ -506,9 +506,9 @@ TEST_P(InferRequestTests, canRun3AsyncRequestsConsistentlyFromThreadsWithoutWait req2.Infer(); req3.Infer(); - std::thread t1([&] { req1.StartAsync(); sts1 = req1.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); }); - std::thread t2([&] { req2.StartAsync(); sts2 = req2.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); }); - std::thread t3([&] { req3.StartAsync(); sts3 = req3.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); }); + std::thread t1([&] { req1.StartAsync(); sts1 = req1.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); }); + std::thread t2([&] { req2.StartAsync(); sts2 = req2.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); }); + std::thread t3([&] { req3.StartAsync(); sts3 = req3.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); }); t1.join(); t2.join(); @@ -528,8 +528,8 @@ TEST_P(InferRequestTests, canWaitWithotStartAsync) { auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration); // Create InferRequest auto req = execNet.CreateInferRequest(); - ASSERT_NO_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); - ASSERT_NO_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY)); + ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::STATUS_ONLY)); ASSERT_NO_THROW(req.Wait(1)); } @@ -555,10 +555,10 @@ TEST_P(InferRequestTests, returnDeviceBusyOnSetBlobAfterAsyncInfer) { InferenceEngine::ResponseDesc response; InferenceEngine::StatusCode sts; - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::STATUS_ONLY); ASSERT_EQ(InferenceEngine::StatusCode::INFER_NOT_STARTED, sts) << response.msg; req.StartAsync(); - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(static_cast(InferenceEngine::StatusCode::OK), sts) << response.msg; try { req.SetBlob(cnnNet.getInputsInfo().begin()->first, outputBlob); @@ -566,7 +566,7 @@ TEST_P(InferRequestTests, returnDeviceBusyOnSetBlobAfterAsyncInfer) { catch (const std::exception &e) { std::cout << "Exception: " << e.what() << std::endl; } - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::STATUS_ONLY); ASSERT_TRUE(sts == InferenceEngine::StatusCode::OK || sts == InferenceEngine::StatusCode::RESULT_NOT_READY) << response.msg; } @@ -584,7 +584,7 @@ TEST_P(InferRequestTests, returnDeviceBusyOnGetBlobAfterAsyncInfer) { InferenceEngine::ResponseDesc response; InferenceEngine::StatusCode sts; req.StartAsync(); - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(static_cast(InferenceEngine::StatusCode::OK), sts) << response.msg; try { req.SetBlob(cnnNet.getInputsInfo().begin()->first, outputBlob); @@ -607,7 +607,7 @@ TEST_P(InferRequestTests, returnDeviceBusyOnGetPerformanceCountAfterAsyncInfer) InferenceEngine::ResponseDesc response; InferenceEngine::StatusCode sts; req.StartAsync(); - sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + sts = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(static_cast(InferenceEngine::StatusCode::OK), sts) << response.msg; std::map perfMap; @@ -645,7 +645,7 @@ TEST_P(InferRequestTestsResultNotReady, ReturnResultNotReadyFromWaitInAsyncModeF callbackTimeStamp.set_value(std::chrono::system_clock::now()); }); req.StartAsync(); - ASSERT_NO_THROW(sts = req.Wait(InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY)); + ASSERT_NO_THROW(sts = req.Wait(InferenceEngine::InferRequest::WaitMode::STATUS_ONLY)); // get timestamp taken AFTER return from the Wait(STATUS_ONLY) const auto afterWaitTimeStamp = std::chrono::system_clock::now(); // IF the callback timestamp is larger than the afterWaitTimeStamp @@ -653,6 +653,6 @@ TEST_P(InferRequestTestsResultNotReady, ReturnResultNotReadyFromWaitInAsyncModeF if (afterWaitTimeStamp < callbackTimeStampFuture.get()) { ASSERT_TRUE(sts == InferenceEngine::StatusCode::RESULT_NOT_READY); } - ASSERT_NO_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); } } // namespace BehaviorTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp index 83a4bf24677..4ef5059f7b5 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_callback.hpp @@ -46,7 +46,7 @@ TEST_P(CallbackTests, canCallSyncAndAsyncWithCompletionCallback) { }); req.StartAsync(); - InferenceEngine::StatusCode waitStatus = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + InferenceEngine::StatusCode waitStatus = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(static_cast(InferenceEngine::StatusCode::OK), waitStatus); ASSERT_TRUE(isCalled); @@ -71,15 +71,12 @@ TEST_P(CallbackTests, canStartSeveralAsyncInsideCompletionCallbackWithSafeDtor) // Create InferRequest InferenceEngine::InferRequest req = execNet.CreateInferRequest(); req.SetCompletionCallback>( - [&](InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode status) { + [&](InferenceEngine::InferRequest request, InferenceEngine::StatusCode status) { if (status != InferenceEngine::StatusCode::OK) { data.promise.set_value(status); } else { if (data.numIter.fetch_add(1) != NUM_ITER) { - auto sts = request->StartAsync(nullptr); - if (sts != InferenceEngine::StatusCode::OK) { - data.promise.set_value(sts); - } + request.StartAsync(); } else { data.promise.set_value(InferenceEngine::StatusCode::OK); } @@ -87,7 +84,7 @@ TEST_P(CallbackTests, canStartSeveralAsyncInsideCompletionCallbackWithSafeDtor) }); auto future = data.promise.get_future(); req.StartAsync(); - InferenceEngine::StatusCode waitStatus = req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + InferenceEngine::StatusCode waitStatus = req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ((int) InferenceEngine::StatusCode::OK, waitStatus); future.wait(); auto callbackStatus = future.get(); @@ -107,7 +104,7 @@ TEST_P(CallbackTests, inferDoesNotCallCompletionCallback) { InferenceEngine::InferRequest req = execNet.CreateInferRequest(); bool isCalled = false; req.SetCompletionCallback>( - [&](InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode status) { + [&](InferenceEngine::InferRequest request, InferenceEngine::StatusCode status) { isCalled = true; }); req.Infer(); @@ -128,6 +125,6 @@ TEST_P(CallbackTests, returnGeneralErrorIfCallbackThrowException) { }); ASSERT_NO_THROW(req.StartAsync()); - ASSERT_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY), InferenceEngine::GeneralError); + ASSERT_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY), InferenceEngine::GeneralError); } } // namespace BehaviorTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_cancellation.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_cancellation.hpp index 0030ade00e3..bbb2526d28d 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_cancellation.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/infer_request_cancellation.hpp @@ -45,7 +45,7 @@ TEST_P(CancellationTests, canCancelAsyncRequest) { ASSERT_NO_THROW(req.Cancel()); try { - req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); } catch (const InferenceEngine::InferCancelled&) { SUCCEED(); } @@ -64,13 +64,13 @@ TEST_P(CancellationTests, canResetAfterCancelAsyncRequest) { ASSERT_NO_THROW(req.StartAsync()); ASSERT_NO_THROW(req.Cancel()); try { - req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); } catch (const InferenceEngine::InferCancelled&) { SUCCEED(); } ASSERT_NO_THROW(req.StartAsync()); - ASSERT_NO_THROW(req.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY)); + ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY)); } TEST_P(CancellationTests, canCancelBeforeAsyncRequest) { @@ -100,7 +100,7 @@ TEST_P(CancellationTests, canCancelInferRequest) { auto infer = std::async(std::launch::async, [&req]{ req.Infer(); }); - const auto statusOnly = InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY; + const auto statusOnly = InferenceEngine::InferRequest::WaitMode::STATUS_ONLY; while (req.Wait(statusOnly) == InferenceEngine::StatusCode::INFER_NOT_STARTED) { } diff --git a/inference-engine/tests/functional/plugin/shared/include/multi/multi_remote_blob_tests.hpp b/inference-engine/tests/functional/plugin/shared/include/multi/multi_remote_blob_tests.hpp index f430c8f6cda..33ce613cb18 100644 --- a/inference-engine/tests/functional/plugin/shared/include/multi/multi_remote_blob_tests.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/multi/multi_remote_blob_tests.hpp @@ -20,7 +20,7 @@ TEST_P(MultiDevice_SupportTest, canCreateContextThenRequestThenBlobsAndInfer) { InferenceEngine::RemoteContext::Ptr ctx; ASSERT_NE(ctx = exec_net.GetContext(), nullptr); InferRequest req = exec_net.CreateInferRequest(); - ASSERT_NE((std::shared_ptr)req, nullptr); + ASSERT_TRUE(req); const InferenceEngine::ConstInputsDataMap inputInfo = exec_net.GetInputsInfo(); for (auto i : inputInfo) { auto rblob = InferenceEngine::make_shared_blob(i.second->getTensorDesc(), ctx); @@ -28,7 +28,7 @@ TEST_P(MultiDevice_SupportTest, canCreateContextThenRequestThenBlobsAndInfer) { req.SetBlob(i.first, rblob); } ASSERT_NO_THROW(req.StartAsync()); - ASSERT_EQ(req.Wait(IInferRequest::RESULT_READY), StatusCode::OK); + ASSERT_EQ(req.Wait(InferRequest::RESULT_READY), StatusCode::OK); } else { ASSERT_THROW(exec_net.GetContext(), InferenceEngine::NotImplemented); diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp index 2a1df11648f..9b4f634b40f 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp @@ -8,7 +8,6 @@ #include #include -#include #include diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp index 22324ad364c..a605d65c551 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_network_internal.hpp @@ -10,7 +10,6 @@ #include "ie_input_info.hpp" #include "cpp/ie_cnn_network.h" -#include "ie_iexecutable_network.hpp" #include diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp index 43395428f72..0e7fbac7a25 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp @@ -7,7 +7,6 @@ #include #include -#include #include "mock_executable_network_internal.hpp" #include "ie_icore.hpp" #include diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp index 7c6265485dd..24541acdb90 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp @@ -12,7 +12,6 @@ #include "ie_input_info.hpp" #include "ie_icnn_network.hpp" -#include "ie_iexecutable_network.hpp" #include #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp index a0f39b7f987..85031f6d316 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_executable_network_base_test.cpp @@ -63,7 +63,6 @@ TEST_F(ExecutableNetworkThreadSafeTests, returnErrorIfStartAsyncThrowsException) EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::runtime_error(""))); EXPECT_NO_THROW(sts = req->StartAsync(&dsc)); ASSERT_TRUE(StatusCode::OK == sts) << dsc.msg; - EXPECT_NO_THROW(sts = req->Wait(IInferRequest::WaitMode::RESULT_READY, &dsc)); + EXPECT_NO_THROW(sts = req->Wait(InferRequest::WaitMode::RESULT_READY, &dsc)); ASSERT_EQ(StatusCode::GENERAL_ERROR, sts) << dsc.msg; } - diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp index 22797de486a..f849cb0753a 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp @@ -26,6 +26,8 @@ using namespace InferenceEngine::details; constexpr const char* MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; constexpr const char* MockNotEmptyICNNNetwork::OUTPUT_BLOB_NAME; +IE_SUPPRESS_DEPRECATED_START + class InferRequestBaseTests : public ::testing::Test { protected: std::shared_ptr mock_impl; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp index 4a6c2622b27..50a0bbae9e0 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_thread_safe_default_test.cpp @@ -169,7 +169,7 @@ TEST_F(InferRequestThreadSafeDefaultTests, callbackTakesOKIfAsyncRequestWasOK) { EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).Times(1); testRequest->StartAsync(); taskExecutor->executeAll(); - testRequest->Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); + testRequest->Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); ASSERT_EQ(nullptr, exceptionPtr); } @@ -183,7 +183,7 @@ TEST_F(InferRequestThreadSafeDefaultTests, callbackIsCalledIfAsyncRequestFailed) EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::exception())); testRequest->StartAsync(); taskExecutor->executeAll(); - EXPECT_THROW(testRequest->Wait(IInferRequest::WaitMode::RESULT_READY), std::exception); + EXPECT_THROW(testRequest->Wait(InferRequest::WaitMode::RESULT_READY), std::exception); ASSERT_NE(nullptr, exceptionPtr); } @@ -192,5 +192,5 @@ TEST_F(InferRequestThreadSafeDefaultTests, canCatchExceptionIfAsyncRequestFailed testRequest = make_shared(mockInferRequestInternal, taskExecutor, taskExecutor); EXPECT_CALL(*mockInferRequestInternal.get(), InferImpl()).WillOnce(Throw(std::exception())); testRequest->StartAsync(); - EXPECT_THROW(testRequest->Wait(IInferRequest::WaitMode::RESULT_READY), std::exception); + EXPECT_THROW(testRequest->Wait(InferRequest::WaitMode::RESULT_READY), std::exception); } diff --git a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp index 489fc8ab52a..5feb57ea9ea 100644 --- a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp @@ -8,7 +8,6 @@ #include #include "cpp/ie_executable_network.hpp" -#include "ie_iexecutable_network.hpp" #include "ie_plugin_cpp.hpp" #include "unit_test_utils/mocks/mock_iexecutable_network.hpp" @@ -90,13 +89,13 @@ TEST_F(ExecutableNetworkTests, GetInputsInfo) { ASSERT_EQ(info, InferenceEngine::ConstInputsDataMap{}); } +IE_SUPPRESS_DEPRECATED_START TEST_F(ExecutableNetworkTests, resetThrowsIfResetToNullptr) { InferenceEngine::IExecutableNetwork::Ptr mockIExeNet_2{}; ASSERT_THROW(exeNetwork.reset(mockIExeNet_2), InferenceEngine::Exception); } -IE_SUPPRESS_DEPRECATED_START TEST_F(ExecutableNetworkTests, QueryStateThrowsIfReturnErr) { EXPECT_CALL(*mockIExeNet.get(), QueryState()) .Times(1) @@ -113,6 +112,7 @@ TEST_F(ExecutableNetworkTests, QueryState) { EXPECT_NO_THROW(MemState_v = exeNetwork.QueryState()); EXPECT_EQ(MemState_v.size(), 1); } + IE_SUPPRESS_DEPRECATED_END class ExecutableNetworkWithIInferReqTests : public ExecutableNetworkTests { @@ -147,10 +147,12 @@ TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfSetRequest ASSERT_THROW(exeNetwork.CreateInferRequest(), InferenceEngine::Exception); } +IE_SUPPRESS_DEPRECATED_START + // CreateInferRequestPtr TEST_F(ExecutableNetworkWithIInferReqTests, CanCreateInferRequestPtr) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); - ASSERT_NO_THROW(exeNetwork.CreateInferRequest()); + ASSERT_NO_THROW(exeNetwork.CreateInferRequestPtr()); } TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfReturnNotOK) { @@ -163,8 +165,6 @@ TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfSetRequ ASSERT_THROW(exeNetwork.CreateInferRequestPtr(), InferenceEngine::Exception); } -IE_SUPPRESS_DEPRECATED_START - class ExecutableNetworkBaseTests : public ::testing::Test { protected: std::shared_ptr mock_impl; diff --git a/inference-engine/tests_deprecated/functional/ie_tests/include/classification_matcher.hpp b/inference-engine/tests_deprecated/functional/ie_tests/include/classification_matcher.hpp index 36bc6fd9870..0b9b0ee81d1 100644 --- a/inference-engine/tests_deprecated/functional/ie_tests/include/classification_matcher.hpp +++ b/inference-engine/tests_deprecated/functional/ie_tests/include/classification_matcher.hpp @@ -8,7 +8,6 @@ #include "base_matcher.hpp" #include "regression_reference.hpp" #include -#include #include "label_probability.hpp" namespace Regression { namespace Matchers { diff --git a/inference-engine/tests_deprecated/functional/ie_tests/src/custom_matcher.cpp b/inference-engine/tests_deprecated/functional/ie_tests/src/custom_matcher.cpp index b6b4a169302..6ce4b3d0f4e 100644 --- a/inference-engine/tests_deprecated/functional/ie_tests/src/custom_matcher.cpp +++ b/inference-engine/tests_deprecated/functional/ie_tests/src/custom_matcher.cpp @@ -6,7 +6,6 @@ #include #include #include "custom_matcher.hpp" -#include "ie_iexecutable_network.hpp" using namespace InferenceEngine; @@ -189,7 +188,7 @@ void Regression::Matchers::CustomMatcher::matchCustom() { inferRequests[i].StartAsync(); } for (int i = 0; i != requestProcessed; i++) { - inferRequests[i].Wait(IInferRequest::RESULT_READY); + inferRequests[i].Wait(InferRequest::RESULT_READY); } sts = OK; } diff --git a/inference-engine/tests_deprecated/functional/ie_tests/src/raw_matcher.cpp b/inference-engine/tests_deprecated/functional/ie_tests/src/raw_matcher.cpp index b8cab381c65..59c65031d29 100644 --- a/inference-engine/tests_deprecated/functional/ie_tests/src/raw_matcher.cpp +++ b/inference-engine/tests_deprecated/functional/ie_tests/src/raw_matcher.cpp @@ -199,7 +199,7 @@ void RawMatcher::match() { if (config.isAsync) { inferRequest.StartAsync(); - inferRequest.Wait(IInferRequest::WaitMode::RESULT_READY); + inferRequest.Wait(InferRequest::WaitMode::RESULT_READY); } else { inferRequest.Infer(); } diff --git a/inference-engine/tests_deprecated/functional/shared_tests/io_blob_tests/cropResize_tests.hpp b/inference-engine/tests_deprecated/functional/shared_tests/io_blob_tests/cropResize_tests.hpp index 2a3ef4ab9ea..415444dfe78 100644 --- a/inference-engine/tests_deprecated/functional/shared_tests/io_blob_tests/cropResize_tests.hpp +++ b/inference-engine/tests_deprecated/functional/shared_tests/io_blob_tests/cropResize_tests.hpp @@ -429,7 +429,7 @@ TEST_P(RandomROITest, PreprocRandomROITest) if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { @@ -534,7 +534,7 @@ TEST_P(CropResizeTest, resizeTest) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -570,7 +570,7 @@ TEST_P(CropResizeTest, resizeAfterLoadTest) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -652,7 +652,7 @@ TEST_P(CropResizeTest, cropRoiTest) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -771,7 +771,7 @@ TEST_P(BatchResizeTest, batchTest) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -911,7 +911,7 @@ TEST_P(DynamicBatchResizeTest, dynamicBatchTest) { req.SetBatch(batch_size); if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -999,7 +999,7 @@ TEST_P(ReorderTest, reorderTest) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } @@ -1147,7 +1147,7 @@ TEST_P(NV12ColorConvertTest, NV12Test) { if (_isAsync) { req.StartAsync(); - req.Wait(IInferRequest::WaitMode::RESULT_READY); + req.Wait(InferRequest::WaitMode::RESULT_READY); } else { req.Infer(); } diff --git a/inference-engine/tests_deprecated/functional/vpu/common/myriad_hw_network_tests.hpp b/inference-engine/tests_deprecated/functional/vpu/common/myriad_hw_network_tests.hpp index 2252dc3cd72..7d91bd5ee22 100644 --- a/inference-engine/tests_deprecated/functional/vpu/common/myriad_hw_network_tests.hpp +++ b/inference-engine/tests_deprecated/functional/vpu/common/myriad_hw_network_tests.hpp @@ -100,7 +100,7 @@ public: } for (int inferInd = 0; inferInd < NUM_REQUESTS; ++inferInd) { - ASSERT_EQ(StatusCode::OK, inferRequests[inferInd].Wait(IInferRequest::RESULT_READY)); + ASSERT_EQ(StatusCode::OK, inferRequests[inferInd].Wait(InferRequest::RESULT_READY)); } for (int inferInd = 0; inferInd < NUM_REQUESTS; ++inferInd) { diff --git a/inference-engine/tools/vpu/vpu_perfcheck/main.cpp b/inference-engine/tools/vpu/vpu_perfcheck/main.cpp index febb53e0d7c..1a59be99943 100644 --- a/inference-engine/tools/vpu/vpu_perfcheck/main.cpp +++ b/inference-engine/tools/vpu/vpu_perfcheck/main.cpp @@ -140,13 +140,6 @@ public: } }; -#define IECALL(call) \ -{ \ - if (InferenceEngine::OK != (call)) { \ - std::cout << #call " failed: " << resp.msg << std::endl; \ - return 1; \ - } \ -} static bool loadImage(const std::string &imageFilename, InferenceEngine::Blob::Ptr &blob); static bool loadVideo(const std::vector &imagesFolder, InferenceEngine::Blob::Ptr &blob); @@ -309,7 +302,6 @@ std::map perfMap; int process(const std::string& modelFileName, const std::string& inputsDir, std::string& file_config_cl, int nBatch, int num_networks) { - InferenceEngine::ResponseDesc resp; InferenceEngine::Core ie; niter /= nBatch; num_requests = num_requests * num_networks; @@ -394,7 +386,7 @@ int process(const std::string& modelFileName, const std::string& inputsDir, exeNetwork[n] = ie.LoadNetwork(cnnNetwork, deviceName, networkConfig); } - std::vector request(num_requests); + std::vector request(num_requests); iter_start.resize(niter); iter_end.resize(niter); iter_time.resize(niter); @@ -406,9 +398,7 @@ int process(const std::string& modelFileName, const std::string& inputsDir, request[r] = exeNetwork[n].CreateInferRequest(); for (auto &input : networkInputs) { - InferenceEngine::Blob::Ptr inputBlob; - IECALL(request[r]->GetBlob(input.first.c_str(), inputBlob, &resp)); - + auto inputBlob = request[r].GetBlob(input.first); const auto& dims = inputBlob->getTensorDesc().getDims(); auto layout = inputBlob->getTensorDesc().getLayout(); @@ -430,8 +420,8 @@ int process(const std::string& modelFileName, const std::string& inputsDir, } } - IECALL(request[r]->SetCompletionCallback( - [](InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) { + request[r].SetCompletionCallback>( + [](InferenceEngine::InferRequest request, InferenceEngine::StatusCode code) -> void { if (code != InferenceEngine::OK) { std::cout << "Infer failed: " << code << std::endl; exit(1); @@ -442,17 +432,13 @@ int process(const std::string& modelFileName, const std::string& inputsDir, iter_end[reqIdx] = Time::now(); - InferenceEngine::ResponseDesc resp; if (profile && (reqIdx == niter / 2)) { - request->GetPerformanceCounts(perfMap, &resp); + perfMap = request.GetPerformanceCounts(); } if (iter >= 0) { iter_start[reqIdx + (num_requests)] = Time::now(); - if (InferenceEngine::OK != request->StartAsync(&resp)) { - std::cout << "StartAsync failed: " << resp.msg << std::endl; - exit(1); - } + request.StartAsync(); } iter_time[reqIdx] = TIMEDIFF(iter_start[reqIdx], iter_end[reqIdx]); @@ -462,14 +448,14 @@ int process(const std::string& modelFileName, const std::string& inputsDir, reallydone = 1; alldone.notify_all(); } - })); + }); } printf("Inference started. Running %d iterations...\n", niter - 2 * 2 * num_requests); fflush(stdout); for (int r = 0; r < num_requests; ++r) { iter_start[r] = Time::now(); - IECALL(request[r]->StartAsync(&resp)); + request[r].StartAsync(); } { From 9abd69109ccb7e9ad2344a16904788e2777ec286 Mon Sep 17 00:00:00 2001 From: Nikolay Tyukaev Date: Wed, 21 Apr 2021 16:32:15 +0300 Subject: [PATCH 33/78] fix (#5335) --- docs/doxygen/ie_docs.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/doxygen/ie_docs.xml b/docs/doxygen/ie_docs.xml index 0b6af577c97..688e80d0215 100644 --- a/docs/doxygen/ie_docs.xml +++ b/docs/doxygen/ie_docs.xml @@ -54,10 +54,11 @@ limitations under the License. - - - - + + + + + From 0d3baee1f3b342058770da8688664a6bd1a888bc Mon Sep 17 00:00:00 2001 From: Alexandra Sidorova Date: Wed, 21 Apr 2021 16:45:07 +0300 Subject: [PATCH 34/78] [CPU] [IE TESTS] Added improvements for DepthToSpace and SpaceToDepth (#3897) --- .../src/mkldnn_plugin/mkldnn_node.cpp | 4 + .../src/mkldnn_plugin/mkldnn_node.h | 6 + .../nodes/common/permute_kernel.cpp | 379 ++++++++++++++++++ .../nodes/common/permute_kernel.h | 71 ++++ .../mkldnn_plugin/nodes/depth_to_space.cpp | 221 ---------- .../src/mkldnn_plugin/nodes/list_tbl.hpp | 2 - .../nodes/mkldnn_depth_to_space_node.cpp | 245 +++++++++++ .../nodes/mkldnn_depth_to_space_node.h | 38 ++ .../mkldnn_plugin/nodes/mkldnn_pad_node.cpp | 6 +- .../nodes/mkldnn_permute_node.cpp | 323 +-------------- .../mkldnn_plugin/nodes/mkldnn_permute_node.h | 32 +- .../nodes/mkldnn_space_to_depth_node.cpp | 242 +++++++++++ .../nodes/mkldnn_space_to_depth_node.h | 38 ++ .../nodes/mkldnn_strided_slice_node.cpp | 7 +- .../mkldnn_plugin/nodes/space_to_depth.cpp | 221 ---------- .../single_layer_tests/depth_to_space.cpp | 15 +- .../single_layer_tests/space_to_depth.cpp | 15 +- .../cpu/single_layer_tests/depth_to_space.cpp | 195 +++++++++ .../plugin/cpu/single_layer_tests/permute.cpp | 77 +++- .../cpu/single_layer_tests/space_to_depth.cpp | 195 +++++++++ .../single_layer/depth_to_space.hpp | 3 + .../single_layer/space_to_depth.hpp | 3 + .../layers/internal/graph_permute_test.cpp | 104 ++--- 23 files changed, 1584 insertions(+), 858 deletions(-) create mode 100644 inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.cpp create mode 100644 inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.h delete mode 100644 inference-engine/src/mkldnn_plugin/nodes/depth_to_space.cpp create mode 100644 inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.cpp create mode 100644 inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.h create mode 100644 inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.cpp create mode 100644 inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.h delete mode 100644 inference-engine/src/mkldnn_plugin/nodes/space_to_depth.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_depth.cpp diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp index ebef1403857..114b6d18c05 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -99,9 +101,11 @@ static const InferenceEngine::details::caseless_unordered_map { "ROIAlign", ROIAlign }, { "ROIPooling", ROIPooling }, { "BatchNormalization", BatchNormalization }, + { "DepthToSpace", DepthToSpace }, { "Flatten", Flatten }, { "Pad", Pad }, { "Permute", Permute }, + { "SpaceToDepth", SpaceToDepth }, { "StridedSlice", StridedSlice }, { "Copy", Copy }, { "LSTMCell", RNNCell }, diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_node.h b/inference-engine/src/mkldnn_plugin/mkldnn_node.h index 4ed5daee429..169bde711c8 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_node.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_node.h @@ -54,9 +54,11 @@ enum Type { ROIAlign, ROIPooling, BatchNormalization, + DepthToSpace, Flatten, Pad, Permute, + SpaceToDepth, StridedSlice, Copy, MemoryOutput, @@ -134,12 +136,16 @@ static std::string NameFromType(Type type) { return "ROIPooling"; case BatchNormalization: return "BatchNormalization"; + case DepthToSpace: + return "DepthToSpace"; case Flatten: return "Flatten"; case Pad: return "Pad"; case Permute: return "Permute"; + case SpaceToDepth: + return "SpaceToDepth"; case StridedSlice: return "StridedSlice"; case Copy: diff --git a/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.cpp b/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.cpp new file mode 100644 index 00000000000..50e21be668f --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.cpp @@ -0,0 +1,379 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "permute_kernel.h" + +#include +#include +#include +#include +#include "cpu_memcpy.h" +#include "utils/bfloat16.hpp" + +#include "cpu/x64/jit_generator.hpp" + +using namespace InferenceEngine; +using namespace MKLDNNPlugin; +using namespace mkldnn; +using namespace mkldnn::impl; +using namespace mkldnn::impl::cpu::x64; +using namespace mkldnn::impl::utils; +using namespace Xbyak; + +#define GET_OFF(field) offsetof(jit_args_permute, field) + +template +struct jit_uni_permute_kernel_f32 : public jit_uni_permute_kernel, public jit_generator { + DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_permute_kernel_f32) + + explicit jit_uni_permute_kernel_f32(jit_permute_config_params jcp_) : jit_uni_permute_kernel(jcp_), jit_generator() {} + + void create_ker() override { + jit_generator::create_kernel(); + ker_ = (decltype(ker_))jit_ker(); + } + + void generate() override { + this->preamble(); + + mov(reg_src, ptr[reg_params + GET_OFF(src)]); + mov(reg_dst, ptr[reg_params + GET_OFF(dst)]); + + loop(jcp.n); + + this->postamble(); + } + + void load(const Xbyak::Xmm &xmm, const Xbyak::Address &addr) { + switch (jcp.data_size) { + case 16: movups(xmm, addr); break; + case 8: movsd(xmm, addr); break; + case 4: movss(xmm, addr); break; + case 2: pinsrw(xmm, addr, 0x0); break; + case 1: pinsrb(xmm, addr, 0x0); break; + } + } + + void store(const Xbyak::Address &addr, const Xbyak::Xmm &xmm) { + switch (jcp.data_size) { + case 16: movups(addr, xmm); break; + case 8: movsd(addr, xmm); break; + case 4: movss(addr, xmm); break; + case 2: pextrw(addr, xmm, 0x0); break; + case 1: pextrb(addr, xmm, 0x0); break; + } + } + + void loop(int n) { + mov(reg_work_amount, jcp.dst_block_dims[n]); + + Xbyak::Label main_loop_label; + Xbyak::Label tail_loop_label; + Xbyak::Label exit_label; + + if (n + 1 == jcp.ndims) { + if (jcp.src_strides[n] == jcp.dst_strides[n] == 1) { + uint32_t step = vlen / jcp.data_size; + + L(main_loop_label); + { + cmp(reg_work_amount, step); + jl(tail_loop_label, T_NEAR); + + uni_vmovups(vmm, ptr[reg_src]); + uni_vmovups(ptr[reg_dst], vmm); + + add(reg_src, step * jcp.data_size); + add(reg_dst, step * jcp.data_size); + sub(reg_work_amount, step); + + jmp(main_loop_label, T_NEAR); + } + } + } + + L(tail_loop_label); { + cmp(reg_work_amount, 0); + je(exit_label, T_NEAR); + + if (n + 1 == jcp.ndims) { + load(xmm, ptr[reg_src]); + store(ptr[reg_dst], xmm); + } else { + aux_reg_src = reg_src; + aux_reg_dst = reg_dst; + push(aux_reg_src); + push(aux_reg_dst); + push(reg_work_amount); + loop(n + 1); + pop(reg_work_amount); + pop(reg_dst); + pop(reg_src); + } + + add(reg_src, jcp.src_strides[n] * jcp.data_size); + add(reg_dst, jcp.dst_strides[n] * jcp.data_size); + sub(reg_work_amount, 1); + + jmp(tail_loop_label, T_NEAR); + } + + L(exit_label); + } + +private: + using Vmm = typename conditional3::type; + uint32_t vlen = cpu_isa_traits::vlen; + + Xbyak::Reg64 reg_src = r8; + Xbyak::Reg64 reg_dst = r9; + Xbyak::Reg64 reg_work_amount = r10; + Xbyak::Reg64 aux_reg_src = r11; + Xbyak::Reg64 aux_reg_dst = r12; + + Xbyak::Reg64 reg_params = abi_param1; + + Vmm vmm = Vmm(0); + Xbyak::Xmm xmm = Xbyak::Xmm(0); +}; + +PermuteKernel::PermuteKernel(const PermuteParams& params) : params(params) { + prepareParams(); +} + +void PermuteKernel::prepareParams() { + SizeVector src_block_strides(params.src_block_dims.size(), 1); + SizeVector dst_block_strides(params.dst_block_dims.size(), 1); + for (int i = params.src_block_dims.size() - 2; i >= 0; i--) + src_block_strides[i] = src_block_strides[i + 1] * params.src_block_dims[i + 1]; + for (int i = params.dst_block_dims.size() - 2; i >= 0; i--) + dst_block_strides[i] = dst_block_strides[i + 1] * params.dst_block_dims[i + 1]; + + SizeVector new_dst_block_strides = dst_block_strides; + SizeVector new_dst_block_order = params.dst_block_order; + SizeVector new_dst_block_dims = params.dst_block_dims; + SizeVector new_src_block_strides(dst_block_strides.size()); + SizeVector mask(dst_block_strides.size()); + + SizeVector tmp_order; + for (size_t i = 0; i < params.dst_block_order.size(); i++) { + tmp_order.push_back(params.order[params.dst_block_order[i]]); + } + + for (int i = tmp_order.size() - 1; i >= 0; i--) { + int pos = std::distance(std::find( + params.src_block_order.rbegin(), params.src_block_order.rend(), tmp_order[i]), params.src_block_order.rend() - 1); + if (pos != -1) { + new_src_block_strides[i] = src_block_strides[pos]; + params.src_block_order.erase(params.src_block_order.begin() + pos); + src_block_strides.erase(src_block_strides.begin() + pos); + mask[i] = 0; + } else { + new_src_block_strides[i] = new_src_block_strides[tmp_order.size() - 1] * params.dst_block_dims[tmp_order.size() - 1]; + mask[i] = 1; + mask[tmp_order.size() - 1] = 1; + } + } + if (!params.src_block_order.empty()) { + int pos = std::distance(tmp_order.begin(), std::find(tmp_order.begin(), tmp_order.end(), params.src_block_order[0])); + new_src_block_strides.insert(new_src_block_strides.begin() + pos, + src_block_strides[0]); + new_dst_block_strides.insert(new_dst_block_strides.begin() + pos, + new_dst_block_strides[pos] * params.src_block_dims[params.src_block_dims.size() - 1]); + new_dst_block_order.insert(new_dst_block_order.begin() + pos, + new_dst_block_order[pos]); + new_dst_block_dims.insert(new_dst_block_dims.begin() + pos + 1, + params.src_block_dims[params.src_block_dims.size() - 1]); + new_dst_block_dims[pos] = div_up(new_dst_block_dims[pos], new_dst_block_dims[pos + 1]); + mask.insert(mask.begin() + pos + 1, 1); + mask[pos] = 1; + } + + SizeVector sorted_src_strides; + SizeVector sorted_dst_strides; + SizeVector sorted_order; + SizeVector sorted_dst_dims; + + // support dynamic batch + int batch_ord = std::distance(params.order.begin(), std::find(params.order.begin(), params.order.end(), 0)); + int batch_count = 0; + int batch_pos = 0; + for (size_t i = 0; i < new_dst_block_order.size(); i++) { + if (new_dst_block_order[i] == batch_ord) { + batch_count++; + batch_pos = i; + } + } + if (batch_count == 1) { + sorted_src_strides.push_back(new_src_block_strides[batch_pos]); + sorted_dst_strides.push_back(new_dst_block_strides[batch_pos]); + sorted_order.push_back(new_dst_block_order[batch_pos]); + sorted_dst_dims.push_back(new_dst_block_dims[batch_pos]); + jcp.supported_dynamic_batch = true; + } + + int n2 = 0; + for (size_t i = 0; i < mask.size(); i++) { + if (mask[i] == 0) { + n2++; + if (batch_count == 1 && new_dst_block_order[i] == batch_ord) { + continue; + } + sorted_src_strides.push_back(new_src_block_strides[i]); + sorted_dst_strides.push_back(new_dst_block_strides[i]); + sorted_order.push_back(new_dst_block_order[i]); + sorted_dst_dims.push_back(new_dst_block_dims[i]); + } + } + for (size_t i = 0; i < mask.size(); i++) { + if (mask[i] == 1) { + sorted_src_strides.push_back(new_src_block_strides[i]); + sorted_dst_strides.push_back(new_dst_block_strides[i]); + sorted_order.push_back(new_dst_block_order[i]); + sorted_dst_dims.push_back(new_dst_block_dims[i]); + } + } + + int max_threads = parallel_get_max_threads(); + const int n_max = 3; // max count dims for parallel + int n = 0; + int work_amount = sorted_dst_dims[0]; + for (size_t i = 1; i < sorted_dst_dims.size() && n < n_max; i++) { + n++; + if (work_amount >= 4 * max_threads) { // 4 * max_threads is a specially selected value for best performance + break; + } + work_amount *= sorted_dst_dims[i]; + } + + jcp.src_strides = sorted_src_strides; + jcp.dst_strides = sorted_dst_strides; + jcp.dst_block_dims = sorted_dst_dims; + jcp.n = std::min(n, n2); + jcp.ndims = sorted_order.size(); + jcp.data_size = params.data_size; + + if (mayiuse(cpu::x64::avx512_common)) { + permute_kernel.reset(new jit_uni_permute_kernel_f32(jcp)); + } else if (mayiuse(cpu::x64::avx2)) { + permute_kernel.reset(new jit_uni_permute_kernel_f32(jcp)); + } else if (mayiuse(cpu::x64::sse41)) { + permute_kernel.reset(new jit_uni_permute_kernel_f32(jcp)); + } + + if (permute_kernel) + permute_kernel->create_ker(); +} + +void PermuteKernel::execute(const uint8_t* src_data, uint8_t* dst_data, const int mb) { + if (permute_kernel) { + optimizedExecute(src_data, dst_data, mb); + return; + } + + referenceExecute(src_data, dst_data, mb); +} + +void PermuteKernel::optimizedExecute(const uint8_t* src_data, uint8_t* dst_data, const int mb) { + SizeVector dst_dims = jcp.dst_block_dims; + const SizeVector dst_strides = jcp.dst_strides; + const SizeVector src_strides = jcp.src_strides; + + if (dst_dims[0] != mb) + dst_dims[0] = mb; + + switch (jcp.n) { + case 1: + parallel_for(dst_dims[0], [&](int i0) { + auto arg = jit_args_permute(); + + size_t dst_off = i0 * dst_strides[0]; + size_t src_off = i0 * src_strides[0]; + arg.src = &src_data[src_off * jcp.data_size]; + arg.dst = &dst_data[dst_off * jcp.data_size]; + + (*permute_kernel)(&arg); + }); + break; + case 2: + parallel_for2d(dst_dims[0], dst_dims[1], [&](int i0, int i1) { + auto arg = jit_args_permute(); + + size_t dst_off = i0 * dst_strides[0] + i1 * dst_strides[1]; + size_t src_off = i0 * src_strides[0] + i1 * src_strides[1]; + arg.src = &src_data[src_off * jcp.data_size]; + arg.dst = &dst_data[dst_off * jcp.data_size]; + + (*permute_kernel)(&arg); + }); + break; + case 3: + parallel_for3d(dst_dims[0], dst_dims[1], dst_dims[2], [&](int i0, int i1, int i2) { + auto arg = jit_args_permute(); + + size_t dst_off = i0 * dst_strides[0] + i1 * dst_strides[1] + i2 * dst_strides[2]; + size_t src_off = i0 * src_strides[0] + i1 * src_strides[1] + i2 * src_strides[2]; + arg.src = &src_data[src_off * jcp.data_size]; + arg.dst = &dst_data[dst_off * jcp.data_size]; + + (*permute_kernel)(&arg); + }); + break; + } + return; +} + +static inline size_t parallel_init(size_t start, size_t nDims, const SizeVector& dims, SizeVector& indexes) { + for (int j = nDims - 1; j >= 0; j--) { + indexes[j] = start % dims[j]; + start = start / dims[j]; + } + return start; +} + +static inline void parallel_step(size_t nDims, const SizeVector& dims, SizeVector& indexes) { + for (int j = nDims - 1; j >= 0; --j) { + ++indexes[j]; + if (indexes[j] < dims[j]) + break; + else + indexes[j] = 0; + } +} + +void PermuteKernel::referenceExecute(const uint8_t* src_data, uint8_t* dst_data, const int mb) { + SizeVector dst_dims = jcp.dst_block_dims; + const SizeVector dst_strides = jcp.dst_strides; + const SizeVector src_strides = jcp.src_strides; + const size_t data_size = jcp.data_size; + const size_t ndims = dst_dims.size(); + + if (dst_dims[0] != mb) + dst_dims[0] = mb; + + size_t work_amount = std::accumulate(dst_dims.begin(), dst_dims.end(), 1, std::multiplies()); + + auto get_idx = [ndims, data_size](const SizeVector& indexes, const SizeVector& strides) { + size_t idx = 0; + for (size_t i = 0; i < ndims; ++i) + idx += indexes[i] * strides[i]; + return idx * data_size; + }; + + parallel_nt(0, [&](const int ithr, const int nthr) { + size_t start = 0, end = 0; + SizeVector indexes(ndims, 0); + splitter(work_amount, nthr, ithr, start, end); + + parallel_init(start, ndims, dst_dims, indexes); + + for (size_t iwork = start; iwork < end; ++iwork) { + const size_t dst_idx = get_idx(indexes, dst_strides); + const size_t src_idx = get_idx(indexes, src_strides); + cpu_memcpy(&dst_data[dst_idx], &src_data[src_idx], data_size); + + parallel_step(ndims, dst_dims, indexes); + } + }); +} diff --git a/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.h b/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.h new file mode 100644 index 00000000000..be6427c7007 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/common/permute_kernel.h @@ -0,0 +1,71 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +namespace MKLDNNPlugin { + +struct PermuteParams { + InferenceEngine::SizeVector src_block_dims; + InferenceEngine::SizeVector dst_block_dims; + InferenceEngine::SizeVector src_block_order; + InferenceEngine::SizeVector dst_block_order; + InferenceEngine::SizeVector order; + size_t data_size; +}; + +struct jit_permute_config_params { + uint32_t ndims; + InferenceEngine::SizeVector dst_block_dims; + InferenceEngine::SizeVector src_strides; + InferenceEngine::SizeVector dst_strides; + int n; + int data_size; + + bool supported_dynamic_batch = false; +}; + +struct jit_args_permute { + const void* src; + const void* dst; +}; + +struct jit_uni_permute_kernel { + void (*ker_)(const jit_args_permute *); + + void operator()(const jit_args_permute *args) { + assert(ker_); + ker_(args); + } + + explicit jit_uni_permute_kernel(jit_permute_config_params jcp_) : ker_(nullptr), jcp(jcp_) {} + virtual ~jit_uni_permute_kernel() {} + + virtual void create_ker() = 0; + + jit_permute_config_params jcp; +}; + +class PermuteKernel { +public: + PermuteKernel(const PermuteParams& params); + + void execute(const uint8_t* src_data, uint8_t* dst_data, const int mb); + +private: + void prepareParams(); + + void optimizedExecute(const uint8_t* src_data, uint8_t* dst_data, const int mb); + void referenceExecute(const uint8_t* src_data, uint8_t* dst_data, const int mb); + + jit_permute_config_params jcp = {}; + std::shared_ptr permute_kernel; + PermuteParams params; +}; + +} // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/nodes/depth_to_space.cpp b/inference-engine/src/mkldnn_plugin/nodes/depth_to_space.cpp deleted file mode 100644 index 6c91ca30b7f..00000000000 --- a/inference-engine/src/mkldnn_plugin/nodes/depth_to_space.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "base.hpp" - -#include -#include -#include -#include -#include -#include "ie_parallel.hpp" - -namespace InferenceEngine { -namespace Extensions { -namespace Cpu { - -class DepthToSpaceImpl: public ExtLayerBase { - enum class DepthToSpaceMode { - BLOCKS_FIRST, - DEPTH_FIRST - }; - -public: - explicit DepthToSpaceImpl(const CNNLayer* layer) { - try { - if (layer->insData.empty() || layer->outData.empty()) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' has incorrect number of input/output edges"; - - inDims = layer->insData[0].lock()->getTensorDesc().getDims(); - if (inDims.size() < 3) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' has incorrect number of input dimensions"; - - if (inDims.size() > 5) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' doesn't support dimensions with rank greater than 5"; - - SizeVector outDims = layer->outData[0]->getTensorDesc().getDims(); - if (inDims.size() != outDims.size()) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' has incorrect number of input/output dimensions"; - - std::string modeString = layer->GetParamAsString("mode"); - if (modeString == "blocks_first") { - mode = DepthToSpaceMode::BLOCKS_FIRST; - } else if (modeString == "depth_first") { - mode = DepthToSpaceMode::DEPTH_FIRST; - } else { - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' doesn't support mode: " << modeString; - } - - blockSize = layer->GetParamAsUInt("block_size", 1); - if (blockSize == 0) - IE_THROW() << layer->name << " Incorrect blockSize parameter is zero!"; - - size_t numSpatialDims = inDims.size() - 2; - blockStep = static_cast(std::pow(blockSize, numSpatialDims)); - if (inDims[1] % blockStep) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << - "' has block_size parameter which is incompatible with input tensor channels dimension size"; - - if (inDims[1] / blockStep != outDims[1]) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << " has incompatible input/output channels"; - - for (int i = 0; i < numSpatialDims; i++) { - if (inDims[i + 2] * blockSize != outDims[i + 2]) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << " has incompatible spatial dims"; - } - - auto computePrc = layer->insData[0].lock()->getTensorDesc().getPrecision(); - const std::set supported_precision_sizes = {1, 2, 4, 8}; - if (supported_precision_sizes.find(computePrc.size()) == supported_precision_sizes.end()) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << " doesn't support precision: " << computePrc.name(); - - - if (inDims.size() == 4 || inDims.size() == 5) { - LayerConfig config; - DataConfig inConfig; - inConfig.desc = TensorDesc(computePrc, inDims, inDims.size() == 4 ? NHWC : NDHWC); - config.inConfs.push_back(inConfig); - - DataConfig outConfig; - outConfig.desc = TensorDesc(computePrc, outDims, outDims.size() == 4 ? NHWC : NDHWC); - config.outConfs.push_back(outConfig); - - config.dynBatchSupport = false; - confs.push_back(config); - } - - LayerConfig config; - DataConfig inConfig; - inConfig.desc = TensorDesc(computePrc, inDims, InferenceEngine::TensorDesc::getLayoutByDims(inDims)); - config.inConfs.push_back(inConfig); - - DataConfig outConfig; - outConfig.desc = TensorDesc(computePrc, outDims, InferenceEngine::TensorDesc::getLayoutByDims(outDims)); - config.outConfs.push_back(outConfig); - - config.dynBatchSupport = false; - confs.push_back(config); - } catch (InferenceEngine::Exception &ex) { - errorMsg = ex.what(); - } - } - - StatusCode execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept override { - switch (inputs[0]->getTensorDesc().getPrecision().size()) { - case 1: depthToSpaceKernel::value_type>(inputs, outputs); break; - case 2: depthToSpaceKernel::value_type>(inputs, outputs); break; - case 4: depthToSpaceKernel::value_type>(inputs, outputs); break; - case 8: depthToSpaceKernel::value_type>(inputs, outputs); break; - default: { - if (resp) { - std::string errorMsg = "DepthToSpace layer with name does not support precision '" - + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; - errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); - - return GENERAL_ERROR; - } - } - } - - return OK; - } - -private: - std::vector getShape5D(const SizeVector& shape) { - std::vector shape5D(5, 1); - for (int i = 0; i < shape.size(); i++) { - shape5D[i] = shape[i]; - } - return shape5D; - } - - std::vector getBlock3D(const SizeVector& shape) { - std::vector block3D(3, 1); - for (int i = 0; i < shape.size() - 2; i++) { - block3D[i] = blockSize; - } - return block3D; - } - - template - void depthToSpaceKernel(std::vector& inputs, std::vector& outputs) { - const T *src_data = inputs[0]->cbuffer().as() + inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - T* dst_data = outputs[0]->buffer().as() + outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - - auto shape5D = getShape5D(inDims); - auto block3D = getBlock3D(inDims); - - size_t spatialStep = shape5D[2] * shape5D[3] * shape5D[4]; - size_t batchStep = shape5D[1] * spatialStep; - - size_t srcChannels = shape5D[1]; - size_t dstChannels = srcChannels / blockStep; - - size_t blockShift = mode == DepthToSpaceMode::BLOCKS_FIRST ? (dstChannels) : 1; - size_t channelShift = mode == DepthToSpaceMode::BLOCKS_FIRST ? 1 : blockStep; - - if (inputs[0]->getTensorDesc().getLayout() == NHWC || inputs[0]->getTensorDesc().getLayout() == NDHWC) { - parallel_for2d(shape5D[0], shape5D[2], [&](size_t i0, size_t i2) { - size_t srcIdx1 = i0 * batchStep; - size_t dstIdx1 = i0 * batchStep; - for (size_t b2 = 0; b2 < block3D[0]; b2++) { - size_t srcIdx2 = srcIdx1 + i2 * shape5D[3] * shape5D[4] * srcChannels + b2 * block3D[1] * block3D[2] * blockShift; - size_t dstIdx2 = dstIdx1 + (i2 * block3D[0] + b2) * shape5D[3] * block3D[1] * shape5D[4] * block3D[2] * dstChannels; - for (size_t i3 = 0; i3 < shape5D[3]; i3++) { - for (size_t b3 = 0; b3 < block3D[1]; b3++) { - size_t srcIdx3 = srcIdx2 + i3 * shape5D[4] * srcChannels + b3 * block3D[2] * blockShift; - size_t dstIdx3 = dstIdx2 + (i3 * block3D[1] + b3) * shape5D[4] * block3D[2] * dstChannels; - for (size_t i4 = 0; i4 < shape5D[4]; i4++) { - for (size_t b4 = 0; b4 < block3D[2]; b4++) { - size_t srcIdx4 = srcIdx3 + i4 * srcChannels + b4 * blockShift; - size_t dstIdx4 = dstIdx3 + (i4 * block3D[2] + b4) * dstChannels; - for (size_t i1 = 0; i1 < dstChannels; i1++) { - size_t srcIdx5 = srcIdx4 + i1 * channelShift; - size_t dstIdx5 = dstIdx4 + i1; - dst_data[dstIdx5] = src_data[srcIdx5]; - } - } - } - } - } - } - }); - } else { - parallel_for2d(shape5D[0], dstChannels, [&](size_t i0, size_t i1) { - size_t srcIdx1 = i0 * batchStep + i1 * channelShift * spatialStep; - size_t dstIdx1 = i0 * batchStep + i1 * blockStep * spatialStep; - for (size_t i2 = 0; i2 < shape5D[2]; i2++) { - for (size_t b2 = 0; b2 < block3D[0]; b2++) { - size_t srcIdx2 = srcIdx1 + i2 * shape5D[3] * shape5D[4] + b2 * block3D[1] * block3D[2] * blockShift * spatialStep; - size_t dstIdx2 = dstIdx1 + (i2 * block3D[0] + b2) * shape5D[3] * block3D[1] * shape5D[4] * block3D[2]; - for (size_t i3 = 0; i3 < shape5D[3]; i3++) { - for (size_t b3 = 0; b3 < block3D[1]; b3++) { - size_t srcIdx3 = srcIdx2 + i3 * shape5D[4] + b3 * block3D[2] * blockShift * spatialStep; - size_t dstIdx3 = dstIdx2 + (i3 * block3D[1] + b3) * shape5D[4] * block3D[2]; - for (size_t i4 = 0; i4 < shape5D[4]; i4++) { - for (size_t b4 = 0; b4 < block3D[2]; b4++) { - size_t srcIdx4 = srcIdx3 + i4 + b4 * blockShift * spatialStep; - size_t dstIdx4 = dstIdx3 + i4 * block3D[2] + b4; - dst_data[dstIdx4] = src_data[srcIdx4]; - } - } - } - } - } - } - }); - } - } - - DepthToSpaceMode mode; - SizeVector inDims; - size_t blockSize; - size_t blockStep; -}; - -REG_FACTORY_FOR(DepthToSpaceImpl, DepthToSpace); - -} // namespace Cpu -} // namespace Extensions -} // namespace InferenceEngine diff --git a/inference-engine/src/mkldnn_plugin/nodes/list_tbl.hpp b/inference-engine/src/mkldnn_plugin/nodes/list_tbl.hpp index 12604eef081..da6e70d7eeb 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/list_tbl.hpp +++ b/inference-engine/src/mkldnn_plugin/nodes/list_tbl.hpp @@ -49,7 +49,6 @@ MKLDNN_EXTENSION_NODE(SqueezeImpl, Squeeze); MKLDNN_EXTENSION_NODE(FillImpl, Fill); MKLDNN_EXTENSION_NODE(UniqueImpl, Unique); MKLDNN_EXTENSION_NODE(PSROIPoolingImpl, PSROIPooling); -MKLDNN_EXTENSION_NODE(DepthToSpaceImpl, DepthToSpace); MKLDNN_EXTENSION_NODE(OneHotImpl, OneHot); MKLDNN_EXTENSION_NODE(BroadcastImpl, Broadcast); MKLDNN_EXTENSION_NODE(ExperimentalSparseWeightedReduceImpl, ExperimentalSparseWeightedSum); @@ -59,7 +58,6 @@ MKLDNN_EXTENSION_NODE(ONNXCustomProposalImpl, ExperimentalDetectronGeneratePropo MKLDNN_EXTENSION_NODE(NonMaxSuppressionImpl, NonMaxSuppression); MKLDNN_EXTENSION_NODE(TopKImpl, TopK); MKLDNN_EXTENSION_NODE(ShuffleChannelsImpl, ShuffleChannels); -MKLDNN_EXTENSION_NODE(SpaceToDepthImpl, SpaceToDepth); MKLDNN_EXTENSION_NODE(PowerFileImpl, PowerFile); MKLDNN_EXTENSION_NODE(BatchToSpaceImpl, BatchToSpace); MKLDNN_EXTENSION_NODE(ExperimentalDetectronPriorGridGeneratorImpl, ExperimentalDetectronPriorGridGenerator); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.cpp new file mode 100644 index 00000000000..6764e49c8d9 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.cpp @@ -0,0 +1,245 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "mkldnn_depth_to_space_node.h" + +#include +#include +#include +#include "common/tensor_desc_creator.h" + +#include +#include + +#define THROW_ERROR IE_THROW() << "DepthToSpace layer with name '" << getName() << "' " + +using namespace MKLDNNPlugin; +using namespace InferenceEngine; +using namespace mkldnn; +using namespace mkldnn::impl; +using namespace mkldnn::impl::cpu::x64; + +MKLDNNDepthToSpaceNode::MKLDNNDepthToSpaceNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) + : MKLDNNNode(layer, eng, cache) {} + +void MKLDNNDepthToSpaceNode::getSupportedDescriptors() { + auto* depthToSpaceLayer = dynamic_cast(getCnnLayer().get()); + if (depthToSpaceLayer == nullptr) + THROW_ERROR << "cannot convert from CNN layer"; + + if (depthToSpaceLayer->insData[0].lock() == nullptr) + THROW_ERROR << "has nullable input data"; + + SizeVector srcDims = depthToSpaceLayer->insData[0].lock()->getTensorDesc().getDims(); + if (srcDims.size() < 3) + THROW_ERROR << "has incorrect number of input dimensions"; + if (srcDims.size() > 5) + THROW_ERROR << "doesn't support dimensions with rank greater than 5"; + + if (depthToSpaceLayer->outData[0] == nullptr) + THROW_ERROR << "has nullable output data"; + + SizeVector dstDims = depthToSpaceLayer->outData[0]->getTensorDesc().getDims(); + if (srcDims.size() != dstDims.size()) + THROW_ERROR << "has incorrect number of input/output dimensions"; + + std::string modeString = depthToSpaceLayer->GetParamAsString("mode"); + if (modeString == "blocks_first") { + mode = Mode::BLOCKS_FIRST; + } else if (modeString == "depth_first") { + mode = Mode::DEPTH_FIRST; + } else { + THROW_ERROR << "doesn't support mode: " << modeString; + } + + blockSize = depthToSpaceLayer->GetParamAsUInt("block_size", 1); + if (blockSize == 0) + THROW_ERROR << "has incorrect block_size parameter is zero!"; + + size_t nSpatialDims = srcDims.size() - 2; + blockStep = static_cast(std::pow(blockSize, nSpatialDims)); + if (srcDims[1] % blockStep) + THROW_ERROR << "has block_size parameter which is incompatible with input tensor channels dimension size"; + + if (srcDims[1] / blockStep != dstDims[1]) + THROW_ERROR << "has incompatible input/output channels"; + + for (size_t i = 0; i < nSpatialDims; ++i) { + if (srcDims[i + 2] * blockSize != dstDims[i + 2]) + THROW_ERROR << "has incompatible spatial dims"; + } + + if (getParentEdges().size() != 1) + THROW_ERROR << "has incorrect number of input edges"; + if (getChildEdges().empty()) + THROW_ERROR << "has incorrect number of output edges"; +} + +void MKLDNNDepthToSpaceNode::initSupportedPrimitiveDescriptors() { + if (!supportedPrimitiveDescriptors.empty()) + return; + + InferenceEngine::Precision precision = getCnnLayer()->insData[0].lock()->getPrecision(); + auto srcDims = getParentEdgeAt(0)->getDims(); + const size_t nDims = srcDims.ndims(); + + impl_desc_type impl_type; + if (mayiuse(impl::cpu::x64::avx512_common)) { + impl_type = impl_desc_type::jit_avx512; + } else if (mayiuse(cpu::x64::avx2)) { + impl_type = impl_desc_type::jit_avx2; + } else if (mayiuse(cpu::x64::sse41)) { + impl_type = impl_desc_type::jit_sse42; + } else { + impl_type = impl_desc_type::ref; + } + + InferenceEngine::LayerConfig config; + config.dynBatchSupport = true; + config.inConfs.resize(1); + config.outConfs.resize(1); + config.inConfs[0].inPlace = -1; + config.inConfs[0].constant = false; + config.outConfs[0].inPlace = -1; + config.outConfs[0].constant = false; + + std::vector supportedTypes; + if (nDims > 2) { + auto canUseBlocked = [=](const size_t block) { + return srcDims[1] % block == 0 && (mode == Mode::BLOCKS_FIRST ? (srcDims[1] / block) % blockStep == 0 : block % blockStep == 0); + }; + + supportedTypes.push_back(TensorDescCreatorTypes::nspc); + if (canUseBlocked(8lu)) + supportedTypes.push_back(TensorDescCreatorTypes::nCsp8c); + if (canUseBlocked(16lu)) + supportedTypes.push_back(TensorDescCreatorTypes::nCsp16c); + } + supportedTypes.push_back(TensorDescCreatorTypes::ncsp); + auto creators = TensorDescCreator::getCommonCreators(); + auto range = TensorDescCreator::makeFilteredRange(creators, nDims, supportedTypes); + + for (auto itr = range.first; itr != range.second; ++itr) { + config.inConfs[0].desc = itr->second->createDesc(precision, getParentEdgeAt(0)->getDims().ToSizeVector()); + config.outConfs[0].desc = itr->second->createDesc(precision, getChildEdgeAt(0)->getDims().ToSizeVector()); + supportedPrimitiveDescriptors.emplace_back(config, impl_type, MKLDNNMemoryDesc(config.outConfs.front().desc).getFormat()); + } +} + +void MKLDNNDepthToSpaceNode::createPrimitive() { + auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); + auto &srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); + if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr()) + THROW_ERROR << "has not allocated destination memory"; + if (!srcMemPtr || !srcMemPtr->GetPrimitivePtr()) + THROW_ERROR << "has not allocated input memory"; + if (getSelectedPrimitiveDescriptor() == nullptr) + THROW_ERROR << "has unidentified preferable primitive descriptor"; + + SizeVector srcDims = getParentEdgeAt(0)->getBlob()->getTensorDesc().getDims(); + SizeVector dstDims = getChildEdgeAt(0)->getBlob()->getTensorDesc().getDims(); + + size_t nDims = srcDims.size(); + const size_t nSpatialDims = nDims - 2; + const bool isBlocked = getParentEdgeAt(0)->getMemory().GetDesc().isBlockedCFormat(); + const size_t reshapedRank = nDims + nSpatialDims + static_cast(isBlocked) + static_cast(isBlocked && mode == Mode::DEPTH_FIRST); + const size_t lastIdx = reshapedRank - 1; + size_t firstSpatialOrder = 2; + + PermuteParams params; + params.data_size = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc.getPrecision().size(); + params.order.resize(reshapedRank, 0); + params.src_block_order.resize(reshapedRank); + params.dst_block_order.resize(reshapedRank); + params.dst_block_dims.resize(reshapedRank); + params.src_block_dims.resize(reshapedRank); + params.src_block_dims[0] = srcDims[0]; + + // reshaping of src dimensions and creating the permutation order for each layout: + // new shape: mode = blocks_first [N, block_size, block_size, ..., block_size, C / (block_size ^ K), D1, D2, ..., DK] + // mode = depth_first [N, C / (block_size ^ K), block_size, block_size, ..., block_size, D1, D2, ..., DK] + // order : mode = blocks_first : [0, K + 1, K + 2, 1, K + 3, 2, K + 4, 3, ..., K + (K + 1), K] + // mode = depth_first : [0, 1, K + 2, 2, K + 3, 3, K + 4, 4, ..., K + (K + 1), K + 1] + // where `k` is number of spatial dimensions + + auto reshapeAndSetPermOrder = [&](const size_t idx1, const size_t idx2, const size_t shift, const SizeVector& dims) { + for (size_t i = 0; i < nSpatialDims; i++) { + params.order[i * 2 + shift] = i + idx1; + params.order[i * 2 + shift + 1] = i + idx2; + + params.src_block_dims[params.order[i * 2 + shift]] = dims[i + shift]; + params.src_block_dims[params.order[i * 2 + shift + 1]] = blockSize; + } + }; + + if (isBlocked) { + SizeVector srcBlockedDims = getParentEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); + SizeVector dstBlockedDims = getChildEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); + + size_t orderShiftForBlocks, orderShiftForDims; + if (mode == Mode::BLOCKS_FIRST) { + orderShiftForBlocks = 1; + orderShiftForDims = nSpatialDims + 2; + + params.src_block_dims[nSpatialDims + 1] = srcBlockedDims[1] / blockStep; + params.src_block_dims[lastIdx] = srcBlockedDims.back(); + + params.order[1] = nSpatialDims + 1; + params.order[lastIdx] = lastIdx; + } else { + orderShiftForBlocks = nSpatialDims + 4; + orderShiftForDims = 3; + + size_t newBlockSize = srcBlockedDims.back() / blockStep; + size_t newBlocksCount = srcBlockedDims[1] * newBlockSize / srcBlockedDims.back(); + params.src_block_dims[1] = newBlocksCount; + params.src_block_dims[2] = srcBlockedDims[1] / newBlocksCount; + params.src_block_dims[lastIdx - nSpatialDims] = newBlockSize; + + params.order[1] = 1; + params.order[2] = 3; + params.order[lastIdx - 1] = 2; + params.order[lastIdx] = lastIdx - nSpatialDims; + } + + reshapeAndSetPermOrder(orderShiftForDims, orderShiftForBlocks, firstSpatialOrder, srcBlockedDims); + } else if (getParentEdgeAt(0)->getMemory().GetDesc().isTailCFormat()) { + srcDims.push_back(srcDims[1]); + dstDims.push_back(dstDims[1]); + srcDims.erase(srcDims.begin() + 1); + dstDims.erase(dstDims.begin() + 1); + firstSpatialOrder = 1; + + size_t shift = static_cast(mode == DEPTH_FIRST) + nSpatialDims + 1; + params.order[lastIdx] = mode == Mode::DEPTH_FIRST ? nSpatialDims + 1 : lastIdx; + params.src_block_dims[params.order[lastIdx]] = srcDims.back() / blockStep; + + reshapeAndSetPermOrder(firstSpatialOrder, shift, firstSpatialOrder, srcDims); + } else { + size_t shift = static_cast(mode == DEPTH_FIRST) + 1; + params.order[1] = mode == DEPTH_FIRST ? 1 : nSpatialDims + 1; + params.src_block_dims[params.order[1]] = srcDims[1] / blockStep; + + reshapeAndSetPermOrder(nSpatialDims + firstSpatialOrder, shift, firstSpatialOrder, srcDims); + } + + std::iota(params.src_block_order.begin(), params.src_block_order.end(), 0); + std::iota(params.dst_block_order.begin(), params.dst_block_order.end(), 0); + for (size_t i = 0; i < reshapedRank; i++) + params.dst_block_dims[i] = params.src_block_dims[params.order[i]]; + + permuteKernel = std::unique_ptr(new PermuteKernel(params)); +} + +void MKLDNNDepthToSpaceNode::execute(mkldnn::stream strm) { + const uint8_t* srcData = reinterpret_cast(this->getParentEdgeAt(0)->getMemoryPtr()->GetPtr()); + uint8_t* dstData = reinterpret_cast(this->getChildEdgeAt(0)->getMemoryPtr()->GetPtr()); + + permuteKernel->execute(srcData, dstData, batchToProcess()); +} + +bool MKLDNNDepthToSpaceNode::created() const { + return getType() == DepthToSpace; +} +REG_MKLDNN_PRIM_FOR(MKLDNNDepthToSpaceNode, DepthToSpace); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.h new file mode 100644 index 00000000000..3ca5f8709a9 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_depth_to_space_node.h @@ -0,0 +1,38 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include "common/permute_kernel.h" + +namespace MKLDNNPlugin { + +class MKLDNNDepthToSpaceNode : public MKLDNNNode { +public: + MKLDNNDepthToSpaceNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); + ~MKLDNNDepthToSpaceNode() override = default; + + void getSupportedDescriptors() override; + void initSupportedPrimitiveDescriptors() override; + void createPrimitive() override; + void execute(mkldnn::stream strm) override; + bool created() const override; + +private: + enum Mode { + BLOCKS_FIRST = 0, + DEPTH_FIRST = 1 + }; + + Mode mode; + size_t blockSize; + size_t blockStep; + + std::unique_ptr permuteKernel; +}; + +} // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_pad_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_pad_node.cpp index 27554f51237..b4e812838f5 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_pad_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_pad_node.cpp @@ -130,8 +130,8 @@ void MKLDNNPadNode::createPrimitive() { params.sizeData = this->getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc.getPrecision().size(); - params.srcDims = getParentEdgeAt(0)->getBlob()->getTensorDesc().getBlockingDesc().getBlockDims(); - params.dstDims = getChildEdgeAt(0)->getBlob()->getTensorDesc().getBlockingDesc().getBlockDims(); + params.srcDims = getParentEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); + params.dstDims = getChildEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); size_t nDims = params.srcDims.size(); params.srcStrides.resize(nDims, 1); @@ -147,7 +147,7 @@ void MKLDNNPadNode::createPrimitive() { padsBegin.push_back(0); padsEnd.push_back(0); } else { - auto order = getParentEdgeAt(0)->getBlob()->getTensorDesc().getBlockingDesc().getOrder(); + auto order = getParentEdgeAt(0)->getDesc().getBlockingDesc().getOrder(); std::vector newPadsBegin(padsBegin.size(), 0), newPadsEnd(padsEnd.size(), 0); for (size_t i = 0; i < padsBegin.size(); ++i) { newPadsBegin[i] = padsBegin[order[i]]; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.cpp index 507cfa1d238..a1575166167 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.cpp @@ -5,136 +5,15 @@ #include "mkldnn_permute_node.h" #include #include -#include #include #include "ie_parallel.hpp" -#include #include using namespace mkldnn; using namespace MKLDNNPlugin; using namespace InferenceEngine; -using namespace mkldnn::impl; -using namespace mkldnn::impl::cpu::x64; -using namespace mkldnn::impl::utils; -#define GET_OFF(field) offsetof(jit_args_permute, field) - -template -struct jit_uni_permute_kernel_f32 : public jit_uni_permute_kernel, public jit_generator { - DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_permute_kernel_f32) - - explicit jit_uni_permute_kernel_f32(jit_permute_conf_t jpp) : jit_uni_permute_kernel(jpp), jit_generator() {} - - void create_ker() override { - jit_generator::create_kernel(); - ker_ = (decltype(ker_))jit_ker(); - } - - void generate() override { - this->preamble(); - - mov(reg_src, ptr[reg_params + GET_OFF(src)]); - mov(reg_dst, ptr[reg_params + GET_OFF(dst)]); - - loop(jpp.n); - - this->postamble(); - } - - void load(const Xbyak::Xmm &xmm, const Xbyak::Address &addr) { - switch (jpp.data_size) { - case 16: movups(xmm, addr); break; - case 8: movsd(xmm, addr); break; - case 4: movss(xmm, addr); break; - case 2: pinsrw(xmm, addr, 0x0); break; - case 1: pinsrb(xmm, addr, 0x0); break; - } - } - - void store(const Xbyak::Address &addr, const Xbyak::Xmm &xmm) { - switch (jpp.data_size) { - case 16: movups(addr, xmm); break; - case 8: movsd(addr, xmm); break; - case 4: movss(addr, xmm); break; - case 2: pextrw(addr, xmm, 0x0); break; - case 1: pextrb(addr, xmm, 0x0); break; - } - } - - void loop(int n) { - mov(reg_work_amount, jpp.dst_block_dims[n]); - - Xbyak::Label main_loop_label; - Xbyak::Label tail_loop_label; - Xbyak::Label exit_label; - - if (n + 1 == jpp.ndims) { - if (jpp.src_strides[n] == jpp.dst_strides[n] == 1) { - uint32_t step = vlen / jpp.data_size; - - L(main_loop_label); - { - cmp(reg_work_amount, step); - jl(tail_loop_label, T_NEAR); - - uni_vmovups(vmm, ptr[reg_src]); - uni_vmovups(ptr[reg_dst], vmm); - - add(reg_src, step * jpp.data_size); - add(reg_dst, step * jpp.data_size); - sub(reg_work_amount, step); - - jmp(main_loop_label, T_NEAR); - } - } - } - - L(tail_loop_label); { - cmp(reg_work_amount, 0); - je(exit_label, T_NEAR); - - if (n + 1 == jpp.ndims) { - load(xmm, ptr[reg_src]); - store(ptr[reg_dst], xmm); - } else { - aux_reg_src = reg_src; - aux_reg_dst = reg_dst; - push(aux_reg_src); - push(aux_reg_dst); - push(reg_work_amount); - loop(n + 1); - pop(reg_work_amount); - pop(reg_dst); - pop(reg_src); - } - - add(reg_src, jpp.src_strides[n] * jpp.data_size); - add(reg_dst, jpp.dst_strides[n] * jpp.data_size); - sub(reg_work_amount, 1); - - jmp(tail_loop_label, T_NEAR); - } - - L(exit_label); - } - -private: - using Vmm = typename conditional3::type; - uint32_t vlen = cpu_isa_traits::vlen; - - Xbyak::Reg64 reg_src = r8; - Xbyak::Reg64 reg_dst = r9; - Xbyak::Reg64 reg_work_amount = r10; - Xbyak::Reg64 aux_reg_src = r11; - Xbyak::Reg64 aux_reg_dst = r12; - - Xbyak::Reg64 reg_params = abi_param1; - - Vmm vmm = Vmm(0); - Xbyak::Xmm xmm = Xbyak::Xmm(0); -}; MKLDNNPermuteNode::MKLDNNPermuteNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) : MKLDNNNode(layer, eng, cache) {} @@ -195,7 +74,7 @@ void MKLDNNPermuteNode::initSupportedPrimitiveDescriptors() { supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown, memory::format_tag::nChw16c}); } - if (prec == Precision::I8 || prec == Precision::U8) { + if (prec == Precision::FP32 || prec == Precision::I8 || prec == Precision::U8) { config.inConfs[0].desc = MKLDNNMemoryDesc(getParentEdgeAt(0)->getDims(), inputDataType, memory::format_tag::nhwc); config.outConfs[0].desc = MKLDNNMemoryDesc(getChildEdgeAt(0)->getDims(), outputDataType, memory::format_tag::nhwc); supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown, memory::format_tag::nhwc}); @@ -216,7 +95,7 @@ void MKLDNNPermuteNode::initSupportedPrimitiveDescriptors() { supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown, memory::format_tag::nCdhw16c}); } - if (prec == Precision::I8 || prec == Precision::U8) { + if (prec == Precision::FP32 || prec == Precision::I8 || prec == Precision::U8) { config.inConfs[0].desc = MKLDNNMemoryDesc(getParentEdgeAt(0)->getDims(), inputDataType, memory::format_tag::ndhwc); config.outConfs[0].desc = MKLDNNMemoryDesc(getChildEdgeAt(0)->getDims(), outputDataType, memory::format_tag::ndhwc); supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown, memory::format_tag::ndhwc}); @@ -239,133 +118,19 @@ void MKLDNNPermuteNode::createPrimitive() { if (getSelectedPrimitiveDescriptor() == nullptr) IE_THROW() << "Preferable primitive descriptor is not set."; - Precision precision = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc.getPrecision(); - auto data_type = MKLDNNExtensionUtils::IEPrecisionToDataType(precision); + PermuteParams params; + params.data_size = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc.getPrecision().size(); + params.order = order; - jit_permute_conf_t jpp; + auto srcDesc = getParentEdgeAt(0)->getDesc(); + params.src_block_dims = srcDesc.getBlockingDesc().getBlockDims(); + params.src_block_order = srcDesc.getBlockingDesc().getOrder(); - auto srcDesc = getParentEdgeAt(0)->getBlob()->getTensorDesc(); - auto src_dims = srcDesc.getDims(); - auto src_block_dims = srcDesc.getBlockingDesc().getBlockDims(); - auto src_block_order = srcDesc.getBlockingDesc().getOrder(); - auto src_block_strides = srcDesc.getBlockingDesc().getStrides(); + auto dstDesc = getChildEdgeAt(0)->getDesc(); + params.dst_block_dims = dstDesc.getBlockingDesc().getBlockDims(); + params.dst_block_order = dstDesc.getBlockingDesc().getOrder(); - auto dstDesc = getChildEdgeAt(0)->getBlob()->getTensorDesc(); - auto dst_dims = dstDesc.getDims(); - auto dst_block_dims = dstDesc.getBlockingDesc().getBlockDims(); - auto dst_block_order = dstDesc.getBlockingDesc().getOrder(); - auto dst_block_strides = dstDesc.getBlockingDesc().getStrides(); - - SizeVector tmp_order; - for (int i = 0; i < dst_block_order.size(); i++) { - tmp_order.push_back(order[dst_block_order[i]]); - } - - SizeVector new_dst_block_strides = dst_block_strides; - SizeVector new_dst_block_order = dst_block_order; - SizeVector new_dst_block_dims = dst_block_dims; - SizeVector new_src_block_strides(dst_block_strides.size()); - SizeVector mask(dst_block_strides.size()); - - for (int i = tmp_order.size() - 1; i >= 0; i--) { - int pos = std::distance(std::find(src_block_order.rbegin(), src_block_order.rend(), tmp_order[i]), src_block_order.rend() - 1); - if (pos != -1) { - new_src_block_strides[i] = src_block_strides[pos]; - src_block_order.erase(src_block_order.begin() + pos); - src_block_strides.erase(src_block_strides.begin() + pos); - mask[i] = 0; - } else { - new_src_block_strides[i] = new_src_block_strides[tmp_order.size() - 1] * dst_block_dims[tmp_order.size() - 1]; - mask[i] = 1; - mask[tmp_order.size() - 1] = 1; - } - } - if (!src_block_order.empty()) { - int pos = std::distance(tmp_order.begin(), std::find(tmp_order.begin(), tmp_order.end(), src_block_order[0])); - new_src_block_strides.insert(new_src_block_strides.begin() + pos, src_block_strides[0]); - new_dst_block_strides.insert(new_dst_block_strides.begin() + pos, new_dst_block_strides[pos] * src_block_dims[src_block_dims.size() - 1]); - new_dst_block_order.insert(new_dst_block_order.begin() + pos, new_dst_block_order[pos]); - new_dst_block_dims.insert(new_dst_block_dims.begin() + pos + 1, src_block_dims[src_block_dims.size() - 1]); - new_dst_block_dims[pos] = div_up(new_dst_block_dims[pos], new_dst_block_dims[pos + 1]); - src_block_order.erase(src_block_order.begin()); - src_block_strides.erase(src_block_strides.begin()); - mask.insert(mask.begin() + pos + 1, 1); - mask[pos] = 1; - } - - SizeVector sorted_src_strides; - SizeVector sorted_dst_strides; - SizeVector sorted_order; - SizeVector sorted_dst_dims; - - // support dynamic batch - int batch_ord = std::distance(order.begin(), std::find(order.begin(), order.end(), 0)); - int batch_count = 0; - int batch_pos = 0; - for (int i = 0; i < new_dst_block_order.size(); i++) { - if (new_dst_block_order[i] == batch_ord) { - batch_count++; - batch_pos = i; - } - } - if (batch_count == 1) { - sorted_src_strides.push_back(new_src_block_strides[batch_pos]); - sorted_dst_strides.push_back(new_dst_block_strides[batch_pos]); - sorted_order.push_back(new_dst_block_order[batch_pos]); - sorted_dst_dims.push_back(new_dst_block_dims[batch_pos]); - jpp.supported_dynamic_batch = true; - } - - int n2 = 0; - for (int i = 0; i < mask.size(); i++) { - if (mask[i] == 0) { - n2++; - if (batch_count == 1 && new_dst_block_order[i] == batch_ord) { - continue; - } - sorted_src_strides.push_back(new_src_block_strides[i]); - sorted_dst_strides.push_back(new_dst_block_strides[i]); - sorted_order.push_back(new_dst_block_order[i]); - sorted_dst_dims.push_back(new_dst_block_dims[i]); - } - } - for (int i = 0; i < mask.size(); i++) { - if (mask[i] == 1) { - sorted_src_strides.push_back(new_src_block_strides[i]); - sorted_dst_strides.push_back(new_dst_block_strides[i]); - sorted_order.push_back(new_dst_block_order[i]); - sorted_dst_dims.push_back(new_dst_block_dims[i]); - } - } - - int max_threads = dnnl_get_max_threads(); - const int n_max = 3; // max count dims for parallel - int n = 0; - int work_amount = sorted_dst_dims[0]; - for (int i = 1; i < sorted_dst_dims.size() && n < n_max; i++) { - n++; - if (work_amount >= 4 * max_threads) { // 4 * max_threads is a specially selected value for best performance - break; - } - work_amount *= sorted_dst_dims[i]; - } - - jpp.src_strides = sorted_src_strides; - jpp.dst_strides = sorted_dst_strides; - jpp.dst_block_dims = sorted_dst_dims; - jpp.n = std::min(n, n2); - jpp.ndims = sorted_order.size(); - jpp.data_size = MKLDNNExtensionUtils::sizeOfDataType(data_type); - - if (mayiuse(cpu::x64::avx512_common)) { - permute_kernel.reset(new jit_uni_permute_kernel_f32(jpp)); - } else if (mayiuse(cpu::x64::avx2)) { - permute_kernel.reset(new jit_uni_permute_kernel_f32(jpp)); - } else if (mayiuse(cpu::x64::sse41)) { - permute_kernel.reset(new jit_uni_permute_kernel_f32(jpp)); - } - if (permute_kernel) - permute_kernel->create_ker(); + permuteKernel = std::unique_ptr(new PermuteKernel(params)); } static void permute_to_0231(int MB, MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr) { @@ -861,70 +626,20 @@ const std::multimap void MKLDNNPermuteNode::execute(mkldnn::stream strm) { auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); auto &srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); + int MB = batchToProcess(); - if (prec == Precision::FP32) { + if (prec == Precision::FP32 && !getParentEdgeAt(0)->getMemory().GetDesc().isTailCFormat()) { for (const auto &impl : OptimizedCases) { - if (impl.first == order && impl.second.isValidParams(batchToProcess(), srcMemPtr, dstMemPtr)) { - impl.second.execute(batchToProcess(), srcMemPtr, dstMemPtr); + if (impl.first == order && impl.second.isValidParams(MB, srcMemPtr, dstMemPtr)) { + impl.second.execute(MB, srcMemPtr, dstMemPtr); return; } } } - if (permute_kernel) { - auto src_data = reinterpret_cast(srcMemPtr->GetPtr()); - auto dst_data = reinterpret_cast(dstMemPtr->GetPtr()); - - const auto &jpp = (*permute_kernel).jpp; - - SizeVector dst_dims = jpp.dst_block_dims; - SizeVector dst_strides = jpp.dst_strides; - SizeVector src_strides = jpp.src_strides; - - if (jpp.supported_dynamic_batch) { - dst_dims[0] = batchToProcess(); - } - - switch (jpp.n) { - case 1: - parallel_for(dst_dims[0], [&](int i0) { - auto arg = jit_args_permute(); - - size_t dst_off = i0 * dst_strides[0]; - size_t src_off = i0 * src_strides[0]; - arg.src = &src_data[src_off * jpp.data_size]; - arg.dst = &dst_data[dst_off * jpp.data_size]; - - (*permute_kernel)(&arg); - }); - break; - case 2: - parallel_for2d(dst_dims[0], dst_dims[1], [&](int i0, int i1) { - auto arg = jit_args_permute(); - - size_t dst_off = i0 * dst_strides[0] + i1 * dst_strides[1]; - size_t src_off = i0 * src_strides[0] + i1 * src_strides[1]; - arg.src = &src_data[src_off * jpp.data_size]; - arg.dst = &dst_data[dst_off * jpp.data_size]; - - (*permute_kernel)(&arg); - }); - break; - case 3: - parallel_for3d(dst_dims[0], dst_dims[1], dst_dims[2], [&](int i0, int i1, int i2) { - auto arg = jit_args_permute(); - - size_t dst_off = i0 * dst_strides[0] + i1 * dst_strides[1] + i2 * dst_strides[2]; - size_t src_off = i0 * src_strides[0] + i1 * src_strides[1] + i2 * src_strides[2]; - arg.src = &src_data[src_off * jpp.data_size]; - arg.dst = &dst_data[dst_off * jpp.data_size]; - - (*permute_kernel)(&arg); - }); - break; - } - return; - } + const uint8_t* srcData = reinterpret_cast(srcMemPtr->GetPtr()); + uint8_t* dstData = reinterpret_cast(dstMemPtr->GetPtr()); + permuteKernel->execute(srcData, dstData, MB); } bool MKLDNNPermuteNode::created() const { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.h index 2a591980b23..9c5f00024d1 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_permute_node.h @@ -11,38 +11,10 @@ #include #include #include +#include "common/permute_kernel.h" namespace MKLDNNPlugin { -struct jit_permute_conf_t { - uint32_t ndims; - InferenceEngine::SizeVector dst_block_dims; - InferenceEngine::SizeVector src_strides; - InferenceEngine::SizeVector dst_strides; - int n; - int data_size; - - bool supported_dynamic_batch = false; -}; - -struct jit_args_permute { - const void* src; - const void* dst; -}; - -struct jit_uni_permute_kernel { - void (*ker_)(const jit_args_permute *); - - void operator()(const jit_args_permute *args) { assert(ker_); ker_(args); } - - jit_permute_conf_t jpp; - - virtual void create_ker() = 0; - - explicit jit_uni_permute_kernel(jit_permute_conf_t jpp) : ker_(nullptr), jpp(jpp) {} - virtual ~jit_uni_permute_kernel() {} -}; - class MKLDNNPermuteNode : public MKLDNNNode { public: MKLDNNPermuteNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); @@ -75,7 +47,7 @@ private: }; static const std::multimap OptimizedCases; - std::shared_ptr permute_kernel; + std::unique_ptr permuteKernel; }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.cpp new file mode 100644 index 00000000000..4965920d708 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.cpp @@ -0,0 +1,242 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "mkldnn_space_to_depth_node.h" + +#include +#include +#include +#include "common/tensor_desc_creator.h" + +#include +#include + +#define THROW_ERROR IE_THROW() << "SpaceToDepth layer with name '" << getName() << "' " + +using namespace MKLDNNPlugin; +using namespace InferenceEngine; +using namespace mkldnn; +using namespace mkldnn::impl; +using namespace mkldnn::impl::cpu::x64; + +MKLDNNSpaceToDepthNode::MKLDNNSpaceToDepthNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) + : MKLDNNNode(layer, eng, cache) {} + +void MKLDNNSpaceToDepthNode::getSupportedDescriptors() { + auto* spaceToDepthLayer = dynamic_cast(getCnnLayer().get()); + if (spaceToDepthLayer == nullptr) + THROW_ERROR << "cannot convert from CNN layer"; + + if (spaceToDepthLayer->insData[0].lock() == nullptr) + THROW_ERROR << "has nullable input data"; + + SizeVector srcDims = spaceToDepthLayer->insData[0].lock()->getTensorDesc().getDims(); + if (srcDims.size() < 3) + THROW_ERROR << "has incorrect number of input dimensions"; + if (srcDims.size() > 5) + THROW_ERROR << "doesn't support dimensions with rank greater than 5"; + + if (spaceToDepthLayer->outData[0] == nullptr) + THROW_ERROR << "has nullable output data"; + + SizeVector dstDims = spaceToDepthLayer->outData[0]->getTensorDesc().getDims(); + if (srcDims.size() != dstDims.size()) + THROW_ERROR << "has incorrect number of input/output dimensions"; + + std::string modeString = spaceToDepthLayer->GetParamAsString("mode"); + if (modeString == "blocks_first") { + mode = Mode::BLOCKS_FIRST; + } else if (modeString == "depth_first") { + mode = Mode::DEPTH_FIRST; + } else { + THROW_ERROR << "doesn't support mode: " << modeString; + } + + blockSize = spaceToDepthLayer->GetParamAsUInt("block_size", 1); + if (blockSize == 0) + THROW_ERROR << "has incorrect block_size parameter is zero!"; + + size_t nSpatialDims = srcDims.size() - 2; + blockStep = static_cast(std::pow(blockSize, nSpatialDims)); + if (dstDims[1] % blockStep) + THROW_ERROR << "has block_size parameter which is incompatible with output tensor channels dimension size"; + + if (dstDims[1] / blockStep != srcDims[1]) + THROW_ERROR << "has incompatible input/output channels"; + + for (size_t i = 0; i < nSpatialDims; ++i) { + if (dstDims[i + 2] * blockSize != srcDims[i + 2]) + THROW_ERROR << "has incompatible spatial dims"; + } + + if (getParentEdges().size() != 1) + THROW_ERROR << "has incorrect number of input edge"; + if (getChildEdges().empty()) + THROW_ERROR << "has incorrect number of output edges"; +} + +void MKLDNNSpaceToDepthNode::initSupportedPrimitiveDescriptors() { + if (!supportedPrimitiveDescriptors.empty()) + return; + + InferenceEngine::Precision precision = getCnnLayer()->insData[0].lock()->getPrecision(); + auto srcDims = getParentEdgeAt(0)->getDims(); + const size_t nDims = srcDims.ndims(); + + impl_desc_type impl_type; + if (mayiuse(impl::cpu::x64::avx512_common)) { + impl_type = impl_desc_type::jit_avx512; + } else if (mayiuse(cpu::x64::avx2)) { + impl_type = impl_desc_type::jit_avx2; + } else if (mayiuse(cpu::x64::sse41)) { + impl_type = impl_desc_type::jit_sse42; + } else { + impl_type = impl_desc_type::ref; + } + + InferenceEngine::LayerConfig config; + config.dynBatchSupport = true; + config.inConfs.resize(1); + config.outConfs.resize(1); + config.inConfs[0].inPlace = -1; + config.inConfs[0].constant = false; + config.outConfs[0].inPlace = -1; + config.outConfs[0].constant = false; + + std::vector supportedTypes; + if (nDims > 2) { + auto canUseBlocked = [=](const size_t block) { + return mode == Mode::DEPTH_FIRST ? block % blockStep == 0 : true; + }; + + supportedTypes.push_back(TensorDescCreatorTypes::nspc); + if (canUseBlocked(8lu)) + supportedTypes.push_back(TensorDescCreatorTypes::nCsp8c); + if (canUseBlocked(16lu)) + supportedTypes.push_back(TensorDescCreatorTypes::nCsp16c); + } + supportedTypes.push_back(TensorDescCreatorTypes::ncsp); + auto creators = TensorDescCreator::getCommonCreators(); + auto range = TensorDescCreator::makeFilteredRange(creators, nDims, supportedTypes); + + for (auto itr = range.first; itr != range.second; ++itr) { + config.inConfs[0].desc = itr->second->createDesc(precision, getParentEdgeAt(0)->getDims().ToSizeVector()); + config.outConfs[0].desc = itr->second->createDesc(precision, getChildEdgeAt(0)->getDims().ToSizeVector()); + supportedPrimitiveDescriptors.emplace_back(config, impl_type, MKLDNNMemoryDesc(config.outConfs.front().desc).getFormat()); + } +} + +void MKLDNNSpaceToDepthNode::createPrimitive() { + auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); + auto &srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); + if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr()) + THROW_ERROR << "has not allocated destination memory"; + if (!srcMemPtr || !srcMemPtr->GetPrimitivePtr()) + THROW_ERROR << "has not allocated input memory"; + if (getSelectedPrimitiveDescriptor() == nullptr) + THROW_ERROR << "has unidentified preferable primitive descriptor"; + + SizeVector srcDims = getParentEdgeAt(0)->getBlob()->getTensorDesc().getDims(); + SizeVector dstDims = getChildEdgeAt(0)->getBlob()->getTensorDesc().getDims(); + + size_t nDims = srcDims.size(); + const size_t nSpatialDims = nDims - 2; + const bool isBlocked = getParentEdgeAt(0)->getMemory().GetDesc().isBlockedCFormat(); + const size_t reshapedRank = nDims + nSpatialDims + static_cast(isBlocked) + static_cast(isBlocked && mode == Mode::DEPTH_FIRST); + const size_t lastIdx = reshapedRank - 1; + size_t firstSpatialOrder = 2; + + PermuteParams params; + params.data_size = getSelectedPrimitiveDescriptor()->getConfig().inConfs[0].desc.getPrecision().size(); + params.order.resize(reshapedRank, 0); + params.src_block_order.resize(reshapedRank); + params.dst_block_order.resize(reshapedRank); + params.dst_block_dims.resize(reshapedRank); + params.src_block_dims.resize(reshapedRank); + params.src_block_dims[0] = srcDims[0]; + + // reshaping of src dimensions and creating the permutation order for each layout: + // new shape: [N, C, D1 / block_size, block_size, D2 / block_size, block_size, ... , DK / block_size, block_size] + // order : mode = blocks_first : [0, 3, 5, ..., K + (K + 1), 1, 2, 4, ..., K + K] + // mode = depth_first : [0, 1, 3, 5, ..., K + (K + 1), 2, 4, ..., K + K] + // where `k` is number of spatial dimensions + + auto reshapeAndSetPermOrder = [&](const size_t idx1, const size_t idx2, const size_t shift, const SizeVector& dims) { + for (size_t i = 0; i < nSpatialDims; i++) { + params.order[i + idx1] = i * 2 + shift; + params.order[i + idx2] = i * 2 + shift + 1; + + params.src_block_dims[params.order[i + idx1]] = dims[i + shift]; + params.src_block_dims[params.order[i + idx2]] = blockSize; + } + }; + + if (isBlocked) { + SizeVector srcBlockedDims = getParentEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); + SizeVector dstBlockedDims = getChildEdgeAt(0)->getDesc().getBlockingDesc().getBlockDims(); + + size_t orderShiftForBlocks, orderShiftForDims; + if (mode == Mode::BLOCKS_FIRST) { + orderShiftForBlocks = nSpatialDims + 2; + orderShiftForDims = 1; + + params.order[nSpatialDims + 1] = 1; + params.order[lastIdx] = lastIdx; + + params.src_block_dims[params.order[nSpatialDims + 1]] = srcBlockedDims[1]; + params.src_block_dims[params.order[lastIdx]] = srcBlockedDims.back(); + } else { + orderShiftForBlocks = 3; + orderShiftForDims = nSpatialDims + 4; + + size_t extraBlockSize = srcBlockedDims.back() / blockStep; + params.src_block_dims[1] = srcBlockedDims[1]; + params.src_block_dims[lastIdx] = extraBlockSize; + params.src_block_dims[lastIdx - 1] = blockStep; + + params.order[1] = 1; + params.order[2] = lastIdx - 1; + params.order[lastIdx - nSpatialDims] = lastIdx; + } + + reshapeAndSetPermOrder(orderShiftForBlocks, orderShiftForDims, firstSpatialOrder, dstBlockedDims); + } else if (getParentEdgeAt(0)->getMemory().GetDesc().isTailCFormat()) { + srcDims.push_back(srcDims[1]); + dstDims.push_back(dstDims[1]); + srcDims.erase(srcDims.begin() + 1); + dstDims.erase(dstDims.begin() + 1); + firstSpatialOrder = 1; + + size_t shift = static_cast(mode == DEPTH_FIRST) + nSpatialDims + 1; + params.order[mode == Mode::DEPTH_FIRST ? nSpatialDims + 1 : lastIdx] = lastIdx; + params.src_block_dims[lastIdx] = srcDims.back(); + + reshapeAndSetPermOrder(firstSpatialOrder, shift, firstSpatialOrder, dstDims); + } else { + size_t shift = static_cast(mode == DEPTH_FIRST) + 1; + params.order[mode == Mode::DEPTH_FIRST ? 1 : nSpatialDims + 1] = 1; + params.src_block_dims[1] = srcDims[1]; + + reshapeAndSetPermOrder(nSpatialDims + firstSpatialOrder, shift, firstSpatialOrder, dstDims); + } + + std::iota(params.src_block_order.begin(), params.src_block_order.end(), 0); + std::iota(params.dst_block_order.begin(), params.dst_block_order.end(), 0); + for (size_t i = 0; i < reshapedRank; i++) + params.dst_block_dims[i] = params.src_block_dims[params.order[i]]; + + permuteKernel = std::unique_ptr(new PermuteKernel(params)); +} + +void MKLDNNSpaceToDepthNode::execute(mkldnn::stream strm) { + const uint8_t* srcData = reinterpret_cast(this->getParentEdgeAt(0)->getMemoryPtr()->GetPtr()); + uint8_t* dstData = reinterpret_cast(this->getChildEdgeAt(0)->getMemoryPtr()->GetPtr()); + + permuteKernel->execute(srcData, dstData, batchToProcess()); +} + +bool MKLDNNSpaceToDepthNode::created() const { + return getType() == SpaceToDepth; +} +REG_MKLDNN_PRIM_FOR(MKLDNNSpaceToDepthNode, SpaceToDepth); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.h new file mode 100644 index 00000000000..0d16bd171f6 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_space_to_depth_node.h @@ -0,0 +1,38 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include "common/permute_kernel.h" + +namespace MKLDNNPlugin { + +class MKLDNNSpaceToDepthNode : public MKLDNNNode { +public: + MKLDNNSpaceToDepthNode(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); + ~MKLDNNSpaceToDepthNode() override = default; + + void getSupportedDescriptors() override; + void initSupportedPrimitiveDescriptors() override; + void createPrimitive() override; + void execute(mkldnn::stream strm) override; + bool created() const override; + +private: + enum Mode { + BLOCKS_FIRST = 0, + DEPTH_FIRST = 1 + }; + + Mode mode; + size_t blockSize; + size_t blockStep; + + std::unique_ptr permuteKernel; +}; + +} // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp index 2b1c686c6b6..f357fe430d3 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_strided_slice_node.cpp @@ -10,7 +10,6 @@ #include #include "ie_parallel.hpp" #include "caseless.hpp" -#include "common/dnnl_thread.hpp" #include "common/cpu_memcpy.h" #include "common/tensor_desc_creator.h" #include "utils/general_utils.h" @@ -471,7 +470,7 @@ void MKLDNNStridedSliceNode::dimsGluing(const size_t realNDims, const SizeVector for (size_t idx = secondDim.first + 1; idx < secondDim.second; idx++) begin[1] /= newDstDims[idx]; - const size_t maxThreads = dnnl_get_max_threads(); + const size_t maxThreads = parallel_get_max_threads(); if (params.dstDims[0] < maxThreads) { params.dstDims[1] /= realDstDim; params.srcDims[1] /= realSrcDim; @@ -486,7 +485,7 @@ void MKLDNNStridedSliceNode::dimsGluing(const size_t realNDims, const SizeVector void MKLDNNStridedSliceNode::indicesCalculation() { // indices calculation before execution for the best performance - params.nThreads = dnnl_get_max_threads(); + params.nThreads = parallel_get_max_threads(); params.srcIndices.resize(params.workAmount, 0); params.dstIndices.resize(params.workAmount, 0); @@ -530,7 +529,7 @@ void MKLDNNStridedSliceNode::execute(mkldnn::stream strm) { if (!params.parametersAreConstant) { auto srcDims = getParentEdgeAt(DATA_ID)->getDims(); auto dstDims = getChildEdgeAt(0)->getDims(); - const size_t nDims = std::max(srcDims.size(), dstDims.size()); + const size_t nDims = std::max(srcDims.ndims(), dstDims.ndims()); const size_t ellipsisMaskCounter = std::accumulate(ellipsisMask.begin(), ellipsisMask.end(), 0); auto fillingInParameters = [&](std::vector ¶meter, const size_t type, const size_t size, const int value) { diff --git a/inference-engine/src/mkldnn_plugin/nodes/space_to_depth.cpp b/inference-engine/src/mkldnn_plugin/nodes/space_to_depth.cpp deleted file mode 100644 index 59c18b4495b..00000000000 --- a/inference-engine/src/mkldnn_plugin/nodes/space_to_depth.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "base.hpp" - -#include -#include -#include -#include -#include -#include "ie_parallel.hpp" - -namespace InferenceEngine { -namespace Extensions { -namespace Cpu { - -class SpaceToDepthImpl: public ExtLayerBase { - enum class SpaceToDepthMode { - BLOCKS_FIRST, - DEPTH_FIRST - }; - -public: - explicit SpaceToDepthImpl(const CNNLayer* layer) { - try { - if (layer->insData.empty() || layer->outData.empty()) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << "' has incorrect number of input/output edges"; - - SizeVector inDims = layer->insData[0].lock()->getTensorDesc().getDims(); - if (inDims.size() < 3) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << "' has incorrect number of input dimensions"; - - if (inDims.size() > 5) - IE_THROW() << "DepthToSpace layer with name '" << layer->name << "' doesn't support dimensions with rank greater than 5"; - - outDims = layer->outData[0]->getTensorDesc().getDims(); - if (inDims.size() != outDims.size()) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << "' has incorrect number of input/output dimensions"; - - std::string modeString = layer->GetParamAsString("mode"); - if (modeString == "blocks_first") { - mode = SpaceToDepthMode::BLOCKS_FIRST; - } else if (modeString == "depth_first") { - mode = SpaceToDepthMode::DEPTH_FIRST; - } else { - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << "' doesn't support mode: " << modeString; - } - - blockSize = layer->GetParamAsUInt("block_size", 1); - if (blockSize == 0) - IE_THROW() << layer->name << " Incorrect blockSize parameter is zero!"; - - size_t numSpatialDims = inDims.size() - 2; - blockStep = static_cast(std::pow(blockSize, numSpatialDims)); - if (outDims[1] % blockStep) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << - "' has block_size parameter which is incompatible with input tensor channels dimension size"; - - if (inDims[1] != outDims[1] / blockStep) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << " has incompatible input/output channels"; - - for (int i = 0; i < numSpatialDims; i++) { - if (inDims[i + 2] != outDims[i + 2] * blockSize) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << " has incompatible spatial dims"; - } - - auto computePrc = layer->insData[0].lock()->getTensorDesc().getPrecision(); - const std::set supported_precision_sizes = {1, 2, 4, 8}; - if (supported_precision_sizes.find(computePrc.size()) == supported_precision_sizes.end()) - IE_THROW() << "SpaceToDepth layer with name '" << layer->name << " doesn't support precision: " << computePrc.name(); - - - if (inDims.size() == 4 || inDims.size() == 5) { - LayerConfig config; - DataConfig inConfig; - inConfig.desc = TensorDesc(computePrc, inDims, inDims.size() == 4 ? NHWC : NDHWC); - config.inConfs.push_back(inConfig); - - DataConfig outConfig; - outConfig.desc = TensorDesc(computePrc, outDims, outDims.size() == 4 ? NHWC : NDHWC); - config.outConfs.push_back(outConfig); - - config.dynBatchSupport = false; - confs.push_back(config); - } - - LayerConfig config; - DataConfig inConfig; - inConfig.desc = TensorDesc(computePrc, inDims, InferenceEngine::TensorDesc::getLayoutByDims(inDims)); - config.inConfs.push_back(inConfig); - - DataConfig outConfig; - outConfig.desc = TensorDesc(computePrc, outDims, InferenceEngine::TensorDesc::getLayoutByDims(outDims)); - config.outConfs.push_back(outConfig); - - config.dynBatchSupport = false; - confs.push_back(config); - } catch (InferenceEngine::Exception &ex) { - errorMsg = ex.what(); - } - } - - StatusCode execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept override { - switch (inputs[0]->getTensorDesc().getPrecision().size()) { - case 1: spaceToDepthKernel::value_type>(inputs, outputs); break; - case 2: spaceToDepthKernel::value_type>(inputs, outputs); break; - case 4: spaceToDepthKernel::value_type>(inputs, outputs); break; - case 8: spaceToDepthKernel::value_type>(inputs, outputs); break; - default: { - if (resp) { - std::string errorMsg = "SpaceToDepth layer with name does not support precision '" - + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; - errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); - - return GENERAL_ERROR; - } - } - } - - return OK; - } - -private: - std::vector getShape5D(const SizeVector& shape) { - std::vector shape5D(5, 1); - for (int i = 0; i < shape.size(); i++) { - shape5D[i] = shape[i]; - } - return shape5D; - } - - std::vector getBlock3D(const SizeVector& shape) { - std::vector block3D(3, 1); - for (int i = 0; i < shape.size() - 2; i++) { - block3D[i] = blockSize; - } - return block3D; - } - - template - void spaceToDepthKernel(std::vector& inputs, std::vector& outputs) { - const T *src_data = inputs[0]->cbuffer().as() + inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - T* dst_data = outputs[0]->buffer().as() + outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - - auto shape5D = getShape5D(outDims); - auto block3D = getBlock3D(outDims); - - size_t spatialStep = shape5D[2] * shape5D[3] * shape5D[4]; - size_t batchStep = shape5D[1] * spatialStep; - - size_t dstChannels = shape5D[1]; - size_t srcChannels = dstChannels / blockStep; - - size_t blockShift = mode == SpaceToDepthMode::BLOCKS_FIRST ? (srcChannels) : 1; - size_t channelShift = mode == SpaceToDepthMode::BLOCKS_FIRST ? 1 : blockStep; - - if (inputs[0]->getTensorDesc().getLayout() == NHWC || inputs[0]->getTensorDesc().getLayout() == NDHWC) { - parallel_for2d(shape5D[0], shape5D[2], [&](size_t i0, size_t i2) { - size_t srcIdx1 = i0 * batchStep; - size_t dstIdx1 = i0 * batchStep; - for (size_t b2 = 0; b2 < block3D[0]; b2++) { - size_t srcIdx2 = srcIdx1 + (i2 * block3D[0] + b2) * shape5D[3] * block3D[1] * shape5D[4] * block3D[2] * srcChannels; - size_t dstIdx2 = dstIdx1 + i2 * shape5D[3] * shape5D[4] * dstChannels + b2 * block3D[1] * block3D[2] * blockShift; - for (size_t i3 = 0; i3 < shape5D[3]; i3++) { - for (size_t b3 = 0; b3 < block3D[1]; b3++) { - size_t dstIdx3 = dstIdx2 + i3 * shape5D[4] * dstChannels + b3 * block3D[2] * blockShift; - size_t srcIdx3 = srcIdx2 + (i3 * block3D[1] + b3) * shape5D[4] * block3D[2] * srcChannels; - for (size_t i4 = 0; i4 < shape5D[4]; i4++) { - for (size_t b4 = 0; b4 < block3D[2]; b4++) { - size_t srcIdx4 = srcIdx3 + (i4 * block3D[2] + b4) * srcChannels; - size_t dstIdx4 = dstIdx3 + i4 * dstChannels + b4 * blockShift; - for (size_t i1 = 0; i1 < srcChannels; i1++) { - size_t srcIdx5 = srcIdx4 + i1; - size_t dstIdx5 = dstIdx4 + i1 * channelShift; - dst_data[dstIdx5] = src_data[srcIdx5]; - } - } - } - } - } - } - }); - } else { - parallel_for2d(shape5D[0], srcChannels, [&](size_t i0, size_t i1) { - size_t srcIdx1 = i0 * batchStep + i1 * blockStep * spatialStep; - size_t dstIdx1 = i0 * batchStep + i1 * channelShift * spatialStep; - for (size_t i2 = 0; i2 < shape5D[2]; i2++) { - for (size_t b2 = 0; b2 < block3D[0]; b2++) { - size_t srcIdx2 = srcIdx1 + (i2 * block3D[0] + b2) * shape5D[3] * block3D[1] * shape5D[4] * block3D[2]; - size_t dstIdx2 = dstIdx1 + i2 * shape5D[3] * shape5D[4] + b2 * block3D[1] * block3D[2] * blockShift * spatialStep; - for (size_t i3 = 0; i3 < shape5D[3]; i3++) { - for (size_t b3 = 0; b3 < block3D[1]; b3++) { - size_t srcIdx3 = srcIdx2 + (i3 * block3D[1] + b3) * shape5D[4] * block3D[2]; - size_t dstIdx3 = dstIdx2 + i3 * shape5D[4] + b3 * block3D[2] * blockShift * spatialStep; - for (size_t i4 = 0; i4 < shape5D[4]; i4++) { - for (size_t b4 = 0; b4 < block3D[2]; b4++) { - size_t srcIdx4 = srcIdx3 + i4 * block3D[2] + b4; - size_t dstIdx4 = dstIdx3 + i4 + b4 * blockShift * spatialStep; - dst_data[dstIdx4] = src_data[srcIdx4]; - } - } - } - } - } - } - }); - } - } - - SpaceToDepthMode mode; - SizeVector outDims; - size_t blockSize; - size_t blockStep; -}; - -REG_FACTORY_FOR(SpaceToDepthImpl, SpaceToDepth); - -} // namespace Cpu -} // namespace Extensions -} // namespace InferenceEngine diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/depth_to_space.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/depth_to_space.cpp index d63bc5c1f5e..d8785579ed6 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/depth_to_space.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/depth_to_space.cpp @@ -20,17 +20,19 @@ const std::vector inputPrecisions = { const std::vector modes = { DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, - DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}; + DepthToSpace::DepthToSpaceMode::DEPTH_FIRST +}; const std::vector> inputShapesBS2 = { {1, 4, 1, 1}, {1, 4, 2, 2}, {1, 4, 3, 3}, {2, 32, 3, 3}, {2, 16, 5, 4}, - {1, 8, 1, 1, 1}, {1, 8, 2, 2, 2}, {1, 8, 3, 3, 3}, {2, 32, 3, 3, 3}, {2, 16, 5, 4, 6}}; + {1, 8, 1, 1, 1}, {1, 8, 2, 2, 2}, {1, 8, 3, 3, 3}, {2, 32, 3, 3, 3}, {2, 16, 5, 4, 6} +}; const auto DepthToSpaceBS2 = ::testing::Combine( ::testing::ValuesIn(inputShapesBS2), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(modes), - ::testing::Values(2), + ::testing::Values(1, 2), ::testing::Values(CommonTestUtils::DEVICE_CPU) ); @@ -38,16 +40,17 @@ INSTANTIATE_TEST_CASE_P(smoke_DepthToSpaceBS2, DepthToSpaceLayerTest, DepthToSpa const std::vector> inputShapesBS3 = { {1, 9, 1, 1}, {1, 9, 2, 2}, {1, 9, 3, 3}, {2, 36, 3, 3}, {2, 27, 5, 4}, - {1, 27, 1, 1, 1}, {1, 27, 2, 2, 2}, {1, 27, 3, 3, 3}, {2, 108, 3, 3, 3}, {2, 54, 5, 4, 6}}; + {1, 27, 1, 1, 1}, {1, 27, 2, 2, 2}, {1, 27, 3, 3, 3}, {2, 108, 3, 3, 3}, {2, 54, 5, 4, 6} +}; const auto DepthToSpaceBS3 = ::testing::Combine( ::testing::ValuesIn(inputShapesBS3), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(modes), - ::testing::Values(3), + ::testing::Values(1, 3), ::testing::Values(CommonTestUtils::DEVICE_CPU) ); INSTANTIATE_TEST_CASE_P(smoke_DepthToSpaceBS3, DepthToSpaceLayerTest, DepthToSpaceBS3, DepthToSpaceLayerTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/space_to_depth.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/space_to_depth.cpp index 54d48ebf992..ff7e33e495e 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/space_to_depth.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/space_to_depth.cpp @@ -20,17 +20,19 @@ const std::vector inputPrecisions = { const std::vector modes = { SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, - SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST}; + SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST +}; const std::vector> inputShapesBS2 = { {1, 1, 2, 2}, {1, 1, 4, 4}, {1, 1, 6, 6}, {2, 8, 6, 6}, {2, 4, 10, 8}, - {1, 1, 2, 2, 2}, {1, 1, 4, 4, 4}, {1, 1, 6, 6, 6}, {2, 8, 6, 6, 6}, {2, 4, 10, 8, 12}}; + {1, 1, 2, 2, 2}, {1, 1, 4, 4, 4}, {1, 1, 6, 6, 6}, {2, 8, 6, 6, 6}, {2, 4, 10, 8, 12} +}; const auto SpaceToDepthBS2 = ::testing::Combine( ::testing::ValuesIn(inputShapesBS2), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(modes), - ::testing::Values(2), + ::testing::Values(1, 2), ::testing::Values(CommonTestUtils::DEVICE_CPU) ); @@ -38,16 +40,17 @@ INSTANTIATE_TEST_CASE_P(smoke_SpaceToDepthBS2, SpaceToDepthLayerTest, SpaceToDep const std::vector> inputShapesBS3 = { {1, 1, 3, 3}, {1, 1, 6, 6}, {1, 1, 9, 9}, {2, 4, 9, 9}, {2, 3, 15, 12}, - {1, 1, 3, 3, 3}, {1, 1, 6, 6, 6}, {1, 1, 9, 9, 9}, {2, 4, 9, 9, 9}, {2, 3, 15, 12, 18}}; + {1, 1, 3, 3, 3}, {1, 1, 6, 6, 6}, {1, 1, 9, 9, 9}, {2, 4, 9, 9, 9}, {2, 3, 15, 12, 18} +}; const auto SpaceToDepthBS3 = ::testing::Combine( ::testing::ValuesIn(inputShapesBS3), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(modes), - ::testing::Values(3), + ::testing::Values(1, 3), ::testing::Values(CommonTestUtils::DEVICE_CPU) ); INSTANTIATE_TEST_CASE_P(smoke_SpaceToDepthBS3, SpaceToDepthLayerTest, SpaceToDepthBS3, SpaceToDepthLayerTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp new file mode 100644 index 00000000000..e6bb59179f5 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp @@ -0,0 +1,195 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::opset3; + +namespace CPULayerTestsDefinitions { + +typedef std::tuple< + LayerTestsDefinitions::depthToSpaceParamsTuple, + CPUSpecificParams +> DepthToSpaceLayerCPUTestParamSet; + +class DepthToSpaceLayerCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + LayerTestsDefinitions::depthToSpaceParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::DepthToSpaceLayerTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + + result << CPUTestsBase::getTestCaseName(cpuParams); + + return result.str(); + } +protected: + void SetUp() override { + LayerTestsDefinitions::depthToSpaceParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = this->GetParam(); + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + + std::vector inputShape; + DepthToSpace::DepthToSpaceMode mode; + std::size_t blockSize; + InferenceEngine::Precision netPrecision; + std::tie(inputShape, netPrecision, mode, blockSize, targetDevice) = basicParamsSet; + + inPrc = outPrc = netPrecision; + selectedType = getPrimitiveType() + "_" + inPrc.name(); + auto inPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(inPrc, {inputShape}); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)); + auto d2s = ngraph::builder::makeDepthToSpace(paramOuts[0], mode, blockSize); + d2s->get_rt_info() = getCPUInfo(); + ngraph::ResultVector results{std::make_shared(d2s)}; + function = std::make_shared(results, params, "DepthToSpace"); + } +}; + +TEST_P(DepthToSpaceLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "DepthToSpace"); +} + +namespace { + +const auto cpuParams_nChw16c = CPUSpecificParams {{nChw16c}, {nChw16c}, {"jit_avx512"}, {"jit_avx512"}}; +const auto cpuParams_nCdhw16c = CPUSpecificParams {{nCdhw16c}, {nCdhw16c}, {"jit_avx512"}, {"jit_avx512"}}; + +const auto cpuParams_nChw8c_avx2 = CPUSpecificParams {{nChw8c}, {nChw8c}, {"jit_avx2"}, {"jit_avx2"}}; +const auto cpuParams_nCdhw8c_avx2 = CPUSpecificParams {{nCdhw8c}, {nCdhw8c}, {"jit_avx2"}, {"jit_avx2"}}; + +const auto cpuParams_nChw8c_sse42 = CPUSpecificParams {{nChw8c}, {nChw8c}, {"jit_sse42"}, {"jit_sse42"}}; +const auto cpuParams_nCdhw8c_sse42 = CPUSpecificParams {{nCdhw8c}, {nCdhw8c}, {"jit_sse42"}, {"jit_sse42"}}; + +const auto cpuParams_nhwc_avx2 = CPUSpecificParams {{nhwc}, {nhwc}, {"jit_avx2"}, {"jit_avx2"}}; +const auto cpuParams_ndhwc_avx2 = CPUSpecificParams {{ndhwc}, {ndhwc}, {"jit_avx2"}, {"jit_avx2"}}; + +const auto cpuParams_nhwc_sse42 = CPUSpecificParams {{nhwc}, {nhwc}, {"jit_sse42"}, {"jit_sse42"}}; +const auto cpuParams_ndhwc_sse42 = CPUSpecificParams {{ndhwc}, {ndhwc}, {"jit_sse42"}, {"jit_sse42"}}; + +const auto cpuParams_nhwc_ref = CPUSpecificParams {{nhwc}, {nhwc}, {"ref_any"}, {"ref_any"}}; +const auto cpuParams_ndhwc_ref = CPUSpecificParams {{ndhwc}, {ndhwc}, {"ref_any"}, {"ref_any"}}; + + +const std::vector inputPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::BF16, + InferenceEngine::Precision::I8 +}; + +const std::vector depthToSpaceModes = { + DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, + DepthToSpace::DepthToSpaceMode::DEPTH_FIRST +}; + +const std::vector> inputShapesBS2_4D = { + {1, 64, 1, 1}, {1, 64, 1, 3}, {1, 128, 3, 3}, {2, 128, 1, 1}, {2, 256, 2, 3} +}; + +const std::vector> inputShapesBS3_4D = { + {1, 27, 1, 1}, {1, 27, 2, 3}, {1, 18, 2, 3}, {3, 18, 1, 1}, {2, 18, 3, 1} +}; + +const std::vector CPUParamsBS2_4D = { + cpuParams_nChw16c, + cpuParams_nChw8c_avx2, + cpuParams_nChw8c_sse42, + cpuParams_nhwc_avx2, + cpuParams_nhwc_sse42, + cpuParams_nhwc_ref, +}; + +const auto depthToSpaceBS2_4DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS2_4D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(depthToSpaceModes), + testing::Values(1, 2), + testing::Values(CommonTestUtils::DEVICE_CPU)), + testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS2_4D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUDepthToSpaceBS2_4D, DepthToSpaceLayerCPUTest, depthToSpaceBS2_4DParams, DepthToSpaceLayerCPUTest::getTestCaseName); + +const std::vector CPUParamsBS3_4D = { + cpuParams_nhwc_avx2, + cpuParams_nhwc_sse42, + cpuParams_nhwc_ref, +}; + +const auto depthToSpaceBS3_4DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS3_4D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(depthToSpaceModes), + testing::Values(1, 3), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS3_4D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUDepthToSpaceBS3_4D, DepthToSpaceLayerCPUTest, depthToSpaceBS3_4DParams, DepthToSpaceLayerCPUTest::getTestCaseName); + +const std::vector> inputShapesBS2_5D = { + {1, 128, 1, 1, 1}, {1, 128, 2, 1, 2}, {1, 256, 2, 1, 3}, {2, 256, 3, 1, 1}, {2, 512, 1, 2, 1} +}; + +const std::vector> inputShapesBS3_5D = { + {1, 54, 1, 1, 1}, {1, 54, 2, 1, 2}, {3, 54, 1, 1, 1}, {2, 54, 3, 1, 2}, {1, 54, 3, 2, 2} +}; + +const std::vector CPUParamsBS2_5D = { + cpuParams_nCdhw16c, + cpuParams_nCdhw8c_avx2, + cpuParams_nCdhw8c_sse42, + cpuParams_ndhwc_avx2, + cpuParams_ndhwc_sse42, + cpuParams_ndhwc_ref, +}; + +const auto depthToSpaceBS2_5DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS2_5D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(depthToSpaceModes), + testing::Values(1, 2), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS2_5D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUDepthToSpaceBS2_5D, DepthToSpaceLayerCPUTest, depthToSpaceBS2_5DParams, DepthToSpaceLayerCPUTest::getTestCaseName); + +const std::vector CPUParamsBS3_5D = { + cpuParams_ndhwc_avx2, + cpuParams_ndhwc_sse42, + cpuParams_ndhwc_ref, +}; + +const auto depthToSpaceBS3_5DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS3_5D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(depthToSpaceModes), + testing::Values(1, 3), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS3_5D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUDepthToSpaceBS3_5D, DepthToSpaceLayerCPUTest, depthToSpaceBS3_5DParams, DepthToSpaceLayerCPUTest::getTestCaseName); + +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/permute.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/permute.cpp index 71c0a9419a5..e95cb6ffa5f 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/permute.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/permute.cpp @@ -82,11 +82,29 @@ TEST_P(PermuteLayerCPUTest, CompareWithRefs) { namespace { std::map additional_config; +const auto cpuParams_nChw16c = CPUSpecificParams {{nChw16c}, {}, {}, {}}; +const auto cpuParams_nCdhw16c = CPUSpecificParams {{nCdhw16c}, {}, {}, {}}; + +const auto cpuParams_nChw8c = CPUSpecificParams {{nChw8c}, {}, {}, {}}; +const auto cpuParams_nCdhw8c = CPUSpecificParams {{nCdhw8c}, {}, {}, {}}; + +const auto cpuParams_nhwc = CPUSpecificParams {{nhwc}, {}, {}, {}}; +const auto cpuParams_ndhwc = CPUSpecificParams {{ndhwc}, {}, {}, {}}; + +const auto cpuParams_nchw = CPUSpecificParams {{nchw}, {}, {}, {}}; +const auto cpuParams_ncdhw = CPUSpecificParams {{ncdhw}, {}, {}, {}}; + const std::vector netPrecisions = { + Precision::I8, Precision::BF16, Precision::FP32 }; +const std::vector netPrecisionsPerChannels = { + Precision::I8, + Precision::FP32 +}; + const std::vector> inputShapes4D = { {2, 32, 10, 20} }; @@ -99,9 +117,17 @@ const std::vector> inputOrder4D = { std::vector{}, }; -std::vector cpuParams_4D = { - CPUSpecificParams({nChw16c}, {}, {}, {}), - CPUSpecificParams({nchw}, {}, {}, {}), +const std::vector> inputOrderPerChannels4D = { + std::vector{0, 1, 2, 3}, + std::vector{0, 2, 1, 3}, + std::vector{1, 0, 2, 3}, + std::vector{}, +}; + +const std::vector CPUParams4D = { + cpuParams_nChw16c, + cpuParams_nChw8c, + cpuParams_nchw, }; const auto params4D = ::testing::Combine( @@ -110,15 +136,37 @@ const auto params4D = ::testing::Combine( ::testing::ValuesIn(inputShapes4D), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(additional_config), - ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D))); + ::testing::ValuesIn(CPUParams4D)); INSTANTIATE_TEST_CASE_P(smoke_Permute4D_CPU, PermuteLayerCPUTest, params4D, PermuteLayerCPUTest::getTestCaseName); +const auto paramsPerChannels4D = ::testing::Combine( + ::testing::ValuesIn(inputOrderPerChannels4D), + ::testing::ValuesIn(netPrecisionsPerChannels), + ::testing::ValuesIn(inputShapes4D), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config), + ::testing::Values(cpuParams_nhwc)); + +INSTANTIATE_TEST_CASE_P(smoke_PermutePerChannels4D_CPU, PermuteLayerCPUTest, paramsPerChannels4D, PermuteLayerCPUTest::getTestCaseName); + const std::vector> inputShapes5D = { {2, 32, 5, 10, 20} }; const std::vector> inputOrder5D = { + std::vector{0, 1, 2, 3, 4}, + std::vector{0, 4, 2, 3, 1}, + std::vector{0, 4, 2, 1, 3}, + std::vector{0, 2, 3, 4, 1}, + std::vector{0, 2, 4, 3, 1}, + std::vector{0, 3, 2, 4, 1}, + std::vector{0, 3, 1, 4, 2}, + std::vector{1, 0, 2, 3, 4}, + std::vector{}, +}; + +const std::vector> inputOrderPerChannels5D = { std::vector{0, 1, 2, 3, 4}, std::vector{0, 4, 2, 3, 1}, std::vector{0, 4, 2, 1, 3}, @@ -129,9 +177,10 @@ const std::vector> inputOrder5D = { std::vector{}, }; -std::vector cpuParams_5D = { - CPUSpecificParams({nCdhw16c}, {}, {}, {}), - CPUSpecificParams({ncdhw}, {}, {}, {}), +const std::vector CPUParams5D = { + cpuParams_nCdhw16c, + cpuParams_nCdhw8c, + cpuParams_ncdhw, }; const auto params5D = ::testing::Combine( @@ -140,9 +189,19 @@ const auto params5D = ::testing::Combine( ::testing::ValuesIn(inputShapes5D), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(additional_config), - ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D))); + ::testing::ValuesIn(CPUParams5D)); INSTANTIATE_TEST_CASE_P(smoke_Permute5D_CPU, PermuteLayerCPUTest, params5D, PermuteLayerCPUTest::getTestCaseName); +const auto paramsPerChannels5D = ::testing::Combine( + ::testing::ValuesIn(inputOrderPerChannels5D), + ::testing::ValuesIn(netPrecisionsPerChannels), + ::testing::ValuesIn(inputShapes5D), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config), + ::testing::Values(cpuParams_ndhwc)); + +INSTANTIATE_TEST_CASE_P(smoke_PermutePerChannels5D_CPU, PermuteLayerCPUTest, paramsPerChannels5D, PermuteLayerCPUTest::getTestCaseName); + } // namespace -} // namespace CPULayerTestsDefinitions \ No newline at end of file +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_depth.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_depth.cpp new file mode 100644 index 00000000000..60c7a431759 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/space_to_depth.cpp @@ -0,0 +1,195 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::opset3; + +namespace CPULayerTestsDefinitions { + +typedef std::tuple< + LayerTestsDefinitions::spaceToDepthParamsTuple, + CPUSpecificParams +> SpaceToDepthLayerCPUTestParamSet; + +class SpaceToDepthLayerCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + LayerTestsDefinitions::spaceToDepthParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::SpaceToDepthLayerTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + + result << CPUTestsBase::getTestCaseName(cpuParams); + + return result.str(); + } +protected: + void SetUp() override { + LayerTestsDefinitions::spaceToDepthParamsTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = this->GetParam(); + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + + std::vector inputShape; + SpaceToDepth::SpaceToDepthMode mode; + std::size_t blockSize; + InferenceEngine::Precision netPrecision; + std::tie(inputShape, netPrecision, mode, blockSize, targetDevice) = basicParamsSet; + + inPrc = outPrc = netPrecision; + selectedType = getPrimitiveType() + "_" + inPrc.name(); + auto inPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(inPrc, {inputShape}); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)); + auto d2s = ngraph::builder::makeSpaceToDepth(paramOuts[0], mode, blockSize); + d2s->get_rt_info() = getCPUInfo(); + ngraph::ResultVector results{std::make_shared(d2s)}; + function = std::make_shared(results, params, "SpaceToDepth"); + } +}; + +TEST_P(SpaceToDepthLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "SpaceToDepth"); +} + +namespace { + +const auto cpuParams_nChw16c = CPUSpecificParams {{nChw16c}, {nChw16c}, {"jit_avx512"}, {"jit_avx512"}}; +const auto cpuParams_nCdhw16c = CPUSpecificParams {{nCdhw16c}, {nCdhw16c}, {"jit_avx512"}, {"jit_avx512"}}; + +const auto cpuParams_nChw8c_avx2 = CPUSpecificParams {{nChw8c}, {nChw8c}, {"jit_avx2"}, {"jit_avx2"}}; +const auto cpuParams_nCdhw8c_avx2 = CPUSpecificParams {{nCdhw8c}, {nCdhw8c}, {"jit_avx2"}, {"jit_avx2"}}; + +const auto cpuParams_nChw8c_sse42 = CPUSpecificParams {{nChw8c}, {nChw8c}, {"jit_sse42"}, {"jit_sse42"}}; +const auto cpuParams_nCdhw8c_sse42 = CPUSpecificParams {{nCdhw8c}, {nCdhw8c}, {"jit_sse42"}, {"jit_sse42"}}; + +const auto cpuParams_nhwc_avx2 = CPUSpecificParams {{nhwc}, {nhwc}, {"jit_avx2"}, {"jit_avx2"}}; +const auto cpuParams_ndhwc_avx2 = CPUSpecificParams {{ndhwc}, {ndhwc}, {"jit_avx2"}, {"jit_avx2"}}; + +const auto cpuParams_nhwc_sse42 = CPUSpecificParams {{nhwc}, {nhwc}, {"jit_sse42"}, {"jit_sse42"}}; +const auto cpuParams_ndhwc_sse42 = CPUSpecificParams {{ndhwc}, {ndhwc}, {"jit_sse42"}, {"jit_sse42"}}; + +const auto cpuParams_nhwc_ref = CPUSpecificParams {{nhwc}, {nhwc}, {"ref_any"}, {"ref_any"}}; +const auto cpuParams_ndhwc_ref = CPUSpecificParams {{ndhwc}, {ndhwc}, {"ref_any"}, {"ref_any"}}; + + +const std::vector inputPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::BF16, + InferenceEngine::Precision::I8 +}; + +const std::vector spaceToDepthModes = { + SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, + SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST +}; + +const std::vector> inputShapesBS2_4D = { + {1, 16, 2, 2}, {1, 16, 4, 2}, {1, 32, 6, 8}, {2, 32, 4, 6}, {2, 64, 8, 2}, +}; + +const std::vector> inputShapesBS3_4D = { + {1, 2, 3, 3}, {1, 3, 3, 6}, {1, 5, 6, 3}, {2, 5, 9, 3}, {3, 5, 6, 6} +}; + +const std::vector CPUParamsBS2_4D = { + cpuParams_nChw16c, + cpuParams_nChw8c_avx2, + cpuParams_nChw8c_sse42, + cpuParams_nhwc_avx2, + cpuParams_nhwc_sse42, + cpuParams_nhwc_ref, +}; + +const auto spaceToDepthBS2_4DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS2_4D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(spaceToDepthModes), + testing::Values(1, 2), + testing::Values(CommonTestUtils::DEVICE_CPU)), + testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS2_4D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUSpaceToDepthBS2_4D, SpaceToDepthLayerCPUTest, spaceToDepthBS2_4DParams, SpaceToDepthLayerCPUTest::getTestCaseName); + +const std::vector CPUParamsBS3_4D = { + cpuParams_nhwc_avx2, + cpuParams_nhwc_sse42, + cpuParams_nhwc_ref, +}; + +const auto spaceToDepthBS3_4DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS3_4D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(spaceToDepthModes), + testing::Values(1, 3), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS3_4D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUSpaceToDepthBS3_4D, SpaceToDepthLayerCPUTest, spaceToDepthBS3_4DParams, SpaceToDepthLayerCPUTest::getTestCaseName); + +const std::vector> inputShapesBS2_5D = { + {1, 16, 2, 2, 2}, {1, 16, 4, 4, 2}, {1, 32, 2, 6, 2}, {2, 32, 4, 2, 2}, {2, 64, 2, 2, 6} +}; + +const std::vector> inputShapesBS3_5D = { + {1, 2, 3, 3, 3}, {1, 2, 3, 6, 9}, {1, 5, 6, 3, 3}, {2, 5, 3, 9, 3}, {3, 5, 3, 3, 6} +}; + +const std::vector CPUParamsBS2_5D = { + cpuParams_nCdhw16c, + cpuParams_nCdhw8c_avx2, + cpuParams_nCdhw8c_sse42, + cpuParams_ndhwc_avx2, + cpuParams_ndhwc_sse42, + cpuParams_ndhwc_ref, +}; + +const auto spaceToDepthBS2_5DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS2_5D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(spaceToDepthModes), + testing::Values(1, 2), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS2_5D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUSpaceToDepthBS2_5D, SpaceToDepthLayerCPUTest, spaceToDepthBS2_5DParams, SpaceToDepthLayerCPUTest::getTestCaseName); + +const std::vector CPUParamsBS3_5D = { + cpuParams_ndhwc_avx2, + cpuParams_ndhwc_sse42, + cpuParams_ndhwc_ref, +}; + +const auto spaceToDepthBS3_5DParams = testing::Combine( + testing::Combine( + testing::ValuesIn(inputShapesBS3_5D), + testing::ValuesIn(inputPrecisions), + testing::ValuesIn(spaceToDepthModes), + testing::Values(1, 3), + testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBS3_5D)) +); + +INSTANTIATE_TEST_CASE_P(smoke_CPUSpaceToDepthBS3_5D, SpaceToDepthLayerCPUTest, spaceToDepthBS3_5DParams, SpaceToDepthLayerCPUTest::getTestCaseName); + +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/depth_to_space.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/depth_to_space.hpp index a031cf9b4d2..481876c0151 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/depth_to_space.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/depth_to_space.hpp @@ -11,6 +11,9 @@ #include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + namespace LayerTestsDefinitions { using depthToSpaceParamsTuple = typename std::tuple< diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/space_to_depth.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/space_to_depth.hpp index a01e67ffa8f..c17b10b053c 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/space_to_depth.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/space_to_depth.hpp @@ -11,6 +11,9 @@ #include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + namespace LayerTestsDefinitions { using spaceToDepthParamsTuple = typename std::tuple< diff --git a/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/layers/internal/graph_permute_test.cpp b/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/layers/internal/graph_permute_test.cpp index 0442b91f1c2..f6ea2b49901 100644 --- a/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/layers/internal/graph_permute_test.cpp +++ b/inference-engine/tests_deprecated/unit/engines/mkldnn/graph/layers/internal/graph_permute_test.cpp @@ -324,7 +324,7 @@ TEST_P(permute_s8, TestsPermute) {} ::testing::Values(Layout::NCHW, Layout::NHWC), \ ::testing::Values(Layout::NCHW, Layout::NHWC), \ ::testing::Values(prec), \ - ::testing::Values(1 + (prec == Precision::I8)), \ + ::testing::Values(2), \ ::testing::Values(SizeVector({2, 3, 4, 5})), \ ::testing::Values(SizeVector({0, 1, 2, 3}), SizeVector({0, 2, 3, 1}), \ SizeVector({0, 2, 1, 3}), SizeVector({0, 1, 3, 2}), \ @@ -339,7 +339,7 @@ TEST_P(permute_s8, TestsPermute) {} ::testing::Values(Layout::NCDHW, Layout::NDHWC), \ ::testing::Values(Layout::NCDHW, Layout::NDHWC), \ ::testing::Values(prec), \ - ::testing::Values(1 + (prec == Precision::I8)), \ + ::testing::Values(2), \ ::testing::Values(SizeVector({2, 3, 4, 5, 6})), \ ::testing::Values(SizeVector({0, 1, 2, 3, 4}), SizeVector({0, 4, 2, 1, 3}), \ SizeVector({0, 2, 4, 3, 1}), SizeVector({0, 3, 2, 4, 1}), \ @@ -358,69 +358,69 @@ TEST_P(permute_s8, TestsPermute) {} #define case_planar_5(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 1, {2, 8, 30, 3, 4, 5}, {0, 1, 4, 2, 5, 3}, {}, {}, {}, {}) #define case_planar_6(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 1, {2, 8, 3, 30, 4, 5}, {0, 3, 4, 1, 5, 2}, {}, {}, {}, {}) -#define case_blocked_0(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 2, 3}, \ +#define case_blocked_0(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 2, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_1(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 3, 1}, \ +#define case_blocked_1(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 3, 1}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {2, 2, 20, 32, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_2(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 1, 3}, \ +#define case_blocked_2(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 1, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {2, 2, 32, 20, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_3(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 3, 2}, \ +#define case_blocked_3(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 3, 2}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {2, 4, 20, 10, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_4(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5}, {1, 0, 2, 3}, \ +#define case_blocked_4(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3, {10, 24, 4, 5}, {1, 0, 2, 3}, \ {10, 3, 4, 5, 8}, {0, 1, 2, 3, 1}, {24, 2, 4, 5, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_5(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 5, 10, 20}, {0, 1, 2, 3, 4}, \ +#define case_blocked_5(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 5, 10, 20}, {0, 1, 2, 3, 4}, \ {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}, {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}) -#define case_blocked_6(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 5, 10, 20}, {0, 4, 2, 1, 3}, \ +#define case_blocked_6(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 5, 10, 20}, {0, 4, 2, 1, 3}, \ {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}, {2, 3, 5, 32, 10, 8}, {0, 1, 2, 3, 4, 1}) -#define case_blocked_7(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 5, 10, 20}, {0, 2, 4, 3, 1}, \ +#define case_blocked_7(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 5, 10, 20}, {0, 2, 4, 3, 1}, \ {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}, {2, 1, 20, 10, 32, 8}, {0, 1, 2, 3, 4, 1}) -#define case_blocked_8(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 5, 10, 20}, {0, 3, 2, 4, 1}, \ +#define case_blocked_8(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 5, 10, 20}, {0, 3, 2, 4, 1}, \ {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}, {2, 2, 5, 20, 32, 8}, {0, 1, 2, 3, 4, 1}) -#define case_blocked_9(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 5, 10, 20}, {0, 3, 1, 4, 2}, \ +#define case_blocked_9(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 4, {2, 32, 5, 10, 20}, {0, 3, 1, 4, 2}, \ {2, 4, 5, 10, 20, 8}, {0, 1, 2, 3, 4, 1}, {2, 2, 32, 20, 5, 8}, {0, 1, 2, 3, 4, 1}) -#define case_blocked_10(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5, 6}, {1, 0, 2, 3, 4}, \ +#define case_blocked_10(prec) test_params_t(Layout::BLOCKED, Layout::BLOCKED, prec, 3, {10, 24, 4, 5, 6}, {1, 0, 2, 3, 4}, \ {10, 3, 4, 5, 6, 8}, {0, 1, 2, 3, 4, 1}, {24, 2, 4, 5, 6, 8}, {0, 1, 2, 3, 4, 1}) -#define case_planar_to_blocked_0(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 2, 3}, \ +#define case_planar_to_blocked_0(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 2, 3}, \ {}, {}, {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_1(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 3, 1}, \ +#define case_planar_to_blocked_1(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 3, 1}, \ {}, {}, {2, 2, 20, 32, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_2(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 1, 3}, \ +#define case_planar_to_blocked_2(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 1, 3}, \ {}, {}, {2, 2, 32, 20, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_3(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 3, 2}, \ +#define case_planar_to_blocked_3(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 3, 2}, \ {}, {}, {2, 4, 20, 10, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_4(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5}, {1, 0, 2, 3}, \ +#define case_planar_to_blocked_4(prec) test_params_t(Layout::NCHW, Layout::BLOCKED, prec, 3, {10, 24, 4, 5}, {1, 0, 2, 3}, \ {}, {}, {24, 2, 4, 5, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_5(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 2, 3}, \ +#define case_planar_to_blocked_5(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 2, 3}, \ {}, {}, {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_6(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 3, 1}, \ +#define case_planar_to_blocked_6(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 3, 1}, \ {}, {}, {2, 2, 20, 32, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_7(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 1, 3}, \ +#define case_planar_to_blocked_7(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 2, 1, 3}, \ {}, {}, {2, 2, 32, 20, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_8(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 3, 2}, \ +#define case_planar_to_blocked_8(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 4, {2, 32, 10, 20}, {0, 1, 3, 2}, \ {}, {}, {2, 4, 20, 10, 8}, {0, 1, 2, 3, 1}) -#define case_planar_to_blocked_9(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5}, {1, 0, 2, 3}, \ +#define case_planar_to_blocked_9(prec) test_params_t(Layout::NHWC, Layout::BLOCKED, prec, 3, {10, 24, 4, 5}, {1, 0, 2, 3}, \ {}, {}, {24, 2, 4, 5, 8}, {0, 1, 2, 3, 1}) -#define case_blocked_to_planar_0(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 2, 3}, \ +#define case_blocked_to_planar_0(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 4, {2, 32, 10, 20}, {0, 1, 2, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_1(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 3, 1}, \ +#define case_blocked_to_planar_1(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 4, {2, 32, 10, 20}, {0, 2, 3, 1}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_2(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 1, 3}, \ +#define case_blocked_to_planar_2(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 4, {2, 32, 10, 20}, {0, 2, 1, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_3(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 3, 2}, \ +#define case_blocked_to_planar_3(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 4, {2, 32, 10, 20}, {0, 1, 3, 2}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_4(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5}, {1, 0, 2, 3}, \ +#define case_blocked_to_planar_4(prec) test_params_t(Layout::BLOCKED, Layout::NCHW, prec, 3, {10, 24, 4, 5}, {1, 0, 2, 3}, \ {10, 3, 4, 5, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_5(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 2, 3}, \ +#define case_blocked_to_planar_5(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 4, {2, 32, 10, 20}, {0, 1, 2, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_6(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 3, 1}, \ +#define case_blocked_to_planar_6(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 4, {2, 32, 10, 20}, {0, 2, 3, 1}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_7(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 2, 1, 3}, \ +#define case_blocked_to_planar_7(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 4, {2, 32, 10, 20}, {0, 2, 1, 3}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_8(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 3 + (prec == Precision::I8), {2, 32, 10, 20}, {0, 1, 3, 2}, \ +#define case_blocked_to_planar_8(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 4, {2, 32, 10, 20}, {0, 1, 3, 2}, \ {2, 4, 10, 20, 8}, {0, 1, 2, 3, 1}, {}, {}) -#define case_blocked_to_planar_9(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 2 + (prec == Precision::I8), {10, 24, 4, 5}, {1, 0, 2, 3}, \ +#define case_blocked_to_planar_9(prec) test_params_t(Layout::BLOCKED, Layout::NHWC, prec, 3, {10, 24, 4, 5}, {1, 0, 2, 3}, \ {10, 3, 4, 5, 8}, {0, 1, 2, 3, 1}, {}, {}) test_params_t test_cases_fp32[] = { @@ -607,29 +607,29 @@ protected: TEST_P(MKLDNNGraphDynBatchPermuteTests, TestsDynBatchPermute) {} test_params_t test_cases_dyn_batch[] = { - test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 1, {2, 3, 4, 5}, {0, 1, 2, 3}, {}, {}, {}, {}), - test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 1, {2, 3, 4, 5}, {0, 2, 3, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 1, {2, 3, 4, 5}, {0, 2, 1, 3}, {}, {}, {}, {}), - test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 1, {2, 3, 4}, {0, 1, 2}, {}, {}, {}, {}), - test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 1, {2, 3, 4}, {0, 2, 1}, {}, {}, {}, {}), - test_params_t(Layout::NC, Layout::NC, Precision::FP32, 1, {2, 3}, {0, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 6}, {0, 1, 2, 3, 4}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 6}, {0, 4, 2, 1, 3}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 6}, {0, 2, 4, 3, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 6}, {0, 3, 2, 4, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 2, {2, 3, 4, 5}, {0, 1, 2, 3}, {}, {}, {}, {}), + test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 2, {2, 3, 4, 5}, {0, 2, 3, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 2, {2, 3, 4, 5}, {0, 2, 1, 3}, {}, {}, {}, {}), + test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 2, {2, 3, 4}, {0, 1, 2}, {}, {}, {}, {}), + test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 2, {2, 3, 4}, {0, 2, 1}, {}, {}, {}, {}), + test_params_t(Layout::NC, Layout::NC, Precision::FP32, 2, {2, 3}, {0, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 6}, {0, 1, 2, 3, 4}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 6}, {0, 4, 2, 1, 3}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 6}, {0, 2, 4, 3, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 6}, {0, 3, 2, 4, 1}, {}, {}, {}, {}), // FIXME: Plugin inserts reorder from blocked to goidhw format here // test_params_t(Layout::BLOCKED, Layout::BLOCKED, Precision::FP32, 1, {2, 8, 2, 2, 4, 5}, {0, 1, 4, 2, 5, 3}, {}, {}, {}, {}), // test_params_t(Layout::BLOCKED, Layout::BLOCKED, Precision::FP32, 1, {2, 8, 3, 3, 4, 5}, {0, 1, 4, 2, 5, 3}, {}, {}, {}, {}), - test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 1, {2, 12, 9}, {0, 2, 1}, {}, {}, {}, {}), + test_params_t(Layout::CHW, Layout::CHW, Precision::FP32, 2, {2, 12, 9}, {0, 2, 1}, {}, {}, {}, {}), // test_params_t(Layout::BLOCKED, Layout::BLOCKED, Precision::FP32, 1, {2, 8, 3, 3, 4, 5}, {0, 3, 4, 1, 5, 2}, {}, {}, {}, {}), - test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 1, {2, 3, 4, 5}, {0, 1, 3, 2}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 7}, {0, 3, 1, 4, 2}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 7}, {0, 2, 1, 3, 4}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 7}, {0, 2, 4, 3, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {2, 3, 4, 5, 7}, {0, 4, 2, 3, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 1, {2, 3, 4, 5}, {0, 3, 1, 2}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {3, 4, 7, 8, 4}, {0, 2, 3, 4, 1}, {}, {}, {}, {}), - test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 1, {3, 4, 7, 8, 4}, {0, 4, 1, 2, 3}, {}, {}, {}, {}), + test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 2, {2, 3, 4, 5}, {0, 1, 3, 2}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 7}, {0, 3, 1, 4, 2}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 7}, {0, 2, 1, 3, 4}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 7}, {0, 2, 4, 3, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {2, 3, 4, 5, 7}, {0, 4, 2, 3, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCHW, Layout::NCHW, Precision::FP32, 2, {2, 3, 4, 5}, {0, 3, 1, 2}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {3, 4, 7, 8, 4}, {0, 2, 3, 4, 1}, {}, {}, {}, {}), + test_params_t(Layout::NCDHW, Layout::NCDHW, Precision::FP32, 2, {3, 4, 7, 8, 4}, {0, 4, 1, 2, 3}, {}, {}, {}, {}), }; INSTANTIATE_TEST_CASE_P(TestsDynBatchPermute, MKLDNNGraphDynBatchPermuteTests, ::testing::ValuesIn(test_cases_dyn_batch)); From ad6a0e7e6d71aa8533a3a03b46c61cc8ccbec728 Mon Sep 17 00:00:00 2001 From: Taylor Yeonbok Lee Date: Wed, 21 Apr 2021 23:08:25 +0900 Subject: [PATCH 35/78] [IE CLDNN] Add additional cost metric for deciding deconv kernel (#5252) - gen9_common_conv_bwd_data_kernel (used for fsv16 format) has additional overhead w.r.t stride. Current intention of the kernel implementation is to reuse kernel b/w multiple input values but if the stride gets bigger the reusable rate descreses. - Thus, added additional panelty for deciding deconv kernel (format) --- inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp index c3020dfaf03..870d64527a6 100644 --- a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp +++ b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp @@ -772,8 +772,9 @@ layout layout_optimizer::get_expected_layout(layout const& current_layout, auto input_tensor = node.get_dependency(0).get_output_layout().size; int input_features = input_tensor.feature[0]; int output_features = expected_tensor.feature[0]; - float r = static_cast(input_features * output_features) / (align_to(input_features, 16) * align_to(output_features, 16)); - if (r > 0.5f) + float f_cost = static_cast(input_features * output_features) / (align_to(input_features, 16) * align_to(output_features, 16)); + float stride_cost = 1/static_cast(prim->stride.spatial[0]); + if (f_cost * stride_cost > 0.1f) expected_format = cldnn::format::b_fs_yx_fsv16; else expected_format = cldnn::format::bfyx; From 6c46f26a3c4c1cbc363809a1cbc02781722e7c77 Mon Sep 17 00:00:00 2001 From: Taylor Yeonbok Lee Date: Wed, 21 Apr 2021 23:50:53 +0900 Subject: [PATCH 36/78] [IE CLDNN] Enabled fusing all types of reorders to permute (#5101) * [IE CLDNN] Enabled fusing all types of reorders to permute - Fusing reorder to differnt dims (e.g., 4D=>5D, 6D=>4D, etc) - Fusing reorder to permute_opt kernel for blocked formats - Fixed bug for activation_opt kernel for blocked formats * [IE CLDNN] Enabled fusing all types of reorders to permute Refactoring for permute fsv opt kernel * [IE CLDNN] Permute reorder fusing Support reordering to different dims from optimized permute kernel for blocked format --- .../activation/activation_kernel_opt.cpp | 35 +++-- .../permute/permute_kernel_ref.cpp | 130 +++++++++++++++--- .../permute/permute_kernel_tile_8x8_4x4.cpp | 71 ++++++---- .../permute_kernel_tile_8x8_4x4_fsv.cpp | 78 ++++++++++- .../core/cl_kernels/permute_ref.cl | 8 +- .../cl_kernels/permute_tile_8x8_4x4_fsv.cl | 95 ++++++++++--- .../thirdparty/clDNN/src/layout_optimizer.cpp | 2 +- .../tests/test_cases/fusings_gpu_test.cpp | 121 +++++++++++++--- 8 files changed, 442 insertions(+), 98 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/activation/activation_kernel_opt.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/activation/activation_kernel_opt.cpp index aac84fb4a7b..db7270cd306 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/activation/activation_kernel_opt.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/activation/activation_kernel_opt.cpp @@ -27,12 +27,35 @@ ParamsKey ActivationKernelOpt::GetSupportedKey() const { return k; } +static size_t GetTotalSize(const activation_params& params) { + const auto input = params.inputs[0]; + size_t totalSize = input.LogicalSize(); + switch (params.inputs[0].GetLayout()) { + case DataLayout::b_fs_yx_fsv4: + totalSize = (totalSize / input.Feature().v) * Align(input.Feature().v, 4); + break; + case DataLayout::b_fs_yx_fsv16: + case DataLayout::b_fs_zyx_fsv16: + totalSize = (totalSize / input.Feature().v) * Align(input.Feature().v, 16); + break; + case DataLayout::b_fs_yx_fsv32: + case DataLayout::b_fs_zyx_fsv32: + case DataLayout::fs_b_yx_fsv32: + totalSize = (totalSize / input.Feature().v) * Align(input.Feature().v, 32); + break; + case DataLayout::bs_fs_zyx_bsv16_fsv16: + case DataLayout::bs_fs_yx_bsv16_fsv16: + totalSize = (totalSize / (input.Feature().v * input.Batch().v)) * Align(input.Feature().v, 16) * Align(input.Batch().v, 16); + break; + default: break; + } + return totalSize; +} + ActivationKernelOpt::Parent::DispatchData ActivationKernelOpt::SetDefault(const activation_params& params) const { auto dispatchData = Parent::SetDefault(params); - const auto totalSize = params.inputs[0].LogicalSize(); - - dispatchData.gws = { totalSize / NUM_COLS_WI, 1, 1 }; + dispatchData.gws = { GetTotalSize(params) / NUM_COLS_WI, 1, 1 }; dispatchData.lws = GetOptimalLocalWorkGroupSizes(dispatchData.gws, params.engineInfo); return dispatchData; @@ -50,17 +73,13 @@ bool ActivationKernelOpt::Validate(const Params& p, const optional_params& o) co const activation_params& params = static_cast(p); - if (params.output.GetLayout() == DataLayout::b_fs_yx_fsv16 && params.output.Feature().v % 16 != 0) - return false; - - const auto totalSize = params.inputs[0].LogicalSize(); + const auto totalSize = GetTotalSize(params); if ((totalSize % NUM_COLS_WI) != 0 || (params.inputs[0].GetFirstElementOffset() % NUM_COLS_WI) != 0 || (params.output.GetFirstElementOffset() % NUM_COLS_WI) != 0) { return false; } - if (params.output.GetLayout() != params.inputs[0].GetLayout()) return false; diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_ref.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_ref.cpp index 7a627453c9e..70b0a6c747a 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_ref.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_ref.cpp @@ -5,7 +5,6 @@ #include "permute_kernel_ref.h" #include "kernel_selector_utils.h" #include - namespace kernel_selector { ParamsKey PermuteKernelRef::GetSupportedKey() const { ParamsKey k; @@ -42,20 +41,95 @@ CommonDispatchData PermuteKernelRef::SetDefault(const permute_params& params) co bool PermuteKernelRef::Validate(const Params& p, const optional_params& o) const { if (!Parent::Validate(p, o)) return false; - const permute_params& params = static_cast(p); + return true; +} - // currently reorder fusing is supported only for format change, not the layout change - if (DataTensor::ChannelsCount(params.inputs[0].GetLayout()) - != DataTensor::ChannelsCount(params.output.GetLayout())) { - return false; +static void GetOrderVector(std::string s, std::vector* res) { + size_t pos_start = 0, pos_end; + std::string token; + while ((pos_end = s.find(",", pos_start)) != std::string::npos) { + token = s.substr(pos_start, pos_end - pos_start); + pos_start = pos_end + 1; + res->push_back(token); } - return true; + res->push_back(s.substr(pos_start)); + return; +} + +static std::string GetReorderedOutputOrder(const permute_params& params, const std::vector& permute_out_idx, + const std::pair& dim_change) { + std::map size_str_map = { + {"b", "INPUT0_BATCH_NUM"}, + {"f", "INPUT0_FEATURE_NUM"}, + {"w", "INPUT0_SIZE_W"}, + {"z", "INPUT0_SIZE_Z"}, + {"y", "INPUT0_SIZE_Y"}, + {"x", "INPUT0_SIZE_X"} + }; + + int32_t dim_diff = static_cast(dim_change.first) - static_cast(dim_change.second); + + std::string reordered_order = permute_out_idx[0] + "," + permute_out_idx[1] + ","; + if (dim_diff > 0) { + // dim is shrinked + std::vector merged_indices; + if (dim_diff == 2) merged_indices.push_back(permute_out_idx[dim_change.first - 3]); + merged_indices.push_back(permute_out_idx[dim_change.first - 2]); + merged_indices.push_back(permute_out_idx[dim_change.first - 1]); + std::string pitches = "1"; + for (size_t i = 0 ; i < merged_indices.size(); ++i) { + if (i > 0) reordered_order += "+"; + reordered_order += (merged_indices[i] + "*" + pitches); + pitches = size_str_map[merged_indices[i]] + "*" + pitches; + } + for (size_t i = dim_change.first - 1 - merged_indices.size(); i > 1; --i) { + reordered_order += ((", " + permute_out_idx[i])); + } + } else { + // dim is expanded + if (dim_change.first == 4 && dim_change.second == 5) { + reordered_order += (permute_out_idx.back() + "/" + std::to_string(params.output.Y().v) + + ", " + permute_out_idx.back() + "%" + std::to_string(params.output.Y().v) + + ", " + permute_out_idx[2]); + } else if (dim_change.first == 4 && dim_change.second == 6) { + reordered_order += (permute_out_idx.back() + "/ (" + std::to_string(params.output.Y().v) + + " * " + std::to_string(params.output.Z().v) + ")" + + ", " + permute_out_idx.back() + "/" + std::to_string(params.output.Y().v) + + ", " + permute_out_idx.back() + "%" + std::to_string(params.output.Y().v) + + ", " + permute_out_idx[2]); + } else if (dim_change.first == 5 && dim_change.second == 6) { + reordered_order += (permute_out_idx.back() + "/" + std::to_string(params.output.Z().v) + + ", " + permute_out_idx.back() + "%" + std::to_string(params.output.Z().v) + + ", " + permute_out_idx[3] + + ", " + permute_out_idx[2]); + } + } + return reordered_order; } JitConstants PermuteKernelRef::GetJitConstants(const permute_params& params, const CommonDispatchData& dispatchData) const { auto jit = Parent::GetJitConstants(params, dispatchData); std::vector in_idx; - std::vector out_idx; + std::vector permute_out_idx; + + std::map size_str_map = { + {"b", "INPUT0_BATCH_NUM"}, + {"f", "INPUT0_FEATURE_NUM"}, + {"w", "INPUT0_SIZE_W"}, + {"z", "INPUT0_SIZE_Z"}, + {"y", "INPUT0_SIZE_Y"}, + {"x", "INPUT0_SIZE_X"} + }; + + std::pair dim_change; + bool reorder_to_different_dim = false; + std::vector reordered_out_idx; + if (DataTensor::ChannelsCount(params.inputs[0].GetLayout()) != DataTensor::ChannelsCount(params.output.GetLayout())) { + // subsequent reorder to differnt dimension is fused + dim_change = {params.inputs[0].GetDims().size(), params.output.GetDims().size()}; + reorder_to_different_dim = true; + } + switch (DataTensor::ChannelsCount(params.inputs[0].GetLayout())) { case 6: in_idx = {"b", "f", "x", "y", "z", "w" }; break; case 5: in_idx = {"b", "f", "x", "y", "z" }; break; @@ -64,32 +138,46 @@ JitConstants PermuteKernelRef::GetJitConstants(const permute_params& params, con assert(params.order.size() == in_idx.size()); for (auto& o : params.order) { - out_idx.push_back(in_idx[o]); + permute_out_idx.push_back(in_idx[o]); } std::string input_order = in_idx[0] + "," + in_idx[1]; - std::string output_order = out_idx[0] + "," + out_idx[1]; for (size_t i = in_idx.size() - 1; i > 1; i--) { input_order += "," + in_idx[i]; - output_order += "," + out_idx[i]; } jit.AddConstant(MakeJitConstant("IN_IDX", "INPUT0_GET_INDEX(" + input_order + ")")); - jit.AddConstant(MakeJitConstant("OUT_IDX", "OUTPUT_GET_INDEX(" + output_order + ")")); + + if (reorder_to_different_dim) { + auto reordered_order = GetReorderedOutputOrder(params, permute_out_idx, dim_change); + jit.AddConstant(MakeJitConstant("OUT_IDX", "OUTPUT_GET_INDEX(" + reordered_order + ")")); + GetOrderVector(reordered_order, &reordered_out_idx); + } else { + std::string output_order = permute_out_idx[0] + "," + permute_out_idx[1]; + for (size_t i = in_idx.size() - 1; i > 1; i--) { + output_order += "," + permute_out_idx[i]; + } + jit.AddConstant(MakeJitConstant("OUT_IDX", "OUTPUT_GET_INDEX(" + output_order + ")")); + } if (!params.fused_ops.empty()) { - if (out_idx.size() == 4) { - std::swap(out_idx[2], out_idx[3]); - } else if (out_idx.size() == 5) { - std::swap(out_idx[2], out_idx[4]); - } else if (out_idx.size() == 6) { - std::swap(out_idx[2], out_idx[5]); - std::swap(out_idx[3], out_idx[4]); + if (permute_out_idx.size() == 4) { + std::swap(permute_out_idx[2], permute_out_idx[3]); + } else if (permute_out_idx.size() == 5) { + std::swap(permute_out_idx[2], permute_out_idx[4]); + } else if (permute_out_idx.size() == 6) { + std::swap(permute_out_idx[2], permute_out_idx[5]); + std::swap(permute_out_idx[3], permute_out_idx[4]); } - FusedOpsConfiguration conf = {"", out_idx, "input_var", params.inputs[0].GetDType(), 1}; - jit.Merge(MakeFusedOpsJitConstants(params, {conf})); + if (reorder_to_different_dim) { + FusedOpsConfiguration conf = {"", reordered_out_idx, "input_var", params.inputs[0].GetDType(), 1}; + jit.Merge(MakeFusedOpsJitConstants(params, {conf})); + } else { + FusedOpsConfiguration conf = {"", permute_out_idx, "input_var", params.inputs[0].GetDType(), 1}; + jit.Merge(MakeFusedOpsJitConstants(params, {conf})); + } } return jit; } diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4.cpp index 8e9dbbf8ecb..f16ff661583 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4.cpp @@ -70,19 +70,54 @@ static inline std::vector GetFusedOpOrderVector(size_t size) { return res; } -static inline std::string GetTiledOutputOrder(size_t size) { +static inline std::string GetTiledOutputOrder(const permute_params& params) { + std::pair dim_change = {params.inputs[0].GetDims().size(), params.output.GetDims().size()}; + std::string order_str = ""; - switch (size) { - case 4 : - order_str = "b, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; - break; - case 5 : - order_str = "b, z, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; - break; - case 6 : - order_str = "b, w, z, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; - break; - default : throw std::runtime_error("Unsupported combination\n"); + int32_t dim_diff = static_cast(dim_change.first) - static_cast(dim_change.second); + + if (dim_diff == 0) { + switch (dim_change.first) { + case 4 : + order_str = "b, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; + break; + case 5 : + order_str = "b, z, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; + break; + case 6 : + order_str = "b, w, z, y, (x * TILE_SIZE + lh), (f * TILE_SIZE)"; + break; + default : throw std::runtime_error("Unsupported combination\n"); + } + } else if (dim_diff > 0) { + // dim is shrinked + order_str = "b, z + lh, y * INPUT0_SIZE_X + x, f"; + if (dim_change.first == 5 && dim_change.second == 4) { + order_str = "b, z, y * INPUT0_SIZE_X + (x * TILE_SIZE + lh), (f*TILE_SIZE)"; + } else if (dim_change.first == 6 && dim_change.second == 4) { + order_str = "b, w, z * INPUT0_SIZE_Y * INPUT0_SIZE_X + y * INPUT0_SIZE_X + (x * TILE_SIZE + lh), (f * TILE_SIZE)"; + } else if (dim_change.first == 6 && dim_change.second == 5) { + order_str = "b, w, z * INPUT0_SIZE_Y + y, x * TILE_SIZE + lh, (f * TILE_SIZE)"; + } + } else { + // dim is expanded + if (dim_change.first == 4 && dim_change.second == 5) { + order_str = ("b, y, (x * TILE_SIZE + lh) / " + std::to_string(params.output.Y().v) + + ", (x * TILE_SIZE +lh) % " + std::to_string(params.output.Y().v) + + ", (f * TILE_SIZE)"); + } else if (dim_change.first == 4 && dim_change.second == 6) { + order_str = ("b, y, (x * TILE_SIZE + lh) / (" + std::to_string(params.output.Y().v) + + " * " + std::to_string(params.output.Z().v) + ")" + + ", (x * TILE_SIZE + lh) / " + std::to_string(params.output.Y().v) + + ", (x * TILE_SIZE + lh) % " + std::to_string(params.output.Y().v) + + ", (f * TILE_SIZE)"); + } else if (dim_change.first == 5 && dim_change.second == 6) { + order_str = ("b, z, y /" + std::to_string(params.output.Z().v) + + ", y % " + std::to_string(params.output.Z().v) + + ", (x * TILE_SIZE + lh), (f * TILE_SIZE)"); + } else { + throw std::runtime_error("Unsupported combination\n"); + } } return order_str; } @@ -104,7 +139,6 @@ static inline std::string GetTiledInputOrder(size_t size) { return order_str; } - JitConstants PermuteKernel_tile_8x8_4x4::GetJitConstants(const permute_params& params, const CommonDispatchData& dispatchData) const { auto jit = Parent::GetJitConstants(params, dispatchData); size_t tile_size = GetTileSize(params); @@ -113,7 +147,7 @@ JitConstants PermuteKernel_tile_8x8_4x4::GetJitConstants(const permute_params& p uint64_t total_lws = dispatchData.lws[0] * dispatchData.lws[1] * dispatchData.lws[2]; jit.AddConstant(MakeJitConstant("VEC_WIDTH", vector_width)); jit.AddConstant(MakeJitConstant("INPUT0_TILED_ORDER", GetTiledInputOrder(params.inputs[0].GetDims().size()))); - jit.AddConstant(MakeJitConstant("OUTPUT_TILED_ORDER", GetTiledOutputOrder(params.output.GetDims().size()))); + jit.AddConstant(MakeJitConstant("OUTPUT_TILED_ORDER", GetTiledOutputOrder(params))); jit.AddConstant(MakeJitConstant("TILE_SIZE", tile_size)); jit.AddConstant(MakeJitConstant("N_VECTORS_IN_TILE", tile_size / vector_width)); jit.AddConstant(MakeJitConstant("LWS", total_lws)); @@ -227,15 +261,6 @@ bool PermuteKernel_tile_8x8_4x4::Validate(const Params& p, const optional_params const permute_params& params = static_cast(p); - if (params.inputs[0].GetDims().size() != params.output.GetDims().size()) { - return false; - } - - if (params.inputs[0].GetLayout() != params.output.GetLayout()) { - // Reorder cannot be fused - return false; - } - if (!is_rotating_except_batch(params.order)) { return false; } diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4_fsv.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4_fsv.cpp index 12417d69699..5923adc30c8 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4_fsv.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/permute/permute_kernel_tile_8x8_4x4_fsv.cpp @@ -40,6 +40,9 @@ ParamsKey PermuteKernel_tile_8x8_4x4_fsv::GetSupportedKey() const { k.EnableOutputLayout(DataLayout::b_fs_zyx_fsv32); k.EnableInputLayout(DataLayout::b_fs_yx_fsv4); k.EnableOutputLayout(DataLayout::b_fs_yx_fsv4); + k.EnableOutputLayout(DataLayout::bfyx); + k.EnableOutputLayout(DataLayout::bfzyx); + k.EnableOutputLayout(DataLayout::bfwzyx); k.EnableTensorOffset(); k.EnableTensorPitches(); k.EnableBatching(); @@ -74,6 +77,47 @@ static inline std::string GetTiledOutputOrder(size_t size) { return order_str; } +static inline std::string GetReorderedTiledOutputOrder(const permute_params& params) { + std::pair dim_change = {params.inputs[0].GetDims().size(), params.output.GetDims().size()}; + + std::string order_str = ""; + int32_t dim_diff = static_cast(dim_change.first) - static_cast(dim_change.second); + if (dim_diff == 0) { + switch (params.output.GetDims().size()) { + case 4 : + order_str = "b, y + lh, x, f"; + break; + case 5 : + order_str = "b, z + lh, y, x, f"; + break; + default : throw std::runtime_error("Unsupported combination\n"); + } + } else if (dim_diff > 0) { + // dim is shrinked (5 -> 4 only) + order_str = "b, z + lh, y * INPUT0_SIZE_X + x, f"; + } else { + // dim is expanded + if (dim_change.first == 4 && dim_change.second == 5) { + order_str = ("b, y + lh, x / " + std::to_string(params.output.Y().v) + + ", x % " + std::to_string(params.output.Y().v) + + ", f"); + } else if (dim_change.first == 4 && dim_change.second == 6) { + order_str = ("b, y + lh, x / (" + std::to_string(params.output.Y().v) + + " * " + std::to_string(params.output.Z().v) + ")" + + ", x / " + std::to_string(params.output.Y().v) + + ", x % " + std::to_string(params.output.Y().v) + + ", f"); + } else if (dim_change.first == 5 && dim_change.second == 6) { + order_str = ("b, z + lh, y /" + std::to_string(params.output.Z().v) + + ", y % " + std::to_string(params.output.Z().v) + + ", x, f"); + } else { + throw std::runtime_error("Unsupported combination\n"); + } + } + return order_str; +} + static inline std::string GetTiledInputOrder(size_t size) { std::string order_str = ""; switch (size) { @@ -145,12 +189,17 @@ JitConstants PermuteKernel_tile_8x8_4x4_fsv::GetJitConstants(const permute_param const size_t fsv_alignment = GetFsvAlignment(params); jit.AddConstant(MakeJitConstant("INPUT0_TILED_ORDER", GetTiledInputOrder(input_ndims))); - jit.AddConstant(MakeJitConstant("OUTPUT_TILED_ORDER", GetTiledOutputOrder(output_ndims))); jit.AddConstant(MakeJitConstant("INPUT0_FEATURE_SLICE_NUM", CeilDiv(f, fsv_alignment))); jit.AddConstant(MakeJitConstant("TILE_SIZE", tile_size)); jit.AddConstant(MakeJitConstant("FSV_ALIGNMENT", fsv_alignment)); jit.AddConstant(MakeJitConstant("TRANS_BUF_SIZE", tile_size * total_lws)); + if (params.inputs[0].GetLayout() != params.output.GetLayout()) { + jit.AddConstant(MakeJitConstant("REORDERED_OUTPUT_TILED_ORDER", GetReorderedTiledOutputOrder(params))); + } else { + jit.AddConstant(MakeJitConstant("OUTPUT_TILED_ORDER", GetTiledOutputOrder(output_ndims))); + } + // whether F is tile_size-aligned if (f % tile_size != 0) { jit.AddConstant(MakeJitConstant("F_REMAINDER_SIZE", f % tile_size)); @@ -172,8 +221,8 @@ JitConstants PermuteKernel_tile_8x8_4x4_fsv::GetJitConstants(const permute_param } if (!params.fused_ops.empty()) { - std::vector output_order = GetFusedOpOrderVector(output_ndims); - FusedOpsConfiguration conf = {"", output_order, "input_var", params.inputs[0].GetDType(), 1}; + std::vector original_output_order = GetFusedOpOrderVector(input_ndims); + FusedOpsConfiguration conf = {"", original_output_order, "input_var", params.inputs[0].GetDType(), 1}; jit.Merge(MakeFusedOpsJitConstants(params, {conf})); } return jit; @@ -258,11 +307,26 @@ bool PermuteKernel_tile_8x8_4x4_fsv::Validate(const Params& p, const optional_pa }; const permute_params& params = static_cast(p); - - if (params.inputs[0].GetDims().size() != params.output.GetDims().size()) { - return false; + // blocked format => blocked format is not supported + if (params.inputs[0].GetLayout() != params.output.GetLayout()) { + if ((params.inputs[0].GetLayout() == DataLayout::b_fs_yx_fsv4) || + (params.inputs[0].GetLayout() == DataLayout::b_fs_yx_fsv16) || + (params.inputs[0].GetLayout() == DataLayout::b_fs_yx_fsv32)) { + if (params.output.GetLayout() != DataLayout::bfyx + && params.output.GetLayout() != DataLayout::bfzyx + && params.output.GetLayout() != DataLayout::bfwzyx) + return false; + } else if ((params.inputs[0].GetLayout() == DataLayout::b_fs_zyx_fsv16) || + (params.inputs[0].GetLayout() == DataLayout::b_fs_zyx_fsv32)) { + if (params.output.GetLayout() != DataLayout::bfyx + && params.output.GetLayout() != DataLayout::bfzyx + && params.output.GetLayout() != DataLayout::bfwzyx) { + return false; + } + } else { + return false; + } } - if (!is_rotating_except_batch(params.order)) { return false; } diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_ref.cl b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_ref.cl index 8d6c530484b..5cdddb5ea4c 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_ref.cl +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_ref.cl @@ -14,9 +14,9 @@ KERNEL (permute_ref)( { //gws(x, y * z * w, b*f) const uint gid_0 = get_global_id(1); -#if INPUT0_DIMS == 4 && OUTPUT0_DIMS == 4 +#if INPUT0_DIMS == 4 const uint y = gid_0; -#elif INPUT0_DIMS == 5 && OUTPUT0_DIMS == 5 +#elif INPUT0_DIMS == 5 const uint z = gid_0 / INPUT0_SIZE_Y; const uint y = gid_0 % INPUT0_SIZE_Y; #else @@ -24,11 +24,11 @@ KERNEL (permute_ref)( const uint z = gid_0 / INPUT0_SIZE_Y % INPUT0_SIZE_Z; const uint y = gid_0 % INPUT0_SIZE_Y; #endif - + const uint x = get_global_id(0); const uint f = (uint)get_global_id(2) % INPUT0_FEATURE_NUM; const uint b = (uint)get_global_id(2) / INPUT0_FEATURE_NUM; - + INPUT0_TYPE input_var = input[IN_IDX]; #if HAS_FUSED_OPS diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_tile_8x8_4x4_fsv.cl b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_tile_8x8_4x4_fsv.cl index f2301cccd05..d911b4e6bf0 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_tile_8x8_4x4_fsv.cl +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/permute_tile_8x8_4x4_fsv.cl @@ -18,6 +18,8 @@ #define VLOAD CAT(vload, TILE_SIZE) #define VSTORE CAT(vstore, TILE_SIZE) #define AS_INPUTVTYPE CAT(as_, INPUTVTYPE) +#define AS_OUTPUTVTYPE CAT(as_, OUTPUTVTYPE) +#define TO_OUTPUTVTYPE CAT(convert_, OUTPUTVTYPE) #define GET_GLOBAL_ID(IDX) ((uint)get_global_id(IDX)) #define GET_LOCAL_ID(IDX) ((uint)get_local_id(IDX)) @@ -51,6 +53,49 @@ KERNEL (permute_tile_8x8_4x4_fsv)( + GET_LOCAL_ID(2); const uint local_buf_offset = local_id * TILE_SIZE; +#ifdef REORDERED_OUTPUT_TILED_ORDER + if (F_NO_REMAINDER_CONDITION) { + unroll_for (uint lh = 0; lh < TILE_SIZE/*8*/; ++lh) { + // read + const uint input_idx = INPUT0_GET_TILED_INDEX(INPUT0_TILED_ORDER); + INPUTVTYPE read_data = AS_INPUTVTYPE(VLOAD(0, input + input_idx)); + // write to ddr + #if HAS_FUSED_OPS + OUTPUTVTYPE out_data; + unroll_for (uint lw = 0; lw < TILE_SIZE; ++lw) { + INPUT0_TYPE input_var = read_data[lw]; + FUSED_OPS; + out_data[lw] = FUSED_OPS_RESULT; + } + const uint output_idx = OUTPUT_GET_TILED_INDEX(REORDERED_OUTPUT_TILED_ORDER); + VSTORE(out_data, 0, output + output_idx); + #else + const uint output_idx = OUTPUT_GET_TILED_INDEX(REORDERED_OUTPUT_TILED_ORDER); + VSTORE(ACTIVATION(TO_OUTPUTVTYPE(read_data), ACTIVATION_PARAMS), 0, output + output_idx); + #endif + } + } +#ifdef F_REMAINDER_CONDITION + else if (F_REMAINDER_CONDITION) { + unroll_for (uint lh = 0; lh < TILE_SIZE/*8*/; ++lh) { + unroll_for (uint lw = 0; lw < F_REMAINDER_SIZE; ++lw) { + // read + const uint input_idx = INPUT0_GET_TILED_INDEX(INPUT0_TILED_ORDER); + INPUTVTYPE read_data = AS_INPUTVTYPE(VLOAD(0, input + input_idx)); + // write to ddr + const uint output_idx = OUTPUT_GET_TILED_INDEX(REORDERED_OUTPUT_TILED_ORDER); + #if HAS_FUSED_OPS + INPUT0_TYPE input_var = read_data[lw]; + FUSED_OPS; + output[output_idx + lw] = FUSED_OPS_RESULT; + #else + output[output_idx + lw] = TO_OUTPUT_TYPE(read_data[lw]); + #endif + } + } + } +#endif // F_REMAINDER_CONDITION +#else // !REORDERED_OUTPUT_TILED_ORDER if (F_NO_REMAINDER_CONDITION) { // read and transpose unroll_for (uint lh = 0; lh < TILE_SIZE; ++lh) { @@ -59,16 +104,15 @@ KERNEL (permute_tile_8x8_4x4_fsv)( unroll_for (uint lw = 0; lw < TILE_SIZE; ++lw) { const uint dst = local_buf_offset + lw; -#if HAS_FUSED_OPS + #if HAS_FUSED_OPS INPUT0_TYPE input_var = read_data[lw]; FUSED_OPS; transpose_buf[dst][lh] = FUSED_OPS_RESULT; -#else + #else transpose_buf[dst][lh] = ACTIVATION(read_data[lw], ACTIVATION_PARAMS); -#endif + #endif } } - // write to ddr #ifdef YZ_REMAINDER_CONDITION if (YZ_REMAINDER_LESS_THAN_TILE_SIZE) { // copy one by one when z % TILE_SIZE < TILE_SIZE/2 @@ -94,12 +138,13 @@ KERNEL (permute_tile_8x8_4x4_fsv)( VSTORE(transpose_buf[local_buf_offset + lw], 0, output + output_idx); } } -#else +#else // YZ_REMAINDER_CONDITION + // write to ddr unroll_for (uint lw = 0; lw < TILE_SIZE; ++lw) { const uint output_idx = OUTPUT_GET_TILED_INDEX(OUTPUT_TILED_ORDER); VSTORE(transpose_buf[local_buf_offset + lw], 0, output + output_idx); } -#endif +#endif //YZ_REMAINDER_CONDITION } #ifdef F_REMAINDER_CONDITION else if (F_REMAINDER_CONDITION) { @@ -109,13 +154,13 @@ KERNEL (permute_tile_8x8_4x4_fsv)( INPUTVTYPE read_data = AS_INPUTVTYPE(VLOAD(0, input + input_idx)); unroll_for (uint lw = 0; lw < F_REMAINDER_SIZE; ++lw) { uint dst = local_buf_offset + lw; - #if HAS_FUSED_OPS - INPUT0_TYPE input_var = read_data[lw]; - FUSED_OPS; - transpose_buf[dst][lh] = FUSED_OPS_RESULT; - #else - transpose_buf[dst][lh] = ACTIVATION(read_data[lw], ACTIVATION_PARAMS); - #endif + #if HAS_FUSED_OPS + INPUT0_TYPE input_var = read_data[lw]; + FUSED_OPS; + transpose_buf[dst][lh] = FUSED_OPS_RESULT; + #else + transpose_buf[dst][lh] = ACTIVATION(read_data[lw], ACTIVATION_PARAMS); + #endif } } // write to ddr @@ -145,12 +190,30 @@ KERNEL (permute_tile_8x8_4x4_fsv)( VSTORE(transpose_buf[local_buf_offset + lw], 0, output + output_idx); } } -#else +#else // !YZ_REMAINDER_CONDITION unroll_for (uint lw = 0; lw < F_REMAINDER_SIZE; ++lw) { const uint output_idx = OUTPUT_GET_TILED_INDEX(OUTPUT_TILED_ORDER); VSTORE(transpose_buf[local_buf_offset + lw], 0, output + output_idx); } -#endif +#endif // YZ_REMAINDER_CONDITION } -#endif +#endif // F_REMAINDER_CONDITION +#endif // REORDERED_OUTPUT)TILED_ORDER } + +#undef unroll_for +#undef CEIL_DIV(A, B) +#undef INPUT0_GET_TILED_INDEX(ORDER) +#undef OUTPUT_GET_TILED_INDEX(ORDER) +#undef YZ_REMAINDER_LESS_THAN_TILE_SIZE +#undef YZ_REMAINDER_MORE_THAN_TILE_SIZE +#undef INPUTVTYPE +#undef OUTPUTVTYPE +#undef VLOAD +#undef VSTORE +#undef AS_INPUTVTYPE +#undef AS_OUTPUTVTYPE +#undef TO_OUTPUTVTYPE +#undef GET_GLOBAL_ID(IDX) +#undef GET_LOCAL_ID(IDX) +#undef GET_LOCAL_SIZE(IDX) diff --git a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp index 870d64527a6..5d53f2fa317 100644 --- a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp +++ b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp @@ -236,7 +236,7 @@ bool layout_optimizer::can_fuse_reorder_to_prev(program_node& prev, program_node fmt_next == format::b_fs_yx_fsv16 || fmt_next == format::b_fs_zyx_fsv16 || fmt_next == format::bs_fs_yx_bsv16_fsv16)) return true; - if (prev.is_type() && fmt_prev.dimension() == fmt_next.dimension()) { + if (prev.is_type()) { return true; } return false; diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp index 6be7d5ae8de..2a57732c269 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp @@ -157,7 +157,6 @@ public: void compare(network& not_fused, network& fused, T& p, bool count_reorder = false) { auto outputs_ref = not_fused.execute(); auto outputs_fused = fused.execute(); - auto get_reorders_count = [](network& net) -> size_t { size_t count = 0; for (auto& pi : net.get_primitives_info()) { @@ -187,7 +186,6 @@ public: description << " " << i.original_id << " " << i.kernel_id << std::endl; } SCOPED_TRACE(description.str()); - // Subtract reorders count to handle execution in different layouts when input/output reorders can be added in the graph ASSERT_EQ(fused.get_executed_primitives().size() - (count_reorder ? 0 : reorders_count_fused), p.expected_fused_primitives); ASSERT_EQ(not_fused.get_executed_primitives().size() - (count_reorder ? 0 : reorders_count_not_fused), p.expected_not_fused_primitives); @@ -6409,7 +6407,6 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, permute_scale_eltwise_actv_scale_actv, struct permute_reorder_params { tensor in_shape; - tensor out_shape; std::vector permute_order1; std::vector permute_order2; data_types permute_type; @@ -6420,20 +6417,47 @@ struct permute_reorder_params { size_t expected_not_fused_primitives; }; -#define CASE_PERMUTE_REORDER_F32_0 {1, 16, 32, 2}, {1, 16, 32, 2}, {0, 3, 2, 1}, {0, 3, 2, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv16, format::bfyx -#define CASE_PERMUTE_REORDER_F32_1 {2, 16, 16, 16}, {2, 16, 16, 16}, {0, 3, 2, 1}, {0, 3, 2, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv4, format::bfyx -#define CASE_PERMUTE_REORDER_F32_2 {1, 16, 4, 5, 16}, {1, 16, 4, 5, 16}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_F32_0 {1, 16, 32, 2}, {0, 3, 2, 1}, {0, 3, 2, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_F32_1 {2, 7, 9, 27}, {0, 3, 2, 1}, {0, 3, 2, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv4, format::bfyx +#define CASE_PERMUTE_REORDER_F32_2 {1, 16, 4, 5, 16},{0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_F16_0 {1, 16, 2, 4}, {0, 2, 1, 3}, {0, 2, 1, 3}, data_types::f16, data_types::f16, format::b_fs_yx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_F16_1 {1, 16, 4, 5, 16}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f16, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_F16_2 {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f16, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx -#define CASE_PERMUTE_REORDER_F16_0 {1, 16, 2, 4}, {1, 16, 2, 4}, {0, 2, 1, 3}, {0, 2, 1, 3}, data_types::f16, data_types::f16, format::b_fs_yx_fsv16, format::bfyx -#define CASE_PERMUTE_REORDER_F16_1 {1, 16, 4, 5, 16}, {1, 16, 4, 5, 16}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f16, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx -#define CASE_PERMUTE_REORDER_F16_2 {1, 5, 1, 2, 14}, {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f16, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx +// type change +#define CASE_PERMUTE_REORDER_S8_TO_F32_0 {1, 15, 4, 5}, {0, 2, 3, 1}, {0, 3, 1, 2}, data_types::i8, data_types::f32, format::b_fs_yx_fsv4, format::bfyx +#define CASE_PERMUTE_REORDER_S8_TO_F32_1 {1, 2, 15, 4, 5}, {0, 2, 4, 1, 3}, {0, 3, 1, 4, 2}, data_types::i8, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_F32_TO_F16_0 {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f32, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_U8_TO_F16_0 {1, 17, 1, 2, 7}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::u8, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx -#define CASE_PERMUTE_REORDER_S8_0 {1, 15, 4, 5}, {1, 15, 4, 5}, {0, 2, 3, 1}, {0, 3, 1, 2}, data_types::i8, data_types::f32, format::b_fs_yx_fsv4, format::bfyx -#define CASE_PERMUTE_REORDER_S8_1 {1, 2, 15, 4, 5}, {1, 2, 15, 4, 5}, {0, 2, 4, 1, 3}, {0, 3, 1, 4, 2}, data_types::i8, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx +// dim change +#define CASE_PERMUTE_REORDER_4D_TO_5D_F32_0 {1, 16, 8, 16}, {1, 2, 0, 3}, {0, 3, 1, 4, 2}, data_types::f32, data_types::f32, format::bfyx, format::bfzyx +#define CASE_PERMUTE_REORDER_4D_TO_6D_F32_1 {1, 16, 8, 16}, {0, 2, 3, 1}, {0, 3, 5, 4, 1, 2}, data_types::f32, data_types::f32, format::bfyx, format::bfwzyx +#define CASE_PERMUTE_REORDER_5D_TO_4D_F32_0 {1, 16, 4, 5, 18},{0, 2, 3, 4, 1}, {0, 3, 1, 2}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_5D_TO_4D_F32_1 {1, 16, 4, 5, 16},{0, 2, 3, 4, 1}, {0, 3, 1, 2}, data_types::f32, data_types::f32, format::bfzyx, format::bfyx +#define CASE_PERMUTE_REORDER_5D_TO_6D_F32_2 {1, 16, 8, 4, 16}, {0, 4, 2, 3, 1}, {0, 3, 5, 4, 1, 2}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfwzyx +#define CASE_PERMUTE_REORDER_6D_TO_4D_F32_0 {1, 16, 4, 5, 4, 16}, {0, 2, 5, 3, 4, 1}, {0, 3, 1, 2}, data_types::f32, data_types::f32, format::bfwzyx, format::bfyx +#define CASE_PERMUTE_REORDER_6D_TO_5D_F32_1 {1, 16, 4, 5, 4, 16}, {0, 2, 5, 3, 4, 1}, {0, 3, 4, 1, 2}, data_types::f32, data_types::f32, format::bfwzyx, format::bfzyx -#define CASE_PERMUTE_REORDER_F32_TO_F16_0 {1, 5, 1, 2, 14}, {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::f32, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx -#define CASE_PERMUTE_REORDER_S8_TO_F32_0 {1, 18, 1, 2, 2}, {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::i8, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx -#define CASE_PERMUTE_REORDER_U8_TO_F16_0 {1, 17, 1, 2, 7}, {1, 5, 1, 2, 14}, {0, 2, 3, 4, 1}, {0, 4, 1, 2, 3}, data_types::u8, data_types::f16, format::b_fs_zyx_fsv16, format::bfzyx +// permute_opt for blocked format +#define CASE_PERMUTE_REORDER_TILED_F32_0 {1, 256, 2, 64}, {0, 3, 1, 2}, {0, 2, 3, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F32_1 {1, 78, 2, 259}, {0, 3, 1, 2}, {0, 2, 3, 1}, data_types::f32, data_types::f32, format::b_fs_yx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F32_2 {1, 48, 1, 3, 259}, {0, 4, 1, 2, 3}, {0, 2, 3, 4, 1}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfzyx + +// permute_opt for blocked format => reorder to differnt dim +#define CASE_PERMUTE_REORDER_TILED_F32_3 {1, 45, 1, 3, 259}, {0, 4, 1, 2, 3}, {0, 2, 3, 1}, data_types::f32, data_types::f32, format::b_fs_zyx_fsv16, format::bfyx + +// permute opt for blocked format => reorder to different dim/type +#define CASE_PERMUTE_REORDER_TILED_I8_4 {1, 45, 1, 3, 259}, {0, 4, 1, 2, 3}, {0, 2, 3, 1}, data_types::i8, data_types::f32, format::b_fs_zyx_fsv16, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F16_5 {1, 48, 3, 256}, {0, 3, 1, 2}, {0, 2, 4, 3, 1}, data_types::f16, data_types::f32, format::b_fs_yx_fsv16, format::bfzyx +#define CASE_PERMUTE_REORDER_TILED_F16_6 {1, 48, 2, 3, 256}, {0, 4, 1, 2, 3}, {0, 2, 5, 4, 3, 1}, data_types::f16, data_types::f32, format::b_fs_zyx_fsv16, format::bfwzyx + +// permute opt for non_blocked format => reorder to differnt dim/type +#define CASE_PERMUTE_REORDER_TILED_F16_7 {1, 48, 2, 3, 256}, {0, 4, 1, 2, 3}, {0, 2, 3, 1}, data_types::f16, data_types::f32, format::bfzyx, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F16_8 {1, 28, 2, 2, 3, 256}, {0, 5, 1, 2, 3, 4}, {0, 2, 3, 1}, data_types::f16, data_types::f32, format::bfwzyx, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F16_9 {1, 24, 2, 3, 256}, {0, 4, 1, 2, 3}, {0, 2, 3, 1}, data_types::f16, data_types::f32, format::bfzyx, format::bfyx +#define CASE_PERMUTE_REORDER_TILED_F16_10 {1, 35, 3, 253}, {0, 3, 1, 2}, {0, 2, 4, 3, 1}, data_types::f16, data_types::f32, format::bfyx, format::bfzyx +#define CASE_PERMUTE_REORDER_TILED_F16_11 {1, 32, 3, 253}, {0, 3, 1, 2}, {0, 2, 4, 5, 3, 1}, data_types::f16, data_types::f32, format::bfyx, format::bfwzyx class PermuteReorderFusingTest : public ::BaseFusingTest { public: @@ -6460,7 +6484,7 @@ TEST_P(permute_redundant_reorder, basic) { input_layout("input", get_input_layout(p)), permute("permute1", "input", p.permute_order1), reorder("reorder1", "permute1", p.output_format, p.output_type), // to be fused - permute("permute2", "reorder1", p.permute_order2) // dummy last op to make reorder n + permute("permute2", "reorder1", p.permute_order2) // dummy last op to make reorder fused ); tolerance = 1e-5f; execute(p); @@ -6474,11 +6498,72 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, permute_redundant_reorder, permute_reorder_params{CASE_PERMUTE_REORDER_F16_0, 3, 4}, permute_reorder_params{CASE_PERMUTE_REORDER_F16_1, 3, 4}, permute_reorder_params{CASE_PERMUTE_REORDER_F16_2, 3, 4}, - permute_reorder_params{CASE_PERMUTE_REORDER_S8_0, 3, 4}, - permute_reorder_params{CASE_PERMUTE_REORDER_S8_1, 3, 4}, - permute_reorder_params{CASE_PERMUTE_REORDER_F32_TO_F16_0, 3, 4}, permute_reorder_params{CASE_PERMUTE_REORDER_S8_TO_F32_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_S8_TO_F32_1, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_F32_TO_F16_0, 3, 4}, permute_reorder_params{CASE_PERMUTE_REORDER_U8_TO_F16_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_4D_TO_5D_F32_0, 3, 3}, + permute_reorder_params{CASE_PERMUTE_REORDER_4D_TO_6D_F32_1, 3, 3}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_4D_F32_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_4D_F32_1, 3, 3}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_6D_F32_2, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_6D_TO_4D_F32_0, 3, 3}, + permute_reorder_params{CASE_PERMUTE_REORDER_6D_TO_5D_F32_1, 3, 3}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_1, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_2, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_3, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_I8_4, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_5, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_6, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_7, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_8, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_9, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_10, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_11, 3, 4}, + }),); + +class permute_act_reorder : public PermuteReorderFusingTest {}; + +TEST_P(permute_act_reorder, basic) { + auto p = GetParam(); + create_topologies( + input_layout("input", get_input_layout(p)), + permute("permute1", "input", p.permute_order1), + activation("activation", "permute1", activation_func::abs), + reorder("reorder1", "activation", p.output_format, p.output_type), // to be fused + permute("permute2", "reorder1", p.permute_order2) // dummy last op to make reorder fused + ); + tolerance = 1e-5f; + execute(p); +} + +INSTANTIATE_TEST_CASE_P(fusings_gpu, permute_act_reorder, + ::testing::ValuesIn(std::vector { + permute_reorder_params{CASE_PERMUTE_REORDER_F32_0, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_F32_1, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_F32_2, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_F16_0, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_F16_1, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_F16_2, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_4D_TO_5D_F32_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_4D_TO_6D_F32_1, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_4D_F32_0, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_4D_F32_1, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_5D_TO_6D_F32_2, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_6D_TO_4D_F32_0, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_6D_TO_5D_F32_1, 3, 4}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_0, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_1, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_2, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F32_3, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_5, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_6, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_7, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_8, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_9, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_10, 3, 5}, + permute_reorder_params{CASE_PERMUTE_REORDER_TILED_F16_11, 3, 5}, }),); class NormalizeFusingTest : public ::BaseFusingTest { From d2c4d068b5dcde5f6fa16b25fa926b7e9799474f Mon Sep 17 00:00:00 2001 From: Yegor Kruglov Date: Wed, 21 Apr 2021 18:46:49 +0300 Subject: [PATCH 37/78] fixed mismatch of input names between framework and MO .mapping file (#5256) --- model-optimizer/extensions/back/ReverseInputChannels.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model-optimizer/extensions/back/ReverseInputChannels.py b/model-optimizer/extensions/back/ReverseInputChannels.py index 49f748ac434..50d78fcd95b 100644 --- a/model-optimizer/extensions/back/ReverseInputChannels.py +++ b/model-optimizer/extensions/back/ReverseInputChannels.py @@ -67,7 +67,8 @@ class InsertReverseChannels(BackReplacementPattern): for name, parameter, _ in suitable_params: reverse_channels = ReverseChannels(graph, {'name': name + '/reverse_input_channels'}).create_node() - parameter.out_port(0).get_connection().set_source(reverse_channels.out_port(0)) + parameter.out_port(0).get_connection().set_source(reverse_channels.out_port(0), + attributes_save_mode='source') parameter.out_port(0).connect(reverse_channels.in_port(0)) From 56e58c044315a3f8170b46141d6e181a9c736580 Mon Sep 17 00:00:00 2001 From: Nikolay Tyukaev Date: Wed, 21 Apr 2021 21:27:42 +0300 Subject: [PATCH 38/78] fix labels (#5340) --- .../convert_model/pytorch_specific/Convert_F3Net.md | 2 +- .../convert_model/pytorch_specific/Convert_QuartzNet.md | 2 +- .../convert_model/pytorch_specific/Convert_YOLACT.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_F3Net.md b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_F3Net.md index ae5a2a94905..a3f244fa55f 100644 --- a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_F3Net.md +++ b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_F3Net.md @@ -1,4 +1,4 @@ -# Convert PyTorch* F3Net to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_onnx_specific_Convert_F3Net} +# Convert PyTorch* F3Net to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_pytorch_specific_Convert_F3Net} [F3Net](https://github.com/weijun88/F3Net): Fusion, Feedback and Focus for Salient Object Detection diff --git a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_QuartzNet.md b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_QuartzNet.md index dde3a5688ee..de0f01ef610 100644 --- a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_QuartzNet.md +++ b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_QuartzNet.md @@ -1,4 +1,4 @@ -# Convert PyTorch* QuartzNet to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_onnx_specific_Convert_QuartzNet} +# Convert PyTorch* QuartzNet to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_pytorch_specific_Convert_QuartzNet} [NeMo project](https://github.com/NVIDIA/NeMo) provides the QuartzNet model. diff --git a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_YOLACT.md b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_YOLACT.md index 162cae36d57..ce0e582875c 100644 --- a/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_YOLACT.md +++ b/docs/MO_DG/prepare_model/convert_model/pytorch_specific/Convert_YOLACT.md @@ -1,4 +1,4 @@ -# Convert PyTorch* YOLACT to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_onnx_specific_Convert_YOLACT} +# Convert PyTorch* YOLACT to the Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_pytorch_specific_Convert_YOLACT} You Only Look At CoefficienTs (YOLACT) is a simple, fully convolutional model for real-time instance segmentation. The PyTorch\* implementation is publicly available in [this GitHub* repository](https://github.com/dbolya/yolact). From a672b9c599eccc9a629ad035f00b3a0d7b9ba394 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 22 Apr 2021 06:24:03 +0300 Subject: [PATCH 39/78] Enabled Wall for nGraph (#5270) * Enabled Wall for nGraph * Fixed Linux build * Fixed ONNX Editor and class-memaccess * Fixed topK * Fixed some builds * Fixed nGraph Python API * Use std::fill instead of cycle * Wno-unded and deprecation for app python versions --- ngraph/CMakeLists.txt | 5 +- ngraph/cmake/external_onnx.cmake | 4 +- ngraph/cmake/external_protobuf.cmake | 4 +- .../runtime/reference/detection_output.hpp | 2 +- .../reference/embedding_bag_offsets_sum.hpp | 2 +- .../reference/embedding_bag_packed_sum.hpp | 2 +- .../reference/embedding_segments_sum.hpp | 2 +- .../ngraph/runtime/reference/interpolate.hpp | 15 +- .../reference/src/coordinate_transform.cpp | 3 - ngraph/core/src/function.cpp | 26 +-- ngraph/core/src/op/mvn.cpp | 2 +- ngraph/core/src/op/topk.cpp | 5 +- ngraph/core/src/op/util/rnn_cell_base.cpp | 4 +- ngraph/core/src/pass/graph_rewrite.cpp | 62 +++---- ngraph/core/src/pass/manager.cpp | 4 +- ngraph/core/src/pass/visualize_tree.cpp | 158 ++++++++--------- ngraph/core/src/validation_util.cpp | 4 +- ngraph/frontend/onnx_editor/src/editor.cpp | 4 +- .../frontend/onnx_import/src/core/graph.cpp | 14 +- .../frontend/onnx_import/src/core/graph.hpp | 2 + .../onnx_import/src/core/graph_cache.hpp | 2 + ngraph/frontend/onnx_import/src/op/slice.cpp | 8 - ngraph/python/CMakeLists.txt | 6 +- ngraph/test/CMakeLists.txt | 4 + ngraph/test/op_is.cpp | 162 ------------------ ngraph/test/runtime/ie/ie_tensor.cpp | 2 +- .../runtime/interpreter/evaluates_map.cpp | 11 +- ngraph/test/type_prop/shape_of.cpp | 6 +- ngraph/test/util/test_case.hpp | 4 +- 29 files changed, 180 insertions(+), 349 deletions(-) diff --git a/ngraph/CMakeLists.txt b/ngraph/CMakeLists.txt index ed4481812be..ae54a346eed 100644 --- a/ngraph/CMakeLists.txt +++ b/ngraph/CMakeLists.txt @@ -198,10 +198,7 @@ if (WIN32) endif() if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnonnull-compare") - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror") endif() if(WIN32) diff --git a/ngraph/cmake/external_onnx.cmake b/ngraph/cmake/external_onnx.cmake index d2502a21bc2..7bf427e1a79 100644 --- a/ngraph/cmake/external_onnx.cmake +++ b/ngraph/cmake/external_onnx.cmake @@ -34,8 +34,8 @@ macro(onnx_set_target_properties) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(onnx PRIVATE /WX-) elseif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") - target_compile_options(onnx PRIVATE -Wno-unused-variable -Wno-unused-parameter) - target_compile_options(onnx_proto PRIVATE -Wno-unused-variable) + target_compile_options(onnx PRIVATE -Wno-all) + target_compile_options(onnx_proto PRIVATE -Wno-all) # it fixes random problems with double registration of descriptors to protobuf database set_target_properties(onnx_proto PROPERTIES diff --git a/ngraph/cmake/external_protobuf.cmake b/ngraph/cmake/external_protobuf.cmake index e185989550e..4cba9620c71 100644 --- a/ngraph/cmake/external_protobuf.cmake +++ b/ngraph/cmake/external_protobuf.cmake @@ -93,14 +93,14 @@ else() if(TARGET libprotoc) list(APPEND _proto_libs libprotoc) set_target_properties(libprotoc PROPERTIES - COMPILE_FLAGS "-Wno-unused-variable -Wno-sign-compare") + COMPILE_FLAGS "-Wno-all") endif() set_target_properties(${_proto_libs} PROPERTIES CXX_VISIBILITY_PRESET default C_VISIBILITY_PRESET default VISIBILITY_INLINES_HIDDEN OFF) set_target_properties(libprotobuf libprotobuf-lite PROPERTIES - COMPILE_FLAGS "-Wno-unused-variable -Wno-sign-compare -Wno-inconsistent-missing-override") + COMPILE_FLAGS "-Wno-all -Wno-inconsistent-missing-override") endif() if(NGRAPH_USE_PROTOBUF_LITE) diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp index e848f4b0383..42a2d59d07b 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp @@ -562,7 +562,7 @@ namespace ngraph const dataType* _armLocation, dataType* result) { - std::memset(result, 0, outTotalSize * sizeof(dataType)); + std::fill(result, result + outTotalSize, dataType{0}); bool withAddBoxPred = _armConfidence != nullptr && _armLocation != nullptr; std::vector armLocPreds; if (withAddBoxPred) diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp index e79ba1c6a90..83e77d3d5ce 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp @@ -32,7 +32,7 @@ namespace ngraph { embDepth *= outShape[i]; } - memset(out, 0, shape_size(outShape) * sizeof(T)); + std::fill(out, out + shape_size(outShape), T{0}); auto get_indices = [&](size_t emb_index, const U*& indices_ref, diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp index 1d2d62a217b..0f67df7f9e1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp @@ -27,7 +27,7 @@ namespace ngraph { embDepth *= outShape[i]; } - memset(out, 0, shape_size(outShape) * sizeof(T)); + std::fill(out, out + shape_size(outShape), T{0}); bool with_weights = (weights != nullptr); size_t idx_idx = 0lu; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp index 2def4384184..817981e17c8 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp @@ -31,7 +31,7 @@ namespace ngraph { embDepth *= outShape[i]; } - memset(out, 0, shape_size(outShape) * sizeof(T)); + std::fill(out, out + shape_size(outShape), T{0}); bool with_weights = (weights != nullptr); diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp index 7741dd413cf..5575201e3cf 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp @@ -39,8 +39,7 @@ namespace ngraph /// /// \param mode the mode of the calculation of the nearest pixel GetNearestPixel(Nearest_mode mode) - : m_mode{mode} - , m_func{get_func(mode)} + : m_func{get_func(mode)} { } @@ -60,7 +59,6 @@ namespace ngraph private: using Func = std::function; - Nearest_mode m_mode; Func m_func; /// \brief Gets the function to calculate the nearest pixel. @@ -121,8 +119,7 @@ namespace ngraph /// /// \param mode the mode of the calculation of the source coordinate. GetOriginalCoordinate(Transform_mode mode) - : m_mode{mode} - , m_func{get_func(mode)} + : m_func{get_func(mode)} { } @@ -151,7 +148,6 @@ namespace ngraph private: using Func = std::function; - Transform_mode m_mode; Func m_func; /// \brief Gets the function to calculate the source coordinate. @@ -209,9 +205,7 @@ namespace ngraph const std::vector& scales) : m_get_nearest_pixel{attrs.nearest_mode} , m_get_original_coord{attrs.coordinate_transformation_mode} - , m_interp_mode{attrs.mode} , m_antialias{attrs.antialias} - , m_cube_coeff{attrs.cube_coeff} , m_input_data_shape{input_data_shape} , m_axes{axes} , m_out_shape{out_shape} @@ -284,9 +278,7 @@ namespace ngraph private: GetNearestPixel m_get_nearest_pixel; GetOriginalCoordinate m_get_original_coord; - InterpolateMode m_interp_mode; bool m_antialias; - double m_cube_coeff; Shape m_input_data_shape; std::vector m_axes; @@ -465,7 +457,8 @@ namespace ngraph (m_axes == axes_without_batch_and_channels)); } - assert(correct_axes); + if (!correct_axes) + throw ngraph_error("Axes are not correct!"); const auto info = helper.get_info_for_generic_linear_onnx(); diff --git a/ngraph/core/reference/src/coordinate_transform.cpp b/ngraph/core/reference/src/coordinate_transform.cpp index d6004e158f0..e1f849f2bed 100644 --- a/ngraph/core/reference/src/coordinate_transform.cpp +++ b/ngraph/core/reference/src/coordinate_transform.cpp @@ -425,8 +425,6 @@ size_t CoordinateIterator::advance(size_t axis) noexcept if (m_oob) return m_target_shape.size(); - bool carry_out = false; - // Increment the target coordinate. do { @@ -440,7 +438,6 @@ size_t CoordinateIterator::advance(size_t axis) noexcept else { m_coordinate[axis] = 0; - carry_out = true; } } while (axis-- > 0); diff --git a/ngraph/core/src/function.cpp b/ngraph/core/src/function.cpp index de7633497b8..b2d831470c6 100644 --- a/ngraph/core/src/function.cpp +++ b/ngraph/core/src/function.cpp @@ -24,11 +24,11 @@ atomic Function::m_next_instance_id(0); Function::Function(const ResultVector& results, const ParameterVector& parameters, const std::string& name) - : m_results(results) - , m_parameters(parameters) - , m_name(name) + : m_name(name) , m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))) , m_topological_sorter(topological_sort>>) + , m_results(results) + , m_parameters(parameters) { check_all_parameters_registered(); } @@ -36,11 +36,11 @@ Function::Function(const ResultVector& results, Function::Function(const OutputVector& results, const ParameterVector& parameters, const std::string& name) - : m_results(as_result_vector(results)) - , m_parameters(parameters) - , m_name(name) + : m_name(name) , m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))) , m_topological_sorter(topological_sort>>) + , m_results(as_result_vector(results)) + , m_parameters(parameters) { check_all_parameters_registered(); } @@ -48,11 +48,11 @@ Function::Function(const OutputVector& results, Function::Function(const NodeVector& results, const ParameterVector& parameters, const std::string& name) - : m_results(as_result_vector(as_output_vector(results))) - , m_parameters(parameters) - , m_name(name) + : m_name(name) , m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))) , m_topological_sorter(topological_sort>>) + , m_results(as_result_vector(as_output_vector(results))) + , m_parameters(parameters) { check_all_parameters_registered(); } @@ -68,12 +68,12 @@ Function::Function(const ResultVector& results, const SinkVector& sinks, const ParameterVector& parameters, const std::string& name) - : m_results(results) - , m_sinks(sinks) - , m_parameters(parameters) - , m_name(name) + : m_name(name) , m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))) , m_topological_sorter(topological_sort>>) + , m_results(results) + , m_sinks(sinks) + , m_parameters(parameters) { check_all_parameters_registered(); } diff --git a/ngraph/core/src/op/mvn.cpp b/ngraph/core/src/op/mvn.cpp index 8c10bc133ce..00d790c6241 100644 --- a/ngraph/core/src/op/mvn.cpp +++ b/ngraph/core/src/op/mvn.cpp @@ -154,8 +154,8 @@ op::v6::MVN::MVN(const Output& data, float eps, MVNEpsMode eps_mode) : Op({data, reduction_axes}) - , m_eps{eps} , m_normalize_variance{normalize_variance} + , m_eps{eps} , m_eps_mode{eps_mode} { constructor_validate_and_infer_types(); diff --git a/ngraph/core/src/op/topk.cpp b/ngraph/core/src/op/topk.cpp index 167c4475247..68cbb175421 100644 --- a/ngraph/core/src/op/topk.cpp +++ b/ngraph/core/src/op/topk.cpp @@ -271,11 +271,10 @@ void op::v1::TopK::validate_and_infer_types() "Index element type attribute should be either \'i32\' or \'i64\'. Got: ", m_index_element_type); - size_t k = 0; if (op::is_constant(input_value(1).get_node())) { - k = read_k_from_constant_node(input_value(1).get_node_shared_ptr(), - get_input_element_type(1)); + // Check k value + read_k_from_constant_node(input_value(1).get_node_shared_ptr(), get_input_element_type(1)); } PartialShape output_shape{input_partial_shape}; diff --git a/ngraph/core/src/op/util/rnn_cell_base.cpp b/ngraph/core/src/op/util/rnn_cell_base.cpp index 923455a0f41..e087cacdfb2 100644 --- a/ngraph/core/src/op/util/rnn_cell_base.cpp +++ b/ngraph/core/src/op/util/rnn_cell_base.cpp @@ -55,8 +55,8 @@ static vector to_lower_case(const vector& vs) } op::util::RNNCellBase::RNNCellBase() - : m_clip(0.f) - , m_hidden_size(0) + : m_hidden_size(0) + , m_clip(0.f) { } diff --git a/ngraph/core/src/pass/graph_rewrite.cpp b/ngraph/core/src/pass/graph_rewrite.cpp index 5c92e9760e9..251636ea19f 100644 --- a/ngraph/core/src/pass/graph_rewrite.cpp +++ b/ngraph/core/src/pass/graph_rewrite.cpp @@ -20,37 +20,37 @@ using namespace std; using namespace ngraph; -// GraphRewrite algorithm: -// GraphRewrite processes an input graph in an topological order(i.e. args before users) -// Given the following graph: Abs2 -// / \ -// Constant1 Add4 - Result5 -// \ / -// Neg3 -// -// The topological order would be : `Constant1`, `Abs2`, `Neg3`, `Add4`, `Result5` -// Note, `Abs2` comes before `Neg3` as `Abs2`'s id = 2 is *less* than `Neg3`'s one (id = 3) -// Next, GraphRewrite will invoke matchers passes registered in add_matcher order. -// For example: -// ngraph::pass::GraphRewrite pass; -// pass.add_matcher(); -// pass.add_matcher(); -// pass.add_matcher(); -// Matcher passes will be called as follows: `m1`, `m2`, `m3` -// Matchers should only replace nodes in the graph that come before the current root -// node in the topological order. For example, if Matcher matches Neg3, it should only -// replace nodes `Abs2` and `Constant1` if needed -// This gives Matchers a nice cascading property. For example, if m1 folds `Abs2(Constant1)` -// and `m2` folds `Neg3(Constant1)` when `m3` is called on `Add4` it will discover that -// both `Abs2` and `Neg3` were already replaced by constants, so `Add4` will also be folded into -// one. -// If any matcher passes succeeds the rest of the matchers will **not** be called. -// E.g. if `m1` succeeds and replaces `Abs2` with a new constant, nor `m2` or `m3` will be called -// However, sometimes, you will need more than one fusion occur on the same node. -// In this case, you need to register nodes in MatcherPass manually using register_new_node method. -// GraphRewrite will automatically add this nodes in the beginning of execution queue. -// If MatcherPass register more than one node make sure that this nodes are registered in -// topological order. +/* GraphRewrite algorithm: + * GraphRewrite processes an input graph in an topological order(i.e. args before users) + * Given the following graph: Abs2 + * / \ + * Constant1 Add4 - Result5 + * \ / + * Neg3 + * + * The topological order would be : `Constant1`, `Abs2`, `Neg3`, `Add4`, `Result5` + * Note, `Abs2` comes before `Neg3` as `Abs2`'s id = 2 is *less* than `Neg3`'s one (id = 3) + * Next, GraphRewrite will invoke matchers passes registered in add_matcher order. + * For example: + * ngraph::pass::GraphRewrite pass; + * pass.add_matcher(); + * pass.add_matcher(); + * pass.add_matcher(); + * Matcher passes will be called as follows: `m1`, `m2`, `m3` + * Matchers should only replace nodes in the graph that come before the current root + * node in the topological order. For example, if Matcher matches Neg3, it should only + * replace nodes `Abs2` and `Constant1` if needed + * This gives Matchers a nice cascading property. For example, if m1 folds `Abs2(Constant1)` + * and `m2` folds `Neg3(Constant1)` when `m3` is called on `Add4` it will discover that + * both `Abs2` and `Neg3` were already replaced by constants, so `Add4` will also be folded into + * one. + * If any matcher passes succeeds the rest of the matchers will **not** be called. + * E.g. if `m1` succeeds and replaces `Abs2` with a new constant, nor `m2` or `m3` will be called + * However, sometimes, you will need more than one fusion occur on the same node. + * In this case, you need to register nodes in MatcherPass manually using register_new_node method. + * GraphRewrite will automatically add this nodes in the beginning of execution queue. + * If MatcherPass register more than one node make sure that this nodes are registered in + * topological order. */ NGRAPH_RTTI_DEFINITION(ngraph::pass::GraphRewrite, "ngraph::pass::GraphRewrite", 0); diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index b5b1a460aa5..e25e4b30d7d 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -41,8 +41,8 @@ namespace ngraph } pass::Manager::Manager() - : m_visualize(getenv_bool("NGRAPH_ENABLE_VISUALIZE_TRACING")) - , m_pass_config(std::make_shared()) + : m_pass_config(std::make_shared()) + , m_visualize(getenv_bool("NGRAPH_ENABLE_VISUALIZE_TRACING")) { } diff --git a/ngraph/core/src/pass/visualize_tree.cpp b/ngraph/core/src/pass/visualize_tree.cpp index 75afd06112d..dfed1d05640 100644 --- a/ngraph/core/src/pass/visualize_tree.cpp +++ b/ngraph/core/src/pass/visualize_tree.cpp @@ -20,85 +20,85 @@ using namespace ngraph; using namespace std; -// -// As we are visualizing the graph, we will make some tweaks to the generated dot file to make -// routing more tractable for Graphviz as well as (hopefully) more legible for the user. -// -// NOTE: It's possible, even likely, that better algorithms are available here. I just tried a -// few different things without doing much research, and this seemed to work well. Please feel -// free to improve on this. --amprocte -// -// ----------------- -// -// The first tweak is to trim edges that, intuitively speaking, have long "skip distance". For -// example: -// -// [Actual Graph Structure] [Visualization] -// n0 n0 -// | \ | \ -// n1 \ n1 [to n50] -// | | | -// n2 | n2 -// | | | -// n3 | n3 -// | | | -// ... | ... [from n0] -// | / | / -// n50 n50 -// -// This is useful for training graphs especially, which tend to have very long feed-forward edges -// for intermediate values from fprop being stored for later reuse in the bprop phase. -// -// Efficiently detecting a "long skip" is a bit tricky. We want to come up with a metric that is -// reasonably fast to compute, but does not result in cuts that will split the graph into multiple -// components. The heuristic we are using for the jump distance between n and m is the maximum -// difference in maximum path length from n and m to any result node that is reachable from both -// n and m (or 0, if no such result node exists). Not sure if this is mathematically *guaranteed* -// not to split graph components, but it seems to work well in practice. -// -// Formally: -// -// Compute-Heights-Above-Each-Parameter(N): -// Inputs: nodes N; define R={n in N | n is a Result node} -// Output: height_maps: map from N to (map from R to int) -// -// height_maps is initially empty -// -// for each r in R: -// Insert into height_map the map {r -> 1} -// -// for each n in N in reverse topological ("results-first") order: -// for each user m of n: -// for each r in height_maps[m].keys: -// height_maps[n][r] := max(height_maps[n][r], height_maps[m][r]+1) -// -// Jump-Distance(n,m,height_maps): -// Inputs: n (source node), m (destination node), height_maps (pre-computed above) -// Output: jump_distance: int -// -// jump_distance := 0 -// -// for each r in height_maps[n].keys: -// if r is in height_maps[m].keys: -// jump_distance := max(jump_distance, abs(height_maps[n][r] - height_maps[m][r])) -// -// Later on, if E is an edge from n to m, and Jump-Distance(n,m,height_map) > K (where K is kind -// of arbitrary but currently set to 20), we will "cut" the edge as illustrated above. -// -// ----------------- -// -// The second tweak aims to eliminate routing pressure from nodes that have large outdegree and -// are connected to many otherwise-distant places in the graph. For this, the only thing we are -// doing at the moment is to "float" Parameter and Constant nodes. This means that rather than -// visualizing them as a single node (which might have very large outdegree as in, e.g., a -// learning rate parameter being fed to many different places), we make a "copy" of the node at -// each occurrence site (with a dashed outline). -// -// NOTE: This tweak could probably be extended to float other kinds of nodes with high out-degree. -// (This situation is likely to arise after constant subexpression elimination.) Here one has to -// be careful to avoid splitting the components. I have some rough ideas on how this could be -// dealt with, but have not had time to implement them yet. --amprocte -// +/* + * As we are visualizing the graph, we will make some tweaks to the generated dot file to make + * routing more tractable for Graphviz as well as (hopefully) more legible for the user. + * + * NOTE: It's possible, even likely, that better algorithms are available here. I just tried a + * few different things without doing much research, and this seemed to work well. Please feel + * free to improve on this. --amprocte + * + * ----------------- + * + * The first tweak is to trim edges that, intuitively speaking, have long "skip distance". For + * example: + * + * [Actual Graph Structure] [Visualization] + * n0 n0 + * | \ | \ + * n1 \ n1 [to n50] + * | | | + * n2 | n2 + * | | | + * n3 | n3 + * | | | + * ... | ... [from n0] + * | / | / + * n50 n50 + * + * This is useful for training graphs especially, which tend to have very long feed-forward edges + * for intermediate values from fprop being stored for later reuse in the bprop phase. + * + * Efficiently detecting a "long skip" is a bit tricky. We want to come up with a metric that is + * reasonably fast to compute, but does not result in cuts that will split the graph into multiple + * components. The heuristic we are using for the jump distance between n and m is the maximum + * difference in maximum path length from n and m to any result node that is reachable from both + * n and m (or 0, if no such result node exists). Not sure if this is mathematically *guaranteed* + * not to split graph components, but it seems to work well in practice. + * + * Formally: + * + * Compute-Heights-Above-Each-Parameter(N): + * Inputs: nodes N; define R={n in N | n is a Result node} + * Output: height_maps: map from N to (map from R to int) + * + * height_maps is initially empty + * + * for each r in R: + * Insert into height_map the map {r -> 1} + * + * for each n in N in reverse topological ("results-first") order: + * for each user m of n: + * for each r in height_maps[m].keys: + * height_maps[n][r] := max(height_maps[n][r], height_maps[m][r]+1) + * + * Jump-Distance(n,m,height_maps): + * Inputs: n (source node), m (destination node), height_maps (pre-computed above) + * Output: jump_distance: int + * + * jump_distance := 0 + * + * for each r in height_maps[n].keys: + * if r is in height_maps[m].keys: + * jump_distance := max(jump_distance, abs(height_maps[n][r] - height_maps[m][r])) + * + * Later on, if E is an edge from n to m, and Jump-Distance(n,m,height_map) > K (where K is kind + * of arbitrary but currently set to 20), we will "cut" the edge as illustrated above. + * + * ----------------- + * + * The second tweak aims to eliminate routing pressure from nodes that have large outdegree and + * are connected to many otherwise-distant places in the graph. For this, the only thing we are + * doing at the moment is to "float" Parameter and Constant nodes. This means that rather than + * visualizing them as a single node (which might have very large outdegree as in, e.g., a + * learning rate parameter being fed to many different places), we make a "copy" of the node at + * each occurrence site (with a dashed outline). + * + * NOTE: This tweak could probably be extended to float other kinds of nodes with high out-degree. + * (This situation is likely to arise after constant subexpression elimination.) Here one has to + * be careful to avoid splitting the components. I have some rough ideas on how this could be + * dealt with, but have not had time to implement them yet. --amprocte + */ const int ngraph::pass::VisualizeTree::max_jump_distance = 20; diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index 639f3b8891b..adba109aa45 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -485,8 +485,8 @@ PartialShape ngraph::infer_batched_pooling_forward(const Node* node, { NODE_VALIDATION_CHECK(node, data_batch_shape.rank().is_dynamic() || - data_batch_shape.rank().get_length() >= 3 && - data_batch_shape.rank().get_length() <= 5, + (data_batch_shape.rank().get_length() >= 3 && + data_batch_shape.rank().get_length() <= 5), "Data batch must have rank of at least 4 or 5 (one batch axis, ", "one input-channel axis, and two or three spatial dimension) ", "(data batch shape: ", diff --git a/ngraph/frontend/onnx_editor/src/editor.cpp b/ngraph/frontend/onnx_editor/src/editor.cpp index ac849a5b0c0..566659e6633 100644 --- a/ngraph/frontend/onnx_editor/src/editor.cpp +++ b/ngraph/frontend/onnx_editor/src/editor.cpp @@ -199,8 +199,8 @@ struct onnx_editor::ONNXModelEditor::Impl }; onnx_editor::ONNXModelEditor::ONNXModelEditor(const std::string& model_path) - : m_pimpl{new ONNXModelEditor::Impl{model_path}, [](Impl* impl) { delete impl; }} - , m_model_path{model_path} + : m_model_path{model_path} + , m_pimpl{new ONNXModelEditor::Impl{model_path}, [](Impl* impl) { delete impl; }} { } diff --git a/ngraph/frontend/onnx_import/src/core/graph.cpp b/ngraph/frontend/onnx_import/src/core/graph.cpp index d373654ec9e..e5323b67fa2 100644 --- a/ngraph/frontend/onnx_import/src/core/graph.cpp +++ b/ngraph/frontend/onnx_import/src/core/graph.cpp @@ -75,13 +75,23 @@ namespace ngraph param_it++; } } + Graph::Graph(const Graph& graph) + : m_parameters(graph.m_parameters) + , m_cache{new GraphCache(*graph.m_cache)} + , m_graph_proto{graph.m_graph_proto} + , m_nodes(graph.m_nodes) + , m_inputs(graph.m_inputs) + , m_outputs(graph.m_outputs) + , m_model{graph.m_model} + { + } Graph::Graph(const ONNX_NAMESPACE::GraphProto& graph_proto, Model& model, std::unique_ptr&& cache) - : m_graph_proto{&graph_proto} + : m_cache{std::move(cache)} + , m_graph_proto{&graph_proto} , m_model{&model} - , m_cache{std::move(cache)} { std::map initializers; // Process all initializers in the graph diff --git a/ngraph/frontend/onnx_import/src/core/graph.hpp b/ngraph/frontend/onnx_import/src/core/graph.hpp index 405bfe94f31..14e3e72f40c 100644 --- a/ngraph/frontend/onnx_import/src/core/graph.hpp +++ b/ngraph/frontend/onnx_import/src/core/graph.hpp @@ -24,6 +24,7 @@ namespace ngraph { public: Graph(const ONNX_NAMESPACE::GraphProto& proto, Model& model); + Graph(const Graph& graph); const std::vector& get_nodes() const { return m_nodes; } const std::vector& get_inputs() const { return m_inputs; } const std::vector& get_outputs() const { return m_outputs; } @@ -35,6 +36,7 @@ namespace ngraph OutputVector make_ng_nodes(const Node& onnx_node) const; const GraphCache& get_graph_cache() const; const OpsetImports& get_opset_imports() const; + virtual ~Graph() = default; protected: Graph(const ONNX_NAMESPACE::GraphProto& proto, diff --git a/ngraph/frontend/onnx_import/src/core/graph_cache.hpp b/ngraph/frontend/onnx_import/src/core/graph_cache.hpp index bdf3a890bd4..a59af9b4a9f 100644 --- a/ngraph/frontend/onnx_import/src/core/graph_cache.hpp +++ b/ngraph/frontend/onnx_import/src/core/graph_cache.hpp @@ -68,6 +68,8 @@ namespace ngraph /// is avalible in parent_graph_cache, otherwise Lack virtual NodeScope node_scope(const std::string& name) const; + virtual ~GraphCache() = default; + private: std::map> m_graph_cache_map; }; diff --git a/ngraph/frontend/onnx_import/src/op/slice.cpp b/ngraph/frontend/onnx_import/src/op/slice.cpp index 04c1ada1aec..eae53e4b7c3 100644 --- a/ngraph/frontend/onnx_import/src/op/slice.cpp +++ b/ngraph/frontend/onnx_import/src/op/slice.cpp @@ -15,14 +15,6 @@ #include "op/gather.hpp" #include "utils/common.hpp" -namespace -{ - int64_t get_valid_array_idx(int64_t idx, int64_t last_idx) - { - return (idx >= 0) ? std::min(idx, last_idx) : std::max(0, last_idx + idx); - } -} - namespace ngraph { namespace onnx_import diff --git a/ngraph/python/CMakeLists.txt b/ngraph/python/CMakeLists.txt index abb1078689f..cacaa1b669a 100644 --- a/ngraph/python/CMakeLists.txt +++ b/ngraph/python/CMakeLists.txt @@ -57,16 +57,16 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # disable warning: This operator was deprecated and will be removed with v0 operation. add_compile_options(/wd4996) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - add_compile_options(-Wno-deprecated-register) + add_compile_options(-Wno-deprecated-register -Wno-range-loop-analysis) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") add_link_options(-stdlib=libc++) - add_compile_options(-Wno-unused-value) + add_compile_options(-Wno-unused-value -Wno-range-loop-analysis) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # WA for GCC 7.5 "PYBIND11_NOINLINE inline" warning add_compile_options(-Wno-error=attributes) endif() -if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND Python_VERSION VERSION_GREATER_EQUAL "3.9") +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # for proper fix need to update pybind to version which does not use PyEval_InitThreads() add_compile_options(-Wno-deprecated-declarations -Wno-undef) endif() diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 6ac7d9c7fe4..de311ee3261 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -497,6 +497,10 @@ if(NOT WIN32) endif() target_link_libraries(unit-test PRIVATE ${CMAKE_DL_LIBS}) +if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(unit-test PRIVATE -Wno-missing-braces) +endif() + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$") target_compile_options(unit-test PRIVATE -Wno-undef -Wno-reserved-id-macro) endif() diff --git a/ngraph/test/op_is.cpp b/ngraph/test/op_is.cpp index 2265f9638ba..0495c1e663e 100644 --- a/ngraph/test/op_is.cpp +++ b/ngraph/test/op_is.cpp @@ -188,33 +188,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_EmbeddingBagOffsetsSum() - { - op::EmbeddingBagOffsetsSum node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - - void op_is_EmbeddingBagPackedSum() - { - op::EmbeddingBagPackedSum node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - - void op_is_EmbeddingSegmentsSum() - { - op::EmbeddingSegmentsSum node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Erf() { op::Erf node; @@ -233,15 +206,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_ExtractImagePatches() - { - op::ExtractImagePatches node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_FakeQuantize() { op::FakeQuantize node; @@ -269,15 +233,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_GRUCell() - { - op::v3::GRUCell node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Gather() { op::v1::Gather node; @@ -287,15 +242,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_GatherND() - { - op::v5::GatherND node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Gelu() { op::Gelu node; @@ -350,15 +296,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_LogicalOr() - { - op::v1::LogicalOr node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_TRUE(op::is_binary_elementwise_logical(&node)); - } - void op_is_LRN() { op::LRN node; @@ -368,15 +305,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_LSTMCell() - { - op::v4::LSTMCell node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_LSTMSequence() { op::v0::LSTMSequence node; @@ -422,15 +350,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_OneHot() - { - op::v1::OneHot node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Parameter() { op::Parameter node; @@ -458,15 +377,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_ReduceProd() - { - op::v1::ReduceProd node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Range() { op::Range node; @@ -476,15 +386,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_ReduceSum() - { - op::v1::ReduceSum node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Relu() { op::Relu node; @@ -494,15 +395,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_Reshape() - { - op::v1::Reshape node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Result() { op::Result node; @@ -512,15 +404,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_Reverse() - { - op::v1::Reverse node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_ReverseSequence() { op::ReverseSequence node; @@ -530,24 +413,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_RNNCell() - { - op::v0::RNNCell node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - - void op_is_Round() - { - op::v5::Round node; - EXPECT_TRUE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Selu() { op::Selu node; @@ -611,15 +476,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_Softmax() - { - op::v1::Softmax node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_SpaceToDepth() { op::SpaceToDepth node; @@ -629,15 +485,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_Split() - { - op::v1::Split node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Sqrt() { op::Sqrt node; @@ -701,15 +548,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_TopK() - { - op::v1::TopK node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_Unsqueeze() { op::v0::Unsqueeze node; diff --git a/ngraph/test/runtime/ie/ie_tensor.cpp b/ngraph/test/runtime/ie/ie_tensor.cpp index 88b7f79ea97..fd4e8468f92 100644 --- a/ngraph/test/runtime/ie/ie_tensor.cpp +++ b/ngraph/test/runtime/ie/ie_tensor.cpp @@ -34,7 +34,7 @@ void runtime::ie::IETensor::write(const void* src, size_t bytes) } if (get_partial_shape().is_dynamic()) { - m_data = move(AlignedBuffer(bytes)); + m_data = AlignedBuffer(bytes); } NGRAPH_CHECK(m_data.size() <= bytes, "Buffer over-write. The buffer size: ", diff --git a/ngraph/test/runtime/interpreter/evaluates_map.cpp b/ngraph/test/runtime/interpreter/evaluates_map.cpp index 8e711c29dcb..94a47220589 100644 --- a/ngraph/test/runtime/interpreter/evaluates_map.cpp +++ b/ngraph/test/runtime/interpreter/evaluates_map.cpp @@ -922,8 +922,8 @@ namespace Shape output_shape; }; - std::vector get_signal_size( - const std::vector>& inputs, size_t num_of_axes) + std::vector get_signal_size(const std::vector>& inputs, + size_t num_of_axes) { if (inputs.size() == 3) { @@ -946,9 +946,8 @@ namespace int64_t input_rank = static_cast(result.input_data_shape.size()); int64_t complex_data_rank = input_rank - 1; - auto canonicalized_axes = runtime::reference::canonicalize_axes(result.axes_data.data(), - result.axes_data_shape, - complex_data_rank); + auto canonicalized_axes = runtime::reference::canonicalize_axes( + result.axes_data.data(), result.axes_data_shape, complex_data_rank); size_t num_of_axes = result.axes_data.size(); auto signal_size = get_signal_size(inputs, num_of_axes); @@ -1971,7 +1970,6 @@ namespace const HostTensorVector& outputs, const HostTensorVector& inputs) { - using T = typename element_type_traits::value_type; runtime::reference::pad(inputs[0]->get_data_ptr(), inputs[1]->get_data_ptr(), outputs[0]->get_data_ptr(), @@ -1989,7 +1987,6 @@ namespace const HostTensorVector& outputs, const HostTensorVector& inputs) { - using T = typename element_type_traits::value_type; runtime::reference::gather_tree(inputs[0]->get_data_ptr(), inputs[1]->get_data_ptr(), inputs[2]->get_data_ptr(), diff --git a/ngraph/test/type_prop/shape_of.cpp b/ngraph/test/type_prop/shape_of.cpp index d15597cb25a..d1c6d0de6b7 100644 --- a/ngraph/test/type_prop/shape_of.cpp +++ b/ngraph/test/type_prop/shape_of.cpp @@ -92,7 +92,7 @@ TEST(type_prop, shape_of_output_type_v3) auto sx = make_shared(a, element::i8); FAIL() << "Invalid output_type not detected"; } - catch (NodeValidationFailure) + catch (const NodeValidationFailure&) { } catch (...) @@ -104,7 +104,7 @@ TEST(type_prop, shape_of_output_type_v3) auto sx = make_shared(a, element::i16); FAIL() << "Invalid output_type not detected"; } - catch (NodeValidationFailure) + catch (const NodeValidationFailure&) { } catch (...) @@ -116,7 +116,7 @@ TEST(type_prop, shape_of_output_type_v3) auto sx = make_shared(a, element::f32); FAIL() << "Invalid output_type not detected"; } - catch (NodeValidationFailure) + catch (const NodeValidationFailure&) { } catch (...) diff --git a/ngraph/test/util/test_case.hpp b/ngraph/test/util/test_case.hpp index 2bb5e524a3e..e59d3ce3f82 100644 --- a/ngraph/test/util/test_case.hpp +++ b/ngraph/test/util/test_case.hpp @@ -25,8 +25,8 @@ namespace ngraph { public: TestCase(const std::shared_ptr& function) - : m_function{function} - , m_engine{create_engine(function, tct)} + : m_engine{create_engine(function, tct)} + , m_function{function} { } From 9d37403f893b0e1983bb81882bd0ef2fef66f8f1 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 22 Apr 2021 08:06:54 +0300 Subject: [PATCH 40/78] Changed clang-format for nGraph to fix namespace comments (#5269) * Changed clang-format for nGraph to fix namepace comments * Update comments * Fixed code style --- ngraph/.clang-format | 2 +- .../include/ngraph/builder/make_constant.hpp | 4 ++-- .../builder/include/ngraph/builder/norm.hpp | 4 ++-- .../include/ngraph/builder/reduce_ops.hpp | 2 +- .../include/ngraph/builder/reshape.hpp | 4 ++-- .../builder/include/ngraph/builder/split.hpp | 4 ++-- .../builder/src/builder/make_constant.cpp | 4 ++-- ngraph/core/builder/src/builder/norm.cpp | 4 ++-- ngraph/core/builder/src/builder/reshape.cpp | 8 +++---- .../core/include/ngraph/attribute_adapter.hpp | 2 +- .../core/include/ngraph/attribute_visitor.hpp | 2 +- ngraph/core/include/ngraph/axis_set.hpp | 2 +- ngraph/core/include/ngraph/axis_vector.hpp | 2 +- ngraph/core/include/ngraph/check.hpp | 2 +- ngraph/core/include/ngraph/coordinate.hpp | 2 +- .../core/include/ngraph/coordinate_diff.hpp | 2 +- .../core/include/ngraph/descriptor/input.hpp | 4 ++-- .../core/include/ngraph/descriptor/output.hpp | 4 ++-- .../core/include/ngraph/descriptor/tensor.hpp | 4 ++-- ngraph/core/include/ngraph/dimension.hpp | 2 +- ngraph/core/include/ngraph/distributed.hpp | 4 ++-- ngraph/core/include/ngraph/enum_names.hpp | 2 +- ngraph/core/include/ngraph/env_util.hpp | 2 +- ngraph/core/include/ngraph/evaluator.hpp | 2 +- ngraph/core/include/ngraph/except.hpp | 2 +- .../core/include/ngraph/factory_adapter.hpp | 2 +- ngraph/core/include/ngraph/file_util.hpp | 4 ++-- ngraph/core/include/ngraph/graph_util.hpp | 6 ++--- ngraph/core/include/ngraph/interval.hpp | 2 +- ngraph/core/include/ngraph/log.hpp | 2 +- ngraph/core/include/ngraph/ngraph.hpp | 2 +- ngraph/core/include/ngraph/node.hpp | 2 +- ngraph/core/include/ngraph/node_input.hpp | 2 +- ngraph/core/include/ngraph/node_output.hpp | 2 +- ngraph/core/include/ngraph/op/abs.hpp | 6 ++--- ngraph/core/include/ngraph/op/acos.hpp | 6 ++--- ngraph/core/include/ngraph/op/acosh.hpp | 6 ++--- ngraph/core/include/ngraph/op/and.hpp | 4 ++-- ngraph/core/include/ngraph/op/asin.hpp | 6 ++--- ngraph/core/include/ngraph/op/asinh.hpp | 6 ++--- ngraph/core/include/ngraph/op/assign.hpp | 8 +++---- ngraph/core/include/ngraph/op/atan.hpp | 6 ++--- ngraph/core/include/ngraph/op/atanh.hpp | 6 ++--- ngraph/core/include/ngraph/op/batch_norm.hpp | 6 ++--- .../core/include/ngraph/op/batch_to_space.hpp | 6 ++--- .../include/ngraph/op/binary_convolution.hpp | 4 ++-- ngraph/core/include/ngraph/op/broadcast.hpp | 4 ++-- ngraph/core/include/ngraph/op/bucketize.hpp | 6 ++--- ngraph/core/include/ngraph/op/ceiling.hpp | 6 ++--- ngraph/core/include/ngraph/op/clamp.hpp | 6 ++--- ngraph/core/include/ngraph/op/concat.hpp | 6 ++--- ngraph/core/include/ngraph/op/constant.hpp | 6 ++--- ngraph/core/include/ngraph/op/convert.hpp | 6 ++--- ngraph/core/include/ngraph/op/cos.hpp | 6 ++--- ngraph/core/include/ngraph/op/cosh.hpp | 6 ++--- ngraph/core/include/ngraph/op/ctc_loss.hpp | 6 ++--- ngraph/core/include/ngraph/op/cum_sum.hpp | 6 ++--- .../ngraph/op/deformable_convolution.hpp | 6 ++--- .../ngraph/op/deformable_psroi_pooling.hpp | 6 ++--- .../core/include/ngraph/op/depth_to_space.hpp | 6 ++--- .../include/ngraph/op/detection_output.hpp | 6 ++--- ngraph/core/include/ngraph/op/dft.hpp | 6 ++--- ngraph/core/include/ngraph/op/elu.hpp | 2 +- .../ngraph/op/embedding_segments_sum.hpp | 6 ++--- .../ngraph/op/embeddingbag_offsets_sum.hpp | 6 ++--- .../ngraph/op/embeddingbag_packedsum.hpp | 6 ++--- ngraph/core/include/ngraph/op/equal.hpp | 4 ++-- ngraph/core/include/ngraph/op/erf.hpp | 6 ++--- ngraph/core/include/ngraph/op/exp.hpp | 6 ++--- ...xperimental_detectron_detection_output.hpp | 6 ++--- ...erimental_detectron_generate_proposals.hpp | 6 ++--- ...imental_detectron_prior_grid_generator.hpp | 6 ++--- .../op/experimental_detectron_roi_feature.hpp | 6 ++--- .../op/experimental_detectron_topkrois.hpp | 6 ++--- .../core/include/ngraph/op/fake_quantize.hpp | 6 ++--- ngraph/core/include/ngraph/op/floor.hpp | 6 ++--- .../include/ngraph/op/gather_elements.hpp | 6 ++--- ngraph/core/include/ngraph/op/gather_nd.hpp | 6 ++--- ngraph/core/include/ngraph/op/gather_tree.hpp | 6 ++--- ngraph/core/include/ngraph/op/gelu.hpp | 8 +++---- ngraph/core/include/ngraph/op/greater.hpp | 4 ++-- ngraph/core/include/ngraph/op/greater_eq.hpp | 4 ++-- ngraph/core/include/ngraph/op/grn.hpp | 6 ++--- ngraph/core/include/ngraph/op/gru_cell.hpp | 6 ++--- .../core/include/ngraph/op/gru_sequence.hpp | 4 ++-- .../core/include/ngraph/op/hard_sigmoid.hpp | 6 ++--- ngraph/core/include/ngraph/op/hsigmoid.hpp | 6 ++--- ngraph/core/include/ngraph/op/hswish.hpp | 6 ++--- ngraph/core/include/ngraph/op/idft.hpp | 6 ++--- ngraph/core/include/ngraph/op/less.hpp | 4 ++-- ngraph/core/include/ngraph/op/log.hpp | 6 ++--- ngraph/core/include/ngraph/op/loop.hpp | 6 ++--- ngraph/core/include/ngraph/op/lrn.hpp | 6 ++--- ngraph/core/include/ngraph/op/lstm_cell.hpp | 4 ++-- .../core/include/ngraph/op/lstm_sequence.hpp | 6 ++--- ngraph/core/include/ngraph/op/matmul.hpp | 2 +- ngraph/core/include/ngraph/op/max.hpp | 6 ++--- ngraph/core/include/ngraph/op/maximum.hpp | 4 ++-- ngraph/core/include/ngraph/op/min.hpp | 6 ++--- ngraph/core/include/ngraph/op/minimum.hpp | 4 ++-- ngraph/core/include/ngraph/op/mish.hpp | 6 ++--- ngraph/core/include/ngraph/op/mod.hpp | 4 ++-- ngraph/core/include/ngraph/op/mvn.hpp | 2 +- ngraph/core/include/ngraph/op/negative.hpp | 6 ++--- ngraph/core/include/ngraph/op/non_zero.hpp | 2 +- .../core/include/ngraph/op/normalize_l2.hpp | 6 ++--- ngraph/core/include/ngraph/op/not.hpp | 4 ++-- ngraph/core/include/ngraph/op/not_equal.hpp | 4 ++-- ngraph/core/include/ngraph/op/op.hpp | 4 ++-- ngraph/core/include/ngraph/op/pad.hpp | 6 ++--- ngraph/core/include/ngraph/op/parameter.hpp | 6 ++--- ngraph/core/include/ngraph/op/power.hpp | 4 ++-- ngraph/core/include/ngraph/op/prelu.hpp | 6 ++--- ngraph/core/include/ngraph/op/prior_box.hpp | 6 ++--- .../include/ngraph/op/prior_box_clustered.hpp | 6 ++--- ngraph/core/include/ngraph/op/proposal.hpp | 8 +++---- .../core/include/ngraph/op/psroi_pooling.hpp | 6 ++--- ngraph/core/include/ngraph/op/range.hpp | 8 +++---- ngraph/core/include/ngraph/op/read_value.hpp | 8 +++---- ngraph/core/include/ngraph/op/reduce_l1.hpp | 6 ++--- ngraph/core/include/ngraph/op/reduce_l2.hpp | 6 ++--- .../include/ngraph/op/reduce_logical_and.hpp | 6 ++--- .../include/ngraph/op/reduce_logical_or.hpp | 6 ++--- ngraph/core/include/ngraph/op/reduce_mean.hpp | 6 ++--- ngraph/core/include/ngraph/op/reduce_prod.hpp | 6 ++--- ngraph/core/include/ngraph/op/relu.hpp | 6 ++--- ngraph/core/include/ngraph/op/reorg_yolo.hpp | 6 ++--- ngraph/core/include/ngraph/op/reshape.hpp | 6 ++--- ngraph/core/include/ngraph/op/result.hpp | 6 ++--- ngraph/core/include/ngraph/op/reverse.hpp | 6 ++--- .../include/ngraph/op/reverse_sequence.hpp | 6 ++--- ngraph/core/include/ngraph/op/rnn_cell.hpp | 4 ++-- .../core/include/ngraph/op/rnn_sequence.hpp | 4 ++-- ngraph/core/include/ngraph/op/round.hpp | 6 ++--- .../ngraph/op/scatter_elements_update.hpp | 6 ++--- .../include/ngraph/op/scatter_nd_update.hpp | 6 ++--- .../core/include/ngraph/op/scatter_update.hpp | 6 ++--- ngraph/core/include/ngraph/op/selu.hpp | 2 +- ngraph/core/include/ngraph/op/shape_of.hpp | 8 +++---- .../include/ngraph/op/shuffle_channels.hpp | 6 ++--- ngraph/core/include/ngraph/op/sigmoid.hpp | 6 ++--- ngraph/core/include/ngraph/op/sign.hpp | 6 ++--- ngraph/core/include/ngraph/op/sin.hpp | 6 ++--- ngraph/core/include/ngraph/op/sinh.hpp | 6 ++--- ngraph/core/include/ngraph/op/sink.hpp | 4 ++-- ngraph/core/include/ngraph/op/softmax.hpp | 6 ++--- ngraph/core/include/ngraph/op/softplus.hpp | 6 ++--- .../core/include/ngraph/op/space_to_batch.hpp | 6 ++--- .../core/include/ngraph/op/space_to_depth.hpp | 2 +- ngraph/core/include/ngraph/op/split.hpp | 6 ++--- ngraph/core/include/ngraph/op/sqrt.hpp | 6 ++--- .../include/ngraph/op/squared_difference.hpp | 2 +- ngraph/core/include/ngraph/op/squeeze.hpp | 6 ++--- .../core/include/ngraph/op/strided_slice.hpp | 6 ++--- ngraph/core/include/ngraph/op/swish.hpp | 6 ++--- ngraph/core/include/ngraph/op/tan.hpp | 6 ++--- ngraph/core/include/ngraph/op/tanh.hpp | 6 ++--- .../include/ngraph/op/tensor_iterator.hpp | 6 ++--- ngraph/core/include/ngraph/op/tile.hpp | 6 ++--- ngraph/core/include/ngraph/op/topk.hpp | 4 ++-- ngraph/core/include/ngraph/op/transpose.hpp | 6 ++--- ngraph/core/include/ngraph/op/unsqueeze.hpp | 6 ++--- .../ngraph/op/util/activation_functions.hpp | 4 ++-- .../ngraph/op/util/arithmetic_reduction.hpp | 6 ++--- .../util/arithmetic_reductions_keep_dims.hpp | 6 ++--- .../include/ngraph/op/util/attr_types.hpp | 24 +++++++++---------- .../op/util/binary_elementwise_arithmetic.hpp | 6 ++--- .../op/util/binary_elementwise_comparison.hpp | 6 ++--- .../op/util/binary_elementwise_logical.hpp | 6 ++--- .../include/ngraph/op/util/broadcast_base.hpp | 6 ++--- .../ngraph/op/util/elementwise_args.hpp | 4 ++-- .../op/util/embeddingbag_offsets_base.hpp | 6 ++--- .../op/util/embeddingbag_packed_base.hpp | 6 ++--- .../core/include/ngraph/op/util/fft_base.hpp | 6 ++--- .../core/include/ngraph/op/util/fused_op.hpp | 6 ++--- .../include/ngraph/op/util/gather_base.hpp | 2 +- .../ngraph/op/util/index_reduction.hpp | 6 ++--- .../ngraph/op/util/logical_reduction.hpp | 6 ++--- .../op/util/logical_reduction_keep_dims.hpp | 6 ++--- .../include/ngraph/op/util/op_annotations.hpp | 6 ++--- .../core/include/ngraph/op/util/op_types.hpp | 4 ++-- .../include/ngraph/op/util/scatter_base.hpp | 6 ++--- .../ngraph/op/util/scatter_nd_base.hpp | 6 ++--- .../include/ngraph/op/util/sub_graph_base.hpp | 6 ++--- .../op/util/unary_elementwise_arithmetic.hpp | 6 ++--- .../core/include/ngraph/op/util/variable.hpp | 2 +- ngraph/core/include/ngraph/opsets/opset.hpp | 2 +- ngraph/core/include/ngraph/opsets/opset1.hpp | 4 ++-- ngraph/core/include/ngraph/opsets/opset2.hpp | 4 ++-- ngraph/core/include/ngraph/opsets/opset3.hpp | 4 ++-- ngraph/core/include/ngraph/opsets/opset4.hpp | 4 ++-- ngraph/core/include/ngraph/opsets/opset5.hpp | 4 ++-- ngraph/core/include/ngraph/output_vector.hpp | 2 +- ngraph/core/include/ngraph/partial_shape.hpp | 2 +- ngraph/core/include/ngraph/pass/manager.hpp | 4 ++-- ngraph/core/include/ngraph/pass/pass.hpp | 4 ++-- .../core/include/ngraph/pass/pass_config.hpp | 4 ++-- ngraph/core/include/ngraph/pass/validate.hpp | 4 ++-- .../include/ngraph/pass/visualize_tree.hpp | 4 ++-- .../core/include/ngraph/pattern/matcher.hpp | 4 ++-- ngraph/core/include/ngraph/pattern/op/any.hpp | 6 ++--- .../core/include/ngraph/pattern/op/any_of.hpp | 6 ++--- .../include/ngraph/pattern/op/any_output.hpp | 6 ++--- .../core/include/ngraph/pattern/op/branch.hpp | 6 ++--- .../include/ngraph/pattern/op/capture.hpp | 6 ++--- .../core/include/ngraph/pattern/op/label.hpp | 6 ++--- ngraph/core/include/ngraph/pattern/op/or.hpp | 6 ++--- .../include/ngraph/pattern/op/pattern.hpp | 6 ++--- .../core/include/ngraph/pattern/op/skip.hpp | 6 ++--- .../core/include/ngraph/pattern/op/true.hpp | 6 ++--- .../include/ngraph/pattern/op/wrap_type.hpp | 6 ++--- ngraph/core/include/ngraph/provenance.hpp | 2 +- ngraph/core/include/ngraph/rank.hpp | 2 +- ngraph/core/include/ngraph/rt_info.hpp | 2 +- .../include/ngraph/runtime/aligned_buffer.hpp | 4 ++-- .../include/ngraph/runtime/host_tensor.hpp | 6 ++--- .../include/ngraph/runtime/shared_buffer.hpp | 4 ++-- ngraph/core/include/ngraph/runtime/tensor.hpp | 4 ++-- ngraph/core/include/ngraph/shape.hpp | 2 +- ngraph/core/include/ngraph/shape_util.hpp | 2 +- ngraph/core/include/ngraph/slice_plan.hpp | 2 +- .../include/ngraph/specialize_function.hpp | 2 +- ngraph/core/include/ngraph/strides.hpp | 2 +- ngraph/core/include/ngraph/type.hpp | 4 ++-- ngraph/core/include/ngraph/type/bfloat16.hpp | 4 ++-- .../core/include/ngraph/type/element_type.hpp | 4 ++-- .../ngraph/type/element_type_traits.hpp | 2 +- ngraph/core/include/ngraph/type/float16.hpp | 4 ++-- ngraph/core/include/ngraph/variant.hpp | 2 +- .../ngraph/runtime/opt_kernel/reshape.hpp | 4 ++-- .../include/ngraph/runtime/reference/abs.hpp | 6 ++--- .../include/ngraph/runtime/reference/acos.hpp | 6 ++--- .../ngraph/runtime/reference/acosh.hpp | 6 ++--- .../include/ngraph/runtime/reference/add.hpp | 6 ++--- .../include/ngraph/runtime/reference/and.hpp | 6 ++--- .../include/ngraph/runtime/reference/asin.hpp | 6 ++--- .../ngraph/runtime/reference/asinh.hpp | 6 ++--- .../include/ngraph/runtime/reference/atan.hpp | 6 ++--- .../ngraph/runtime/reference/atan2.hpp | 6 ++--- .../ngraph/runtime/reference/atanh.hpp | 6 ++--- .../runtime/reference/autobroadcast_binop.hpp | 8 +++---- .../ngraph/runtime/reference/avg_pool.hpp | 6 ++--- .../ngraph/runtime/reference/batch_norm.hpp | 6 ++--- .../runtime/reference/binary_convolution.hpp | 2 +- .../ngraph/runtime/reference/broadcast.hpp | 4 ++-- .../ngraph/runtime/reference/ceiling.hpp | 6 ++--- .../ngraph/runtime/reference/clamp.hpp | 6 ++--- .../ngraph/runtime/reference/concat.hpp | 4 ++-- .../ngraph/runtime/reference/constant.hpp | 6 ++--- .../ngraph/runtime/reference/convolution.hpp | 2 +- .../include/ngraph/runtime/reference/copy.hpp | 6 ++--- .../include/ngraph/runtime/reference/cos.hpp | 6 ++--- .../include/ngraph/runtime/reference/cosh.hpp | 6 ++--- .../ngraph/runtime/reference/ctc_loss.hpp | 6 ++--- .../ngraph/runtime/reference/cum_sum.hpp | 6 ++--- .../ngraph/runtime/reference/divide.hpp | 6 ++--- .../include/ngraph/runtime/reference/elu.hpp | 6 ++--- .../reference/embedding_bag_offsets_sum.hpp | 6 ++--- .../reference/embedding_bag_packed_sum.hpp | 6 ++--- .../reference/embedding_segments_sum.hpp | 6 ++--- .../ngraph/runtime/reference/equal.hpp | 6 ++--- .../include/ngraph/runtime/reference/erf.hpp | 6 ++--- .../ngraph/runtime/reference/eval_helpers.hpp | 2 +- .../include/ngraph/runtime/reference/exp.hpp | 6 ++--- .../reference/extract_image_patches.hpp | 6 ++--- .../runtime/reference/fake_quantize.hpp | 8 +++---- .../include/ngraph/runtime/reference/fft.hpp | 6 ++--- .../ngraph/runtime/reference/floor.hpp | 6 ++--- .../ngraph/runtime/reference/floor_mod.hpp | 6 ++--- .../ngraph/runtime/reference/function.hpp | 4 ++-- .../ngraph/runtime/reference/gather_tree.hpp | 4 ++-- .../include/ngraph/runtime/reference/gelu.hpp | 6 ++--- .../ngraph/runtime/reference/greater.hpp | 6 ++--- .../ngraph/runtime/reference/greater_eq.hpp | 6 ++--- .../runtime/reference/group_convolution.hpp | 2 +- .../ngraph/runtime/reference/gru_cell.hpp | 6 ++--- .../ngraph/runtime/reference/hard_sigmoid.hpp | 6 ++--- .../ngraph/runtime/reference/helpers.hpp | 6 ++--- .../ngraph/runtime/reference/hsigmoid.hpp | 6 ++--- .../ngraph/runtime/reference/hswish.hpp | 6 ++--- .../ngraph/runtime/reference/interpolate.hpp | 6 ++--- .../include/ngraph/runtime/reference/less.hpp | 6 ++--- .../ngraph/runtime/reference/less_eq.hpp | 6 ++--- .../include/ngraph/runtime/reference/log.hpp | 6 ++--- .../runtime/reference/logical_reduction.hpp | 6 ++--- .../include/ngraph/runtime/reference/loop.hpp | 4 ++-- .../ngraph/runtime/reference/lstm_cell.hpp | 6 ++--- .../ngraph/runtime/reference/matmul.hpp | 8 +++---- .../include/ngraph/runtime/reference/max.hpp | 6 ++--- .../ngraph/runtime/reference/max_pool.hpp | 6 ++--- .../ngraph/runtime/reference/maximum.hpp | 6 ++--- .../include/ngraph/runtime/reference/mean.hpp | 6 ++--- .../ngraph/runtime/reference/minimum.hpp | 6 ++--- .../include/ngraph/runtime/reference/mish.hpp | 6 ++--- .../include/ngraph/runtime/reference/mod.hpp | 6 ++--- .../ngraph/runtime/reference/multiply.hpp | 6 ++--- .../ngraph/runtime/reference/negate.hpp | 6 ++--- .../runtime/reference/non_max_suppression.hpp | 6 ++--- .../ngraph/runtime/reference/non_zero.hpp | 6 ++--- .../include/ngraph/runtime/reference/not.hpp | 6 ++--- .../ngraph/runtime/reference/not_equal.hpp | 6 ++--- .../ngraph/runtime/reference/one_hot.hpp | 6 ++--- .../include/ngraph/runtime/reference/or.hpp | 6 ++--- .../ngraph/runtime/reference/power.hpp | 6 ++--- .../ngraph/runtime/reference/prelu.hpp | 6 ++--- .../ngraph/runtime/reference/prior_box.hpp | 6 ++--- .../runtime/reference/prior_box_clustered.hpp | 6 ++--- .../ngraph/runtime/reference/product.hpp | 6 ++--- .../runtime/reference/psroi_pooling.hpp | 6 ++--- .../ngraph/runtime/reference/quantize.hpp | 6 ++--- .../ngraph/runtime/reference/range.hpp | 6 ++--- .../ngraph/runtime/reference/reduce_l1.hpp | 6 ++--- .../ngraph/runtime/reference/reduce_l2.hpp | 6 ++--- .../include/ngraph/runtime/reference/relu.hpp | 6 ++--- .../ngraph/runtime/reference/reorg_yolo.hpp | 4 ++-- .../ngraph/runtime/reference/reshape.hpp | 4 ++-- .../ngraph/runtime/reference/result.hpp | 6 ++--- .../ngraph/runtime/reference/reverse.hpp | 4 ++-- .../runtime/reference/reverse_sequence.hpp | 6 ++--- .../ngraph/runtime/reference/rnn_cell.hpp | 6 ++--- .../include/ngraph/runtime/reference/roll.hpp | 6 ++--- .../ngraph/runtime/reference/round.hpp | 6 ++--- .../reference/scatter_elements_update.hpp | 6 ++--- .../runtime/reference/scatter_update.hpp | 6 ++--- .../ngraph/runtime/reference/select.hpp | 6 ++--- .../include/ngraph/runtime/reference/selu.hpp | 6 ++--- .../ngraph/runtime/reference/sequences.hpp | 6 ++--- .../ngraph/runtime/reference/shape_of.hpp | 6 ++--- .../ngraph/runtime/reference/sigmoid.hpp | 6 ++--- .../include/ngraph/runtime/reference/sign.hpp | 6 ++--- .../include/ngraph/runtime/reference/sin.hpp | 6 ++--- .../include/ngraph/runtime/reference/sinh.hpp | 6 ++--- .../ngraph/runtime/reference/slice.hpp | 4 ++-- .../ngraph/runtime/reference/softmax.hpp | 6 ++--- .../ngraph/runtime/reference/softplus.hpp | 6 ++--- .../ngraph/runtime/reference/split.hpp | 4 ++-- .../include/ngraph/runtime/reference/sqrt.hpp | 6 ++--- .../runtime/reference/squared_difference.hpp | 6 ++--- .../runtime/reference/strided_slice.hpp | 4 ++-- .../ngraph/runtime/reference/subtract.hpp | 6 ++--- .../include/ngraph/runtime/reference/sum.hpp | 6 ++--- .../ngraph/runtime/reference/swish.hpp | 6 ++--- .../include/ngraph/runtime/reference/tan.hpp | 6 ++--- .../include/ngraph/runtime/reference/tanh.hpp | 6 ++--- .../runtime/reference/tensor_iterator.hpp | 6 ++--- .../include/ngraph/runtime/reference/tile.hpp | 4 ++-- .../include/ngraph/runtime/reference/topk.hpp | 6 ++--- .../ngraph/runtime/reference/transpose.hpp | 6 ++--- .../include/ngraph/runtime/reference/xor.hpp | 6 ++--- .../src/runtime/opt_kernel/reshape.cpp | 2 +- .../src/runtime/reference/broadcast.cpp | 6 ++--- .../src/runtime/reference/convert.cpp | 6 ++--- .../reference/src/runtime/reference/fft.cpp | 8 +++---- .../src/runtime/reference/function.cpp | 6 ++--- .../src/runtime/reference/jit_generator.cpp | 6 ++--- .../reference/src/runtime/reference/loop.cpp | 6 ++--- .../runtime/reference/non_max_suppression.cpp | 8 +++---- .../reference/src/runtime/reference/pad.cpp | 2 +- .../src/runtime/reference/reorg_yolo.cpp | 6 ++--- .../src/runtime/reference/tensor_iterator.cpp | 6 ++--- .../reference/src/runtime/reference/tile.cpp | 2 +- ngraph/core/src/attribute_adapter.cpp | 2 +- ngraph/core/src/dimension.cpp | 2 +- ngraph/core/src/distributed.cpp | 2 +- ngraph/core/src/factory.cpp | 2 +- ngraph/core/src/interval.cpp | 2 +- ngraph/core/src/itt.hpp | 6 ++--- ngraph/core/src/ngraph.cpp | 2 +- ngraph/core/src/node.cpp | 2 +- ngraph/core/src/node_input.cpp | 2 +- ngraph/core/src/node_output.cpp | 2 +- ngraph/core/src/op/abs.cpp | 2 +- ngraph/core/src/op/acos.cpp | 2 +- ngraph/core/src/op/acosh.cpp | 2 +- ngraph/core/src/op/add.cpp | 2 +- ngraph/core/src/op/and.cpp | 2 +- ngraph/core/src/op/asin.cpp | 2 +- ngraph/core/src/op/asinh.cpp | 2 +- ngraph/core/src/op/atan.cpp | 2 +- ngraph/core/src/op/atanh.cpp | 2 +- ngraph/core/src/op/batch_to_space.cpp | 2 +- ngraph/core/src/op/binary_convolution.cpp | 2 +- ngraph/core/src/op/broadcast.cpp | 6 ++--- ngraph/core/src/op/ceiling.cpp | 2 +- ngraph/core/src/op/clamp.cpp | 2 +- ngraph/core/src/op/concat.cpp | 2 +- ngraph/core/src/op/constant.cpp | 6 ++--- ngraph/core/src/op/convert.cpp | 2 +- ngraph/core/src/op/cos.cpp | 2 +- ngraph/core/src/op/cosh.cpp | 2 +- ngraph/core/src/op/depth_to_space.cpp | 2 +- ngraph/core/src/op/divide.cpp | 2 +- ngraph/core/src/op/equal.cpp | 2 +- ngraph/core/src/op/erf.cpp | 2 +- ngraph/core/src/op/exp.cpp | 2 +- ngraph/core/src/op/floor.cpp | 2 +- ngraph/core/src/op/floor_mod.cpp | 2 +- ngraph/core/src/op/gelu.cpp | 2 +- ngraph/core/src/op/greater.cpp | 2 +- ngraph/core/src/op/greater_eq.cpp | 2 +- ngraph/core/src/op/hsigmoid.cpp | 2 +- ngraph/core/src/op/hswish.cpp | 2 +- ngraph/core/src/op/interpolate.cpp | 4 ++-- ngraph/core/src/op/less.cpp | 2 +- ngraph/core/src/op/less_eq.cpp | 2 +- ngraph/core/src/op/log.cpp | 2 +- ngraph/core/src/op/matmul.cpp | 2 +- ngraph/core/src/op/max.cpp | 2 +- ngraph/core/src/op/max_pool.cpp | 2 +- ngraph/core/src/op/maximum.cpp | 2 +- ngraph/core/src/op/minimum.cpp | 2 +- ngraph/core/src/op/mish.cpp | 2 +- ngraph/core/src/op/multiply.cpp | 2 +- ngraph/core/src/op/negative.cpp | 2 +- ngraph/core/src/op/non_max_suppression.cpp | 2 +- ngraph/core/src/op/non_zero.cpp | 2 +- ngraph/core/src/op/not.cpp | 2 +- ngraph/core/src/op/not_equal.cpp | 2 +- ngraph/core/src/op/or.cpp | 2 +- ngraph/core/src/op/power.cpp | 2 +- ngraph/core/src/op/prelu.cpp | 2 +- ngraph/core/src/op/prior_box.cpp | 2 +- ngraph/core/src/op/prior_box_clustered.cpp | 2 +- ngraph/core/src/op/range.cpp | 2 +- ngraph/core/src/op/reduce_l1.cpp | 2 +- ngraph/core/src/op/reduce_l2.cpp | 2 +- ngraph/core/src/op/reduce_mean.cpp | 2 +- ngraph/core/src/op/reduce_prod.cpp | 2 +- ngraph/core/src/op/reduce_sum.cpp | 2 +- ngraph/core/src/op/relu.cpp | 2 +- ngraph/core/src/op/reshape.cpp | 2 +- ngraph/core/src/op/reverse.cpp | 2 +- ngraph/core/src/op/roi_align.cpp | 2 +- ngraph/core/src/op/round.cpp | 2 +- .../core/src/op/scatter_elements_update.cpp | 2 +- ngraph/core/src/op/scatter_nd_update.cpp | 2 +- ngraph/core/src/op/scatter_update.cpp | 2 +- ngraph/core/src/op/shape_of.cpp | 2 +- ngraph/core/src/op/sigmoid.cpp | 2 +- ngraph/core/src/op/sign.cpp | 2 +- ngraph/core/src/op/sin.cpp | 2 +- ngraph/core/src/op/sinh.cpp | 2 +- ngraph/core/src/op/softmax.cpp | 2 +- ngraph/core/src/op/softplus.cpp | 2 +- ngraph/core/src/op/split.cpp | 2 +- ngraph/core/src/op/sqrt.cpp | 2 +- ngraph/core/src/op/squeeze.cpp | 2 +- ngraph/core/src/op/strided_slice.cpp | 4 ++-- ngraph/core/src/op/subtract.cpp | 2 +- ngraph/core/src/op/swish.cpp | 2 +- ngraph/core/src/op/tan.cpp | 2 +- ngraph/core/src/op/tanh.cpp | 2 +- ngraph/core/src/op/topk.cpp | 2 +- ngraph/core/src/op/transpose.cpp | 2 +- ngraph/core/src/op/unsqueeze.cpp | 2 +- ngraph/core/src/op/util/attr_types.cpp | 2 +- ngraph/core/src/op/util/broadcast_base.cpp | 2 +- ngraph/core/src/op/util/sub_graph_base.cpp | 2 +- ngraph/core/src/op/variadic_split.cpp | 2 +- ngraph/core/src/op/xor.cpp | 2 +- ngraph/core/src/pass/manager.cpp | 6 ++--- ngraph/core/src/pass/perf_counters.cpp | 4 ++-- ngraph/core/src/pass/perf_counters.hpp | 4 ++-- ngraph/core/src/pattern/matcher.cpp | 8 +++---- ngraph/core/src/pattern/op/pattern.cpp | 6 ++--- ngraph/core/src/provenance.cpp | 2 +- ngraph/core/src/runtime/aligned_buffer.cpp | 2 +- ngraph/core/src/type.cpp | 2 +- ngraph/core/src/type/element_type.cpp | 6 ++--- ngraph/core/src/util.cpp | 4 ++-- ngraph/core/src/validation_util.cpp | 2 +- .../onnx_common/include/onnx_common/utils.hpp | 2 +- ngraph/frontend/onnx_common/src/utils.cpp | 4 ++-- .../include/onnx_import/core/node.hpp | 2 +- .../onnx_import/src/core/null_node.hpp | 2 +- .../frontend/onnx_import/src/core/tensor.hpp | 16 ++++++------- .../onnx_import/src/default_opset.hpp | 2 +- .../frontend/onnx_import/src/exceptions.cpp | 8 +++---- .../frontend/onnx_import/src/op/constant.cpp | 2 +- .../onnx_import/src/op/conv_transpose.cpp | 2 +- ngraph/frontend/onnx_import/src/op/cos.hpp | 2 +- ngraph/frontend/onnx_import/src/op/cosh.hpp | 4 ++-- .../onnx_import/src/op/dequantize_linear.cpp | 14 +++++------ .../frontend/onnx_import/src/op/dropout.cpp | 2 +- ngraph/frontend/onnx_import/src/op/gru.cpp | 2 +- .../onnx_import/src/op/image_scaler.cpp | 8 +++---- .../onnx_import/src/op/image_scaler.hpp | 6 ++--- ngraph/frontend/onnx_import/src/op/log.hpp | 2 +- .../onnx_import/src/op/log_softmax.cpp | 4 ++-- .../onnx_import/src/op/log_softmax.hpp | 2 +- ngraph/frontend/onnx_import/src/op/loop.cpp | 2 +- .../src/op/org.openvinotoolkit/group_norm.cpp | 4 ++-- .../src/op/org.openvinotoolkit/prior_box.cpp | 4 ++-- ngraph/frontend/onnx_import/src/op/pad.cpp | 2 +- ngraph/frontend/onnx_import/src/op/reduce.hpp | 2 +- ngraph/frontend/onnx_import/src/op/rnn.cpp | 2 +- ngraph/frontend/onnx_import/src/op/slice.cpp | 2 +- .../frontend/onnx_import/src/op/softmax.cpp | 12 +++++----- .../onnx_import/src/op/thresholded_relu.cpp | 2 +- ngraph/frontend/onnx_import/src/op/topk.cpp | 8 +++---- ngraph/frontend/onnx_import/src/op/topk.hpp | 2 +- .../frontend/onnx_import/src/ops_bridge.cpp | 2 +- .../src/utils/arg_min_max_factory.cpp | 6 ++--- .../src/utils/arg_min_max_factory.hpp | 2 +- .../onnx_import/src/utils/recurrent.cpp | 6 ++--- .../onnx_import/src/utils/recurrent.hpp | 6 ++--- .../src/utils/tensor_external_data.cpp | 6 ++--- .../src/utils/tensor_external_data.hpp | 6 ++--- ngraph/python/src/pyngraph/passes/manager.cpp | 2 +- 509 files changed, 1151 insertions(+), 1151 deletions(-) diff --git a/ngraph/.clang-format b/ngraph/.clang-format index e9f0ba3c121..109a57d5326 100644 --- a/ngraph/.clang-format +++ b/ngraph/.clang-format @@ -51,4 +51,4 @@ IncludeCategories: Priority: 2 SortIncludes: true -FixNamespaceComments: false +FixNamespaceComments: true diff --git a/ngraph/core/builder/include/ngraph/builder/make_constant.hpp b/ngraph/core/builder/include/ngraph/builder/make_constant.hpp index e864f8e4671..2bf99528da8 100644 --- a/ngraph/core/builder/include/ngraph/builder/make_constant.hpp +++ b/ngraph/core/builder/include/ngraph/builder/make_constant.hpp @@ -121,5 +121,5 @@ namespace ngraph /// std::shared_ptr make_constant_from_double(const element::Type& type, const Shape& shape, double num); - } -} + } // namespace builder +} // namespace ngraph diff --git a/ngraph/core/builder/include/ngraph/builder/norm.hpp b/ngraph/core/builder/include/ngraph/builder/norm.hpp index 85e0afe0166..a4fd9e9e931 100644 --- a/ngraph/core/builder/include/ngraph/builder/norm.hpp +++ b/ngraph/core/builder/include/ngraph/builder/norm.hpp @@ -84,6 +84,6 @@ namespace ngraph const Output& reduction_axes, std::size_t p_norm = 2, float bias = 0.f); - } - } // namespace builder + } // namespace opset1 + } // namespace builder } // namespace ngraph diff --git a/ngraph/core/builder/include/ngraph/builder/reduce_ops.hpp b/ngraph/core/builder/include/ngraph/builder/reduce_ops.hpp index 57060a6e301..b816badb35b 100644 --- a/ngraph/core/builder/include/ngraph/builder/reduce_ops.hpp +++ b/ngraph/core/builder/include/ngraph/builder/reduce_ops.hpp @@ -79,7 +79,7 @@ namespace ngraph const Output& reduction_axes, bool keep_dims = false, bool bessel_correction = false); - } + } // namespace opset1 } // namespace builder } // namespace ngraph diff --git a/ngraph/core/builder/include/ngraph/builder/reshape.hpp b/ngraph/core/builder/include/ngraph/builder/reshape.hpp index 4d1b4cd2c0d..e00c8a0848b 100644 --- a/ngraph/core/builder/include/ngraph/builder/reshape.hpp +++ b/ngraph/core/builder/include/ngraph/builder/reshape.hpp @@ -82,6 +82,6 @@ namespace ngraph std::shared_ptr collapse(const Output& value, const std::size_t start_axis, const std::size_t end_axis); - } - } // namespace builder + } // namespace opset1 + } // namespace builder } // namespace ngraph diff --git a/ngraph/core/builder/include/ngraph/builder/split.hpp b/ngraph/core/builder/include/ngraph/builder/split.hpp index 6abfffdcda6..520c7d2391e 100644 --- a/ngraph/core/builder/include/ngraph/builder/split.hpp +++ b/ngraph/core/builder/include/ngraph/builder/split.hpp @@ -77,6 +77,6 @@ namespace ngraph /// The vector is output of VariadicSplit:v1 op /// OutputVector split(const Output& value, size_t num_splits, int64_t axis = 0); - } - } // namespace builder + } // namespace opset1 + } // namespace builder } // namespace ngraph diff --git a/ngraph/core/builder/src/builder/make_constant.cpp b/ngraph/core/builder/src/builder/make_constant.cpp index 6ab42245140..899c790f348 100644 --- a/ngraph/core/builder/src/builder/make_constant.cpp +++ b/ngraph/core/builder/src/builder/make_constant.cpp @@ -90,5 +90,5 @@ namespace ngraph } return result; } - } -} + } // namespace builder +} // namespace ngraph diff --git a/ngraph/core/builder/src/builder/norm.cpp b/ngraph/core/builder/src/builder/norm.cpp index bd60f578c89..48ea9b5f2c5 100644 --- a/ngraph/core/builder/src/builder/norm.cpp +++ b/ngraph/core/builder/src/builder/norm.cpp @@ -54,8 +54,8 @@ namespace ngraph return {make_shared(values, inv_p_node) ->add_provenance_group_members_above({value})}; } - } - } + } // namespace opset1 + } // namespace detail shared_ptr builder::opset1::l0_norm(const Output& value, const Output& reduction_axes) diff --git a/ngraph/core/builder/src/builder/reshape.cpp b/ngraph/core/builder/src/builder/reshape.cpp index ebb6318bc53..36c0a45e17b 100644 --- a/ngraph/core/builder/src/builder/reshape.cpp +++ b/ngraph/core/builder/src/builder/reshape.cpp @@ -113,10 +113,10 @@ namespace ngraph // node_rank-1] return make_shared(node_rank, axis_node); } - } // opset1 - } // builder - } // ngraph -} + } // namespace + } // namespace opset1 + } // namespace builder +} // namespace ngraph shared_ptr builder::opset1::flatten(const Output& value, int axis) { diff --git a/ngraph/core/include/ngraph/attribute_adapter.hpp b/ngraph/core/include/ngraph/attribute_adapter.hpp index 95de396bcca..d3370942110 100644 --- a/ngraph/core/include/ngraph/attribute_adapter.hpp +++ b/ngraph/core/include/ngraph/attribute_adapter.hpp @@ -557,4 +557,4 @@ namespace ngraph static constexpr DiscreteTypeInfo type_info{"AttributeAdapter>", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/attribute_visitor.hpp b/ngraph/core/include/ngraph/attribute_visitor.hpp index f592376e1cb..559b8dae4ef 100644 --- a/ngraph/core/include/ngraph/attribute_visitor.hpp +++ b/ngraph/core/include/ngraph/attribute_visitor.hpp @@ -147,4 +147,4 @@ namespace ngraph std::unordered_map, node_id_t> m_node_id_map; std::unordered_map> m_id_node_map; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/axis_set.hpp b/ngraph/core/include/ngraph/axis_set.hpp index ad2f96179e4..bab6d34f3da 100644 --- a/ngraph/core/include/ngraph/axis_set.hpp +++ b/ngraph/core/include/ngraph/axis_set.hpp @@ -58,4 +58,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const AxisSet& axis_set); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/axis_vector.hpp b/ngraph/core/include/ngraph/axis_vector.hpp index 170141d476f..18f12dc1c1c 100644 --- a/ngraph/core/include/ngraph/axis_vector.hpp +++ b/ngraph/core/include/ngraph/axis_vector.hpp @@ -56,4 +56,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const AxisVector& axis_vector); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/check.hpp b/ngraph/core/include/ngraph/check.hpp index c819812e2f3..3f3d3e8ffed 100644 --- a/ngraph/core/include/ngraph/check.hpp +++ b/ngraph/core/include/ngraph/check.hpp @@ -42,7 +42,7 @@ namespace ngraph const std::string& context_info, const std::string& explanation); }; -} +} // namespace ngraph // // Helper macro for defining custom check macros, which throw custom exception classes and provide diff --git a/ngraph/core/include/ngraph/coordinate.hpp b/ngraph/core/include/ngraph/coordinate.hpp index 626ce131b85..a10139772c0 100644 --- a/ngraph/core/include/ngraph/coordinate.hpp +++ b/ngraph/core/include/ngraph/coordinate.hpp @@ -57,4 +57,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const Coordinate& coordinate); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/coordinate_diff.hpp b/ngraph/core/include/ngraph/coordinate_diff.hpp index cdad0a873e4..0a2e5787618 100644 --- a/ngraph/core/include/ngraph/coordinate_diff.hpp +++ b/ngraph/core/include/ngraph/coordinate_diff.hpp @@ -57,4 +57,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const CoordinateDiff& coordinate_diff); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/descriptor/input.hpp b/ngraph/core/include/ngraph/descriptor/input.hpp index 53678520b7e..b16f3bb0ffc 100644 --- a/ngraph/core/include/ngraph/descriptor/input.hpp +++ b/ngraph/core/include/ngraph/descriptor/input.hpp @@ -103,5 +103,5 @@ namespace ngraph bool m_is_relevant_to_shape; bool m_is_relevant_to_value; }; - } -} + } // namespace descriptor +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/descriptor/output.hpp b/ngraph/core/include/ngraph/descriptor/output.hpp index d97846083bf..8df7f68df02 100644 --- a/ngraph/core/include/ngraph/descriptor/output.hpp +++ b/ngraph/core/include/ngraph/descriptor/output.hpp @@ -78,5 +78,5 @@ namespace ngraph RTMap m_rt_info; std::vector m_inputs; }; - } -} + } // namespace descriptor +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/descriptor/tensor.hpp b/ngraph/core/include/ngraph/descriptor/tensor.hpp index 01aae03f49b..676bd9eddd0 100644 --- a/ngraph/core/include/ngraph/descriptor/tensor.hpp +++ b/ngraph/core/include/ngraph/descriptor/tensor.hpp @@ -89,5 +89,5 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream&, const ngraph::descriptor::Tensor&); - } -} + } // namespace descriptor +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/dimension.hpp b/ngraph/core/include/ngraph/dimension.hpp index 6032be872ae..699d8b651fe 100644 --- a/ngraph/core/include/ngraph/dimension.hpp +++ b/ngraph/core/include/ngraph/dimension.hpp @@ -163,4 +163,4 @@ namespace ngraph /// Inserts the string `?` if `dimension` is dynamic; else inserts `dimension.get_length()`. NGRAPH_API std::ostream& operator<<(std::ostream& str, const Dimension& dimension); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/distributed.hpp b/ngraph/core/include/ngraph/distributed.hpp index 2308344b0d7..136152799e0 100644 --- a/ngraph/core/include/ngraph/distributed.hpp +++ b/ngraph/core/include/ngraph/distributed.hpp @@ -26,7 +26,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& out, const Type& obj); - } + } // namespace reduction template <> class NGRAPH_API AttributeAdapter @@ -41,4 +41,4 @@ namespace ngraph static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/enum_names.hpp b/ngraph/core/include/ngraph/enum_names.hpp index 2cf5dddaa84..213613d8064 100644 --- a/ngraph/core/include/ngraph/enum_names.hpp +++ b/ngraph/core/include/ngraph/enum_names.hpp @@ -81,4 +81,4 @@ namespace ngraph { return EnumNames::as_string(value); } -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/env_util.hpp b/ngraph/core/include/ngraph/env_util.hpp index 3892310a64c..b8adecf880d 100644 --- a/ngraph/core/include/ngraph/env_util.hpp +++ b/ngraph/core/include/ngraph/env_util.hpp @@ -35,4 +35,4 @@ namespace ngraph /// \return Returns the boolean value of the environment variable. NGRAPH_API bool getenv_bool(const char* env_var, bool default_value = false); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/evaluator.hpp b/ngraph/core/include/ngraph/evaluator.hpp index 6f2de07bcbc..0fe3f577bee 100644 --- a/ngraph/core/include/ngraph/evaluator.hpp +++ b/ngraph/core/include/ngraph/evaluator.hpp @@ -200,4 +200,4 @@ namespace ngraph op_handler m_default_handler; value_map& m_value_map; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/except.hpp b/ngraph/core/include/ngraph/except.hpp index dd2e9be9c51..639c27818b8 100644 --- a/ngraph/core/include/ngraph/except.hpp +++ b/ngraph/core/include/ngraph/except.hpp @@ -39,4 +39,4 @@ namespace ngraph { } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/factory_adapter.hpp b/ngraph/core/include/ngraph/factory_adapter.hpp index 9a78a3d941e..f77b6a6c76b 100644 --- a/ngraph/core/include/ngraph/factory_adapter.hpp +++ b/ngraph/core/include/ngraph/factory_adapter.hpp @@ -51,4 +51,4 @@ namespace ngraph protected: std::shared_ptr& m_ref; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/file_util.hpp b/ngraph/core/include/ngraph/file_util.hpp index a8e283e85e8..7f679a36e03 100644 --- a/ngraph/core/include/ngraph/file_util.hpp +++ b/ngraph/core/include/ngraph/file_util.hpp @@ -70,5 +70,5 @@ namespace ngraph /// \param path A path to file /// \return A sanitiazed path NGRAPH_API std::string sanitize_path(const std::string& path); - } -} + } // namespace file_util +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/graph_util.hpp b/ngraph/core/include/ngraph/graph_util.hpp index 96c6a19ffb0..fda65edffff 100644 --- a/ngraph/core/include/ngraph/graph_util.hpp +++ b/ngraph/core/include/ngraph/graph_util.hpp @@ -24,7 +24,7 @@ namespace ngraph { class Input; class Output; - } + } // namespace descriptor namespace op { @@ -32,7 +32,7 @@ namespace ngraph { class Parameter; } - } + } // namespace op NGRAPH_API void traverse_nodes(const std::shared_ptr p, @@ -480,4 +480,4 @@ namespace ngraph NGRAPH_API bool replace_node_update_name(std::shared_ptr target, std::shared_ptr replacement); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/interval.hpp b/ngraph/core/include/ngraph/interval.hpp index b807d4bad94..08302289f99 100644 --- a/ngraph/core/include/ngraph/interval.hpp +++ b/ngraph/core/include/ngraph/interval.hpp @@ -104,4 +104,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& str, const Interval& interval); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/log.hpp b/ngraph/core/include/ngraph/log.hpp index ee369569096..10b444894ac 100644 --- a/ngraph/core/include/ngraph/log.hpp +++ b/ngraph/core/include/ngraph/log.hpp @@ -167,4 +167,4 @@ namespace ngraph #define NGRAPH_DEBUG \ ::ngraph::NullLogger {} #endif -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/ngraph.hpp b/ngraph/core/include/ngraph/ngraph.hpp index 1f359d5ec34..b97b6af3bda 100644 --- a/ngraph/core/include/ngraph/ngraph.hpp +++ b/ngraph/core/include/ngraph/ngraph.hpp @@ -32,7 +32,7 @@ namespace ngraph /// \note Throws a runtime_error if there is an error during parsing NGRAPH_API void get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra); -} +} // namespace ngraph /// \namespace ngraph /// \brief The Intel nGraph C++ API. diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index 4cc0b430ad5..b1eb4a3f6b7 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -670,7 +670,7 @@ namespace ngraph { } }; -} +} // namespace ngraph #define NODE_VALIDATION_CHECK(node, ...) \ NGRAPH_CHECK_HELPER(::ngraph::NodeValidationFailure, (node), __VA_ARGS__) diff --git a/ngraph/core/include/ngraph/node_input.hpp b/ngraph/core/include/ngraph/node_input.hpp index 21343bc634b..d5bd9d44d05 100644 --- a/ngraph/core/include/ngraph/node_input.hpp +++ b/ngraph/core/include/ngraph/node_input.hpp @@ -115,4 +115,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& out, const Input& input); NGRAPH_API std::ostream& operator<<(std::ostream& out, const Input& input); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/node_output.hpp b/ngraph/core/include/ngraph/node_output.hpp index 8fd205f3e91..1e52e4f8576 100644 --- a/ngraph/core/include/ngraph/node_output.hpp +++ b/ngraph/core/include/ngraph/node_output.hpp @@ -182,4 +182,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& out, const Output& output); NGRAPH_API std::ostream& operator<<(std::ostream& out, const Output& output); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/abs.hpp b/ngraph/core/include/ngraph/op/abs.hpp index 67a6c7acef4..c40daeeb027 100644 --- a/ngraph/core/include/ngraph/op/abs.hpp +++ b/ngraph/core/include/ngraph/op/abs.hpp @@ -39,7 +39,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Abs; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/acos.hpp b/ngraph/core/include/ngraph/op/acos.hpp index 7d0c29ea5d7..329717b8874 100644 --- a/ngraph/core/include/ngraph/op/acos.hpp +++ b/ngraph/core/include/ngraph/op/acos.hpp @@ -37,7 +37,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Acos; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/acosh.hpp b/ngraph/core/include/ngraph/op/acosh.hpp index 731af0df0d9..4e6f4384702 100644 --- a/ngraph/core/include/ngraph/op/acosh.hpp +++ b/ngraph/core/include/ngraph/op/acosh.hpp @@ -38,7 +38,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v3 using v3::Acosh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/and.hpp b/ngraph/core/include/ngraph/op/and.hpp index 49fe0f80a74..1eb15511939 100644 --- a/ngraph/core/include/ngraph/op/and.hpp +++ b/ngraph/core/include/ngraph/op/and.hpp @@ -45,5 +45,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/asin.hpp b/ngraph/core/include/ngraph/op/asin.hpp index a50e5b15d4e..449b19fca3f 100644 --- a/ngraph/core/include/ngraph/op/asin.hpp +++ b/ngraph/core/include/ngraph/op/asin.hpp @@ -38,7 +38,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Asin; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/asinh.hpp b/ngraph/core/include/ngraph/op/asinh.hpp index 413f61d5f5f..34fc2cbe890 100644 --- a/ngraph/core/include/ngraph/op/asinh.hpp +++ b/ngraph/core/include/ngraph/op/asinh.hpp @@ -38,7 +38,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v3 using v3::Asinh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/assign.hpp b/ngraph/core/include/ngraph/op/assign.hpp index e7ceabb2cdf..cf801f22409 100644 --- a/ngraph/core/include/ngraph/op/assign.hpp +++ b/ngraph/core/include/ngraph/op/assign.hpp @@ -74,7 +74,7 @@ namespace ngraph private: std::string m_variable_id; }; - } + } // namespace v3 namespace v6 { /// \brief Assign operation sets an input value to the variable with `variable_id` @@ -106,6 +106,6 @@ namespace ngraph return m_variable->get_info().variable_id; } }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/atan.hpp b/ngraph/core/include/ngraph/op/atan.hpp index 5168158bd75..4644d2870af 100644 --- a/ngraph/core/include/ngraph/op/atan.hpp +++ b/ngraph/core/include/ngraph/op/atan.hpp @@ -39,7 +39,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Atan; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/atanh.hpp b/ngraph/core/include/ngraph/op/atanh.hpp index 420b35c7448..edb8f965d0d 100644 --- a/ngraph/core/include/ngraph/op/atanh.hpp +++ b/ngraph/core/include/ngraph/op/atanh.hpp @@ -38,7 +38,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v3 using v3::Atanh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/batch_norm.hpp b/ngraph/core/include/ngraph/op/batch_norm.hpp index 22d3db026d3..c65ffc7c2de 100644 --- a/ngraph/core/include/ngraph/op/batch_norm.hpp +++ b/ngraph/core/include/ngraph/op/batch_norm.hpp @@ -91,6 +91,6 @@ namespace ngraph double m_epsilon; }; - } // namespace v0 - } -} + } // namespace v5 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/batch_to_space.hpp b/ngraph/core/include/ngraph/op/batch_to_space.hpp index c26be881062..a9c42e4ded0 100644 --- a/ngraph/core/include/ngraph/op/batch_to_space.hpp +++ b/ngraph/core/include/ngraph/op/batch_to_space.hpp @@ -50,6 +50,6 @@ namespace ngraph clone_with_new_inputs(const OutputVector& new_args) const override; bool visit_attributes(AttributeVisitor& visitor) override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/binary_convolution.hpp b/ngraph/core/include/ngraph/op/binary_convolution.hpp index d072288d882..12e2c448f54 100644 --- a/ngraph/core/include/ngraph/op/binary_convolution.hpp +++ b/ngraph/core/include/ngraph/op/binary_convolution.hpp @@ -99,8 +99,8 @@ namespace ngraph float m_pad_value; PadType m_auto_pad; }; - } - } // namespace op + } // namespace v1 + } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, diff --git a/ngraph/core/include/ngraph/op/broadcast.hpp b/ngraph/core/include/ngraph/op/broadcast.hpp index 617a1c965f4..30e0b6e490a 100644 --- a/ngraph/core/include/ngraph/op/broadcast.hpp +++ b/ngraph/core/include/ngraph/op/broadcast.hpp @@ -137,5 +137,5 @@ namespace ngraph AutoBroadcastSpec m_broadcast_spec; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/bucketize.hpp b/ngraph/core/include/ngraph/op/bucketize.hpp index 0db27a0699c..f45cbd4746e 100644 --- a/ngraph/core/include/ngraph/op/bucketize.hpp +++ b/ngraph/core/include/ngraph/op/bucketize.hpp @@ -52,7 +52,7 @@ namespace ngraph element::Type m_output_type; bool m_with_right_bound; }; - } + } // namespace v3 using v3::Bucketize; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/ceiling.hpp b/ngraph/core/include/ngraph/op/ceiling.hpp index b35ecd0a32f..3e8f071e873 100644 --- a/ngraph/core/include/ngraph/op/ceiling.hpp +++ b/ngraph/core/include/ngraph/op/ceiling.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Ceiling; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/clamp.hpp b/ngraph/core/include/ngraph/op/clamp.hpp index 3b92f05ddd7..22b41fb4305 100644 --- a/ngraph/core/include/ngraph/op/clamp.hpp +++ b/ngraph/core/include/ngraph/op/clamp.hpp @@ -47,7 +47,7 @@ namespace ngraph double m_min; double m_max; }; - } + } // namespace v0 using v0::Clamp; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/concat.hpp b/ngraph/core/include/ngraph/op/concat.hpp index 11e5daff39f..b168045d577 100644 --- a/ngraph/core/include/ngraph/op/concat.hpp +++ b/ngraph/core/include/ngraph/op/concat.hpp @@ -60,7 +60,7 @@ namespace ngraph /// \brief m_concat_axis stores m_axis plus the number of rank for each iteration int64_t m_concat_axis = -1; }; - } + } // namespace v0 using v0::Concat; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/constant.hpp b/ngraph/core/include/ngraph/op/constant.hpp index c5000dce48f..ce0fbc127b1 100644 --- a/ngraph/core/include/ngraph/op/constant.hpp +++ b/ngraph/core/include/ngraph/op/constant.hpp @@ -474,7 +474,7 @@ namespace ngraph bool m_all_elements_bitwise_identical; bool m_alloc_buffer_on_visit_attributes = true; }; - } + } // namespace v0 using v0::Constant; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/convert.hpp b/ngraph/core/include/ngraph/op/convert.hpp index c8b0303e327..8007b81dede 100644 --- a/ngraph/core/include/ngraph/op/convert.hpp +++ b/ngraph/core/include/ngraph/op/convert.hpp @@ -50,7 +50,7 @@ namespace ngraph protected: ngraph::element::Type m_destination_type; }; - } + } // namespace v0 using v0::Convert; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/cos.hpp b/ngraph/core/include/ngraph/op/cos.hpp index f5363c61930..e310dec7554 100644 --- a/ngraph/core/include/ngraph/op/cos.hpp +++ b/ngraph/core/include/ngraph/op/cos.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Cos; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/cosh.hpp b/ngraph/core/include/ngraph/op/cosh.hpp index 97740bb1249..f71433c8b5e 100644 --- a/ngraph/core/include/ngraph/op/cosh.hpp +++ b/ngraph/core/include/ngraph/op/cosh.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Cosh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/ctc_loss.hpp b/ngraph/core/include/ngraph/op/ctc_loss.hpp index 1d4fcb50c67..23f8e4ff570 100644 --- a/ngraph/core/include/ngraph/op/ctc_loss.hpp +++ b/ngraph/core/include/ngraph/op/ctc_loss.hpp @@ -68,6 +68,6 @@ namespace ngraph bool ctc_merge_repeated_; bool unique_; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/cum_sum.hpp b/ngraph/core/include/ngraph/op/cum_sum.hpp index 5db877f099c..8a133a2502b 100644 --- a/ngraph/core/include/ngraph/op/cum_sum.hpp +++ b/ngraph/core/include/ngraph/op/cum_sum.hpp @@ -99,7 +99,7 @@ namespace ngraph bool m_exclusive; bool m_reverse; }; - } + } // namespace v0 using v0::CumSum; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/deformable_convolution.hpp b/ngraph/core/include/ngraph/op/deformable_convolution.hpp index e1a6ad9790b..7ed84915456 100644 --- a/ngraph/core/include/ngraph/op/deformable_convolution.hpp +++ b/ngraph/core/include/ngraph/op/deformable_convolution.hpp @@ -86,6 +86,6 @@ namespace ngraph int64_t m_group; int64_t m_deformable_group; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/deformable_psroi_pooling.hpp b/ngraph/core/include/ngraph/op/deformable_psroi_pooling.hpp index 120ef942086..93177b79f55 100644 --- a/ngraph/core/include/ngraph/op/deformable_psroi_pooling.hpp +++ b/ngraph/core/include/ngraph/op/deformable_psroi_pooling.hpp @@ -91,6 +91,6 @@ namespace ngraph float m_trans_std = 1.f; int64_t m_part_size = 1; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/depth_to_space.hpp b/ngraph/core/include/ngraph/op/depth_to_space.hpp index 57d8ba3d56a..c978587ed50 100644 --- a/ngraph/core/include/ngraph/op/depth_to_space.hpp +++ b/ngraph/core/include/ngraph/op/depth_to_space.hpp @@ -70,9 +70,9 @@ namespace ngraph bool evaluate_depth_to_space(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } + } // namespace v0 using v0::DepthToSpace; - } + } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v0::DepthToSpace::DepthToSpaceMode& type); @@ -91,4 +91,4 @@ namespace ngraph "AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/detection_output.hpp b/ngraph/core/include/ngraph/op/detection_output.hpp index fd20c5a0e53..a07a6d06173 100644 --- a/ngraph/core/include/ngraph/op/detection_output.hpp +++ b/ngraph/core/include/ngraph/op/detection_output.hpp @@ -77,7 +77,7 @@ namespace ngraph private: DetectionOutputAttrs m_attrs; }; - } + } // namespace v0 using v0::DetectionOutput; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/dft.hpp b/ngraph/core/include/ngraph/op/dft.hpp index 11abbb8ab91..43d6f33737b 100644 --- a/ngraph/core/include/ngraph/op/dft.hpp +++ b/ngraph/core/include/ngraph/op/dft.hpp @@ -56,6 +56,6 @@ namespace ngraph std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } - } -} + } // namespace v7 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/elu.hpp b/ngraph/core/include/ngraph/op/elu.hpp index ab45add17f8..3b15c52bb73 100644 --- a/ngraph/core/include/ngraph/op/elu.hpp +++ b/ngraph/core/include/ngraph/op/elu.hpp @@ -40,7 +40,7 @@ namespace ngraph private: double m_alpha; }; - } + } // namespace v0 using v0::Elu; } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/embedding_segments_sum.hpp b/ngraph/core/include/ngraph/op/embedding_segments_sum.hpp index 312bac9246b..f449958b9d7 100644 --- a/ngraph/core/include/ngraph/op/embedding_segments_sum.hpp +++ b/ngraph/core/include/ngraph/op/embedding_segments_sum.hpp @@ -76,7 +76,7 @@ namespace ngraph static constexpr int DEFAULT_INDEX = 4; static constexpr int PER_SAMPLE_WEIGHTS = 5; }; - } + } // namespace v3 using v3::EmbeddingSegmentsSum; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/embeddingbag_offsets_sum.hpp b/ngraph/core/include/ngraph/op/embeddingbag_offsets_sum.hpp index 8c2b86e197c..2bdc84392a6 100644 --- a/ngraph/core/include/ngraph/op/embeddingbag_offsets_sum.hpp +++ b/ngraph/core/include/ngraph/op/embeddingbag_offsets_sum.hpp @@ -58,7 +58,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v3 using v3::EmbeddingBagOffsetsSum; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/embeddingbag_packedsum.hpp b/ngraph/core/include/ngraph/op/embeddingbag_packedsum.hpp index d7cbd203b3b..6d713c96c61 100644 --- a/ngraph/core/include/ngraph/op/embeddingbag_packedsum.hpp +++ b/ngraph/core/include/ngraph/op/embeddingbag_packedsum.hpp @@ -45,7 +45,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v3 using v3::EmbeddingBagPackedSum; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/equal.hpp b/ngraph/core/include/ngraph/op/equal.hpp index e4ef0eb0a41..283beca984a 100644 --- a/ngraph/core/include/ngraph/op/equal.hpp +++ b/ngraph/core/include/ngraph/op/equal.hpp @@ -56,5 +56,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/erf.hpp b/ngraph/core/include/ngraph/op/erf.hpp index c32e2e30344..7c4deb41c2b 100644 --- a/ngraph/core/include/ngraph/op/erf.hpp +++ b/ngraph/core/include/ngraph/op/erf.hpp @@ -26,7 +26,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Erf; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/exp.hpp b/ngraph/core/include/ngraph/op/exp.hpp index bbaf0647f8e..3a0a5692edc 100644 --- a/ngraph/core/include/ngraph/op/exp.hpp +++ b/ngraph/core/include/ngraph/op/exp.hpp @@ -32,7 +32,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Exp; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/experimental_detectron_detection_output.hpp b/ngraph/core/include/ngraph/op/experimental_detectron_detection_output.hpp index 059b16c5a38..d0902e7d965 100644 --- a/ngraph/core/include/ngraph/op/experimental_detectron_detection_output.hpp +++ b/ngraph/core/include/ngraph/op/experimental_detectron_detection_output.hpp @@ -72,6 +72,6 @@ namespace ngraph private: Attributes m_attrs; }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/experimental_detectron_generate_proposals.hpp b/ngraph/core/include/ngraph/op/experimental_detectron_generate_proposals.hpp index 4b1e9e31825..a1cb0697cdd 100644 --- a/ngraph/core/include/ngraph/op/experimental_detectron_generate_proposals.hpp +++ b/ngraph/core/include/ngraph/op/experimental_detectron_generate_proposals.hpp @@ -62,6 +62,6 @@ namespace ngraph private: Attributes m_attrs; }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/experimental_detectron_prior_grid_generator.hpp b/ngraph/core/include/ngraph/op/experimental_detectron_prior_grid_generator.hpp index 47a953d11bd..76347e37988 100644 --- a/ngraph/core/include/ngraph/op/experimental_detectron_prior_grid_generator.hpp +++ b/ngraph/core/include/ngraph/op/experimental_detectron_prior_grid_generator.hpp @@ -65,6 +65,6 @@ namespace ngraph void validate(); }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/experimental_detectron_roi_feature.hpp b/ngraph/core/include/ngraph/op/experimental_detectron_roi_feature.hpp index da7d3b1119b..a64de29dca2 100644 --- a/ngraph/core/include/ngraph/op/experimental_detectron_roi_feature.hpp +++ b/ngraph/core/include/ngraph/op/experimental_detectron_roi_feature.hpp @@ -59,6 +59,6 @@ namespace ngraph private: Attributes m_attrs; }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/experimental_detectron_topkrois.hpp b/ngraph/core/include/ngraph/op/experimental_detectron_topkrois.hpp index 20c0ebadd63..c3a762e1404 100644 --- a/ngraph/core/include/ngraph/op/experimental_detectron_topkrois.hpp +++ b/ngraph/core/include/ngraph/op/experimental_detectron_topkrois.hpp @@ -44,6 +44,6 @@ namespace ngraph private: size_t m_max_rois; }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/fake_quantize.hpp b/ngraph/core/include/ngraph/op/fake_quantize.hpp index c5479f2b7ea..3caff056760 100644 --- a/ngraph/core/include/ngraph/op/fake_quantize.hpp +++ b/ngraph/core/include/ngraph/op/fake_quantize.hpp @@ -72,7 +72,7 @@ namespace ngraph std::size_t m_levels; AutoBroadcastSpec m_auto_broadcast = op::AutoBroadcastType::NUMPY; }; - } + } // namespace v0 using v0::FakeQuantize; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/floor.hpp b/ngraph/core/include/ngraph/op/floor.hpp index 8094f2f6764..8cb99b15887 100644 --- a/ngraph/core/include/ngraph/op/floor.hpp +++ b/ngraph/core/include/ngraph/op/floor.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Floor; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/gather_elements.hpp b/ngraph/core/include/ngraph/op/gather_elements.hpp index 055719578e5..ce26c7cfd59 100644 --- a/ngraph/core/include/ngraph/op/gather_elements.hpp +++ b/ngraph/core/include/ngraph/op/gather_elements.hpp @@ -39,6 +39,6 @@ namespace ngraph private: int64_t m_axis; }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/gather_nd.hpp b/ngraph/core/include/ngraph/op/gather_nd.hpp index 4614967f293..fe830d35a76 100644 --- a/ngraph/core/include/ngraph/op/gather_nd.hpp +++ b/ngraph/core/include/ngraph/op/gather_nd.hpp @@ -40,6 +40,6 @@ namespace ngraph private: size_t m_batch_dims; }; - } - } -} + } // namespace v5 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/gather_tree.hpp b/ngraph/core/include/ngraph/op/gather_tree.hpp index bd182307ca4..b8bc687a187 100644 --- a/ngraph/core/include/ngraph/op/gather_tree.hpp +++ b/ngraph/core/include/ngraph/op/gather_tree.hpp @@ -38,6 +38,6 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/gelu.hpp b/ngraph/core/include/ngraph/op/gelu.hpp index f18c3f24bb9..824ddadfc90 100644 --- a/ngraph/core/include/ngraph/op/gelu.hpp +++ b/ngraph/core/include/ngraph/op/gelu.hpp @@ -37,7 +37,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v0 using v0::Gelu; NGRAPH_SUPPRESS_DEPRECATED_END @@ -83,8 +83,8 @@ namespace ngraph private: GeluApproximationMode m_approximation_mode = GeluApproximationMode::ERF; }; - } - } + } // namespace v7 + } // namespace op template <> class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase @@ -99,4 +99,4 @@ namespace ngraph 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/greater.hpp b/ngraph/core/include/ngraph/op/greater.hpp index ebe0d1b1e09..eb8884e060a 100644 --- a/ngraph/core/include/ngraph/op/greater.hpp +++ b/ngraph/core/include/ngraph/op/greater.hpp @@ -38,5 +38,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/greater_eq.hpp b/ngraph/core/include/ngraph/op/greater_eq.hpp index edbda8fcd8f..813677b6481 100644 --- a/ngraph/core/include/ngraph/op/greater_eq.hpp +++ b/ngraph/core/include/ngraph/op/greater_eq.hpp @@ -39,5 +39,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/grn.hpp b/ngraph/core/include/ngraph/op/grn.hpp index 09db74ac7a3..d34312703fb 100644 --- a/ngraph/core/include/ngraph/op/grn.hpp +++ b/ngraph/core/include/ngraph/op/grn.hpp @@ -43,9 +43,9 @@ namespace ngraph protected: float m_bias = 1.0f; }; - } + } // namespace v0 using v0::GRN; - } -} + } // namespace op +} // namespace ngraph NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/ngraph/op/gru_cell.hpp b/ngraph/core/include/ngraph/op/gru_cell.hpp index 172e7316fb7..b203e3b4caf 100644 --- a/ngraph/core/include/ngraph/op/gru_cell.hpp +++ b/ngraph/core/include/ngraph/op/gru_cell.hpp @@ -164,6 +164,6 @@ namespace ngraph /// bool m_linear_before_reset; }; - } - } -} + } // namespace v3 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/gru_sequence.hpp b/ngraph/core/include/ngraph/op/gru_sequence.hpp index b9f01f8682b..57c3b247b8a 100644 --- a/ngraph/core/include/ngraph/op/gru_sequence.hpp +++ b/ngraph/core/include/ngraph/op/gru_sequence.hpp @@ -51,6 +51,6 @@ namespace ngraph op::RecurrentSequenceDirection m_direction; bool m_linear_before_reset; }; - } - } // namespace op + } // namespace v5 + } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/hard_sigmoid.hpp b/ngraph/core/include/ngraph/op/hard_sigmoid.hpp index f3dbcd9eaf3..587e1932fbe 100644 --- a/ngraph/core/include/ngraph/op/hard_sigmoid.hpp +++ b/ngraph/core/include/ngraph/op/hard_sigmoid.hpp @@ -41,9 +41,9 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v0 using v0::HardSigmoid; - } -} + } // namespace op +} // namespace ngraph NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/ngraph/op/hsigmoid.hpp b/ngraph/core/include/ngraph/op/hsigmoid.hpp index ee0e4d1d6ab..150163d413d 100644 --- a/ngraph/core/include/ngraph/op/hsigmoid.hpp +++ b/ngraph/core/include/ngraph/op/hsigmoid.hpp @@ -36,6 +36,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v5 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/hswish.hpp b/ngraph/core/include/ngraph/op/hswish.hpp index 87deda52cff..767c638d127 100644 --- a/ngraph/core/include/ngraph/op/hswish.hpp +++ b/ngraph/core/include/ngraph/op/hswish.hpp @@ -36,6 +36,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/idft.hpp b/ngraph/core/include/ngraph/op/idft.hpp index f3a7d585b74..c51a76ebddb 100644 --- a/ngraph/core/include/ngraph/op/idft.hpp +++ b/ngraph/core/include/ngraph/op/idft.hpp @@ -44,6 +44,6 @@ namespace ngraph std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } - } -} + } // namespace v7 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/less.hpp b/ngraph/core/include/ngraph/op/less.hpp index 9885724e31a..2c6a7462569 100644 --- a/ngraph/core/include/ngraph/op/less.hpp +++ b/ngraph/core/include/ngraph/op/less.hpp @@ -38,5 +38,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/log.hpp b/ngraph/core/include/ngraph/op/log.hpp index f9cc666794b..39a0404ea8f 100644 --- a/ngraph/core/include/ngraph/op/log.hpp +++ b/ngraph/core/include/ngraph/op/log.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Log; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/loop.hpp b/ngraph/core/include/ngraph/op/loop.hpp index 3145fe91c21..aa669ae8c9e 100644 --- a/ngraph/core/include/ngraph/op/loop.hpp +++ b/ngraph/core/include/ngraph/op/loop.hpp @@ -81,8 +81,8 @@ namespace ngraph SpecialBodyPorts m_special_body_ports; }; - } - } + } // namespace v5 + } // namespace op template <> class NGRAPH_API AttributeAdapter @@ -98,4 +98,4 @@ namespace ngraph "AttributeAdapter", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/lrn.hpp b/ngraph/core/include/ngraph/op/lrn.hpp index 2baba69c9d1..76443b221a9 100644 --- a/ngraph/core/include/ngraph/op/lrn.hpp +++ b/ngraph/core/include/ngraph/op/lrn.hpp @@ -67,7 +67,7 @@ namespace ngraph double m_bias; size_t m_size; }; - } + } // namespace v0 using v0::LRN; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/lstm_cell.hpp b/ngraph/core/include/ngraph/op/lstm_cell.hpp index 21e82a8f0fe..5e39cfff684 100644 --- a/ngraph/core/include/ngraph/op/lstm_cell.hpp +++ b/ngraph/core/include/ngraph/op/lstm_cell.hpp @@ -247,7 +247,7 @@ namespace ngraph static constexpr std::size_t s_gates_count{4}; static constexpr std::size_t s_peepholes_count{3}; }; - } // v0 + } // namespace v0 namespace v4 { @@ -388,7 +388,7 @@ namespace ngraph static constexpr std::size_t s_gates_count{4}; }; - } // v4 + } // namespace v4 } // namespace op NGRAPH_API diff --git a/ngraph/core/include/ngraph/op/lstm_sequence.hpp b/ngraph/core/include/ngraph/op/lstm_sequence.hpp index 03324555857..b5c0ec5dfef 100644 --- a/ngraph/core/include/ngraph/op/lstm_sequence.hpp +++ b/ngraph/core/include/ngraph/op/lstm_sequence.hpp @@ -134,7 +134,7 @@ namespace ngraph }; NGRAPH_SUPPRESS_DEPRECATED_END - } + } // namespace v0 namespace v5 { @@ -194,7 +194,7 @@ namespace ngraph private: direction m_direction; }; - } - } // namespace op + } // namespace v5 + } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/matmul.hpp b/ngraph/core/include/ngraph/op/matmul.hpp index d0bd86e8f93..35971c34da9 100644 --- a/ngraph/core/include/ngraph/op/matmul.hpp +++ b/ngraph/core/include/ngraph/op/matmul.hpp @@ -48,7 +48,7 @@ namespace ngraph bool m_transpose_a; bool m_transpose_b; }; - } + } // namespace v0 using v0::MatMul; } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/max.hpp b/ngraph/core/include/ngraph/op/max.hpp index 94032212f4c..7f98124dcda 100644 --- a/ngraph/core/include/ngraph/op/max.hpp +++ b/ngraph/core/include/ngraph/op/max.hpp @@ -34,6 +34,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/maximum.hpp b/ngraph/core/include/ngraph/op/maximum.hpp index b0361ec8b12..901bec51433 100644 --- a/ngraph/core/include/ngraph/op/maximum.hpp +++ b/ngraph/core/include/ngraph/op/maximum.hpp @@ -41,5 +41,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/min.hpp b/ngraph/core/include/ngraph/op/min.hpp index d78d30725d1..eec35ad9961 100644 --- a/ngraph/core/include/ngraph/op/min.hpp +++ b/ngraph/core/include/ngraph/op/min.hpp @@ -36,6 +36,6 @@ namespace ngraph bool evaluate_lower(const HostTensorVector& outputs) const override; bool evaluate_upper(const HostTensorVector& outputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/minimum.hpp b/ngraph/core/include/ngraph/op/minimum.hpp index 5e20fece2a2..233c3b81d6c 100644 --- a/ngraph/core/include/ngraph/op/minimum.hpp +++ b/ngraph/core/include/ngraph/op/minimum.hpp @@ -41,5 +41,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/mish.hpp b/ngraph/core/include/ngraph/op/mish.hpp index 5e2042f4864..de1fea59ef5 100644 --- a/ngraph/core/include/ngraph/op/mish.hpp +++ b/ngraph/core/include/ngraph/op/mish.hpp @@ -35,6 +35,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/mod.hpp b/ngraph/core/include/ngraph/op/mod.hpp index e586b90a427..4b9851be6b6 100644 --- a/ngraph/core/include/ngraph/op/mod.hpp +++ b/ngraph/core/include/ngraph/op/mod.hpp @@ -37,5 +37,5 @@ namespace ngraph clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/mvn.hpp b/ngraph/core/include/ngraph/op/mvn.hpp index d94a2145f2d..cc3ab0bb9d7 100644 --- a/ngraph/core/include/ngraph/op/mvn.hpp +++ b/ngraph/core/include/ngraph/op/mvn.hpp @@ -74,7 +74,7 @@ namespace ngraph bool m_normalize_variance; AxisSet m_reduction_axes; }; - } + } // namespace v0 using v0::MVN; NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/ngraph/op/negative.hpp b/ngraph/core/include/ngraph/op/negative.hpp index 7ccfeb11b3e..8d73425597a 100644 --- a/ngraph/core/include/ngraph/op/negative.hpp +++ b/ngraph/core/include/ngraph/op/negative.hpp @@ -31,9 +31,9 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Negative; - } + } // namespace op NGRAPH_API std::shared_ptr operator-(const Output& arg0); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/non_zero.hpp b/ngraph/core/include/ngraph/op/non_zero.hpp index dffcb301558..b81b9a64141 100644 --- a/ngraph/core/include/ngraph/op/non_zero.hpp +++ b/ngraph/core/include/ngraph/op/non_zero.hpp @@ -64,7 +64,7 @@ namespace ngraph protected: element::Type m_output_type = element::i64; }; - } + } // namespace v3 using v3::NonZero; } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/normalize_l2.hpp b/ngraph/core/include/ngraph/op/normalize_l2.hpp index e025af6f10b..ea63ffae7ca 100644 --- a/ngraph/core/include/ngraph/op/normalize_l2.hpp +++ b/ngraph/core/include/ngraph/op/normalize_l2.hpp @@ -56,9 +56,9 @@ namespace ngraph float m_eps; EpsMode m_eps_mode; }; - } + } // namespace v0 using v0::NormalizeL2; - } -} + } // namespace op +} // namespace ngraph NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/include/ngraph/op/not.hpp b/ngraph/core/include/ngraph/op/not.hpp index 8b19d7648fa..d25fe1aafa0 100644 --- a/ngraph/core/include/ngraph/op/not.hpp +++ b/ngraph/core/include/ngraph/op/not.hpp @@ -32,6 +32,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } // namespace op + } // namespace v1 + } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/not_equal.hpp b/ngraph/core/include/ngraph/op/not_equal.hpp index 33e71977181..d8bbaf32f19 100644 --- a/ngraph/core/include/ngraph/op/not_equal.hpp +++ b/ngraph/core/include/ngraph/op/not_equal.hpp @@ -40,5 +40,5 @@ namespace ngraph bool visit_attributes(AttributeVisitor& visitor) override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/op.hpp b/ngraph/core/include/ngraph/op/op.hpp index 495c3037c29..8581b850c11 100644 --- a/ngraph/core/include/ngraph/op/op.hpp +++ b/ngraph/core/include/ngraph/op/op.hpp @@ -22,5 +22,5 @@ namespace ngraph } Op(const OutputVector& arguments); }; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/pad.hpp b/ngraph/core/include/ngraph/op/pad.hpp index 3590241b7b0..73adca8a03b 100644 --- a/ngraph/core/include/ngraph/op/pad.hpp +++ b/ngraph/core/include/ngraph/op/pad.hpp @@ -80,6 +80,6 @@ namespace ngraph bool evaluate_pad(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/parameter.hpp b/ngraph/core/include/ngraph/op/parameter.hpp index 0bab533dc0e..50de93b529b 100644 --- a/ngraph/core/include/ngraph/op/parameter.hpp +++ b/ngraph/core/include/ngraph/op/parameter.hpp @@ -58,9 +58,9 @@ namespace ngraph element::Type m_element_type; bool m_is_relevant_to_shapes; }; - } + } // namespace v0 using v0::Parameter; - } + } // namespace op using ParameterVector = std::vector>; template <> @@ -77,4 +77,4 @@ namespace ngraph protected: ParameterVector& m_ref; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/power.hpp b/ngraph/core/include/ngraph/op/power.hpp index 471fd36e568..ce7b37f59d8 100644 --- a/ngraph/core/include/ngraph/op/power.hpp +++ b/ngraph/core/include/ngraph/op/power.hpp @@ -54,5 +54,5 @@ namespace ngraph const HostTensorVector& inputs) const override; }; } // namespace v1 - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/prelu.hpp b/ngraph/core/include/ngraph/op/prelu.hpp index 64f322ec97a..f3ffca22510 100644 --- a/ngraph/core/include/ngraph/op/prelu.hpp +++ b/ngraph/core/include/ngraph/op/prelu.hpp @@ -38,7 +38,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::PRelu; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/prior_box.hpp b/ngraph/core/include/ngraph/op/prior_box.hpp index 2e0318af7cc..5267da03b87 100644 --- a/ngraph/core/include/ngraph/op/prior_box.hpp +++ b/ngraph/core/include/ngraph/op/prior_box.hpp @@ -70,7 +70,7 @@ namespace ngraph private: PriorBoxAttrs m_attrs; }; - } + } // namespace v0 using v0::PriorBox; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/prior_box_clustered.hpp b/ngraph/core/include/ngraph/op/prior_box_clustered.hpp index c890b533591..b519b5427e3 100644 --- a/ngraph/core/include/ngraph/op/prior_box_clustered.hpp +++ b/ngraph/core/include/ngraph/op/prior_box_clustered.hpp @@ -58,7 +58,7 @@ namespace ngraph private: PriorBoxClusteredAttrs m_attrs; }; - } + } // namespace v0 using v0::PriorBoxClustered; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/proposal.hpp b/ngraph/core/include/ngraph/op/proposal.hpp index 1b9a11b1e68..87998b67e69 100644 --- a/ngraph/core/include/ngraph/op/proposal.hpp +++ b/ngraph/core/include/ngraph/op/proposal.hpp @@ -70,7 +70,7 @@ namespace ngraph protected: ProposalAttrs m_attrs; }; - } + } // namespace v0 namespace v4 { @@ -95,8 +95,8 @@ namespace ngraph clone_with_new_inputs(const OutputVector& new_args) const override; const ProposalAttrs& get_attrs() const { return m_attrs; } }; - } + } // namespace v4 using v0::Proposal; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/psroi_pooling.hpp b/ngraph/core/include/ngraph/op/psroi_pooling.hpp index c664b8d5646..ca7162a824a 100644 --- a/ngraph/core/include/ngraph/op/psroi_pooling.hpp +++ b/ngraph/core/include/ngraph/op/psroi_pooling.hpp @@ -60,7 +60,7 @@ namespace ngraph int m_spatial_bins_y; std::string m_mode; }; - } + } // namespace v0 using v0::PSROIPooling; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/range.hpp b/ngraph/core/include/ngraph/op/range.hpp index 47b90ae2316..f40347021d5 100644 --- a/ngraph/core/include/ngraph/op/range.hpp +++ b/ngraph/core/include/ngraph/op/range.hpp @@ -46,7 +46,7 @@ namespace ngraph private: element::Type m_output_type; }; - } + } // namespace v4 namespace v0 { /// \brief Range operation, analogous to `range()` in Python. @@ -78,7 +78,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Range; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/read_value.hpp b/ngraph/core/include/ngraph/op/read_value.hpp index 83be3c11550..b4978d30b8c 100644 --- a/ngraph/core/include/ngraph/op/read_value.hpp +++ b/ngraph/core/include/ngraph/op/read_value.hpp @@ -77,7 +77,7 @@ namespace ngraph private: std::string m_variable_id; }; - } + } // namespace v3 namespace v6 { @@ -114,6 +114,6 @@ namespace ngraph return m_variable->get_info().variable_id; } }; - } - } -} + } // namespace v6 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_l1.hpp b/ngraph/core/include/ngraph/op/reduce_l1.hpp index 1329b5d9e22..1d09233ec6a 100644 --- a/ngraph/core/include/ngraph/op/reduce_l1.hpp +++ b/ngraph/core/include/ngraph/op/reduce_l1.hpp @@ -41,6 +41,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_l2.hpp b/ngraph/core/include/ngraph/op/reduce_l2.hpp index 1daa8697acd..547db7ff783 100644 --- a/ngraph/core/include/ngraph/op/reduce_l2.hpp +++ b/ngraph/core/include/ngraph/op/reduce_l2.hpp @@ -40,6 +40,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_logical_and.hpp b/ngraph/core/include/ngraph/op/reduce_logical_and.hpp index 3f969363e92..09050dfd2fe 100644 --- a/ngraph/core/include/ngraph/op/reduce_logical_and.hpp +++ b/ngraph/core/include/ngraph/op/reduce_logical_and.hpp @@ -37,6 +37,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_logical_or.hpp b/ngraph/core/include/ngraph/op/reduce_logical_or.hpp index ee9564f9a23..cb3b668eaf3 100644 --- a/ngraph/core/include/ngraph/op/reduce_logical_or.hpp +++ b/ngraph/core/include/ngraph/op/reduce_logical_or.hpp @@ -37,6 +37,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_mean.hpp b/ngraph/core/include/ngraph/op/reduce_mean.hpp index 9f0f3bdb262..c5437a3f622 100644 --- a/ngraph/core/include/ngraph/op/reduce_mean.hpp +++ b/ngraph/core/include/ngraph/op/reduce_mean.hpp @@ -33,6 +33,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reduce_prod.hpp b/ngraph/core/include/ngraph/op/reduce_prod.hpp index b3904a76da9..367d4cddd1c 100644 --- a/ngraph/core/include/ngraph/op/reduce_prod.hpp +++ b/ngraph/core/include/ngraph/op/reduce_prod.hpp @@ -42,6 +42,6 @@ namespace ngraph bool evaluate_lower(const HostTensorVector& outputs) const override; bool evaluate_upper(const HostTensorVector& outputs) const override; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/relu.hpp b/ngraph/core/include/ngraph/op/relu.hpp index 91d0cc6ae8f..89c603e107e 100644 --- a/ngraph/core/include/ngraph/op/relu.hpp +++ b/ngraph/core/include/ngraph/op/relu.hpp @@ -36,7 +36,7 @@ namespace ngraph const HostTensorVector& inputs) const override; bool visit_attributes(AttributeVisitor& visitor) override; }; - } + } // namespace v0 using v0::Relu; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reorg_yolo.hpp b/ngraph/core/include/ngraph/op/reorg_yolo.hpp index 402b999a208..1e8467ae0b3 100644 --- a/ngraph/core/include/ngraph/op/reorg_yolo.hpp +++ b/ngraph/core/include/ngraph/op/reorg_yolo.hpp @@ -39,7 +39,7 @@ namespace ngraph private: Strides m_strides; }; - } + } // namespace v0 using v0::ReorgYolo; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reshape.hpp b/ngraph/core/include/ngraph/op/reshape.hpp index 7c55fb5d507..0f3bf028153 100644 --- a/ngraph/core/include/ngraph/op/reshape.hpp +++ b/ngraph/core/include/ngraph/op/reshape.hpp @@ -64,6 +64,6 @@ namespace ngraph bool evaluate_reshape(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/result.hpp b/ngraph/core/include/ngraph/op/result.hpp index c0c0f113b76..15e04ff7b69 100644 --- a/ngraph/core/include/ngraph/op/result.hpp +++ b/ngraph/core/include/ngraph/op/result.hpp @@ -42,10 +42,10 @@ namespace ngraph private: bool m_needs_default_layout{false}; }; - } + } // namespace v0 using v0::Result; - } + } // namespace op using ResultVector = std::vector>; template <> @@ -62,4 +62,4 @@ namespace ngraph protected: ResultVector& m_ref; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reverse.hpp b/ngraph/core/include/ngraph/op/reverse.hpp index aca1ea40385..9c0ea573a99 100644 --- a/ngraph/core/include/ngraph/op/reverse.hpp +++ b/ngraph/core/include/ngraph/op/reverse.hpp @@ -66,8 +66,8 @@ namespace ngraph bool evaluate_reverse(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } - } + } // namespace v1 + } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v1::Reverse::Mode& type); @@ -85,4 +85,4 @@ namespace ngraph static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/reverse_sequence.hpp b/ngraph/core/include/ngraph/op/reverse_sequence.hpp index 765156e7343..0e5fe300528 100644 --- a/ngraph/core/include/ngraph/op/reverse_sequence.hpp +++ b/ngraph/core/include/ngraph/op/reverse_sequence.hpp @@ -49,7 +49,7 @@ namespace ngraph size_t m_normalized_batch_axis; size_t m_normalized_seq_axis; }; - } + } // namespace v0 using v0::ReverseSequence; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/rnn_cell.hpp b/ngraph/core/include/ngraph/op/rnn_cell.hpp index 1e7b54b957b..e01793ccf88 100644 --- a/ngraph/core/include/ngraph/op/rnn_cell.hpp +++ b/ngraph/core/include/ngraph/op/rnn_cell.hpp @@ -135,6 +135,6 @@ namespace ngraph static constexpr std::size_t s_gates_count{1}; }; - } - } // namespace op + } // namespace v0 + } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/rnn_sequence.hpp b/ngraph/core/include/ngraph/op/rnn_sequence.hpp index 072c45ddf75..f08601413c9 100644 --- a/ngraph/core/include/ngraph/op/rnn_sequence.hpp +++ b/ngraph/core/include/ngraph/op/rnn_sequence.hpp @@ -50,6 +50,6 @@ namespace ngraph protected: op::RecurrentSequenceDirection m_direction; }; - } - } // namespace op + } // namespace v5 + } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/round.hpp b/ngraph/core/include/ngraph/op/round.hpp index 8e9832f6c04..f9bfb630a27 100644 --- a/ngraph/core/include/ngraph/op/round.hpp +++ b/ngraph/core/include/ngraph/op/round.hpp @@ -53,8 +53,8 @@ namespace ngraph private: RoundMode m_mode; }; - } - } + } // namespace v5 + } // namespace op NGRAPH_API std::ostream& operator<<(std::ostream& s, const op::v5::Round::RoundMode& type); @@ -72,4 +72,4 @@ namespace ngraph 5}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/scatter_elements_update.hpp b/ngraph/core/include/ngraph/op/scatter_elements_update.hpp index 89de7aee85b..38188cc4260 100644 --- a/ngraph/core/include/ngraph/op/scatter_elements_update.hpp +++ b/ngraph/core/include/ngraph/op/scatter_elements_update.hpp @@ -45,7 +45,7 @@ namespace ngraph bool evaluate_scatter_element_update(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } + } // namespace v3 using v3::ScatterElementsUpdate; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/scatter_nd_update.hpp b/ngraph/core/include/ngraph/op/scatter_nd_update.hpp index 3fccbdee97a..a144e455859 100644 --- a/ngraph/core/include/ngraph/op/scatter_nd_update.hpp +++ b/ngraph/core/include/ngraph/op/scatter_nd_update.hpp @@ -35,7 +35,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v3 using v3::ScatterNDUpdate; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/scatter_update.hpp b/ngraph/core/include/ngraph/op/scatter_update.hpp index 915c02eb989..a3989ecd92a 100644 --- a/ngraph/core/include/ngraph/op/scatter_update.hpp +++ b/ngraph/core/include/ngraph/op/scatter_update.hpp @@ -46,6 +46,6 @@ namespace ngraph bool evaluate_scatter_update(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } - } -} + } // namespace v3 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/selu.hpp b/ngraph/core/include/ngraph/op/selu.hpp index 3c827872bfc..9d71f71936b 100644 --- a/ngraph/core/include/ngraph/op/selu.hpp +++ b/ngraph/core/include/ngraph/op/selu.hpp @@ -38,7 +38,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v0 using v0::Selu; } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/shape_of.hpp b/ngraph/core/include/ngraph/op/shape_of.hpp index 6158d3c9321..e7b6c9c565a 100644 --- a/ngraph/core/include/ngraph/op/shape_of.hpp +++ b/ngraph/core/include/ngraph/op/shape_of.hpp @@ -52,7 +52,7 @@ namespace ngraph bool m_is_foldable = true; element::Type m_output_type; }; - } + } // namespace v3 namespace v0 { @@ -89,7 +89,7 @@ namespace ngraph private: bool m_is_foldable = true; }; - } + } // namespace v0 using v0::ShapeOf; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/shuffle_channels.hpp b/ngraph/core/include/ngraph/op/shuffle_channels.hpp index 0506ce57a92..0cfcad09d8d 100644 --- a/ngraph/core/include/ngraph/op/shuffle_channels.hpp +++ b/ngraph/core/include/ngraph/op/shuffle_channels.hpp @@ -61,7 +61,7 @@ namespace ngraph int64_t m_axis; int64_t m_group; }; - } + } // namespace v0 using v0::ShuffleChannels; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sigmoid.hpp b/ngraph/core/include/ngraph/op/sigmoid.hpp index 3033834a5cc..9518678a467 100644 --- a/ngraph/core/include/ngraph/op/sigmoid.hpp +++ b/ngraph/core/include/ngraph/op/sigmoid.hpp @@ -27,7 +27,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Sigmoid; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sign.hpp b/ngraph/core/include/ngraph/op/sign.hpp index 06151904d65..2c6e38d353b 100644 --- a/ngraph/core/include/ngraph/op/sign.hpp +++ b/ngraph/core/include/ngraph/op/sign.hpp @@ -31,7 +31,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Sign; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sin.hpp b/ngraph/core/include/ngraph/op/sin.hpp index 9660925ce79..a04e62d4322 100644 --- a/ngraph/core/include/ngraph/op/sin.hpp +++ b/ngraph/core/include/ngraph/op/sin.hpp @@ -44,7 +44,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Sin; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sinh.hpp b/ngraph/core/include/ngraph/op/sinh.hpp index d659a28b951..df38da42364 100644 --- a/ngraph/core/include/ngraph/op/sinh.hpp +++ b/ngraph/core/include/ngraph/op/sinh.hpp @@ -30,7 +30,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Sinh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sink.hpp b/ngraph/core/include/ngraph/op/sink.hpp index 4c7a39da0de..db57bcb273c 100644 --- a/ngraph/core/include/ngraph/op/sink.hpp +++ b/ngraph/core/include/ngraph/op/sink.hpp @@ -30,6 +30,6 @@ namespace ngraph { } }; - } + } // namespace op using SinkVector = std::vector>; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/softmax.hpp b/ngraph/core/include/ngraph/op/softmax.hpp index d90df0fc864..0790fb0d772 100644 --- a/ngraph/core/include/ngraph/op/softmax.hpp +++ b/ngraph/core/include/ngraph/op/softmax.hpp @@ -46,6 +46,6 @@ namespace ngraph private: size_t m_axis; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/softplus.hpp b/ngraph/core/include/ngraph/op/softplus.hpp index 221442b9506..4f775d38907 100644 --- a/ngraph/core/include/ngraph/op/softplus.hpp +++ b/ngraph/core/include/ngraph/op/softplus.hpp @@ -35,6 +35,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/space_to_batch.hpp b/ngraph/core/include/ngraph/op/space_to_batch.hpp index 21ddf1c5175..82e052d97ec 100644 --- a/ngraph/core/include/ngraph/op/space_to_batch.hpp +++ b/ngraph/core/include/ngraph/op/space_to_batch.hpp @@ -56,7 +56,7 @@ namespace ngraph bool evaluate_space_to_batch(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } + } // namespace v1 using v1::SpaceToBatch; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/space_to_depth.hpp b/ngraph/core/include/ngraph/op/space_to_depth.hpp index 51b4fe9a631..536027213a2 100644 --- a/ngraph/core/include/ngraph/op/space_to_depth.hpp +++ b/ngraph/core/include/ngraph/op/space_to_depth.hpp @@ -67,7 +67,7 @@ namespace ngraph bool evaluate_space_to_depth(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } + } // namespace v0 using v0::SpaceToDepth; } // namespace op diff --git a/ngraph/core/include/ngraph/op/split.hpp b/ngraph/core/include/ngraph/op/split.hpp index aa2efb69359..90851cadd3d 100644 --- a/ngraph/core/include/ngraph/op/split.hpp +++ b/ngraph/core/include/ngraph/op/split.hpp @@ -45,6 +45,6 @@ namespace ngraph protected: size_t m_num_splits; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/sqrt.hpp b/ngraph/core/include/ngraph/op/sqrt.hpp index 5e0d887a21a..ea601e969c9 100644 --- a/ngraph/core/include/ngraph/op/sqrt.hpp +++ b/ngraph/core/include/ngraph/op/sqrt.hpp @@ -44,7 +44,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Sqrt; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/squared_difference.hpp b/ngraph/core/include/ngraph/op/squared_difference.hpp index 5e0c018e772..1ebc41eefa7 100644 --- a/ngraph/core/include/ngraph/op/squared_difference.hpp +++ b/ngraph/core/include/ngraph/op/squared_difference.hpp @@ -38,7 +38,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v0 using v0::SquaredDifference; } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/squeeze.hpp b/ngraph/core/include/ngraph/op/squeeze.hpp index 1ae837cc6f6..4bfeb78bbf9 100644 --- a/ngraph/core/include/ngraph/op/squeeze.hpp +++ b/ngraph/core/include/ngraph/op/squeeze.hpp @@ -42,7 +42,7 @@ namespace ngraph private: Output get_default_axes_input() const; }; - } + } // namespace v0 using v0::Squeeze; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/strided_slice.hpp b/ngraph/core/include/ngraph/op/strided_slice.hpp index b1f3624da8f..c3b78d2d56c 100644 --- a/ngraph/core/include/ngraph/op/strided_slice.hpp +++ b/ngraph/core/include/ngraph/op/strided_slice.hpp @@ -105,6 +105,6 @@ namespace ngraph std::vector m_shrink_axis_mask; std::vector m_ellipsis_mask; }; - } - } -} + } // namespace v1 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/swish.hpp b/ngraph/core/include/ngraph/op/swish.hpp index eb03fba5edd..8ef0b1d021c 100644 --- a/ngraph/core/include/ngraph/op/swish.hpp +++ b/ngraph/core/include/ngraph/op/swish.hpp @@ -40,6 +40,6 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } - } -} + } // namespace v4 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/tan.hpp b/ngraph/core/include/ngraph/op/tan.hpp index 386df888c85..16d55f0eaa6 100644 --- a/ngraph/core/include/ngraph/op/tan.hpp +++ b/ngraph/core/include/ngraph/op/tan.hpp @@ -44,7 +44,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Tan; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/tanh.hpp b/ngraph/core/include/ngraph/op/tanh.hpp index ff5ccac39cf..f3eb2513f71 100644 --- a/ngraph/core/include/ngraph/op/tanh.hpp +++ b/ngraph/core/include/ngraph/op/tanh.hpp @@ -30,7 +30,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v0 using v0::Tanh; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/tensor_iterator.hpp b/ngraph/core/include/ngraph/op/tensor_iterator.hpp index b2090fdf774..84330483aca 100644 --- a/ngraph/core/include/ngraph/op/tensor_iterator.hpp +++ b/ngraph/core/include/ngraph/op/tensor_iterator.hpp @@ -41,7 +41,7 @@ namespace ngraph private: void try_to_set_num_iterations_if_no_slice_inputs(); }; - } + } // namespace v0 using v0::TensorIterator; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/tile.hpp b/ngraph/core/include/ngraph/op/tile.hpp index fb65df10658..d05b97a97ea 100644 --- a/ngraph/core/include/ngraph/op/tile.hpp +++ b/ngraph/core/include/ngraph/op/tile.hpp @@ -40,6 +40,6 @@ namespace ngraph bool evaluate_tile(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; - } - } -} + } // namespace v0 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/topk.hpp b/ngraph/core/include/ngraph/op/topk.hpp index ab63c3ca28b..6f59e259ca6 100644 --- a/ngraph/core/include/ngraph/op/topk.hpp +++ b/ngraph/core/include/ngraph/op/topk.hpp @@ -156,5 +156,5 @@ namespace ngraph const element::Type& k_element_type) const override; }; } // namespace v3 - } // op -} // ngraph + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/transpose.hpp b/ngraph/core/include/ngraph/op/transpose.hpp index e0b934c9cdf..8e261d576f8 100644 --- a/ngraph/core/include/ngraph/op/transpose.hpp +++ b/ngraph/core/include/ngraph/op/transpose.hpp @@ -41,7 +41,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; }; - } + } // namespace v1 using v1::Transpose; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/unsqueeze.hpp b/ngraph/core/include/ngraph/op/unsqueeze.hpp index 6d9587aecd6..51dc8a5512d 100644 --- a/ngraph/core/include/ngraph/op/unsqueeze.hpp +++ b/ngraph/core/include/ngraph/op/unsqueeze.hpp @@ -37,7 +37,7 @@ namespace ngraph virtual std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; - } + } // namespace v0 using v0::Unsqueeze; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/activation_functions.hpp b/ngraph/core/include/ngraph/op/util/activation_functions.hpp index 2963f6c1d8b..1aed7242cb7 100644 --- a/ngraph/core/include/ngraph/op/util/activation_functions.hpp +++ b/ngraph/core/include/ngraph/op/util/activation_functions.hpp @@ -42,7 +42,7 @@ namespace ngraph { } }; - } + } // namespace error namespace detail { @@ -57,7 +57,7 @@ namespace ngraph float beta UNUSED_PARAMETER); std::shared_ptr hardsigmoid(const std::shared_ptr& arg, float alpha, float beta); - } + } // namespace detail using ActivationFunctionType = std::shared_ptr (*)(const std::shared_ptr&, float, diff --git a/ngraph/core/include/ngraph/op/util/arithmetic_reduction.hpp b/ngraph/core/include/ngraph/op/util/arithmetic_reduction.hpp index 893c54664c0..2d433e340d2 100644 --- a/ngraph/core/include/ngraph/op/util/arithmetic_reduction.hpp +++ b/ngraph/core/include/ngraph/op/util/arithmetic_reduction.hpp @@ -42,6 +42,6 @@ namespace ngraph /// \brief Change the reduction axes void set_reduction_axes(const AxisSet& reduction_axes); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/arithmetic_reductions_keep_dims.hpp b/ngraph/core/include/ngraph/op/util/arithmetic_reductions_keep_dims.hpp index f92d282ce42..aba6333663b 100644 --- a/ngraph/core/include/ngraph/op/util/arithmetic_reductions_keep_dims.hpp +++ b/ngraph/core/include/ngraph/op/util/arithmetic_reductions_keep_dims.hpp @@ -39,6 +39,6 @@ namespace ngraph private: bool m_keep_dims = false; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/attr_types.hpp b/ngraph/core/include/ngraph/op/util/attr_types.hpp index ea9f8516b8f..8f2b9078395 100644 --- a/ngraph/core/include/ngraph/op/util/attr_types.hpp +++ b/ngraph/core/include/ngraph/op/util/attr_types.hpp @@ -26,7 +26,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const PadMode& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase @@ -69,7 +69,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const PadType& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase @@ -95,7 +95,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const RoundingType& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter @@ -161,7 +161,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const AutoBroadcastType& type); - } + } // namespace op namespace op { /// \brief BroadcastType specifies rules used for mapping of input tensor axes to output @@ -191,7 +191,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const BroadcastType& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter @@ -234,7 +234,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const EpsMode& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase @@ -263,7 +263,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const TopKSortType& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter @@ -289,7 +289,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const TopKMode& type); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase @@ -342,7 +342,7 @@ namespace ngraph private: AutoBroadcastType type_from_string(const std::string& type) const; }; - } + } // namespace op template <> class AttributeAdapter : public VisitorAdapter @@ -394,7 +394,7 @@ namespace ngraph return a.m_type == m_type && a.m_axis == m_axis; } }; - } + } // namespace op template <> class AttributeAdapter : public VisitorAdapter @@ -427,7 +427,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const RecurrentSequenceDirection& direction); - } + } // namespace op template <> class NGRAPH_API AttributeAdapter @@ -443,4 +443,4 @@ namespace ngraph "AttributeAdapter", 1}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp b/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp index 34eaa0623bf..a151694ea08 100644 --- a/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp +++ b/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp @@ -67,6 +67,6 @@ namespace ngraph AutoBroadcastSpec m_autob; void validate_and_infer_elementwise_arithmetic(const op::AutoBroadcastSpec& autob); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/binary_elementwise_comparison.hpp b/ngraph/core/include/ngraph/op/util/binary_elementwise_comparison.hpp index e3df7b20960..64ca2502b41 100644 --- a/ngraph/core/include/ngraph/op/util/binary_elementwise_comparison.hpp +++ b/ngraph/core/include/ngraph/op/util/binary_elementwise_comparison.hpp @@ -64,6 +64,6 @@ namespace ngraph private: AutoBroadcastSpec m_autob; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/binary_elementwise_logical.hpp b/ngraph/core/include/ngraph/op/util/binary_elementwise_logical.hpp index 7925401be17..babe24813ec 100644 --- a/ngraph/core/include/ngraph/op/util/binary_elementwise_logical.hpp +++ b/ngraph/core/include/ngraph/op/util/binary_elementwise_logical.hpp @@ -64,6 +64,6 @@ namespace ngraph void validate_and_infer_elementwise_logical(const op::AutoBroadcastSpec& autob); AutoBroadcastSpec m_autob = AutoBroadcastSpec::NUMPY; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/broadcast_base.hpp b/ngraph/core/include/ngraph/op/util/broadcast_base.hpp index aa2c20d3bdb..6cb822c4941 100644 --- a/ngraph/core/include/ngraph/op/util/broadcast_base.hpp +++ b/ngraph/core/include/ngraph/op/util/broadcast_base.hpp @@ -88,6 +88,6 @@ namespace ngraph Shape get_target_shape(const HostTensorPtr& input1) const; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/elementwise_args.hpp b/ngraph/core/include/ngraph/op/util/elementwise_args.hpp index a050ea74ddd..309eefc45ec 100644 --- a/ngraph/core/include/ngraph/op/util/elementwise_args.hpp +++ b/ngraph/core/include/ngraph/op/util/elementwise_args.hpp @@ -15,5 +15,5 @@ namespace ngraph std::tuple validate_and_infer_elementwise_args( Node* node, const op::AutoBroadcastSpec& autob = op::AutoBroadcastSpec()); } - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/embeddingbag_offsets_base.hpp b/ngraph/core/include/ngraph/op/util/embeddingbag_offsets_base.hpp index a8990bedf15..b894d9047a9 100644 --- a/ngraph/core/include/ngraph/op/util/embeddingbag_offsets_base.hpp +++ b/ngraph/core/include/ngraph/op/util/embeddingbag_offsets_base.hpp @@ -65,6 +65,6 @@ namespace ngraph static constexpr int DEFAULT_INDEX = 3; static constexpr int PER_SAMPLE_WEIGHTS = 4; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/embeddingbag_packed_base.hpp b/ngraph/core/include/ngraph/op/util/embeddingbag_packed_base.hpp index 9ce6e611137..b60fd3c7f4a 100644 --- a/ngraph/core/include/ngraph/op/util/embeddingbag_packed_base.hpp +++ b/ngraph/core/include/ngraph/op/util/embeddingbag_packed_base.hpp @@ -49,7 +49,7 @@ namespace ngraph static constexpr int INDICES = 1; static constexpr int PER_SAMPLE_WEIGHTS = 2; }; - } + } // namespace util using util::EmbeddingBagPackedBase; - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/fft_base.hpp b/ngraph/core/include/ngraph/op/util/fft_base.hpp index 9652e43a6f6..32a566baaaf 100644 --- a/ngraph/core/include/ngraph/op/util/fft_base.hpp +++ b/ngraph/core/include/ngraph/op/util/fft_base.hpp @@ -41,6 +41,6 @@ namespace ngraph void validate(); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/fused_op.hpp b/ngraph/core/include/ngraph/op/util/fused_op.hpp index 7bbdb036415..f20069c4328 100644 --- a/ngraph/core/include/ngraph/op/util/fused_op.hpp +++ b/ngraph/core/include/ngraph/op/util/fused_op.hpp @@ -47,6 +47,6 @@ namespace ngraph /// FusedOp(const OutputVector& args); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/gather_base.hpp b/ngraph/core/include/ngraph/op/util/gather_base.hpp index e6bd909731d..b13c2ad722c 100644 --- a/ngraph/core/include/ngraph/op/util/gather_base.hpp +++ b/ngraph/core/include/ngraph/op/util/gather_base.hpp @@ -45,6 +45,6 @@ namespace ngraph protected: int64_t m_batch_dims = 0; }; - } // namespace utils + } // namespace util } // namespace op } // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/index_reduction.hpp b/ngraph/core/include/ngraph/op/util/index_reduction.hpp index c745139932b..88a1e8501f3 100644 --- a/ngraph/core/include/ngraph/op/util/index_reduction.hpp +++ b/ngraph/core/include/ngraph/op/util/index_reduction.hpp @@ -38,6 +38,6 @@ namespace ngraph uint64_t m_axis{0}; element::Type m_index_element_type; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/logical_reduction.hpp b/ngraph/core/include/ngraph/op/util/logical_reduction.hpp index e5d0d95ba38..0fa85369b31 100644 --- a/ngraph/core/include/ngraph/op/util/logical_reduction.hpp +++ b/ngraph/core/include/ngraph/op/util/logical_reduction.hpp @@ -44,6 +44,6 @@ namespace ngraph const AxisSet get_reduction_axes() const; void set_reduction_axes(const AxisSet& reduction_axes); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/logical_reduction_keep_dims.hpp b/ngraph/core/include/ngraph/op/util/logical_reduction_keep_dims.hpp index 340f377f67f..602b02582f2 100644 --- a/ngraph/core/include/ngraph/op/util/logical_reduction_keep_dims.hpp +++ b/ngraph/core/include/ngraph/op/util/logical_reduction_keep_dims.hpp @@ -39,6 +39,6 @@ namespace ngraph private: bool m_keep_dims = false; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/op_annotations.hpp b/ngraph/core/include/ngraph/op/util/op_annotations.hpp index cfe58a39f5e..6cb5c2b09c7 100644 --- a/ngraph/core/include/ngraph/op/util/op_annotations.hpp +++ b/ngraph/core/include/ngraph/op/util/op_annotations.hpp @@ -53,6 +53,6 @@ namespace ngraph bool m_cacheable = false; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/op_types.hpp b/ngraph/core/include/ngraph/op/util/op_types.hpp index 950c2cab0b9..b672f5518c4 100644 --- a/ngraph/core/include/ngraph/op/util/op_types.hpp +++ b/ngraph/core/include/ngraph/op/util/op_types.hpp @@ -63,5 +63,5 @@ namespace ngraph bool is_constant(const std::shared_ptr& node); NGRAPH_API bool is_commutative(const std::shared_ptr& node); - } -} + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/scatter_base.hpp b/ngraph/core/include/ngraph/op/util/scatter_base.hpp index 8a0123a88ac..869fbeaca93 100644 --- a/ngraph/core/include/ngraph/op/util/scatter_base.hpp +++ b/ngraph/core/include/ngraph/op/util/scatter_base.hpp @@ -46,6 +46,6 @@ namespace ngraph static constexpr int UPDATES = 2; static constexpr int AXIS = 3; }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/scatter_nd_base.hpp b/ngraph/core/include/ngraph/op/util/scatter_nd_base.hpp index c34845fe57a..795780298d7 100644 --- a/ngraph/core/include/ngraph/op/util/scatter_nd_base.hpp +++ b/ngraph/core/include/ngraph/op/util/scatter_nd_base.hpp @@ -41,6 +41,6 @@ namespace ngraph const Output& indices, const Output& updates); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 7dbf9a5a887..a44c830b78c 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -338,8 +338,8 @@ namespace ngraph using OutputDescriptionPtr = std::shared_ptr; using InputDescriptionVector = std::vector; using OutputDescriptionVector = std::vector; - } - } + } // namespace util + } // namespace op template <> class NGRAPH_API AttributeAdapter< @@ -384,4 +384,4 @@ namespace ngraph 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/unary_elementwise_arithmetic.hpp b/ngraph/core/include/ngraph/op/util/unary_elementwise_arithmetic.hpp index 4899c345d14..2e6468f71ce 100644 --- a/ngraph/core/include/ngraph/op/util/unary_elementwise_arithmetic.hpp +++ b/ngraph/core/include/ngraph/op/util/unary_elementwise_arithmetic.hpp @@ -52,6 +52,6 @@ namespace ngraph private: void validate_and_infer_elementwise_arithmetic(); }; - } - } -} + } // namespace util + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/variable.hpp b/ngraph/core/include/ngraph/op/util/variable.hpp index 59405140086..287949c562c 100644 --- a/ngraph/core/include/ngraph/op/util/variable.hpp +++ b/ngraph/core/include/ngraph/op/util/variable.hpp @@ -48,4 +48,4 @@ namespace ngraph 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset.hpp b/ngraph/core/include/ngraph/opsets/opset.hpp index 2bed2ab3baa..f0929ed839d 100644 --- a/ngraph/core/include/ngraph/opsets/opset.hpp +++ b/ngraph/core/include/ngraph/opsets/opset.hpp @@ -124,4 +124,4 @@ namespace ngraph const NGRAPH_API OpSet& get_opset5(); const NGRAPH_API OpSet& get_opset6(); const NGRAPH_API OpSet& get_opset7(); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset1.hpp b/ngraph/core/include/ngraph/opsets/opset1.hpp index 0b7e9680202..60607b6f07b 100644 --- a/ngraph/core/include/ngraph/opsets/opset1.hpp +++ b/ngraph/core/include/ngraph/opsets/opset1.hpp @@ -13,5 +13,5 @@ namespace ngraph #define NGRAPH_OP(a, b) using b::a; #include "ngraph/opsets/opset1_tbl.hpp" #undef NGRAPH_OP - } -} + } // namespace opset1 +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset2.hpp b/ngraph/core/include/ngraph/opsets/opset2.hpp index 50fae745925..8665980a89d 100644 --- a/ngraph/core/include/ngraph/opsets/opset2.hpp +++ b/ngraph/core/include/ngraph/opsets/opset2.hpp @@ -14,5 +14,5 @@ namespace ngraph #define NGRAPH_OP(a, b) using b::a; #include "ngraph/opsets/opset2_tbl.hpp" #undef NGRAPH_OP - } -} + } // namespace opset2 +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset3.hpp b/ngraph/core/include/ngraph/opsets/opset3.hpp index 3562cd8aed6..0978f1351d5 100644 --- a/ngraph/core/include/ngraph/opsets/opset3.hpp +++ b/ngraph/core/include/ngraph/opsets/opset3.hpp @@ -13,5 +13,5 @@ namespace ngraph #define NGRAPH_OP(a, b) using b::a; #include "ngraph/opsets/opset3_tbl.hpp" #undef NGRAPH_OP - } -} + } // namespace opset3 +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset4.hpp b/ngraph/core/include/ngraph/opsets/opset4.hpp index 027a27e19b2..fb4ce821288 100644 --- a/ngraph/core/include/ngraph/opsets/opset4.hpp +++ b/ngraph/core/include/ngraph/opsets/opset4.hpp @@ -13,5 +13,5 @@ namespace ngraph #define NGRAPH_OP(a, b) using b::a; #include "ngraph/opsets/opset4_tbl.hpp" #undef NGRAPH_OP - } -} + } // namespace opset4 +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/opsets/opset5.hpp b/ngraph/core/include/ngraph/opsets/opset5.hpp index 00f42365ca6..0ac11dce44b 100644 --- a/ngraph/core/include/ngraph/opsets/opset5.hpp +++ b/ngraph/core/include/ngraph/opsets/opset5.hpp @@ -13,5 +13,5 @@ namespace ngraph #define NGRAPH_OP(a, b) using b::a; #include "ngraph/opsets/opset5_tbl.hpp" #undef NGRAPH_OP - } -} + } // namespace opset5 +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/output_vector.hpp b/ngraph/core/include/ngraph/output_vector.hpp index 2e366531857..2fc31c94fca 100644 --- a/ngraph/core/include/ngraph/output_vector.hpp +++ b/ngraph/core/include/ngraph/output_vector.hpp @@ -16,4 +16,4 @@ namespace ngraph using NodeVector = std::vector>; using OutputVector = std::vector>; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/partial_shape.hpp b/ngraph/core/include/ngraph/partial_shape.hpp index 5813bf3f15e..c100273d765 100644 --- a/ngraph/core/include/ngraph/partial_shape.hpp +++ b/ngraph/core/include/ngraph/partial_shape.hpp @@ -365,4 +365,4 @@ namespace ngraph std::vector m_buffer; bool m_buffer_valid{false}; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pass/manager.hpp b/ngraph/core/include/ngraph/pass/manager.hpp index f0cfde11fef..4ea4e50a316 100644 --- a/ngraph/core/include/ngraph/pass/manager.hpp +++ b/ngraph/core/include/ngraph/pass/manager.hpp @@ -115,5 +115,5 @@ namespace ngraph bool m_visualize = false; bool m_per_pass_validation = true; }; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pass/pass.hpp b/ngraph/core/include/ngraph/pass/pass.hpp index 1b5027d8739..ce3d4d528f1 100644 --- a/ngraph/core/include/ngraph/pass/pass.hpp +++ b/ngraph/core/include/ngraph/pass/pass.hpp @@ -120,5 +120,5 @@ namespace ngraph ALL_FUSIONS = 0xFFFFFFFF }; typedef EnumMask FusionTypeMask; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pass/pass_config.hpp b/ngraph/core/include/ngraph/pass/pass_config.hpp index 98f276e9d5d..14884a69bfb 100644 --- a/ngraph/core/include/ngraph/pass/pass_config.hpp +++ b/ngraph/core/include/ngraph/pass/pass_config.hpp @@ -183,5 +183,5 @@ namespace ngraph std::unordered_set m_disabled; std::unordered_set m_enabled; }; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pass/validate.hpp b/ngraph/core/include/ngraph/pass/validate.hpp index 3517334e336..a1c4a92d80e 100644 --- a/ngraph/core/include/ngraph/pass/validate.hpp +++ b/ngraph/core/include/ngraph/pass/validate.hpp @@ -33,5 +33,5 @@ namespace ngraph } bool run_on_function(std::shared_ptr f) override; }; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pass/visualize_tree.hpp b/ngraph/core/include/ngraph/pass/visualize_tree.hpp index 3b801daaec5..c65a96175a6 100644 --- a/ngraph/core/include/ngraph/pass/visualize_tree.hpp +++ b/ngraph/core/include/ngraph/pass/visualize_tree.hpp @@ -61,5 +61,5 @@ namespace ngraph bool m_dot_only; static const int max_jump_distance; }; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/matcher.hpp b/ngraph/core/include/ngraph/pattern/matcher.hpp index 20d7b305ca3..c27773c3e17 100644 --- a/ngraph/core/include/ngraph/pattern/matcher.hpp +++ b/ngraph/core/include/ngraph/pattern/matcher.hpp @@ -272,5 +272,5 @@ namespace ngraph RPatternValueMap m_matches; Output m_match_root; }; - } -} + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/any.hpp b/ngraph/core/include/ngraph/pattern/op/any.hpp index ae3de355935..019fa20901c 100644 --- a/ngraph/core/include/ngraph/pattern/op/any.hpp +++ b/ngraph/core/include/ngraph/pattern/op/any.hpp @@ -57,6 +57,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/any_of.hpp b/ngraph/core/include/ngraph/pattern/op/any_of.hpp index 37b52e75b92..2560a1e8f9c 100644 --- a/ngraph/core/include/ngraph/pattern/op/any_of.hpp +++ b/ngraph/core/include/ngraph/pattern/op/any_of.hpp @@ -71,6 +71,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/any_output.hpp b/ngraph/core/include/ngraph/pattern/op/any_output.hpp index cd59f66caba..ff0c520a306 100644 --- a/ngraph/core/include/ngraph/pattern/op/any_output.hpp +++ b/ngraph/core/include/ngraph/pattern/op/any_output.hpp @@ -30,6 +30,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/branch.hpp b/ngraph/core/include/ngraph/pattern/op/branch.hpp index 3b4c832622c..fa3f09d6d05 100644 --- a/ngraph/core/include/ngraph/pattern/op/branch.hpp +++ b/ngraph/core/include/ngraph/pattern/op/branch.hpp @@ -57,6 +57,6 @@ namespace ngraph Node* m_destination_node{nullptr}; size_t m_destination_index{0}; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/capture.hpp b/ngraph/core/include/ngraph/pattern/op/capture.hpp index 9413fc5d278..2eed02824c8 100644 --- a/ngraph/core/include/ngraph/pattern/op/capture.hpp +++ b/ngraph/core/include/ngraph/pattern/op/capture.hpp @@ -42,6 +42,6 @@ namespace ngraph protected: std::set m_static_nodes; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/label.hpp b/ngraph/core/include/ngraph/pattern/op/label.hpp index b78f9ac253b..226719fc7ec 100644 --- a/ngraph/core/include/ngraph/pattern/op/label.hpp +++ b/ngraph/core/include/ngraph/pattern/op/label.hpp @@ -131,12 +131,12 @@ namespace ngraph protected: static Output wrap_values(const OutputVector& wrapped_values); }; - } + } // namespace op NGRAPH_API std::shared_ptr any_input(); NGRAPH_API std::shared_ptr any_input(const pattern::op::ValuePredicate& pred); - } -} + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/or.hpp b/ngraph/core/include/ngraph/pattern/op/or.hpp index 6b4247f64d5..cbb4e2f89e0 100644 --- a/ngraph/core/include/ngraph/pattern/op/or.hpp +++ b/ngraph/core/include/ngraph/pattern/op/or.hpp @@ -32,6 +32,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/pattern.hpp b/ngraph/core/include/ngraph/pattern/op/pattern.hpp index e7ce75608e6..ff40fc79588 100644 --- a/ngraph/core/include/ngraph/pattern/op/pattern.hpp +++ b/ngraph/core/include/ngraph/pattern/op/pattern.hpp @@ -100,6 +100,6 @@ namespace ngraph protected: ValuePredicate m_predicate; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/skip.hpp b/ngraph/core/include/ngraph/pattern/op/skip.hpp index bf90868bb3c..ad86bc9c9de 100644 --- a/ngraph/core/include/ngraph/pattern/op/skip.hpp +++ b/ngraph/core/include/ngraph/pattern/op/skip.hpp @@ -51,6 +51,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/true.hpp b/ngraph/core/include/ngraph/pattern/op/true.hpp index e6d72e6fd4f..54394fb48e9 100644 --- a/ngraph/core/include/ngraph/pattern/op/true.hpp +++ b/ngraph/core/include/ngraph/pattern/op/true.hpp @@ -28,6 +28,6 @@ namespace ngraph const Output& pattern_value, const Output& graph_value) override; }; - } - } -} + } // namespace op + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/pattern/op/wrap_type.hpp b/ngraph/core/include/ngraph/pattern/op/wrap_type.hpp index abd9cc7b923..1594cec795b 100644 --- a/ngraph/core/include/ngraph/pattern/op/wrap_type.hpp +++ b/ngraph/core/include/ngraph/pattern/op/wrap_type.hpp @@ -50,7 +50,7 @@ namespace ngraph private: std::vector m_wrapped_types; }; - } + } // namespace op template std::shared_ptr wrap_type(const OutputVector& inputs, @@ -71,5 +71,5 @@ namespace ngraph { return wrap_type({}, pred); } - } -} + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/provenance.hpp b/ngraph/core/include/ngraph/provenance.hpp index fe1bf511ff4..b30a051e06d 100644 --- a/ngraph/core/include/ngraph/provenance.hpp +++ b/ngraph/core/include/ngraph/provenance.hpp @@ -16,4 +16,4 @@ namespace ngraph void set_provenance_enabled(bool enabled); NGRAPH_API bool get_provenance_enabled(); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/rank.hpp b/ngraph/core/include/ngraph/rank.hpp index c7cbd53f0ab..6ffddf49012 100644 --- a/ngraph/core/include/ngraph/rank.hpp +++ b/ngraph/core/include/ngraph/rank.hpp @@ -13,4 +13,4 @@ namespace ngraph /// /// XXX: THIS TYPE IS EXPERIMENTAL AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE. using Rank = Dimension; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/rt_info.hpp b/ngraph/core/include/ngraph/rt_info.hpp index edd2ffd016b..8e826a7a386 100644 --- a/ngraph/core/include/ngraph/rt_info.hpp +++ b/ngraph/core/include/ngraph/rt_info.hpp @@ -23,4 +23,4 @@ namespace ngraph NGRAPH_API void copy_runtime_info(const ngraph::NodeVector& from, ngraph::NodeVector to); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp b/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp index 5f550540793..474868c6978 100644 --- a/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp +++ b/ngraph/core/include/ngraph/runtime/aligned_buffer.hpp @@ -60,7 +60,7 @@ namespace ngraph char* m_aligned_buffer; size_t m_byte_size; }; - } + } // namespace runtime template <> class NGRAPH_API AttributeAdapter> : public DirectValueAccessor> @@ -72,4 +72,4 @@ namespace ngraph "AttributeAdapter>", 0}; const DiscreteTypeInfo& get_type_info() const override { return type_info; } }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/runtime/host_tensor.hpp b/ngraph/core/include/ngraph/runtime/host_tensor.hpp index 961630fbaa1..7a97a5d8ccd 100644 --- a/ngraph/core/include/ngraph/runtime/host_tensor.hpp +++ b/ngraph/core/include/ngraph/runtime/host_tensor.hpp @@ -19,7 +19,7 @@ namespace ngraph { class Constant; } - } + } // namespace op namespace runtime { class NGRAPH_API HostTensor : public ngraph::runtime::Tensor @@ -121,5 +121,5 @@ namespace ngraph void* m_aligned_buffer_pool{nullptr}; size_t m_buffer_size; }; - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/runtime/shared_buffer.hpp b/ngraph/core/include/ngraph/runtime/shared_buffer.hpp index e30d7b3f5c4..40afce2f66b 100644 --- a/ngraph/core/include/ngraph/runtime/shared_buffer.hpp +++ b/ngraph/core/include/ngraph/runtime/shared_buffer.hpp @@ -35,5 +35,5 @@ namespace ngraph private: T _shared_object; }; - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/runtime/tensor.hpp b/ngraph/core/include/ngraph/runtime/tensor.hpp index 72e5e8248ac..c886108fe72 100644 --- a/ngraph/core/include/ngraph/runtime/tensor.hpp +++ b/ngraph/core/include/ngraph/runtime/tensor.hpp @@ -84,5 +84,5 @@ namespace ngraph std::shared_ptr m_descriptor; bool m_stale; }; - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/shape.hpp b/ngraph/core/include/ngraph/shape.hpp index 1d03e62ae13..7f38ba8e29d 100644 --- a/ngraph/core/include/ngraph/shape.hpp +++ b/ngraph/core/include/ngraph/shape.hpp @@ -106,4 +106,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const Shape& shape); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/shape_util.hpp b/ngraph/core/include/ngraph/shape_util.hpp index a5d08aae8fd..d25708f1551 100644 --- a/ngraph/core/include/ngraph/shape_util.hpp +++ b/ngraph/core/include/ngraph/shape_util.hpp @@ -108,4 +108,4 @@ namespace ngraph std::vector>{ std::pair(new_axis_pos, new_axis_val)}); } -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/slice_plan.hpp b/ngraph/core/include/ngraph/slice_plan.hpp index 254e09bb4d1..cc26285fd32 100644 --- a/ngraph/core/include/ngraph/slice_plan.hpp +++ b/ngraph/core/include/ngraph/slice_plan.hpp @@ -55,4 +55,4 @@ namespace ngraph const AxisSet& new_axis_mask, const AxisSet& shrink_axis_mask, const AxisSet& ellipsis_mask); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/specialize_function.hpp b/ngraph/core/include/ngraph/specialize_function.hpp index 3ca64de4202..e4c480048ff 100644 --- a/ngraph/core/include/ngraph/specialize_function.hpp +++ b/ngraph/core/include/ngraph/specialize_function.hpp @@ -97,4 +97,4 @@ namespace ngraph const std::vector& parameter_element_types, const std::vector& parameter_shapes, const std::vector& parameter_values); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/strides.hpp b/ngraph/core/include/ngraph/strides.hpp index 35ecc8301f8..46dafdd7e81 100644 --- a/ngraph/core/include/ngraph/strides.hpp +++ b/ngraph/core/include/ngraph/strides.hpp @@ -54,4 +54,4 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& s, const Strides& strides); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/type.hpp b/ngraph/core/include/ngraph/type.hpp index ade5c82f19b..f9998116789 100644 --- a/ngraph/core/include/ngraph/type.hpp +++ b/ngraph/core/include/ngraph/type.hpp @@ -109,7 +109,7 @@ namespace ngraph return is_type(value) ? std::static_pointer_cast(value) : std::shared_ptr(); } -} +} // namespace ngraph namespace std { @@ -118,4 +118,4 @@ namespace std { size_t operator()(const ngraph::DiscreteTypeInfo& k) const; }; -} +} // namespace std diff --git a/ngraph/core/include/ngraph/type/bfloat16.hpp b/ngraph/core/include/ngraph/type/bfloat16.hpp index 251f2368798..e91207ecc26 100644 --- a/ngraph/core/include/ngraph/type/bfloat16.hpp +++ b/ngraph/core/include/ngraph/type/bfloat16.hpp @@ -211,7 +211,7 @@ namespace ngraph { return *this = *this / other; } -} +} // namespace ngraph namespace std { @@ -278,4 +278,4 @@ namespace std static constexpr bool tinyness_before = false; static constexpr float_round_style round_style = round_to_nearest; }; -} +} // namespace std diff --git a/ngraph/core/include/ngraph/type/element_type.hpp b/ngraph/core/include/ngraph/type/element_type.hpp index 155df054583..3059f9545e8 100644 --- a/ngraph/core/include/ngraph/type/element_type.hpp +++ b/ngraph/core/include/ngraph/type/element_type.hpp @@ -172,7 +172,7 @@ namespace ngraph NGRAPH_API std::ostream& operator<<(std::ostream& out, const ngraph::element::Type& obj); - } + } // namespace element template <> class NGRAPH_API AttributeAdapter @@ -210,4 +210,4 @@ namespace ngraph /// \brief Return the number of bytes in the compile-time representation of the element type. size_t compiler_byte_size(element::Type_t et); -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/element_type_traits.hpp b/ngraph/core/include/ngraph/type/element_type_traits.hpp index d24b3c7df41..d11de025342 100644 --- a/ngraph/core/include/ngraph/type/element_type_traits.hpp +++ b/ngraph/core/include/ngraph/type/element_type_traits.hpp @@ -111,4 +111,4 @@ namespace ngraph { using value_type = uint64_t; }; -} +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/float16.hpp b/ngraph/core/include/ngraph/type/float16.hpp index 3549305e01b..c76451c366b 100644 --- a/ngraph/core/include/ngraph/type/float16.hpp +++ b/ngraph/core/include/ngraph/type/float16.hpp @@ -190,7 +190,7 @@ namespace ngraph { return *this = *this / other; } -} +} // namespace ngraph namespace std { @@ -259,4 +259,4 @@ namespace std static constexpr bool tinyness_before = false; static constexpr float_round_style round_style = round_to_nearest; }; -} +} // namespace std diff --git a/ngraph/core/include/ngraph/variant.hpp b/ngraph/core/include/ngraph/variant.hpp index 81ac7818c2a..90b87cb5b37 100644 --- a/ngraph/core/include/ngraph/variant.hpp +++ b/ngraph/core/include/ngraph/variant.hpp @@ -74,4 +74,4 @@ namespace ngraph { } }; -} +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp b/ngraph/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp index cbaa33b27dd..30ba487ecc6 100644 --- a/ngraph/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp @@ -21,5 +21,5 @@ namespace ngraph const Shape& out_shape, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/abs.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/abs.hpp index 91a52d793e0..7aa0b4cf4ca 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/abs.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/abs.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = (arg[i] < T(0) ? T(-arg[i]) : arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/acos.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/acos.hpp index 828de4b8035..567cb5f8ada 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/acos.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/acos.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::acos(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/acosh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/acosh.hpp index ca9860557db..7c01940cb80 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/acosh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/acosh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::acosh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/add.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/add.hpp index bd5dcf2c19a..0605a135cc8 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/add.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/add.hpp @@ -37,6 +37,6 @@ namespace ngraph return x + y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/and.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/and.hpp index 72be8817bcd..53686fbbeb0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/and.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/and.hpp @@ -38,6 +38,6 @@ namespace ngraph return static_cast(x && y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/asin.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/asin.hpp index 38d86711964..2b1cb4af0ca 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/asin.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/asin.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::asin(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/asinh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/asinh.hpp index 96d5dd4addb..02db44c13b4 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/asinh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/asinh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::asinh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/atan.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/atan.hpp index 84229bbf232..03dcdf525f2 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/atan.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/atan.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::atan(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/atan2.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/atan2.hpp index 3cac9a743a6..b2c279eb35a 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/atan2.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/atan2.hpp @@ -21,6 +21,6 @@ namespace ngraph *pout++ = static_cast(std::atan2(*py++, *px++)); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/atanh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/atanh.hpp index d8df90c9194..7e2cb95df0e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/atanh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/atanh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::atanh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/autobroadcast_binop.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/autobroadcast_binop.hpp index f87adcb9852..33ff0672b25 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/autobroadcast_binop.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/autobroadcast_binop.hpp @@ -83,7 +83,7 @@ namespace ngraph --axis; return axis; } - } + } // namespace internal /// \brief Helper function to implement autobroadcasting elementwise binop references. /// @@ -538,6 +538,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/avg_pool.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/avg_pool.hpp index 7d25f712bd1..49a008476f8 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/avg_pool.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/avg_pool.hpp @@ -235,6 +235,6 @@ namespace ngraph std::fesetround(old_mode); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/batch_norm.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/batch_norm.hpp index 5165b41dc8f..e2eeb1ba1cc 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/batch_norm.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/batch_norm.hpp @@ -196,6 +196,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/binary_convolution.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/binary_convolution.hpp index daf17805194..2c6bbfd9a7c 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/binary_convolution.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/binary_convolution.hpp @@ -125,7 +125,7 @@ namespace ngraph } } } - } + } // namespace details template void binary_convolution(const T_IN* in, diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/broadcast.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/broadcast.hpp index a7d1203fd1e..7c93d3d434c 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/broadcast.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/broadcast.hpp @@ -20,5 +20,5 @@ namespace ngraph const AxisSet& broadcast_axes, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/ceiling.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/ceiling.hpp index b5dfe161ef0..18220056ca6 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/ceiling.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/ceiling.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::ceil(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/clamp.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/clamp.hpp index 43ebc3812d0..4d213731c65 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/clamp.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/clamp.hpp @@ -32,6 +32,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/concat.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/concat.hpp index 3ef3e2047fe..5dbde485e76 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/concat.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/concat.hpp @@ -21,5 +21,5 @@ namespace ngraph int64_t concatenation_axis, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/constant.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/constant.hpp index aafae16a451..4a54c5e6f80 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/constant.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/constant.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = arg0[i]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/convolution.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/convolution.hpp index 2e52d88753b..e5e12bac9ac 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/convolution.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/convolution.hpp @@ -234,7 +234,7 @@ namespace ngraph NGRAPH_CHECK(out_spatial_shape == infered_out_spatial_shape, "Incorrect output shape provided"); } - } + } // namespace template void convolution(const T* in, diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/copy.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/copy.hpp index 4cea1688d94..e13b616e0dc 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/copy.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/copy.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = arg[i]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/cos.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/cos.hpp index bea6d6e5182..b28947246a4 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/cos.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/cos.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::cos(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/cosh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/cosh.hpp index 1f4a9e0ae6b..2529f9a8893 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/cosh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/cosh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::cosh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/ctc_loss.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/ctc_loss.hpp index 603643b2bef..52535f8c669 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/ctc_loss.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/ctc_loss.hpp @@ -208,6 +208,6 @@ namespace ngraph } // for (size_t b = 0; b < batchNum; b++) } // CTCLoss - } // reference - } // runtime -} // ngraph + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp index 039cc64c011..bc1f490e3bd 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/cum_sum.hpp @@ -127,6 +127,6 @@ namespace ngraph cum_sum(it.second); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/divide.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/divide.hpp index a55515a318e..a1cc6d5a61b 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/divide.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/divide.hpp @@ -137,6 +137,6 @@ namespace ngraph return x / y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/elu.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/elu.hpp index 1ea8a70ee75..793ff9098b3 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/elu.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/elu.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp index 83e77d3d5ce..9be031a2a12 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_offsets_sum.hpp @@ -116,6 +116,6 @@ namespace ngraph } // embeddingBagOffsetsSum - } // reference - } // runtime -} // ngraph + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp index 0f67df7f9e1..26f5566a403 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_bag_packed_sum.hpp @@ -58,6 +58,6 @@ namespace ngraph } // embeddingBagPackedSum - } // reference - } // runtime -} // ngraph + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp index 817981e17c8..59684616727 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/embedding_segments_sum.hpp @@ -88,6 +88,6 @@ namespace ngraph } } // embeddingSegmentsSum - } // reference - } // runtime -} // ngraph + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/equal.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/equal.hpp index a63522ef5d1..de81da857fb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/equal.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/equal.hpp @@ -46,9 +46,9 @@ namespace ngraph return x == y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph #if defined(__GNUC__) #pragma GCC diagnostic pop diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/erf.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/erf.hpp index 439649e71f7..f7524dc56fe 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/erf.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/erf.hpp @@ -36,6 +36,6 @@ namespace ngraph out[i] = std::round(std::erf(arg[i])); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/eval_helpers.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/eval_helpers.hpp index 40b8c6f74ee..935237778d1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/eval_helpers.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/eval_helpers.hpp @@ -12,4 +12,4 @@ namespace ngraph { AxisSet extract_reduction_axes(const HostTensorPtr& axes, const char* op_name); } -} +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/exp.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/exp.hpp index f0cf2efda5e..58165e47977 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/exp.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/exp.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::exp(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/extract_image_patches.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/extract_image_patches.hpp index 686ae9cc5dd..f967e08d8ed 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/extract_image_patches.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/extract_image_patches.hpp @@ -143,6 +143,6 @@ namespace ngraph } } // extractImagePatches - } // reference - } // runtime -} // ngraph + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/fake_quantize.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/fake_quantize.hpp index 911a5f12bdf..d3a30caa9cf 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/fake_quantize.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/fake_quantize.hpp @@ -87,7 +87,7 @@ namespace ngraph increment_current_dim(current_dims, shape, incremented_dim_number - 1); } } - } + } // namespace template void fake_quantize(const T* arg, @@ -230,6 +230,6 @@ namespace ngraph } std::fesetround(initial_round_mode); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/fft.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/fft.hpp index 8429058ca08..106bf72537d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/fft.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/fft.hpp @@ -57,6 +57,6 @@ namespace ngraph std::vector canonicalize_axes(const int64_t* axes_data, const Shape& axes_data_shape, int64_t complex_data_rank); - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/floor.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/floor.hpp index 04619d47ee4..edbf1f7ffe1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/floor.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/floor.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::floor(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/floor_mod.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/floor_mod.hpp index 3ae7bbebeac..ace226354ff 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/floor_mod.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/floor_mod.hpp @@ -32,6 +32,6 @@ namespace ngraph return x - y * std::floor(x / divisor); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/function.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/function.hpp index 7733f373dad..89d799494c3 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/function.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/function.hpp @@ -19,5 +19,5 @@ namespace ngraph const HostTensorVector& inputs, HostTensorVector& outputs); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/gather_tree.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/gather_tree.hpp index 5e53a64ab22..5d8a9347c31 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/gather_tree.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/gather_tree.hpp @@ -23,5 +23,5 @@ namespace ngraph const Shape& end_token_shape, const element::Type& type); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/gelu.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/gelu.hpp index 8859e36bf30..b7615056745 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/gelu.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/gelu.hpp @@ -36,6 +36,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/greater.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/greater.hpp index 232b4ac9a9a..c8090a576f6 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/greater.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/greater.hpp @@ -41,6 +41,6 @@ namespace ngraph return x > y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/greater_eq.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/greater_eq.hpp index e9017f5218d..d11c3ca275b 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/greater_eq.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/greater_eq.hpp @@ -41,6 +41,6 @@ namespace ngraph return x >= y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/group_convolution.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/group_convolution.hpp index ff56719cd63..9285f4a7320 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/group_convolution.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/group_convolution.hpp @@ -15,7 +15,7 @@ namespace constexpr size_t in_channel_axis = 1; constexpr size_t out_batch_axis = 0; constexpr size_t out_channel_axis = 1; -} +} // namespace namespace ngraph { diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/gru_cell.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/gru_cell.hpp index 7fc91cdfc84..4cb10025c1e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/gru_cell.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/gru_cell.hpp @@ -299,6 +299,6 @@ namespace ngraph gate_shape, op::AutoBroadcastSpec::NUMPY); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/hard_sigmoid.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/hard_sigmoid.hpp index 874a251a62b..e8ed04cec2f 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/hard_sigmoid.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/hard_sigmoid.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::max(0.0f, std::min(1.0f, alpha * arg[i] + beta)); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/helpers.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/helpers.hpp index 30ea19afc9b..8aebd679b03 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/helpers.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/helpers.hpp @@ -27,6 +27,6 @@ namespace ngraph { using type = long double; }; - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/hsigmoid.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/hsigmoid.hpp index 3c23bda26ee..f64de03eb9f 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/hsigmoid.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/hsigmoid.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::min(std::max(arg[i] + 3.0f, 0.0f), 6.0f) / 6.0f; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/hswish.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/hswish.hpp index 7ed485d7f70..281b22ebf2e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/hswish.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/hswish.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = arg[i] * std::min(std::max(arg[i] + 3.0f, 0.0f), 6.0f) / 6.0f; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp index 5575201e3cf..d023aebf53e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp @@ -659,6 +659,6 @@ namespace ngraph InterpolateEval evaluator{attrs}; evaluator(input_data, input_data_shape, scales, axes, out, out_shape); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/less.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/less.hpp index 261e76c8d66..525f42e9806 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/less.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/less.hpp @@ -41,6 +41,6 @@ namespace ngraph return x < y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/less_eq.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/less_eq.hpp index eeace6f521e..7c59010f536 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/less_eq.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/less_eq.hpp @@ -41,6 +41,6 @@ namespace ngraph return x <= y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/log.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/log.hpp index a5019719322..1d21539854d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/log.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/log.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::log(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/logical_reduction.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/logical_reduction.hpp index fe6810fa294..f9e24d89292 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/logical_reduction.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/logical_reduction.hpp @@ -64,6 +64,6 @@ namespace ngraph arg[input_transform.index(input_coord)]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/loop.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/loop.hpp index 01521cf7870..7042e87d6d8 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/loop.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/loop.hpp @@ -20,5 +20,5 @@ namespace ngraph const HostTensorVector& out, const HostTensorVector& args); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/lstm_cell.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/lstm_cell.hpp index fef490f6c52..53a681cf1dd 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/lstm_cell.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/lstm_cell.hpp @@ -201,6 +201,6 @@ namespace ngraph gate_shape, op::AutoBroadcastSpec::NUMPY); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp index 86ebcc62c83..3405245f986 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp @@ -65,7 +65,7 @@ namespace ngraph std::swap(axes_order[rank - 1], axes_order[rank - 2]); return axes_order; } - } + } // namespace details /// \brief Reference kernel for matmul computation. /// /// \tparam T Type of input and output tensors. @@ -253,6 +253,6 @@ namespace ngraph dot_output_shape); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/max.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/max.hpp index bbcd2ad2a4f..d8e39fefd65 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/max.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/max.hpp @@ -49,6 +49,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/max_pool.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/max_pool.hpp index d1df1fd2b90..f6c21b15966 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/max_pool.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/max_pool.hpp @@ -114,6 +114,6 @@ namespace ngraph out[output_transform.index(out_coord)] = result; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/maximum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/maximum.hpp index aa3b2a8b768..0f9a4c435cb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/maximum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/maximum.hpp @@ -38,6 +38,6 @@ namespace ngraph return x > y ? x : y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/mean.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/mean.hpp index 0c8acd8188d..16cae63afb8 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/mean.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/mean.hpp @@ -76,6 +76,6 @@ namespace ngraph out[output_transform.index(output_coord)] / count; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/minimum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/minimum.hpp index 4d4dfc72af0..68e7bd4db4e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/minimum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/minimum.hpp @@ -38,6 +38,6 @@ namespace ngraph return x < y ? x : y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/mish.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/mish.hpp index 9a1b9f7efd2..90e22247a63 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/mish.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/mish.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = arg[i] * std::tanh(std::log((std::exp(arg[i]) + 1.0))); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/mod.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/mod.hpp index b657cd54887..e255a11ac2e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/mod.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/mod.hpp @@ -28,6 +28,6 @@ namespace ngraph return T(x - std::truncf(x / y) * y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/multiply.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/multiply.hpp index 3dfd61bd2af..65b26b5e950 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/multiply.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/multiply.hpp @@ -38,6 +38,6 @@ namespace ngraph return x * y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/negate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/negate.hpp index c75ffc93929..2e409481df7 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/negate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/negate.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = -arg[i]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/non_max_suppression.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/non_max_suppression.hpp index b3db42148c7..fa6475ec854 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/non_max_suppression.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/non_max_suppression.hpp @@ -45,6 +45,6 @@ namespace ngraph const std::vector& selected_scores, int64_t valid_outputs, const ngraph::element::Type selected_scores_type); - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/non_zero.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/non_zero.hpp index 70742d98cac..2cd841d24ae 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/non_zero.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/non_zero.hpp @@ -129,6 +129,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/not.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/not.hpp index 6e447292f01..9e3b77e34ee 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/not.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/not.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = static_cast(!(arg[i])); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/not_equal.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/not_equal.hpp index 22a272792a4..95f2d10d437 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/not_equal.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/not_equal.hpp @@ -46,9 +46,9 @@ namespace ngraph return x != y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph #if defined(__GNUC__) #pragma GCC diagnostic pop diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/one_hot.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/one_hot.hpp index d6e138bdf93..3caffafec75 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/one_hot.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/one_hot.hpp @@ -50,6 +50,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/or.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/or.hpp index b9311da1765..b734f047f80 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/or.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/or.hpp @@ -39,6 +39,6 @@ namespace ngraph return static_cast(x || y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/power.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/power.hpp index c28f735a23b..45574e72885 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/power.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/power.hpp @@ -39,6 +39,6 @@ namespace ngraph return std::pow(x, y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/prelu.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/prelu.hpp index 06d1fe91239..34a420399ac 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/prelu.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/prelu.hpp @@ -31,6 +31,6 @@ namespace ngraph arg[i] < T(0) ? T(arg[i] * slope[cnt++ % shape_size(slope_shape)]) : arg[i]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/prior_box.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/prior_box.hpp index a10ac1aacb1..f85fe0ad391 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/prior_box.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/prior_box.hpp @@ -282,6 +282,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/prior_box_clustered.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/prior_box_clustered.hpp index 16d30aff3e7..b597788fcf7 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/prior_box_clustered.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/prior_box_clustered.hpp @@ -99,6 +99,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/product.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/product.hpp index 8466717a4b6..14615dc8b7c 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/product.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/product.hpp @@ -41,6 +41,6 @@ namespace ngraph out[output_index] = out[output_index] * arg[input_transform.index(input_coord)]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/psroi_pooling.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/psroi_pooling.hpp index d018c3c59ea..1ccdfb74103 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/psroi_pooling.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/psroi_pooling.hpp @@ -195,6 +195,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/quantize.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/quantize.hpp index 662e3bb2227..606a6226b07 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/quantize.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/quantize.hpp @@ -103,6 +103,6 @@ namespace ngraph output[input_transform.index(input_coord)] = static_cast(qvalue); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/range.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/range.hpp index 056deb6c6ee..6e5051a197a 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/range.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/range.hpp @@ -46,6 +46,6 @@ namespace ngraph val += *step; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l1.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l1.hpp index ea8be17ebd8..86eac8ceb26 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l1.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l1.hpp @@ -42,6 +42,6 @@ namespace ngraph out[output_index] + std::abs(arg[input_transform.index(input_coord)]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l2.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l2.hpp index a1472db855f..b7ae96586b2 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l2.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reduce_l2.hpp @@ -48,6 +48,6 @@ namespace ngraph sqrt(out[output_transform.index(output_coord)]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/relu.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/relu.hpp index 99b022b9775..9a20bfe97d0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/relu.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/relu.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = arg[i] > zero ? arg[i] : zero; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reorg_yolo.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reorg_yolo.hpp index 77e5a717c06..6a3ebad98ca 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reorg_yolo.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reorg_yolo.hpp @@ -21,5 +21,5 @@ namespace ngraph int64_t stride, const size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reshape.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reshape.hpp index f620379f814..d6696b8feeb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reshape.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reshape.hpp @@ -24,5 +24,5 @@ namespace ngraph const Shape& out_shape, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/result.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/result.hpp index b5e31a11b1a..ce5384fa967 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/result.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/result.hpp @@ -21,6 +21,6 @@ namespace ngraph { memcpy(out, arg, sizeof(T) * count); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reverse.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reverse.hpp index 3d5f0d79f7b..bc61fc7c597 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reverse.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reverse.hpp @@ -21,5 +21,5 @@ namespace ngraph const AxisSet& reversed_axes, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp index e8897b41d83..865e1dbbbd1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/reverse_sequence.hpp @@ -52,6 +52,6 @@ namespace ngraph out[input_transform.index(out_coord)] = arg[input_transform.index(in_coord)]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/rnn_cell.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/rnn_cell.hpp index 82a2cee2eec..16b115d32d0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/rnn_cell.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/rnn_cell.hpp @@ -115,6 +115,6 @@ namespace ngraph " is not supported."); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/roll.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/roll.hpp index 0c479222cb5..df835ea3cc0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/roll.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/roll.hpp @@ -89,6 +89,6 @@ namespace ngraph start += last_dim; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/round.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/round.hpp index caf4e5cd077..eeac6f95cf0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/round.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/round.hpp @@ -42,6 +42,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_elements_update.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_elements_update.hpp index 9cf7777b0d6..1d398db722d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_elements_update.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_elements_update.hpp @@ -48,6 +48,6 @@ namespace ngraph out_buf[data_transform.index(out_cord)] = updates[indices_idx]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp index a6978ff6263..3805e07773b 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp @@ -107,6 +107,6 @@ namespace ngraph updates_indices_coord_iter++; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/select.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/select.hpp index 06a91a307bf..88c90c34c13 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/select.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/select.hpp @@ -52,6 +52,6 @@ namespace ngraph broadcast_spec, [](char s, T x, T y) -> T { return static_cast(s ? x : y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/selu.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/selu.hpp index fe1d699284a..9adc1c49e95 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/selu.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/selu.hpp @@ -29,6 +29,6 @@ namespace ngraph (std::exp(arg[i]) - 1)); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp index a3a75398011..617b44b50c3 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp @@ -667,6 +667,6 @@ namespace ngraph sizeof(T)); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/shape_of.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/shape_of.hpp index 742c0765777..c35fdc3ba09 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/shape_of.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/shape_of.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = static_cast(arg_shape[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sigmoid.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sigmoid.hpp index 8f61d7ce970..7367314dd4d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sigmoid.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sigmoid.hpp @@ -23,6 +23,6 @@ namespace ngraph out[i] = 1 / (1 + exp_value); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sign.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sign.hpp index 2eb790c08ea..12ef5a89e86 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sign.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sign.hpp @@ -20,6 +20,6 @@ namespace ngraph out[i] = (arg[i] < T(0) ? T(-1) : (arg[i] > T(0) ? T(1) : T(0))); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sin.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sin.hpp index a303d57360c..e5a66df401d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sin.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sin.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::sin(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sinh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sinh.hpp index fe8bb812f06..3712bcd36aa 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sinh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sinh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::sinh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/slice.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/slice.hpp index 581eaf8e53f..61273f0cc73 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/slice.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/slice.hpp @@ -22,5 +22,5 @@ namespace ngraph const Shape& out_shape, size_t elem_size); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/softmax.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/softmax.hpp index 78851db9e7e..c31c901012c 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/softmax.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/softmax.hpp @@ -44,6 +44,6 @@ namespace ngraph delete[] temp_ptr; } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/softplus.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/softplus.hpp index 2ff071febf4..d68ecb31c0d 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/softplus.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/softplus.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::log(std::exp(arg[i]) + 1.0); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/split.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/split.hpp index a5af5ce8478..f2a809db109 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/split.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/split.hpp @@ -21,5 +21,5 @@ namespace ngraph size_t num_splits, char** out_data); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sqrt.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sqrt.hpp index a5fa4f348af..bcafec998d3 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sqrt.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sqrt.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::sqrt(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/squared_difference.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/squared_difference.hpp index 564b48579bc..d4ddd82ef20 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/squared_difference.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/squared_difference.hpp @@ -29,6 +29,6 @@ namespace ngraph return (x - y) * (x - y); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/strided_slice.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/strided_slice.hpp index 1a49342b8c9..f44f6049ccb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/strided_slice.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/strided_slice.hpp @@ -26,5 +26,5 @@ namespace ngraph const SlicePlan& sp, size_t elem_type); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/subtract.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/subtract.hpp index 1e8c6aca5d7..890607d0522 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/subtract.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/subtract.hpp @@ -38,6 +38,6 @@ namespace ngraph return x - y; }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sum.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sum.hpp index 33e8134780d..0c20eaf431a 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sum.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sum.hpp @@ -79,6 +79,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/swish.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/swish.hpp index 018eeb7807a..1d69d9282a7 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/swish.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/swish.hpp @@ -26,6 +26,6 @@ namespace ngraph out[i] = arg[i] / (1.0 + std::exp(-arg[i] * beta_value)); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/tan.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/tan.hpp index 36aba53c276..33dc63e6804 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/tan.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/tan.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::tan(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/tanh.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/tanh.hpp index f4df2997f00..f78435352cb 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/tanh.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/tanh.hpp @@ -21,6 +21,6 @@ namespace ngraph out[i] = std::tanh(arg[i]); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/tensor_iterator.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/tensor_iterator.hpp index de5305bfd61..6b34197fdc1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/tensor_iterator.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/tensor_iterator.hpp @@ -24,6 +24,6 @@ namespace ngraph const HostTensorVector& out, const HostTensorVector& args, const custom_evaluate_function& evaluate = nullptr); - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/tile.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/tile.hpp index ce9d5361ace..3205bf325f1 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/tile.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/tile.hpp @@ -22,5 +22,5 @@ namespace ngraph const size_t elem_size, const std::vector& repeats); } - } -} + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp index 58b2732b025..99ad194c28a 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp @@ -134,6 +134,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/transpose.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/transpose.hpp index f87690bc989..fe9a6b8a772 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/transpose.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/transpose.hpp @@ -56,6 +56,6 @@ namespace ngraph out[i] = arg[in_position]; } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/xor.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/xor.hpp index 9f841e568ca..59a6facc5e4 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/xor.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/xor.hpp @@ -38,6 +38,6 @@ namespace ngraph return static_cast((x || y) && !(x && y)); }); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/opt_kernel/reshape.cpp b/ngraph/core/reference/src/runtime/opt_kernel/reshape.cpp index 564591b5584..f0d559f1847 100644 --- a/ngraph/core/reference/src/runtime/opt_kernel/reshape.cpp +++ b/ngraph/core/reference/src/runtime/opt_kernel/reshape.cpp @@ -233,7 +233,7 @@ namespace } } } -} +} // namespace void runtime::opt_kernel::reshape(const char* in, char* out, const Shape& in_shape, diff --git a/ngraph/core/reference/src/runtime/reference/broadcast.cpp b/ngraph/core/reference/src/runtime/reference/broadcast.cpp index 43a169440c4..d86aee745a7 100644 --- a/ngraph/core/reference/src/runtime/reference/broadcast.cpp +++ b/ngraph/core/reference/src/runtime/reference/broadcast.cpp @@ -38,6 +38,6 @@ namespace ngraph return tile(arg, out, adjusted_in_shape, adjusted_out_shape, elem_size, repeats); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/convert.cpp b/ngraph/core/reference/src/runtime/reference/convert.cpp index 9810cac9a6a..d87567b9b43 100644 --- a/ngraph/core/reference/src/runtime/reference/convert.cpp +++ b/ngraph/core/reference/src/runtime/reference/convert.cpp @@ -184,6 +184,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/fft.cpp b/ngraph/core/reference/src/runtime/reference/fft.cpp index 01ce6b49a45..dcea34084fc 100644 --- a/ngraph/core/reference/src/runtime/reference/fft.cpp +++ b/ngraph/core/reference/src/runtime/reference/fft.cpp @@ -482,7 +482,7 @@ namespace ngraph return result; } - } + } // namespace // Calculation of FFT void fft(const float* input_data, @@ -630,6 +630,6 @@ namespace ngraph default:; } } - } - } -} \ No newline at end of file + } // namespace reference + } // namespace runtime +} // namespace ngraph \ No newline at end of file diff --git a/ngraph/core/reference/src/runtime/reference/function.cpp b/ngraph/core/reference/src/runtime/reference/function.cpp index 7cb36b760b1..58256806d64 100644 --- a/ngraph/core/reference/src/runtime/reference/function.cpp +++ b/ngraph/core/reference/src/runtime/reference/function.cpp @@ -130,6 +130,6 @@ namespace ngraph } call(outputs, inputs, function); } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/jit_generator.cpp b/ngraph/core/reference/src/runtime/reference/jit_generator.cpp index adb8c7c3c7f..783fa6a715d 100644 --- a/ngraph/core/reference/src/runtime/reference/jit_generator.cpp +++ b/ngraph/core/reference/src/runtime/reference/jit_generator.cpp @@ -213,6 +213,6 @@ namespace ngraph { copy(dst, src, size); } - } - } -} + } // namespace jit + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/loop.cpp b/ngraph/core/reference/src/runtime/reference/loop.cpp index 3dc9bb06711..79991b45700 100644 --- a/ngraph/core/reference/src/runtime/reference/loop.cpp +++ b/ngraph/core/reference/src/runtime/reference/loop.cpp @@ -264,6 +264,6 @@ namespace ngraph "ExecutionCondition is false. Zero count of iteration not supported."); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/non_max_suppression.cpp b/ngraph/core/reference/src/runtime/reference/non_max_suppression.cpp index 8319eb8cc10..3a1ce762e4a 100644 --- a/ngraph/core/reference/src/runtime/reference/non_max_suppression.cpp +++ b/ngraph/core/reference/src/runtime/reference/non_max_suppression.cpp @@ -124,7 +124,7 @@ namespace ngraph int64_t class_index = 0; float score = 0.0f; }; - } + } // namespace void non_max_suppression(const float* boxes_data, const Shape& boxes_data_shape, const float* scores_data, @@ -381,6 +381,6 @@ namespace ngraph *valid_outputs_ptr = static_cast(valid_outputs); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/pad.cpp b/ngraph/core/reference/src/runtime/reference/pad.cpp index 64a8c6ff194..b10eebab800 100644 --- a/ngraph/core/reference/src/runtime/reference/pad.cpp +++ b/ngraph/core/reference/src/runtime/reference/pad.cpp @@ -207,7 +207,7 @@ namespace ngraph int axis_correction{}; }; - } + } // namespace void pad(const char* data, const char* pad_value, diff --git a/ngraph/core/reference/src/runtime/reference/reorg_yolo.cpp b/ngraph/core/reference/src/runtime/reference/reorg_yolo.cpp index 065d6eca1b7..1fbf441268b 100644 --- a/ngraph/core/reference/src/runtime/reference/reorg_yolo.cpp +++ b/ngraph/core/reference/src/runtime/reference/reorg_yolo.cpp @@ -72,6 +72,6 @@ namespace ngraph } } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/tensor_iterator.cpp b/ngraph/core/reference/src/runtime/reference/tensor_iterator.cpp index 34b5af69b8b..4c390040f5b 100644 --- a/ngraph/core/reference/src/runtime/reference/tensor_iterator.cpp +++ b/ngraph/core/reference/src/runtime/reference/tensor_iterator.cpp @@ -174,6 +174,6 @@ namespace ngraph out[concat_desc->m_output_index]->get_element_type().size()); } } - } - } -} + } // namespace reference + } // namespace runtime +} // namespace ngraph diff --git a/ngraph/core/reference/src/runtime/reference/tile.cpp b/ngraph/core/reference/src/runtime/reference/tile.cpp index 45c7657a847..35873b4ae1b 100644 --- a/ngraph/core/reference/src/runtime/reference/tile.cpp +++ b/ngraph/core/reference/src/runtime/reference/tile.cpp @@ -31,7 +31,7 @@ namespace pitch.push_back(1); return pitch; } -} +} // namespace void runtime::reference::tile(const char* arg, char* out, diff --git a/ngraph/core/src/attribute_adapter.cpp b/ngraph/core/src/attribute_adapter.cpp index 36ce2864d72..3e063834129 100644 --- a/ngraph/core/src/attribute_adapter.cpp +++ b/ngraph/core/src/attribute_adapter.cpp @@ -47,4 +47,4 @@ namespace ngraph constexpr DiscreteTypeInfo AttributeAdapter>::type_info; constexpr DiscreteTypeInfo AttributeAdapter>::type_info; constexpr DiscreteTypeInfo AttributeAdapter>::type_info; -} +} // namespace ngraph diff --git a/ngraph/core/src/dimension.cpp b/ngraph/core/src/dimension.cpp index db8428bf5bd..2941d1ff083 100644 --- a/ngraph/core/src/dimension.cpp +++ b/ngraph/core/src/dimension.cpp @@ -127,7 +127,7 @@ namespace { return vt == Interval::s_max ? -1 : vt; } -} +} // namespace Dimension::value_type Dimension::get_max_length() const { diff --git a/ngraph/core/src/distributed.cpp b/ngraph/core/src/distributed.cpp index 1050d5c05ff..8b38bc7a509 100644 --- a/ngraph/core/src/distributed.cpp +++ b/ngraph/core/src/distributed.cpp @@ -22,7 +22,7 @@ namespace ngraph } constexpr DiscreteTypeInfo AttributeAdapter::type_info; -} +} // namespace ngraph std::ostream& reduction::operator<<(std::ostream& out, const reduction::Type& obj) { diff --git a/ngraph/core/src/factory.cpp b/ngraph/core/src/factory.cpp index c5b1c2e4a7b..c6c25f18eee 100644 --- a/ngraph/core/src/factory.cpp +++ b/ngraph/core/src/factory.cpp @@ -17,4 +17,4 @@ namespace ngraph static mutex registry_mutex; return registry_mutex; } -} +} // namespace ngraph diff --git a/ngraph/core/src/interval.cpp b/ngraph/core/src/interval.cpp index 640b7343fee..f02ad332885 100644 --- a/ngraph/core/src/interval.cpp +++ b/ngraph/core/src/interval.cpp @@ -183,4 +183,4 @@ namespace ngraph } return str << ")"; } -} +} // namespace ngraph diff --git a/ngraph/core/src/itt.hpp b/ngraph/core/src/itt.hpp index 2c20ae5ae2b..c3fd1274696 100644 --- a/ngraph/core/src/itt.hpp +++ b/ngraph/core/src/itt.hpp @@ -22,9 +22,9 @@ namespace ngraph OV_ITT_DOMAIN(nGraph); OV_ITT_DOMAIN(nGraphPass_LT); OV_ITT_DOMAIN(ngraph_op, "nGraph::Op"); - } - } -} + } // namespace domains + } // namespace itt +} // namespace ngraph OV_CC_DOMAINS(ngraph_op); OV_ITT_DOMAIN(SIMPLE_ngraph_pass); diff --git a/ngraph/core/src/ngraph.cpp b/ngraph/core/src/ngraph.cpp index ee28dad7211..4b64caa9aa7 100644 --- a/ngraph/core/src/ngraph.cpp +++ b/ngraph/core/src/ngraph.cpp @@ -21,4 +21,4 @@ namespace ngraph string version = NGRAPH_VERSION_NUMBER; ngraph::parse_version_string(version, major, minor, patch, extra); } -} +} // namespace ngraph diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index 3bfcd476551..3743e221f1a 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -552,7 +552,7 @@ namespace ngraph { ostream& operator<<(ostream& out, const Node& node) { return node.write_description(out, 1); } ostream& operator<<(ostream& out, const Node* node) { return node->write_description(out, 1); } -} +} // namespace ngraph std::ostream& Node::write_description(std::ostream& out, uint32_t depth) const { diff --git a/ngraph/core/src/node_input.cpp b/ngraph/core/src/node_input.cpp index 8ab99370c11..f7f70b2ebd7 100644 --- a/ngraph/core/src/node_input.cpp +++ b/ngraph/core/src/node_input.cpp @@ -151,4 +151,4 @@ namespace ngraph << ".input(" << input.get_index() << "):" << input.get_element_type() << input.get_partial_shape(); } -} +} // namespace ngraph diff --git a/ngraph/core/src/node_output.cpp b/ngraph/core/src/node_output.cpp index 695e41b2d50..9799c49b8fa 100644 --- a/ngraph/core/src/node_output.cpp +++ b/ngraph/core/src/node_output.cpp @@ -191,4 +191,4 @@ namespace ngraph << "[" << output.get_index() << "]:" << output.get_element_type() << output.get_partial_shape(); } -} +} // namespace ngraph diff --git a/ngraph/core/src/op/abs.cpp b/ngraph/core/src/op/abs.cpp index 3c0119db69e..1608f92b26c 100644 --- a/ngraph/core/src/op/abs.cpp +++ b/ngraph/core/src/op/abs.cpp @@ -58,7 +58,7 @@ namespace absop } return rc; } -} +} // namespace absop bool op::Abs::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/acos.cpp b/ngraph/core/src/op/acos.cpp index 85cc887b14f..e5643137828 100644 --- a/ngraph/core/src/op/acos.cpp +++ b/ngraph/core/src/op/acos.cpp @@ -66,7 +66,7 @@ namespace acosop } return rc; } -} +} // namespace acosop bool op::Acos::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/acosh.cpp b/ngraph/core/src/op/acosh.cpp index ce8fb0e94a5..851925eec31 100644 --- a/ngraph/core/src/op/acosh.cpp +++ b/ngraph/core/src/op/acosh.cpp @@ -55,7 +55,7 @@ namespace acoshop } return rc; } -} +} // namespace acoshop bool op::v3::Acosh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/add.cpp b/ngraph/core/src/op/add.cpp index 17c8f356074..974cbe47685 100644 --- a/ngraph/core/src/op/add.cpp +++ b/ngraph/core/src/op/add.cpp @@ -51,7 +51,7 @@ namespace add } return rc; } -} +} // namespace add // ------------------------------- v1 ------------------------------------------ diff --git a/ngraph/core/src/op/and.cpp b/ngraph/core/src/op/and.cpp index 4dc66f30441..5b3912fa6e0 100644 --- a/ngraph/core/src/op/and.cpp +++ b/ngraph/core/src/op/and.cpp @@ -71,7 +71,7 @@ namespace logand } return rc; } -} +} // namespace logand bool op::v1::LogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/asin.cpp b/ngraph/core/src/op/asin.cpp index f6c501fe05f..40640994433 100644 --- a/ngraph/core/src/op/asin.cpp +++ b/ngraph/core/src/op/asin.cpp @@ -67,7 +67,7 @@ namespace asinop } return rc; } -} +} // namespace asinop bool op::Asin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/asinh.cpp b/ngraph/core/src/op/asinh.cpp index d6da46d8a05..c8f12bbdf99 100644 --- a/ngraph/core/src/op/asinh.cpp +++ b/ngraph/core/src/op/asinh.cpp @@ -55,7 +55,7 @@ namespace asinhop } return rc; } -} +} // namespace asinhop bool op::v3::Asinh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/atan.cpp b/ngraph/core/src/op/atan.cpp index 02af809e18a..623e52a51f8 100644 --- a/ngraph/core/src/op/atan.cpp +++ b/ngraph/core/src/op/atan.cpp @@ -66,7 +66,7 @@ namespace atanop } return rc; } -} +} // namespace atanop bool op::Atan::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/atanh.cpp b/ngraph/core/src/op/atanh.cpp index 3d88be2a3c2..96a0dd3720d 100644 --- a/ngraph/core/src/op/atanh.cpp +++ b/ngraph/core/src/op/atanh.cpp @@ -55,7 +55,7 @@ namespace atanhop } return rc; } -} +} // namespace atanhop bool op::v3::Atanh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/batch_to_space.cpp b/ngraph/core/src/op/batch_to_space.cpp index 9cbcec70fea..25f8b0bf13c 100644 --- a/ngraph/core/src/op/batch_to_space.cpp +++ b/ngraph/core/src/op/batch_to_space.cpp @@ -244,7 +244,7 @@ namespace flat_data, outputs[0]->get_data_ptr(), data_shape, slice_plan, elem_size); return true; } -} +} // namespace bool ngraph::op::v1::BatchToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/binary_convolution.cpp b/ngraph/core/src/op/binary_convolution.cpp index 328097c66e0..fabe1d129a8 100644 --- a/ngraph/core/src/op/binary_convolution.cpp +++ b/ngraph/core/src/op/binary_convolution.cpp @@ -134,7 +134,7 @@ namespace ngraph { return s << as_string(type); } -} +} // namespace ngraph op::v1::BinaryConvolution::BinaryConvolutionMode op::v1::BinaryConvolution::mode_from_string(const std::string& mode) const diff --git a/ngraph/core/src/op/broadcast.cpp b/ngraph/core/src/op/broadcast.cpp index 0e21b9bac7a..33ff84fd6c4 100644 --- a/ngraph/core/src/op/broadcast.cpp +++ b/ngraph/core/src/op/broadcast.cpp @@ -55,7 +55,7 @@ namespace axes_known = true; return std::make_pair(axes_known, broadcast_axes); } -} +} // namespace std::pair op::v3::Broadcast::get_broadcast_axes() const { @@ -127,7 +127,7 @@ namespace } return result_shape; } -} +} // namespace bool op::v3::Broadcast::broadcast_evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const @@ -236,7 +236,7 @@ namespace } return broadcast_mode; } -} +} // namespace constexpr NodeTypeInfo op::v1::Broadcast::type_info; diff --git a/ngraph/core/src/op/ceiling.cpp b/ngraph/core/src/op/ceiling.cpp index 6b16608cf06..e866fb1326a 100644 --- a/ngraph/core/src/op/ceiling.cpp +++ b/ngraph/core/src/op/ceiling.cpp @@ -68,7 +68,7 @@ namespace ceiling } return rc; } -} +} // namespace ceiling bool op::Ceiling::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/clamp.cpp b/ngraph/core/src/op/clamp.cpp index 809694242fe..62fa86d503b 100644 --- a/ngraph/core/src/op/clamp.cpp +++ b/ngraph/core/src/op/clamp.cpp @@ -98,7 +98,7 @@ namespace clamp } return rc; } -} +} // namespace clamp bool op::v0::Clamp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/concat.cpp b/ngraph/core/src/op/concat.cpp index 77437fffe50..a1232eec1ce 100644 --- a/ngraph/core/src/op/concat.cpp +++ b/ngraph/core/src/op/concat.cpp @@ -136,7 +136,7 @@ namespace return true; } -} +} // namespace bool op::Concat::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/constant.cpp b/ngraph/core/src/op/constant.cpp index 0476d202b70..74471cc9f57 100644 --- a/ngraph/core/src/op/constant.cpp +++ b/ngraph/core/src/op/constant.cpp @@ -697,6 +697,6 @@ namespace ngraph size_t /* target_element_count */) { } - } - } -} + } // namespace v0 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/src/op/convert.cpp b/ngraph/core/src/op/convert.cpp index 80fe8de11c8..47ce6907322 100644 --- a/ngraph/core/src/op/convert.cpp +++ b/ngraph/core/src/op/convert.cpp @@ -145,7 +145,7 @@ namespace convert else return false; } -} +} // namespace convert bool op::v0::Convert::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/cos.cpp b/ngraph/core/src/op/cos.cpp index 026f8f5e116..79c28e3f23c 100644 --- a/ngraph/core/src/op/cos.cpp +++ b/ngraph/core/src/op/cos.cpp @@ -64,7 +64,7 @@ namespace cosop } return rc; } -} +} // namespace cosop bool op::Cos::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/cosh.cpp b/ngraph/core/src/op/cosh.cpp index 492ebbe386a..b2c0b673e3e 100644 --- a/ngraph/core/src/op/cosh.cpp +++ b/ngraph/core/src/op/cosh.cpp @@ -63,7 +63,7 @@ namespace coshop } return rc; } -} +} // namespace coshop bool op::Cosh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/depth_to_space.cpp b/ngraph/core/src/op/depth_to_space.cpp index 8cd850f516e..4b97e199dea 100644 --- a/ngraph/core/src/op/depth_to_space.cpp +++ b/ngraph/core/src/op/depth_to_space.cpp @@ -254,7 +254,7 @@ namespace ngraph { return s << as_string(type); } -} +} // namespace ngraph op::DepthToSpace::DepthToSpaceMode op::DepthToSpace::mode_from_string(const std::string& mode) const { diff --git a/ngraph/core/src/op/divide.cpp b/ngraph/core/src/op/divide.cpp index 0dc53b4e257..2e7e1893080 100644 --- a/ngraph/core/src/op/divide.cpp +++ b/ngraph/core/src/op/divide.cpp @@ -50,7 +50,7 @@ namespace divide } return rc; } -} +} // namespace divide // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/equal.cpp b/ngraph/core/src/op/equal.cpp index 1d6f45adf44..02373ea4735 100644 --- a/ngraph/core/src/op/equal.cpp +++ b/ngraph/core/src/op/equal.cpp @@ -47,7 +47,7 @@ namespace equal } return rc; } -} +} // namespace equal //------------------------------- v1 ------------------------------------------- diff --git a/ngraph/core/src/op/erf.cpp b/ngraph/core/src/op/erf.cpp index b559b2becc4..39851520d91 100644 --- a/ngraph/core/src/op/erf.cpp +++ b/ngraph/core/src/op/erf.cpp @@ -62,7 +62,7 @@ namespace erfop } return rc; } -} +} // namespace erfop bool op::Erf::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/exp.cpp b/ngraph/core/src/op/exp.cpp index 19c50392fe6..5cb36c024d7 100644 --- a/ngraph/core/src/op/exp.cpp +++ b/ngraph/core/src/op/exp.cpp @@ -63,7 +63,7 @@ namespace expop } return rc; } -} +} // namespace expop bool op::Exp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/floor.cpp b/ngraph/core/src/op/floor.cpp index 78d04e0029d..74ace6debf7 100644 --- a/ngraph/core/src/op/floor.cpp +++ b/ngraph/core/src/op/floor.cpp @@ -74,7 +74,7 @@ namespace floorop } return rc; } -} +} // namespace floorop bool op::Floor::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/floor_mod.cpp b/ngraph/core/src/op/floor_mod.cpp index d16c7c2fd95..a3575642d28 100644 --- a/ngraph/core/src/op/floor_mod.cpp +++ b/ngraph/core/src/op/floor_mod.cpp @@ -66,7 +66,7 @@ namespace floor_mod } return rc; } -} +} // namespace floor_mod bool op::v1::FloorMod::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/gelu.cpp b/ngraph/core/src/op/gelu.cpp index 9bd27023875..c2b07a50ef5 100644 --- a/ngraph/core/src/op/gelu.cpp +++ b/ngraph/core/src/op/gelu.cpp @@ -182,7 +182,7 @@ namespace gelu } return rc; } -} +} // namespace gelu bool op::v7::Gelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/greater.cpp b/ngraph/core/src/op/greater.cpp index e67a6f63b89..ed2dde4ddc3 100644 --- a/ngraph/core/src/op/greater.cpp +++ b/ngraph/core/src/op/greater.cpp @@ -47,7 +47,7 @@ namespace greaterop } return rc; } -} +} // namespace greaterop //-------------------------------------- v1 ------------------------------------ diff --git a/ngraph/core/src/op/greater_eq.cpp b/ngraph/core/src/op/greater_eq.cpp index 0ea56fc3644..b7bd0adaa52 100644 --- a/ngraph/core/src/op/greater_eq.cpp +++ b/ngraph/core/src/op/greater_eq.cpp @@ -47,7 +47,7 @@ namespace greater_equalop } return rc; } -} +} // namespace greater_equalop //---------------------------------- v1 ---------------------------------------- diff --git a/ngraph/core/src/op/hsigmoid.cpp b/ngraph/core/src/op/hsigmoid.cpp index 6ce9477dea7..2f7ee0f93a7 100644 --- a/ngraph/core/src/op/hsigmoid.cpp +++ b/ngraph/core/src/op/hsigmoid.cpp @@ -60,7 +60,7 @@ namespace } return rc; } -} +} // namespace bool op::v5::HSigmoid::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/hswish.cpp b/ngraph/core/src/op/hswish.cpp index d4401b21c1d..9ef892c46c6 100644 --- a/ngraph/core/src/op/hswish.cpp +++ b/ngraph/core/src/op/hswish.cpp @@ -59,7 +59,7 @@ namespace hswish } return rc; } -} +} // namespace hswish bool op::v4::HSwish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/interpolate.cpp b/ngraph/core/src/op/interpolate.cpp index 113b42fe768..3e3bf2a409c 100644 --- a/ngraph/core/src/op/interpolate.cpp +++ b/ngraph/core/src/op/interpolate.cpp @@ -173,7 +173,7 @@ namespace } return static_cast(static_cast(bound) * scale); } -} +} // namespace void op::v4::Interpolate::infer_using_scales(PartialShape& output_shape, const std::vector& axes, @@ -417,7 +417,7 @@ namespace return result; } -} +} // namespace void op::v4::Interpolate::correct_pads() { diff --git a/ngraph/core/src/op/less.cpp b/ngraph/core/src/op/less.cpp index 5f3e0ef5526..8447d13c73c 100644 --- a/ngraph/core/src/op/less.cpp +++ b/ngraph/core/src/op/less.cpp @@ -47,7 +47,7 @@ namespace lessop } return rc; } -} +} // namespace lessop // ----------------------------- v1 -------------------------------------------- diff --git a/ngraph/core/src/op/less_eq.cpp b/ngraph/core/src/op/less_eq.cpp index 0defd01d228..af83b483a2a 100644 --- a/ngraph/core/src/op/less_eq.cpp +++ b/ngraph/core/src/op/less_eq.cpp @@ -66,7 +66,7 @@ namespace less_equalop } return rc; } -} +} // namespace less_equalop bool op::v1::LessEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/log.cpp b/ngraph/core/src/op/log.cpp index 4e4dafbf082..222b5f12e10 100644 --- a/ngraph/core/src/op/log.cpp +++ b/ngraph/core/src/op/log.cpp @@ -62,7 +62,7 @@ namespace logop } return rc; } -} +} // namespace logop bool op::Log::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/matmul.cpp b/ngraph/core/src/op/matmul.cpp index d0cc4acb790..2252183c092 100644 --- a/ngraph/core/src/op/matmul.cpp +++ b/ngraph/core/src/op/matmul.cpp @@ -246,7 +246,7 @@ namespace matmul } return rc; } -} // namespace +} // namespace matmul bool op::MatMul::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/max.cpp b/ngraph/core/src/op/max.cpp index 493810edbac..0c93434c451 100644 --- a/ngraph/core/src/op/max.cpp +++ b/ngraph/core/src/op/max.cpp @@ -44,7 +44,7 @@ namespace maxop } return rc; } -} +} // namespace maxop NGRAPH_RTTI_DEFINITION(op::v1::ReduceMax, "ReduceMax", 1, util::ArithmeticReductionKeepDims); diff --git a/ngraph/core/src/op/max_pool.cpp b/ngraph/core/src/op/max_pool.cpp index f4f49bba990..fbb6c3fa3c2 100644 --- a/ngraph/core/src/op/max_pool.cpp +++ b/ngraph/core/src/op/max_pool.cpp @@ -229,7 +229,7 @@ namespace maxpool } return rc; } -} // namespace +} // namespace maxpool bool op::v1::MaxPool::evaluate_maxpool(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/maximum.cpp b/ngraph/core/src/op/maximum.cpp index ff63e1fa3cf..b15c6c0b20c 100644 --- a/ngraph/core/src/op/maximum.cpp +++ b/ngraph/core/src/op/maximum.cpp @@ -54,7 +54,7 @@ namespace maximumop } return rc; } -} +} // namespace maximumop // ------------------------------------ v1 ------------------------------------- diff --git a/ngraph/core/src/op/minimum.cpp b/ngraph/core/src/op/minimum.cpp index 2ad1822f533..f9781c4c389 100644 --- a/ngraph/core/src/op/minimum.cpp +++ b/ngraph/core/src/op/minimum.cpp @@ -52,7 +52,7 @@ namespace minimumop } return rc; } -} +} // namespace minimumop // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/mish.cpp b/ngraph/core/src/op/mish.cpp index ccd059b0c73..339466b7709 100644 --- a/ngraph/core/src/op/mish.cpp +++ b/ngraph/core/src/op/mish.cpp @@ -66,7 +66,7 @@ namespace mish } return rc; } -} +} // namespace mish bool op::v4::Mish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/multiply.cpp b/ngraph/core/src/op/multiply.cpp index f34acb6b6c1..e40bd3bfebe 100644 --- a/ngraph/core/src/op/multiply.cpp +++ b/ngraph/core/src/op/multiply.cpp @@ -47,7 +47,7 @@ namespace multiplyop } return rc; } -} +} // namespace multiplyop // ------------------------------------ v1 ------------------------------------- diff --git a/ngraph/core/src/op/negative.cpp b/ngraph/core/src/op/negative.cpp index 44aa1d344c8..6fc9857fc20 100644 --- a/ngraph/core/src/op/negative.cpp +++ b/ngraph/core/src/op/negative.cpp @@ -59,7 +59,7 @@ namespace negativeop } return rc; } -} +} // namespace negativeop bool op::Negative::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/non_max_suppression.cpp b/ngraph/core/src/op/non_max_suppression.cpp index 06f146de819..19359bfa6c8 100644 --- a/ngraph/core/src/op/non_max_suppression.cpp +++ b/ngraph/core/src/op/non_max_suppression.cpp @@ -704,7 +704,7 @@ namespace return ngraph::is_scalar(shape) || (is_vector(shape) && (shape[0] == 1)); } -} +} // namespace void op::v5::NonMaxSuppression::validate() { diff --git a/ngraph/core/src/op/non_zero.cpp b/ngraph/core/src/op/non_zero.cpp index ab996d89aed..db7998f718a 100644 --- a/ngraph/core/src/op/non_zero.cpp +++ b/ngraph/core/src/op/non_zero.cpp @@ -165,7 +165,7 @@ namespace nonzero } return rc; } -} +} // namespace nonzero bool op::v3::NonZero::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/not.cpp b/ngraph/core/src/op/not.cpp index a0dbecc4b7e..30192544a1f 100644 --- a/ngraph/core/src/op/not.cpp +++ b/ngraph/core/src/op/not.cpp @@ -75,7 +75,7 @@ namespace notop } return rc; } -} +} // namespace notop bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/not_equal.cpp b/ngraph/core/src/op/not_equal.cpp index e9fc67acc46..0db7617bc1a 100644 --- a/ngraph/core/src/op/not_equal.cpp +++ b/ngraph/core/src/op/not_equal.cpp @@ -47,7 +47,7 @@ namespace not_equalop } return rc; } -} +} // namespace not_equalop // ----------------------------------- v1 -------------------------------------- diff --git a/ngraph/core/src/op/or.cpp b/ngraph/core/src/op/or.cpp index 7a0269561b7..8412d1df044 100644 --- a/ngraph/core/src/op/or.cpp +++ b/ngraph/core/src/op/or.cpp @@ -64,7 +64,7 @@ namespace logor } return rc; } -} +} // namespace logor bool op::v1::LogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/power.cpp b/ngraph/core/src/op/power.cpp index cc8400edebe..b62356566f2 100644 --- a/ngraph/core/src/op/power.cpp +++ b/ngraph/core/src/op/power.cpp @@ -50,7 +50,7 @@ namespace power } return rc; } -} +} // namespace power // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/prelu.cpp b/ngraph/core/src/op/prelu.cpp index a7e3ac0aee0..c7d5038e809 100644 --- a/ngraph/core/src/op/prelu.cpp +++ b/ngraph/core/src/op/prelu.cpp @@ -73,7 +73,7 @@ namespace prelu } return rc; } -} +} // namespace prelu bool op::PRelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/prior_box.cpp b/ngraph/core/src/op/prior_box.cpp index 13596fdfb44..d1db0539734 100644 --- a/ngraph/core/src/op/prior_box.cpp +++ b/ngraph/core/src/op/prior_box.cpp @@ -179,7 +179,7 @@ namespace prior_box } return rc; } -} +} // namespace prior_box bool op::v0::PriorBox::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/prior_box_clustered.cpp b/ngraph/core/src/op/prior_box_clustered.cpp index 3be58c0f998..21a5ad12a87 100644 --- a/ngraph/core/src/op/prior_box_clustered.cpp +++ b/ngraph/core/src/op/prior_box_clustered.cpp @@ -152,7 +152,7 @@ namespace prior_box_clustered } return rc; } -} +} // namespace prior_box_clustered bool op::v0::PriorBoxClustered::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/range.cpp b/ngraph/core/src/op/range.cpp index 6e87dc645e3..7e040b3a280 100644 --- a/ngraph/core/src/op/range.cpp +++ b/ngraph/core/src/op/range.cpp @@ -288,7 +288,7 @@ namespace rangeop } return rc; } -} +} // namespace rangeop bool op::v4::Range::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_l1.cpp b/ngraph/core/src/op/reduce_l1.cpp index f4c02d6f133..351cbea426d 100644 --- a/ngraph/core/src/op/reduce_l1.cpp +++ b/ngraph/core/src/op/reduce_l1.cpp @@ -65,7 +65,7 @@ namespace reduce_l1 } return rc; } -} +} // namespace reduce_l1 bool op::v4::ReduceL1::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/reduce_l2.cpp b/ngraph/core/src/op/reduce_l2.cpp index 8c2498f0c3d..1f5ff694a64 100644 --- a/ngraph/core/src/op/reduce_l2.cpp +++ b/ngraph/core/src/op/reduce_l2.cpp @@ -63,7 +63,7 @@ namespace reduce_l2 } return rc; } -} +} // namespace reduce_l2 bool op::v4::ReduceL2::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/reduce_mean.cpp b/ngraph/core/src/op/reduce_mean.cpp index 28331a8e905..01bb0ddcde4 100644 --- a/ngraph/core/src/op/reduce_mean.cpp +++ b/ngraph/core/src/op/reduce_mean.cpp @@ -62,7 +62,7 @@ namespace mean } return rc; } -} +} // namespace mean bool op::v1::ReduceMean::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/reduce_prod.cpp b/ngraph/core/src/op/reduce_prod.cpp index c0e8836ebf2..53f31945725 100644 --- a/ngraph/core/src/op/reduce_prod.cpp +++ b/ngraph/core/src/op/reduce_prod.cpp @@ -67,7 +67,7 @@ namespace reduce_prod } return rc; } -} +} // namespace reduce_prod bool op::v1::ReduceProd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/reduce_sum.cpp b/ngraph/core/src/op/reduce_sum.cpp index 935942fe7cf..8da6ba369a3 100644 --- a/ngraph/core/src/op/reduce_sum.cpp +++ b/ngraph/core/src/op/reduce_sum.cpp @@ -67,7 +67,7 @@ namespace reduce_sum } return rc; } -} +} // namespace reduce_sum bool op::v1::ReduceSum::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/relu.cpp b/ngraph/core/src/op/relu.cpp index 1b015b9e70f..e698406dde4 100644 --- a/ngraph/core/src/op/relu.cpp +++ b/ngraph/core/src/op/relu.cpp @@ -58,7 +58,7 @@ namespace relu } return rc; } -} +} // namespace relu bool op::Relu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reshape.cpp b/ngraph/core/src/op/reshape.cpp index d15520880fa..4ee131587de 100644 --- a/ngraph/core/src/op/reshape.cpp +++ b/ngraph/core/src/op/reshape.cpp @@ -187,7 +187,7 @@ namespace reshapeop reshape_node->get_input_shape(0)); } } -} +} // namespace reshapeop NGRAPH_RTTI_DEFINITION(op::v1::Reshape, "Reshape", 1); diff --git a/ngraph/core/src/op/reverse.cpp b/ngraph/core/src/op/reverse.cpp index ac4cba8df76..e9f1c85eb20 100644 --- a/ngraph/core/src/op/reverse.cpp +++ b/ngraph/core/src/op/reverse.cpp @@ -147,7 +147,7 @@ namespace reverseop size_t axes_rank = in->get_element_count(); std::copy(axes_indices, axes_indices + axes_rank, std::inserter(axes, axes.end())); } -} +} // namespace reverseop #define GET_AXES(a, ...) \ case element::Type_t::a: \ diff --git a/ngraph/core/src/op/roi_align.cpp b/ngraph/core/src/op/roi_align.cpp index db7b257f67a..f02fb934c85 100644 --- a/ngraph/core/src/op/roi_align.cpp +++ b/ngraph/core/src/op/roi_align.cpp @@ -285,7 +285,7 @@ namespace roi_alinop return rc; } -} // namespace +} // namespace roi_alinop bool op::v3::ROIAlign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/round.cpp b/ngraph/core/src/op/round.cpp index 70949858e29..85a50cdf002 100644 --- a/ngraph/core/src/op/round.cpp +++ b/ngraph/core/src/op/round.cpp @@ -62,7 +62,7 @@ namespace roundop } return rc; } -} +} // namespace roundop NGRAPH_RTTI_DEFINITION(op::v5::Round, "Round", 5); diff --git a/ngraph/core/src/op/scatter_elements_update.cpp b/ngraph/core/src/op/scatter_elements_update.cpp index dc2bfd0c11c..d66cde3dec9 100644 --- a/ngraph/core/src/op/scatter_elements_update.cpp +++ b/ngraph/core/src/op/scatter_elements_update.cpp @@ -253,7 +253,7 @@ namespace scatter_element_update } return rc; } -} +} // namespace scatter_element_update bool op::v3::ScatterElementsUpdate::evaluate_scatter_element_update( const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/scatter_nd_update.cpp b/ngraph/core/src/op/scatter_nd_update.cpp index a887daf2cb1..915984418f9 100644 --- a/ngraph/core/src/op/scatter_nd_update.cpp +++ b/ngraph/core/src/op/scatter_nd_update.cpp @@ -85,7 +85,7 @@ namespace scatter } return rc; } -} +} // namespace scatter bool op::v3::ScatterNDUpdate::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/scatter_update.cpp b/ngraph/core/src/op/scatter_update.cpp index 347ca43587f..4c5b3d21390 100644 --- a/ngraph/core/src/op/scatter_update.cpp +++ b/ngraph/core/src/op/scatter_update.cpp @@ -39,7 +39,7 @@ namespace scatter_update auto data_ptr = in->get_data_ptr(); return std::vector(data_ptr, data_ptr + in->get_element_count()); } -} +} // namespace scatter_update #define GET_INDICES(a, ...) \ case element::Type_t::a: \ diff --git a/ngraph/core/src/op/shape_of.cpp b/ngraph/core/src/op/shape_of.cpp index 2f34c88a25a..ca480339777 100644 --- a/ngraph/core/src/op/shape_of.cpp +++ b/ngraph/core/src/op/shape_of.cpp @@ -210,7 +210,7 @@ namespace shape_of } return true; } -} +} // namespace shape_of bool op::v3::ShapeOf::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const diff --git a/ngraph/core/src/op/sigmoid.cpp b/ngraph/core/src/op/sigmoid.cpp index 8a0353b24c0..c3051c6929e 100644 --- a/ngraph/core/src/op/sigmoid.cpp +++ b/ngraph/core/src/op/sigmoid.cpp @@ -59,7 +59,7 @@ namespace sigmoid } return rc; } -} +} // namespace sigmoid bool op::Sigmoid::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sign.cpp b/ngraph/core/src/op/sign.cpp index 836d4db915c..fb7749014f5 100644 --- a/ngraph/core/src/op/sign.cpp +++ b/ngraph/core/src/op/sign.cpp @@ -61,7 +61,7 @@ namespace signop } return rc; } -} +} // namespace signop bool op::Sign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sin.cpp b/ngraph/core/src/op/sin.cpp index 0308f20b1cd..47dff773364 100644 --- a/ngraph/core/src/op/sin.cpp +++ b/ngraph/core/src/op/sin.cpp @@ -63,7 +63,7 @@ namespace sinop } return rc; } -} +} // namespace sinop bool op::Sin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sinh.cpp b/ngraph/core/src/op/sinh.cpp index 352f88723b5..9d6416e5079 100644 --- a/ngraph/core/src/op/sinh.cpp +++ b/ngraph/core/src/op/sinh.cpp @@ -63,7 +63,7 @@ namespace sinhop } return rc; } -} +} // namespace sinhop bool op::Sinh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/softmax.cpp b/ngraph/core/src/op/softmax.cpp index 641246dff8a..2517133f763 100644 --- a/ngraph/core/src/op/softmax.cpp +++ b/ngraph/core/src/op/softmax.cpp @@ -48,7 +48,7 @@ namespace } return rc; } -} +} // namespace // *** SOFTMAX OP SET V1 *** constexpr NodeTypeInfo op::v1::Softmax::type_info; diff --git a/ngraph/core/src/op/softplus.cpp b/ngraph/core/src/op/softplus.cpp index aefaca0d07f..af6049d1b30 100644 --- a/ngraph/core/src/op/softplus.cpp +++ b/ngraph/core/src/op/softplus.cpp @@ -65,7 +65,7 @@ namespace softplus } return rc; } -} +} // namespace softplus bool op::v4::SoftPlus::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/split.cpp b/ngraph/core/src/op/split.cpp index 9202074cd7e..1b91b154457 100644 --- a/ngraph/core/src/op/split.cpp +++ b/ngraph/core/src/op/split.cpp @@ -137,7 +137,7 @@ namespace split evaluate(data_tensor, outputs, axis, num_splits); return true; } -} +} // namespace split bool op::v1::Split::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sqrt.cpp b/ngraph/core/src/op/sqrt.cpp index 35ac4d9b74b..d1a1fca015b 100644 --- a/ngraph/core/src/op/sqrt.cpp +++ b/ngraph/core/src/op/sqrt.cpp @@ -61,7 +61,7 @@ namespace sqrtop } return rc; } -} +} // namespace sqrtop bool op::Sqrt::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/squeeze.cpp b/ngraph/core/src/op/squeeze.cpp index f5094f9406b..481595b2ea6 100644 --- a/ngraph/core/src/op/squeeze.cpp +++ b/ngraph/core/src/op/squeeze.cpp @@ -247,7 +247,7 @@ namespace squeeze { return evaluate(arg0, out); } -} +} // namespace squeeze bool op::v0::Squeeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/strided_slice.cpp b/ngraph/core/src/op/strided_slice.cpp index 1519c7489b0..be2036f0abf 100644 --- a/ngraph/core/src/op/strided_slice.cpp +++ b/ngraph/core/src/op/strided_slice.cpp @@ -72,7 +72,7 @@ namespace return op::Constant::create( element::i64, Shape{strides_length}, vector(strides_length, 1)); } -} +} // namespace op::v1::StridedSlice::StridedSlice(const Output& data, const Output& begin, @@ -267,7 +267,7 @@ namespace strided_slice ellipsis_mask); return evaluate(in, slice_plan, out); } -} +} // namespace strided_slice bool op::v1::StridedSlice::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const diff --git a/ngraph/core/src/op/subtract.cpp b/ngraph/core/src/op/subtract.cpp index d513bc67fac..630904e4a4f 100644 --- a/ngraph/core/src/op/subtract.cpp +++ b/ngraph/core/src/op/subtract.cpp @@ -48,7 +48,7 @@ namespace subtract } return rc; } -} +} // namespace subtract // ------------------------------- v1 ------------------------------------------ diff --git a/ngraph/core/src/op/swish.cpp b/ngraph/core/src/op/swish.cpp index 72320269e8c..f29284e5874 100644 --- a/ngraph/core/src/op/swish.cpp +++ b/ngraph/core/src/op/swish.cpp @@ -117,7 +117,7 @@ namespace swish } return rc; } -} +} // namespace swish bool op::v4::Swish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/tan.cpp b/ngraph/core/src/op/tan.cpp index fc5cc702d02..a3dae283193 100644 --- a/ngraph/core/src/op/tan.cpp +++ b/ngraph/core/src/op/tan.cpp @@ -64,7 +64,7 @@ namespace tanop } return rc; } -} +} // namespace tanop bool op::Tan::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/tanh.cpp b/ngraph/core/src/op/tanh.cpp index acca15dd2f6..fe4fac69dd3 100644 --- a/ngraph/core/src/op/tanh.cpp +++ b/ngraph/core/src/op/tanh.cpp @@ -62,7 +62,7 @@ namespace tanhop } return rc; } -} +} // namespace tanhop bool op::Tanh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/topk.cpp b/ngraph/core/src/op/topk.cpp index 68cbb175421..9cd2fa3ae0a 100644 --- a/ngraph/core/src/op/topk.cpp +++ b/ngraph/core/src/op/topk.cpp @@ -202,7 +202,7 @@ namespace topk } return k; } -} +} // namespace topk // v1 version starts constexpr NodeTypeInfo op::v1::TopK::type_info; diff --git a/ngraph/core/src/op/transpose.cpp b/ngraph/core/src/op/transpose.cpp index 74d24c58b7d..6470efc2c15 100644 --- a/ngraph/core/src/op/transpose.cpp +++ b/ngraph/core/src/op/transpose.cpp @@ -130,7 +130,7 @@ namespace transpose arg1->get_element_type().size()); return true; } -} +} // namespace transpose bool op::v1::Transpose::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/unsqueeze.cpp b/ngraph/core/src/op/unsqueeze.cpp index 1c6f2c08a62..dd593d0920e 100644 --- a/ngraph/core/src/op/unsqueeze.cpp +++ b/ngraph/core/src/op/unsqueeze.cpp @@ -132,7 +132,7 @@ namespace unsqueeze } return rc; } -} +} // namespace unsqueeze bool op::v0::Unsqueeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/op/util/attr_types.cpp b/ngraph/core/src/op/util/attr_types.cpp index 53b59138bcd..e2fb8ebd982 100644 --- a/ngraph/core/src/op/util/attr_types.cpp +++ b/ngraph/core/src/op/util/attr_types.cpp @@ -219,4 +219,4 @@ namespace ngraph {"bidirectional", op::RecurrentSequenceDirection::BIDIRECTIONAL}}); return enum_names; } -} +} // namespace ngraph diff --git a/ngraph/core/src/op/util/broadcast_base.cpp b/ngraph/core/src/op/util/broadcast_base.cpp index bb640f5a66a..3264a6a29ce 100644 --- a/ngraph/core/src/op/util/broadcast_base.cpp +++ b/ngraph/core/src/op/util/broadcast_base.cpp @@ -475,7 +475,7 @@ namespace } return target_shape; } -} +} // namespace bool op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0, const HostTensorPtr& out, diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 2f2cd0c9822..916b7cc7c5b 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -201,4 +201,4 @@ namespace ngraph constexpr DiscreteTypeInfo AttributeAdapter< std::vector>>::type_info; -} +} // namespace ngraph diff --git a/ngraph/core/src/op/variadic_split.cpp b/ngraph/core/src/op/variadic_split.cpp index 950ff6a99f1..9b0fea4ede9 100644 --- a/ngraph/core/src/op/variadic_split.cpp +++ b/ngraph/core/src/op/variadic_split.cpp @@ -154,7 +154,7 @@ namespace variadic_split return true; } -} +} // namespace variadic_split bool op::v1::VariadicSplit::evaluate_variadic_split(const HostTensorVector& inputs, const HostTensorVector& outputs) const diff --git a/ngraph/core/src/op/xor.cpp b/ngraph/core/src/op/xor.cpp index f38546cb532..d70c7a59ced 100644 --- a/ngraph/core/src/op/xor.cpp +++ b/ngraph/core/src/op/xor.cpp @@ -71,7 +71,7 @@ namespace logxor } return rc; } -} +} // namespace logxor bool op::v1::LogicalXor::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index e25e4b30d7d..c04cc7f1331 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -36,9 +36,9 @@ namespace ngraph static PerfCounters counters; return counters; } - } - } -} + } // namespace + } // namespace pass +} // namespace ngraph pass::Manager::Manager() : m_pass_config(std::make_shared()) diff --git a/ngraph/core/src/pass/perf_counters.cpp b/ngraph/core/src/pass/perf_counters.cpp index 9fb3a81c226..97010fc8e08 100644 --- a/ngraph/core/src/pass/perf_counters.cpp +++ b/ngraph/core/src/pass/perf_counters.cpp @@ -16,5 +16,5 @@ namespace ngraph return it->second; return m_counters[&type_inf] = openvino::itt::handle(type_inf.name); } - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/src/pass/perf_counters.hpp b/ngraph/core/src/pass/perf_counters.hpp index 5d1cef265c0..89a30531556 100644 --- a/ngraph/core/src/pass/perf_counters.hpp +++ b/ngraph/core/src/pass/perf_counters.hpp @@ -30,5 +30,5 @@ namespace ngraph std::mutex m_mutex; counters_map m_counters; }; - } -} + } // namespace pass +} // namespace ngraph diff --git a/ngraph/core/src/pattern/matcher.cpp b/ngraph/core/src/pattern/matcher.cpp index b8bca92824b..0e07bdd5828 100644 --- a/ngraph/core/src/pattern/matcher.cpp +++ b/ngraph/core/src/pattern/matcher.cpp @@ -32,7 +32,7 @@ namespace ngraph ? node->output(0) : std::make_shared(node)->output(0); } - } + } // namespace Matcher::Matcher(std::shared_ptr pattern_node) : m_pattern_node(make_node_output(pattern_node)) @@ -253,7 +253,7 @@ namespace ngraph } return result; } - } + } // namespace RecurrentMatcher::RecurrentMatcher( const Output& initial_pattern, @@ -305,5 +305,5 @@ namespace ngraph return matched; } - } -} + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/src/pattern/op/pattern.cpp b/ngraph/core/src/pattern/op/pattern.cpp index bd04a084c42..a62155b66fc 100644 --- a/ngraph/core/src/pattern/op/pattern.cpp +++ b/ngraph/core/src/pattern/op/pattern.cpp @@ -28,7 +28,7 @@ namespace ngraph }; } } - } + } // namespace op PatternMap as_pattern_map(const PatternValueMap& pattern_value_map) { @@ -114,5 +114,5 @@ namespace ngraph [=](element::Type type) { return type == output_type; }); }; } - } -} + } // namespace pattern +} // namespace ngraph diff --git a/ngraph/core/src/provenance.cpp b/ngraph/core/src/provenance.cpp index ff1442ce179..30893503668 100644 --- a/ngraph/core/src/provenance.cpp +++ b/ngraph/core/src/provenance.cpp @@ -12,4 +12,4 @@ namespace ngraph void set_provenance_enabled(bool enabled) { s_provenance_enabled = enabled; } bool get_provenance_enabled() { return s_provenance_enabled; } -} +} // namespace ngraph diff --git a/ngraph/core/src/runtime/aligned_buffer.cpp b/ngraph/core/src/runtime/aligned_buffer.cpp index 121c88e911c..ec38c0edfca 100644 --- a/ngraph/core/src/runtime/aligned_buffer.cpp +++ b/ngraph/core/src/runtime/aligned_buffer.cpp @@ -78,4 +78,4 @@ namespace ngraph : DirectValueAccessor>(value) { } -} +} // namespace ngraph diff --git a/ngraph/core/src/type.cpp b/ngraph/core/src/type.cpp index 9e3bf3b1a48..d5bf8ba9b9c 100644 --- a/ngraph/core/src/type.cpp +++ b/ngraph/core/src/type.cpp @@ -14,4 +14,4 @@ namespace std // don't use parent for hash calculation, it is not a part of type (yet) return ngraph::hash_combine(vector{name_hash, version_hash}); } -} +} // namespace std diff --git a/ngraph/core/src/type/element_type.cpp b/ngraph/core/src/type/element_type.cpp index 3ce890e3081..8d688fbf995 100644 --- a/ngraph/core/src/type/element_type.cpp +++ b/ngraph/core/src/type/element_type.cpp @@ -209,8 +209,8 @@ namespace ngraph { return Type_t::bf16; } - } -} + } // namespace element +} // namespace ngraph std::ostream& element::operator<<(std::ostream& out, const element::Type& obj) { @@ -333,7 +333,7 @@ namespace ngraph {"u64", element::Type_t::u64}}); return enum_names; } -} +} // namespace ngraph constexpr DiscreteTypeInfo AttributeAdapter::type_info; diff --git a/ngraph/core/src/util.cpp b/ngraph/core/src/util.cpp index b56c7b65e69..2d799c30bb6 100644 --- a/ngraph/core/src/util.cpp +++ b/ngraph/core/src/util.cpp @@ -292,7 +292,7 @@ namespace ngraph return result; } -} +} // namespace ngraph std::ostream& operator<<(std::ostream& os, const ngraph::NodeVector& nv) { @@ -394,7 +394,7 @@ namespace ngraph return output; } -} +} // namespace ngraph AxisVector ngraph::get_default_order(const Shape& shape) { diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index adba109aa45..7678a9f76eb 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -1235,7 +1235,7 @@ namespace } vector exec_nop(Node* node, vector& inputs) { return {inputs.at(0)}; } -} +} // namespace pair ngraph::maximum_value(const Output& value) { diff --git a/ngraph/frontend/onnx_common/include/onnx_common/utils.hpp b/ngraph/frontend/onnx_common/include/onnx_common/utils.hpp index c9d28bede13..499875cc26b 100644 --- a/ngraph/frontend/onnx_common/include/onnx_common/utils.hpp +++ b/ngraph/frontend/onnx_common/include/onnx_common/utils.hpp @@ -38,5 +38,5 @@ namespace ngraph /// bool is_supported_ng_type(const element::Type_t& ng_type); - } // namespace onnx_editor + } // namespace onnx_common } // namespace ngraph diff --git a/ngraph/frontend/onnx_common/src/utils.cpp b/ngraph/frontend/onnx_common/src/utils.cpp index 55e1a4e9288..1fbe610137f 100644 --- a/ngraph/frontend/onnx_common/src/utils.cpp +++ b/ngraph/frontend/onnx_common/src/utils.cpp @@ -57,7 +57,7 @@ namespace ngraph {element::Type_t::u32, TensorProto_DataType::TensorProto_DataType_UINT32}, {element::Type_t::u64, TensorProto_DataType::TensorProto_DataType_UINT64}, {element::Type_t::boolean, TensorProto_DataType::TensorProto_DataType_BOOL}}; - } + } // namespace element::Type_t onnx_to_ng_data_type(const TensorProto_DataType& onnx_type) { @@ -88,5 +88,5 @@ namespace ngraph return NG_2_ONNX_TYPES.count(ng_type) > 0; } - } // namespace onnx_editor + } // namespace onnx_common } // namespace ngraph diff --git a/ngraph/frontend/onnx_import/include/onnx_import/core/node.hpp b/ngraph/frontend/onnx_import/include/onnx_import/core/node.hpp index 32913e3a411..e5a59fa9ea9 100644 --- a/ngraph/frontend/onnx_import/include/onnx_import/core/node.hpp +++ b/ngraph/frontend/onnx_import/include/onnx_import/core/node.hpp @@ -15,7 +15,7 @@ namespace ONNX_NAMESPACE { // forward declaration class NodeProto; -} +} // namespace ONNX_NAMESPACE namespace ngraph { diff --git a/ngraph/frontend/onnx_import/src/core/null_node.hpp b/ngraph/frontend/onnx_import/src/core/null_node.hpp index cd386014fa2..c02a06ecfd2 100644 --- a/ngraph/frontend/onnx_import/src/core/null_node.hpp +++ b/ngraph/frontend/onnx_import/src/core/null_node.hpp @@ -19,7 +19,7 @@ namespace ngraph bool is_null(const std::shared_ptr& node); ONNX_IMPORTER_API bool is_null(const Output& output); - } + } // namespace op namespace onnx_import { /// \brief Represents a missing optional input or output of an ONNX node diff --git a/ngraph/frontend/onnx_import/src/core/tensor.hpp b/ngraph/frontend/onnx_import/src/core/tensor.hpp index 069d11a9cf8..53d1dea864c 100644 --- a/ngraph/frontend/onnx_import/src/core/tensor.hpp +++ b/ngraph/frontend/onnx_import/src/core/tensor.hpp @@ -95,8 +95,8 @@ namespace ngraph { } }; - } - } + } // namespace tensor + } // namespace error namespace detail { @@ -153,8 +153,8 @@ namespace ngraph return false; } } - } - } + } // namespace detail + } // namespace template inline std::vector get_data(const ONNX_NAMESPACE::TensorProto& tensor) @@ -419,8 +419,8 @@ namespace ngraph } throw error::tensor::invalid_data_type{tensor.data_type()}; } - } - } + } // namespace tensor + } // namespace detail class Tensor { @@ -586,5 +586,5 @@ namespace ngraph { return (outs << ""); } - } -} + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/default_opset.hpp b/ngraph/frontend/onnx_import/src/default_opset.hpp index 52736fe6d15..a0ab2f136ae 100644 --- a/ngraph/frontend/onnx_import/src/default_opset.hpp +++ b/ngraph/frontend/onnx_import/src/default_opset.hpp @@ -10,4 +10,4 @@ namespace ngraph { namespace default_opset = ngraph::opset7; } -} +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/exceptions.cpp b/ngraph/frontend/onnx_import/src/exceptions.cpp index 5907ba12553..1c31c9d9bc5 100644 --- a/ngraph/frontend/onnx_import/src/exceptions.cpp +++ b/ngraph/frontend/onnx_import/src/exceptions.cpp @@ -20,7 +20,7 @@ namespace ngraph ss << "While validating ONNX node '" << node << "'"; return ss.str(); } - } - } - } -} + } // namespace detail + } // namespace error + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/constant.cpp b/ngraph/frontend/onnx_import/src/op/constant.cpp index 1ae150d39a6..0aa68d8909c 100644 --- a/ngraph/frontend/onnx_import/src/op/constant.cpp +++ b/ngraph/frontend/onnx_import/src/op/constant.cpp @@ -158,7 +158,7 @@ namespace ngraph default: throw error::tensor::invalid_data_type{tensor}; } } - } + } // namespace OutputVector constant(const onnx_import::Node& node) { diff --git a/ngraph/frontend/onnx_import/src/op/conv_transpose.cpp b/ngraph/frontend/onnx_import/src/op/conv_transpose.cpp index 9f57a7dea95..455b14b4d68 100644 --- a/ngraph/frontend/onnx_import/src/op/conv_transpose.cpp +++ b/ngraph/frontend/onnx_import/src/op/conv_transpose.cpp @@ -215,7 +215,7 @@ namespace ngraph bias, bias_shape_node, false) ->add_provenance_group_members_above({bias}); } - } + } // namespace OutputVector conv_transpose(const Node& node) { diff --git a/ngraph/frontend/onnx_import/src/op/cos.hpp b/ngraph/frontend/onnx_import/src/op/cos.hpp index 69d8f61605a..33cb6a85a8b 100644 --- a/ngraph/frontend/onnx_import/src/op/cos.hpp +++ b/ngraph/frontend/onnx_import/src/op/cos.hpp @@ -17,7 +17,7 @@ namespace ngraph { OutputVector cos(const Node& node); } - } + } // namespace op } // namespace onnx_import diff --git a/ngraph/frontend/onnx_import/src/op/cosh.hpp b/ngraph/frontend/onnx_import/src/op/cosh.hpp index aedc76f1f03..28380654936 100644 --- a/ngraph/frontend/onnx_import/src/op/cosh.hpp +++ b/ngraph/frontend/onnx_import/src/op/cosh.hpp @@ -17,7 +17,7 @@ namespace ngraph { OutputVector cosh(const Node& node); } - } - } // namespace onnx_import + } // namespace op + } // namespace onnx_import } // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/dequantize_linear.cpp b/ngraph/frontend/onnx_import/src/op/dequantize_linear.cpp index e52c1580266..f6b37511d60 100644 --- a/ngraph/frontend/onnx_import/src/op/dequantize_linear.cpp +++ b/ngraph/frontend/onnx_import/src/op/dequantize_linear.cpp @@ -42,7 +42,7 @@ namespace ngraph return default_opset::Constant::create(element::f32, Shape{}, {0}); } } - } + } // namespace namespace set_1 { OutputVector dequantize_linear(const Node& node) @@ -68,7 +68,7 @@ namespace ngraph return {std::make_shared( std::make_shared(converted_x, zero_point), scale)}; } - } + } // namespace set_1 namespace set_13 { @@ -155,7 +155,7 @@ namespace ngraph return std::make_shared(input, target_shape, true); } - } + } // namespace OutputVector dequantize_linear(const Node& node) { @@ -191,7 +191,7 @@ namespace ngraph return {std::make_shared( std::make_shared(converted_x, zero_point), scale)}; } - } - } - } -} + } // namespace set_13 + } // namespace op + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/dropout.cpp b/ngraph/frontend/onnx_import/src/op/dropout.cpp index a2fccac1893..6666e67c10f 100644 --- a/ngraph/frontend/onnx_import/src/op/dropout.cpp +++ b/ngraph/frontend/onnx_import/src/op/dropout.cpp @@ -40,7 +40,7 @@ namespace ngraph return {input_data}; } } - } + } // namespace namespace set_12 { diff --git a/ngraph/frontend/onnx_import/src/op/gru.cpp b/ngraph/frontend/onnx_import/src/op/gru.cpp index d0c600c8aac..397095e5be0 100644 --- a/ngraph/frontend/onnx_import/src/op/gru.cpp +++ b/ngraph/frontend/onnx_import/src/op/gru.cpp @@ -99,7 +99,7 @@ namespace ngraph bool m_linear_before_reset; }; - } + } // namespace OutputVector gru(const Node& node) { diff --git a/ngraph/frontend/onnx_import/src/op/image_scaler.cpp b/ngraph/frontend/onnx_import/src/op/image_scaler.cpp index f38630b3b5b..236e1e3f227 100644 --- a/ngraph/frontend/onnx_import/src/op/image_scaler.cpp +++ b/ngraph/frontend/onnx_import/src/op/image_scaler.cpp @@ -45,7 +45,7 @@ namespace ngraph return {scaler}; } - } - } - } -} + } // namespace set_1 + } // namespace op + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/image_scaler.hpp b/ngraph/frontend/onnx_import/src/op/image_scaler.hpp index a7787d05368..dd7c505bcfe 100644 --- a/ngraph/frontend/onnx_import/src/op/image_scaler.hpp +++ b/ngraph/frontend/onnx_import/src/op/image_scaler.hpp @@ -17,6 +17,6 @@ namespace ngraph { OutputVector image_scaler(const Node& node); } - } - } -} + } // namespace op + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/log.hpp b/ngraph/frontend/onnx_import/src/op/log.hpp index 03ab4955b4a..c6c40ae7558 100644 --- a/ngraph/frontend/onnx_import/src/op/log.hpp +++ b/ngraph/frontend/onnx_import/src/op/log.hpp @@ -17,7 +17,7 @@ namespace ngraph { OutputVector log(const Node& node); } - } + } // namespace op } // namespace onnx_import diff --git a/ngraph/frontend/onnx_import/src/op/log_softmax.cpp b/ngraph/frontend/onnx_import/src/op/log_softmax.cpp index 88ce0129974..b44e8dcfcf4 100644 --- a/ngraph/frontend/onnx_import/src/op/log_softmax.cpp +++ b/ngraph/frontend/onnx_import/src/op/log_softmax.cpp @@ -62,7 +62,7 @@ namespace ngraph return {result}; } - } + } // namespace detail namespace op { @@ -74,7 +74,7 @@ namespace ngraph namespace set_13 { OutputVector log_softmax(const Node& node) { return detail::log_softmax(node, -1); } - } // namespace set_1 + } // namespace set_13 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/log_softmax.hpp b/ngraph/frontend/onnx_import/src/op/log_softmax.hpp index 56f25d7c370..cd2d24bed79 100644 --- a/ngraph/frontend/onnx_import/src/op/log_softmax.hpp +++ b/ngraph/frontend/onnx_import/src/op/log_softmax.hpp @@ -23,7 +23,7 @@ namespace ngraph { OutputVector log_softmax(const Node& node); - } // namespace set_1 + } // namespace set_13 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/loop.cpp b/ngraph/frontend/onnx_import/src/op/loop.cpp index 9b011f91c59..8d8c8c66057 100644 --- a/ngraph/frontend/onnx_import/src/op/loop.cpp +++ b/ngraph/frontend/onnx_import/src/op/loop.cpp @@ -61,7 +61,7 @@ namespace ngraph } return false; } - } + } // namespace OutputVector loop(const Node& node) { diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp index 30076dafc8d..c4abacc162b 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/group_norm.cpp @@ -51,8 +51,8 @@ namespace ngraph } return std::make_shared(new_shape, 0); } - } - } // detail + } // namespace + } // namespace detail namespace set_1 { diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp index 97620d4615c..855f8938668 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp @@ -31,8 +31,8 @@ namespace ngraph std::vector{0}, // begin mask std::vector{0}); // end mask } - } - } // detail + } // namespace + } // namespace detail namespace set_1 { diff --git a/ngraph/frontend/onnx_import/src/op/pad.cpp b/ngraph/frontend/onnx_import/src/op/pad.cpp index 1c01f64182b..47d90a037e0 100644 --- a/ngraph/frontend/onnx_import/src/op/pad.cpp +++ b/ngraph/frontend/onnx_import/src/op/pad.cpp @@ -41,7 +41,7 @@ namespace return pad_mode; } -} +} // namespace namespace ngraph { namespace onnx_import diff --git a/ngraph/frontend/onnx_import/src/op/reduce.hpp b/ngraph/frontend/onnx_import/src/op/reduce.hpp index b43420518a5..c01432aee28 100644 --- a/ngraph/frontend/onnx_import/src/op/reduce.hpp +++ b/ngraph/frontend/onnx_import/src/op/reduce.hpp @@ -27,7 +27,7 @@ namespace ngraph /// \return The nGraph node equivalent of the ONNX operation. /// OutputVector reduce_sum(const Node& node); - } + } // namespace set_13 namespace set_1 { /// \brief Compute the log sum of the input tensor's elements along the diff --git a/ngraph/frontend/onnx_import/src/op/rnn.cpp b/ngraph/frontend/onnx_import/src/op/rnn.cpp index 5200974d6e7..f149b4b5fd3 100644 --- a/ngraph/frontend/onnx_import/src/op/rnn.cpp +++ b/ngraph/frontend/onnx_import/src/op/rnn.cpp @@ -38,7 +38,7 @@ namespace ngraph virtual ~RNNAttributes() = default; }; - } + } // namespace OutputVector rnn(const Node& node) { diff --git a/ngraph/frontend/onnx_import/src/op/slice.cpp b/ngraph/frontend/onnx_import/src/op/slice.cpp index eae53e4b7c3..2b9f5f0b520 100644 --- a/ngraph/frontend/onnx_import/src/op/slice.cpp +++ b/ngraph/frontend/onnx_import/src/op/slice.cpp @@ -155,7 +155,7 @@ namespace ngraph return std::make_shared(adjusted_indices, 0); } - } + } // namespace namespace set_10 { diff --git a/ngraph/frontend/onnx_import/src/op/softmax.cpp b/ngraph/frontend/onnx_import/src/op/softmax.cpp index 0548e72e674..24b0e9722ce 100644 --- a/ngraph/frontend/onnx_import/src/op/softmax.cpp +++ b/ngraph/frontend/onnx_import/src/op/softmax.cpp @@ -24,7 +24,7 @@ namespace ngraph const bool special_zero = false; return std::make_shared(result, data_shape, special_zero); } - } + } // namespace namespace op { @@ -68,7 +68,7 @@ namespace ngraph return {result}; } - } + } // namespace set_1 namespace set_7 { OutputVector softmax(const Node& node) @@ -109,7 +109,7 @@ namespace ngraph return {result}; } - } - } - } -} + } // namespace set_7 + } // namespace op + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/thresholded_relu.cpp b/ngraph/frontend/onnx_import/src/op/thresholded_relu.cpp index f1d9dd718b2..d0f489a8b0a 100644 --- a/ngraph/frontend/onnx_import/src/op/thresholded_relu.cpp +++ b/ngraph/frontend/onnx_import/src/op/thresholded_relu.cpp @@ -31,7 +31,7 @@ namespace ngraph return {std::make_shared(data, data_map)}; } - } // namespace set_1default_opset + } // namespace set_1 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/topk.cpp b/ngraph/frontend/onnx_import/src/op/topk.cpp index 606c1fa3d81..6f2f1b7f6ca 100644 --- a/ngraph/frontend/onnx_import/src/op/topk.cpp +++ b/ngraph/frontend/onnx_import/src/op/topk.cpp @@ -27,7 +27,7 @@ namespace return ngraph::onnx_import::reshape::interpret_as_scalar(k_node); } -} +} // namespace namespace ngraph { @@ -54,7 +54,7 @@ namespace ngraph return {top_k->output(0), top_k->output(1)}; } - } + } // namespace set_1 namespace set_10 { @@ -74,7 +74,7 @@ namespace ngraph return {top_k->output(0), top_k->output(1)}; } - } + } // namespace set_10 namespace set_11 { @@ -102,7 +102,7 @@ namespace ngraph return {top_k->output(0), top_k->output(1)}; } - } + } // namespace set_11 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/topk.hpp b/ngraph/frontend/onnx_import/src/op/topk.hpp index f57c512056a..14c86c78eed 100644 --- a/ngraph/frontend/onnx_import/src/op/topk.hpp +++ b/ngraph/frontend/onnx_import/src/op/topk.hpp @@ -21,7 +21,7 @@ namespace ngraph /// \return The vector containing Ngraph nodes producing output of ONNX TopK /// operation (both values and indices). OutputVector topk(const Node& node); - } + } // namespace set_1 /// \brief Performs TopK operation from ONNX version 1.5 /// diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index 419f1f99552..d4eccd61478 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -171,7 +171,7 @@ namespace ngraph } return std::end(map); } - } + } // namespace detail void OperatorsBridge::_register_operator(const std::string& name, std::int64_t version, diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index 3826bf1b080..b0378fae0f4 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -48,6 +48,6 @@ namespace ngraph } return std::make_shared(topk->output(1), element::i64); } - } - } -} + } // namespace utils + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp index b87337b74af..fadd83a083c 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp @@ -41,6 +41,6 @@ namespace ngraph std::int64_t m_axis; }; - } // namespace arg + } // namespace utils } // namespace onnx_import } // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/utils/recurrent.cpp b/ngraph/frontend/onnx_import/src/utils/recurrent.cpp index 37127554092..fc9409413ed 100644 --- a/ngraph/frontend/onnx_import/src/utils/recurrent.cpp +++ b/ngraph/frontend/onnx_import/src/utils/recurrent.cpp @@ -127,6 +127,6 @@ namespace ngraph m_direction = ngraph::as_enum(direction); } - } // recurrent - } // onnx_import -} // ngraph + } // namespace recurrent + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/utils/recurrent.hpp b/ngraph/frontend/onnx_import/src/utils/recurrent.hpp index 87aa6af5f35..42170249462 100644 --- a/ngraph/frontend/onnx_import/src/utils/recurrent.hpp +++ b/ngraph/frontend/onnx_import/src/utils/recurrent.hpp @@ -73,6 +73,6 @@ namespace ngraph std::vector m_activations_beta; }; - } // recurrent - } // onnx_import -} // ngraph + } // namespace recurrent + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/utils/tensor_external_data.cpp b/ngraph/frontend/onnx_import/src/utils/tensor_external_data.cpp index 98759d922cb..77b6db14beb 100644 --- a/ngraph/frontend/onnx_import/src/utils/tensor_external_data.cpp +++ b/ngraph/frontend/onnx_import/src/utils/tensor_external_data.cpp @@ -82,6 +82,6 @@ namespace ngraph s << ", sha1_digest: " << m_sha1_digest << ")"; return s.str(); } - } - } -} + } // namespace detail + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/utils/tensor_external_data.hpp b/ngraph/frontend/onnx_import/src/utils/tensor_external_data.hpp index a2fd166b060..6db383428ea 100644 --- a/ngraph/frontend/onnx_import/src/utils/tensor_external_data.hpp +++ b/ngraph/frontend/onnx_import/src/utils/tensor_external_data.hpp @@ -38,6 +38,6 @@ namespace ngraph int m_data_lenght = 0; int m_sha1_digest = 0; }; - } - } -} + } // namespace detail + } // namespace onnx_import +} // namespace ngraph diff --git a/ngraph/python/src/pyngraph/passes/manager.cpp b/ngraph/python/src/pyngraph/passes/manager.cpp index 1da2bee4df8..5545bdd8738 100644 --- a/ngraph/python/src/pyngraph/passes/manager.cpp +++ b/ngraph/python/src/pyngraph/passes/manager.cpp @@ -34,7 +34,7 @@ namespace return; } }; -} +} // namespace void regclass_pyngraph_passes_Manager(py::module m) { From 805d184357d3b82d0b49d5ef8e4ccf9886653335 Mon Sep 17 00:00:00 2001 From: Rafal Blaczkowski Date: Thu, 22 Apr 2021 07:58:11 +0200 Subject: [PATCH 41/78] Enable parallel execution open vino onnx ci (#5332) * Separate workdir for parallel runs * Use random * Get back old working configuration * Change label * Debug parameters * Change models dir to SHA approach * Fix WORKDIR names * Change mountig models dirs * Update model preproces script * Improvements * Isolate all private variables * Fix model dir path * Update model preproces * Update node label * Remove debug printlns --- .ci/openvino-onnx/Jenkinsfile | 79 +++++++++++-------- .../tests/test_onnx/model_zoo_preprocess.sh | 34 ++++---- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/.ci/openvino-onnx/Jenkinsfile b/.ci/openvino-onnx/Jenkinsfile index 63db471f90d..48529879ef1 100644 --- a/.ci/openvino-onnx/Jenkinsfile +++ b/.ci/openvino-onnx/Jenkinsfile @@ -3,11 +3,12 @@ DOCKER_CONTAINER_NAME= "openvino-onnx-ci-container" DOCKER_IMAGE_TAG = "openvino-onnx-ci-image" +ONNX_MODEL_ZOO_SHA = "d58213534f2a4d1c4b19ba62b3bb5f544353256e" BACKEND_CONFIGURATIONS = [ [ name: "Release", build_type: "Release", protobuf_lite : "OFF" ], [ name: "Debug", build_type: "Debug", protobuf_lite : "OFF" ], - [ name: "Rel+Lite", build_type: "Release", protobuf_lite : "ON" ], + [ name: "Rel_Lite", build_type: "Release", protobuf_lite : "ON" ], ] // workaround for aborting previous builds on PR update @@ -29,7 +30,7 @@ BACKEND_CONFIGURATIONS = [ } -def getGitPrInfo(String project) { +def getGitPrInfo(String project, String workdir) { def gitPrInfo = [ prAuthorEmail : "", commitAuthorEmail : "", @@ -37,7 +38,7 @@ def getGitPrInfo(String project) { commitSubject : "" ] try { - dir ("${WORKDIR}/${project}") { + dir ("${workdir}/${project}") { gitPrInfo.prAuthorEmail = sh (script: 'git log -1 --pretty="format:%ae" ', returnStdout: true).trim() gitPrInfo.commitAuthorEmail = sh (script: 'git log -1 --pretty="format:%ce" ', returnStdout: true).trim() gitPrInfo.commitSubject = sh (script: 'git log -1 --pretty="format:%H" ', returnStdout: true).trim() @@ -70,8 +71,8 @@ def notifyByEmail(def gitPrInfo) { } } -def gitSubmoduleUpdate(String repository_name) { - dir ("${WORKDIR}/${repository_name}") { +def gitSubmoduleUpdate(String repository_name, String workdir) { + dir ("${workdir}/${repository_name}") { sh label: "Init ${repository_name} submodules", script: """ @@ -83,23 +84,32 @@ def gitSubmoduleUpdate(String repository_name) { } } -def prepare_repository() { - dir("${WORKDIR}") { +def prepare_repository(String workdir) { + dir("${workdir}") { + println "Preparing repository in directory: ${workdir}" checkout scm - gitSubmoduleUpdate(PROJECT_NAME) + gitSubmoduleUpdate(PROJECT_NAME, workdir) } } def updateModels() { sh """ - ./ngraph/python/tests/test_onnx/model_zoo_preprocess.sh -d ${HOME}/ONNX_CI/data -o + ./ngraph/python/tests/test_onnx/model_zoo_preprocess.sh -d ${HOME}/ONNX_CI/models_data -o -s ${ONNX_MODEL_ZOO_SHA} """ } -def buildDockerImage(Map configuration) { +def get_docker_container_name(Map configuration){ + println "RUN get_docker_container_name for ${configuration.name}" + String docker_container_name = "${DOCKER_CONTAINER_NAME}_${BUILD_NUMBER}_${env.CHANGE_ID}_${configuration.name}" + return docker_container_name +} + +def buildDockerImage(Map configuration, String workdir) { + String docker_image_tag = "${DOCKER_IMAGE_TAG}_${BUILD_NUMBER}_${env.CHANGE_ID}_${configuration.name}".toLowerCase() + println "docker_image_tag: ${docker_image_tag}" updateModels() sh """ - docker build --tag=${DOCKER_IMAGE_TAG} \ + docker build --tag=${docker_image_tag} \ --build-arg BUILD_TYPE=${configuration.build_type} \ --build-arg PROTOBUF_LITE=${configuration.protobuf_lite} \ --file=.ci/openvino-onnx/Dockerfile \ @@ -108,20 +118,26 @@ def buildDockerImage(Map configuration) { """ } -def runTests(Map configuration) { +def runTests(Map configuration, String workdir) { + println "Run tests for ${configuration.name}" + String docker_image_tag = "${DOCKER_IMAGE_TAG}_${BUILD_NUMBER}_${env.CHANGE_ID}_${configuration.name}".toLowerCase() + + String docker_container_name = get_docker_container_name(configuration) + // Run only basic unit tests in Debug configuration if (configuration.build_type == "Debug") { sh """ - docker run --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_TAG} + docker run --name ${docker_container_name} ${docker_image_tag} """ } // Run unit-tests AND large model tests by default else { sh """ - docker run --name ${DOCKER_CONTAINER_NAME} \ - --volume ${HOME}/ONNX_CI/data/model_zoo:/root/.onnx/model_zoo \ - ${DOCKER_IMAGE_TAG} /bin/bash -c "tox && tox -e zoo_models" + docker run --name ${docker_container_name} \ + --volume ${HOME}/ONNX_CI/models_data/model_zoo/onnx_model_zoo_${ONNX_MODEL_ZOO_SHA}:/root/.onnx/model_zoo/onnx_model_zoo \ + --volume ${HOME}/ONNX_CI/data/model_zoo/MSFT:/root/.onnx/model_zoo/MSFT \ + ${docker_image_tag} /bin/bash -c "tox && tox -e zoo_models" """ } } @@ -130,7 +146,6 @@ def getConfigurationsMap() { def configurationsMap = [:] for (backend in BACKEND_CONFIGURATIONS) { def configuration = backend.clone() - configuration.name = "${configuration.name}" configurationsMap[configuration.name] = { stage(configuration.name) { CONFIGURATION_WORKFLOW(configuration) } } @@ -139,29 +154,22 @@ def getConfigurationsMap() { } CONFIGURATION_WORKFLOW = { configuration -> - node("OpenVino") { + node("OpenVINO") { try { PROJECT_NAME = "openvino" - WORKDIR = "${HOME}/workspace/${BUILD_NUMBER}" + String workdir = "${HOME}/workspace/${BUILD_NUMBER}_${env.CHANGE_ID}_${configuration.name}" stage("Clone repository") { - stopPreviousRunningBuilds() - try { - prepare_repository() - } - catch(e){ - sleep(time: 30, unit: "SECONDS") - prepare_repository() - } + prepare_repository(workdir) } stage("Prepare Docker environment") { - dir("${WORKDIR}") { - buildDockerImage(configuration) + dir("${workdir}") { + buildDockerImage(configuration, workdir) } } stage("Run tests") { - timeout(time: 20, unit: 'MINUTES') { - runTests(configuration) + timeout(time: 60, unit: 'MINUTES') { + runTests(configuration, workdir) } } } @@ -172,15 +180,15 @@ CONFIGURATION_WORKFLOW = { configuration -> } else { currentBuild.result = "FAILURE" } - gitPrInfo = getGitPrInfo(PROJECT_NAME) + def gitPrInfo = getGitPrInfo(PROJECT_NAME, workdir) notifyByEmail(gitPrInfo) } finally { stage("Cleanup") { deleteDir() + String docker_container_name = get_docker_container_name(configuration) sh """ - docker rm -f ${DOCKER_CONTAINER_NAME} - docker image prune -f + docker rm -f ${docker_container_name} """ } } @@ -191,11 +199,12 @@ pipeline { agent none options { skipDefaultCheckout true - timeout(activity: true, time: 60, unit: 'MINUTES') + timeout(activity: true, time: 120, unit: 'MINUTES') } stages { stage('Parallel CI') { steps { + stopPreviousRunningBuilds() script { parallelStagesMap = getConfigurationsMap() parallel parallelStagesMap diff --git a/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh b/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh index 0595024e1ab..5c8496bb359 100755 --- a/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh +++ b/ngraph/python/tests/test_onnx/model_zoo_preprocess.sh @@ -5,7 +5,7 @@ set -e -# provide ONNX Model Zoo commit hash ID to update: +# default ONNX Model Zoo commit hash ID: ONNX_SHA=d58213534f2a4d1c4b19ba62b3bb5f544353256e MODELS_DIR="$HOME/.onnx/model_zoo" @@ -20,11 +20,12 @@ function print_help { echo " -d set location of the models (for onnx model ZOO and MSFT models)" printf " By default the models location is: %s\n" "$HOME/.onnx/model_zoo" echo " -o update Onnx Model Zoo models" + echo " -s Onnx Model Zoo commit SHA" echo " -m update MSFT models" echo " -f force update of a chosen model" } -while getopts ":homfd:" opt; do +while getopts "homfd:s:" opt; do case ${opt} in h ) print_help @@ -41,6 +42,9 @@ while getopts ":homfd:" opt; do o ) ENABLE_ONNX_MODELS_ZOO=true ;; + s ) + ONNX_SHA="$OPTARG" + ;; m ) ENABLE_MSFT_MODELS=true ;; @@ -52,7 +56,7 @@ done shift $((OPTIND -1)) MODEL_ZOO_DIR="$MODELS_DIR/model_zoo" -ONNX_MODELS_DIR="$MODEL_ZOO_DIR/onnx_model_zoo" +ONNX_MODELS_DIR="$MODEL_ZOO_DIR/onnx_model_zoo_$ONNX_SHA" MSFT_MODELS_DIR="$MODEL_ZOO_DIR/MSFT" function pull_and_postprocess_onnx_model_zoo() { @@ -75,12 +79,23 @@ function pull_and_postprocess_onnx_model_zoo() { mkdir -p test_data_set_0 mv *.pb test_data_set_0/ - # Save SHA of successfully post processed repository - git rev-parse HEAD > "$MODEL_ZOO_DIR/onnx_sha" + rm -f $MODEL_ZOO_DIR/executing_$ONNX_SHA } function update_onnx_models() { + if test `find $MODEL_ZOO_DIR/executing_$ONNX_SHA -mmin +60 2>/dev/null`;then + rm -rf $ONNX_MODELS_DIR + rm -f $MODEL_ZOO_DIR/executing_$ONNX_SHA + fi + + while [[ -f $MODEL_ZOO_DIR/executing_$ONNX_SHA ]]; + do + echo "Onnx Models update are currently executing - sleeping 5 minutes" + sleep 300 + done + if [[ ! -d $ONNX_MODELS_DIR ]] ; then + touch $MODEL_ZOO_DIR/executing_$ONNX_SHA echo "The ONNX Model Zoo repository doesn't exist on your filesystem then will be cloned" git clone https://github.com/onnx/models.git "$ONNX_MODELS_DIR" cd "$ONNX_MODELS_DIR" @@ -96,15 +111,6 @@ function update_onnx_models() { git clone https://github.com/onnx/models.git "$ONNX_MODELS_DIR" fi fi - - cd "$ONNX_MODELS_DIR" - export CURRENT_ONNX_MODELS_SHA=`head -n1 "$MODEL_ZOO_DIR/onnx_sha" 2> /dev/null 2>&1` - if [[ $ONNX_SHA = $CURRENT_ONNX_MODELS_SHA ]] ; then - echo "ONNX Model Zoo repository is in the right state" - else - printf "Current onnx model zoo state is: %s \nChecking out to expected onnx model zoo state: %s \n\n" "$CURRENT_ONNX_MODELS_SHA" "$ONNX_SHA" - pull_and_postprocess_onnx_model_zoo - fi } function update_msft_models() { From 22a3d81a59c95707c3212b65bd2b42f84576e6e8 Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Thu, 22 Apr 2021 09:09:52 +0300 Subject: [PATCH 42/78] install requirements file for common python (#5325) --- inference-engine/ie_bridges/python/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inference-engine/ie_bridges/python/CMakeLists.txt b/inference-engine/ie_bridges/python/CMakeLists.txt index 5167b33a5ec..24d16ca77e0 100644 --- a/inference-engine/ie_bridges/python/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/CMakeLists.txt @@ -82,6 +82,10 @@ install(FILES requirements.txt DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION} COMPONENT ${PYTHON_VERSION}) +install(FILES requirements.txt + DESTINATION ${PYTHON_BRIDGE_CPACK_PATH} + COMPONENT ${PYTHON_VERSION}) + install(PROGRAMS src/openvino/__init__.py DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino COMPONENT ${PYTHON_VERSION}) From 6770f7995ecbc5bed7a2192ff79bea4600e36f21 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Thu, 22 Apr 2021 09:33:16 +0300 Subject: [PATCH 43/78] [IE Python] fix BlobBuffer dtype for FP16 precision (#5155) * Fix deepcopy * Add test * Revert dtype for BF16 precision * Fix test * Add exception for BF16 * Update BlobBuffer dtype for FP16 precision * Revert exception for BF16 * Update test --- .../src/openvino/inference_engine/ie_api.pyx | 12 +++++++-- .../ie_bridges/python/tests/test_Blob.py | 27 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx index a2ce9b629e9..7c7457e3e98 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx @@ -1533,5 +1533,13 @@ cdef class BlobBuffer: return precision_to_format[name].encode() - def to_numpy(self): - return np.asarray(self) + def to_numpy(self): + precision = deref(self.ptr).getTensorDesc().getPrecision() + name = bytes(precision.name()).decode() + if name == "FP16": + return np.asarray(self).view(dtype=np.float16) + else: + return np.asarray(self) + + + diff --git a/inference-engine/ie_bridges/python/tests/test_Blob.py b/inference-engine/ie_bridges/python/tests/test_Blob.py index 1f0d00519ab..ae50c7221a3 100644 --- a/inference-engine/ie_bridges/python/tests/test_Blob.py +++ b/inference-engine/ie_bridges/python/tests/test_Blob.py @@ -4,8 +4,9 @@ import pytest import numpy as np +import os -from openvino.inference_engine import TensorDesc, Blob +from openvino.inference_engine import TensorDesc, Blob, IECore from conftest import image_path @@ -96,3 +97,27 @@ def test_incompatible_input_precision(): Blob(tensor_desc, image) assert "Data type float64 of provided numpy array " \ "doesn't match to TensorDesc precision FP32" in str(e.value) + + +#issue 49903 +@pytest.mark.skip(reason="Test will enable when CPU fix will be merge") +@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") +def test_buffer_values_after_add_outputs(device): + path_to_repo = os.environ["MODELS_PATH"] + test_net_xml_fp16 = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.xml') + test_net_bin_fp16 = os.path.join(path_to_repo, "models", "test_model", 'test_model_fp16.bin') + ie_core = IECore() + if device == "CPU": + if ie_core.get_metric(device, "FULL_DEVICE_NAME") == "arm_compute::NEON": + pytest.skip("Can't run on ARM plugin due-to ngraph") + net = ie_core.read_network(model=test_net_xml_fp16, weights=test_net_bin_fp16) + output_layer = "22" + net.add_outputs(output_layer) + exec_net = ie_core.load_network(net, device) + feed_dict = { + 'data': np.random.normal(0, 1, (1, 3, 32, 32)).astype(np.float32) + } + result = exec_net.infer(feed_dict) + assert np.all(abs(result[output_layer])<30) + assert result[output_layer].dtype == np.float16 + \ No newline at end of file From aec12d6dff0bedf9e62839b674f5c47c3c25cf57 Mon Sep 17 00:00:00 2001 From: Anton Pankratv Date: Thu, 22 Apr 2021 09:44:44 +0300 Subject: [PATCH 44/78] Fixed missed linking references for outer plugins (#5341) --- .../src}/low_precision_transformations/layer_transformation.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename inference-engine/tests/functional/plugin/{cpu/shared_tests_instances => shared/src}/low_precision_transformations/layer_transformation.cpp (100%) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/layer_transformation.cpp similarity index 100% rename from inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp rename to inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/layer_transformation.cpp From b3ac14c8d45e4abf4adce56374c23bf0a548a9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20W=C3=BCrtz?= Date: Thu, 22 Apr 2021 08:46:40 +0200 Subject: [PATCH 45/78] Fix openvino build without OpenCV. (#5154) * Fix openvino build without OpenCV. * Don't call find_package in case of ENABLE_OPENCV=OFF --- docs/snippets/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/snippets/CMakeLists.txt b/docs/snippets/CMakeLists.txt index d033653e9de..1d2a20eea0a 100644 --- a/docs/snippets/CMakeLists.txt +++ b/docs/snippets/CMakeLists.txt @@ -15,7 +15,12 @@ if(NOT CLDNN__IOCL_ICD_INCDIRS OR TRUE) endif() # remove OpenCV related sources -find_package(OpenCV QUIET) +if (ENABLE_OPENCV) + find_package(OpenCV QUIET) +else() + set(OpenCV_FOUND FALSE) +endif() + if(NOT OpenCV_FOUND) list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/dldt_optimization_guide5.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ShapeInference.cpp") From 82e2b4188b7971549ca3b462cb0b7e3985ddce78 Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Thu, 22 Apr 2021 11:03:49 +0300 Subject: [PATCH 46/78] feat: add checks for Py samples (#5339) --- .github/workflows/py_checks.yml | 33 +++++++++++++++++++ .../classification_sample_async.py | 2 +- .../hello_classification.py | 2 +- .../hello_query_device/hello_query_device.py | 2 +- .../hello_reshape_ssd/hello_reshape_ssd.py | 2 +- .../ngraph_function_creation_sample.py | 13 ++++---- .../object_detection_sample_ssd.py | 2 +- .../python/sample/requirements_dev.txt | 26 +++++++++++++++ .../ie_bridges/python/sample/setup.cfg | 12 +++++++ .../style_transfer_sample.py | 2 +- 10 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/py_checks.yml create mode 100644 inference-engine/ie_bridges/python/sample/requirements_dev.txt create mode 100644 inference-engine/ie_bridges/python/sample/setup.cfg diff --git a/.github/workflows/py_checks.yml b/.github/workflows/py_checks.yml new file mode 100644 index 00000000000..9b7c4a7a94b --- /dev/null +++ b/.github/workflows/py_checks.yml @@ -0,0 +1,33 @@ +name: IE Python Checks +# TODO: add for IE API, wheels +on: + workflow_dispatch: + push: + paths: + - 'inference-engine/ie_bridges/python/sample/**' + pull_request: + paths: + - 'inference-engine/ie_bridges/python/sample/**' +jobs: + linters: + runs-on: ubuntu-18.04 + steps: + - name: Code checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' + - name: Install dependencies + run: python -m pip install -r inference-engine/ie_bridges/python/sample/requirements_dev.txt + - name: Run Flake + run: python -m flake8 ./ --config=setup.cfg --show-source + working-directory: inference-engine/ie_bridges/python/sample + - name: Run MyPy + run: python -m mypy ./ --config-file ./setup.cfg --show-error-context --show-column-numbers --pretty + working-directory: inference-engine/ie_bridges/python/sample + - name: Run Bandit + run: python -m bandit -r ./ -f screen + working-directory: inference-engine/ie_bridges/python/sample \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py b/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py index b592856ab1a..099997045da 100755 --- a/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py +++ b/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore, StatusCode def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py b/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py index 03933310efa..0c74f281379 100755 --- a/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py +++ b/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py b/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py index 3fbd1d045f2..c478d6d6b71 100755 --- a/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py +++ b/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py @@ -9,7 +9,7 @@ from openvino.inference_engine import IECore def param_to_string(metric) -> str: - '''Convert a list / tuple of parameters returned from IE to a string''' + """Convert a list / tuple of parameters returned from IE to a string""" if isinstance(metric, (list, tuple)): return ', '.join([str(x) for x in metric]) else: diff --git a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py index b6053ba4245..6b5bdfc09c1 100755 --- a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py +++ b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py b/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py index fb3378e60ce..86ab98b3053 100755 --- a/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py +++ b/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py @@ -6,6 +6,7 @@ import argparse import logging as log import struct as st import sys +import typing from functools import reduce import cv2 @@ -15,7 +16,7 @@ from openvino.inference_engine import IECore, IENetwork def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') @@ -33,7 +34,7 @@ def parse_args() -> argparse.Namespace: def read_image(image_path: str) -> np.ndarray: - '''Read and return an image as grayscale (one channel)''' + """Read and return an image as grayscale (one channel)""" image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) # Try to open image as ubyte @@ -54,9 +55,9 @@ def read_image(image_path: str) -> np.ndarray: def create_ngraph_function(args: argparse.Namespace) -> ngraph.impl.Function: - '''Create a network on the fly from the source code using ngraph''' + """Create a network on the fly from the source code using ngraph""" - def shape_and_length(shape: list) -> (list, int): + def shape_and_length(shape: list) -> typing.Tuple[list, int]: length = reduce(lambda x, y: x * y, shape) return shape, length @@ -204,8 +205,8 @@ def main(): image = read_image(args.input[i]) light_pixel_count = np.count_nonzero(image > 127) - darK_pixel_count = np.count_nonzero(image < 127) - is_light_image = (light_pixel_count - darK_pixel_count) > 0 + dark_pixel_count = np.count_nonzero(image < 127) + is_light_image = (light_pixel_count - dark_pixel_count) > 0 if is_light_image: log.warning(f'Image {args.input[i]} is inverted to white over black') diff --git a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py index 73c7e883193..ab7ec523b39 100755 --- a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py +++ b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/requirements_dev.txt b/inference-engine/ie_bridges/python/sample/requirements_dev.txt new file mode 100644 index 00000000000..e57ed73f1e1 --- /dev/null +++ b/inference-engine/ie_bridges/python/sample/requirements_dev.txt @@ -0,0 +1,26 @@ +bandit +flake8 +flake8-annotations-complexity +flake8-bandit +flake8-broken-line +flake8-bugbear +flake8-class-attributes-order +flake8-comprehensions +flake8-debugger +flake8-eradicate +flake8-executable +flake8-expression-complexity +flake8-print +flake8-pytest-style +flake8-rst-docstrings +flake8-string-format +flake8-variables-names +flake8_builtins +flake8_coding +flake8_commas +flake8_pep3101 +flake8_quotes +import-order +mypy +Pep8-naming +radon \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/setup.cfg b/inference-engine/ie_bridges/python/sample/setup.cfg new file mode 100644 index 00000000000..da434c2a303 --- /dev/null +++ b/inference-engine/ie_bridges/python/sample/setup.cfg @@ -0,0 +1,12 @@ +[flake8] +max-line-length = 120 +max-parameters-amount = 8 +show_source = True +docstring-convention = google +enable-extensions=G + +[pydocstyle] +convention = google + +[mypy] +ignore_missing_imports = True \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py b/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py index 03311a74de7..736fa288a85 100755 --- a/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py +++ b/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') From 3e8bc2db697e74427ff0e6d8801ed9d830917c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Thu, 22 Apr 2021 11:59:29 +0200 Subject: [PATCH 47/78] Handle f32/bf16 conversion in UT (#5330) --- ngraph/test/backend/convert.in.cpp | 72 +++++++------------ ngraph/test/runtime/ie/unit_test.manifest | 4 -- .../runtime/interpreter/evaluates_map.cpp | 3 + .../runtime/interpreter/unit_test.manifest | 2 - ngraph/test/util/engine/ie_engines.cpp | 28 +++++++- 5 files changed, 55 insertions(+), 54 deletions(-) diff --git a/ngraph/test/backend/convert.in.cpp b/ngraph/test/backend/convert.in.cpp index 57892e37f91..ab9f33c6743 100644 --- a/ngraph/test/backend/convert.in.cpp +++ b/ngraph/test/backend/convert.in.cpp @@ -9,7 +9,9 @@ #include "runtime/backend.hpp" #include "util/all_close.hpp" #include "util/all_close_f.hpp" +#include "util/engine/test_engines.hpp" #include "util/ndarray.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" #include "util/test_tools.hpp" @@ -18,6 +20,8 @@ using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); + NGRAPH_TEST(${BACKEND_NAME}, convert_int32_float32) { Shape shape{2, 2}; @@ -104,61 +108,35 @@ NGRAPH_TEST(${BACKEND_NAME}, convert_float32_bool) NGRAPH_TEST(${BACKEND_NAME}, convert_float32_bf16) { - Shape shape_a{1, 1, 3, 5}; - - // input data - vector a_data = { + const vector a_data = { 0.5f, 1.5f, 0.5f, 2.5f, 1.5f, 0.5f, 3.5f, 2.5f, 0.5f, 0.5f, 2.5f, 0.5f, 0.5f, 0.5f, 1.5f}; - auto A = make_shared(element::f32, shape_a); - auto convert = make_shared(A, element::bf16); - auto f = make_shared(NodeVector{convert}, ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, a_data); - auto result = backend->create_tensor(element::bf16, shape_a); - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{ - 0.5, 1.5, 0.5, 2.5, 1.5, 0.5, 3.5, 2.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 1.5}), - read_vector(result)); + const auto A = make_shared(element::f32, Shape{1, 1, 3, 5}); + const auto convert = make_shared(A, element::bf16); + const auto f = make_shared(NodeVector{convert}, ParameterVector{A}); + + auto test_case = test::TestCase(f); + test_case.add_input(a_data); + test_case.add_expected_output( + std::vector(std::begin(a_data), std::end(a_data))); + + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, convert_bf16_float32) { - Shape shape_a{1, 1, 3, 5}; - - // input data - vector a_data = { + const vector a_data = { 0.5, 1.5, 0.5, 2.5, 1.5, 0.5, 3.5, 2.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 1.5}; - auto A = make_shared(element::bf16, shape_a); - auto convert = make_shared(A, element::f32); - auto f = make_shared(NodeVector{convert}, ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - // Create some tensors for input/output - auto a = backend->create_tensor(element::bf16, shape_a); - copy_data(a, a_data); - auto result = backend->create_tensor(element::f32, shape_a); - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{0.5f, - 1.5f, - 0.5f, - 2.5f, - 1.5f, - 0.5f, - 3.5f, - 2.5f, - 0.5f, - 0.5f, - 2.5f, - 0.5f, - 0.5f, - 0.5f, - 1.5f}), - read_vector(result)); + const auto A = make_shared(element::bf16, Shape{1, 1, 3, 5}); + const auto convert = make_shared(A, element::f32); + const auto f = make_shared(NodeVector{convert}, ParameterVector{A}); + + auto test_case = test::TestCase(f); + test_case.add_input(a_data); + test_case.add_expected_output(std::vector(std::begin(a_data), std::end(a_data))); + + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, convert_fp16_float32) diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index ea2955000d6..55eb04de1fc 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -565,10 +565,6 @@ quantize_clamp_int32 max_3d_to_scalar_double argmin_trivial_in_double -# Incorrect precision bf16! -convert_float32_bf16 -convert_bf16_float32 - # [nGraph upgrade pass] Unable to convert Softmax:0 to Softmax:1 with zero or more than one axis. softmax_dynamic_axes softmax_all diff --git a/ngraph/test/runtime/interpreter/evaluates_map.cpp b/ngraph/test/runtime/interpreter/evaluates_map.cpp index 94a47220589..8ab43d6e8ef 100644 --- a/ngraph/test/runtime/interpreter/evaluates_map.cpp +++ b/ngraph/test/runtime/interpreter/evaluates_map.cpp @@ -1545,6 +1545,9 @@ namespace case element::Type_t::f64: convert_v0::evaluate(op, outputs, inputs); break; + case element::Type_t::bf16: + convert_v0::evaluate(op, outputs, inputs); + break; default: return false; } return true; diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index c04ba98df6b..7d7d209c50d 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -1,6 +1,4 @@ fake_quantize_pdpd -convert_float32_bf16 -convert_bf16_float32 INTERPRETER.onnx_model_quant_conv_linear INTERPRETER.onnx_top_k_opset_10 diff --git a/ngraph/test/util/engine/ie_engines.cpp b/ngraph/test/util/engine/ie_engines.cpp index a7af958304f..8e1a8f4e75e 100644 --- a/ngraph/test/util/engine/ie_engines.cpp +++ b/ngraph/test/util/engine/ie_engines.cpp @@ -59,6 +59,29 @@ namespace return ngraph::test::all_close(test_results.first, test_results.second); } + template + typename std::enable_if::value, testing::AssertionResult>::type + compare_blobs(InferenceEngine::MemoryBlob::CPtr computed, + InferenceEngine::MemoryBlob::CPtr expected, + const size_t tolerance_bits) + { + const auto test_results = extract_test_results(computed, expected); + + NGRAPH_CHECK(test_results.first.size() == test_results.second.size(), + "Number of expected and computed results don't match"); + + std::vector expected_double(test_results.first.size()); + std::vector result_double(test_results.second.size()); + + for (size_t i = 0; i < test_results.first.size(); ++i) + { + expected_double[i] = static_cast(test_results.first[i]); + result_double[i] = static_cast(test_results.second[i]); + } + + return ngraph::test::all_close_f(expected_double, result_double, tolerance_bits); + } + /// Compares two blobs elementwise inline testing::AssertionResult compare_blobs(InferenceEngine::MemoryBlob::CPtr computed, InferenceEngine::MemoryBlob::CPtr expected, @@ -107,7 +130,10 @@ namespace case InferenceEngine::Precision::BOOL: return compare_blobs(computed, expected, tolerance_bits); break; - default: IE_THROW() << "Not implemented yet"; + case InferenceEngine::Precision::BF16: + return compare_blobs(computed, expected, tolerance_bits); + break; + default: THROW_IE_EXCEPTION << "Not implemented yet"; } } }; // namespace From 78cf72819b4b2c0a020e858acc1fe280f3691890 Mon Sep 17 00:00:00 2001 From: Elizaveta Lobanova Date: Thu, 22 Apr 2021 13:27:21 +0300 Subject: [PATCH 48/78] [GNA] fix pwl for Sigmoid quantised with signed range (#5271) --- .../src/gna_plugin/backend/make_pwl.cpp | 8 +- .../skip_tests_config.cpp | 1 + .../subgraph_tests/activation_fq.cpp | 83 +++++++++++++++++++ .../include/subgraph_tests/activation_fq.hpp | 15 ++++ .../subgraph/activation_fq.hpp | 60 ++++++++++++++ .../src/subgraph/activation_fq.cpp | 82 ++++++++++++++++++ 6 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/activation_fq.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/subgraph_tests/activation_fq.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/activation_fq.hpp create mode 100644 inference-engine/tests/functional/shared_test_classes/src/subgraph/activation_fq.cpp diff --git a/inference-engine/src/gna_plugin/backend/make_pwl.cpp b/inference-engine/src/gna_plugin/backend/make_pwl.cpp index f4b71c0f0c0..597ab304200 100644 --- a/inference-engine/src/gna_plugin/backend/make_pwl.cpp +++ b/inference-engine/src/gna_plugin/backend/make_pwl.cpp @@ -37,18 +37,18 @@ void make_gna_pwl(const DnnActivation fun, gna_pwl[0].xBase = static_cast (INT32_MIN & XBASEMASK); // zero out the 2 lsb if (fun == kActSigmoid) { gnalog() << "=========================== Sigmoid Segments ===========================\n"; - auto minVal = fun.fqParams.set ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : 0; + auto minVal = (fun.fqParams.set && *fun.fqParams.input_low > 0) ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : 0; gna_pwl[0].yBase = gna_pwl[1].yBase = minVal; gna_pwl[1].xBase = (static_cast (in_scale * (-pwl[0].b / pwl[0].m))) & XBASEMASK; } else if (fun == kActTanh) { gnalog() << "=========================== Tanh Segments ===========================\n"; - auto minVal = fun.fqParams.set ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : + auto minVal = (fun.fqParams.set && *fun.fqParams.input_low > -1) ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : static_cast(-1.0 * out_scale); gna_pwl[0].yBase = gna_pwl[1].yBase = minVal; gna_pwl[1].xBase = (static_cast (in_scale * (-1.0 - pwl[0].b) / pwl[0].m)) & XBASEMASK; } else { gnalog() << "=========================== SoftSign Segments ===========================\n"; - auto minVal = fun.fqParams.set ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : + auto minVal = (fun.fqParams.set && *fun.fqParams.input_low > -1) ? FLOAT_TO_INT16(*fun.fqParams.input_low * out_scale) : static_cast(-1.0 * out_scale); gna_pwl[0].yBase = gna_pwl[1].yBase = minVal; gna_pwl[1].xBase = (static_cast (in_scale * (-1.0 - pwl[0].b) / pwl[0].m)) & XBASEMASK; @@ -82,7 +82,7 @@ void make_gna_pwl(const DnnActivation fun, << "\n"; } // insert extra segment for xvalues > u_bound - auto maxVal = fun.fqParams.set ? *fun.fqParams.input_high : 1.0; + auto maxVal = (fun.fqParams.set && *fun.fqParams.input_high <= 1) ? *fun.fqParams.input_high : 1.0; gna_pwl[n_segments - 1].xBase = ((uint32_t) (in_scale * (1.0 - pwl[pwl_size - 2].b) / pwl[pwl_size - 2].m)) & XBASEMASK; gna_pwl[n_segments - 1].yBase = FLOAT_TO_INT16(maxVal * out_scale); diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp index 989ee090d87..a4f7353ba15 100644 --- a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp @@ -34,6 +34,7 @@ std::vector disabledTestPatterns() { ".*Behavior.*CallbackThrowException.*", // TODO: FIX BUG 32210 R"(.*ActivationLayerTest.CompareWithRefs/(Sigmoid|Tanh|Exp|Log).*)", + R"(.*ActivationFQSubgraph.*activation=(Exp|Log).*)", // TODO: Issue 32542 R"(.*(EltwiseLayerTest).*eltwiseOpType=(Sum|Sub).*opType=SCALAR.*)", R"(.*(EltwiseLayerTest).*eltwiseOpType=Prod.*secondaryInputType=PARAMETER.*opType=SCALAR.*)", diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/activation_fq.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/activation_fq.cpp new file mode 100644 index 00000000000..223b243768b --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/activation_fq.cpp @@ -0,0 +1,83 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include + +#include "subgraph_tests/activation_fq.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace SubgraphTestsDefinitions; + +namespace { + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::FP32 +}; + + +using ConfigType = std::map; +const ConfigType configFP32 = { + {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, +}; + +const ConfigType configSWExact = { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_COMPACT_MODE", "NO"} +}; + +const std::vector> gnaQuantModes = { + {"sw_fp32", configFP32}, + {"sw_exact", configSWExact} +}; + +const std::vector> inputShapes = { + {1, 250}, + {1, 640}, + {1, 1024} +}; + +const std::vector level = {65535}; +const std::vector> inputParams = { + {-1, 1, 0.01}, + {-5, 5, 1}, + {-100, 100, 1}, + {-16, 16, 1} +}; + +const std::vector>> constShapes = { + {{1}} +}; + +const auto fqParams = ::testing::Combine( + ::testing::Values(level), + ::testing::ValuesIn(constShapes), + ::testing::ValuesIn(inputParams) +); + +const std::vector activations = { + ngraph::helpers::ActivationTypes::Sigmoid, + ngraph::helpers::ActivationTypes::Tanh, + ngraph::helpers::ActivationTypes::Relu, + ngraph::helpers::ActivationTypes::Log, + ngraph::helpers::ActivationTypes::Abs, + ngraph::helpers::ActivationTypes::Sign, + ngraph::helpers::ActivationTypes::Exp +}; + +INSTANTIATE_TEST_CASE_P(smoke_ActivationFQSubgraph, ActivationFakeQuantizeSubgraphTest, + ::testing::Combine( + fqParams, + ::testing::ValuesIn(activations), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(inputShapes), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(gnaQuantModes)), + ActivationFakeQuantizeSubgraphTest::getTestCaseName); +} // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/activation_fq.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/activation_fq.hpp new file mode 100644 index 00000000000..77357811547 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/activation_fq.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/subgraph/activation_fq.hpp" + +namespace SubgraphTestsDefinitions { + +TEST_P(ActivationFakeQuantizeSubgraphTest, CompareWithRefs) { + Run(); +} + +} // namespace SubgraphTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/activation_fq.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/activation_fq.hpp new file mode 100644 index 00000000000..6fabc5dfbf6 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/activation_fq.hpp @@ -0,0 +1,60 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "shared_test_classes/base/layer_test_utils.hpp" + +namespace SubgraphTestsDefinitions { +static std::map activationNames = { + {ngraph::helpers::ActivationTypes::Sigmoid, "Sigmoid"}, + {ngraph::helpers::ActivationTypes::Tanh, "Tanh"}, + {ngraph::helpers::ActivationTypes::Relu, "Relu"}, + {ngraph::helpers::ActivationTypes::Exp, "Exp"}, + {ngraph::helpers::ActivationTypes::Log, "Log"}, + {ngraph::helpers::ActivationTypes::Sign, "Sign"}, + {ngraph::helpers::ActivationTypes::Abs, "Abs"}, +}; + +typedef std::tuple< + std::vector, // levels + std::vector>, // const inputs shape + std::vector // input generator data: low, high, resolution +> fqSpecificParams; + +typedef std::tuple< + fqSpecificParams, + ngraph::helpers::ActivationTypes, + InferenceEngine::Precision, // Net precision + InferenceEngine::Precision, // Input precision + InferenceEngine::Precision, // Output precision + InferenceEngine::Layout, // Input layout + InferenceEngine::Layout, // Output layout + InferenceEngine::SizeVector, // Input shapes + LayerTestsUtils::TargetDevice, // Device name + std::pair> // Additional backend configuration and alis name to it +> fqSubgraphTestParamsSet; + +class ActivationFakeQuantizeSubgraphTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; + +protected: + float inputDataMin = 0.0; + float inputDataMax = 10.0; + float inputDataResolution = 1.0; + int32_t seed = 1; +}; +} // namespace SubgraphTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/subgraph/activation_fq.cpp b/inference-engine/tests/functional/shared_test_classes/src/subgraph/activation_fq.cpp new file mode 100644 index 00000000000..6138604af78 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/src/subgraph/activation_fq.cpp @@ -0,0 +1,82 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "shared_test_classes/subgraph/activation_fq.hpp" + +namespace SubgraphTestsDefinitions { + + std::string ActivationFakeQuantizeSubgraphTest::getTestCaseName(testing::TestParamInfo obj) { + fqSpecificParams fqParams; + ngraph::helpers::ActivationTypes activationType; + InferenceEngine::Precision netPrecision; + InferenceEngine::Precision inPrc, outPrc; + InferenceEngine::Layout inLayout, outLayout; + InferenceEngine::SizeVector inputShapes; + std::string targetDevice; + std::pair> config; + std::tie(fqParams, activationType, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShapes, targetDevice, config) = obj.param; + std::vector levels; + std::vector> constShape; + std::vector inputParams; + std::tie(levels, constShape, inputParams) = fqParams; + + std::ostringstream result; + result << "InputShape=" << CommonTestUtils::vec2str(inputShapes) << "_"; + result << "CS=" << CommonTestUtils::vec2str(constShape) << "_"; + result << "LEVELS=" << CommonTestUtils::vec2str(levels) << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "inPRC=" << inPrc.name() << "_"; + result << "outPRC=" << outPrc.name() << "_"; + result << "inL=" << inLayout << "_"; + result << "outL=" << outLayout << "_"; + result << "trgDev=" << targetDevice; + if (!config.first.empty()) { + result << "_targetConfig=" << config.first; + } + if (inputParams.size() == 3) { + result << "_inputArg=" << inputParams[0] << "_" << inputParams[1] << "_" << inputParams[2]; + } + result << "_activation=" << activationNames[activationType]; + return result.str(); + } + + void ActivationFakeQuantizeSubgraphTest::SetUp() { + fqSpecificParams fqParams; + ngraph::helpers::ActivationTypes activationType; + std::vector inputShape; + std::pair> config; + InferenceEngine::Precision netPrecision; + std::tie(fqParams, activationType, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetDevice, config) = this->GetParam(); + configuration.insert(config.second.begin(), config.second.end()); + + std::vector levels; + std::vector> constShape; + std::vector inputArg; + std::tie(levels, constShape, inputArg) = fqParams; + if (inputArg.size() == 3) { + inputDataMin = inputArg[0]; + inputDataMax = inputArg[1]; + inputDataResolution = inputArg[2]; + } + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + + auto act = ngraph::builder::makeActivation(params[0], ngPrc, activationType); + + auto FQNode = ngraph::builder::makeFakeQuantize(act, ngraph::element::f32, levels[0], constShape[0], + { inputDataMin }, { inputDataMax }, { inputDataMin }, { inputDataMax }); + + auto FQ = std::dynamic_pointer_cast(FQNode); + + ngraph::ResultVector results{std::make_shared(FQ)}; + function = std::make_shared(results, params, "ActivationFakeQuantizeSubgraph"); + } + +InferenceEngine::Blob::Ptr ActivationFakeQuantizeSubgraphTest::GenerateInput(const InferenceEngine::InputInfo &info) const { + return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), inputDataMax - inputDataMin, inputDataMin, 1 / inputDataResolution, + seed); +} +} // namespace SubgraphTestsDefinitions From 99df448669760e3be9c09614678a0873b74dc29b Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Thu, 22 Apr 2021 14:02:54 +0300 Subject: [PATCH 49/78] refactor: add clang style check for samples (#5306) * refactor: add clang style check for samples * fix: add .clang-format for ie * fix: style check for missing headers * refactor: remove cpplint for IE samples * fix: setw is not a member of std for classification_results.hpp * feat: add indent after ifdefine * feat: set up google style for IE samples * fix indents for w_dirent headers * fix: include issues for utils.cpp due to clang-format --- .../clang_format/clang_format_check.cmake | 5 +- .../ie_bridges/c/samples/.clang-format | 25 + .../common/opencv_c_wraper/CMakeLists.txt | 4 +- .../opencv_c_wraper/opencv_c_wraper.cpp | 99 +-- .../common/opencv_c_wraper/opencv_c_wraper.h | 43 +- .../c/samples/hello_classification/main.c | 124 +-- .../hello_nv12_input_classification/main.c | 166 +++-- .../object_detection_sample_ssd/c_w_dirent.h | 179 ++--- .../object_detection_sample_ssd/main.c | 332 +++++---- .../object_detection_sample_ssd.h | 81 +- inference-engine/samples/.clang-format | 25 + inference-engine/samples/CMakeLists.txt | 20 +- .../samples/benchmark_app/benchmark_app.hpp | 84 ++- .../benchmark_app/infer_request_wrap.hpp | 51 +- .../samples/benchmark_app/inputs_filling.cpp | 209 +++--- .../samples/benchmark_app/inputs_filling.hpp | 9 +- .../samples/benchmark_app/main.cpp | 300 ++++---- .../samples/benchmark_app/progress_bar.hpp | 1 - .../benchmark_app/statistics_report.cpp | 67 +- .../benchmark_app/statistics_report.hpp | 32 +- .../samples/benchmark_app/utils.cpp | 122 ++- .../samples/benchmark_app/utils.hpp | 60 +- .../CMakeLists.txt | 2 +- .../classification_sample_async.h | 23 +- .../classification_sample_async/main.cpp | 178 +++-- .../common/format_reader/CMakeLists.txt | 4 + .../common/format_reader/MnistUbyte.cpp | 30 +- .../samples/common/format_reader/MnistUbyte.h | 8 +- .../samples/common/format_reader/bmp.cpp | 19 +- .../samples/common/format_reader/bmp.h | 32 +- .../common/format_reader/format_reader.cpp | 18 +- .../common/format_reader/format_reader.h | 37 +- .../common/format_reader/format_reader_ptr.h | 11 +- .../common/format_reader/opencv_wraper.cpp | 17 +- .../common/format_reader/opencv_wraper.h | 29 +- .../samples/common/format_reader/register.h | 12 +- .../samples/common/utils/CMakeLists.txt | 6 +- .../utils/include/samples/args_helper.hpp | 28 +- .../include/samples/classification_results.h | 77 +- .../common/utils/include/samples/common.hpp | 705 ++++++++---------- .../include/samples/console_progress.hpp | 28 +- .../utils/include/samples/csv_dumper.hpp | 16 +- .../utils/include/samples/ocv_common.hpp | 38 +- .../include/samples/os/windows/w_dirent.h | 152 ++-- .../common/utils/include/samples/slog.hpp | 19 +- .../include/samples/vpu/vpu_tools_common.hpp | 4 +- .../samples/common/utils/src/args_helper.cpp | 99 +-- .../samples/common/utils/src/common.cpp | 2 +- .../samples/hello_classification/main.cpp | 107 +-- .../hello_nv12_input_classification/main.cpp | 177 ++--- .../samples/hello_query_device/main.cpp | 83 ++- .../samples/hello_reshape_ssd/main.cpp | 87 ++- .../reshape_ssd_extension.hpp | 37 +- .../CMakeLists.txt | 7 +- .../ngraph_function_creation_sample/main.cpp | 233 +++--- .../ngraph_function_creation_sample.hpp | 11 +- .../object_detection_sample_ssd/main.cpp | 188 +++-- .../object_detection_sample_ssd.h | 25 +- .../samples/speech_sample/main.cpp | 611 +++++++-------- .../samples/speech_sample/speech_sample.hpp | 41 +- .../samples/style_transfer_sample/main.cpp | 155 ++-- .../style_transfer_sample.h | 27 +- 62 files changed, 2754 insertions(+), 2667 deletions(-) create mode 100644 inference-engine/ie_bridges/c/samples/.clang-format create mode 100644 inference-engine/samples/.clang-format diff --git a/cmake/developer_package/clang_format/clang_format_check.cmake b/cmake/developer_package/clang_format/clang_format_check.cmake index 63707ce765c..8b0601203ee 100644 --- a/cmake/developer_package/clang_format/clang_format_check.cmake +++ b/cmake/developer_package/clang_format/clang_format_check.cmake @@ -7,12 +7,11 @@ file(REMOVE "${OUTPUT_FILE}") execute_process(COMMAND ${CLANG_FORMAT} -style=file -output-replacements-xml ${INPUT_FILE} OUTPUT_VARIABLE STYLE_CHECK_RESULT ) -# Display the cpplint output to console (to parse it form IDE) -message("${output}") + file(WRITE "${OUTPUT_FILE}" "${STYLE_CHECK_RESULT}") if(NOT SKIP_RETURN_CODE) if("${STYLE_CHECK_RESULT}" MATCHES ".* -#include + #include + #include -int image_read(const char *img_path, c_mat_t *img) { +int image_read(const char* img_path, c_mat_t* img) { if (img_path == nullptr || img == nullptr) { - return - 1; + return -1; } cv::Mat mat = cv::imread(img_path); @@ -32,7 +42,7 @@ int image_read(const char *img_path, c_mat_t *img) { img->mat_height = mat.size().height; img->mat_type = mat.type(); img->mat_data_size = mat.elemSize() * img->mat_width * img->mat_height; - img->mat_data = (unsigned char *)malloc(sizeof(unsigned char) * img->mat_data_size); + img->mat_data = (unsigned char*)malloc(sizeof(unsigned char) * img->mat_data_size); if (img->mat_data == NULL) { return -1; @@ -45,7 +55,7 @@ int image_read(const char *img_path, c_mat_t *img) { return 0; } -int image_resize(const c_mat_t *src_img, c_mat_t *dst_img, const int width, const int height) { +int image_resize(const c_mat_t* src_img, c_mat_t* dst_img, const int width, const int height) { if (src_img == nullptr || dst_img == nullptr) { return -1; } @@ -60,7 +70,7 @@ int image_resize(const c_mat_t *src_img, c_mat_t *dst_img, const int width, cons dst_img->mat_height = mat_dst.size().height; dst_img->mat_type = mat_dst.type(); dst_img->mat_data_size = mat_dst.elemSize() * dst_img->mat_width * dst_img->mat_height; - dst_img->mat_data = (unsigned char *)malloc(sizeof(unsigned char) * dst_img->mat_data_size); + dst_img->mat_data = (unsigned char*)malloc(sizeof(unsigned char) * dst_img->mat_data_size); if (dst_img->mat_data == NULL) { return -1; @@ -76,12 +86,12 @@ int image_resize(const c_mat_t *src_img, c_mat_t *dst_img, const int width, cons return 1; } -int image_save(const char *img_path, c_mat_t *img) { +int image_save(const char* img_path, c_mat_t* img) { cv::Mat mat(cv::Size(img->mat_width, img->mat_height), img->mat_type, img->mat_data); return cv::imwrite(img_path, mat); } -int image_free(c_mat_t *img) { +int image_free(c_mat_t* img) { if (img) { free(img->mat_data); img->mat_data = NULL; @@ -89,31 +99,12 @@ int image_free(c_mat_t *img) { return -1; } -int image_add_rectangles(c_mat_t *img, rectangle_t rects[], int classes[], int num, int thickness) { +int image_add_rectangles(c_mat_t* img, rectangle_t rects[], int classes[], int num, int thickness) { int colors_num = 21; - color_t colors[21] = { // colors to be used for bounding boxes - { 128, 64, 128 }, - { 232, 35, 244 }, - { 70, 70, 70 }, - { 156, 102, 102 }, - { 153, 153, 190 }, - { 153, 153, 153 }, - { 30, 170, 250 }, - { 0, 220, 220 }, - { 35, 142, 107 }, - { 152, 251, 152 }, - { 180, 130, 70 }, - { 60, 20, 220 }, - { 0, 0, 255 }, - { 142, 0, 0 }, - { 70, 0, 0 }, - { 100, 60, 0 }, - { 90, 0, 0 }, - { 230, 0, 0 }, - { 32, 11, 119 }, - { 0, 74, 111 }, - { 81, 0, 81 } - }; + color_t colors[21] = {// colors to be used for bounding boxes + {128, 64, 128}, {232, 35, 244}, {70, 70, 70}, {156, 102, 102}, {153, 153, 190}, {153, 153, 153}, {30, 170, 250}, + {0, 220, 220}, {35, 142, 107}, {152, 251, 152}, {180, 130, 70}, {60, 20, 220}, {0, 0, 255}, {142, 0, 0}, + {70, 0, 0}, {100, 60, 0}, {90, 0, 0}, {230, 0, 0}, {32, 11, 119}, {0, 74, 111}, {81, 0, 81}}; for (int i = 0; i < num; i++) { int x = rects[i].x_min; @@ -123,16 +114,32 @@ int image_add_rectangles(c_mat_t *img, rectangle_t rects[], int classes[], int n int cls = classes[i] % colors_num; // color of a bounding box line - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w < 0) w = 0; - if (h < 0) h = 0; + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (w < 0) + w = 0; + if (h < 0) + h = 0; - if (x >= img->mat_width) { x = img->mat_width - 1; w = 0; thickness = 1; } - if (y >= img->mat_height) { y = img->mat_height - 1; h = 0; thickness = 1; } + if (x >= img->mat_width) { + x = img->mat_width - 1; + w = 0; + thickness = 1; + } + if (y >= img->mat_height) { + y = img->mat_height - 1; + h = 0; + thickness = 1; + } - if ((x + w) >= img->mat_width) { w = img->mat_width - x - 1; } - if ((y + h) >= img->mat_height) { h = img->mat_height - y - 1; } + if ((x + w) >= img->mat_width) { + w = img->mat_width - x - 1; + } + if ((y + h) >= img->mat_height) { + h = img->mat_height - y - 1; + } thickness = std::min(std::min(thickness, w / 2 + 1), h / 2 + 1); diff --git a/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h b/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h index 80ecfefbba4..93e2358ec0d 100644 --- a/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h +++ b/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h @@ -16,9 +16,9 @@ #else #if defined(_WIN32) #ifdef opencv_c_wraper_EXPORTS - #define OPENCV_C_WRAPPER(...) OPENCV_C_EXTERN __declspec(dllexport) __VA_ARGS__ __cdecl + #define OPENCV_C_WRAPPER(...) OPENCV_C_EXTERN __declspec(dllexport) __VA_ARGS__ __cdecl #else - #define OPENCV_C_WRAPPER(...) OPENCV_C_EXTERN __declspec(dllimport) __VA_ARGS__ __cdecl + #define OPENCV_C_WRAPPER(...) OPENCV_C_EXTERN __declspec(dllimport) __VA_ARGS__ __cdecl #endif #else #define OPENCV_C_WRAPPER(...) OPENCV_C_EXTERN __attribute__((visibility("default"))) __VA_ARGS__ @@ -30,13 +30,13 @@ * @brief OpenCV Mat Wrapper */ typedef struct c_mat { - unsigned char *mat_data; + unsigned char* mat_data; int mat_data_size; int mat_width; int mat_height; int mat_channels; int mat_type; -}c_mat_t; +} c_mat_t; /** * @struct rectangle @@ -47,7 +47,7 @@ typedef struct rectangle { int y_min; int rect_width; int rect_height; -}rectangle_t; +} rectangle_t; /** * @struct color @@ -57,7 +57,7 @@ typedef struct color { unsigned char r; unsigned char g; unsigned char b; -}color_t; +} color_t; /** * @brief Load an image from a file. If the image cannot be read, the function return -1. @@ -65,7 +65,7 @@ typedef struct color { * @param img A pointer to the newly created c_mat_t. * @return Status of the operation: 0 for success, -1 for fail. */ -OPENCV_C_WRAPPER(int) image_read(const char *img_path, c_mat_t *img); +OPENCV_C_WRAPPER(int) image_read(const char* img_path, c_mat_t* img); /** * @brief Resizes an image. @@ -75,30 +75,33 @@ OPENCV_C_WRAPPER(int) image_read(const char *img_path, c_mat_t *img); * @param height The height of dst_img. * @return Status of the operation: 0 for success, -1 for fail. */ -OPENCV_C_WRAPPER(int) image_resize(const c_mat_t *src_img, c_mat_t *dst_img, const int width, const int height); +OPENCV_C_WRAPPER(int) +image_resize(const c_mat_t* src_img, c_mat_t* dst_img, const int width, const int height); /** - * @brief Saves an image to a specified file.The image format is chosen based on the filename extension. + * @brief Saves an image to a specified file.The image format is chosen based on the filename + * extension. * @param img_path Path of the file to be saved. * @param img Image to be saved. * @return Status of the operation: 0 for success, -1 for fail. */ -OPENCV_C_WRAPPER(int) image_save(const char *img_path, c_mat_t *img); +OPENCV_C_WRAPPER(int) image_save(const char* img_path, c_mat_t* img); /** * @brief Releases memory occupied by a c_mat_t instance. * @param img A pointer to the c_mat_t instance to free memory. * @return Status of the operation: 0 for success, -1 for fail. */ -OPENCV_C_WRAPPER(int) image_free(c_mat_t *img); +OPENCV_C_WRAPPER(int) image_free(c_mat_t* img); /** -* @brief Adds colored rectangles to the image -* @param img - image where rectangles are put -* @param rects - array for the rectangle -* @param classes - array for classes -* @param num - number of the rects and classes -* @param thickness - thickness of a line (in pixels) to be used for bounding boxes -* @return Status of the operation: 0 for success, -1 for fail. -*/ -OPENCV_C_WRAPPER(int) image_add_rectangles(c_mat_t *img, rectangle_t rects[], int classes[], int num, int thickness); + * @brief Adds colored rectangles to the image + * @param img - image where rectangles are put + * @param rects - array for the rectangle + * @param classes - array for classes + * @param num - number of the rects and classes + * @param thickness - thickness of a line (in pixels) to be used for bounding boxes + * @return Status of the operation: 0 for success, -1 for fail. + */ +OPENCV_C_WRAPPER(int) +image_add_rectangles(c_mat_t* img, rectangle_t rects[], int classes[], int num, int thickness); diff --git a/inference-engine/ie_bridges/c/samples/hello_classification/main.c b/inference-engine/ie_bridges/c/samples/hello_classification/main.c index 86d8125a1b0..af1a9b6104a 100644 --- a/inference-engine/ie_bridges/c/samples/hello_classification/main.c +++ b/inference-engine/ie_bridges/c/samples/hello_classification/main.c @@ -2,29 +2,28 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include #include #include #include #include -#include -#include - /** -* @brief Struct to store classification results -*/ + * @brief Struct to store classification results + */ struct classify_res { size_t class_id; float probability; }; /** -* @brief Sort result of image classification by probability -* @param struct with classification results to sort -* @param size of the struct -* @return none -*/ -void classify_res_sort(struct classify_res *res, size_t n) { + * @brief Sort result of image classification by probability + * @param struct with classification results to sort + * @param size of the struct + * @return none + */ +void classify_res_sort(struct classify_res* res, size_t n) { size_t i, j; for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { @@ -42,12 +41,12 @@ void classify_res_sort(struct classify_res *res, size_t n) { } /** -* @brief Convert output blob to classify struct for processing results -* @param blob of output data -* @param size of the blob -* @return struct classify_res -*/ -struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { + * @brief Convert output blob to classify struct for processing results + * @param blob of output data + * @param size of the blob + * @return struct classify_res + */ +struct classify_res* output_blob_to_classify_res(ie_blob_t* blob, size_t* n) { dimensions_t output_dim; IEStatusCode status = ie_blob_get_dims(blob, &output_dim); if (status != OK) @@ -55,7 +54,7 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { *n = output_dim.dims[1]; - struct classify_res *cls = (struct classify_res *)malloc(sizeof(struct classify_res) * (*n)); + struct classify_res* cls = (struct classify_res*)malloc(sizeof(struct classify_res) * (*n)); if (!cls) { return NULL; } @@ -66,7 +65,7 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { free(cls); return NULL; } - float *blob_data = (float*) (blob_cbuffer.cbuffer); + float* blob_data = (float*)(blob_cbuffer.cbuffer); size_t i; for (i = 0; i < *n; ++i) { @@ -78,13 +77,13 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { } /** -* @brief Print results of classification -* @param struct of the classification results -* @param size of the struct of classification results -* @param string image path -* @return none -*/ -void print_classify_res(struct classify_res *cls, size_t n, const char *img_path) { + * @brief Print results of classification + * @param struct of the classification results + * @param size of the struct of classification results + * @param string image path + * @return none + */ +void print_classify_res(struct classify_res* cls, size_t n, const char* img_path) { printf("\nImage %s\n", img_path); printf("\nclassid probability\n"); printf("------- -----------\n"); @@ -92,37 +91,43 @@ void print_classify_res(struct classify_res *cls, size_t n, const char *img_path for (i = 0; i < n; ++i) { printf("%zu %f\n", cls[i].class_id, cls[i].probability); } - printf("\nThis sample is an API example, for any performance measurements please use the dedicated benchmark_app tool\n"); + printf("\nThis sample is an API example," + " for any performance measurements please use the dedicated benchmark_" + "app tool\n"); } -int main(int argc, char **argv) { - // ------------------------------ Parsing and validation of input args --------------------------------- +int main(int argc, char** argv) { + // ------------------------------ Parsing and validation of input args + // --------------------------------- if (argc != 4) { - printf("Usage : ./hello_classification \n"); + printf("Usage : ./hello_classification " + "\n"); return EXIT_FAILURE; } - const char *input_model = argv[1]; - const char *input_image_path = argv[2]; - const char *device_name = argv[3]; - ie_core_t *core = NULL; - ie_network_t *network = NULL; - ie_executable_network_t *exe_network = NULL; - ie_infer_request_t *infer_request = NULL; + const char* input_model = argv[1]; + const char* input_image_path = argv[2]; + const char* device_name = argv[3]; + ie_core_t* core = NULL; + ie_network_t* network = NULL; + ie_executable_network_t* exe_network = NULL; + ie_infer_request_t* infer_request = NULL; char *input_name = NULL, *output_name = NULL; ie_blob_t *imgBlob = NULL, *output_blob = NULL; size_t network_input_size; size_t network_output_size; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- IEStatusCode status = ie_core_create("", &core); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin + // files) or ONNX (.onnx file) format status = ie_core_read_network(core, input_model, NULL, &network); if (status != OK) goto err; @@ -140,78 +145,89 @@ int main(int argc, char **argv) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- status = ie_network_get_input_name(network, 0, &input_name); if (status != OK) goto err; /* Mark input as resizable by setting of a resize algorithm. - * In this case we will be able to set an input blob of any shape to an infer request. - * Resize and layout conversions are executed automatically during inference */ + * In this case we will be able to set an input blob of any shape to an infer + * request. Resize and layout conversions are executed automatically during + * inference */ status |= ie_network_set_input_resize_algorithm(network, input_name, RESIZE_BILINEAR); status |= ie_network_set_input_layout(network, input_name, NHWC); status |= ie_network_set_input_precision(network, input_name, U8); if (status != OK) goto err; - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- status |= ie_network_get_output_name(network, 0, &output_name); status |= ie_network_set_output_precision(network, output_name, FP32); - if (status !=OK) + if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ ie_config_t config = {NULL, NULL, NULL}; status = ie_core_load_network(core, network, device_name, &config, &exe_network); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- status = ie_exec_network_create_infer_request(exe_network, &infer_request); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- - /* Read input image to a blob and set it to an infer request without resize and layout conversions. */ + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- + /* Read input image to a blob and set it to an infer request without resize + * and layout conversions. */ c_mat_t img; image_read(input_image_path, &img); dimensions_t dimens = {4, {1, (size_t)img.mat_channels, (size_t)img.mat_height, (size_t)img.mat_width}}; tensor_desc_t tensorDesc = {NHWC, dimens, U8}; size_t size = img.mat_data_size; - //just wrap IplImage data to ie_blob_t pointer without allocating of new memory + // just wrap IplImage data to ie_blob_t pointer without allocating of new + // memory status = ie_blob_make_memory_from_preallocated(&tensorDesc, img.mat_data, size, &imgBlob); if (status != OK) { image_free(&img); goto err; } - //infer_request accepts input blob of any size + // infer_request accepts input blob of any size status = ie_infer_request_set_blob(infer_request, input_name, imgBlob); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference -------------------------------------------------------- + // --------------------------- Step 7. Do inference + // -------------------------------------------------------- /* Running the request synchronously */ status = ie_infer_request_infer(infer_request); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------ + // --------------------------- Step 8. Process output + // ------------------------------------------------------ status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); if (status != OK) { image_free(&img); goto err; } size_t class_num; - struct classify_res *cls = output_blob_to_classify_res(output_blob, &class_num); + struct classify_res* cls = output_blob_to_classify_res(output_blob, &class_num); classify_res_sort(cls, class_num); diff --git a/inference-engine/ie_bridges/c/samples/hello_nv12_input_classification/main.c b/inference-engine/ie_bridges/c/samples/hello_nv12_input_classification/main.c index d5384a79bf6..9effcdef06a 100644 --- a/inference-engine/ie_bridges/c/samples/hello_nv12_input_classification/main.c +++ b/inference-engine/ie_bridges/c/samples/hello_nv12_input_classification/main.c @@ -2,28 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include #include #include #include -#include - /** -* @brief Struct to store classification results -*/ + * @brief Struct to store classification results + */ struct classify_res { size_t class_id; float probability; }; /** -* @brief Sort result of image classification by probability -* @param struct with classification results to sort -* @param size of the struct -* @return none -*/ -void classify_res_sort(struct classify_res *res, size_t n) { + * @brief Sort result of image classification by probability + * @param struct with classification results to sort + * @param size of the struct + * @return none + */ +void classify_res_sort(struct classify_res* res, size_t n) { size_t i, j; for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { @@ -41,12 +40,12 @@ void classify_res_sort(struct classify_res *res, size_t n) { } /** -* @brief Convert output blob to classify struct for processing results -* @param blob of output data -* @param size of the blob -* @return struct classify_res -*/ -struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { + * @brief Convert output blob to classify struct for processing results + * @param blob of output data + * @param size of the blob + * @return struct classify_res + */ +struct classify_res* output_blob_to_classify_res(ie_blob_t* blob, size_t* n) { dimensions_t output_dim; IEStatusCode status = ie_blob_get_dims(blob, &output_dim); if (status != OK) @@ -54,7 +53,7 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { *n = output_dim.dims[1]; - struct classify_res *cls = (struct classify_res *)malloc(sizeof(struct classify_res) * (*n)); + struct classify_res* cls = (struct classify_res*)malloc(sizeof(struct classify_res) * (*n)); if (!cls) { return NULL; } @@ -65,7 +64,7 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { free(cls); return NULL; } - float *blob_data = (float*) (blob_cbuffer.cbuffer); + float* blob_data = (float*)(blob_cbuffer.cbuffer); size_t i; for (i = 0; i < *n; ++i) { @@ -77,13 +76,13 @@ struct classify_res *output_blob_to_classify_res(ie_blob_t *blob, size_t *n) { } /** -* @brief Print results of classification -* @param struct of the classification results -* @param size of the struct of classification results -* @param string image path -* @return none -*/ -void print_classify_res(struct classify_res *cls, size_t n, const char *img_path) { + * @brief Print results of classification + * @param struct of the classification results + * @param size of the struct of classification results + * @param string image path + * @return none + */ +void print_classify_res(struct classify_res* cls, size_t n, const char* img_path) { printf("\nImage %s\n", img_path); printf("\nclassid probability\n"); printf("------- -----------\n"); @@ -91,18 +90,21 @@ void print_classify_res(struct classify_res *cls, size_t n, const char *img_path for (i = 0; i < n; ++i) { printf("%zu %f\n", cls[i].class_id, cls[i].probability); } - printf("\nThis sample is an API example, for any performance measurements please use the dedicated benchmark_app tool\n"); + printf("\nThis sample is an API example," + " for any performance measurements please use the dedicated benchmark_" + "app tool\n"); } /** -* @brief Read image data -* @param string image path -* @param pointer to store image data -* @param size bytes of image -* @return total number of elements successfully read, in case of error it doesn't equal to size param -*/ -size_t read_image_from_file(const char *img_path, unsigned char *img_data, size_t size) { - FILE *fp = fopen(img_path, "rb+"); + * @brief Read image data + * @param string image path + * @param pointer to store image data + * @param size bytes of image + * @return total number of elements successfully read, in case of error it + * doesn't equal to size param + */ +size_t read_image_from_file(const char* img_path, unsigned char* img_data, size_t size) { + FILE* fp = fopen(img_path, "rb+"); size_t read_size = 0; if (fp) { @@ -117,14 +119,14 @@ size_t read_image_from_file(const char *img_path, unsigned char *img_data, size_ } /** -* @brief Check image has supported width and height -* @param string image size in WIDTHxHEIGHT format -* @param pointer to image width -* @param pointer to image height -* @return bool status True(success) or False(fail) -*/ -bool is_supported_image_size(const char *size_str, size_t *width, size_t *height) { - const char *_size = size_str; + * @brief Check image has supported width and height + * @param string image size in WIDTHxHEIGHT format + * @param pointer to image width + * @param pointer to image height + * @return bool status True(success) or False(fail) + */ +bool is_supported_image_size(const char* size_str, size_t* width, size_t* height) { + const char* _size = size_str; size_t _width = 0, _height = 0; while (_size && *_size != 'x' && *_size != '\0') { if ((*_size <= '9') && (*_size >= '0')) { @@ -161,14 +163,17 @@ bool is_supported_image_size(const char *size_str, size_t *width, size_t *height } err: printf("Incorrect format of image size parameter, expected WIDTHxHEIGHT, " - "actual: %s\n", size_str); + "actual: %s\n", + size_str); return false; } -int main(int argc, char **argv) { - // ------------------------------ Parsing and validation of input args --------------------------------- +int main(int argc, char** argv) { + // ------------------------------ Parsing and validation of input args + // --------------------------------- if (argc != 5) { - printf("Usage : ./hello_classification \n"); + printf("Usage : ./hello_classification " + " \n"); return EXIT_FAILURE; } @@ -176,80 +181,91 @@ int main(int argc, char **argv) { if (!is_supported_image_size(argv[3], &input_width, &input_height)) return EXIT_FAILURE; - const char *input_model = argv[1]; - const char *input_image_path = argv[2]; - const char *device_name = argv[4]; - unsigned char *img_data = NULL; - ie_core_t *core = NULL; - ie_network_t *network = NULL; - ie_executable_network_t *exe_network = NULL; - ie_infer_request_t *infer_request = NULL; + const char* input_model = argv[1]; + const char* input_image_path = argv[2]; + const char* device_name = argv[4]; + unsigned char* img_data = NULL; + ie_core_t* core = NULL; + ie_network_t* network = NULL; + ie_executable_network_t* exe_network = NULL; + ie_infer_request_t* infer_request = NULL; char *input_name = NULL, *output_name = NULL; ie_blob_t *y_blob = NULL, *uv_blob = NULL, *nv12_blob = NULL, *output_blob = NULL; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- IEStatusCode status = ie_core_create("", &core); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin + // files) or ONNX (.onnx file) format status = ie_core_read_network(core, input_model, NULL, &network); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- status = ie_network_get_input_name(network, 0, &input_name); if (status != OK) goto err; /* Mark input as resizable by setting of a resize algorithm. - * In this case we will be able to set an input blob of any shape to an infer request. - * Resize and layout conversions are executed automatically during inference */ - status |= ie_network_set_input_resize_algorithm(network, input_name, RESIZE_BILINEAR); + * In this case we will be able to set an input blob of any shape to an infer + * request. Resize and layout conversions are executed automatically during + * inference */ + status |= ie_network_set_input_resize_algorithm(network, input_name, RESIZE_BILINEAR); status |= ie_network_set_input_layout(network, input_name, NCHW); status |= ie_network_set_input_precision(network, input_name, U8); - // set input color format to NV12 to enable automatic input color format pre-processing + // set input color format to NV12 to enable automatic input color format + // pre-processing status |= ie_network_set_color_format(network, input_name, NV12); if (status != OK) goto err; - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- status |= ie_network_get_output_name(network, 0, &output_name); status |= ie_network_set_output_precision(network, output_name, FP32); - if (status !=OK) + if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ ie_config_t config = {NULL, NULL, NULL}; status = ie_core_load_network(core, network, device_name, &config, &exe_network); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- status = ie_exec_network_create_infer_request(exe_network, &infer_request); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- - // read image with size converted to NV12 data size: height(NV12) = 3 / 2 * logical height + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- read image with + // size converted to NV12 data size: height(NV12) = 3 / 2 * logical height img_size = input_width * (input_height * 3 / 2); - img_data = (unsigned char *)calloc(img_size, sizeof(unsigned char)); + img_data = (unsigned char*)calloc(img_size, sizeof(unsigned char)); if (NULL == img_data) goto err; if (img_size != read_image_from_file(input_image_path, img_data, img_size)) goto err; - // --------------------------- Create a blob to hold the NV12 input data ------------------------------- - // Create tensor descriptors for Y and UV blobs + // --------------------------- Create a blob to hold the NV12 input data + // ------------------------------- Create tensor descriptors for Y and UV + // blobs dimensions_t y_dimens = {4, {1, 1, input_height, input_width}}; dimensions_t uv_dimens = {4, {1, 2, input_height / 2, input_width / 2}}; tensor_desc_t y_tensor = {NHWC, y_dimens, U8}; @@ -271,20 +287,22 @@ int main(int argc, char **argv) { goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference -------------------------------------------------------- + // --------------------------- Step 7. Do inference + // -------------------------------------------------------- /* Running the request synchronously */ status = ie_infer_request_infer(infer_request); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------ + // --------------------------- Step 8. Process output + // ------------------------------------------------------ status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); if (status != OK) goto err; size_t class_num; - struct classify_res *cls = output_blob_to_classify_res(output_blob, &class_num); + struct classify_res* cls = output_blob_to_classify_res(output_blob, &class_num); classify_res_sort(cls, class_num); diff --git a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/c_w_dirent.h b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/c_w_dirent.h index c6dc9ee442d..259019d3021 100644 --- a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/c_w_dirent.h +++ b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/c_w_dirent.h @@ -6,69 +6,71 @@ #if defined(_WIN32) -#ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN_UNDEF -#endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN_UNDEF + #endif -#ifndef NOMINMAX -# define NOMINMAX -# define NOMINMAX_UNDEF -#endif + #ifndef NOMINMAX + #define NOMINMAX + #define NOMINMAX_UNDEF + #endif -#if defined(_M_IX86) && !defined(_X86_) && !defined(_AMD64_) -# define _X86_ -#endif + #if defined(_M_IX86) && !defined(_X86_) && !defined(_AMD64_) + #define _X86_ + #endif -#if defined(_M_X64) && !defined(_X86_) && !defined(_AMD64_) -# define _AMD64_ -#endif + #if defined(_M_X64) && !defined(_X86_) && !defined(_AMD64_) + #define _AMD64_ + #endif -#if defined(_M_ARM) && !defined(_ARM_) && !defined(_ARM64_) -# define _ARM_ -#endif + #if defined(_M_ARM) && !defined(_ARM_) && !defined(_ARM64_) + #define _ARM_ + #endif -#if defined(_M_ARM64) && !defined(_ARM_) && !defined(_ARM64_) -# define _ARM64_ -#endif + #if defined(_M_ARM64) && !defined(_ARM_) && !defined(_ARM64_) + #define _ARM64_ + #endif -#include -#include -#include -#include -#include + // clang-format off + #include + #include + #include + #include + #include + // clang-format on -// Copied from linux libc sys/stat.h: -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) + // Copied from linux libc sys/stat.h: + #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) + #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) /// @brief structure to store directory names typedef struct dirent { - char *d_name; -}dirent; + char* d_name; +} dirent; /** -* @brief Add directory to directory names struct -* @param int argc - count of args -* @param char *argv[] - array values of args -* @param char *opts - array of options -* @return pointer to directory names struct -*/ -static dirent *createDirent(const wchar_t *wsFilePath) { - dirent *d = (dirent *)malloc(sizeof(dirent)); + * @brief Add directory to directory names struct + * @param int argc - count of args + * @param char *argv[] - array values of args + * @param char *opts - array of options + * @return pointer to directory names struct + */ +static dirent* createDirent(const wchar_t* wsFilePath) { + dirent* d = (dirent*)malloc(sizeof(dirent)); size_t i; size_t slen = wcslen(wsFilePath); - d->d_name = (char *)(malloc(slen + 1)); + d->d_name = (char*)(malloc(slen + 1)); wcstombs_s(&i, d->d_name, slen + 1, wsFilePath, slen); return d; } /** -* @brief Free directory names struct -* @param point to directory names structure -* @return none -*/ -static void freeDirent(dirent **d) { + * @brief Free directory names struct + * @param point to directory names structure + * @return none + */ +static void freeDirent(dirent** d) { free((*d)->d_name); (*d)->d_name = NULL; free(*d); @@ -79,19 +81,20 @@ static void freeDirent(dirent **d) { typedef struct DIR { WIN32_FIND_DATAA FindFileData; HANDLE hFind; - dirent *next; -}DIR; + dirent* next; +} DIR; /** -* @brief Compare two string, second string is the end of the first -* @param string to compare -* @param end string to find -* @return status 1(success) or 0(fail) -*/ -static int endsWith(const char *src, const char *with) { + * @brief Compare two string, second string is the end of the first + * @param string to compare + * @param end string to find + * @return status 1(success) or 0(fail) + */ +static int endsWith(const char* src, const char* with) { int wl = (int)(strlen(with)); int so = (int)(strlen(with)) - wl; - if (so < 0) return 0; + if (so < 0) + return 0; if (strncmp(with, &(src[so]), wl) == 0) return 1; else @@ -99,10 +102,10 @@ static int endsWith(const char *src, const char *with) { } /** -* @brief Check file handler is valid -* @param struct of directory data -* @return status 1(success) or 0(fail) -*/ + * @brief Check file handler is valid + * @param struct of directory data + * @return status 1(success) or 0(fail) + */ static int isValid(DIR* dp) { if (dp->hFind != INVALID_HANDLE_VALUE && dp->FindFileData.dwReserved0) { return 1; @@ -112,14 +115,14 @@ static int isValid(DIR* dp) { } /** -* @brief Create directory data struct element -* @param string directory path -* @return pointer to directory data struct element -*/ -static DIR *opendir(const char *dirPath) { - DIR *dp = (DIR *)malloc(sizeof(DIR)); + * @brief Create directory data struct element + * @param string directory path + * @return pointer to directory data struct element + */ +static DIR* opendir(const char* dirPath) { + DIR* dp = (DIR*)malloc(sizeof(DIR)); dp->next = NULL; - char *ws = (char *)(malloc(strlen(dirPath) + 1)); + char* ws = (char*)(malloc(strlen(dirPath) + 1)); strcpy(ws, dirPath); if (endsWith(ws, "\\")) strcat(ws, "*"); @@ -136,14 +139,16 @@ static DIR *opendir(const char *dirPath) { } /** -* @brief Walk throw directory data struct -* @param pointer to directory data struct -* @return pointer to directory data struct next element -*/ -static struct dirent *readdir(DIR *dp) { - if (dp->next != NULL) freeDirent(&(dp->next)); + * @brief Walk throw directory data struct + * @param pointer to directory data struct + * @return pointer to directory data struct next element + */ +static struct dirent* readdir(DIR* dp) { + if (dp->next != NULL) + freeDirent(&(dp->next)); - if (!dp->FindFileData.dwReserved0) return NULL; + if (!dp->FindFileData.dwReserved0) + return NULL; wchar_t wbuf[4096]; @@ -155,30 +160,30 @@ static struct dirent *readdir(DIR *dp) { } /** -* @brief Remove directory data struct -* @param pointer to struct directory data -* @return none -*/ -static void closedir(DIR *dp){ + * @brief Remove directory data struct + * @param pointer to struct directory data + * @return none + */ +static void closedir(DIR* dp) { if (dp->next) { freeDirent(&(dp->next)); } free(dp); } -#ifdef WIN32_LEAN_AND_MEAN_UNDEF -# undef WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN_UNDEF -#endif + #ifdef WIN32_LEAN_AND_MEAN_UNDEF + #undef WIN32_LEAN_AND_MEAN + #undef WIN32_LEAN_AND_MEAN_UNDEF + #endif -#ifdef NOMINMAX_UNDEF -# undef NOMINMAX_UNDEF -# undef NOMINMAX -#endif + #ifdef NOMINMAX_UNDEF + #undef NOMINMAX_UNDEF + #undef NOMINMAX + #endif #else -#include -#include + #include + #include -#endif +#endif \ No newline at end of file diff --git a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c index 4d9d05b1556..4eac9dd3ad6 100644 --- a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c +++ b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c @@ -2,73 +2,73 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include #include #include -#include #include "object_detection_sample_ssd.h" -#include #ifdef _WIN32 -#include "c_w_dirent.h" + #include "c_w_dirent.h" #else -#include + #include #endif #define MAX_IMAGES 20 -static const char *img_msg = NULL; -static const char *input_model = NULL; -static const char *device_name = "CPU"; -static const char *custom_plugin_cfg_msg = NULL; -static const char *custom_ex_library_msg = NULL; -static const char *config_msg = NULL; +static const char* img_msg = NULL; +static const char* input_model = NULL; +static const char* device_name = "CPU"; +static const char* custom_plugin_cfg_msg = NULL; +static const char* custom_ex_library_msg = NULL; +static const char* config_msg = NULL; static int file_num = 0; -static char **file_paths = NULL; +static char** file_paths = NULL; -const char *info = "[ INFO ] "; -const char *warn = "[ WARNING ] "; +const char* info = "[ INFO ] "; +const char* warn = "[ WARNING ] "; /** -* @brief Parse and check command line arguments -* @param int argc - count of args -* @param char *argv[] - array values of args -* @return int - status 1(success) or -1(fail) -*/ -int ParseAndCheckCommandLine(int argc, char *argv[]) { + * @brief Parse and check command line arguments + * @param int argc - count of args + * @param char *argv[] - array values of args + * @return int - status 1(success) or -1(fail) + */ +int ParseAndCheckCommandLine(int argc, char* argv[]) { int opt = 0; int help = 0; - char *string = "hi:m:d:c:l:g:"; + char* string = "hi:m:d:c:l:g:"; printf("%sParsing input parameters\n", info); while ((opt = getopt(argc, argv, string)) != -1) { switch (opt) { - case 'h': - showUsage(); - help = 1; - break; - case 'i': - img_msg = optarg; - break; - case 'm': - input_model = optarg; - break; - case 'd': - device_name = optarg; - break; - case 'c': - custom_plugin_cfg_msg = optarg; - break; - case 'l': - custom_ex_library_msg = optarg; - break; - case 'g': - config_msg = optarg; - break; - default: + case 'h': + showUsage(); + help = 1; + break; + case 'i': + img_msg = optarg; + break; + case 'm': + input_model = optarg; + break; + case 'd': + device_name = optarg; + break; + case 'c': + custom_plugin_cfg_msg = optarg; + break; + case 'l': + custom_ex_library_msg = optarg; + break; + case 'g': + config_msg = optarg; + break; + default: return -1; } } @@ -88,11 +88,12 @@ int ParseAndCheckCommandLine(int argc, char *argv[]) { } /** -* @brief This function checks input args and existence of specified files in a given folder. Updated the file_paths and file_num. -* @param arg path to a file to be checked for existence -* @return none. -*/ -void readInputFilesArgument(const char *arg) { + * @brief This function checks input args and existence of specified files in a + * given folder. Updated the file_paths and file_num. + * @param arg path to a file to be checked for existence + * @return none. + */ +void readInputFilesArgument(const char* arg) { struct stat sb; int i; if (stat(arg, &sb) != 0) { @@ -100,28 +101,29 @@ void readInputFilesArgument(const char *arg) { return; } if (S_ISDIR(sb.st_mode)) { - DIR *dp; + DIR* dp; dp = opendir(arg); if (dp == NULL) { printf("%sFile %s cannot be opened!\n", warn, arg); return; } - struct dirent *ep; + struct dirent* ep; while (NULL != (ep = readdir(dp))) { - const char *fileName = ep->d_name; - if (strcmp(fileName, ".") == 0 || strcmp(fileName, "..") == 0) continue; - char *file_path = (char *)calloc(strlen(arg) + strlen(ep->d_name) + 2, sizeof(char)); + const char* fileName = ep->d_name; + if (strcmp(fileName, ".") == 0 || strcmp(fileName, "..") == 0) + continue; + char* file_path = (char*)calloc(strlen(arg) + strlen(ep->d_name) + 2, sizeof(char)); memcpy(file_path, arg, strlen(arg)); memcpy(file_path + strlen(arg), "/", strlen("/")); memcpy(file_path + strlen(arg) + strlen("/"), ep->d_name, strlen(ep->d_name) + 1); if (file_num == 0) { - file_paths = (char **)calloc(1, sizeof(char *)); + file_paths = (char**)calloc(1, sizeof(char*)); file_paths[0] = file_path; ++file_num; } else { - char **temp = (char **)realloc(file_paths, sizeof(char *) * (file_num +1)); + char** temp = (char**)realloc(file_paths, sizeof(char*) * (file_num + 1)); if (temp) { file_paths = temp; file_paths[file_num++] = file_path; @@ -138,20 +140,21 @@ void readInputFilesArgument(const char *arg) { closedir(dp); dp = NULL; } else { - char *file_path = (char *)calloc(strlen(arg) + 1, sizeof(char)); + char* file_path = (char*)calloc(strlen(arg) + 1, sizeof(char)); memcpy(file_path, arg, strlen(arg) + 1); if (file_num == 0) { - file_paths = (char **)calloc(1, sizeof(char *)); + file_paths = (char**)calloc(1, sizeof(char*)); } file_paths[file_num++] = file_path; } } /** -* @brief This function find -i key in input args. It's necessary to process multiple values for single key -* @return none. -*/ -void parseInputFilesArguments(int argc, char **argv) { + * @brief This function find -i key in input args. It's necessary to process + * multiple values for single key + * @return none. + */ +void parseInputFilesArguments(int argc, char** argv) { int readArguments = 0, i; for (i = 0; i < argc; ++i) { if (strcmp(argv[i], "-i") == 0) { @@ -178,42 +181,42 @@ void parseInputFilesArguments(int argc, char **argv) { } /** -* @brief Convert the contents of configuration file to the ie_config_t struct. -* @param config_file File path. -* @param comment Separator symbol. -* @return A pointer to the ie_config_t instance. -*/ -ie_config_t *parseConfig(const char *config_file, char comment) { - FILE *file = fopen(config_file, "r"); + * @brief Convert the contents of configuration file to the ie_config_t struct. + * @param config_file File path. + * @param comment Separator symbol. + * @return A pointer to the ie_config_t instance. + */ +ie_config_t* parseConfig(const char* config_file, char comment) { + FILE* file = fopen(config_file, "r"); if (!file) { return NULL; } - ie_config_t *cfg = NULL; + ie_config_t* cfg = NULL; char key[256], value[256]; - if (fscanf(file, "%s", key)!= EOF && fscanf(file, "%s", value) != EOF) { - char *cfg_name = (char *)calloc(strlen(key) + 1, sizeof(char)); - char *cfg_value = (char *)calloc(strlen(value) + 1, sizeof(char)); + if (fscanf(file, "%s", key) != EOF && fscanf(file, "%s", value) != EOF) { + char* cfg_name = (char*)calloc(strlen(key) + 1, sizeof(char)); + char* cfg_value = (char*)calloc(strlen(value) + 1, sizeof(char)); memcpy(cfg_name, key, strlen(key) + 1); memcpy(cfg_value, value, strlen(value) + 1); - ie_config_t *cfg_t = (ie_config_t *)calloc(1, sizeof(ie_config_t)); + ie_config_t* cfg_t = (ie_config_t*)calloc(1, sizeof(ie_config_t)); cfg_t->name = cfg_name; cfg_t->value = cfg_value; cfg_t->next = NULL; cfg = cfg_t; } if (cfg) { - ie_config_t *cfg_temp = cfg; - while (fscanf(file, "%s", key)!= EOF && fscanf(file, "%s", value) != EOF) { + ie_config_t* cfg_temp = cfg; + while (fscanf(file, "%s", key) != EOF && fscanf(file, "%s", value) != EOF) { if (strlen(key) == 0 || key[0] == comment) { continue; } - char *cfg_name = (char *)calloc(strlen(key) + 1, sizeof(char)); - char *cfg_value = (char *)calloc(strlen(value) + 1, sizeof(char)); + char* cfg_name = (char*)calloc(strlen(key) + 1, sizeof(char)); + char* cfg_value = (char*)calloc(strlen(value) + 1, sizeof(char)); memcpy(cfg_name, key, strlen(key) + 1); memcpy(cfg_value, value, strlen(value) + 1); - ie_config_t *cfg_t = (ie_config_t *)calloc(1, sizeof(ie_config_t)); + ie_config_t* cfg_t = (ie_config_t*)calloc(1, sizeof(ie_config_t)); cfg_t->name = cfg_name; cfg_t->value = cfg_value; cfg_t->next = NULL; @@ -227,19 +230,19 @@ ie_config_t *parseConfig(const char *config_file, char comment) { } /** -* @brief Releases memory occupied by config -* @param config A pointer to the config to free memory. -* @return none -*/ -void config_free(ie_config_t *config) { + * @brief Releases memory occupied by config + * @param config A pointer to the config to free memory. + * @return none + */ +void config_free(ie_config_t* config) { while (config) { - ie_config_t *temp = config; + ie_config_t* temp = config; if (config->name) { - free((char *)config->name); + free((char*)config->name); config->name = NULL; } if (config->value) { - free((char *)config->value); + free((char*)config->value); config->value = NULL; } if (config->next) { @@ -252,17 +255,17 @@ void config_free(ie_config_t *config) { } /** -* @brief Convert the numbers to char *; -* @param str A pointer to the converted string. -* @param num The number to convert. -* @return none. -*/ -void int2str(char *str, int num) { + * @brief Convert the numbers to char *; + * @param str A pointer to the converted string. + * @param num The number to convert. + * @return none. + */ +void int2str(char* str, int num) { int i = 0, j; if (num == 0) { str[0] = '0'; str[1] = '\0'; - return; + return; } while (num != 0) { @@ -273,23 +276,26 @@ void int2str(char *str, int num) { str[i] = '\0'; --i; for (j = 0; j < i; ++j, --i) { - char temp = str[j]; + char temp = str[j]; str[j] = str[i]; str[i] = temp; } } -int main(int argc, char **argv) { - /** This sample covers certain topology and cannot be generalized for any object detection one **/ - // ------------------------------ Get Inference Engine API version --------------------------------- +int main(int argc, char** argv) { + /** This sample covers certain topology and cannot be generalized for any + * object detection one **/ + // ------------------------------ Get Inference Engine API version + // --------------------------------- ie_version_t version = ie_c_api_version(); printf("%sInferenceEngine: \n", info); printf("%s\n", version.api_version); ie_version_free(&version); - // ------------------------------ Parsing and validation of input args --------------------------------- + // ------------------------------ Parsing and validation of input args + // --------------------------------- - char **argv_temp =(char **)calloc(argc, sizeof(char *)); + char** argv_temp = (char**)calloc(argc, sizeof(char*)); if (!argv_temp) { return EXIT_FAILURE; } @@ -300,10 +306,10 @@ int main(int argc, char **argv) { } char *input_weight = NULL, *imageInputName = NULL, *imInfoInputName = NULL, *output_name = NULL; - ie_core_t *core = NULL; - ie_network_t *network = NULL; - ie_executable_network_t *exe_network = NULL; - ie_infer_request_t *infer_request = NULL; + ie_core_t* core = NULL; + ie_network_t* network = NULL; + ie_executable_network_t* exe_network = NULL; + ie_infer_request_t* infer_request = NULL; ie_blob_t *imageInput = NULL, *output_blob = NULL; if (ParseAndCheckCommandLine(argc, argv) < 0) { @@ -312,7 +318,8 @@ int main(int argc, char **argv) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Read input ----------------------------------------------------------- + // --------------------------- Read input + // ----------------------------------------------------------- /** This file_paths stores paths to the processed images **/ parseInputFilesArguments(argc, argv_temp); if (!file_num) { @@ -322,14 +329,16 @@ int main(int argc, char **argv) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- printf("%sLoading Inference Engine\n", info); IEStatusCode status = ie_core_create("", &core); if (status != OK) goto err; - // ------------------------------ Get Available Devices ------------------------------------------------------ + // ------------------------------ Get Available Devices + // ------------------------------------------------------ ie_core_versions_t ver; printf("%sDevice info: \n", info); status = ie_core_get_versions(core, device_name, &ver); @@ -343,7 +352,8 @@ int main(int argc, char **argv) { ie_core_versions_free(&ver); if (custom_ex_library_msg) { - // Custom CPU extension is loaded as a shared library and passed as a pointer to base extension + // Custom CPU extension is loaded as a shared library and passed as a + // pointer to base extension status = ie_core_add_extension(core, custom_ex_library_msg, "CPU"); if (status != OK) goto err; @@ -351,7 +361,8 @@ int main(int argc, char **argv) { } if (custom_plugin_cfg_msg && (device_name == "GPU" || device_name == "MYRIAD" || device_name == "HDDL")) { - // Config for device plugin custom extension is loaded from an .xml description + // Config for device plugin custom extension is loaded from an .xml + // description ie_config_t cfg = {"CONFIG_FILE", custom_plugin_cfg_msg, NULL}; status = ie_core_set_config(core, &cfg, device_name); if (status != OK) @@ -360,7 +371,8 @@ int main(int argc, char **argv) { } // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin + // files) or ONNX (.onnx file) format printf("%sLoading network:\n", info); printf("\t%s\n", input_model); status = ie_core_read_network(core, input_model, NULL, &network); @@ -368,8 +380,10 @@ int main(int argc, char **argv) { goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- printf("%sPreparing input blobs\n", info); /** SSD network has one input and one output **/ @@ -381,11 +395,13 @@ int main(int argc, char **argv) { } /** - * Some networks have SSD-like output format (ending with DetectionOutput layer), but - * having 2 inputs as Faster-RCNN: one for image and one for "image info". + * Some networks have SSD-like output format (ending with DetectionOutput + * layer), but having 2 inputs as Faster-RCNN: one for image and one for + * "image info". * - * Although object_datection_sample_ssd's main task is to support clean SSD, it could score - * the networks with two inputs as well. For such networks imInfoInputName will contain the "second" input name. + * Although object_datection_sample_ssd's main task is to support clean SSD, + * it could score the networks with two inputs as well. For such networks + * imInfoInputName will contain the "second" input name. */ size_t input_width = 0, input_height = 0; @@ -393,7 +409,7 @@ int main(int argc, char **argv) { /** Iterating over all input blobs **/ for (i = 0; i < input_num; ++i) { - char *name = NULL; + char* name = NULL; status |= ie_network_get_input_name(network, i, &name); dimensions_t input_dim; status |= ie_network_get_input_dims(network, name, &input_dim); @@ -414,7 +430,7 @@ int main(int argc, char **argv) { imInfoInputName = name; status = ie_network_set_input_precision(network, name, FP32); - if (status !=OK || (input_dim.dims[1] != 3 && input_dim.dims[1] != 6)) { + if (status != OK || (input_dim.dims[1] != 3 && input_dim.dims[1] != 6)) { printf("Invalid input info. Should be 3 or 6 values length\n"); goto err; } @@ -434,8 +450,8 @@ int main(int argc, char **argv) { } /** Collect images data **/ - c_mat_t *originalImages = (c_mat_t *)calloc(file_num, sizeof(c_mat_t)); - c_mat_t *images = (c_mat_t *)calloc(file_num, sizeof(c_mat_t)); + c_mat_t* originalImages = (c_mat_t*)calloc(file_num, sizeof(c_mat_t)); + c_mat_t* images = (c_mat_t*)calloc(file_num, sizeof(c_mat_t)); if (!originalImages || !images) goto err; @@ -464,8 +480,7 @@ int main(int argc, char **argv) { for (j = 0; j < resized_img.mat_data_size; ++j) resized_img.mat_data[j] = img.mat_data[j]; } else { - printf("%sImage is resized from (%d, %d) to (%zu, %zu)\n", \ - warn, img.mat_width, img.mat_height, input_width, input_height); + printf("%sImage is resized from (%d, %d) to (%zu, %zu)\n", warn, img.mat_width, img.mat_height, input_width, input_height); if (image_resize(&img, &resized_img, (int)input_width, (int)input_height) == -1) { printf("%sImage %s cannot be resized!\n", warn, file_paths[i]); @@ -491,8 +506,10 @@ int main(int argc, char **argv) { if (status != OK) goto err; - /** Using ie_network_reshape() to set the batch size equal to the number of input images **/ - /** For input with NCHW/NHWC layout the first dimension N is the batch size **/ + /** Using ie_network_reshape() to set the batch size equal to the number of + * input images **/ + /** For input with NCHW/NHWC layout the first dimension N is the batch size + * **/ shapes.shapes[0].shape.dims[0] = image_num; status = ie_network_reshape(network, shapes); if (status != OK) @@ -507,7 +524,8 @@ int main(int argc, char **argv) { ie_network_input_shapes_free(&shapes2); printf("%sBatch size is %zu\n", info, batchSize); - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- printf("%sPreparing output blobs\n", info); size_t output_num = 0; @@ -518,8 +536,8 @@ int main(int argc, char **argv) { goto err; } - status = ie_network_get_output_name(network, output_num-1, &output_name); - if (status !=OK) + status = ie_network_get_output_name(network, output_num - 1, &output_name); + if (status != OK) goto err; dimensions_t output_dim; @@ -539,16 +557,18 @@ int main(int argc, char **argv) { goto err; } - /** Set the precision of output data provided by the user, should be called before load of the network to the device **/ + /** Set the precision of output data provided by the user, should be called + * before load of the network to the device **/ status = ie_network_set_output_precision(network, output_name, FP32); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ printf("%sLoading model to the device\n", info); if (config_msg) { - ie_config_t * config = parseConfig(config_msg, '#'); + ie_config_t* config = parseConfig(config_msg, '#'); status = ie_core_load_network(core, network, device_name, config, &exe_network); config_free(config); if (status != OK) { @@ -563,21 +583,24 @@ int main(int argc, char **argv) { // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- printf("%sCreate infer request\n", info); status = ie_exec_network_create_infer_request(exe_network, &infer_request); if (status != OK) goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- /** Creating input blob **/ status = ie_infer_request_get_blob(infer_request, imageInputName, &imageInput); if (status != OK) goto err; - /** Filling input tensor with images. First b channel, then g and r channels **/ + /** Filling input tensor with images. First b channel, then g and r channels + * **/ dimensions_t input_tensor_dims; status = ie_blob_get_dims(imageInput, &input_tensor_dims); if (status != OK) @@ -589,7 +612,7 @@ int main(int argc, char **argv) { status = ie_blob_get_buffer(imageInput, &blob_buffer); if (status != OK) goto err; - unsigned char *data = (unsigned char *)(blob_buffer.buffer); + unsigned char* data = (unsigned char*)(blob_buffer.buffer); /** Iterate over all input images **/ int image_id, pid, ch, k; @@ -598,9 +621,9 @@ int main(int argc, char **argv) { for (pid = 0; pid < image_size; ++pid) { /** Iterate over all channels **/ for (ch = 0; ch < num_channels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - data[image_id * image_size * num_channels + ch * image_size + pid] = - images[image_id].mat_data[pid * num_channels + ch]; + /** [images stride + channels stride + pixel id ] all in bytes + * **/ + data[image_id * image_size * num_channels + ch * image_size + pid] = images[image_id].mat_data[pid * num_channels + ch]; } } image_free(&images[image_id]); @@ -609,19 +632,19 @@ int main(int argc, char **argv) { ie_blob_free(&imageInput); if (imInfoInputName != NULL) { - ie_blob_t *input2 = NULL; + ie_blob_t* input2 = NULL; status = ie_infer_request_get_blob(infer_request, imInfoInputName, &input2); dimensions_t imInfoDim; status |= ie_blob_get_dims(input2, &imInfoDim); - //Fill input tensor with values + // Fill input tensor with values ie_blob_buffer_t info_blob_buffer; status |= ie_blob_get_buffer(input2, &info_blob_buffer); if (status != OK) { ie_blob_free(&input2); goto err; } - float *p = (float *)(info_blob_buffer.buffer); + float* p = (float*)(info_blob_buffer.buffer); for (image_id = 0; image_id < batchSize; ++image_id) { p[image_id * imInfoDim.dims[1] + 0] = (float)input_height; p[image_id * imInfoDim.dims[1] + 1] = (float)input_width; @@ -634,7 +657,8 @@ int main(int argc, char **argv) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference -------------------------------------------------------- + // --------------------------- Step 7. Do inference + // -------------------------------------------------------- printf("%sStart inference\n", info); status = ie_infer_request_infer_async(infer_request); status |= ie_infer_request_wait(infer_request, -1); @@ -642,7 +666,8 @@ int main(int argc, char **argv) { goto err; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------ + // --------------------------- Step 8. Process output + // ------------------------------------------------------ printf("%sProcessing output blobs\n", info); status = ie_infer_request_get_blob(infer_request, output_name, &output_blob); @@ -653,14 +678,14 @@ int main(int argc, char **argv) { status = ie_blob_get_cbuffer(output_blob, &output_blob_buffer); if (status != OK) goto err; - const float* detection = (float *)(output_blob_buffer.cbuffer); + const float* detection = (float*)(output_blob_buffer.cbuffer); - int **classes = (int **)calloc(image_num, sizeof(int *)); - rectangle_t **boxes = (rectangle_t **)calloc(image_num, sizeof(rectangle_t *)); - int *object_num = (int *)calloc(image_num, sizeof(int)); + int** classes = (int**)calloc(image_num, sizeof(int*)); + rectangle_t** boxes = (rectangle_t**)calloc(image_num, sizeof(rectangle_t*)); + int* object_num = (int*)calloc(image_num, sizeof(int)); for (i = 0; i < image_num; ++i) { - classes[i] = (int *)calloc(maxProposalCount, sizeof(int)); - boxes[i] = (rectangle_t *)calloc(maxProposalCount, sizeof(rectangle_t)); + classes[i] = (int*)calloc(maxProposalCount, sizeof(int)); + boxes[i] = (rectangle_t*)calloc(maxProposalCount, sizeof(rectangle_t)); object_num[i] = 0; } @@ -679,8 +704,7 @@ int main(int argc, char **argv) { int xmax = (int)(detection[curProposal * objectSize + 5] * originalImages[image_id].mat_width); int ymax = (int)(detection[curProposal * objectSize + 6] * originalImages[image_id].mat_height); - printf("[%d, %d] element, prob = %f (%d, %d)-(%d, %d) batch id : %d", \ - curProposal, label, confidence, xmin, ymin, xmax, ymax, image_id); + printf("[%d, %d] element, prob = %f (%d, %d)-(%d, %d) batch id : %d", curProposal, label, confidence, xmin, ymin, xmax, ymax, image_id); if (confidence > 0.5) { /** Drawing only objects with >50% probability **/ @@ -700,10 +724,10 @@ int main(int argc, char **argv) { if (object_num[batch_id] > 0) { image_add_rectangles(&originalImages[batch_id], boxes[batch_id], classes[batch_id], object_num[batch_id], 2); } - const char *out = "out_"; + const char* out = "out_"; char str_num[16] = {0}; int2str(str_num, batch_id); - char *img_path = (char *)calloc(strlen(out) + strlen(str_num) + strlen(".bmp") + 1, sizeof(char)); + char* img_path = (char*)calloc(strlen(out) + strlen(str_num) + strlen(".bmp") + 1, sizeof(char)); memcpy(img_path, out, strlen(out)); memcpy(img_path + strlen(out), str_num, strlen(str_num)); memcpy(img_path + strlen(out) + strlen(str_num), ".bmp", strlen(".bmp") + 1); @@ -716,7 +740,9 @@ int main(int argc, char **argv) { // ----------------------------------------------------------------------------------------------------- printf("%sExecution successful\n", info); - printf("\nThis sample is an API example, for any performance measurements please use the dedicated benchmark_app tool\n"); + printf("\nThis sample is an API example," + " for any performance measurements please use the dedicated benchmark_" + "app tool\n"); for (i = 0; i < image_num; ++i) { free(classes[i]); diff --git a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/object_detection_sample_ssd.h b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/object_detection_sample_ssd.h index e8e1c126e79..ec3a1b98fbd 100644 --- a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/object_detection_sample_ssd.h +++ b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/object_detection_sample_ssd.h @@ -7,32 +7,33 @@ #include /// @brief message for help argument -static const char *help_message = "Print a usage message."; +static const char* help_message = "Print a usage message."; /// @brief message for model argument static const char* model_message = "Required. Path to an .xml file with a trained model."; /// @brief message for images argument -static const char *image_message = "Required. Path to one or more images or folder with images."; +static const char* image_message = "Required. Path to one or more images or folder with images."; /// @brief message for assigning cnn calculation to device -static const char *target_device_message = "Optional. Specify the target device to infer. " \ -"Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ -"Sample will look for a suitable plugin for device specified."; +static const char* target_device_message = "Optional. Specify the target device to infer. " + "Default value is CPU. Use \"-d HETERO:\" format to specify " + "HETERO plugin. " + "Sample will look for a suitable plugin for device specified."; /// @brief message for plugin custom kernels desc -static const char *custom_plugin_config_message = "Required for GPU, MYRIAD, HDDL custom kernels. "\ -"Absolute path to the .xml config file with the kernels descriptions."; +static const char* custom_plugin_config_message = "Required for GPU, MYRIAD, HDDL custom kernels. " + "Absolute path to the .xml config file with the kernels descriptions."; /// @brief message for user extension library argument -static const char *custom_ex_library_message = "Required for CPU plugin custom layers. " \ -"Absolute path to a shared library with the kernels implementations."; +static const char* custom_ex_library_message = "Required for CPU plugin custom layers. " + "Absolute path to a shared library with the kernels implementations."; /// @brief message for config argument -static const char *config_message = "Path to the configuration file. Default value: \"config\"."; +static const char* config_message = "Path to the configuration file. Default value: \"config\"."; /** -* \brief This function show a help message -*/ + * \brief This function show a help message + */ static void showUsage() { printf("\nobject_detection_sample_ssd_c [OPTION]\n"); printf("Options:\n\n"); @@ -49,61 +50,63 @@ static void showUsage() { int opterr = 1; int optind = 1; int optopt; -char *optarg; +char* optarg; -#define ERR(s, c) if(opterr){\ - fputs(argv[0], stderr);\ - fputs(s, stderr);\ - fputc('\'', stderr);\ - fputc(c, stderr);\ - fputs("\'\n", stderr);} +#define ERR(s, c) \ + if (opterr) { \ + fputs(argv[0], stderr); \ + fputs(s, stderr); \ + fputc('\'', stderr); \ + fputc(c, stderr); \ + fputs("\'\n", stderr); \ + } /** -* @brief Check command line arguments with available options -* @param int argc - count of args -* @param char *argv[] - array values of args -* @param char *opts - array of options -* @return option name or -1(fail) -*/ -static int getopt(int argc, char **argv, char *opts) { + * @brief Check command line arguments with available options + * @param int argc - count of args + * @param char *argv[] - array values of args + * @param char *opts - array of options + * @return option name or -1(fail) + */ +static int getopt(int argc, char** argv, char* opts) { static int sp = 1; register int c = 0; - register char *cp = NULL; + register char* cp = NULL; if (sp == 1) { - if(optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') + if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return -1; - else if(strcmp(argv[optind], "--") == 0) { + else if (strcmp(argv[optind], "--") == 0) { optind++; return -1; } optopt = c = argv[optind][sp]; - if(c == ':' || (cp = strchr(opts, c)) == 0) { + if (c == ':' || (cp = strchr(opts, c)) == 0) { ERR(": unrecognized option -- ", c); showUsage(); - if(argv[optind][++sp] == '\0') { + if (argv[optind][++sp] == '\0') { optind++; sp = 1; } - return('?'); + return ('?'); } - if(*++cp == ':') { - if(argv[optind][sp+1] != '\0') - optarg = &argv[optind++][sp+1]; - else if(++optind >= argc) { + if (*++cp == ':') { + if (argv[optind][sp + 1] != '\0') + optarg = &argv[optind++][sp + 1]; + else if (++optind >= argc) { ERR(": option requires an argument -- ", c); sp = 1; - return('?'); + return ('?'); } else optarg = argv[optind++]; sp = 1; } else { - if(argv[optind][++sp] == '\0') { + if (argv[optind][++sp] == '\0') { sp = 1; optind++; } optarg = NULL; } } - return(c); + return (c); } diff --git a/inference-engine/samples/.clang-format b/inference-engine/samples/.clang-format new file mode 100644 index 00000000000..c93e6254b5b --- /dev/null +++ b/inference-engine/samples/.clang-format @@ -0,0 +1,25 @@ +BasedOnStyle: Google +IndentWidth: 4 +UseTab: Never + +Language: Cpp +Standard: Cpp11 + +AccessModifierOffset: -4 +AlignConsecutiveMacros: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: false +AlwaysBreakBeforeMultilineStrings: false +ColumnLimit: 160 +# Specialize this comment pragma in order to avoid changes in SEA copyrights +CommentPragmas: '^#' +DerivePointerAlignment: false +FixNamespaceComments: true +IndentCaseLabels: false +IndentPPDirectives: BeforeHash +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: false \ No newline at end of file diff --git a/inference-engine/samples/CMakeLists.txt b/inference-engine/samples/CMakeLists.txt index 25a5b863a59..b60a97e1c1f 100644 --- a/inference-engine/samples/CMakeLists.txt +++ b/inference-engine/samples/CMakeLists.txt @@ -191,10 +191,10 @@ include(CMakeParseArguments) # [INCLUDE_DIRECTORIES ] # [DEPENDENCIES ] # [OPENCV_DEPENDENCIES ] -# [EXCLUDE_CPPLINT] +# [EXCLUDE_CLANG_FORMAT] # macro(ie_add_sample) - set(options EXCLUDE_CPPLINT) + set(options EXCLUDE_CLANG_FORMAT) set(oneValueArgs NAME) set(multiValueArgs SOURCES HEADERS DEPENDENCIES OPENCV_DEPENDENCIES INCLUDE_DIRECTORIES) cmake_parse_arguments(IE_SAMPLE "${options}" "${oneValueArgs}" @@ -211,13 +211,13 @@ macro(ie_add_sample) # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj - source_group("src" FILES ${IE_SAMPLES_SOURCES}) - if(IE_SAMPLES_HEADERS) - source_group("include" FILES ${IE_SAMPLES_HEADERS}) + source_group("src" FILES ${IE_SAMPLE_SOURCES}) + if(IE_SAMPLE_HEADERS) + source_group("include" FILES ${IE_SAMPLE_HEADERS}) endif() # Create executable file from sources - add_executable(${IE_SAMPLE_NAME} ${IE_SAMPLE_SOURCES} ${IE_SAMPLES_HEADERS}) + add_executable(${IE_SAMPLE_NAME} ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS}) if(IE_SAMPLE_OPENCV_DEPENDENCIES) target_compile_definitions(${IE_SAMPLE_NAME} PRIVATE USE_OPENCV) endif() @@ -248,12 +248,8 @@ macro(ie_add_sample) endif() add_dependencies(ie_samples ${IE_SAMPLE_NAME}) - if(COMMAND add_cpplint_target AND NOT IE_SAMPLE_EXCLUDE_CPPLINT) - if(c_sample) - set(custom_filters "-readability/casting") - endif() - add_cpplint_target(${IE_SAMPLE_NAME}_cpplint FOR_TARGETS ${IE_SAMPLE_NAME} - CUSTOM_FILTERS ${custom_filters}) + if(COMMAND add_clang_format_target AND NOT IE_SAMPLE_EXCLUDE_CLANG_FORMAT) + add_clang_format_target(${IE_SAMPLE_NAME}_clang FOR_SOURCES ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS}) endif() endmacro() diff --git a/inference-engine/samples/benchmark_app/benchmark_app.hpp b/inference-engine/samples/benchmark_app/benchmark_app.hpp index 66f9d0b2224..4abad5ee24f 100644 --- a/inference-engine/samples/benchmark_app/benchmark_app.hpp +++ b/inference-engine/samples/benchmark_app/benchmark_app.hpp @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /// @brief message for help argument static const char help_message[] = "Print a usage message"; @@ -16,20 +17,22 @@ static const char help_message[] = "Print a usage message"; static const char input_message[] = "Optional. Path to a folder with images and/or binaries or to specific image or binary file."; /// @brief message for model argument -static const char model_message[] = "Required. Path to an .xml/.onnx/.prototxt file with a trained model or to a .blob files with a trained compiled model."; +static const char model_message[] = "Required. Path to an .xml/.onnx/.prototxt file with a trained model or to a .blob files with " + "a trained compiled model."; /// @brief message for execution mode static const char api_message[] = "Optional. Enable Sync/Async API. Default value is \"async\"."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify a target device to infer on (the list of available devices is shown below). " \ -"Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ -"Use \"-d MULTI:\" format to specify MULTI plugin. " \ -"The application looks for a suitable plugin for the specified device."; +static const char target_device_message[] = "Optional. Specify a target device to infer on (the list of available devices is shown below). " + "Default value is CPU. Use \"-d HETERO:\" format to specify " + "HETERO plugin. " + "Use \"-d MULTI:\" format to specify MULTI plugin. " + "The application looks for a suitable plugin for the specified device."; /// @brief message for iterations count -static const char iterations_count_message[] = "Optional. Number of iterations. " \ -"If not specified, the number of iterations is calculated depending on a device."; +static const char iterations_count_message[] = "Optional. Number of iterations. " + "If not specified, the number of iterations is calculated depending on a device."; /// @brief message for requests count static const char infer_requests_count_message[] = "Optional. Number of infer requests. Default value is determined automatically for device."; @@ -43,33 +46,40 @@ static const char infer_num_threads_message[] = "Optional. Number of threads to /// @brief message for #streams for CPU inference static const char infer_num_streams_message[] = "Optional. Number of streams to use for inference on the CPU, GPU or MYRIAD devices " - "(for HETERO and MULTI device cases use format :,: or just ). " - "Default value is determined automatically for a device.Please note that although the automatic selection " - "usually provides a reasonable performance, it still may be non - optimal for some cases, especially for " + "(for HETERO and MULTI device cases use format :,: or just " + "). " + "Default value is determined automatically for a device.Please note that although the " + "automatic selection " + "usually provides a reasonable performance, it still may be non - optimal for some cases, " + "especially for " "very small networks. See sample's README for more details. " "Also, using nstreams>1 is inherently throughput-oriented option, " "while for the best-latency estimations the number of streams should be set to 1."; /// @brief message for enforcing of BF16 execution where it is possible -static const char enforce_bf16_message[] = "Optional. By default floating point operations execution in bfloat16 precision are enforced if supported by platform.\n" +static const char enforce_bf16_message[] = "Optional. By default floating point operations execution in bfloat16 precision are enforced " + "if supported by platform.\n" " 'true' - enable bfloat16 regardless of platform support\n" " 'false' - disable bfloat16 regardless of platform support"; /// @brief message for user library argument -static const char custom_cpu_library_message[] = "Required for CPU custom layers. Absolute path to a shared library with the kernels implementations."; +static const char custom_cpu_library_message[] = "Required for CPU custom layers. Absolute path to a shared library with the kernels " + "implementations."; /// @brief message for clDNN custom kernels desc static const char custom_cldnn_message[] = "Required for GPU custom kernels. Absolute path to an .xml file with the kernels description."; -static const char batch_size_message[] = "Optional. Batch size value. If not specified, the batch size value is determined from Intermediate Representation."; +static const char batch_size_message[] = "Optional. Batch size value. If not specified, the batch size value is determined from " + "Intermediate Representation."; // @brief message for CPU threads pinning option -static const char infer_threads_pinning_message[] = "Optional. Enable threads->cores (\"YES\", default), threads->(NUMA)nodes (\"NUMA\") " \ - "or completely disable (\"NO\") " \ +static const char infer_threads_pinning_message[] = "Optional. Enable threads->cores (\"YES\", default), threads->(NUMA)nodes (\"NUMA\") " + "or completely disable (\"NO\") " "CPU threads pinning for CPU-involved inference."; // @brief message for stream_output option -static const char stream_output_message[] = "Optional. Print progress as a plain text. When specified, an interactive progress bar is replaced with a " +static const char stream_output_message[] = "Optional. Print progress as a plain text. When specified, an interactive progress bar is " + "replaced with a " "multiline output."; // @brief message for report_type option @@ -87,7 +97,8 @@ static const char report_folder_message[] = "Optional. Path to a folder where st static const char exec_graph_path_message[] = "Optional. Path to a file where to store executable graph information serialized."; // @brief message for progress bar option -static const char progress_message[] = "Optional. Show progress bar (can affect performance measurement). Default values is \"false\"."; +static const char progress_message[] = "Optional. Show progress bar (can affect performance measurement). Default values is " + "\"false\"."; // @brief message for performance counters option static const char pc_message[] = "Optional. Report performance counters."; @@ -95,13 +106,15 @@ static const char pc_message[] = "Optional. Report performance counters."; #ifdef USE_OPENCV // @brief message for load config option static const char load_config_message[] = "Optional. Path to XML/YAML/JSON file to load custom IE parameters." - " Please note, command line parameters have higher priority then parameters from configuration file."; + " Please note, command line parameters have higher priority then parameters from configuration " + "file."; // @brief message for dump config option static const char dump_config_message[] = "Optional. Path to XML/YAML/JSON file to dump IE parameters, which were set by application."; #endif -static const char shape_message[] = "Optional. Set shape for input. For example, \"input1[1,3,224,224],input2[1,4]\" or \"[1,3,224,224]\"" +static const char shape_message[] = "Optional. Set shape for input. For example, \"input1[1,3,224,224],input2[1,4]\" or " + "\"[1,3,224,224]\"" " in case of one input size."; static const char layout_message[] = "Optional. Prompts how network layouts should be treated by application. " @@ -110,17 +123,15 @@ static const char layout_message[] = "Optional. Prompts how network layouts shou // @brief message for quantization bits static const char gna_qb_message[] = "Optional. Weight bits for quantization: 8 or 16 (default)"; -static constexpr char inputs_precision_message[] = - "Optional. Specifies precision for all input layers of the network."; +static constexpr char inputs_precision_message[] = "Optional. Specifies precision for all input layers of the network."; -static constexpr char outputs_precision_message[] = - "Optional. Specifies precision for all output layers of the network."; +static constexpr char outputs_precision_message[] = "Optional. Specifies precision for all output layers of the network."; -static constexpr char iop_message[] = - "Optional. Specifies precision for input and output layers by name.\n" -" Example: -iop \"input:FP16, output:FP16\".\n" -" Notice that quotes are required.\n" -" Overwrites precision from ip and op options for specified layers."; +static constexpr char iop_message[] = "Optional. Specifies precision for input and output layers by name.\n" + " Example: -iop \"input:FP16, output:FP16\".\n" + " Notice that quotes are required.\n" + " Overwrites precision from ip and op options for " + "specified layers."; /// @brief Define flag for showing help message
DEFINE_bool(h, false, help_message); @@ -161,7 +172,8 @@ DEFINE_uint32(t, 0, execution_time_message); /// @brief Number of infer requests in parallel DEFINE_uint32(nireq, 0, infer_requests_count_message); -/// @brief Number of threads to use for inference on the CPU in throughput mode (also affects Hetero cases) +/// @brief Number of threads to use for inference on the CPU in throughput mode (also affects Hetero +/// cases) DEFINE_uint32(nthreads, 0, infer_num_threads_message); /// @brief Number of streams to use for inference on the CPU (also affects Hetero cases) @@ -225,8 +237,8 @@ DEFINE_string(op, "", outputs_precision_message); DEFINE_string(iop, "", iop_message); /** -* @brief This function show a help message -*/ + * @brief This function show a help message + */ static void showUsage() { std::cout << std::endl; std::cout << "benchmark_app [OPTION]" << std::endl; @@ -263,7 +275,7 @@ static void showUsage() { std::cout << " -load_config " << load_config_message << std::endl; #endif std::cout << " -qb " << gna_qb_message << std::endl; - std::cout << " -ip " << inputs_precision_message << std::endl; - std::cout << " -op " << outputs_precision_message << std::endl; - std::cout << " -iop \"\" " << iop_message << std::endl; + std::cout << " -ip " << inputs_precision_message << std::endl; + std::cout << " -op " << outputs_precision_message << std::endl; + std::cout << " -iop \"\" " << iop_message << std::endl; } diff --git a/inference-engine/samples/benchmark_app/infer_request_wrap.hpp b/inference-engine/samples/benchmark_app/infer_request_wrap.hpp index 85d6f679d8a..741b2ad7f13 100644 --- a/inference-engine/samples/benchmark_app/infer_request_wrap.hpp +++ b/inference-engine/samples/benchmark_app/infer_request_wrap.hpp @@ -4,18 +4,18 @@ #pragma once -#include -#include -#include -#include -#include +#include #include #include -#include -#include #include - #include +#include +#include +#include +#include +#include +#include + #include "statistics_report.hpp" typedef std::chrono::high_resolution_clock Time; @@ -30,15 +30,12 @@ public: ~InferReqWrap() = default; - explicit InferReqWrap(InferenceEngine::ExecutableNetwork& net, size_t id, QueueCallbackFunction callbackQueue) : - _request(net.CreateInferRequest()), - _id(id), - _callbackQueue(callbackQueue) { - _request.SetCompletionCallback( - [&]() { - _endTime = Time::now(); - _callbackQueue(_id, getExecutionTimeInMilliseconds()); - }); + explicit InferReqWrap(InferenceEngine::ExecutableNetwork& net, size_t id, QueueCallbackFunction callbackQueue) + : _request(net.CreateInferRequest()), _id(id), _callbackQueue(callbackQueue) { + _request.SetCompletionCallback([&]() { + _endTime = Time::now(); + _callbackQueue(_id, getExecutionTimeInMilliseconds()); + }); } void startAsync() { @@ -61,7 +58,7 @@ public: return _request.GetPerformanceCounts(); } - InferenceEngine::Blob::Ptr getBlob(const std::string &name) { + InferenceEngine::Blob::Ptr getBlob(const std::string& name) { return _request.GetBlob(name); } @@ -82,9 +79,8 @@ class InferRequestsQueue final { public: InferRequestsQueue(InferenceEngine::ExecutableNetwork& net, size_t nireq) { for (size_t id = 0; id < nireq; id++) { - requests.push_back(std::make_shared(net, id, std::bind(&InferRequestsQueue::putIdleRequest, this, - std::placeholders::_1, - std::placeholders::_2))); + requests.push_back( + std::make_shared(net, id, std::bind(&InferRequestsQueue::putIdleRequest, this, std::placeholders::_1, std::placeholders::_2))); _idleIds.push(id); } resetTimes(); @@ -108,8 +104,7 @@ public: return std::chrono::duration_cast(_endTime - _startTime).count() * 0.000001; } - void putIdleRequest(size_t id, - const double latency) { + void putIdleRequest(size_t id, const double latency) { std::unique_lock lock(_mutex); _latencies.push_back(latency); _idleIds.push(id); @@ -119,7 +114,9 @@ public: InferReqWrap::Ptr getIdleRequest() { std::unique_lock lock(_mutex); - _cv.wait(lock, [this]{ return _idleIds.size() > 0; }); + _cv.wait(lock, [this] { + return _idleIds.size() > 0; + }); auto request = requests.at(_idleIds.front()); _idleIds.pop(); _startTime = std::min(Time::now(), _startTime); @@ -128,7 +125,9 @@ public: void waitAll() { std::unique_lock lock(_mutex); - _cv.wait(lock, [this]{ return _idleIds.size() == requests.size(); }); + _cv.wait(lock, [this] { + return _idleIds.size() == requests.size(); + }); } std::vector getLatencies() { @@ -138,7 +137,7 @@ public: std::vector requests; private: - std::queue_idleIds; + std::queue _idleIds; std::mutex _mutex; std::condition_variable _cv; Time::time_point _startTime; diff --git a/inference-engine/samples/benchmark_app/inputs_filling.cpp b/inference-engine/samples/benchmark_app/inputs_filling.cpp index c024e00c7bc..e12f7656f17 100644 --- a/inference-engine/samples/benchmark_app/inputs_filling.cpp +++ b/inference-engine/samples/benchmark_app/inputs_filling.cpp @@ -2,36 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include +#include "inputs_filling.hpp" #include -#include -#include "inputs_filling.hpp" +#include +#include +#include +#include +#include +#include using namespace InferenceEngine; #ifdef USE_OPENCV -static const std::vector supported_image_extensions = { "bmp", "dib", - "jpeg", "jpg", "jpe", - "jp2", - "png", - "pbm", "pgm", "ppm", - "sr", "ras", - "tiff", "tif" }; +static const std::vector supported_image_extensions = {"bmp", "dib", "jpeg", "jpg", "jpe", "jp2", "png", + "pbm", "pgm", "ppm", "sr", "ras", "tiff", "tif"}; #else -static const std::vector supported_image_extensions = { "bmp" }; +static const std::vector supported_image_extensions = {"bmp"}; #endif -static const std::vector supported_binary_extensions = { "bin" }; +static const std::vector supported_binary_extensions = {"bin"}; -std::vector filterFilesByExtensions(const std::vector& filePaths, - const std::vector& extensions) { +std::vector filterFilesByExtensions(const std::vector& filePaths, const std::vector& extensions) { std::vector filtered; - auto getExtension = [](const std::string &name) { + auto getExtension = [](const std::string& name) { auto extensionPosition = name.rfind('.', name.size()); return extensionPosition == std::string::npos ? "" : name.substr(extensionPosition + 1, name.size() - 1); }; @@ -45,27 +39,24 @@ std::vector filterFilesByExtensions(const std::vector& return filtered; } -void fillBlobImage(Blob::Ptr& inputBlob, - const std::vector& filePaths, - const size_t& batchSize, - const benchmark_app::InputInfo& app_info, - const size_t& requestId, - const size_t& inputId, - const size_t& inputSize) { +void fillBlobImage(Blob::Ptr& inputBlob, const std::vector& filePaths, const size_t& batchSize, const benchmark_app::InputInfo& app_info, + const size_t& requestId, const size_t& inputId, const size_t& inputSize) { MemoryBlob::Ptr minput = as(inputBlob); if (!minput) { - IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in fillBlobImage, " << - "but by fact we were not able to cast inputBlob to MemoryBlob"; + IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in " + "fillBlobImage, " + << "but by fact we were not able to cast inputBlob to MemoryBlob"; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto minputHolder = minput->wmap(); - auto inputBlobData = minputHolder.as(); + auto inputBlobData = minputHolder.as(); /** Collect images data ptrs **/ std::vector> vreader; vreader.reserve(batchSize); - for (size_t i = 0ULL, inputIndex = requestId*batchSize*inputSize + inputId; i < batchSize; i++, inputIndex += inputSize) { + for (size_t i = 0ULL, inputIndex = requestId * batchSize * inputSize + inputId; i < batchSize; i++, inputIndex += inputSize) { inputIndex %= filePaths.size(); slog::info << "Prepare image " << filePaths[inputIndex] << slog::endl; @@ -94,10 +85,11 @@ void fillBlobImage(Blob::Ptr& inputBlob, for (size_t h = 0; h < app_info.height(); ++h) { /** Iterate over all channels **/ for (size_t ch = 0; ch < numChannels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - size_t offset = imageId * numChannels * width * height + - (((app_info.layout == "NCHW") || (app_info.layout == "CHW")) ? - (ch * width * height + h * width + w) : (h * width * numChannels + w * numChannels + ch)); + /** [images stride + channels stride + pixel id ] all in + * bytes **/ + size_t offset = imageId * numChannels * width * height + (((app_info.layout == "NCHW") || (app_info.layout == "CHW")) + ? (ch * width * height + h * width + w) + : (h * width * numChannels + w * numChannels + ch)); inputBlobData[offset] = vreader.at(imageId).get()[h * width * numChannels + w * numChannels + ch]; } } @@ -105,23 +97,21 @@ void fillBlobImage(Blob::Ptr& inputBlob, } } -template -void fillBlobBinary(Blob::Ptr& inputBlob, - const std::vector& filePaths, - const size_t& batchSize, - const size_t& requestId, - const size_t& inputId, +template +void fillBlobBinary(Blob::Ptr& inputBlob, const std::vector& filePaths, const size_t& batchSize, const size_t& requestId, const size_t& inputId, const size_t& inputSize) { MemoryBlob::Ptr minput = as(inputBlob); if (!minput) { - IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in fillBlobBinary, " << - "but by fact we were not able to cast inputBlob to MemoryBlob"; + IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in " + "fillBlobBinary, " + << "but by fact we were not able to cast inputBlob to MemoryBlob"; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto minputHolder = minput->wmap(); - auto inputBlobData = minputHolder.as(); - for (size_t i = 0ULL, inputIndex = requestId*batchSize*inputSize + inputId; i < batchSize; i++, inputIndex += inputSize) { + auto inputBlobData = minputHolder.as(); + for (size_t i = 0ULL, inputIndex = requestId * batchSize * inputSize + inputId; i < batchSize; i++, inputIndex += inputSize) { inputIndex %= filePaths.size(); slog::info << "Prepare binary file " << filePaths[inputIndex] << slog::endl; @@ -135,39 +125,35 @@ void fillBlobBinary(Blob::Ptr& inputBlob, if (!binaryFile.good()) { IE_THROW() << "Can not read " << filePaths[inputIndex]; } - auto inputSize = inputBlob->size()*sizeof(T)/batchSize; + auto inputSize = inputBlob->size() * sizeof(T) / batchSize; if (fileSize != inputSize) { - IE_THROW() << "File " << filePaths[inputIndex] << " contains " << std::to_string(fileSize) << " bytes " - "but the network expects " << std::to_string(inputSize); + IE_THROW() << "File " << filePaths[inputIndex] << " contains " << std::to_string(fileSize) + << " bytes " + "but the network expects " + << std::to_string(inputSize); } - binaryFile.read(&inputBlobData[i*inputSize], inputSize); + binaryFile.read(&inputBlobData[i * inputSize], inputSize); } } -template +template using uniformDistribution = - typename std::conditional< - std::is_floating_point::value, - std::uniform_real_distribution, - typename std::conditional< - std::is_integral::value, - std::uniform_int_distribution, - void>::type - >::type; + typename std::conditional::value, std::uniform_real_distribution, + typename std::conditional::value, std::uniform_int_distribution, void>::type>::type; -template -void fillBlobRandom(Blob::Ptr& inputBlob, - T rand_min = std::numeric_limits::min(), - T rand_max = std::numeric_limits::max()) { +template +void fillBlobRandom(Blob::Ptr& inputBlob, T rand_min = std::numeric_limits::min(), T rand_max = std::numeric_limits::max()) { MemoryBlob::Ptr minput = as(inputBlob); if (!minput) { - IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in fillBlobRandom, " - << "but by fact we were not able to cast inputBlob to MemoryBlob"; + IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in " + "fillBlobRandom, " + << "but by fact we were not able to cast inputBlob to MemoryBlob"; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto minputHolder = minput->wmap(); - auto inputBlobData = minputHolder.as(); + auto inputBlobData = minputHolder.as(); std::mt19937 gen(0); uniformDistribution distribution(rand_min, rand_max); for (size_t i = 0; i < inputBlob->size(); i++) { @@ -175,23 +161,23 @@ void fillBlobRandom(Blob::Ptr& inputBlob, } } -template -void fillBlobImInfo(Blob::Ptr& inputBlob, - const size_t& batchSize, - std::pair image_size) { +template +void fillBlobImInfo(Blob::Ptr& inputBlob, const size_t& batchSize, std::pair image_size) { MemoryBlob::Ptr minput = as(inputBlob); if (!minput) { - IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in fillBlobImInfo, " << - "but by fact we were not able to cast inputBlob to MemoryBlob"; + IE_THROW() << "We expect inputBlob to be inherited from MemoryBlob in " + "fillBlobImInfo, " + << "but by fact we were not able to cast inputBlob to MemoryBlob"; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto minputHolder = minput->wmap(); - auto inputBlobData = minputHolder.as(); + auto inputBlobData = minputHolder.as(); for (size_t b = 0; b < batchSize; b++) { - size_t iminfoSize = inputBlob->size()/batchSize; + size_t iminfoSize = inputBlob->size() / batchSize; for (size_t i = 0; i < iminfoSize; i++) { - size_t index = b*iminfoSize + i; + size_t index = b * iminfoSize + i; if (0 == i) inputBlobData[index] = static_cast(image_size.first); else if (1 == i) @@ -202,17 +188,14 @@ void fillBlobImInfo(Blob::Ptr& inputBlob, } } -void fillBlobs(const std::vector& inputFiles, - const size_t& batchSize, - benchmark_app::InputsInfo& app_inputs_info, +void fillBlobs(const std::vector& inputFiles, const size_t& batchSize, benchmark_app::InputsInfo& app_inputs_info, std::vector requests) { std::vector> input_image_sizes; for (auto& item : app_inputs_info) { if (item.second.isImage()) { input_image_sizes.push_back(std::make_pair(item.second.width(), item.second.height())); } - slog::info << "Network input '" << item.first << "' precision " << item.second.precision - << ", dimensions (" << item.second.layout << "): "; + slog::info << "Network input '" << item.first << "' precision " << item.second.precision << ", dimensions (" << item.second.layout << "): "; for (const auto& i : item.second.shape) { slog::info << i << " "; } @@ -226,48 +209,52 @@ void fillBlobs(const std::vector& inputFiles, std::vector imageFiles; if (inputFiles.empty()) { - slog::warn << "No input files were given: all inputs will be filled with random values!" << slog::endl; + slog::warn << "No input files were given: all inputs will be filled with " + "random values!" + << slog::endl; } else { binaryFiles = filterFilesByExtensions(inputFiles, supported_binary_extensions); std::sort(std::begin(binaryFiles), std::end(binaryFiles)); - auto binaryToBeUsed = binaryInputCount*batchSize*requests.size(); + auto binaryToBeUsed = binaryInputCount * batchSize * requests.size(); if (binaryToBeUsed > 0 && binaryFiles.empty()) { std::stringstream ss; for (auto& ext : supported_binary_extensions) { - if (!ss.str().empty()) { - ss << ", "; - } - ss << ext; + if (!ss.str().empty()) { + ss << ", "; + } + ss << ext; } - slog::warn << "No supported binary inputs found! Please check your file extensions: " << ss.str() << slog::endl; + slog::warn << "No supported binary inputs found! Please check your file " + "extensions: " + << ss.str() << slog::endl; } else if (binaryToBeUsed > binaryFiles.size()) { - slog::warn << "Some binary input files will be duplicated: " << binaryToBeUsed << - " files are required but only " << binaryFiles.size() << " are provided" << slog::endl; + slog::warn << "Some binary input files will be duplicated: " << binaryToBeUsed << " files are required but only " << binaryFiles.size() + << " are provided" << slog::endl; } else if (binaryToBeUsed < binaryFiles.size()) { - slog::warn << "Some binary input files will be ignored: only " << binaryToBeUsed << - " are required from " << binaryFiles.size() << slog::endl; + slog::warn << "Some binary input files will be ignored: only " << binaryToBeUsed << " are required from " << binaryFiles.size() << slog::endl; } imageFiles = filterFilesByExtensions(inputFiles, supported_image_extensions); std::sort(std::begin(imageFiles), std::end(imageFiles)); - auto imagesToBeUsed = imageInputCount*batchSize*requests.size(); + auto imagesToBeUsed = imageInputCount * batchSize * requests.size(); if (imagesToBeUsed > 0 && imageFiles.empty()) { - std::stringstream ss; - for (auto& ext : supported_image_extensions) { - if (!ss.str().empty()) { - ss << ", "; + std::stringstream ss; + for (auto& ext : supported_image_extensions) { + if (!ss.str().empty()) { + ss << ", "; + } + ss << ext; } - ss << ext; - } - slog::warn << "No supported image inputs found! Please check your file extensions: " << ss.str() << slog::endl; + slog::warn << "No supported image inputs found! Please check your file " + "extensions: " + << ss.str() << slog::endl; } else if (imagesToBeUsed > imageFiles.size()) { - slog::warn << "Some image input files will be duplicated: " << imagesToBeUsed << - " files are required but only " << imageFiles.size() << " are provided" << slog::endl; + slog::warn << "Some image input files will be duplicated: " << imagesToBeUsed << " files are required but only " << imageFiles.size() + << " are provided" << slog::endl; } else if (imagesToBeUsed < imageFiles.size()) { - slog::warn << "Some image input files will be ignored: only " << imagesToBeUsed << - " are required from " << imageFiles.size() << slog::endl; + slog::warn << "Some image input files will be ignored: only " << imagesToBeUsed << " are required from " << imageFiles.size() << slog::endl; } } @@ -308,8 +295,7 @@ void fillBlobs(const std::vector& inputFiles, if (app_info.isImageInfo() && (input_image_sizes.size() == 1)) { // Most likely it is image info: fill with image information auto image_size = input_image_sizes.at(0); - slog::info << "Fill input '" << item.first << "' with image size " << image_size.first << "x" - << image_size.second << slog::endl; + slog::info << "Fill input '" << item.first << "' with image size " << image_size.first << "x" << image_size.second << slog::endl; if (precision == InferenceEngine::Precision::FP32) { fillBlobImInfo(inputBlob, batchSize, image_size); } else if (precision == InferenceEngine::Precision::FP16) { @@ -325,8 +311,7 @@ void fillBlobs(const std::vector& inputFiles, } } // Fill random - slog::info << "Fill input '" << item.first << "' with random values (" - << std::string((app_info.isImage() ? "image" : "some binary data")) + slog::info << "Fill input '" << item.first << "' with random values (" << std::string((app_info.isImage() ? "image" : "some binary data")) << " is expected)" << slog::endl; if (precision == InferenceEngine::Precision::FP32) { fillBlobRandom(inputBlob); @@ -337,10 +322,12 @@ void fillBlobs(const std::vector& inputFiles, } else if (precision == InferenceEngine::Precision::I64) { fillBlobRandom(inputBlob); } else if (precision == InferenceEngine::Precision::U8) { - // uniform_int_distribution is not allowed in the C++17 standard and vs2017/19 + // uniform_int_distribution is not allowed in the C++17 + // standard and vs2017/19 fillBlobRandom(inputBlob); } else if (precision == InferenceEngine::Precision::I8) { - // uniform_int_distribution is not allowed in the C++17 standard and vs2017/19 + // uniform_int_distribution is not allowed in the C++17 standard + // and vs2017/19 fillBlobRandom(inputBlob); } else if (precision == InferenceEngine::Precision::U16) { fillBlobRandom(inputBlob); diff --git a/inference-engine/samples/benchmark_app/inputs_filling.hpp b/inference-engine/samples/benchmark_app/inputs_filling.hpp index 82ceefdf188..4410faae11e 100644 --- a/inference-engine/samples/benchmark_app/inputs_filling.hpp +++ b/inference-engine/samples/benchmark_app/inputs_filling.hpp @@ -4,15 +4,12 @@ #pragma once +#include #include #include -#include - -#include "utils.hpp" #include "infer_request_wrap.hpp" +#include "utils.hpp" -void fillBlobs(const std::vector& inputFiles, - const size_t& batchSize, - benchmark_app::InputsInfo& app_inputs_info, +void fillBlobs(const std::vector& inputFiles, const size_t& batchSize, benchmark_app::InputsInfo& app_inputs_info, std::vector requests); diff --git a/inference-engine/samples/benchmark_app/main.cpp b/inference-engine/samples/benchmark_app/main.cpp index ed2153c2bd9..7b540bb60f3 100644 --- a/inference-engine/samples/benchmark_app/main.cpp +++ b/inference-engine/samples/benchmark_app/main.cpp @@ -4,25 +4,24 @@ #include #include -#include -#include -#include -#include -#include - -#include -#include #include #include +#include +#include +#include +#include #include #include -#include +#include +#include +#include +#include #include "benchmark_app.hpp" #include "infer_request_wrap.hpp" +#include "inputs_filling.hpp" #include "progress_bar.hpp" #include "statistics_report.hpp" -#include "inputs_filling.hpp" #include "utils.hpp" using namespace InferenceEngine; @@ -37,8 +36,9 @@ uint64_t getDurationInNanoseconds(uint32_t duration) { return duration * 1000000000LL; } -bool ParseAndCheckCommandLine(int argc, char *argv[]) { - // ---------------------------Parsing and validating input arguments-------------------------------------- +bool ParseAndCheckCommandLine(int argc, char* argv[]) { + // ---------------------------Parsing and validating input + // arguments-------------------------------------- slog::info << "Parsing input parameters" << slog::endl; gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true); if (FLAGS_help || FLAGS_h) { @@ -56,8 +56,7 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { throw std::logic_error("Incorrect API. Please set -api option to `sync` or `async` value."); } - if (!FLAGS_report_type.empty() && - FLAGS_report_type != noCntReport && FLAGS_report_type != averageCntReport && FLAGS_report_type != detailedCntReport) { + if (!FLAGS_report_type.empty() && FLAGS_report_type != noCntReport && FLAGS_report_type != averageCntReport && FLAGS_report_type != detailedCntReport) { std::string err = "only " + std::string(noCntReport) + "/" + std::string(averageCntReport) + "/" + std::string(detailedCntReport) + " report types are supported (invalid -report_type option value)"; throw std::logic_error(err); @@ -70,8 +69,8 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { bool isNetworkCompiled = fileExt(FLAGS_m) == "blob"; bool isPrecisionSet = !(FLAGS_ip.empty() && FLAGS_op.empty() && FLAGS_iop.empty()); if (isNetworkCompiled && isPrecisionSet) { - std::string err = std::string("Cannot set precision for a compiled network. ") + - std::string("Please re-compile your network with required precision using compile_tool"); + std::string err = std::string("Cannot set precision for a compiled network. ") + std::string("Please re-compile your network with required precision " + "using compile_tool"); throw std::logic_error(err); } @@ -80,19 +79,17 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { static void next_step(const std::string additional_info = "") { static size_t step_id = 0; - static const std::map step_names = { - { 1, "Parsing and validating input arguments" }, - { 2, "Loading Inference Engine" }, - { 3, "Setting device configuration" }, - { 4, "Reading network files" }, - { 5, "Resizing network to match image sizes and given batch" }, - { 6, "Configuring input of the model" }, - { 7, "Loading the model to the device" }, - { 8, "Setting optimal runtime parameters" }, - { 9, "Creating infer requests and filling input blobs with images" }, - { 10, "Measuring performance" }, - { 11, "Dumping statistics report" } - }; + static const std::map step_names = {{1, "Parsing and validating input arguments"}, + {2, "Loading Inference Engine"}, + {3, "Setting device configuration"}, + {4, "Reading network files"}, + {5, "Resizing network to match image sizes and given batch"}, + {6, "Configuring input of the model"}, + {7, "Loading the model to the device"}, + {8, "Setting optimal runtime parameters"}, + {9, "Creating infer requests and filling input blobs with images"}, + {10, "Measuring performance"}, + {11, "Dumping statistics report"}}; step_id++; if (step_names.count(step_id) == 0) @@ -103,23 +100,23 @@ static void next_step(const std::string additional_info = "") { } template -T getMedianValue(const std::vector &vec) { +T getMedianValue(const std::vector& vec) { std::vector sortedVec(vec); std::sort(sortedVec.begin(), sortedVec.end()); - return (sortedVec.size() % 2 != 0) ? - sortedVec[sortedVec.size() / 2ULL] : - (sortedVec[sortedVec.size() / 2ULL] + sortedVec[sortedVec.size() / 2ULL - 1ULL]) / static_cast(2.0); + return (sortedVec.size() % 2 != 0) ? sortedVec[sortedVec.size() / 2ULL] + : (sortedVec[sortedVec.size() / 2ULL] + sortedVec[sortedVec.size() / 2ULL - 1ULL]) / static_cast(2.0); } /** -* @brief The entry point of the benchmark application -*/ -int main(int argc, char *argv[]) { + * @brief The entry point of the benchmark application + */ +int main(int argc, char* argv[]) { std::shared_ptr statistics; try { ExecutableNetwork exeNetwork; - // ----------------- 1. Parsing and validating input arguments ------------------------------------------------- + // ----------------- 1. Parsing and validating input arguments + // ------------------------------------------------- next_step(); if (!ParseAndCheckCommandLine(argc, argv)) { @@ -134,18 +131,19 @@ int main(int argc, char *argv[]) { std::vector flags; StatisticsReport::Parameters command_line_arguments; gflags::GetAllFlags(&flags); - for (auto &flag : flags) { + for (auto& flag : flags) { if (!flag.is_default) { - command_line_arguments.push_back({ flag.name, flag.current_value }); + command_line_arguments.push_back({flag.name, flag.current_value}); } } if (!FLAGS_report_type.empty()) { - statistics = std::make_shared(StatisticsReport::Config{FLAGS_report_type, FLAGS_report_folder}); + statistics = std::make_shared(StatisticsReport::Config {FLAGS_report_type, FLAGS_report_folder}); statistics->addParameters(StatisticsReport::Category::COMMAND_LINE_PARAMETERS, command_line_arguments); } - auto isFlagSetInCommandLine = [&command_line_arguments] (const std::string& name) { - return (std::find_if(command_line_arguments.begin(), command_line_arguments.end(), - [ name ] (const std::pair& p) { return p.first == name;}) != command_line_arguments.end()); + auto isFlagSetInCommandLine = [&command_line_arguments](const std::string& name) { + return (std::find_if(command_line_arguments.begin(), command_line_arguments.end(), [name](const std::pair& p) { + return p.first == name; + }) != command_line_arguments.end()); }; std::string device_name = FLAGS_d; @@ -167,12 +165,14 @@ int main(int argc, char *argv[]) { std::vector inputFiles; parseInputFilesArguments(inputFiles); - // ----------------- 2. Loading the Inference Engine ----------------------------------------------------------- + // ----------------- 2. Loading the Inference Engine + // ----------------------------------------------------------- next_step(); Core ie; if (FLAGS_d.find("CPU") != std::string::npos && !FLAGS_l.empty()) { - // CPU (MKLDNN) extensions is loaded as a shared library and passed as a pointer to base extension + // CPU (MKLDNN) extensions is loaded as a shared library and passed as a + // pointer to base extension const auto extension_ptr = std::make_shared(FLAGS_l); ie.AddExtension(extension_ptr); slog::info << "CPU (MKLDNN) extensions is loaded " << FLAGS_l << slog::endl; @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) { } if (config.count("GPU") && config.at("GPU").count(CONFIG_KEY(CONFIG_FILE))) { auto ext = config.at("GPU").at(CONFIG_KEY(CONFIG_FILE)); - ie.SetConfig({{ CONFIG_KEY(CONFIG_FILE), ext }}, "GPU"); + ie.SetConfig({{CONFIG_KEY(CONFIG_FILE), ext}}, "GPU"); slog::info << "GPU extensions is loaded " << ext << slog::endl; } @@ -195,30 +195,28 @@ int main(int argc, char *argv[]) { slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(device_name) << std::endl; - // ----------------- 3. Setting device configuration ----------------------------------------------------------- + // ----------------- 3. Setting device configuration + // ----------------------------------------------------------- next_step(); bool perf_counts = false; // Update config per device according to command line parameters for (auto& device : devices) { - if (!config.count(device)) config[device] = {}; + if (!config.count(device)) + config[device] = {}; std::map& device_config = config.at(device); // Set performance counter if (isFlagSetInCommandLine("pc")) { // set to user defined value device_config[CONFIG_KEY(PERF_COUNT)] = FLAGS_pc ? CONFIG_VALUE(YES) : CONFIG_VALUE(NO); - } else if (device_config.count(CONFIG_KEY(PERF_COUNT)) && - (device_config.at(CONFIG_KEY(PERF_COUNT)) == "YES")) { - slog::warn << "Performance counters for " << device << - " device is turned on. To print results use -pc option." << slog::endl; + } else if (device_config.count(CONFIG_KEY(PERF_COUNT)) && (device_config.at(CONFIG_KEY(PERF_COUNT)) == "YES")) { + slog::warn << "Performance counters for " << device << " device is turned on. To print results use -pc option." << slog::endl; } else if (FLAGS_report_type == detailedCntReport || FLAGS_report_type == averageCntReport) { - slog::warn << "Turn on performance counters for " << device << - " device since report type is " << FLAGS_report_type << "." << slog::endl; + slog::warn << "Turn on performance counters for " << device << " device since report type is " << FLAGS_report_type << "." << slog::endl; device_config[CONFIG_KEY(PERF_COUNT)] = CONFIG_VALUE(YES); } else if (!FLAGS_exec_graph_path.empty()) { - slog::warn << "Turn on performance counters for " << device << - " device due to execution graph dumping." << slog::endl; + slog::warn << "Turn on performance counters for " << device << " device due to execution graph dumping." << slog::endl; device_config[CONFIG_KEY(PERF_COUNT)] = CONFIG_VALUE(YES); } else { // set to default value @@ -226,22 +224,28 @@ int main(int argc, char *argv[]) { } perf_counts = (device_config.at(CONFIG_KEY(PERF_COUNT)) == CONFIG_VALUE(YES)) ? true : perf_counts; - auto setThroughputStreams = [&] () { + auto setThroughputStreams = [&]() { const std::string key = device + "_THROUGHPUT_STREAMS"; if (device_nstreams.count(device)) { // set to user defined value std::vector supported_config_keys = ie.GetMetric(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); if (std::find(supported_config_keys.begin(), supported_config_keys.end(), key) == supported_config_keys.end()) { throw std::logic_error("Device " + device + " doesn't support config key '" + key + "'! " + - "Please specify -nstreams for correct devices in format :,:" + + "Please specify -nstreams for correct devices in format " + ":,:" + " or via configuration file."); } device_config[key] = device_nstreams.at(device); } else if (!device_config.count(key) && (FLAGS_api == "async")) { - slog::warn << "-nstreams default value is determined automatically for " << device << " device. " - "Although the automatic selection usually provides a reasonable performance, " - "but it still may be non-optimal for some cases, for more information look at README." << slog::endl; - if (std::string::npos == device.find("MYRIAD")) // MYRIAD sets the default number of streams implicitly (without _AUTO) + slog::warn << "-nstreams default value is determined automatically for " << device + << " device. " + "Although the automatic selection usually provides a " + "reasonable performance, " + "but it still may be non-optimal for some cases, for more " + "information look at README." + << slog::endl; + if (std::string::npos == device.find("MYRIAD")) // MYRIAD sets the default number of + // streams implicitly (without _AUTO) device_config[key] = std::string(device + "_THROUGHPUT_AUTO"); } if (device_config.count(key)) @@ -260,10 +264,8 @@ int main(int argc, char *argv[]) { // set to user defined value device_config[CONFIG_KEY(CPU_BIND_THREAD)] = FLAGS_pin; } else if (!device_config.count(CONFIG_KEY(CPU_BIND_THREAD))) { - if ((device_name.find("MULTI") != std::string::npos) && - (device_name.find("GPU") != std::string::npos)) { - slog::warn << "Turn off threads pinning for " << device << - " device since multi-scenario with GPU device is used." << slog::endl; + if ((device_name.find("MULTI") != std::string::npos) && (device_name.find("GPU") != std::string::npos)) { + slog::warn << "Turn off threads pinning for " << device << " device since multi-scenario with GPU device is used." << slog::endl; device_config[CONFIG_KEY(CPU_BIND_THREAD)] = CONFIG_VALUE(NO); } else { // set to default value @@ -277,10 +279,12 @@ int main(int argc, char *argv[]) { // for GPU execution, more throughput-oriented execution via streams setThroughputStreams(); - if ((device_name.find("MULTI") != std::string::npos) && - (device_name.find("CPU") != std::string::npos)) { - slog::warn << "Turn on GPU trottling. Multi-device execution with the CPU + GPU performs best with GPU trottling hint," << - "which releases another CPU thread (that is otherwise used by the GPU driver for active polling)"<< slog::endl; + if ((device_name.find("MULTI") != std::string::npos) && (device_name.find("CPU") != std::string::npos)) { + slog::warn << "Turn on GPU trottling. Multi-device execution with " + "the CPU + GPU performs best with GPU trottling hint," + << "which releases another CPU thread (that is otherwise " + "used by the GPU driver for active polling)" + << slog::endl; device_config[CLDNN_CONFIG_KEY(PLUGIN_THROTTLE)] = "1"; } } else if (device == "MYRIAD") { @@ -296,9 +300,8 @@ int main(int argc, char *argv[]) { device_config[GNA_CONFIG_KEY(LIB_N_THREADS)] = std::to_string(FLAGS_nthreads); } else { std::vector supported_config_keys = ie.GetMetric(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - auto supported = [&] (const std::string& key) { - return std::find(std::begin(supported_config_keys), std::end(supported_config_keys), key) - != std::end(supported_config_keys); + auto supported = [&](const std::string& key) { + return std::find(std::begin(supported_config_keys), std::end(supported_config_keys), key) != std::end(supported_config_keys); }; if (supported(CONFIG_KEY(CPU_THREADS_NUM)) && isFlagSetInCommandLine("nthreads")) { device_config[CONFIG_KEY(CPU_THREADS_NUM)] = std::to_string(FLAGS_nthreads); @@ -316,12 +319,12 @@ int main(int argc, char *argv[]) { ie.SetConfig(item.second, item.first); } - auto double_to_string = [] (const double number) { + auto double_to_string = [](const double number) { std::stringstream ss; ss << std::fixed << std::setprecision(2) << number; return ss.str(); }; - auto get_total_ms_time = [] (Time::time_point& startTime) { + auto get_total_ms_time = [](Time::time_point& startTime) { return std::chrono::duration_cast(Time::now() - startTime).count() * 0.000001; }; @@ -331,7 +334,8 @@ int main(int argc, char *argv[]) { benchmark_app::InputsInfo app_inputs_info; std::string output_name; if (!isNetworkCompiled) { - // ----------------- 4. Reading the Intermediate Representation network ---------------------------------------- + // ----------------- 4. Reading the Intermediate Representation network + // ---------------------------------------- next_step(); slog::info << "Loading network files" << slog::endl; @@ -341,17 +345,15 @@ int main(int argc, char *argv[]) { auto duration_ms = double_to_string(get_total_ms_time(startTime)); slog::info << "Read network took " << duration_ms << " ms" << slog::endl; if (statistics) - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"read network time (ms)", duration_ms} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"read network time (ms)", duration_ms}}); const InputsDataMap inputInfo(cnnNetwork.getInputsInfo()); if (inputInfo.empty()) { throw std::logic_error("no inputs info is provided"); } - // ----------------- 5. Resizing network to match image sizes and given batch ---------------------------------- + // ----------------- 5. Resizing network to match image sizes and given + // batch ---------------------------------- next_step(); batchSize = cnnNetwork.getBatchSize(); // Parse input shapes if specified @@ -367,10 +369,7 @@ int main(int argc, char *argv[]) { auto duration_ms = double_to_string(get_total_ms_time(startTime)); slog::info << "Reshape network took " << duration_ms << " ms" << slog::endl; if (statistics) - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"reshape network time (ms)", duration_ms} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"reshape network time (ms)", duration_ms}}); } // use batch size according to provided layout and shapes batchSize = (!FLAGS_layout.empty()) ? getBatchSize(app_inputs_info) : cnnNetwork.getBatchSize(); @@ -378,7 +377,8 @@ int main(int argc, char *argv[]) { topology_name = cnnNetwork.getName(); slog::info << (FLAGS_b != 0 ? "Network batch size was changed to: " : "Network batch size: ") << batchSize << slog::endl; - // ----------------- 6. Configuring inputs and outputs ---------------------------------------------------------------------- + // ----------------- 6. Configuring inputs and outputs + // ---------------------------------------------------------------------- next_step(); processPrecision(cnnNetwork, FLAGS_ip, FLAGS_op, FLAGS_iop); @@ -393,19 +393,16 @@ int main(int argc, char *argv[]) { } } - printInputAndOutputsInfo(cnnNetwork); - // ----------------- 7. Loading the model to the device -------------------------------------------------------- + // ----------------- 7. Loading the model to the device + // -------------------------------------------------------- next_step(); startTime = Time::now(); exeNetwork = ie.LoadNetwork(cnnNetwork, device_name); duration_ms = double_to_string(get_total_ms_time(startTime)); slog::info << "Load network took " << duration_ms << " ms" << slog::endl; if (statistics) - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"load network time (ms)", duration_ms} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"load network time (ms)", duration_ms}}); } else { next_step(); slog::info << "Skipping the step for compiled network" << slog::endl; @@ -413,23 +410,22 @@ int main(int argc, char *argv[]) { slog::info << "Skipping the step for compiled network" << slog::endl; next_step(); slog::info << "Skipping the step for compiled network" << slog::endl; - // ----------------- 7. Loading the model to the device -------------------------------------------------------- + // ----------------- 7. Loading the model to the device + // -------------------------------------------------------- next_step(); auto startTime = Time::now(); exeNetwork = ie.ImportNetwork(FLAGS_m, device_name, {}); auto duration_ms = double_to_string(get_total_ms_time(startTime)); slog::info << "Import network took " << duration_ms << " ms" << slog::endl; if (statistics) - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"import network time (ms)", duration_ms} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"import network time (ms)", duration_ms}}); app_inputs_info = getInputsInfo(FLAGS_shape, FLAGS_layout, FLAGS_b, exeNetwork.GetInputsInfo()); if (batchSize == 0) { batchSize = 1; } } - // ----------------- 8. Setting optimal runtime parameters ----------------------------------------------------- + // ----------------- 8. Setting optimal runtime parameters + // ----------------------------------------------------- next_step(); // Update number of streams @@ -448,10 +444,10 @@ int main(int argc, char *argv[]) { try { nireq = exeNetwork.GetMetric(key).as(); } catch (const std::exception& ex) { - IE_THROW() - << "Every device used with the benchmark_app should " - << "support OPTIMAL_NUMBER_OF_INFER_REQUESTS ExecutableNetwork metric. " - << "Failed to query the metric for the " << device_name << " with error:" << ex.what(); + IE_THROW() << "Every device used with the benchmark_app should " + << "support OPTIMAL_NUMBER_OF_INFER_REQUESTS " + "ExecutableNetwork metric. " + << "Failed to query the metric for the " << device_name << " with error:" << ex.what(); } } } @@ -459,10 +455,10 @@ int main(int argc, char *argv[]) { // Iteration limit uint32_t niter = FLAGS_niter; if ((niter > 0) && (FLAGS_api == "async")) { - niter = ((niter + nireq - 1)/nireq)*nireq; + niter = ((niter + nireq - 1) / nireq) * nireq; if (FLAGS_niter != niter) { - slog::warn << "Number of iterations was aligned by request number from " - << FLAGS_niter << " to " << niter << " using number of requests " << nireq << slog::endl; + slog::warn << "Number of iterations was aligned by request number from " << FLAGS_niter << " to " << niter << " using number of requests " + << nireq << slog::endl; } } @@ -480,32 +476,33 @@ int main(int argc, char *argv[]) { if (statistics) { statistics->addParameters(StatisticsReport::Category::RUNTIME_CONFIG, { - {"topology", topology_name}, - {"target device", device_name}, - {"API", FLAGS_api}, - {"precision", std::string(precision.name())}, - {"batch size", std::to_string(batchSize)}, - {"number of iterations", std::to_string(niter)}, - {"number of parallel infer requests", std::to_string(nireq)}, - {"duration (ms)", std::to_string(getDurationInMilliseconds(duration_seconds))}, + {"topology", topology_name}, + {"target device", device_name}, + {"API", FLAGS_api}, + {"precision", std::string(precision.name())}, + {"batch size", std::to_string(batchSize)}, + {"number of iterations", std::to_string(niter)}, + {"number of parallel infer requests", std::to_string(nireq)}, + {"duration (ms)", std::to_string(getDurationInMilliseconds(duration_seconds))}, }); for (auto& nstreams : device_nstreams) { std::stringstream ss; ss << "number of " << nstreams.first << " streams"; - statistics->addParameters(StatisticsReport::Category::RUNTIME_CONFIG, - { - {ss.str(), nstreams.second}, - }); + statistics->addParameters(StatisticsReport::Category::RUNTIME_CONFIG, { + {ss.str(), nstreams.second}, + }); } } - // ----------------- 9. Creating infer requests and filling input blobs ---------------------------------------- + // ----------------- 9. Creating infer requests and filling input blobs + // ---------------------------------------- next_step(); InferRequestsQueue inferRequestsQueue(exeNetwork, nireq); fillBlobs(inputFiles, batchSize, app_inputs_info, inferRequestsQueue.requests); - // ----------------- 10. Measuring performance ------------------------------------------------------------------ + // ----------------- 10. Measuring performance + // ------------------------------------------------------------------ size_t progressCnt = 0; size_t progressBarTotalCount = progressBarDefaultTotalCount; size_t iteration = 0; @@ -557,21 +554,18 @@ int main(int argc, char *argv[]) { auto duration_ms = double_to_string(inferRequestsQueue.getLatencies()[0]); slog::info << "First inference took " << duration_ms << " ms" << slog::endl; if (statistics) - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"first inference time (ms)", duration_ms} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"first inference time (ms)", duration_ms}}); inferRequestsQueue.resetTimes(); auto startTime = Time::now(); auto execTime = std::chrono::duration_cast(Time::now() - startTime).count(); /** Start inference & calculate performance **/ - /** to align number if iterations to guarantee that last infer requests are executed in the same conditions **/ + /** to align number if iterations to guarantee that last infer requests are + * executed in the same conditions **/ ProgressBar progressBar(progressBarTotalCount, FLAGS_stream_output, FLAGS_progress); - while ((niter != 0LL && iteration < niter) || - (duration_nanoseconds != 0LL && (uint64_t)execTime < duration_nanoseconds) || + while ((niter != 0LL && iteration < niter) || (duration_nanoseconds != 0LL && (uint64_t)execTime < duration_nanoseconds) || (FLAGS_api == "async" && iteration % nireq != 0)) { inferRequest = inferRequestsQueue.getIdleRequest(); if (!inferRequest) { @@ -581,11 +575,12 @@ int main(int argc, char *argv[]) { if (FLAGS_api == "sync") { inferRequest->infer(); } else { - // As the inference request is currently idle, the wait() adds no additional overhead (and should return immediately). - // The primary reason for calling the method is exception checking/re-throwing. - // Callback, that governs the actual execution can handle errors as well, - // but as it uses just error codes it has no details like ‘what()’ method of `std::exception` - // So, rechecking for any exceptions here. + // As the inference request is currently idle, the wait() adds no + // additional overhead (and should return immediately). The primary + // reason for calling the method is exception checking/re-throwing. + // Callback, that governs the actual execution can handle errors as + // well, but as it uses just error codes it has no details like ‘what()’ + // method of `std::exception` So, rechecking for any exceptions here. inferRequest->wait(); inferRequest->startAsync(); } @@ -596,9 +591,10 @@ int main(int argc, char *argv[]) { if (niter > 0) { progressBar.addProgress(1); } else { - // calculate how many progress intervals are covered by current iteration. - // depends on the current iteration time and time of each progress interval. - // Previously covered progress intervals must be skipped. + // calculate how many progress intervals are covered by current + // iteration. depends on the current iteration time and time of each + // progress interval. Previously covered progress intervals must be + // skipped. auto progressIntervalTime = duration_nanoseconds / progressBarTotalCount; size_t newProgress = execTime / progressIntervalTime - progressCnt; progressBar.addProgress(newProgress); @@ -611,30 +607,25 @@ int main(int argc, char *argv[]) { double latency = getMedianValue(inferRequestsQueue.getLatencies()); double totalDuration = inferRequestsQueue.getDurationInMilliseconds(); - double fps = (FLAGS_api == "sync") ? batchSize * 1000.0 / latency : - batchSize * 1000.0 * iteration / totalDuration; + double fps = (FLAGS_api == "sync") ? batchSize * 1000.0 / latency : batchSize * 1000.0 * iteration / totalDuration; if (statistics) { - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"total execution time (ms)", double_to_string(totalDuration)}, - {"total number of iterations", std::to_string(iteration)}, - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, { + {"total execution time (ms)", double_to_string(totalDuration)}, + {"total number of iterations", std::to_string(iteration)}, + }); if (device_name.find("MULTI") == std::string::npos) { - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"latency (ms)", double_to_string(latency)}, - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, { + {"latency (ms)", double_to_string(latency)}, + }); } - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"throughput", double_to_string(fps)} - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, {{"throughput", double_to_string(fps)}}); } progressBar.finish(); - // ----------------- 11. Dumping statistics report ------------------------------------------------------------- + // ----------------- 11. Dumping statistics report + // ------------------------------------------------------------- next_step(); #ifdef USE_OPENCV @@ -649,7 +640,7 @@ int main(int argc, char *argv[]) { CNNNetwork execGraphInfo = exeNetwork.GetExecGraphInfo(); execGraphInfo.serialize(FLAGS_exec_graph_path); slog::info << "executable graph is stored to " << FLAGS_exec_graph_path << slog::endl; - } catch (const std::exception & ex) { + } catch (const std::exception& ex) { slog::err << "Can't get executable graph: " << ex.what() << slog::endl; } } @@ -681,10 +672,9 @@ int main(int argc, char *argv[]) { slog::err << ex.what() << slog::endl; if (statistics) { - statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, - { - {"error", ex.what()}, - }); + statistics->addParameters(StatisticsReport::Category::EXECUTION_RESULTS, { + {"error", ex.what()}, + }); statistics->dump(); } diff --git a/inference-engine/samples/benchmark_app/progress_bar.hpp b/inference-engine/samples/benchmark_app/progress_bar.hpp index 0893a04bb02..3f519462cb7 100644 --- a/inference-engine/samples/benchmark_app/progress_bar.hpp +++ b/inference-engine/samples/benchmark_app/progress_bar.hpp @@ -5,7 +5,6 @@ #pragma once #include - #include /// @brief Responsible for progress bar handling within the benchmark_app diff --git a/inference-engine/samples/benchmark_app/statistics_report.cpp b/inference-engine/samples/benchmark_app/statistics_report.cpp index 39bdaa034b0..8ad8443804f 100644 --- a/inference-engine/samples/benchmark_app/statistics_report.cpp +++ b/inference-engine/samples/benchmark_app/statistics_report.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include - #include "statistics_report.hpp" -void StatisticsReport::addParameters(const Category &category, const Parameters& parameters) { +#include +#include +#include +#include +#include + +void StatisticsReport::addParameters(const Category& category, const Parameters& parameters) { if (_parameters.count(category) == 0) _parameters[category] = parameters; else @@ -20,7 +20,7 @@ void StatisticsReport::addParameters(const Category &category, const Parameters& void StatisticsReport::dump() { CsvDumper dumper(true, _config.report_folder + _separator + "benchmark_report.csv"); - auto dump_parameters = [ &dumper ] (const Parameters ¶meters) { + auto dump_parameters = [&dumper](const Parameters& parameters) { for (auto& parameter : parameters) { dumper << parameter.first << parameter.second; dumper.endLine(); @@ -53,46 +53,54 @@ void StatisticsReport::dump() { slog::info << "Statistics report is stored to " << dumper.getFilename() << slog::endl; } -void StatisticsReport::dumpPerformanceCountersRequest(CsvDumper& dumper, - const PerformaceCounters& perfCounts) { +void StatisticsReport::dumpPerformanceCountersRequest(CsvDumper& dumper, const PerformaceCounters& perfCounts) { auto performanceMapSorted = perfCountersSorted(perfCounts); long long total = 0L; long long total_cpu = 0L; - dumper << "layerName" << "execStatus" << "layerType" << "execType"; - dumper << "realTime (ms)" << "cpuTime (ms)"; + dumper << "layerName" + << "execStatus" + << "layerType" + << "execType"; + dumper << "realTime (ms)" + << "cpuTime (ms)"; dumper.endLine(); - for (const auto &layer : performanceMapSorted) { + for (const auto& layer : performanceMapSorted) { dumper << layer.first; // layer name switch (layer.second.status) { - case InferenceEngine::InferenceEngineProfileInfo::EXECUTED: - dumper << "EXECUTED"; - break; - case InferenceEngine::InferenceEngineProfileInfo::NOT_RUN: - dumper << "NOT_RUN"; - break; - case InferenceEngine::InferenceEngineProfileInfo::OPTIMIZED_OUT: - dumper << "OPTIMIZED_OUT"; - break; + case InferenceEngine::InferenceEngineProfileInfo::EXECUTED: + dumper << "EXECUTED"; + break; + case InferenceEngine::InferenceEngineProfileInfo::NOT_RUN: + dumper << "NOT_RUN"; + break; + case InferenceEngine::InferenceEngineProfileInfo::OPTIMIZED_OUT: + dumper << "OPTIMIZED_OUT"; + break; } dumper << layer.second.layer_type << layer.second.exec_type; - dumper << std::to_string(layer.second.realTime_uSec / 1000.0) << std::to_string(layer.second.cpu_uSec/ 1000.0); + dumper << std::to_string(layer.second.realTime_uSec / 1000.0) << std::to_string(layer.second.cpu_uSec / 1000.0); total += layer.second.realTime_uSec; total_cpu += layer.second.cpu_uSec; dumper.endLine(); } - dumper << "Total" << "" << "" << ""; - dumper << total / 1000.0 << total_cpu / 1000.0; + dumper << "Total" + << "" + << "" + << ""; + dumper << total / 1000.0 << total_cpu / 1000.0; dumper.endLine(); dumper.endLine(); } -void StatisticsReport::dumpPerformanceCounters(const std::vector &perfCounts) { +void StatisticsReport::dumpPerformanceCounters(const std::vector& perfCounts) { if ((_config.report_type.empty()) || (_config.report_type == noCntReport)) { - slog::info << "Statistics collecting for performance counters was not requested. No reports are dumped." << slog::endl; + slog::info << "Statistics collecting for performance counters was not " + "requested. No reports are dumped." + << slog::endl; return; } if (perfCounts.empty()) { @@ -105,12 +113,13 @@ void StatisticsReport::dumpPerformanceCounters(const std::vector performanceCountersAvg; // iterate over each processed infer request and handle its PM data for (size_t i = 0; i < perfCounts.size(); i++) { auto performanceMapSorted = perfCountersSorted(perfCounts[i]); - // iterate over each layer from sorted vector and add required PM data to the per-layer maps + // iterate over each layer from sorted vector and add required PM data + // to the per-layer maps for (const auto& pm : performanceMapSorted) { if (performanceCountersAvg.count(pm.first) == 0) { performanceCountersAvg[pm.first] = perfCounts.at(i).at(pm.first); diff --git a/inference-engine/samples/benchmark_app/statistics_report.hpp b/inference-engine/samples/benchmark_app/statistics_report.hpp index df6d08707ca..1110cf78522 100644 --- a/inference-engine/samples/benchmark_app/statistics_report.hpp +++ b/inference-engine/samples/benchmark_app/statistics_report.hpp @@ -4,15 +4,14 @@ #pragma once -#include -#include -#include -#include - #include +#include #include -#include #include +#include +#include +#include +#include // @brief statistics reports types static constexpr char noCntReport[] = "no_counters"; @@ -36,30 +35,29 @@ public: EXECUTION_RESULTS, }; - explicit StatisticsReport(Config config) : _config(std::move(config)) { + explicit StatisticsReport(Config config): _config(std::move(config)) { _separator = #if defined _WIN32 || defined __CYGWIN__ - # if defined UNICODE - L"\\"; - # else - "\\"; - # endif + #if defined UNICODE + L"\\"; + #else + "\\"; + #endif #else - "/"; + "/"; #endif if (_config.report_folder.empty()) _separator = ""; } - void addParameters(const Category &category, const Parameters& parameters); + void addParameters(const Category& category, const Parameters& parameters); void dump(); - void dumpPerformanceCounters(const std::vector &perfCounts); + void dumpPerformanceCounters(const std::vector& perfCounts); private: - void dumpPerformanceCountersRequest(CsvDumper& dumper, - const PerformaceCounters& perfCounts); + void dumpPerformanceCountersRequest(CsvDumper& dumper, const PerformaceCounters& perfCounts); // configuration of current benchmark execution const Config _config; diff --git a/inference-engine/samples/benchmark_app/utils.cpp b/inference-engine/samples/benchmark_app/utils.cpp index 22e53bb346b..e41bfbd1be8 100644 --- a/inference-engine/samples/benchmark_app/utils.cpp +++ b/inference-engine/samples/benchmark_app/utils.cpp @@ -2,68 +2,61 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +// clang-format off #include -#include -#include +#include #include #include -#include - #include #include +#include +#include +#include #include "utils.hpp" +// clang-format on #ifdef USE_OPENCV -#include + #include #endif namespace benchmark_app { - bool InputInfo::isImage() const { - if ((layout != "NCHW") && (layout != "NHWC") && - (layout != "CHW") && (layout != "HWC")) - return false; - return (channels() == 3); - } - bool InputInfo::isImageInfo() const { - if (layout != "NC") - return false; - return (channels() >= 2); - } - size_t InputInfo::getDimentionByLayout(char character) const { - size_t pos = layout.find(character); - if (pos == std::string::npos) - throw std::runtime_error("Error: Can't get " + std::string(character, 1) + " from layout " + layout); - return shape.at(pos); - } - size_t InputInfo::width() const { - return getDimentionByLayout('W'); - } - size_t InputInfo::height() const { - return getDimentionByLayout('H'); - } - size_t InputInfo::channels() const { - return getDimentionByLayout('C'); - } - size_t InputInfo::batch() const { - return getDimentionByLayout('N'); - } - size_t InputInfo::depth() const { - return getDimentionByLayout('D'); - } -} // namespace benchmark_app +bool InputInfo::isImage() const { + if ((layout != "NCHW") && (layout != "NHWC") && (layout != "CHW") && (layout != "HWC")) + return false; + return (channels() == 3); +} +bool InputInfo::isImageInfo() const { + if (layout != "NC") + return false; + return (channels() >= 2); +} +size_t InputInfo::getDimentionByLayout(char character) const { + size_t pos = layout.find(character); + if (pos == std::string::npos) + throw std::runtime_error("Error: Can't get " + std::string(character, 1) + " from layout " + layout); + return shape.at(pos); +} +size_t InputInfo::width() const { + return getDimentionByLayout('W'); +} +size_t InputInfo::height() const { + return getDimentionByLayout('H'); +} +size_t InputInfo::channels() const { + return getDimentionByLayout('C'); +} +size_t InputInfo::batch() const { + return getDimentionByLayout('N'); +} +size_t InputInfo::depth() const { + return getDimentionByLayout('D'); +} +} // namespace benchmark_app uint32_t deviceDefaultDeviceDurationInSeconds(const std::string& device) { - static const std::map deviceDefaultDurationInSeconds { - { "CPU", 60 }, - { "GPU", 60 }, - { "VPU", 60 }, - { "MYRIAD", 60 }, - { "HDDL", 60 }, - { "FPGA", 120 }, - { "UNKNOWN", 120 } - }; + static const std::map deviceDefaultDurationInSeconds {{"CPU", 60}, {"GPU", 60}, {"VPU", 60}, {"MYRIAD", 60}, + {"HDDL", 60}, {"FPGA", 120}, {"UNKNOWN", 120}}; uint32_t duration = 0; for (const auto& deviceDurationInSeconds : deviceDefaultDurationInSeconds) { if (device.find(deviceDurationInSeconds.first) != std::string::npos) { @@ -71,10 +64,10 @@ uint32_t deviceDefaultDeviceDurationInSeconds(const std::string& device) { } } if (duration == 0) { - const auto unknownDeviceIt = find_if( - deviceDefaultDurationInSeconds.begin(), - deviceDefaultDurationInSeconds.end(), - [](std::pair deviceDuration) { return deviceDuration.first == "UNKNOWN"; }); + const auto unknownDeviceIt = + find_if(deviceDefaultDurationInSeconds.begin(), deviceDefaultDurationInSeconds.end(), [](std::pair deviceDuration) { + return deviceDuration.first == "UNKNOWN"; + }); if (unknownDeviceIt == deviceDefaultDurationInSeconds.end()) { throw std::logic_error("UNKNOWN device was not found in the device duration list"); @@ -85,7 +78,7 @@ uint32_t deviceDefaultDeviceDurationInSeconds(const std::string& device) { return duration; } -std::vector split(const std::string &s, char delim) { +std::vector split(const std::string& s, char delim) { std::vector result; std::stringstream ss(s); std::string item; @@ -109,8 +102,7 @@ std::vector parseDevices(const std::string& device_string) { return devices; } -std::map parseNStreamsValuePerDevice(const std::vector& devices, - const std::string& values_string) { +std::map parseNStreamsValuePerDevice(const std::vector& devices, const std::string& values_string) { // Format: :,: or just std::map result; auto device_value_strings = split(values_string, ','); @@ -123,8 +115,7 @@ std::map parseNStreamsValuePerDevice(const std::vector if (it != devices.end()) { result[device_name] = nstreams; } else { - throw std::logic_error("Can't set nstreams value " + std::string(nstreams) + - " for device '" + device_name + "'! Incorrect device name!"); + throw std::logic_error("Can't set nstreams value " + std::string(nstreams) + " for device '" + device_name + "'! Incorrect device name!"); } } else if (device_value_vec.size() == 1) { auto value = device_value_vec.at(0); @@ -146,7 +137,8 @@ size_t getBatchSize(const benchmark_app::InputsInfo& inputs_info) { if (batch_size == 0) batch_size = info.second.shape[batch_index]; else if (batch_size != info.second.shape[batch_index]) - throw std::logic_error("Can't deterimine batch size: batch is different for different inputs!"); + throw std::logic_error("Can't deterimine batch size: batch is " + "different for different inputs!"); } } if (batch_size == 0) @@ -157,10 +149,12 @@ size_t getBatchSize(const benchmark_app::InputsInfo& inputs_info) { std::string getShapesString(const InferenceEngine::ICNNNetwork::InputShapes& shapes) { std::stringstream ss; for (auto& shape : shapes) { - if (!ss.str().empty()) ss << ", "; + if (!ss.str().empty()) + ss << ", "; ss << "\'" << shape.first << "': ["; for (size_t i = 0; i < shape.second.size(); i++) { - if (i > 0) ss << ", "; + if (i > 0) + ss << ", "; ss << shape.second.at(i); } ss << "]"; @@ -169,13 +163,12 @@ std::string getShapesString(const InferenceEngine::ICNNNetwork::InputShapes& sha } #ifdef USE_OPENCV -void dump_config(const std::string& filename, - const std::map>& config) { +void dump_config(const std::string& filename, const std::map>& config) { cv::FileStorage fs(filename, cv::FileStorage::WRITE); if (!fs.isOpened()) throw std::runtime_error("Error: Can't open config file : " + filename); for (auto device_it = config.begin(); device_it != config.end(); ++device_it) { - fs << device_it->first << "{:"; + fs << device_it->first << "{:"; for (auto param_it = device_it->second.begin(); param_it != device_it->second.end(); ++param_it) fs << param_it->first << param_it->second; fs << "}"; @@ -183,8 +176,7 @@ void dump_config(const std::string& filename, fs.release(); } -void load_config(const std::string& filename, - std::map>& config) { +void load_config(const std::string& filename, std::map>& config) { cv::FileStorage fs(filename, cv::FileStorage::READ); if (!fs.isOpened()) throw std::runtime_error("Error: Can't load config file : " + filename); diff --git a/inference-engine/samples/benchmark_app/utils.hpp b/inference-engine/samples/benchmark_app/utils.hpp index 765e02a5466..0abebefe9e0 100644 --- a/inference-engine/samples/benchmark_app/utils.hpp +++ b/inference-engine/samples/benchmark_app/utils.hpp @@ -4,39 +4,38 @@ #pragma once +#include #include #include -#include namespace benchmark_app { - struct InputInfo { - InferenceEngine::Precision precision; - InferenceEngine::SizeVector shape; - std::string layout; - bool isImage() const; - bool isImageInfo() const; - size_t getDimentionByLayout(char character) const; - size_t width() const; - size_t height() const; - size_t channels() const; - size_t batch() const; - size_t depth() const; - }; - using InputsInfo = std::map; -} +struct InputInfo { + InferenceEngine::Precision precision; + InferenceEngine::SizeVector shape; + std::string layout; + bool isImage() const; + bool isImageInfo() const; + size_t getDimentionByLayout(char character) const; + size_t width() const; + size_t height() const; + size_t channels() const; + size_t batch() const; + size_t depth() const; +}; +using InputsInfo = std::map; +} // namespace benchmark_app std::vector parseDevices(const std::string& device_string); uint32_t deviceDefaultDeviceDurationInSeconds(const std::string& device); -std::map parseNStreamsValuePerDevice(const std::vector& devices, - const std::string& values_string); +std::map parseNStreamsValuePerDevice(const std::vector& devices, const std::string& values_string); std::string getShapesString(const InferenceEngine::ICNNNetwork::InputShapes& shapes); size_t getBatchSize(const benchmark_app::InputsInfo& inputs_info); -std::vector split(const std::string &s, char delim); +std::vector split(const std::string& s, char delim); template -std::map parseInputParameters(const std::string parameter_string, - const std::map& input_info) { - // Parse parameter string like "input0[value0],input1[value1]" or "[value]" (applied to all inputs) +std::map parseInputParameters(const std::string parameter_string, const std::map& input_info) { + // Parse parameter string like "input0[value0],input1[value1]" or "[value]" (applied to all + // inputs) std::map return_value; std::string search_string = parameter_string; auto start_pos = search_string.find_first_of('['); @@ -65,11 +64,8 @@ std::map parseInputParameters(const std::string parame } template -benchmark_app::InputsInfo getInputsInfo(const std::string& shape_string, - const std::string& layout_string, - const size_t batch_size, - const std::map& input_info, - bool& reshape_required) { +benchmark_app::InputsInfo getInputsInfo(const std::string& shape_string, const std::string& layout_string, const size_t batch_size, + const std::map& input_info, bool& reshape_required) { std::map shape_map = parseInputParameters(shape_string, input_info); std::map layout_map = parseInputParameters(layout_string, input_info); reshape_required = false; @@ -114,17 +110,13 @@ benchmark_app::InputsInfo getInputsInfo(const std::string& shape_string, } template -benchmark_app::InputsInfo getInputsInfo(const std::string& shape_string, - const std::string& layout_string, - const size_t batch_size, +benchmark_app::InputsInfo getInputsInfo(const std::string& shape_string, const std::string& layout_string, const size_t batch_size, const std::map& input_info) { bool reshape_required = false; return getInputsInfo(shape_string, layout_string, batch_size, input_info, reshape_required); } #ifdef USE_OPENCV -void dump_config(const std::string& filename, - const std::map>& config); -void load_config(const std::string& filename, - std::map>& config); +void dump_config(const std::string& filename, const std::map>& config); +void load_config(const std::string& filename, std::map>& config); #endif \ No newline at end of file diff --git a/inference-engine/samples/classification_sample_async/CMakeLists.txt b/inference-engine/samples/classification_sample_async/CMakeLists.txt index c1dc01d0536..5f3bbbfcbc0 100644 --- a/inference-engine/samples/classification_sample_async/CMakeLists.txt +++ b/inference-engine/samples/classification_sample_async/CMakeLists.txt @@ -4,5 +4,5 @@ ie_add_sample(NAME classification_sample_async SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" - HEADERS classification_sample_async.h + HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/classification_sample_async.h" DEPENDENCIES format_reader ie_samples_utils) diff --git a/inference-engine/samples/classification_sample_async/classification_sample_async.h b/inference-engine/samples/classification_sample_async/classification_sample_async.h index ee7fefd10ef..454acba6554 100644 --- a/inference-engine/samples/classification_sample_async/classification_sample_async.h +++ b/inference-engine/samples/classification_sample_async/classification_sample_async.h @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /// @brief message for help argument static const char help_message[] = "Print a usage message."; @@ -16,24 +17,24 @@ static const char help_message[] = "Print a usage message."; static const char model_message[] = "Required. Path to an .xml file with a trained model."; /// @brief message for images argument -static const char image_message[] = "Required. Path to a folder with images or path to an image files: a .ubyte file for LeNet"\ +static const char image_message[] = "Required. Path to a folder with images or path to an image files: a .ubyte file for LeNet" " and a .bmp file for the other networks."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " \ - "Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ +static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " + "Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " "Sample will look for a suitable plugin for device specified."; /// @brief message for top results number static const char ntop_message[] = "Optional. Number of top results. Default value is 10."; /// @brief message for plugin custom kernels desc -static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. "\ -"Absolute path to the .xml config file with the kernels descriptions."; +static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. " + "Absolute path to the .xml config file with the kernels descriptions."; /// @brief message for user library argument -static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " \ -"Absolute path to a shared library with the kernels implementations."; +static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " + "Absolute path to a shared library with the kernels implementations."; /// @brief Define flag for showing help message
DEFINE_bool(h, false, help_message); @@ -63,8 +64,8 @@ DEFINE_string(c, "", custom_plugin_cfg_message); DEFINE_string(l, "", custom_ex_library_message); /** -* @brief This function show a help message -*/ + * @brief This function show a help message + */ static void showUsage() { std::cout << std::endl; std::cout << "classification_sample_async [OPTION]" << std::endl; diff --git a/inference-engine/samples/classification_sample_async/main.cpp b/inference-engine/samples/classification_sample_async/main.cpp index 220e4997893..c9fd094cb54 100644 --- a/inference-engine/samples/classification_sample_async/main.cpp +++ b/inference-engine/samples/classification_sample_async/main.cpp @@ -3,41 +3,38 @@ // /** -* @brief The entry point the Inference Engine sample application -* @file classification_sample_async/main.cpp -* @example classification_sample_async/main.cpp -*/ - -#include -#include -#include -#include -#include -#include -#include - -#include + * @brief The entry point the Inference Engine sample application + * @file classification_sample_async/main.cpp + * @example classification_sample_async/main.cpp + */ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include - -#include +#include +#include #include "classification_sample_async.h" using namespace InferenceEngine; /** -* @brief Checks input args -* @param argc number of args -* @param argv list of input arguments -* @return bool status true(Success) or false(Fail) -*/ -bool ParseAndCheckCommandLine(int argc, char *argv[]) { + * @brief Checks input args + * @param argc number of args + * @param argv list of input arguments + * @return bool status true(Success) or false(Fail) + */ +bool ParseAndCheckCommandLine(int argc, char* argv[]) { gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true); if (FLAGS_h) { showUsage(); @@ -63,58 +60,71 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { return true; } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { try { - // ------------------------------ Get Inference Engine version ------------------------------------------------------ + // ------------------------------ Get Inference Engine version + // ------------------------------------------------------ slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << slog::endl; - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (!ParseAndCheckCommandLine(argc, argv)) { return 0; } - // ------------------------------ Read input ----------------------------------------------------------- + // ------------------------------ Read input + // ----------------------------------------------------------- /** This vector stores paths to the processed images **/ std::vector imageNames; parseInputFilesArguments(imageNames); - if (imageNames.empty()) throw std::logic_error("No suitable images were found"); + if (imageNames.empty()) + throw std::logic_error("No suitable images were found"); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- slog::info << "Loading Inference Engine" << slog::endl; Core ie; - // ------------------------------ Get Available Devices ------------------------------------------------------ + // ------------------------------ Get Available Devices + // ------------------------------------------------------ slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(FLAGS_d) << std::endl; if (!FLAGS_l.empty()) { - // Custom CPU extension is loaded as a shared library and passed as a pointer to base extension + // Custom CPU extension is loaded as a shared library and passed as a + // pointer to base extension IExtensionPtr extension_ptr = std::make_shared(FLAGS_l); ie.AddExtension(extension_ptr); slog::info << "CPU Extension loaded: " << FLAGS_l << slog::endl; } if (!FLAGS_c.empty() && (FLAGS_d == "GPU" || FLAGS_d == "MYRIAD" || FLAGS_d == "HDDL")) { - // Config for device plugin custom extension is loaded from an .xml description + // Config for device plugin custom extension is loaded from an .xml + // description ie.SetConfig({{PluginConfigParams::KEY_CONFIG_FILE, FLAGS_c}}, FLAGS_d); slog::info << "Config for " << FLAGS_d << " device plugin custom extension loaded: " << FLAGS_c << slog::endl; } // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format slog::info << "Loading network files:" << slog::endl << FLAGS_m << slog::endl; /** Read network model **/ CNNNetwork network = ie.ReadNetwork(FLAGS_m); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - if (network.getOutputsInfo().size() != 1) throw std::logic_error("Sample supports topologies with 1 output only"); + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + if (network.getOutputsInfo().size() != 1) + throw std::logic_error("Sample supports topologies with 1 output only"); - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- slog::info << "Preparing input blobs" << slog::endl; /** Taking information about all topology inputs **/ InputsDataMap inputInfo(network.getInputsInfo()); - if (inputInfo.size() != 1) throw std::logic_error("Sample supports topologies with 1 input only"); + if (inputInfo.size() != 1) + throw std::logic_error("Sample supports topologies with 1 input only"); auto inputInfoItem = *inputInfo.begin(); @@ -125,7 +135,7 @@ int main(int argc, char *argv[]) { std::vector> imagesData = {}; std::vector validImageNames = {}; - for (const auto & i : imageNames) { + for (const auto& i : imageNames) { FormatReader::ReaderPtr reader(i.c_str()); if (reader.get() == nullptr) { slog::warn << "Image " + i + " cannot be read!" << slog::endl; @@ -133,14 +143,14 @@ int main(int argc, char *argv[]) { } /** Store image data **/ std::shared_ptr data( - reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], - inputInfoItem.second->getTensorDesc().getDims()[2])); + reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], inputInfoItem.second->getTensorDesc().getDims()[2])); if (data != nullptr) { imagesData.push_back(data); validImageNames.push_back(i); } } - if (imagesData.empty()) throw std::logic_error("Valid input images were not found!"); + if (imagesData.empty()) + throw std::logic_error("Valid input images were not found!"); /** Setting batch size using image count **/ network.setBatchSize(imagesData.size()); @@ -149,33 +159,40 @@ int main(int argc, char *argv[]) { // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ slog::info << "Loading model to the device" << slog::endl; ExecutableNetwork executable_network = ie.LoadNetwork(network, FLAGS_d); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- slog::info << "Create infer request" << slog::endl; InferRequest inferRequest = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- - for (auto & item : inputInfo) { + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- + for (auto& item : inputInfo) { Blob::Ptr inputBlob = inferRequest.GetBlob(item.first); SizeVector dims = inputBlob->getTensorDesc().getDims(); - /** Fill input tensor with images. First b channel, then g and r channels **/ + /** Fill input tensor with images. First b channel, then g and r channels + * **/ size_t num_channels = dims[1]; size_t image_size = dims[3] * dims[2]; MemoryBlob::Ptr minput = as(inputBlob); if (!minput) { - slog::err << "We expect MemoryBlob from inferRequest, but by fact we were not able to cast inputBlob to MemoryBlob" << slog::endl; + slog::err << "We expect MemoryBlob from inferRequest, but by fact we " + "were not able to cast inputBlob to MemoryBlob" + << slog::endl; return 1; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its + // buffer happens auto minputHolder = minput->wmap(); - auto data = minputHolder.as::value_type *>(); + auto data = minputHolder.as::value_type*>(); if (data == nullptr) throw std::runtime_error("Input blob has not allocated buffer"); /** Iterate over all input images **/ @@ -184,8 +201,9 @@ int main(int argc, char *argv[]) { for (size_t pid = 0; pid < image_size; pid++) { /** Iterate over all channels **/ for (size_t ch = 0; ch < num_channels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - data[image_id * image_size * num_channels + ch * image_size + pid] = imagesData.at(image_id).get()[pid*num_channels + ch]; + /** [images stride + channels stride + pixel id ] all in + * bytes **/ + data[image_id * image_size * num_channels + ch * image_size + pid] = imagesData.at(image_id).get()[pid * num_channels + ch]; } } } @@ -193,24 +211,25 @@ int main(int argc, char *argv[]) { // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference --------------------------------------------------------- + // --------------------------- Step 7. Do inference + // --------------------------------------------------------- size_t numIterations = 10; size_t curIteration = 0; std::condition_variable condVar; - inferRequest.SetCompletionCallback( - [&] { - curIteration++; - slog::info << "Completed " << curIteration << " async request execution" << slog::endl; - if (curIteration < numIterations) { - /* here a user can read output containing inference results and put new input - to repeat async request again */ - inferRequest.StartAsync(); - } else { - /* continue sample execution after last Asynchronous inference request execution */ - condVar.notify_one(); - } - }); + inferRequest.SetCompletionCallback([&] { + curIteration++; + slog::info << "Completed " << curIteration << " async request execution" << slog::endl; + if (curIteration < numIterations) { + /* here a user can read output containing inference results and put new + input to repeat async request again */ + inferRequest.StartAsync(); + } else { + /* continue sample execution after last Asynchronous inference request + * execution */ + condVar.notify_one(); + } + }); /* Start async request for the first time */ slog::info << "Start inference (" << numIterations << " asynchronous executions)" << slog::endl; @@ -219,11 +238,14 @@ int main(int argc, char *argv[]) { /* Wait all repetitions of the async request */ std::mutex mutex; std::unique_lock lock(mutex); - condVar.wait(lock, [&]{ return curIteration == numIterations; }); + condVar.wait(lock, [&] { + return curIteration == numIterations; + }); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------- + // --------------------------- Step 8. Process output + // ------------------------------------------------------- slog::info << "Processing output blobs" << slog::endl; OutputsDataMap outputInfo(network.getOutputsInfo()); if (outputInfo.empty()) @@ -233,8 +255,8 @@ int main(int argc, char *argv[]) { /** Validating -nt value **/ const size_t resultsCnt = outputBlob->size() / batchSize; if (FLAGS_nt > resultsCnt || FLAGS_nt < 1) { - slog::warn << "-nt " << FLAGS_nt << " is not available for this network (-nt should be less than " \ - << resultsCnt+1 << " and more than 0)\n Maximal value " << resultsCnt << " will be used." << slog::endl; + slog::warn << "-nt " << FLAGS_nt << " is not available for this network (-nt should be less than " << resultsCnt + 1 + << " and more than 0)\n Maximal value " << resultsCnt << " will be used." << slog::endl; FLAGS_nt = resultsCnt; } @@ -252,23 +274,21 @@ int main(int argc, char *argv[]) { } } // Prints formatted classification results - ClassificationResult classificationResult(outputBlob, validImageNames, - batchSize, FLAGS_nt, - labels); + ClassificationResult classificationResult(outputBlob, validImageNames, batchSize, FLAGS_nt, labels); classificationResult.print(); // ----------------------------------------------------------------------------------------------------- - } - catch (const std::exception& error) { + } catch (const std::exception& error) { slog::err << error.what() << slog::endl; return 1; - } - catch (...) { + } catch (...) { slog::err << "Unknown/internal exception happened." << slog::endl; return 1; } slog::info << "Execution successful" << slog::endl; - slog::info << slog::endl << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << slog::endl; + slog::info << slog::endl + << "This sample is an API example, for any performance measurements " + "please use the dedicated benchmark_app tool" + << slog::endl; return 0; } diff --git a/inference-engine/samples/common/format_reader/CMakeLists.txt b/inference-engine/samples/common/format_reader/CMakeLists.txt index 132eadcf626..d75061e56cd 100644 --- a/inference-engine/samples/common/format_reader/CMakeLists.txt +++ b/inference-engine/samples/common/format_reader/CMakeLists.txt @@ -41,3 +41,7 @@ target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME} FOLDER cpp_samples) + +if(COMMAND add_clang_format_target) + add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) +endif() \ No newline at end of file diff --git a/inference-engine/samples/common/format_reader/MnistUbyte.cpp b/inference-engine/samples/common/format_reader/MnistUbyte.cpp index 7ddf335b167..1aee331739c 100644 --- a/inference-engine/samples/common/format_reader/MnistUbyte.cpp +++ b/inference-engine/samples/common/format_reader/MnistUbyte.cpp @@ -2,23 +2,24 @@ // SPDX-License-Identifier: Apache-2.0 // +#include + #include #include #include -#include using namespace FormatReader; int MnistUbyte::reverseInt(int i) { unsigned char ch1, ch2, ch3, ch4; - ch1 = (unsigned char) (i & 255); - ch2 = (unsigned char) ((i >> 8) & 255); - ch3 = (unsigned char) ((i >> 16) & 255); - ch4 = (unsigned char) ((i >> 24) & 255); + ch1 = (unsigned char)(i & 255); + ch2 = (unsigned char)((i >> 8) & 255); + ch3 = (unsigned char)((i >> 16) & 255); + ch4 = (unsigned char)((i >> 24) & 255); return (static_cast(ch1) << 24) + (static_cast(ch2) << 16) + (static_cast(ch3) << 8) + ch4; } -MnistUbyte::MnistUbyte(const std::string &filename) { +MnistUbyte::MnistUbyte(const std::string& filename) { std::ifstream file(filename, std::ios::binary); if (!file.is_open()) { return; @@ -27,22 +28,21 @@ MnistUbyte::MnistUbyte(const std::string &filename) { int number_of_images = 0; int n_rows = 0; int n_cols = 0; - file.read(reinterpret_cast(&magic_number), sizeof(magic_number)); + file.read(reinterpret_cast(&magic_number), sizeof(magic_number)); magic_number = reverseInt(magic_number); if (magic_number != 2051) { return; } - file.read(reinterpret_cast(&number_of_images), sizeof(number_of_images)); + file.read(reinterpret_cast(&number_of_images), sizeof(number_of_images)); number_of_images = reverseInt(number_of_images); - file.read(reinterpret_cast(&n_rows), sizeof(n_rows)); + file.read(reinterpret_cast(&n_rows), sizeof(n_rows)); n_rows = reverseInt(n_rows); - _height = (size_t) n_rows; - file.read(reinterpret_cast(&n_cols), sizeof(n_cols)); + _height = (size_t)n_rows; + file.read(reinterpret_cast(&n_cols), sizeof(n_cols)); n_cols = reverseInt(n_cols); - _width = (size_t) n_cols; + _width = (size_t)n_cols; if (number_of_images > 1) { - std::cout << "[MNIST] Warning: number_of_images in mnist file equals " << number_of_images - << ". Only a first image will be read." << std::endl; + std::cout << "[MNIST] Warning: number_of_images in mnist file equals " << number_of_images << ". Only a first image will be read." << std::endl; } size_t size = _width * _height * 1; @@ -53,7 +53,7 @@ MnistUbyte::MnistUbyte(const std::string &filename) { for (int r = 0; r < n_rows; ++r) { for (int c = 0; c < n_cols; ++c) { unsigned char temp = 0; - file.read(reinterpret_cast(&temp), sizeof(temp)); + file.read(reinterpret_cast(&temp), sizeof(temp)); _data.get()[count++] = temp; } } diff --git a/inference-engine/samples/common/format_reader/MnistUbyte.h b/inference-engine/samples/common/format_reader/MnistUbyte.h index 6a9c2e3e1ca..243e821f40c 100644 --- a/inference-engine/samples/common/format_reader/MnistUbyte.h +++ b/inference-engine/samples/common/format_reader/MnistUbyte.h @@ -8,9 +8,10 @@ */ #pragma once +#include + #include #include -#include #include "register.h" @@ -31,9 +32,8 @@ public: * @param filename - path to input data * @return MnistUbyte reader object */ - explicit MnistUbyte(const std::string &filename); - virtual ~MnistUbyte() { - } + explicit MnistUbyte(const std::string& filename); + virtual ~MnistUbyte() {} /** * \brief Get size diff --git a/inference-engine/samples/common/format_reader/bmp.cpp b/inference-engine/samples/common/format_reader/bmp.cpp index dc4bf1546ae..30d6088f354 100644 --- a/inference-engine/samples/common/format_reader/bmp.cpp +++ b/inference-engine/samples/common/format_reader/bmp.cpp @@ -3,14 +3,14 @@ // #include "bmp.h" + #include #include using namespace std; using namespace FormatReader; - -BitMap::BitMap(const string &filename) { +BitMap::BitMap(const string& filename) { BmpHeader header; BmpInfoHeader infoHeader; @@ -19,19 +19,18 @@ BitMap::BitMap(const string &filename) { return; } - input.read(reinterpret_cast(&header.type), 2); + input.read(reinterpret_cast(&header.type), 2); - if (header.type != 'M'*256+'B') { + if (header.type != 'M' * 256 + 'B') { std::cerr << "[BMP] file is not bmp type\n"; return; } - input.read(reinterpret_cast(&header.size), 4); - input.read(reinterpret_cast(&header.reserved), 4); - input.read(reinterpret_cast(&header.offset), 4); - - input.read(reinterpret_cast(&infoHeader), sizeof(BmpInfoHeader)); + input.read(reinterpret_cast(&header.size), 4); + input.read(reinterpret_cast(&header.reserved), 4); + input.read(reinterpret_cast(&header.offset), 4); + input.read(reinterpret_cast(&infoHeader), sizeof(BmpInfoHeader)); bool rowsReversed = infoHeader.height < 0; _width = infoHeader.width; @@ -57,7 +56,7 @@ BitMap::BitMap(const string &filename) { // reading by rows in invert vertically for (uint32_t i = 0; i < _height; i++) { uint32_t storeAt = rowsReversed ? i : (uint32_t)_height - 1 - i; - input.read(reinterpret_cast(_data.get()) + _width * 3 * storeAt, _width * 3); + input.read(reinterpret_cast(_data.get()) + _width * 3 * storeAt, _width * 3); input.read(pad, padSize); } } diff --git a/inference-engine/samples/common/format_reader/bmp.h b/inference-engine/samples/common/format_reader/bmp.h index 8e97aa731f4..b8a459952e6 100644 --- a/inference-engine/samples/common/format_reader/bmp.h +++ b/inference-engine/samples/common/format_reader/bmp.h @@ -8,9 +8,10 @@ */ #pragma once +#include + #include #include -#include #include "register.h" @@ -24,22 +25,22 @@ private: static Register reg; typedef struct BmpHeaderType { - unsigned short type = 0u; /* Magic identifier */ - unsigned int size = 0u; /* File size in bytes */ + unsigned short type = 0u; /* Magic identifier */ + unsigned int size = 0u; /* File size in bytes */ unsigned int reserved = 0u; - unsigned int offset = 0u; /* Offset to image data, bytes */ + unsigned int offset = 0u; /* Offset to image data, bytes */ } BmpHeader; typedef struct BmpInfoHeaderType { - unsigned int size = 0u; /* Header size in bytes */ - int width = 0, height = 0; /* Width and height of image */ - unsigned short planes = 0u; /* Number of colour planes */ - unsigned short bits = 0u; /* Bits per pixel */ - unsigned int compression = 0u; /* Compression type */ - unsigned int imagesize = 0u; /* Image size in bytes */ - int xresolution = 0, yresolution = 0; /* Pixels per meter */ - unsigned int ncolours = 0u; /* Number of colours */ - unsigned int importantcolours = 0u; /* Important colours */ + unsigned int size = 0u; /* Header size in bytes */ + int width = 0, height = 0; /* Width and height of image */ + unsigned short planes = 0u; /* Number of colour planes */ + unsigned short bits = 0u; /* Bits per pixel */ + unsigned int compression = 0u; /* Compression type */ + unsigned int imagesize = 0u; /* Image size in bytes */ + int xresolution = 0, yresolution = 0; /* Pixels per meter */ + unsigned int ncolours = 0u; /* Number of colours */ + unsigned int importantcolours = 0u; /* Important colours */ } BmpInfoHeader; public: @@ -48,9 +49,8 @@ public: * @param filename - path to input data * @return BitMap reader object */ - explicit BitMap(const std::string &filename); - virtual ~BitMap() { - } + explicit BitMap(const std::string& filename); + virtual ~BitMap() {} /** * \brief Get size diff --git a/inference-engine/samples/common/format_reader/format_reader.cpp b/inference-engine/samples/common/format_reader/format_reader.cpp index dc8bb4e7edc..a8ae1cf6098 100644 --- a/inference-engine/samples/common/format_reader/format_reader.cpp +++ b/inference-engine/samples/common/format_reader/format_reader.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include -#include "bmp.h" + +#include + #include "MnistUbyte.h" +#include "bmp.h" #include "opencv_wraper.h" using namespace FormatReader; @@ -19,11 +21,13 @@ Register OCVReader::reg; Register BitMap::reg; #endif -Reader *Registry::CreateReader(const char *filename) { +Reader* Registry::CreateReader(const char* filename) { for (auto maker : _data) { - Reader *ol = maker(filename); - if (ol != nullptr && ol->size() != 0) return ol; - if (ol != nullptr) delete ol; + Reader* ol = maker(filename); + if (ol != nullptr && ol->size() != 0) + return ol; + if (ol != nullptr) + delete ol; } return nullptr; } @@ -32,6 +36,6 @@ void Registry::RegisterReader(CreatorFunction f) { _data.push_back(f); } -FORMAT_READER_API(Reader*) CreateFormatReader(const char *filename) { +FORMAT_READER_API(Reader*) CreateFormatReader(const char* filename) { return Registry::CreateReader(filename); } diff --git a/inference-engine/samples/common/format_reader/format_reader.h b/inference-engine/samples/common/format_reader/format_reader.h index 4b415c282d1..0a7c14fbaae 100644 --- a/inference-engine/samples/common/format_reader/format_reader.h +++ b/inference-engine/samples/common/format_reader/format_reader.h @@ -8,28 +8,27 @@ */ #pragma once +#include #include #include #include -#include #if defined(_WIN32) -# ifdef IMPLEMENT_FORMAT_READER -# define FORMAT_READER_API(type) extern "C" __declspec(dllexport) type -# else -# define FORMAT_READER_API(type) extern "C" type -# endif -#elif(__GNUC__ >= 4) -# ifdef IMPLEMENT_FORMAT_READER -# define FORMAT_READER_API(type) extern "C" __attribute__((visibility("default"))) type -# else -# define FORMAT_READER_API(type) extern "C" type -# endif + #ifdef IMPLEMENT_FORMAT_READER + #define FORMAT_READER_API(type) extern "C" __declspec(dllexport) type + #else + #define FORMAT_READER_API(type) extern "C" type + #endif +#elif (__GNUC__ >= 4) + #ifdef IMPLEMENT_FORMAT_READER + #define FORMAT_READER_API(type) extern "C" __attribute__((visibility("default"))) type + #else + #define FORMAT_READER_API(type) extern "C" type + #endif #else -# define FORMAT_READER_API(TYPE) extern "C" TYPE + #define FORMAT_READER_API(TYPE) extern "C" TYPE #endif - namespace FormatReader { /** * \class FormatReader @@ -51,13 +50,17 @@ public: * \brief Get width * @return width */ - size_t width() const { return _width; } + size_t width() const { + return _width; + } /** * \brief Get height * @return height */ - size_t height() const { return _height; } + size_t height() const { + return _height; + } /** * \brief Get input data ptr @@ -78,4 +81,4 @@ public: * \brief Function for create reader * @return FormatReader pointer */ -FORMAT_READER_API(FormatReader::Reader*) CreateFormatReader(const char *filename); \ No newline at end of file +FORMAT_READER_API(FormatReader::Reader*) CreateFormatReader(const char* filename); \ No newline at end of file diff --git a/inference-engine/samples/common/format_reader/format_reader_ptr.h b/inference-engine/samples/common/format_reader/format_reader_ptr.h index d2beb3e1b5a..ad026c3c148 100644 --- a/inference-engine/samples/common/format_reader/format_reader_ptr.h +++ b/inference-engine/samples/common/format_reader/format_reader_ptr.h @@ -8,19 +8,20 @@ */ #pragma once -#include "format_reader.h" #include #include +#include "format_reader.h" + namespace FormatReader { class ReaderPtr { public: - explicit ReaderPtr(const char *imageName) : reader(CreateFormatReader(imageName)) {} + explicit ReaderPtr(const char* imageName): reader(CreateFormatReader(imageName)) {} /** * @brief dereference operator overload * @return Reader */ - Reader *operator->() const noexcept { + Reader* operator->() const noexcept { return reader.get(); } @@ -28,11 +29,11 @@ public: * @brief dereference operator overload * @return Reader */ - Reader *operator*() const noexcept { + Reader* operator*() const noexcept { return reader.get(); } - Reader *get() { + Reader* get() { return reader.get(); } diff --git a/inference-engine/samples/common/format_reader/opencv_wraper.cpp b/inference-engine/samples/common/format_reader/opencv_wraper.cpp index a27d2f90125..dce8b651069 100644 --- a/inference-engine/samples/common/format_reader/opencv_wraper.cpp +++ b/inference-engine/samples/common/format_reader/opencv_wraper.cpp @@ -3,18 +3,17 @@ // #ifdef USE_OPENCV -#include "opencv_wraper.h" -#include -#include + #include "opencv_wraper.h" -#include - -#include + #include + #include + #include + #include using namespace std; using namespace FormatReader; -OCVReader::OCVReader(const string &filename) { +OCVReader::OCVReader(const string& filename) { img = cv::imread(filename); _size = 0; @@ -22,8 +21,8 @@ OCVReader::OCVReader(const string &filename) { return; } - _size = img.size().width * img.size().height * img.channels(); - _width = img.size().width; + _size = img.size().width * img.size().height * img.channels(); + _width = img.size().width; _height = img.size().height; } diff --git a/inference-engine/samples/common/format_reader/opencv_wraper.h b/inference-engine/samples/common/format_reader/opencv_wraper.h index 2b48047bc73..aed9448ee01 100644 --- a/inference-engine/samples/common/format_reader/opencv_wraper.h +++ b/inference-engine/samples/common/format_reader/opencv_wraper.h @@ -9,13 +9,13 @@ #pragma once #ifdef USE_OPENCV -#include -#include -#include + #include -#include + #include + #include + #include -#include "register.h" + #include "register.h" namespace FormatReader { /** @@ -30,18 +30,17 @@ private: public: /** - * \brief Constructor of BMP reader - * @param filename - path to input data - * @return BitMap reader object - */ - explicit OCVReader(const std::string &filename); - virtual ~OCVReader() { - } + * \brief Constructor of BMP reader + * @param filename - path to input data + * @return BitMap reader object + */ + explicit OCVReader(const std::string& filename); + virtual ~OCVReader() {} /** - * \brief Get size - * @return size - */ + * \brief Get size + * @return size + */ size_t size() const override { return _size; } diff --git a/inference-engine/samples/common/format_reader/register.h b/inference-engine/samples/common/format_reader/register.h index 58d59caf1f6..8f92a804b4b 100644 --- a/inference-engine/samples/common/format_reader/register.h +++ b/inference-engine/samples/common/format_reader/register.h @@ -8,9 +8,10 @@ #pragma once #include + #include -#include #include +#include namespace FormatReader { /** @@ -19,15 +20,16 @@ namespace FormatReader { */ class Registry { private: - typedef std::function CreatorFunction; + typedef std::function CreatorFunction; static std::vector _data; + public: /** * \brief Create reader * @param filename - path to input data * @return Reader for input data or nullptr */ - static Reader *CreateReader(const char *filename); + static Reader* CreateReader(const char* filename); /** * \brief Registers reader in fabric @@ -40,7 +42,7 @@ public: * \class Register * \brief Registers reader in fabric */ -template +template class Register { public: /** @@ -48,7 +50,7 @@ public: * @return Register object */ Register() { - Registry::RegisterReader([](const std::string &filename) -> Reader * { + Registry::RegisterReader([](const std::string& filename) -> Reader* { return new To(filename); }); } diff --git a/inference-engine/samples/common/utils/CMakeLists.txt b/inference-engine/samples/common/utils/CMakeLists.txt index fb5d462a2f2..96dd896bdb0 100644 --- a/inference-engine/samples/common/utils/CMakeLists.txt +++ b/inference-engine/samples/common/utils/CMakeLists.txt @@ -3,7 +3,7 @@ # set(TARGET_NAME "ie_samples_utils") -file(GLOB_RECURSE SOURCES "*.cpp" "*.hpp") +file(GLOB_RECURSE SOURCES "*.cpp" "*.hpp" "*.h") source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) add_library(${TARGET_NAME} STATIC ${SOURCES}) @@ -17,3 +17,7 @@ target_link_libraries(${TARGET_NAME} PUBLIC IE::inference_engine gflags) + +if(COMMAND add_clang_format_target) + add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) +endif() \ No newline at end of file diff --git a/inference-engine/samples/common/utils/include/samples/args_helper.hpp b/inference-engine/samples/common/utils/include/samples/args_helper.hpp index 0b4d5da3c29..fa8b1a5392d 100644 --- a/inference-engine/samples/common/utils/include/samples/args_helper.hpp +++ b/inference-engine/samples/common/utils/include/samples/args_helper.hpp @@ -9,28 +9,26 @@ #pragma once +#include #include #include -#include +/** + * @brief This function checks input args and existence of specified files in a given folder + * @param arg path to a file to be checked for existence + * @return files updated vector of verified input files + */ +void readInputFilesArguments(std::vector& files, const std::string& arg); /** -* @brief This function checks input args and existence of specified files in a given folder -* @param arg path to a file to be checked for existence -* @return files updated vector of verified input files -*/ -void readInputFilesArguments(std::vector &files, const std::string& arg); + * @brief This function find -i/--images key in input args + * It's necessary to process multiple values for single key + * @return files updated vector of verified input files + */ +void parseInputFilesArguments(std::vector& files); -/** -* @brief This function find -i/--images key in input args -* It's necessary to process multiple values for single key -* @return files updated vector of verified input files -*/ -void parseInputFilesArguments(std::vector &files); - -void processPrecision(InferenceEngine::CNNNetwork& network, const std::string &ip, const std::string &op, const std::string &iop); +void processPrecision(InferenceEngine::CNNNetwork& network, const std::string& ip, const std::string& op, const std::string& iop); void processLayout(InferenceEngine::CNNNetwork& network, const std::string& il, const std::string& ol, const std::string& iol); void printInputAndOutputsInfo(const InferenceEngine::CNNNetwork& network); - diff --git a/inference-engine/samples/common/utils/include/samples/classification_results.h b/inference-engine/samples/common/utils/include/samples/classification_results.h index 3435694579f..b17e47bda61 100644 --- a/inference-engine/samples/common/utils/include/samples/classification_results.h +++ b/inference-engine/samples/common/utils/include/samples/classification_results.h @@ -4,23 +4,23 @@ /** * @brief a header file with output classification results - * @file classification_results.hpp + * @file classification_results.h */ #pragma once -#include -#include -#include -#include #include - #include +#include +#include +#include +#include +#include /** * @class ClassificationResult * @brief A ClassificationResult creates an output table with results */ -template +template class ClassificationResultT { private: const std::string _classidStr = "classid"; @@ -57,7 +57,8 @@ private: void topResults(unsigned int n, InferenceEngine::TBlob& input, std::vector& output) { InferenceEngine::SizeVector dims = input.getTensorDesc().getDims(); size_t input_rank = dims.size(); - if (!input_rank || !dims[0]) IE_THROW() << "Input blob has incorrect dimensions!"; + if (!input_rank || !dims[0]) + IE_THROW() << "Input blob has incorrect dimensions!"; size_t batchSize = dims[0]; std::vector indexes(input.size() / batchSize); @@ -71,10 +72,9 @@ private: batchData += offset; std::iota(std::begin(indexes), std::end(indexes), 0); - std::partial_sort(std::begin(indexes), std::begin(indexes) + n, std::end(indexes), - [&batchData](unsigned l, unsigned r) { - return batchData[l] > batchData[r]; - }); + std::partial_sort(std::begin(indexes), std::begin(indexes) + n, std::end(indexes), [&batchData](unsigned l, unsigned r) { + return batchData[l] > batchData[r]; + }); for (unsigned j = 0; j < n; j++) { output.at(i * n + j) = indexes.at(j); } @@ -89,13 +89,13 @@ private: * @param output Vector of indexes for the top n places */ void topResults(unsigned int n, InferenceEngine::Blob& input, std::vector& output) { - #define TBLOB_TOP_RESULT(precision) \ - case InferenceEngine::Precision::precision: { \ - using myBlobType = InferenceEngine::PrecisionTrait::value_type; \ - InferenceEngine::TBlob& tblob = dynamic_cast&>(input); \ - topResults(n, tblob, output); \ - break; \ - } +#define TBLOB_TOP_RESULT(precision) \ + case InferenceEngine::Precision::precision: { \ + using myBlobType = InferenceEngine::PrecisionTrait::value_type; \ + InferenceEngine::TBlob& tblob = dynamic_cast&>(input); \ + topResults(n, tblob, output); \ + break; \ + } switch (input.getTensorDesc().getPrecision()) { TBLOB_TOP_RESULT(FP32); @@ -114,21 +114,18 @@ private: IE_THROW() << "cannot locate blob for precision: " << input.getTensorDesc().getPrecision(); } - #undef TBLOB_TOP_RESULT +#undef TBLOB_TOP_RESULT } public: - explicit ClassificationResultT(InferenceEngine::Blob::Ptr output_blob, - std::vector image_names = {}, - size_t batch_size = 1, - size_t num_of_top = 10, - std::vector labels = {}) : - _nTop(num_of_top), - _outBlob(std::move(output_blob)), - _labels(std::move(labels)), - _imageNames(std::move(image_names)), - _batchSize(batch_size), - _results() { + explicit ClassificationResultT(InferenceEngine::Blob::Ptr output_blob, std::vector image_names = {}, size_t batch_size = 1, size_t num_of_top = 10, + std::vector labels = {}) + : _nTop(num_of_top), + _outBlob(std::move(output_blob)), + _labels(std::move(labels)), + _imageNames(std::move(image_names)), + _batchSize(batch_size), + _results() { if (_imageNames.size() != _batchSize) { throw std::logic_error("Batch size should be equal to the number of images."); } @@ -136,8 +133,8 @@ public: } /** - * @brief prints formatted classification results - */ + * @brief prints formatted classification results + */ void print() { /** Print the result iterating over each batch **/ std::cout << std::endl << "Top " << _nTop << " results:" << std::endl << std::endl; @@ -154,15 +151,17 @@ public: /** Getting probability for resulting class **/ InferenceEngine::MemoryBlob::CPtr moutput = InferenceEngine::as(_outBlob); if (!moutput) { - throw std::logic_error("We expect _outBlob to be inherited from MemoryBlob in ClassificationResult::print, " + throw std::logic_error("We expect _outBlob to be inherited from MemoryBlob in " + "ClassificationResult::print, " "but by fact we were not able to cast _outBlob to MemoryBlob"); } // locked memory holder should be alive all time while access to its buffer happens auto moutputHolder = moutput->rmap(); - const auto result = moutputHolder. - as::value_type*>() - [_results[id] + image_id * (_outBlob->size() / _batchSize)]; + const auto result = + moutputHolder + .as::value_type*>()[_results[id] + + image_id * (_outBlob->size() / _batchSize)]; std::cout << std::setw(static_cast(_classidStr.length())) << std::left << _results[id] << " "; std::cout << std::left << std::setw(static_cast(_probabilityStr.length())) << std::fixed << result; @@ -177,8 +176,8 @@ public: } /** - * @brief returns the classification results in a vector - */ + * @brief returns the classification results in a vector + */ std::vector getResults() { return _results; } diff --git a/inference-engine/samples/common/utils/include/samples/common.hpp b/inference-engine/samples/common/utils/include/samples/common.hpp index 7e0da7cb67b..48de4961ad9 100644 --- a/inference-engine/samples/common/utils/include/samples/common.hpp +++ b/inference-engine/samples/common/utils/include/samples/common.hpp @@ -9,53 +9,55 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include - +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #ifndef UNUSED - #if defined (_MSC_VER) && !defined (__clang__) - #define UNUSED - #else - #define UNUSED __attribute__((unused)) - #endif + #if defined(_MSC_VER) && !defined(__clang__) + #define UNUSED + #else + #define UNUSED __attribute__((unused)) + #endif #endif /** * @brief trim from start (in place) * @param s - string to trim */ -inline void ltrim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c){ - return !std::isspace(c); - })); +inline void ltrim(std::string& s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { + return !std::isspace(c); + })); } /** * @brief trim from end (in place) * @param s - string to trim */ -inline void rtrim(std::string &s) { - s.erase(std::find_if(s.rbegin(), s.rend(), [](int c) { - return !std::isspace(c); - }).base(), s.end()); +inline void rtrim(std::string& s) { + s.erase(std::find_if(s.rbegin(), s.rend(), + [](int c) { + return !std::isspace(c); + }) + .base(), + s.end()); } /** * @brief trim from both ends (in place) * @param s - string to trim */ -inline std::string &trim(std::string &s) { +inline std::string& trim(std::string& s) { ltrim(s); rtrim(s); return s; @@ -65,40 +67,44 @@ inline std::string &trim(std::string &s) { * @param filepath - full file name * @return filename without extension */ -static UNUSED std::string fileNameNoExt(const std::string &filepath) { +static UNUSED std::string fileNameNoExt(const std::string& filepath) { auto pos = filepath.rfind('.'); - if (pos == std::string::npos) return filepath; + if (pos == std::string::npos) + return filepath; return filepath.substr(0, pos); } /** -* @brief Get extension from filename -* @param filename - name of the file which extension should be extracted -* @return string with extracted file extension -*/ + * @brief Get extension from filename + * @param filename - name of the file which extension should be extracted + * @return string with extracted file extension + */ inline std::string fileExt(const std::string& filename) { auto pos = filename.rfind('.'); - if (pos == std::string::npos) return ""; + if (pos == std::string::npos) + return ""; return filename.substr(pos + 1); } -static UNUSED std::ostream &operator<<(std::ostream &os, const InferenceEngine::Version *version) { +static UNUSED std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version* version) { os << "\n\tAPI version ............ "; if (nullptr == version) { os << "UNKNOWN"; } else { os << version->apiVersion.major << "." << version->apiVersion.minor; if (nullptr != version->buildNumber) { - os << "\n\t" << "Build .................. " << version->buildNumber; + os << "\n\t" + << "Build .................. " << version->buildNumber; } if (nullptr != version->description) { - os << "\n\t" << "Description ....... " << version->description; + os << "\n\t" + << "Description ....... " << version->description; } } return os; } -inline std::ostream &operator<<(std::ostream &os, const InferenceEngine::Version &version) { +inline std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version& version) { os << "\t" << version.description << " version ......... "; os << version.apiVersion.major << "." << version.apiVersion.minor; @@ -108,8 +114,8 @@ inline std::ostream &operator<<(std::ostream &os, const InferenceEngine::Version return os; } -inline std::ostream &operator<<(std::ostream &os, const std::map &versions) { - for (auto && version : versions) { +inline std::ostream& operator<<(std::ostream& os, const std::map& versions) { + for (auto&& version : versions) { os << "\t" << version.first << std::endl; os << version.second << std::endl; } @@ -117,9 +123,8 @@ inline std::ostream &operator<<(std::ostream &os, const std::map> blobToImageOutputArray(InferenceEngine::TBlob::Ptr output, - size_t *pWidth, size_t *pHeight, - size_t *pChannels) { +static UNUSED std::vector> blobToImageOutputArray(InferenceEngine::TBlob::Ptr output, size_t* pWidth, size_t* pHeight, + size_t* pChannels) { std::vector> outArray; size_t W = 0, C = 0, H = 0; @@ -141,7 +146,7 @@ static UNUSED std::vector> blobToImageOutputArray(InferenceE } // Get classes - const float *outData = output->data(); + const float* outData = output->data(); for (unsigned h = 0; h < H; h++) { std::vector row; for (unsigned w = 0; w < W; w++) { @@ -159,9 +164,12 @@ static UNUSED std::vector> blobToImageOutputArray(InferenceE outArray.push_back(row); } - if (pWidth != nullptr) *pWidth = W; - if (pHeight != nullptr) *pHeight = H; - if (pChannels != nullptr) *pChannels = C; + if (pWidth != nullptr) + *pWidth = W; + if (pHeight != nullptr) + *pHeight = H; + if (pChannels != nullptr) + *pChannels = C; return outArray; } @@ -183,9 +191,7 @@ public: * @param g - value for green channel * @param b - value for blue channel */ - Color(unsigned char r, - unsigned char g, - unsigned char b) : _r(r), _g(g), _b(b) {} + Color(unsigned char r, unsigned char g, unsigned char b): _r(r), _g(g), _b(b) {} inline unsigned char red() { return _r; @@ -209,32 +215,12 @@ public: * @param classesNum - the number of classes * @return false if error else true */ -static UNUSED void writeOutputBmp(std::vector> data, size_t classesNum, std::ostream &outFile) { - unsigned int seed = (unsigned int) time(NULL); +static UNUSED void writeOutputBmp(std::vector> data, size_t classesNum, std::ostream& outFile) { + unsigned int seed = (unsigned int)time(NULL); // Known colors for training classes from Cityscape dataset - static std::vector colors = { - {128, 64, 128}, - {232, 35, 244}, - {70, 70, 70}, - {156, 102, 102}, - {153, 153, 190}, - {153, 153, 153}, - {30, 170, 250}, - {0, 220, 220}, - {35, 142, 107}, - {152, 251, 152}, - {180, 130, 70}, - {60, 20, 220}, - {0, 0, 255}, - {142, 0, 0}, - {70, 0, 0}, - {100, 60, 0}, - {90, 0, 0}, - {230, 0, 0}, - {32, 11, 119}, - {0, 74, 111}, - {81, 0, 81} - }; + static std::vector colors = {{128, 64, 128}, {232, 35, 244}, {70, 70, 70}, {156, 102, 102}, {153, 153, 190}, {153, 153, 153}, {30, 170, 250}, + {0, 220, 220}, {35, 142, 107}, {152, 251, 152}, {180, 130, 70}, {60, 20, 220}, {0, 0, 255}, {142, 0, 0}, + {70, 0, 0}, {100, 60, 0}, {90, 0, 0}, {230, 0, 0}, {32, 11, 119}, {0, 74, 111}, {81, 0, 81}}; while (classesNum > colors.size()) { static std::mt19937 rng(seed); @@ -244,30 +230,35 @@ static UNUSED void writeOutputBmp(std::vector> data, size_t } unsigned char file[14] = { - 'B', 'M', // magic - 0, 0, 0, 0, // size in bytes - 0, 0, // app data - 0, 0, // app data - 40 + 14, 0, 0, 0 // start of data offset + 'B', + 'M', // magic + 0, 0, 0, + 0, // size in bytes + 0, + 0, // app data + 0, + 0, // app data + 40 + 14, 0, 0, + 0 // start of data offset }; unsigned char info[40] = { - 40, 0, 0, 0, // info hd size - 0, 0, 0, 0, // width - 0, 0, 0, 0, // height - 1, 0, // number color planes - 24, 0, // bits per pixel - 0, 0, 0, 0, // compression is none - 0, 0, 0, 0, // image bits size - 0x13, 0x0B, 0, 0, // horz resolution in pixel / m - 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) - 0, 0, 0, 0, // #colors in palette - 0, 0, 0, 0, // #important colors + 40, 0, 0, 0, // info hd size + 0, 0, 0, 0, // width + 0, 0, 0, 0, // height + 1, 0, // number color planes + 24, 0, // bits per pixel + 0, 0, 0, 0, // compression is none + 0, 0, 0, 0, // image bits size + 0x13, 0x0B, 0, 0, // horz resolution in pixel / m + 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) + 0, 0, 0, 0, // #colors in palette + 0, 0, 0, 0, // #important colors }; auto height = data.size(); auto width = data.at(0).size(); - if (height > (size_t) std::numeric_limits::max || width > (size_t) std::numeric_limits::max) { + if (height > (size_t)std::numeric_limits::max || width > (size_t)std::numeric_limits::max) { IE_THROW() << "File size is too big: " << height << " X " << width; } @@ -275,29 +266,29 @@ static UNUSED void writeOutputBmp(std::vector> data, size_t int sizeData = static_cast(width * height * 3 + height * padSize); int sizeAll = sizeData + sizeof(file) + sizeof(info); - file[2] = (unsigned char) (sizeAll); - file[3] = (unsigned char) (sizeAll >> 8); - file[4] = (unsigned char) (sizeAll >> 16); - file[5] = (unsigned char) (sizeAll >> 24); + file[2] = (unsigned char)(sizeAll); + file[3] = (unsigned char)(sizeAll >> 8); + file[4] = (unsigned char)(sizeAll >> 16); + file[5] = (unsigned char)(sizeAll >> 24); - info[4] = (unsigned char) (width); - info[5] = (unsigned char) (width >> 8); - info[6] = (unsigned char) (width >> 16); - info[7] = (unsigned char) (width >> 24); + info[4] = (unsigned char)(width); + info[5] = (unsigned char)(width >> 8); + info[6] = (unsigned char)(width >> 16); + info[7] = (unsigned char)(width >> 24); - int32_t negativeHeight = -(int32_t) height; - info[8] = (unsigned char) (negativeHeight); - info[9] = (unsigned char) (negativeHeight >> 8); - info[10] = (unsigned char) (negativeHeight >> 16); - info[11] = (unsigned char) (negativeHeight >> 24); + int32_t negativeHeight = -(int32_t)height; + info[8] = (unsigned char)(negativeHeight); + info[9] = (unsigned char)(negativeHeight >> 8); + info[10] = (unsigned char)(negativeHeight >> 16); + info[11] = (unsigned char)(negativeHeight >> 24); - info[20] = (unsigned char) (sizeData); - info[21] = (unsigned char) (sizeData >> 8); - info[22] = (unsigned char) (sizeData >> 16); - info[23] = (unsigned char) (sizeData >> 24); + info[20] = (unsigned char)(sizeData); + info[21] = (unsigned char)(sizeData >> 8); + info[22] = (unsigned char)(sizeData >> 16); + info[23] = (unsigned char)(sizeData >> 24); - outFile.write(reinterpret_cast(file), sizeof(file)); - outFile.write(reinterpret_cast(info), sizeof(info)); + outFile.write(reinterpret_cast(file), sizeof(file)); + outFile.write(reinterpret_cast(info), sizeof(info)); unsigned char pad[3] = {0, 0, 0}; @@ -308,21 +299,21 @@ static UNUSED void writeOutputBmp(std::vector> data, size_t pixel[0] = colors.at(index).red(); pixel[1] = colors.at(index).green(); pixel[2] = colors.at(index).blue(); - outFile.write(reinterpret_cast(pixel), 3); + outFile.write(reinterpret_cast(pixel), 3); } - outFile.write(reinterpret_cast(pad), padSize); + outFile.write(reinterpret_cast(pad), padSize); } } /** -* @brief Writes output data to BMP image -* @param name - image name -* @param data - output data -* @param height - height of the target image -* @param width - width of the target image -* @return false if error else true -*/ -static UNUSED bool writeOutputBmp(std::string name, unsigned char *data, size_t height, size_t width) { + * @brief Writes output data to BMP image + * @param name - image name + * @param data - output data + * @param height - height of the target image + * @param width - width of the target image + * @return false if error else true + */ +static UNUSED bool writeOutputBmp(std::string name, unsigned char* data, size_t height, size_t width) { std::ofstream outFile; outFile.open(name, std::ofstream::binary); if (!outFile.is_open()) { @@ -330,24 +321,29 @@ static UNUSED bool writeOutputBmp(std::string name, unsigned char *data, size_t } unsigned char file[14] = { - 'B', 'M', // magic - 0, 0, 0, 0, // size in bytes - 0, 0, // app data - 0, 0, // app data - 40 + 14, 0, 0, 0 // start of data offset + 'B', + 'M', // magic + 0, 0, 0, + 0, // size in bytes + 0, + 0, // app data + 0, + 0, // app data + 40 + 14, 0, 0, + 0 // start of data offset }; unsigned char info[40] = { - 40, 0, 0, 0, // info hd size - 0, 0, 0, 0, // width - 0, 0, 0, 0, // height - 1, 0, // number color planes - 24, 0, // bits per pixel - 0, 0, 0, 0, // compression is none - 0, 0, 0, 0, // image bits size - 0x13, 0x0B, 0, 0, // horz resolution in pixel / m - 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) - 0, 0, 0, 0, // #colors in palette - 0, 0, 0, 0, // #important colors + 40, 0, 0, 0, // info hd size + 0, 0, 0, 0, // width + 0, 0, 0, 0, // height + 1, 0, // number color planes + 24, 0, // bits per pixel + 0, 0, 0, 0, // compression is none + 0, 0, 0, 0, // image bits size + 0x13, 0x0B, 0, 0, // horz resolution in pixel / m + 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) + 0, 0, 0, 0, // #colors in palette + 0, 0, 0, 0, // #important colors }; if (height > (size_t)std::numeric_limits::max || width > (size_t)std::numeric_limits::max) { @@ -379,10 +375,10 @@ static UNUSED bool writeOutputBmp(std::string name, unsigned char *data, size_t info[22] = (unsigned char)(sizeData >> 16); info[23] = (unsigned char)(sizeData >> 24); - outFile.write(reinterpret_cast(file), sizeof(file)); - outFile.write(reinterpret_cast(info), sizeof(info)); + outFile.write(reinterpret_cast(file), sizeof(file)); + outFile.write(reinterpret_cast(info), sizeof(info)); - unsigned char pad[3] = { 0, 0, 0 }; + unsigned char pad[3] = {0, 0, 0}; for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { @@ -391,47 +387,27 @@ static UNUSED bool writeOutputBmp(std::string name, unsigned char *data, size_t pixel[1] = data[y * width * 3 + x * 3 + 1]; pixel[2] = data[y * width * 3 + x * 3 + 2]; - outFile.write(reinterpret_cast(pixel), 3); + outFile.write(reinterpret_cast(pixel), 3); } - outFile.write(reinterpret_cast(pad), padSize); + outFile.write(reinterpret_cast(pad), padSize); } return true; } - /** -* @brief Adds colored rectangles to the image -* @param data - data where rectangles are put -* @param height - height of the rectangle -* @param width - width of the rectangle -* @param rectangles - vector points for the rectangle, should be 4x compared to num classes -* @param classes - vector of classes -* @param thickness - thickness of a line (in pixels) to be used for bounding boxes -*/ -static UNUSED void addRectangles(unsigned char *data, size_t height, size_t width, std::vector rectangles, std::vector classes, int thickness = 1) { - std::vector colors = { // colors to be used for bounding boxes - { 128, 64, 128 }, - { 232, 35, 244 }, - { 70, 70, 70 }, - { 156, 102, 102 }, - { 153, 153, 190 }, - { 153, 153, 153 }, - { 30, 170, 250 }, - { 0, 220, 220 }, - { 35, 142, 107 }, - { 152, 251, 152 }, - { 180, 130, 70 }, - { 60, 20, 220 }, - { 0, 0, 255 }, - { 142, 0, 0 }, - { 70, 0, 0 }, - { 100, 60, 0 }, - { 90, 0, 0 }, - { 230, 0, 0 }, - { 32, 11, 119 }, - { 0, 74, 111 }, - { 81, 0, 81 } - }; + * @brief Adds colored rectangles to the image + * @param data - data where rectangles are put + * @param height - height of the rectangle + * @param width - width of the rectangle + * @param rectangles - vector points for the rectangle, should be 4x compared to num classes + * @param classes - vector of classes + * @param thickness - thickness of a line (in pixels) to be used for bounding boxes + */ +static UNUSED void addRectangles(unsigned char* data, size_t height, size_t width, std::vector rectangles, std::vector classes, int thickness = 1) { + std::vector colors = {// colors to be used for bounding boxes + {128, 64, 128}, {232, 35, 244}, {70, 70, 70}, {156, 102, 102}, {153, 153, 190}, {153, 153, 153}, {30, 170, 250}, + {0, 220, 220}, {35, 142, 107}, {152, 251, 152}, {180, 130, 70}, {60, 20, 220}, {0, 0, 255}, {142, 0, 0}, + {70, 0, 0}, {100, 60, 0}, {90, 0, 0}, {230, 0, 0}, {32, 11, 119}, {0, 74, 111}, {81, 0, 81}}; if (rectangles.size() % 4 != 0 || rectangles.size() / 4 != classes.size()) { return; } @@ -444,16 +420,32 @@ static UNUSED void addRectangles(unsigned char *data, size_t height, size_t widt int cls = classes.at(i) % colors.size(); // color of a bounding box line - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w < 0) w = 0; - if (h < 0) h = 0; + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (w < 0) + w = 0; + if (h < 0) + h = 0; - if (static_cast(x) >= width) { x = width - 1; w = 0; thickness = 1; } - if (static_cast(y) >= height) { y = height - 1; h = 0; thickness = 1; } + if (static_cast(x) >= width) { + x = width - 1; + w = 0; + thickness = 1; + } + if (static_cast(y) >= height) { + y = height - 1; + h = 0; + thickness = 1; + } - if (static_cast(x + w) >= width) { w = width - x - 1; } - if (static_cast(y + h) >= height) { h = height - y - 1; } + if (static_cast(x + w) >= width) { + w = width - x - 1; + } + if (static_cast(y + h) >= height) { + h = height - y - 1; + } thickness = std::min(std::min(thickness, w / 2 + 1), h / 2 + 1); @@ -487,8 +479,6 @@ static UNUSED void addRectangles(unsigned char *data, size_t height, size_t widt } } - - /** * Write output data to image * \param name - image name @@ -497,54 +487,59 @@ static UNUSED void addRectangles(unsigned char *data, size_t height, size_t widt * \return false if error else true */ -static UNUSED bool writeOutputBmp(unsigned char *data, size_t height, size_t width, std::ostream &outFile) { +static UNUSED bool writeOutputBmp(unsigned char* data, size_t height, size_t width, std::ostream& outFile) { unsigned char file[14] = { - 'B', 'M', // magic - 0, 0, 0, 0, // size in bytes - 0, 0, // app data - 0, 0, // app data - 40+14, 0, 0, 0 // start of data offset + 'B', + 'M', // magic + 0, 0, 0, + 0, // size in bytes + 0, + 0, // app data + 0, + 0, // app data + 40 + 14, 0, 0, + 0 // start of data offset }; unsigned char info[40] = { - 40, 0, 0, 0, // info hd size - 0, 0, 0, 0, // width - 0, 0, 0, 0, // height - 1, 0, // number color planes - 24, 0, // bits per pixel - 0, 0, 0, 0, // compression is none - 0, 0, 0, 0, // image bits size - 0x13, 0x0B, 0, 0, // horz resolution in pixel / m - 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) - 0, 0, 0, 0, // #colors in palette - 0, 0, 0, 0, // #important colors + 40, 0, 0, 0, // info hd size + 0, 0, 0, 0, // width + 0, 0, 0, 0, // height + 1, 0, // number color planes + 24, 0, // bits per pixel + 0, 0, 0, 0, // compression is none + 0, 0, 0, 0, // image bits size + 0x13, 0x0B, 0, 0, // horz resolution in pixel / m + 0x13, 0x0B, 0, 0, // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72 dpi) + 0, 0, 0, 0, // #colors in palette + 0, 0, 0, 0, // #important colors }; if (height > (size_t)std::numeric_limits::max || width > (size_t)std::numeric_limits::max) { IE_THROW() << "File size is too big: " << height << " X " << width; } - int padSize = static_cast(4 - (width * 3) % 4) % 4; + int padSize = static_cast(4 - (width * 3) % 4) % 4; int sizeData = static_cast(width * height * 3 + height * padSize); - int sizeAll = sizeData + sizeof(file) + sizeof(info); + int sizeAll = sizeData + sizeof(file) + sizeof(info); - file[ 2] = (unsigned char)(sizeAll ); - file[ 3] = (unsigned char)(sizeAll >> 8); - file[ 4] = (unsigned char)(sizeAll >> 16); - file[ 5] = (unsigned char)(sizeAll >> 24); + file[2] = (unsigned char)(sizeAll); + file[3] = (unsigned char)(sizeAll >> 8); + file[4] = (unsigned char)(sizeAll >> 16); + file[5] = (unsigned char)(sizeAll >> 24); - info[ 4] = (unsigned char)(width ); - info[ 5] = (unsigned char)(width >> 8); - info[ 6] = (unsigned char)(width >> 16); - info[ 7] = (unsigned char)(width >> 24); + info[4] = (unsigned char)(width); + info[5] = (unsigned char)(width >> 8); + info[6] = (unsigned char)(width >> 16); + info[7] = (unsigned char)(width >> 24); int32_t negativeHeight = -(int32_t)height; - info[ 8] = (unsigned char)(negativeHeight ); - info[ 9] = (unsigned char)(negativeHeight >> 8); + info[8] = (unsigned char)(negativeHeight); + info[9] = (unsigned char)(negativeHeight >> 8); info[10] = (unsigned char)(negativeHeight >> 16); info[11] = (unsigned char)(negativeHeight >> 24); - info[20] = (unsigned char)(sizeData ); - info[21] = (unsigned char)(sizeData >> 8); + info[20] = (unsigned char)(sizeData); + info[21] = (unsigned char)(sizeData >> 8); info[22] = (unsigned char)(sizeData >> 16); info[23] = (unsigned char)(sizeData >> 24); @@ -556,34 +551,33 @@ static UNUSED bool writeOutputBmp(unsigned char *data, size_t height, size_t wid for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { unsigned char pixel[3]; - pixel[0] = data[y*width*3 + x*3]; - pixel[1] = data[y*width*3 + x*3 + 1]; - pixel[2] = data[y*width*3 + x*3 + 2]; - outFile.write(reinterpret_cast(pixel), 3); + pixel[0] = data[y * width * 3 + x * 3]; + pixel[1] = data[y * width * 3 + x * 3 + 1]; + pixel[2] = data[y * width * 3 + x * 3 + 2]; + outFile.write(reinterpret_cast(pixel), 3); } - outFile.write(reinterpret_cast(pad), padSize); + outFile.write(reinterpret_cast(pad), padSize); } return true; } -static std::vector> -perfCountersSorted(std::map perfMap) { +static std::vector> perfCountersSorted( + std::map perfMap) { using perfItem = std::pair; std::vector sorted; - for (auto &kvp : perfMap) sorted.push_back(kvp); + for (auto& kvp : perfMap) + sorted.push_back(kvp); - std::stable_sort(sorted.begin(), sorted.end(), - [](const perfItem& l, const perfItem& r) { - return l.second.execution_index < r.second.execution_index; - }); + std::stable_sort(sorted.begin(), sorted.end(), [](const perfItem& l, const perfItem& r) { + return l.second.execution_index < r.second.execution_index; + }); return sorted; } -static UNUSED void printPerformanceCounts(const std::map& performanceMap, - std::ostream &stream, std::string deviceName, - bool bshowHeader = true) { +static UNUSED void printPerformanceCounts(const std::map& performanceMap, std::ostream& stream, + std::string deviceName, bool bshowHeader = true) { long long totalTime = 0; // Print performance counts if (bshowHeader) { @@ -592,16 +586,15 @@ static UNUSED void printPerformanceCounts(const std::map= maxLayerName) { - toPrint = it.first.substr(0, maxLayerName - 4); + toPrint = it.first.substr(0, maxLayerName - 4); toPrint += "..."; } - stream << std::setw(maxLayerName) << std::left << toPrint; switch (it.second.status) { case InferenceEngine::InferenceEngineProfileInfo::EXECUTED: @@ -616,7 +609,7 @@ static UNUSED void printPerformanceCounts(const std::map 0) { totalTime += it.second.realTime_uSec; @@ -628,7 +621,7 @@ static UNUSED void printPerformanceCounts(const std::map getMapFullDevicesNames(InferenceEngine try { p = ie.GetMetric(deviceName, METRIC_KEY(FULL_DEVICE_NAME)); devicesMap.insert(std::pair(deviceName, p.as())); - } - catch (InferenceEngine::Exception &) { + } catch (InferenceEngine::Exception&) { } } } @@ -662,9 +654,8 @@ inline std::string getFullDeviceName(InferenceEngine::Core& ie, std::string devi InferenceEngine::Parameter p; try { p = ie.GetMetric(device, METRIC_KEY(FULL_DEVICE_NAME)); - return p.as(); - } - catch (InferenceEngine::Exception &) { + return p.as(); + } catch (InferenceEngine::Exception&) { return ""; } } @@ -679,8 +670,7 @@ public: bool difficult; DetectedObject(int _objectType, float _xmin, float _ymin, float _xmax, float _ymax, float _prob, bool _difficult = false) - : objectType(_objectType), xmin(_xmin), xmax(_xmax), ymin(_ymin), ymax(_ymax), prob(_prob), difficult(_difficult) { - } + : objectType(_objectType), xmin(_xmin), xmax(_xmax), ymin(_ymin), ymax(_ymax), prob(_prob), difficult(_difficult) {} DetectedObject(const DetectedObject& other) = default; @@ -688,27 +678,24 @@ public: // Add small space to eliminate empty squares float epsilon = 0; // 1e-5f; - DetectedObject detectedObject1(detectedObject1_.objectType, - (detectedObject1_.xmin - epsilon), - (detectedObject1_.ymin - epsilon), - (detectedObject1_.xmax- epsilon), - (detectedObject1_.ymax- epsilon), detectedObject1_.prob); - DetectedObject detectedObject2(detectedObject2_.objectType, - (detectedObject2_.xmin + epsilon), - (detectedObject2_.ymin + epsilon), - (detectedObject2_.xmax), - (detectedObject2_.ymax), detectedObject2_.prob); + DetectedObject detectedObject1(detectedObject1_.objectType, (detectedObject1_.xmin - epsilon), (detectedObject1_.ymin - epsilon), + (detectedObject1_.xmax - epsilon), (detectedObject1_.ymax - epsilon), detectedObject1_.prob); + DetectedObject detectedObject2(detectedObject2_.objectType, (detectedObject2_.xmin + epsilon), (detectedObject2_.ymin + epsilon), + (detectedObject2_.xmax), (detectedObject2_.ymax), detectedObject2_.prob); if (detectedObject1.objectType != detectedObject2.objectType) { // objects are different, so the result is 0 return 0.0f; } - if (detectedObject1.xmax < detectedObject1.xmin) return 0.0; - if (detectedObject1.ymax < detectedObject1.ymin) return 0.0; - if (detectedObject2.xmax < detectedObject2.xmin) return 0.0; - if (detectedObject2.ymax < detectedObject2.ymin) return 0.0; - + if (detectedObject1.xmax < detectedObject1.xmin) + return 0.0; + if (detectedObject1.ymax < detectedObject1.ymin) + return 0.0; + if (detectedObject2.xmax < detectedObject2.xmin) + return 0.0; + if (detectedObject2.ymax < detectedObject2.ymin) + return 0.0; float xmin = (std::max)(detectedObject1.xmin, detectedObject2.xmin); float ymin = (std::max)(detectedObject1.ymin, detectedObject2.ymin); @@ -749,11 +736,9 @@ public: const std::list alist; const bool check_probs; - explicit ImageDescription(const std::list &_alist, bool _check_probs = false) - : alist(_alist), check_probs(_check_probs) { - } + explicit ImageDescription(const std::list& _alist, bool _check_probs = false): alist(_alist), check_probs(_check_probs) {} - static float ioUMultiple(const ImageDescription &detectedObjects, const ImageDescription &desiredObjects) { + static float ioUMultiple(const ImageDescription& detectedObjects, const ImageDescription& desiredObjects) { const ImageDescription *detectedObjectsSmall, *detectedObjectsBig; bool check_probs = desiredObjects.check_probs; @@ -786,17 +771,17 @@ public: float mn = std::min((*bestJ).prob, (*doS.begin()).prob); float mx = std::max((*bestJ).prob, (*doS.begin()).prob); - coeff = mn/mx; + coeff = mn / mx; } } doS.pop_front(); - if (bestJ != doB.end()) doB.erase(bestJ); + if (bestJ != doB.end()) + doB.erase(bestJ); fullScore += coeff * score; } fullScore /= detectedObjectsBig->alist.size(); - return fullScore; } @@ -811,9 +796,7 @@ public: struct AveragePrecisionCalculator { private: - enum MatchKind { - TruePositive, FalsePositive - }; + enum MatchKind { TruePositive, FalsePositive }; /** * Here we count all TP and FP matches for all the classes in all the images. @@ -825,26 +808,25 @@ private: double threshold; static bool SortBBoxDescend(const DetectedObject& bbox1, const DetectedObject& bbox2) { - return bbox1.prob > bbox2.prob; + return bbox1.prob > bbox2.prob; } static bool SortPairDescend(const std::pair& p1, const std::pair& p2) { - return p1.first > p2.first; + return p1.first > p2.first; } public: - explicit AveragePrecisionCalculator(double _threshold) : threshold(_threshold) { } + explicit AveragePrecisionCalculator(double _threshold): threshold(_threshold) {} // gt_bboxes -> des // bboxes -> det - void consumeImage(const ImageDescription &detectedObjects, const ImageDescription &desiredObjects) { + void consumeImage(const ImageDescription& detectedObjects, const ImageDescription& desiredObjects) { // Collecting IoU values std::vector visited(desiredObjects.alist.size(), false); - std::vector bboxes{ std::begin(detectedObjects.alist), std::end(detectedObjects.alist) }; + std::vector bboxes {std::begin(detectedObjects.alist), std::end(detectedObjects.alist)}; std::sort(bboxes.begin(), bboxes.end(), SortBBoxDescend); - for (auto&& detObj : bboxes) { // Searching for the best match to this detection // Searching for desired object @@ -882,17 +864,17 @@ public: for (auto desObj = desiredObjects.alist.begin(); desObj != desiredObjects.alist.end(); desObj++) { if (!desObj->difficult) { N[desObj->objectType]++; - } } } + } std::map calculateAveragePrecisionPerClass() const { /** - * Precision-to-TP curve per class (a variation of precision-to-recall curve without dividing into N) + * Precision-to-TP curve per class (a variation of precision-to-recall curve without + * dividing into N) */ std::map> precisionToTP; - std::map res; for (auto m : matches) { @@ -908,8 +890,10 @@ public: for (auto mm : m.second) { // Here we are descending in a probability value MatchKind mk = mm.second; - if (mk == TruePositive) TP++; - else if (mk == FalsePositive) FP++; + if (mk == TruePositive) + TP++; + else if (mk == FalsePositive) + FP++; double precision = static_cast(TP) / (TP + FP); double recall = 0; @@ -932,7 +916,7 @@ public: if (rec[i] < j / 10.) { start_idx = i; if (j > 0) { - max_precs[j-1] = max_precs[j]; + max_precs[j - 1] = max_precs[j]; } break; } else { @@ -953,36 +937,16 @@ public: }; /** -* @brief Adds colored rectangles to the image -* @param data - data where rectangles are put -* @param height - height of the rectangle -* @param width - width of the rectangle -* @param detectedObjects - vector of detected objects -*/ -static UNUSED void addRectangles(unsigned char *data, size_t height, size_t width, std::vector detectedObjects) { - std::vector colors = { - { 128, 64, 128 }, - { 232, 35, 244 }, - { 70, 70, 70 }, - { 156, 102, 102 }, - { 153, 153, 190 }, - { 153, 153, 153 }, - { 30, 170, 250 }, - { 0, 220, 220 }, - { 35, 142, 107 }, - { 152, 251, 152 }, - { 180, 130, 70 }, - { 60, 20, 220 }, - { 0, 0, 255 }, - { 142, 0, 0 }, - { 70, 0, 0 }, - { 100, 60, 0 }, - { 90, 0, 0 }, - { 230, 0, 0 }, - { 32, 11, 119 }, - { 0, 74, 111 }, - { 81, 0, 81 } - }; + * @brief Adds colored rectangles to the image + * @param data - data where rectangles are put + * @param height - height of the rectangle + * @param width - width of the rectangle + * @param detectedObjects - vector of detected objects + */ +static UNUSED void addRectangles(unsigned char* data, size_t height, size_t width, std::vector detectedObjects) { + std::vector colors = {{128, 64, 128}, {232, 35, 244}, {70, 70, 70}, {156, 102, 102}, {153, 153, 190}, {153, 153, 153}, {30, 170, 250}, + {0, 220, 220}, {35, 142, 107}, {152, 251, 152}, {180, 130, 70}, {60, 20, 220}, {0, 0, 255}, {142, 0, 0}, + {70, 0, 0}, {100, 60, 0}, {90, 0, 0}, {230, 0, 0}, {32, 11, 119}, {0, 74, 111}, {81, 0, 81}}; for (size_t i = 0; i < detectedObjects.size(); i++) { int cls = detectedObjects[i].objectType % colors.size(); @@ -992,8 +956,8 @@ static UNUSED void addRectangles(unsigned char *data, size_t height, size_t widt int ymin = static_cast(detectedObjects[i].ymin * height); int ymax = static_cast(detectedObjects[i].ymax * height); - size_t shift_first = ymin*width * 3; - size_t shift_second = ymax*width * 3; + size_t shift_first = ymin * width * 3; + size_t shift_second = ymax * width * 3; for (int x = xmin; x < xmax; x++) { data[shift_first + x * 3] = colors.at(cls).red(); data[shift_first + x * 3 + 1] = colors.at(cls).green(); @@ -1006,12 +970,12 @@ static UNUSED void addRectangles(unsigned char *data, size_t height, size_t widt shift_first = xmin * 3; shift_second = xmax * 3; for (int y = ymin; y < ymax; y++) { - data[shift_first + y*width * 3] = colors.at(cls).red(); - data[shift_first + y*width * 3 + 1] = colors.at(cls).green(); - data[shift_first + y*width * 3 + 2] = colors.at(cls).blue(); - data[shift_second + y*width * 3] = colors.at(cls).red(); - data[shift_second + y*width * 3 + 1] = colors.at(cls).green(); - data[shift_second + y*width * 3 + 2] = colors.at(cls).blue(); + data[shift_first + y * width * 3] = colors.at(cls).red(); + data[shift_first + y * width * 3 + 1] = colors.at(cls).green(); + data[shift_first + y * width * 3 + 2] = colors.at(cls).blue(); + data[shift_second + y * width * 3] = colors.at(cls).red(); + data[shift_second + y * width * 3 + 1] = colors.at(cls).green(); + data[shift_second + y * width * 3 + 2] = colors.at(cls).blue(); } } } @@ -1020,17 +984,10 @@ inline std::size_t getTensorWidth(const InferenceEngine::TensorDesc& desc) { const auto& layout = desc.getLayout(); const auto& dims = desc.getDims(); const auto& size = dims.size(); - if ((size >= 2) && - (layout == InferenceEngine::Layout::NCHW || - layout == InferenceEngine::Layout::NHWC || - layout == InferenceEngine::Layout::NCDHW || - layout == InferenceEngine::Layout::NDHWC || - layout == InferenceEngine::Layout::OIHW || - layout == InferenceEngine::Layout::GOIHW || - layout == InferenceEngine::Layout::OIDHW || - layout == InferenceEngine::Layout::GOIDHW || - layout == InferenceEngine::Layout::CHW || - layout == InferenceEngine::Layout::HW)) { + if ((size >= 2) && (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC || layout == InferenceEngine::Layout::NCDHW || + layout == InferenceEngine::Layout::NDHWC || layout == InferenceEngine::Layout::OIHW || layout == InferenceEngine::Layout::GOIHW || + layout == InferenceEngine::Layout::OIDHW || layout == InferenceEngine::Layout::GOIDHW || layout == InferenceEngine::Layout::CHW || + layout == InferenceEngine::Layout::HW)) { // Regardless of layout, dimensions are stored in fixed order return dims.back(); } else { @@ -1043,17 +1000,10 @@ inline std::size_t getTensorHeight(const InferenceEngine::TensorDesc& desc) { const auto& layout = desc.getLayout(); const auto& dims = desc.getDims(); const auto& size = dims.size(); - if ((size >= 2) && - (layout == InferenceEngine::Layout::NCHW || - layout == InferenceEngine::Layout::NHWC || - layout == InferenceEngine::Layout::NCDHW || - layout == InferenceEngine::Layout::NDHWC || - layout == InferenceEngine::Layout::OIHW || - layout == InferenceEngine::Layout::GOIHW || - layout == InferenceEngine::Layout::OIDHW || - layout == InferenceEngine::Layout::GOIDHW || - layout == InferenceEngine::Layout::CHW || - layout == InferenceEngine::Layout::HW)) { + if ((size >= 2) && (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC || layout == InferenceEngine::Layout::NCDHW || + layout == InferenceEngine::Layout::NDHWC || layout == InferenceEngine::Layout::OIHW || layout == InferenceEngine::Layout::GOIHW || + layout == InferenceEngine::Layout::OIDHW || layout == InferenceEngine::Layout::GOIDHW || layout == InferenceEngine::Layout::CHW || + layout == InferenceEngine::Layout::HW)) { // Regardless of layout, dimensions are stored in fixed order return dims.at(size - 2); } else { @@ -1064,26 +1014,26 @@ inline std::size_t getTensorHeight(const InferenceEngine::TensorDesc& desc) { inline std::size_t getTensorChannels(const InferenceEngine::TensorDesc& desc) { const auto& layout = desc.getLayout(); - if (layout == InferenceEngine::Layout::NCHW || - layout == InferenceEngine::Layout::NHWC || - layout == InferenceEngine::Layout::NCDHW || - layout == InferenceEngine::Layout::NDHWC || - layout == InferenceEngine::Layout::C || - layout == InferenceEngine::Layout::CHW || - layout == InferenceEngine::Layout::NC || - layout == InferenceEngine::Layout::CN) { + if (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC || layout == InferenceEngine::Layout::NCDHW || + layout == InferenceEngine::Layout::NDHWC || layout == InferenceEngine::Layout::C || layout == InferenceEngine::Layout::CHW || + layout == InferenceEngine::Layout::NC || layout == InferenceEngine::Layout::CN) { // Regardless of layout, dimensions are stored in fixed order const auto& dims = desc.getDims(); switch (desc.getLayoutByDims(dims)) { - case InferenceEngine::Layout::C: return dims.at(0); - case InferenceEngine::Layout::NC: return dims.at(1); - case InferenceEngine::Layout::CHW: return dims.at(0); - case InferenceEngine::Layout::NCHW: return dims.at(1); - case InferenceEngine::Layout::NCDHW: return dims.at(1); - case InferenceEngine::Layout::SCALAR: // [[fallthrough]] - case InferenceEngine::Layout::BLOCKED: // [[fallthrough]] - default: - IE_THROW() << "Tensor does not have channels dimension"; + case InferenceEngine::Layout::C: + return dims.at(0); + case InferenceEngine::Layout::NC: + return dims.at(1); + case InferenceEngine::Layout::CHW: + return dims.at(0); + case InferenceEngine::Layout::NCHW: + return dims.at(1); + case InferenceEngine::Layout::NCDHW: + return dims.at(1); + case InferenceEngine::Layout::SCALAR: // [[fallthrough]] + case InferenceEngine::Layout::BLOCKED: // [[fallthrough]] + default: + IE_THROW() << "Tensor does not have channels dimension"; } } else { IE_THROW() << "Tensor does not have channels dimension"; @@ -1093,24 +1043,23 @@ inline std::size_t getTensorChannels(const InferenceEngine::TensorDesc& desc) { inline std::size_t getTensorBatch(const InferenceEngine::TensorDesc& desc) { const auto& layout = desc.getLayout(); - if (layout == InferenceEngine::Layout::NCHW || - layout == InferenceEngine::Layout::NHWC || - layout == InferenceEngine::Layout::NCDHW || - layout == InferenceEngine::Layout::NDHWC || - layout == InferenceEngine::Layout::NC || - layout == InferenceEngine::Layout::CN) { + if (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC || layout == InferenceEngine::Layout::NCDHW || + layout == InferenceEngine::Layout::NDHWC || layout == InferenceEngine::Layout::NC || layout == InferenceEngine::Layout::CN) { // Regardless of layout, dimensions are stored in fixed order const auto& dims = desc.getDims(); switch (desc.getLayoutByDims(dims)) { - case InferenceEngine::Layout::NC: return dims.at(0); - case InferenceEngine::Layout::NCHW: return dims.at(0); - case InferenceEngine::Layout::NCDHW: return dims.at(0); - case InferenceEngine::Layout::CHW: // [[fallthrough]] - case InferenceEngine::Layout::C: // [[fallthrough]] - case InferenceEngine::Layout::SCALAR: // [[fallthrough]] - case InferenceEngine::Layout::BLOCKED: // [[fallthrough]] - default: - IE_THROW() << "Tensor does not have channels dimension"; + case InferenceEngine::Layout::NC: + return dims.at(0); + case InferenceEngine::Layout::NCHW: + return dims.at(0); + case InferenceEngine::Layout::NCDHW: + return dims.at(0); + case InferenceEngine::Layout::CHW: // [[fallthrough]] + case InferenceEngine::Layout::C: // [[fallthrough]] + case InferenceEngine::Layout::SCALAR: // [[fallthrough]] + case InferenceEngine::Layout::BLOCKED: // [[fallthrough]] + default: + IE_THROW() << "Tensor does not have channels dimension"; } } else { IE_THROW() << "Tensor does not have channels dimension"; @@ -1131,11 +1080,11 @@ inline void showAvailableDevices() { } /** -* @brief Parse text config file. The file must have the following format (with space a delimeter): -* CONFIG_NAME1 CONFIG_VALUE1 -* CONFIG_NAME2 CONFIG_VALUE2 -* -* @param configName - filename for a file with config options -* @param comment - lines starting with symbol `comment` are skipped -*/ -std::map parseConfig(const std::string &configName, char comment = '#'); + * @brief Parse text config file. The file must have the following format (with space a delimeter): + * CONFIG_NAME1 CONFIG_VALUE1 + * CONFIG_NAME2 CONFIG_VALUE2 + * + * @param configName - filename for a file with config options + * @param comment - lines starting with symbol `comment` are skipped + */ +std::map parseConfig(const std::string& configName, char comment = '#'); diff --git a/inference-engine/samples/common/utils/include/samples/console_progress.hpp b/inference-engine/samples/common/utils/include/samples/console_progress.hpp index 500a0165549..efe45d43d08 100644 --- a/inference-engine/samples/common/utils/include/samples/console_progress.hpp +++ b/inference-engine/samples/common/utils/include/samples/console_progress.hpp @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include /** * @class ConsoleProgress @@ -25,15 +25,13 @@ class ConsoleProgress { public: /** - * @brief A constructor of ConsoleProgress class - * @param _total - maximum value that is correspondent to 100% - * @param _detalization - number of symbols(.) to use to represent progress - */ - explicit ConsoleProgress(size_t _total, - bool _stream_output = false, - size_t _percent_to_update = DEFAULT_PERCENT_TO_UPDATE_PROGRESS, - size_t _detalization = DEFAULT_DETALIZATION) : - total(_total), detalization(_detalization), percent_to_update(_percent_to_update) { + * @brief A constructor of ConsoleProgress class + * @param _total - maximum value that is correspondent to 100% + * @param _detalization - number of symbols(.) to use to represent progress + */ + explicit ConsoleProgress(size_t _total, bool _stream_output = false, size_t _percent_to_update = DEFAULT_PERCENT_TO_UPDATE_PROGRESS, + size_t _detalization = DEFAULT_DETALIZATION) + : total(_total), detalization(_detalization), percent_to_update(_percent_to_update) { stream_output = _stream_output; if (total == 0) { total = 1; @@ -41,7 +39,8 @@ public: } /** - * @brief Shows progress with current data. Progress is shown from the beginning of the current line. + * @brief Shows progress with current data. Progress is shown from the beginning of the current + * line. */ void showProgress() const { std::stringstream strm; @@ -68,13 +67,12 @@ public: * @brief Updates current value and progressbar */ void updateProgress() { - if (cur_progress > total) cur_progress = total; + if (cur_progress > total) + cur_progress = total; size_t prev_percent = 100 * prev_progress / total; size_t cur_percent = 100 * cur_progress / total; - if (prev_progress == 0 || - cur_progress == total || - prev_percent + percent_to_update <= cur_percent) { + if (prev_progress == 0 || cur_progress == total || prev_percent + percent_to_update <= cur_percent) { showProgress(); prev_progress = cur_progress; } diff --git a/inference-engine/samples/common/utils/include/samples/csv_dumper.hpp b/inference-engine/samples/common/utils/include/samples/csv_dumper.hpp index dbd4001ad25..807f7c02295 100644 --- a/inference-engine/samples/common/utils/include/samples/csv_dumper.hpp +++ b/inference-engine/samples/common/utils/include/samples/csv_dumper.hpp @@ -4,13 +4,13 @@ #pragma once -#include -#include -#include -#include #include +#include +#include #include +#include +#include /** * @class CsvDumper @@ -36,7 +36,7 @@ public: * @param enabled - True if dumping is enabled by default. * @param name - name of file to dump to. File won't be created if first parameter is false. */ - explicit CsvDumper(bool enabled = true, const std::string& name = "") : canDump(enabled) { + explicit CsvDumper(bool enabled = true, const std::string& name = ""): canDump(enabled) { if (!canDump) { return; } @@ -58,12 +58,12 @@ public: } /** - * @brief Overloads operator to organize streaming values to file. Does nothing if dumping is disabled - * Adds delimiter at the end of value provided + * @brief Overloads operator to organize streaming values to file. Does nothing if dumping is + * disabled Adds delimiter at the end of value provided * @param add - value to add to dump * @return reference to same object */ - template + template CsvDumper& operator<<(const T& add) { if (canDump) { file << add << delimiter; diff --git a/inference-engine/samples/common/utils/include/samples/ocv_common.hpp b/inference-engine/samples/common/utils/include/samples/ocv_common.hpp index 8505c753675..7f2de431ebe 100644 --- a/inference-engine/samples/common/utils/include/samples/ocv_common.hpp +++ b/inference-engine/samples/common/utils/include/samples/ocv_common.hpp @@ -9,15 +9,15 @@ #pragma once -#include #include +#include /** -* @brief Sets image data stored in cv::Mat object to a given Blob object. -* @param orig_image - given cv::Mat object with an image data. -* @param blob - Blob object which to be filled by an image data. -* @param batchIndex - batch index of an image inside of the blob. -*/ + * @brief Sets image data stored in cv::Mat object to a given Blob object. + * @param orig_image - given cv::Mat object with an image data. + * @param blob - Blob object which to be filled by an image data. + * @param batchIndex - batch index of an image inside of the blob. + */ template void matU8ToBlob(const cv::Mat& orig_image, InferenceEngine::Blob::Ptr& blob, int batchIndex = 0) { InferenceEngine::SizeVector blobSize = blob->getTensorDesc().getDims(); @@ -27,26 +27,24 @@ void matU8ToBlob(const cv::Mat& orig_image, InferenceEngine::Blob::Ptr& blob, in InferenceEngine::MemoryBlob::Ptr mblob = InferenceEngine::as(blob); if (!mblob) { IE_THROW() << "We expect blob to be inherited from MemoryBlob in matU8ToBlob, " - << "but by fact we were not able to cast inputBlob to MemoryBlob"; + << "but by fact we were not able to cast inputBlob to MemoryBlob"; } // locked memory holder should be alive all time while access to its buffer happens auto mblobHolder = mblob->wmap(); - T *blob_data = mblobHolder.as(); + T* blob_data = mblobHolder.as(); cv::Mat resized_image(orig_image); - if (static_cast(width) != orig_image.size().width || - static_cast(height) != orig_image.size().height) { + if (static_cast(width) != orig_image.size().width || static_cast(height) != orig_image.size().height) { cv::resize(orig_image, resized_image, cv::Size(width, height)); } int batchOffset = batchIndex * width * height * channels; for (size_t c = 0; c < channels; c++) { - for (size_t h = 0; h < height; h++) { + for (size_t h = 0; h < height; h++) { for (size_t w = 0; w < width; w++) { - blob_data[batchOffset + c * width * height + h * width + w] = - resized_image.at(h, w)[c]; + blob_data[batchOffset + c * width * height + h * width + w] = resized_image.at(h, w)[c]; } } } @@ -59,7 +57,7 @@ void matU8ToBlob(const cv::Mat& orig_image, InferenceEngine::Blob::Ptr& blob, in * @param mat - given cv::Mat object with an image data. * @return resulting Blob pointer. */ -static UNUSED InferenceEngine::Blob::Ptr wrapMat2Blob(const cv::Mat &mat) { +static UNUSED InferenceEngine::Blob::Ptr wrapMat2Blob(const cv::Mat& mat) { size_t channels = mat.channels(); size_t height = mat.size().height; size_t width = mat.size().width; @@ -67,16 +65,12 @@ static UNUSED InferenceEngine::Blob::Ptr wrapMat2Blob(const cv::Mat &mat) { size_t strideH = mat.step.buf[0]; size_t strideW = mat.step.buf[1]; - bool is_dense = - strideW == channels && - strideH == channels * width; + bool is_dense = strideW == channels && strideH == channels * width; - if (!is_dense) IE_THROW() - << "Doesn't support conversion from not dense cv::Mat"; + if (!is_dense) + IE_THROW() << "Doesn't support conversion from not dense cv::Mat"; - InferenceEngine::TensorDesc tDesc(InferenceEngine::Precision::U8, - {1, channels, height, width}, - InferenceEngine::Layout::NHWC); + InferenceEngine::TensorDesc tDesc(InferenceEngine::Precision::U8, {1, channels, height, width}, InferenceEngine::Layout::NHWC); return InferenceEngine::make_shared_blob(tDesc, mat.data); } diff --git a/inference-engine/samples/common/utils/include/samples/os/windows/w_dirent.h b/inference-engine/samples/common/utils/include/samples/os/windows/w_dirent.h index 452b6825696..5352a8f8b13 100644 --- a/inference-engine/samples/common/utils/include/samples/os/windows/w_dirent.h +++ b/inference-engine/samples/common/utils/include/samples/os/windows/w_dirent.h @@ -6,50 +6,52 @@ #if defined(_WIN32) -#ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN_UNDEF -#endif + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN_UNDEF + #endif -#ifndef NOMINMAX -# define NOMINMAX -# define NOMINMAX_UNDEF -#endif + #ifndef NOMINMAX + #define NOMINMAX + #define NOMINMAX_UNDEF + #endif -#if defined(_M_IX86) && !defined(_X86_) && !defined(_AMD64_) -# define _X86_ -#endif + #if defined(_M_IX86) && !defined(_X86_) && !defined(_AMD64_) + #define _X86_ + #endif -#if defined(_M_X64) && !defined(_X86_) && !defined(_AMD64_) -# define _AMD64_ -#endif + #if defined(_M_X64) && !defined(_X86_) && !defined(_AMD64_) + #define _AMD64_ + #endif -#if defined(_M_ARM) && !defined(_ARM_) && !defined(_ARM64_) -# define _ARM_ -#endif + #if defined(_M_ARM) && !defined(_ARM_) && !defined(_ARM64_) + #define _ARM_ + #endif -#if defined(_M_ARM64) && !defined(_ARM_) && !defined(_ARM64_) -# define _ARM64_ -#endif + #if defined(_M_ARM64) && !defined(_ARM_) && !defined(_ARM64_) + #define _ARM64_ + #endif -#include -#include -#include -#include -#include + // clang-format off + #include + #include + #include + #include + #include + // clang-format on -// Copied from linux libc sys/stat.h: -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) + // Copied from linux libc sys/stat.h: + #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) + #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) /// @brief structure to store directory names struct dirent { - char *d_name; + char* d_name; - explicit dirent(const wchar_t *wsFilePath) { + explicit dirent(const wchar_t* wsFilePath) { size_t i; auto slen = wcslen(wsFilePath); - d_name = static_cast(malloc(slen + 1)); + d_name = static_cast(malloc(slen + 1)); wcstombs_s(&i, d_name, slen + 1, wsFilePath, slen); } ~dirent() { @@ -61,22 +63,23 @@ struct dirent { class DIR { WIN32_FIND_DATAA FindFileData; HANDLE hFind; - dirent *next; + dirent* next; - static inline bool endsWith(const std::string &src, const char *with) { + static inline bool endsWith(const std::string& src, const char* with) { int wl = static_cast(strlen(with)); int so = static_cast(src.length()) - wl; - if (so < 0) return false; + if (so < 0) + return false; return 0 == strncmp(with, &src[so], wl); } public: - DIR(const DIR &other) = delete; - DIR(DIR &&other) = delete; - DIR& operator=(const DIR &other) = delete; - DIR& operator=(DIR &&other) = delete; + DIR(const DIR& other) = delete; + DIR(DIR&& other) = delete; + DIR& operator=(const DIR& other) = delete; + DIR& operator=(DIR&& other) = delete; - explicit DIR(const char *dirPath) : next(nullptr) { + explicit DIR(const char* dirPath): next(nullptr) { std::string ws = dirPath; if (endsWith(ws, "\\")) ws += "*"; @@ -87,28 +90,31 @@ public: } ~DIR() { - if (!next) delete next; + if (!next) + delete next; next = nullptr; FindClose(hFind); } /** - * @brief Check file handler is valid - * @return status True(success) or False(fail) - */ + * @brief Check file handler is valid + * @return status True(success) or False(fail) + */ bool isValid() const { return (hFind != INVALID_HANDLE_VALUE && FindFileData.dwReserved0); } /** - * @brief Add directory to directory names struct - * @return pointer to directory names struct - */ + * @brief Add directory to directory names struct + * @return pointer to directory names struct + */ dirent* nextEnt() { - if (next != nullptr) delete next; + if (next != nullptr) + delete next; next = nullptr; - if (!FindFileData.dwReserved0) return nullptr; + if (!FindFileData.dwReserved0) + return nullptr; wchar_t wbuf[4096]; @@ -121,11 +127,11 @@ public: }; /** -* @brief Create directory data struct element -* @param string directory path -* @return pointer to directory data struct element -*/ -static DIR* opendir(const char *dirPath) { + * @brief Create directory data struct element + * @param string directory path + * @return pointer to directory data struct element + */ +static DIR* opendir(const char* dirPath) { auto dp = new DIR(dirPath); if (!dp->isValid()) { delete dp; @@ -135,36 +141,36 @@ static DIR* opendir(const char *dirPath) { } /** -* @brief Walk throw directory data struct -* @param pointer to directory data struct -* @return pointer to directory data struct next element -*/ -static struct dirent* readdir(DIR *dp) { + * @brief Walk throw directory data struct + * @param pointer to directory data struct + * @return pointer to directory data struct next element + */ +static struct dirent* readdir(DIR* dp) { return dp->nextEnt(); } /** -* @brief Remove directory data struct -* @param pointer to struct directory data -* @return void -*/ -static void closedir(DIR *dp) { + * @brief Remove directory data struct + * @param pointer to struct directory data + * @return void + */ +static void closedir(DIR* dp) { delete dp; } -#ifdef WIN32_LEAN_AND_MEAN_UNDEF -# undef WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN_UNDEF -#endif + #ifdef WIN32_LEAN_AND_MEAN_UNDEF + #undef WIN32_LEAN_AND_MEAN + #undef WIN32_LEAN_AND_MEAN_UNDEF + #endif -#ifdef NOMINMAX_UNDEF -# undef NOMINMAX_UNDEF -# undef NOMINMAX -#endif + #ifdef NOMINMAX_UNDEF + #undef NOMINMAX_UNDEF + #undef NOMINMAX + #endif #else -#include -#include + #include + #include #endif diff --git a/inference-engine/samples/common/utils/include/samples/slog.hpp b/inference-engine/samples/common/utils/include/samples/slog.hpp index 5bfc75e16da..f4cdedab045 100644 --- a/inference-engine/samples/common/utils/include/samples/slog.hpp +++ b/inference-engine/samples/common/utils/include/samples/slog.hpp @@ -12,25 +12,22 @@ #include namespace slog { - /** * @class LogStreamEndLine * @brief The LogStreamEndLine class implements an end line marker for a log stream */ -class LogStreamEndLine { }; +class LogStreamEndLine {}; static constexpr LogStreamEndLine endl; - /** * @class LogStreamBoolAlpha * @brief The LogStreamBoolAlpha class implements bool printing for a log stream */ -class LogStreamBoolAlpha { }; +class LogStreamBoolAlpha {}; static constexpr LogStreamBoolAlpha boolalpha; - /** * @class LogStream * @brief The LogStream class implements a stream for sample logging @@ -45,8 +42,7 @@ public: * @brief A constructor. Creates an LogStream object * @param prefix The prefix to print */ - LogStream(const std::string &prefix, std::ostream& log_stream) - : _prefix(prefix), _new_line(true) { + LogStream(const std::string& prefix, std::ostream& log_stream): _prefix(prefix), _new_line(true) { _log_stream = &log_stream; } @@ -54,8 +50,8 @@ public: * @brief A stream output operator to be used within the logger * @param arg Object for serialization in the logger message */ - template - LogStream &operator<<(const T &arg) { + template + LogStream& operator<<(const T& arg) { if (_new_line) { (*_log_stream) << "[ " << _prefix << " ] "; _new_line = false; @@ -66,7 +62,7 @@ public: } // Specializing for LogStreamEndLine to support slog::endl - LogStream& operator<< (const LogStreamEndLine &/*arg*/) { + LogStream& operator<<(const LogStreamEndLine& /*arg*/) { _new_line = true; (*_log_stream) << std::endl; @@ -74,13 +70,12 @@ public: } // Specializing for LogStreamBoolAlpha to support slog::boolalpha - LogStream& operator<< (const LogStreamBoolAlpha &/*arg*/) { + LogStream& operator<<(const LogStreamBoolAlpha& /*arg*/) { (*_log_stream) << std::boolalpha; return *this; } }; - static LogStream info("INFO", std::cout); static LogStream warn("WARNING", std::cout); static LogStream err("ERROR", std::cerr); diff --git a/inference-engine/samples/common/utils/include/samples/vpu/vpu_tools_common.hpp b/inference-engine/samples/common/utils/include/samples/vpu/vpu_tools_common.hpp index a260053dc3a..2f2ca98caf2 100644 --- a/inference-engine/samples/common/utils/include/samples/vpu/vpu_tools_common.hpp +++ b/inference-engine/samples/common/utils/include/samples/vpu/vpu_tools_common.hpp @@ -4,10 +4,10 @@ #pragma once -#include #include +#include -static std::map parseConfig(const std::string &configName, char comment = '#') { +static std::map parseConfig(const std::string& configName, char comment = '#') { std::map config = {}; std::ifstream file(configName); diff --git a/inference-engine/samples/common/utils/src/args_helper.cpp b/inference-engine/samples/common/utils/src/args_helper.cpp index c2c0e247a0b..8ec1678f57b 100644 --- a/inference-engine/samples/common/utils/src/args_helper.cpp +++ b/inference-engine/samples/common/utils/src/args_helper.cpp @@ -5,24 +5,24 @@ #include "samples/args_helper.hpp" #include -#include #include +#include #include #ifdef _WIN32 -#include + #include #else -#include + #include #endif /** -* @brief Checks input file argument and add it to files vector -* @param files reference to vector to store file names -* @param arg file or folder name -* @return none -*/ -void readInputFilesArguments(std::vector &files, const std::string& arg) { + * @brief Checks input file argument and add it to files vector + * @param files reference to vector to store file names + * @param arg file or folder name + * @return none + */ +void readInputFilesArguments(std::vector& files, const std::string& arg) { struct stat sb; if (stat(arg.c_str(), &sb) != 0) { slog::warn << "File " << arg << " cannot be opened!" << slog::endl; @@ -43,10 +43,11 @@ void readInputFilesArguments(std::vector &files, const std::string& return; } - struct dirent *ep; + struct dirent* ep; while (nullptr != (ep = readdir(dp.get()))) { std::string fileName = ep->d_name; - if (fileName == "." || fileName == "..") continue; + if (fileName == "." || fileName == "..") + continue; files.push_back(arg + "/" + ep->d_name); } } else { @@ -55,14 +56,19 @@ void readInputFilesArguments(std::vector &files, const std::string& } /** -* @brief This function find -i key in input args. It's necessary to process multiple values for single key -* @param files reference to vector -* @return none. -*/ -void parseInputFilesArguments(std::vector &files) { + * @brief This function find -i key in input args. It's necessary to process multiple values for + * single key + * @param files reference to vector + * @return none. + */ +void parseInputFilesArguments(std::vector& files) { std::vector args = gflags::GetArgvs(); - const auto is_image_arg = [](const std::string& s){ return s == "-i" || s == "--images";}; - const auto is_arg = [](const std::string& s){return s.front() == '-';}; + const auto is_image_arg = [](const std::string& s) { + return s == "-i" || s == "--images"; + }; + const auto is_arg = [](const std::string& s) { + return s.front() == '-'; + }; const auto img_start = std::find_if(begin(args), end(args), is_image_arg); if (img_start == end(args)) { return; @@ -85,7 +91,6 @@ void parseInputFilesArguments(std::vector &files) { } namespace { - std::vector splitStringList(const std::string& str, char delim) { if (str.empty()) return {}; @@ -122,11 +127,9 @@ std::map parseArgMap(std::string argMap) { return parsedMap; } - using supported_precisions_t = std::unordered_map; -InferenceEngine::Precision getPrecision(std::string value, - const supported_precisions_t& supported_precisions) { +InferenceEngine::Precision getPrecision(std::string value, const supported_precisions_t& supported_precisions) { std::transform(value.begin(), value.end(), value.begin(), ::toupper); const auto precision = supported_precisions.find(value); @@ -139,24 +142,16 @@ InferenceEngine::Precision getPrecision(std::string value, InferenceEngine::Precision getPrecision(const std::string& value) { static const supported_precisions_t supported_precisions = { - { "FP32", InferenceEngine::Precision::FP32 }, - { "FP16", InferenceEngine::Precision::FP16 }, - { "BF16", InferenceEngine::Precision::BF16 }, - { "U64", InferenceEngine::Precision::U64 }, - { "I64", InferenceEngine::Precision::I64 }, - { "U32", InferenceEngine::Precision::U32 }, - { "I32", InferenceEngine::Precision::I32 }, - { "U16", InferenceEngine::Precision::U16 }, - { "I16", InferenceEngine::Precision::I16 }, - { "U8", InferenceEngine::Precision::U8 }, - { "I8", InferenceEngine::Precision::I8 }, - { "BOOL", InferenceEngine::Precision::BOOL }, + {"FP32", InferenceEngine::Precision::FP32}, {"FP16", InferenceEngine::Precision::FP16}, {"BF16", InferenceEngine::Precision::BF16}, + {"U64", InferenceEngine::Precision::U64}, {"I64", InferenceEngine::Precision::I64}, {"U32", InferenceEngine::Precision::U32}, + {"I32", InferenceEngine::Precision::I32}, {"U16", InferenceEngine::Precision::U16}, {"I16", InferenceEngine::Precision::I16}, + {"U8", InferenceEngine::Precision::U8}, {"I8", InferenceEngine::Precision::I8}, {"BOOL", InferenceEngine::Precision::BOOL}, }; return getPrecision(value, supported_precisions); } -void setPrecisions(const InferenceEngine::CNNNetwork& network, const std::string &iop) { +void setPrecisions(const InferenceEngine::CNNNetwork& network, const std::string& iop) { const auto user_precisions_map = parseArgMap(iop); auto inputs = network.getInputsInfo(); @@ -179,10 +174,9 @@ void setPrecisions(const InferenceEngine::CNNNetwork& network, const std::string } } -} // namespace +} // namespace -void processPrecision(InferenceEngine::CNNNetwork& network, const std::string &ip, const std::string &op, - const std::string &iop) { +void processPrecision(InferenceEngine::CNNNetwork& network, const std::string& ip, const std::string& op, const std::string& iop) { if (!ip.empty()) { const auto user_precision = getPrecision(ip); for (auto&& layer : network.getInputsInfo()) { @@ -203,12 +197,10 @@ void processPrecision(InferenceEngine::CNNNetwork& network, const std::string &i } namespace { - using supported_layouts_t = std::unordered_map; using matchLayoutToDims_t = std::unordered_map; -InferenceEngine::Layout getLayout(std::string value, - const supported_layouts_t& supported_layouts) { +InferenceEngine::Layout getLayout(std::string value, const supported_layouts_t& supported_layouts) { std::transform(value.begin(), value.end(), value.begin(), ::toupper); const auto layout = supported_layouts.find(value); @@ -221,14 +213,9 @@ InferenceEngine::Layout getLayout(std::string value, InferenceEngine::Layout getLayout(const std::string& value) { static const supported_layouts_t supported_layouts = { - { "NCDHW", InferenceEngine::Layout::NCDHW }, - { "NDHWC", InferenceEngine::Layout::NDHWC }, - { "NCHW", InferenceEngine::Layout::NCHW }, - { "NHWC", InferenceEngine::Layout::NHWC }, - { "CHW", InferenceEngine::Layout::CHW }, - { "HWC", InferenceEngine::Layout::HWC}, - { "NC", InferenceEngine::Layout::NC }, - { "C", InferenceEngine::Layout::C }, + {"NCDHW", InferenceEngine::Layout::NCDHW}, {"NDHWC", InferenceEngine::Layout::NDHWC}, {"NCHW", InferenceEngine::Layout::NCHW}, + {"NHWC", InferenceEngine::Layout::NHWC}, {"CHW", InferenceEngine::Layout::CHW}, {"HWC", InferenceEngine::Layout::HWC}, + {"NC", InferenceEngine::Layout::NC}, {"C", InferenceEngine::Layout::C}, }; return getLayout(value, supported_layouts); @@ -236,14 +223,10 @@ InferenceEngine::Layout getLayout(const std::string& value) { bool isMatchLayoutToDims(InferenceEngine::Layout layout, size_t dimension) { static const matchLayoutToDims_t matchLayoutToDims = { - {static_cast(InferenceEngine::Layout::NCDHW), 5 }, - {static_cast(InferenceEngine::Layout::NDHWC), 5 }, - {static_cast(InferenceEngine::Layout::NCHW), 4 }, - {static_cast(InferenceEngine::Layout::NHWC), 4 }, - {static_cast(InferenceEngine::Layout::CHW), 3 }, - {static_cast(InferenceEngine::Layout::NC), 2 }, - {static_cast(InferenceEngine::Layout::C), 1 } - }; + {static_cast(InferenceEngine::Layout::NCDHW), 5}, {static_cast(InferenceEngine::Layout::NDHWC), 5}, + {static_cast(InferenceEngine::Layout::NCHW), 4}, {static_cast(InferenceEngine::Layout::NHWC), 4}, + {static_cast(InferenceEngine::Layout::CHW), 3}, {static_cast(InferenceEngine::Layout::NC), 2}, + {static_cast(InferenceEngine::Layout::C), 1}}; const auto dims = matchLayoutToDims.find(static_cast(layout)); if (dims == matchLayoutToDims.end()) { @@ -284,7 +267,7 @@ void setLayouts(const InferenceEngine::CNNNetwork& network, const std::string io } } -} // namespace +} // namespace void processLayout(InferenceEngine::CNNNetwork& network, const std::string& il, const std::string& ol, const std::string& iol) { if (!il.empty()) { diff --git a/inference-engine/samples/common/utils/src/common.cpp b/inference-engine/samples/common/utils/src/common.cpp index e434c53a460..d2d904e6d07 100644 --- a/inference-engine/samples/common/utils/src/common.cpp +++ b/inference-engine/samples/common/utils/src/common.cpp @@ -4,7 +4,7 @@ #include "samples/common.hpp" -std::map parseConfig(const std::string &configName, char comment) { +std::map parseConfig(const std::string& configName, char comment) { std::map config = {}; std::ifstream file(configName); diff --git a/inference-engine/samples/hello_classification/main.cpp b/inference-engine/samples/hello_classification/main.cpp index af9bd6ec8ba..858a87ead5b 100644 --- a/inference-engine/samples/hello_classification/main.cpp +++ b/inference-engine/samples/hello_classification/main.cpp @@ -2,16 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include +#include #include +#include +#include +#include #include - -#include +#include +#include using namespace InferenceEngine; @@ -19,15 +18,15 @@ using namespace InferenceEngine; * @brief Define names based depends on Unicode path support */ #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) -#define tcout std::wcout -#define file_name_t std::wstring -#define imread_t imreadW -#define ClassificationResult_t ClassificationResultW + #define tcout std::wcout + #define file_name_t std::wstring + #define imread_t imreadW + #define ClassificationResult_t ClassificationResultW #else -#define tcout std::cout -#define file_name_t std::string -#define imread_t cv::imread -#define ClassificationResult_t ClassificationResult + #define tcout std::cout + #define file_name_t std::string + #define imread_t cv::imread + #define ClassificationResult_t ClassificationResult #endif #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) @@ -37,19 +36,14 @@ using namespace InferenceEngine; cv::Mat imreadW(std::wstring input_image_path) { cv::Mat image; std::ifstream input_image_stream; - input_image_stream.open( - input_image_path.c_str(), - std::iostream::binary | std::ios_base::ate | std::ios_base::in); + input_image_stream.open(input_image_path.c_str(), std::iostream::binary | std::ios_base::ate | std::ios_base::in); if (input_image_stream.is_open()) { if (input_image_stream.good()) { input_image_stream.seekg(0, std::ios::end); std::size_t file_size = input_image_stream.tellg(); input_image_stream.seekg(0, std::ios::beg); std::vector buffer(0); - std::copy( - std::istreambuf_iterator(input_image_stream), - std::istreambuf_iterator(), - std::back_inserter(buffer)); + std::copy(std::istreambuf_iterator(input_image_stream), std::istreambuf_iterator(), std::back_inserter(buffer)); image = cv::imdecode(cv::Mat(1, file_size, CV_8UC1, &buffer[0]), cv::IMREAD_COLOR); } else { tcout << "Input file '" << input_image_path << "' processing error" << std::endl; @@ -66,9 +60,9 @@ cv::Mat imreadW(std::wstring input_image_path) { * @param ref on wstring * @return string */ -std::string simpleConvert(const std::wstring & wstr) { +std::string simpleConvert(const std::wstring& wstr) { std::string str; - for (auto && wc : wstr) + for (auto&& wc : wstr) str += static_cast(wc); return str; } @@ -76,50 +70,59 @@ std::string simpleConvert(const std::wstring & wstr) { /** * @brief Main with support Unicode paths, wide strings */ -int wmain(int argc, wchar_t *argv[]) { +int wmain(int argc, wchar_t* argv[]) { #else -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { #endif try { - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (argc != 4) { tcout << "Usage : " << argv[0] << " " << std::endl; return EXIT_FAILURE; } - const file_name_t input_model{argv[1]}; - const file_name_t input_image_path{argv[2]}; + const file_name_t input_model {argv[1]}; + const file_name_t input_image_path {argv[2]}; #if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) const std::string device_name = simpleConvert(argv[3]); #else - const std::string device_name{argv[3]}; + const std::string device_name {argv[3]}; #endif // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- Core ie; // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format CNNNetwork network = ie.ReadNetwork(input_model); - if (network.getOutputsInfo().size() != 1) throw std::logic_error("Sample supports topologies with 1 output only"); - if (network.getInputsInfo().size() != 1) throw std::logic_error("Sample supports topologies with 1 input only"); + if (network.getOutputsInfo().size() != 1) + throw std::logic_error("Sample supports topologies with 1 output only"); + if (network.getInputsInfo().size() != 1) + throw std::logic_error("Sample supports topologies with 1 input only"); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- InputInfo::Ptr input_info = network.getInputsInfo().begin()->second; std::string input_name = network.getInputsInfo().begin()->first; /* Mark input as resizable by setting of a resize algorithm. - * In this case we will be able to set an input blob of any shape to an infer request. - * Resize and layout conversions are executed automatically during inference */ + * In this case we will be able to set an input blob of any shape to an + * infer request. Resize and layout conversions are executed automatically + * during inference */ input_info->getPreProcess().setResizeAlgorithm(RESIZE_BILINEAR); input_info->setLayout(Layout::NHWC); input_info->setPrecision(Precision::U8); - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- if (network.getOutputsInfo().empty()) { std::cerr << "Network outputs info is empty" << std::endl; return EXIT_FAILURE; @@ -130,37 +133,45 @@ int main(int argc, char *argv[]) { output_info->setPrecision(Precision::FP32); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading a model to the device ------------------------------------------ + // --------------------------- Step 4. Loading a model to the device + // ------------------------------------------ ExecutableNetwork executable_network = ie.LoadNetwork(network, device_name); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create an infer request ------------------------------------------------- + // --------------------------- Step 5. Create an infer request + // ------------------------------------------------- InferRequest infer_request = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- - /* Read input image to a blob and set it to an infer request without resize and layout conversions. */ + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- + /* Read input image to a blob and set it to an infer request without resize + * and layout conversions. */ cv::Mat image = imread_t(input_image_path); - Blob::Ptr imgBlob = wrapMat2Blob(image); // just wrap Mat data by Blob::Ptr without allocating of new memory + Blob::Ptr imgBlob = wrapMat2Blob(image); // just wrap Mat data by Blob::Ptr + // without allocating of new memory infer_request.SetBlob(input_name, imgBlob); // infer_request accepts input blob of any size // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference -------------------------------------------------------- + // --------------------------- Step 7. Do inference + // -------------------------------------------------------- /* Running the request synchronously */ infer_request.Infer(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------ + // --------------------------- Step 8. Process output + // ------------------------------------------------------ Blob::Ptr output = infer_request.GetBlob(output_name); // Print classification results ClassificationResult_t classificationResult(output, {input_image_path}); classificationResult.print(); // ----------------------------------------------------------------------------------------------------- - } catch (const std::exception & ex) { + } catch (const std::exception& ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } std::cout << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << std::endl; + "please use the dedicated benchmark_app tool" + << std::endl; return EXIT_SUCCESS; } diff --git a/inference-engine/samples/hello_nv12_input_classification/main.cpp b/inference-engine/samples/hello_nv12_input_classification/main.cpp index 9dba644bab2..59ec0329cce 100644 --- a/inference-engine/samples/hello_nv12_input_classification/main.cpp +++ b/inference-engine/samples/hello_nv12_input_classification/main.cpp @@ -2,28 +2,25 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include + +#include +#include #include -#include +#include +#include +#include #include +#include #include #include -#include -#include - -#include - -#include -#include -#include - -#include #ifdef _WIN32 -#include + #include #else -#include + #include #endif - using namespace InferenceEngine; /** @@ -33,23 +30,20 @@ using namespace InferenceEngine; */ std::pair parseImageSize(const std::string& size_string) { auto delimiter_pos = size_string.find("x"); - if (delimiter_pos == std::string::npos - || delimiter_pos >= size_string.size() - 1 - || delimiter_pos == 0) { + if (delimiter_pos == std::string::npos || delimiter_pos >= size_string.size() - 1 || delimiter_pos == 0) { std::stringstream err; err << "Incorrect format of image size parameter, expected WIDTHxHEIGHT, " - "actual: " << size_string; + "actual: " + << size_string; throw std::runtime_error(err.str()); } - size_t width = static_cast( - std::stoull(size_string.substr(0, delimiter_pos))); - size_t height = static_cast( - std::stoull(size_string.substr(delimiter_pos + 1, size_string.size()))); + size_t width = static_cast(std::stoull(size_string.substr(0, delimiter_pos))); + size_t height = static_cast(std::stoull(size_string.substr(delimiter_pos + 1, size_string.size()))); if (width == 0 || height == 0) { - throw std::runtime_error( - "Incorrect format of image size parameter, width and height must not be equal to 0"); + throw std::runtime_error("Incorrect format of image size parameter, width " + "and height must not be equal to 0"); } if (width % 2 != 0 || height % 2 != 0) { @@ -59,12 +53,14 @@ std::pair parseImageSize(const std::string& size_string) { return {width, height}; } -// Comparing to samples/args_helper.hpp, this version filters files by ".yuv" extension +// Comparing to samples/args_helper.hpp, this version filters files by ".yuv" +// extension /** -* @brief This function checks input args and existence of specified files in a given folder -* @param path path to a file to be checked for existence -* @return files updated vector of verified input files -*/ + * @brief This function checks input args and existence of specified files in a + * given folder + * @param path path to a file to be checked for existence + * @return files updated vector of verified input files + */ std::vector readInputFileNames(const std::string& path) { struct stat sb; if (stat(path.c_str(), &sb) != 0) { @@ -75,7 +71,7 @@ std::vector readInputFileNames(const std::string& path) { std::vector files; if (S_ISDIR(sb.st_mode)) { - DIR *dp = opendir(path.c_str()); + DIR* dp = opendir(path.c_str()); if (dp == nullptr) { slog::warn << "Directory " << path << " cannot be opened!" << slog::endl; return {}; @@ -83,7 +79,8 @@ std::vector readInputFileNames(const std::string& path) { for (struct dirent* ep = readdir(dp); ep != nullptr; ep = readdir(dp)) { std::string fileName = ep->d_name; - if (fileName == "." || fileName == ".." || fileName.substr(fileName.size() - 4) != ".yuv") continue; + if (fileName == "." || fileName == ".." || fileName.substr(fileName.size() - 4) != ".yuv") + continue; files.push_back(path + "/" + ep->d_name); } closedir(dp); @@ -139,25 +136,25 @@ std::vector readImagesDataFromFiles(const std::vector& fil } /** -* @brief Read input image to blob -* @param ref to input image data -* @param width input image -* @param height input image -* @return blob point to hold the NV12 input data -*/ + * @brief Read input image to blob + * @param ref to input image data + * @param width input image + * @param height input image + * @return blob point to hold the NV12 input data + */ std::vector readInputBlobs(std::vector& data, size_t width, size_t height) { - // read image with size converted to NV12 data size: height(NV12) = 3 / 2 * logical height + // read image with size converted to NV12 data size: height(NV12) = 3 / 2 * + // logical height // Create tensor descriptors for Y and UV blobs - const InferenceEngine::TensorDesc y_plane_desc(InferenceEngine::Precision::U8, {1, 1, height, width}, - InferenceEngine::Layout::NHWC); - const InferenceEngine::TensorDesc uv_plane_desc(InferenceEngine::Precision::U8, {1, 2, height / 2, width / 2}, - InferenceEngine::Layout::NHWC); + const InferenceEngine::TensorDesc y_plane_desc(InferenceEngine::Precision::U8, {1, 1, height, width}, InferenceEngine::Layout::NHWC); + const InferenceEngine::TensorDesc uv_plane_desc(InferenceEngine::Precision::U8, {1, 2, height / 2, width / 2}, InferenceEngine::Layout::NHWC); const size_t offset = width * height; std::vector blobs; for (auto& buf : data) { - // --------------------------- Create a blob to hold the NV12 input data ------------------------------- + // --------------------------- Create a blob to hold the NV12 input data + // ------------------------------- auto ptr = &buf[0]; // Create blob for Y plane from raw data @@ -172,48 +169,44 @@ std::vector readInputBlobs(std::vector& data, size_t width, } /** -* @brief Check supported batched blob for device -* @param IE core object -* @param string device name -* @return True(success) or False(fail) -*/ + * @brief Check supported batched blob for device + * @param IE core object + * @param string device name + * @return True(success) or False(fail) + */ bool isBatchedBlobSupported(const Core& ie, const std::string& device_name) { - const std::vector supported_metrics = - ie.GetMetric(device_name, METRIC_KEY(SUPPORTED_METRICS)); + const std::vector supported_metrics = ie.GetMetric(device_name, METRIC_KEY(SUPPORTED_METRICS)); - if (std::find(supported_metrics.begin(), supported_metrics.end(), - METRIC_KEY(OPTIMIZATION_CAPABILITIES)) == - supported_metrics.end()) { - return false; + if (std::find(supported_metrics.begin(), supported_metrics.end(), METRIC_KEY(OPTIMIZATION_CAPABILITIES)) == supported_metrics.end()) { + return false; } - const std::vector optimization_caps = - ie.GetMetric(device_name, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); + const std::vector optimization_caps = ie.GetMetric(device_name, METRIC_KEY(OPTIMIZATION_CAPABILITIES)); - return std::find(optimization_caps.begin(), optimization_caps.end(), - METRIC_VALUE(BATCHED_BLOB)) != optimization_caps.end(); + return std::find(optimization_caps.begin(), optimization_caps.end(), METRIC_VALUE(BATCHED_BLOB)) != optimization_caps.end(); } /** -* @brief The entry point of the Inference Engine sample application -*/ -int main(int argc, char *argv[]) { + * @brief The entry point of the Inference Engine sample application + */ +int main(int argc, char* argv[]) { try { - // ------------------------------ Parsing and validation input arguments------------------------------ + // ------------------------------ Parsing and validation input + // arguments------------------------------ if (argc != 5) { - std::cout << "Usage : " << argv[0] << " " - << std::endl; + std::cout << "Usage : " << argv[0] << " " << std::endl; return EXIT_FAILURE; } - const std::string input_model{argv[1]}; - const std::string input_image_path{argv[2]}; + const std::string input_model {argv[1]}; + const std::string input_image_path {argv[2]}; size_t input_width = 0, input_height = 0; std::tie(input_width, input_height) = parseImageSize(argv[3]); - const std::string device_name{argv[4]}; + const std::string device_name {argv[4]}; // ----------------------------------------------------------------------------------------------------- - // ------------------------------ Read image names ----------------------------------------------------- + // ------------------------------ Read image names + // ----------------------------------------------------- auto image_names = readInputFileNames(input_image_path); if (image_names.empty()) { @@ -221,15 +214,18 @@ int main(int argc, char *argv[]) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------------------ + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------------------ Core ie; // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format CNNNetwork network = ie.ReadNetwork(input_model); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Reshape model ------------------------------------------------- + // --------------------------- Reshape model + // ------------------------------------------------- size_t netInputSize = isBatchedBlobSupported(ie, device_name) ? image_names.size() : 1; ICNNNetwork::InputShapes inputShapes = network.getInputShapes(); for (auto& shape : inputShapes) { @@ -244,8 +240,10 @@ int main(int argc, char *argv[]) { std::cout << "Batch size is " << batchSize << std::endl; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input and output ------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input and output + // ------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- if (network.getInputsInfo().empty()) { std::cerr << "Network inputs info is empty" << std::endl; return EXIT_FAILURE; @@ -257,11 +255,12 @@ int main(int argc, char *argv[]) { input_info->setPrecision(Precision::U8); // set input resize algorithm to enable input autoresize input_info->getPreProcess().setResizeAlgorithm(ResizeAlgorithm::RESIZE_BILINEAR); - // set input color format to ColorFormat::NV12 to enable automatic input color format - // pre-processing + // set input color format to ColorFormat::NV12 to enable automatic input + // color format pre-processing input_info->getPreProcess().setColorFormat(ColorFormat::NV12); - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- if (network.getOutputsInfo().empty()) { std::cerr << "Network outputs info is empty" << std::endl; return EXIT_FAILURE; @@ -272,20 +271,24 @@ int main(int argc, char *argv[]) { output_info->setPrecision(Precision::FP32); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading a model to the device ---------------------------------------- + // --------------------------- Step 4. Loading a model to the device + // ---------------------------------------- ExecutableNetwork executable_network = ie.LoadNetwork(network, device_name); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create an infer request ---------------------------------------------- + // --------------------------- Step 5. Create an infer request + // ---------------------------------------------- InferRequest infer_request = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- auto image_bufs = readImagesDataFromFiles(image_names, input_width * (input_height * 3 / 2)); auto inputs = readInputBlobs(image_bufs, input_width, input_height); - // If batch_size > 1 => batched blob supported => replace all inputs by a BatchedBlob + // If batch_size > 1 => batched blob supported => replace all inputs by a + // BatchedBlob if (netInputSize > 1) { assert(netInputSize == inputs.size()); std::cout << "Infer using BatchedBlob of NV12 images." << std::endl; @@ -309,16 +312,19 @@ int main(int argc, char *argv[]) { for (size_t i = 0; i < inputs.size(); i++) { const auto& input = inputs[i]; - // --------------------------- Set the input blob to the InferRequest ------------------------------ + // --------------------------- Set the input blob to the InferRequest + // ------------------------------ infer_request.SetBlob(input_name, input); // ------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference ----------------------------------------------------- + // --------------------------- Step 7. Do inference + // ----------------------------------------------------- /* Running the request synchronously */ infer_request.Infer(); // ------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output --------------------------------------------------- + // --------------------------- Step 8. Process output + // --------------------------------------------------- Blob::Ptr output = infer_request.GetBlob(output_name); // Print classification results @@ -329,11 +335,12 @@ int main(int argc, char *argv[]) { classificationResult.print(); // ------------------------------------------------------------------------------------------------- } - } catch (const std::exception & ex) { + } catch (const std::exception& ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } std::cout << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << std::endl; + "please use the dedicated benchmark_app tool" + << std::endl; return EXIT_SUCCESS; } diff --git a/inference-engine/samples/hello_query_device/main.cpp b/inference-engine/samples/hello_query_device/main.cpp index c22e7e1c19c..0ac9285a3e7 100644 --- a/inference-engine/samples/hello_query_device/main.cpp +++ b/inference-engine/samples/hello_query_device/main.cpp @@ -2,39 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include #include -#include #include +#include +#include #include #include -#include -#include - -#include - -#include +#include using namespace InferenceEngine; namespace { - /** -* @brief Overload output stream operator to print vectors in pretty form [value1, value2, ...] -*/ + * @brief Overload output stream operator to print vectors in pretty form + * [value1, value2, ...] + */ template -std::ostream & operator << (std::ostream & stream, const std::vector & v) { +std::ostream& operator<<(std::ostream& stream, const std::vector& v) { stream << "[ "; - for (auto && value : v) + for (auto&& value : v) stream << value << " "; return stream << "]"; } /** -* @brief Print IE Parameters -* @param reference on IE Parameter -* @return void -*/ -void printParameterValue(const Parameter & value) { + * @brief Print IE Parameters + * @param reference on IE Parameter + * @return void + */ +void printParameterValue(const Parameter& value) { if (value.empty()) { std::cout << "EMPTY VALUE" << std::endl; } else if (value.is()) { @@ -48,24 +46,24 @@ void printParameterValue(const Parameter & value) { } else if (value.is()) { std::string stringValue = value.as(); std::cout << (stringValue.empty() ? "\"\"" : stringValue) << std::endl; - } else if (value.is >()) { - std::cout << value.as >() << std::endl; - } else if (value.is >()) { - std::cout << value.as >() << std::endl; - } else if (value.is >()) { - std::cout << value.as >() << std::endl; - } else if (value.is >()) { - std::cout << value.as >() << std::endl; - } else if (value.is >()) { - auto values = value.as >(); + } else if (value.is>()) { + std::cout << value.as>() << std::endl; + } else if (value.is>()) { + std::cout << value.as>() << std::endl; + } else if (value.is>()) { + std::cout << value.as>() << std::endl; + } else if (value.is>()) { + std::cout << value.as>() << std::endl; + } else if (value.is>()) { + auto values = value.as>(); std::cout << "{ "; std::cout << std::get<0>(values) << ", "; std::cout << std::get<1>(values) << ", "; std::cout << std::get<2>(values); std::cout << " }"; std::cout << std::endl; - } else if (value.is >()) { - auto values = value.as >(); + } else if (value.is>()) { + auto values = value.as>(); std::cout << "{ "; std::cout << std::get<0>(values) << ", "; std::cout << std::get<1>(values); @@ -78,42 +76,45 @@ void printParameterValue(const Parameter & value) { } // namespace -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { try { - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (argc != 1) { - std::cout << "Usage : "<< argv[0] << std::endl; + std::cout << "Usage : " << argv[0] << std::endl; return EXIT_FAILURE; } - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- std::cout << "Loading Inference Engine" << std::endl; Core ie; - // --------------------------- Get list of available devices ------------------------------------- + // --------------------------- Get list of available devices + // ------------------------------------- std::vector availableDevices = ie.GetAvailableDevices(); - // --------------------------- Query and print supported metrics and config keys-------------------- + // --------------------------- Query and print supported metrics and config + // keys-------------------- std::cout << "Available devices: " << std::endl; - for (auto && device : availableDevices) { + for (auto&& device : availableDevices) { std::cout << device << std::endl; std::cout << "\tSUPPORTED_METRICS: " << std::endl; std::vector supportedMetrics = ie.GetMetric(device, METRIC_KEY(SUPPORTED_METRICS)); - for (auto && metricName : supportedMetrics) { + for (auto&& metricName : supportedMetrics) { if (metricName != METRIC_KEY(SUPPORTED_METRICS) && metricName != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { std::cout << "\t\t" << metricName << " : " << std::flush; printParameterValue(ie.GetMetric(device, metricName)); } } - if (std::find(supportedMetrics.begin(), supportedMetrics.end(), - METRIC_KEY(SUPPORTED_CONFIG_KEYS)) != supportedMetrics.end()) { + if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(SUPPORTED_CONFIG_KEYS)) != supportedMetrics.end()) { std::cout << "\tSUPPORTED_CONFIG_KEYS (default values): " << std::endl; std::vector supportedConfigKeys = ie.GetMetric(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - for (auto && configKey : supportedConfigKeys) { + for (auto&& configKey : supportedConfigKeys) { std::cout << "\t\t" << configKey << " : " << std::flush; printParameterValue(ie.GetConfig(device, configKey)); } @@ -121,7 +122,7 @@ int main(int argc, char *argv[]) { std::cout << std::endl; } - } catch (const std::exception & ex) { + } catch (const std::exception& ex) { std::cerr << std::endl << "Exception occurred: " << ex.what() << std::endl << std::flush; return EXIT_FAILURE; } diff --git a/inference-engine/samples/hello_reshape_ssd/main.cpp b/inference-engine/samples/hello_reshape_ssd/main.cpp index be8a6395f72..e625e068659 100644 --- a/inference-engine/samples/hello_reshape_ssd/main.cpp +++ b/inference-engine/samples/hello_reshape_ssd/main.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include - #include +#include #include - #include +#include +#include #include "reshape_ssd_extension.hpp" @@ -17,19 +15,20 @@ using namespace InferenceEngine; int main(int argc, char* argv[]) { try { - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (argc != 5) { - std::cout << "Usage : "<< argv[0] <<" " - << std::endl; + std::cout << "Usage : " << argv[0] << " " << std::endl; return EXIT_FAILURE; } - const std::string input_model{argv[1]}; - const std::string input_image_path{argv[2]}; - const std::string device_name{argv[3]}; - const size_t batch_size{std::stoul(argv[4])}; + const std::string input_model {argv[1]}; + const std::string input_image_path {argv[2]}; + const std::string device_name {argv[3]}; + const size_t batch_size {std::stoul(argv[4])}; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- Core ie; IExtensionPtr inPlaceExtension; @@ -40,7 +39,8 @@ int main(int argc, char* argv[]) { } // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format CNNNetwork network = ie.ReadNetwork(input_model); OutputsDataMap outputs_info(network.getOutputsInfo()); @@ -48,7 +48,8 @@ int main(int argc, char* argv[]) { if (inputs_info.size() != 1 || outputs_info.size() != 1) throw std::logic_error("Sample supports clean SSD network with one input and one output"); - // --------------------------- Resize network to match image sizes and given batch---------------------- + // --------------------------- Resize network to match image sizes and given + // batch---------------------- auto input_shapes = network.getInputShapes(); std::string input_name; SizeVector input_shape; @@ -63,21 +64,24 @@ int main(int argc, char* argv[]) { network.reshape(input_shapes); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- InputInfo::Ptr input_info; std::tie(input_name, input_info) = *inputs_info.begin(); // Set input layout and precision input_info->setLayout(Layout::NCHW); input_info->setPrecision(Precision::U8); - // --------------------------- Prepare output blobs ---------------------------------------------------- + // --------------------------- Prepare output blobs + // ---------------------------------------------------- DataPtr output_info; std::string output_name; std::tie(output_name, output_info) = *outputs_info.begin(); // SSD has an additional post-processing DetectionOutput layer // that simplifies output filtering, try to find it. if (auto ngraphFunction = network.getFunction()) { - for (const auto & op : ngraphFunction->get_ops()) { + for (const auto& op : ngraphFunction->get_ops()) { if (op->get_type_info() == ngraph::op::DetectionOutput::type_info) { if (output_info->getName() != op->get_friendly_name()) { throw std::logic_error("Detection output op does not produce a network output"); @@ -103,10 +107,12 @@ int main(int argc, char* argv[]) { output_info->setPrecision(Precision::FP32); auto dumpVec = [](const SizeVector& vec) -> std::string { - if (vec.empty()) return "[]"; + if (vec.empty()) + return "[]"; std::stringstream oss; oss << "[" << vec[0]; - for (size_t i = 1; i < vec.size(); i++) oss << "," << vec[i]; + for (size_t i = 1; i < vec.size(); i++) + oss << "," << vec[i]; oss << "]"; return oss.str(); }; @@ -114,42 +120,49 @@ int main(int argc, char* argv[]) { std::cout << "Resulting output shape = " << dumpVec(output_shape) << std::endl; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading a model to the device ------------------------------------------ + // --------------------------- Step 4. Loading a model to the device + // ------------------------------------------ ExecutableNetwork executable_network = ie.LoadNetwork(network, device_name); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create an infer request ------------------------------------------------- + // --------------------------- Step 5. Create an infer request + // ------------------------------------------------- InferRequest infer_request = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- Blob::Ptr input = infer_request.GetBlob(input_name); for (size_t b = 0; b < batch_size; b++) { matU8ToBlob(image, input, b); } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference -------------------------------------------------------- + // --------------------------- Step 7. Do inference + // -------------------------------------------------------- infer_request.Infer(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------ + // --------------------------- Step 8. Process output + // ------------------------------------------------------ Blob::Ptr output = infer_request.GetBlob(output_name); MemoryBlob::CPtr moutput = as(output); if (!moutput) { throw std::logic_error("We expect output to be inherited from MemoryBlob, " "but by fact we were not able to cast output to MemoryBlob"); } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto moutputHolder = moutput->rmap(); - const float *detection = moutputHolder.as(); + const float* detection = moutputHolder.as(); /* Each detection has image_id that denotes processed image */ for (size_t cur_proposal = 0; cur_proposal < max_proposal_count; cur_proposal++) { float image_id = detection[cur_proposal * object_size + 0]; float label = detection[cur_proposal * object_size + 1]; float confidence = detection[cur_proposal * object_size + 2]; - /* CPU and GPU devices have difference in DetectionOutput layer, so we need both checks */ + /* CPU and GPU devices have difference in DetectionOutput layer, so we + * need both checks */ if (image_id < 0 || confidence == 0.0f) { continue; } @@ -164,20 +177,24 @@ int main(int argc, char* argv[]) { std::ostringstream conf; conf << ":" << std::fixed << std::setprecision(3) << confidence; cv::rectangle(image, cv::Point2f(xmin, ymin), cv::Point2f(xmax, ymax), cv::Scalar(0, 0, 255)); - std::cout << "[" << cur_proposal << "," << label << "] element, prob = " << confidence << - ", bbox = (" << xmin << "," << ymin << ")-(" << xmax << "," << ymax << ")" << ", batch id = " - << image_id << std::endl; + std::cout << "[" << cur_proposal << "," << label << "] element, prob = " << confidence << ", bbox = (" << xmin << "," << ymin << ")-(" << xmax + << "," << ymax << ")" + << ", batch id = " << image_id << std::endl; } } cv::imwrite("hello_reshape_ssd_output.jpg", image); - std::cout << "The resulting image was saved in the file: hello_reshape_ssd_output.jpg" << std::endl; + std::cout << "The resulting image was saved in the file: " + "hello_reshape_ssd_output.jpg" + << std::endl; // ----------------------------------------------------------------------------------------------------- } catch (const std::exception& ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } - std::cout << std::endl << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << std::endl; + std::cout << std::endl + << "This sample is an API example, for any performance measurements " + "please use the dedicated benchmark_app tool" + << std::endl; return EXIT_SUCCESS; } diff --git a/inference-engine/samples/hello_reshape_ssd/reshape_ssd_extension.hpp b/inference-engine/samples/hello_reshape_ssd/reshape_ssd_extension.hpp index 391730ac3c3..ac92f7c2aa4 100644 --- a/inference-engine/samples/hello_reshape_ssd/reshape_ssd_extension.hpp +++ b/inference-engine/samples/hello_reshape_ssd/reshape_ssd_extension.hpp @@ -2,20 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include #include #include -#include -#include -#include - -#include #include +#include +#include #define CUSTOM_RELU_TYPE "CustomReLU" class CustomReLUImpl : public InferenceEngine::ILayerExecImpl { public: - explicit CustomReLUImpl(const std::shared_ptr& node) : _node(node) {} + explicit CustomReLUImpl(const std::shared_ptr& node): _node(node) {} InferenceEngine::StatusCode getSupportedConfigurations(std::vector& conf, InferenceEngine::ResponseDesc* /*resp*/) noexcept override { @@ -38,26 +37,22 @@ public: for (size_t i = 0; i < shape.size(); i++) { order.push_back(i); } - cfg.desc = InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, - shape, {shape, order}); + cfg.desc = InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, shape, {shape, order}); layerConfig.outConfs.push_back(cfg); layerConfig.inConfs.push_back(cfg); conf.push_back(layerConfig); return InferenceEngine::OK; } - InferenceEngine::StatusCode - init(InferenceEngine::LayerConfig& /*config*/, InferenceEngine::ResponseDesc* /*resp*/) noexcept override { + InferenceEngine::StatusCode init(InferenceEngine::LayerConfig& /*config*/, InferenceEngine::ResponseDesc* /*resp*/) noexcept override { return InferenceEngine::StatusCode::OK; } - InferenceEngine::StatusCode - execute(std::vector& inputs, std::vector& outputs, - InferenceEngine::ResponseDesc* /*resp*/) noexcept override { + InferenceEngine::StatusCode execute(std::vector& inputs, std::vector& outputs, + InferenceEngine::ResponseDesc* /*resp*/) noexcept override { static bool wasCalled = false; if (!wasCalled) { - std::cout << "Running " + std::string(CUSTOM_RELU_TYPE) + " kernel for the first time (next messages won't be printed)" - << std::endl; + std::cout << "Running " + std::string(CUSTOM_RELU_TYPE) + " kernel for the first time (next messages won't be printed)" << std::endl; wasCalled = true; } for (size_t i = 0; i < inputs.size(); i++) { @@ -70,8 +65,8 @@ public: auto minputHolder = minput->rmap(); auto moutputHolder = moutput->wmap(); - auto inputData = minputHolder.as(); - auto outputData = moutputHolder.as(); + auto inputData = minputHolder.as(); + auto outputData = moutputHolder.as(); for (size_t j = 0; j < minput->size(); j++) { outputData[j] = inputData[j] < 0 ? 0 : inputData[j]; } @@ -83,10 +78,12 @@ private: const std::shared_ptr _node; }; -class CustomReluOp: public ngraph::op::Op { +class CustomReluOp : public ngraph::op::Op { public: - static constexpr ngraph::NodeTypeInfo type_info{CUSTOM_RELU_TYPE, 0}; - const ngraph::NodeTypeInfo& get_type_info() const override { return type_info; } + static constexpr ngraph::NodeTypeInfo type_info {CUSTOM_RELU_TYPE, 0}; + const ngraph::NodeTypeInfo& get_type_info() const override { + return type_info; + } CustomReluOp() = default; explicit CustomReluOp(const ngraph::Output& arg): Op({arg}) { diff --git a/inference-engine/samples/ngraph_function_creation_sample/CMakeLists.txt b/inference-engine/samples/ngraph_function_creation_sample/CMakeLists.txt index cae02806b5f..37fd62c2ecc 100644 --- a/inference-engine/samples/ngraph_function_creation_sample/CMakeLists.txt +++ b/inference-engine/samples/ngraph_function_creation_sample/CMakeLists.txt @@ -4,12 +4,9 @@ set(TARGET_NAME "ngraph_function_creation_sample") -file (GLOB MAIN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -file (GLOB MAIN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) - ie_add_sample(NAME ngraph_function_creation_sample - SOURCES ${MAIN_SRC} - HEADERS ${MAIN_HEADERS} + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" + HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/ngraph_function_creation_sample.hpp" DEPENDENCIES format_reader ie_samples_utils) find_package(ngraph REQUIRED) diff --git a/inference-engine/samples/ngraph_function_creation_sample/main.cpp b/inference-engine/samples/ngraph_function_creation_sample/main.cpp index a57e1be51ad..0855c961a63 100644 --- a/inference-engine/samples/ngraph_function_creation_sample/main.cpp +++ b/inference-engine/samples/ngraph_function_creation_sample/main.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,22 +12,21 @@ #include #include #include -#include #include #include -#include "ngraph_function_creation_sample.hpp" #include "ngraph/ngraph.hpp" +#include "ngraph_function_creation_sample.hpp" using namespace InferenceEngine; using namespace ngraph; /** -* @brief Checks input args -* @param argc number of args -* @param argv list of input arguments -* @return bool status true(Success) or false(Fail) -*/ + * @brief Checks input args + * @param argc number of args + * @param argv list of input arguments + * @return bool status true(Success) or false(Fail) + */ bool ParseAndCheckCommandLine(int argc, char* argv[]) { slog::info << "Parsing input parameters" << slog::endl; @@ -38,12 +38,14 @@ bool ParseAndCheckCommandLine(int argc, char* argv[]) { } if (FLAGS_nt <= 0 || FLAGS_nt > 10) { - throw std::logic_error("Incorrect value for nt argument. It should be greater than 0 and less than 10."); + throw std::logic_error("Incorrect value for nt argument. It should be " + "greater than 0 and less than 10."); } if (FLAGS_m.empty()) { showUsage(); - throw std::logic_error("Path to a .bin file with weights for the trained model is required but not set. Please set -m option."); + throw std::logic_error("Path to a .bin file with weights for the trained model is required " + "but not set. Please set -m option."); } if (FLAGS_i.empty()) { @@ -55,12 +57,12 @@ bool ParseAndCheckCommandLine(int argc, char* argv[]) { } /** -* @brief Read file to the buffer -* @param file_name string -* @param buffer to store file content -* @param maxSize length of file -* @return none -*/ + * @brief Read file to the buffer + * @param file_name string + * @param buffer to store file content + * @param maxSize length of file + * @return none + */ void readFile(const std::string& file_name, void* buffer, size_t maxSize) { std::ifstream inputFile; @@ -78,10 +80,10 @@ void readFile(const std::string& file_name, void* buffer, size_t maxSize) { } /** -* @brief Read .bin file with weights for the trained model -* @param filepath string -* @return weightsPtr tensor blob -*/ + * @brief Read .bin file with weights for the trained model + * @param filepath string + * @return weightsPtr tensor blob + */ TBlob::CPtr ReadWeights(std::string filepath) { std::ifstream weightFile(filepath, std::ifstream::ate | std::ifstream::binary); int64_t fileSize = weightFile.tellg(); @@ -100,126 +102,116 @@ TBlob::CPtr ReadWeights(std::string filepath) { } /** -* @brief Create ngraph function -* @return Ptr to ngraph function -*/ + * @brief Create ngraph function + * @return Ptr to ngraph function + */ std::shared_ptr createNgraphFunction() { TBlob::CPtr weightsPtr = ReadWeights(FLAGS_m); if (weightsPtr->byteSize() != 1724336) - IE_THROW() << "Incorrect weights file. This sample works only with LeNet classification network."; + IE_THROW() << "Incorrect weights file. This sample works only with LeNet " + "classification network."; // -------input------ - std::vector padBegin{ 0, 0 }; - std::vector padEnd{ 0, 0 }; + std::vector padBegin {0, 0}; + std::vector padEnd {0, 0}; - auto paramNode = std::make_shared( - element::Type_t::f32, Shape(std::vector{ {64, 1, 28, 28}})); + auto paramNode = std::make_shared(element::Type_t::f32, Shape(std::vector {{64, 1, 28, 28}})); paramNode->set_friendly_name("Parameter"); // -------convolution 1---- - auto convFirstShape = Shape{ 20, 1, 5, 5 }; - std::shared_ptr convolutionFirstConstantNode = std::make_shared( - element::Type_t::f32, convFirstShape, weightsPtr->cbuffer().as()); + auto convFirstShape = Shape {20, 1, 5, 5}; + std::shared_ptr convolutionFirstConstantNode = + std::make_shared(element::Type_t::f32, convFirstShape, weightsPtr->cbuffer().as()); - std::shared_ptr convolutionNodeFirst = std::make_shared( - paramNode->output(0), convolutionFirstConstantNode->output(0), Strides(SizeVector{ 1, 1 }), - CoordinateDiff(padBegin), CoordinateDiff(padEnd), Strides(SizeVector{ 1, 1 })); + std::shared_ptr convolutionNodeFirst = + std::make_shared(paramNode->output(0), convolutionFirstConstantNode->output(0), Strides(SizeVector {1, 1}), + CoordinateDiff(padBegin), CoordinateDiff(padEnd), Strides(SizeVector {1, 1})); // -------Add-------------- - auto addFirstShape = Shape{ 1, 20, 1, 1 }; + auto addFirstShape = Shape {1, 20, 1, 1}; auto offset = shape_size(convFirstShape) * sizeof(float); - std::shared_ptr addFirstConstantNode = std::make_shared( - element::Type_t::f32, addFirstShape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr addFirstConstantNode = + std::make_shared(element::Type_t::f32, addFirstShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr addNodeFirst = - std::make_shared(convolutionNodeFirst->output(0), addFirstConstantNode->output(0)); + std::shared_ptr addNodeFirst = std::make_shared(convolutionNodeFirst->output(0), addFirstConstantNode->output(0)); // -------MAXPOOL---------- - Shape padBeginShape{ 0, 0 }; - Shape padEndShape{ 0, 0 }; + Shape padBeginShape {0, 0}; + Shape padEndShape {0, 0}; - std::shared_ptr maxPoolingNodeFirst = std::make_shared( - addNodeFirst->output(0), std::vector{2, 2}, padBeginShape, padEndShape, - std::vector{2, 2}, op::RoundingType::CEIL, op::PadType::EXPLICIT); + std::shared_ptr maxPoolingNodeFirst = + std::make_shared(addNodeFirst->output(0), std::vector {2, 2}, padBeginShape, padEndShape, std::vector {2, 2}, + op::RoundingType::CEIL, op::PadType::EXPLICIT); // -------convolution 2---- - auto convSecondShape = Shape{ 50, 20, 5, 5 }; + auto convSecondShape = Shape {50, 20, 5, 5}; offset += shape_size(addFirstShape) * sizeof(float); - std::shared_ptr convolutionSecondConstantNode = std::make_shared( - element::Type_t::f32, convSecondShape, - (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr convolutionSecondConstantNode = + std::make_shared(element::Type_t::f32, convSecondShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr convolutionNodeSecond = std::make_shared( - maxPoolingNodeFirst->output(0), convolutionSecondConstantNode->output(0), Strides({ 1, 1 }), - CoordinateDiff(padBegin), CoordinateDiff(padEnd), Strides({ 1, 1 })); + std::shared_ptr convolutionNodeSecond = + std::make_shared(maxPoolingNodeFirst->output(0), convolutionSecondConstantNode->output(0), Strides({1, 1}), + CoordinateDiff(padBegin), CoordinateDiff(padEnd), Strides({1, 1})); // -------Add 2------------ - auto addSecondShape = Shape{ 1, 50, 1, 1 }; + auto addSecondShape = Shape {1, 50, 1, 1}; offset += shape_size(convSecondShape) * sizeof(float); - std::shared_ptr addSecondConstantNode = std::make_shared( - element::Type_t::f32, addSecondShape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr addSecondConstantNode = + std::make_shared(element::Type_t::f32, addSecondShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr addNodeSecond = - std::make_shared(convolutionNodeSecond->output(0), addSecondConstantNode->output(0)); + std::shared_ptr addNodeSecond = std::make_shared(convolutionNodeSecond->output(0), addSecondConstantNode->output(0)); // -------MAXPOOL 2-------- - std::shared_ptr maxPoolingNodeSecond = std::make_shared( - addNodeSecond->output(0), Strides{ 2, 2 }, padBeginShape, padEndShape, Shape{ 2, 2 }, - op::RoundingType::CEIL, op::PadType::EXPLICIT); + std::shared_ptr maxPoolingNodeSecond = std::make_shared(addNodeSecond->output(0), Strides {2, 2}, padBeginShape, padEndShape, + Shape {2, 2}, op::RoundingType::CEIL, op::PadType::EXPLICIT); // -------Reshape---------- - auto reshapeFirstShape = Shape{ 2 }; + auto reshapeFirstShape = Shape {2}; auto reshapeOffset = shape_size(addSecondShape) * sizeof(float) + offset; - std::shared_ptr reshapeFirstConstantNode = std::make_shared( - element::Type_t::i64, reshapeFirstShape, (weightsPtr->cbuffer().as() + reshapeOffset)); + std::shared_ptr reshapeFirstConstantNode = + std::make_shared(element::Type_t::i64, reshapeFirstShape, (weightsPtr->cbuffer().as() + reshapeOffset)); - std::shared_ptr reshapeFirstNode = - std::make_shared(maxPoolingNodeSecond->output(0), reshapeFirstConstantNode->output(0), true); + std::shared_ptr reshapeFirstNode = std::make_shared(maxPoolingNodeSecond->output(0), reshapeFirstConstantNode->output(0), true); // -------MatMul 1--------- - auto matMulFirstShape = Shape{ 500, 800 }; + auto matMulFirstShape = Shape {500, 800}; offset = shape_size(reshapeFirstShape) * sizeof(int64_t) + reshapeOffset; - std::shared_ptr matMulFirstConstantNode = std::make_shared( - element::Type_t::f32, matMulFirstShape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr matMulFirstConstantNode = + std::make_shared(element::Type_t::f32, matMulFirstShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr matMulFirstNode = - std::make_shared(reshapeFirstNode->output(0), matMulFirstConstantNode->output(0), false, true); + std::shared_ptr matMulFirstNode = std::make_shared(reshapeFirstNode->output(0), matMulFirstConstantNode->output(0), false, true); // -------Add 3------------ - auto addThirdShape = Shape{1, 500}; + auto addThirdShape = Shape {1, 500}; offset += shape_size(matMulFirstShape) * sizeof(float); - std::shared_ptr addThirdConstantNode = std::make_shared( - element::Type_t::f32, addThirdShape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr addThirdConstantNode = + std::make_shared(element::Type_t::f32, addThirdShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr addThirdNode = - std::make_shared(matMulFirstNode->output(0), addThirdConstantNode->output(0)); + std::shared_ptr addThirdNode = std::make_shared(matMulFirstNode->output(0), addThirdConstantNode->output(0)); // -------Relu------------- std::shared_ptr reluNode = std::make_shared(addThirdNode->output(0)); // -------Reshape 2-------- - auto reshapeSecondShape = Shape{ 2 }; - std::shared_ptr reshapeSecondConstantNode = std::make_shared( - element::Type_t::i64, reshapeSecondShape, (weightsPtr->cbuffer().as() + reshapeOffset)); + auto reshapeSecondShape = Shape {2}; + std::shared_ptr reshapeSecondConstantNode = + std::make_shared(element::Type_t::i64, reshapeSecondShape, (weightsPtr->cbuffer().as() + reshapeOffset)); - std::shared_ptr reshapeSecondNode = - std::make_shared(reluNode->output(0), reshapeSecondConstantNode->output(0), true); + std::shared_ptr reshapeSecondNode = std::make_shared(reluNode->output(0), reshapeSecondConstantNode->output(0), true); // -------MatMul 2--------- - auto matMulSecondShape = Shape{ 10, 500 }; + auto matMulSecondShape = Shape {10, 500}; offset += shape_size(addThirdShape) * sizeof(float); - std::shared_ptr matMulSecondConstantNode = std::make_shared( - element::Type_t::f32, matMulSecondShape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr matMulSecondConstantNode = + std::make_shared(element::Type_t::f32, matMulSecondShape, (weightsPtr->cbuffer().as() + offset)); - std::shared_ptr matMulSecondNode = - std::make_shared(reshapeSecondNode->output(0), matMulSecondConstantNode->output(0), false, true); + std::shared_ptr matMulSecondNode = std::make_shared(reshapeSecondNode->output(0), matMulSecondConstantNode->output(0), false, true); // -------Add 4------------ - auto add4Shape = Shape{ 1, 10 }; + auto add4Shape = Shape {1, 10}; offset += shape_size(matMulSecondShape) * sizeof(float); - std::shared_ptr add4ConstantNode = std::make_shared( - element::Type_t::f32, add4Shape, (weightsPtr->cbuffer().as() + offset)); + std::shared_ptr add4ConstantNode = std::make_shared(element::Type_t::f32, add4Shape, (weightsPtr->cbuffer().as() + offset)); std::shared_ptr add4Node = std::make_shared(matMulSecondNode->output(0), add4ConstantNode->output(0)); @@ -229,26 +221,29 @@ std::shared_ptr createNgraphFunction() { // -------ngraph function-- auto result_full = std::make_shared(softMaxNode->output(0)); - std::shared_ptr fnPtr = std::make_shared( - result_full, ngraph::ParameterVector{ paramNode }, "lenet"); + std::shared_ptr fnPtr = std::make_shared(result_full, ngraph::ParameterVector {paramNode}, "lenet"); return fnPtr; } /** - * @brief The entry point for inference engine automatic ngraph function creation sample + * @brief The entry point for inference engine automatic ngraph function + * creation sample * @file ngraph_function_creation_sample/main.cpp * @example ngraph_function_creation_sample/main.cpp */ int main(int argc, char* argv[]) { try { - // ------------------------------ Get Inference Engine version ------------------------------------------------------ + // ------------------------------ Get Inference Engine version + // ------------------------------------------------------ slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << slog::endl; - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (!ParseAndCheckCommandLine(argc, argv)) { return 0; } - // ------------------------------ Read input ----------------------------------------------------------- + // ------------------------------ Read input + // ----------------------------------------------------------- /** This vector stores paths to the processed images **/ std::vector images; parseInputFilesArguments(images); @@ -257,21 +252,26 @@ int main(int argc, char* argv[]) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- slog::info << "Loading Inference Engine" << slog::endl; Core ie; - // ------------------------------ Get Available Devices ------------------------------------------------------ + // ------------------------------ Get Available Devices + // ------------------------------------------------------ slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(FLAGS_d) << std::endl; // ----------------------------------------------------------------------------------------------------- - //--------------------------- Step 2. Create network using ngraph function ----------------------------------- + //--------------------------- Step 2. Create network using ngraph function + //----------------------------------- CNNNetwork network(createNgraphFunction()); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- slog::info << "Preparing input blobs" << slog::endl; InputsDataMap inputInfo = network.getInputsInfo(); @@ -294,8 +294,8 @@ int main(int argc, char* argv[]) { continue; } /** Store image data **/ - std::shared_ptr data(reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], - inputInfoItem.second->getTensorDesc().getDims()[2])); + std::shared_ptr data( + reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], inputInfoItem.second->getTensorDesc().getDims()[2])); if (data.get() != nullptr) { imagesData.push_back(data); } @@ -310,7 +310,8 @@ int main(int argc, char* argv[]) { size_t batchSize = network.getBatchSize(); slog::info << "Batch size is " << std::to_string(batchSize) << slog::endl; - // --------------------------- Prepare output blobs ----------------------------------------------------- + // --------------------------- Prepare output blobs + // ----------------------------------------------------- slog::info << "Checking that the outputs are as the sample expects" << slog::endl; OutputsDataMap outputInfo(network.getOutputsInfo()); std::string firstOutputName; @@ -349,23 +350,27 @@ int main(int argc, char* argv[]) { // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ slog::info << "Loading model to the device" << slog::endl; ExecutableNetwork exeNetwork = ie.LoadNetwork(network, FLAGS_d); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- slog::info << "Create infer request" << slog::endl; InferRequest infer_request = exeNetwork.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- /** Iterate over all the input blobs **/ for (const auto& item : inputInfo) { /** Creating input blob **/ Blob::Ptr input = infer_request.GetBlob(item.first); - /** Filling input tensor with images. First b channel, then g and r channels **/ + /** Filling input tensor with images. First b channel, then g and r + * channels **/ size_t num_channels = input->getTensorDesc().getDims()[1]; size_t image_size = input->getTensorDesc().getDims()[2] * input->getTensorDesc().getDims()[3]; @@ -377,9 +382,9 @@ int main(int argc, char* argv[]) { for (size_t pid = 0; pid < image_size; pid++) { /** Iterate over all channels **/ for (size_t ch = 0; ch < num_channels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - data[image_id * image_size * num_channels + ch * image_size + pid] = - imagesData.at(image_id).get()[pid * num_channels + ch]; + /** [images stride + channels stride + pixel id ] all in + * bytes **/ + data[image_id * image_size * num_channels + ch * image_size + pid] = imagesData.at(image_id).get()[pid * num_channels + ch]; } } } @@ -387,12 +392,14 @@ int main(int argc, char* argv[]) { inputInfo = {}; // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference --------------------------------------------------------- + // --------------------------- Step 7. Do inference + // --------------------------------------------------------- slog::info << "Start inference" << slog::endl; infer_request.Infer(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------- + // --------------------------- Step 8. Process output + // ------------------------------------------------------- slog::info << "Processing output blobs" << slog::endl; const Blob::Ptr outputBlob = infer_request.GetBlob(firstOutputName); @@ -400,8 +407,8 @@ int main(int argc, char* argv[]) { /** Validating -nt value **/ const size_t resultsCnt = outputBlob->size() / batchSize; if (FLAGS_nt > resultsCnt || FLAGS_nt < 1) { - slog::warn << "-nt " << FLAGS_nt << " is not available for this network (-nt should be less than " - << resultsCnt + 1 << " and more than 0).\n Maximal value " << resultsCnt << " will be used."; + slog::warn << "-nt " << FLAGS_nt << " is not available for this network (-nt should be less than " << resultsCnt + 1 + << " and more than 0).\n Maximal value " << resultsCnt << " will be used."; FLAGS_nt = resultsCnt; } @@ -428,7 +435,7 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } slog::info << "This sample is an API example, for performance measurements, " - "use the dedicated benchmark_app tool" - << slog::endl; + "use the dedicated benchmark_app tool" + << slog::endl; return 0; } diff --git a/inference-engine/samples/ngraph_function_creation_sample/ngraph_function_creation_sample.hpp b/inference-engine/samples/ngraph_function_creation_sample/ngraph_function_creation_sample.hpp index 1792f95cf05..fc7726d963b 100644 --- a/inference-engine/samples/ngraph_function_creation_sample/ngraph_function_creation_sample.hpp +++ b/inference-engine/samples/ngraph_function_creation_sample/ngraph_function_creation_sample.hpp @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /// @brief message for help argument static const char help_message[] = "Print a usage message."; @@ -19,9 +20,9 @@ static const char input_message[] = "Required. Path to a folder with images or p static const char model_message[] = "Required. Path to a .bin file with weights for the trained model."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " \ -"Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ -"Sample will look for a suitable plugin for device specified."; +static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " + "Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " + "Sample will look for a suitable plugin for device specified."; /// @brief message for top results number static const char ntop_message[] = "Number of top results. The default value is 10."; diff --git a/inference-engine/samples/object_detection_sample_ssd/main.cpp b/inference-engine/samples/object_detection_sample_ssd/main.cpp index 5fb673bdf86..1c7b6a00132 100644 --- a/inference-engine/samples/object_detection_sample_ssd/main.cpp +++ b/inference-engine/samples/object_detection_sample_ssd/main.cpp @@ -2,33 +2,32 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include +#include +#include #include "object_detection_sample_ssd.h" using namespace InferenceEngine; /** -* @brief Checks input args -* @param argc number of args -* @param argv list of input arguments -* @return bool status true(Success) or false(Fail) -*/ -bool ParseAndCheckCommandLine(int argc, char *argv[]) { + * @brief Checks input args + * @param argc number of args + * @param argv list of input arguments + * @return bool status true(Success) or false(Fail) + */ +bool ParseAndCheckCommandLine(int argc, char* argv[]) { gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true); if (FLAGS_h) { showUsage(); @@ -52,71 +51,86 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { } /** -* \brief The entry point for the Inference Engine object_detection sample application -* \file object_detection_sample_ssd/main.cpp -* \example object_detection_sample_ssd/main.cpp -*/ -int main(int argc, char *argv[]) { + * \brief The entry point for the Inference Engine object_detection sample + * application \file object_detection_sample_ssd/main.cpp \example + * object_detection_sample_ssd/main.cpp + */ +int main(int argc, char* argv[]) { try { - /** This sample covers certain topology and cannot be generalized for any object detection one **/ - // ------------------------------ Get Inference Engine version ------------------------------------------------------ + /** This sample covers certain topology and cannot be generalized for any + * object detection one **/ + // ------------------------------ Get Inference Engine version + // ------------------------------------------------------ slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << "\n"; - // --------------------------- Parsing and validation of input arguments --------------------------------- + // --------------------------- Parsing and validation of input arguments + // --------------------------------- if (!ParseAndCheckCommandLine(argc, argv)) { return 0; } // ----------------------------------------------------------------------------------------------------- - // ------------------------------ Read input ----------------------------------------------------------- + // ------------------------------ Read input + // ----------------------------------------------------------- /** This vector stores paths to the processed images **/ std::vector images; parseInputFilesArguments(images); - if (images.empty()) throw std::logic_error("No suitable images were found"); + if (images.empty()) + throw std::logic_error("No suitable images were found"); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- slog::info << "Loading Inference Engine" << slog::endl; Core ie; - // ------------------------------ Get Available Devices ------------------------------------------------------ + // ------------------------------ Get Available Devices + // ------------------------------------------------------ slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(FLAGS_d) << std::endl; if (!FLAGS_l.empty()) { - // Custom CPU extension is loaded as a shared library and passed as a pointer to base extension + // Custom CPU extension is loaded as a shared library and passed as a + // pointer to base extension IExtensionPtr extension_ptr = std::make_shared(FLAGS_l); ie.AddExtension(extension_ptr); slog::info << "Custom extension loaded: " << FLAGS_l << slog::endl; } if (!FLAGS_c.empty() && (FLAGS_d == "GPU" || FLAGS_d == "MYRIAD" || FLAGS_d == "HDDL")) { - // Config for device plugin custom extension is loaded from an .xml description - ie.SetConfig({ { PluginConfigParams::KEY_CONFIG_FILE, FLAGS_c } }, FLAGS_d); + // Config for device plugin custom extension is loaded from an .xml + // description + ie.SetConfig({{PluginConfigParams::KEY_CONFIG_FILE, FLAGS_c}}, FLAGS_d); slog::info << "Config for " << FLAGS_d << " device plugin custom extension loaded: " << FLAGS_c << slog::endl; } // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format slog::info << "Loading network files:" << slog::endl << FLAGS_m << slog::endl; /** Read network model **/ CNNNetwork network = ie.ReadNetwork(FLAGS_m); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- - // -------------------------------- Prepare input blobs -------------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- + // -------------------------------- Prepare input blobs + // -------------------------------------------------- slog::info << "Preparing input blobs" << slog::endl; /** Taking information about all topology inputs **/ InputsDataMap inputsInfo(network.getInputsInfo()); /** - * Some networks have SSD-like output format (ending with DetectionOutput layer), but - * having 2 inputs as Faster-RCNN: one for image and one for "image info". + * Some networks have SSD-like output format (ending with DetectionOutput + * layer), but having 2 inputs as Faster-RCNN: one for image and one for + * "image info". * - * Although object_datection_sample_ssd's main task is to support clean SSD, it could score - * the networks with two inputs as well. For such networks imInfoInputName will contain the "second" input name. + * Although object_datection_sample_ssd's main task is to support clean SSD, + * it could score the networks with two inputs as well. For such networks + * imInfoInputName will contain the "second" input name. */ - if (inputsInfo.size() != 1 && inputsInfo.size() != 2) throw std::logic_error("Sample supports topologies only with 1 or 2 inputs"); + if (inputsInfo.size() != 1 && inputsInfo.size() != 2) + throw std::logic_error("Sample supports topologies only with 1 or 2 inputs"); std::string imageInputName, imInfoInputName; @@ -126,7 +140,7 @@ int main(int argc, char *argv[]) { /** Stores input image **/ /** Iterating over all input blobs **/ - for (auto & item : inputsInfo) { + for (auto& item : inputsInfo) { /** Working with first input tensor that stores image **/ if (item.second->getInputData()->getTensorDesc().getDims().size() == 4) { imageInputName = item.first; @@ -152,7 +166,8 @@ int main(int argc, char *argv[]) { if (inputInfo == nullptr) { inputInfo = inputsInfo.begin()->second; } - // --------------------------- Prepare output blobs ------------------------------------------------- + // --------------------------- Prepare output blobs + // ------------------------------------------------- slog::info << "Preparing output blobs" << slog::endl; OutputsDataMap outputsInfo(network.getOutputsInfo()); @@ -166,9 +181,8 @@ int main(int argc, char *argv[]) { // that simplifies output filtering, try to find it. if (auto ngraphFunction = network.getFunction()) { for (const auto& out : outputsInfo) { - for (const auto & op : ngraphFunction->get_ops()) { - if (op->get_type_info() == ngraph::op::DetectionOutput::type_info && - op->get_friendly_name() == out.second->getName()) { + for (const auto& op : ngraphFunction->get_ops()) { + if (op->get_type_info() == ngraph::op::DetectionOutput::type_info && op->get_friendly_name() == out.second->getName()) { outputName = out.first; outputInfo = out.second; break; @@ -194,26 +208,30 @@ int main(int argc, char *argv[]) { throw std::logic_error("Incorrect output dimensions for SSD model"); } - /** Set the precision of output data provided by the user, should be called before load of the network to the device **/ + /** Set the precision of output data provided by the user, should be called + * before load of the network to the device **/ outputInfo->setPrecision(Precision::FP32); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ slog::info << "Loading model to the device" << slog::endl; ExecutableNetwork executable_network = ie.LoadNetwork(network, FLAGS_d, parseConfig(FLAGS_config)); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- slog::info << "Create infer request" << slog::endl; InferRequest infer_request = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- /** Collect images data ptrs **/ std::vector> imagesData, originalImagesData; std::vector imageWidths, imageHeights; - for (auto & i : images) { + for (auto& i : images) { FormatReader::ReaderPtr reader(i.c_str()); if (reader.get() == nullptr) { slog::warn << "Image " + i + " cannot be read!" << slog::endl; @@ -229,34 +247,38 @@ int main(int argc, char *argv[]) { imageHeights.push_back(reader->height()); } } - if (imagesData.empty()) throw std::logic_error("Valid input images were not found!"); + if (imagesData.empty()) + throw std::logic_error("Valid input images were not found!"); size_t batchSize = network.getBatchSize(); slog::info << "Batch size is " << std::to_string(batchSize) << slog::endl; if (batchSize != imagesData.size()) { - slog::warn << "Number of images " + std::to_string(imagesData.size()) + \ - " doesn't match batch size " + std::to_string(batchSize) << slog::endl; + slog::warn << "Number of images " + std::to_string(imagesData.size()) + " doesn't match batch size " + std::to_string(batchSize) << slog::endl; batchSize = std::min(batchSize, imagesData.size()); - slog::warn << "Number of images to be processed is "<< std::to_string(batchSize) << slog::endl; + slog::warn << "Number of images to be processed is " << std::to_string(batchSize) << slog::endl; } /** Creating input blob **/ Blob::Ptr imageInput = infer_request.GetBlob(imageInputName); - /** Filling input tensor with images. First b channel, then g and r channels **/ + /** Filling input tensor with images. First b channel, then g and r channels + * **/ MemoryBlob::Ptr mimage = as(imageInput); if (!mimage) { - slog::err << "We expect image blob to be inherited from MemoryBlob, but by fact we were not able " - "to cast imageInput to MemoryBlob" << slog::endl; + slog::err << "We expect image blob to be inherited from MemoryBlob, but " + "by fact we were not able " + "to cast imageInput to MemoryBlob" + << slog::endl; return 1; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto minputHolder = mimage->wmap(); size_t num_channels = mimage->getTensorDesc().getDims()[1]; size_t image_size = mimage->getTensorDesc().getDims()[3] * mimage->getTensorDesc().getDims()[2]; - unsigned char *data = minputHolder.as(); + unsigned char* data = minputHolder.as(); /** Iterate over all input images limited by batch size **/ for (size_t image_id = 0; image_id < std::min(imagesData.size(), batchSize); ++image_id) { @@ -264,8 +286,9 @@ int main(int argc, char *argv[]) { for (size_t pid = 0; pid < image_size; pid++) { /** Iterate over all channels **/ for (size_t ch = 0; ch < num_channels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - data[image_id * image_size * num_channels + ch * image_size + pid] = imagesData.at(image_id).get()[pid*num_channels + ch]; + /** [images stride + channels stride + pixel id ] all in + * bytes **/ + data[image_id * image_size * num_channels + ch * image_size + pid] = imagesData.at(image_id).get()[pid * num_channels + ch]; } } } @@ -277,13 +300,16 @@ int main(int argc, char *argv[]) { /** Fill input tensor with values **/ MemoryBlob::Ptr minput2 = as(input2); if (!minput2) { - slog::err << "We expect input2 blob to be inherited from MemoryBlob, but by fact we were not able " - "to cast input2 to MemoryBlob" << slog::endl; + slog::err << "We expect input2 blob to be inherited from MemoryBlob, " + "but by fact we were not able " + "to cast input2 to MemoryBlob" + << slog::endl; return 1; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its + // buffer happens auto minput2Holder = minput2->wmap(); - float *p = minput2Holder.as::value_type *>(); + float* p = minput2Holder.as::value_type*>(); for (size_t image_id = 0; image_id < std::min(imagesData.size(), batchSize); ++image_id) { p[image_id * imInfoDim + 0] = static_cast(inputsInfo[imageInputName]->getTensorDesc().getDims()[2]); @@ -295,12 +321,14 @@ int main(int argc, char *argv[]) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference --------------------------------------------------------- + // --------------------------- Step 7. Do inference + // --------------------------------------------------------- slog::info << "Start inference" << slog::endl; infer_request.Infer(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------- + // --------------------------- Step 8. Process output + // ------------------------------------------------------- slog::info << "Processing output blobs" << slog::endl; const Blob::Ptr output_blob = infer_request.GetBlob(outputName); @@ -309,12 +337,13 @@ int main(int argc, char *argv[]) { throw std::logic_error("We expect output to be inherited from MemoryBlob, " "but by fact we were not able to cast output to MemoryBlob"); } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto moutputHolder = moutput->rmap(); - const float *detection = moutputHolder.as::value_type *>(); + const float* detection = moutputHolder.as::value_type*>(); - std::vector > boxes(batchSize); - std::vector > classes(batchSize); + std::vector> boxes(batchSize); + std::vector> classes(batchSize); /* Each detection has image_id that denotes processed image */ for (int curProposal = 0; curProposal < maxProposalCount; curProposal++) { @@ -330,8 +359,9 @@ int main(int argc, char *argv[]) { auto xmax = static_cast(detection[curProposal * objectSize + 5] * imageWidths[image_id]); auto ymax = static_cast(detection[curProposal * objectSize + 6] * imageHeights[image_id]); - std::cout << "[" << curProposal << "," << label << "] element, prob = " << confidence << - " (" << xmin << "," << ymin << ")-(" << xmax << "," << ymax << ")" << " batch id : " << image_id; + std::cout << "[" << curProposal << "," << label << "] element, prob = " << confidence << " (" << xmin << "," << ymin << ")-(" << xmax << "," + << ymax << ")" + << " batch id : " << image_id; if (confidence > 0.5) { /** Drawing only objects with >50% probability **/ @@ -356,18 +386,18 @@ int main(int argc, char *argv[]) { } } // ----------------------------------------------------------------------------------------------------- - } - catch (const std::exception& error) { + } catch (const std::exception& error) { slog::err << error.what() << slog::endl; return 1; - } - catch (...) { + } catch (...) { slog::err << "Unknown/internal exception happened." << slog::endl; return 1; } slog::info << "Execution successful" << slog::endl; - slog::info << slog::endl << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << slog::endl; + slog::info << slog::endl + << "This sample is an API example, for any performance measurements " + "please use the dedicated benchmark_app tool" + << slog::endl; return 0; } diff --git a/inference-engine/samples/object_detection_sample_ssd/object_detection_sample_ssd.h b/inference-engine/samples/object_detection_sample_ssd/object_detection_sample_ssd.h index 67204cfabf1..fea030e8c4b 100644 --- a/inference-engine/samples/object_detection_sample_ssd/object_detection_sample_ssd.h +++ b/inference-engine/samples/object_detection_sample_ssd/object_detection_sample_ssd.h @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /* thickness of a line (in pixels) to be used for bounding boxes */ #define BBOX_THICKNESS 2 @@ -22,17 +23,19 @@ static const char model_message[] = "Required. Path to an .xml file with a train static const char image_message[] = "Required. Path to an image."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " \ -"Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ -"Sample will look for a suitable plugin for device specified."; +static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown " + "below). " + "Default value is CPU. Use \"-d HETERO:\" format to specify " + "HETERO plugin. " + "Sample will look for a suitable plugin for device specified."; /// @brief message for plugin custom kernels desc -static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. "\ -"Absolute path to the .xml config file with the kernels descriptions."; +static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. " + "Absolute path to the .xml config file with the kernels descriptions."; /// @brief message for user library argument -static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " \ -"Absolute path to a shared library with the kernels implementations."; +static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " + "Absolute path to a shared library with the kernels implementations."; /// @brief message for config argument static constexpr char config_message[] = "Path to the configuration file."; @@ -64,8 +67,8 @@ DEFINE_string(l, "", custom_ex_library_message); DEFINE_string(config, "", config_message); /** -* \brief This function show a help message -*/ + * \brief This function show a help message + */ static void showUsage() { std::cout << std::endl; std::cout << "object_detection_sample_ssd [OPTION]" << std::endl; diff --git a/inference-engine/samples/speech_sample/main.cpp b/inference-engine/samples/speech_sample/main.cpp index 98ddc192ec8..d6b79c76f91 100644 --- a/inference-engine/samples/speech_sample/main.cpp +++ b/inference-engine/samples/speech_sample/main.cpp @@ -2,32 +2,32 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "speech_sample.hpp" - #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include +#include +#include +#include +#include -#define MAX_SCORE_DIFFERENCE 0.0001f // max score difference for frame error threshold -#define MAX_VAL_2B_FEAT 16384 // max to find scale factor +#include "speech_sample.hpp" + +#define MAX_SCORE_DIFFERENCE 0.0001f // max score difference for frame error threshold +#define MAX_VAL_2B_FEAT 16384 // max to find scale factor using namespace InferenceEngine; @@ -35,8 +35,8 @@ typedef std::chrono::high_resolution_clock Time; typedef std::chrono::duration> ms; typedef std::chrono::duration fsec; /** -* @brief struct to store score error -*/ + * @brief struct to store score error + */ typedef struct { uint32_t numScores; uint32_t numErrors; @@ -52,8 +52,8 @@ typedef struct { } score_error_t; /** -* @brief struct to store infer request data per frame -*/ + * @brief struct to store infer request data per frame + */ struct InferRequestStruct { InferRequest inferRequest; int frameIndex; @@ -61,30 +61,29 @@ struct InferRequestStruct { }; /** -* @brief Check number of input files and model network inputs -* @param numInputs number model inputs -* @param numInputArkFiles number of input ARK files -* @return none. -*/ + * @brief Check number of input files and model network inputs + * @param numInputs number model inputs + * @param numInputArkFiles number of input ARK files + * @return none. + */ void CheckNumberOfInputs(size_t numInputs, size_t numInputArkFiles) { if (numInputs != numInputArkFiles) { - throw std::logic_error("Number of network inputs (" + std::to_string(numInputs) + ")" - " is not equal to number of ark files (" + std::to_string(numInputArkFiles) + ")"); + throw std::logic_error("Number of network inputs (" + std::to_string(numInputs) + + ")" + " is not equal to number of ark files (" + + std::to_string(numInputArkFiles) + ")"); } } /** -* @brief Get info from Kaldi ARK speech feature vector file -* @param fileName .ark file name -* @param numArrayToFindSize number speech feature vectors in the file -* @param ptrNumArrays pointer to specific number array -* @param ptrNumMemoryBytes pointer to specific number of memory bytes -* @return none. -*/ -void GetKaldiArkInfo(const char *fileName, - uint32_t numArrayToFindSize, - uint32_t *ptrNumArrays, - uint32_t *ptrNumMemoryBytes) { + * @brief Get info from Kaldi ARK speech feature vector file + * @param fileName .ark file name + * @param numArrayToFindSize number speech feature vectors in the file + * @param ptrNumArrays pointer to specific number array + * @param ptrNumMemoryBytes pointer to specific number of memory bytes + * @return none. + */ +void GetKaldiArkInfo(const char* fileName, uint32_t numArrayToFindSize, uint32_t* ptrNumArrays, uint32_t* ptrNumMemoryBytes) { uint32_t numArrays = 0; uint32_t numMemoryBytes = 0; @@ -98,11 +97,11 @@ void GetKaldiArkInfo(const char *fileName, if (line.compare("BFM ") != 0) { break; } - in_file.read(reinterpret_cast(&numRows), sizeof(uint32_t)); // read number of rows - std::getline(in_file, line, '\4'); // read control-D - in_file.read(reinterpret_cast(&numCols), sizeof(uint32_t)); // read number of columns + in_file.read(reinterpret_cast(&numRows), sizeof(uint32_t)); // read number of rows + std::getline(in_file, line, '\4'); // read control-D + in_file.read(reinterpret_cast(&numCols), sizeof(uint32_t)); // read number of columns num_bytes = numRows * numCols * sizeof(float); - in_file.seekg(num_bytes, in_file.cur); // read data + in_file.seekg(num_bytes, in_file.cur); // read data if (numArrays == numArrayToFindSize) { numMemoryBytes += num_bytes; @@ -115,23 +114,25 @@ void GetKaldiArkInfo(const char *fileName, exit(-1); } - if (ptrNumArrays != NULL) *ptrNumArrays = numArrays; - if (ptrNumMemoryBytes != NULL) *ptrNumMemoryBytes = numMemoryBytes; + if (ptrNumArrays != NULL) + *ptrNumArrays = numArrays; + if (ptrNumMemoryBytes != NULL) + *ptrNumMemoryBytes = numMemoryBytes; } /** -* @brief Load Kaldi ARK speech feature vector file -* @param fileName .ark file name -* @param arrayIndex number speech feature vector in the file -* @param ptrName reference to variable length name -* @param memory reference to speech feature vector to save -* @param ptrNumRows pointer to number of rows to read -* @param ptrNumColumns pointer to number of columns to read -* @param ptrNumBytesPerElement pointer to number bytes per element (size of float by default) -* @return none. -*/ -void LoadKaldiArkArray(const char *fileName, uint32_t arrayIndex, std::string &ptrName, std::vector &memory, - uint32_t *ptrNumRows, uint32_t *ptrNumColumns, uint32_t *ptrNumBytesPerElement) { + * @brief Load Kaldi ARK speech feature vector file + * @param fileName .ark file name + * @param arrayIndex number speech feature vector in the file + * @param ptrName reference to variable length name + * @param memory reference to speech feature vector to save + * @param ptrNumRows pointer to number of rows to read + * @param ptrNumColumns pointer to number of columns to read + * @param ptrNumBytesPerElement pointer to number bytes per element (size of float by default) + * @return none. + */ +void LoadKaldiArkArray(const char* fileName, uint32_t arrayIndex, std::string& ptrName, std::vector& memory, uint32_t* ptrNumRows, + uint32_t* ptrNumColumns, uint32_t* ptrNumBytesPerElement) { std::ifstream in_file(fileName, std::ios::binary); if (in_file.good()) { uint32_t i = 0; @@ -143,24 +144,24 @@ void LoadKaldiArkArray(const char *fileName, uint32_t arrayIndex, std::string &p if (line.compare("BFM ") != 0) { break; } - in_file.read(reinterpret_cast(&numRows), sizeof(uint32_t)); // read number of rows - std::getline(in_file, line, '\4'); // read control-D - in_file.read(reinterpret_cast(&numCols), sizeof(uint32_t)); // read number of columns - in_file.seekg(numRows * numCols * sizeof(float), in_file.cur); // read data + in_file.read(reinterpret_cast(&numRows), sizeof(uint32_t)); // read number of rows + std::getline(in_file, line, '\4'); // read control-D + in_file.read(reinterpret_cast(&numCols), sizeof(uint32_t)); // read number of columns + in_file.seekg(numRows * numCols * sizeof(float), in_file.cur); // read data i++; } if (!in_file.eof()) { std::string line; - std::getline(in_file, ptrName, '\0'); // read variable length name followed by space and NUL - std::getline(in_file, line, '\4'); // read "BFM" followed by space and control-D + std::getline(in_file, ptrName, '\0'); // read variable length name followed by space and NUL + std::getline(in_file, line, '\4'); // read "BFM" followed by space and control-D if (line.compare("BFM ") != 0) { fprintf(stderr, "Cannot find array specifier in file %s in LoadKaldiArkArray()!\n", fileName); exit(-1); } - in_file.read(reinterpret_cast(ptrNumRows), sizeof(uint32_t)); // read number of rows - std::getline(in_file, line, '\4'); // read control-D - in_file.read(reinterpret_cast(ptrNumColumns), sizeof(uint32_t)); // read number of columns - in_file.read(reinterpret_cast(&memory.front()), + in_file.read(reinterpret_cast(ptrNumRows), sizeof(uint32_t)); // read number of rows + std::getline(in_file, line, '\4'); // read control-D + in_file.read(reinterpret_cast(ptrNumColumns), sizeof(uint32_t)); // read number of columns + in_file.read(reinterpret_cast(&memory.front()), *ptrNumRows * *ptrNumColumns * sizeof(float)); // read array data } in_file.close(); @@ -173,21 +174,16 @@ void LoadKaldiArkArray(const char *fileName, uint32_t arrayIndex, std::string &p } /** -* @brief Save Kaldi ARK speech feature vector file -* @param fileName .ark file name -* @param shouldAppend bool flag to rewrite or add to the end of file -* @param name reference to variable length name -* @param ptrMemory pointer to speech feature vector to save -* @param numRows number of rows -* @param numColumns number of columns -* @return none. -*/ -void SaveKaldiArkArray(const char *fileName, - bool shouldAppend, - std::string name, - void *ptrMemory, - uint32_t numRows, - uint32_t numColumns) { + * @brief Save Kaldi ARK speech feature vector file + * @param fileName .ark file name + * @param shouldAppend bool flag to rewrite or add to the end of file + * @param name reference to variable length name + * @param ptrMemory pointer to speech feature vector to save + * @param numRows number of rows + * @param numColumns number of columns + * @return none. + */ +void SaveKaldiArkArray(const char* fileName, bool shouldAppend, std::string name, void* ptrMemory, uint32_t numRows, uint32_t numColumns) { std::ios_base::openmode mode = std::ios::binary; if (shouldAppend) { mode |= std::ios::app; @@ -198,10 +194,10 @@ void SaveKaldiArkArray(const char *fileName, out_file.write("\0", 1); out_file.write("BFM ", 4); out_file.write("\4", 1); - out_file.write(reinterpret_cast(&numRows), sizeof(uint32_t)); + out_file.write(reinterpret_cast(&numRows), sizeof(uint32_t)); out_file.write("\4", 1); - out_file.write(reinterpret_cast(&numColumns), sizeof(uint32_t)); - out_file.write(reinterpret_cast(ptrMemory), numRows * numColumns * sizeof(float)); + out_file.write(reinterpret_cast(&numColumns), sizeof(uint32_t)); + out_file.write(reinterpret_cast(ptrMemory), numRows * numColumns * sizeof(float)); out_file.close(); } else { throw std::runtime_error(std::string("Failed to open %s for writing in SaveKaldiArkArray()!\n") + fileName); @@ -209,14 +205,14 @@ void SaveKaldiArkArray(const char *fileName, } /** -* @brief Get scale factor for quantization -* @param ptrFloatMemory pointer to float memory with speech feature vector -* @param targetMax max scale factor -* @param numElements number of elements in speech feature vector -* @return scale factor -*/ -float ScaleFactorForQuantization(void *ptrFloatMemory, float targetMax, uint32_t numElements) { - float *ptrFloatFeat = reinterpret_cast(ptrFloatMemory); + * @brief Get scale factor for quantization + * @param ptrFloatMemory pointer to float memory with speech feature vector + * @param targetMax max scale factor + * @param numElements number of elements in speech feature vector + * @return scale factor + */ +float ScaleFactorForQuantization(void* ptrFloatMemory, float targetMax, uint32_t numElements) { + float* ptrFloatFeat = reinterpret_cast(ptrFloatMemory); float max = 0.0; float scaleFactor; @@ -236,11 +232,11 @@ float ScaleFactorForQuantization(void *ptrFloatMemory, float targetMax, uint32_t } /** -* @brief Clean score error -* @param error pointer to score error struct -* @return none. -*/ -void ClearScoreError(score_error_t *error) { + * @brief Clean score error + * @param error pointer to score error struct + * @return none. + */ +void ClearScoreError(score_error_t* error) { error->numScores = 0; error->numErrors = 0; error->maxError = 0.0; @@ -254,12 +250,12 @@ void ClearScoreError(score_error_t *error) { } /** -* @brief Update total score error -* @param error pointer to score error struct -* @param totalError pointer to total score error struct -* @return none. -*/ -void UpdateScoreError(score_error_t *error, score_error_t *totalError) { + * @brief Update total score error + * @param error pointer to score error struct + * @param totalError pointer to total score error struct + * @return none. + */ +void UpdateScoreError(score_error_t* error, score_error_t* totalError) { totalError->numErrors += error->numErrors; totalError->numScores += error->numScores; totalError->sumRmsError += error->rmsError; @@ -276,25 +272,21 @@ void UpdateScoreError(score_error_t *error, score_error_t *totalError) { } /** -* @brief Compare score errors, array should be the same length -* @param ptrScoreArray - pointer to score error struct array -* @param ptrRefScoreArray - pointer to score error struct array to compare -* @param scoreError - pointer to score error struct to save a new error -* @param numRows - number rows in score error arrays -* @param numColumns - number columns in score error arrays -* @return none. -*/ -void CompareScores(float *ptrScoreArray, - void *ptrRefScoreArray, - score_error_t *scoreError, - uint32_t numRows, - uint32_t numColumns) { + * @brief Compare score errors, array should be the same length + * @param ptrScoreArray - pointer to score error struct array + * @param ptrRefScoreArray - pointer to score error struct array to compare + * @param scoreError - pointer to score error struct to save a new error + * @param numRows - number rows in score error arrays + * @param numColumns - number columns in score error arrays + * @return none. + */ +void CompareScores(float* ptrScoreArray, void* ptrRefScoreArray, score_error_t* scoreError, uint32_t numRows, uint32_t numColumns) { uint32_t numErrors = 0; ClearScoreError(scoreError); - float *A = ptrScoreArray; - float *B = reinterpret_cast(ptrRefScoreArray); + float* A = ptrScoreArray; + float* B = reinterpret_cast(ptrRefScoreArray); for (uint32_t i = 0; i < numRows; i++) { for (uint32_t j = 0; j < numColumns; j++) { float score = A[i * numColumns + j]; @@ -325,44 +317,42 @@ void CompareScores(float *ptrScoreArray, } /** -* @brief Get total stdev error -* @param error pointer to score error struct -* @return error -*/ + * @brief Get total stdev error + * @param error pointer to score error struct + * @return error + */ float StdDevError(score_error_t error) { - return (sqrt(error.sumSquaredError / error.numScores - - (error.sumError / error.numScores) * (error.sumError / error.numScores))); + return (sqrt(error.sumSquaredError / error.numScores - (error.sumError / error.numScores) * (error.sumError / error.numScores))); } #if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64) -#ifdef _WIN32 -#include -#include -#else + #ifdef _WIN32 + #include + #include + #else -#include + #include -#endif + #endif -inline void native_cpuid(unsigned int *eax, unsigned int *ebx, - unsigned int *ecx, unsigned int *edx) { +inline void native_cpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx, unsigned int* edx) { size_t level = *eax; -#ifdef _WIN32 + #ifdef _WIN32 int regs[4] = {static_cast(*eax), static_cast(*ebx), static_cast(*ecx), static_cast(*edx)}; __cpuid(regs, level); *eax = static_cast(regs[0]); *ebx = static_cast(regs[1]); *ecx = static_cast(regs[2]); *edx = static_cast(regs[3]); -#else + #else __get_cpuid(level, eax, ebx, ecx, edx); -#endif + #endif } /** -* @brief Get GNA module frequency -* @return GNA module frequency in MHz -*/ + * @brief Get GNA module frequency + * @return GNA module frequency in MHz + */ float getGnaFrequencyMHz() { uint32_t eax = 1; uint32_t ebx = 0; @@ -390,14 +380,14 @@ float getGnaFrequencyMHz() { if (family == sixth_family) { switch (model) { - case cannon_lake_model: - case ice_lake_model: - case next_model: - return 400; - case gemini_lake_model: - return 200; - default: - return 1; + case cannon_lake_model: + case ice_lake_model: + case next_model: + return 400; + case gemini_lake_model: + return 200; + default: + return 1; } } else { // counters not supported and we returns just default value @@ -408,41 +398,34 @@ float getGnaFrequencyMHz() { #endif // if not ARM /** -* @brief Print a report on the statistical score error -* @param totalError reference to a total score error struct -* @param framesNum number of frames in utterance -* @param stream output stream -* @return none. -*/ -void printReferenceCompareResults(score_error_t const &totalError, - size_t framesNum, - std::ostream &stream) { - stream << " max error: " << - totalError.maxError << std::endl; - stream << " avg error: " << - totalError.sumError / totalError.numScores << std::endl; - stream << " avg rms error: " << - totalError.sumRmsError / framesNum << std::endl; - stream << " stdev error: " << - StdDevError(totalError) << std::endl << std::endl; + * @brief Print a report on the statistical score error + * @param totalError reference to a total score error struct + * @param framesNum number of frames in utterance + * @param stream output stream + * @return none. + */ +void printReferenceCompareResults(score_error_t const& totalError, size_t framesNum, std::ostream& stream) { + stream << " max error: " << totalError.maxError << std::endl; + stream << " avg error: " << totalError.sumError / totalError.numScores << std::endl; + stream << " avg rms error: " << totalError.sumRmsError / framesNum << std::endl; + stream << " stdev error: " << StdDevError(totalError) << std::endl << std::endl; stream << std::endl; } /** -* @brief Print a report on the performance counts -* @param utterancePerfMap reference to a map to store performance counters -* @param callsNum frame index -* @param stream output stream -* @param fullDeviceName full device name string -* @return none. -*/ -void printPerformanceCounters(std::map const &utterancePerfMap, - size_t callsNum, - std::ostream &stream, std::string fullDeviceName) { + * @brief Print a report on the performance counts + * @param utterancePerfMap reference to a map to store performance counters + * @param callsNum frame index + * @param stream output stream + * @param fullDeviceName full device name string + * @return none. + */ +void printPerformanceCounters(std::map const& utterancePerfMap, size_t callsNum, std::ostream& stream, + std::string fullDeviceName) { #if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64) stream << std::endl << "Performance counts:" << std::endl; - stream << std::setw(10) << std::right << "" << "Counter descriptions"; + stream << std::setw(10) << std::right << "" + << "Counter descriptions"; stream << std::setw(22) << "Utt scoring time"; stream << std::setw(18) << "Avg infer time"; stream << std::endl; @@ -451,8 +434,8 @@ void printPerformanceCounters(std::map(it.second.realTime_uSec); float call_units = current_units / callsNum; // if GNA HW counters @@ -473,38 +456,37 @@ void printPerformanceCounters(std::map &perfCounters) { + * @brief Get performance counts + * @param request reference to infer request + * @param perfCounters reference to a map to save performance counters + * @return none. + */ +void getPerformanceCounters(InferenceEngine::InferRequest& request, std::map& perfCounters) { auto retPerfCounters = request.GetPerformanceCounts(); - for (const auto &pair : retPerfCounters) { + for (const auto& pair : retPerfCounters) { perfCounters[pair.first] = pair.second; } } /** -* @brief Summarize performance counts -* @param perfCounters reference to a map to get performance counters -* @param totalPerfCounters reference to a map to save total performance counters -* @return none. -*/ -void sumPerformanceCounters(std::map const &perfCounters, - std::map &totalPerfCounters) { - for (const auto &pair : perfCounters) { + * @brief Summarize performance counts + * @param perfCounters reference to a map to get performance counters + * @param totalPerfCounters reference to a map to save total performance counters + * @return none. + */ +void sumPerformanceCounters(std::map const& perfCounters, + std::map& totalPerfCounters) { + for (const auto& pair : perfCounters) { totalPerfCounters[pair.first].realTime_uSec += pair.second.realTime_uSec; } } /** -* @brief Parse scale factors -* @param str reference to user-specified input scale factor for quantization, can be separated by comma -* @return vector scale factors -*/ + * @brief Parse scale factors + * @param str reference to user-specified input scale factor for quantization, can be separated by comma + * @return vector scale factors + */ std::vector ParseScaleFactors(const std::string& str) { std::vector scaleFactorInput; @@ -513,10 +495,9 @@ std::vector ParseScaleFactors(const std::string& str) { std::istringstream stream(str); int i = 0; while (getline(stream, outStr, ',')) { - auto floatScaleFactor = std::stof(outStr); + auto floatScaleFactor = std::stof(outStr); if (floatScaleFactor <= 0.0f) { - throw std::logic_error("Scale factor for input #" + std::to_string(i) - + " (counting from zero) is out of range (must be positive)."); + throw std::logic_error("Scale factor for input #" + std::to_string(i) + " (counting from zero) is out of range (must be positive)."); } scaleFactorInput.push_back(outStr); i++; @@ -528,10 +509,10 @@ std::vector ParseScaleFactors(const std::string& str) { } /** -* @brief Parse string of file names separated by comma to save it to vector of file names -* @param str file names separated by comma -* @return vector of file names -*/ + * @brief Parse string of file names separated by comma to save it to vector of file names + * @param str file names separated by comma + * @return vector of file names + */ std::vector ConvertStrToVector(std::string str) { std::vector blobName; if (!str.empty()) { @@ -547,12 +528,12 @@ std::vector ConvertStrToVector(std::string str) { } /** -* @brief Checks input arguments -* @param argc number of args -* @param argv list of input arguments -* @return bool status true(Success) or false(Fail) -*/ -bool ParseAndCheckCommandLine(int argc, char *argv[]) { + * @brief Checks input arguments + * @param argc number of args + * @param argv list of input arguments + * @return bool status true(Success) or false(Fail) + */ +bool ParseAndCheckCommandLine(int argc, char* argv[]) { slog::info << "Parsing input parameters" << slog::endl; gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true); @@ -582,27 +563,25 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { throw std::logic_error("Only one of -m and -rg is allowed."); } - std::vector supportedDevices = { - "CPU", - "GPU", - "GNA_AUTO", - "GNA_HW", - "GNA_SW_EXACT", - "GNA_SW", - "GNA_SW_FP32", - "HETERO:GNA,CPU", - "HETERO:GNA_HW,CPU", - "HETERO:GNA_SW_EXACT,CPU", - "HETERO:GNA_SW,CPU", - "HETERO:GNA_SW_FP32,CPU", - "MYRIAD" - }; + std::vector supportedDevices = {"CPU", + "GPU", + "GNA_AUTO", + "GNA_HW", + "GNA_SW_EXACT", + "GNA_SW", + "GNA_SW_FP32", + "HETERO:GNA,CPU", + "HETERO:GNA_HW,CPU", + "HETERO:GNA_SW_EXACT,CPU", + "HETERO:GNA_SW,CPU", + "HETERO:GNA_SW_FP32,CPU", + "MYRIAD"}; if (std::find(supportedDevices.begin(), supportedDevices.end(), FLAGS_d) == supportedDevices.end()) { throw std::logic_error("Specified device is not supported."); } - uint32_t batchSize = (uint32_t) FLAGS_bs; + uint32_t batchSize = (uint32_t)FLAGS_bs; if ((batchSize < 1) || (batchSize > 8)) { throw std::logic_error("Batch size out of range (1..8)."); } @@ -644,7 +623,7 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { * @file speech_sample/main.cpp * @example speech_sample/main.cpp */ -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { try { // ------------------------------ Get Inference Engine version ------------------------------------------------------ slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << slog::endl; @@ -692,13 +671,14 @@ int main(int argc, char *argv[]) { } // ------------------------------ Get Available Devices ------------------------------------------------------ - auto isFeature = [&](const std::string xFeature) { return FLAGS_d.find(xFeature) != std::string::npos; }; + auto isFeature = [&](const std::string xFeature) { + return FLAGS_d.find(xFeature) != std::string::npos; + }; bool useGna = isFeature("GNA"); bool useHetero = isFeature("HETERO"); - std::string deviceStr = - useHetero && useGna ? "HETERO:GNA,CPU" : FLAGS_d.substr(0, (FLAGS_d.find("_"))); + std::string deviceStr = useHetero && useGna ? "HETERO:GNA,CPU" : FLAGS_d.substr(0, (FLAGS_d.find("_"))); slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(deviceStr) << std::endl; @@ -707,7 +687,7 @@ int main(int argc, char *argv[]) { // --------------------------- Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format slog::info << "Loading network files:" << slog::endl << FLAGS_m << slog::endl; - uint32_t batchSize = (FLAGS_cw_r > 0 || FLAGS_cw_l > 0) ? 1 : (uint32_t) FLAGS_bs; + uint32_t batchSize = (FLAGS_cw_r > 0 || FLAGS_cw_l > 0) ? 1 : (uint32_t)FLAGS_bs; if (!FLAGS_m.empty()) { /** Read network model **/ @@ -718,8 +698,7 @@ int main(int argc, char *argv[]) { // --------------------------- Set batch size --------------------------------------------------- /** Set batch size. Unlike in imaging, batching in time (rather than space) is done for speech recognition. **/ network.setBatchSize(batchSize); - slog::info << "Batch size is " << std::to_string(network.getBatchSize()) - << slog::endl; + slog::info << "Batch size is " << std::to_string(network.getBatchSize()) << slog::endl; } // ----------------------------------------------------------------------------------------------------- @@ -729,10 +708,8 @@ int main(int argc, char *argv[]) { std::map gnaPluginConfig; std::map genericPluginConfig; if (useGna) { - std::string gnaDevice = - useHetero ? FLAGS_d.substr(FLAGS_d.find("GNA"), FLAGS_d.find(",") - FLAGS_d.find("GNA")) : FLAGS_d; - gnaPluginConfig[GNAConfigParams::KEY_GNA_DEVICE_MODE] = - gnaDevice.find("_") == std::string::npos ? "GNA_AUTO" : gnaDevice; + std::string gnaDevice = useHetero ? FLAGS_d.substr(FLAGS_d.find("GNA"), FLAGS_d.find(",") - FLAGS_d.find("GNA")) : FLAGS_d; + gnaPluginConfig[GNAConfigParams::KEY_GNA_DEVICE_MODE] = gnaDevice.find("_") == std::string::npos ? "GNA_AUTO" : gnaDevice; } if (FLAGS_pc) { @@ -741,14 +718,12 @@ int main(int argc, char *argv[]) { if (FLAGS_q.compare("user") == 0) { if (!FLAGS_rg.empty()) { - slog::warn << "Custom scale factor will be ignored - using scale factor from provided imported gna model: " - << FLAGS_rg << slog::endl; + slog::warn << "Custom scale factor will be ignored - using scale factor from provided imported gna model: " << FLAGS_rg << slog::endl; } else { auto scaleFactorInput = ParseScaleFactors(FLAGS_sf); if (numInputArkFiles != scaleFactorInput.size()) { - std::string errMessage("Incorrect command line for multiple inputs: " - + std::to_string(scaleFactorInput.size()) + " scale factors provided for " - + std::to_string(numInputArkFiles) + " input files."); + std::string errMessage("Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) + + " scale factors provided for " + std::to_string(numInputArkFiles) + " input files."); throw std::logic_error(errMessage); } @@ -770,17 +745,9 @@ int main(int argc, char *argv[]) { uint32_t numArrays(0), numBytes(0), numFrames(0), numFrameElements(0), numBytesPerElement(0); GetKaldiArkInfo(inputArkName, 0, &numArrays, &numBytes); ptrFeatures.resize(numBytes); - LoadKaldiArkArray(inputArkName, - 0, - name, - ptrFeatures, - &numFrames, - &numFrameElements, - &numBytesPerElement); - auto floatScaleFactor = - ScaleFactorForQuantization(ptrFeatures.data(), MAX_VAL_2B_FEAT, numFrames * numFrameElements); - slog::info << "Using scale factor of " << floatScaleFactor << " calculated from first utterance." - << slog::endl; + LoadKaldiArkArray(inputArkName, 0, name, ptrFeatures, &numFrames, &numFrameElements, &numBytesPerElement); + auto floatScaleFactor = ScaleFactorForQuantization(ptrFeatures.data(), MAX_VAL_2B_FEAT, numFrames * numFrameElements); + slog::info << "Using scale factor of " << floatScaleFactor << " calculated from first utterance." << slog::endl; std::string scaleFactorConfigKey = GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(i); gnaPluginConfig[scaleFactorConfigKey] = std::to_string(floatScaleFactor); } @@ -819,13 +786,12 @@ int main(int argc, char *argv[]) { for (const auto& outBlobName : output_names) { int pos_layer = outBlobName.rfind(":"); if (pos_layer == -1) { - throw std::logic_error(std::string("Output ") + std::string(outBlobName) - + std::string(" doesn't have a port")); + throw std::logic_error(std::string("Output ") + std::string(outBlobName) + std::string(" doesn't have a port")); } outputs.push_back(outBlobName.substr(0, pos_layer)); try { ports.push_back(std::stoi(outBlobName.substr(pos_layer + 1))); - } catch (const std::exception &) { + } catch (const std::exception&) { throw std::logic_error("Ports should have integer type"); } } @@ -883,8 +849,8 @@ int main(int argc, char *argv[]) { std::vector inputNameBlobs = ConvertStrToVector(FLAGS_iname); if (inputNameBlobs.size() != cInputInfo.size()) { std::string errMessage(std::string("Number of network inputs ( ") + std::to_string(cInputInfo.size()) + - " ) is not equal to the number of inputs entered in the -iname argument ( " + - std::to_string(inputNameBlobs.size()) + " )."); + " ) is not equal to the number of inputs entered in the -iname argument ( " + std::to_string(inputNameBlobs.size()) + + " )."); throw std::logic_error(errMessage); } for (const auto& input : inputNameBlobs) { @@ -905,7 +871,7 @@ int main(int argc, char *argv[]) { inputInfo = network.getInputsInfo(); } /** Configure input precision if model is loaded from IR **/ - for (auto &item : inputInfo) { + for (auto& item : inputInfo) { Precision inputPrecision = Precision::FP32; // specify Precision::I16 to provide quantized inputs item.second->setPrecision(inputPrecision); } @@ -933,7 +899,7 @@ int main(int argc, char *argv[]) { } } - for (auto &item : outputInfo) { + for (auto& item : outputInfo) { DataPtr outData = item.second; if (!outData) { throw std::logic_error("output data pointer is not valid"); @@ -972,7 +938,7 @@ int main(int argc, char *argv[]) { ptrUtterances.resize(inputArkFiles.size()); // initialize memory state before starting - for (auto &&state : inferRequests.begin()->inferRequest.QueryState()) { + for (auto&& state : inferRequests.begin()->inferRequest.QueryState()) { state.Reset(); } @@ -983,10 +949,9 @@ int main(int argc, char *argv[]) { uint32_t numFrames(0), n(0); std::vector numFrameElementsInput; - uint32_t numFramesReference(0), numFrameElementsReference(0), numBytesPerElementReference(0), - numBytesReferenceScoreThisUtterance(0); + uint32_t numFramesReference(0), numFrameElementsReference(0), numBytesPerElementReference(0), numBytesReferenceScoreThisUtterance(0); auto dims = outputs.empty() ? cOutputInfo.rbegin()->second->getDims() : cOutputInfo[outputs[next_output]]->getDims(); - const auto numScoresPerFrame = std::accumulate(std::begin(dims), std::end(dims), size_t{1}, std::multiplies()); + const auto numScoresPerFrame = std::accumulate(std::begin(dims), std::end(dims), size_t {1}, std::multiplies()); slog::info << "Number scores per frame : " << numScoresPerFrame << slog::endl; @@ -998,19 +963,13 @@ int main(int argc, char *argv[]) { uint32_t currentNumFrames(0), currentNumFrameElementsInput(0), currentNumBytesPerElementInput(0); GetKaldiArkInfo(inputArkFilename, utteranceIndex, &n, &numBytesThisUtterance[i]); ptrUtterance.resize(numBytesThisUtterance[i]); - LoadKaldiArkArray(inputArkFilename, - utteranceIndex, - uttName, - ptrUtterance, - ¤tNumFrames, - ¤tNumFrameElementsInput, + LoadKaldiArkArray(inputArkFilename, utteranceIndex, uttName, ptrUtterance, ¤tNumFrames, ¤tNumFrameElementsInput, ¤tNumBytesPerElementInput); if (numFrames == 0) { numFrames = currentNumFrames; } else if (numFrames != currentNumFrames) { - std::string errMessage( - "Number of frames in ark files is different: " + std::to_string(numFrames) + - " and " + std::to_string(currentNumFrames)); + std::string errMessage("Number of frames in ark files is different: " + std::to_string(numFrames) + " and " + + std::to_string(currentNumFrames)); throw std::logic_error(errMessage); } @@ -1019,10 +978,9 @@ int main(int argc, char *argv[]) { } int i = 0; - for (auto &ptrInputBlob : ptrInputBlobs) { + for (auto& ptrInputBlob : ptrInputBlobs) { if (ptrInputBlob->size() != numFrameElementsInput[i++] * batchSize) { - throw std::logic_error("network input size(" + std::to_string(ptrInputBlob->size()) + - ") mismatch to ark file size (" + + throw std::logic_error("network input size(" + std::to_string(ptrInputBlob->size()) + ") mismatch to ark file size (" + std::to_string(numFrameElementsInput[i - 1] * batchSize) + ")"); } } @@ -1033,13 +991,8 @@ int main(int argc, char *argv[]) { std::string refUtteranceName; GetKaldiArkInfo(reference_name_files[next_output].c_str(), utteranceIndex, &n, &numBytesReferenceScoreThisUtterance); ptrReferenceScores.resize(numBytesReferenceScoreThisUtterance); - LoadKaldiArkArray(reference_name_files[next_output].c_str(), - utteranceIndex, - refUtteranceName, - ptrReferenceScores, - &numFramesReference, - &numFrameElementsReference, - &numBytesPerElementReference); + LoadKaldiArkArray(reference_name_files[next_output].c_str(), utteranceIndex, refUtteranceName, ptrReferenceScores, &numFramesReference, + &numFrameElementsReference, &numBytesPerElementReference); } double totalTime = 0.0; @@ -1049,8 +1002,8 @@ int main(int argc, char *argv[]) { ClearScoreError(&totalError); totalError.threshold = frameError.threshold = MAX_SCORE_DIFFERENCE; auto outputFrame = &ptrScores.front(); - std::vector inputFrame; - for (auto &ut : ptrUtterances) { + std::vector inputFrame; + for (auto& ut : ptrUtterances) { inputFrame.push_back(&ut.front()); } @@ -1059,47 +1012,44 @@ int main(int argc, char *argv[]) { size_t frameIndex = 0; uint32_t numFramesArkFile = numFrames; numFrames += FLAGS_cw_l + FLAGS_cw_r; - uint32_t numFramesThisBatch{batchSize}; + uint32_t numFramesThisBatch {batchSize}; auto t0 = Time::now(); auto t1 = t0; while (frameIndex <= numFrames) { if (frameIndex == numFrames) { - if (std::find_if(inferRequests.begin(), - inferRequests.end(), - [&](InferRequestStruct x) { return (x.frameIndex != -1); }) == - inferRequests.end()) { + if (std::find_if(inferRequests.begin(), inferRequests.end(), [&](InferRequestStruct x) { + return (x.frameIndex != -1); + }) == inferRequests.end()) { break; } } bool inferRequestFetched = false; /** Start inference loop **/ - for (auto &inferRequest : inferRequests) { + for (auto& inferRequest : inferRequests) { if (frameIndex == numFrames) { numFramesThisBatch = 1; } else { - numFramesThisBatch = (numFrames - frameIndex < batchSize) ? (numFrames - frameIndex) - : batchSize; + numFramesThisBatch = (numFrames - frameIndex < batchSize) ? (numFrames - frameIndex) : batchSize; } /* waits until inference result becomes available */ if (inferRequest.frameIndex != -1) { - StatusCode code = inferRequest.inferRequest.Wait( - InferenceEngine::InferRequest::WaitMode::RESULT_READY); + StatusCode code = inferRequest.inferRequest.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); if (code != StatusCode::OK) { - if (!useHetero) continue; - if (code != StatusCode::INFER_NOT_STARTED) continue; + if (!useHetero) + continue; + if (code != StatusCode::INFER_NOT_STARTED) + continue; } // --------------------------- Step 8. Process output part 1 ------------------------------------------------------- ConstOutputsDataMap newOutputInfo; if (inferRequest.frameIndex >= 0) { if (!FLAGS_o.empty()) { /* Prepare output data for save to file in future */ - outputFrame = - &ptrScores.front() + - numScoresPerFrame * sizeof(float) * (inferRequest.frameIndex); + outputFrame = &ptrScores.front() + numScoresPerFrame * sizeof(float) * (inferRequest.frameIndex); if (!outputs.empty()) { newOutputInfo[outputs[next_output]] = cOutputInfo[outputs[next_output]]; } else { @@ -1114,11 +1064,8 @@ int main(int argc, char *argv[]) { } // locked memory holder should be alive all time while access to its buffer happens auto moutputHolder = moutput->rmap(); - auto byteSize = - numScoresPerFrame * sizeof(float); - std::memcpy(outputFrame, - moutputHolder.as(), - byteSize); + auto byteSize = numScoresPerFrame * sizeof(float); + std::memcpy(outputFrame, moutputHolder.as(), byteSize); } if (!FLAGS_r.empty()) { /** Compare output data with reference scores **/ @@ -1135,13 +1082,9 @@ int main(int argc, char *argv[]) { } // locked memory holder should be alive all time while access to its buffer happens auto moutputHolder = moutput->rmap(); - CompareScores(moutputHolder.as(), - &ptrReferenceScores[inferRequest.frameIndex * - numFrameElementsReference * - numBytesPerElementReference], - &frameError, - inferRequest.numFramesThisBatch, - numFrameElementsReference); + CompareScores(moutputHolder.as(), + &ptrReferenceScores[inferRequest.frameIndex * numFrameElementsReference * numBytesPerElementReference], + &frameError, inferRequest.numFramesThisBatch, numFrameElementsReference); UpdateScoreError(&frameError, &totalError); } if (FLAGS_pc) { @@ -1162,7 +1105,7 @@ int main(int argc, char *argv[]) { // --------------------------- Step 6. Prepare input -------------------------------------------------------- ptrInputBlobs.clear(); if (FLAGS_iname.empty()) { - for (auto &input : cInputInfo) { + for (auto& input : cInputInfo) { ptrInputBlobs.push_back(inferRequest.inferRequest.GetBlob(input.first)); } } else { @@ -1181,17 +1124,14 @@ int main(int argc, char *argv[]) { for (size_t i = 0; i < numInputArkFiles; ++i) { MemoryBlob::Ptr minput = as(ptrInputBlobs[i]); if (!minput) { - std::string errMessage("We expect ptrInputBlobs[" + std::to_string(i) + - "] to be inherited from MemoryBlob, " + - "but in fact we were not able to cast input blob to MemoryBlob"); + std::string errMessage("We expect ptrInputBlobs[" + std::to_string(i) + "] to be inherited from MemoryBlob, " + + "but in fact we were not able to cast input blob to MemoryBlob"); throw std::logic_error(errMessage); } // locked memory holder should be alive all time while access to its buffer happens auto minputHolder = minput->wmap(); - std::memcpy(minputHolder.as(), - inputFrame[i], - minput->byteSize()); + std::memcpy(minputHolder.as(), inputFrame[i], minput->byteSize()); } // ----------------------------------------------------------------------------------------------------- @@ -1208,9 +1148,8 @@ int main(int argc, char *argv[]) { if (idx > 0 && idx < static_cast(numFramesArkFile)) { inputFrame[j] += sizeof(float) * numFrameElementsInput[j] * numFramesThisBatch; } else if (idx >= static_cast(numFramesArkFile)) { - inputFrame[j] = &ptrUtterances[j].front() + - (numFramesArkFile - 1) * sizeof(float) * numFrameElementsInput[j] * - numFramesThisBatch; + inputFrame[j] = + &ptrUtterances[j].front() + (numFramesArkFile - 1) * sizeof(float) * numFrameElementsInput[j] * numFramesThisBatch; } else if (idx <= 0) { inputFrame[j] = &ptrUtterances[j].front(); } @@ -1233,7 +1172,7 @@ int main(int argc, char *argv[]) { totalTime += d.count(); // resetting state between utterances - for (auto &&state : inferRequests.begin()->inferRequest.QueryState()) { + for (auto&& state : inferRequests.begin()->inferRequest.QueryState()) { state.Reset(); } // ----------------------------------------------------------------------------------------------------- @@ -1243,17 +1182,13 @@ int main(int argc, char *argv[]) { if (!FLAGS_o.empty()) { /* Save output data to file */ bool shouldAppend = (utteranceIndex == 0) ? false : true; - SaveKaldiArkArray(output_name_files[next_output].c_str(), shouldAppend, uttName, &ptrScores.front(), - numFramesArkFile, numScoresPerFrame); + SaveKaldiArkArray(output_name_files[next_output].c_str(), shouldAppend, uttName, &ptrScores.front(), numFramesArkFile, numScoresPerFrame); } /** Show performance results **/ - std::cout << "Total time in Infer (HW and SW):\t" << totalTime << " ms" - << std::endl; - std::cout << "Frames in utterance:\t\t\t" << numFrames << " frames" - << std::endl; - std::cout << "Average Infer time per frame:\t\t" << totalTime / static_cast(numFrames) << " ms" - << std::endl; + std::cout << "Total time in Infer (HW and SW):\t" << totalTime << " ms" << std::endl; + std::cout << "Frames in utterance:\t\t\t" << numFrames << " frames" << std::endl; + std::cout << "Average Infer time per frame:\t\t" << totalTime / static_cast(numFrames) << " ms" << std::endl; if (FLAGS_pc) { // print performance results printPerformanceCounters(utterancePerfMap, frameIndex, std::cout, getFullDeviceName(ie, FLAGS_d)); @@ -1267,12 +1202,10 @@ int main(int argc, char *argv[]) { } } // ----------------------------------------------------------------------------------------------------- - } - catch (const std::exception &error) { + } catch (const std::exception& error) { slog::err << error.what() << slog::endl; return 1; - } - catch (...) { + } catch (...) { slog::err << "Unknown/internal exception happened" << slog::endl; return 1; } diff --git a/inference-engine/samples/speech_sample/speech_sample.hpp b/inference-engine/samples/speech_sample/speech_sample.hpp index 5dd71f1e354..a2c7f3aee6c 100644 --- a/inference-engine/samples/speech_sample/speech_sample.hpp +++ b/inference-engine/samples/speech_sample/speech_sample.hpp @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /// @brief message for help argument static const char help_message[] = "Print a usage message."; @@ -19,17 +20,19 @@ static const char input_message[] = "Required. Paths to .ark files. Example of u static const char model_message[] = "Required. Path to an .xml file with a trained model (required if -rg is missing)."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify a target device to infer on. CPU, GPU, MYRIAD, GNA_AUTO, GNA_HW, GNA_SW_FP32, " +static const char target_device_message[] = "Optional. Specify a target device to infer on. CPU, GPU, MYRIAD, GNA_AUTO, GNA_HW, " + "GNA_SW_FP32, " "GNA_SW_EXACT and HETERO with combination of GNA as the primary device and CPU" - " as a secondary (e.g. HETERO:GNA,CPU) are supported. The list of available devices is shown below. " + " as a secondary (e.g. HETERO:GNA,CPU) are supported. The list of available devices is shown " + "below. " "The sample will look for a suitable plugin for device specified."; /// @brief message for performance counters static const char performance_counter_message[] = "Optional. Enables per-layer performance report."; /// @brief message for user library argument -static const char custom_cpu_library_message[] = "Required for CPU plugin custom layers." \ -"Absolute path to a shared library with the kernels implementations."; +static const char custom_cpu_library_message[] = "Required for CPU plugin custom layers." + "Absolute path to a shared library with the kernels implementations."; /// @brief message for score output argument static const char output_message[] = "Optional. Output file name to save ark scores."; @@ -58,37 +61,38 @@ static const char quantization_bits_message[] = "Optional. Weight bits for quant /// @brief message for scale factor argument static const char scale_factor_message[] = "Optional. User-specified input scale factor for quantization (use with -q user). " - "If the network contains multiple inputs, provide scale factors by separating them with commas."; + "If the network contains multiple inputs, provide scale factors by separating them with " + "commas."; /// @brief message for batch size argument static const char batch_size_message[] = "Optional. Batch size 1-8 (default 1)"; /// @brief message for #threads for CPU inference -static const char infer_num_threads_message[] = "Optional. Number of threads to use for concurrent async" \ -" inference requests on the GNA."; +static const char infer_num_threads_message[] = "Optional. Number of threads to use for concurrent async" + " inference requests on the GNA."; /// @brief message for left context window argument -static const char context_window_message_l[] = "Optional. Number of frames for left context windows (default is 0). " \ +static const char context_window_message_l[] = "Optional. Number of frames for left context windows (default is 0). " "Works only with context window networks." " If you use the cw_l or cw_r flag, then batch size and nthreads arguments are ignored."; /// @brief message for right context window argument -static const char context_window_message_r[] = "Optional. Number of frames for right context windows (default is 0). " \ +static const char context_window_message_r[] = "Optional. Number of frames for right context windows (default is 0). " "Works only with context window networks." " If you use the cw_r or cw_l flag, then batch size and nthreads arguments are ignored."; /// @brief message for output layer names -static const char output_layer_names_message[] = "Optional. Layer names for output blobs. " \ - "The names are separated with \",\" " \ - "Example: Output1:port,Output2:port "; +static const char output_layer_names_message[] = "Optional. Layer names for output blobs. " + "The names are separated with \",\" " + "Example: Output1:port,Output2:port "; /// @brief message for inputs layer names -static const char input_layer_names_message[] = "Optional. Layer names for input blobs. " \ - "The names are separated with \",\" " \ - "Example: Input1,Input2 "; +static const char input_layer_names_message[] = "Optional. Layer names for input blobs. " + "The names are separated with \",\" " + "Example: Input1,Input2 "; /// @brief message for PWL max error percent -static const char pwl_max_error_percent_message[] = "Optional. The maximum percent of error for PWL function." \ +static const char pwl_max_error_percent_message[] = "Optional. The maximum percent of error for PWL function." "The value must be in <0, 100> range. The default value is 1.0."; /// \brief Define flag for showing help message
@@ -191,4 +195,3 @@ static void showUsage() { std::cout << " -iname \"\" " << input_layer_names_message << std::endl; std::cout << " -pwl_me \"\" " << pwl_max_error_percent_message << std::endl; } - diff --git a/inference-engine/samples/style_transfer_sample/main.cpp b/inference-engine/samples/style_transfer_sample/main.cpp index 6af07797b3c..2ffa42fce4a 100644 --- a/inference-engine/samples/style_transfer_sample/main.cpp +++ b/inference-engine/samples/style_transfer_sample/main.cpp @@ -2,28 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include - #include -#include +#include +#include +#include #include #include -#include +#include +#include #include "style_transfer_sample.h" using namespace InferenceEngine; /** -* @brief Checks input args -* @param argc number of args -* @param argv list of input arguments -* @return bool status true(Success) or false(Fail) -*/ -bool ParseAndCheckCommandLine(int argc, char *argv[]) { + * @brief Checks input args + * @param argc number of args + * @param argv list of input arguments + * @return bool status true(Success) or false(Fail) + */ +bool ParseAndCheckCommandLine(int argc, char* argv[]) { slog::info << "Parsing input parameters" << slog::endl; gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true); @@ -51,11 +50,13 @@ bool ParseAndCheckCommandLine(int argc, char *argv[]) { * @file style_transfer_sample/main.cpp * @example style_transfer_sample/main.cpp */ -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { try { - // ------------------------------ Get Inference Engine version ------------------------------------------------------ + // ------------------------------ Get Inference Engine version + // ------------------------------------------------------ slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << slog::endl; - // ------------------------------ Parsing and validation of input arguments --------------------------------- + // ------------------------------ Parsing and validation of input arguments + // --------------------------------- if (!ParseAndCheckCommandLine(argc, argv)) { return 0; } @@ -63,46 +64,55 @@ int main(int argc, char *argv[]) { /** This vector stores paths to the processed images **/ std::vector imageNames; parseInputFilesArguments(imageNames); - if (imageNames.empty()) throw std::logic_error("No suitable images were found"); + if (imageNames.empty()) + throw std::logic_error("No suitable images were found"); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 1. Initialize inference engine core ------------------------------------- + // --------------------------- Step 1. Initialize inference engine core + // ------------------------------------- slog::info << "Loading Inference Engine" << slog::endl; Core ie; - // ------------------------------ Get Available Devices ------------------------------------------------------ + // ------------------------------ Get Available Devices + // ------------------------------------------------------ slog::info << "Device info: " << slog::endl; std::cout << ie.GetVersions(FLAGS_d) << std::endl; if (!FLAGS_l.empty()) { - // Custom CPU extension is loaded as a shared library and passed as a pointer to base extension + // Custom CPU extension is loaded as a shared library and passed as a + // pointer to base extension IExtensionPtr extension_ptr = std::make_shared(FLAGS_l); ie.AddExtension(extension_ptr); slog::info << "Custom Extension loaded: " << FLAGS_l << slog::endl; } if (!FLAGS_c.empty() && (FLAGS_d == "GPU" || FLAGS_d == "MYRIAD" || FLAGS_d == "HDDL")) { - // Config for device plugin custom extension is loaded from an .xml description + // Config for device plugin custom extension is loaded from an .xml + // description ie.SetConfig({{PluginConfigParams::KEY_CONFIG_FILE, FLAGS_c}}, "GPU"); slog::info << "Config for " << FLAGS_d << " device plugin custom extension loaded: " << FLAGS_c << slog::endl; } // ----------------------------------------------------------------------------------------------------- - // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format + // Step 2. Read a model in OpenVINO Intermediate Representation (.xml and + // .bin files) or ONNX (.onnx file) format slog::info << "Loading network files:" << slog::endl << FLAGS_m << slog::endl; /** Read network model **/ CNNNetwork network = ie.ReadNetwork(FLAGS_m); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 3. Configure input & output --------------------------------------------- + // --------------------------- Step 3. Configure input & output + // --------------------------------------------- - // --------------------------- Prepare input blobs ----------------------------------------------------- + // --------------------------- Prepare input blobs + // ----------------------------------------------------- slog::info << "Preparing input blobs" << slog::endl; /** Taking information about all topology inputs **/ InputsDataMap inputInfo(network.getInputsInfo()); - if (inputInfo.size() != 1) throw std::logic_error("Sample supports topologies only with 1 input"); + if (inputInfo.size() != 1) + throw std::logic_error("Sample supports topologies only with 1 input"); auto inputInfoItem = *inputInfo.begin(); /** Iterate over all the input blobs **/ @@ -113,37 +123,38 @@ int main(int argc, char *argv[]) { inputInfoItem.second->setPrecision(Precision::FP32); /** Collect images data ptrs **/ - for (auto & i : imageNames) { + for (auto& i : imageNames) { FormatReader::ReaderPtr reader(i.c_str()); if (reader.get() == nullptr) { slog::warn << "Image " + i + " cannot be read!" << slog::endl; continue; } /** Store image data **/ - std::shared_ptr data(reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], - inputInfoItem.second->getTensorDesc().getDims()[2])); + std::shared_ptr data( + reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], inputInfoItem.second->getTensorDesc().getDims()[2])); if (data.get() != nullptr) { imagesData.push_back(data); } } - if (imagesData.empty()) throw std::logic_error("Valid input images were not found!"); + if (imagesData.empty()) + throw std::logic_error("Valid input images were not found!"); /** Setting batch size using image count **/ network.setBatchSize(imagesData.size()); slog::info << "Batch size is " << std::to_string(network.getBatchSize()) << slog::endl; - // ------------------------------ Prepare output blobs ------------------------------------------------- + // ------------------------------ Prepare output blobs + // ------------------------------------------------- slog::info << "Preparing output blobs" << slog::endl; OutputsDataMap outputInfo(network.getOutputsInfo()); // BlobMap outputBlobs; std::string firstOutputName; - const float meanValues[] = {static_cast(FLAGS_mean_val_r), - static_cast(FLAGS_mean_val_g), + const float meanValues[] = {static_cast(FLAGS_mean_val_r), static_cast(FLAGS_mean_val_g), static_cast(FLAGS_mean_val_b)}; - for (auto & item : outputInfo) { + for (auto& item : outputInfo) { if (firstOutputName.empty()) { firstOutputName = item.first; } @@ -156,33 +167,38 @@ int main(int argc, char *argv[]) { } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 4. Loading model to the device ------------------------------------------ + // --------------------------- Step 4. Loading model to the device + // ------------------------------------------ slog::info << "Loading model to the device" << slog::endl; ExecutableNetwork executable_network = ie.LoadNetwork(network, FLAGS_d); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 5. Create infer request ------------------------------------------------- + // --------------------------- Step 5. Create infer request + // ------------------------------------------------- slog::info << "Create infer request" << slog::endl; InferRequest infer_request = executable_network.CreateInferRequest(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 6. Prepare input -------------------------------------------------------- + // --------------------------- Step 6. Prepare input + // -------------------------------------------------------- /** Iterate over all the input blobs **/ - for (const auto & item : inputInfo) { + for (const auto& item : inputInfo) { MemoryBlob::Ptr minput = as(infer_request.GetBlob(item.first)); if (!minput) { - slog::err << "We expect input blob to be inherited from MemoryBlob, " << - "but by fact we were not able to cast it to MemoryBlob" << slog::endl; + slog::err << "We expect input blob to be inherited from MemoryBlob, " + << "but by fact we were not able to cast it to MemoryBlob" << slog::endl; return 1; } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its + // buffer happens auto ilmHolder = minput->wmap(); - /** Filling input tensor with images. First b channel, then g and r channels **/ + /** Filling input tensor with images. First b channel, then g and r + * channels **/ size_t num_channels = minput->getTensorDesc().getDims()[1]; size_t image_size = minput->getTensorDesc().getDims()[3] * minput->getTensorDesc().getDims()[2]; - auto data = ilmHolder.as::value_type *>(); + auto data = ilmHolder.as::value_type*>(); if (data == nullptr) throw std::runtime_error("Input blob has not allocated buffer"); /** Iterate over all input images **/ @@ -191,29 +207,33 @@ int main(int argc, char *argv[]) { for (size_t pid = 0; pid < image_size; pid++) { /** Iterate over all channels **/ for (size_t ch = 0; ch < num_channels; ++ch) { - /** [images stride + channels stride + pixel id ] all in bytes **/ - data[image_id * image_size * num_channels + ch * image_size + pid ] = - imagesData.at(image_id).get()[pid*num_channels + ch] - meanValues[ch]; + /** [images stride + channels stride + pixel id ] all in + * bytes **/ + data[image_id * image_size * num_channels + ch * image_size + pid] = + imagesData.at(image_id).get()[pid * num_channels + ch] - meanValues[ch]; } } } } // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 7. Do inference --------------------------------------------------------- + // --------------------------- Step 7. Do inference + // --------------------------------------------------------- slog::info << "Start inference" << slog::endl; infer_request.Infer(); // ----------------------------------------------------------------------------------------------------- - // --------------------------- Step 8. Process output ------------------------------------------------------- + // --------------------------- Step 8. Process output + // ------------------------------------------------------- MemoryBlob::CPtr moutput = as(infer_request.GetBlob(firstOutputName)); if (!moutput) { throw std::logic_error("We expect output to be inherited from MemoryBlob, " "but by fact we were not able to cast it to MemoryBlob"); } - // locked memory holder should be alive all time while access to its buffer happens + // locked memory holder should be alive all time while access to its buffer + // happens auto lmoHolder = moutput->rmap(); - const auto output_data = lmoHolder.as::value_type *>(); + const auto output_data = lmoHolder.as::value_type*>(); size_t num_images = moutput->getTensorDesc().getDims()[0]; size_t num_channels = moutput->getTensorDesc().getDims()[1]; @@ -228,25 +248,28 @@ int main(int argc, char *argv[]) { for (size_t n = 0; n < num_images; n++) { for (size_t i = 0; i < nPixels; i++) { - data_img[i * num_channels] = static_cast(output_data[i + n * nPixels * num_channels] + - meanValues[0]); - data_img[i * num_channels + 1] = static_cast( - output_data[(i + nPixels) + n * nPixels * num_channels] + meanValues[1]); - data_img[i * num_channels + 2] = static_cast( - output_data[(i + 2 * nPixels) + n * nPixels * num_channels] + meanValues[2]); + data_img[i * num_channels] = static_cast(output_data[i + n * nPixels * num_channels] + meanValues[0]); + data_img[i * num_channels + 1] = static_cast(output_data[(i + nPixels) + n * nPixels * num_channels] + meanValues[1]); + data_img[i * num_channels + 2] = static_cast(output_data[(i + 2 * nPixels) + n * nPixels * num_channels] + meanValues[2]); float temp = data_img[i * num_channels]; data_img[i * num_channels] = data_img[i * num_channels + 2]; data_img[i * num_channels + 2] = temp; - if (data_img[i * num_channels] < 0) data_img[i * num_channels] = 0; - if (data_img[i * num_channels] > 255) data_img[i * num_channels] = 255; + if (data_img[i * num_channels] < 0) + data_img[i * num_channels] = 0; + if (data_img[i * num_channels] > 255) + data_img[i * num_channels] = 255; - if (data_img[i * num_channels + 1] < 0) data_img[i * num_channels + 1] = 0; - if (data_img[i * num_channels + 1] > 255) data_img[i * num_channels + 1] = 255; + if (data_img[i * num_channels + 1] < 0) + data_img[i * num_channels + 1] = 0; + if (data_img[i * num_channels + 1] > 255) + data_img[i * num_channels + 1] = 255; - if (data_img[i * num_channels + 2] < 0) data_img[i * num_channels + 2] = 0; - if (data_img[i * num_channels + 2] > 255) data_img[i * num_channels + 2] = 255; + if (data_img[i * num_channels + 2] < 0) + data_img[i * num_channels + 2] = 0; + if (data_img[i * num_channels + 2] > 255) + data_img[i * num_channels + 2] = 255; } std::string out_img_name = std::string("out" + std::to_string(n + 1) + ".bmp"); std::ofstream outFile; @@ -264,18 +287,18 @@ int main(int argc, char *argv[]) { } } // ----------------------------------------------------------------------------------------------------- - } - catch (const std::exception &error) { + } catch (const std::exception& error) { slog::err << error.what() << slog::endl; return 1; - } - catch (...) { + } catch (...) { slog::err << "Unknown/internal exception happened" << slog::endl; return 1; } slog::info << "Execution successful" << slog::endl; - slog::info << slog::endl << "This sample is an API example, for any performance measurements " - "please use the dedicated benchmark_app tool" << slog::endl; + slog::info << slog::endl + << "This sample is an API example, for any performance measurements " + "please use the dedicated benchmark_app tool" + << slog::endl; return 0; } diff --git a/inference-engine/samples/style_transfer_sample/style_transfer_sample.h b/inference-engine/samples/style_transfer_sample/style_transfer_sample.h index fbc69efcb55..c787e0470b5 100644 --- a/inference-engine/samples/style_transfer_sample/style_transfer_sample.h +++ b/inference-engine/samples/style_transfer_sample/style_transfer_sample.h @@ -4,10 +4,11 @@ #pragma once +#include + +#include #include #include -#include -#include /// @brief message for help argument static const char help_message[] = "Print a usage message."; @@ -16,26 +17,26 @@ static const char help_message[] = "Print a usage message."; static const char image_message[] = "Path to a folder with images or paths to image files."; /// @brief message for model argument -static const char model_message[] = "Required. Path to an .xml file with a trained model.";\ +static const char model_message[] = "Required. Path to an .xml file with a trained model."; /// @brief message for assigning cnn calculation to device -static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown below). " \ - "Default value is CPU. Use \"-d HETERO:\" format to specify HETERO plugin. " \ +static const char target_device_message[] = "Optional. Specify the target device to infer on (the list of available devices is shown " + "below). " + "Default value is CPU. Use \"-d HETERO:\" format to specify " + "HETERO plugin. " "Sample will look for a suitable plugin for device specified"; /// @brief message for plugin custom kernels desc -static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. "\ -"Absolute path to the .xml config file with the kernels descriptions."; +static const char custom_plugin_cfg_message[] = "Required for GPU, MYRIAD, HDDL custom kernels. " + "Absolute path to the .xml config file with the kernels descriptions."; /// @brief message for user library argument -static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " \ -"Absolute path to a shared library with the kernels implementations."; +static const char custom_ex_library_message[] = "Required for CPU plugin custom layers. " + "Absolute path to a shared library with the kernels implementations."; /// @brief message for mean values arguments static const char preprocess_data_message[] = "Mean values. Required if the model needs mean values for preprocessing and postprocessing."; - - /// @brief Define flag for showing help message
DEFINE_bool(h, false, help_message); @@ -67,8 +68,8 @@ DEFINE_double(mean_val_g, 0.0, preprocess_data_message); DEFINE_double(mean_val_b, 0.0, preprocess_data_message); /** -* @brief This function show a help message -*/ + * @brief This function show a help message + */ static void showUsage() { std::cout << std::endl; std::cout << "style_transfer_sample [OPTION]" << std::endl; From 13e91c3ce28a873857321809fe9405001c1031a5 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Thu, 22 Apr 2021 15:26:21 +0300 Subject: [PATCH 50/78] [IE TESTS] Report update (#5346) * Init * fix op versions --- .../layer_tests_summary/summarize.py | 368 ++++++++++-------- .../template/report_template.html | 25 +- 2 files changed, 226 insertions(+), 167 deletions(-) diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index 5f84a57cfe0..08e4f42acc1 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -1,116 +1,122 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import xml.etree.ElementTree as ET -from jinja2 import Environment, FileSystemLoader import argparse import os +import logging +import xml.etree.ElementTree as ET + +from jinja2 import Environment, FileSystemLoader from datetime import datetime -parser = argparse.ArgumentParser() +logging.basicConfig() +logger = logging.getLogger('Summarize') +logger.setLevel(logging.INFO) -xml_help = """ -Paths to xml summary files from layer tests. -In case of entries intersection, results will -be merged basing on timestamp - entry from latest -report is be kept. -""" -out_help = "Path where to save html report" -parser.add_argument("--xml", help=xml_help, nargs="*", required=True) -parser.add_argument("--out", help=out_help, default="") -args = parser.parse_args() +def parse_arguments(): + parser = argparse.ArgumentParser() -verified_operations = [ - 'Abs-0', - 'Acos-0', - 'Add-1', - 'Asin-0', - 'Assign-6', - 'AvgPool-1', - 'BatchNormInference-5', - 'BinaryConvolution-1', - 'Broadcast-1', - 'Broadcast-3', - 'Bucketize-3', - 'CTCGreedyDecoder-0', - 'CTCGreedyDecoderSeqLen-6', - 'Concat-0', - 'ConvertLike-1', - 'Convolution-1', - 'DeformableConvolution-1', - 'DetectionOutput-0', - 'Divide-1', - 'ExperimentalDetectronDetectionOutput-6', - 'ExperimentalDetectronGenerateProposalsSingleImage-6', - 'ExperimentalDetectronPriorGridGenerator-6', - 'ExperimentalDetectronROIFeatureExtractor-6', - 'ExperimentalDetectronTopKROIs-6', + xml_help = """ + Paths to xml summary files from layer tests. + In case of entries intersection, results will + be merged basing on timestamp - entry from latest + report is be kept. + """ + out_help = "Path where to save html report" + + parser.add_argument("--xml", help=xml_help, nargs="*", required=True) + parser.add_argument("--out", help=out_help, default="") + + return parser.parse_args() + + +def get_verified_op_list(): + return [ + 'Abs-1', + 'Acos-1', + 'Add-1', + 'Asin-1', + 'Assign-6', + 'AvgPool-1', + 'BatchNormInference-5', + 'BinaryConvolution-1', + 'Broadcast-1', + 'Broadcast-3', + 'Bucketize-3', + 'CTCGreedyDecoder-1', + 'CTCGreedyDecoderSeqLen-6', + 'Concat-1', + 'ConvertLike-1', + 'Convolution-1', + 'DeformableConvolution-1', + 'DetectionOutput-1', + 'Divide-1', + 'ExperimentalDetectronDetectionOutput-6', + 'ExperimentalDetectronGenerateProposalsSingleImage-6', + 'ExperimentalDetectronPriorGridGenerator-6', + 'ExperimentalDetectronROIFeatureExtractor-6', + 'ExperimentalDetectronTopKROIs-6', 'FloorMod-1' - 'GRUSequence-5', - 'Gather-1', - 'GatherElements-6', - 'GatherND-5', - 'Gelu-7', - 'GroupConvolution-1', - 'GroupConvolutionBackpropData-1', - 'GRUSequence-5', - 'HSigmoid-5', - 'HSwish-4', - 'HardSigmoid-0', - 'Interpolate-4', - 'LRN-0', - 'LSTMCell-4', - 'LSTMSequence-5', - 'LogSoftmax-5', - 'Loop-5', - 'MVN-6', + 'GRUSequence-5', + 'Gather-1', + 'GatherElements-6', + 'GatherND-5', + 'Gelu-7', + 'GroupConvolution-1', + 'GroupConvolutionBackpropData-1', + 'GRUSequence-5', + 'HSigmoid-5', + 'HSwish-4', + 'HardSigmoid-1', + 'Interpolate-4', + 'LRN-1', + 'LSTMCell-4', + 'LSTMSequence-5', + 'LogSoftmax-5', + 'Loop-5', + 'MVN-6', 'Maximum-1', - 'MaxPool-1', - 'Mish-4', - 'Multiply-1', - 'NonMaxSuppression-4', - 'NonMaxSuppression-5', - 'PSROIPooling-0', - 'Proposal-0', - 'Proposal-4', - 'RNNSequence-4', - 'ROIAlign-3', - 'ROIPooling-0', - 'Range-0', - 'Range-4', - 'ReadValue-6', - 'ReduceL1-4', - 'ReduceL2-4', - 'ReduceMean-1', - 'RegionYOLO-0', - 'Relu-0', - 'ReorgYOLO-0', - 'GRUSequence-5', - 'Round-5', - 'ScatterNDUpdate-3', - 'ShapeOf-0', - 'ShapeOf-3', - 'Sigmoid-0', - 'Sin-0', - 'SoftPlus-4', - 'Softmax-1', - 'Split-1', - 'StridedSlice-1', - 'Substract-1', - 'Swish-4', - 'Tile-0', - 'TopK-1', - 'TopK-3' -] - -pass_rate_avg = dict() -general_pass_rate = dict() -general_test_count = dict() -general_passed_tests = dict() + 'MaxPool-1', + 'Mish-4', + 'Multiply-1', + 'NonMaxSuppression-4', + 'NonMaxSuppression-5', + 'PSROIPooling-1', + 'Proposal-1', + 'Proposal-4', + 'RNNSequence-5', + 'ROIAlign-3', + 'ROIPooling-2', + 'Range-1', + 'Range-4', + 'ReadValue-6', + 'ReduceL1-4', + 'ReduceL2-4', + 'ReduceMean-1', + 'RegionYOLO-1', + 'Relu-1', + 'ReorgYOLO-2', + 'Round-5', + 'ScatterNDUpdate-4', + 'ShapeOf-1', + 'ShapeOf-3', + 'Sigmoid-1', + 'Sin-1', + 'SoftPlus-4', + 'Softmax-1', + 'Split-1', + 'StridedSlice-1', + 'Subtract-1', + 'Swish-4', + 'Tile-1', + 'TopK-1', + 'TopK-3' + ] def update_passrates(results: ET.SubElement): + logger.info("Update passrates in the final report is started") for device in results: for op in device: passed_tests = 0 @@ -123,87 +129,129 @@ def update_passrates(results: ET.SubElement): total_tests += int(op.attrib.get(attrib)) passrate = float(passed_tests * 100 / total_tests) if passed_tests < total_tests else 100 op.set("passrate", str(round(passrate, 1))) + logger.info("Update passrates in the final report is completed") -def merge_xmls(xmls: list): - if len(xmls) == 1: - return xmls[0] +def merge_xmls(xml_paths: list): + logger.info("Merging XML files is started") + summary = ET.Element("report") - summary.set("timestamp", xmls[0].attrib["timestamp"]) - results = ET.SubElement(summary, "results") + timestamp = None + summary_results = ET.SubElement(summary, "results") ops_list = ET.SubElement(summary, "ops_list") - for xml in xmls: - for op in xml.find("ops_list"): + for xml_path in xml_paths: + try: + xml_root = ET.parse(xml_path).getroot() + logger.info(f'Info from {xml_path} is adding to the final summary') + except ET.ParseError: + logger.error(f'Error parsing {xml_path}') + + if timestamp is None or timestamp < xml_root.attrib["timestamp"]: + logger.info(f'Timestamp is updated from {timestamp} to {xml_root.attrib["timestamp"]}') + timestamp = xml_root.attrib["timestamp"] + + for op in xml_root.find("ops_list"): if ops_list.find(op.tag) is None: ET.SubElement(ops_list, op.tag) - for device in xml.find("results"): - device_results = results.find(device.tag) + + for device in xml_root.find("results"): + device_results = summary_results.find(device.tag) if device_results is None: - results.append(device) + summary_results.append(device) else: - for entry in device: - res_summary = device_results.find(entry.tag) - if res_summary is not None: + for op_result in device: + current_op_res = device_results.find(op_result.tag) + if current_op_res is not None: # workaround for unsaved reports total_tests_count_xml, total_tests_count_summary = (0, 0) - for attr_name in device_results.find(entry.tag).attrib: + for attr_name in device_results.find(op_result.tag).attrib: if attr_name == "passrate": continue - else: - total_tests_count_xml += int(entry.attrib.get(attr_name)) - total_tests_count_summary += int(res_summary.attrib.get(attr_name)) - if total_tests_count_xml > total_tests_count_summary: - for attr_name in device_results.find(entry.tag).attrib: + total_tests_count_xml += int(op_result.attrib.get(attr_name)) + total_tests_count_summary += int(current_op_res.attrib.get(attr_name)) + if total_tests_count_xml > total_tests_count_xml: + logger.warning(f'Test counter is different in {op_result.tag} for {device.tag}'\ + f'({total_tests_count_xml} vs {total_tests_count_xml})') + for attr_name in device_results.find(op_result.tag).attrib: if attr_name == "passrate": continue - else: - xml_value = int(entry.attrib.get(attr_name)) - device_results.find(res_summary.tag).set(attr_name, str(xml_value)) + xml_value = int(op_result.attrib.get(attr_name)) + device_results.find(current_op_res.tag).set(attr_name, str(xml_value)) else: - device_results.append(entry) - update_passrates(results) + device_results.append(op_result) + update_passrates(summary_results) + summary.set("timestamp", timestamp) + logger.info("Merging XML files is competed") return summary -xmls = [] -for xml in args.xml: - try: - xmls.append(ET.parse(xml).getroot()) - except ET.ParseError: - print("Error parsing", xml) -root = merge_xmls(xmls) -timestamp = root.attrib["timestamp"] -ops = [] -for op in root.find("ops_list"): - ops.append(op.tag) -ordered_ops = sorted(ops) -results = {} -for device in root.find("results"): - results[device.tag] = {op.tag: op.attrib for op in device} - pass_rate_avg[device.tag] = 0 - general_test_count[device.tag] = 0 - general_passed_tests[device.tag] = 0 - for op in results[device.tag]: - pass_rate = round(float(results[device.tag][op]["passrate"]), 1) - results[device.tag][op]["passrate"] = pass_rate - pass_rate_avg[device.tag] += pass_rate - general_test_count[device.tag] += (int(results[device.tag][op]["passed"]) + int(results[device.tag][op]["failed"]) + - int(results[device.tag][op]["crashed"]) + int(results[device.tag][op]["skipped"])) - general_passed_tests[device.tag] += int(results[device.tag][op]["passed"]) - pass_rate_avg[device.tag] /= len(results[device.tag]) - pass_rate_avg[device.tag] = round(float(pass_rate_avg[device.tag]), 1) - general_pass_rate[device.tag] = general_passed_tests[device.tag] * 100 / general_test_count[device.tag] - general_pass_rate[device.tag] = round(float(general_pass_rate[device.tag]), 1) +def collect_statistic(root: ET.Element): + logger.info("Statistic collecting is started") + trusted_ops = dict() + pass_rate_avg = dict() + general_pass_rate = dict() + general_test_count = dict() + general_passed_tests = dict() -devices = results.keys() + results = dict() + for device in root.find("results"): + results[device.tag] = {op.tag: op.attrib for op in device} -file_loader = FileSystemLoader('template') -env = Environment(loader=file_loader) -template = env.get_template('report_template.html') + pass_rate_avg[device.tag] = 0 + general_test_count[device.tag] = 0 + general_passed_tests[device.tag] = 0 + trusted_ops[device.tag] = 0 + for op in results[device.tag]: + pass_rate = round(float(results[device.tag][op]["passrate"]), 1) + results[device.tag][op]["passrate"] = pass_rate -res = template.render(ordered_ops=ordered_ops, devices=devices, results=results, timestamp=timestamp, - general_pass_rate=general_pass_rate, pass_rate_avg=pass_rate_avg, - verified_operations=verified_operations) + pass_rate_avg[device.tag] += pass_rate + if pass_rate == 100.: + trusted_ops[device.tag] += 1 + general_test_count[device.tag] += ( + int(results[device.tag][op]["passed"]) + int(results[device.tag][op]["failed"]) + + int(results[device.tag][op]["crashed"]) + int(results[device.tag][op]["skipped"])) + general_passed_tests[device.tag] += int(results[device.tag][op]["passed"]) -with open(os.path.join(args.out, "report.html"), "w") as f: - f.write(res) + pass_rate_avg[device.tag] /= len(results[device.tag]) + pass_rate_avg[device.tag] = round(float(pass_rate_avg[device.tag]), 1) + general_pass_rate[device.tag] = general_passed_tests[device.tag] * 100 / general_test_count[device.tag] + general_pass_rate[device.tag] = round(float(general_pass_rate[device.tag]), 1) + + devices = results.keys() + logger.info("Statistic collecting is completed") + return devices, results, general_pass_rate, pass_rate_avg, general_test_count, trusted_ops + + +def create_summary(summary_root: ET.Element, output_folder: str): + device_list, results, general_pass_rate, pass_rate_avg, general_test_count, trusted_ops = \ + collect_statistic(summary_root) + + timestamp = summary_root.attrib["timestamp"] + + op_list = list() + for op in summary_root.find("ops_list"): + op_list.append(op.tag) + op_list = sorted(op_list) + + file_loader = FileSystemLoader('template') + env = Environment(loader=file_loader) + template = env.get_template('report_template.html') + + verified_operations = get_verified_op_list() + + res_summary = template.render(ordered_ops=op_list, devices=device_list, results=results, timestamp=timestamp, + general_pass_rate=general_pass_rate, pass_rate_avg=pass_rate_avg, + verified_operations=verified_operations, trusted_ops=trusted_ops, + general_test_count=general_test_count) + + report_path = os.path.join(output_folder, "report.html") + with open(report_path, "w") as f: + logger.info(f'Final report is saved to {report_path}') + f.write(res_summary) + + +if __name__ == "__main__": + args = parse_arguments() + summary_root = merge_xmls(args.xml) + create_summary(summary_root, args.out) diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/report_template.html b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/report_template.html index f31a987f6c8..6eeeba16b1a 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/report_template.html +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/report_template.html @@ -32,17 +32,17 @@ - - + + - + - +
Not verified Ngraph references"Operation_name"-"opset_version" Not verified Ngraph references
Collected statistic infoCollected statistic info
- + {% for d in devices -%} @@ -56,7 +56,18 @@ {% for d in devices -%} {% endfor %} - + + + + {% for d in devices -%} + + {% endfor %} + + + + {% for d in devices -%} + + {% endfor %} @@ -77,7 +88,7 @@ {% if op in verified_operations -%} {% else -%} - + {% endif -%} {% for d in devices -%} {% if op in results[d] -%} From 311416ac024ff419591cab8adf62e1f08c47dd0b Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Thu, 22 Apr 2021 14:31:06 +0200 Subject: [PATCH 51/78] [Spec] Transpose op spec update (#5215) * Update detailed description * Update input info * Output description update * Update math formula * Change T1, T2 to T and T_AXIS * Update input description * Update output description * Update examples * Simplify output description * Add missed comma --- docs/ops/movement/Transpose_1.md | 47 ++++++++------------------------ 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/docs/ops/movement/Transpose_1.md b/docs/ops/movement/Transpose_1.md index 877f6018151..604dc3258d3 100644 --- a/docs/ops/movement/Transpose_1.md +++ b/docs/ops/movement/Transpose_1.md @@ -6,30 +6,26 @@ **Short description**: *Transpose* operation reorders the input tensor dimensions. -**Attributes**: +**Detailed description**: *Transpose* operation reorders the input tensor dimensions. Source indexes and destination indexes are bound by the formula: +\f[output[i(order[0]), i(order[1]), ..., i(order[N-1])] = input[i(0), i(1), ..., i(N-1)]\\ \quad \textrm{where} \quad i(j) \quad\textrm{is in the range} \quad [0, (input.shape[j]-1)]\f] -No attributes available. + +**Attributes**: *Transpose* operation has no attributes. **Inputs**: -* **1**: "arg" - the tensor to be transposed. A tensor of type T1. **Required.** -* **2**: "input_order" - the permutation to apply to the axes of the input shape. Must be a vector of element T2 type, with shape [n], where n is the rank of "arg". The tensor's value must contain every integer in the range [0,n-1]. If an empty list is specified [] then the axes will be inverted. A tensor of type T2. **Required.** +* **1**: `arg` - the tensor to be transposed. A tensor of type `T` and arbitrary shape. **Required.** +* **2**: `input_order` - the permutation to apply to the axes of the first input shape. A 1D tensor of `n` elements `T_AXIS` type and shape `[n]`, where `n` is the rank of the first input or `0`. The tensor's value must contain every integer in the range `[0, n-1]`, but if an empty tensor is specified (shape `[0]`), then the axes will be inverted. **Required.** **Outputs**: -* **1**: A tensor with shape and type matching 1st tensor. +* **1**: A tensor of type `T` and transposed shape according to the rules specified above. **Types** -* *T1*: arbitrary supported type. -* *T2*: any integer type. +* *T*: any supported type. +* *T_AXIS*: any integer type. -**Detailed description**: - -*Transpose* operation reorders the input tensor dimensions. Source indexes and destination indexes are bound by the formula: -\f[ - output[i(order[0]), i(order[1]), ..., i(order[N-1])] = input[i(0), i(1), ..., i(N-1)], where i(j) in range 0..(input.shape[j]-1). -\f] **Examples** @@ -57,28 +53,7 @@ No attributes available. ``` -*Example 2: input_order in not specified* - -```xml - - - - 2 - 3 - 4 - - - - - 4 - 3 - 2 - - - -``` - -*Example 3: input_order = empty_list []* +*Example 2: input_order = empty 1D tensor of Shape[0] ```xml @@ -89,7 +64,7 @@ No attributes available. 4 - 0 + 0 From ed0b66f31d277ba39ead0a9d5e065d668b6e4895 Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Thu, 22 Apr 2021 15:51:35 +0300 Subject: [PATCH 52/78] Fix timeline report for MemCheck by querying target instead of current branch (#5350) --- tests/stress_tests/scripts/memcheck_upload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stress_tests/scripts/memcheck_upload.py b/tests/stress_tests/scripts/memcheck_upload.py index 75e7fbd2b8f..43b217a1275 100644 --- a/tests/stress_tests/scripts/memcheck_upload.py +++ b/tests/stress_tests/scripts/memcheck_upload.py @@ -67,7 +67,7 @@ def metadata_from_manifest(manifest): 'commit_sha': repo_trigger['revision'], 'commit_date': repo_trigger['commit_time'], 'repo_url': repo_trigger['url'], - 'target_branch': repo_trigger['branch'], + 'target_branch': repo_trigger['target_branch'], 'event_type': manifest['components'][PRODUCT_NAME]['build_event'].lower(), f'{PRODUCT_NAME}_version': manifest['components'][PRODUCT_NAME]['version'], } From f2f0fb36dafd6a2cb3b9f8482ef325ff8d7f6d0b Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Thu, 22 Apr 2021 16:19:16 +0300 Subject: [PATCH 53/78] [IE TESTS] Enable validation of template plugin in Conformance suite (#5345) * Init * Remove device dependency --- .../conformance/test_runner/include/conformance.hpp | 1 + .../conformance/test_runner/include/gflag_config.hpp | 3 +++ .../plugin/conformance/test_runner/src/core_config.cpp | 9 +++++++++ .../plugin/conformance/test_runner/src/main.cpp | 5 ++++- .../conformance/test_runner/src/read_ir/read_ir.cpp | 1 + 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/include/conformance.hpp b/inference-engine/tests/functional/plugin/conformance/test_runner/include/conformance.hpp index d7ac9207735..5069d8dfc90 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/include/conformance.hpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/include/conformance.hpp @@ -5,6 +5,7 @@ namespace ConformanceTests { extern const char* targetDevice; +extern const char* targetPluginName; extern std::vector IRFolderPaths; } // namespace ConformanceTests diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp b/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp index 68cefe44450..015ef61faf8 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/include/gflag_config.hpp @@ -17,6 +17,7 @@ static const char target_device_message[] = "Required. Specify the target device "Use \"-d HETERO:\" format to specify HETERO plugin. " "The application looks for a suitable plugin for the specified device."; static const char input_folders_message[] = "Required. Paths to the input folders with IRs. Delimiter is `,` symbol."; +static const char target_plugin_message[] = "Optional. Name of plugin library. The example is MKLDNNPlugin. Use only with unregistered in IE Core devices"; static const char output_folder_message[] = "Optional. Paths to the output folder to save report. Default value is \".\""; static const char report_unique_name_message[] = "Optional. Allow to save report with unique name (report_pid_timestamp.xml). " "Mutually exclusive with --extend_report. Default value is false"; @@ -25,6 +26,7 @@ static const char save_report_timeout_message[] = "Optional. Allow to try to sav DEFINE_bool(h, false, help_message); DEFINE_string(device, "CPU", target_device_message); +DEFINE_string(plugin_lib_name, "", target_plugin_message); DEFINE_string(input_folders, ".", input_folders_message); DEFINE_string(output_folder, ".", output_folder_message); DEFINE_uint32(save_report_timeout, 60, save_report_timeout_message); @@ -48,4 +50,5 @@ static void showUsage() { std::cout << " --device " << target_device_message << std::endl; std::cout << " --input_folders \"\" " << input_folders_message << std::endl; std::cout << " --output_folder \"\" " << output_folder_message << std::endl; + std::cout << " --plugin_lib_name " << output_folder_message << std::endl; } \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/core_config.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/core_config.cpp index e75091f571f..0a79478fc6f 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/core_config.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/core_config.cpp @@ -4,5 +4,14 @@ #include "functional_test_utils/core_config.hpp" +#include "conformance.hpp" + void CoreConfiguration(LayerTestsUtils::LayerTestsCommon* test) { + std::shared_ptr core = PluginCache::get().ie(); + auto availableDevices = core->GetAvailableDevices(); + std::string targetDevice = std::string(ConformanceTests::targetDevice); + if (std::find(availableDevices.begin(), availableDevices.end(), targetDevice) == availableDevices.end()) { + core->RegisterPlugin(ConformanceTests::targetPluginName, + ConformanceTests::targetDevice); + } } diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp index 3172d66a42c..0e35c605f87 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp @@ -49,8 +49,11 @@ int main(int argc, char* argv[]) { // ---------------------------Initialization of Gtest env ----------------------------------------------- ConformanceTests::targetDevice = FLAGS_device.c_str(); ConformanceTests::IRFolderPaths = CommonTestUtils::splitStringByDelimiter(FLAGS_input_folders); + if (!FLAGS_plugin_lib_name.empty()) { + ConformanceTests::targetPluginName = FLAGS_plugin_lib_name.c_str(); + } ::testing::InitGoogleTest(&argc, argv); ::testing::AddGlobalTestEnvironment(new LayerTestsUtils::TestEnvironment); - return RUN_ALL_TESTS();; + return RUN_ALL_TESTS(); } diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/read_ir/read_ir.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/read_ir/read_ir.cpp index a5f33b187da..e465970a77a 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/read_ir/read_ir.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/read_ir/read_ir.cpp @@ -11,6 +11,7 @@ using namespace LayerTestsDefinitions; const char* targetDevice = ""; std::vector IRFolderPaths = {}; +const char* targetPluginName = ""; namespace { INSTANTIATE_TEST_CASE_P(conformance, From e4d4eda31bf7f19a67fd77f05bcbe1caeffcf392 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Thu, 22 Apr 2021 16:53:53 +0300 Subject: [PATCH 54/78] [IE CONFORMANCE] Skipping tests on device (#5329) * Init * test * f * ddd * Extend --- .../conformance/test_runner/src/main.cpp | 15 +-- .../test_runner/src/skip_tests_config.cpp | 94 ++++++++++++++++++- 2 files changed, 97 insertions(+), 12 deletions(-) diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp index 0e35c605f87..d471e58ece3 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/main.cpp @@ -30,19 +30,12 @@ int main(int argc, char* argv[]) { return 0; } if (FLAGS_extend_report && FLAGS_report_unique_name) { - std::cout << "Using mutually exclusive arguments: --extend_report and --report_unique_name" << std::endl; - return -1; + throw std::runtime_error("Using mutually exclusive arguments: --extend_report and --report_unique_name"); } - if (!FLAGS_disable_test_config) { - FuncTestUtils::SkipTestsConfig::disable_tests_skipping = false; - } - if (FLAGS_extend_report) { - LayerTestsUtils::Summary::setExtendReport(true); - } - if (FLAGS_report_unique_name) { - LayerTestsUtils::Summary::setSaveReportWithUniqueName(true); - } + FuncTestUtils::SkipTestsConfig::disable_tests_skipping = FLAGS_disable_test_config; + LayerTestsUtils::Summary::setExtendReport(FLAGS_extend_report); + LayerTestsUtils::Summary::setSaveReportWithUniqueName(FLAGS_report_unique_name); LayerTestsUtils::Summary::setOutputFolder(FLAGS_output_folder); LayerTestsUtils::Summary::setSaveReportTimeout(FLAGS_save_report_timeout); diff --git a/inference-engine/tests/functional/plugin/conformance/test_runner/src/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/conformance/test_runner/src/skip_tests_config.cpp index 1d6dd6d3360..3372f2f3a43 100644 --- a/inference-engine/tests/functional/plugin/conformance/test_runner/src/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/conformance/test_runner/src/skip_tests_config.cpp @@ -5,8 +5,100 @@ #include #include +#include "common_test_utils/test_constants.hpp" + +#include "conformance.hpp" + #include "functional_test_utils/skip_tests_config.hpp" std::vector disabledTestPatterns() { - return {}; + std::vector skippedTestsRegExp; + std::string targetDevice = ConformanceTests::targetDevice; + if (targetDevice.find(CommonTestUtils::DEVICE_MYRIAD) != std::string::npos) { + std::vector myriadSkips{ + // TODO: Issue: 53061 + R"(.*ReduceMean_334003.*)", R"(.*ReduceMean_334702.*)", R"(.*Select_1172002.*)", R"(.*Select_1178458.*)", + R"(.*Divide_567867.*)", R"(.*Divide_1377278.*)", R"(.*Divide_1030260.*)", R"(.*Pad_274459.*)", R"(.*Pad_276201.*)", + R"(.*Pad_276193.*)", R"(.*Add_1070296.*)", R"(.*Add_284191.*)", R"(.*Add_1087636.*)", R"(.*VariadicSplit_614428.*)", + R"(.*VariadicSplit_642662.*)", R"(.*VariadicSplit_412430.*)", R"(.*VariadicSplit_475191.*)", R"(.*VariadicSplit_475203.*)", + R"(.*VariadicSplit_279359.*)", R"(.*VariadicSplit_31490.*)", R"(.*VariadicSplit_1444989.*)", R"(.*VariadicSplit_31499.*)", + R"(.*VariadicSplit_279373.*)", R"(.*VariadicSplit_279345.*)", R"(.*VariadicSplit_31508.*)", R"(.*VariadicSplit_535004.*)", + R"(.*VariadicSplit_148861.*)", R"(.*VariadicSplit_475199.*)", R"(.*VariadicSplit_412439.*)", R"(.*VariadicSplit_412448.*)", + R"(.*VariadicSplit_475175.*)", R"(.*VariadicSplit_427269.*)", R"(.*VariadicSplit_1070300.*)", R"(.*VariadicSplit_478455.*)", + R"(.*VariadicSplit_416024.*)", R"(.*VariadicSplit_478469.*)", R"(.*VariadicSplit_416006.*)", R"(.*VariadicSplit_35108.*)", + R"(.*VariadicSplit_478473.*)", R"(.*VariadicSplit_416015.*)", R"(.*VariadicSplit_280446.*)", R"(.*VariadicSplit_6686.*)", + R"(.*VariadicSplit_1087640.*)", R"(.*VariadicSplit_1443292.*)", R"(.*VariadicSplit_35099.*)", R"(.*VariadicSplit_280460.*)", + R"(.*VariadicSplit_35090.*)", R"(.*VariadicSplit_430827.*)", R"(.*VariadicSplit_478461.*)", R"(.*VariadicSplit_280432.*)", + R"(.*VariadicSplit_539066.*)", R"(.*VariadicSplit_149040.*)", R"(.*VariadicSplit_614761.*)", R"(.*VariadicSplit_629649.*)", + R"(.*Unsqueeze_65214.*)", R"(.*Unsqueeze_4838.*)", R"(.*Unsqueeze_6661.*)", R"(.*Multiply_65211.*)", R"(.*Multiply_4833.*)", + R"(.*Multiply_48331.*)", R"(.*Multiply_6656.*)", R"(.*Subtract_534968.*)", R"(.*Subtract_567907.*)", R"(.*Gather_21153.*)", + R"(.*Gather_302464.*)", R"(.*Gather_588814.*)", R"(.*Gather_588810.*)", R"(.*Gather_952843.*)", R"(.*Gather_588818.*)", + R"(.*Gather_588871.*)", R"(.*Gather_48276.*)", R"(.*Gather_1652589.*)", R"(.*Gather_535000.*)", R"(.*Gather_360953.*)", + R"(.*Gather_588867.*)", R"(.*Gather_48283.*)", R"(.*Gather_1311696.*)", R"(.*Gather_588796.*)", R"(.*Gather_4847.*)", + R"(.*Gather_4803.*)", R"(.*Gather_284209.*)", R"(.*Gather_4869.*)", R"(.*Gather_97426.*)", R"(.*Gather_360963.*)", R"(.*Gather_1570871.*)", + R"(.*Gather_513092.*)", R"(.*Gather_629616.*)", R"(.*Gather_48287.*)", R"(.*Gather_284215.*)", R"(.*Gather_48335.*)", R"(.*Gather_1444.*)", + R"(.*Gather_4810.*)", R"(.*Gather_1395.*)", R"(.*Gather_1653002.*)", R"(.*Gather_53520.*)", R"(.*Gather_567864.*)", R"(.*Gather_362776.*)", + R"(.*Gather_567856.*)", R"(.*Gather_567919.*)", R"(.*Gather_567830.*)", R"(.*Gather_567923.*)", R"(.*Gather_567860.*)", R"(.*Gather_539062.*)", + R"(.*Gather_1304430.*)", R"(.*Gather_938915.*)", R"(.*Gather_53527.*)", R"(.*Convert_284211.*)", R"(.*Convert_4830.*)", R"(.*Convert_567844.*)", + R"(.*Convert_6653.*)", R"(.*FakeQuantize_738613.*)", R"(.*FakeQuantize_738639.*)", R"(.*Split_65164.*)", R"(.*Split_274446.*)", + R"(.*Split_361038.*)", R"(.*Split_330570.*)", R"(.*Split_276188.*)", R"(.*Split_68625.*)", R"(.*Split_333279.*)", R"(.*Split_362843.*)", + R"(.*Split_68647.*)", R"(.*Floor_6658.*)", R"(.*TopK_1172093.*)", R"(.*TopK_1172038.*)", R"(.*TopK_1178526.*)", R"(.*TopK_515250.*)", + R"(.*TopK_1178477.*)", R"(.*Reshape_1105704.*)", R"(.*Reshape_1118646.*)", R"(.*Reshape_588858.*)", R"(.*Reshape_567910.*)", + // TODO: Crashes: Should be handled + R"(.*CTCGreedyDecoderSeqLen_271798.*)", R"(.*MVN_276196.*)", R"(.*MVN_274454.*)", + // hung + R"(.*Clamp_1178483.*)", + // lost results + R"(.*Add_1087636.*)", R"(.*Add_2868.*)", R"(.*Add_2979.*)", R"(.*Add_53543.*)", + }; + skippedTestsRegExp.insert(skippedTestsRegExp.end(), + std::make_move_iterator(myriadSkips.begin()), + std::make_move_iterator(myriadSkips.end())); + } + if (targetDevice.find(CommonTestUtils::DEVICE_GPU) != std::string::npos) { + std::vector gpuSkips{ + // TODO: Issue: 53062 + R"(.*TensorIterator_1195103.*)", R"(.*TensorIterator_1195129.*)", R"(.*TensorIterator_1653010.*)", R"(.*TensorIterator_199835.*)", + R"(.*TensorIterator_303641.*)", R"(.*TensorIterator_303667.*)", R"(.*TensorIterator_337260.*)", R"(.*TensorIterator_362846.*)", + R"(.*TensorIterator_362869.*)", R"(.*TensorIterator_362906.*)", R"(.*TensorIterator_365496.*)", R"(.*TensorIterator_365522.*)", + R"(.*TensorIterator_365556.*)", R"(.*TensorIterator_365579.*)", R"(.*TensorIterator_616544.*)", R"(.*TensorIterator_616570.*)", + R"(.*TensorIterator_864978.*)", R"(.*TensorIterator_865004.*)", R"(.*TensorIterator_865030.*)", R"(.*TensorIterator_865056.*)", + R"(.*TensorIterator_865082.*)", R"(.*TensorIterator_865108.*)", R"(.*TensorIterator_972832.*)", R"(.*TensorIterator_972858.*)", + R"(.*TensorIterator_972884.*)", R"(.*TensorIterator_972910.*)", R"(.*TensorIterator_972936.*)", R"(.*TensorIterator_972962.*)", + R"(.*TensorIterator_972988.*)", R"(.*TensorIterator_973014.*)", R"(.*TensorIterator_1194007.*)", R"(.*TensorIterator_1194033.*)", + R"(.*TensorIterator_302500.*)", R"(.*TensorIterator_337024.*)", R"(.*TensorIterator_361044.*)", R"(.*TensorIterator_361067.*)", + R"(.*TensorIterator_361108.*)", R"(.*TensorIterator_361131.*)", R"(.*TensorIterator_364171.*)", R"(.*TensorIterator_364197.*)", + R"(.*TensorIterator_364231.*)", R"(.*TensorIterator_364254.*)", R"(.*TensorIterator_615626.*)", R"(.*TensorIterator_615652.*)", + R"(.*TensorIterator_865760.*)", R"(.*TensorIterator_865812.*)", R"(.*TensorIterator_865838.*)", R"(.*TensorIterator_865864.*)", + R"(.*TensorIterator_973781.*)", R"(.*TensorIterator_973807.*)", + // Hung: + R"(.*AvgPool_1199829.*)", R"(.*AvgPool_1201153.*)", R"(.*GroupConvolution_330567.*)", R"(.*ROIPooling_1199827.*)", + R"(.*MaxPool_43108.*)", + }; + skippedTestsRegExp.insert(skippedTestsRegExp.end(), + std::make_move_iterator(gpuSkips.begin()), + std::make_move_iterator(gpuSkips.end())); + } + if (targetDevice.find(CommonTestUtils::DEVICE_CPU) != std::string::npos) { + std::vector cpuSkips{ + // Hung: + R"(.*AvgPool_1199829.*)", R"(.*AvgPool_1201153.*)", R"(.*ROIPooling_1199827.*)", + }; + skippedTestsRegExp.insert(skippedTestsRegExp.end(), + std::make_move_iterator(cpuSkips.begin()), + std::make_move_iterator(cpuSkips.end())); + } + if (targetDevice.find(CommonTestUtils::DEVICE_GNA) != std::string::npos) { + std::vector gnaSkips{ + // Lost results + R"(.*Add_1087636.*)", R"(.*Add_2868.*)", R"(.*Add_2979.*)", R"(.*Add_53543.*)", + // hung + R"(.*Concat_535028.*)", R"(.*Concat_377139.*)", R"(.*Concat_379481.*)", R"(.*Concat_539044.*)", R"(.*Concat_539074.*)", + R"(.*Concat_534956.*)", + }; + skippedTestsRegExp.insert(skippedTestsRegExp.end(), + std::make_move_iterator(gnaSkips.begin()), + std::make_move_iterator(gnaSkips.end())); + } + return skippedTestsRegExp; } From 636736825cfe681ef2b39f37ce907b6f3dd763a4 Mon Sep 17 00:00:00 2001 From: Ivan Kochin Date: Thu, 22 Apr 2021 18:11:13 +0300 Subject: [PATCH 55/78] OpenVINO Hybrid CPUs support internal interface (#4602) * OpenVINO Hybrid CPUs support * Remove custom::task_arena abstraction layout * Get back to the custom::task_arena interface * Add windows.h inclusion * Fix typo in macro name * Separate TBB and TBBbind packages * Fix compile-time conditions * Fix preprocessors conditions * Fix typo * Fix linking * make linking private * Fix typo * Fix target_compile_definitions syntax * Implement CMake install logic, update sha hash for the tbbbind_2_4 package * Add tbbbind_2_4 required paths to setup_vars * Update CI paths * Include ie_parallel.hpp to ie_system_conf.cpp * Try to update dependencies scripts * Try to fix dependencies.bat * Modify dependencies script * Use static tbbbind_2_4 library * Remove redundant paths from CI * Update tbbbind package version * Make custom::task_arena inherited from tbb::task_arena * Incapsulate all TBB versions related logic inside the custom namespace * Move custom layer header to internal scope + minor improvements * Introduce new ThreadBindingType + fix compilation * Fix compilation * Use public tbbbind_2_4 package * Apply review comments * Fix compilation without tbbbind_2_4 * Fix compilation with different TBB versions Co-authored-by: Kochin, Ivan --- inference-engine/cmake/dependencies.cmake | 11 + inference-engine/cmake/ie_parallel.cmake | 8 +- inference-engine/include/ie_parallel.hpp | 4 + inference-engine/include/ie_plugin_config.hpp | 1 + .../src/inference_engine/CMakeLists.txt | 16 + .../src/inference_engine/ie_system_conf.cpp | 8 +- .../threading/ie_cpu_streams_executor.cpp | 26 +- .../threading/ie_istreams_executor.cpp | 3 + .../threading/ie_parallel_custom_arena.cpp | 281 ++++++++++++++++++ .../threading/ie_parallel_custom_arena.hpp | 103 +++++++ inference-engine/src/mkldnn_plugin/config.cpp | 3 + .../threading/ie_istreams_executor.hpp | 8 +- 12 files changed, 446 insertions(+), 26 deletions(-) create mode 100755 inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.cpp create mode 100755 inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.hpp diff --git a/inference-engine/cmake/dependencies.cmake b/inference-engine/cmake/dependencies.cmake index b4c3f947761..dfca56ba5c1 100644 --- a/inference-engine/cmake/dependencies.cmake +++ b/inference-engine/cmake/dependencies.cmake @@ -145,6 +145,11 @@ if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") TARGET_PATH "${TEMP}/tbb" ENVIRONMENT "TBBROOT" SHA256 "f1c9b9e2861efdaa01552bd25312ccbc5feeb45551e5f91ae61e29221c5c1479") + RESOLVE_DEPENDENCY(TBBBIND_2_4 + ARCHIVE_WIN "tbbbind_2_4_static_win.zip" + TARGET_PATH "${TEMP}/tbbbind_2_4" + ENVIRONMENT "TBBBIND_2_4_ROOT" + SHA256 "1a3a05082cc5ef1a764d635793be347b82c795f0e9ced771515fc3706a4dc4f0") elseif(ANDROID) # Should be before LINUX due LINUX is detected as well RESOLVE_DEPENDENCY(TBB ARCHIVE_ANDROID "tbb2020_20200404_android.tgz" @@ -156,6 +161,10 @@ if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") ARCHIVE_LIN "tbb2020_20200415_lin_strip.tgz" TARGET_PATH "${TEMP}/tbb" SHA256 "95b2f3b0b70c7376a0c7de351a355c2c514b42c4966e77e3e34271a599501008") + RESOLVE_DEPENDENCY(TBBBIND_2_4 + ARCHIVE_LIN "tbbbind_2_4_static_lin.tgz" + TARGET_PATH "${TEMP}/tbbbind_2_4" + SHA256 "888582a94f81821f9894cc089db36d5a6c2e0b6998cfa1fec0c027f28c597ada") elseif(LINUX AND AARCH64) RESOLVE_DEPENDENCY(TBB ARCHIVE_LIN "keembay/tbb2020_38404_kmb_lic.tgz" @@ -175,6 +184,8 @@ if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") update_deps_cache(TBBROOT "${TBB}" "Path to TBB root folder") update_deps_cache(TBB_DIR "${TBB}/cmake" "Path to TBB cmake folder") + update_deps_cache(TBBBIND_2_4_DIR "${TBBBIND_2_4}/cmake" "Path to TBBBIND_2_4 cmake folder") + if (WIN32) log_rpath_from_dir(TBB "${TBB}/bin") else () diff --git a/inference-engine/cmake/ie_parallel.cmake b/inference-engine/cmake/ie_parallel.cmake index f6d5ea62c25..dc07dfc0703 100644 --- a/inference-engine/cmake/ie_parallel.cmake +++ b/inference-engine/cmake/ie_parallel.cmake @@ -8,13 +8,7 @@ function(set_ie_threading_interface_for TARGET_NAME) set("TBB_FOUND" ${TBB_FOUND} PARENT_SCOPE) set("TBB_IMPORTED_TARGETS" ${TBB_IMPORTED_TARGETS} PARENT_SCOPE) set("TBB_VERSION" ${TBB_VERSION} PARENT_SCOPE) - if (TBB_FOUND) - if (TBB_VERSION VERSION_LESS 2020) - ext_message(WARNING "TBB version is less than OpenVINO recommends to use.\ - Some TBB related features like NUMA-aware tbb::task_arena\ - execution will be disabled.") - endif() - else () + if (NOT TBB_FOUND) ext_message(WARNING "TBB was not found by the configured TBB_DIR/TBBROOT path.\ SEQ method will be used.") endif () diff --git a/inference-engine/include/ie_parallel.hpp b/inference-engine/include/ie_parallel.hpp index fbdc72c7368..b7e2946a023 100644 --- a/inference-engine/include/ie_parallel.hpp +++ b/inference-engine/include/ie_parallel.hpp @@ -32,6 +32,10 @@ #ifndef TBB_PREVIEW_NUMA_SUPPORT # define TBB_PREVIEW_NUMA_SUPPORT 1 #endif +#ifndef TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION +# define TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION 1 +#endif + #include "tbb/blocked_range.h" #include "tbb/blocked_range2d.h" #include "tbb/blocked_range3d.h" diff --git a/inference-engine/include/ie_plugin_config.hpp b/inference-engine/include/ie_plugin_config.hpp index a211c491be6..645307b9ab4 100644 --- a/inference-engine/include/ie_plugin_config.hpp +++ b/inference-engine/include/ie_plugin_config.hpp @@ -214,6 +214,7 @@ DECLARE_CONFIG_KEY(CPU_THREADS_NUM); */ DECLARE_CONFIG_KEY(CPU_BIND_THREAD); DECLARE_CONFIG_VALUE(NUMA); +DECLARE_CONFIG_VALUE(HYBRID_AWARE); /** * @brief Optimize CPU execution to maximize throughput. diff --git a/inference-engine/src/inference_engine/CMakeLists.txt b/inference-engine/src/inference_engine/CMakeLists.txt index debd364bebe..9d1b9009867 100644 --- a/inference-engine/src/inference_engine/CMakeLists.txt +++ b/inference-engine/src/inference_engine/CMakeLists.txt @@ -4,6 +4,10 @@ set (TARGET_NAME "inference_engine") +if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") + find_package(TBBBIND_2_4) +endif() + file (GLOB LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cpp/*.cpp @@ -121,6 +125,10 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DI target_link_libraries(${TARGET_NAME}_obj PRIVATE ${TARGET_NAME}_reader_api) set_ie_threading_interface_for(${TARGET_NAME}_obj) +if (TBBBIND_2_4_FOUND) + target_compile_definitions(${TARGET_NAME}_obj PRIVATE -DTBBBIND_2_4_AVAILABLE) + target_link_libraries(${TARGET_NAME}_obj PRIVATE ${TBBBIND_2_4_IMPORTED_TARGETS}) +endif() add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME}_obj) @@ -136,6 +144,10 @@ ie_add_vs_version_file(NAME ${TARGET_NAME} FILEDESCRIPTION "Inference Engine Core Runtime library") set_ie_threading_interface_for(${TARGET_NAME}) +if (TBBBIND_2_4_FOUND) + target_compile_definitions(${TARGET_NAME} PRIVATE -DTBBBIND_2_4_AVAILABLE) + target_link_libraries(${TARGET_NAME} PRIVATE ${TBBBIND_2_4_IMPORTED_TARGETS}) +endif() target_link_libraries(${TARGET_NAME} PRIVATE pugixml openvino::itt ${CMAKE_DL_LIBS} Threads::Threads ${NGRAPH_LIBRARIES} inference_engine_transformations) @@ -163,6 +175,10 @@ add_library(${TARGET_NAME}_s STATIC ${IE_STATIC_DEPENDENT_FILES}) set_ie_threading_interface_for(${TARGET_NAME}_s) +if (TBBBIND_2_4_FOUND) + target_compile_definitions(${TARGET_NAME}_s PRIVATE -DTBBBIND_2_4_AVAILABLE) + target_link_libraries(${TARGET_NAME}_s PRIVATE ${TBBBIND_2_4_IMPORTED_TARGETS}) +endif() target_include_directories(${TARGET_NAME}_s PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" $ diff --git a/inference-engine/src/inference_engine/ie_system_conf.cpp b/inference-engine/src/inference_engine/ie_system_conf.cpp index fa7793ecc9c..8b5bbbb0e79 100644 --- a/inference-engine/src/inference_engine/ie_system_conf.cpp +++ b/inference-engine/src/inference_engine/ie_system_conf.cpp @@ -4,7 +4,7 @@ #include #include -#include "ie_parallel.hpp" +#include "threading/ie_parallel_custom_arena.hpp" #include "ie_system_conf.h" #include #include @@ -98,11 +98,7 @@ std::vector getAvailableNUMANodes() { return {0}; } #if ((IE_THREAD == IE_THREAD_TBB) || (IE_THREAD == IE_THREAD_TBB_AUTO)) std::vector getAvailableNUMANodes() { -#if TBB_INTERFACE_VERSION >= 11100 - return tbb::info::numa_nodes(); -#else - return {0}; -#endif + return custom::info::numa_nodes(); } #endif diff --git a/inference-engine/src/inference_engine/threading/ie_cpu_streams_executor.cpp b/inference-engine/src/inference_engine/threading/ie_cpu_streams_executor.cpp index 7343dfb1488..5c9bdde9b61 100644 --- a/inference-engine/src/inference_engine/threading/ie_cpu_streams_executor.cpp +++ b/inference-engine/src/inference_engine/threading/ie_cpu_streams_executor.cpp @@ -15,7 +15,7 @@ #include #include "threading/ie_thread_local.hpp" -#include "ie_parallel.hpp" +#include "ie_parallel_custom_arena.hpp" #include "ie_system_conf.h" #include "threading/ie_thread_affinity.hpp" #include "threading/ie_cpu_streams_executor.hpp" @@ -71,15 +71,21 @@ struct CPUStreamsExecutor::Impl { ((_impl->_config._streams + _impl->_usedNumaNodes.size() - 1)/_impl->_usedNumaNodes.size())) : _impl->_usedNumaNodes.at(_streamId % _impl->_usedNumaNodes.size()); #if IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO - auto concurrency = (0 == _impl->_config._threadsPerStream) ? tbb::task_arena::automatic : _impl->_config._threadsPerStream; - if (ThreadBindingType::NUMA == _impl->_config._threadBindingType) { -#if TBB_INTERFACE_VERSION >= 11100 // TBB has numa aware task_arena api - _taskArena.reset(new tbb::task_arena{tbb::task_arena::constraints{_numaNodeId, concurrency}}); -#else - _taskArena.reset(new tbb::task_arena{concurrency}); -#endif + auto concurrency = (0 == _impl->_config._threadsPerStream) ? custom::task_arena::automatic : _impl->_config._threadsPerStream; + if (ThreadBindingType::HYBRID_AWARE == _impl->_config._threadBindingType) { + _taskArena.reset(new custom::task_arena{ + custom::task_arena::constraints{} + .set_core_type(custom::info::core_types().back()) + .set_max_concurrency(concurrency) + }); + } else if (ThreadBindingType::NUMA == _impl->_config._threadBindingType) { + _taskArena.reset(new custom::task_arena{ + custom::task_arena::constraints{} + .set_numa_id(_numaNodeId) + .set_max_concurrency(concurrency) + }); } else if ((0 != _impl->_config._threadsPerStream) || (ThreadBindingType::CORES == _impl->_config._threadBindingType)) { - _taskArena.reset(new tbb::task_arena{concurrency}); + _taskArena.reset(new custom::task_arena{concurrency}); if (ThreadBindingType::CORES == _impl->_config._threadBindingType) { CpuSet processMask; int ncpus = 0; @@ -140,7 +146,7 @@ struct CPUStreamsExecutor::Impl { bool _execute = false; std::queue _taskQueue; #if IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO - std::unique_ptr _taskArena; + std::unique_ptr _taskArena; std::unique_ptr _observer; #endif }; diff --git a/inference-engine/src/inference_engine/threading/ie_istreams_executor.cpp b/inference-engine/src/inference_engine/threading/ie_istreams_executor.cpp index cc54cdc3b28..96d3860001d 100644 --- a/inference-engine/src/inference_engine/threading/ie_istreams_executor.cpp +++ b/inference-engine/src/inference_engine/threading/ie_istreams_executor.cpp @@ -122,6 +122,9 @@ Parameter IStreamsExecutor::Config::GetConfig(const std::string& key) { case IStreamsExecutor::ThreadBindingType::NUMA: return {CONFIG_VALUE(NUMA)}; break; + case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE: + return {CONFIG_VALUE(HYBRID_AWARE)}; + break; } } else if (key == CONFIG_KEY(CPU_THROUGHPUT_STREAMS)) { return {_streams}; diff --git a/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.cpp b/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.cpp new file mode 100755 index 00000000000..4030ea83430 --- /dev/null +++ b/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.cpp @@ -0,0 +1,281 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ie_parallel_custom_arena.hpp" + +#if IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO + +#ifndef TBBBIND_2_4_AVAILABLE +# define TBBBIND_2_4_AVAILABLE 0 +#endif + +#define USE_TBBBIND_2_4 (TBBBIND_2_4_AVAILABLE && TBB_INTERFACE_VERSION < 12020) +#define TBB_NUMA_SUPPORT_PRESENT (TBB_INTERFACE_VERSION >= 11100) +#define TBB_HYBRID_CPUS_SUPPORT_PRESENT (TBB_INTERFACE_VERSION >= 12020) + +#if defined(_WIN32) || defined(_WIN64) +#include +#endif + +namespace custom { +namespace detail { + +#if USE_TBBBIND_2_4 +class binding_handler; + +extern "C" { +void __TBB_internal_initialize_system_topology( + std::size_t groups_num, + int& numa_nodes_count, int*& numa_indexes_list, + int& core_types_count, int*& core_types_indexes_list +); +binding_handler* __TBB_internal_allocate_binding_handler(int number_of_slots, int numa_id, int core_type_id, int max_threads_per_core); +void __TBB_internal_deallocate_binding_handler(binding_handler* handler_ptr); +void __TBB_internal_apply_affinity(binding_handler* handler_ptr, int slot_num); +void __TBB_internal_restore_affinity(binding_handler* handler_ptr, int slot_num); +int __TBB_internal_get_default_concurrency(int numa_id, int core_type_id, int max_threads_per_core); +} + +int get_processors_group_num() { +#if defined(_WIN32) || defined(_WIN64) + SYSTEM_INFO si; + GetNativeSystemInfo(&si); + + DWORD_PTR pam, sam, m = 1; + GetProcessAffinityMask(GetCurrentProcess(), &pam, &sam); + int nproc = 0; + for (std::size_t i = 0; i < sizeof(DWORD_PTR) * CHAR_BIT; ++i, m <<= 1) { + if ( pam & m ) + ++nproc; + } + if (nproc == static_cast(si.dwNumberOfProcessors)) { + return GetActiveProcessorGroupCount(); + } +#endif + return 1; +} + +bool is_binding_environment_valid() { +#if defined(_WIN32) && !defined(_WIN64) + static bool result = [] { + // For 32-bit Windows applications, process affinity masks can only support up to 32 logical CPUs. + SYSTEM_INFO si; + GetNativeSystemInfo(&si); + if (si.dwNumberOfProcessors > 32) return false; + return true; + }(); + return result; +#else + return true; +#endif /* _WIN32 && !_WIN64 */ +} + +static int numa_nodes_count = 0; +static int* numa_nodes_indexes = nullptr; + +static int core_types_count = 0; +static int* core_types_indexes = nullptr; + +void initialize_system_topology() { + static std::once_flag is_topology_initialized; + + std::call_once(is_topology_initialized, [&]{ + if (is_binding_environment_valid()) { + __TBB_internal_initialize_system_topology( + get_processors_group_num(), + numa_nodes_count, numa_nodes_indexes, + core_types_count, core_types_indexes); + } else { + static int dummy_index = task_arena::automatic; + + numa_nodes_count = 1; + numa_nodes_indexes = &dummy_index; + + core_types_count = 1; + core_types_indexes = &dummy_index; + } + }); +} + +class binding_observer : public tbb::task_scheduler_observer { + binding_handler* my_binding_handler; +public: + binding_observer(tbb::task_arena& ta, int num_slots, const constraints& c) + : task_scheduler_observer(ta) { + detail::initialize_system_topology(); + my_binding_handler = detail::__TBB_internal_allocate_binding_handler(num_slots, c.numa_id, c.core_type, c.max_threads_per_core); + } + ~binding_observer() { + detail::__TBB_internal_deallocate_binding_handler(my_binding_handler); + } + + void on_scheduler_entry(bool) override { + detail::__TBB_internal_apply_affinity(my_binding_handler, tbb::this_task_arena::current_thread_index()); + } + void on_scheduler_exit(bool) override { + detail::__TBB_internal_restore_affinity(my_binding_handler, tbb::this_task_arena::current_thread_index()); + } +}; + +binding_observer* construct_binding_observer(tbb::task_arena& ta, int num_slots, const constraints& c) { + binding_observer* observer = nullptr; + if (detail::is_binding_environment_valid() && + ((c.core_type >= 0 && info::core_types().size() > 1) || (c.numa_id >= 0 && info::numa_nodes().size() > 1) || c.max_threads_per_core > 0)) { + observer = new binding_observer(ta, num_slots, c); + observer->observe(true); + } + return observer; +} + +void destroy_binding_observer(binding_observer* observer) { + observer->observe(false); + delete observer; +} +#endif /*USE_TBBBIND_2_4*/ + +#if TBB_NUMA_SUPPORT_PRESENT +tbb::task_arena::constraints convert_constraints(custom::task_arena::constraints& c) { + tbb::task_arena::constraints result{}; +#if TBB_HYBRID_CPUS_SUPPORT_PRESENT + result.core_type = c.core_type; + result.max_threads_per_core = c.max_threads_per_core; +#endif + result.numa_id = c.numa_id; + result.max_concurrency = c.max_concurrency; + return result; +} +#endif +} // namespace detail + +task_arena::task_arena(int max_concurrency_, unsigned reserved_for_masters) + : tbb::task_arena{max_concurrency_, reserved_for_masters} + , my_initialization_state{} + , my_constraints{} + , my_binding_observer{nullptr} +{} + +task_arena::task_arena(const constraints& constraints_, unsigned reserved_for_masters) + : tbb::task_arena{info::default_concurrency(constraints_), reserved_for_masters} + , my_initialization_state{} + , my_constraints{constraints_} + , my_binding_observer{nullptr} +{} + +task_arena::task_arena(const task_arena &s) + : tbb::task_arena{s} + , my_initialization_state{} + , my_constraints{s.my_constraints} + , my_binding_observer{nullptr} +{} + +void task_arena::initialize() { +#if USE_TBBBIND_2_4 + std::call_once(my_initialization_state, [this] { + tbb::task_arena::initialize(); + my_binding_observer = detail::construct_binding_observer( + *this, tbb::task_arena::max_concurrency(), my_constraints); + }); +#elif TBB_NUMA_SUPPORT_PRESENT || TBB_HYBRID_CPUS_SUPPORT_PRESENT + tbb::task_arena::initialize(convert_constraints(my_constraints)); +#else + tbb::task_arena::initialize(); +#endif +} + +void task_arena::initialize(int max_concurrency_, unsigned reserved_for_masters) { +#if USE_TBBBIND_2_4 + std::call_once(my_initialization_state, [this, &max_concurrency_, &reserved_for_masters] { + tbb::task_arena::initialize(max_concurrency_, reserved_for_masters); + my_binding_observer = detail::construct_binding_observer( + *this, tbb::task_arena::max_concurrency(), my_constraints); + }); +#elif TBB_NUMA_SUPPORT_PRESENT || TBB_HYBRID_CPUS_SUPPORT_PRESENT + my_constraints.max_concurrency = max_concurrency_; + tbb::task_arena::initialize(convert_constraints(my_constraints), reserved_for_masters); +#else + tbb::task_arena::initialize(max_concurrency_, reserved_for_masters); +#endif +} + +void task_arena::initialize(constraints constraints_, unsigned reserved_for_masters) { + std::call_once(my_initialization_state, [this, &constraints_, &reserved_for_masters] { + my_constraints = constraints_; +#if USE_TBBBIND_2_4 + tbb::task_arena::initialize(info::default_concurrency(constraints_), reserved_for_masters); + my_binding_observer = detail::construct_binding_observer( + *this, tbb::task_arena::max_concurrency(), my_constraints); +#elif TBB_NUMA_SUPPORT_PRESENT || TBB_HYBRID_CPUS_SUPPORT_PRESENT + tbb::task_arena::initialize(convert_constraints(my_constraints), reserved_for_masters); +#else + tbb::task_arena::initialize(my_constraints.max_concurrency, reserved_for_masters); +#endif + }); +} + +int task_arena::max_concurrency() { + initialize(); + return tbb::task_arena::max_concurrency(); +} + +task_arena::~task_arena() { +#if USE_TBBBIND_2_4 + if (my_binding_observer != nullptr) { + detail::destroy_binding_observer(my_binding_observer); + } +#endif +} + +namespace info { +std::vector numa_nodes() { +#if USE_TBBBIND_2_4 + detail::initialize_system_topology(); + std::vector node_indexes(detail::numa_nodes_count); + std::memcpy(node_indexes.data(), detail::numa_nodes_indexes, detail::numa_nodes_count * sizeof(int)); + return node_indexes; +#elif TBB_NUMA_SUPPORT_PRESENT + return tbb::info::numa_nodes(); +#else + return {tbb::task_arena::automatic}; +#endif +} + +std::vector core_types() { +#if USE_TBBBIND_2_4 + detail::initialize_system_topology(); + std::vector core_type_indexes(detail::core_types_count); + std::memcpy(core_type_indexes.data(), detail::core_types_indexes, detail::core_types_count * sizeof(int)); + return core_type_indexes; +#elif TBB_HYBRID_CPUS_SUPPORT_PRESENT + return tbb::info::core_types(); +#else + return {tbb::task_arena::automatic}; +#endif +} + +int default_concurrency(task_arena::constraints c) { + if (c.max_concurrency > 0) { + return c.max_concurrency; + } +#if USE_TBBBIND_2_4 + if (detail::is_binding_environment_valid()) { + detail::initialize_system_topology(); + return detail::__TBB_internal_get_default_concurrency(c.numa_id, c.core_type, c.max_threads_per_core); + } + return tbb::this_task_arena::max_concurrency(); +#elif TBB_HYBRID_CPUS_SUPPORT_PRESENT + return tbb::info::default_concurrency(convert_constraints(c)); +#elif TBB_NUMA_SUPPORT_PRESENT + return tbb::info::default_concurrency(c.numa_id); +#else + return tbb::this_task_arena::max_concurrency(); +#endif +} + +int default_concurrency(numa_node_id id) { + return default_concurrency(task_arena::constraints{}.set_numa_id(id)); +} + +} // namespace info +} // namespace custom +#endif /*IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO*/ diff --git a/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.hpp b/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.hpp new file mode 100755 index 00000000000..c8005ba82db --- /dev/null +++ b/inference-engine/src/inference_engine/threading/ie_parallel_custom_arena.hpp @@ -0,0 +1,103 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief Contains declarations and custom threading interfaces based on TBB info and task_arena APIs. + * + * @file ie_parallel_custom.hpp + */ + +#pragma once + +#include "ie_parallel.hpp" + +#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO) + +#include +#include +#include +#include + +namespace custom { + +using numa_node_id = int; +using core_type_id = int; + +namespace detail { +struct constraints { + constraints(numa_node_id id = -1, int maximal_concurrency = -1) + : numa_id{id} + , max_concurrency{maximal_concurrency} + , core_type{tbb::task_arena::automatic} + , max_threads_per_core{tbb::task_arena::automatic} + {} + + constraints& set_numa_id(numa_node_id id) { + numa_id = id; + return *this; + } + constraints& set_max_concurrency(int maximal_concurrency) { + max_concurrency = maximal_concurrency; + return *this; + } + constraints& set_core_type(core_type_id id) { + core_type = id; + return *this; + } + constraints& set_max_threads_per_core(int threads_number) { + max_threads_per_core = threads_number; + return *this; + } + + numa_node_id numa_id = tbb::task_arena::automatic; + int max_concurrency = tbb::task_arena::automatic; + core_type_id core_type = tbb::task_arena::automatic; + int max_threads_per_core = tbb::task_arena::automatic; +}; + +class binding_observer; +} // namespace detail + +class task_arena : public tbb::task_arena { + std::once_flag my_initialization_state; + detail::constraints my_constraints; + detail::binding_observer* my_binding_observer; + +public: + using constraints = detail::constraints; + static const int automatic = tbb::task_arena::automatic; + + task_arena(int max_concurrency_ = automatic, unsigned reserved_for_masters = 1); + task_arena(const constraints& constraints_, unsigned reserved_for_masters = 1); + task_arena(const task_arena &s); + + void initialize(); + void initialize(int max_concurrency_, unsigned reserved_for_masters = 1); + void initialize(constraints constraints_, unsigned reserved_for_masters = 1); + + int max_concurrency(); + + template + void enqueue(F&& f) { + initialize(); + tbb::task_arena::enqueue(std::forward(f)); + } + template + auto execute(F&& f) -> decltype(f()) { + initialize(); + return tbb::task_arena::execute(std::forward(f)); + } + + ~task_arena(); +}; + +namespace info { + std::vector numa_nodes(); + std::vector core_types(); + + int default_concurrency(numa_node_id id = task_arena::automatic); + int default_concurrency(task_arena::constraints c); +} // namespace info +} // namespace custom +#endif /*(IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)*/ diff --git a/inference-engine/src/mkldnn_plugin/config.cpp b/inference-engine/src/mkldnn_plugin/config.cpp index 8e2f29b8504..920a5ff2788 100644 --- a/inference-engine/src/mkldnn_plugin/config.cpp +++ b/inference-engine/src/mkldnn_plugin/config.cpp @@ -127,6 +127,9 @@ void Config::updateProperties() { case IStreamsExecutor::ThreadBindingType::NUMA: _config.insert({ PluginConfigParams::KEY_CPU_BIND_THREAD, PluginConfigParams::NUMA }); break; + case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE: + _config.insert({ PluginConfigParams::KEY_CPU_BIND_THREAD, PluginConfigParams::HYBRID_AWARE}); + break; } if (collectPerfCounters == true) _config.insert({ PluginConfigParams::KEY_PERF_COUNT, PluginConfigParams::YES }); diff --git a/inference-engine/src/plugin_api/threading/ie_istreams_executor.hpp b/inference-engine/src/plugin_api/threading/ie_istreams_executor.hpp index 34bdeeef65b..67a601bb772 100644 --- a/inference-engine/src/plugin_api/threading/ie_istreams_executor.hpp +++ b/inference-engine/src/plugin_api/threading/ie_istreams_executor.hpp @@ -39,9 +39,11 @@ public: * @brief Defines thread binding type */ enum ThreadBindingType : std::uint8_t { - NONE, //!< Don't bind threads - CORES, //!< Bind threads to cores - NUMA //!< Bind threads to NUMA nodes + NONE, //!< Don't bind the inference threads + CORES, //!< Bind inference threads to the CPU cores (round-robin) + // the following modes are implemented only for the TBB code-path: + NUMA, //!< Bind to the NUMA nodes (default mode for the non-hybrid CPUs on the Win/MacOS, where the 'CORES' is not implemeneted) + HYBRID_AWARE //!< Let the runtime bind the inference threads depending on the cores type (default mode for the hybrid CPUs) }; /** From cc7ae5e6d1caa411a92dc6c9a2b4bbf8575f7ce9 Mon Sep 17 00:00:00 2001 From: Patryk Elszkowski Date: Thu, 22 Apr 2021 17:41:41 +0200 Subject: [PATCH 56/78] add for serialization names for i4 u4 (#5337) Co-authored-by: Patryk Elszkowski --- .../src/transformations/src/transformations/serialize.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inference-engine/src/transformations/src/transformations/serialize.cpp b/inference-engine/src/transformations/src/transformations/serialize.cpp index c2eb4d6a5bd..873eea32a14 100644 --- a/inference-engine/src/transformations/src/transformations/serialize.cpp +++ b/inference-engine/src/transformations/src/transformations/serialize.cpp @@ -492,6 +492,8 @@ std::string get_output_precision_name(ngraph::Output& o) { return "BF16"; case ::ngraph::element::Type_t::f64: return "FP64"; + case ::ngraph::element::Type_t::i4: + return "I4"; case ::ngraph::element::Type_t::i8: return "I8"; case ::ngraph::element::Type_t::i16: @@ -500,6 +502,8 @@ std::string get_output_precision_name(ngraph::Output& o) { return "I32"; case ::ngraph::element::Type_t::i64: return "I64"; + case ::ngraph::element::Type_t::u4: + return "U4"; case ::ngraph::element::Type_t::u8: return "U8"; case ::ngraph::element::Type_t::u16: From 28cad9e3fb633c0e6006102cd306b6b82673ddfe Mon Sep 17 00:00:00 2001 From: Gleb Kazantaev Date: Thu, 22 Apr 2021 19:13:14 +0300 Subject: [PATCH 57/78] Add transformation pipline for POT (#5328) --- .../offline_transformations_api.pyx | 4 +++ .../offline_transformations_api_impl.cpp | 7 ++++ .../offline_transformations_api_impl.hpp | 4 +++ .../offline_transformations_api_impl_defs.pxd | 4 +++ .../include/pot_transformations.hpp | 33 +++++++++++++++++++ .../src/pot_transformations.cpp | 25 ++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 inference-engine/src/offline_transformations/include/pot_transformations.hpp create mode 100644 inference-engine/src/offline_transformations/src/pot_transformations.cpp diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api.pyx b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api.pyx index 8e9be27b31b..ccf5b834110 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api.pyx +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api.pyx @@ -5,10 +5,14 @@ from .cimport offline_transformations_api_impl_defs as C from ..inference_engine.ie_api cimport IENetwork from libcpp cimport bool +from libcpp.string cimport string def ApplyMOCTransformations(IENetwork network, bool cf): C.ApplyMOCTransformations(network.impl, cf) +def ApplyPOTTransformations(IENetwork network, string device): + C.ApplyPOTTransformations(network.impl, device) + def ApplyLowLatencyTransformation(IENetwork network): C.ApplyLowLatencyTransformation(network.impl) diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.cpp b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.cpp index eeb19a63ac5..74b77468ae2 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.cpp +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.cpp @@ -5,6 +5,7 @@ #include "offline_transformations_api_impl.hpp" #include +#include #include #include @@ -21,6 +22,12 @@ void InferenceEnginePython::ApplyMOCTransformations(InferenceEnginePython::IENet manager.run_passes(network.actual->getFunction()); } +void InferenceEnginePython::ApplyPOTTransformations(InferenceEnginePython::IENetwork network, std::string device) { + ngraph::pass::Manager manager; + manager.register_pass(std::move(device)); + manager.run_passes(network.actual->getFunction()); +} + void InferenceEnginePython::ApplyLowLatencyTransformation(InferenceEnginePython::IENetwork network) { ngraph::pass::Manager manager; manager.register_pass(); diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.hpp b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.hpp index 038574423a4..b56be6c08e5 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.hpp +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl.hpp @@ -4,6 +4,8 @@ #pragma once +#include + #include "Python.h" #include "ie_api_impl.hpp" @@ -11,6 +13,8 @@ namespace InferenceEnginePython { void ApplyMOCTransformations(InferenceEnginePython::IENetwork network, bool cf); +void ApplyPOTTransformations(InferenceEnginePython::IENetwork network, std::string device); + void ApplyLowLatencyTransformation(InferenceEnginePython::IENetwork network); void ApplyPruningTransformation(InferenceEnginePython::IENetwork network); diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl_defs.pxd b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl_defs.pxd index ce8928af39e..803ccdd7e66 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl_defs.pxd +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/offline_transformations_api_impl_defs.pxd @@ -2,11 +2,15 @@ # SPDX-License-Identifier: Apache-2.0 from libcpp cimport bool +from libcpp.string cimport string + from ..inference_engine.ie_api_impl_defs cimport IENetwork cdef extern from "offline_transformations_api_impl.hpp" namespace "InferenceEnginePython": cdef void ApplyMOCTransformations(IENetwork network, bool cf) + cdef void ApplyPOTTransformations(IENetwork network, string device) + cdef void ApplyLowLatencyTransformation(IENetwork network) cdef void ApplyPruningTransformation(IENetwork network) diff --git a/inference-engine/src/offline_transformations/include/pot_transformations.hpp b/inference-engine/src/offline_transformations/include/pot_transformations.hpp new file mode 100644 index 00000000000..ac0d9df8ae2 --- /dev/null +++ b/inference-engine/src/offline_transformations/include/pot_transformations.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include + +namespace ngraph { +namespace pass { + +class POTTransformations; + +} // namespace pass +} // namespace ngraph + +/** + * @brief This transformation is an entry point for nGraph transformations that will be + * executed inside POT. + */ + +class ngraph::pass::POTTransformations: public ngraph::pass::FunctionPass { + std::string m_device; + +public: + NGRAPH_RTTI_DECLARATION; + explicit POTTransformations(std::string device) : m_device(std::move(device)) {} + + bool run_on_function(std::shared_ptr) override; +}; diff --git a/inference-engine/src/offline_transformations/src/pot_transformations.cpp b/inference-engine/src/offline_transformations/src/pot_transformations.cpp new file mode 100644 index 00000000000..7211b42e475 --- /dev/null +++ b/inference-engine/src/offline_transformations/src/pot_transformations.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include + +#include + +#include "pot_transformations.hpp" + +NGRAPH_RTTI_DEFINITION(ngraph::pass::POTTransformations, "POTTransformations", 0); + +bool ngraph::pass::POTTransformations::run_on_function(std::shared_ptr f) { + ngraph::pass::Manager manager(get_pass_config()); + if (m_device == "CPU") { + // TODO: register CPU passes + // manager.register_pass(); + } else { + throw ngraph_error("Device name is unsupported"); + } + manager.run_passes(f); + return false; +} \ No newline at end of file From cf6acfde78dd9c219e50825cc89a29390be84163 Mon Sep 17 00:00:00 2001 From: Vladimir Paramuzov Date: Thu, 22 Apr 2021 19:37:45 +0300 Subject: [PATCH 58/78] [IE CLDNN] Fixed ambiguous native_powr call in mvn for fp16 out type (#5298) --- .../actual_kernels/mvn/mvn_kernel_base.cpp | 2 +- .../cl_kernels/mvn_gpu_b_fs_yx_fsv16_imad.cl | 8 ++++---- .../tests/test_cases/fusings_gpu_test.cpp | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/mvn/mvn_kernel_base.cpp b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/mvn/mvn_kernel_base.cpp index d19b95ff980..8e85c733ec2 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/mvn/mvn_kernel_base.cpp +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/actual_kernels/mvn/mvn_kernel_base.cpp @@ -82,7 +82,7 @@ KernelsData MVNKernelBase::GetCommonKernelsData(const Params& params, } Datatype MVNKernelBase::GetActivationType(const mvn_params& params) const { - if (params.output.GetDType() == Datatype::F16) + if (params.inputs[0].GetDType() == Datatype::F16) return Datatype::F16; return Datatype::F32; } diff --git a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/mvn_gpu_b_fs_yx_fsv16_imad.cl b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/mvn_gpu_b_fs_yx_fsv16_imad.cl index a5c866a26f5..3e260790315 100644 --- a/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/mvn_gpu_b_fs_yx_fsv16_imad.cl +++ b/inference-engine/thirdparty/clDNN/kernel_selector/core/cl_kernels/mvn_gpu_b_fs_yx_fsv16_imad.cl @@ -216,9 +216,9 @@ KERNEL(mvn_var_1)(const __global INPUT0_TYPE* input, DECLARE_PACKED_ACCUMULATE(accumulate_sum, MEAN_TYPE, MEAN_TYPE, FSV, INPUT_SLICE_PITCH, ITEM_GROUPS, LWS, ACCUMULATE_SUM) #if defined EPS_OUTSIDE_SQRT - #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr(native_sqrt((sum_diff_sq) / ITEMS_NUM) + (MEAN_TYPE)EPSILON, -1.f); + #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr(native_sqrt((sum_diff_sq) / ITEMS_NUM) + (MEAN_TYPE)EPSILON, (MEAN_TYPE)-1.f); #elif defined EPS_INSIDE_SQRT - #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr((sum_diff_sq) / ITEMS_NUM + (MEAN_TYPE)EPSILON, -0.5f) + #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr((sum_diff_sq) / ITEMS_NUM + (MEAN_TYPE)EPSILON, (MEAN_TYPE)-0.5f) #endif #if SG_NUM != 1 DECLARE_WG_PACKED_REDUCE_ADD(reduce_var_across_sg, MEAN_TYPE, FSV, SG_NUM, CALC_INVERSE_VARIANCE) @@ -275,9 +275,9 @@ DECLARE_SG_PACKED_REDUCE_ADD(reduce_mean, MEAN_TYPE, FSV, CALC_MEAN) DECLARE_PACKED_ACCUMULATE_EARGS(accumulate_sum_sq_dev, MEAN_TYPE, INPUT0_TYPE, FSV, INPUT_SLICE_PITCH, ITEMS_NUM, LWS, ACCUMULATE_SUM_SQ_DEV, EXTRA_ARGS_DECL, EXTRA_ARGS) #if defined EPS_OUTSIDE_SQRT - #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr(native_sqrt((sum_diff_sq) / ITEMS_NUM) + (MEAN_TYPE)EPSILON, -1.f); + #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr(native_sqrt((sum_diff_sq) / ITEMS_NUM) + (MEAN_TYPE)EPSILON, (MEAN_TYPE)-1.f); #elif defined EPS_INSIDE_SQRT - #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr((sum_diff_sq) / ITEMS_NUM + (MEAN_TYPE)EPSILON, -0.5f) + #define CALC_INVERSE_VARIANCE(sum_diff_sq) native_powr((sum_diff_sq) / ITEMS_NUM + (MEAN_TYPE)EPSILON, (MEAN_TYPE)-0.5f) #endif #if SG_NUM != 1 DECLARE_WG_PACKED_REDUCE_ADD(reduce_inverse_variance, MEAN_TYPE, FSV, SG_NUM, CALC_INVERSE_VARIANCE) diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp index 2a57732c269..33975234b03 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp @@ -3452,6 +3452,26 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, mvn_eltwise, mvn_test_params{ CASE_MVN_3D_U8_5, 3, 3 }, }), ); +class mvn_eltwise_f16 : public MVNFusingTest {}; +TEST_P(mvn_eltwise_f16, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", layout{ p.input_type, p.input_format, p.input_size }), + mvn("mvn", "input", p.normalize_variance, 1e-10f, false, false), + data("eltw_data", get_mem(layout{ p.input_type, p.default_format, p.elwise_size })), + eltwise("eltw", {"mvn", "eltw_data"}, eltwise_mode::sum, data_types::f16), + reorder("reorder_bfyx", "eltw", p.default_format, data_types::f32) + ); + + tolerance = 0.1f; + execute(p); +} + +INSTANTIATE_TEST_CASE_P(fusings_gpu, mvn_eltwise_f16, + ::testing::ValuesIn(std::vector{ + mvn_test_params{ CASE_MVN_I8_6, 2, 3 }, + mvn_test_params{ CASE_MVN_U8_2, 2, 3 }, +}), ); + /* ----------------------------------------------------------------------------------------------------- */ /* ---------------------------------------- LRN cases -------------------------------------------------- */ /* ----------------------------------------------------------------------------------------------------- */ From 6a850b1e7b6ca3de59d1161dea70472ed9738f7e Mon Sep 17 00:00:00 2001 From: Patryk Elszkowski Date: Fri, 23 Apr 2021 06:07:23 +0200 Subject: [PATCH 59/78] refactor convertOutputPrecision (#5338) Co-authored-by: Patryk Elszkowski --- .../src/utils/ngraph_helpers.cpp | 541 ++++-------------- 1 file changed, 113 insertions(+), 428 deletions(-) diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp index 48ac22942cc..93dca7990f8 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp @@ -288,16 +288,6 @@ std::shared_ptr getNodeSharedPtr(const ngraph::NodeTypeInfo &type_ NGRAPH_UNREACHABLE("supported opsets does not contain op with name: ", type_info.name, " version: ", type_info.version); } -template -std::vector convertPrecision(const std::vector &buffer, const size_t elementsCount, const size_t elementSize) { - std::vector convertedData(elementsCount * elementSize); - const fromPrec *src = reinterpret_cast(buffer.data()); - toPrec *dst = reinterpret_cast(convertedData.data()); - for (size_t i = 0; i < elementsCount; i++) - dst[i] = static_cast(src[i]); - return convertedData; -} - bool is_tensor_iterator_exist(const std::shared_ptr & func) { const auto& ops = func->get_ops(); for (const auto& node : ops) { @@ -309,429 +299,124 @@ bool is_tensor_iterator_exist(const std::shared_ptr & func) { return false; } +namespace { + +template +std::vector convertPrecision(const std::vector &buffer, const size_t elementsCount) { + using fromPrec = fundamental_type_for; + using toPrec = fundamental_type_for; + + NGRAPH_CHECK(buffer.size() >= elementsCount * sizeof(fromPrec), "avoid buffer overflow"); + + constexpr auto elementSize = sizeof(toPrec); + std::vector convertedData(elementsCount * elementSize); + + const fromPrec *src = reinterpret_cast(buffer.data()); + toPrec *dst = reinterpret_cast(convertedData.data()); + for (size_t i = 0; i < elementsCount; i++) { + dst[i] = static_cast(src[i]); + } + return convertedData; +} + +template +std::vector convertPrecisionFrom(const std::vector &output, const element::Type_t &toPrecision, const size_t elementsCount) { + switch (toPrecision) { + case element::Type_t::boolean: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::bf16: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::f16: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::f32: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::f64: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::i8: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::i16: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::i32: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::i64: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::u8: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::u16: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::u32: { + return convertPrecision(output, elementsCount); + } + case element::Type_t::u64: { + return convertPrecision(output, elementsCount); + } + default: + throw std::runtime_error( + std::string("convertOutputPrecision can't convert from: ") + element::Type(FromType).get_type_name() + + " to: " + element::Type(toPrecision).get_type_name()); + } +} + +} // namespace std::vector convertOutputPrecision(const std::vector &output, const element::Type_t &fromPrecision, const element::Type_t &toPrecision, const size_t elementsCount) { switch (fromPrecision) { - case element::Type_t::u8: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::u16: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::i8: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::i16: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::i32: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::i64: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::u64: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::f32: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::boolean: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::boolean: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::f16: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::boolean: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - case element::Type_t::bf16: { - switch (toPrecision) { - case element::Type_t::u8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i8: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::i64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f32: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::f16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::bf16: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::u64: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - case element::Type_t::boolean: { - return convertPrecision(output, elementsCount, element::Type(toPrecision).size()); - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " to: " + - element::Type(toPrecision).get_type_name()); - } - } - default: - throw std::runtime_error("convertOutputPrecision can't convert from: " + element::Type(fromPrecision).get_type_name() + " precision"); + case element::Type_t::boolean: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::bf16: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::f16: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::f32: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::f64: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::i8: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::i16: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::i32: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::i64: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::u8: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::u16: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::u32: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + case element::Type_t::u64: { + return convertPrecisionFrom(output, toPrecision, elementsCount); + } + default: + throw std::runtime_error( + std::string("convertOutputPrecision can't convert from: ") + element::Type(fromPrecision).get_type_name() + + " precision"); } } From 576e75031776aeecd7bd4949e9d06751ed56e921 Mon Sep 17 00:00:00 2001 From: Patryk Elszkowski Date: Fri, 23 Apr 2021 06:31:04 +0200 Subject: [PATCH 60/78] Constant op class update for Low Precision (#5311) * add support for u1, u4 and i4 in op::v1::Constant * fix convert_i4_to_string test * Fix makeBinaryConvolution to fill memory allocated for LP types * Add unit-test for range validation Co-authored-by: Patryk Elszkowski --- .../src/binary_convolution.cpp | 4 +- ngraph/core/include/ngraph/op/constant.hpp | 347 ++++++++++--- ngraph/core/src/descriptor/tensor.cpp | 1 - ngraph/core/src/op/constant.cpp | 354 +++----------- ngraph/test/constant.cpp | 460 +++++++++++++++++- ngraph/test/int4.cpp | 2 +- 6 files changed, 806 insertions(+), 362 deletions(-) diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/binary_convolution.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/binary_convolution.cpp index eaaada3da2e..be08d36a9ba 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/binary_convolution.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/binary_convolution.cpp @@ -25,7 +25,7 @@ std::shared_ptr makeBinaryConvolution(const Output &in, std::vector filterWeightsShape = {numOutChannels, shape[1]}; filterWeightsShape.insert(filterWeightsShape.end(), filterSize.begin(), filterSize.end()); auto filterWeightsNode = std::make_shared(element::u1, filterWeightsShape); - size_t byteNum = ngraph::shape_size(filterWeightsShape) / sizeof(int8_t); + const size_t byteNum = (ngraph::shape_size(filterWeightsShape) + 7) / 8; int8_t *buffer = const_cast(filterWeightsNode->get_data_ptr()); if (filterWeihgts.size() == 0) { std::vector weihgts = NGraphFunctions::Utils::generateVector(byteNum); @@ -41,4 +41,4 @@ std::shared_ptr makeBinaryConvolution(const Output &in, } } // namespace builder -} // namespace ngraph \ No newline at end of file +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/constant.hpp b/ngraph/core/include/ngraph/op/constant.hpp index ce0fbc127b1..194d9d205df 100644 --- a/ngraph/core/include/ngraph/op/constant.hpp +++ b/ngraph/core/include/ngraph/op/constant.hpp @@ -6,7 +6,6 @@ #include #include -#include #include "ngraph/coordinate_diff.hpp" #include "ngraph/node.hpp" @@ -61,7 +60,7 @@ namespace ngraph if (values.size() == 1) { - write_values(std::vector(shape_size(m_shape), values[0])); + fill_data(type, values.front()); } else { @@ -83,6 +82,14 @@ namespace ngraph class = typename std::enable_if::value>::type> Constant(const element::Type& type, const Shape& shape, T value) : Constant(type, shape) + { + fill_data(type, value); + constructor_validate_and_infer_types(); + m_all_elements_bitwise_identical = true; + } + + template + void fill_data(const element::Type& type, T value) { using Type_t = element::Type_t; #if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) @@ -97,25 +104,23 @@ namespace ngraph case Type_t::f16: fill_data(value); break; case Type_t::f32: fill_data(value); break; case Type_t::f64: fill_data(value); break; + case Type_t::i4: fill_data(value); break; case Type_t::i8: fill_data(value); break; case Type_t::i16: fill_data(value); break; case Type_t::i32: fill_data(value); break; case Type_t::i64: fill_data(value); break; + case Type_t::u1: fill_data(value); break; + case Type_t::u4: fill_data(value); break; case Type_t::u8: fill_data(value); break; case Type_t::u16: fill_data(value); break; case Type_t::u32: fill_data(value); break; case Type_t::u64: fill_data(value); break; - case Type_t::i4: - case Type_t::u1: - case Type_t::u4: case Type_t::undefined: case Type_t::dynamic: throw std::runtime_error("unsupported type"); } #if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) #pragma GCC diagnostic pop #endif - constructor_validate_and_infer_types(); - m_all_elements_bitwise_identical = true; } /// \brief Constructs a tensor constant @@ -284,10 +289,13 @@ namespace ngraph case Type_t::f16: cast_vector(rc); break; case Type_t::f32: cast_vector(rc); break; case Type_t::f64: cast_vector(rc); break; + case Type_t::i4: cast_vector(rc); break; case Type_t::i8: cast_vector(rc); break; case Type_t::i16: cast_vector(rc); break; case Type_t::i32: cast_vector(rc); break; case Type_t::i64: cast_vector(rc); break; + case Type_t::u1: cast_vector(rc); break; + case Type_t::u4: cast_vector(rc); break; case Type_t::u8: cast_vector(rc); break; case Type_t::u16: cast_vector(rc); break; case Type_t::u32: cast_vector(rc); break; @@ -335,8 +343,52 @@ namespace ngraph m_alloc_buffer_on_visit_attributes = val; } - protected: - template + private: + template , + typename std::enable_if::type = true> + StorageDataType get_element_value(size_t index) const + { + return get_data_ptr()[index]; + } + + template , + typename std::enable_if::type = true> + StorageDataType get_element_value(size_t index) const + { + return (get_data_ptr()[index / 8] >> (7 - (index % 8))) & 1; + } + + template , + typename std::enable_if::type = true> + StorageDataType get_element_value(size_t index) const + { + return (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; + } + + template , + typename std::enable_if::type = true> + StorageDataType get_element_value(size_t index) const + { + const uint8_t i4data = + (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; + const bool is_negative_number = (i4data >> 3) & 0b1; + const int8_t data = is_negative_number ? i4data | 0xF0 : i4data; + return data; + } + + template ::type = true> void cast_vector(std::vector& output_vector) const { // this function is workaround for waring during windows building @@ -352,18 +404,116 @@ namespace ngraph [](IN_T c) { return static_cast(c); }); } + template ::type = true> + void cast_vector(std::vector& output) const + { + using IN_T = fundamental_type_for; + const auto element_number = shape_size(m_shape); + const auto source_begin = get_data_ptr(); + const auto source_end = std::next(source_begin, (element_number + 7) / 8); + const auto round_element_no = element_number % 8 + ? element_number - element_number % 8 + 8 + : element_number; + output.reserve(round_element_no); // adds 7 more elements here? + std::for_each(source_begin, source_end, [&](IN_T c) { + for (const auto i : {7, 6, 5, 4, 3, 2, 1, 0}) + { + const uint8_t data = (c >> i) & 0x01; + output.push_back(data); + } + }); + output.resize(element_number); + } + + template ::type = true> + void cast_vector(std::vector& output) const + { + using IN_T = fundamental_type_for; + const auto element_number = shape_size(m_shape); + const auto source_begin = get_data_ptr(); + const auto source_end = std::next(source_begin, (element_number + 1) / 2); + const auto round_element_no = + element_number % 2 ? element_number + 1 : element_number; + output.reserve(round_element_no); // adds 1 more elements here? + std::for_each(source_begin, source_end, [&](IN_T c) { + for (const auto i : {4, 0}) + { + const uint8_t data = (c >> i) & 0x0F; + output.push_back(data); + } + }); + output.resize(element_number); + } + template ::type = true> + void cast_vector(std::vector& output) const + { + using IN_T = fundamental_type_for; + const auto element_number = shape_size(m_shape); + const auto source_begin = get_data_ptr(); + const auto source_end = std::next(source_begin, (element_number + 1) / 2); + const auto round_element_no = + element_number % 2 ? element_number + 1 : element_number; + output.reserve(round_element_no); // adds 1 more elements here? + std::for_each(source_begin, source_end, [&](IN_T c) { + for (const auto i : {4, 0}) + { + const uint8_t i4data = (c >> i) & 0x0F; + const bool is_negative_number = (i4data >> 3) & 0b1; + const int8_t data = is_negative_number ? i4data | 0xF0 : i4data; + output.push_back(data); + } + }); + output.resize(element_number); + } + template > + typename StorageDataType = fundamental_type_for, + typename std::enable_if::type = true> void fill_data(const T& value) { const auto size = shape_size(m_shape); - std::fill_n(get_data_ptr_nc(), size, static_cast(value)); + const auto v = static_cast(value); + std::fill_n(get_data_ptr_nc(), size, v); + } + + template , + typename std::enable_if::type = true> + void fill_data(const T& value) + { + const StorageDataType v = value ? 0xFF : 0x00; + std::fill_n(get_data_ptr_nc(), mem_size(), v); + } + + template , + typename std::enable_if::type = true> + void fill_data(const T& value) + { + uint8_t v = value_in_range(value); + v &= 0x0F; + v += v << 4; + std::fill_n(get_data_ptr_nc(), mem_size(), v); } void allocate_buffer(); void* get_data_ptr_nc() { return (m_data ? m_data->get_ptr() : nullptr); } + template typename element_type_traits::value_type* get_data_ptr_nc() { @@ -383,31 +533,87 @@ namespace ngraph template void write_values(const std::vector& values) { - write_to_buffer( - m_element_type, m_shape, values, get_data_ptr_nc(), shape_size(m_shape)); + write_to_buffer(values); } - template - static void write_buffer(void* target, const std::vector& source, size_t count) + template , + typename std::enable_if::type = true> + void write_buffer(const std::vector& source) { - T* p = reinterpret_cast(target); - for (size_t i = 0; i < count; i++) + auto p = get_data_ptr_nc(); + for (size_t i = 0; i < source.size(); i++) { - p[i] = static_cast(source[i]); + p[i] = static_cast(source[i]); } } - template - static void write_to_buffer(const element::Type& target_type, - const Shape& /* target_shape */, - const std::vector& source, - void* target, - size_t target_element_count) + template , + typename std::enable_if::type = true> + void write_buffer(const std::vector& source) { + auto p = get_data_ptr_nc(); + size_t i = 0; + for (; i < source.size() / 2; i++) + { + const auto v1 = value_in_range(source[i * 2]) & 0x0F; + const auto v2 = value_in_range(source[i * 2 + 1]) & 0x0F; + const auto v = (v1 << 4) | v2; + p[i] = static_cast(v); + } + if (source.size() % 2) + { + const auto v1 = value_in_range(source[i * 2]) & 0x0F; + const auto v = v1 << 4; + p[i] = static_cast(v); + } + } + + template , + typename std::enable_if::type = true> + void write_buffer(const std::vector& source) + { + auto p = get_data_ptr_nc(); + size_t i = 0; + for (; i < source.size() / 8; i++) + { + uint8_t v{}; + for (int j = 0; j != 8; j++) + { + const uint8_t b = source[i * 8 + j] ? 0x01 << (7 - j) : 0; + v |= b; + } + p[i] = static_cast(v); + } + uint8_t v{}; + for (unsigned j = 0; j != source.size() % 8; j++) + { + const uint8_t b = source[i * 8 + j] ? 0x01 << (7 - j) : 0; + v |= b; + } + p[i] = static_cast(v); + } + + template + void write_to_buffer(const std::vector& source) + { + const auto& target_type = m_element_type; + size_t target_element_count = shape_size(m_shape); if (source.size() != target_element_count) { throw std::runtime_error("Constant initializer does not match shape"); } + using Type_t = element::Type_t; #if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wswitch" @@ -415,48 +621,22 @@ namespace ngraph #endif switch (target_type) { - case element::Type_t::boolean: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::bf16: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::f16: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::f32: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::f64: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::i8: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::i16: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::i32: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::i64: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::u8: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::u16: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::u32: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::u64: - write_buffer(target, source, target_element_count); - break; - case element::Type_t::i4: - case element::Type_t::u1: - case element::Type_t::u4: + case Type_t::boolean: write_buffer(source); break; + case Type_t::bf16: write_buffer(source); break; + case Type_t::f16: write_buffer(source); break; + case Type_t::f32: write_buffer(source); break; + case Type_t::f64: write_buffer(source); break; + case Type_t::i4: write_buffer(source); break; + case Type_t::i8: write_buffer(source); break; + case Type_t::i16: write_buffer(source); break; + case Type_t::i32: write_buffer(source); break; + case Type_t::i64: write_buffer(source); break; + case Type_t::u1: write_buffer(source); break; + case Type_t::u4: write_buffer(source); break; + case Type_t::u8: write_buffer(source); break; + case Type_t::u16: write_buffer(source); break; + case Type_t::u32: write_buffer(source); break; + case Type_t::u64: write_buffer(source); break; case element::Type_t::undefined: case element::Type_t::dynamic: throw std::runtime_error("unsupported type"); } @@ -464,10 +644,45 @@ namespace ngraph #pragma GCC diagnostic pop #endif } + template < + ngraph::element::Type_t Type, + typename std::enable_if::type = true> + static ngraph::fundamental_type_for + value_in_range(const ngraph::fundamental_type_for& value) + { + NGRAPH_CHECK(0 <= value && value <= 15, + "assigned value out of range u4 values"); + return value; + } + + template < + ngraph::element::Type_t Type, + typename std::enable_if::type = true> + static ngraph::fundamental_type_for + value_in_range(const ngraph::fundamental_type_for& value) + { + NGRAPH_CHECK(-8 <= value && value <= 7, + "assigned value out of range i4 values"); + return value; + } bool are_all_data_elements_bitwise_identical() const; static constexpr size_t host_alignment() { return 64; } + size_t mem_size() const + { + const bool bitwidth_less_than_byte = m_element_type.bitwidth() < 8; + if (bitwidth_less_than_byte) + { + const auto size = shape_size(m_shape); + const auto bitwidth = size * m_element_type.bitwidth(); + // for rounding by `(bitwidth + 7) / 8` will work for + // `bitwidth < numeric_limits::max() - 7` + return bitwidth / 8 + (bitwidth % 8 ? 1 : 0); + } + return shape_size(m_shape) * m_element_type.size(); + } + element::Type m_element_type; Shape m_shape{}; std::shared_ptr m_data; diff --git a/ngraph/core/src/descriptor/tensor.cpp b/ngraph/core/src/descriptor/tensor.cpp index 081fcbcf8be..58b06df90ad 100644 --- a/ngraph/core/src/descriptor/tensor.cpp +++ b/ngraph/core/src/descriptor/tensor.cpp @@ -96,7 +96,6 @@ size_t descriptor::Tensor::size() const const bool bitwidth_less_than_byte = m_element_type.bitwidth() < 8; if (bitwidth_less_than_byte) { - // TODO consider caching this value return ceil((1.0 * shape_size(get_shape()) * m_element_type.bitwidth()) / 8); } return shape_size(get_shape()) * m_element_type.size(); diff --git a/ngraph/core/src/op/constant.cpp b/ngraph/core/src/op/constant.cpp index 74471cc9f57..ef3134c95c9 100644 --- a/ngraph/core/src/op/constant.cpp +++ b/ngraph/core/src/op/constant.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "itt.hpp" #include "ngraph/log.hpp" @@ -17,7 +18,7 @@ using namespace ngraph; using namespace std; template -string to_cpp_string(T value) +static inline string to_cpp_string(T value) { string rc; if (std::isnan(value)) @@ -63,122 +64,31 @@ op::Constant::Constant(const element::Type& type, constructor_validate_and_infer_types(); + using Type_t = element::Type_t; + if (values.size() == 1 && shape_size(m_shape) != 1) { // broadcast single value switch (m_element_type) { - case element::Type_t::boolean: - { - bool value = stoi(values[0]) != 0; - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::bf16: - { - bfloat16 value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::f16: - { - float16 value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::f32: - { - float value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::f64: - { - double value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::i8: - { - int8_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::i16: - { - int16_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::i32: - { - int32_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::i64: - { - int64_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::u8: - { - uint8_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::u16: - { - uint16_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::u32: - { - uint32_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::u64: - { - uint64_t value = parse_string(values[0]); - auto target = get_data_ptr_nc(); - std::fill(target, target + shape_size(m_shape), value); - break; - } - case element::Type_t::undefined: - { - throw std::runtime_error("deserialize unsupported type undefined"); - } - case element::Type_t::dynamic: - { - throw std::runtime_error("deserialize unsupported type dynamic"); - } - case element::Type_t::i4: - { - throw std::runtime_error("deserialize unsupported type i4"); - } - case element::Type_t::u4: - { - throw std::runtime_error("deserialize unsupported type u4"); - } - case element::Type_t::u1: - { - throw std::runtime_error("deserialize unsupported type u1"); - } + case Type_t::boolean: fill_data(stoi(values[0])); break; + case Type_t::bf16: fill_data(parse_string(values[0])); break; + case Type_t::f16: fill_data(parse_string(values[0])); break; + case Type_t::f32: fill_data(parse_string(values[0])); break; + case Type_t::f64: fill_data(parse_string(values[0])); break; + case Type_t::i4: fill_data(parse_string(values[0])); break; + case Type_t::i8: fill_data(parse_string(values[0])); break; + case Type_t::i16: fill_data(parse_string(values[0])); break; + case Type_t::i32: fill_data(parse_string(values[0])); break; + case Type_t::i64: fill_data(parse_string(values[0])); break; + case Type_t::u1: fill_data(stoi(values[0])); break; + case Type_t::u4: fill_data(parse_string(values[0])); break; + case Type_t::u8: fill_data(parse_string(values[0])); break; + case Type_t::u16: fill_data(parse_string(values[0])); break; + case Type_t::u32: fill_data(parse_string(values[0])); break; + case Type_t::u64: fill_data(parse_string(values[0])); break; + case Type_t::undefined: throw std::runtime_error("deserialize unsupported type undefined"); + case Type_t::dynamic: throw std::runtime_error("deserialize unsupported type dynamic"); } m_all_elements_bitwise_identical = true; } @@ -186,110 +96,24 @@ op::Constant::Constant(const element::Type& type, { switch (m_element_type) { - case element::Type_t::boolean: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::bf16: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - for (size_t i = 0; i < value.size(); i++) - { - target[i] = value[i]; - } - break; - } - case element::Type_t::f16: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - for (size_t i = 0; i < value.size(); i++) - { - target[i] = value[i]; - } - break; - } - case element::Type_t::f32: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::f64: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::i8: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::i16: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::i32: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::i64: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::u8: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::u16: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::u32: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::u64: - { - vector value = parse_string(values); - auto target = get_data_ptr_nc(); - std::copy(value.begin(), value.end(), target); - break; - } - case element::Type_t::undefined: - throw std::runtime_error("deserialize unsupported type undefined"); - case element::Type_t::dynamic: - throw std::runtime_error("deserialize unsupported type dynamic"); - case element::Type_t::i4: throw std::runtime_error("deserialize unsupported type i4"); - case element::Type_t::u4: throw std::runtime_error("deserialize unsupported type u4"); - case element::Type_t::u1: throw std::runtime_error("deserialize unsupported type u1"); + case Type_t::boolean: write_buffer(parse_string(values)); break; + case Type_t::bf16: write_buffer(parse_string(values)); break; + case Type_t::f16: write_buffer(parse_string(values)); break; + case Type_t::f32: write_buffer(parse_string(values)); break; + case Type_t::f64: write_buffer(parse_string(values)); break; + case Type_t::i4: write_buffer(parse_string(values)); break; + case Type_t::i8: write_buffer(parse_string(values)); break; + case Type_t::i16: write_buffer(parse_string(values)); break; + case Type_t::i32: write_buffer(parse_string(values)); break; + case Type_t::i64: write_buffer(parse_string(values)); break; + case Type_t::u1: write_buffer(parse_string(values)); break; + case Type_t::u4: write_buffer(parse_string(values)); break; + case Type_t::u8: write_buffer(parse_string(values)); break; + case Type_t::u16: write_buffer(parse_string(values)); break; + case Type_t::u32: write_buffer(parse_string(values)); break; + case Type_t::u64: write_buffer(parse_string(values)); break; + case Type_t::undefined: throw std::runtime_error("deserialize unsupported type undefined"); + case Type_t::dynamic: throw std::runtime_error("deserialize unsupported type dynamic"); } m_all_elements_bitwise_identical = are_all_data_elements_bitwise_identical(); } @@ -305,8 +129,7 @@ op::Constant::Constant(const element::Type& type, const Shape& shape) void op::Constant::allocate_buffer() { - m_data = make_shared(shape_size(m_shape) * m_element_type.size(), - host_alignment()); + m_data = make_shared(mem_size(), host_alignment()); std::memset(m_data->get_ptr(), 0, m_data->size()); } @@ -338,45 +161,31 @@ string op::Constant::convert_value_to_string(size_t index) const #pragma GCC diagnostic error "-Wswitch" #pragma GCC diagnostic error "-Wswitch-enum" #endif + using Type_t = element::Type_t; switch (get_element_type()) { - case element::Type_t::boolean: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::bf16: - rc = to_cpp_string(static_cast(get_data_ptr()[index])); + case Type_t::boolean: rc = to_string(get_element_value(index)); break; + case Type_t::bf16: + rc = to_cpp_string(static_cast(get_element_value(index))); break; - case element::Type_t::f16: - rc = to_cpp_string(static_cast(get_data_ptr()[index])); + case Type_t::f16: + rc = to_cpp_string(static_cast(get_element_value(index))); break; - case element::Type_t::f32: rc = to_cpp_string(get_data_ptr()[index]); break; - case element::Type_t::f64: rc = to_cpp_string(get_data_ptr()[index]); break; - case element::Type_t::i4: - { - uint8_t i4data = (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; - int8_t data = i4data; - if ((i4data >> 3) & 0b1) - { - // negative number - data = (i4data & 0x7) | 0xF0; - } - rc = to_string(data); - break; - } - case element::Type_t::u4: - rc = to_string((get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F); - break; - case element::Type_t::i8: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::i16: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::i32: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::i64: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::u1: - rc = to_string((get_data_ptr()[index / 8] >> (7 - (index % 8))) & 1); - break; - case element::Type_t::u8: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::u16: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::u32: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::u64: rc = to_string(get_data_ptr()[index]); break; - case element::Type_t::undefined: throw runtime_error("unsupported type"); - case element::Type_t::dynamic: throw runtime_error("unsupported type"); + case Type_t::f32: rc = to_cpp_string(get_element_value(index)); break; + case Type_t::f64: rc = to_cpp_string(get_element_value(index)); break; + case Type_t::i4: rc = to_string(get_element_value(index)); break; + case Type_t::i8: rc = to_string(get_element_value(index)); break; + case Type_t::i16: rc = to_string(get_element_value(index)); break; + case Type_t::i32: rc = to_string(get_element_value(index)); break; + case Type_t::i64: rc = to_string(get_element_value(index)); break; + case Type_t::u1: rc = to_string(get_element_value(index)); break; + case Type_t::u4: rc = to_string(get_element_value(index)); break; + case Type_t::u8: rc = to_string(get_element_value(index)); break; + case Type_t::u16: rc = to_string(get_element_value(index)); break; + case Type_t::u32: rc = to_string(get_element_value(index)); break; + case Type_t::u64: rc = to_string(get_element_value(index)); break; + case Type_t::undefined: throw runtime_error("unsupported type"); + case Type_t::dynamic: throw runtime_error("unsupported type"); } #if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) #pragma GCC diagnostic pop @@ -425,6 +234,12 @@ vector op::Constant::get_value_strings() const rc.push_back(to_cpp_string(value)); } break; + case element::Type_t::i4: + for (auto value : cast_vector()) + { + rc.push_back(to_string(value)); + } + break; case element::Type_t::i8: for (int value : get_vector()) { @@ -449,6 +264,13 @@ vector op::Constant::get_value_strings() const rc.push_back(to_string(value)); } break; + case element::Type_t::u1: + case element::Type_t::u4: + for (auto value : cast_vector()) + { + rc.push_back(to_string(value)); + } + break; case element::Type_t::u8: for (uint32_t value : get_vector()) { @@ -473,9 +295,6 @@ vector op::Constant::get_value_strings() const rc.push_back(to_string(value)); } break; - case element::Type_t::u1: - case element::Type_t::i4: - case element::Type_t::u4: case element::Type_t::undefined: case element::Type_t::dynamic: throw runtime_error("unsupported type"); } @@ -677,26 +496,3 @@ bool op::v0::Constant::evaluate_upper(const HostTensorVector& outputs) const { return evaluate(outputs, {}); } - -// -// We have to open up namespace blocks here to work around a problem with gcc: -// -// https://stackoverflow.com/questions/25594644/warning-specialization-of-template-in-different-namespace -// -namespace ngraph -{ - namespace op - { - namespace v0 - { - template <> - void Constant::write_to_buffer(const element::Type& /* target_type */, - const Shape& /* target_shape */, - const vector& /* source */, - void* /* target */, - size_t /* target_element_count */) - { - } - } // namespace v0 - } // namespace op -} // namespace ngraph diff --git a/ngraph/test/constant.cpp b/ngraph/test/constant.cpp index 81400021c6c..5de4e73eb9a 100644 --- a/ngraph/test/constant.cpp +++ b/ngraph/test/constant.cpp @@ -19,7 +19,8 @@ using namespace std; TEST(constant, boolean_string) { Shape shape{4}; - op::Constant c(element::boolean, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::boolean, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -32,6 +33,13 @@ TEST(constant, boolean_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, boolean_string_broadcast) @@ -95,7 +103,8 @@ TEST(constant, boolean_vector_broadcast) TEST(constant, float_string) { Shape shape{4}; - op::Constant c(element::f32, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::f32, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -108,6 +117,13 @@ TEST(constant, float_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, float_string_broadcast) @@ -171,7 +187,8 @@ TEST(constant, float_vector_broadcast) TEST(constant, double_string) { Shape shape{4}; - op::Constant c(element::f64, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::f64, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -184,6 +201,13 @@ TEST(constant, double_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, double_string_broadcast) @@ -240,6 +264,147 @@ TEST(constant, double_vector_broadcast) EXPECT_EQ(p[3], 1); } +// +// int4 +// + +TEST(constant, int4_string) +{ + Shape shape{3}; + std::vector input{"1", "0", "-1"}; + op::Constant c(element::i4, shape, input); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 0); + EXPECT_EQ(v[2], -1); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0x10, p[0]); + EXPECT_EQ(0xF0, p[1] & 0xF0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } +} + +TEST(constant, int4_string_broadcast_negative_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{"-1"}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], -1); + EXPECT_EQ(v[1], -1); + EXPECT_EQ(v[2], -1); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0xFF, p[0]); + EXPECT_EQ(0xF0, p[1] & 0xF0); + + EXPECT_EQ(std::vector(3, "-1"), c.get_value_strings()); +} + +TEST(constant, int4_string_broadcast_positive_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{"1"}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 1); + EXPECT_EQ(v[2], 1); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0x11, p[0]); + EXPECT_EQ(0x10, p[1] & 0xF0); + + EXPECT_EQ(std::vector(3, "1"), c.get_value_strings()); +} + +TEST(constant, int4_vector_negative_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{-1, -2, -1}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(-1)); + EXPECT_EQ(v[1], int8_t(-2)); + EXPECT_EQ(v[2], int8_t(-1)); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0xFE, p[0]); + EXPECT_EQ(0xF0, p[1] & 0xF0); +} + +TEST(constant, int4_vector_positive_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{1, 2, 5}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(1)); + EXPECT_EQ(v[1], int8_t(2)); + EXPECT_EQ(v[2], int8_t(5)); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0x12, p[0]); + EXPECT_EQ(0x50, p[1] & 0xF0); +} + +TEST(constant, int4_vector_broadcast_negative_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{-1}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(-1)); + EXPECT_EQ(v[1], int8_t(-1)); + EXPECT_EQ(v[2], int8_t(-1)); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0xFF, p[0]); + EXPECT_EQ(0xF0, p[1] & 0xF0); +} + +TEST(constant, int4_vector_broadcast_positive_number) +{ + Shape shape{3}; + op::Constant c(element::i4, shape, vector{3}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(3)); + EXPECT_EQ(v[1], int8_t(3)); + EXPECT_EQ(v[2], int8_t(3)); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0x33, p[0]); + EXPECT_EQ(0x30, p[1] & 0xF0); +} + +TEST(constant, int4_input_value_validation) +{ + Shape shape{2}; + EXPECT_THROW(op::Constant c(element::i4, shape, 8), ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::i4, shape, -9), ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{-9}), ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{8}), ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{-9, 1}), + ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{8, 2}), + ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{"-9", "1"}), + ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::i4, shape, std::vector{"8", "1"}), + ::ngraph::CheckFailure); +} + // // int8 // @@ -247,7 +412,8 @@ TEST(constant, double_vector_broadcast) TEST(constant, int8_string) { Shape shape{4}; - op::Constant c(element::i8, shape, vector{"1", "0", "1", "0"}); + std::vector input{"1", "0", "1", "0"}; + op::Constant c(element::i8, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -260,6 +426,15 @@ TEST(constant, int8_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, int8_string_broadcast) @@ -278,6 +453,8 @@ TEST(constant, int8_string_broadcast) EXPECT_EQ(p[1], 1); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 1); + + EXPECT_EQ(std::vector(4, "1"), c.get_value_strings()); } TEST(constant, int8_vector) @@ -323,7 +500,8 @@ TEST(constant, int8_vector_broadcast) TEST(constant, int16_string) { Shape shape{4}; - op::Constant c(element::i16, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::i16, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -336,6 +514,13 @@ TEST(constant, int16_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, int16_string_broadcast) @@ -399,7 +584,8 @@ TEST(constant, int16_vector_broadcast) TEST(constant, int32_string) { Shape shape{4}; - op::Constant c(element::i32, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::i32, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -412,6 +598,13 @@ TEST(constant, int32_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, int32_string_broadcast) @@ -475,7 +668,8 @@ TEST(constant, int32_vector_broadcast) TEST(constant, int64_string) { Shape shape{4}; - op::Constant c(element::i64, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::i64, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -488,6 +682,13 @@ TEST(constant, int64_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, int64_string_broadcast) @@ -544,6 +745,191 @@ TEST(constant, int64_vector_broadcast) EXPECT_EQ(p[3], 1); } +// +// uint1 +// + +TEST(constant, uint1_string) +{ + Shape shape{4}; + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u1, shape, input); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 0); + EXPECT_EQ(v[2], 1); + EXPECT_EQ(v[3], 0); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0], 0b10100000); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } +} + +TEST(constant, uint1_string_broadcast) +{ + Shape shape{4}; + op::Constant c(element::u1, shape, vector{"1"}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 1); + EXPECT_EQ(v[2], 1); + EXPECT_EQ(v[3], 1); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0] & 0b11110000, 0b11110000); +} + +TEST(constant, uint1_vector_less_than_single_byte) +{ + Shape shape{4}; + vector input{1, 0, 1, 0}; + op::Constant c(element::u1, shape, input); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(v[i], input[i]) << "Error on index: " << i; + } + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0] & 0b11110000, 0b10100000); +} + +TEST(constant, uint1_vector_bigger_than_single_byte) +{ + Shape shape{12}; + vector input{1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; + op::Constant c(element::u1, shape, input); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(v[i], input[i]) << "Error on index: " << i; + } + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0] & 0b11110000, 0b10100000); +} + +TEST(constant, uint1_vector_broadcast) +{ + Shape shape{3}; + op::Constant c(element::u1, shape, vector{1}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(1)); + EXPECT_EQ(v[1], int8_t(1)); + EXPECT_EQ(v[2], int8_t(1)); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(0xE0, p[0] & 0xE0); +} + +// +// uint4 +// + +TEST(constant, uint4_string) +{ + Shape shape{4}; + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u4, shape, input); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 0); + EXPECT_EQ(v[2], 1); + EXPECT_EQ(v[3], 0); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0], 0x10); + EXPECT_EQ(p[1], 0x10); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } +} + +TEST(constant, uint4_string_broadcast) +{ + Shape shape{4}; + op::Constant c(element::u4, shape, vector{"1"}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 1); + EXPECT_EQ(v[2], 1); + EXPECT_EQ(v[3], 1); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0], 0x11); + EXPECT_EQ(p[1], 0x11); +} + +TEST(constant, uint4_vector) +{ + Shape shape{4}; + op::Constant c(element::u4, shape, vector{1, 0, 1, 0}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], 1); + EXPECT_EQ(v[1], 0); + EXPECT_EQ(v[2], 1); + EXPECT_EQ(v[3], 0); + + const auto p = c.get_data_ptr(); + EXPECT_EQ(p[0], 0x10); + EXPECT_EQ(p[1], 0x10); +} + +TEST(constant, uint4_vector_broadcast) +{ + Shape shape{3}; + op::Constant c(element::u4, shape, vector{1}); + auto v = c.cast_vector(); + ASSERT_EQ(v.size(), shape_size(shape)); + EXPECT_EQ(v[0], int8_t(1)); + EXPECT_EQ(v[1], int8_t(1)); + EXPECT_EQ(v[2], int8_t(1)); + + const auto p = c.get_data_ptr(); + const auto first_byte = p[0]; + const auto second_byte = p[1] & 0xF0; + EXPECT_EQ(0x11, first_byte); + EXPECT_EQ(0x10, second_byte); +} + +TEST(constant, uint4_input_value_validation) +{ + Shape shape{2}; + EXPECT_THROW(op::Constant c(element::u4, shape, 16), ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::u4, shape, -1), ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{-1}), ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{16}), ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{-1, 1}), + ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{16, 2}), + ::ngraph::CheckFailure); + + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{"-1", "1"}), + ::ngraph::CheckFailure); + EXPECT_THROW(op::Constant c(element::u4, shape, std::vector{"16", "1"}), + ::ngraph::CheckFailure); +} + // // uint8 // @@ -551,7 +937,8 @@ TEST(constant, int64_vector_broadcast) TEST(constant, uint8_string) { Shape shape{4}; - op::Constant c(element::u8, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u8, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -564,6 +951,13 @@ TEST(constant, uint8_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, uint8_string_broadcast) @@ -627,7 +1021,8 @@ TEST(constant, uint8_vector_broadcast) TEST(constant, uint16_string) { Shape shape{4}; - op::Constant c(element::u16, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u16, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -640,6 +1035,13 @@ TEST(constant, uint16_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, uint16_string_broadcast) @@ -703,7 +1105,8 @@ TEST(constant, uint16_vector_broadcast) TEST(constant, uint32_string) { Shape shape{4}; - op::Constant c(element::u32, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u32, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -716,6 +1119,13 @@ TEST(constant, uint32_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, uint32_string_broadcast) @@ -779,7 +1189,8 @@ TEST(constant, uint32_vector_broadcast) TEST(constant, uint64_string) { Shape shape{4}; - op::Constant c(element::u64, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::u64, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], 1); @@ -792,6 +1203,13 @@ TEST(constant, uint64_string) EXPECT_EQ(p[1], 0); EXPECT_EQ(p[2], 1); EXPECT_EQ(p[3], 0); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, uint64_string_broadcast) @@ -855,7 +1273,8 @@ TEST(constant, uint64_vector_broadcast) TEST(constant, bfloat16_string) { Shape shape{4}; - op::Constant c(element::bf16, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::bf16, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], bfloat16(1)); @@ -868,6 +1287,13 @@ TEST(constant, bfloat16_string) EXPECT_EQ(p[1], bfloat16(0)); EXPECT_EQ(p[2], bfloat16(1)); EXPECT_EQ(p[3], bfloat16(0)); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, bfloat16_string_broadcast) @@ -931,7 +1357,8 @@ TEST(constant, bfloat16_vector_broadcast) TEST(constant, float16_string) { Shape shape{4}; - op::Constant c(element::f16, shape, vector{"1", "0", "1", "0"}); + vector input{"1", "0", "1", "0"}; + op::Constant c(element::f16, shape, input); auto v = c.get_vector(); ASSERT_EQ(v.size(), shape_size(shape)); EXPECT_EQ(v[0], float16(1)); @@ -944,6 +1371,13 @@ TEST(constant, float16_string) EXPECT_EQ(p[1], float16(0)); EXPECT_EQ(p[2], float16(1)); EXPECT_EQ(p[3], float16(0)); + + EXPECT_EQ(input, c.get_value_strings()); + + for (unsigned i = 0; i != input.size(); ++i) + { + EXPECT_EQ(input[i], c.convert_value_to_string(i)); + } } TEST(constant, float16_string_broadcast) diff --git a/ngraph/test/int4.cpp b/ngraph/test/int4.cpp index c1910faa0b0..b933cf60cbb 100644 --- a/ngraph/test/int4.cpp +++ b/ngraph/test/int4.cpp @@ -15,7 +15,7 @@ TEST(int4, convert_i4_to_string) vector values{171, 16}; auto constant = make_shared(element::i4, Shape{3}, &values[0]); - vector ref{"-14", "-13", "1"}; + vector ref{"-6", "-5", "1"}; for (size_t i = 0; i < 3; ++i) { ASSERT_EQ(constant->convert_value_to_string(i), ref[i]); From 4073e16a9eb2d9ddc2e1a84aab6b386358175df1 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 23 Apr 2021 09:27:39 +0300 Subject: [PATCH 61/78] Fixed compilation for deprecated API (#5356) * Fixed compilation of offline API * Fixed compilation with gcc 5.4 * Fixed compilation of ONNX importer dependencies --- .../openvino/inference_engine/CMakeLists.txt | 3 +- .../openvino/inference_engine/ie_api_impl.cpp | 42 ++++++------------- .../openvino/inference_engine/ie_api_impl.hpp | 3 +- .../offline_transformations/CMakeLists.txt | 3 +- inference-engine/include/ie_api.h | 3 +- ngraph/cmake/external_onnx.cmake | 2 +- ngraph/cmake/external_protobuf.cmake | 4 +- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt index a2297ad197b..83fe8cf21d2 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt @@ -22,8 +22,7 @@ disable_deprecated_warnings() cython_add_module(${TARGET_NAME} ${SOURCE}) set(INSTALLED_TARGETS ${TARGET_NAME}) -file(GLOB OTHER_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/*.pyx) +file(GLOB OTHER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.pyx) list(REMOVE_ITEM OTHER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/ie_api.pyx") foreach(PYX_FILE ${OTHER_SOURCES}) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp index d8967c54abb..d55ddd1333c 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp @@ -39,15 +39,13 @@ std::map layout_map = {{"ANY", Infere } \ -uint32_t getOptimalNumberOfRequests(const InferenceEngine::IExecutableNetwork::Ptr actual) { +uint32_t getOptimalNumberOfRequests(const InferenceEngine::ExecutableNetwork & actual) { try { - InferenceEngine::ResponseDesc response; - InferenceEngine::Parameter parameter_value; - IE_CHECK_CALL(actual->GetMetric(METRIC_KEY(SUPPORTED_METRICS), parameter_value, &response)); + auto parameter_value = actual.GetMetric(METRIC_KEY(SUPPORTED_METRICS)); auto supported_metrics = parameter_value.as < std::vector < std::string >> (); - std::string key = METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS); + const std::string key = METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS); if (std::find(supported_metrics.begin(), supported_metrics.end(), key) != supported_metrics.end()) { - IE_CHECK_CALL(actual->GetMetric(key, parameter_value, &response)); + parameter_value = actual.GetMetric(key); if (parameter_value.is()) return parameter_value.as(); else @@ -292,35 +290,23 @@ void InferenceEnginePython::IEExecNetwork::infer() { } InferenceEnginePython::IENetwork InferenceEnginePython::IEExecNetwork::GetExecGraphInfo() { - InferenceEngine::ResponseDesc response; - InferenceEngine::ICNNNetwork::Ptr graph; - IE_CHECK_CALL(actual->GetExecGraphInfo(graph, &response)); - return IENetwork(std::make_shared(graph)); + return IENetwork(std::make_shared(actual.GetExecGraphInfo())); } PyObject *InferenceEnginePython::IEExecNetwork::getMetric(const std::string &metric_name) { - InferenceEngine::Parameter parameter; - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->GetMetric(metric_name, parameter, &response)); - return parse_parameter(parameter); + return parse_parameter(actual.GetMetric(metric_name)); } PyObject *InferenceEnginePython::IEExecNetwork::getConfig(const std::string &name) { - InferenceEngine::Parameter parameter; - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->GetConfig(name, parameter, &response)); - return parse_parameter(parameter); + return parse_parameter(actual.GetConfig(name)); } void InferenceEnginePython::IEExecNetwork::exportNetwork(const std::string &model_file) { - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->Export(model_file, &response)); + actual.Export(model_file); } std::map InferenceEnginePython::IEExecNetwork::getInputs() { - InferenceEngine::ConstInputsDataMap inputsDataMap; - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->GetInputsInfo(inputsDataMap, &response)); + InferenceEngine::ConstInputsDataMap inputsDataMap = actual.GetInputsInfo(); std::map pyInputs; for (const auto &item : inputsDataMap) { pyInputs[item.first] = item.second->getInputData(); @@ -329,9 +315,7 @@ std::map InferenceEnginePython::IEExecNe } std::map InferenceEnginePython::IEExecNetwork::getInputsInfo() { - InferenceEngine::ConstInputsDataMap inputsDataMap; - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->GetInputsInfo(inputsDataMap, &response)); + InferenceEngine::ConstInputsDataMap inputsDataMap = actual.GetInputsInfo(); std::map pyInputs; for (const auto &item : inputsDataMap) { pyInputs[item.first] = item.second; @@ -340,9 +324,7 @@ std::map InferenceEnginePython:: } std::map InferenceEnginePython::IEExecNetwork::getOutputs() { - InferenceEngine::ConstOutputsDataMap outputsDataMap; - InferenceEngine::ResponseDesc response; - IE_CHECK_CALL(actual->GetOutputsInfo(outputsDataMap, &response)); + InferenceEngine::ConstOutputsDataMap outputsDataMap = actual.GetOutputsInfo(); std::map pyOutputs; for (const auto &item : outputsDataMap) { pyOutputs[item.first] = item.second; @@ -525,7 +507,7 @@ void InferenceEnginePython::IEExecNetwork::createInferRequests(int num_requests) infer_request.index = i; request_queue_ptr->setRequestIdle(i); infer_request.request_queue_ptr = request_queue_ptr; - IE_CHECK_CALL(actual->CreateInferRequest(infer_request.request_ptr, &response)) + infer_request.request_ptr = actual.CreateInferRequest(); IE_CHECK_CALL(infer_request.request_ptr->SetUserData(&infer_request, &response)); infer_request.request_ptr->SetCompletionCallback(latency_callback); } diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp index 0faab4baccd..901ad408ebc 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp @@ -23,7 +23,6 @@ #include #include -#include typedef std::chrono::high_resolution_clock Time; typedef std::chrono::nanoseconds ns; @@ -128,7 +127,7 @@ struct InferRequestWrap { struct IEExecNetwork { - InferenceEngine::IExecutableNetwork::Ptr actual; + InferenceEngine::ExecutableNetwork actual; std::vector infer_requests; std::string name; IdleInferRequestQueue::Ptr request_queue_ptr; diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/CMakeLists.txt b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/CMakeLists.txt index 9c67863f0d4..11be34b222e 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/CMakeLists.txt @@ -34,7 +34,8 @@ else() list(APPEND InferenceEngine_LIBRARIES IE::offline_transformations) endif() -target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../inference_engine") +target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inference_engine") +target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TARGET_NAME} PRIVATE ${InferenceEngine_LIBRARIES}) # Compatibility with python 2.7 which has deprecated "register" specifier diff --git a/inference-engine/include/ie_api.h b/inference-engine/include/ie_api.h index 2f64b23313a..327cf522f52 100644 --- a/inference-engine/include/ie_api.h +++ b/inference-engine/include/ie_api.h @@ -88,7 +88,8 @@ # define _IE_SUPPRESS_DEPRECATED_END_MSVC #endif -#if defined __GNUC__ && (__GNUC__ <= 4 || defined __i386__ || defined __arm__ || defined __aarch64__) +#if defined __GNUC__ && (__GNUC__ <= 4 || (__GNUC__ == 5 && __GNUC_MINOR__ <= 5) || \ + (defined __i386__ || defined __arm__ || defined __aarch64__)) # define _IE_SUPPRESS_DEPRECATED_START_GCC IE_SUPPRESS_DEPRECATED_START # define _IE_SUPPRESS_DEPRECATED_END_GCC IE_SUPPRESS_DEPRECATED_END #else diff --git a/ngraph/cmake/external_onnx.cmake b/ngraph/cmake/external_onnx.cmake index 7bf427e1a79..56921d2d3ad 100644 --- a/ngraph/cmake/external_onnx.cmake +++ b/ngraph/cmake/external_onnx.cmake @@ -35,7 +35,7 @@ macro(onnx_set_target_properties) target_compile_options(onnx PRIVATE /WX-) elseif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") target_compile_options(onnx PRIVATE -Wno-all) - target_compile_options(onnx_proto PRIVATE -Wno-all) + target_compile_options(onnx_proto PRIVATE -Wno-all -Wno-unused-variable) # it fixes random problems with double registration of descriptors to protobuf database set_target_properties(onnx_proto PROPERTIES diff --git a/ngraph/cmake/external_protobuf.cmake b/ngraph/cmake/external_protobuf.cmake index 4cba9620c71..ff7b7a2a9d2 100644 --- a/ngraph/cmake/external_protobuf.cmake +++ b/ngraph/cmake/external_protobuf.cmake @@ -93,14 +93,14 @@ else() if(TARGET libprotoc) list(APPEND _proto_libs libprotoc) set_target_properties(libprotoc PROPERTIES - COMPILE_FLAGS "-Wno-all") + COMPILE_FLAGS "-Wno-all -Wno-unused-variable") endif() set_target_properties(${_proto_libs} PROPERTIES CXX_VISIBILITY_PRESET default C_VISIBILITY_PRESET default VISIBILITY_INLINES_HIDDEN OFF) set_target_properties(libprotobuf libprotobuf-lite PROPERTIES - COMPILE_FLAGS "-Wno-all -Wno-inconsistent-missing-override") + COMPILE_FLAGS "-Wno-all -Wno-unused-variable -Wno-inconsistent-missing-override") endif() if(NGRAPH_USE_PROTOBUF_LITE) From 6510a68b10ca58acd1d82ffb4871bbd98fdc6344 Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Fri, 23 Apr 2021 10:07:40 +0300 Subject: [PATCH 62/78] fix: exclude .clang-format files from drop (#5353) --- inference-engine/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/inference-engine/CMakeLists.txt b/inference-engine/CMakeLists.txt index 4f6df8b1f3a..59c2b219541 100644 --- a/inference-engine/CMakeLists.txt +++ b/inference-engine/CMakeLists.txt @@ -78,14 +78,16 @@ if(UNIX) COMPONENT cpp_samples USE_SOURCE_PERMISSIONS PATTERN *.bat EXCLUDE - PATTERN speech_libs_and_demos EXCLUDE) + PATTERN speech_libs_and_demos EXCLUDE + PATTERN .clang-format EXCLUDE) elseif(WIN32) install(DIRECTORY samples/ DESTINATION ${IE_CPACK_IE_DIR}/samples/cpp COMPONENT cpp_samples USE_SOURCE_PERMISSIONS PATTERN *.sh EXCLUDE - PATTERN speech_libs_and_demos EXCLUDE) + PATTERN speech_libs_and_demos EXCLUDE + PATTERN .clang-format EXCLUDE) endif() # install C samples @@ -105,7 +107,8 @@ endif() install(DIRECTORY ie_bridges/c/samples/ DESTINATION ${IE_CPACK_IE_DIR}/samples/c COMPONENT c_samples - PATTERN ie_bridges/c/samples/CMakeLists.txt EXCLUDE) + PATTERN ie_bridges/c/samples/CMakeLists.txt EXCLUDE + PATTERN ie_bridges/c/samples/.clang-format EXCLUDE) install(FILES samples/CMakeLists.txt DESTINATION ${IE_CPACK_IE_DIR}/samples/c From 528d4b1bac104e1b7b3d4cef421fbc0d9a58c87c Mon Sep 17 00:00:00 2001 From: Chenhu Wang Date: Fri, 23 Apr 2021 16:29:53 +0800 Subject: [PATCH 63/78] contain only some typical fusion, reduce tensor size, not skip on traget without avx512 (#5361) --- .../single_layer_tests/interpolate.cpp | 16 +-- .../cpu/single_layer_tests/interpolate.cpp | 102 +++++++++--------- 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp index 573598bdd09..d5a9c8364e7 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp @@ -17,7 +17,7 @@ const std::vector netPrecisions = { }; const std::vector> inShapes = { - {1, 4, 30, 30}, + {1, 4, 6, 6}, }; const std::vector modesWithoutNearest = { @@ -71,15 +71,15 @@ const std::vector cubeCoefs = { }; const std::vector> defaultAxes = { - {2, 3} + {0, 1, 2, 3} }; const std::vector> targetShapes = { - {40, 40}, + {1, 4, 8, 8}, }; const std::vector> defaultScales = { - {1.333333f, 1.333333f} + {1.f, 1.f, 1.333333f, 1.333333f} }; const auto interpolateCasesWithoutNearest = ::testing::Combine( @@ -131,11 +131,11 @@ INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Nearest, InterpolateLayerTest, ::testi InterpolateLayerTest::getTestCaseName); const std::vector> targetShapesTailTest = { - {1, 4, 10, 41}, // 10 * 41 is not multipler of 4, cover tail process code path + {1, 4, 2, 11}, // cover down sample and tails process code path }; const std::vector> defaultScalesTailTest = { - {0.333333f, 1.366666f} + {1.f, 1.f, 0.333333f, 1.833333f} }; const auto interpolateCasesWithoutNearestTail = ::testing::Combine( @@ -162,7 +162,7 @@ const auto interpolateCasesTail = ::testing::Combine( ::testing::ValuesIn(defaultAxes), ::testing::ValuesIn(defaultScalesTailTest)); -INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Basic_2, InterpolateLayerTest, ::testing::Combine( +INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Basic_Down_Sample_Tail, InterpolateLayerTest, ::testing::Combine( interpolateCasesWithoutNearestTail, ::testing::ValuesIn(netPrecisions), ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), @@ -174,7 +174,7 @@ INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Basic_2, InterpolateLayerTest, ::testi ::testing::Values(CommonTestUtils::DEVICE_CPU)), InterpolateLayerTest::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Nearest_2, InterpolateLayerTest, ::testing::Combine( +INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Nearest_Down_Sample_Tail, InterpolateLayerTest, ::testing::Combine( interpolateCasesTail, ::testing::ValuesIn(netPrecisions), ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp index 65c5f90953a..a381fcf07be 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp @@ -59,7 +59,7 @@ protected: LayerTestsDefinitions::InterpolateSpecificParams interpolateParams; std::vector inputShape; std::vector targetShape; - auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; + Precision netPrecision; std::tie(interpolateParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetShape, targetDevice) = basicParamsSet; ngraph::op::v4::Interpolate::InterpolateMode mode; @@ -101,7 +101,7 @@ protected: selectedType = getPrimitiveType(); } selectedType.push_back('_'); - selectedType += "FP32"; + selectedType += netPrecision.name(); } }; @@ -118,17 +118,17 @@ namespace { std::vector filterCPUInfoForDevice() { std::vector resCPUParams; if (with_cpu_x86_avx512f()) { - resCPUParams.push_back(CPUSpecificParams{{nChw16c, x, x}, {nChw16c}, {"jit_avx512"}, "jit_avx512"}); - resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx512"}, "jit_avx512"}); + resCPUParams.push_back(CPUSpecificParams{{nChw16c, x, x, x}, {nChw16c}, {"jit_avx512"}, "jit_avx512"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x, x}, {nhwc}, {"jit_avx512"}, "jit_avx512"}); } else if (with_cpu_x86_avx2()) { - resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x}, {nChw8c}, {"jit_avx2"}, "jit_avx2"}); - resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx2"}, "jit_avx2"}); - resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x, x}, {nChw8c}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x, x}, {nhwc}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{nchw, x, x, x}, {nchw}, {"jit_avx2"}, "jit_avx2"}); } else if (with_cpu_x86_sse42()) { - resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x}, {nChw8c}, {"jit_sse42"}, "jit_sse42"}); - resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_sse42"}, "jit_sse42"}); + resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x, x}, {nChw8c}, {"jit_sse42"}, "jit_sse42"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x, x}, {nhwc}, {"jit_sse42"}, "jit_sse42"}); } else { - resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"ref"}, "ref"}); + resCPUParams.push_back(CPUSpecificParams{{nchw, x, x, x}, {nchw}, {"ref"}, "ref"}); } return resCPUParams; } @@ -177,11 +177,11 @@ const std::vector cubeCoefs = { }; const std::vector> defaultAxes = { - {2, 3} + {0, 1, 2, 3} }; const std::vector> defaultScales = { - {1.25f, 1.5f} + {1.f, 1.f, 1.25f, 1.5f} }; const auto interpolateCasesNN = ::testing::Combine( @@ -235,16 +235,22 @@ const auto interpolateCasesCubic = ::testing::Combine( const std::vector interpolateFusingParamsSet{ emptyFusingSpec, fusingRelu, - fusingElu, - fusingSigmoid, - fusingClamp, fusingSwish, }; -std::vector> bf16EnforceFlags = { - {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, - {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}} -}; +std::vector> filterAdditionalConfig() { + if (with_cpu_x86_avx512f()) { + return { + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}} + }; + } else { + return { + // default config as an stub for target without avx512, otherwise all tests with BF16 in its name are skipped + {{PluginConfigParams::KEY_PERF_COUNT, PluginConfigParams::NO}} + }; + } +} INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN_Layout_Test, InterpolateLayerCPUTest, ::testing::Combine( @@ -255,12 +261,12 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN_Layout_Test, InterpolateLayerCPUTest ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 40, 40})), - ::testing::Values(std::vector({1, 21, 50, 60})), + ::testing::Values(std::vector({1, 21, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinearOnnx_Layout_Test, InterpolateLayerCPUTest, @@ -272,12 +278,12 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinearOnnx_Layout_Test, InterpolateLaye ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 40, 40})), - ::testing::Values(std::vector({1, 21, 50, 60})), + ::testing::Values(std::vector({1, 21, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinear_Layout_Test, InterpolateLayerCPUTest, @@ -289,12 +295,12 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinear_Layout_Test, InterpolateLayerCPU ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 40, 40})), - ::testing::Values(std::vector({1, 21, 50, 60})), + ::testing::Values(std::vector({1, 21, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_CASE_P(smoke_InterpolateCubic_Layout_Test, InterpolateLayerCPUTest, @@ -306,30 +312,30 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateCubic_Layout_Test, InterpolateLayerCPUT ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 40, 40})), - ::testing::Values(std::vector({1, 21, 50, 60})), + ::testing::Values(std::vector({1, 21, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); ////////////////////////5D///////////////////////////// std::vector filterCPUInfoForDevice5D() { std::vector resCPUParams; if (with_cpu_x86_avx512f()) { - resCPUParams.push_back(CPUSpecificParams{{nCdhw16c, x, x}, {nCdhw16c}, {"jit_avx512"}, "jit_avx512"}); - resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x}, {ndhwc}, {"jit_avx512"}, "jit_avx512"}); - resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x}, {ncdhw}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{nCdhw16c, x, x, x}, {nCdhw16c}, {"jit_avx512"}, "jit_avx512"}); + resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x, x}, {ndhwc}, {"jit_avx512"}, "jit_avx512"}); + resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x, x}, {ncdhw}, {"jit_avx2"}, "jit_avx2"}); } else if (with_cpu_x86_avx2()) { - resCPUParams.push_back(CPUSpecificParams{{nCdhw8c, x, x}, {nCdhw8c}, {"jit_avx2"}, "jit_avx2"}); - resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x}, {ndhwc}, {"jit_avx2"}, "jit_avx2"}); - resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x}, {ncdhw}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{nCdhw8c, x, x, x}, {nCdhw8c}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x, x}, {ndhwc}, {"jit_avx2"}, "jit_avx2"}); + resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x, x}, {ncdhw}, {"jit_avx2"}, "jit_avx2"}); } else if (with_cpu_x86_sse42()) { - resCPUParams.push_back(CPUSpecificParams{{nCdhw8c, x, x}, {nCdhw8c}, {"jit_sse42"}, "jit_sse42"}); - resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x}, {ndhwc}, {"jit_sse42"}, "jit_sse42"}); + resCPUParams.push_back(CPUSpecificParams{{nCdhw8c, x, x, x}, {nCdhw8c}, {"jit_sse42"}, "jit_sse42"}); + resCPUParams.push_back(CPUSpecificParams{{ndhwc, x, x, x}, {ndhwc}, {"jit_sse42"}, "jit_sse42"}); } else { - resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x}, {ncdhw}, {"ref"}, "ref"}); + resCPUParams.push_back(CPUSpecificParams{{ncdhw, x, x, x}, {ncdhw}, {"ref"}, "ref"}); } return resCPUParams; } @@ -339,11 +345,11 @@ const std::vector> pads5D = { }; const std::vector> defaultAxes5D = { - {2, 3, 4} + {0, 1, 2, 3, 4} }; const std::vector> defaultScales5D = { - {1.25f, 1.5f, 1.5f} + {1.f, 1.f, 1.25f, 1.5f, 0.5f} }; const auto interpolateCasesLinearOnnx5D = ::testing::Combine( @@ -379,12 +385,12 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinearOnnx5D_Layout_Test, InterpolateLa ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 4, 10, 10})), - ::testing::Values(std::vector({1, 21, 5, 15, 15})), + ::testing::Values(std::vector({1, 21, 4, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6, 2})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice5D()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN5D_Layout_Test, InterpolateLayerCPUTest, @@ -396,12 +402,12 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN5D_Layout_Test, InterpolateLayerCPUTe ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 21, 4, 10, 10})), - ::testing::Values(std::vector({1, 21, 5, 15, 15})), + ::testing::Values(std::vector({1, 21, 4, 4, 4})), + ::testing::Values(std::vector({1, 21, 5, 6, 2})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice5D()), ::testing::ValuesIn(interpolateFusingParamsSet), - ::testing::ValuesIn(bf16EnforceFlags)), + ::testing::ValuesIn(filterAdditionalConfig())), InterpolateLayerCPUTest::getTestCaseName); } // namespace From 1426dc7d68fe21a7c73af2934e344b1340207e46 Mon Sep 17 00:00:00 2001 From: Chenhu Wang Date: Fri, 23 Apr 2021 16:38:18 +0800 Subject: [PATCH 64/78] [CPU] Activations are fused with MVN (#5272) --- .../mkldnn_plugin/mkldnn_graph_optimizer.cpp | 12 +-- .../mkldnn_plugin/nodes/mkldnn_mvn_node.cpp | 4 +- .../plugin/cpu/single_layer_tests/mvn.cpp | 79 +++++++++++++++++-- .../cpu/test_utils/fusing_test_utils.hpp | 15 +++- 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp index cb339748695..5452c2343a6 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp @@ -1393,7 +1393,7 @@ void MKLDNNGraphOptimizer::FuseMVNAndSimpleOperation(MKLDNNGraph &graph) { auto& graphNodes = graph.GetNodes(); auto isSutableParentNode = [](MKLDNNNodePtr node) { - bool isSutableMVN = (node->getType() == MVN) && (node->inDims[0].ndims() == 4 || node->inDims[0].ndims() == 5); + bool isSutableMVN = (node->getType() == MVN); if (isSutableMVN) { auto *mvnLayer = dynamic_cast(node->getCnnLayer().get()); @@ -1406,7 +1406,7 @@ void MKLDNNGraphOptimizer::FuseMVNAndSimpleOperation(MKLDNNGraph &graph) { } }; - auto isSutableChildNode = [](MKLDNNNodePtr node) { + auto isSutableChildNode = [&](MKLDNNNodePtr node) { if (!node->getCnnLayer()) return false; @@ -1420,9 +1420,11 @@ void MKLDNNGraphOptimizer::FuseMVNAndSimpleOperation(MKLDNNGraph &graph) { if (eltwiseNode == nullptr) IE_THROW() << "Cannot get eltwise node " << node->getName(); - return ((eltwiseNode->getOpType() == MulAdd) || - (eltwiseNode->getOpType() == Prelu) || - eltwiseNode->getOpType() == Relu); + return IsOneOf(eltwiseNode->getOpType(), {Relu, Gelu, Elu, Tanh, Logistic, Square, Abs, Sqrt, + Linear, BoundedRelu, SoftRelu, Relu6, Exp, Clamp, Swish, + Hswish, Mish, Hsigmoid, Round, Erf}) || + ((eltwiseNode->getOpType() == MulAdd && eltwiseNode->getCnnLayer()->blobs.size() == 2) || + (eltwiseNode->getOpType() == Prelu)); } return false; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp index 55bdb61a210..86f8dbc78fb 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp @@ -511,8 +511,8 @@ private: Xbyak::Reg64 reg_load_table = r15; Xbyak::Reg64 reg_load_store_mask = rcx; - Vmm vmm_val = Vmm(0); - Vmm vmm_mean = Vmm(1); + Vmm vmm_val = Vmm(1); + Vmm vmm_mean = Vmm(0); Vmm vmm_variance_inv = Vmm(2); Vmm vmm_zero = Vmm(3); diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp index 36c7ff5859b..db53819cdce 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp @@ -5,6 +5,7 @@ #include #include "ngraph_functions/builders.hpp" #include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" using namespace InferenceEngine; using namespace CPUTestUtils; @@ -14,18 +15,20 @@ namespace CPULayerTestsDefinitions { typedef std::tuple< LayerTestsDefinitions::mvnParams, CPUSpecificParams, + fusingSpecificParams, Precision, // CNNNetwork input precision Precision> // CNNNetwork output precision MvnLayerCPUTestParamSet; class MvnLayerCPUTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { + virtual public LayerTestsUtils::LayerTestsCommon, public CpuTestWithFusing { public: static std::string getTestCaseName(testing::TestParamInfo obj) { LayerTestsDefinitions::mvnParams basicParamsSet; CPUSpecificParams cpuParams; + fusingSpecificParams fusingParams; Precision inputPrecision, outputPrecision; - std::tie(basicParamsSet, cpuParams, inputPrecision, outputPrecision) = obj.param; + std::tie(basicParamsSet, cpuParams, fusingParams, inputPrecision, outputPrecision) = obj.param; std::ostringstream result; result << LayerTestsDefinitions::MvnLayerTest::getTestCaseName(testing::TestParamInfo( @@ -36,15 +39,19 @@ public: result << CPUTestsBase::getTestCaseName(cpuParams); + result << CpuTestWithFusing::getTestCaseName(fusingParams); + return result.str(); } protected: void SetUp() override { LayerTestsDefinitions::mvnParams basicParamsSet; CPUSpecificParams cpuParams; - std::tie(basicParamsSet, cpuParams, inPrc, outPrc) = this->GetParam(); + fusingSpecificParams fusingParams; + std::tie(basicParamsSet, cpuParams, fusingParams, inPrc, outPrc) = this->GetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(postOpMgrPtr, fusedOps) = fusingParams; InferenceEngine::SizeVector inputShapes; InferenceEngine::Precision netPrecision; @@ -55,15 +62,11 @@ protected: auto param = ngraph::builder::makeParams(netPrc, {inputShapes}); auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); auto mvn = ngraph::builder::makeMVN(paramOuts[0], acrossChanels, normalizeVariance, eps); - ngraph::ResultVector results{std::make_shared(mvn)}; selectedType = getPrimitiveType() + "_" + inPrc.name(); threshold = 0.015f; - - mvn->get_rt_info() = getCPUInfo(); - - function = std::make_shared(results, param, "mvn"); + function = makeNgraphFunction(netPrc, param, mvn, "mvn"); } }; @@ -137,6 +140,7 @@ const auto Mvn3D = ::testing::Combine( ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::Values(emptyCPUSpec), + ::testing::Values(emptyFusingSpec), ::testing::ValuesIn(inpOutPrc), ::testing::ValuesIn(inpOutPrc)); @@ -151,6 +155,7 @@ const auto Mvn4D = ::testing::Combine( ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D)), + ::testing::Values(emptyFusingSpec), ::testing::ValuesIn(inpOutPrc), ::testing::ValuesIn(inpOutPrc)); @@ -165,11 +170,69 @@ const auto Mvn5D = ::testing::Combine( ::testing::ValuesIn(epsilon), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D)), + ::testing::Values(emptyFusingSpec), ::testing::ValuesIn(inpOutPrc), ::testing::ValuesIn(inpOutPrc)); INSTANTIATE_TEST_CASE_P(smoke_CompareWithRefs_5D, MvnLayerCPUTest, Mvn5D, MvnLayerCPUTest::getTestCaseName); +std::vector fusingParamsSet { + /* activations */ + fusingRelu, + fusingElu, + fusingTanh, + fusingSwish, + /* FQ */ + fusingFakeQuantizePerChannel, + fusingFakeQuantizePerChannelRelu, + fusingFakeQuantizePerTensorRelu, +}; + +const auto Mvn3DFuse = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(inputShapes_3D), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::Values(false), + ::testing::Values(true), + ::testing::ValuesIn(epsilon), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(emptyCPUSpec), + ::testing::ValuesIn(fusingParamsSet), + ::testing::ValuesIn(inpOutPrc), + ::testing::ValuesIn(inpOutPrc)); + +INSTANTIATE_TEST_CASE_P(smoke_CompareWithRefs_3D_Fuse, MvnLayerCPUTest, Mvn3DFuse, MvnLayerCPUTest::getTestCaseName); + +const auto Mvn4DFuse = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(inputShapes_4D), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::Values(false), + ::testing::Values(true), + ::testing::ValuesIn(epsilon), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D)), + ::testing::ValuesIn(fusingParamsSet), + ::testing::ValuesIn(inpOutPrc), + ::testing::ValuesIn(inpOutPrc)); + +INSTANTIATE_TEST_CASE_P(smoke_CompareWithRefs_4D_Fuse, MvnLayerCPUTest, Mvn4DFuse, MvnLayerCPUTest::getTestCaseName); + +const auto Mvn5DFuse = ::testing::Combine( + ::testing::Combine( + ::testing::ValuesIn(inputShapes_5D), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::Values(false), + ::testing::Values(true), + ::testing::ValuesIn(epsilon), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D)), + ::testing::ValuesIn(fusingParamsSet), + ::testing::ValuesIn(inpOutPrc), + ::testing::ValuesIn(inpOutPrc)); + +INSTANTIATE_TEST_CASE_P(smoke_CompareWithRefs_5D_Fuse, MvnLayerCPUTest, Mvn5DFuse, MvnLayerCPUTest::getTestCaseName); + } // namespace } // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.hpp b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.hpp index ba04fb884bf..9d2de2b2715 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.hpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.hpp @@ -112,7 +112,10 @@ const auto fusingMish = fusingSpecificParams{std::make_shared(std: {[](std::shared_ptr inpNode, const ngraph::element::Type& ngPrc, ngraph::ParameterVector& params){ return ngraph::builder::makeActivation(inpNode, ngPrc, ngraph::helpers::Mish, {}, {}); }, "Mish"}}), {"Mish"}}; - +const auto fusingTanh = fusingSpecificParams{std::make_shared(std::vector{ + {[](std::shared_ptr inpNode, const ngraph::element::Type& ngPrc, ngraph::ParameterVector& params){ + return ngraph::builder::makeActivation(inpNode, ngPrc, ngraph::helpers::Tanh, {}, {}); + }, "Tanh"}}), {"Tanh"}}; const auto fusingReluScaleShift = fusingSpecificParams{std::make_shared(std::vector{ {[](std::shared_ptr inpNode, const ngraph::element::Type& ngPrc, ngraph::ParameterVector& params){ return ngraph::builder::makeActivation(inpNode, ngPrc, ngraph::helpers::Relu); @@ -154,6 +157,16 @@ const auto fusingScaleShift = fusingSpecificParams{ std::make_shared(ngraph::element::f32, newShape, {}, true); return std::make_shared(inpNode, constNode); }, "Add(PerChannel)"}}), {"Add"} }; +const auto fusingFakeQuantizePerChannel = fusingSpecificParams{std::make_shared(std::vector{ + {[](std::shared_ptr inpNode, const ngraph::element::Type& ngPrc, ngraph::ParameterVector& params){ + auto localPrc = inpNode->get_element_type(); + auto shape = inpNode->get_shape(); + if (shape.size() == 1) + THROW_IE_EXCEPTION << "If shape.size() == 1 then Granularity can be PerTensor only"; + ngraph::Shape newShape(shape.size(), 1); + newShape[1] = shape[1]; + return ngraph::builder::makeFakeQuantize(inpNode, localPrc, 256, newShape); + }, "FakeQuantize(PerChannel)"}}), {"FakeQuantize"}}; const auto fusingFakeQuantizePerChannelRelu = fusingSpecificParams{std::make_shared(std::vector{ {[](std::shared_ptr inpNode, const ngraph::element::Type& ngPrc, ngraph::ParameterVector& params){ auto localPrc = inpNode->get_element_type(); From e121fbd7de756a1cabfb8e374783f6adfe659f96 Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov <32412802+just-sparta@users.noreply.github.com> Date: Fri, 23 Apr 2021 12:56:59 +0300 Subject: [PATCH 65/78] Add int8 models to memcheck tests (#5333) --- .../desktop_references_config.xml | 103 ++++++++++++++++++ .../nightly_configs/desktop_test_config.xml | 28 +++++ tests/stress_tests/scripts/get_testdata.py | 5 +- 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_references_config.xml b/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_references_config.xml index 2d9e6e4db5b..dac3d2ef436 100644 --- a/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_references_config.xml +++ b/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_references_config.xml @@ -316,5 +316,108 @@ # values from {"commit_id": "af63cb78ee5cbd66bac0d0980db61cb11b5d9995", "commit_date": "2021-03-03 15:44"} and *= 1.3 # values from {"commit_id": "af63cb78ee5cbd66bac0d0980db61cb11b5d9995", "commit_date": "2021-03-03 15:44"} and *= 1.3 # values from {"commit_id": "af63cb78ee5cbd66bac0d0980db61cb11b5d9995", "commit_date": "2021-03-03 15:44"} and *= 1.3 + + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 + # values from {"commit_id": "ce67c414833cddd447acc7573b99c8ebc6a1591e", "commit_date": "2021-04-21 14:41"} and *= 1.3 diff --git a/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_test_config.xml b/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_test_config.xml index a9696483d72..98b47574b56 100644 --- a/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_test_config.xml +++ b/tests/stress_tests/.automation/memcheck_tests/nightly_configs/desktop_test_config.xml @@ -84,5 +84,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/stress_tests/scripts/get_testdata.py b/tests/stress_tests/scripts/get_testdata.py index f838611d1e4..77bf2c1a52d 100755 --- a/tests/stress_tests/scripts/get_testdata.py +++ b/tests/stress_tests/scripts/get_testdata.py @@ -15,6 +15,8 @@ import shutil import subprocess import sys import json + +from distutils.dir_util import copy_tree from inspect import getsourcefile from pathlib import Path from xml.etree import ElementTree as ET @@ -208,7 +210,8 @@ def main(): # Do it manually to have only one folder with IRs for ir_src_path in args.omz_models_out_dir.rglob("*.xml"): ir_dst_path = args.omz_irs_out_dir / os.path.relpath(ir_src_path, args.omz_models_out_dir) - shutil.copytree(ir_src_path.parent, ir_dst_path.parent) + # allows copy to an existing folder + copy_tree(str(ir_src_path.parent), str(ir_dst_path.parent)) if __name__ == "__main__": From 576e692b1d2c4a4b86ab8c212bfb70d19212bce1 Mon Sep 17 00:00:00 2001 From: Anton Chetverikov Date: Fri, 23 Apr 2021 13:23:06 +0300 Subject: [PATCH 66/78] Update errors raising cases in modules versions checker in MO (#5141) * Change error raising to message printing * Update modules versions check * Update check and add unit test * Fix wrong function call * Update unit tests * Fix test Co-authored-by: achetver --- model-optimizer/mo/utils/versions_checker.py | 14 ++-- .../mo/utils/versions_checker_test.py | 82 ++++++++++++++++++- 2 files changed, 87 insertions(+), 9 deletions(-) diff --git a/model-optimizer/mo/utils/versions_checker.py b/model-optimizer/mo/utils/versions_checker.py index 4d79d2038cd..e0760fa79aa 100644 --- a/model-optimizer/mo/utils/versions_checker.py +++ b/model-optimizer/mo/utils/versions_checker.py @@ -77,7 +77,7 @@ def parse_and_filter_versions_list(required_fw_versions, version_list, env_setup not_satisfied_list = [] for name, key, required_version in env_req_version_list: version_check(name, installed_python_version, required_version, - key, not_satisfied_list, 0) + key, not_satisfied_list) if len(not_satisfied_list) > 0: # this python_version requirement is not satisfied to required environment # and requirement for a dependency will be skipped @@ -131,7 +131,7 @@ def get_module_version_list_from_file(file_name, env_setup): return req_dict -def version_check(name, installed_v, required_v, sign, not_satisfied_v, exit_code): +def version_check(name, installed_v, required_v, sign, not_satisfied_v): """ Please do not add parameter type annotations (param:type). Because we import this file while checking Python version. @@ -144,8 +144,6 @@ def version_check(name, installed_v, required_v, sign, not_satisfied_v, exit_cod :param required_v: required version of module :param sign: sing for comparison of required and installed versions :param not_satisfied_v: list of modules with not satisfying versions - :param exit_code: flag of successful execution (0 - successful, 1 - error) - :return: exit code """ if sign is not None: req_ver = LooseVersion(required_v) @@ -166,9 +164,6 @@ def version_check(name, installed_v, required_v, sign, not_satisfied_v, exit_cod satisfied = True if not satisfied: not_satisfied_v.append((name, 'installed: {}'.format(installed_v), 'required: {} {}'.format(sign, required_v))) - if name in critical_modules: - exit_code = 1 - return exit_code def get_environment_setup(): @@ -223,9 +218,12 @@ def check_requirements(framework=None): importable_name = modules.get(name, name) exec("import {}".format(importable_name)) installed_version = sys.modules[importable_name].__version__ - exit_code = version_check(name, installed_version, required_version, key, not_satisfied_versions, exit_code) + version_check(name, installed_version, required_version, key, not_satisfied_versions) exec("del {}".format(importable_name)) except (AttributeError, ImportError): + # we need to raise error only in cases when import of critical modules is failed + if name in critical_modules: + exit_code = 1 if key is not None and required_version is not None: not_satisfied_versions.append((name, 'not installed', 'required: {} {}'.format(key, required_version))) else: diff --git a/model-optimizer/unit_tests/mo/utils/versions_checker_test.py b/model-optimizer/unit_tests/mo/utils/versions_checker_test.py index 5c83d8ecd60..bf625fe3483 100644 --- a/model-optimizer/unit_tests/mo/utils/versions_checker_test.py +++ b/model-optimizer/unit_tests/mo/utils/versions_checker_test.py @@ -5,7 +5,7 @@ import unittest import unittest.mock as mock from unittest.mock import mock_open -from mo.utils.versions_checker import get_module_version_list_from_file, parse_and_filter_versions_list +from mo.utils.versions_checker import get_module_version_list_from_file, parse_and_filter_versions_list, version_check class TestingVersionsChecker(unittest.TestCase): @@ -74,3 +74,83 @@ class TestingVersionsChecker(unittest.TestCase): ('mxnet', '<=', '1.3.1')] for i, v in enumerate(req_list): self.assertEqual(v, ref_list[i]) + + def test_version_check_equal(self): + modules_versions_list = [('module_1', '==', '2.0', '2.0'), + ('module_2', '==', '2.0', '2.0.1'), + ] + + ref_list = [('module_2', 'installed: 2.0.1', 'required: == 2.0'), + ] + + not_satisfied_versions = [] + + for name, key, required_version, installed_version in modules_versions_list: + version_check(name, installed_version, required_version, key, not_satisfied_versions) + self.assertEqual(not_satisfied_versions, ref_list) + + def test_version_check_less_equal(self): + modules_versions_list = [('module_1', '>=', '1.12.0', '1.09.2'), + ('module_2', '>=', '1.12.0', '1.12.0'), + ('module_3', '>=', '1.12.0', '1.12.1'), + ('module_4', '>=', '1.12.0', '1.20.0'), + ] + + ref_list = [('module_1', 'installed: 1.09.2', 'required: >= 1.12.0'), + ] + + not_satisfied_versions = [] + + for name, key, required_version, installed_version in modules_versions_list: + version_check(name, installed_version, required_version, key, not_satisfied_versions) + self.assertEqual(not_satisfied_versions, ref_list) + + def test_version_check_greater_equal(self): + modules_versions_list = [('module_1', '>=', '1.12.0', '1.09.2'), + ('module_2', '>=', '1.12.0', '1.12.0'), + ('module_3', '>=', '1.12.0', '1.12.1'), + ('module_4', '>=', '1.12.0', '1.20.0'), + ] + + ref_list = [('module_1', 'installed: 1.09.2', 'required: >= 1.12.0') + ] + + not_satisfied_versions = [] + + for name, key, required_version, installed_version in modules_versions_list: + version_check(name, installed_version, required_version, key, not_satisfied_versions) + self.assertEqual(not_satisfied_versions, ref_list) + + def test_version_check_less(self): + modules_versions_list = [('module_1', '<', '1.11', '1.01'), + ('module_2', '<', '1.11', '1.10.1'), + ('module_3', '<', '1.11', '1.11'), + ('module_4', '<', '1.11', '1.20'), + ] + + ref_list = [('module_3', 'installed: 1.11', 'required: < 1.11'), + ('module_4', 'installed: 1.20', 'required: < 1.11'), + ] + + not_satisfied_versions = [] + + for name, key, required_version, installed_version in modules_versions_list: + version_check(name, installed_version, required_version, key, not_satisfied_versions) + self.assertEqual(not_satisfied_versions, ref_list) + + def test_version_check_greater(self): + modules_versions_list = [('module_1', '>', '1.11', '1.01'), + ('module_2', '>', '1.11', '1.11'), + ('module_3', '>', '1.11', '1.11.1'), + ('module_4', '>', '1.11', '1.20'), + ] + + ref_list = [('module_1', 'installed: 1.01', 'required: > 1.11'), + ('module_2', 'installed: 1.11', 'required: > 1.11'), + ] + + not_satisfied_versions = [] + + for name, key, required_version, installed_version in modules_versions_list: + version_check(name, installed_version, required_version, key, not_satisfied_versions) + self.assertEqual(not_satisfied_versions, ref_list) From 05c23dfd94850b2bb155dc7cd6bedecfa4b4a129 Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Fri, 23 Apr 2021 13:26:53 +0300 Subject: [PATCH 67/78] [LPT][CommonOptimizations] ShuffleChannelsTransformation and ShuffleChannelsFusion (#4916) * [nGraph] op::v0::ShuffleChannels: added type_info macros * [LPT] ShuffleChannelsTransformation * [CPU] ShuffleChannels decomposition disabled * [LPT][TESTS] ShuffleChannelsTransformation functional tests * [LPT][TESTS] ShuffleChannelsTransformation plugin tests * [CommonOptimizations] Added ShuffleChannelsFusion transformation * [CommonOptimizations][TESTS] ShuffleChannelsFusion tests * refactoring and adding comments * [CommonOptimizations] ShuffleChannelsFusion refactoring and fixes * [CommonOptimizations] ShuffleChannelsFusion: removed unnecessary check * [CommonOptimizations] transformation refactored and test-cases with dynamic shape added --- .../low_precision/layer_transformation.hpp | 2 +- .../low_precision/shuffle_channels.hpp | 25 ++ .../src/layer_transformation.cpp | 2 +- .../src/mat_mul.cpp | 2 +- .../src/shuffle_channels.cpp | 93 ++++++ .../src/transformer.cpp | 2 + .../src/mkldnn_plugin/mkldnn_plugin.cpp | 2 + .../shuffle_channels_fusion.hpp | 40 +++ .../common_optimizations.cpp | 2 + .../shuffle_channels_fusion.cpp | 121 ++++++++ .../shuffle_channels_transformation.cpp | 290 ++++++++++++++++++ .../shuffle_channels_fusion_test.cpp | 126 ++++++++ .../shuffle_channels_transformation.cpp | 101 ++++++ .../shuffle_channels_transformation.cpp | 88 ++++++ .../shuffle_channels_transformation.hpp | 43 +++ .../shuffle_channels_transformation.cpp | 62 ++++ .../shuffle_channels_function.hpp | 46 +++ .../src/shuffle_channels_function.cpp | 83 +++++ .../include/ngraph/op/shuffle_channels.hpp | 4 +- ngraph/core/src/op/shuffle_channels.cpp | 4 +- 20 files changed, 1132 insertions(+), 6 deletions(-) create mode 100644 inference-engine/src/low_precision_transformations/include/low_precision/shuffle_channels.hpp create mode 100644 inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp create mode 100644 inference-engine/src/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp create mode 100644 inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp create mode 100644 inference-engine/tests/functional/inference_engine/lp_transformations/shuffle_channels_transformation.cpp create mode 100644 inference-engine/tests/functional/inference_engine/transformations/shuffle_channels_fusion_test.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/shuffle_channels_transformation.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/shuffle_channels_transformation.cpp create mode 100644 inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/shuffle_channels_function.hpp create mode 100644 inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/shuffle_channels_function.cpp diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/layer_transformation.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/layer_transformation.hpp index e401bf8d6f7..54fadb9d738 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/layer_transformation.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/layer_transformation.hpp @@ -342,7 +342,7 @@ protected: void addPattern(ngraph::pass::GraphRewrite& pass, TransformationContext& context, std::shared_ptr patternRoot) const; //TODO: replace with canBeTransformed when quantization by special dimension is supported for all transformations - bool canBeTransformedSpecialDimension(const TransformationContext& context, std::shared_ptr layer) const; + bool canBeTransformedSpatialDimension(const TransformationContext& context, std::shared_ptr layer) const; template void addSingleNodePattern(ngraph::pass::GraphRewrite& pass, TransformationContext& context) const { diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/shuffle_channels.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/shuffle_channels.hpp new file mode 100644 index 00000000000..42124d4b7b1 --- /dev/null +++ b/inference-engine/src/low_precision_transformations/include/low_precision/shuffle_channels.hpp @@ -0,0 +1,25 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "low_precision/layer_transformation.hpp" + +namespace ngraph { +namespace pass { +namespace low_precision { + +class TRANSFORMATIONS_API ShuffleChannelsTransformation : public LayerTransformation { +public: + ShuffleChannelsTransformation(const Params& params); + void registerMatcherIn(GraphRewrite& pass, TransformationContext& context) const override; + bool transform(TransformationContext& context, ngraph::pattern::Matcher& m) const override; + bool isPrecisionPreserved(std::shared_ptr layer) const noexcept override; + bool canBeTransformed(const TransformationContext& context, std::shared_ptr op) const override; +}; + +} // namespace low_precision +} // namespace pass +} // namespace ngraph diff --git a/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp b/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp index a3d3b3b15d2..dbbb8206b4d 100644 --- a/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/layer_transformation.cpp @@ -115,7 +115,7 @@ bool LayerTransformation::canBeTransformed(const TransformationContext& context, return true; } -bool LayerTransformation::canBeTransformedSpecialDimension(const TransformationContext& context, std::shared_ptr layer) const { +bool LayerTransformation::canBeTransformedSpatialDimension(const TransformationContext& context, std::shared_ptr layer) const { if (!isQuantized(layer)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp index 8bb6cfa5d60..80e752448e4 100644 --- a/inference-engine/src/low_precision_transformations/src/mat_mul.cpp +++ b/inference-engine/src/low_precision_transformations/src/mat_mul.cpp @@ -163,7 +163,7 @@ bool MatMulTransformation::isPrecisionPreserved(std::shared_ptr layer) con } bool MatMulTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr layer) const { - if (!LayerTransformation::canBeTransformedSpecialDimension(context, layer)) { + if (!LayerTransformation::canBeTransformedSpatialDimension(context, layer)) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp b/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp new file mode 100644 index 00000000000..2ed3e54a86b --- /dev/null +++ b/inference-engine/src/low_precision_transformations/src/shuffle_channels.cpp @@ -0,0 +1,93 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "low_precision/shuffle_channels.hpp" + +#include +#include +#include + +#include "low_precision/network_helper.hpp" + +namespace ngraph { +namespace pass { +namespace low_precision { +ShuffleChannelsTransformation::ShuffleChannelsTransformation(const Params& params) : LayerTransformation(params) {} + +void ShuffleChannelsTransformation::registerMatcherIn(GraphRewrite& pass, TransformationContext& context) const { + addPattern( + pass, + context, + make_op_pattern({ make_op_label() })); +} + +bool ShuffleChannelsTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher& m) const { + if (!canBeTransformed(context, m.get_match_root())) { + return false; + } + + const auto shuffleChannels = as_type_ptr(NetworkHelper::separateInStandaloneBranch(m.get_match_root())); + auto dequantization = NetworkHelper::getDequantization(shuffleChannels); + + const auto shuffleDequantizationConstant = [&](const std::shared_ptr& eltwise) { + const auto normalizedConst = NetworkHelper::normalizeDequantizationShape(eltwise); + const auto constShape = normalizedConst->get_shape(); + + if (shape_size(constShape) == 1ul) { + return NetworkHelper::toScalar(normalizedConst); + } else { + const size_t normalizedAxis = ngraph::normalize_axis( + shuffleChannels->get_friendly_name(), + shuffleChannels->get_axis(), + shuffleChannels->get_input_partial_shape(0).rank()); + + if (constShape[normalizedAxis] == 1ul) { + return normalizedConst; + } else { + const auto group = shuffleChannels->get_group(); + const auto shuffledConst = fold(normalizedConst, normalizedAxis, group); + return as_type_ptr(shuffledConst); + } + } + }; + + if (dequantization.subtract) { + const auto shuffledSubConst = shuffleDequantizationConstant(dequantization.subtract); + replace_node(dequantization.subtractConstant, shuffledSubConst); + dequantization.subtractConstant = shuffledSubConst; + } + + const auto shuffledMulConst = shuffleDequantizationConstant(dequantization.multiply); + replace_node(dequantization.multiplyConstant, shuffledMulConst); + dequantization.multiplyConstant = shuffledMulConst; + + moveDequantizationAfter(context, shuffleChannels, dequantization, false); + return true; +} + +bool ShuffleChannelsTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr op) const { + if (!LayerTransformation::canBeTransformedSpatialDimension(context, op)) { + return false; + } + + const auto shuffleChannels = as_type_ptr(op); + if (shuffleChannels == nullptr) { + return false; + } + + const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(shuffleChannels); + if (dequantization.empty()) { + return false; + } + + return true; +} + +bool ShuffleChannelsTransformation::isPrecisionPreserved(std::shared_ptr layer) const noexcept { + return true; +} + +} // namespace low_precision +} // namespace pass +} // namespace ngraph diff --git a/inference-engine/src/low_precision_transformations/src/transformer.cpp b/inference-engine/src/low_precision_transformations/src/transformer.cpp index d66263bdf07..18b49018760 100644 --- a/inference-engine/src/low_precision_transformations/src/transformer.cpp +++ b/inference-engine/src/low_precision_transformations/src/transformer.cpp @@ -45,6 +45,7 @@ #include "low_precision/prelu.hpp" #include "low_precision/reshape.hpp" #include "low_precision/relu.hpp" +#include "low_precision/shuffle_channels.hpp" #include "low_precision/squeeze.hpp" #include "low_precision/subtract.hpp" #include "low_precision/split.hpp" @@ -228,6 +229,7 @@ LowPrecisionTransformations LowPrecisionTransformer::getAllTransformations(const add(params). add(params). add(params). + add(params). add(params). add(params). add(params). diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index 5dd4fa84f1d..7f043c40361 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -269,6 +270,7 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { // List of enabled/disabled transformations pass_config->disable(); + pass_config->disable(); pass_config->disable(); pass_config->disable(); pass_config->disable(); diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp new file mode 100644 index 00000000000..0efd7e2b0d7 --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include + +#include + +namespace ngraph { +namespace pass { + + class TRANSFORMATIONS_API ShuffleChannelsFusion; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief ShuffleChannelsFusion transformation detects Reshape-Transpose-Reshape pattern + * and tries to fuse it into a single ShuffleChannels layer with axis = 1. + * + * x' = reshape(x, [N, group, C / group, H, W]) or reshape(x, [N, group, C / group, H * W]) + * x'' = transpose(x', [0, 2, 1, 3, 4]) or transpose(x', [0, 2, 1, 3]) + * y = reshape(x'', [N, C, H, W]) + * + * @param reshape_constants_check the flag that defines the need for additional checks of reshapes constant + * Additional checks are required when ShuffleChannelsFusion using inside offline transformations + * and are not necessary when ShuffleChannelsFusion using inside CommonOptimizations + */ + +class ngraph::pass::ShuffleChannelsFusion : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + ShuffleChannelsFusion(const bool reshape_constants_check); +}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 2df73b3a6a7..1e281888b98 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -32,6 +32,7 @@ #include "transformations/common_optimizations/clamp_fusion.hpp" #include "transformations/common_optimizations/pad_fusion.hpp" #include "transformations/common_optimizations/eliminate_unsqueeze_gather.hpp" +#include "transformations/common_optimizations/shuffle_channels_fusion.hpp" #include "transformations/common_optimizations/softmax_fusion.hpp" #include "transformations/common_optimizations/mvn_fusion.hpp" #include "transformations/common_optimizations/binarize_weights.hpp" @@ -104,6 +105,7 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptradd_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); + common_fusions->add_matcher(false); common_fusions->add_matcher(); common_fusions->add_matcher(); common_fusions->add_matcher(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp new file mode 100644 index 00000000000..054fb411f33 --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp @@ -0,0 +1,121 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/common_optimizations/shuffle_channels_fusion.hpp" +#include "itt.hpp" + +#include +#include + +#include +#include +#include + +bool check_shapes(const ngraph::Shape& shape_input, const ngraph::Shape& shape_reshape_before, + const ngraph::AxisVector& transpose_constant_values, const ngraph::Shape& shape_reshape_after) { + // x: [N, C, H, W] + bool is_transformation_valid = (shape_input.size() == 4); + + // x'= reshape(x, [N, group, C / group, H * W]) or reshape(x, [N, group, C / group, H, W]) + bool is_reshape_before_valid = (shape_reshape_before.size() == 4 || shape_reshape_before.size() == 5); + if (is_reshape_before_valid) { + size_t group = shape_reshape_before[1]; + ngraph::Shape expected_reshape_before = { shape_input[0], group, shape_input[1] / group }; + + if (shape_reshape_before.size() == 4) { + expected_reshape_before.push_back(shape_input[2] * shape_input[3]); + } else { + expected_reshape_before.push_back(shape_input[2]); + expected_reshape_before.push_back(shape_input[3]); + } + + is_reshape_before_valid &= (expected_reshape_before == shape_reshape_before); + } + + // x''= transpose(x', [0, 2, 1, 3]) or transpose(x', [0, 2, 1, 3, 4]) + bool is_transpose_valid = (transpose_constant_values.size() == 4 || transpose_constant_values.size() == 5); + if (is_transpose_valid) { + ngraph::AxisVector expected_transpose_values{ 0, 2, 1, 3 }; + if (transpose_constant_values.size() == 5) { + expected_transpose_values.push_back(4); + } + + is_transpose_valid &= (expected_transpose_values == transpose_constant_values); + } + + // y = reshape(x'', [N, C, H, W]) + bool is_reshape_after_valid = (shape_input == shape_reshape_after); + + is_transformation_valid &= is_reshape_before_valid & is_transpose_valid & is_reshape_after_valid; + return is_transformation_valid; +} + +NGRAPH_RTTI_DEFINITION(ngraph::pass::ShuffleChannelsFusion, "ShuffleChannelsFusion", 0); + +ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constants_check) { + MATCHER_SCOPE(ShuffleChannelsFusion); + auto input = ngraph::pattern::any_input(pattern::has_static_shape()); + auto reshape_before_const_pattern = ngraph::pattern::wrap_type(); + auto transpose_const_pattern = ngraph::pattern::wrap_type(); + auto reshape_after_const_pattern = ngraph::pattern::wrap_type(); + + auto has_static_shape_and_single_consumer = [](const Output& output) { + return pattern::has_static_shape()(output) && pattern::consumers_count(1)(output); + }; + auto reshape_before_pattern = ngraph::pattern::wrap_type({input, reshape_before_const_pattern}, + has_static_shape_and_single_consumer); + auto transpose_pattern = ngraph::pattern::wrap_type({reshape_before_pattern, transpose_const_pattern}, + has_static_shape_and_single_consumer); + auto reshape_after_pattern = ngraph::pattern::wrap_type({transpose_pattern, reshape_after_const_pattern}, + pattern::has_static_shape()); + + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_value_map(); + + auto data = pattern_map.at(input); + auto reshape_before = std::dynamic_pointer_cast(pattern_map.at(reshape_before_pattern).get_node_shared_ptr()); + auto transpose = std::dynamic_pointer_cast(pattern_map.at(transpose_pattern).get_node_shared_ptr()); + auto reshape_after = std::dynamic_pointer_cast(pattern_map.at(reshape_after_pattern).get_node_shared_ptr()); + if (!reshape_after || !transpose || !reshape_after) + return false; + + if (reshape_constants_check) { + auto reshape_before_constant = std::dynamic_pointer_cast( + pattern_map.at(reshape_before_const_pattern).get_node_shared_ptr()); + auto reshape_after_constant = std::dynamic_pointer_cast( + pattern_map.at(reshape_after_const_pattern).get_node_shared_ptr()); + + if (!reshape_before_constant || !reshape_after_constant) + return false; + + const auto& reshape_before_values = reshape_before_constant->cast_vector(); + const auto& reshape_after_values = reshape_after_constant->cast_vector(); + if (std::any_of(reshape_before_values.cbegin(), reshape_before_values.cend(), [](const int64_t& value) { return value == -1; }) || + std::any_of(reshape_after_values.cbegin(), reshape_after_values.cend(), [](const int64_t& value) { return value == -1; })) { + return false; + } + } + + auto shape_input = reshape_before->get_input_shape(0); + auto shape_reshape_before = reshape_before->get_output_shape(0); + auto shape_reshape_after = reshape_after->get_output_shape(0); + + auto transpose_constant = std::dynamic_pointer_cast(pattern_map.at(transpose_const_pattern).get_node_shared_ptr()); + auto transpose_constant_values = transpose_constant->get_axis_vector_val(); + if (!check_shapes(shape_input, shape_reshape_before, transpose_constant_values, shape_reshape_after)) + return false; + + int64_t axis = 1ul; + int64_t group = shape_reshape_before[1]; + + auto shuffle_shannels = std::make_shared(data, axis, group); + shuffle_shannels->set_friendly_name(reshape_after->get_friendly_name()); + ngraph::copy_runtime_info({ reshape_before, transpose, reshape_after }, shuffle_shannels); + ngraph::replace_node(reshape_after, shuffle_shannels); + return true; + }; + + auto m = std::make_shared(reshape_after_pattern, matcher_name); + register_matcher(m, callback); +} diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/shuffle_channels_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/shuffle_channels_transformation.cpp new file mode 100644 index 00000000000..88a205089d6 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/shuffle_channels_transformation.cpp @@ -0,0 +1,290 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "layer_transformation.hpp" + +#include +#include + +#include + +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" +#include "simple_low_precision_transformer.hpp" +#include "lpt_ngraph_functions/shuffle_channels_function.hpp" +#include "lpt_ngraph_functions/common/dequantization_operations.hpp" + +namespace { +using namespace testing; +using namespace ngraph::pass; + +class ShuffleChannelsTransformationTestValues { +public: +public: + class Actual { + public: + ngraph::element::Type inputPrecision; + ngraph::builder::subgraph::DequantizationOperations dequantization; + }; + + class Expected { + public: + ngraph::element::Type inputPrecision; + ngraph::builder::subgraph::DequantizationOperations dequantizationBefore; + ngraph::element::Type preicsionAfterOperation; + ngraph::builder::subgraph::DequantizationOperations dequantizationAfter; + }; + + ngraph::pass::low_precision::LayerTransformation::Params params; + std::int64_t axis; + std::int64_t group; + Actual actual; + Expected expected; +}; + +typedef std::tuple< + ngraph::Shape, + ShuffleChannelsTransformationTestValues> ShuffleChannelsTransformationParams; + +class ShuffleChannelsTransformation : public LayerTransformation, public testing::WithParamInterface { +public: + void SetUp() override { + ngraph::Shape inputShape = std::get<0>(GetParam()); + ShuffleChannelsTransformationTestValues testValues = std::get<1>(GetParam()); + + actualFunction = ngraph::builder::subgraph::ShuffleChannelsFunction::getOriginal( + testValues.actual.inputPrecision, + inputShape, + testValues.actual.dequantization, + testValues.axis, + testValues.group); + + SimpleLowPrecisionTransformer transform; + transform.add(testValues.params); + transform.transform(actualFunction); + + referenceFunction = ngraph::builder::subgraph::ShuffleChannelsFunction::getReference( + testValues.expected.inputPrecision, + inputShape, + testValues.expected.dequantizationBefore, + testValues.axis, + testValues.group, + testValues.expected.preicsionAfterOperation, + testValues.expected.dequantizationAfter); + } + + static std::string getTestCaseName(testing::TestParamInfo obj) { + ngraph::Shape inputShape = std::get<0>(obj.param); + ShuffleChannelsTransformationTestValues testValues = std::get<1>(obj.param); + + std::ostringstream result; + result << + LayerTransformation::getTestCaseNameByParams(testValues.actual.inputPrecision, inputShape, testValues.params) << "_" << + testValues.actual.dequantization << "_axis_" << + testValues.axis << "_group_" << testValues.group; + + return result.str(); + } +}; + +TEST_P(ShuffleChannelsTransformation, CompareFunctions) { + actualFunction->validate_nodes_and_infer_types(); + auto res = compare_functions(referenceFunction, actualFunction, true, true); + ASSERT_TRUE(res.first) << res.second; +} + +const std::vector inputShapes = { + { 1, 3, 8, 10 }, + { 4, 3, 8, 10 }, +}; + +const std::vector testValues = { + // U8 per tensor quantization + { + LayerTransformation::createParamsU8I8(), + 1, // axis + 1, // group + { + ngraph::element::u8, + {{ngraph::element::f32}, {128.f}, {0.02f}} + }, + { + ngraph::element::u8, + {}, + ngraph::element::u8, + {{ngraph::element::f32}, {128.f}, {0.02f}} + } + }, + // U8 per channel quantization + { + LayerTransformation::createParamsU8I8(), + 1, + 1, + { + ngraph::element::u8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + }, + { + ngraph::element::u8, + {}, + ngraph::element::u8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + } + }, + // U8 quantization by special dimension, shuffling by the same dimension + { + LayerTransformation::createParamsU8I8(), + 2, + 4, + { + ngraph::element::u8, + { + {ngraph::element::f32}, + {{121.f, 122.f, 123.f, 124.f, 125.f, 126.f, 127.f, 128.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}}, + {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}} + } + }, + { + ngraph::element::u8, + {}, + ngraph::element::u8, + { + {ngraph::element::f32}, + {{121.f, 123.f, 125.f, 127.f, 122.f, 124.f, 126.f, 128.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}}, + {{1.f, 3.f, 5.f, 7.f, 2.f, 4.f, 6.f, 8.f}, ngraph::element::f32, ngraph::Shape {1, 1, 8, 1}}, + } + } + }, + // U8 per channel quantization, shuffling by special dimension + { + LayerTransformation::createParamsU8I8(), + -2, + 4, + { + ngraph::element::u8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + }, + { + ngraph::element::u8, + {}, + ngraph::element::u8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + } + }, + // I8 per tensor quantization + { + LayerTransformation::createParamsI8I8(), + 1, + 1, + { + ngraph::element::i8, + {{ngraph::element::f32}, {128.f}, {0.02f}} + }, + { + ngraph::element::i8, + {}, + ngraph::element::i8, + {{ngraph::element::f32}, {128.f}, {0.02f}} + } + }, + // I8 per channel quantization + { + LayerTransformation::createParamsI8I8(), + 1, + 1, + { + ngraph::element::i8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + }, + { + ngraph::element::i8, + {}, + ngraph::element::i8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + } + }, + // I8 quantization by special dimension, shuffling by the same dimension + { + LayerTransformation::createParamsI8I8(), + 2, + 4, + { + ngraph::element::i8, + { + {ngraph::element::f32}, + {{121.f, 122.f, 123.f, 124.f, 125.f, 126.f, 127.f, 128.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}}, + {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}} + } + }, + { + ngraph::element::i8, + {}, + ngraph::element::i8, + { + {ngraph::element::f32}, + {{121.f, 123.f, 125.f, 127.f, 122.f, 124.f, 126.f, 128.f}, ngraph::element::f32, ngraph::Shape{1, 1, 8, 1}}, + {{1.f, 3.f, 5.f, 7.f, 2.f, 4.f, 6.f, 8.f}, ngraph::element::f32, ngraph::Shape {1, 1, 8, 1}}, + } + } + }, + // I8 per channel quantization, shuffling by special dimension + { + LayerTransformation::createParamsI8I8(), + -2, + 4, + { + ngraph::element::i8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + }, + { + ngraph::element::i8, + {}, + ngraph::element::i8, + {{ngraph::element::f32}, {{128.f, 64.f, 32.f}}, {{0.01f, 0.02f, 0.03f}}} + } + }, + // U8 per tensor quantization, not update precision + { + LayerTransformation::createParamsU8I8().setUpdatePrecisions(false), + 3, + 5, + { + ngraph::element::f32, + {{}, {128.f}, {0.02f}} + }, + { + ngraph::element::f32, + {}, + ngraph::element::f32, + {{}, {128.f}, {0.02f}} + } + }, + // U8 without dequantization operations + { + LayerTransformation::createParamsU8I8(), + 2, + 4, + { + ngraph::element::u8, + {{}, {}, {}} + }, + { + ngraph::element::u8, + {}, + ngraph::element::u8, + {{}, {}, {}} + } + }, +}; + +INSTANTIATE_TEST_CASE_P( + smoke_LPT, + ShuffleChannelsTransformation, + ::testing::Combine( + ::testing::ValuesIn(inputShapes), + ::testing::ValuesIn(testValues)), + ShuffleChannelsTransformation::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/inference_engine/transformations/shuffle_channels_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/shuffle_channels_fusion_test.cpp new file mode 100644 index 00000000000..f8e9c6ec259 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/shuffle_channels_fusion_test.cpp @@ -0,0 +1,126 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "common_test_utils/test_common.hpp" +#include +#include + +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +namespace { +using namespace testing; +using namespace ngraph; + +class ShuffleChannelsFusionTestValues { +public: + bool dynamicShape; + std::vector reshape_before_val; + std::vector transpose_val; + std::vector reshape_after_val; + size_t batch_size; + bool check_reshape_values; + bool fuse_happened; +}; + +template +inline std::ostream& operator<<(std::ostream& os, const std::vector& values) { + os << "{ "; + for (size_t i = 0; i < values.size(); ++i) { + os << values[i]; + if (i != (values.size() - 1ul)) { + os << ", "; + } + } + os << " }"; + return os; +} + +class ShuffleChannelsFusion : public ::testing::Test, public testing::WithParamInterface { +public: + void SetUp() override { + const auto values = GetParam(); + { + const PartialShape inputPartialShape = values.dynamicShape ? PartialShape::dynamic() : Shape{ values.batch_size, 128, 720, 480 }; + auto input0 = std::make_shared(element::f32, inputPartialShape); + auto shape_reshape_before = opset6::Constant::create(element::i64, Shape{ values.reshape_before_val.size() }, values.reshape_before_val); + auto permutation = opset6::Constant::create(element::i64, Shape{ values.transpose_val.size() }, values.transpose_val); + auto shape_reshape_after = opset6::Constant::create(element::i64, Shape{ values.reshape_after_val.size() }, values.reshape_after_val); + + auto reshape_before = std::make_shared(input0, shape_reshape_before, false); + auto permute = std::make_shared(reshape_before, permutation); + auto reshape_after = std::make_shared(permute, shape_reshape_after, false); + f = std::make_shared(ngraph::NodeVector{ reshape_after }, ngraph::ParameterVector{ input0 }); + + ngraph::pass::Manager manager; + auto pass_config = manager.get_pass_config(); + manager.register_pass(); + manager.register_pass(values.check_reshape_values); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + if (values.fuse_happened) { + auto input0 = std::make_shared(ngraph::element::f32, ngraph::Shape{ values.batch_size, 128, 720, 480 }); + auto shuffle_channels = std::make_shared(input0, 1, values.reshape_before_val[1]); + f_ref = std::make_shared(ngraph::NodeVector{ shuffle_channels }, ngraph::ParameterVector{ input0 }); + } else { + f_ref = f; + } + } + + static std::string getTestCaseName(testing::TestParamInfo obj) { + const ShuffleChannelsFusionTestValues testValues = obj.param; + + std::ostringstream result; + if (testValues.dynamicShape) { + result << "_dynamic_shape_"; + } else { + result << "_batch_size_" << testValues.batch_size; + } + + result << "_before_" << testValues.reshape_before_val + << "_transpose_" << testValues.transpose_val << "_after_" << testValues.reshape_after_val + << (testValues.check_reshape_values ? "check_reshape_values" : ""); + + return result.str(); + } + +protected: + std::shared_ptr f; + std::shared_ptr f_ref; +}; + +TEST_P(ShuffleChannelsFusion, CompareFunctions) { + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +const std::vector testValues = { + { true, {1, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, 128, 720, 480}, 1, false, false }, + { false, {1, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, 128, 720, 480}, 1, false, true }, + { false, {1, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, 128, 720, 480}, 1, true, true }, + { false, {1, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, -1, 720, 480}, 1, false, true }, + { false, {4, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, -1, 720, 480}, 4, false, false }, + { false, {1, 2, 64, 720, 480}, {0, 2, 1, 3, 4}, {1, -1, 720, 480}, 1, true, false }, + { true, {1, 4, 32, 720 * 480}, {0, 2, 1, 3}, {1, 128, 720, 480}, 1, false, false }, + { false, {1, 4, 32, 720 * 480}, {0, 2, 1, 3}, {1, 128, 720, 480}, 1, false, true }, + { false, {1, 2, 64, 720 * 480}, {0, 2, 1, 3}, {1, 128, 720, 480}, 1, true, true }, + { false, {1, 2, 64, 720 * 480}, {0, 2, 1, 3}, {1, -1, 720, 480}, 1, false, true }, + { false, {4, 2, 64, 720 * 480}, {0, 2, 1, 3}, {1, -1, 720, 480}, 4, false, false }, + { false, {1, 2, 64, 720 * 480}, {0, 2, 1, 3}, {1, -1, 720, 480}, 1, true, false }, +}; +INSTANTIATE_TEST_CASE_P( + TransformationTests, + ShuffleChannelsFusion, + ::testing::ValuesIn(testValues), + ShuffleChannelsFusion::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp new file mode 100644 index 00000000000..6d2e97a0008 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision_transformations/shuffle_channels_transformation.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector netPrecisions = { + ngraph::element::f32, + // ngraph::element::f16 +}; + +const std::vector inputShapes = { + { 1, 3, 16, 16 }, + { 4, 3, 16, 16 } +}; + +const std::vector trasformationParamValues = { + LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true), +}; + +const std::vector params = { + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + 0, + 1, + "output_original", + "U8" + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + -3, + 1, + "output_original", + "U8" + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { 0.f, 0.f, 0.f }, + { 25.5f / 2.f, 25.5f / 4.f, 25.5f } + }, + -3, + 1, + "output_original", + "U8" + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { -4.f, -3.f, 0.f }, + { 10.f, 12.f, 25.5f } + }, + -3, + 1, + "output_original", + "U8" + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + 2, + 4, + "output_original", + "U8" + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { 0.f, 0.f, 0.f }, + { 25.5f / 2.f, 25.5f / 4.f, 25.5f } + }, + -1, + 8, + "output_original", + "U8" + }, +}; + +INSTANTIATE_TEST_CASE_P(smoke_LPT, ShuffleChannelsTransformation, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(inputShapes), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::ValuesIn(trasformationParamValues), + ::testing::ValuesIn(params)), + ShuffleChannelsTransformation::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp new file mode 100644 index 00000000000..e1fae4213e9 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/shuffle_channels_transformation.cpp @@ -0,0 +1,88 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision_transformations/shuffle_channels_transformation.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector netPrecisions = { + ngraph::element::f32, + ngraph::element::f16 +}; + +const std::vector inputShapes = { + { 1, 3, 16, 16 } +}; + +const std::vector trasformationParamValues = { + LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams(), +}; + +const std::vector params = { + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + 0, + 1, + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + -3, + 1, + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { 0.f, 0.f, 0.f }, + { 25.5f / 2.f, 25.5f / 4.f, 25.5f } + }, + -3, + 1, + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { -4.f, -3.f, 0.f }, + { 10.f, 12.f, 25.5f } + }, + -3, + 1, + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + 2, + 4, + }, + { + { + 256ul, + ngraph::Shape { 1, 3, 1, 1 }, + { 0.f }, + { 25.5f }, + { 0.f, 0.f, 0.f }, + { 25.5f / 2.f, 25.5f / 4.f, 25.5f } + }, + -1, + 8, + }, +}; + +INSTANTIATE_TEST_CASE_P(smoke_LPT, ShuffleChannelsTransformation, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(inputShapes), + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::ValuesIn(trasformationParamValues), + ::testing::ValuesIn(params)), + ShuffleChannelsTransformation::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/shuffle_channels_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/shuffle_channels_transformation.hpp new file mode 100644 index 00000000000..217eb2f7ea9 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/shuffle_channels_transformation.hpp @@ -0,0 +1,43 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp" +#include "lpt_ngraph_functions/common/fake_quantize_on_data.hpp" + +namespace LayerTestsDefinitions { + +class ShuffleChannelsTransformationParam { +public: + ngraph::builder::subgraph::FakeQuantizeOnData fakeQuantizeOnData; + std::int64_t axis; + std::int64_t group; + std::string layerName; + std::string expectedKernelType; +}; + +typedef std::tuple< + ngraph::element::Type, + ngraph::Shape, + std::string, + ngraph::pass::low_precision::LayerTransformation::Params, + ShuffleChannelsTransformationParam +> ShuffleChannelsTransformationParams; + +class ShuffleChannelsTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; + void Run() override; +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/shuffle_channels_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/shuffle_channels_transformation.cpp new file mode 100644 index 00000000000..06d502a69d8 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/shuffle_channels_transformation.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "low_precision_transformations/shuffle_channels_transformation.hpp" + +#include +#include +#include +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "lpt_ngraph_functions/shuffle_channels_function.hpp" + +namespace LayerTestsDefinitions { + +std::string ShuffleChannelsTransformation::getTestCaseName(testing::TestParamInfo obj) { + ngraph::element::Type netPrecision; + ngraph::Shape inputShape; + std::string targetDevice; + ngraph::pass::low_precision::LayerTransformation::Params params; + ShuffleChannelsTransformationParam param; + std::tie(netPrecision, inputShape, targetDevice, params, param) = obj.param; + + std::ostringstream result; + result << getTestCaseNameByParams(netPrecision, inputShape, targetDevice, params) << "_" << + param.fakeQuantizeOnData << "_axis_" << param.axis << "_group_" << param.group; + return result.str(); +} + +void ShuffleChannelsTransformation::SetUp() { + ngraph::element::Type netPrecision; + ngraph::Shape inputShape; + ngraph::pass::low_precision::LayerTransformation::Params params; + ShuffleChannelsTransformationParam param; + std::tie(netPrecision, inputShape, targetDevice, params, param) = this->GetParam(); + + function = ngraph::builder::subgraph::ShuffleChannelsFunction::getOriginal( + netPrecision, + inputShape, + param.fakeQuantizeOnData, + param.axis, + param.group); +} + +void ShuffleChannelsTransformation::Run() { + LayerTestsCommon::Run(); + + const auto params = std::get<4>(GetParam()); + const auto actualType = getRuntimePrecision(params.layerName); + EXPECT_EQ(actualType, params.expectedKernelType); +} + +TEST_P(ShuffleChannelsTransformation, CompareWithRefImpl) { + Run(); +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/shuffle_channels_function.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/shuffle_channels_function.hpp new file mode 100644 index 00000000000..6ebd3bcda99 --- /dev/null +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/shuffle_channels_function.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "lpt_ngraph_functions/common/dequantization_operations.hpp" +#include "lpt_ngraph_functions/common/builders.hpp" + +namespace ngraph { +namespace builder { +namespace subgraph { + +class ShuffleChannelsFunction { +public: + static std::shared_ptr getOriginal( + const ngraph::element::Type inputPrecision, + const ngraph::Shape& inputShape, + const ngraph::builder::subgraph::DequantizationOperations& deqBefore, + const std::int64_t axis, + const std::int64_t group); + + static std::shared_ptr getOriginal( + const ngraph::element::Type inputPrecision, + const ngraph::Shape& inputShape, + const ngraph::builder::subgraph::FakeQuantizeOnData& fqOnData, + const std::int64_t axis, + const std::int64_t group); + + static std::shared_ptr getReference( + const ngraph::element::Type inputPrecision, + const ngraph::Shape& inputShape, + const ngraph::builder::subgraph::DequantizationOperations& deqBefore, + const std::int64_t axis, + const std::int64_t group, + const ngraph::element::Type precisionAfterOperation, + const ngraph::builder::subgraph::DequantizationOperations& deqAfter); +}; + +} // namespace subgraph +} // namespace builder +} // namespace ngraph diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/shuffle_channels_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/shuffle_channels_function.cpp new file mode 100644 index 00000000000..5d3eb571204 --- /dev/null +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/shuffle_channels_function.cpp @@ -0,0 +1,83 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision/network_helper.hpp" +#include "lpt_ngraph_functions/common/builders.hpp" + +#include "lpt_ngraph_functions/shuffle_channels_function.hpp" +#include "ngraph_functions/subgraph_builders.hpp" + +namespace ngraph { +namespace builder { +namespace subgraph { +std::shared_ptr ShuffleChannelsFunction::getOriginal( + const element::Type inputPrecision, + const Shape& inputShape, + const builder::subgraph::DequantizationOperations& deqBefore, + const std::int64_t axis, + const std::int64_t group) { + const auto input = std::make_shared(inputPrecision, inputShape); + const auto dequantization = makeDequantization(input, deqBefore); + + const auto shuffleChannels = std::make_shared(dequantization, axis, group); + shuffleChannels->set_friendly_name("output"); + + const auto function = std::make_shared( + ResultVector{ std::make_shared(shuffleChannels) }, + ParameterVector{ input }, + "ShuffleChannelsFunction"); + + return function; +} + +std::shared_ptr ShuffleChannelsFunction::getOriginal( + const ngraph::element::Type inputPrecision, + const ngraph::Shape& inputShape, + const ngraph::builder::subgraph::FakeQuantizeOnData& fqOnData, + const std::int64_t axis, + const std::int64_t group) { + const auto input = std::make_shared(inputPrecision, inputShape); + const auto fakeQuantize = makeFakeQuantize(input, inputPrecision, fqOnData); + + const auto shuffleChannels = std::make_shared(fakeQuantize, axis, group); + shuffleChannels->set_friendly_name("output"); + + const auto function = std::make_shared( + ResultVector{ std::make_shared(shuffleChannels) }, + ParameterVector{ input }, + "ShuffleChannelsFunction"); + + return function; +} + +std::shared_ptr ShuffleChannelsFunction::getReference( + const ngraph::element::Type inputPrecision, + const ngraph::Shape& inputShape, + const ngraph::builder::subgraph::DequantizationOperations& deqBefore, + const std::int64_t axis, + const std::int64_t group, + const ngraph::element::Type precisionAfterOperation, + const ngraph::builder::subgraph::DequantizationOperations& deqAfter) { + const auto input = std::make_shared(inputPrecision, inputShape); + const auto dequantizationBefore = makeDequantization(input, deqBefore); + + const auto shuffleChannels = std::make_shared(dequantizationBefore, axis, group); + ngraph::pass::low_precision::NetworkHelper::setOutDataPrecision(shuffleChannels, precisionAfterOperation); + + const auto dequantizationAfter = makeDequantization(shuffleChannels, deqAfter); + dequantizationAfter->set_friendly_name("output"); + + const auto function = std::make_shared( + ResultVector{ std::make_shared(dequantizationAfter) }, + ParameterVector{ input }, + "ShuffleChannelsFunction"); + + return function; +} + +} // namespace subgraph +} // namespace builder +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/shuffle_channels.hpp b/ngraph/core/include/ngraph/op/shuffle_channels.hpp index 0cfcad09d8d..4bccd9c231a 100644 --- a/ngraph/core/include/ngraph/op/shuffle_channels.hpp +++ b/ngraph/core/include/ngraph/op/shuffle_channels.hpp @@ -19,8 +19,8 @@ namespace ngraph class NGRAPH_API ShuffleChannels : public Op { public: - static constexpr NodeTypeInfo type_info{"ShuffleChannels", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; + ShuffleChannels() = default; /// \brief Constructs a ShuffleChannels node. /// diff --git a/ngraph/core/src/op/shuffle_channels.cpp b/ngraph/core/src/op/shuffle_channels.cpp index 205addd4ffe..5c2e2cb7837 100644 --- a/ngraph/core/src/op/shuffle_channels.cpp +++ b/ngraph/core/src/op/shuffle_channels.cpp @@ -16,7 +16,9 @@ using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::ShuffleChannels::type_info; +NGRAPH_SUPPRESS_DEPRECATED_START + +NGRAPH_RTTI_DEFINITION(op::v0::ShuffleChannels, "ShuffleChannels", 0); op::ShuffleChannels::ShuffleChannels(const Output& data, const int64_t axis, From 8d2bc2b8959524155e0a1398c12e8c7382ffaa7e Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Fri, 23 Apr 2021 15:01:59 +0300 Subject: [PATCH 68/78] [PyPI] Corrected OS support matrix (#4919) + removed optional --system-site-packages from the instructions --- docs/install_guides/pypi-openvino-dev.md | 9 ++++----- docs/install_guides/pypi-openvino-rt.md | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/install_guides/pypi-openvino-dev.md b/docs/install_guides/pypi-openvino-dev.md index b8c3dcc3e52..6fbd66ecc8e 100644 --- a/docs/install_guides/pypi-openvino-dev.md +++ b/docs/install_guides/pypi-openvino-dev.md @@ -30,11 +30,10 @@ The table below lists the supported operating systems and Python* versions requi | :------------------------------------------------------------| :---------------------------------------------------| | Ubuntu* 18.04 long-term support (LTS), 64-bit | 3.6, 3.7 | | Ubuntu* 20.04 long-term support (LTS), 64-bit | 3.6, 3.7 | -| Red Hat* Enterprise Linux* 8.2, 64-bit | 3.6, 3.7 | -| CentOS* 7.4, 64-bit | 3.6, 3.7 | +| Red Hat* Enterprise Linux* 8, 64-bit | 3.6, 3.7 | +| CentOS* 7, 64-bit | 3.6, 3.7 | | macOS* 10.15.x versions | 3.6, 3.7, 3.8 | -| Windows 10*, 64-bit Pro, Enterprise or Education (1607 Anniversary Update, Build 14393 or higher) editions | 3.6, 3.7, 3.8 | -| Windows Server* 2016 or higher | 3.6, 3.7, 3.8 | +| Windows 10*, 64-bit | 3.6, 3.7, 3.8 | > **NOTE**: This package can be installed on other versions of Linux and Windows OSes, but only the specific versions above are fully validated. @@ -48,7 +47,7 @@ To avoid dependency conflicts, use a virtual environment. Skip this Create virtual environment: ```sh python -m pip install --user virtualenv -python -m venv openvino_env --system-site-packages +python -m venv openvino_env ``` > **NOTE**: On Linux and macOS, you may need to type `python3` instead of diff --git a/docs/install_guides/pypi-openvino-rt.md b/docs/install_guides/pypi-openvino-rt.md index 9b825c86518..03a7eae1858 100644 --- a/docs/install_guides/pypi-openvino-rt.md +++ b/docs/install_guides/pypi-openvino-rt.md @@ -27,11 +27,10 @@ The table below lists the supported operating systems and Python* versions requi | :------------------------------------------------------------| :---------------------------------------------------| | Ubuntu* 18.04 long-term support (LTS), 64-bit | 3.6, 3.7 | | Ubuntu* 20.04 long-term support (LTS), 64-bit | 3.6, 3.7 | -| Red Hat* Enterprise Linux* 8.2, 64-bit | 3.6, 3.7 | -| CentOS* 7.4, 64-bit | 3.6, 3.7 | +| Red Hat* Enterprise Linux* 8, 64-bit | 3.6, 3.7 | +| CentOS* 7, 64-bit | 3.6, 3.7 | | macOS* 10.15.x versions | 3.6, 3.7, 3.8 | -| Windows 10*, 64-bit Pro, Enterprise or Education (1607 Anniversary Update, Build 14393 or higher) editions | 3.6, 3.7, 3.8 | -| Windows Server* 2016 or higher | 3.6, 3.7, 3.8 | +| Windows 10*, 64-bit | 3.6, 3.7, 3.8 | > **NOTE**: This package can be installed on other versions of Linux and Windows OSes, but only the specific versions above are fully validated. @@ -45,7 +44,7 @@ To avoid dependency conflicts, use a virtual environment. Skip this Create virtual environment: ```sh python -m pip install --user virtualenv -python -m venv openvino_env --system-site-packages +python -m venv openvino_env ``` > **NOTE**: On Linux and macOS, you may need to type `python3` instead of From 59a001580fe34e2320991a7989b677eeb161fba5 Mon Sep 17 00:00:00 2001 From: Gabriele Galiero Casay Date: Fri, 23 Apr 2021 14:58:08 +0200 Subject: [PATCH 69/78] Revise Split operation reference implementation (#5174) * Review Split operation class * Added node validation checks * Added type_prop unit tests with invalid cases and negative axis value * Add ngraph check for host tensor inputs and outputs * Enable CPU backend tests * Add serialization single layer tests * Add more precisions, axis and num of splits in single layer tests * Add op to script of trusted operations * Fix check macro for inputs and outputs in evaluate method * Fix comparison of integer expressions of different signedness compilation error * Add validation check for upper bound dimension for dynamic shapes * Add node validation check for num_splits attribute greater than zero * Align spec with num_splits attribute range of values --- docs/ops/movement/Split_1.md | 2 +- ngraph/core/src/op/split.cpp | 57 +++-- ngraph/test/runtime/ie/unit_test.manifest | 10 - ngraph/test/type_prop/split.cpp | 264 ++++++++++++++++------ 4 files changed, 241 insertions(+), 92 deletions(-) diff --git a/docs/ops/movement/Split_1.md b/docs/ops/movement/Split_1.md index c93df849453..1dfa5f10c6f 100644 --- a/docs/ops/movement/Split_1.md +++ b/docs/ops/movement/Split_1.md @@ -22,7 +22,7 @@ Where D is the rank of input tensor `data`. The axis being split must be evenly * *num_splits* * **Description**: number of outputs into which the input tensor `data` will be split along `axis` dimension. The dimension of `data` shape along `axis` must be evenly divisible by *num_splits* - * **Range of values**: a positive integer less than or equal to the value of `axis` dimension being split over + * **Range of values**: an integer within the range `[1, data.shape[axis]]` * **Type**: `int` * **Default value**: none * **Required**: *yes* diff --git a/ngraph/core/src/op/split.cpp b/ngraph/core/src/op/split.cpp index 1b91b154457..82c886bd9ed 100644 --- a/ngraph/core/src/op/split.cpp +++ b/ngraph/core/src/op/split.cpp @@ -36,28 +36,29 @@ bool ngraph::op::v1::Split::visit_attributes(AttributeVisitor& visitor) void op::v1::Split::validate_and_infer_types() { NGRAPH_OP_SCOPE(v1_Split_validate_and_infer_types); - const auto data_ps = input_value(0).get_partial_shape(); - const auto axis_ps = input_value(1).get_partial_shape(); - const auto axis_et = input_value(1).get_element_type(); - - if (axis_ps.rank().is_static()) - { - NODE_VALIDATION_CHECK(this, - axis_ps.rank().get_length() == 0, - "The 'axis' input is expected to be a scalar. Got: ", - axis_ps); - } + const PartialShape& data_ps = get_input_partial_shape(0); + const PartialShape& axis_ps = get_input_partial_shape(1); + const element::Type& axis_et = get_input_element_type(1); NODE_VALIDATION_CHECK( - this, axis_et.is_integral(), "The 'axis' input only accepts integral types"); + this, axis_ps.rank().compatible(0), "'axis' input must be a scalar. Got: ", axis_ps); + + NODE_VALIDATION_CHECK(this, + axis_et.is_integral_number(), + "Element type of 'axis' input must be integer. Got: ", + axis_et); + + NODE_VALIDATION_CHECK(this, + m_num_splits > 0, + "Attribute 'num_splits' must be greater than zero. Got: ", + m_num_splits); PartialShape each_output_shape{data_ps}; + const Rank data_rank = data_ps.rank(); const auto axis_input = get_constant_from_source(input_value(1)); - if (axis_input && data_ps.rank().is_static()) + if (axis_input && data_rank.is_static()) { auto axis = axis_input->cast_vector()[0]; - - const auto data_rank = get_input_partial_shape(0).rank(); axis = ngraph::normalize_axis(this, axis, data_rank); if (data_ps[axis].is_static()) @@ -66,16 +67,34 @@ void op::v1::Split::validate_and_infer_types() NODE_VALIDATION_CHECK(this, dimension_at_axis % m_num_splits == 0, - "The input tensor's dimension pointed by the 'axis' parameter: ", + "Dimension of data input shape along 'axis': ", dimension_at_axis, - " has to be a multiple of the 'num_splits' attribute value: ", + " must be evenly divisible by 'num_splits' attribute value: ", m_num_splits); each_output_shape[axis] = dimension_at_axis / m_num_splits; } else { - each_output_shape[axis] = Dimension::dynamic(); + const auto dim_interval_at_axis = data_ps[axis].get_interval(); + NODE_VALIDATION_CHECK( + this, + dim_interval_at_axis.get_max_val() >= static_cast(m_num_splits), + "The interval maximum of the dimension for data input shape along 'axis' must be " + "greater or equal to 'num_splits' attribute. Got: ", + dim_interval_at_axis, + " and ", + m_num_splits); + + auto dim_interval_at_axis_min = + static_cast(dim_interval_at_axis.get_min_val() * (1.0f / m_num_splits)); + auto dim_interval_at_axis_max = dim_interval_at_axis.get_max_val(); + if (dim_interval_at_axis.has_upper_bound()) + { + dim_interval_at_axis_max = + static_cast(dim_interval_at_axis_max * (1.0f / m_num_splits)); + } + each_output_shape[axis] = Dimension(dim_interval_at_axis_min, dim_interval_at_axis_max); } } else @@ -142,6 +161,8 @@ namespace split bool op::v1::Split::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v1_Split_evaluate); + NGRAPH_CHECK(validate_host_tensor_vector(outputs, m_num_splits) && + validate_host_tensor_vector(inputs, 2)); const auto& data = inputs[0]; const auto& axis = inputs[1]; return split::evaluate_split(data, axis, outputs, m_num_splits, this); diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 55eb04de1fc..ae984901d13 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -69,16 +69,6 @@ onnx_model_split_variable_parts_2d onnx_top_k_opset_10_const_k onnx_top_k_opset_11_const_k_smallest onnx_top_k_opset_11_const_k_smallest_negative_axis -split_1d -split_2d_axis_0 -split_2d_axis_1 -split_3d_axis_0 -split_3d_axis_1 -split_3d_axis_2 -split_4d_axis_0 -split_4d_axis_1 -split_4d_axis_2 -split_4d_axis_3 # [NOT_IMPLEMENTED] Input image format BOOL is not supported yet... bool_input_or diff --git a/ngraph/test/type_prop/split.cpp b/ngraph/test/type_prop/split.cpp index 864691afb10..b83fc27dee7 100644 --- a/ngraph/test/type_prop/split.cpp +++ b/ngraph/test/type_prop/split.cpp @@ -11,66 +11,7 @@ NGRAPH_SUPPRESS_DEPRECATED_START using namespace std; using namespace ngraph; -TEST(type_prop, split) -{ - const auto data = make_shared(element::i32, Shape{2, 6}); - - try - { - const auto axis = op::Constant::create(element::i64, Shape{}, {1}); - const auto split = make_shared(data, axis, 7); - FAIL() << "Split node was created with incorrect data."; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING( - error.what(), - std::string("The input tensor's dimension pointed by the 'axis' parameter: 6 has to be " - "a multiple of the 'num_splits' attribute value: 7")); - } - - try - { - const auto axis = op::Constant::create(element::i64, Shape{}, {-5}); - const auto split = make_shared(data, axis, 4); // invalid axis - FAIL() << "Split node was created with incorrect data."; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Parameter axis -5 out of the tensor rank")); - } - - const auto axis = op::Constant::create(element::i64, Shape{}, {1}); - const auto split = make_shared(data, axis, 2); - EXPECT_EQ(split->outputs().size(), 2); - EXPECT_EQ(split->get_output_shape(0), (Shape{2, 3})); - EXPECT_EQ(split->get_output_shape(1), (Shape{2, 3})); - EXPECT_EQ(split->get_output_element_type(0), element::i32); - EXPECT_EQ(split->get_output_element_type(1), element::i32); -} - -TEST(type_prop, split_axis_must_be_scalar) -{ - const auto data = make_shared(element::i32, Shape{2, 6}); - const auto axis = op::Constant::create(element::i64, Shape{2}, {0, 1}); - - try - { - const auto split = make_shared(data, axis, 1); - FAIL() << "Incorrect axis of Split not detected."; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("The 'axis' input is expected to be a scalar")); - } - catch (...) - { - FAIL() << "Deduced type check failed for unexpected reason."; - } -} - -TEST(type_prop, split_v1) +TEST(type_prop, split_v1_axis_const_positive) { const auto data = make_shared(element::f16, Shape{2, 3, 4}); const auto axis = op::Constant::create(element::i64, {}, {1}); @@ -85,6 +26,21 @@ TEST(type_prop, split_v1) } } +TEST(type_prop, split_v1_axis_const_negative) +{ + const auto data = make_shared(element::i32, Shape{2, 6}); + const auto axis = op::Constant::create(element::i64, {}, {-2}); + const size_t num_splits = 2; + const auto split = make_shared(data, axis, num_splits); + + EXPECT_EQ(split->outputs().size(), num_splits); + for (size_t i = 0; i < num_splits; ++i) + { + EXPECT_EQ(split->get_output_element_type(i), element::i32); + EXPECT_EQ(split->get_output_shape(i), (Shape{1, 6})); + } +} + TEST(type_prop, split_v1_axis_const_data_axis_dim_known) { const auto data = @@ -132,6 +88,61 @@ TEST(type_prop, split_v1_axis_const_data_axis_dim_unknown) } } +TEST(type_prop, split_v1_axis_const_data_axis_dim_interval_known_divisible) +{ + const auto data = + make_shared(element::f32, PartialShape{4, Dimension(3, 6), 3, 5}); + const auto axis = op::Constant::create(element::i8, {}, {1}); + const size_t num_splits = 3; + const auto split = make_shared(data, axis, num_splits); + + EXPECT_EQ(split->outputs().size(), num_splits); + for (size_t i = 0; i < num_splits; ++i) + { + EXPECT_EQ(split->get_output_partial_shape(i), + (PartialShape{4, Dimension(1, 2), 3, 5})); + } +} + +TEST(type_prop, split_v1_axis_const_data_axis_dim_interval_known_upper_bound_divisible) +{ + const auto data = + make_shared(element::f32, PartialShape{4, Dimension(2, 4), 3, 5}); + const auto axis = op::Constant::create(element::i8, {}, {1}); + const size_t num_splits = 3; + const auto split = make_shared(data, axis, num_splits); + + EXPECT_EQ(split->outputs().size(), num_splits); + for (size_t i = 0; i < num_splits; ++i) + { + EXPECT_EQ(split->get_output_partial_shape(i), + (PartialShape{4, Dimension(0, 1), 3, 5})); + } +} + +TEST(type_prop, split_v1_axis_const_invalid_data_axis_dim_interval_known) +{ + const auto data = + make_shared(element::f32, PartialShape{4, Dimension(1, 2), 3, 5}); + const auto axis = op::Constant::create(element::i8, {}, {1}); + const size_t num_splits = 3; + try + { + const auto split = make_shared(data, axis, num_splits); + FAIL() << "Invalid dimension of data input along axis not detected"; + } + catch(const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + "The interval maximum of the dimension for data input shape along 'axis' must be " + "greater or equal to 'num_splits' attribute."); + } + catch (...) + { + FAIL() << "Invalid dimension of data input along axis validation check failed for unexpected reason"; + } +} + TEST(type_prop, split_v1_axis_const_only_data_rank_known) { const auto data = make_shared(element::f32, PartialShape::dynamic(4)); @@ -146,7 +157,7 @@ TEST(type_prop, split_v1_axis_const_only_data_rank_known) } } -TEST(type_prop, split_v1_axis_not_const_only_data_rank_known) +TEST(type_prop, split_v1_axis_param_only_data_rank_known) { const auto data = make_shared(element::f32, PartialShape::dynamic(4)); const auto axis = make_shared(element::u32, PartialShape{}); @@ -174,7 +185,7 @@ TEST(type_prop, split_v1_axis_const_data_rank_unknown) } } -TEST(type_prop, split_v1_axis_not_const_data_rank_unknown) +TEST(type_prop, split_v1_axis_param_data_rank_unknown) { const auto data = make_shared(element::f32, PartialShape::dynamic()); const auto axis = make_shared(element::u8, PartialShape{}); @@ -188,7 +199,7 @@ TEST(type_prop, split_v1_axis_not_const_data_rank_unknown) } } -TEST(type_prop, split_v1_axis_dynamic_rank) +TEST(type_prop, split_v1_axis_param_dynamic_ranks) { const auto data = make_shared(element::f32, PartialShape::dynamic()); const auto axis = make_shared(element::u8, PartialShape::dynamic()); @@ -201,3 +212,130 @@ TEST(type_prop, split_v1_axis_dynamic_rank) EXPECT_EQ(split->get_output_partial_shape(i), PartialShape::dynamic()); } } + +TEST(type_prop, split_v1_invalid_axis_et) +{ + auto data = make_shared(element::f32, Shape{2, 6}); + + try + { + auto axis = op::Constant::create(element::f32, Shape{}, {1}); + auto split = make_shared(data, axis, 2); + // axis input element type is floating-point + FAIL() << "Invalid floating-point element type of 'axis' input not detected"; + } + catch (NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "Element type of 'axis' input must be integer."); + } + catch(...) + { + FAIL() << "Element type of 'axis' input validation check failed for unexpected reason"; + } + + try + { + auto axis = op::Constant::create(element::boolean, Shape{}, {1}); + auto split = make_shared(data, axis, 2); + // axis input element type is boolean + FAIL() << "Invalid boolean element type of axis input not detected"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "Element type of 'axis' input must be integer."); + } + catch(...) + { + FAIL() << "Element type of 'axis' input validation check failed for unexpected reason"; + } +} + +TEST(type_prop, split_v1_invalid_axis_not_a_scalar) +{ + auto data = make_shared(element::i32, Shape{2, 6}); + auto axis = op::Constant::create(element::i64, Shape{2}, {0, 1}); + + try + { + auto split = make_shared(data, axis, 1); + // axis has rank 1, not a scalar + FAIL() << "Invalid shape of axis input not detected"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("'axis' input must be a scalar.")); + } + catch (...) + { + FAIL() << "Scalar 'axis' input validation check failed for unexpected reason"; + } +} + +TEST(type_prop, split_v1_invalid_num_splits) +{ + auto data = make_shared(element::i32, Shape{2, 6}); + auto axis = op::Constant::create(element::i64, Shape{}, {1}); + const size_t num_splits = 0; + try + { + auto split = make_shared(data, axis, num_splits); + // num_splits value is zero + FAIL() << "Invalid 'num_splits' attribute value not detected."; + } + catch (const ngraph_error& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "Attribute 'num_splits' must be greater than zero"); + } + catch(...) + { + FAIL() << "Attribute 'num_splits' validation check failed for unexpected reason"; + } +} + +TEST(type_prop, split_v1_invalid_axis_value) +{ + auto data = make_shared(element::i32, Shape{2, 6}); + auto axis = op::Constant::create(element::i64, Shape{}, {-5}); + const size_t num_splits = 4; + try + { + auto split = make_shared(data, axis, num_splits); + // axis value not in the range [-2, 1] + FAIL() << "Invalid 'axis' value not detected."; + } + catch (const ngraph_error& error) + { + EXPECT_HAS_SUBSTRING(error.what(), "Parameter axis -5 out of the tensor rank range"); + } + catch(...) + { + FAIL() << "'axis' value validation check failed for unexpected reason"; + } +} + +TEST(type_prop, split_v1_incompatible_data_shape_with_num_splits) +{ + auto data = make_shared(element::i32, Shape{2, 6}); + auto axis = op::Constant::create(element::i64, Shape{}, {1}); + const size_t num_splits = 4; + + try + { + auto split = make_shared(data, axis, num_splits); + FAIL() << "Incompatible shape of data input along 'axis' and 'num_splits' attribute " + "not detected."; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Dimension of data input shape along 'axis': 6 must be evenly " + "divisible by 'num_splits' attribute value: 4")); + } + catch(...) + { + FAIL() << "Data input shape along 'axis' dimension validation check with " + "'num_splits' attribute, failed for unexpected reason"; + } +} From 0a8c3ef5a921c44daa5cb10e6b7c6583fbb69c1c Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 23 Apr 2021 16:34:26 +0300 Subject: [PATCH 70/78] Fixed python test_utils compilation for clang-12 (#5362) --- .../ie_bridges/python/src/openvino/test_utils/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt b/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt index 949d32f1692..cef09321eb8 100644 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt @@ -34,7 +34,8 @@ else() list(APPEND InferenceEngine_LIBRARIES IE::commonTestUtils) endif() -target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../inference_engine") +target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inference_engine") target_link_libraries(${TARGET_NAME} PRIVATE ${InferenceEngine_LIBRARIES}) # Compatibility with python 2.7 which has deprecated "register" specifier From 9a569805c234a5dda0eeea2c806499a35e515f90 Mon Sep 17 00:00:00 2001 From: Mateusz Bencer Date: Fri, 23 Apr 2021 15:35:46 +0200 Subject: [PATCH 71/78] remove redundant header (#5363) --- .../detail/subgraph_extraction.hpp | 104 ------------------ .../src/detail/subgraph_extraction.cpp | 2 +- 2 files changed, 1 insertion(+), 105 deletions(-) delete mode 100644 ngraph/frontend/onnx_editor/include/onnx_editor/detail/subgraph_extraction.hpp diff --git a/ngraph/frontend/onnx_editor/include/onnx_editor/detail/subgraph_extraction.hpp b/ngraph/frontend/onnx_editor/include/onnx_editor/detail/subgraph_extraction.hpp deleted file mode 100644 index 55220d23ad1..00000000000 --- a/ngraph/frontend/onnx_editor/include/onnx_editor/detail/subgraph_extraction.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include - -#include "onnx_editor/editor_types.hpp" - -namespace ONNX_NAMESPACE -{ - class GraphProto; - class NodeProto; - class ValueInfoProto; -} // namespace ONNX_NAMESPACE - -namespace ngraph -{ - namespace onnx_editor - { - /// \brief Subgraph extraction helper structure - struct SubgraphExtractor - { - SubgraphExtractor(ONNX_NAMESPACE::GraphProto& graph); - - /// \brief Adds new inputs to the graph and connects them to the nodes indicated by - /// the provided input edges. - void add_new_inputs(const std::vector& new_inputs); - - /// \brief Adds new outputs to the graph with the same name as the nodes pointed to - /// by the input edges "new_outputs". - void add_new_outputs(const std::vector& new_outputs); - - /// \brief Extracts the final subgraph by traversing the original model bottom-up - /// starting at each of the provided output edges. The extracted subgraph - /// contains all previously added inputs and potentially a subset of original - /// model's inputs that contribute to the value calculated in the output tensors. - /// In the end the underlying GraphProto is modified and obsolete elements - /// are discarded after this method call has finished. - /// - /// \param subgraph_outputs A list of expected outputs of the extracted subgraph. - void extract_subgraph(std::vector subgraph_outputs); - - /// \brief Represents a subgraph of an ONNX model by holding a subset of nodes, inputs, - /// outputs and initializers of the original graph. Objects of this struct can be - /// merged into other instances using the += operator to build a subgraph from - /// smaller clusters. - struct SubgraphComponents - { - SubgraphComponents() = default; - SubgraphComponents(const SubgraphComponents&) = delete; - SubgraphComponents(SubgraphComponents&&) = default; - SubgraphComponents& operator=(const SubgraphComponents&) = delete; - SubgraphComponents& operator=(SubgraphComponents&&) = default; - - std::set nodes; - std::set inputs; - std::set initializers; - std::set outputs; - - SubgraphComponents& operator+=(SubgraphComponents&& other) - { - nodes.insert(other.nodes.begin(), other.nodes.end()); - inputs.insert(other.inputs.begin(), other.inputs.end()); - initializers.insert(other.initializers.begin(), other.initializers.end()); - outputs.insert(other.outputs.begin(), other.outputs.end()); - return *this; - } - }; - - private: - ONNX_NAMESPACE::GraphProto& m_onnx_graph; - - // Graph traversal helper: node index -> node inputs (one-to-many) - std::unordered_multimap m_node_inputs; - // Number of consumers of all tensors in the graph - std::map m_tensor_consumers; - - /// \brief Replaces the old input edge with a new one in the helper struct. - /// This is used by the output contributors discovery. - void replace_input_edge(const InputEdge& old_edge, const InputEdge& new_edge); - - /// \brief Returns a list of edges of each outputs of the graph "m_onnx_graph" - std::vector all_output_edges() const; - - /// \brief Traverses the graph bottom-up and collects all nodes, inputs and initializers - /// that contribute to an output designated by the provided output edge. - /// A sum of such SubgraphComponents objects forms a target extracted subgraph. - SubgraphComponents - discover_output_contributors(const OutputEdge& output_edge, - const SubgraphComponents& already_collected) const; - - /// \brief Modifies the underlying GraphProto object and discards all obsolete elements. - /// - /// \param subgraph An object describing the subgraph to be extracted (elems to be kept) - void extract_subgraph_from_onnx_model(const SubgraphComponents& subgraph); - }; - } // namespace onnx_editor -} // namespace ngraph diff --git a/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp b/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp index 9bd2692e082..92980dbab0f 100644 --- a/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp +++ b/ngraph/frontend/onnx_editor/src/detail/subgraph_extraction.cpp @@ -7,7 +7,7 @@ #include #include "ngraph/check.hpp" -#include "onnx_editor/detail/subgraph_extraction.hpp" +#include "subgraph_extraction.hpp" using namespace ngraph::onnx_editor; From 2063f173914e55448f34be2e2bc4b0c872fec5cc Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Fri, 23 Apr 2021 16:40:08 +0300 Subject: [PATCH 72/78] fix: doxygen links for samples (#5365) --- docs/IE_DG/Samples_Overview.md | 35 ++++++++++--------- docs/doxygen/openvino_docs.xml | 22 ++++++------ .../object_detection_sample_ssd/README.md | 4 +-- .../classification_sample_async/README.md | 29 +++++++-------- .../sample/hello_classification/README.md | 26 +++++++------- .../sample/hello_query_device/README.md | 6 ++-- .../python/sample/hello_reshape_ssd/README.md | 26 +++++++------- .../ngraph_function_creation_sample/README.md | 35 +++++++++---------- .../object_detection_sample_ssd/README.md | 27 +++++++------- .../sample/style_transfer_sample/README.md | 26 +++++++------- .../classification_sample_async/README.md | 4 +-- .../object_detection_sample_ssd/README.md | 4 +-- 12 files changed, 123 insertions(+), 121 deletions(-) diff --git a/docs/IE_DG/Samples_Overview.md b/docs/IE_DG/Samples_Overview.md index 8243fc7f7d6..11bfb1d51c3 100644 --- a/docs/IE_DG/Samples_Overview.md +++ b/docs/IE_DG/Samples_Overview.md @@ -1,22 +1,23 @@ # Inference Engine Samples {#openvino_docs_IE_DG_Samples_Overview} -The Inference Engine sample applications are simple console applications that show how to utilize specific Inference Engine capabilities within an application, assist developers in executing specific tasks such as loading a model, running inference, querying specific device capabilities and etc. +The Inference Engine sample applications are simple console applications that show how to utilize specific Inference Engine capabilities within an application, assist developers in executing specific tasks such as loading a model, running inference, querying specific device capabilities and etc. After installation of Intel® Distribution of OpenVINO™ toolkit, С, C++ and Python* sample applications are available in the following directories, respectively: * `/inference_engine/samples/c` * `/inference_engine/samples/cpp` -* `/inference_engine/samples/python` +* `/inference_engine/samples/python` Inference Engine sample applications include the following: + - **[Automatic Speech Recognition C++ Sample](../../inference-engine/samples/speech_sample/README.md)** – Acoustic model inference based on Kaldi neural networks and speech feature vectors. - **Benchmark Application** – Estimates deep learning inference performance on supported devices for synchronous and asynchronous modes. - - [Benchmark C++ Application](../../inference-engine/samples/benchmark_app/README.md) - - [Benchmark Python Application](../../inference-engine/tools/benchmark_tool/README.md) + - [Benchmark C++ Tool](../../inference-engine/samples/benchmark_app/README.md) + - [Benchmark Python Tool](../../inference-engine/tools/benchmark_tool/README.md) - **Hello Classification Sample** – Inference of image classification networks like AlexNet and GoogLeNet using Synchronous Inference Request API. Input of any size and layout can be set to an infer request which will be pre-processed automatically during inference (the sample supports only images as inputs and supports Unicode paths). - [Hello Classification C++ Sample](../../inference-engine/samples/hello_classification/README.md) - [Hello Classification C Sample](../../inference-engine/ie_bridges/c/samples/hello_classification/README.md) - [Hello Classification Python Sample](../../inference-engine/ie_bridges/python/sample/hello_classification/README.md) -- **Hello NV12 Input Classification Sample** – Input of any size and layout can be provided to an infer request. The sample transforms the input to the NV12 color format and pre-process it automatically during inference. The sample supports only images as inputs. +- **Hello NV12 Input Classification Sample** – Input of any size and layout can be provided to an infer request. The sample transforms the input to the NV12 color format and pre-process it automatically during inference. The sample supports only images as inputs. - [Hello NV12 Input Classification C++ Sample](../../inference-engine/samples/hello_nv12_input_classification/README.md) - [Hello NV12 Input Classification C Sample](../../inference-engine/ie_bridges/c/samples/hello_nv12_input_classification/README.md) - **Hello Query Device Sample** – Query of available Inference Engine devices and their metrics, configuration values. @@ -25,21 +26,21 @@ Inference Engine sample applications include the following: - **Hello Reshape SSD Sample** – Inference of SSD networks resized by ShapeInfer API according to an input size. - [Hello Reshape SSD C++ Sample**](../../inference-engine/samples/hello_reshape_ssd/README.md) - [Hello Reshape SSD Python Sample**](../../inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md) -- **Image Classification Sample Async** – Inference of image classification networks like AlexNet and GoogLeNet using Asynchronous Inference Request API (the sample supports only images as inputs). - - [Image Classification C++ Sample Async](../../inference-engine/samples/classification_sample_async/README.md) - - [Image Classification Python* Sample Async](../../inference-engine/ie_bridges/python/sample/classification_sample_async/README.md) -- **Neural Style Transfer Sample** – Style Transfer sample (the sample supports only images as inputs). - - [Neural Style Transfer C++ Sample](../../inference-engine/samples/style_transfer_sample/README.md) - - [Neural Style Transfer Python* Sample](../../inference-engine/ie_bridges/python/sample/style_transfer_sample/README.md) +- **Image Classification Sample Async** – Inference of image classification networks like AlexNet and GoogLeNet using Asynchronous Inference Request API (the sample supports only images as inputs). + - [Image Classification Async C++ Sample](../../inference-engine/samples/classification_sample_async/README.md) + - [Image Classification Async Python* Sample](../../inference-engine/ie_bridges/python/sample/classification_sample_async/README.md) +- **Style Transfer Sample** – Style Transfer sample (the sample supports only images as inputs). + - [Style Transfer C++ Sample](../../inference-engine/samples/style_transfer_sample/README.md) + - [Style Transfer Python* Sample](../../inference-engine/ie_bridges/python/sample/style_transfer_sample/README.md) - **nGraph Function Creation Sample** – Construction of the LeNet network using the nGraph function creation sample. - [nGraph Function Creation C++ Sample](../../inference-engine/samples/ngraph_function_creation_sample/README.md) - [nGraph Function Creation Python Sample](../../inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/README.md) -- **Object Detection for SSD Sample** – Inference of object detection networks based on the SSD, this sample is simplified version that supports only images as inputs. - - [Object Detection for SSD C++ Sample](../../inference-engine/samples/object_detection_sample_ssd/README.md) - - [Object Detection for SSD C Sample](../../inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md) - - [Object Detection for SSD Python* Sample](../../inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md) +- **Object Detection for SSD Sample** – Inference of object detection networks based on the SSD, this sample is simplified version that supports only images as inputs. + - [Object Detection SSD C++ Sample](../../inference-engine/samples/object_detection_sample_ssd/README.md) + - [Object Detection SSD C Sample](../../inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md) + - [Object Detection SSD Python* Sample](../../inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md) -> **NOTE**: All samples support input paths containing only ASCII characters, except the Hello Classification Sample, that supports Unicode. +> **NOTE**: All C++ samples support input paths containing only ASCII characters, except the Hello Classification Sample, that supports Unicode. ## Media Files Available for Samples @@ -55,7 +56,7 @@ To run the sample, you can use [public](@ref omz_models_group_public) or [Intel' The officially supported Linux* build environment is the following: -* Ubuntu* 18.04 LTS 64-bit or CentOS* 7.6 64-bit +* Ubuntu* 18.04 LTS 64-bit or CentOS* 7 64-bit * GCC* 7.5.0 (for Ubuntu* 18.04) or GCC* 4.8.5 (for CentOS* 7.6) * CMake* version 3.10 or higher diff --git a/docs/doxygen/openvino_docs.xml b/docs/doxygen/openvino_docs.xml index 92238645a05..34539a41246 100644 --- a/docs/doxygen/openvino_docs.xml +++ b/docs/doxygen/openvino_docs.xml @@ -163,25 +163,25 @@ limitations under the License. - - + + - + - + - - - - - + + + + + - - + + diff --git a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md index a50649d254c..7370b6ab61f 100644 --- a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md +++ b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/README.md @@ -1,8 +1,8 @@ -# Object Detection C Sample SSD {#openvino_inference_engine_ie_bridges_c_samples_object_detection_sample_ssd_README} +# Object Detection SSD C Sample {#openvino_inference_engine_ie_bridges_c_samples_object_detection_sample_ssd_README} This sample demonstrates how to execute an inference of object detection networks like SSD-VGG using Asynchronous Inference Request API and [input reshape feature](../../../../../docs/IE_DG/ShapeInference.md). -Object Detection C sample SSD application demonstrates how to use the following Inference Engine C API in applications: +Object Detection SSD C sample application demonstrates how to use the following Inference Engine C API in applications: | Feature | API | Description | |:--- |:--- |:--- diff --git a/inference-engine/ie_bridges/python/sample/classification_sample_async/README.md b/inference-engine/ie_bridges/python/sample/classification_sample_async/README.md index 368699665e5..a689438cb8b 100644 --- a/inference-engine/ie_bridges/python/sample/classification_sample_async/README.md +++ b/inference-engine/ie_bridges/python/sample/classification_sample_async/README.md @@ -1,4 +1,4 @@ -# Classification Async Python* Sample {#openvino_inference_engine_ie_bridges_python_sample_classification_sample_async_README} +# Image Classification Async Python* Sample {#openvino_inference_engine_ie_bridges_python_sample_classification_sample_async_README} This sample demonstrates how to do inference of image classification networks using Asynchronous Inference Request API. Models with only 1 input and output are supported. @@ -30,13 +30,13 @@ each sample step at [Integration Steps](../../../../../docs/IE_DG/Integrate_with Run the application with the -h option to see the usage message: -``` +```sh python classification_sample_async.py -h ``` Usage message: -``` +```sh usage: classification_sample_async.py [-h] -m MODEL -i INPUT [INPUT ...] [-l EXTENSION] [-c CONFIG] [-d DEVICE] [--labels LABELS] [-nt NUMBER_TOP] @@ -67,20 +67,21 @@ Options: ``` To run the sample, you need specify a model and image: - - you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. + +- you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. > **NOTES**: > -> * By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). +> - By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). > -> * Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). +> - Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > -> * The sample accepts models in ONNX format (.onnx) that do not require preprocessing. +> - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python classification_sample_async.py -m /alexnet.xml -i /cat.bmp /car.bmp -d GPU ``` @@ -88,7 +89,7 @@ python classification_sample_async.py -m /alexnet.xml -i -h option to see the usage message: -``` +```sh python hello_classification.py -h ``` Usage message: -``` +```sh usage: hello_classification.py [-h] -m MODEL -i INPUT [-d DEVICE] [--labels LABELS] [-nt NUMBER_TOP] @@ -57,20 +57,20 @@ Options: ``` To run the sample, you need specify a model and image: - - you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. +- you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. > **NOTES**: > -> * By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). +> - By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). > -> * Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). +> - Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > -> * The sample accepts models in ONNX format (.onnx) that do not require preprocessing. +> - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python hello_classification.py -m /alexnet.xml -i /cat.bmp -d GPU ``` @@ -78,7 +78,7 @@ python hello_classification.py -m /alexnet.xml -i The sample application logs each step in a standard output stream and outputs top-10 inference results. -``` +```sh [ INFO ] Creating Inference Engine [ INFO ] Reading the network: models\alexnet.xml [ INFO ] Configuring input and output blobs @@ -105,10 +105,10 @@ The sample application logs each step in a standard output stream and outputs to ## See Also -* [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) -* [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) -* [Model Downloader](@ref omz_tools_downloader_README) -* [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) +- [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) +- [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) +- [Model Downloader](@ref omz_tools_downloader_README) +- [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) [IECore]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html [IECore.read_network]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html#a0d69c298618fab3a08b855442dca430f diff --git a/inference-engine/ie_bridges/python/sample/hello_query_device/README.md b/inference-engine/ie_bridges/python/sample/hello_query_device/README.md index 15b1b7e1a45..35e84bc23ed 100644 --- a/inference-engine/ie_bridges/python/sample/hello_query_device/README.md +++ b/inference-engine/ie_bridges/python/sample/hello_query_device/README.md @@ -22,7 +22,7 @@ The sample queries all available Inference Engine devices and prints their suppo The sample has no command-line parameters. To see the report, run the following command: -``` +```sh python hello_query_device.py ``` @@ -30,7 +30,7 @@ python hello_query_device.py For example: -``` +```sh [ INFO ] Creating Inference Engine [ INFO ] Available devices: [ INFO ] CPU : @@ -104,7 +104,7 @@ For example: ## See Also -* [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) +- [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) [IECore]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html [IECore.get_metric]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html#af1cdf2ecbea6399c556957c2c2fdf8eb diff --git a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md index 2c5dac57b23..956f219e1b0 100644 --- a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md +++ b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/README.md @@ -31,13 +31,13 @@ each sample step at [Integration Steps](../../../../../docs/IE_DG/Integrate_with Run the application with the -h option to see the usage message: -``` +```sh python hello_reshape_ssd.py -h ``` Usage message: -``` +```sh usage: hello_reshape_ssd.py [-h] -m MODEL -i INPUT [-l EXTENSION] [-c CONFIG] [-d DEVICE] [--labels LABELS] @@ -65,20 +65,20 @@ Options: ``` To run the sample, you need specify a model and image: - - you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. +- you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. > **NOTES**: > -> * By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). +> - By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). > -> * Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). +> - Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > -> * The sample accepts models in ONNX format (.onnx) that do not require preprocessing. +> - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python hello_reshape_ssd.py -m /mobilenet-ssd.xml -i /cat.bmp -d GPU ``` @@ -86,7 +86,7 @@ python hello_reshape_ssd.py -m /mobilenet-ssd.xml -i -h option to see the usage message: -``` +```sh python ngraph_function_creation_sample.py -h ``` Usage message: -``` +```sh usage: ngraph_function_creation_sample.py [-h] -m MODEL -i INPUT [INPUT ...] [-d DEVICE] [--labels LABELS] [-nt NUMBER_TOP] @@ -57,21 +56,22 @@ Options: ``` To run the sample, you need specify a model weights and image: - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. -> **NOTE**: -> -> * This sample supports models with FP32 weights only. +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. + +> **NOTE**: > -> * The `lenet.bin` weights file was generated by the [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) tool from the public LeNet model with the `--input_shape [64,1,28,28]` parameter specified. +> - This sample supports models with FP32 weights only. > -> * The original model is available in the [Caffe* repository](https://github.com/BVLC/caffe/tree/master/examples/mnist) on GitHub\*. +> - The `lenet.bin` weights file was generated by the [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) tool from the public LeNet model with the `--input_shape [64,1,28,28]` parameter specified. > -> * The white over black images will be automatically inverted in color for a better predictions. +> - The original model is available in the [Caffe* repository](https://github.com/BVLC/caffe/tree/master/examples/mnist) on GitHub\*. +> +> - The white over black images will be automatically inverted in color for a better predictions. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python ngraph_function_creation_sample.py -m /lenet.bin -i /3.bmp -d GPU ``` @@ -79,7 +79,7 @@ python ngraph_function_creation_sample.py -m /lenet.bin -i /lenet.bin [ INFO ] Configuring input and output blobs @@ -116,7 +116,7 @@ The sample application logs each step in a standard output stream and outputs to -
Operation{{results[d]|length}}
Trusted op counter (passrate=100%):{{trusted_ops[d]}}
Tested op counter:{{general_test_count[d]}}
AVG passrate per op (=sum_pass_rates/covered_ops_num):{{ op }}{{ op }}{{ op }}Removal Date December 1, 2020
+ *Starting with the OpenVINO™ toolkit 2020.2 release, all of the features previously available through nGraph have been merged into the OpenVINO™ toolkit. As a result, all the features previously available through ONNX RT Execution Provider for nGraph have been merged with ONNX RT Execution Provider for OpenVINO™ toolkit.* @@ -124,11 +124,10 @@ The sample application logs each step in a standard output stream and outputs to ## See Also -* [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) -* [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) -* [Model Downloader](@ref omz_tools_downloader_README) -* [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) - +- [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) +- [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) +- [Model Downloader](@ref omz_tools_downloader_README) +- [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) [IECore]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html [IENetwork]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IENetwork.html diff --git a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md index a6c77d9e308..17a5640ccf3 100644 --- a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md +++ b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/README.md @@ -31,13 +31,13 @@ each sample step at [Integration Steps](../../../../../docs/IE_DG/Integrate_with Run the application with the -h option to see the usage message: -``` +```sh python object_detection_sample_ssd.py -h ``` Usage message: -``` +```sh usage: object_detection_sample_ssd.py [-h] -m MODEL -i INPUT [-l EXTENSION] [-c CONFIG] [-d DEVICE] [--labels LABELS] @@ -66,20 +66,21 @@ Options: ``` To run the sample, you need specify a model and image: - - you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. + +- you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. > **NOTES**: > -> * By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). +> - By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). > -> * Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). +> - Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > -> * The sample accepts models in ONNX format (.onnx) that do not require preprocessing. +> - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python object_detection_sample_ssd.py -m /mobilenet-ssd.xml -i /cat.bmp -d GPU ``` @@ -87,7 +88,7 @@ python object_detection_sample_ssd.py -m /mobilenet-ssd.xml -i

-h option to see the usage message: -``` +```sh python style_transfer_sample.py -h ``` Usage message: -``` +```sh usage: style_transfer_sample.py [-h] -m MODEL -i INPUT [INPUT ...] [-l EXTENSION] [-c CONFIG] [-d DEVICE] [--original_size] [--mean_val_r MEAN_VAL_R] @@ -79,20 +79,20 @@ Options: ``` To run the sample, you need specify a model and image: - - you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). - - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. +- you can use [public](@ref omz_models_public_index) or [Intel's](@ref omz_models_intel_index) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader_README). +- you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. > **NOTES**: > -> * By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). +> - By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Reverse Input Channels** section of [Converting a Model Using General Conversion Parameters](../../../../../docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md). > -> * Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). +> - Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md). > -> * The sample accepts models in ONNX format (.onnx) that do not require preprocessing. +> - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. You can do inference of an image using a pre-trained model on a GPU using the following command: -``` +```sh python style_transfer_sample.py -m /fast-neural-style-mosaic-onnx.onnx -i /car.png /cat.jpg -d GPU ``` @@ -100,7 +100,7 @@ python style_transfer_sample.py -m /fast-neural-style-mosaic-onnx The sample application logs each step in a standard output stream and creates an output image (`out_0.bmp`) or a sequence of images (`out_0.bmp`, .., `out_.bmp`) that are redrawn in the style of the style transfer model used. -``` +```sh [ INFO ] Creating Inference Engine [ INFO ] Reading the network: models\fast-neural-style-mosaic-onnx.onnx [ INFO ] Configuring input and output blobs @@ -115,10 +115,10 @@ The sample application logs each step in a standard output stream and creates an ## See Also -* [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) -* [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) -* [Model Downloader](@ref omz_tools_downloader_README) -* [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) +- [Integrate the Inference Engine with Your Application](../../../../../docs/IE_DG/Integrate_with_customer_application_new_API.md) +- [Using Inference Engine Samples](../../../../../docs/IE_DG/Samples_Overview.md) +- [Model Downloader](@ref omz_tools_downloader_README) +- [Model Optimizer](../../../../../docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md) [IECore]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html [IECore.add_extension]:https://docs.openvinotoolkit.org/latest/ie_python_api/classie__api_1_1IECore.html#a8a4b671a9928c7c059bd1e76d2333967 diff --git a/inference-engine/samples/classification_sample_async/README.md b/inference-engine/samples/classification_sample_async/README.md index 48f27baf910..9a007fdebb4 100644 --- a/inference-engine/samples/classification_sample_async/README.md +++ b/inference-engine/samples/classification_sample_async/README.md @@ -1,10 +1,10 @@ -# Image Classification C++ Sample Async {#openvino_inference_engine_samples_classification_sample_async_README} +# Image Classification Async C++ Sample {#openvino_inference_engine_samples_classification_sample_async_README} This sample demonstrates how to execute an inference of image classification networks like AlexNet and GoogLeNet using Asynchronous Inference Request API. In addition to regular images, the sample also supports single-channel `ubyte` images as an input for LeNet model. -Image Classification C++ sample application demonstrates how to use the following Inference Engine C++ API in applications: +Image Classification Async C++ sample application demonstrates how to use the following Inference Engine C++ API in applications: | Feature | API | Description | |:--- |:--- |:--- diff --git a/inference-engine/samples/object_detection_sample_ssd/README.md b/inference-engine/samples/object_detection_sample_ssd/README.md index 7dce55e3bea..a52b7d3fcbb 100644 --- a/inference-engine/samples/object_detection_sample_ssd/README.md +++ b/inference-engine/samples/object_detection_sample_ssd/README.md @@ -1,8 +1,8 @@ -# Object Detection C++ Sample SSD {#openvino_inference_engine_samples_object_detection_sample_ssd_README} +# Object Detection SSD C++ Sample {#openvino_inference_engine_samples_object_detection_sample_ssd_README} This sample demonstrates how to execute an inference of object detection networks like SSD-VGG using Synchronous Inference Request API. -Object Detection C++ sample SSD application demonstrates how to use the following Inference Engine C++ API in applications: +Object Detection SSD C++ sample application demonstrates how to use the following Inference Engine C++ API in applications: | Feature | API | Description | |:--- |:--- |:--- From 7d0cae8bb5f1c10595cf60fb02e8f075a7b01fef Mon Sep 17 00:00:00 2001 From: Steve Yoo Date: Fri, 23 Apr 2021 23:19:35 +0900 Subject: [PATCH 73/78] Add test cases for PReLU in cpu plugin (#5293) * For case when slope is vector --- .../shared_tests_instances/single_layer_tests/activation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp index 5decd0d9c88..dfcee6bd5fa 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp @@ -71,6 +71,10 @@ std::map, std::vector>> basic = { std::map, std::vector>> preluBasic = { {{1, 50}, {{1}, {50}}}, {{1, 128}, {{1}, {128}}}, + {{20, 128}, {{20}, {128}, {20, 128}}}, + {{1, 20, 128}, {{1}, {20}, {128}, {20, 128}}}, + {{1, 20, 128, 128}, {{1}, {20}, {128}, {128, 128}, {20, 128, 128}}}, + {{1, 20, 20, 128, 128}, {{1}, {20}, {128}, {128, 128}, {20, 128, 128}, {20, 20, 128, 128}}}, }; const auto basicCases = ::testing::Combine( From fcea3f8a0c73e4e66ed1adedd18c8998b112a361 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Sat, 24 Apr 2021 09:41:48 +0300 Subject: [PATCH 74/78] Implement nGraph shell for Einsum-7 (#5282) * Implement nGraph shell for Einsum-7 Signed-off-by: Roman Kazantsev * Correct doxygen formats Signed-off-by: Roman Kazantsev * Apply clang format change Signed-off-by: Roman Kazantsev * Support implicit mode and capital letters Signed-off-by: Roman Kazantsev * Correct and optimize the code based on review Signed-off-by: Roman Kazantsev * Correct private methods and its API, add more tests Signed-off-by: Roman Kazantsev * Make equation aux methods public and remove regex usage Signed-off-by: Roman Kazantsev * Make is_subscript_correct function local Signed-off-by: Roman Kazantsev * Correct check for missed ellipsis and add test for it Signed-off-by: Roman Kazantsev --- ngraph/core/include/ngraph/op/einsum.hpp | 69 ++++ ngraph/core/include/ngraph/ops.hpp | 1 + .../core/include/ngraph/opsets/opset7_tbl.hpp | 1 + ngraph/core/src/op/einsum.cpp | 308 ++++++++++++++++ ngraph/test/CMakeLists.txt | 1 + ngraph/test/type_prop/einsum.cpp | 349 ++++++++++++++++++ 6 files changed, 729 insertions(+) create mode 100644 ngraph/core/include/ngraph/op/einsum.hpp create mode 100644 ngraph/core/src/op/einsum.cpp create mode 100644 ngraph/test/type_prop/einsum.cpp diff --git a/ngraph/core/include/ngraph/op/einsum.hpp b/ngraph/core/include/ngraph/op/einsum.hpp new file mode 100644 index 00000000000..08f066823e9 --- /dev/null +++ b/ngraph/core/include/ngraph/op/einsum.hpp @@ -0,0 +1,69 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ngraph/node.hpp" +#include "ngraph/op/op.hpp" + +namespace ngraph +{ + namespace op + { + namespace v7 + { + /// \brief Einsum operation. + class NGRAPH_API Einsum : public Op + { + public: + NGRAPH_RTTI_DECLARATION; + + Einsum() = default; + + /// + /// \brief Constructs Einsum operation. + /// + /// \param inputs Input nodes on which Einsum operation performs + /// contraction + /// + /// \param equation Einstein summation convention + /// + Einsum(const OutputVector& inputs, const std::string& equation); + + void validate_and_infer_types() override; + + bool visit_attributes(AttributeVisitor& visitor) override; + + std::shared_ptr + clone_with_new_inputs(const OutputVector& new_args) const override; + + /// \brief Check correctness of equation format and extract input subscripts + /// and output subscript + /// + /// \param equation Equation to be parsed and checked + /// + /// \param input_subscripts A vector of extracted input subscripts + /// + /// \param output_subscript An output subscript + /// + static void parse_equation(const std::string& equation, + std::vector& input_subscripts, + std::string& output_subscript); + + /// \brief Extract labels (from subscript) that can be alphabetic letters or + /// ellipsis + /// + /// \param subscript Subscript + /// + /// \return A vector of extracted labels from the input subscript in the order + /// of appearence + /// + static std::vector extract_labels(const std::string& subscript); + + private: + std::string m_equation; + }; + } // namespace v7 + } // namespace op +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/ops.hpp b/ngraph/core/include/ngraph/ops.hpp index b5a9016c402..5a4ad078616 100644 --- a/ngraph/core/include/ngraph/ops.hpp +++ b/ngraph/core/include/ngraph/ops.hpp @@ -41,6 +41,7 @@ #include "ngraph/op/detection_output.hpp" #include "ngraph/op/dft.hpp" #include "ngraph/op/divide.hpp" +#include "ngraph/op/einsum.hpp" #include "ngraph/op/elu.hpp" #include "ngraph/op/embedding_segments_sum.hpp" #include "ngraph/op/embeddingbag_offsets_sum.hpp" diff --git a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp index 8a3d0d6ef9b..b35dba55a1d 100644 --- a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp +++ b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp @@ -171,6 +171,7 @@ NGRAPH_OP(ReadValue, ngraph::op::v6) // new version // New operations added in opset7 NGRAPH_OP(DFT, ngraph::op::v7) +NGRAPH_OP(Einsum, ngraph::op::v7) NGRAPH_OP(Gelu, ngraph::op::v7) NGRAPH_OP(IDFT, ngraph::op::v7) NGRAPH_OP(Roll, ngraph::op::v7) diff --git a/ngraph/core/src/op/einsum.cpp b/ngraph/core/src/op/einsum.cpp new file mode 100644 index 00000000000..fbf52ef888b --- /dev/null +++ b/ngraph/core/src/op/einsum.cpp @@ -0,0 +1,308 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include + +#include "itt.hpp" +#include "ngraph/op/einsum.hpp" + +using namespace std; +using namespace ngraph; + +NGRAPH_RTTI_DEFINITION(op::v7::Einsum, "Einsum", 7); + +op::v7::Einsum::Einsum(const OutputVector& inputs, const std::string& equation) + : Op(inputs) + , m_equation(equation) +{ + // normalize input equation by removing extra white-spaces from the equation + m_equation.erase(std::remove_if(m_equation.begin(), m_equation.end(), ::isspace), + m_equation.end()); + + constructor_validate_and_infer_types(); +} + +/// \brief Check that a subscript contains only alphabetic letters or +/// alphabetic letters with one ellipsis +/// +/// \param subscripts A subscript to check its format +/// +/// \param is_ellipsis_met Marker if ellipsis is met in the subscript +/// +/// \return true - correct subscript, false - otherwise +/// +bool is_subscript_correct(const std::string& subscript, bool& is_ellipsis_met) +{ + is_ellipsis_met = false; + auto subscript_length = subscript.length(); + for (size_t ch_idx = 0; ch_idx < subscript_length; ++ch_idx) + { + if (is_ellipsis_met == false && ((subscript_length - ch_idx) > 2) && + (subscript.substr(ch_idx, 3).compare("...") == 0)) + { + // mark that ellipsis is met once + is_ellipsis_met = true; + + // make additional increment since ellipsis consists of three dots. + ch_idx += 2; + } + else if (std::isalpha(subscript[ch_idx]) == 0) + { + return false; + } + } + + return true; +} + +void op::v7::Einsum::parse_equation(const std::string& equation, + std::vector& input_subscripts, + std::string& output_subscript) +{ + NGRAPH_OP_SCOPE(v7_Einsum_parse_equation); + + // split equation to input subscripts and an output subscript + auto pos_output_delimeter = equation.find("->"); + auto input_subscripts_str = equation.substr(0, pos_output_delimeter); + + // split the input subscripts into a vector of input subscripts + bool is_ellipsis_met = false; + input_subscripts.clear(); + std::istringstream input; + input.str(input_subscripts_str); + for (std::string input_subscript; std::getline(input, input_subscript, ',');) + { + bool local_is_ellipsis_met = false; + // check that input subscript contains only alphabetic letter or ellipsis + NGRAPH_CHECK(is_subscript_correct(input_subscript, local_is_ellipsis_met), + "Input subscript of Einsum equation must consist of either only " + "alphabetic letters or alphabetic letters with one ellipsis."); + + // mark that ellipsis is met at least in one input subscript + if (local_is_ellipsis_met) + { + is_ellipsis_met = true; + } + input_subscripts.push_back(input_subscript); + } + + if (pos_output_delimeter == std::string::npos) + { + // recover output subscript + output_subscript = ""; + for (auto const& input_subscript : input_subscripts) + { + for (auto const& label : input_subscript) + { + if (std::isalpha(label) && output_subscript.find(label) == std::string::npos) + { + output_subscript += label; + } + } + } + std::sort(output_subscript.begin(), output_subscript.end()); + if (is_ellipsis_met) + { + output_subscript = "..." + output_subscript; + } + } + else + { + output_subscript = equation.substr(pos_output_delimeter + 2); + bool output_is_ellipsis_met = false; + + // check that the output subscript has the correct format + NGRAPH_CHECK(is_subscript_correct(output_subscript, output_is_ellipsis_met), + "Output subscript of Einsum equation must consist of either only " + "alphabetic letters or alphabetic letters with one ellipsis."); + + // if the ellipsis is met in input subscripts, one ellipsis must be in the output subscript + NGRAPH_CHECK(is_ellipsis_met == output_is_ellipsis_met, + "Output subscript of Einsum equation must contain one ellipsis if " + "ellipsis is met in any input subscript."); + } +} + +std::vector op::v7::Einsum::extract_labels(const std::string& subscript) +{ + NGRAPH_OP_SCOPE(v7_Einsum_extract_labels); + + std::vector labels; + labels.clear(); + auto subscript_length = subscript.length(); + for (size_t ch_idx = 0; ch_idx < subscript_length; ++ch_idx) + { + if (std::isalpha(subscript[ch_idx])) + { + labels.push_back(subscript.substr(ch_idx, 1)); + } + else if (((subscript_length - ch_idx) > 2) && + (subscript.substr(ch_idx, 3).compare("...") == 0)) + { + labels.push_back("..."); + // make additional increment since ellipsis consists of three dots. + ch_idx += 2; + } + else + { + NGRAPH_CHECK(false, "Einsum equation has invalid label."); + } + } + + return labels; +} + +void op::v7::Einsum::validate_and_infer_types() +{ + NGRAPH_OP_SCOPE(v7_Einsum_validate_and_infer_types); + + // check that Einsum operation has at least one input + auto num_inputs = get_input_size(); + NODE_VALIDATION_CHECK(this, num_inputs > 0, "Einsum must have at least one input."); + + // check that all inputs have the same type and the type is numeric + const auto& input_type_0 = get_input_element_type(0); + NODE_VALIDATION_CHECK(this, + input_type_0.is_real() || input_type_0.is_integral_number(), + "The input type for Einsum operation must be numeric."); + for (size_t input_idx = 1; input_idx < num_inputs; ++input_idx) + { + const auto& input_type_i = get_input_element_type(input_idx); + NODE_VALIDATION_CHECK(this, + input_type_0 == input_type_i, + "Inputs to Einsum operation must have the same type."); + } + + // check that equation has correct format and extract input and output subscripts + std::vector input_subscripts; + std::string output_subscript; + parse_equation(m_equation, input_subscripts, output_subscript); + + // a number of input subscripts must match with a number of input tensors + NODE_VALIDATION_CHECK( + this, + input_subscripts.size() == num_inputs, + "Equation must contain a number of subscripts equal to a number of Einsum inputs."); + + // create a dictionary with dimension sizes (or ranges in case dynamic shapes) for each label + // and check their compatibility in case repeating labels + unordered_map label_to_shape; + label_to_shape.clear(); + + for (size_t input_idx = 0; input_idx < num_inputs; ++input_idx) + { + const auto& pshape = get_input_partial_shape(input_idx); + std::vector labels; + labels = extract_labels(input_subscripts[input_idx]); + + if (pshape.rank().is_static()) + { + size_t input_rank = pshape.rank().get_length(); + // check that a rank is greater or equal to a number of labels + // these numbers are always equal if there is no ellipsis in the subscript + NODE_VALIDATION_CHECK( + this, + input_rank >= labels.size(), + "Input rank must be greater or equal to a number of labels in the " + "corresponding input subscript."); + + for (size_t label_ind = 0, dim_ind = 0; + label_ind < labels.size() && dim_ind < input_rank; + ++label_ind) + { + auto const& label = labels[label_ind]; + if (label.compare("...") == 0) + { + size_t num_broadcasted_dims = input_rank - labels.size() + 1; + auto current_sub_pshape = PartialShape(std::vector( + pshape.begin() + dim_ind, pshape.begin() + dim_ind + num_broadcasted_dims)); + if (label_to_shape.find(label) == label_to_shape.end()) + { + label_to_shape[label] = current_sub_pshape; + } + else + { + bool is_broadcast_success = + PartialShape::broadcast_merge_into(label_to_shape[label], + current_sub_pshape, + op::AutoBroadcastType::NUMPY); + NODE_VALIDATION_CHECK(this, + is_broadcast_success, + "Input dimensions labeled with ellipsis for Einsum " + "must be broadcastable."); + } + dim_ind += num_broadcasted_dims; + } + else + { + if (label_to_shape.find(label) == label_to_shape.end()) + { + label_to_shape[label] = PartialShape{pshape[dim_ind]}; + } + else + { + NODE_VALIDATION_CHECK( + this, + label_to_shape[label].compatible(PartialShape{pshape[label_ind]}), + "Different input dimensions indicated by the same labels for Einsum " + "must be compatible."); + PartialShape::merge_into(label_to_shape[label], + PartialShape{pshape[dim_ind]}); + } + ++dim_ind; + } + } + } + else + { + for (auto const& label : labels) + { + NODE_VALIDATION_CHECK(this, + label != "...", + "The subscript corresponding to a dynamic rank input must " + "not contain ellipsis."); + + if (label_to_shape.find(label) == label_to_shape.end()) + { + label_to_shape[label] = PartialShape{Dimension::dynamic()}; + } + } + } + } + + // compute the output shape + std::vector output_labels; + output_labels = extract_labels(output_subscript); + std::vector output_pshape_vector; + + for (auto const& output_label : output_labels) + { + NODE_VALIDATION_CHECK(this, + label_to_shape.find(output_label) != label_to_shape.end(), + "Label in output subscript of Einsum equation must enter at least " + "one input subscript."); + output_pshape_vector.insert(output_pshape_vector.end(), + label_to_shape[output_label].begin(), + label_to_shape[output_label].end()); + } + set_output_type(0, input_type_0, PartialShape(output_pshape_vector)); +} + +bool op::v7::Einsum::visit_attributes(AttributeVisitor& visitor) +{ + NGRAPH_OP_SCOPE(v7_Einsum_visit_attributes); + visitor.on_attribute("equation", m_equation); + return true; +} + +shared_ptr op::v7::Einsum::clone_with_new_inputs(const OutputVector& new_args) const +{ + NGRAPH_OP_SCOPE(v7_Einsum_clone_with_new_inputs); + check_new_args_count(this, new_args); + return make_shared(new_args, m_equation); +} diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index de311ee3261..30246008c0d 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -115,6 +115,7 @@ set(SRC type_prop/depth_to_space.cpp type_prop/dft.cpp type_prop/dyn_reshape.cpp + type_prop/einsum.cpp type_prop/experimental_detectron_generate_proposals.cpp type_prop/experimental_detectron_roi_feature_extractor.cpp type_prop/experimental_detectron_topkrois.cpp diff --git a/ngraph/test/type_prop/einsum.cpp b/ngraph/test/type_prop/einsum.cpp new file mode 100644 index 00000000000..a65fb0677f4 --- /dev/null +++ b/ngraph/test/type_prop/einsum.cpp @@ -0,0 +1,349 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "util/type_prop.hpp" + +using namespace std; +using namespace ngraph; + +TEST(type_prop, einsum_staticshape_dotproduct) +{ + std::string equation = "i,i->"; + Shape input1_shape{3}; + Shape input2_shape{3}; + Shape out_shape{}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_matmul) +{ + std::string equation = "ab,bc->ac"; + Shape input1_shape{2, 3}; + Shape input2_shape{3, 4}; + Shape out_shape{2, 4}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_trace) +{ + std::string equation = "kii->k"; + Shape input1_shape{2, 3, 3}; + Shape out_shape{2}; + auto I1 = make_shared(element::f32, input1_shape); + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_diagextraction) +{ + std::string equation = "kii->ki"; + Shape input1_shape{2, 3, 3}; + Shape out_shape{2, 3}; + auto I1 = make_shared(element::f32, input1_shape); + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_transpose) +{ + std::string equation = "ijk->kij"; + Shape input1_shape{1, 2, 3}; + Shape out_shape{3, 1, 2}; + auto I1 = make_shared(element::f32, input1_shape); + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_multimatmul) +{ + std::string equation = "ab,bcd,bc->ca"; + Shape input1_shape{2, 5}; + Shape input2_shape{5, 3, 6}; + Shape input3_shape{5, 3}; + Shape out_shape{3, 2}; + auto I1 = make_shared(element::i32, input1_shape); + auto I2 = make_shared(element::i32, input2_shape); + auto I3 = make_shared(element::i32, input3_shape); + auto O = make_shared(OutputVector{I1, I2, I3}, equation); + ASSERT_EQ(O->get_element_type(), element::i32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_ellipsis) +{ + std::string equation = "a...->..."; + Shape input1_shape{5, 3}; + Shape out_shape{3}; + auto I1 = make_shared(element::f32, input1_shape); + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_ellipsis2) +{ + std::string equation = "a...,...->a..."; + Shape input1_shape{3, 5}; + Shape input2_shape{1}; + Shape out_shape{3, 5}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_staticshape_ellipsis3) +{ + std::string equation = "a...b,b...->a..."; + Shape input1_shape{11, 1, 4, 3}; + Shape input2_shape{3, 11, 7, 1}; + Shape out_shape{11, 11, 7, 4}; + auto I1 = make_shared(element::i32, input1_shape); + auto I2 = make_shared(element::i32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::i32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_dynamicshape_dotproduct) +{ + std::string equation = "a,ab->ab"; + const auto input1_shape = PartialShape{Dimension(2, 7)}; + const auto input2_shape = PartialShape{Dimension(3, 10), 3}; + const auto out_shape = PartialShape{Dimension(3, 7), 3}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, einsum_dynamicshape_diagextraction) +{ + std::string equation = "xyzxy->xyz"; + const auto input1_shape = PartialShape{Dimension(2, 7), Dimension(1, 5), 4, Dimension(3, 5), 3}; + const auto out_shape = PartialShape{Dimension(3, 5), 3, 4}; + auto I1 = make_shared(element::i32, input1_shape); + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::i32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, DISABLED_einsum_dynamicshape_ellipsis1) +{ + // TODO: fix bug #53518 - PartialShape::broadcast_merge_into or Dimension::broadcast_merge + // to support broadcasting between Dimension(3, 5) and Dimension(1, 3) + // for which the result must be Dimension(3, 5) + std::string equation = "a...b,b...->a..."; + const auto input1_shape = PartialShape{11, 1, Dimension(3, 5), 3}; + const auto input2_shape = PartialShape{3, 11, 7, Dimension(1, 3)}; + const auto out_shape = PartialShape{11, 11, 7, Dimension(3, 5)}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, einsum_implicitmode_mixedcaseletters) +{ + // the following equation is equivalent to "AbC->ACb" + std::string equation = "AbC"; + const auto input1_shape = PartialShape{1, Dimension(2, 3), Dimension(4, 5)}; + auto I1 = make_shared(element::f32, input1_shape); + const auto out_shape = PartialShape{1, Dimension(4, 5), Dimension(2, 3)}; + auto O = make_shared(OutputVector{I1}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, einsum_implicitmode_mixedcaseletters2) +{ + // the following equation is equivalent to "a...b,B...->...Bab" + std::string equation = "a...b,B..."; + const auto input1_shape = PartialShape{Dimension(3, 5), 11, 1, 3}; + const auto input2_shape = PartialShape{Dimension(1, 3), 3, 1, 7}; + const auto out_shape = PartialShape{3, 11, 7, Dimension(1, 3), Dimension(3, 5), 3}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + auto O = make_shared(OutputVector{I1, I2}, equation); + ASSERT_EQ(O->get_element_type(), element::f32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, einsum_dynamicrank_multimatmul) +{ + std::string equation = "ab,bcd,bc->ca"; + Shape input1_shape{2, 5}; + PartialShape input2_shape = PartialShape::dynamic(); + Shape input3_shape{5, 3}; + Shape out_shape{3, 2}; + auto I1 = make_shared(element::i32, input1_shape); + auto I2 = make_shared(element::i32, input2_shape); + auto I3 = make_shared(element::i32, input3_shape); + auto O = make_shared(OutputVector{I1, I2, I3}, equation); + ASSERT_EQ(O->get_element_type(), element::i32); + ASSERT_EQ(O->get_shape(), out_shape); +} + +TEST(type_prop, einsum_dynamicrank_multimatmul2) +{ + std::string equation = "ab,bcd,bc->ca"; + PartialShape input1_shape = PartialShape::dynamic(); + PartialShape input2_shape = PartialShape::dynamic(); + PartialShape input3_shape = PartialShape::dynamic(); + PartialShape out_shape{Dimension(), Dimension()}; + auto I1 = make_shared(element::i32, input1_shape); + auto I2 = make_shared(element::i32, input2_shape); + auto I3 = make_shared(element::i32, input3_shape); + auto O = make_shared(OutputVector{I1, I2, I3}, equation); + ASSERT_EQ(O->get_element_type(), element::i32); + ASSERT_TRUE(O->get_output_partial_shape(0).same_scheme(out_shape)); +} + +TEST(type_prop, einsum_incorrectequation_subscriptnumber) +{ + std::string equation = "ab,bc,cd->ac"; + Shape input1_shape{2, 3}; + Shape input2_shape{3, 4}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + + try + { + auto O = make_shared(OutputVector{I1, I2}, equation); + // Should have thrown, so fail if it didn't + FAIL() << "Incorrect number of input subscripts"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Equation must contain a number of subscripts equal to a " + "number of Einsum inputs.")); + } + catch (...) + { + FAIL() << "Equation format check failed"; + } +} + +TEST(type_prop, einsum_incorrectequation_invalidlabels) +{ + std::string equation = "a$,Bc->ac"; + Shape input1_shape{2, 3}; + Shape input2_shape{3, 4}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + + try + { + auto O = make_shared(OutputVector{I1, I2}, equation); + // Should have thrown, so fail if it didn't + FAIL() << "Incorrect number of input subscripts"; + } + catch (const CheckFailure& error) + { + EXPECT_HAS_SUBSTRING( + error.what(), + std::string("Input subscript of Einsum equation must consist of either only alphabetic " + "letters or alphabetic letters with one ellipsis.")); + } + catch (...) + { + FAIL() << "Equation format check failed"; + } +} + +TEST(type_prop, einsum_incorrectequation_incompatibleshapes) +{ + std::string equation = "ab,bc->ac"; + Shape input1_shape{2, 10}; + Shape input2_shape{3, 4}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + + try + { + auto O = make_shared(OutputVector{I1, I2}, equation); + // Should have thrown, so fail if it didn't + FAIL() << "Incompatible dimension indicated by the same labels"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Different input dimensions indicated by the same labels " + "for Einsum must be compatible.")); + } + catch (...) + { + FAIL() << "Equation format check failed"; + } +} + +TEST(type_prop, einsum_incorrectequation_notbroadcastableshapes) +{ + std::string equation = "a...b,b...->a..."; + Shape input1_shape{11, 1, 4, 3}; + Shape input2_shape{3, 11, 7, 5}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + + try + { + auto O = make_shared(OutputVector{I1, I2}, equation); + // Should have thrown, so fail if it didn't + FAIL() << "Non-broadcastable shapes covered by ellipsis"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING( + error.what(), + std::string( + "Input dimensions labeled with ellipsis for Einsum must be broadcastable.")); + } + catch (...) + { + FAIL() << "Equation format check failed"; + } +} + +TEST(type_prop, einsum_incorrectequation_missedellipsis) +{ + std::string equation = "a...b,b...->a"; + Shape input1_shape{11, 1, 4, 3}; + Shape input2_shape{3, 11, 7, 5}; + auto I1 = make_shared(element::f32, input1_shape); + auto I2 = make_shared(element::f32, input2_shape); + + try + { + auto O = make_shared(OutputVector{I1, I2}, equation); + // Should have thrown, so fail if it didn't + FAIL() << "Non-broadcastable shapes covered by ellipsis"; + } + catch (const CheckFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Output subscript of Einsum equation must contain one " + "ellipsis if ellipsis is met in any input subscript.")); + } + catch (...) + { + FAIL() << "Equation format check failed"; + } +} From b770be227bba35c3805a8613df0e5eba5cdad98e Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Sat, 24 Apr 2021 12:29:46 +0300 Subject: [PATCH 75/78] [IE TEST] fix small issue in summarize (#5367) * [IE TEST] fix small issue in summarize * Add --- .../layer_tests_summary/__init__.py | 2 + .../layer_tests_summary/merge_xmls.py | 25 +--- .../layer_tests_summary/summarize.py | 140 ++++-------------- .../layer_tests_summary/utils/__init__.py | 2 + .../layer_tests_summary/utils/constants.py | 84 +++++++++++ .../layer_tests_summary/utils/utils.py | 26 ++++ 6 files changed, 145 insertions(+), 134 deletions(-) create mode 100644 inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/__init__.py create mode 100644 inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/__init__.py create mode 100644 inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py create mode 100644 inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/utils.py diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/__init__.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/__init__.py new file mode 100644 index 00000000000..f8f3f25edc7 --- /dev/null +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py index 3746663b68c..9f6cd663cad 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/merge_xmls.py @@ -1,17 +1,15 @@ # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import xml.etree.ElementTree as ET import argparse import os -from datetime import datetime -import logging import glob -logging.basicConfig() -logger = logging.getLogger('XmlMerger') -logger.setLevel(logging.INFO) +import xml.etree.ElementTree as ET +from utils import utils + +logger = get_logger('XmlMerger') def parse_arguments(): parser = argparse.ArgumentParser() @@ -26,21 +24,6 @@ def parse_arguments(): return parser.parse_args() -def update_passrates(results: ET.SubElement): - for device in results: - for op in device: - passed_tests = 0 - total_tests = 0 - for attrib in op.attrib: - if attrib == "passrate": - continue - if attrib == "passed": - passed_tests = int(op.attrib.get(attrib)) - total_tests += int(op.attrib.get(attrib)) - passrate = float(passed_tests * 100 / total_tests) if passed_tests < total_tests else 100 - op.set("passrate", str(round(passrate, 1))) - - def aggregate_test_results(results: ET.SubElement, xml_reports: list): timestamp = None for xml in xml_reports: diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py index 08e4f42acc1..9ba9dea8a98 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/summarize.py @@ -3,16 +3,14 @@ import argparse import os -import logging import xml.etree.ElementTree as ET from jinja2 import Environment, FileSystemLoader -from datetime import datetime -logging.basicConfig() -logger = logging.getLogger('Summarize') -logger.setLevel(logging.INFO) +from utils import constants +from utils import utils +logger = utils.get_logger('Summarize') def parse_arguments(): parser = argparse.ArgumentParser() @@ -30,108 +28,6 @@ def parse_arguments(): return parser.parse_args() - -def get_verified_op_list(): - return [ - 'Abs-1', - 'Acos-1', - 'Add-1', - 'Asin-1', - 'Assign-6', - 'AvgPool-1', - 'BatchNormInference-5', - 'BinaryConvolution-1', - 'Broadcast-1', - 'Broadcast-3', - 'Bucketize-3', - 'CTCGreedyDecoder-1', - 'CTCGreedyDecoderSeqLen-6', - 'Concat-1', - 'ConvertLike-1', - 'Convolution-1', - 'DeformableConvolution-1', - 'DetectionOutput-1', - 'Divide-1', - 'ExperimentalDetectronDetectionOutput-6', - 'ExperimentalDetectronGenerateProposalsSingleImage-6', - 'ExperimentalDetectronPriorGridGenerator-6', - 'ExperimentalDetectronROIFeatureExtractor-6', - 'ExperimentalDetectronTopKROIs-6', - 'FloorMod-1' - 'GRUSequence-5', - 'Gather-1', - 'GatherElements-6', - 'GatherND-5', - 'Gelu-7', - 'GroupConvolution-1', - 'GroupConvolutionBackpropData-1', - 'GRUSequence-5', - 'HSigmoid-5', - 'HSwish-4', - 'HardSigmoid-1', - 'Interpolate-4', - 'LRN-1', - 'LSTMCell-4', - 'LSTMSequence-5', - 'LogSoftmax-5', - 'Loop-5', - 'MVN-6', - 'Maximum-1', - 'MaxPool-1', - 'Mish-4', - 'Multiply-1', - 'NonMaxSuppression-4', - 'NonMaxSuppression-5', - 'PSROIPooling-1', - 'Proposal-1', - 'Proposal-4', - 'RNNSequence-5', - 'ROIAlign-3', - 'ROIPooling-2', - 'Range-1', - 'Range-4', - 'ReadValue-6', - 'ReduceL1-4', - 'ReduceL2-4', - 'ReduceMean-1', - 'RegionYOLO-1', - 'Relu-1', - 'ReorgYOLO-2', - 'Round-5', - 'ScatterNDUpdate-4', - 'ShapeOf-1', - 'ShapeOf-3', - 'Sigmoid-1', - 'Sin-1', - 'SoftPlus-4', - 'Softmax-1', - 'Split-1', - 'StridedSlice-1', - 'Subtract-1', - 'Swish-4', - 'Tile-1', - 'TopK-1', - 'TopK-3' - ] - - -def update_passrates(results: ET.SubElement): - logger.info("Update passrates in the final report is started") - for device in results: - for op in device: - passed_tests = 0 - total_tests = 0 - for attrib in op.attrib: - if attrib == "passrate": - continue - if attrib == "passed": - passed_tests = int(op.attrib.get(attrib)) - total_tests += int(op.attrib.get(attrib)) - passrate = float(passed_tests * 100 / total_tests) if passed_tests < total_tests else 100 - op.set("passrate", str(round(passrate, 1))) - logger.info("Update passrates in the final report is completed") - - def merge_xmls(xml_paths: list): logger.info("Merging XML files is started") @@ -169,7 +65,7 @@ def merge_xmls(xml_paths: list): continue total_tests_count_xml += int(op_result.attrib.get(attr_name)) total_tests_count_summary += int(current_op_res.attrib.get(attr_name)) - if total_tests_count_xml > total_tests_count_xml: + if total_tests_count_xml > total_tests_count_summary: logger.warning(f'Test counter is different in {op_result.tag} for {device.tag}'\ f'({total_tests_count_xml} vs {total_tests_count_xml})') for attr_name in device_results.find(op_result.tag).attrib: @@ -179,7 +75,7 @@ def merge_xmls(xml_paths: list): device_results.find(current_op_res.tag).set(attr_name, str(xml_value)) else: device_results.append(op_result) - update_passrates(summary_results) + utils.update_passrates(summary_results) summary.set("timestamp", timestamp) logger.info("Merging XML files is competed") return summary @@ -192,6 +88,7 @@ def collect_statistic(root: ET.Element): general_pass_rate = dict() general_test_count = dict() general_passed_tests = dict() + op_res = dict() results = dict() for device in root.find("results"): @@ -208,16 +105,33 @@ def collect_statistic(root: ET.Element): pass_rate_avg[device.tag] += pass_rate if pass_rate == 100.: trusted_ops[device.tag] += 1 - general_test_count[device.tag] += ( - int(results[device.tag][op]["passed"]) + int(results[device.tag][op]["failed"]) + - int(results[device.tag][op]["crashed"]) + int(results[device.tag][op]["skipped"])) + device_general_test_count = \ + int(results[device.tag][op]["passed"]) + int(results[device.tag][op]["failed"]) +\ + int(results[device.tag][op]["crashed"]) + int(results[device.tag][op]["skipped"]) + general_test_count[device.tag] += device_general_test_count general_passed_tests[device.tag] += int(results[device.tag][op]["passed"]) + if op in op_res.keys(): + op_res[op].update({device.tag: device_general_test_count}) + else: + op_res.update({op: {device.tag: device_general_test_count}}) pass_rate_avg[device.tag] /= len(results[device.tag]) pass_rate_avg[device.tag] = round(float(pass_rate_avg[device.tag]), 1) general_pass_rate[device.tag] = general_passed_tests[device.tag] * 100 / general_test_count[device.tag] general_pass_rate[device.tag] = round(float(general_pass_rate[device.tag]), 1) + logger.info("Test number comparison between devices is started") + for op in op_res: + op_counter = None + is_not_printed = True + for dev in op_res[op]: + if op_counter is None: + op_counter = op_res[op][dev] + elif op_counter != op_res[op][dev] and is_not_printed: + is_not_printed = False + logger.warning(f'{op} : {op_res[op]}') + logger.info("Test number comparison between devices is completed") + devices = results.keys() logger.info("Statistic collecting is completed") return devices, results, general_pass_rate, pass_rate_avg, general_test_count, trusted_ops @@ -238,7 +152,7 @@ def create_summary(summary_root: ET.Element, output_folder: str): env = Environment(loader=file_loader) template = env.get_template('report_template.html') - verified_operations = get_verified_op_list() + verified_operations = constants.VERIFIED_OP_REFERENCES res_summary = template.render(ordered_ops=op_list, devices=device_list, results=results, timestamp=timestamp, general_pass_rate=general_pass_rate, pass_rate_avg=pass_rate_avg, diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/__init__.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/__init__.py new file mode 100644 index 00000000000..f8f3f25edc7 --- /dev/null +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py new file mode 100644 index 00000000000..5359efa3f99 --- /dev/null +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py @@ -0,0 +1,84 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +VERIFIED_OP_REFERENCES = [ + 'Abs-1', + 'Acos-1', + 'Add-1', + 'Asin-1', + 'Assign-6', + 'AvgPool-1', + 'BatchNormInference-5', + 'BinaryConvolution-1', + 'Broadcast-1', + 'Broadcast-3', + 'Bucketize-3', + 'CTCGreedyDecoder-1', + 'CTCGreedyDecoderSeqLen-6', + 'Concat-1', + 'ConvertLike-1', + 'Convolution-1', + 'DeformableConvolution-1', + 'DetectionOutput-1', + 'Divide-1', + 'ExperimentalDetectronDetectionOutput-6', + 'ExperimentalDetectronGenerateProposalsSingleImage-6', + 'ExperimentalDetectronPriorGridGenerator-6', + 'ExperimentalDetectronROIFeatureExtractor-6', + 'ExperimentalDetectronTopKROIs-6', + 'FloorMod-1' + 'GRUSequence-5', + 'Gather-1', + 'GatherElements-6', + 'GatherND-5', + 'Gelu-7', + 'GroupConvolution-1', + 'GroupConvolutionBackpropData-1', + 'GRUSequence-5', + 'HSigmoid-5', + 'HSwish-4', + 'HardSigmoid-1', + 'Interpolate-4', + 'LRN-1', + 'LSTMCell-4', + 'LSTMSequence-5', + 'LogSoftmax-5', + 'Loop-5', + 'MVN-6', + 'Maximum-1', + 'MaxPool-1', + 'Mish-4', + 'Multiply-1', + 'NonMaxSuppression-4', + 'NonMaxSuppression-5', + 'PSROIPooling-1', + 'Proposal-1', + 'Proposal-4', + 'RNNSequence-5', + 'ROIAlign-3', + 'ROIPooling-2', + 'Range-1', + 'Range-4', + 'ReadValue-6', + 'ReduceL1-4', + 'ReduceL2-4', + 'ReduceMean-1', + 'RegionYOLO-1', + 'Relu-1', + 'ReorgYOLO-2', + 'Round-5', + 'ScatterNDUpdate-4', + 'ShapeOf-1', + 'ShapeOf-3', + 'Sigmoid-1', + 'Sin-1', + 'SoftPlus-4', + 'Softmax-1', + 'Split-1', + 'StridedSlice-1', + 'Subtract-1', + 'Swish-4', + 'Tile-1', + 'TopK-1', + 'TopK-3' +] \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/utils.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/utils.py new file mode 100644 index 00000000000..c29376da38e --- /dev/null +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/utils.py @@ -0,0 +1,26 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import logging +import xml.etree.ElementTree as ET + +def get_logger(app_name: str): + logging.basicConfig() + logger = logging.getLogger(app_name) + logger.setLevel(logging.INFO) + return logger + + +def update_passrates(results: ET.SubElement): + for device in results: + for op in device: + passed_tests = 0 + total_tests = 0 + for attrib in op.attrib: + if attrib == "passrate": + continue + if attrib == "passed": + passed_tests = int(op.attrib.get(attrib)) + total_tests += int(op.attrib.get(attrib)) + passrate = float(passed_tests * 100 / total_tests) if passed_tests < total_tests else 100 + op.set("passrate", str(round(passrate, 1))) \ No newline at end of file From 594c4882e61f3eb2a9440922aa559bcd2d1f7c5e Mon Sep 17 00:00:00 2001 From: Ivan Novoselov Date: Sun, 25 Apr 2021 19:52:07 +0300 Subject: [PATCH 76/78] [CPU] optimize ExtractImagePatches (#4898) --- .../nodes/extract_image_patches.cpp | 680 ++++++++++++------ .../nodes/extract_image_patches.hpp | 62 ++ .../extract_image_patches.cpp | 15 +- .../extract_image_patches.cpp | 92 +++ .../single_layer/extract_image_patches.hpp | 2 +- 5 files changed, 623 insertions(+), 228 deletions(-) create mode 100644 inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp create mode 100755 inference-engine/tests/functional/plugin/cpu/single_layer_tests/extract_image_patches.cpp diff --git a/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.cpp b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.cpp index 63370ab2b27..a8f32387ec8 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.cpp @@ -1,17 +1,15 @@ -// Copyright (C) 2018-2021 Intel Corporation +// Copyright (C) 2020-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // -#include "list.hpp" -#include "base.hpp" +#include "extract_image_patches.hpp" #include "caseless.hpp" - -#include -#include -#include -#include -#include #include "ie_parallel.hpp" +#include "list.hpp" +#include +#include +#include +#include namespace InferenceEngine { namespace Extensions { @@ -19,229 +17,479 @@ namespace Cpu { using details::CaselessEq; -class ExtractImagePatchesImpl : public ExtLayerBase { -public: - explicit ExtractImagePatchesImpl(const CNNLayer* layer) { - try { - std::string errorPrefix = std::string("Layer ") + layer->type + " with name '" + layer->name + "' "; - if (details::CaselessEq()("ExtractImagePatchesLayer", layer->type)) - IE_THROW() << errorPrefix << "is not an instance of ExtractImagePatchesLayer class"; +using namespace dnnl::impl::cpu; +using namespace dnnl::impl::cpu::x64; +using namespace dnnl::impl::utils; +using namespace Xbyak; - if (layer->insData.size() != 1 || layer->outData.size() != 1) - IE_THROW() << errorPrefix << "has incorrect number of input or output edges!" - << " Input: " << layer->insData.size() << "; Output: " << layer->outData.size(); +#define GET_OFF(field) offsetof(jit_extract_image_patches_args, field) - auto inData = layer->insData[0].lock(); - if (inData == nullptr) - IE_THROW() << errorPrefix << "has nullable input data"; +template +struct jit_extract_image_patches_kernel : public jit_uni_extract_image_patches_kernel, public jit_generator { + DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_extract_image_patches_kernel) - if (inData->getTensorDesc().getDims().size() != 4) - IE_THROW() << errorPrefix << "must have 4D input tensor. Actual: " << inData->getTensorDesc().getDims().size(); + explicit jit_extract_image_patches_kernel(jit_extract_image_patches_params jpp) : jit_uni_extract_image_patches_kernel(jpp), jit_generator() {} - if (layer->outData[0]->getTensorDesc().getDims().size() != 4) - IE_THROW() << errorPrefix << "must have 4D output tensor. Actual: " << layer->outData[0]->getTensorDesc().getDims().size(); - - if (inData->getLayout() != NCHW) - IE_THROW() << errorPrefix << "has unsupported layout: " << inData->getLayout(); - - const auto precision = inData->getTensorDesc().getPrecision(); - if (_supported_precisions_sizes.find(precision.size()) == _supported_precisions_sizes.end()) - IE_THROW() << errorPrefix << "has unsupported precision: " << precision.name(); - - auto ksizes = layer->GetParamAsUInts("sizes"); - auto strides = layer->GetParamAsUInts("strides"); - auto rates = layer->GetParamAsUInts("rates"); - _auto_pad = layer->GetParamAsString("auto_pad"); - if (!CaselessEq()(_auto_pad, "valid") - && !CaselessEq()(_auto_pad, "same_upper") - && !CaselessEq()(_auto_pad, "same_lower")) - IE_THROW() << errorPrefix << "has unsupported auto_pad value: " << _auto_pad; - if (ksizes.size() != 2 || strides.size() != 2 || rates.size() != 2) - IE_THROW() << errorPrefix << "must have the following attributes with shape {2}: sizes, strides, rates."; - - _ksizes.clear(); - _strides.clear(); - _rates.clear(); - for (size_t i = 0; i < ksizes.size(); i++) - _ksizes.push_back((int64_t)ksizes[i]); - for (size_t i = 0; i < strides.size(); i++) - _strides.push_back((int64_t)strides[i]); - for (size_t i = 0; i < rates.size(); i++) - _rates.push_back((int64_t)rates[i]); - - LayerConfig config; - - DataConfig inConfig; - inConfig.desc = inData->getTensorDesc(); - config.inConfs.push_back(inConfig); - - DataConfig outConfig; - outConfig.desc = layer->outData[0]->getTensorDesc(); - outConfig.desc.setPrecision(inConfig.desc.getPrecision()); - outConfig.desc.setLayout(inConfig.desc.getLayout()); - config.outConfs.push_back(outConfig); - - config.dynBatchSupport = false; - confs.push_back(config); - } catch (InferenceEngine::Exception &ex) { - errorMsg = ex.what(); - } + void create_ker() override { + jit_generator::create_kernel(); + ker_ = (decltype(ker_))jit_ker(); } - StatusCode execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept override { - switch (inputs[0]->getTensorDesc().getPrecision().size()) { - case 1: { - process_data::value_type>(inputs, outputs); - break; - } - case 2: { - process_data::value_type>(inputs, outputs); - break; - } - case 4: { - process_data::value_type>(inputs, outputs); - break; - } - case 8: { - process_data::value_type>(inputs, outputs); - break; - } - default: { - if (resp) { - std::string errorMsg = "ExtractImagePatches layer does not support precision '" - + std::string(inputs[0]->getTensorDesc().getPrecision().name()) + "'"; - errorMsg.copy(resp->msg, sizeof(resp->msg) - 1); - } - return GENERAL_ERROR; - } + void generate() override { + this->preamble(); + + mov(reg_num_pads, ptr[reg_params + GET_OFF(h_lo_pad)]); + mov(reg_h_hi_pad, ptr[reg_params + GET_OFF(h_hi_pad)]); + mov(reg_w_lo_pad, ptr[reg_params + GET_OFF(w_lo_pad)]); + mov(reg_w_hi_pad, ptr[reg_params + GET_OFF(w_hi_pad)]); + mov(reg_src, ptr[reg_params + GET_OFF(src)]); + mov(reg_dst, ptr[reg_params + GET_OFF(dst)]); + + mov(reg_src_incr, jpp.SH * jpp.IW * jpp.dtype_size); + mov(reg_aux64, reg_w_hi_pad); + mul_by_const(reg_aux64, reg_aux64_2, jpp.SW * jpp.dtype_size); + sub(reg_src_incr, reg_aux64); + + mov(reg_aux64, reg_w_lo_pad); + mul_by_const(reg_aux64, reg_aux64_2, jpp.SW * jpp.dtype_size); + add(reg_src_incr, reg_aux64); + add(reg_src, reg_aux64); + + mov(reg_ow_work_amount, reg_w_hi_pad); + sub(reg_ow_work_amount, reg_w_lo_pad); + + uni_vpxor(vmm_zero, vmm_zero, vmm_zero); + if (mayiuse_gather) { + mov(reg_aux64, gather_index_table); + uni_vmovups(vmm_gather_index, ptr[reg_aux64]); } + loop(); - return OK; - } + this->postamble(); - template - void process_data(std::vector& inputs, std::vector& outputs) noexcept { - const T* src_data = inputs[0]->cbuffer().as() + - inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - T* dst_data = outputs[0]->buffer().as() + - outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); - - const auto& inDims = inputs[0]->getTensorDesc().getDims(); - const size_t inDimsSize = inDims.size(); - - const size_t BATCH = 0, CHANNEL = 1, HIGHT = 0, WIDTH = 1; - - const int64_t IC = inDims[CHANNEL]; - const int64_t IH = inDims[inDimsSize - 2]; - const int64_t IW = inDims[inDimsSize - 1]; - - const auto& outDims = outputs[0]->getTensorDesc().getDims(); - const size_t outDimsSize = outDims.size(); - - const int64_t OB = outDims[BATCH]; - const int64_t OC = outDims[CHANNEL]; - const int64_t OH = outDims[outDimsSize - 2]; - const int64_t OW = outDims[outDimsSize - 1]; - - const int64_t KH = _ksizes[HIGHT]; - const int64_t KW = _ksizes[WIDTH]; - const int64_t SH = _strides[HIGHT]; - const int64_t SW = _strides[WIDTH]; - const int64_t RH = _rates[HIGHT]; - const int64_t RW = _rates[WIDTH]; - - int64_t iwStep = KW + (RW - 1) * (KW - 1); - int64_t ihStep = KH + (RH - 1) * (KH - 1); - - int64_t PL = 0, PT = 0; - if (!CaselessEq()(_auto_pad, "valid")) { - int64_t PW = (std::ceil(1.f * IW/SW) - 1) * SW + iwStep - IW; - int64_t PH = (std::ceil(1.f * IH/SH) - 1) * SH + ihStep - IH; - - if ((PW > 0) && (PW < iwStep)) { - if (PW % 2 == 1) { - if (CaselessEq()(_auto_pad, "same_lower")) { - PL = (PW + 1) / 2; - } else if (CaselessEq()(_auto_pad, "same_upper")) { - PL = (PW - 1) / 2; - } - } else { - PL = PW / 2; - } - } - if ((PH > 0) && (PH < ihStep)) { - if (PH % 2 == 1) { - if (CaselessEq()(_auto_pad, "same_lower")) { - PT = (PH + 1) / 2; - } else if (CaselessEq()(_auto_pad, "same_upper")) { - PT = (PH - 1) / 2; - } - } else { - PT = PH / 2; - } - } - } - - const int64_t OH_OW = OH * OW; - const int64_t OC_OH_OW = OC * OH_OW; - const int64_t IH_IW = IH * IW; - const int64_t IC_IH_IW = IC * IH_IW; - - const int64_t work_amount = OB; - - auto thread_body = [&](const int ithr, const int nthr) { - int64_t start(0lu), end(0lu); - splitter(work_amount, nthr, ithr, start, end); - if (start >= end) - return; - - for (int64_t ob = start; ob < end; ob++) { - const int64_t ibICIHIW = ob * IC_IH_IW; - const int64_t obOCOHOW = ob * OC_OH_OW; - for (int64_t oh = 0; oh < OH; oh++) { - const int64_t obOCOHOWohOW = obOCOHOW + oh * OW; - int64_t ih0 = oh * SH - PT; - for (int64_t ow = 0; ow < OW; ow++) { - const int64_t obOCOHOWohOWow = obOCOHOWohOW + ow; - int64_t iw0 = ow * SW - PL; - int64_t oc = 0; - - for (int64_t kh = 0; kh < KH; kh++) { - int64_t ihKH = ih0 + kh * RH; - int64_t ibICIHIWihFHIW = ibICIHIW + ihKH * IW; - for (int64_t kw = 0; kw < KW; kw++) { - for (int64_t ic = 0; ic < IC; ic++, oc++) { - int64_t iwKW = iw0 + kw * RW; - int64_t dst_idx = obOCOHOWohOWow + oc * OH_OW; - if (ihKH < 0 || ihKH >= IH || iwKW < 0 || iwKW >= IW) { - dst_data[dst_idx] = T(0); - } else { - int64_t src_idx = ibICIHIWihFHIW + ic * IH_IW + iwKW; - dst_data[dst_idx] = src_data[src_idx]; - } - } - } - } - } - } - } - }; - - parallel_nt(0, thread_body); + if (mayiuse_gather) + prepare_table(); } private: - std::vector _ksizes; - std::vector _strides; - std::vector _rates; - std::string _auto_pad; + using Vmm = typename conditional3::type; + using reg64_t = const Xbyak::Reg64; + using reg32_t = const Xbyak::Reg32; + bool mayiuse_gather = (mayiuse(x64::avx2) || mayiuse(x64::avx512_common)) && (jpp.dtype_size == 4); + uint32_t vlen = cpu_isa_traits::vlen; + reg64_t reg_src = r8; + reg64_t reg_dst = r9; + reg64_t reg_oh_count = r10; + reg64_t reg_ow_count = r11; + reg64_t reg_num_pads = r12; + reg64_t reg_src_incr = r13; + reg64_t reg_aux64 = rax; + reg64_t reg_w_hi_pad = r14; + reg64_t reg_w_lo_pad = r15; + reg64_t reg_h_hi_pad = rbp; + reg64_t reg_aux64_2 = rbx; + reg64_t reg_ow_work_amount = rsi; + reg64_t reg_params = abi_param1; - static const std::set _supported_precisions_sizes; + Vmm vmm = Vmm(0); + Xmm xmm = Xmm(0); + Vmm vmm_zero = Vmm(1); // reserved for pad + Xbyak::Xmm xmm_aux = Xbyak::Xmm(2); + Vmm vmm_gather_index = Vmm(3); + Vmm vmm_gather_mask = Vmm(4); + Opmask k_mask = Xbyak::Opmask(1); + Xbyak::Label gather_index_table; + + inline void load_scalar(Vmm vmm_arg, const Xbyak::Address &op) { + Xbyak::Xmm xmm_src = Xmm(vmm_arg.getIdx()); + switch (jpp.dtype_size) { + case 4: uni_vmovss(vmm_arg, op); break; + case 2: uni_vpinsrw(xmm_src, xmm_src, op, 0x0); break; + case 1: uni_vpinsrb(xmm_src, xmm_src, op, 0x0); break; + default: IE_THROW() << "The data type of size '" << jpp.dtype_size << "' is not supported."; + } + } + inline void store_scalar(const Xbyak::Address &op, Vmm vmm_arg) { + Xbyak::Xmm xmm_dst = Xmm(vmm_arg.getIdx()); + switch (jpp.dtype_size) { + case 4: uni_vmovss(op, vmm_arg); break; + case 2: uni_vpextrw(op, xmm_dst, 0x0); break; + case 1: uni_vpextrb(op, xmm_dst, 0x0); break; + default: IE_THROW() << "The data type of size '" << jpp.dtype_size << "' is not supported."; + } + } + + inline void pad_with_zeros(reg64_t ®_num_pads_arg, reg64_t ®_dst_arg) { + Xbyak::Label main, tail, exit; + L(main); + { + cmp(reg_num_pads_arg, jpp.block_size); + jl(tail); + uni_vmovups(ptr[reg_dst_arg], vmm_zero); + add(reg_dst_arg, jpp.dtype_size * jpp.block_size); + sub(reg_num_pads_arg, jpp.block_size); + jmp(main); + } + L(tail); + { + cmp(reg_num_pads_arg, 0); + jle(exit); + store_scalar(ptr[reg_dst_arg], vmm_zero); + add(reg_dst_arg, jpp.dtype_size); + dec(reg_num_pads_arg); + jmp(tail); + } + L(exit); + } + + inline void custom_uni_vgatherdps(const Vmm &vmm_arg, reg64_t &mem_base, const Vmm &mem_offset, Vmm &vmm_mask) { + switch (isa) { + case x64::avx2: + uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask); + vgatherdps(vmm_arg, ptr[mem_base + mem_offset], vmm_mask); + break; + case x64::avx512_common: + kxnord(k_mask, k_mask, k_mask); + vgatherdps(vmm_arg | k_mask, ptr[mem_base + mem_offset]); + break; + case x64::sse41: + emulate_gather(vmm_arg, mem_base); + break; + default: IE_THROW() << "Got unsupported instruction set."; + } + } + + inline void gather_src2vmm(const Vmm &vmm_arg, reg64_t &mem_base) { + switch (jpp.dtype_size) { + case 4: custom_uni_vgatherdps(vmm, mem_base, vmm_gather_index, vmm_gather_mask); break; + case 2: + case 1: emulate_gather(vmm_arg, mem_base); break; + default: IE_THROW() << "The data type of size '" << jpp.dtype_size << "' is not supported."; + } + } + + inline void emulate_gather(const Xbyak::Xmm &xmm_arg, reg64_t &mem_base, int xmm_offset = 0) { + const int xmm_size = 16; // bytes + const int xmm_block_size = xmm_size / jpp.dtype_size; + const int offset = xmm_offset * jpp.SW * jpp.dtype_size * xmm_block_size; + for (int i = 0; i < xmm_block_size; i++) { + Xbyak::Address addr = ptr[mem_base + i * jpp.SW * jpp.dtype_size + offset]; + switch (jpp.dtype_size) { + case 4: uni_vpinsrd(xmm_arg, xmm_arg, addr, i); break; + case 2: uni_vpinsrw(xmm_arg, xmm_arg, addr, i); break; + case 1: uni_vpinsrb(xmm_arg, xmm_arg, addr, i); break; + default: IE_THROW() << "The data type of size '" << jpp.dtype_size << "' is not supported."; + } + } + } + inline void emulate_gather(const Xbyak::Ymm &ymm_arg, reg64_t &mem_base) { + Xbyak::Xmm low_xmm = Xbyak::Xmm(ymm_arg.getIdx()); + emulate_gather(low_xmm, mem_base, 0); + emulate_gather(xmm_aux, mem_base, 1); + vinserti128(ymm_arg, ymm_arg, xmm_aux, 1); + } + + inline void emulate_gather(const Xbyak::Zmm &zmm_arg, reg64_t &mem_base) { + Xbyak::Xmm low_xmm = Xbyak::Xmm(zmm_arg.getIdx()); + emulate_gather(low_xmm, mem_base, 0); + for (int i = 1; i < 4; i++) { + emulate_gather(xmm_aux, mem_base, i); + vinserti64x2(zmm_arg, zmm_arg, xmm_aux, i); + } + } + + void loop() { + mov(reg_oh_count, reg_h_hi_pad); + // reg_num_pads contains h_lo_pad at this point + sub(reg_oh_count, reg_num_pads); + + Xbyak::Label ih_loop, ih_tail, ih_exit; + Xbyak::Label iw_loop, iw_tail, iw_exit; + if (jpp.need_padding) { + mul_by_const(reg_num_pads, reg_aux64, jpp.OW); + pad_with_zeros(reg_num_pads, reg_dst); + } + L(ih_loop); + { + cmp(reg_oh_count, 0); + jle(ih_exit, T_NEAR); + if (jpp.need_padding) { + mov(reg_num_pads, reg_w_lo_pad); + pad_with_zeros(reg_num_pads, reg_dst); + } + mov(reg_ow_count, reg_ow_work_amount); + L(iw_loop); + { + cmp(reg_ow_count, jpp.block_size); + jle(iw_tail, T_NEAR); + gather_src2vmm(vmm, reg_src); + add(reg_src, jpp.SW * jpp.dtype_size * jpp.block_size); + uni_vmovups(ptr[reg_dst], vmm); + add(reg_dst, jpp.dtype_size * jpp.block_size); + sub(reg_ow_count, jpp.block_size); + jmp(iw_loop); + } + L(iw_tail); + { + cmp(reg_ow_count, 0); + jle(iw_exit, T_NEAR); + load_scalar(vmm, ptr[reg_src]); + store_scalar(ptr[reg_dst], vmm); + dec(reg_ow_count); + add(reg_src, jpp.SW * jpp.dtype_size); + add(reg_dst, jpp.dtype_size); + jmp(iw_tail); + } + L(iw_exit); + if (jpp.need_padding) { + mov(reg_num_pads, jpp.OW); + sub(reg_num_pads, reg_w_hi_pad); + pad_with_zeros(reg_num_pads, reg_dst); + } + dec(reg_oh_count); + add(reg_src, reg_src_incr); + jmp(ih_loop, T_NEAR); + } + L(ih_exit); + if (jpp.need_padding) { + mov(reg_num_pads, jpp.OH); + sub(reg_num_pads, reg_h_hi_pad); + mul_by_const(reg_num_pads, reg_aux64, jpp.OW); + pad_with_zeros(reg_num_pads, reg_dst); + } + } + + void prepare_table() { + align(64); + L(gather_index_table); + for (int32_t i = 0; i < vlen / sizeof(int32_t); i++) + dd(i * jpp.SW * jpp.dtype_size); + } }; -const std::set ExtractImagePatchesImpl::_supported_precisions_sizes = {1, 2, 4, 8}; +ExtractImagePatchesImpl::ExtractImagePatchesImpl(const CNNLayer* layer) { + try { + std::string errorPrefix = std::string("Layer ") + layer->type + " with name '" + layer->name + "' "; + if (details::CaselessEq()("ExtractImagePatchesLayer", layer->type)) + IE_THROW() << errorPrefix << "is not an instance of ExtractImagePatchesLayer class"; -REG_FACTORY_FOR(ExtractImagePatchesImpl, ExtractImagePatches); + if (layer->insData.size() != 1 || layer->outData.size() != 1) + IE_THROW() << errorPrefix << "has incorrect number of input or output edges!" + << " Input: " << layer->insData.size() << "; Output: " << layer->outData.size(); + + auto inData = layer->insData[0].lock(); + if (inData == nullptr) + IE_THROW() << errorPrefix << "has nullable input data"; + + if (inData->getTensorDesc().getDims().size() != 4) + IE_THROW() << errorPrefix << "must have 4D input tensor. Actual: " << inData->getTensorDesc().getDims().size(); + + if (layer->outData[0]->getTensorDesc().getDims().size() != 4) + IE_THROW() << errorPrefix << "must have 4D output tensor. Actual: " << layer->outData[0]->getTensorDesc().getDims().size(); + + if (inData->getLayout() != NCHW) + IE_THROW() << errorPrefix << "has unsupported layout: " << inData->getLayout(); + + const auto precision = inData->getTensorDesc().getPrecision(); + if (_supported_precisions_sizes.find(precision.size()) == _supported_precisions_sizes.end()) + IE_THROW() << errorPrefix << "has unsupported precision: " << precision.name(); + + auto ksizes = layer->GetParamAsUInts("sizes"); + auto strides = layer->GetParamAsUInts("strides"); + auto rates = layer->GetParamAsUInts("rates"); + std::string auto_pad = layer->GetParamAsString("auto_pad"); + if (!CaselessEq()(auto_pad, "valid") + && !CaselessEq()(auto_pad, "same_upper") + && !CaselessEq()(auto_pad, "same_lower")) + IE_THROW() << errorPrefix << "has unsupported auto_pad value: " << auto_pad; + if (ksizes.size() != 2 || strides.size() != 2 || rates.size() != 2) + IE_THROW() << errorPrefix << "must have the following attributes with shape {2}: sizes, strides, rates."; + _ksizes.clear(); + _strides.clear(); + _rates.clear(); + for (const auto& x : ksizes) { + if (x < 0) + IE_THROW() << "Kernel sizes must be non-negative, got '" << x << "'."; + _ksizes.push_back(static_cast(x)); + } + for (const auto& x : strides) { + if (x < 0) + IE_THROW() << "Strides must be non-negative, got '" << x << "'."; + _strides.push_back(static_cast(x)); + } + for (const auto& x : rates) { + if (x < 0) + IE_THROW() << "Rates must be non-negative, got '" << x << "'."; + _rates.push_back(static_cast(x)); + } + + SizeVector in_dims = inData->getTensorDesc().getDims(); + _pad_left = 0; + _pad_top = 0; + jit_extract_image_patches_params jpp; + jpp.need_padding = false; + if (!CaselessEq()(auto_pad, "valid")) { + const size_t iheight = in_dims[2]; + const size_t iwidth = in_dims[3]; + const int64_t ihStep = _ksizes[0] + (_rates[0] - 1) * (_ksizes[0] - 1); + const int64_t iwStep = _ksizes[1] + (_rates[1] - 1) * (_ksizes[1] - 1); + + int64_t PW = (std::ceil(1.f * iwidth/_strides[1]) - 1) * _strides[1] + iwStep - iwidth; + int64_t PH = (std::ceil(1.f * iheight/_strides[0]) - 1) * _strides[0] + ihStep - iheight; + + int64_t increment_sign = 0; + if (CaselessEq()(auto_pad, "same_lower")) { + increment_sign = 1; + } else if (CaselessEq()(auto_pad, "same_upper")) { + increment_sign = -1; + } + + if ((PW > 0) && (PW < iwStep)) { + _pad_left = static_cast((PW + increment_sign * (PW % 2)) / 2); + jpp.need_padding = true; + } + if ((PH > 0) && (PH < ihStep)) { + _pad_top = static_cast((PH + increment_sign * (PH % 2)) / 2); + jpp.need_padding = true; + } + } + + jpp.IW = in_dims[3]; + SizeVector out_dims = layer->outData[0]->getTensorDesc().getDims(); + jpp.OH = out_dims[2]; + jpp.OW = out_dims[3]; + jpp.KH = _ksizes[0]; + jpp.KW = _ksizes[1]; + jpp.SH = _strides[0]; + jpp.SW = _strides[1]; + jpp.dtype_size = layer->insData.front().lock()->getPrecision().size(); + jpp.block_size = 1; + + if (mayiuse(x64::avx512_common)) { + jpp.block_size = cpu_isa_traits::vlen / jpp.dtype_size; + extract_image_patches_kernel.reset(new jit_extract_image_patches_kernel(jpp)); + } else if (mayiuse(x64::avx2)) { + jpp.block_size = cpu_isa_traits::vlen / jpp.dtype_size; + extract_image_patches_kernel.reset(new jit_extract_image_patches_kernel(jpp)); + } else if (mayiuse(x64::sse41)) { + jpp.block_size = cpu_isa_traits::vlen / jpp.dtype_size; + extract_image_patches_kernel.reset(new jit_extract_image_patches_kernel(jpp)); + } + + if (extract_image_patches_kernel) + extract_image_patches_kernel->create_ker(); + + LayerConfig config; + + DataConfig inConfig; + inConfig.desc = inData->getTensorDesc(); + config.inConfs.push_back(inConfig); + + DataConfig outConfig; + outConfig.desc = layer->outData[0]->getTensorDesc(); + outConfig.desc.setPrecision(inConfig.desc.getPrecision()); + outConfig.desc.setLayout(inConfig.desc.getLayout()); + config.outConfs.push_back(outConfig); + + config.dynBatchSupport = false; + confs.push_back(config); + } catch (InferenceEngine::Exception &ex) { + errorMsg = ex.what(); + } +} + + +StatusCode ExtractImagePatchesImpl::execute(std::vector& inputs, std::vector& outputs, ResponseDesc *resp) noexcept { + const char *src_data = inputs[0]->cbuffer().as() + + inputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + char *dst_data = outputs[0]->buffer().as() + + outputs[0]->getTensorDesc().getBlockingDesc().getOffsetPadding(); + const size_t dtype_size = inputs[0]->getTensorDesc().getPrecision().size(); + + const auto& inDims = inputs[0]->getTensorDesc().getDims(); + const size_t IC = inDims[1]; + const size_t IH = inDims[2]; + const size_t IW = inDims[3]; + + const auto& outDims = outputs[0]->getTensorDesc().getDims(); + const size_t OB = outDims[0]; + const size_t OH = outDims[2]; + const size_t OW = outDims[3]; + + const size_t KH = _ksizes[0], KW = _ksizes[1]; + const size_t SH = _strides[0], SW = _strides[1]; + const size_t RH = _rates[0], RW = _rates[1]; + const size_t PT = _pad_top, PL = _pad_left; + + const std::vector istrides = inputs[0]->getTensorDesc().getBlockingDesc().getStrides(); + const std::vector ostrides = outputs[0]->getTensorDesc().getBlockingDesc().getStrides(); + const std::vector ostrides_partial = {ostrides[0], KW * IC * ostrides[1], IC * ostrides[1], ostrides[1]}; + + if (extract_image_patches_kernel) { + parallel_for4d(OB, KH, KW, IC, [&](const size_t ob, const size_t kh, const size_t kw, const size_t ic) { + const int64_t ih_start = kh * RH - PT; + const int64_t iw_start = kw * RW - PL; + const size_t ih_lpad = ih_start >= 0 ? 0 : std::ceil(-1.f * ih_start / SH); + const size_t iw_lpad = iw_start >= 0 ? 0 : std::ceil(-1.f * iw_start / SW); + const size_t ih_hpad = std::ceil((IH - 1.f * ih_start) / SH) > OH ? OH : std::ceil((IH - 1.f * ih_start) / SH); + const size_t iw_hpad = std::ceil((IW - 1.f * iw_start) / SW) > OW ? OW : std::ceil((IW - 1.f * iw_start) / SW); + + size_t dst_offset = ob * ostrides_partial[0] + kh * ostrides_partial[1] + kw * ostrides_partial[2] + ic * ostrides_partial[3]; + size_t src_offset = ob * istrides[0] + ic * istrides[1] + ih_start * istrides[2] + iw_start + ih_lpad * SH * IW; + + auto args = jit_extract_image_patches_args(); + args.src = src_data + src_offset * dtype_size; + args.dst = dst_data + dst_offset * dtype_size; + args.h_lo_pad = ih_lpad; + args.h_hi_pad = ih_hpad; + args.w_lo_pad = iw_lpad; + args.w_hi_pad = iw_hpad; + (*extract_image_patches_kernel)(&args); + }); + } else { + parallel_for4d(OB, KH, KW, IC, [&](const size_t ob, const size_t kh, const size_t kw, const size_t ic) { + const int64_t iw_start = kw * RW - PL; + const int64_t ih_start = kh * RH - PT; + const size_t ih_lpad = ih_start >= 0 ? 0 : std::ceil(- 1.f * ih_start / SH); + const size_t iw_lpad = iw_start >= 0 ? 0 : std::ceil(- 1.f * iw_start / SW); + + const size_t ih_hpad = std::ceil((IH - 1.f * ih_start) / SH) > OH ? OH : std::ceil((IH + -1.f * ih_start) / SH); + const size_t iw_hpad = std::ceil((IW - 1.f * iw_start) / SW) > OW ? OW : std::ceil((IW - 1.f * iw_start) / SW); + + char *my_dst_ptr = dst_data + + (ob * ostrides_partial[0] + kh * ostrides_partial[1] + kw * ostrides_partial[2] + ic * ostrides_partial[3]) * dtype_size; + const char *my_src_ptr = src_data + (ob * istrides[0] + ic * istrides[1] + ih_start * istrides[2] + iw_start) * dtype_size; + + size_t num_bytes_to_set = ih_lpad * OW * dtype_size; + memset(my_dst_ptr, 0, num_bytes_to_set); + my_dst_ptr += num_bytes_to_set; + + const char* src_ptr_h_stop = my_src_ptr + ih_hpad * SH * IW * dtype_size; + for (const char *src_h_ptr = my_src_ptr + ih_lpad * SH * IW * dtype_size; + src_h_ptr < src_ptr_h_stop; src_h_ptr += SH * IW * dtype_size) { + num_bytes_to_set = iw_lpad * dtype_size; + memset(my_dst_ptr, 0, num_bytes_to_set); + my_dst_ptr += num_bytes_to_set; + + const char* src_ptr_w_stop = src_h_ptr + iw_hpad * SW * dtype_size; + for (const char* src_w_ptr = src_h_ptr + iw_lpad * SW * dtype_size; + src_w_ptr < src_ptr_w_stop; src_w_ptr += SW * dtype_size) { + num_bytes_to_set = dtype_size; + memcpy(my_dst_ptr, src_w_ptr, num_bytes_to_set); + my_dst_ptr += num_bytes_to_set; + } + num_bytes_to_set = (OW - iw_hpad) * dtype_size; + memset(my_dst_ptr, 0, num_bytes_to_set); + my_dst_ptr += num_bytes_to_set; + } + num_bytes_to_set = (OH - ih_hpad) * OW * dtype_size; + memset(my_dst_ptr, 0, num_bytes_to_set); + }); + } + return OK; +} + +const std::set ExtractImagePatchesImpl::_supported_precisions_sizes = {1, 2, 4}; } // namespace Cpu } // namespace Extensions diff --git a/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp new file mode 100644 index 00000000000..0effc66b565 --- /dev/null +++ b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp @@ -0,0 +1,62 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once + +#include "base.hpp" +#include +#include + +namespace InferenceEngine { +namespace Extensions { +namespace Cpu { + +struct jit_extract_image_patches_params { + size_t IW; + size_t OH, OW; + size_t KH, KW; + size_t SH, SW; + size_t dtype_size; + size_t block_size; + bool need_padding; +}; + +struct jit_extract_image_patches_args { + uint64_t h_lo_pad; + uint64_t h_hi_pad; + uint64_t w_lo_pad; + uint64_t w_hi_pad; + const void* src; + void* dst; +}; + +struct jit_uni_extract_image_patches_kernel { + void (*ker_)(const jit_extract_image_patches_args *); + void operator()(const jit_extract_image_patches_args *args) { assert(ker_); ker_(args); } + jit_extract_image_patches_params jpp; + virtual void create_ker() = 0; + explicit jit_uni_extract_image_patches_kernel(jit_extract_image_patches_params jpp) : ker_(nullptr), jpp(jpp) {} + virtual ~jit_uni_extract_image_patches_kernel() {} +}; + + +class ExtractImagePatchesImpl : public ExtLayerBase { +public: + explicit ExtractImagePatchesImpl(const CNNLayer*); + StatusCode execute(std::vector&, std::vector&, ResponseDesc*) noexcept override; + +private: + std::vector _ksizes; + std::vector _strides; + std::vector _rates; + size_t _pad_left; + size_t _pad_top; + std::shared_ptr extract_image_patches_kernel; + static const std::set _supported_precisions_sizes; +}; + +REG_FACTORY_FOR(ExtractImagePatchesImpl, ExtractImagePatches); + +} // namespace Cpu +} // namespace Extensions +} // namespace InferenceEngine diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/extract_image_patches.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/extract_image_patches.cpp index d43bc4679c0..14ca4d3e619 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/extract_image_patches.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/extract_image_patches.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2021 Intel Corporation +// Copyright (C) 2020-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // @@ -19,19 +19,12 @@ const std::vector autoPads = {PadType::VALID, PadType::SAME_UPPER, PadT const std::vector netPrecisions = { InferenceEngine::Precision::I8, InferenceEngine::Precision::U8, - InferenceEngine::Precision::I16, + InferenceEngine::Precision::BF16, InferenceEngine::Precision::I32, - InferenceEngine::Precision::FP32 + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::I64 }; -const auto extractImagePatchesParamsSet = ::testing::Combine( - ::testing::ValuesIn(inDataShape), - ::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(rates), - ::testing::ValuesIn(autoPads) -); - INSTANTIATE_TEST_CASE_P(smoke_layers_CPU, ExtractImagePatchesTest, ::testing::Combine( ::testing::ValuesIn(inDataShape), diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/extract_image_patches.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/extract_image_patches.cpp new file mode 100755 index 00000000000..028cd9118d8 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/extract_image_patches.cpp @@ -0,0 +1,92 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils/cpu_test_utils.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" +#include + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { +using LayerTestsDefinitions::extractImagePatchesTuple; + +typedef std::tuple< + extractImagePatchesTuple, + CPUSpecificParams> extractImagePatchesCPUTestParamsSet; + +class ExtractImagePatchesLayerCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + extractImagePatchesTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::ExtractImagePatchesTest::getTestCaseName(testing::TestParamInfo( + basicParamsSet, 0)); + + result << CPUTestsBase::getTestCaseName(cpuParams); + return result.str(); + } +protected: + void SetUp() override { + extractImagePatchesTuple basicParamsSet; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, cpuParams) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + + std::vector inputShape, kernel, strides, rates; + ngraph::op::PadType pad_type; + InferenceEngine::Precision netPrecision; + std::tie(inputShape, kernel, strides, rates, pad_type, netPrecision, inPrc, outPrc, inLayout, targetDevice) = basicParamsSet; + selectedType = std::string("unknown_") + netPrecision.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto inputNode = std::make_shared(ngPrc, ngraph::Shape(inputShape)); + ngraph::ParameterVector params = {inputNode}; + + auto extImgPatches = std::make_shared( + inputNode, ngraph::Shape(kernel), ngraph::Strides(strides), ngraph::Shape(rates), pad_type); + ngraph::ResultVector results{std::make_shared(extImgPatches)}; + function = std::make_shared(results, params, "ExtractImagePatches"); + } +}; + +TEST_P(ExtractImagePatchesLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + Run(); + CheckPluginRelatedResults(executableNetwork, "ExtractImagePatches"); +} + +namespace { + const std::vector> inShapes = {{2, 3, 13, 37}}; + const std::vector> kSizes = {{1, 5}, {3, 4}, {3, 1}}; + const std::vector> strides = {{1, 2}, {2, 2}, {2, 1}}; + const std::vector> rates = {{1, 3}, {3, 3}, {3, 1}}; + + const std::vector autoPads = {ngraph::op::PadType::VALID, ngraph::op::PadType::SAME_UPPER, ngraph::op::PadType::SAME_LOWER}; + const std::vector netPrecision = {Precision::I8, Precision::BF16, Precision::FP32}; + const CPUSpecificParams CPUParams = emptyCPUSpec; + +const auto Layer_params = ::testing::Combine( + ::testing::ValuesIn(inShapes), + ::testing::ValuesIn(kSizes), + ::testing::ValuesIn(strides), + ::testing::ValuesIn(rates), + ::testing::ValuesIn(autoPads), + ::testing::ValuesIn(netPrecision), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU)); + +INSTANTIATE_TEST_CASE_P(smoke_ExtractImagePatches_CPU, ExtractImagePatchesLayerCPUTest, + ::testing::Combine(Layer_params, ::testing::Values(CPUParams)), + ExtractImagePatchesLayerCPUTest::getTestCaseName); + +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/extract_image_patches.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/extract_image_patches.hpp index af16c325b47..2be311afcf4 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/extract_image_patches.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/extract_image_patches.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2021 Intel Corporation +// Copyright (C) 2020 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // From 8bb73273f117edbf5605219899048ab076f170af Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Sun, 25 Apr 2021 21:42:04 +0300 Subject: [PATCH 77/78] fix: string comparing in object_detection_sample_ssd_c (#5371) --- .../ie_bridges/c/samples/object_detection_sample_ssd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c index 4eac9dd3ad6..6c347192c5b 100644 --- a/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c +++ b/inference-engine/ie_bridges/c/samples/object_detection_sample_ssd/main.c @@ -360,7 +360,7 @@ int main(int argc, char** argv) { printf("%sCustom extension loaded: %s\n", info, custom_ex_library_msg); } - if (custom_plugin_cfg_msg && (device_name == "GPU" || device_name == "MYRIAD" || device_name == "HDDL")) { + if (custom_plugin_cfg_msg && (strcmp(device_name, "GPU") == 0 || strcmp(device_name, "MYRIAD") == 0 || strcmp(device_name, "HDDL") == 0)) { // Config for device plugin custom extension is loaded from an .xml // description ie_config_t cfg = {"CONFIG_FILE", custom_plugin_cfg_msg, NULL}; From 39e1a21c42da1a44bfecd4ed92259751ae0fd765 Mon Sep 17 00:00:00 2001 From: Egor Duplensky Date: Sun, 25 Apr 2021 22:18:38 +0300 Subject: [PATCH 78/78] [CPU] Enable bf16 RNN primitives (#4942) --- .../src/mkldnn_plugin/nodes/mkldnn_rnn.cpp | 497 +++++++++++------- .../src/mkldnn_plugin/nodes/mkldnn_rnn.h | 26 +- .../cpu/single_layer_tests/gru_cell.cpp | 135 +++++ .../cpu/single_layer_tests/gru_sequence.cpp | 202 +++++++ .../cpu/single_layer_tests/lstm_cell.cpp | 132 +++++ .../cpu/single_layer_tests/lstm_sequence.cpp | 205 ++++++++ .../cpu/single_layer_tests/rnn_cell.cpp | 124 +++++ .../cpu/single_layer_tests/rnn_sequence.cpp | 202 +++++++ .../plugin/cpu/test_utils/cpu_test_utils.cpp | 78 ++- .../plugin/cpu/test_utils/cpu_test_utils.hpp | 41 +- .../single_layer/lstm_cell.hpp | 3 +- inference-engine/thirdparty/mkl-dnn | 2 +- 12 files changed, 1425 insertions(+), 222 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_cell.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_cell.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_cell.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp index 62e4a64eda0..9b220b0a9a6 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp @@ -5,12 +5,17 @@ #include "mkldnn_rnn.h" #include "mkldnn_extension_utils.h" +#include "mkldnn_node.h" #include "utils/general_utils.h" #include "nodes/common/cpu_memcpy.h" +#include "utils/bfloat16.hpp" +#include "nodes/common/cpu_convert.h" #include #include +#define THROW_ERROR IE_THROW() << NameFromType(getType()) << " layer '" << getName() << "' " + using namespace mkldnn; using namespace InferenceEngine; @@ -39,7 +44,7 @@ static algorithm ie2mkl(RNNCellBase::CellType cell_type) { case RNNCellBase::GRU: return algorithm::vanilla_gru; case RNNCellBase::GRU_LBR: return algorithm::lbr_gru; default: - IE_THROW() << "Unsupported cell type"; + IE_THROW() << "RNN node. Unsupported cell type"; return algorithm::undef; } } @@ -51,7 +56,7 @@ size_t gatesCount(algorithm alg) { case algorithm::lbr_gru: return 3; case algorithm::vanilla_lstm: return 4; default: - IE_THROW() << "Unsupported cell type"; + IE_THROW() << "RNN node. Unsupported cell type"; return 0; } } @@ -63,11 +68,24 @@ size_t statesCount(algorithm alg) { case algorithm::lbr_gru: return 1; case algorithm::vanilla_lstm: return 2; default: - IE_THROW() << "Unsupported cell type"; + IE_THROW() << "RNN node. Unsupported cell type"; return 0; } } +bool haveCellState(algorithm alg) { + return alg == algorithm::vanilla_lstm; +} + +const std::map MKLDNNRNN::weightsByLayerPrec { + // layer precision, weights precision + {InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP32}, + {InferenceEngine::Precision::BF16, InferenceEngine::Precision::BF16}, + // FP16 and U8 are not supported yet + // {InferenceEngine::Precision::FP16, InferenceEngine::Precision::FP16}, + // {InferenceEngine::Precision::U8, InferenceEngine::Precision::I8}, +}; + MKLDNNRNN::MKLDNNRNN(const InferenceEngine::CNNLayerPtr& layer, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) : MKLDNNNode(layer, eng, cache) { is_cell = one_of(layer->type, "LSTMCell", "GRUCell", "RNNCell"); @@ -78,6 +96,8 @@ bool MKLDNNRNN::created() const { } void MKLDNNRNN::getSupportedDescriptors() { + runtimePrecision = getCnnLayer()->insData[0].lock()->getPrecision(); + if (is_cell) fillCellDesc(); else @@ -89,14 +109,14 @@ void MKLDNNRNN::fillCellDesc() { auto cellLayer = std::dynamic_pointer_cast(getCnnLayer()); if (!cellLayer) - IE_THROW() << "No original layer for RNNCell."; + THROW_ERROR << "No original layer for RNNCell."; cell_type = ie2mkl(cellLayer->cellType); cell_act = ie2mkl(cellLayer->activations[0]); // Works only for RNN with one gate if (cellLayer->clip != 0.0f) { // TODO [oneDNN]: No more supported - IE_THROW() << "Clipping is not supported for RNN primitive"; + THROW_ERROR << "Clipping is not supported for RNN primitive"; // cell_desc.set_clipping(cellLayer->clip); } @@ -104,16 +124,16 @@ void MKLDNNRNN::fillCellDesc() { auto &outs = cellLayer->outData; if (!one_of(ins.size(), 3, 2)) - IE_THROW() << "Incorrect number of input ports for layer " << getName(); + THROW_ERROR << "Incorrect number of input ports for layer " << getName(); if (!one_of(outs.size(), 2, 1)) - IE_THROW() << "Incorrect number of output ports for layer " << getName(); + THROW_ERROR << "Incorrect number of output ports for layer " << getName(); auto in_data_dims = getParentEdgeAt(0)->getDims(); auto in_h_state_dims = getParentEdgeAt(1)->getDims(); auto out_h_state_dims = getChildEdgeAt(0)->getDims(); if (in_data_dims.ndims() != 2 || in_h_state_dims.ndims() != 2) - IE_THROW() << "Incorrect shape of input/output ports for layer " << getName(); + THROW_ERROR << "Incorrect shape of input/output ports for layer " << getName(); G = gatesCount(cell_type); S = statesCount(cell_type); @@ -130,7 +150,7 @@ void MKLDNNRNN::fillCellDesc() { if (in_data_dims != D_shape || in_h_state_dims != S_shape || out_h_state_dims != S_shape) - IE_THROW() << "Incorrect shape of input/output ports for layer " << getName(); + THROW_ERROR << "Incorrect shape of input/output ports for layer " << getName(); if (S == 2) { auto in_c_state_dims = getParentEdgeAt(2)->getDims(); @@ -138,7 +158,7 @@ void MKLDNNRNN::fillCellDesc() { if (in_c_state_dims != S_shape || out_c_state_dims != S_shape) - IE_THROW() << "Incorrect shape of input/output ports for layer " << getName(); + THROW_ERROR << "Incorrect shape of input/output ports for layer " << getName(); } auto blobs = cellLayer->blobs; @@ -147,40 +167,53 @@ void MKLDNNRNN::fillCellDesc() { if (blobs.find("biases") != blobs.end()) bias = blobs["biases"]; if (!weights) - IE_THROW() << "RNN Layer. Weights do not present."; + THROW_ERROR << "RNN Layer. Weights do not present."; - if (weights->size() != G*SC*(SC+DC)) - IE_THROW() << "RNN Layer. Weights size is not correct. Expected size:" << G*SC*(SC+DC); + if (weights->size() != G * SC * (SC + DC)) + THROW_ERROR << "RNN Layer. Weights size is not correct. Expected size:" << G * SC * (SC + DC); - if (bias && bias->size() != Gb*SC) - IE_THROW() << "RNN Layer. Biases size is not correct. Expected size:" << G*SC; + if (bias && bias->size() != Gb * SC) + THROW_ERROR << "RNN Layer. Biases size is not correct. Expected size:" << G * SC; + + auto dataType = MKLDNNExtensionUtils::IEPrecisionToDataType(runtimePrecision); + + // layer input plus states + in_data_d.resize(S + 1); + out_data_d.resize(S + 1); // Shapes and Attributes are correct. Can start internal stuff initialization. - for (size_t i = 0; i < S; i++) { - in_states_d.emplace_back(S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc); - out_states_d.emplace_back(S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc); + in_data_d[RNNInOutKind::Layer] = {{T, N, DC}, dataType, memory::format_tag::tnc}; + out_data_d[RNNInOutKind::Layer] = {{T, N, SC}, dataType, memory::format_tag::tnc}; + + in_data_d[RNNInOutKind::HiddenState] = {S_4D_shape, dataType, memory::format_tag::ldnc}; + out_data_d[RNNInOutKind::HiddenState] = {S_4D_shape, dataType, memory::format_tag::ldnc}; + + if (haveCellState(cell_type)) { + in_data_d[RNNInOutKind::CellState] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; + out_data_d[RNNInOutKind::CellState] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; } - in_data_d = {{T, N, DC}, memory::data_type::f32, memory::format_tag::tnc};; - out_data_d = {{T, N, SC}, memory::data_type::f32, memory::format_tag::tnc};; - - w_data_d = {{L, D, DC, G, SC}, memory::data_type::f32, memory::format_tag::ldigo}; - w_state_d = {{L, D, SC, G, SC}, memory::data_type::f32, memory::format_tag::ldigo}; + w_data_d = {{L, D, DC, G, SC}, dataType, memory::format_tag::ldigo}; + w_state_d = {{L, D, SC, G, SC}, dataType, memory::format_tag::ldigo}; if (bias) w_bias_d = {{L, D, Gb, SC}, memory::data_type::f32, memory::format_tag::ldgo}; std::vector in_candidate, out_candidate; - std::vector outputFormats; - in_candidate.emplace_back(MKLDNNMemoryDesc {D_shape, memory::data_type::f32, memory::format_tag::nc}); - in_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, memory::data_type::f32, memory::format_tag::nc}); - out_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, memory::data_type::f32, memory::format_tag::nc}); - outputFormats.emplace_back(memory::format_tag::nc); + in_candidate.emplace_back(MKLDNNMemoryDesc {D_shape, dataType, memory::format_tag::nc}); + in_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, dataType, memory::format_tag::nc}); + out_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, dataType, memory::format_tag::nc}); - if (S == 2) { + if (haveCellState(cell_type)) { in_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, memory::data_type::f32, memory::format_tag::nc}); out_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, memory::data_type::f32, memory::format_tag::nc}); - outputFormats.emplace_back(memory::format_tag::nc); + } + + Precision weights_prec = as(weights)->getTensorDesc().getPrecision(); + + if (!verifyWeightsPrecision(runtimePrecision, weights_prec)) { + if (runtimePrecision == Precision::BF16 && weights_prec == Precision::FP32) + convertWeightsBlobToBF16(); } createDescriptor(in_candidate, out_candidate); @@ -191,10 +224,10 @@ void MKLDNNRNN::fillSeqDesc() { auto rnnLayer = std::dynamic_pointer_cast(getCnnLayer()); if (!rnnLayer) - IE_THROW() << "Wrong RNN layer representation. Cannot cast to RNNSequenceLayer."; + THROW_ERROR << "Wrong RNN layer representation. Cannot cast to RNNSequenceLayer."; if (!one_of(rnnLayer->cellType, _RNN::LSTM, _RNN::GRU, _RNN::GRU_LBR, _RNN::RNN)) - IE_THROW() << "RNN layer supports only LSTM/GRU/RNN cell"; + THROW_ERROR << "RNN layer supports only LSTM/GRU/RNN cell"; cell_type = ie2mkl(rnnLayer->cellType); cell_act = algorithm::undef; @@ -203,31 +236,31 @@ void MKLDNNRNN::fillSeqDesc() { // TODO [oneDNN]: No more supported if (rnnLayer->clip != 0.0f) { - IE_THROW() << "Clipping is not supported for RNN primitive"; + THROW_ERROR << "Clipping is not supported for RNN primitive"; // cell_desc.set_clipping(rnnLayer->clip); } if (!one_of(rnnLayer->axis, 0, 1)) - IE_THROW() << "RNN layer supports only sequence axis 0 or 1"; + THROW_ERROR << "RNN layer supports only sequence axis 0 or 1"; nativeOrder = rnnLayer->axis == 0; if (!one_of(rnnLayer->direction, _RNN::FWD, _RNN::BWD)) - IE_THROW() << "RNN layer supports only unidirectional RNN layer"; + THROW_ERROR << "RNN layer supports only unidirectional RNN layer"; direction = ie2mkl(rnnLayer->direction); auto &ins = rnnLayer->insData; auto &outs = rnnLayer->outData; if (!one_of(ins.size(), 3, 2, 1)) - IE_THROW() << "Incorrect number of input ports for layer " << getName(); + THROW_ERROR << "Incorrect number of input ports for layer " << getName(); if (!one_of(outs.size(), 3, 2, 1)) - IE_THROW() << "Incorrect number of output ports for layer " << getName(); + THROW_ERROR << "Incorrect number of output ports for layer " << getName(); auto in_data_dims = getParentEdgeAt(0)->getDims(); auto out_data_dims = getChildEdgeAt(0)->getDims(); if (in_data_dims.ndims() != 3 || out_data_dims.ndims() != 3) - IE_THROW() << "Incorrect shape of input/output ports for layer " << getName(); + THROW_ERROR << "Incorrect shape of input/output ports for layer " << getName(); if (!nativeOrder) { std::swap(in_data_dims[0], in_data_dims[1]); @@ -246,125 +279,153 @@ void MKLDNNRNN::fillSeqDesc() { MKLDNNDims ID_shape {T, N, DC}, OD_shape {T, N, SC}, S_shape {N, SC}, S_4D_shape {L, D, N, SC}; if (out_data_dims != OD_shape) - IE_THROW() << "Incorrect shape of input/output ports for layer " << getName(); + THROW_ERROR << "Incorrect shape of input/output ports for layer " << getName(); - in_states_d.resize(S); - out_states_d.resize(S); - - for (int i = 1; i < ins.size(); i++) { - if (getParentEdgeAt(i)->getDims() != S_shape) - IE_THROW() << "Incorrect shape of state ports for layer " << getName(); - in_states_d[i - 1] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; - } - - for (int i = 1; i < outs.size(); i++) { - if (getChildEdgeAt(i)->getDims() != S_shape) - IE_THROW() << "Incorrect shape of state ports for layer " << getName(); - out_states_d[i - 1] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; - } - - auto blobs = rnnLayer->blobs; + auto& blobs = rnnLayer->blobs; Blob::Ptr weights, bias; if (blobs.find("weights") != blobs.end()) weights = blobs["weights"]; if (blobs.find("biases") != blobs.end()) bias = blobs["biases"]; if (!weights) - IE_THROW() << "RNN Layer. Weights do not present."; + THROW_ERROR << "RNN Layer. Weights do not present."; - if (weights->size() != G*SC*(SC+DC)) - IE_THROW() << "RNN Layer. Weights size is not correct. Expected size:" << G*SC*(SC+DC); + if (weights->size() != G * SC * (SC + DC)) + THROW_ERROR << "RNN Layer. Weights size is not correct. Expected size:" << G * SC * (SC + DC); - w_data_d = {{L, D, DC, G, SC}, memory::data_type::f32, memory::format_tag::ldigo}; - w_state_d = {{L, D, SC, G, SC}, memory::data_type::f32, memory::format_tag::ldigo}; + for (int i = 1; i < ins.size(); i++) { + if (getParentEdgeAt(i)->getDims() != S_shape) + THROW_ERROR << "Incorrect shape of state ports for layer " << getName(); + } - if (bias && bias->size() != Gb*SC) - IE_THROW() << "RNN Layer. Biases size is not correct. Expected size:" << G*SC; + for (int i = 1; i < outs.size(); i++) { + if (getChildEdgeAt(i)->getDims() != S_shape) + THROW_ERROR << "Incorrect shape of state ports for layer " << getName(); + } + + // layer input plus states + in_data_d.resize(S + 1); + out_data_d.resize(S + 1); + + auto dataType = MKLDNNExtensionUtils::IEPrecisionToDataType(runtimePrecision); + + // Try to create descriptor and corresponding configuration + in_data_d[RNNInOutKind::Layer] = {in_data_dims, dataType, memory::format_tag::tnc}; + out_data_d[RNNInOutKind::Layer] = {out_data_dims, dataType, memory::format_tag::tnc}; + + in_data_d[RNNInOutKind::HiddenState] = {S_4D_shape, dataType, memory::format_tag::ldnc}; + out_data_d[RNNInOutKind::HiddenState] = {S_4D_shape, dataType, memory::format_tag::ldnc}; + + if (haveCellState(cell_type)) { + in_data_d[RNNInOutKind::CellState] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; + out_data_d[RNNInOutKind::CellState] = {S_4D_shape, memory::data_type::f32, memory::format_tag::ldnc}; + } + + w_data_d = {{L, D, DC, G, SC}, dataType, memory::format_tag::ldigo}; + w_state_d = {{L, D, SC, G, SC}, dataType, memory::format_tag::ldigo}; + + if (bias && bias->size() != Gb * SC) + THROW_ERROR << "RNN Layer. Biases size is not correct. Expected size:" << G * SC; if (bias) w_bias_d = {{L, D, Gb, SC}, memory::data_type::f32, memory::format_tag::ldgo}; - // Try to create descriptor and corresponding configuration - in_data_d = {in_data_dims, memory::data_type::f32, memory::format_tag::tnc}; - out_data_d = {out_data_dims, memory::data_type::f32, memory::format_tag::tnc}; + std::vector in_candidate, out_candidate; - std::vector in_candidate; - if (nativeOrder) - in_candidate.push_back(in_data_d); - else - in_candidate.push_back(MKLDNNMemoryDesc{{N, T, DC}, memory::data_type::f32, memory::format_tag::ntc}); - - for (int i = 1; i < ins.size(); i++) - in_candidate.emplace_back(MKLDNNMemoryDesc {S_shape, memory::data_type::f32, memory::format_tag::nc}); - - std::vector out_candidate; if (nativeOrder) { - out_candidate.push_back(out_data_d); + in_candidate.push_back(in_data_d[RNNInOutKind::Layer]); + out_candidate.push_back(out_data_d[RNNInOutKind::Layer]); } else { - out_candidate.push_back(MKLDNNMemoryDesc{{N, T, SC}, memory::data_type::f32, memory::format_tag::ntc}); + in_candidate.emplace_back(MKLDNNMemoryDesc{{N, T, DC}, dataType, memory::format_tag::ntc}); + out_candidate.emplace_back(MKLDNNMemoryDesc{{N, T, SC}, dataType, memory::format_tag::ntc}); } - for (int i = 1; i < outs.size(); i++) { + in_candidate.emplace_back(MKLDNNMemoryDesc{S_shape, dataType, memory::format_tag::nc}); + out_candidate.emplace_back(MKLDNNMemoryDesc{S_shape, dataType, memory::format_tag::nc}); + + if (haveCellState(cell_type)) { + in_candidate.emplace_back(MKLDNNMemoryDesc{S_shape, memory::data_type::f32, memory::format_tag::nc}); out_candidate.emplace_back(MKLDNNMemoryDesc{S_shape, memory::data_type::f32, memory::format_tag::nc}); } + Precision weights_prec = as(weights)->getTensorDesc().getPrecision(); + + if (!verifyWeightsPrecision(runtimePrecision, weights_prec)) { + if (runtimePrecision == Precision::BF16 && weights_prec == Precision::FP32) + convertWeightsBlobToBF16(); + } + createDescriptor(in_candidate, out_candidate); } +void MKLDNNRNN::convertWeightsBlobToBF16() { + Blob::Ptr &weights = getCnnLayer()->blobs["weights"]; + MemoryBlob::Ptr cur_weights = as(weights); + TensorDesc td(Precision::BF16, cur_weights->getTensorDesc().getDims(), cur_weights->getTensorDesc().getLayout()); + MemoryBlob::Ptr new_weights_blob = make_shared_blob(td); + + new_weights_blob->allocate(); + bfloat16_t *dst = new_weights_blob->wmap(); + + float* fp32src = cur_weights->rmap().as(); + cpu_convert(fp32src, dst, Precision::FP32, Precision::BF16, new_weights_blob->size()); + weights = new_weights_blob; +} + void MKLDNNRNN::createDescriptor(const std::vector &inputDesc, const std::vector &outputDesc) { switch (cell_type) { case mkldnn::algorithm::vanilla_rnn: { MKLDNNDescriptor desc(std::shared_ptr( new vanilla_rnn_forward::desc(prop_kind::forward_scoring, cell_act, direction, - /* In Data */ in_data_d, - /* In State */ in_states_d[0], + /* In Data */ in_data_d[RNNInOutKind::Layer], + /* In State */ in_data_d[RNNInOutKind::HiddenState], /* Weights data */ w_data_d, /* Weights state */ w_state_d, /* Bias */ w_bias_d, - /* Out Data */ out_data_d, - /* Out State */ out_states_d[0]))); + /* Out Data */ out_data_d[RNNInOutKind::Layer], + /* Out State */ out_data_d[RNNInOutKind::HiddenState]))); descs.push_back(desc); } break; case mkldnn::algorithm::vanilla_gru: { MKLDNNDescriptor desc(std::shared_ptr( new gru_forward::desc(prop_kind::forward_scoring, direction, - /* In Data */ in_data_d, - /* In State */ in_states_d[0], + /* In Data */ in_data_d[RNNInOutKind::Layer], + /* In State */ in_data_d[RNNInOutKind::HiddenState], /* Weights data */ w_data_d, /* Weights state */ w_state_d, /* Bias */ w_bias_d, - /* Out Data */ out_data_d, - /* Out State */ out_states_d[0]))); + /* Out Data */ out_data_d[RNNInOutKind::Layer], + /* Out State */ out_data_d[RNNInOutKind::HiddenState]))); descs.push_back(desc); } break; case mkldnn::algorithm::lbr_gru: { MKLDNNDescriptor desc(std::shared_ptr( new lbr_gru_forward::desc(prop_kind::forward_scoring, direction, - /* In Data */ in_data_d, - /* In State */ in_states_d[0], + /* In Data */ in_data_d[RNNInOutKind::Layer], + /* In State */ in_data_d[RNNInOutKind::HiddenState], /* Weights data */ w_data_d, /* Weights state */ w_state_d, /* Bias */ w_bias_d, - /* Out Data */ out_data_d, - /* Out State */ out_states_d[0]))); + /* Out Data */ out_data_d[RNNInOutKind::Layer], + /* Out State */ out_data_d[RNNInOutKind::HiddenState]))); descs.push_back(desc); } break; case mkldnn::algorithm::vanilla_lstm: { MKLDNNDescriptor desc(std::shared_ptr( new lstm_forward::desc(prop_kind::forward_scoring, direction, - /* In Data */ in_data_d, - /* In State H */ in_states_d[0], - /* In State C */ in_states_d[1], + /* In Data */ in_data_d[RNNInOutKind::Layer], + /* In State */ in_data_d[RNNInOutKind::HiddenState], + /* In State C */ in_data_d[RNNInOutKind::CellState], /* Weights data */ w_data_d, /* Weights state */ w_state_d, /* Bias */ w_bias_d, - /* Out Data */ out_data_d, - /* Out State H */ out_states_d[0], - /* Out State C */ out_states_d[1]))); + /* Out Data */ out_data_d[RNNInOutKind::Layer], + /* Out State */ out_data_d[RNNInOutKind::HiddenState], + /* Out State C */ out_data_d[RNNInOutKind::CellState]))); descs.push_back(desc); } break; default: - IE_THROW() << "Unknown cell type"; + THROW_ERROR << "Unknown cell type"; } // Fill supported config @@ -389,130 +450,170 @@ void MKLDNNRNN::createDescriptor(const std::vector &inputDesc, supportedPrimitiveDescriptors.emplace_back(config, ref_any); } +bool MKLDNNRNN::verifyWeightsPrecision(const Precision &layerPrec, const Precision &weightsPrec) { + if (!weightsByLayerPrec.count(layerPrec)) + THROW_ERROR << "Unsupported layer precision " << layerPrec; + return weightsPrec == weightsByLayerPrec.at(layerPrec); +} + +void MKLDNNRNN::verifyWeights() { + auto layer = getCnnLayer(); + auto weightsIt = layer->blobs.find("weights"); + + if (weightsIt == layer->blobs.end()) + THROW_ERROR << "Missed weights blob."; + + const auto& weightsPrec = weightsIt->second->getTensorDesc().getPrecision(); + + if (!verifyWeightsPrecision(runtimePrecision, weightsPrec)) { + THROW_ERROR << "Weights precision " << weightsPrec << + " does not match runtime precision" << runtimePrecision; + } +} + +void MKLDNNRNN::verifyBiases() { + auto layer = getCnnLayer(); + if (layer->blobs.find("biases") != layer->blobs.end() + && layer->blobs["biases"]->getTensorDesc().getPrecision() != Precision::FP32) + THROW_ERROR << "Invalid biases precision: " << layer->blobs["biases"]->getTensorDesc().getPrecision(); +} + void MKLDNNRNN::createPrimitive() { if (prim) return; - std::string errorPrefix = "RNN layer '" + getCnnLayer()->name + "'"; - auto weightsIt = getCnnLayer()->blobs.find("weights"); - if (weightsIt == getCnnLayer()->blobs.end()) - IE_THROW() << errorPrefix << " does not have weights blob."; - if (weightsIt->second->getTensorDesc().getPrecision() != Precision::FP32) - IE_THROW() << errorPrefix << " has invalid weights precision: " << weightsIt->second->getTensorDesc().getPrecision(); - if (getCnnLayer()->blobs.find("biases") != getCnnLayer()->blobs.end() - && getCnnLayer()->blobs["biases"]->getTensorDesc().getPrecision() != Precision::FP32) - IE_THROW() << errorPrefix << " has invalid biases precision: " << getCnnLayer()->blobs["biases"]->getTensorDesc().getPrecision(); + verifyWeights(); + verifyBiases(); + + /* + * Gate order + * ====== LSTM ====== + * Caffe - IFOC, ONNX - IOFC + * IE - FICO, mkldnn - IFCO + * + * ====== GRU ====== + * IE - URO, mkldnn - URO + */ + const int gate_map_lstm[] = {1, 0, 2, 3}; // FICO -> IFCO + const int gate_map_gru[] = {0, 1, 2, 3}; + const int gate_map_rnn[] = {0}; + const int *gate_map; + const int gate_map_lstm_size = sizeof(gate_map_lstm) / sizeof(int); + const int gate_map_gru_size = sizeof(gate_map_gru) / sizeof(int); + const int gate_map_rnn_size = sizeof(gate_map_rnn) / sizeof(int); + if (cell_type == algorithm::vanilla_lstm) { + gate_map = gate_map_lstm; + if (G > gate_map_lstm_size) { + THROW_ERROR << "G isn't equal to the size of gate_map"; + } + } else if (cell_type == algorithm::vanilla_gru) { + gate_map = gate_map_gru; + if (G > gate_map_gru_size) { + THROW_ERROR << "G isn't equal to the size of gate_map"; + } + } else if (cell_type == algorithm::lbr_gru) { + gate_map = gate_map_gru; + if (G > gate_map_gru_size) { + THROW_ERROR << "G isn't equal to the size of gate_map"; + } + } else if (cell_type == algorithm::vanilla_rnn) { + gate_map = gate_map_rnn; + if (G > gate_map_rnn_size) { + THROW_ERROR << "G isn't equal to the size of gate_map"; + } + } else { + gate_map = gate_map_gru; + if (G > gate_map_gru_size) { + THROW_ERROR << "G isn't equal to the size of gate_map"; + } + } + + if (runtimePrecision == Precision::BF16) + fillWeights(gate_map); + else if (runtimePrecision == Precision::FP32) + fillWeights(gate_map); + else // TODO FP16 and INT8 support + THROW_ERROR << "Unsupported data type"; + + if (runtimePrecision == Precision::BF16 || + runtimePrecision == Precision::FP32) + fillBiases(gate_map); auto pd = descs[0].createPrimitiveDescriptorIterator(getEngine()); + prim.reset(new mkldnn::primitive(pd)); +} - auto src_data_mem = getParentEdgeAt(0)->getMemoryPtr(); - auto dst_data_mem = getChildEdgeAt(0)->getMemoryPtr(); - - // create weight blobs (data and state part) - auto w_data_mem = std::make_shared(getEngine()); - w_data_mem->Create(w_data_d); - internalBlobMemory.push_back(w_data_mem); - - auto w_state_mem = std::make_shared(getEngine()); - w_state_mem->Create(w_state_d); - internalBlobMemory.push_back(w_state_mem); +/* + * IE format: + * B - [gates, out_state_size] + * + * MKLDNN format: + * B - [gates, out_state_size] + * + */ +template +void MKLDNNRNN::fillBiases(const int *gate_map) { + if (!w_bias_d) + return; auto w_bias_mem = std::make_shared(getEngine()); w_bias_mem->Create(w_bias_d); internalBlobMemory.push_back(w_bias_mem); - { - /* Copy Weight data - * IE format: - * W - [gates, out_state_size, in_data_size + in_state_size] - * B - [gates, out_state_size] - * - * MKLDNN format: - * W - [1, 1, in_date_size, gates, out_state_size] - * R - [1, 1, in_state_size, gates, out_state_size] - * B - [gates, out_state_size] - * - * Gate order - * ====== LSTM ====== - * Caffe - IFOC, ONNX - IOFC - * IE - FICO, mkldnn - IFCO - * - * ====== GRU ====== - * IE - URO, mkldnn - URO - */ - const int gate_map_lstm[] = {1, 0, 2, 3}; // FICO -> IFCO - const int gate_map_gru[] = {0, 1, 2, 3}; - const int gate_map_rnn[] = {0}; - const int *gate_map; - const int gate_map_lstm_size = sizeof(gate_map_lstm) / sizeof(int); - const int gate_map_gru_size = sizeof(gate_map_gru) / sizeof(int); - const int gate_map_rnn_size = sizeof(gate_map_rnn) / sizeof(int); - if (cell_type == algorithm::vanilla_lstm) { - gate_map = gate_map_lstm; - if (G > gate_map_lstm_size) { - IE_THROW() << "G isn't equal to the size of gate_map"; - } - } else if (cell_type == algorithm::vanilla_gru) { - gate_map = gate_map_gru; - if (G > gate_map_gru_size) { - IE_THROW() << "G isn't equal to the size of gate_map"; - } - } else if (cell_type == algorithm::lbr_gru) { - gate_map = gate_map_gru; - if (G > gate_map_gru_size) { - IE_THROW() << "G isn't equal to the size of gate_map"; - } - } else if (cell_type == algorithm::vanilla_rnn) { - gate_map = gate_map_rnn; - if (G > gate_map_rnn_size) { - IE_THROW() << "G isn't equal to the size of gate_map"; - } - } else { - gate_map = gate_map_gru; - if (G > gate_map_gru_size) { - IE_THROW() << "G isn't equal to the size of gate_map"; - } - } + auto ie_b_ptr = getCnnLayer()->blobs["biases"]->buffer().as(); + auto b_ptr = static_cast(w_bias_mem->GetData()); + for (int g = 0; g < Gb; g++) { + Prec *l_b_ptr = b_ptr + gate_map[g]*SC; + const Prec *l_ie_b_ptr = ie_b_ptr + g * SC; + cpu_memcpy(l_b_ptr, l_ie_b_ptr, SC * sizeof(Prec)); + } +} - auto ie_w_ptr = getCnnLayer()->blobs["weights"]->buffer().as(); - auto w_ptr = static_cast(w_data_mem->GetData()); - auto r_ptr = static_cast(w_state_mem->GetData()); - const int step = SC * G; +/* + * IE format: + * W - [gates, out_state_size, in_data_size + in_state_size] + * + * MKLDNN format: + * W - [1, 1, in_date_size, gates, out_state_size] + * R - [1, 1, in_state_size, gates, out_state_size] + * + */ +template +void MKLDNNRNN::fillWeights(const int *gate_map) { + // create weight blobs (data and state part) + auto w_data_mem = std::make_shared(getEngine()); + w_data_mem->Create(w_data_d); + internalBlobMemory.push_back(w_data_mem); + auto w_state_mem = std::make_shared(getEngine()); + w_state_mem->Create(w_state_d); + internalBlobMemory.push_back(w_state_mem); - for (int g = 0; g < G; g++) { - for (int out_i = 0; out_i < SC; out_i++) { - float *l_w_ptr = w_ptr + gate_map[g]*SC + out_i; - float *l_r_ptr = r_ptr + gate_map[g]*SC+ out_i; - for (int in_i = 0; in_i < DC; in_i++) { - *l_w_ptr = *ie_w_ptr; - ie_w_ptr++; - l_w_ptr += step; - } + auto ie_w_ptr = getCnnLayer()->blobs["weights"]->buffer().as(); + auto w_ptr = static_cast(w_data_mem->GetData()); + auto r_ptr = static_cast(w_state_mem->GetData()); + const int step = SC * G; - for (int in_i = 0; in_i < SC; in_i++) { - *l_r_ptr = *ie_w_ptr; - ie_w_ptr++; - l_r_ptr += step; - } + for (int g = 0; g < G; g++) { + for (int out_i = 0; out_i < SC; out_i++) { + Prec *l_w_ptr = w_ptr + gate_map[g]*SC + out_i; + Prec *l_r_ptr = r_ptr + gate_map[g]*SC+ out_i; + for (int in_i = 0; in_i < DC; in_i++) { + *l_w_ptr = *ie_w_ptr; + ie_w_ptr++; + l_w_ptr += step; } - } - if (w_bias_d) { - auto ie_b_ptr = getCnnLayer()->blobs["biases"]->buffer().as(); - auto b_ptr = static_cast(w_bias_mem->GetData()); - for (int g = 0; g < Gb; g++) { - float *l_b_ptr = b_ptr + gate_map[g]*SC; - const float *l_ie_b_ptr = ie_b_ptr + g * SC; - cpu_memcpy(l_b_ptr, l_ie_b_ptr, SC * sizeof(float)); + for (int in_i = 0; in_i < SC; in_i++) { + *l_r_ptr = *ie_w_ptr; + ie_w_ptr++; + l_r_ptr += step; } } } - - prim.reset(new mkldnn::primitive(pd)); } void MKLDNNRNN::execute(mkldnn::stream strm) { if (!prim) - IE_THROW() << "No initialized primitive to execute"; + THROW_ERROR << "No initialized primitive to execute"; const auto src_data_mem = getParentEdgeAt(0)->getMemoryPtr(); const auto dst_data_mem = getChildEdgeAt(0)->getMemoryPtr(); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h index cb16a3d242d..2cf51f09913 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.h @@ -28,8 +28,19 @@ public: private: void fillCellDesc(); void fillSeqDesc(); + bool verifyWeightsPrecision(const InferenceEngine::Precision& layerPrec, + const InferenceEngine::Precision& weightsPrec); + void verifyWeights(); + void verifyBiases(); + void convertWeightsBlobToBF16(); + + template + void fillWeights(const int* gate_map); + template + void fillBiases(const int* gate_map); private: + InferenceEngine::Precision runtimePrecision; /** Specify mode Cell or Seq. true - Cell, false - Seq */ bool is_cell = false; @@ -56,11 +67,14 @@ private: const ptrdiff_t L = 1; /**< What is it??. Constant for mkldnn impl */ const ptrdiff_t D = 1; /**< Num of direction. 1 or 2 */ - MKLDNNMemoryDesc in_data_d; - MKLDNNMemoryDesc out_data_d; + std::vector in_data_d; + std::vector out_data_d; - std::vector in_states_d; - std::vector out_states_d; + enum RNNInOutKind { + Layer = 0, + HiddenState = 1, + CellState = 2 + }; MKLDNNMemoryDesc w_data_d; MKLDNNMemoryDesc w_state_d; @@ -69,7 +83,7 @@ private: // List of in/out reorders if required std::vector exec_before; std::vector exec_after; -}; + static const std::map weightsByLayerPrec; +}; // class MKLDNNRNN } // namespace MKLDNNPlugin - diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_cell.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_cell.cpp new file mode 100644 index 00000000000..6f58eeda2f4 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_cell.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph/op/gru_cell.hpp" +#include +#include "test_utils/cpu_test_utils.hpp" +#include "transformations/op_conversions/gru_cell_decomposition.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using GRUCellCpuSpecificParams = typename std::tuple>; + +class GRUCellCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::GRUCellParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::GRUCellTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + return result.str(); + } + +protected: + void SetUp() { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::GRUCellParams basicParamsSet; + std::map additionalConfig; + + bool should_decompose; + size_t batch; + size_t hidden_size; + size_t input_size; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + bool linear_before_reset; + InferenceEngine::Precision netPrecision; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, linear_before_reset, netPrecision, targetDevice) = basicParamsSet; + + std::vector> inputShapes = { + {{batch, input_size}, + {batch, hidden_size}, + {3 * hidden_size, input_size}, + {3 * hidden_size, hidden_size}, + {(linear_before_reset ? 4 : 3) * hidden_size}}, + }; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]}); + std::vector WRB = {inputShapes[2], inputShapes[3], inputShapes[4]}; + auto gru_cell = ngraph::builder::makeGRU( + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), WRB, hidden_size, activations, {}, {}, clip, linear_before_reset); + ngraph::ResultVector results{std::make_shared(gru_cell->output(0))}; + + function = makeNgraphFunction(ngPrc, params, gru_cell, "gru_cell"); + } +}; + +TEST_P(GRUCellCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNCell"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; + +CPUSpecificParams cpuParams{{nc, nc}, {nc}, {"ref_any"}, "ref_any"}; + +std::vector should_decompose{false}; +std::vector batch{1, 5}; +std::vector hidden_size{1, 10}; +std::vector input_size{1, 30}; +// oneDNN supports only sigmoid-tanh +std::vector> activations = {{"sigmoid", "tanh"}}; +// oneDNN supports only zero clip +std::vector clip = {0.f}; +std::vector linear_before_reset = {true, false}; +std::vector netPrecisions = {InferenceEngine::Precision::FP32}; + +INSTANTIATE_TEST_CASE_P(smoke_GRUCellCPU, + GRUCellCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(should_decompose), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(linear_before_reset), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + GRUCellCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp new file mode 100644 index 00000000000..5efa57cb808 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/gru_sequence.cpp @@ -0,0 +1,202 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/gru_sequence.hpp" +#include "ngraph/pass/visualize_tree.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" +#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using GRUSequenceCpuSpecificParams = typename std::tuple>; + +class GRUSequenceCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::GRUSequenceParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + std::ostringstream result; + + result << LayerTestsDefinitions::GRUSequenceTest::getTestCaseName(testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + return result.str(); + } + +protected: + void SetUp() { + LayerTestsDefinitions::GRUSequenceParams basicParamsSet; + CPUSpecificParams cpuParams; + std::map additionalConfig; + + size_t seq_lenghts; + size_t batch; + size_t hidden_size; + size_t input_size = 10; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + bool linear_before_reset; + ngraph::op::RecurrentSequenceDirection direction; + InferenceEngine::Precision netPrecision; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(m_mode, seq_lenghts, batch, hidden_size, activations, clip, linear_before_reset, direction, netPrecision, targetDevice) = basicParamsSet; + + size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1; + std::vector> inputShapes = { + {{batch, seq_lenghts, input_size}, + {batch, num_directions, hidden_size}, + {batch}, + {num_directions, 3 * hidden_size, input_size}, + {num_directions, 3 * hidden_size, hidden_size}, + {num_directions, (linear_before_reset ? 4 : 3) * hidden_size}}, + }; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + m_max_seq_len = seq_lenghts; + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]}); + if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM + || m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM) { + auto seq_lengths = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[2]}).at(0); + seq_lengths->set_friendly_name("seq_lengths"); + params.push_back(seq_lengths); + } + std::vector WRB = {inputShapes[3], inputShapes[4], inputShapes[5], inputShapes[2]}; + auto gru_sequence = ngraph::builder::makeGRU(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), + WRB, + hidden_size, + activations, + {}, + {}, + clip, + linear_before_reset, + true, + direction, + m_mode); + ngraph::ResultVector results{std::make_shared(gru_sequence->output(0)), + std::make_shared(gru_sequence->output(1))}; + + function = makeNgraphFunction(ngPrc, params, gru_sequence, "gru_sequence"); + + if (m_mode != ngraph::helpers::SequenceTestsMode::PURE_SEQ) { + ngraph::pass::Manager manager; + if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + manager.register_pass(); + manager.register_pass(); + manager.run_passes(function); + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, true); + } else { + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, false); + } + } + + void GenerateInputs() { + for (const auto &input : executableNetwork.GetInputsInfo()) { + const auto &info = input.second; + auto blob = GenerateInput(*info); + if (input.first == "seq_lengths") { + blob = FuncTestUtils::createAndFillBlob(info->getTensorDesc(), m_max_seq_len, 0); + } + inputs.push_back(blob); + } + } + +private: + ngraph::helpers::SequenceTestsMode m_mode; + int64_t m_max_seq_len = 0; +}; + +TEST_P(GRUSequenceCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNSeq"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; + +CPUSpecificParams cpuParams{{ntc, nc}, {ntc, nc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, nc}, {tnc, nc}, {"ref_any"}, "ref_any"};; + +std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; +// output values increase rapidly without clip, so use only seq_lenghts = 2 +std::vector seq_lengths_zero_clip{2}; +std::vector batch{10}; +std::vector batch_size_one{1}; +std::vector hidden_size{1, 10}; +std::vector> activations = {{"sigmoid", "tanh"}}; +std::vector linear_before_reset = {true, false}; +std::vector clip{0.f}; +std::vector direction = {ngraph::op::RecurrentSequenceDirection::FORWARD}; + +std::vector netPrecisions = {InferenceEngine::Precision::FP32}; + +INSTANTIATE_TEST_CASE_P(smoke_GRUSequenceCPU, + GRUSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(linear_before_reset), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + GRUSequenceCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_GRUSequenceCPUBatchSizeOne, + GRUSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch_size_one), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(linear_before_reset), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParamsBatchSizeOne), + ::testing::ValuesIn(additionalConfig)), + GRUSequenceCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_cell.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_cell.cpp new file mode 100644 index 00000000000..4ee12f62ea9 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_cell.cpp @@ -0,0 +1,132 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph/op/lstm_cell.hpp" +#include +#include "test_utils/cpu_test_utils.hpp" +#include "transformations/op_conversions/lstm_cell_decomposition.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using LSTMCellCpuSpecificParams = typename std::tuple>; + +class LSTMCellLayerCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::LSTMCellParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + std::ostringstream result; + + result << LayerTestsDefinitions::LSTMCellTest::getTestCaseName(testing::TestParamInfo( + basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto& item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + return result.str(); + } + +protected: + void SetUp() { + LayerTestsDefinitions::LSTMCellParams basicParamsSet; + CPUSpecificParams cpuParams; + std::map additionalConfig; + + bool should_decompose; + size_t batch; + size_t hidden_size; + size_t input_size; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + InferenceEngine::Precision netPrecision; + threshold = 0.05; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, netPrecision, targetDevice) = basicParamsSet; + + std::vector> inputShapes = { + {{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size}, {4 * hidden_size, hidden_size}, {4 * hidden_size}}, + }; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1], inputShapes[2]}); + std::vector WRB = {inputShapes[3], inputShapes[4], inputShapes[5]}; + + auto lstm_cell = ngraph::builder::makeLSTM( + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), WRB, hidden_size, activations, {}, {}, clip); + + ngraph::ResultVector results{std::make_shared(lstm_cell->output(0)), + std::make_shared(lstm_cell->output(1))}; + + function = makeNgraphFunction(ngPrc, params, lstm_cell, "lstm_cell"); + } +}; + +TEST_P(LSTMCellLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNCell"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}, + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}}; + +CPUSpecificParams cpuParams{{nc, nc, nc}, {nc}, {"ref_any"}, "ref_any"}; + +std::vector should_decompose{false}; +std::vector batch{5}; +std::vector hidden_size{1, 10}; +std::vector input_size{1, 30}; +// oneDNN supports only sigmoid-tanh-tanh +std::vector> activations = {{"sigmoid", "tanh", "tanh"}}; +// oneDNN supports only zero clip +std::vector clip{0.f}; +std::vector netPrecisions = {InferenceEngine::Precision::FP32, InferenceEngine::Precision::BF16}; + +INSTANTIATE_TEST_CASE_P(smoke_LSTMCellCPU, + LSTMCellLayerCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(should_decompose), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + LSTMCellLayerCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp new file mode 100644 index 00000000000..50e9717de51 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/lstm_sequence.cpp @@ -0,0 +1,205 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/lstm_sequence.hpp" +#include "ngraph/pass/visualize_tree.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" +#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using LSTMSequenceCpuSpecificParams = typename std::tuple>; + +class LSTMSequenceCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::LSTMSequenceParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + std::ostringstream result; + + result << LayerTestsDefinitions::LSTMSequenceTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + return result.str(); + } + +protected: + void SetUp() { + LayerTestsDefinitions::LSTMSequenceParams basicParamsSet; + CPUSpecificParams cpuParams; + std::map additionalConfig; + + size_t seq_lenghts; + size_t batch; + size_t hidden_size; + size_t input_size; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + ngraph::op::RecurrentSequenceDirection direction; + InferenceEngine::Precision netPrecision; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(m_mode, seq_lenghts, batch, hidden_size, input_size, activations, clip, direction, netPrecision, targetDevice) = basicParamsSet; + + size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1; + m_max_seq_len = seq_lenghts; + std::vector> inputShapes = { + {{batch, seq_lenghts, input_size}, + {batch, num_directions, hidden_size}, + {batch, num_directions, hidden_size}, + {batch}, + {num_directions, 4 * hidden_size, input_size}, + {num_directions, 4 * hidden_size, hidden_size}, + {num_directions, 4 * hidden_size}}, + }; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1], inputShapes[2]}); + if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM + || m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM) { + auto seq_lengths = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[3]}).at(0); + seq_lengths->set_friendly_name("seq_lengths"); + params.push_back(seq_lengths); + } + std::vector WRB = {inputShapes[4], inputShapes[5], inputShapes[6], inputShapes[3]}; + auto lstm_sequence = ngraph::builder::makeLSTM(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), + WRB, + hidden_size, + activations, + {}, + {}, + clip, + true, + direction, + m_mode); + ngraph::ResultVector results{std::make_shared(lstm_sequence->output(0)), + std::make_shared(lstm_sequence->output(1)), + std::make_shared(lstm_sequence->output(2))}; + + function = makeNgraphFunction(ngPrc, params, lstm_sequence, "lstm_sequence"); + + if (m_mode != ngraph::helpers::SequenceTestsMode::PURE_SEQ) { + ngraph::pass::Manager manager; + if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + manager.register_pass(); + manager.register_pass(); + manager.run_passes(function); + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, true); + } else { + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, false); + } + } + + void GenerateInputs() { + for (const auto &input : executableNetwork.GetInputsInfo()) { + const auto &info = input.second; + auto blob = GenerateInput(*info); + if (input.first == "seq_lengths") { + blob = FuncTestUtils::createAndFillBlob(info->getTensorDesc(), m_max_seq_len, 0); + } + + inputs.push_back(blob); + } + } + +private: + ngraph::helpers::SequenceTestsMode m_mode; + int64_t m_max_seq_len = 0; +}; + +TEST_P(LSTMSequenceCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNSeq"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; + +CPUSpecificParams cpuParams{{ntc, nc, nc}, {ntc, nc, nc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, nc, nc}, {tnc, nc, nc}, {"ref_any"}, "ref_any"}; + +std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; +std::vector seq_lengths_zero_clip{2}; +std::vector batch_size_one{1}; +std::vector batch{10}; +std::vector hidden_size{1, 10}; +std::vector input_size{10}; +// oneDNN supports only sigmoid-tanh-tanh +std::vector> activations = {{"sigmoid", "tanh", "tanh"}}; +// oneDNN supports only zero clip +std::vector clip{0.f}; +std::vector direction = {ngraph::op::RecurrentSequenceDirection::FORWARD}; +std::vector netPrecisions = {InferenceEngine::Precision::FP32}; + +INSTANTIATE_TEST_CASE_P(smoke_LSTMSequenceCPU, + LSTMSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + LSTMSequenceCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_LSTMSequenceCPUbatchSizeOne, + LSTMSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch_size_one), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParamsBatchSizeOne), + ::testing::ValuesIn(additionalConfig)), + LSTMSequenceCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_cell.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_cell.cpp new file mode 100644 index 00000000000..381bdfecf36 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_cell.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph/op/rnn_cell.hpp" +#include +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using RNNCellCpuSpecificParams = typename std::tuple>; + +class RNNCellCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::RNNCellParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::RNNCellTest::getTestCaseName( + testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + + return result.str(); + } + +protected: + void SetUp() { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::RNNCellParams basicParamsSet; + std::map additionalConfig; + + bool should_decompose; + size_t batch; + size_t hidden_size; + size_t input_size; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + InferenceEngine::Precision netPrecision; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, netPrecision, targetDevice) = basicParamsSet; + + std::vector> inputShapes = {{batch, input_size}, {batch, hidden_size}, + {hidden_size, input_size}, {hidden_size, hidden_size}, {hidden_size}}; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]}); + std::vector WRB = {inputShapes[2], inputShapes[3], inputShapes[4]}; + auto rnn_cell = ngraph::builder::makeRNN( + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), + WRB, hidden_size, activations, {}, {}, clip); + ngraph::ResultVector results{std::make_shared(rnn_cell)}; + function = makeNgraphFunction(ngPrc, params, rnn_cell, "rnn_cell"); + } +}; + +TEST_P(RNNCellCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNCell"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; + +CPUSpecificParams cpuParams{{nc, nc}, {nc}, {"ref_any"}, "ref_any"}; +std::vector should_decompose{false}; +std::vector batch{1, 5}; +std::vector hidden_size{1, 10}; +std::vector input_size{1, 30}; +std::vector> activations = {{"relu"}, {"sigmoid"}, {"tanh"}}; +// oneDNN supports only zero clip +std::vector clip = {0.f}; +std::vector netPrecisions = {InferenceEngine::Precision::FP32}; + +INSTANTIATE_TEST_CASE_P(smoke_RNNCellCPU, + RNNCellCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(should_decompose), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + RNNCellCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp new file mode 100644 index 00000000000..671539db351 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/rnn_sequence.cpp @@ -0,0 +1,202 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/rnn_sequence.hpp" +#include "ngraph/pass/visualize_tree.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" +#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using RNNSequenceCpuSpecificParams = typename std::tuple>; + +class RNNSequenceCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, + public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + CPUSpecificParams cpuParams; + LayerTestsDefinitions::RNNSequenceParams basicParamsSet; + std::map additionalConfig; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = obj.param; + std::ostringstream result; + + result << LayerTestsDefinitions::RNNSequenceTest::getTestCaseName(testing::TestParamInfo(basicParamsSet, 0)); + result << CPUTestsBase::getTestCaseName(cpuParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + return result.str(); + } + +protected: + void SetUp() { + LayerTestsDefinitions::RNNSequenceParams basicParamsSet; + CPUSpecificParams cpuParams; + std::map additionalConfig; + + size_t seq_lenghts; + size_t batch; + size_t hidden_size; + size_t input_size; + std::vector activations; + std::vector activations_alpha; + std::vector activations_beta; + float clip; + ngraph::op::RecurrentSequenceDirection direction; + InferenceEngine::Precision netPrecision; + + std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam(); + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(m_mode, seq_lenghts, batch, hidden_size, input_size, activations, clip, direction, netPrecision, targetDevice) = basicParamsSet; + + size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1; + std::vector> inputShapes = { + {{batch, seq_lenghts, input_size}, + {batch, num_directions, hidden_size}, + {batch}, + {num_directions, hidden_size, input_size}, + {num_directions, hidden_size, hidden_size}, + {num_directions, hidden_size}}, + }; + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + inPrc = outPrc = Precision::BF16; + } else { + inPrc = outPrc = netPrecision; + } + + selectedType += "_"; + selectedType += outPrc.name(); + + m_max_seq_len = seq_lenghts; + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32); + auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]}); + if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM + || m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM) { + auto seq_lengths = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[2]}).at(0); + seq_lengths->set_friendly_name("seq_lengths"); + params.push_back(seq_lengths); + } + std::vector WRB = {inputShapes[3], inputShapes[4], inputShapes[5], inputShapes[2]}; + auto rnn_sequence = ngraph::builder::makeRNN(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)), + WRB, + hidden_size, + activations, + {}, + {}, + clip, + true, + direction, + m_mode); + ngraph::ResultVector results{std::make_shared(rnn_sequence->output(0)), + std::make_shared(rnn_sequence->output(1))}; + function = makeNgraphFunction(ngPrc, params, rnn_sequence, "rnn_sequence"); + if (m_mode != ngraph::helpers::SequenceTestsMode::PURE_SEQ) { + ngraph::pass::Manager manager; + if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + manager.register_pass(); + manager.register_pass(); + manager.run_passes(function); + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, true); + } else { + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, false); + } + } + + void GenerateInputs() { + for (const auto &input : executableNetwork.GetInputsInfo()) { + const auto &info = input.second; + auto blob = GenerateInput(*info); + if (input.first == "seq_lengths") { + blob = FuncTestUtils::createAndFillBlob(info->getTensorDesc(), m_max_seq_len, 0); + } + + inputs.push_back(blob); + } + } + +private: + ngraph::helpers::SequenceTestsMode m_mode; + int64_t m_max_seq_len = 0; +}; + +TEST_P(RNNSequenceCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); + CheckPluginRelatedResults(executableNetwork, "RNNSeq"); +} + +namespace { +/* CPU PARAMS */ +std::vector> additionalConfig + = {{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}}; + +CPUSpecificParams cpuParams{{ntc, nc}, {ntc, nc}, {"ref_any"}, "ref_any"}; +CPUSpecificParams cpuParamsBatchSizeOne{{tnc, nc}, {tnc, nc}, {"ref_any"}, "ref_any"}; + +std::vector mode{ngraph::helpers::SequenceTestsMode::PURE_SEQ}; +// output values increase rapidly without clip, so use only seq_lenghts = 2 +std::vector seq_lengths_zero_clip{2}; +std::vector batch{10}; +std::vector batch_size_one{1}; +std::vector hidden_size{10}; +// std::vector hidden_size{1, 10}; +std::vector input_size{10}; +std::vector> activations = {{"relu"}, {"sigmoid"}, {"tanh"}}; +// oneDNN supports only zero clip +std::vector clip{0.f}; + +std::vector direction{ngraph::op::RecurrentSequenceDirection::FORWARD}; + +std::vector netPrecisions = {InferenceEngine::Precision::FP32}; + +INSTANTIATE_TEST_CASE_P(smoke_RNNSequenceCPU, + RNNSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParams), + ::testing::ValuesIn(additionalConfig)), + RNNSequenceCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_RNNSequenceCPUBatchSizeOne, + RNNSequenceCPUTest, + ::testing::Combine(::testing::Combine(::testing::ValuesIn(mode), + ::testing::ValuesIn(seq_lengths_zero_clip), + ::testing::ValuesIn(batch_size_one), + ::testing::ValuesIn(hidden_size), + ::testing::ValuesIn(input_size), + ::testing::ValuesIn(activations), + ::testing::ValuesIn(clip), + ::testing::ValuesIn(direction), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(cpuParamsBatchSizeOne), + ::testing::ValuesIn(additionalConfig)), + RNNSequenceCPUTest::getTestCaseName); +} // namespace +} // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp index 3bd91fbb639..1f3a271f0a1 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp @@ -8,16 +8,29 @@ namespace CPUTestUtils { const char *CPUTestsBase::cpu_fmt2str(cpu_memory_format_t v) { - if (v == nchw) return "nchw"; - if (v == nChw8c) return "nChw8c"; - if (v == nChw16c) return "nChw16c"; - if (v == nhwc) return "nhwc"; - if (v == ncdhw) return "ncdhw"; - if (v == nCdhw8c) return "nCdhw8c"; - if (v == nCdhw16c) return "nCdhw16c"; - if (v == ndhwc) return "ndhwc"; - if (v == nc) return "nc"; - if (v == x) return "x"; +#define CASE(_fmt) do { \ + if (v == _fmt) return #_fmt; \ +} while (0) + CASE(undef); + CASE(nchw); + CASE(nChw8c); + CASE(nChw16c); + CASE(nhwc); + CASE(ncdhw); + CASE(nCdhw8c); + CASE(nCdhw16c); + CASE(ndhwc); + CASE(nc); + CASE(x); + CASE(tnc); + CASE(ntc); + CASE(ldnc); + CASE(ldigo); + CASE(ldgoi); + CASE(ldio); + CASE(ldoi); + CASE(ldgo); +#undef CASE assert(!"unknown fmt"); return "undef"; } @@ -39,6 +52,10 @@ cpu_memory_format_t CPUTestsBase::cpu_str2fmt(const char *str) { CASE(acdeb); CASE(aBcde8b); CASE(aBcde16b); + CASE(abc); + CASE(bac); + CASE(abdc); + CASE(abdec); CASE(nchw); CASE(nChw8c); CASE(nChw16c); @@ -49,6 +66,14 @@ cpu_memory_format_t CPUTestsBase::cpu_str2fmt(const char *str) { CASE(ndhwc); CASE(nc); CASE(x); + CASE(tnc); + CASE(ntc); + CASE(ldnc); + CASE(ldigo); + CASE(ldgoi); + CASE(ldio); + CASE(ldoi); + CASE(ldgo); #undef CASE assert(!"unknown memory format"); return undef; @@ -120,18 +145,38 @@ void CPUTestsBase::CheckPluginRelatedResults(InferenceEngine::ExecutableNetwork auto shape = parentNode->get_output_tensor(0).get_shape(); auto actualInputMemoryFormat = getExecValueOutputsLayout(parentNode); - if (!should_be_skipped(shape, inFmts[i])) + if (!should_be_skipped(shape, inFmts[i])) { ASSERT_EQ(inFmts[i], cpu_str2fmt(actualInputMemoryFormat.c_str())); + } } } - for (int i = 0; i < outFmts.size(); i++) { + + /* actual output formats are represented as a single string, for example 'fmt1' or 'fmt1, fmt2, fmt3' + * convert it to the list of formats */ + auto getActualOutputMemoryFormats = [] (const std::string& fmtStr) -> std::vector { + std::vector result; + std::stringstream ss(fmtStr); + std::string str; + while (std::getline(ss, str, ',')) { + result.push_back(str); + } + return result; + }; + + auto actualOutputMemoryFormats = getActualOutputMemoryFormats(getExecValueOutputsLayout(node)); + + for (size_t i = 0; i < outFmts.size(); i++) { const auto actualOutputMemoryFormat = getExecValue(ExecGraphInfoSerialization::OUTPUT_LAYOUTS); const auto shape = node->get_output_shape(i); - if (!should_be_skipped(shape, outFmts[i])) - ASSERT_EQ(outFmts[i], cpu_str2fmt(actualOutputMemoryFormat.c_str())); + if (should_be_skipped(shape, outFmts[i])) + continue; + + ASSERT_EQ(outFmts[i], cpu_str2fmt(actualOutputMemoryFormats[i].c_str())); } + auto primType = getExecValue(ExecGraphInfoSerialization::IMPL_TYPE); + ASSERT_EQ(selectedType, primType); } } @@ -197,8 +242,11 @@ std::shared_ptr CPUTestsBase::makeNgraphFunction(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode, std::string name) const { auto newLastNode = modifyGraph(ngPrc, params, lastNode); + ngraph::ResultVector results; + + for (int i = 0; i < newLastNode->get_output_size(); i++) + results.push_back(std::make_shared(newLastNode->output(i))); - ngraph::ResultVector results = {std::make_shared(newLastNode)}; return std::make_shared(results, params, name); } diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp index 09b90ea2434..3797c167feb 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp @@ -24,6 +24,11 @@ namespace CPUTestUtils { acdeb, aBcde8b, aBcde16b, + // RNN layouts + abc, + bac, + abdc, + abdec, x = a, nc = ab, @@ -34,7 +39,41 @@ namespace CPUTestUtils { ncdhw = abcde, nCdhw8c = aBcde8b, nCdhw16c = aBcde16b, - ndhwc = acdeb + ndhwc = acdeb, + // RNN layouts + tnc = abc, + /// 3D RNN data tensor in the format (batch, seq_length, input channels). + ntc = bac, + /// 4D RNN states tensor in the format (num_layers, num_directions, + /// batch, state channels). + ldnc = abcd, + /// 5D RNN weights tensor in the format (num_layers, num_directions, + /// input_channels, num_gates, output_channels). + /// + /// - For LSTM cells, the gates order is input, forget, candidate + /// and output gate. + /// - For GRU cells, the gates order is update, reset and output gate. + ldigo = abcde, + /// 5D RNN weights tensor in the format (num_layers, num_directions, + /// num_gates, output_channels, input_channels). + /// + /// - For LSTM cells, the gates order is input, forget, candidate + /// and output gate. + /// - For GRU cells, the gates order is update, reset and output gate. + ldgoi = abdec, + /// 4D LSTM projection tensor in the format (num_layers, num_directions, + /// num_channels_in_hidden_state, num_channels_in_recurrent_projection). + ldio = abcd, + /// 4D LSTM projection tensor in the format (num_layers, num_directions, + /// num_channels_in_recurrent_projection, num_channels_in_hidden_state). + ldoi = abdc, + /// 4D RNN bias tensor in the format (num_layers, num_directions, + /// num_gates, output_channels). + /// + /// - For LSTM cells, the gates order is input, forget, candidate + /// and output gate. + /// - For GRU cells, the gates order is update, reset and output gate. + ldgo = abcd, } cpu_memory_format_t; using CPUSpecificParams = std::tuple< diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/lstm_cell.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/lstm_cell.hpp index f07b1d51bf0..df6995174f9 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/lstm_cell.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/lstm_cell.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -26,7 +27,7 @@ using LSTMCellParams = typename std::tuple< std::string>; // Device name class LSTMCellTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public LayerTestsUtils::LayerTestsCommon { public: static std::string getTestCaseName(const testing::TestParamInfo &obj); diff --git a/inference-engine/thirdparty/mkl-dnn b/inference-engine/thirdparty/mkl-dnn index 0813c00df75..462982a2f92 160000 --- a/inference-engine/thirdparty/mkl-dnn +++ b/inference-engine/thirdparty/mkl-dnn @@ -1 +1 @@ -Subproject commit 0813c00df7558bc9b858d3a73c725bab2ce1b1eb +Subproject commit 462982a2f9272ad26473ec13d983b10dbd193cd3