aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Lamberti <derek.lamberti@arm.com>2019-02-21 16:29:43 +0000
committerderek.lamberti <derek.lamberti@arm.com>2019-02-22 09:57:45 +0000
commit8ddae33ada66cc2ecdc0cde7799d81dda7532fb5 (patch)
tree3f835fe51cd00ddd1660e431b29db65991c66b06
parentc64ea9fdf975a65e9a1dd67b44469add270d6f8b (diff)
downloadarmnn-8ddae33ada66cc2ecdc0cde7799d81dda7532fb5.tar.gz
IVGSVSW-2736 Fix dangling reference to temporary storage
Change-Id: Ie6c553798eac732f37148d81970366e5a4ede1be Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
-rw-r--r--include/armnnDeserializer/IDeserializer.hpp6
-rw-r--r--src/armnnDeserializer/Deserializer.cpp255
-rw-r--r--src/armnnDeserializer/Deserializer.hpp42
-rw-r--r--src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp11
-rw-r--r--tests/InferenceModel.hpp10
5 files changed, 171 insertions, 153 deletions
diff --git a/include/armnnDeserializer/IDeserializer.hpp b/include/armnnDeserializer/IDeserializer.hpp
index 11e098a523..b2e5d10b69 100644
--- a/include/armnnDeserializer/IDeserializer.hpp
+++ b/include/armnnDeserializer/IDeserializer.hpp
@@ -15,7 +15,11 @@
namespace armnnDeserializer
{
-using BindingPointInfo = std::pair<armnn::LayerBindingId, armnn::TensorInfo>;
+struct BindingPointInfo
+{
+ armnn::LayerBindingId m_BindingId;
+ armnn::TensorInfo m_TensorInfo;
+};
class IDeserializer;
using IDeserializerPtr = std::unique_ptr<IDeserializer, void(*)(IDeserializer* parser)>;
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 9ec7835021..0bfbe7ea64 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -415,10 +415,10 @@ Deserializer::TensorRawPtrVector Deserializer::GetOutputs(const GraphPtr& graphP
return result;
}
-void Deserializer::ParseUnsupportedLayer(unsigned int layerIndex)
+void Deserializer::ParseUnsupportedLayer(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- const auto layerName = GetBaseLayer(m_Graph, layerIndex)->layerName()->c_str();
+ CHECK_LAYERS(graph, 0, layerIndex);
+ const auto layerName = GetBaseLayer(graph, layerIndex)->layerName()->c_str();
throw ParseException(
boost::str(
boost::format("Layer not supported. "
@@ -432,7 +432,8 @@ void Deserializer::ParseUnsupportedLayer(unsigned int layerIndex)
void Deserializer::ResetParser()
{
m_Network = armnn::INetworkPtr(nullptr, nullptr);
- m_Graph = nullptr;
+ m_InputBindings.clear();
+ m_OutputBindings.clear();
}
IDeserializer* IDeserializer::CreateRaw()
@@ -453,15 +454,16 @@ void IDeserializer::Destroy(IDeserializer* parser)
INetworkPtr Deserializer::CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent)
{
ResetParser();
- m_Graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
- return CreateNetworkFromGraph();
+ GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
+ return CreateNetworkFromGraph(graph);
}
armnn::INetworkPtr Deserializer::CreateNetworkFromBinary(std::istream& binaryContent)
{
ResetParser();
- m_Graph = LoadGraphFromBinary(binaryContent);
- return CreateNetworkFromGraph();
+ std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
+ GraphPtr graph = LoadGraphFromBinary(content.data(), content.size());
+ return CreateNetworkFromGraph(graph);
}
Deserializer::GraphPtr Deserializer::LoadGraphFromBinary(const uint8_t* binaryContent, size_t len)
@@ -483,32 +485,26 @@ Deserializer::GraphPtr Deserializer::LoadGraphFromBinary(const uint8_t* binaryCo
return GetSerializedGraph(binaryContent);
}
-Deserializer::GraphPtr Deserializer::LoadGraphFromBinary(std::istream& binaryContent)
-{
- std::string content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
- return GetSerializedGraph(content.data());
-}
-
-INetworkPtr Deserializer::CreateNetworkFromGraph()
+INetworkPtr Deserializer::CreateNetworkFromGraph(GraphPtr graph)
{
m_Network = INetwork::Create();
- BOOST_ASSERT(m_Graph != nullptr);
+ BOOST_ASSERT(graph != nullptr);
unsigned int layerIndex = 0;
- m_GraphConnections.emplace_back(m_Graph->layers()->size());
- for (AnyLayer const* layer : *m_Graph->layers())
+ m_GraphConnections.emplace_back(graph->layers()->size());
+ for (AnyLayer const* layer : *graph->layers())
{
if (layer->layer_type() != Layer_InputLayer &&
layer->layer_type() != Layer_OutputLayer)
{
// lookup and call the parser function
auto& parserFunction = m_ParserFunctions[layer->layer_type()];
- (this->*parserFunction)(layerIndex);
+ (this->*parserFunction)(graph, layerIndex);
}
++layerIndex;
}
- SetupInputLayers();
- SetupOutputLayers();
+ SetupInputLayers(graph);
+ SetupOutputLayers(graph);
// establish the connections from the layer outputs to the inputs of the subsequent layers
for (size_t connectionIndex = 0; connectionIndex < m_GraphConnections[0].size(); ++connectionIndex)
@@ -531,16 +527,11 @@ INetworkPtr Deserializer::CreateNetworkFromGraph()
BindingPointInfo Deserializer::GetNetworkInputBindingInfo(unsigned int layerIndex,
const std::string& name) const
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetGraphInputs(m_Graph);
-
- for (auto const& input : inputs)
+ for (auto inputBinding : m_InputBindings)
{
- if (input->layerName()->c_str() == name)
+ if (inputBinding.first == name)
{
- int bindingId = reinterpret_cast<armnn::LayerBindingId>(GetBindingLayerInfo(m_Graph, input->index()));
- auto layerBase = GetBaseLayer(m_Graph,input->index())->outputSlots()->Get(layerIndex);
- return std::make_pair(bindingId, ToTensorInfo(layerBase->tensorInfo()));
+ return inputBinding.second;
}
}
throw ParseException(
@@ -553,18 +544,11 @@ BindingPointInfo Deserializer::GetNetworkInputBindingInfo(unsigned int layerInde
BindingPointInfo Deserializer::GetNetworkOutputBindingInfo(unsigned int layerIndex,
const std::string& name) const
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto outputs = GetGraphOutputs(m_Graph);
-
- for (auto const& output : outputs)
+ for (auto outputBinding : m_OutputBindings)
{
- if (output->layerName()->c_str() == name)
+ if (outputBinding.first == name)
{
- int bindingId = reinterpret_cast<armnn::LayerBindingId>(GetBindingLayerInfo(m_Graph, output->index()));
- auto layer = GetBaseLayer(m_Graph, output->index());
- auto sourceLayerIndex = layer->inputSlots()->Get(0)->connection()->sourceLayerIndex();
- auto sourceLayer = GetBaseLayer(m_Graph, sourceLayerIndex);
- return std::make_pair(bindingId, ToTensorInfo(sourceLayer->outputSlots()->Get(0)->tensorInfo()));
+ return outputBinding.second;
}
}
throw ParseException(
@@ -574,41 +558,61 @@ BindingPointInfo Deserializer::GetNetworkOutputBindingInfo(unsigned int layerInd
CHECK_LOCATION().AsString()));
}
-void Deserializer::SetupInputLayers()
+void Deserializer::SetupInputLayers(GraphPtr graph)
{
- CHECK_GRAPH(m_Graph, 0);
- auto inputs = GetGraphInputs(m_Graph);
+ CHECK_GRAPH(graph, 0);
+ auto inputs = GetGraphInputs(graph);
+ m_InputBindings.clear();
+ m_InputBindings.reserve(inputs.size());
for (auto const& input : inputs)
{
+ LayerBindingId bindingId = GetBindingLayerInfo(graph, input->index());
IConnectableLayer* layer =
- m_Network->AddInputLayer(GetBindingLayerInfo(m_Graph, input->index()), input->layerName()->c_str());
+ m_Network->AddInputLayer(bindingId, input->layerName()->c_str());
auto tensorInfo = ToTensorInfo(input->outputSlots()->Get(0)->tensorInfo());
layer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
- RegisterOutputSlots(input->index(), layer);
+ RegisterOutputSlots(graph, input->index(), layer);
+
+ BOOST_ASSERT_MSG(input->layerName()->c_str(), "Input has no name.");
+ BindingPointInfo bindingInfo = {bindingId, tensorInfo};
+ m_InputBindings.push_back(std::make_pair(input->layerName()->c_str(), bindingInfo));
}
}
-void Deserializer::SetupOutputLayers()
+void Deserializer::SetupOutputLayers(GraphPtr graph)
{
- CHECK_GRAPH(m_Graph, 0);
- auto outputs = GetGraphOutputs(m_Graph);
+ CHECK_GRAPH(graph, 0);
+ auto outputs = GetGraphOutputs(graph);
+ m_OutputBindings.clear();
+ m_OutputBindings.reserve(outputs.size());
for (auto const& output : outputs)
{
+ LayerBindingId bindingId = GetBindingLayerInfo(graph, output->index());
IConnectableLayer* layer =
- m_Network->AddOutputLayer(GetBindingLayerInfo(m_Graph, output->index()), output->layerName()->c_str());
+ m_Network->AddOutputLayer(bindingId, output->layerName()->c_str());
+
+ RegisterInputSlots(graph, output->index(), layer);
+
+ auto baseLayer = GetBaseLayer(graph, output->index());
+ auto sourceLayerIndex = baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex();
+ auto sourceLayer = GetBaseLayer(graph, sourceLayerIndex);
+ auto tensorInfo = ToTensorInfo(sourceLayer->outputSlots()->Get(0)->tensorInfo());
- RegisterInputSlots(output->index(), layer);
+ BOOST_ASSERT_MSG(output->layerName()->c_str(), "Output has no name.");
+ BindingPointInfo bindingInfo = {bindingId, tensorInfo};
+ m_OutputBindings.push_back(std::make_pair(output->layerName()->c_str(), bindingInfo));
}
}
-void Deserializer::RegisterOutputSlots(uint32_t layerIndex,
- IConnectableLayer* layer)
+void Deserializer::RegisterOutputSlots(GraphPtr graph,
+ uint32_t layerIndex,
+ IConnectableLayer* layer)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
BOOST_ASSERT(layer != nullptr);
- auto parsedLayer = GetBaseLayer(m_Graph, layerIndex);
+ auto parsedLayer = GetBaseLayer(graph, layerIndex);
if (parsedLayer->outputSlots()->size() != layer->GetNumOutputSlots())
{
throw ParseException(
@@ -627,12 +631,13 @@ void Deserializer::RegisterOutputSlots(uint32_t layerIndex,
}
}
-void Deserializer::RegisterInputSlots(uint32_t layerIndex,
- armnn::IConnectableLayer* layer)
+void Deserializer::RegisterInputSlots(GraphPtr graph,
+ uint32_t layerIndex,
+ armnn::IConnectableLayer* layer)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
BOOST_ASSERT(layer != nullptr);
- auto parsedLayer = GetBaseLayer(m_Graph, layerIndex);
+ auto parsedLayer = GetBaseLayer(graph, layerIndex);
if (parsedLayer->inputSlots()->size() != layer->GetNumInputSlots())
{
throw ParseException(
@@ -681,19 +686,19 @@ void Deserializer::RegisterOutputSlotOfConnection(uint32_t connectionIndex,
slots.outputSlot = slot;
}
-void Deserializer::ParseActivation(unsigned int layerIndex)
+void Deserializer::ParseActivation(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto layerName = boost::str(boost::format("Activation:%1%") % layerIndex);
- auto serializerLayer = m_Graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
+ auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
auto serializerDescriptor = serializerLayer->descriptor();
armnn::ActivationDescriptor descriptor;
@@ -706,18 +711,18 @@ void Deserializer::ParseActivation(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseAdd(unsigned int layerIndex)
+void Deserializer::ParseAdd(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 2);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
m_layerName = boost::str(boost::format("Addition:%1%") % layerIndex);
@@ -726,23 +731,23 @@ void Deserializer::ParseAdd(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseConvolution2d(unsigned int layerIndex)
+void Deserializer::ParseConvolution2d(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto layerName = boost::str(boost::format("Convolution2d:%1%") % layerIndex);
- auto serializerLayer = m_Graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
+ auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
auto serializerDescriptor = serializerLayer->descriptor();
armnn::Convolution2dDescriptor descriptor;
@@ -769,23 +774,23 @@ void Deserializer::ParseConvolution2d(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseDepthwiseConvolution2d(unsigned int layerIndex)
+void Deserializer::ParseDepthwiseConvolution2d(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto layerName = boost::str(boost::format("DepthwiseConvolution2d:%1%") % layerIndex);
- auto serializerLayer = m_Graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
+ auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
auto serializerDescriptor = serializerLayer->descriptor();
armnn::DepthwiseConvolution2dDescriptor descriptor;
@@ -813,18 +818,18 @@ void Deserializer::ParseDepthwiseConvolution2d(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseMultiplication(unsigned int layerIndex)
+void Deserializer::ParseMultiplication(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 2);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
m_layerName = boost::str(boost::format("Multiplication:%1%") % layerIndex);
@@ -833,23 +838,23 @@ void Deserializer::ParseMultiplication(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseFullyConnected(unsigned int layerIndex)
+void Deserializer::ParseFullyConnected(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_LOCATION();
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto layerName = boost::str(boost::format("FullyConnected:%1%") % layerIndex);
- auto flatBufferLayer = m_Graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
+ auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
auto flatBufferDescriptor = flatBufferLayer->descriptor();
armnn::FullyConnectedDescriptor fullyConnectedDescriptor;
@@ -877,21 +882,21 @@ void Deserializer::ParseFullyConnected(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParsePermute(unsigned int layerIndex)
+void Deserializer::ParsePermute(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
auto dimsMapping =
- m_Graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
+ graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
- auto inputs = GetInputs(m_Graph, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto outputInfo = ToTensorInfo(outputs[0]);
@@ -901,8 +906,8 @@ void Deserializer::ParsePermute(unsigned int layerIndex)
IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, m_layerName.c_str());
layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
armnn::Pooling2dDescriptor Deserializer::GetPoolingDescriptor(Deserializer::PoolingDescriptor pooling2dDesc,
@@ -996,16 +1001,16 @@ armnn::Pooling2dDescriptor Deserializer::GetPoolingDescriptor(Deserializer::Pool
return desc;
}
-void Deserializer::ParsePooling2d(unsigned int layerIndex)
+void Deserializer::ParsePooling2d(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
- auto pooling2dDes = m_Graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
+ auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
- auto inputs = GetInputs(m_Graph, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
CHECK_VALID_SIZE(inputs.size(), 1);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
auto outputInfo = ToTensorInfo(outputs[0]);
@@ -1014,8 +1019,8 @@ void Deserializer::ParsePooling2d(unsigned int layerIndex)
IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, m_layerName.c_str());
layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
armnn::TensorInfo Deserializer::OutputShapeOfReshape(const armnn::TensorInfo& inputTensorInfo,
@@ -1048,18 +1053,18 @@ armnn::TensorInfo Deserializer::OutputShapeOfReshape(const armnn::TensorInfo& in
return reshapeInfo;
}
-void Deserializer::ParseReshape(unsigned int layerIndex)
+void Deserializer::ParseReshape(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
- auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
- auto outputs = GetOutputs(m_Graph, layerIndex);
+ auto outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
armnn::TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]);
armnn::TensorInfo actualOutputTensorInfo = ToTensorInfo(outputs[0]);
- const auto targetDims = m_Graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
+ const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
armnn::TensorInfo reshapeOutputTensorInfo = Deserializer::OutputShapeOfReshape(inputTensorInfo, outputDims);
@@ -1087,22 +1092,22 @@ void Deserializer::ParseReshape(unsigned int layerIndex)
IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
layer->GetOutputSlot(0).SetTensorInfo(reshapeOutputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
-void Deserializer::ParseSoftmax(unsigned int layerIndex)
+void Deserializer::ParseSoftmax(GraphPtr graph, unsigned int layerIndex)
{
- CHECK_LAYERS(m_Graph, 0, layerIndex);
+ CHECK_LAYERS(graph, 0, layerIndex);
- Deserializer::TensorRawPtrVector inputs = GetInputs(m_Graph, layerIndex);
+ Deserializer::TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
CHECK_VALID_SIZE(inputs.size(), 1);
- Deserializer::TensorRawPtrVector outputs = GetOutputs(m_Graph, layerIndex);
+ Deserializer::TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
armnn::SoftmaxDescriptor descriptor;
- descriptor.m_Beta = m_Graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
+ descriptor.m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
const std::string layerName = boost::str(boost::format("Softmax:%1%") % layerIndex);
IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
@@ -1110,8 +1115,8 @@ void Deserializer::ParseSoftmax(unsigned int layerIndex)
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
- RegisterInputSlots(layerIndex, layer);
- RegisterOutputSlots(layerIndex, layer);
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
}
} // namespace armnnDeserializer
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 25c651a50b..d1cb17d3af 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -44,7 +44,6 @@ public:
public:
// testable helpers
static GraphPtr LoadGraphFromBinary(const uint8_t* binaryContent, size_t len);
- static GraphPtr LoadGraphFromBinary(std::istream& binaryContent);
static TensorRawPtrVector GetInputs(const GraphPtr& graph, unsigned int layerIndex);
static TensorRawPtrVector GetOutputs(const GraphPtr& graph, unsigned int layerIndex);
static LayerBaseRawPtrVector GetGraphInputs(const GraphPtr& graphPtr);
@@ -62,40 +61,43 @@ private:
Deserializer& operator=(const Deserializer&) = delete;
/// Create the network from an already loaded flatbuffers graph
- armnn::INetworkPtr CreateNetworkFromGraph();
+ armnn::INetworkPtr CreateNetworkFromGraph(GraphPtr graph);
// signature for the parser functions
- using LayerParsingFunction = void(Deserializer::*)(unsigned int layerIndex);
-
- void ParseUnsupportedLayer(unsigned int layerIndex);
- void ParseActivation(unsigned int layerIndex);
- void ParseAdd(unsigned int layerIndex);
- void ParseConvolution2d(unsigned int layerIndex);
- void ParseDepthwiseConvolution2d(unsigned int layerIndex);
- void ParseFullyConnected(unsigned int layerIndex);
- void ParseMultiplication(unsigned int layerIndex);
- void ParsePermute(unsigned int layerIndex);
- void ParsePooling2d(unsigned int layerIndex);
- void ParseReshape(unsigned int layerIndex);
- void ParseSoftmax(unsigned int layerIndex);
+ using LayerParsingFunction = void(Deserializer::*)(GraphPtr graph, unsigned int layerIndex);
+
+ void ParseUnsupportedLayer(GraphPtr graph, unsigned int layerIndex);
+ void ParseActivation(GraphPtr graph, unsigned int layerIndex);
+ void ParseAdd(GraphPtr graph, unsigned int layerIndex);
+ void ParseConvolution2d(GraphPtr graph, unsigned int layerIndex);
+ void ParseDepthwiseConvolution2d(GraphPtr graph, unsigned int layerIndex);
+ void ParseFullyConnected(GraphPtr graph, unsigned int layerIndex);
+ void ParseMultiplication(GraphPtr graph, unsigned int layerIndex);
+ void ParsePermute(GraphPtr graph, unsigned int layerIndex);
+ void ParsePooling2d(GraphPtr graph, unsigned int layerIndex);
+ void ParseReshape(GraphPtr graph, unsigned int layerIndex);
+ void ParseSoftmax(GraphPtr graph, unsigned int layerIndex);
void RegisterOutputSlotOfConnection(uint32_t connectionIndex, armnn::IOutputSlot* slot);
void RegisterInputSlotOfConnection(uint32_t connectionIndex, armnn::IInputSlot* slot);
- void RegisterInputSlots(uint32_t layerIndex,
+ void RegisterInputSlots(GraphPtr graph, uint32_t layerIndex,
armnn::IConnectableLayer* layer);
- void RegisterOutputSlots(uint32_t layerIndex,
+ void RegisterOutputSlots(GraphPtr graph, uint32_t layerIndex,
armnn::IConnectableLayer* layer);
void ResetParser();
- void SetupInputLayers();
- void SetupOutputLayers();
+ void SetupInputLayers(GraphPtr graphPtr);
+ void SetupOutputLayers(GraphPtr graphPtr);
/// The network we're building. Gets cleared after it is passed to the user
armnn::INetworkPtr m_Network;
- GraphPtr m_Graph;
std::vector<LayerParsingFunction> m_ParserFunctions;
std::string m_layerName;
+ using NameToBindingInfo = std::pair<std::string, BindingPointInfo >;
+ std::vector<NameToBindingInfo> m_InputBindings;
+ std::vector<NameToBindingInfo> m_OutputBindings;
+
/// A mapping of an output slot to each of the input slots it should be connected to
/// The outputSlot is from the layer that creates this tensor as one of its outputs
/// The inputSlots are from the layers that use this tensor as one of their inputs
diff --git a/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
index e5416362b6..d6504864ca 100644
--- a/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
+++ b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
@@ -166,11 +166,16 @@ void ParserFlatbuffersSerializeFixture::RunTest(unsigned int layersId,
{
using BindingPointInfo = std::pair<armnn::LayerBindingId, armnn::TensorInfo>;
+ auto ConvertBindingInfo = [](const armnnDeserializer::BindingPointInfo& bindingInfo)
+ {
+ return std::make_pair(bindingInfo.m_BindingId, bindingInfo.m_TensorInfo);
+ };
+
// Setup the armnn input tensors from the given vectors.
armnn::InputTensors inputTensors;
for (auto&& it : inputData)
{
- BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(layersId, it.first);
+ BindingPointInfo bindingInfo = ConvertBindingInfo(m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
armnn::VerifyTensorInfoDataType(bindingInfo.second, ArmnnType);
inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) });
}
@@ -180,7 +185,7 @@ void ParserFlatbuffersSerializeFixture::RunTest(unsigned int layersId,
armnn::OutputTensors outputTensors;
for (auto&& it : expectedOutputData)
{
- BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(layersId, it.first);
+ BindingPointInfo bindingInfo = ConvertBindingInfo(m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
armnn::VerifyTensorInfoDataType(bindingInfo.second, ArmnnType);
outputStorage.emplace(it.first, MakeTensor<DataType, NumOutputDimensions>(bindingInfo.second));
outputTensors.push_back(
@@ -192,7 +197,7 @@ void ParserFlatbuffersSerializeFixture::RunTest(unsigned int layersId,
// Compare each output tensor to the expected values
for (auto&& it : expectedOutputData)
{
- BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(layersId, it.first);
+ BindingPointInfo bindingInfo = ConvertBindingInfo(m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
auto outputExpected = MakeTensor<DataType, NumOutputDimensions>(bindingInfo.second, it.second);
BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first]));
}
diff --git a/tests/InferenceModel.hpp b/tests/InferenceModel.hpp
index 3b3dd95e88..6e73f5275f 100644
--- a/tests/InferenceModel.hpp
+++ b/tests/InferenceModel.hpp
@@ -203,14 +203,16 @@ public:
for (const std::string& inputLayerName : params.m_InputBindings)
{
- BindingPointInfo inputBinding = parser->GetNetworkInputBindingInfo(subGraphId, inputLayerName);
- inputBindings.push_back(inputBinding);
+ armnnDeserializer::BindingPointInfo inputBinding =
+ parser->GetNetworkInputBindingInfo(subGraphId, inputLayerName);
+ inputBindings.push_back(std::make_pair(inputBinding.m_BindingId, inputBinding.m_TensorInfo));
}
for (const std::string& outputLayerName : params.m_OutputBindings)
{
- BindingPointInfo outputBinding = parser->GetNetworkOutputBindingInfo(subGraphId, outputLayerName);
- outputBindings.push_back(outputBinding);
+ armnnDeserializer::BindingPointInfo outputBinding =
+ parser->GetNetworkOutputBindingInfo(subGraphId, outputLayerName);
+ outputBindings.push_back(std::make_pair(outputBinding.m_BindingId, outputBinding.m_TensorInfo));
}
return network;