11 #include "flatbuffers/idl.h" 12 #include "flatbuffers/util.h" 14 #include <ArmnnSchema_generated.h> 20 #include <boost/assert.hpp> 21 #include <boost/format.hpp> 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);
73 boost::format(
"The runtime failed to load the network. " 74 "Error was: %1%. in %2% [%3%:%4%]") %
86 m_SingleInputName = inputName;
87 m_SingleOutputName = outputName;
96 flatbuffers::Parser parser;
98 bool ok = parser.Parse(schemafile.c_str());
99 BOOST_ASSERT_MSG(ok,
"Failed to parse schema file");
101 ok &= parser.Parse(m_JsonString.c_str());
102 BOOST_ASSERT_MSG(ok,
"Failed to parse json input");
110 const uint8_t* bufferPtr = parser.builder_.GetBufferPointer();
111 size_t size =
static_cast<size_t>(parser.builder_.GetSize());
112 m_GraphBinary.assign(bufferPtr, bufferPtr+size);
119 template<std::size_t NumOutputDimensions,
122 void RunTest(
unsigned int layersId,
123 const std::vector<DataType>& inputData,
124 const std::vector<DataType>& expectedOutputData);
126 template<std::size_t NumOutputDimensions,
131 void RunTest(
unsigned int layersId,
132 const std::vector<InputDataType>& inputData,
133 const std::vector<OutputDataType>& expectedOutputData);
137 template<std::size_t NumOutputDimensions,
140 void RunTest(
unsigned int layersId,
141 const std::map<std::string, std::vector<DataType>>& inputData,
142 const std::map<std::string, std::vector<DataType>>& expectedOutputData);
144 template<std::size_t NumOutputDimensions,
149 void RunTest(
unsigned int layersId,
150 const std::map<std::string, std::vector<InputDataType>>& inputData,
151 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData);
154 armnnSerializer::TensorInfo tensorType,
const std::string& name,
155 const float scale,
const int64_t zeroPoint)
158 BOOST_CHECK_EQUAL(shapeSize, tensors->dimensions()->size());
159 BOOST_CHECK_EQUAL_COLLECTIONS(shape.begin(), shape.end(),
160 tensors->dimensions()->begin(), tensors->dimensions()->end());
161 BOOST_CHECK_EQUAL(tensorType.dataType(), tensors->dataType());
162 BOOST_CHECK_EQUAL(scale, tensors->quantizationScale());
163 BOOST_CHECK_EQUAL(zeroPoint, tensors->quantizationOffset());
167 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
169 const std::vector<DataType>& inputData,
170 const std::vector<DataType>& expectedOutputData)
172 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
175 template<std::size_t NumOutputDimensions,
178 typename InputDataType,
179 typename OutputDataType>
181 const std::vector<InputDataType>& inputData,
182 const std::vector<OutputDataType>& expectedOutputData)
184 RunTest<NumOutputDimensions, ArmnnInputType, ArmnnOutputType>(layersId,
189 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
191 const std::map<std::string, std::vector<DataType>>& inputData,
192 const std::map<std::string, std::vector<DataType>>& expectedOutputData)
194 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
197 template<std::size_t NumOutputDimensions,
200 typename InputDataType,
201 typename OutputDataType>
203 unsigned int layersId,
204 const std::map<std::string, std::vector<InputDataType>>& inputData,
205 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData)
209 return std::make_pair(bindingInfo.m_BindingId, bindingInfo.m_TensorInfo);
214 for (
auto&& it : inputData)
217 m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
219 inputTensors.push_back({ bindingInfo.first,
armnn::ConstTensor(bindingInfo.second, it.second.data()) });
223 std::map<std::string, boost::multi_array<OutputDataType, NumOutputDimensions>> outputStorage;
225 for (
auto&& it : expectedOutputData)
228 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
230 outputStorage.emplace(it.first, MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second));
231 outputTensors.push_back(
232 { bindingInfo.first,
armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) });
238 for (
auto&& it : expectedOutputData)
241 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
242 auto outputExpected = MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second, it.second);
243 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 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) 2020 ARM Limited.
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.
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...