Skip to content

Commit 4888137

Browse files
authored
sycl : fix llama_kv_cache hang when kv_cache is huge: 5GB (ggml-org#21283)
1 parent fbd441c commit 4888137

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

ggml/src/ggml-sycl/ggml-sycl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,15 @@ static void ggml_backend_sycl_buffer_clear(ggml_backend_buffer_t buffer,
569569
SYCL_CHECK(
570570
CHECK_TRY_ERROR(dpct::get_current_device().queues_wait_and_throw()));
571571

572-
SYCL_CHECK(CHECK_TRY_ERROR((*stream)
573-
.memset(ctx->dev_ptr, value, buffer->size)
574-
.wait()));
572+
constexpr size_t MAX_CHUNK = 2ULL << 30; // 2 GiB
573+
for (size_t off = 0; off < buffer->size; off += MAX_CHUNK) {
574+
size_t chunk = std::min(buffer->size - off, MAX_CHUNK);
575+
SYCL_CHECK(CHECK_TRY_ERROR(
576+
(*stream)
577+
.memset(static_cast<char*>(ctx->dev_ptr) + off, value, chunk)
578+
.wait()
579+
));
580+
}
575581
}
576582
catch (sycl::exception const &exc) {
577583
std::cerr << exc.what() << "Exception caught at file:" << __FILE__

0 commit comments

Comments
 (0)