[IE CLDNN] Fixing eltwise input sizes (#2017)

This commit is contained in:
Lukasz Debski 2020-09-02 08:36:52 +02:00 committed by GitHub
parent e3178122ee
commit 315274ad12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2218,6 +2218,7 @@ void Program::CreateEltwisePrimitive(cldnn::topology& topology, InferenceEngine:
auto eltwiseLayer = as<InferenceEngine::EltwiseLayer *> (layer); auto eltwiseLayer = as<InferenceEngine::EltwiseLayer *> (layer);
auto inputPrimitives = GetPrevLayersPrimitives(layer); auto inputPrimitives = GetPrevLayersPrimitives(layer);
std::string eltwiseLayerName = layer_type_name_ID(layer);
std::vector<float> coefficients = eltwiseLayer->coeff; std::vector<float> coefficients = eltwiseLayer->coeff;
if (eltwiseLayer->_operation != InferenceEngine::EltwiseLayer::Sum && !coefficients.empty()) { if (eltwiseLayer->_operation != InferenceEngine::EltwiseLayer::Sum && !coefficients.empty()) {
@ -2228,8 +2229,40 @@ void Program::CreateEltwisePrimitive(cldnn::topology& topology, InferenceEngine:
THROW_IE_EXCEPTION << "Number of provided coefficients is not equal to number of operands"; THROW_IE_EXCEPTION << "Number of provided coefficients is not equal to number of operands";
} }
auto outDimsN = layer->outData[0]->getTensorDesc().getDims().size();
for (size_t i = 0; i < inputPrimitives.size(); ++i) {
auto inputDims = layer->insData[i].lock()->getTensorDesc().getDims();
auto inputDimsN = inputDims.size();
if (inputDimsN != outDimsN) {
// Add reorder if changing number of dimensions requires changing format
auto targetFormat = defaultFormatForDims(outDimsN);
if (targetFormat.value != defaultFormatForDims(inputDimsN).value) {
auto reorderName = eltwiseLayerName + "_cldnn_in" + std::to_string(i) + "_reorder";
auto targetDatatype = DataTypeFromPrecision(layer->precision);
auto reorderPrim = cldnn::reorder(reorderName, inputPrimitives[i], targetFormat, targetDatatype);
topology.add(reorderPrim);
AddInnerPrimitiveToProfiler(reorderName, eltwiseLayerName, layer);
inputPrimitives[i] = reorderName;
}
auto reshapeName = eltwiseLayerName + "_cldnn_in" + std::to_string(i) + "_reshape";
// Extend input dimensions by prepending ones
inputDims.insert(inputDims.begin(), outDimsN - inputDimsN, 1ul);
auto targetShape = CldnnTensorFromIEDims(inputDims);
auto reshapePrim = cldnn::reshape(reshapeName, inputPrimitives[i], targetShape);
topology.add(reshapePrim);
AddInnerPrimitiveToProfiler(reshapeName, eltwiseLayerName, layer);
inputPrimitives[i] = reshapeName;
}
}
auto out_dt = DataTypeFromPrecision(eltwiseLayer->precision); auto out_dt = DataTypeFromPrecision(eltwiseLayer->precision);
std::string eltwiseLayerName = layer_type_name_ID(layer);
auto eltwisePrim = cldnn::eltwise( auto eltwisePrim = cldnn::eltwise(
eltwiseLayerName, eltwiseLayerName,
inputPrimitives, inputPrimitives,