77#include " backend-internal.h"
88#include " backend-dispatched.h"
99
10+ #include " shared/api_remoting.h"
1011#include " shared/apir_backend.h"
1112#include " shared/venus_cs.h"
1213
@@ -26,9 +27,11 @@ extern "C" {
2627 buffer->iface .free_buffer (buffer);
2728 }
2829
29- size_t free, total;
30- dev->iface .get_memory (dev, &free, &total);
31- WARNING (" %s: free memory: %ld MB\n " , __func__, (size_t ) free/1024 /1024 );
30+ if (dev) {
31+ size_t free, total;
32+ dev->iface .get_memory (dev, &free, &total);
33+ INFO (" %s: free memory: %ld MB" , __func__, (size_t ) free/1024 /1024 );
34+ }
3235
3336 show_timer (&graph_compute_timer);
3437 show_timer (&set_tensor_timer);
@@ -43,7 +46,7 @@ extern "C" {
4346 INFO (" %s: bye-bye" , __func__);
4447 }
4548
46- uint32_t apir_backend_initialize () {
49+ ApirLoadLibraryReturnCode apir_backend_initialize () {
4750 const char * dlsym_error;
4851
4952 const char * library_name = getenv (GGML_BACKEND_LIBRARY_PATH_ENV);
@@ -53,56 +56,61 @@ extern "C" {
5356 INFO (" %s: loading %s (%s|%s)" , __func__, library_name, library_reg, library_init);
5457
5558 if (!library_name) {
56- ERROR (" Cannot open library: env var '%s' not defined\n " , GGML_BACKEND_LIBRARY_PATH_ENV);
59+ ERROR (" cannot open the GGML library: env var '%s' not defined\n " , GGML_BACKEND_LIBRARY_PATH_ENV);
5760
58- return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY ;
61+ return APIR_LOAD_LIBRARY_ENV_VAR_MISSING ;
5962 }
6063
6164 backend_library_handle = dlopen (library_name, RTLD_LAZY);
6265
6366 if (!backend_library_handle) {
64- ERROR (" Cannot open library: %s\n " , dlerror ());
67+ ERROR (" cannot open the GGML library: %s" , dlerror ());
6568
66- return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY ;
69+ return APIR_LOAD_LIBRARY_CANNOT_OPEN ;
6770 }
6871
6972 if (!library_reg) {
70- ERROR (" Cannot register library: env var '%s' not defined\n " , GGML_BACKEND_LIBRARY_REG_ENV);
73+ ERROR (" cannot register the GGML library: env var '%s' not defined" , GGML_BACKEND_LIBRARY_REG_ENV);
7174
72- return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY ;
75+ return APIR_LOAD_LIBRARY_ENV_VAR_MISSING ;
7376 }
7477
7578 void *ggml_backend_reg_fct = dlsym (backend_library_handle, library_reg);
7679 dlsym_error = dlerror ();
7780 if (dlsym_error) {
78- ERROR (" Cannot load symbol: %s\n " , dlsym_error);
81+ ERROR (" cannot find the GGML backend registration symbol '%s' (from %s): %s" ,
82+ library_reg, GGML_BACKEND_LIBRARY_REG_ENV, dlsym_error);
7983
80- return APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS ;
84+ return APIR_LOAD_LIBRARY_SYMBOL_MISSING ;
8185 }
8286
8387 if (!library_init) {
84- ERROR (" Cannot initialize library: env var '%s' not defined\n " , library_init);
88+ ERROR (" cannot initialize the GGML library: env var '%s' not defined" , library_init);
8589
86- return APIR_BACKEND_INITIALIZE_CANNOT_OPEN_GGML_LIBRARY ;
90+ return APIR_LOAD_LIBRARY_ENV_VAR_MISSING ;
8791 }
8892
8993 void *ggml_backend_init_fct = dlsym (backend_library_handle, library_init);
9094 dlsym_error = dlerror ();
9195 if (dlsym_error) {
92- ERROR (" Cannot load symbol: %s\n " , dlsym_error);
96+ ERROR (" cannot find the GGML backend init symbol '%s' (from %s): %s" ,
97+ library_init, GGML_BACKEND_LIBRARY_INIT_ENV, dlsym_error);
9398
94- return APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS ;
99+ return APIR_LOAD_LIBRARY_SYMBOL_MISSING ;
95100 }
96101
97102 ggml_backend_metal_get_device_context_fct = (void (*)(ggml_backend_dev_t , bool *, bool *, bool *)) dlsym (backend_library_handle, GGML_BACKEND_LIBRARY_METAL_DEVICE_CONTEXT);
98103 dlsym_error = dlerror ();
99104 if (dlsym_error) {
100- ERROR (" Cannot load symbol: %s\n " , dlsym_error);
105+ ERROR (" cannot find the GGML device context symbol '%s': %s\n " ,
106+ GGML_BACKEND_LIBRARY_METAL_DEVICE_CONTEXT, dlsym_error);
101107
102- return APIR_BACKEND_INITIALIZE_MISSING_GGML_SYMBOLS ;
108+ return APIR_LOAD_LIBRARY_SYMBOL_MISSING ;
103109 }
104110
105- return backend_dispatch_initialize (ggml_backend_reg_fct, ggml_backend_init_fct);
111+ uint32_t ret = backend_dispatch_initialize (ggml_backend_reg_fct, ggml_backend_init_fct);
112+
113+ return (ApirLoadLibraryReturnCode) (APIR_LOAD_LIBRARY_INIT_BASE_INDEX + ret);
106114 }
107115
108116 uint32_t apir_backend_dispatcher (uint32_t cmd_type, struct virgl_apir_context *ctx,
@@ -122,8 +130,8 @@ extern "C" {
122130 struct vn_cs_decoder *dec = &_dec;
123131
124132
125- if (cmd_type > APIR_BACKEND_DISPATCH_TABLE_COUNT) {
126- ERROR (" Received an invalid dispatch index (%d > %d)\n " ,
133+ if (cmd_type >= APIR_BACKEND_DISPATCH_TABLE_COUNT) {
134+ ERROR (" Received an invalid dispatch index (%d >= %d)\n " ,
127135 cmd_type, APIR_BACKEND_DISPATCH_TABLE_COUNT);
128136 return APIR_BACKEND_FORWARD_INDEX_INVALID;
129137 }
0 commit comments