From 3172006a248b5ccc60446736fe005c93eb8ffdae Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 12 Nov 2023 16:36:20 +0200 Subject: [PATCH] ggml : fix some compile warnings --- ggml-cuda.cu | 9 +++++++++ ggml-metal.m | 9 +++++---- whisper.cpp | 24 +++++++++--------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ggml-cuda.cu b/ggml-cuda.cu index 34c45f38..058011a4 100644 --- a/ggml-cuda.cu +++ b/ggml-cuda.cu @@ -7962,6 +7962,15 @@ bool ggml_cuda_compute_forward(struct ggml_compute_params * params, struct ggml_ return false; } + if (tensor->op == GGML_OP_MUL_MAT) { + if (tensor->src[0]->ne[3] != tensor->src[1]->ne[3]) { +#ifndef NDEBUG + fprintf(stderr, "%s: cannot compute %s: src0->ne[3] = %d, src1->ne[3] = %d - fallback to CPU\n", __func__, tensor->name, tensor->src[0]->ne[3], tensor->src[1]->ne[3]); +#endif + return false; + } + } + switch (tensor->op) { case GGML_OP_REPEAT: func = ggml_cuda_repeat; diff --git a/ggml-metal.m b/ggml-metal.m index 6293908c..3d22b0b2 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -128,7 +128,7 @@ struct ggml_metal_context { // MSL code // TODO: move the contents here when ready // for now it is easier to work in a separate file -static NSString * const msl_library_source = @"see metal.metal"; +//static NSString * const msl_library_source = @"see metal.metal"; // Here to assist with NSBundle Path Hack @interface GGMLMetalClass : NSObject @@ -144,7 +144,8 @@ void ggml_metal_log_set_callback(ggml_log_callback log_callback, void * user_dat ggml_metal_log_user_data = user_data; } -static void ggml_metal_log(enum ggml_log_level level, const char* format, ...){ +GGML_ATTRIBUTE_FORMAT(2, 3) +static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){ if (ggml_metal_log_callback != NULL) { va_list args; va_start(args, format); @@ -339,7 +340,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) { // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf for (int i = MTLGPUFamilyApple1 + 20; i >= MTLGPUFamilyApple1; --i) { if ([ctx->device supportsFamily:i]) { - GGML_METAL_LOG_INFO("%s: GPU family: MTLGPUFamilyApple%d (%d)\n", __func__, i - MTLGPUFamilyApple1 + 1, i); + GGML_METAL_LOG_INFO("%s: GPU family: MTLGPUFamilyApple%d (%d)\n", __func__, i - (int) MTLGPUFamilyApple1 + 1, i); break; } } @@ -583,7 +584,7 @@ bool ggml_metal_add_buffer( ctx->device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0); if (ctx->device.currentAllocatedSize > ctx->device.recommendedMaxWorkingSetSize) { - GGML_METAL_LOG_WARN(", warning: current allocated size is greater than the recommended max working set size\n", __func__); + GGML_METAL_LOG_WARN("%s: warning: current allocated size is greater than the recommended max working set size\n", __func__); } else { GGML_METAL_LOG_INFO("\n"); } diff --git a/whisper.cpp b/whisper.cpp index 244cfeb1..1c7d7e94 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -118,7 +118,7 @@ static void byteswap_tensor(ggml_tensor * tensor) { // WHISPER_ATTRIBUTE_FORMAT(2, 3) -static void whisper_log_internal (ggml_log_level level, const char* format, ...); +static void whisper_log_internal (ggml_log_level level, const char * format, ...); static void whisper_log_callback_default(ggml_log_level level, const char * text, void * user_data); #define WHISPER_LOG_INFO(...) whisper_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__) @@ -5848,27 +5848,21 @@ void whisper_log_set(ggml_log_callback log_callback, void * user_data) { g_state.log_callback_user_data = user_data; } -static void whisper_log_internal_v(ggml_log_level level, const char * format, va_list args) { - va_list args_copy; - va_copy(args_copy, args); - char buffer[128]; - int len = vsnprintf(buffer, 128, format, args); - if (len < 128) { +GGML_ATTRIBUTE_FORMAT(2, 3) +static void whisper_log_internal(ggml_log_level level, const char * format, ...) { + va_list args; + va_start(args, format); + char buffer[1024]; + int len = vsnprintf(buffer, 1024, format, args); + if (len < 1024) { g_state.log_callback(level, buffer, g_state.log_callback_user_data); } else { char* buffer2 = new char[len+1]; - vsnprintf(buffer2, len+1, format, args_copy); + vsnprintf(buffer2, len+1, format, args); buffer2[len] = 0; g_state.log_callback(level, buffer2, g_state.log_callback_user_data); delete[] buffer2; } - va_end(args_copy); -} - -static void whisper_log_internal(ggml_log_level level, const char * format, ...) { - va_list args; - va_start(args, format); - whisper_log_internal_v(level, format, args); va_end(args); }