#include <ClContextDeserializer.hpp>
|
| 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...
|
|
Definition at line 13 of file ClContextDeserializer.hpp.
◆ ClContextDeserializer()
◆ ~ClContextDeserializer()
◆ 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] | clCompileContext | The CLCompileContext to be serialized |
[in] | context | The CL Kernel context built-in program will be created from |
[in] | device | The CL Kernel device built-in program will be created from |
[in] | filePath | The serialized file |
Definition at line 36 of file ClContextDeserializer.cpp.
41 std::vector<std::uint8_t> binaryContent;
42 #if !SERIALIZER_USE_MMAP
43 std::ifstream inputFileStream(filePath, std::ios::binary);
44 while (inputFileStream)
47 inputFileStream.get(input);
50 binaryContent.push_back(
static_cast<std::uint8_t
>(input));
53 inputFileStream.close();
56 int fp = open(filePath.c_str(),O_RDONLY);
59 ARMNN_LOG(error) << (std::string(
"Cannot open file ") + filePath);
63 const unsigned long dataSize =
static_cast<unsigned long>(statbuf.st_size);
64 binaryContent.resize(
static_cast<long unsigned int>(dataSize));
65 void* ptrmem = mmap(NULL, dataSize,PROT_READ,MAP_PRIVATE,fp,0);
66 if(ptrmem!=MAP_FAILED)
68 memcpy (binaryContent.data(), ptrmem, dataSize);
71 if(ptrmem == MAP_FAILED)
73 ARMNN_LOG(error) << (std::string(
"Cannot map file ") + filePath);
#define ARMNN_LOG(severity)
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.
References ARMNN_LOG, ClContextDeserializer::DeserializeFromBinary(), and armnn::error.
◆ 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] | clCompileContext | The CLCompileContext to be serialized |
[in] | context | The CL Kernel context built-in program will be created from |
[in] | device | The CL Kernel device built-in program will be created from |
[in] | filePath | The serialized file |
Definition at line 81 of file ClContextDeserializer.cpp.
86 if (binaryContent.data() ==
nullptr)
88 throw InvalidArgumentException(fmt::format(
"Invalid (null) binary content {}",
92 size_t binaryContentSize = binaryContent.size();
93 flatbuffers::Verifier verifier(binaryContent.data(), binaryContentSize);
94 if (verifier.VerifyBuffer<ClContext>() ==
false)
96 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn "
97 "flatbuffers format. size:{0} {1}",
103 for (Program
const* program : *clContext->programs())
105 const char*
volatile programName = program->name()->c_str();
106 auto programBinary = program->binary();
107 std::vector<uint8_t> binary(programBinary->begin(), programBinary->begin() + programBinary->size());
109 cl::Program::Binaries binaries{ binary };
110 std::vector<cl::Device> devices {device};
111 cl::Program theProgram(context, devices, binaries);
113 clCompileContext.add_built_program(programName, theProgram);
const armnn::ClContext * GetClContext(const void *buf)
References CHECK_LOCATION, and armnn::GetClContext().
Referenced by ClContextDeserializer::Deserialize().
The documentation for this class was generated from the following files: