From eb76f3e37993ab0c7d1c0d1c361245e1597690aa Mon Sep 17 00:00:00 2001 From: Self Denial Date: Mon, 15 Jan 2024 02:37:44 -0700 Subject: [PATCH] Fix CPU-only build under Android Termux enviornment. Update gpu.go initGPUHandles() to declare gpuHandles variable before reading it. This resolves an "invalid memory address or nil pointer dereference" error. Update dyn_ext_server.c to avoid setting the RTLD_DEEPBIND flag under __TERMUX__ (Android). --- gpu/gpu.go | 2 +- llm/dyn_ext_server.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gpu/gpu.go b/gpu/gpu.go index 4cfede8d..451b7557 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -63,6 +63,7 @@ func initGPUHandles() { // TODO - if the ollama build is CPU only, don't do these checks as they're irrelevant and confusing + gpuHandles = &handles{nil, nil} var cudaMgmtName string var cudaMgmtPatterns []string var rocmMgmtName string @@ -87,7 +88,6 @@ func initGPUHandles() { } slog.Info("Detecting GPU type") - gpuHandles = &handles{nil, nil} cudaLibPaths := FindGPULibs(cudaMgmtName, cudaMgmtPatterns) if len(cudaLibPaths) > 0 { cuda := LoadCUDAMgmt(cudaLibPaths) diff --git a/llm/dyn_ext_server.c b/llm/dyn_ext_server.c index e9aa3481..5807ca63 100644 --- a/llm/dyn_ext_server.c +++ b/llm/dyn_ext_server.c @@ -3,7 +3,7 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) && !defined(__TERMUX__) #include #define LOAD_LIBRARY(lib, flags) dlopen(lib, flags) #define LOAD_SYMBOL(handle, sym) dlsym(handle, sym)