|
| 1 | +#include "ggml-remoting.h" |
| 2 | + |
| 3 | +static const char * ggml_backend_remoting_device_get_name(ggml_backend_dev_t dev) { |
| 4 | + UNUSED(dev); |
| 5 | + return "API Remoting"; |
| 6 | +} |
| 7 | + |
| 8 | +static const char * ggml_backend_remoting_device_get_description(ggml_backend_dev_t dev) { |
| 9 | + UNUSED(dev); |
| 10 | + return "API Remoting device"; |
| 11 | +} |
| 12 | + |
| 13 | +static enum ggml_backend_dev_type ggml_backend_remoting_device_get_type(ggml_backend_dev_t dev) { |
| 14 | + UNUSED(dev); |
| 15 | + return GGML_BACKEND_DEVICE_TYPE_GPU; |
| 16 | +} |
| 17 | + |
| 18 | +static void ggml_backend_remoting_device_get_memory(ggml_backend_dev_t device, size_t * free, size_t * total) { |
| 19 | + UNUSED(device); |
| 20 | + *total = 1024*1024*1024; |
| 21 | + *free = *total; |
| 22 | +} |
| 23 | + |
| 24 | +static bool ggml_backend_remoting_device_supports_op(ggml_backend_dev_t dev, const ggml_tensor * op) { |
| 25 | + UNUSED(dev); |
| 26 | + UNUSED(op); |
| 27 | + |
| 28 | + return true; |
| 29 | +} |
| 30 | + |
| 31 | +static bool ggml_backend_remoting_device_supports_buft(ggml_backend_dev_t dev, ggml_backend_buffer_type_t buft) { |
| 32 | + UNUSED(dev); |
| 33 | + UNUSED(buft); |
| 34 | + return true; |
| 35 | +} |
| 36 | + |
| 37 | +static bool ggml_backend_remoting_device_offload_op(ggml_backend_dev_t dev, const ggml_tensor * op) { |
| 38 | + const int min_batch_size = 32; |
| 39 | + |
| 40 | + return (op->ne[1] >= min_batch_size && op->op != GGML_OP_GET_ROWS) || |
| 41 | + (op->ne[2] >= min_batch_size && op->op == GGML_OP_MUL_MAT_ID); |
| 42 | + |
| 43 | + UNUSED(dev); |
| 44 | +} |
| 45 | + |
| 46 | +static ggml_backend_buffer_type_t ggml_backend_remoting_device_get_host_buffer_type(ggml_backend_dev_t dev) { |
| 47 | + UNUSED(dev); |
| 48 | + return ggml_backend_remoting_host_buffer_type(); |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +static void ggml_backend_remoting_device_get_props(ggml_backend_dev_t dev, struct ggml_backend_dev_props * props) { |
| 53 | + props->name = ggml_backend_remoting_device_get_name(dev); |
| 54 | + props->description = ggml_backend_remoting_device_get_description(dev); |
| 55 | + props->type = ggml_backend_remoting_device_get_type(dev); |
| 56 | + ggml_backend_remoting_device_get_memory(dev, &props->memory_free, &props->memory_total); |
| 57 | + props->caps = { |
| 58 | + /* .async = */ false, |
| 59 | + /* .host_buffer = */ true, |
| 60 | + /* .buffer_from_host_ptr = */ false, |
| 61 | + /* .events = */ false, |
| 62 | + }; |
| 63 | +} |
| 64 | + |
| 65 | +const struct ggml_backend_device_i ggml_backend_remoting_device_i = { |
| 66 | + /* .get_name = */ ggml_backend_remoting_device_get_name, |
| 67 | + /* .get_description = */ ggml_backend_remoting_device_get_description, |
| 68 | + /* .get_memory = */ ggml_backend_remoting_device_get_memory, |
| 69 | + /* .get_type = */ ggml_backend_remoting_device_get_type, |
| 70 | + /* .get_props = */ ggml_backend_remoting_device_get_props, |
| 71 | + /* .init_backend = */ ggml_backend_remoting_device_init, |
| 72 | + /* .get_buffer_type = */ ggml_backend_remoting_device_get_buffer_type, |
| 73 | + /* .get_host_buffer_type = */ ggml_backend_remoting_device_get_host_buffer_type, |
| 74 | + /* .buffer_from_host_ptr = */ NULL, |
| 75 | + /* .supports_op = */ ggml_backend_remoting_device_supports_op, |
| 76 | + /* .supports_buft = */ ggml_backend_remoting_device_supports_buft, |
| 77 | + /* .offload_op = */ ggml_backend_remoting_device_offload_op, |
| 78 | + /* .event_new = */ NULL, |
| 79 | + /* .event_free = */ NULL, |
| 80 | + /* .event_synchronize = */ NULL, |
| 81 | +}; |
0 commit comments