@@ -2954,11 +2954,6 @@ static void ggml_backend_cuda_device_props(ggml_backend_dev_t dev, ggml_backend_
2954
2954
};
2955
2955
}
2956
2956
2957
- static ggml_backend_reg_t ggml_backend_cuda_device_reg (ggml_backend_dev_t dev) {
2958
- GGML_UNUSED (dev);
2959
- return ggml_backend_cuda_reg ();
2960
- }
2961
-
2962
2957
static ggml_backend_t ggml_backend_cuda_device_init (ggml_backend_dev_t dev, const char * params) {
2963
2958
GGML_UNUSED (params);
2964
2959
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context ;
@@ -3262,7 +3257,6 @@ static ggml_backend_device_i ggml_backend_cuda_device_interface = {
3262
3257
/* .get_memory = */ ggml_backend_cuda_device_memory,
3263
3258
/* .get_type = */ ggml_backend_cuda_device_type,
3264
3259
/* .get_props = */ ggml_backend_cuda_device_props,
3265
- /* .get_backend_reg = */ ggml_backend_cuda_device_reg,
3266
3260
/* .init_backend = */ ggml_backend_cuda_device_init,
3267
3261
/* .buffer_type = */ ggml_backend_cuda_device_buffer_type,
3268
3262
/* .host_buffer_type = */ ggml_backend_cuda_device_host_buffer_type,
@@ -3291,7 +3285,7 @@ static size_t ggml_backend_cuda_reg_get_device_count(ggml_backend_reg_t reg) {
3291
3285
return ctx->devices .size ();
3292
3286
}
3293
3287
3294
- static ggml_backend_dev_t ggml_backend_cuda_reg_get_device (ggml_backend_reg_t reg, size_t index) {
3288
+ static ggml_backend_dev_t ggml_backend_cuda_reg_device_get (ggml_backend_reg_t reg, size_t index) {
3295
3289
ggml_backend_cuda_reg_context * ctx = (ggml_backend_cuda_reg_context *)reg->context ;
3296
3290
GGML_ASSERT (index < ctx->devices .size ());
3297
3291
return ctx->devices [index];
@@ -3319,19 +3313,20 @@ static void ggml_backend_cuda_reg_set_log_callback(ggml_backend_reg_t reg, ggml_
3319
3313
static ggml_backend_reg_i ggml_backend_cuda_reg_interface = {
3320
3314
/* .get_name = */ ggml_backend_cuda_reg_name,
3321
3315
/* .device_count = */ ggml_backend_cuda_reg_get_device_count,
3322
- /* .device_get = */ ggml_backend_cuda_reg_get_device ,
3316
+ /* .device_get = */ ggml_backend_cuda_reg_device_get ,
3323
3317
/* .get_proc_address = */ ggml_backend_cuda_get_proc_address,
3324
3318
/* .set_log_callback = */ ggml_backend_cuda_reg_set_log_callback,
3325
3319
};
3326
3320
3327
3321
// backend registry
3328
3322
ggml_backend_reg_t ggml_backend_cuda_reg () {
3329
- static ggml_backend_reg_t reg = nullptr ;
3323
+ static ggml_backend_reg reg;
3324
+ static bool initialized = false ;
3330
3325
3331
3326
{
3332
3327
static std::mutex mutex;
3333
3328
std::lock_guard<std::mutex> lock (mutex);
3334
- if (!reg ) {
3329
+ if (!initialized ) {
3335
3330
ggml_backend_cuda_reg_context * ctx = new ggml_backend_cuda_reg_context;
3336
3331
3337
3332
for (int i = 0 ; i < ggml_cuda_info ().device_count ; i++) {
@@ -3346,19 +3341,22 @@ ggml_backend_reg_t ggml_backend_cuda_reg() {
3346
3341
3347
3342
ggml_backend_dev_t dev = new ggml_backend_device {
3348
3343
/* .interface = */ ggml_backend_cuda_device_interface,
3344
+ /* .reg = */ ®,
3349
3345
/* .context = */ dev_ctx
3350
3346
};
3351
3347
ctx->devices .push_back (dev);
3352
3348
}
3353
3349
3354
- reg = new ggml_backend_reg {
3350
+ reg = ggml_backend_reg {
3355
3351
/* .interface = */ ggml_backend_cuda_reg_interface,
3356
3352
/* .context = */ ctx
3357
3353
};
3358
3354
}
3355
+
3356
+ initialized = true ;
3359
3357
}
3360
3358
3361
- return reg;
3359
+ return & reg;
3362
3360
}
3363
3361
3364
3362
ggml_backend_t ggml_backend_cuda_init (int device) {
0 commit comments