Revert "[CPU] Changed output blobs creation used output info (#3796)" (#4492)

This reverts commit a15246e1d0.
This commit is contained in:
Maxim Andronov 2021-02-25 23:06:19 +03:00 committed by GitHub
parent 1458ba392e
commit cce3375d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 264 deletions

View File

@ -19,7 +19,7 @@ const std::vector<std::map<std::string, std::string>> 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)

View File

@ -209,28 +209,3 @@ InferenceEngine::Precision MKLDNNExtensionUtils::getMaxPrecision(std::vector<Inf
return InferenceEngine::Precision::UNSPECIFIED;
}
bool MKLDNNExtensionUtils::isDenseTensor(const InferenceEngine::TensorDesc &desc) {
if (desc.getLayout() == InferenceEngine::Layout::SCALAR)
return true;
auto blkDesc = desc.getBlockingDesc();
auto blkDims = blkDesc.getBlockDims();
auto strides = blkDesc.getStrides();
if (blkDims.size() != desc.getDims().size() || strides[blkDims.size() - 1] != 1)
return false;
for (int i = static_cast<int>(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; });
}

View File

@ -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<InferenceEngine::Precision> precisions);
static bool isDenseTensor(const InferenceEngine::TensorDesc &desc);
static bool isDefaultTensor(const InferenceEngine::TensorDesc &desc);
};
} // namespace MKLDNNPlugin

View File

@ -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;
}

View File

@ -7,7 +7,6 @@
#include "mkldnn_extension_mngr.h"
#include "mkldnn_weights_cache.hpp"
#include "mkldnn_itt.h"
#include "mkldnn_extension_utils.h"
#include <legacy/net_pass.h>
#include <threading/ie_executor_manager.hpp>
@ -330,48 +329,23 @@ InferenceEngine::ExecutableNetworkInternal::Ptr
Engine::LoadExeNetworkImpl(const InferenceEngine::CNNNetwork &network, const std::map<std::string, std::string> &config) {
OV_ITT_SCOPED_TASK(itt::domains::MKLDNNPlugin, "Engine::LoadExeNetworkImpl");
static const std::vector<InferenceEngine::Precision> 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...

View File

@ -9,7 +9,6 @@
#include <type_traits>
#include <tuple>
#include <ie_parallel.hpp>
#include <ngraph/type/float16.hpp>
using namespace InferenceEngine;
@ -39,11 +38,6 @@ struct PrecisionInfo<Precision::BF16> {
using value_type = MKLDNNPlugin::bfloat16_t;
};
template <>
struct PrecisionInfo<Precision::FP16> {
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;

View File

@ -12,7 +12,6 @@ namespace {
const std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::U16,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::FP32
};
@ -20,7 +19,7 @@ const std::vector<std::map<std::string, std::string>> 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)

View File

@ -1,146 +0,0 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <ngraph/type/float16.hpp>
#include <vector>
#include "nodes/common/cpu_convert.h"
using namespace InferenceEngine;
using namespace ngraph;
using cpuConvertTestParamsSet = std::tuple<Precision, // input precision
Precision>; // target precision
class CpuConvertTest : virtual public ::testing::Test, public testing::WithParamInterface<cpuConvertTestParamsSet> {
public:
static std::string getTestCaseName(testing::TestParamInfo<cpuConvertTestParamsSet> 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<uint8_t> srcData(size * inputPrecision.size());
std::vector<uint8_t> dstData(size * targetPrecision.size());
std::vector<uint8_t> 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<class Type>
void fill(const size_t size, void *ptr) {
Type *castPtr = reinterpret_cast<Type *>(ptr);
for (size_t i = 0; i < size; i++)
castPtr[i] = static_cast<Type>(i);
}
void fillBuffer(Precision precision, const size_t size, void *ptr) {
switch (precision) {
case Precision::U8:
fill<uint8_t>(size, ptr);
break;
case Precision::I8:
fill<int8_t>(size, ptr);
break;
case Precision::U16:
fill<uint16_t>(size, ptr);
break;
case Precision::I16:
fill<int16_t>(size, ptr);
break;
case Precision::I32:
fill<int32_t>(size, ptr);
break;
case Precision::U64:
fill<uint64_t>(size, ptr);
break;
case Precision::I64:
fill<int64_t>(size, ptr);
break;
case Precision::FP16:
fill<float16>(size, ptr);
break;
case Precision::FP32:
fill<float>(size, ptr);
break;
default:
std::string error = "Can't fill buffer with " + std::string(precision.name()) + " precision";
throw std::runtime_error(error);
}
}
template<class Type>
bool compare(const size_t size, void *ptr1, void *ptr2) {
Type *castPtr1 = reinterpret_cast<Type *>(ptr1);
Type *castPtr2 = reinterpret_cast<Type *>(ptr2);
for (size_t i = 0; i < size; i++) {
if (abs(castPtr1[i] - castPtr2[i]) > static_cast<Type>(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<uint8_t>(size, ptr1, ptr2);
case Precision::I8:
return compare<int8_t>(size, ptr1, ptr2);
case Precision::U16:
return compare<uint16_t>(size, ptr1, ptr2);
case Precision::I16:
return compare<int16_t>(size, ptr1, ptr2);
case Precision::I32:
return compare<int32_t>(size, ptr1, ptr2);
case Precision::U64:
return compare<uint16_t>(size, ptr1, ptr2);
case Precision::I64:
return compare<int16_t>(size, ptr1, ptr2);
case Precision::FP16:
return compare<float16>(size, ptr1, ptr2);
case Precision::FP32:
return compare<float>(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<Precision> 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);