ArmNN
 21.08
SerializerTestUtils.cpp File Reference
#include "SerializerTestUtils.hpp"
#include "../Serializer.hpp"
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

void CompareConstTensor (const armnn::ConstTensor &tensor1, const armnn::ConstTensor &tensor2)
 
armnn::INetworkPtr DeserializeNetwork (const std::string &serializerString)
 
std::string SerializeNetwork (const armnn::INetwork &network)
 

Function Documentation

◆ CompareConstTensor()

void CompareConstTensor ( const armnn::ConstTensor tensor1,
const armnn::ConstTensor tensor2 
)

Definition at line 116 of file SerializerTestUtils.cpp.

References armnn::Boolean, armnn::Float32, BaseTensor< MemoryType >::GetDataType(), armnn::GetDataTypeName(), BaseTensor< MemoryType >::GetMemoryArea(), BaseTensor< MemoryType >::GetNumElements(), BaseTensor< MemoryType >::GetShape(), armnn::QAsymmU8, armnn::QSymmS8, and armnn::Signed32.

Referenced by LayerVerifierBaseWithDescriptorAndConstants< Descriptor >::ExecuteStrategy(), and TEST_SUITE().

117 {
118  CHECK(tensor1.GetShape() == tensor2.GetShape());
119  CHECK(GetDataTypeName(tensor1.GetDataType()) == GetDataTypeName(tensor2.GetDataType()));
120 
121  switch (tensor1.GetDataType())
122  {
124  CompareConstTensorData<const float*>(
125  tensor1.GetMemoryArea(), tensor2.GetMemoryArea(), tensor1.GetNumElements());
126  break;
129  CompareConstTensorData<const uint8_t*>(
130  tensor1.GetMemoryArea(), tensor2.GetMemoryArea(), tensor1.GetNumElements());
131  break;
133  CompareConstTensorData<const int8_t*>(
134  tensor1.GetMemoryArea(), tensor2.GetMemoryArea(), tensor1.GetNumElements());
135  break;
137  CompareConstTensorData<const int32_t*>(
138  tensor1.GetMemoryArea(), tensor2.GetMemoryArea(), tensor1.GetNumElements());
139  break;
140  default:
141  // Note that Float16 is not yet implemented
142  MESSAGE("Unexpected datatype");
143  CHECK(false);
144  }
145 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:297
unsigned int GetNumElements() const
Definition: Tensor.hpp:303
MemoryType GetMemoryArea() const
Definition: Tensor.hpp:305
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:193
DataType GetDataType() const
Definition: Tensor.hpp:300

◆ DeserializeNetwork()

armnn::INetworkPtr DeserializeNetwork ( const std::string &  serializerString)

Definition at line 147 of file SerializerTestUtils.cpp.

Referenced by TEST_SUITE().

148 {
149  std::vector<std::uint8_t> const serializerVector{serializerString.begin(), serializerString.end()};
150  return IDeserializer::Create()->CreateNetworkFromBinary(serializerVector);
151 }

◆ SerializeNetwork()

std::string SerializeNetwork ( const armnn::INetwork network)

Definition at line 153 of file SerializerTestUtils.cpp.

References ISerializer::Create().

Referenced by TEST_SUITE().

154 {
156 
157  serializer->Serialize(network);
158 
159  std::stringstream stream;
160  serializer->SaveSerializedToStream(stream);
161 
162  std::string serializerString{stream.str()};
163  return serializerString;
164 }
std::unique_ptr< ISerializer, void(*)(ISerializer *serializer)> ISerializerPtr
Definition: ISerializer.hpp:15
static ISerializerPtr Create()
Definition: Serializer.cpp:35