Skip to content

Commit bc94ca2

Browse files
committed
llama : allow llama_memory_(nullptr)
ggml-ci
1 parent 0a1f017 commit bc94ca2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/llama-context.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,10 @@ llama_memory_t llama_get_memory(const struct llama_context * ctx) {
24282428
}
24292429

24302430
void llama_memory_clear(llama_memory_t mem) {
2431+
if (!mem) {
2432+
return;
2433+
}
2434+
24312435
mem->clear();
24322436
}
24332437

@@ -2436,6 +2440,10 @@ bool llama_memory_seq_rm(
24362440
llama_seq_id seq_id,
24372441
llama_pos p0,
24382442
llama_pos p1) {
2443+
if (!mem) {
2444+
return true;
2445+
}
2446+
24392447
return mem->seq_rm(seq_id, p0, p1);
24402448
}
24412449

@@ -2445,12 +2453,20 @@ void llama_memory_seq_cp(
24452453
llama_seq_id seq_id_dst,
24462454
llama_pos p0,
24472455
llama_pos p1) {
2456+
if (!mem) {
2457+
return;
2458+
}
2459+
24482460
mem->seq_cp(seq_id_src, seq_id_dst, p0, p1);
24492461
}
24502462

24512463
void llama_memory_seq_keep(
24522464
llama_memory_t mem,
24532465
llama_seq_id seq_id) {
2466+
if (!mem) {
2467+
return;
2468+
}
2469+
24542470
mem->seq_keep(seq_id);
24552471
}
24562472

@@ -2460,6 +2476,10 @@ void llama_memory_seq_add(
24602476
llama_pos p0,
24612477
llama_pos p1,
24622478
llama_pos delta) {
2479+
if (!mem) {
2480+
return;
2481+
}
2482+
24632483
mem->seq_add(seq_id, p0, p1, delta);
24642484
}
24652485

@@ -2469,22 +2489,38 @@ void llama_memory_seq_div(
24692489
llama_pos p0,
24702490
llama_pos p1,
24712491
int d) {
2492+
if (!mem) {
2493+
return;
2494+
}
2495+
24722496
mem->seq_div(seq_id, p0, p1, d);
24732497
}
24742498

24752499
llama_pos llama_memory_seq_pos_min(
24762500
llama_memory_t mem,
24772501
llama_seq_id seq_id) {
2502+
if (!mem) {
2503+
return -1;
2504+
}
2505+
24782506
return mem->seq_pos_min(seq_id);
24792507
}
24802508

24812509
llama_pos llama_memory_seq_pos_max(
24822510
llama_memory_t mem,
24832511
llama_seq_id seq_id) {
2512+
if (!mem) {
2513+
return -1;
2514+
}
2515+
24842516
return mem->seq_pos_max(seq_id);
24852517
}
24862518

24872519
bool llama_memory_can_shift(llama_memory_t mem) {
2520+
if (!mem) {
2521+
return false;
2522+
}
2523+
24882524
return mem->get_can_shift();
24892525
}
24902526

0 commit comments

Comments
 (0)