@@ -211,27 +211,45 @@ extern "C" {
211
211
GGML_API void ggml_backend_device_register (ggml_backend_dev_t device );
212
212
213
213
// Add backend dynamic loading support to the backend
214
- typedef ggml_backend_reg_t (* ggml_backend_init_t )(void );
215
214
216
- #ifdef GGML_BACKEND_DL
217
- #ifdef __cplusplus
218
- # define GGML_BACKEND_DL_IMPL (reg_fn ) \
219
- extern "C" { \
220
- GGML_BACKEND_API ggml_backend_reg_t ggml_backend_init(void); \
221
- } \
222
- ggml_backend_reg_t ggml_backend_init(void) { \
223
- return reg_fn(); \
224
- }
225
- #else
226
- # define GGML_BACKEND_DL_IMPL (reg_fn ) \
227
- GGML_BACKEND_API ggml_backend_reg_t ggml_backend_init(void); \
228
- ggml_backend_reg_t ggml_backend_init(void) { \
229
- return reg_fn(); \
230
- }
231
- #endif
232
- #else
233
- # define GGML_BACKEND_DL_IMPL (reg_fn )
234
- #endif
215
+ // Initialize the backend
216
+ typedef ggml_backend_reg_t (* ggml_backend_init_t )(void );
217
+ // Optional: obtain a score for the backend based on the system configuration
218
+ // Higher scores are preferred, 0 means the backend is not supported in the current system
219
+ typedef int (* ggml_backend_score_t )(void );
220
+
221
+ #ifdef GGML_BACKEND_DL
222
+ # ifdef __cplusplus
223
+ # define GGML_BACKEND_DL_IMPL (reg_fn ) \
224
+ extern "C" { \
225
+ GGML_BACKEND_API ggml_backend_reg_t ggml_backend_init(void); \
226
+ } \
227
+ ggml_backend_reg_t ggml_backend_init(void) { \
228
+ return reg_fn(); \
229
+ }
230
+ # define GGML_BACKEND_DL_SCORE_IMPL (score_fn ) \
231
+ extern "C" { \
232
+ GGML_BACKEND_API int ggml_backend_score(void); \
233
+ } \
234
+ int ggml_backend_score(void) { \
235
+ return score_fn(); \
236
+ }
237
+ # else
238
+ # define GGML_BACKEND_DL_IMPL (reg_fn ) \
239
+ GGML_BACKEND_API ggml_backend_reg_t ggml_backend_init(void); \
240
+ ggml_backend_reg_t ggml_backend_init(void) { \
241
+ return reg_fn(); \
242
+ }
243
+ # define GGML_BACKEND_DL_SCORE_IMPL (score_fn ) \
244
+ GGML_BACKEND_API int ggml_backend_score(void); \
245
+ int ggml_backend_score(void) { \
246
+ return score_fn(); \
247
+ }
248
+ # endif
249
+ #else
250
+ # define GGML_BACKEND_DL_IMPL (reg_fn )
251
+ # define GGML_BACKEND_DL_SCORE_IMPL (score_fn )
252
+ #endif
235
253
236
254
#ifdef __cplusplus
237
255
}
0 commit comments