[IE CLDNN] Fixing eltwise input sizes (#2017)
This commit is contained in:
parent
e3178122ee
commit
315274ad12
@ -2218,6 +2218,7 @@ void Program::CreateEltwisePrimitive(cldnn::topology& topology, InferenceEngine:
|
||||
|
||||
auto eltwiseLayer = as<InferenceEngine::EltwiseLayer *> (layer);
|
||||
auto inputPrimitives = GetPrevLayersPrimitives(layer);
|
||||
std::string eltwiseLayerName = layer_type_name_ID(layer);
|
||||
|
||||
std::vector<float> coefficients = eltwiseLayer->coeff;
|
||||
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";
|
||||
}
|
||||
|
||||
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);
|
||||
std::string eltwiseLayerName = layer_type_name_ID(layer);
|
||||
auto eltwisePrim = cldnn::eltwise(
|
||||
eltwiseLayerName,
|
||||
inputPrimitives,
|
||||
|
Loading…
Reference in New Issue
Block a user