|
10 | 10 | #include "shared/apir_backend.h" |
11 | 11 | #include "shared/venus_cs.h" |
12 | 12 |
|
13 | | -#define USE_METAL 1 |
14 | | - |
15 | | -#if USE_METAL |
16 | | -#define GGML_BACKEND_LIBRARY_PATH "/Users/kevinpouget/remoting/llama_cpp/build.remoting-backend/bin/libggml-metal.dylib" |
17 | | -#define GGML_BACKEND_REG_FCT_NAME "ggml_backend_metal_reg" |
18 | | -#define GGML_BACKEND_INIT_FCT_NAME "ggml_backend_metal_init" |
19 | | -#else |
20 | | -#define GGML_BACKEND_LIBRARY_PATH "/Users/kevinpouget/remoting/llama_cpp/build.remoting-backend/bin/libggml-vulkan.dylib" |
21 | | -#define GGML_BACKEND_REG_FCT_NAME "ggml_backend_vk_reg" |
22 | | -#define GGML_BACKEND_INIT_FCT_NAME "ggml_backend_vk_init" |
23 | | -#endif |
| 13 | +#define GGML_BACKEND_LIBRARY_PATH_ENV "APIR_LLAMA_CPP_GGML_LIBRARY_PATH" |
| 14 | +#define GGML_BACKEND_LIBRARY_REG_ENV "APIR_LLAMA_CPP_GGML_LIBRARY_REG" |
| 15 | +#define GGML_BACKEND_LIBRARY_INIT_ENV "APIR_LLAMA_CPP_GGML_LIBRARY_INIT" |
| 16 | + |
24 | 17 |
|
25 | 18 | static void *backend_library_handle = NULL; |
26 | 19 |
|
@@ -52,25 +45,47 @@ extern "C" { |
52 | 45 | uint32_t apir_backend_initialize() { |
53 | 46 | const char* dlsym_error; |
54 | 47 |
|
55 | | - INFO("%s: hello " GGML_BACKEND_REG_FCT_NAME " :wave: \\o/", __func__); |
| 48 | + const char* library_name = getenv(GGML_BACKEND_LIBRARY_PATH_ENV); |
| 49 | + const char* library_reg = getenv(GGML_BACKEND_LIBRARY_REG_ENV); |
| 50 | + const char* library_init = getenv(GGML_BACKEND_LIBRARY_INIT_ENV); |
| 51 | + |
| 52 | + INFO("%s: loading %s (%s|%s)", __func__, library_name, library_reg, library_init); |
| 53 | + |
| 54 | + if (!library_name) { |
| 55 | + ERROR("Cannot open library: env var '%s' not defined\n", GGML_BACKEND_LIBRARY_PATH_ENV); |
56 | 56 |
|
57 | | - backend_library_handle = dlopen(GGML_BACKEND_LIBRARY_PATH, RTLD_LAZY); |
| 57 | + return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY; |
| 58 | + } |
| 59 | + |
| 60 | + backend_library_handle = dlopen(library_name, RTLD_LAZY); |
58 | 61 |
|
59 | 62 | if (!backend_library_handle) { |
60 | 63 | ERROR("Cannot open library: %s\n", dlerror()); |
61 | 64 |
|
62 | 65 | return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY; |
63 | 66 | } |
64 | 67 |
|
65 | | - void *ggml_backend_reg_fct = dlsym(backend_library_handle, GGML_BACKEND_REG_FCT_NAME); |
| 68 | + if (!library_reg) { |
| 69 | + ERROR("Cannot register library: env var '%s' not defined\n", GGML_BACKEND_LIBRARY_REG_ENV); |
| 70 | + |
| 71 | + return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY; |
| 72 | + } |
| 73 | + |
| 74 | + void *ggml_backend_reg_fct = dlsym(backend_library_handle, library_reg); |
66 | 75 | dlsym_error = dlerror(); |
67 | 76 | if (dlsym_error) { |
68 | 77 | ERROR("Cannot load symbol: %s\n", dlsym_error); |
69 | 78 |
|
70 | 79 | return APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS; |
71 | 80 | } |
72 | 81 |
|
73 | | - void *ggml_backend_init_fct = dlsym(backend_library_handle, GGML_BACKEND_INIT_FCT_NAME); |
| 82 | + if (!library_init) { |
| 83 | + ERROR("Cannot initialize library: env var '%s' not defined\n", library_init); |
| 84 | + |
| 85 | + return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY; |
| 86 | + } |
| 87 | + |
| 88 | + void *ggml_backend_init_fct = dlsym(backend_library_handle, library_init); |
74 | 89 | dlsym_error = dlerror(); |
75 | 90 | if (dlsym_error) { |
76 | 91 | ERROR("Cannot load symbol: %s\n", dlsym_error); |
|
0 commit comments