@@ -2954,11 +2954,6 @@ static void ggml_backend_cuda_device_props(ggml_backend_dev_t dev, ggml_backend_
29542954 };
29552955}
29562956
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-
29622957static ggml_backend_t ggml_backend_cuda_device_init (ggml_backend_dev_t dev, const char * params) {
29632958 GGML_UNUSED (params);
29642959 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 = {
32623257 /* .get_memory = */ ggml_backend_cuda_device_memory,
32633258 /* .get_type = */ ggml_backend_cuda_device_type,
32643259 /* .get_props = */ ggml_backend_cuda_device_props,
3265- /* .get_backend_reg = */ ggml_backend_cuda_device_reg,
32663260 /* .init_backend = */ ggml_backend_cuda_device_init,
32673261 /* .buffer_type = */ ggml_backend_cuda_device_buffer_type,
32683262 /* .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) {
32913285 return ctx->devices .size ();
32923286}
32933287
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) {
32953289 ggml_backend_cuda_reg_context * ctx = (ggml_backend_cuda_reg_context *)reg->context ;
32963290 GGML_ASSERT (index < ctx->devices .size ());
32973291 return ctx->devices [index];
@@ -3319,19 +3313,20 @@ static void ggml_backend_cuda_reg_set_log_callback(ggml_backend_reg_t reg, ggml_
33193313static ggml_backend_reg_i ggml_backend_cuda_reg_interface = {
33203314 /* .get_name = */ ggml_backend_cuda_reg_name,
33213315 /* .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 ,
33233317 /* .get_proc_address = */ ggml_backend_cuda_get_proc_address,
33243318 /* .set_log_callback = */ ggml_backend_cuda_reg_set_log_callback,
33253319};
33263320
33273321// backend registry
33283322ggml_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 ;
33303325
33313326 {
33323327 static std::mutex mutex;
33333328 std::lock_guard<std::mutex> lock (mutex);
3334- if (!reg ) {
3329+ if (!initialized ) {
33353330 ggml_backend_cuda_reg_context * ctx = new ggml_backend_cuda_reg_context;
33363331
33373332 for (int i = 0 ; i < ggml_cuda_info ().device_count ; i++) {
@@ -3346,19 +3341,22 @@ ggml_backend_reg_t ggml_backend_cuda_reg() {
33463341
33473342 ggml_backend_dev_t dev = new ggml_backend_device {
33483343 /* .interface = */ ggml_backend_cuda_device_interface,
3344+ /* .reg = */ ®,
33493345 /* .context = */ dev_ctx
33503346 };
33513347 ctx->devices .push_back (dev);
33523348 }
33533349
3354- reg = new ggml_backend_reg {
3350+ reg = ggml_backend_reg {
33553351 /* .interface = */ ggml_backend_cuda_reg_interface,
33563352 /* .context = */ ctx
33573353 };
33583354 }
3355+
3356+ initialized = true ;
33593357 }
33603358
3361- return reg;
3359+ return & reg;
33623360}
33633361
33643362ggml_backend_t ggml_backend_cuda_init (int device) {
0 commit comments