From cce3375d556d23716feec82b734884caa0d03a1a Mon Sep 17 00:00:00 2001 From: Maxim Andronov Date: Thu, 25 Feb 2021 23:06:19 +0300 Subject: [PATCH] Revert "[CPU] Changed output blobs creation used output info (#3796)" (#4492) This reverts commit a15246e1d0d592ac7c2634e20ac88fb837c8305e. --- .../behavior/preprocessing.cpp | 4 +- .../mkldnn_plugin/mkldnn_extension_utils.cpp | 25 --- .../mkldnn_plugin/mkldnn_extension_utils.h | 2 - .../mkldnn_plugin/mkldnn_infer_request.cpp | 76 ++++----- .../src/mkldnn_plugin/mkldnn_plugin.cpp | 50 ++---- .../nodes/common/cpu_convert.cpp | 14 +- .../behavior/preprocessing.cpp | 5 +- .../tests/unit/cpu/cpu_convert.cpp | 146 ------------------ 8 files changed, 58 insertions(+), 264 deletions(-) delete mode 100644 inference-engine/tests/unit/cpu/cpu_convert.cpp diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp index 37a65e52484..1897979f5b5 100644 --- a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp +++ b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp @@ -19,7 +19,7 @@ const std::vector> configs = { {} }; -INSTANTIATE_TEST_CASE_P(smoke_PreprocessingPrecisionConvertTestsViaSetInput, PreprocessingPrecisionConvertTest, +INSTANTIATE_TEST_CASE_P(PreprocessingPrecisionConvertTestsViaSetInput, PreprocessingPrecisionConvertTest, ::testing::Combine( ::testing::ValuesIn(inputPrecisions), ::testing::Values(4), // Number of input tensor channels @@ -28,7 +28,7 @@ INSTANTIATE_TEST_CASE_P(smoke_PreprocessingPrecisionConvertTestsViaSetInput, Pre ::testing::ValuesIn(configs)), PreprocessingPrecisionConvertTest::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_PreprocessingPrecisionConvertTestsViaGetBlob, PreprocessingPrecisionConvertTest, +INSTANTIATE_TEST_CASE_P(PreprocessingPrecisionConvertTestsViaGetBlob, PreprocessingPrecisionConvertTest, ::testing::Combine( ::testing::ValuesIn(inputPrecisions), ::testing::Values(4), // Number of input tensor channels (blob_copy only supports 4d and 5d tensors) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.cpp index a4b449fb067..797e49834ac 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.cpp @@ -209,28 +209,3 @@ InferenceEngine::Precision MKLDNNExtensionUtils::getMaxPrecision(std::vector(blkDims.size()) - 2; i >=0; i--) { - if (strides[i] != strides[i + 1] * blkDims[i + 1]) - return false; - } - - return true; -} - -bool MKLDNNExtensionUtils::isDefaultTensor(const InferenceEngine::TensorDesc &desc) { - auto blkDesc = desc.getBlockingDesc(); - return isDenseTensor(desc) && blkDesc.getOffsetPadding() == 0 && - std::all_of(blkDesc.getOffsetPaddingToData().begin(), blkDesc.getOffsetPaddingToData().end(), [](size_t i){ return i == 0; }); -} diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.h b/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.h index 4ea78ea0a99..26fc09c92de 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_extension_utils.h @@ -79,8 +79,6 @@ public: static bool initTensorsAreEqual(const InferenceEngine::TensorDesc &desc1, const InferenceEngine::TensorDesc &desc2); static std::string getReorderArgs(const InferenceEngine::TensorDesc &parentDesc, const InferenceEngine::TensorDesc &childDesc); static InferenceEngine::Precision getMaxPrecision(std::vector precisions); - static bool isDenseTensor(const InferenceEngine::TensorDesc &desc); - static bool isDefaultTensor(const InferenceEngine::TensorDesc &desc); }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp index 989f129b9e9..6e2fb790e8f 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp @@ -103,12 +103,18 @@ void MKLDNNPlugin::MKLDNNInferRequest::PushInputData() { switch (inPrec) { // these precisions are supported by mkldnn, so we push the blob directly - case InferenceEngine::Precision::U8: case InferenceEngine::Precision::I8: case InferenceEngine::Precision::I32: case InferenceEngine::Precision::BF16: - case InferenceEngine::Precision::FP32: + case InferenceEngine::Precision::FP32: { + break; + } + // these precisions are supported by mkldnn, so we push the blob directly + // BUT if a mean image exists, we convert the blob and send FP32 + case InferenceEngine::Precision::U8: case InferenceEngine::Precision::BOOL: { + if (graph->hasMeanImageFor(input.first)) + inPrec = InferenceEngine::Precision::FP32; break; } // these precisions are unsupported by mkldnn, so we convert the blob and send I32 @@ -119,17 +125,9 @@ void MKLDNNPlugin::MKLDNNInferRequest::PushInputData() { inPrec = InferenceEngine::Precision::I32; break; } - case InferenceEngine::Precision::FP16: { - inPrec = InferenceEngine::Precision::FP32; - break; - } default: THROW_IE_EXCEPTION << "Unsupported input precision " << input.second->getTensorDesc().getPrecision(); } - - if (graph->hasMeanImageFor(input.first)) - inPrec = InferenceEngine::Precision::FP32; - pushInput(input.first, input.second, inPrec); } } @@ -237,21 +235,25 @@ InferenceEngine::Blob::Ptr MKLDNNPlugin::MKLDNNInferRequest::GetBlob(const std:: return data; } + InferenceEngine::TensorDesc desc = blobs[name]->getTensorDesc(); + InferenceEngine::Precision originPrecision = blobs[name]->getTensorDesc().getPrecision(); if (_networkInputs.find(name) != _networkInputs.end()) { - InferenceEngine::TensorDesc desc = _networkInputs[name]->getTensorDesc(); - InferenceEngine::Precision originPrecision = blobs[name]->getTensorDesc().getPrecision(); - _inputs[name] = make_blob_with_precision(desc); - _inputs[name]->allocate(); - if (desc.getPrecision() == originPrecision && - graph->_meanImages.find(name) == graph->_meanImages.end() && !graph->getProperty().batchLimit) { - externalPtr[name] = _inputs[name]->buffer(); - } - data = _inputs[name]; - checkBlob(data, name, true); - return data; - } else { - THROW_IE_EXCEPTION << "Blob with name: " << name << " exists in MKLDNN graph, but absents in network inputs"; + InferenceEngine::Layout l = _networkInputs[name]->getLayout(); + InferenceEngine::Precision p = _networkInputs[name]->getPrecision(); + InferenceEngine::SizeVector dims = _networkInputs[name]->getTensorDesc().getDims(); + + desc = InferenceEngine::TensorDesc(p, dims, l); } + + _inputs[name] = make_blob_with_precision(desc); + _inputs[name]->allocate(); + if (desc.getPrecision() == originPrecision && + graph->_meanImages.find(name) == graph->_meanImages.end() && !graph->getProperty().batchLimit) { + externalPtr[name] = _inputs[name]->buffer(); + } + data = _inputs[name]; + checkBlob(data, name, true); + return data; } blobs.clear(); graph->getOutputBlobs(blobs); @@ -262,19 +264,23 @@ InferenceEngine::Blob::Ptr MKLDNNPlugin::MKLDNNInferRequest::GetBlob(const std:: return data; } - if (_networkOutputs.find(name) != _networkOutputs.end()) { - InferenceEngine::TensorDesc desc = _networkOutputs[name]->getTensorDesc(); - _outputs[name] = make_blob_with_precision(desc); - _outputs[name]->allocate(); - if (desc.getPrecision() == InferenceEngine::Precision::FP32 && !graph->getProperty().batchLimit) { - externalPtr[name] = _outputs[name]->buffer(); - } - data = _outputs[name]; - checkBlob(data, name, false); - return data; - } else { - THROW_IE_EXCEPTION << "Blob with name: " << name << " exists in MKLDNN graph, but absents in network outputs"; + InferenceEngine::TensorDesc desc = blobs[name]->getTensorDesc(); + + // WA: need to avoid exception thrown when we compare blocking desc in SetBlob + // in situation if we push output blobs as inputs for next network (in Hetero plugin) + // it may be that output tensor desc will be different from real input tensor desc for next network + // because the optimal descriptor was chosen (e.g. inPlace case for Split node) + auto currBlockDesc = InferenceEngine::BlockingDesc(desc.getBlockingDesc().getBlockDims(), desc.getBlockingDesc().getOrder()); + desc = InferenceEngine::TensorDesc(desc.getPrecision(), desc.getDims(), currBlockDesc); + + _outputs[name] = make_blob_with_precision(desc); + _outputs[name]->allocate(); + if (desc.getPrecision() == InferenceEngine::Precision::FP32 && !graph->getProperty().batchLimit) { + externalPtr[name] = _outputs[name]->buffer(); } + data = _outputs[name]; + checkBlob(data, name, false); + return data; } THROW_IE_EXCEPTION << "Cannot find blob with name: " << name; } diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index cbb008f7d34..75a0841d8f6 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -7,7 +7,6 @@ #include "mkldnn_extension_mngr.h" #include "mkldnn_weights_cache.hpp" #include "mkldnn_itt.h" -#include "mkldnn_extension_utils.h" #include #include @@ -330,48 +329,23 @@ InferenceEngine::ExecutableNetworkInternal::Ptr Engine::LoadExeNetworkImpl(const InferenceEngine::CNNNetwork &network, const std::map &config) { OV_ITT_SCOPED_TASK(itt::domains::MKLDNNPlugin, "Engine::LoadExeNetworkImpl"); - static const std::vector supportedInOutPrec = { - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U64, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::BF16, - InferenceEngine::Precision::BOOL - }; - // verification of supported input InferenceEngine::InputsDataMap _networkInputs = network.getInputsInfo(); - for (const auto &in : _networkInputs) { - auto input_precision = in.second->getPrecision(); - if (std::find(supportedInOutPrec.begin(), supportedInOutPrec.end(), input_precision) == supportedInOutPrec.end()) { + for (const auto &ii : _networkInputs) { + auto input_precision = ii.second->getPrecision(); + if (input_precision != InferenceEngine::Precision::FP32 && + input_precision != InferenceEngine::Precision::I32 && + input_precision != InferenceEngine::Precision::U16 && + input_precision != InferenceEngine::Precision::I16 && + input_precision != InferenceEngine::Precision::I8 && + input_precision != InferenceEngine::Precision::U8 && + input_precision != InferenceEngine::Precision::BF16 && + input_precision != InferenceEngine::Precision::BOOL && + input_precision != InferenceEngine::Precision::I64 && + input_precision != InferenceEngine::Precision::U64) { THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str << "Input image format " << input_precision << " is not supported yet..."; } - - if (!MKLDNNExtensionUtils::isDefaultTensor(in.second->getTensorDesc())) { - THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str - << "CPU plug-in doesn't support network input which are not dense or have non zero offsets. Input name: '" << in.first << "'"; - } - } - - // verification of supported output - InferenceEngine::OutputsDataMap _networkOutputs = network.getOutputsInfo(); - for (const auto &out : _networkOutputs) { - auto output_precision = out.second->getPrecision(); - if (std::find(supportedInOutPrec.begin(), supportedInOutPrec.end(), output_precision) == supportedInOutPrec.end()) { - THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str - << "CPU plug-in doesn't support network output with " << output_precision << " precision"; - } - - if (!MKLDNNExtensionUtils::isDefaultTensor(out.second->getTensorDesc())) { - THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str - << "CPU plug-in doesn't support network output which are not dense or have non zero offsets. Output name: '" << out.first << "'"; - } } // TODO: handle input precision differently - per input and not one per network... diff --git a/inference-engine/src/mkldnn_plugin/nodes/common/cpu_convert.cpp b/inference-engine/src/mkldnn_plugin/nodes/common/cpu_convert.cpp index c5d8a4fb46b..3ad00c96e7e 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/common/cpu_convert.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/common/cpu_convert.cpp @@ -9,7 +9,6 @@ #include #include #include -#include using namespace InferenceEngine; @@ -39,11 +38,6 @@ struct PrecisionInfo { using value_type = MKLDNNPlugin::bfloat16_t; }; -template <> -struct PrecisionInfo { - using value_type = ngraph::float16; -}; - struct ConvertContext { const void *srcPtr; void *dstPtr; @@ -109,13 +103,7 @@ void cpu_convert(const void *srcPtr, void *dstPtr, Precision srcPrc, Precision d MKLDNN_CVT(BF16, I64), MKLDNN_CVT(BF16, FP32), MKLDNN_CVT(BF16, BOOL), MKLDNN_CVT(BOOL, U8), MKLDNN_CVT(BOOL, I8), MKLDNN_CVT(BOOL, U16), MKLDNN_CVT(BOOL, I16), MKLDNN_CVT(BOOL, I32), MKLDNN_CVT(BOOL, U64), - MKLDNN_CVT(BOOL, I64), MKLDNN_CVT(BOOL, FP32), MKLDNN_CVT(BOOL, BF16), - MKLDNN_CVT(U8, FP16), MKLDNN_CVT(I8, FP16), MKLDNN_CVT(U16, FP16), - MKLDNN_CVT(I16, FP16), MKLDNN_CVT(I32, FP16), MKLDNN_CVT(U64, FP16), - MKLDNN_CVT(I64, FP16), MKLDNN_CVT(FP32, FP16), MKLDNN_CVT(BOOL, FP16), - MKLDNN_CVT(FP16, U8), MKLDNN_CVT(FP16, I8), MKLDNN_CVT(FP16, U16), - MKLDNN_CVT(FP16, I16), MKLDNN_CVT(FP16, I32), MKLDNN_CVT(FP16, U64), - MKLDNN_CVT(FP16, I64), MKLDNN_CVT(FP16, FP32), MKLDNN_CVT(FP16, BOOL)); + MKLDNN_CVT(BOOL, I64), MKLDNN_CVT(BOOL, FP32), MKLDNN_CVT(BOOL, BF16)); if (!ctx.converted) THROW_IE_EXCEPTION << "cpu_convert can't convert from: " << srcPrc << " precision to: " << dstPrc; diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp index cd4536340de..a0106b02350 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp @@ -12,7 +12,6 @@ namespace { const std::vector inputPrecisions = { InferenceEngine::Precision::U16, - InferenceEngine::Precision::FP16, InferenceEngine::Precision::FP32 }; @@ -20,7 +19,7 @@ const std::vector> configs = { {} }; -INSTANTIATE_TEST_CASE_P(smoke_BehaviourPreprocessingTestsViaSetInput, PreprocessingPrecisionConvertTest, +INSTANTIATE_TEST_CASE_P(BehaviourPreprocessingTestsViaSetInput, PreprocessingPrecisionConvertTest, ::testing::Combine( ::testing::ValuesIn(inputPrecisions), ::testing::Values(1, 2, 3, 4, 5), // Number of input tensor channels @@ -29,7 +28,7 @@ INSTANTIATE_TEST_CASE_P(smoke_BehaviourPreprocessingTestsViaSetInput, Preprocess ::testing::ValuesIn(configs)), PreprocessingPrecisionConvertTest::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_BehaviourPreprocessingTestsViaGetBlob, PreprocessingPrecisionConvertTest, +INSTANTIATE_TEST_CASE_P(BehaviourPreprocessingTestsViaGetBlob, PreprocessingPrecisionConvertTest, ::testing::Combine( ::testing::ValuesIn(inputPrecisions), ::testing::Values(4, 5), // Number of input tensor channels (blob_copy only supports 4d and 5d tensors) diff --git a/inference-engine/tests/unit/cpu/cpu_convert.cpp b/inference-engine/tests/unit/cpu/cpu_convert.cpp deleted file mode 100644 index 8797cca02f5..00000000000 --- a/inference-engine/tests/unit/cpu/cpu_convert.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include "nodes/common/cpu_convert.h" - -using namespace InferenceEngine; -using namespace ngraph; - -using cpuConvertTestParamsSet = std::tuple; // target precision - -class CpuConvertTest : virtual public ::testing::Test, public testing::WithParamInterface { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - Precision inputPrecision, targetPrecision; - std::tie(inputPrecision, targetPrecision) = obj.param; - - std::ostringstream result; - - result << "InputPrecision=" << inputPrecision << "_"; - result << "TargetPrecision=" << targetPrecision; - - return result.str(); - } - -protected: - void SetUp() override { - const size_t size = 100; - Precision inputPrecision, targetPrecision; - std::tie(inputPrecision, targetPrecision) = this->GetParam(); - - std::vector srcData(size * inputPrecision.size()); - std::vector dstData(size * targetPrecision.size()); - std::vector refData(size * targetPrecision.size()); - fillBuffer(inputPrecision, size, srcData.data()); - fillBuffer(targetPrecision, size, refData.data()); - - cpu_convert(srcData.data(), dstData.data(), inputPrecision, targetPrecision, size); - - ASSERT_TRUE(compare(targetPrecision, size, dstData.data(), refData.data())); - } - -private: - template - void fill(const size_t size, void *ptr) { - Type *castPtr = reinterpret_cast(ptr); - for (size_t i = 0; i < size; i++) - castPtr[i] = static_cast(i); - } - - void fillBuffer(Precision precision, const size_t size, void *ptr) { - switch (precision) { - case Precision::U8: - fill(size, ptr); - break; - case Precision::I8: - fill(size, ptr); - break; - case Precision::U16: - fill(size, ptr); - break; - case Precision::I16: - fill(size, ptr); - break; - case Precision::I32: - fill(size, ptr); - break; - case Precision::U64: - fill(size, ptr); - break; - case Precision::I64: - fill(size, ptr); - break; - case Precision::FP16: - fill(size, ptr); - break; - case Precision::FP32: - fill(size, ptr); - break; - default: - std::string error = "Can't fill buffer with " + std::string(precision.name()) + " precision"; - throw std::runtime_error(error); - } - } - - template - bool compare(const size_t size, void *ptr1, void *ptr2) { - Type *castPtr1 = reinterpret_cast(ptr1); - Type *castPtr2 = reinterpret_cast(ptr2); - for (size_t i = 0; i < size; i++) { - if (abs(castPtr1[i] - castPtr2[i]) > static_cast(0.001)) - return false; - } - return true; - } - - bool compare(Precision precision, const size_t size, void *ptr1, void *ptr2) { - switch (precision) { - case Precision::U8: - return compare(size, ptr1, ptr2); - case Precision::I8: - return compare(size, ptr1, ptr2); - case Precision::U16: - return compare(size, ptr1, ptr2); - case Precision::I16: - return compare(size, ptr1, ptr2); - case Precision::I32: - return compare(size, ptr1, ptr2); - case Precision::U64: - return compare(size, ptr1, ptr2); - case Precision::I64: - return compare(size, ptr1, ptr2); - case Precision::FP16: - return compare(size, ptr1, ptr2); - case Precision::FP32: - return compare(size, ptr1, ptr2); - default: - std::string error = "Can't compare buffer with " + std::string(precision.name()) + " precision"; - throw std::runtime_error(error); - } - return true; - } -}; - -TEST_P(CpuConvertTest, CompareWithRefs) {} - -const std::vector precisions = { - Precision::U8, - Precision::I8, - Precision::U16, - Precision::I16, - Precision::I32, - Precision::U64, - Precision::I64, - Precision::FP32, - Precision::FP16 -}; - -INSTANTIATE_TEST_CASE_P(smoke_Check, CpuConvertTest, - ::testing::Combine( - ::testing::ValuesIn(precisions), - ::testing::ValuesIn(precisions)), CpuConvertTest::getTestCaseName);