1#pragma once
 2
 3#include "apir_backend.gen.h"
 4
 5#include <stdint.h>  // for uintptr_t
 6#include <time.h>    // for timespec, clock_gettime
 7
 8#define APIR_BACKEND_INITIALIZE_SUCCESS                     0
 9#define APIR_BACKEND_INITIALIZE_CANNOT_OPEN_BACKEND_LIBRARY 1
10#define APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY    2
11#define APIR_BACKEND_INITIALIZE_MISSING_BACKEND_SYMBOLS     3
12#define APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS        4
13#define APIR_BACKEND_INITIALIZE_BACKEND_FAILED              5
14#define APIR_BACKEND_INITIALIZE_BACKEND_REG_FAILED          6
15#define APIR_BACKEND_INITIALIZE_ALREADY_INITED              7
16#define APIR_BACKEND_INITIALIZE_NO_DEVICE                   8
17
18
19// new entries here need to be added to the apir_backend_initialize_error function below
20
21#define APIR_BACKEND_FORWARD_INDEX_INVALID 6
22
23// 0 is fast, 1 avoids the backend to crash if an unsupported tensor is received
24#define APIR_BACKEND_CHECK_SUPPORTS_OP 0
25
26typedef uintptr_t apir_buffer_type_host_handle_t;
27typedef uintptr_t apir_buffer_host_handle_t;
28
29static const char * apir_backend_initialize_error(int code) {
30#define APIR_BACKEND_INITIALIZE_ERROR(code_name) \
31    do {                                         \
32        if (code == code_name)                   \
33            return #code_name;                   \
34    } while (0)
35
36    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_SUCCESS);
37    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_CANNOT_OPEN_BACKEND_LIBRARY);
38    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY);
39    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_MISSING_BACKEND_SYMBOLS);
40    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS);
41    APIR_BACKEND_INITIALIZE_ERROR(APIR_BACKEND_INITIALIZE_BACKEND_FAILED);
42
43    return "Unknown APIR_BACKEND_INITIALIZE error:/";
44
45#undef APIR_BACKEND_INITIALIZE_ERROR
46}