char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
153d324bc
char/aliceai-t5-moe
1#include "backend-dispatched.h" 2#include "backend-virgl-apir.h" 3#include "ggml-backend-impl.h" 4#include "ggml-backend.h" 5#include "ggml-impl.h" 6 7#include <cstdint> 8 9uint32_t backend_device_get_device_count (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 10GGML_UNUSED (ctx ); 11GGML_UNUSED (ctx ); 12GGML_UNUSED (dec ); 13 14int32_t dev_count = reg -> iface .get_device_count (reg ); 15apir_encode_int32_t (enc ,& dev_count ); 16 17return 0 ; 18} 19 20uint32_t backend_device_get_count (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 21GGML_UNUSED (ctx ); 22GGML_UNUSED (ctx ); 23GGML_UNUSED (dec ); 24 25int32_t dev_count = reg -> iface .get_device_count (reg ); 26apir_encode_int32_t (enc ,& dev_count ); 27 28return 0 ; 29} 30 31uint32_t backend_device_get_name (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 32GGML_UNUSED (ctx ); 33GGML_UNUSED (dec ); 34 35const char * string = dev -> iface .get_name (dev ); 36 37const size_t string_size = strlen (string )+ 1 ; 38apir_encode_array_size (enc ,string_size ); 39apir_encode_char_array (enc ,string ,string_size ); 40 41return 0 ; 42} 43 44uint32_t backend_device_get_description (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 45GGML_UNUSED (ctx ); 46GGML_UNUSED (dec ); 47 48const char * string = dev -> iface .get_description (dev ); 49 50const size_t string_size = strlen (string )+ 1 ; 51apir_encode_array_size (enc ,string_size ); 52apir_encode_char_array (enc ,string ,string_size ); 53 54return 0 ; 55} 56 57uint32_t backend_device_get_type (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 58GGML_UNUSED (ctx ); 59GGML_UNUSED (dec ); 60 61uint32_t type = dev -> iface .get_type (dev ); 62apir_encode_uint32_t (enc ,& type ); 63 64return 0 ; 65} 66 67uint32_t backend_device_get_memory (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 68GGML_UNUSED (ctx ); 69GGML_UNUSED (dec ); 70 71size_t free ,total ; 72dev -> iface .get_memory (dev ,& free ,& total ); 73 74apir_encode_size_t (enc ,& free ); 75apir_encode_size_t (enc ,& total ); 76 77return 0 ; 78} 79 80uint32_t backend_device_supports_op (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 81GGML_UNUSED (ctx ); 82 83const ggml_tensor * op = apir_decode_ggml_tensor_inplace (dec ); 84 85bool supports_op = dev -> iface .supports_op (dev ,op ); 86 87apir_encode_bool_t (enc ,& supports_op ); 88 89return 0 ; 90} 91 92uint32_t backend_device_get_buffer_type (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 93GGML_UNUSED (ctx ); 94GGML_UNUSED (dec ); 95 96ggml_backend_buffer_type_t bufft = dev -> iface .get_buffer_type (dev ); 97 98apir_encode_ggml_buffer_type (enc ,bufft ); 99 100return 0 ; 101} 102 103uint32_t backend_device_get_props (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 104GGML_UNUSED (ctx ); 105GGML_UNUSED (dec ); 106 107ggml_backend_dev_props props ; 108dev -> iface .get_props (dev ,& props ); 109 110apir_encode_bool_t (enc ,& props .caps .async ); 111apir_encode_bool_t (enc ,& props .caps .host_buffer ); 112apir_encode_bool_t (enc ,& props .caps .buffer_from_host_ptr ); 113apir_encode_bool_t (enc ,& props .caps .events ); 114apir_encode_bool_t (enc ,& props .caps .mmap_support ); 115 116return 0 ; 117} 118 119uint32_t backend_device_buffer_from_ptr (apir_encoder * enc ,apir_decoder * dec ,virgl_apir_context * ctx ) { 120GGML_UNUSED (ctx ); 121GGML_UNUSED (dec ); 122 123uint32_t shmem_res_id ; 124apir_decode_virtgpu_shmem_res_id (dec ,& shmem_res_id ); 125 126void * shmem_ptr = ctx -> iface -> get_shmem_ptr (ctx -> ctx_id ,shmem_res_id ); 127if (!shmem_ptr ) { 128GGML_LOG_ERROR (GGML_VIRTGPU_BCK "%s: Couldn't get the shmem addr from virgl\n" ,__func__ ); 129apir_decoder_set_fatal (dec ); 130return 1 ; 131 } 132 133size_t size ; 134apir_decode_size_t (dec ,& size ); 135size_t max_tensor_size ; 136apir_decode_size_t (dec ,& max_tensor_size ); 137 138ggml_backend_buffer_t buffer ; 139buffer = dev -> iface .buffer_from_host_ptr (dev ,shmem_ptr ,size ,max_tensor_size ); 140 141apir_encode_ggml_buffer (enc ,buffer ); 142apir_encode_ggml_buffer_type (enc ,buffer -> buft ); 143 144if (buffer ) { 145apir_track_backend_buffer (buffer ); 146 } 147 148return 0 ; 149}