Skip to content

Commit 86587da

Browse files
authored
llama : check returned fn ptrs from ggml_backend_reg_get_proc_address (#15893)
This commit adds check for two function pointers returned from ggml_backend_reg_get_proc_address. The motivation for this is that the function pointer could be nullptr if the get proc address function changes in the future. This is also consistent with all the other calls to ggml_backend_reg_get_proc_address in the code base.
1 parent ff02caf commit 86587da

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/llama-context.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,9 @@ ggml_status llama_context::graph_compute(
14471447
if (backend_cpu != nullptr) {
14481448
auto * reg = ggml_backend_dev_backend_reg(ggml_backend_get_device(backend_cpu));
14491449
auto * set_threadpool_fn = (decltype(ggml_backend_cpu_set_threadpool) *) ggml_backend_reg_get_proc_address(reg, "ggml_backend_cpu_set_threadpool");
1450-
set_threadpool_fn(backend_cpu, tp);
1450+
if (set_threadpool_fn) {
1451+
set_threadpool_fn(backend_cpu, tp);
1452+
}
14511453
}
14521454

14531455
// set the number of threads for all the backends

src/llama.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ void llama_numa_init(enum ggml_numa_strategy numa) {
8383
GGML_ASSERT(dev && "CPU backend is not loaded");
8484
auto * reg = ggml_backend_dev_backend_reg(dev);
8585
auto * numa_init_fn = (decltype(ggml_numa_init) *) ggml_backend_reg_get_proc_address(reg, "ggml_backend_cpu_numa_init");
86-
numa_init_fn(numa);
86+
if (numa_init_fn) {
87+
numa_init_fn(numa);
88+
}
8789
}
8890
}
8991

0 commit comments

Comments
 (0)