char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Kevin Pougetggml-virtgpu: improve the reliability of the code (#19846)ffaafde16

char/aliceai-t5-moe
2.8 KiB36 linesraw
1#pragma once
2
3// clang-format off
4#include "virtgpu.h"
5#include "ggml-remoting.h"
6#include "backend/shared/apir_backend.h"
7#include "backend/shared/apir_cs_ggml.h"
8#include "ggml-backend-impl.h"
9// clang-format on
10
11#define REMOTE_CALL_PREPARE(gpu_dev_name, encoder_name, apir_command_type__)                                           \
12    int32_t      REMOTE_CALL_PREPARE_forward_flag = (int32_t) apir_command_type__;                                     \
13    const char * REMOTE_CALL_PREPARE_command_name = apir_dispatch_command_name(apir_command_type__);                   \
14    do {                                                                                                               \
15        encoder_name = remote_call_prepare(gpu_dev_name, APIR_COMMAND_TYPE_FORWARD, REMOTE_CALL_PREPARE_forward_flag); \
16        if (!encoder_name) {                                                                                           \
17            GGML_ABORT(GGML_VIRTGPU "%s: failed to prepare the remote call encoder", __func__);                        \
18        }                                                                                                              \
19    } while (0)
20
21#define REMOTE_CALL(gpu_dev_name, encoder_name, decoder_name, ret_name)                                     \
22    do {                                                                                                    \
23        ret_name = (ApirForwardReturnCode) remote_call(gpu_dev_name, encoder_name, &decoder_name, 0, NULL); \
24        if (!decoder_name) {                                                                                \
25            GGML_ABORT(GGML_VIRTGPU "%s: failed to kick the remote call", __func__);                        \
26        }                                                                                                   \
27        if (ret_name < APIR_FORWARD_BASE_INDEX) {                                                           \
28            GGML_ABORT(GGML_VIRTGPU "%s: failed to forward the API call: %s: code %d", __func__,            \
29                       apir_forward_error(ret_name), ret_name);                                             \
30        }                                                                                                   \
31        ret_name = (ApirForwardReturnCode) (ret_name - APIR_FORWARD_BASE_INDEX);                            \
32        if (ret_name != 0) {                                                                                \
33            GGML_ABORT(GGML_VIRTGPU "backend function '%s' failed (return code: %d)",                       \
34                       REMOTE_CALL_PREPARE_command_name, ret_name);                                         \
35        }                                                                                                   \
36    } while (0)