ArmNN
 24.02
ClContextSerializer Class Reference

#include <ClContextSerializer.hpp>

Public Member Functions

 ClContextSerializer ()=default
 
 ~ClContextSerializer ()=default
 
void Serialize (const arm_compute::CLCompileContext &clCompileContext)
 Serializes the CLCompileContext built-in programs. More...
 
bool SaveSerializedToStream (std::ostream &stream)
 Serializes the ClContext to the stream. More...
 

Detailed Description

Definition at line 15 of file ClContextSerializer.hpp.

Constructor & Destructor Documentation

◆ ClContextSerializer()

ClContextSerializer ( )
default

◆ ~ClContextSerializer()

~ClContextSerializer ( )
default

Member Function Documentation

◆ SaveSerializedToStream()

bool SaveSerializedToStream ( std::ostream &  stream)

Serializes the ClContext to the stream.

Parameters
[stream]the stream to save to
Returns
true if ClContext is Serialized to the Stream, false otherwise

Definition at line 49 of file ClContextSerializer.cpp.

50 {
51  // Write to a stream
52  auto bytesToWrite = armnn::numeric_cast<std::streamsize>(m_FlatBufferBuilder.GetSize());
53  stream.write(reinterpret_cast<const char*>(m_FlatBufferBuilder.GetBufferPointer()), bytesToWrite);
54  return !stream.bad();
55 }

◆ Serialize()

void Serialize ( const arm_compute::CLCompileContext &  clCompileContext)

Serializes the CLCompileContext built-in programs.

Parameters
[in]clCompileContextThe CLCompileContext to be serialized.

Definition at line 23 of file ClContextSerializer.cpp.

24 {
25  // Get map of built programs from clCompileContext
26  std::map<std::string, cl::Program> builtProgramsMap = clCompileContext.get_built_programs();
27  if (builtProgramsMap.empty())
28  {
29  ARMNN_LOG(warning) << "There are no built programs to be serialised.";
30  return;
31  }
32 
33  // Create Flatbuffer CL Programs
34  std::vector<flatbuffers::Offset<armnn::Program>> clPrograms;
35  for(const auto& program : builtProgramsMap)
36  {
37  std::vector<std::vector<uint8_t>> binaries = program.second.getInfo<CL_PROGRAM_BINARIES>();
38  clPrograms.push_back(CreateProgram(m_FlatBufferBuilder,
39  m_FlatBufferBuilder.CreateString(program.first),
40  m_FlatBufferBuilder.CreateVector(binaries[0])));
41  }
42 
43  // Create Flatbuffer CLContext
44  auto clContext = CreateClContext(m_FlatBufferBuilder, m_FlatBufferBuilder.CreateVector(clPrograms));
45 
46  m_FlatBufferBuilder.Finish(clContext);
47 }

References ARMNN_LOG, armnn::CreateClContext(), armnn::CreateProgram(), and armnn::warning.


The documentation for this class was generated from the following files:
armnn::CreateProgram
flatbuffers::Offset< Program > CreateProgram(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::String > name=0, flatbuffers::Offset< flatbuffers::Vector< uint8_t >> binary=0)
Definition: ClContextSchema_generated.h:118
armnn::CreateClContext
flatbuffers::Offset< ClContext > CreateClContext(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< armnn::Program >>> programs=0)
Definition: ClContextSchema_generated.h:57
ARMNN_LOG
#define ARMNN_LOG(severity)
Definition: Logging.hpp:212