|
| 1 | +#include <iostream> |
| 2 | +#include <dlfcn.h> |
| 3 | + |
| 4 | +#include "ggml-remoting-backend.h" |
| 5 | + |
| 6 | +#include "ggml-impl.h" |
| 7 | +#include "ggml-backend-impl.h" |
| 8 | +#include "ggml-backend.h" |
| 9 | + |
| 10 | +#include "backend-internal.h" |
| 11 | + |
| 12 | +#define UNUSED GGML_UNUSED |
| 13 | + |
| 14 | +static size_t ggml_backend_remoting_reg_get_device_count(ggml_backend_reg_t reg) { |
| 15 | + UNUSED(reg); |
| 16 | + return 0; |
| 17 | +} |
| 18 | + |
| 19 | +static const char * ggml_backend_remoting_reg_get_name(ggml_backend_reg_t reg) { |
| 20 | + UNUSED(reg); |
| 21 | + return GGML_REMOTING_BACKEND_NAME; |
| 22 | +} |
| 23 | + |
| 24 | +static ggml_backend_dev_t ggml_backend_remoting_reg_get_device(ggml_backend_reg_t reg, size_t device) { |
| 25 | + UNUSED(reg); |
| 26 | + UNUSED(device); |
| 27 | + |
| 28 | + return NULL; |
| 29 | +} |
| 30 | + |
| 31 | +static const struct ggml_backend_reg_i ggml_backend_remoting_reg_i = { |
| 32 | + /* .get_name = */ ggml_backend_remoting_reg_get_name, |
| 33 | + /* .get_device_count = */ ggml_backend_remoting_reg_get_device_count, |
| 34 | + /* .get_device = */ ggml_backend_remoting_reg_get_device, |
| 35 | + /* .get_proc_address = */ NULL, |
| 36 | +}; |
| 37 | + |
| 38 | +ggml_backend_reg_t ggml_backend_remoting_backend_reg() { |
| 39 | + static ggml_backend_reg reg = { |
| 40 | + /* .api_version = */ GGML_BACKEND_API_VERSION, |
| 41 | + /* .iface = */ ggml_backend_remoting_reg_i, |
| 42 | + /* .context = */ nullptr, |
| 43 | + }; |
| 44 | + |
| 45 | + LOG("%s, hello :wave:", __func__); |
| 46 | + |
| 47 | + return ® |
| 48 | +} |
| 49 | + |
| 50 | +typedef ggml_backend_reg_t (*backend_reg_fct_t)(void); |
| 51 | + |
| 52 | +#define METAL_LIBRARY_PATH "/Users/kevinpouget/remoting/llama_cpp/build.remoting-backend/bin/libggml-metal.dylib" |
| 53 | +#define ENTRYPOINT_FCT_NAME "ggml_backend_metal_reg" |
| 54 | + |
| 55 | +extern "C" { |
| 56 | + void ggml_backend_remoting_backend_say_hello() { |
| 57 | + LOG("%s: hello :wave: \\o/", __func__); |
| 58 | + |
| 59 | + void * library_handle = dlopen(METAL_LIBRARY_PATH, RTLD_LAZY); |
| 60 | + |
| 61 | + if (!library_handle) { |
| 62 | + FATAL("Cannot open library: %s\n", dlerror()); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + backend_reg_fct_t entrypoint_fct = (backend_reg_fct_t) dlsym(library_handle, ENTRYPOINT_FCT_NAME); |
| 67 | + const char* dlsym_error = dlerror(); |
| 68 | + if (dlsym_error) { |
| 69 | + FATAL("Cannot load symbol: %s\n", dlsym_error); |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + ggml_backend_reg_t reg = entrypoint_fct(); |
| 74 | + LOG("%s: --> %s", __func__, reg->iface.get_name(reg)); |
| 75 | + |
| 76 | + dlclose(library_handle); |
| 77 | + } |
| 78 | +} |
0 commit comments