}
llama_context::~llama_context() {
+ // wait for any pending asynchronous copies into the output buffers before they are freed
+ synchronize();
+
if (!model.hparams.no_alloc) {
for (size_t i = 0; i < backend_ptrs.size(); ++i) {
ggml_backend_t backend = backend_ptrs[i];
// micro-batching is not possible for non-causal encoding, so we process the batch in a single shot
GGML_ASSERT(cparams.n_ubatch >= n_tokens && "encoder requires n_ubatch >= n_tokens");
+ // TODO: this clear of the buffer can easily be forgotten - need something better
+ // sync first so any in-flight async copies into embd_seq complete before it is freed
+ if (!embd_seq.empty()) {
+ synchronize();
+ }
+ embd_seq.clear();
+
if (t_compute_start_us == 0) {
t_compute_start_us = ggml_time_us();
}
- // TODO: this clear of the buffer can easily be forgotten - need something better
- embd_seq.clear();
-
sched_reserve();
n_queued_tokens += n_tokens;
GGML_ASSERT((cparams.causal_attn || cparams.n_ubatch >= n_tokens_all) && "non-causal attention requires n_ubatch >= n_tokens");
+ // TODO: this clear of the buffer can easily be forgotten - need something better
+ // sync first so any in-flight async copies into embd_seq complete before it is freed
+ if (!embd_seq.empty()) {
+ synchronize();
+ }
+ embd_seq.clear();
+
if (t_compute_start_us == 0) {
t_compute_start_us = ggml_time_us();
}
n_queued_tokens += n_tokens_all;
- // TODO: this clear of the buffer can easily be forgotten - need something better
- embd_seq.clear();
output_swaps.clear();
sched_reserve();