Skip to content

Commit d4f39c4

Browse files
committed
opencl: use GGML_LOG_xxx instead of fprintf(stderr, ...)
1 parent 4f84d4a commit d4f39c4

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

ggml/src/ggml-opencl2/ggml-opencl2.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
do { \
4040
cl_int err_ = (err); \
4141
if (err_ != CL_SUCCESS) { \
42-
fprintf(stderr, "ggml_opencl: %s error %d at %s:%d\n", \
42+
GGML_LOG_ERROR("ggml_opencl: %s error %d at %s:%d\n", \
4343
#err, err_, __FILE__, __LINE__); \
4444
GGML_ASSERT(0); \
4545
} \
@@ -239,7 +239,7 @@ static cl_program build_program_from_source(cl_context ctx, cl_device_id dev, co
239239

240240
p = clCreateProgramWithSource(ctx, 1, (const char**)&program_buffer, &program_size, &err);
241241
if(err < 0) {
242-
fprintf(stderr, "OpenCL error creating program");
242+
GGML_LOG_ERROR("OpenCL error creating program");
243243
exit(1);
244244
}
245245

@@ -249,7 +249,7 @@ static cl_program build_program_from_source(cl_context ctx, cl_device_id dev, co
249249
program_log = (char*) malloc(log_size + 1);
250250
program_log[log_size] = '\0';
251251
clGetProgramBuildInfo(p, dev, CL_PROGRAM_BUILD_LOG, log_size + 1, program_log, NULL);
252-
fprintf(stderr, "ggml_opencl: kernel compile error:\n\n%s\n", program_log);
252+
GGML_LOG_ERROR("ggml_opencl: kernel compile error:\n\n%s\n", program_log);
253253
free(program_log);
254254
exit(1);
255255
}
@@ -277,7 +277,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
277277
cl_int err;
278278

279279
#ifdef GGML_PROFILE_OPENCL
280-
fprintf(stderr, "ggml_opencl: OpenCL profiling enabled\n");
280+
GGML_LOG_INFO("ggml_opencl: OpenCL profiling enabled\n");
281281
#endif
282282

283283
struct cl_device;
@@ -346,7 +346,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
346346
}
347347

348348
if (n_devices == 0) {
349-
fprintf(stderr, "ggml_opencl: could find any OpenCL devices.\n");
349+
GGML_LOG_ERROR("ggml_opencl: could find any OpenCL devices.\n");
350350
exit(1);
351351
}
352352

@@ -365,7 +365,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
365365
if (user_platform_number != -1 && user_device_number != -1) {
366366
cl_platform* platform = &platforms[user_platform_number];
367367
if ((unsigned)user_device_number >= platform->n_devices) {
368-
fprintf(stderr, "ggml_opencl: invalid device number %d\n", user_device_number);
368+
GGML_LOG_ERROR("ggml_opencl: invalid device number %d\n", user_device_number);
369369
exit(1);
370370
}
371371
default_device = &platform->devices[user_device_number];
@@ -384,7 +384,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
384384
}
385385
}
386386
if (user_platform_number == -1) {
387-
fprintf(stderr, "ggml_opencl: no platform matching '%s' was found.\n", user_platform_string);
387+
GGML_LOG_ERROR("ggml_opencl: no platform matching '%s' was found.\n", user_platform_string);
388388
exit(1);
389389
}
390390
}
@@ -394,7 +394,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
394394
n_selected_devices = p->n_devices;
395395
default_device = p->default_device;
396396
if (n_selected_devices == 0) {
397-
fprintf(stderr, "ggml_opencl: selected platform '%s' does not have any devices.\n", p->name);
397+
GGML_LOG_ERROR("ggml_opencl: selected platform '%s' does not have any devices.\n", p->name);
398398
exit(1);
399399
}
400400
}
@@ -408,7 +408,7 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
408408
}
409409
}
410410
if (user_device_number == -1) {
411-
fprintf(stderr, "ggml_opencl: no device matching '%s' was found.\n", user_device_string);
411+
GGML_LOG_ERROR("ggml_opencl: no device matching '%s' was found.\n", user_device_string);
412412
exit(1);
413413
}
414414
}
@@ -425,10 +425,10 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
425425
}
426426
}
427427

428-
fprintf(stderr, "ggml_opencl: selecting platform: '%s'\n", default_device->platform->name);
429-
fprintf(stderr, "ggml_opencl: selecting device: '%s'\n", default_device->name);
428+
GGML_LOG_INFO("ggml_opencl: selecting platform: '%s'\n", default_device->platform->name);
429+
GGML_LOG_INFO("ggml_opencl: selecting device: '%s'\n", default_device->name);
430430
if (default_device->type != CL_DEVICE_TYPE_GPU) {
431-
fprintf(stderr, "ggml_opencl: warning, not a GPU: '%s'.\n", default_device->name);
431+
GGML_LOG_WARN("ggml_opencl: warning, not a GPU: '%s'.\n", default_device->name);
432432
}
433433

434434
dev_ctx->platform = default_device->platform->id;
@@ -447,16 +447,16 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
447447
backend_ctx->adreno_wave_size = 128;
448448
} else {
449449
backend_ctx->adreno_wave_size = 128;
450-
fprintf(stderr, "ggml_opencl: Unsupported Adreno GPU: %s, "
450+
GGML_LOG_WARN("ggml_opencl: Unsupported Adreno GPU: %s, "
451451
"using wave size %d, "
452452
"may not work as expected\n",
453453
backend_ctx->device_name.c_str(), backend_ctx->adreno_wave_size);
454454
}
455455
} else if (strstr(default_device->name, "Intel")) {
456456
backend_ctx->gpu_family = GPU_FAMILY::INTEL;
457457
} else {
458-
fprintf(stderr, "Unknown GPU: %s\n", default_device->name);
459-
GGML_ASSERT(false && "Unknown GPU");
458+
GGML_LOG_ERROR("Unknown GPU: %s\n", default_device->name);
459+
exit(1);
460460
}
461461

462462
// Populate backend device name
@@ -473,13 +473,13 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
473473
char *driver_version = (char *)alloca(driver_version_str_size + 1);
474474
clGetDeviceInfo(device, CL_DRIVER_VERSION, driver_version_str_size, driver_version, NULL);
475475
driver_version[driver_version_str_size] = '\0';
476-
fprintf(stderr, "ggml_opencl: OpenCL driver: %s\n", driver_version);
476+
GGML_LOG_INFO("ggml_opencl: OpenCL driver: %s\n", driver_version);
477477
backend_ctx->driver_version = driver_version;
478478

479479
int adreno_cl_compiler_version = get_adreno_cl_compiler_version(driver_version);
480480
bool has_vector_subgroup_broadcast =
481481
adreno_cl_compiler_version >= 47 || adreno_cl_compiler_version == 17;
482-
fprintf(stderr, "ggml_opencl: vector subgroup broadcast support: %s\n",
482+
GGML_LOG_INFO("ggml_opencl: vector subgroup broadcast support: %s\n",
483483
has_vector_subgroup_broadcast ? "true" : "false");
484484

485485
size_t ext_str_size;
@@ -489,33 +489,33 @@ static ggml_backend_opencl2_context * ggml_cl2_init(ggml_backend_dev_t dev) {
489489
ext_buffer[ext_str_size] = '\0'; // ensure it is null terminated
490490
// Check if ext_buffer contains cl_khr_fp16
491491
backend_ctx->fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL;
492-
fprintf(stderr, "ggml_opencl: device FP16 support: %s\n", backend_ctx->fp16_support ? "true" : "false");
492+
GGML_LOG_INFO("ggml_opencl: device FP16 support: %s\n", backend_ctx->fp16_support ? "true" : "false");
493493

494494
CL_CHECK(clGetDeviceInfo(device, CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(cl_uint), &backend_ctx->alignment, NULL));
495-
fprintf(stderr, "ggml_opencl: mem base addr align: %u\n", backend_ctx->alignment);
495+
GGML_LOG_INFO("ggml_opencl: mem base addr align: %u\n", backend_ctx->alignment);
496496

497497
clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(size_t), &backend_ctx->max_alloc_size, NULL);
498-
fprintf(stderr, "ggml_opencl: max mem alloc size: %zu MB\n", backend_ctx->max_alloc_size/1024/1024);
498+
GGML_LOG_INFO("ggml_opencl: max mem alloc size: %zu MB\n", backend_ctx->max_alloc_size/1024/1024);
499499

500500
// Check SVM.
501501
cl_device_svm_capabilities svm_caps;
502502
CL_CHECK(clGetDeviceInfo(device, CL_DEVICE_SVM_CAPABILITIES, sizeof(cl_device_svm_capabilities), &svm_caps, 0));
503-
fprintf(stderr, "ggml_opencl: SVM coarse grain buffer support: %s\n",
503+
GGML_LOG_INFO("ggml_opencl: SVM coarse grain buffer support: %s\n",
504504
svm_caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER ? "true" : "false");
505-
fprintf(stderr, "ggml_opencl: SVM fine grain buffer support: %s\n",
505+
GGML_LOG_INFO("ggml_opencl: SVM fine grain buffer support: %s\n",
506506
svm_caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER ? "true" : "false");
507-
fprintf(stderr, "ggml_opencl: SVM fine grain system support: %s\n",
507+
GGML_LOG_INFO("ggml_opencl: SVM fine grain system support: %s\n",
508508
svm_caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM ? "true" : "false");
509-
fprintf(stderr, "ggml_opencl: SVM atomics support: %s\n",
509+
GGML_LOG_INFO("ggml_opencl: SVM atomics support: %s\n",
510510
svm_caps & CL_DEVICE_SVM_ATOMICS ? "true" : "false");
511511

512512
// Print out configurations
513513
#ifdef GGML_OPENCL_SOA_Q
514-
fprintf(stderr, "ggml_opencl: flattening quantized weights representation as struct of arrays (GGML_OPENCL_SOA_Q)\n");
514+
GGML_LOG_INFO("ggml_opencl: flattening quantized weights representation as struct of arrays (GGML_OPENCL_SOA_Q)\n");
515515
#endif // GGML_OPENCL_SOA_Q
516516

517517
#ifdef GGML_OPENCL_USE_ADRENO_KERNELS
518-
fprintf(stderr, "ggml_opencl: using kernels optimized for Adreno (GGML_OPENCL_USE_ADRENO_KERNELS)\n");
518+
GGML_LOG_INFO("ggml_opencl: using kernels optimized for Adreno (GGML_OPENCL_USE_ADRENO_KERNELS)\n");
519519
#endif // GGML_OPENCL_USE_ADRENO_KERNELS
520520

521521
cl_context_properties properties[] = {
@@ -768,7 +768,7 @@ static void ggml_cl2_free(void) {
768768
#ifdef GGML_OPENCL_PROFILING
769769
FILE * fperf = fopen("cl_profiling.csv", "w");
770770
if (!fperf) {
771-
fprintf(stderr, "Failed to open cl_profiling.csv\n");
771+
GGML_LOG_ERROR("Failed to open cl_profiling.csv\n");
772772
return;
773773
}
774774

@@ -784,7 +784,7 @@ static void ggml_cl2_free(void) {
784784
}
785785
fclose(fperf);
786786

787-
fprintf(stderr, "ggml_opencl: total kernel time: %f\n", total_kernel_time);
787+
GGML_LOG_INFO("ggml_opencl: total kernel time: %f\n", total_kernel_time);
788788
#endif
789789
}
790790

@@ -911,7 +911,7 @@ static ggml_status ggml_backend_opencl2_graph_compute(ggml_backend_t backend, gg
911911

912912
bool ok = ggml_cl_compute_forward(backend, node);
913913
if (!ok) {
914-
fprintf(stderr, "%s: error: op not supported %s (%s)\n", __func__, node->name, ggml_op_name(node->op));
914+
GGML_LOG_ERROR("%s: error: op not supported %s (%s)\n", __func__, node->name, ggml_op_name(node->op));
915915
}
916916
GGML_ASSERT(ok);
917917
}
@@ -1537,7 +1537,7 @@ static ggml_backend_buffer_t ggml_backend_opencl2_buffer_type_alloc_buffer(ggml_
15371537
cl_int err;
15381538
cl_mem mem = clCreateBuffer(backend_ctx->context, CL_MEM_READ_WRITE, size, NULL, &err);
15391539
if (err != CL_SUCCESS) {
1540-
fprintf(stderr, "%s: failed to allocate %.2f MiB\n", __func__, size / 1024.0 / 1024.0);
1540+
GGML_LOG_INFO("%s: failed to allocate %.2f MiB\n", __func__, size / 1024.0 / 1024.0);
15411541
return nullptr;
15421542
}
15431543

0 commit comments

Comments
 (0)