| 33 | namespace arm_compute |
| 34 | { |
| 35 | void restore_program_cache_from_file(const std::string &filename) |
| 36 | { |
| 37 | std::ifstream cache_file(filename, std::ios::binary); |
| 38 | if (cache_file.is_open()) |
| 39 | { |
| 40 | if (!CLScheduler::get().is_initialised()) |
| 41 | { |
| 42 | arm_compute::CLScheduler::get().default_init(); |
| 43 | } |
| 44 | |
| 45 | while (!cache_file.eof()) |
| 46 | { |
| 47 | size_t name_len = 0; |
| 48 | size_t binary_len = 0; |
| 49 | cache_file.read(reinterpret_cast<char *>(&name_len), sizeof(size_t)); |
| 50 | cache_file.read(reinterpret_cast<char *>(&binary_len), sizeof(size_t)); |
| 51 | if (name_len == 0 || binary_len == 0) |
| 52 | { |
| 53 | break; |
| 54 | } |
| 55 | std::vector<char> tmp(name_len); |
| 56 | std::vector<unsigned char> binary(binary_len); |
| 57 | std::string name; |
| 58 | cache_file.read(tmp.data(), name_len); |
| 59 | name.assign(tmp.data(), name_len); |
| 60 | tmp.resize(binary_len); |
| 61 | cache_file.read(reinterpret_cast<char *>(binary.data()), binary_len); |
| 62 | cl::Context context = arm_compute::CLScheduler::get().context(); |
| 63 | cl::Program::Binaries binaries{binary}; |
| 64 | std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>(); |
| 65 | cl::Program program(context, devices, binaries); |
| 66 | program.build(); |
| 67 | CLKernelLibrary::get().add_built_program(name, program); |
| 68 | } |
| 69 | cache_file.close(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void save_program_cache_to_file(const std::string &filename) |
| 74 | { |
no test coverage detected