37 std::ifstream cache_file(filename, std::ios::binary);
38 if(cache_file.is_open())
45 while(!cache_file.eof())
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)
55 std::vector<char> tmp(name_len);
56 std::vector<unsigned char> binary(binary_len);
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);
63 cl::Program::Binaries binaries{ binary };
64 std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
65 cl::Program program(context, devices, binaries);
77 std::ofstream cache_file(filename, std::ios::binary);
78 if(cache_file.is_open())
82 std::vector<std::vector<unsigned char>> binaries = it.second.getInfo<CL_PROGRAM_BINARIES>();
85 size_t kernel_name_size = kernel_name.length();
86 size_t binary_size = binaries[0].size();
87 cache_file.write(reinterpret_cast<char *>(&kernel_name_size),
sizeof(
size_t));
88 cache_file.write(reinterpret_cast<char *>(&binary_size),
sizeof(
size_t));
89 cache_file.write(kernel_name.c_str(), kernel_name_size);
90 cache_file.write(reinterpret_cast<const char *>(binaries[0].data()), binaries[0].size());
void restore_program_cache_from_file(const std::string &filename="cache.bin")
This function loads prebuilt opencl kernels from a file.
void add_built_program(const std::string &built_program_name, const cl::Program &program)
Add a new built program to the cache.
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
bool is_initialised() const
Copyright (c) 2017-2021 Arm Limited.
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
cl::Context & context()
Accessor for the associated CL context.
void save_program_cache_to_file(const std::string &filename="cache.bin")
This function saves opencl kernels library to a file.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
void default_init(ICLTuner *cl_tuner=nullptr, CLGEMMHeuristicsHandle *gemm_h=nullptr)
Initialises the context and command queue used by the scheduler to default values and sets a default ...
const std::map< std::string, cl::Program > & get_built_programs() const
Access the cache of built OpenCL programs.