1+ #include " ../../../dataStructure/hashtable/hashtable.h"
2+ #include " ../../../include/libCacheSim/evictionAlgo.h"
3+
4+ // Include the generated logic
5+ #include " LLMCode.hpp"
6+
7+ #ifdef __cplusplus
8+ extern " C" {
9+ #endif
10+
11+ typedef struct {
12+ CacheManager* manager;
13+ } FullCodeEvolve_params_t;
14+
15+ // function declarations
16+ static void FullCodeEvolve_free (cache_t *cache);
17+ static bool FullCodeEvolve_get (cache_t *cache, const request_t *req);
18+ static cache_obj_t *FullCodeEvolve_find (cache_t *cache, const request_t *req, const bool update_cache);
19+ static cache_obj_t *FullCodeEvolve_insert (cache_t *cache, const request_t *req);
20+ static cache_obj_t *FullCodeEvolve_to_evict (cache_t *cache, const request_t *req);
21+ static void FullCodeEvolve_evict (cache_t *cache, const request_t *req);
22+ static bool FullCodeEvolve_remove (cache_t *cache, const obj_id_t obj_id);
23+ static void FullCodeEvolve_print_cache (const cache_t *cache);
24+
25+ // ***********************************************************************
26+ // **** end user facing functions ****
27+ // **** init, free, get ****
28+ // ***********************************************************************
29+ /* *
30+ * @brief initialize a FullCodeEvolve cache
31+ *
32+ * @param ccache_params some common cache parameters
33+ * @param cache_specific_params FullCodeEvolve specific parameters, should be NULL
34+ */
35+ cache_t *FullCodeEvolve_init (const common_cache_params_t ccache_params,
36+ const char *cache_specific_params) {
37+ cache_t *cache =
38+ cache_struct_init (" FullCodeEvolve" , ccache_params, cache_specific_params);
39+ cache->cache_init = FullCodeEvolve_init;
40+ cache->cache_free = FullCodeEvolve_free;
41+ cache->get = cache_get_base;
42+ cache->find = FullCodeEvolve_find;
43+ cache->insert = FullCodeEvolve_insert;
44+ cache->evict = FullCodeEvolve_evict;
45+ cache->remove = FullCodeEvolve_remove;
46+ cache->to_evict = FullCodeEvolve_to_evict;
47+ cache->get_occupied_byte = cache_get_occupied_byte_default;
48+ cache->can_insert = cache_can_insert_default;
49+ cache->get_n_obj = cache_get_n_obj_default;
50+ cache->print_cache = FullCodeEvolve_print_cache;
51+
52+ if (ccache_params.consider_obj_metadata ) {
53+ cache->obj_md_size = 8 * 2 ;
54+ } else {
55+ cache->obj_md_size = 0 ;
56+ }
57+
58+ FullCodeEvolve_params_t* params = (FullCodeEvolve_params_t*) malloc (sizeof (FullCodeEvolve_params_t));
59+ params->manager = new CacheManager ();
60+ cache->eviction_params = params;
61+ return cache;
62+ }
63+
64+ // ***********************************************************************
65+ // **** developer facing APIs (used by cache developer) ****
66+ // ***********************************************************************
67+
68+ /* *
69+ * @brief check whether an object is in the cache
70+ *
71+ * @param cache
72+ * @param req
73+ * @param update_cache whether to update the cache,
74+ * if true, the object is promoted
75+ * and if the object is expired, it is removed from the cache
76+ * @return true on hit, false on miss
77+ */
78+ static cache_obj_t *FullCodeEvolve_find (cache_t *cache, const request_t *req,
79+ const bool update_cache) {
80+ assert (update_cache);
81+ FullCodeEvolve_params_t *params = (FullCodeEvolve_params_t *)cache->eviction_params ;
82+ cache_obj_t *cache_obj = cache_find_base (cache, req, update_cache);
83+
84+ bool cache_obj_LLM = params->manager ->find (req->obj_id );
85+
86+ // correctness checks: either both reference cache+LLM Cache (a) find object, or (b) miss object.
87+ if (cache_obj) assert (cache_obj_LLM);
88+ else assert (!cache_obj_LLM);
89+
90+ return cache_obj;
91+ }
92+
93+ /* *
94+ * @brief insert an object into the cache,
95+ * update the hash table and cache metadata
96+ * this function assumes the cache has enough space
97+ * and eviction is not part of this function
98+ *
99+ * @param cache
100+ * @param req
101+ * @return the inserted object
102+ */
103+ static cache_obj_t *FullCodeEvolve_insert (cache_t *cache, const request_t *req) {
104+ FullCodeEvolve_params_t *params = (FullCodeEvolve_params_t *)cache->eviction_params ;
105+
106+ cache_obj_t *obj = cache_insert_base (cache, req);
107+ params->manager ->insert (req->obj_id );
108+
109+ return obj;
110+ }
111+
112+ /* *
113+ * @brief evict an object from the cache
114+ * it needs to call cache_evict_base before returning
115+ * which updates some metadata such as n_obj, occupied size, and hash table
116+ *
117+ * @param cache
118+ * @param req not used
119+ */
120+ static void FullCodeEvolve_evict (cache_t *cache, const request_t *req) {
121+ FullCodeEvolve_params_t *params = (FullCodeEvolve_params_t *)cache->eviction_params ;
122+ obj_id_t victim_id = params->manager ->evict ();
123+
124+ request_t fake_req = {};
125+ fake_req.obj_id = victim_id;
126+
127+ cache_obj_t * victim = cache_find_base (cache, &fake_req, false );
128+ if (victim){
129+ cache_evict_base (cache, victim, true );
130+ }
131+ else assert (false );
132+ }
133+
134+ static void FullCodeEvolve_free (cache_t *cache) {
135+ FullCodeEvolve_params_t *params = (FullCodeEvolve_params_t *)cache->eviction_params ;
136+
137+ delete params->manager ;
138+ free (params);
139+ cache->eviction_params = nullptr ;
140+
141+ cache_struct_free (cache);
142+ }
143+
144+
145+ static void FullCodeEvolve_remove_obj (cache_t *cache, cache_obj_t *obj) {
146+ assert (false );
147+ }
148+
149+ static bool FullCodeEvolve_remove (cache_t *cache, const obj_id_t obj_id) {
150+ assert (false );
151+ }
152+
153+ static void FullCodeEvolve_print_cache (const cache_t *cache) {
154+ assert (false );
155+ }
156+
157+ static cache_obj_t *FullCodeEvolve_to_evict (cache_t *cache, const request_t *req) {
158+ assert (false );
159+ return new cache_obj_t ();
160+ }
161+
162+ #ifdef __cplusplus
163+ }
164+ #endif
0 commit comments