| 511 | } |
| 512 | |
| 513 | llama_memory_context_ptr llama_kv_cache::init_batch( |
| 514 | llama_batch_allocr & balloc, |
| 515 | uint32_t n_ubatch, |
| 516 | bool embd_all) { |
| 517 | GGML_UNUSED(embd_all); |
| 518 | |
| 519 | do { |
| 520 | balloc.split_reset(); |
| 521 | |
| 522 | std::vector<llama_ubatch> ubatches; |
| 523 | while (true) { |
| 524 | auto ubatch = n_stream == 1 ? balloc.split_simple(n_ubatch) : balloc.split_equal(n_ubatch, true); |
| 525 | |
| 526 | if (ubatch.n_tokens == 0) { |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | ubatches.push_back(std::move(ubatch)); // NOLINT |
| 531 | } |
| 532 | |
| 533 | if (balloc.get_n_used() < balloc.get_n_tokens()) { |
| 534 | // failed to find a suitable split |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | auto sinfos = prepare(ubatches); |
| 539 | if (sinfos.empty()) { |
| 540 | break; |
| 541 | } |
| 542 | |
| 543 | return std::make_unique<llama_kv_cache_context>( |
| 544 | this, std::move(sinfos), std::move(ubatches)); |
| 545 | } while (false); |
| 546 | |
| 547 | return std::make_unique<llama_kv_cache_context>(LLAMA_MEMORY_STATUS_FAILED_PREPARE); |
| 548 | } |
| 549 | |
| 550 | llama_memory_context_ptr llama_kv_cache::init_full() { |
| 551 | return std::make_unique<llama_kv_cache_context>(this); |
no test coverage detected