MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / virtgpu_handshake

Function virtgpu_handshake

external/ggml/src/ggml-virtgpu/virtgpu.cpp:31–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29const uint64_t APIR_LOADLIBRARY_MAX_WAIT_MS = 60 * 1000; // 60s
30
31static int virtgpu_handshake(virtgpu * gpu) {
32 apir_encoder * encoder;
33 apir_decoder * decoder;
34
35 encoder = remote_call_prepare(gpu, APIR_COMMAND_TYPE_HANDSHAKE, 0);
36 if (!encoder) {
37 GGML_ABORT(GGML_VIRTGPU "%s: failed to prepare the remote call encoder", __func__);
38 return 1;
39 }
40
41 /* write handshake props */
42
43 uint32_t guest_major = APIR_PROTOCOL_MAJOR;
44 uint32_t guest_minor = APIR_PROTOCOL_MINOR;
45 apir_encode_uint32_t(encoder, &guest_major);
46 apir_encode_uint32_t(encoder, &guest_minor);
47
48 /* *** */
49
50 uint32_t ret_magic;
51 long long call_duration_ns;
52 ret_magic = remote_call(gpu, encoder, &decoder, APIR_HANDSHAKE_MAX_WAIT_MS, &call_duration_ns);
53 log_call_duration(call_duration_ns, "API Remoting handshake");
54
55 if (!decoder) {
56 GGML_ABORT(GGML_VIRTGPU
57 "%s: failed to initiate the communication with the virglrenderer library. "
58 "Most likely, the wrong virglrenderer library was loaded in the hypervisor.",
59 __func__);
60 return 1;
61 }
62
63 /* read handshake return values */
64
65 uint32_t host_major;
66 uint32_t host_minor;
67
68 if (ret_magic != APIR_HANDSHAKE_MAGIC) {
69 GGML_ABORT(GGML_VIRTGPU "%s: handshake with the virglrenderer failed (code=%d | %s)", __func__, ret_magic,
70 apir_backend_initialize_error(ret_magic));
71 } else {
72 apir_decode_uint32_t(decoder, &host_major);
73 apir_decode_uint32_t(decoder, &host_minor);
74 }
75
76 remote_call_finish(gpu, encoder, decoder);
77
78 if (ret_magic != APIR_HANDSHAKE_MAGIC) {
79 return 1;
80 }
81
82 GGML_LOG_INFO(GGML_VIRTGPU "%s: Guest is running with %u.%u\n", __func__, guest_major, guest_minor);
83 GGML_LOG_INFO(GGML_VIRTGPU "%s: Host is running with %u.%u\n", __func__, host_major, host_minor);
84
85 if (guest_major != host_major) {
86 GGML_LOG_ERROR(GGML_VIRTGPU "Host major (%d) and guest major (%d) version differ\n", host_major, guest_major);
87 } else if (guest_minor != host_minor) {
88 GGML_LOG_WARN(GGML_VIRTGPU "Host minor (%d) and guest minor (%d) version differ\n", host_minor, guest_minor);

Callers 1

create_virtgpuFunction · 0.85

Calls 7

remote_call_prepareFunction · 0.85
apir_encode_uint32_tFunction · 0.85
remote_callFunction · 0.85
log_call_durationFunction · 0.85
apir_decode_uint32_tFunction · 0.85
remote_call_finishFunction · 0.85

Tested by

no test coverage detected