32 std::deque<u64> last_device_builds;
34 u64 max_device_memsize;
35 u64 current_device_memsize = 0;
36 u64 current_host_memsize = 0;
40 : max_device_memsize(max_memsize), generator(generator) {}
43 inline bool offload_exist(
u64 id) {
return cache_offload.
has_key(
id); }
45 inline bool cache_entry_exist(
u64 id) {
return cache.
has_key(
id); }
48 ObjectCache tmp = ObjectCache::build_from_host(cache_offload.
get(
id));
49 cache_offload.
erase(
id);
50 current_host_memsize -= tmp.get_memsize();
59 current_device_memsize -= tmp.get_memsize();
66 current_host_memsize += c.get_memsize();
67 cache_offload.
add_obj(
id, std::forward<HostObjectCache>(c));
71 current_device_memsize += c.get_memsize();
72 cache.
add_obj(
id, std::forward<ObjectCache>(c));
73 last_device_builds.push_back(
id);
76 inline void offload_entry(
u64 id) {
78 push_offload(
id, std::move(tmp));
82 if (cache_offload.
has_key(
id)) {
83 return pop_offload(
id);
93 inline void offload_oldest() {
95 bool successful_pop =
false;
100 "the cache is empty no entry can be popped");
103 u64 last_id = last_device_builds.front();
104 last_device_builds.pop_front();
108 offload_entry(last_id);
110 successful_pop =
true;
112 "ObjectCacheHandler",
113 "offloaded cache for id =",
121 }
while (!successful_pop);
131 u64 add_sz = c.get_memsize();
133 if (add_sz + current_device_memsize > max_device_memsize) {
135 "their is no space within the imposed limit, try freeing some space in the "
136 "cache, or increase the size limit");
139 push_cache(
id, std::forward<ObjectCache>(c));
140 last_device_builds.push_back(
id);
154 u64 new_sz = new_cache.get_memsize();
156 while (new_sz + current_device_memsize > max_device_memsize) {
159 "their no space left to allocate a cache, try with smaller objects, or "
160 "increase the size limit");
163 "ObjectCacheHandler",
164 "The cache is too small, or the objects too big, some caches will "
165 "have to be recomputed on the fly");
169 push_new(
id, std::move(new_cache));
171 "ObjectCacheHandler",
172 "built cache for id =",
188 return cache.
get(
id);
191 return cache.
get(
id);
197 inline void reset() {
198 last_device_builds.clear();
200 cache_offload.
reset();
201 current_device_memsize = 0;
202 current_host_memsize = 0;