11 #include "flatbuffers/idl.h" 12 #include "flatbuffers/util.h" 21 #include <fmt/format.h> 38 std::unique_ptr<IDeserializer, void (*)(IDeserializer* parser)>
m_Parser;
56 m_Parser->CreateNetworkFromBinary(m_GraphBinary);
64 m_Runtime->GetDeviceSpec());
66 std::string errorMessage;
67 armnn::Status ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, move(optimized), errorMessage);
71 throw armnn::Exception(fmt::format(
"The runtime failed to load the network. " 72 "Error was: {0}. in {1} [{2}:{3}]",
84 m_SingleInputName = inputName;
85 m_SingleOutputName = outputName;
94 flatbuffers::Parser parser;
96 bool ok = parser.Parse(schemafile.c_str());
99 ok &= parser.Parse(m_JsonString.c_str());
108 const uint8_t* bufferPtr = parser.builder_.GetBufferPointer();
109 size_t size =
static_cast<size_t>(parser.builder_.GetSize());
110 m_GraphBinary.assign(bufferPtr, bufferPtr+size);
117 template<std::size_t NumOutputDimensions,
120 void RunTest(
unsigned int layersId,
121 const std::vector<DataType>& inputData,
122 const std::vector<DataType>& expectedOutputData);
124 template<std::size_t NumOutputDimensions,
129 void RunTest(
unsigned int layersId,
130 const std::vector<InputDataType>& inputData,
131 const std::vector<OutputDataType>& expectedOutputData);
135 template<std::size_t NumOutputDimensions,
138 void RunTest(
unsigned int layersId,
139 const std::map<std::string, std::vector<DataType>>& inputData,
140 const std::map<std::string, std::vector<DataType>>& expectedOutputData);
142 template<std::size_t NumOutputDimensions,
147 void RunTest(
unsigned int layersId,
148 const std::map<std::string, std::vector<InputDataType>>& inputData,
149 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData);
152 armnnSerializer::TensorInfo tensorType,
const std::string& name,
153 const float scale,
const int64_t zeroPoint)
156 BOOST_CHECK_EQUAL(shapeSize, tensors->dimensions()->size());
157 BOOST_CHECK_EQUAL_COLLECTIONS(shape.begin(), shape.end(),
158 tensors->dimensions()->begin(), tensors->dimensions()->end());
159 BOOST_CHECK_EQUAL(tensorType.dataType(), tensors->dataType());
160 BOOST_CHECK_EQUAL(scale, tensors->quantizationScale());
161 BOOST_CHECK_EQUAL(zeroPoint, tensors->quantizationOffset());
165 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
167 const std::vector<DataType>& inputData,
168 const std::vector<DataType>& expectedOutputData)
170 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
173 template<std::size_t NumOutputDimensions,
176 typename InputDataType,
177 typename OutputDataType>
179 const std::vector<InputDataType>& inputData,
180 const std::vector<OutputDataType>& expectedOutputData)
182 RunTest<NumOutputDimensions, ArmnnInputType, ArmnnOutputType>(layersId,
187 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
189 const std::map<std::string, std::vector<DataType>>& inputData,
190 const std::map<std::string, std::vector<DataType>>& expectedOutputData)
192 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
195 template<std::size_t NumOutputDimensions,
198 typename InputDataType,
199 typename OutputDataType>
201 unsigned int layersId,
202 const std::map<std::string, std::vector<InputDataType>>& inputData,
203 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData)
207 return std::make_pair(bindingInfo.m_BindingId, bindingInfo.m_TensorInfo);
212 for (
auto&& it : inputData)
215 m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
217 inputTensors.push_back({ bindingInfo.first,
armnn::ConstTensor(bindingInfo.second, it.second.data()) });
221 std::map<std::string, boost::multi_array<OutputDataType, NumOutputDimensions>> outputStorage;
223 for (
auto&& it : expectedOutputData)
226 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
228 outputStorage.emplace(it.first, MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second));
229 outputTensors.push_back(
230 { bindingInfo.first,
armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) });
236 for (
auto&& it : expectedOutputData)
239 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
240 auto outputExpected = MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second, it.second);
241 BOOST_TEST(
CompareTensors(outputExpected, outputStorage[it.first]));
void CheckTensors(const TensorRawPtr &tensors, size_t shapeSize, const std::vector< int32_t > &shape, armnnSerializer::TensorInfo tensorType, const std::string &name, const float scale, const int64_t zeroPoint)
CPU Execution: Reference C++ kernels.
void RunTest(unsigned int layersId, const std::vector< DataType > &inputData, const std::vector< DataType > &expectedOutputData)
Executes the network with the given input tensor and checks the result against the given output tenso...
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
ParserFlatbuffersSerializeFixture()
boost::test_tools::predicate_result CompareTensors(const boost::multi_array< T, n > &a, const boost::multi_array< T, n > &b, bool compareBoolean=false, bool isDynamic=false)
bool ReadStringToBinary()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
armnn::NetworkId m_NetworkIdentifier
typename ResolveTypeImpl< DT >::Type ResolveType
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> m_Parser
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
#define ARMNN_ASSERT_MSG(COND, MSG)
armnnSerializer::TensorInfo * TensorRawPtr
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
armnn::IRuntimePtr m_Runtime
std::string m_SingleOutputName
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
const char deserialize_schema_start
Base class for all ArmNN exceptions so that users can filter to just those.
const char deserialize_schema_end
void VerifyTensorInfoDataType(const armnn::TensorInfo &info, armnn::DataType dataType)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
std::vector< uint8_t > m_GraphBinary
std::string m_SingleInputName
If the single-input-single-output overload of Setup() is called, these will store the input and outpu...