TODO: will be removed with backend v2
| 6253 | |
| 6254 | // TODO: will be removed with backend v2 |
| 6255 | struct llm_offload_trie { |
| 6256 | struct node { |
| 6257 | ~node() { |
| 6258 | for (int i = 0; i < 256; ++i) { |
| 6259 | if (children[i]) { |
| 6260 | delete children[i]; |
| 6261 | } |
| 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | node * children[256] = { nullptr }; |
| 6266 | llm_offload_func_e func = OFFLOAD_FUNC_NOP; |
| 6267 | }; |
| 6268 | |
| 6269 | llm_offload_trie() { |
| 6270 | root = new node; |
| 6271 | } |
| 6272 | |
| 6273 | llm_offload_trie(const std::unordered_map<const char *, llm_offload_func_e> & map) { |
| 6274 | root = new node; |
| 6275 | |
| 6276 | for (const auto & kv : map) { |
| 6277 | add(kv.first, kv.second); |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | ~llm_offload_trie() { |
| 6282 | delete root; |
| 6283 | } |
| 6284 | |
| 6285 | void add(const char * name, llm_offload_func_e func) { |
| 6286 | node * cur = root; |
| 6287 | |
| 6288 | for (int i = 0; ; ++i) { |
| 6289 | const uint8_t c = name[i]; |
| 6290 | |
| 6291 | if (!c) { |
| 6292 | break; |
| 6293 | } |
| 6294 | |
| 6295 | if (!cur->children[c]) { |
| 6296 | cur->children[c] = new node; |
| 6297 | } |
| 6298 | |
| 6299 | cur = cur->children[c]; |
| 6300 | } |
| 6301 | |
| 6302 | cur->func = func; |
| 6303 | } |
| 6304 | |
| 6305 | llm_offload_func_e find(const char * name) const { |
| 6306 | const node * cur = root; |
| 6307 | |
| 6308 | for (int i = 0; ; ++i) { |
| 6309 | const uint8_t c = name[i]; |
| 6310 | |
| 6311 | if (!c) { |
| 6312 | break; |
nothing calls this directly
no outgoing calls
no test coverage detected