13 #include <flatbuffers/flexbuffers.h>
15 #include <fmt/format.h>
23 #if defined(__linux__)
24 #define SERIALIZER_USE_MMAP 1
25 #if SERIALIZER_USE_MMAP
39 const std::string& filePath)
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);
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)
84 const std::vector<uint8_t>& binaryContent)
86 if (binaryContent.data() ==
nullptr)
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);