@@ -187,14 +187,16 @@ struct ggml_backend_opencl_context {
187
187
#endif // GGML_OPENCL_USE_ADRENO_KERNELS
188
188
};
189
189
190
- static ggml_backend_device g_ggml_backend_opencl_device;
190
+ static ggml_backend_device g_ggml_backend_opencl_device;
191
191
static ggml_backend_opencl_device_context g_ggml_ctx_dev_main {
192
192
/* .platform =*/ nullptr ,
193
193
/* .platform_nane =*/ " " ,
194
194
/* .device =*/ nullptr ,
195
195
/* .device_name =*/ " " ,
196
196
};
197
197
198
+ static int ggml_backend_opencl_n_devices = 0 ;
199
+
198
200
// Profiling
199
201
#ifdef GGML_OPENCL_PROFILING
200
202
struct ProfilingInfo {
@@ -270,6 +272,7 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
270
272
271
273
initialized = true ;
272
274
backend_ctx = new ggml_backend_opencl_context ();
275
+ backend_ctx->gpu_family = GPU_FAMILY::UNKNOWN;
273
276
274
277
cl_int err;
275
278
@@ -305,7 +308,10 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
305
308
struct cl_device * default_device = NULL ;
306
309
307
310
cl_platform_id platform_ids[NPLAT];
308
- CL_CHECK (clGetPlatformIDs (NPLAT, platform_ids, &n_platforms));
311
+ if (clGetPlatformIDs (NPLAT, platform_ids, &n_platforms) != CL_SUCCESS) {
312
+ GGML_LOG_ERROR (" ggml_opencl: plaform IDs not available.\n " );
313
+ return backend_ctx;
314
+ }
309
315
310
316
for (unsigned i = 0 ; i < n_platforms; i++) {
311
317
struct cl_platform * p = &platforms[i];
@@ -344,7 +350,7 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
344
350
345
351
if (n_devices == 0 ) {
346
352
GGML_LOG_ERROR (" ggml_opencl: could find any OpenCL devices.\n " );
347
- exit ( 1 ) ;
353
+ return backend_ctx ;
348
354
}
349
355
350
356
char * user_platform_string = getenv (" GGML_OPENCL_PLATFORM" );
@@ -453,7 +459,8 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
453
459
backend_ctx->gpu_family = GPU_FAMILY::INTEL;
454
460
} else {
455
461
GGML_LOG_ERROR (" Unknown GPU: %s\n " , default_device->name );
456
- exit (1 );
462
+ backend_ctx->gpu_family = GPU_FAMILY::UNKNOWN;
463
+ return backend_ctx;
457
464
}
458
465
459
466
// Populate backend device name
@@ -758,6 +765,9 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
758
765
CL_CHECK ((backend_ctx->B_d_max = clCreateBuffer (context, 0 , max_B_d_bytes, NULL , &err), err));
759
766
#endif // GGML_OPENCL_USE_ADRENO_KERNELS
760
767
768
+ // For now we support a single devices
769
+ ggml_backend_opencl_n_devices = 1 ;
770
+
761
771
return backend_ctx;
762
772
}
763
773
@@ -1728,7 +1738,7 @@ static const char * ggml_backend_opencl_reg_get_name(ggml_backend_reg_t reg) {
1728
1738
}
1729
1739
1730
1740
static size_t ggml_backend_opencl_reg_device_count (ggml_backend_reg_t reg) {
1731
- return 1 ;
1741
+ return ggml_backend_opencl_n_devices ;
1732
1742
1733
1743
GGML_UNUSED (reg);
1734
1744
}
0 commit comments