char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
153d324bc
char/aliceai-t5-moe
1#include "virtgpu-forward-impl.h" 2#include "virtgpu-shm.h" 3 4int apir_device_get_count (virtgpu * gpu ) { 5apir_encoder * encoder ; 6apir_decoder * decoder ; 7ApirForwardReturnCode ret ; 8 9REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_COUNT ); 10REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 11 12int32_t dev_count = -1 ; 13apir_decode_int32_t (decoder ,& dev_count ); 14 15remote_call_finish (gpu ,encoder ,decoder ); 16 17return dev_count ; 18} 19 20char * apir_device_get_name (virtgpu * gpu ) { 21apir_encoder * encoder ; 22apir_decoder * decoder ; 23ApirForwardReturnCode ret ; 24 25REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_NAME ); 26REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 27 28const size_t string_size = apir_decode_array_size_unchecked (decoder ); 29char * string = (char * )apir_decoder_alloc_array (sizeof (char ),string_size ); 30if (!string ) { 31GGML_LOG_ERROR (GGML_VIRTGPU "%s: Could not allocate the device name buffer\n" ,__func__ ); 32return NULL ; 33 } 34apir_decode_char_array (decoder ,string ,string_size ); 35 36remote_call_finish (gpu ,encoder ,decoder ); 37 38return string ; 39} 40 41char * apir_device_get_description (virtgpu * gpu ) { 42apir_encoder * encoder ; 43apir_decoder * decoder ; 44ApirForwardReturnCode ret ; 45 46REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_DESCRIPTION ); 47 48REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 49 50const size_t string_size = apir_decode_array_size_unchecked (decoder ); 51char * string = (char * )apir_decoder_alloc_array (sizeof (char ),string_size ); 52if (!string ) { 53GGML_LOG_ERROR (GGML_VIRTGPU "%s: Could not allocate the device description buffer\n" ,__func__ ); 54 55return NULL ; 56 } 57apir_decode_char_array (decoder ,string ,string_size ); 58 59remote_call_finish (gpu ,encoder ,decoder ); 60 61return string ; 62} 63 64uint32_t apir_device_get_type (virtgpu * gpu ) { 65static uint32_t dev_type = 255 ; 66if (dev_type != 255 ) { 67return dev_type ; 68 } 69 70apir_encoder * encoder ; 71apir_decoder * decoder ; 72ApirForwardReturnCode ret ; 73 74REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_TYPE ); 75 76REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 77 78apir_decode_uint32_t (decoder ,& dev_type ); 79 80remote_call_finish (gpu ,encoder ,decoder ); 81 82return dev_type ; 83} 84 85void apir_device_get_memory (virtgpu * gpu ,size_t * free ,size_t * total ) { 86static size_t dev_free = 0 ; 87static size_t dev_total = 0 ; 88apir_encoder * encoder ; 89apir_decoder * decoder ; 90ApirForwardReturnCode ret ; 91 92REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_MEMORY ); 93 94REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 95 96apir_decode_size_t (decoder ,& dev_free ); 97apir_decode_size_t (decoder ,& dev_total ); 98 99* free = dev_free ; 100* total = dev_total ; 101 102remote_call_finish (gpu ,encoder ,decoder ); 103 104return ; 105} 106 107bool apir_device_supports_op (virtgpu * gpu ,const ggml_tensor * op ) { 108apir_encoder * encoder ; 109apir_decoder * decoder ; 110ApirForwardReturnCode ret ; 111 112REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_SUPPORTS_OP ); 113 114apir_encode_ggml_tensor_inline (encoder ,op ); 115 116REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 117 118bool supports_op ; 119apir_decode_bool_t (decoder ,& supports_op ); 120 121remote_call_finish (gpu ,encoder ,decoder ); 122 123return supports_op ; 124} 125 126apir_buffer_type_host_handle_t apir_device_get_buffer_type (virtgpu * gpu ) { 127apir_encoder * encoder ; 128apir_decoder * decoder ; 129ApirForwardReturnCode ret ; 130 131REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_BUFFER_TYPE ); 132 133REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 134 135apir_buffer_type_host_handle_t buft_handle ; 136apir_decode_apir_buffer_type_host_handle_t (decoder ,& buft_handle ); 137 138remote_call_finish (gpu ,encoder ,decoder ); 139 140return buft_handle ; 141} 142 143void apir_device_get_props (virtgpu * gpu , 144bool * async , 145bool * host_buffer , 146bool * buffer_from_host_ptr , 147bool * events , 148bool * mmap_support ) { 149apir_encoder * encoder ; 150apir_decoder * decoder ; 151ApirForwardReturnCode ret ; 152 153REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_GET_PROPS ); 154 155REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 156 157apir_decode_bool_t (decoder ,async ); 158apir_decode_bool_t (decoder ,host_buffer ); 159apir_decode_bool_t (decoder ,buffer_from_host_ptr ); 160apir_decode_bool_t (decoder ,events ); 161apir_decode_bool_t (decoder ,mmap_support ); 162 163remote_call_finish (gpu ,encoder ,decoder ); 164 165return ; 166} 167 168apir_buffer_context_t apir_device_buffer_from_ptr (virtgpu * gpu ,size_t size ,size_t max_tensor_size ) { 169apir_encoder * encoder ; 170apir_decoder * decoder ; 171ApirForwardReturnCode ret ; 172 173apir_buffer_context_t buffer_context ; 174 175REMOTE_CALL_PREPARE (gpu ,encoder ,APIR_COMMAND_TYPE_DEVICE_BUFFER_FROM_PTR ); 176 177if (virtgpu_shmem_create (gpu ,size ,& buffer_context .shmem )) { 178GGML_ABORT (GGML_VIRTGPU "%s: Couldn't allocate %ldb of guest-host shared buffer" ,__func__ ,size ); 179 } 180 181apir_encode_virtgpu_shmem_res_id (encoder ,buffer_context .shmem .res_id ); 182 183apir_encode_size_t (encoder ,& size ); 184apir_encode_size_t (encoder ,& max_tensor_size ); 185 186REMOTE_CALL (gpu ,encoder ,decoder ,ret ); 187 188apir_decode_apir_buffer_host_handle_t (decoder ,& buffer_context .host_handle ); 189buffer_context .buft_host_handle = apir_decode_apir_buffer_type_host_handle (decoder ); 190 191remote_call_finish (gpu ,encoder ,decoder ); 192 193return buffer_context ; 194}