13 #include <boost/core/ignore_unused.hpp> 14 #include <boost/assert.hpp> 15 #include <boost/format.hpp> 20 #include "flatbuffers/idl.h" 21 #include "flatbuffers/util.h" 23 #include <ArmnnSchema_generated.h> 39 std::unique_ptr<IDeserializer, void (*)(IDeserializer* parser)>
m_Parser;
57 m_Parser->CreateNetworkFromBinary(m_GraphBinary);
65 m_Runtime->GetDeviceSpec());
67 std::string errorMessage;
68 armnn::Status ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, move(optimized), errorMessage);
74 boost::format(
"The runtime failed to load the network. " 75 "Error was: %1%. in %2% [%3%:%4%]") %
87 m_SingleInputName = inputName;
88 m_SingleOutputName = outputName;
97 flatbuffers::Parser parser;
99 bool ok = parser.Parse(schemafile.c_str());
100 BOOST_ASSERT_MSG(ok,
"Failed to parse schema file");
102 ok &= parser.Parse(m_JsonString.c_str());
103 BOOST_ASSERT_MSG(ok,
"Failed to parse json input");
111 const uint8_t* bufferPtr = parser.builder_.GetBufferPointer();
112 size_t size =
static_cast<size_t>(parser.builder_.GetSize());
113 m_GraphBinary.assign(bufferPtr, bufferPtr+size);
120 template<std::size_t NumOutputDimensions,
123 void RunTest(
unsigned int layersId,
124 const std::vector<DataType>& inputData,
125 const std::vector<DataType>& expectedOutputData);
127 template<std::size_t NumOutputDimensions,
132 void RunTest(
unsigned int layersId,
133 const std::vector<InputDataType>& inputData,
134 const std::vector<OutputDataType>& expectedOutputData);
138 template<std::size_t NumOutputDimensions,
141 void RunTest(
unsigned int layersId,
142 const std::map<std::string, std::vector<DataType>>& inputData,
143 const std::map<std::string, std::vector<DataType>>& expectedOutputData);
145 template<std::size_t NumOutputDimensions,
150 void RunTest(
unsigned int layersId,
151 const std::map<std::string, std::vector<InputDataType>>& inputData,
152 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData);
155 armnnSerializer::TensorInfo tensorType,
const std::string& name,
156 const float scale,
const int64_t zeroPoint)
158 boost::ignore_unused(name);
159 BOOST_CHECK_EQUAL(shapeSize, tensors->dimensions()->size());
160 BOOST_CHECK_EQUAL_COLLECTIONS(shape.begin(), shape.end(),
161 tensors->dimensions()->begin(), tensors->dimensions()->end());
162 BOOST_CHECK_EQUAL(tensorType.dataType(), tensors->dataType());
163 BOOST_CHECK_EQUAL(scale, tensors->quantizationScale());
164 BOOST_CHECK_EQUAL(zeroPoint, tensors->quantizationOffset());
168 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
170 const std::vector<DataType>& inputData,
171 const std::vector<DataType>& expectedOutputData)
173 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
176 template<std::size_t NumOutputDimensions,
179 typename InputDataType,
180 typename OutputDataType>
182 const std::vector<InputDataType>& inputData,
183 const std::vector<OutputDataType>& expectedOutputData)
185 RunTest<NumOutputDimensions, ArmnnInputType, ArmnnOutputType>(layersId,
190 template<std::
size_t NumOutputDimensions, armnn::DataType ArmnnType,
typename DataType>
192 const std::map<std::string, std::vector<DataType>>& inputData,
193 const std::map<std::string, std::vector<DataType>>& expectedOutputData)
195 RunTest<NumOutputDimensions, ArmnnType, ArmnnType, DataType, DataType>(layersId, inputData, expectedOutputData);
198 template<std::size_t NumOutputDimensions,
201 typename InputDataType,
202 typename OutputDataType>
204 unsigned int layersId,
205 const std::map<std::string, std::vector<InputDataType>>& inputData,
206 const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData)
210 return std::make_pair(bindingInfo.m_BindingId, bindingInfo.m_TensorInfo);
215 for (
auto&& it : inputData)
218 m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
220 inputTensors.push_back({ bindingInfo.first,
armnn::ConstTensor(bindingInfo.second, it.second.data()) });
224 std::map<std::string, boost::multi_array<OutputDataType, NumOutputDimensions>> outputStorage;
226 for (
auto&& it : expectedOutputData)
229 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
231 outputStorage.emplace(it.first, MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second));
232 outputTensors.push_back(
233 { bindingInfo.first,
armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) });
239 for (
auto&& it : expectedOutputData)
242 m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
243 auto outputExpected = MakeTensor<OutputDataType, NumOutputDimensions>(bindingInfo.second, it.second);
244 BOOST_TEST(
CompareTensors(outputExpected, outputStorage[it.first]));
bool ReadStringToBinary()
std::vector< uint8_t > m_GraphBinary
ParserFlatbuffersSerializeFixture()
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
void VerifyTensorInfoDataType(const armnn::TensorInfo &info, armnn::DataType dataType)
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)
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
std::string m_SingleInputName
typename ResolveTypeImpl< DT >::Type ResolveType
std::string m_SingleOutputName
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
armnn::NetworkId m_NetworkIdentifier
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> m_Parser
armnnSerializer::TensorInfo * TensorRawPtr
Base class for all ArmNN exceptions so that users can filter to just those.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
CPU Execution: Reference C++ kernels.
const char deserialize_schema_end
const char deserialize_schema_start
void RunTest(unsigned int layersId, const std::vector< DataType > &inputData, const std::vector< DataType > &expectedOutputData)
armnn::IRuntimePtr m_Runtime
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
boost::test_tools::predicate_result CompareTensors(const boost::multi_array< T, n > &a, const boost::multi_array< T, n > &b, bool compareBoolean=false)