summaryrefslogtreecommitdiff
path: root/llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
commitb333b06772c89d96aacb5490d6a219fba7c09cc6 (patch)
tree211df60083a5946baa2ed61d33d8121b7e251b06 /llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp
downloadllmnpc-b333b06772c89d96aacb5490d6a219fba7c09cc6.tar.gz
Engage!
Diffstat (limited to 'llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp')
-rw-r--r--llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp b/llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp
new file mode 100644
index 0000000..c7acb8b
--- /dev/null
+++ b/llama.cpp/ggml/src/ggml-virtgpu/backend/backend-dispatched-device.cpp
@@ -0,0 +1,148 @@
+#include "backend-dispatched.h"
+#include "backend-virgl-apir.h"
+#include "ggml-backend-impl.h"
+#include "ggml-backend.h"
+#include "ggml-impl.h"
+
+#include <cstdint>
+
+uint32_t backend_device_get_device_count(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ int32_t dev_count = reg->iface.get_device_count(reg);
+ apir_encode_int32_t(enc, &dev_count);
+
+ return 0;
+}
+
+uint32_t backend_device_get_count(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ int32_t dev_count = reg->iface.get_device_count(reg);
+ apir_encode_int32_t(enc, &dev_count);
+
+ return 0;
+}
+
+uint32_t backend_device_get_name(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ const char * string = dev->iface.get_name(dev);
+
+ const size_t string_size = strlen(string) + 1;
+ apir_encode_array_size(enc, string_size);
+ apir_encode_char_array(enc, string, string_size);
+
+ return 0;
+}
+
+uint32_t backend_device_get_description(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ const char * string = dev->iface.get_description(dev);
+
+ const size_t string_size = strlen(string) + 1;
+ apir_encode_array_size(enc, string_size);
+ apir_encode_char_array(enc, string, string_size);
+
+ return 0;
+}
+
+uint32_t backend_device_get_type(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ uint32_t type = dev->iface.get_type(dev);
+ apir_encode_uint32_t(enc, &type);
+
+ return 0;
+}
+
+uint32_t backend_device_get_memory(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ size_t free, total;
+ dev->iface.get_memory(dev, &free, &total);
+
+ apir_encode_size_t(enc, &free);
+ apir_encode_size_t(enc, &total);
+
+ return 0;
+}
+
+uint32_t backend_device_supports_op(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+
+ const ggml_tensor * op = apir_decode_ggml_tensor_inplace(dec);
+
+ bool supports_op = dev->iface.supports_op(dev, op);
+
+ apir_encode_bool_t(enc, &supports_op);
+
+ return 0;
+}
+
+uint32_t backend_device_get_buffer_type(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ ggml_backend_buffer_type_t bufft = dev->iface.get_buffer_type(dev);
+
+ apir_encode_ggml_buffer_type(enc, bufft);
+
+ return 0;
+}
+
+uint32_t backend_device_get_props(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ ggml_backend_dev_props props;
+ dev->iface.get_props(dev, &props);
+
+ apir_encode_bool_t(enc, &props.caps.async);
+ apir_encode_bool_t(enc, &props.caps.host_buffer);
+ apir_encode_bool_t(enc, &props.caps.buffer_from_host_ptr);
+ apir_encode_bool_t(enc, &props.caps.events);
+
+ return 0;
+}
+
+uint32_t backend_device_buffer_from_ptr(apir_encoder * enc, apir_decoder * dec, virgl_apir_context * ctx) {
+ GGML_UNUSED(ctx);
+ GGML_UNUSED(dec);
+
+ uint32_t shmem_res_id;
+ apir_decode_virtgpu_shmem_res_id(dec, &shmem_res_id);
+
+ void * shmem_ptr = ctx->iface->get_shmem_ptr(ctx->ctx_id, shmem_res_id);
+ if (!shmem_ptr) {
+ GGML_LOG_ERROR(GGML_VIRTGPU_BCK "%s: Couldn't get the shmem addr from virgl\n", __func__);
+ apir_decoder_set_fatal(dec);
+ return 1;
+ }
+
+ size_t size;
+ apir_decode_size_t(dec, &size);
+ size_t max_tensor_size;
+ apir_decode_size_t(dec, &max_tensor_size);
+
+ ggml_backend_buffer_t buffer;
+ buffer = dev->iface.buffer_from_host_ptr(dev, shmem_ptr, size, max_tensor_size);
+
+ apir_encode_ggml_buffer(enc, buffer);
+ apir_encode_ggml_buffer_type(enc, buffer->buft);
+
+ if (buffer) {
+ apir_track_backend_buffer(buffer);
+ }
+
+ return 0;
+}