ArmNN
 21.02
ClContextDeserializer Class Reference

#include <ClContextDeserializer.hpp>

Public Member Functions

 ClContextDeserializer ()=default
 
 ~ClContextDeserializer ()=default
 
void Deserialize (arm_compute::CLCompileContext &clCompileContext, cl::Context &context, cl::Device &device, const std::string &filePath)
 Deserializes the CLCompileContext built-in programs from a binary file. More...
 
void DeserializeFromBinary (arm_compute::CLCompileContext &clCompileContext, cl::Context &context, cl::Device &device, const std::vector< uint8_t > &binaryContent)
 Deserializes the CLCompileContext built-in programs from binary file contents. More...
 

Detailed Description

Definition at line 13 of file ClContextDeserializer.hpp.

Constructor & Destructor Documentation

◆ ClContextDeserializer()

ClContextDeserializer ( )
default

◆ ~ClContextDeserializer()

~ClContextDeserializer ( )
default

Member Function Documentation

◆ Deserialize()

void Deserialize ( arm_compute::CLCompileContext &  clCompileContext,
cl::Context &  context,
cl::Device &  device,
const std::string &  filePath 
)

Deserializes the CLCompileContext built-in programs from a binary file.

Parameters
[in]clCompileContextThe CLCompileContext to be serialized
[in]contextThe CL Kernel context built-in program will be created from
[in]deviceThe CL Kernel device built-in program will be created from
[in]filePathThe serialized file

Definition at line 24 of file ClContextDeserializer.cpp.

References ClContextDeserializer::DeserializeFromBinary().

Referenced by ClWorkloadFactory::AfterWorkloadsCreated().

28 {
29  std::ifstream inputFileStream(filePath, std::ios::binary);
30  std::vector<std::uint8_t> binaryContent;
31  while (inputFileStream)
32  {
33  char input;
34  inputFileStream.get(input);
35  if (inputFileStream)
36  {
37  binaryContent.push_back(static_cast<std::uint8_t>(input));
38  }
39  }
40  inputFileStream.close();
41  DeserializeFromBinary(clCompileContext, context, device, binaryContent);
42 }
void DeserializeFromBinary(arm_compute::CLCompileContext &clCompileContext, cl::Context &context, cl::Device &device, const std::vector< uint8_t > &binaryContent)
Deserializes the CLCompileContext built-in programs from binary file contents.

◆ DeserializeFromBinary()

void DeserializeFromBinary ( arm_compute::CLCompileContext &  clCompileContext,
cl::Context &  context,
cl::Device &  device,
const std::vector< uint8_t > &  binaryContent 
)

Deserializes the CLCompileContext built-in programs from binary file contents.

Parameters
[in]clCompileContextThe CLCompileContext to be serialized
[in]contextThe CL Kernel context built-in program will be created from
[in]deviceThe CL Kernel device built-in program will be created from
[in]filePathThe serialized file

Definition at line 44 of file ClContextDeserializer.cpp.

References CHECK_LOCATION, and armnn::GetClContext().

Referenced by ClContextDeserializer::Deserialize().

48 {
49  if (binaryContent.data() == nullptr)
50  {
51  throw InvalidArgumentException(fmt::format("Invalid (null) binary content {}",
52  CHECK_LOCATION().AsString()));
53  }
54 
55  size_t binaryContentSize = binaryContent.size();
56  flatbuffers::Verifier verifier(binaryContent.data(), binaryContentSize);
57  if (verifier.VerifyBuffer<ClContext>() == false)
58  {
59  throw ParseException(fmt::format("Buffer doesn't conform to the expected Armnn "
60  "flatbuffers format. size:{0} {1}",
61  binaryContentSize,
62  CHECK_LOCATION().AsString()));
63  }
64  auto clContext = GetClContext(binaryContent.data());
65 
66  for (Program const* program : *clContext->programs())
67  {
68  auto programName = program->name()->c_str();
69  auto programBinary = program->binary();
70  std::vector<uint8_t> binary(programBinary->begin(), programBinary->begin() + programBinary->size());
71 
72  cl::Program::Binaries binaries{ binary };
73  std::vector<cl::Device> devices {device};
74  cl::Program theProgram(context, devices, binaries);
75  theProgram.build();
76  clCompileContext.add_built_program(programName, theProgram);
77  }
78 }
const armnn::ClContext * GetClContext(const void *buf)
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197

The documentation for this class was generated from the following files: