From a4c329b2cd60de0e30bcca5e4121cb15d6565e9f Mon Sep 17 00:00:00 2001 From: Juan Pablo Garibotti Arias Date: Thu, 9 Oct 2025 14:52:11 +0200 Subject: [PATCH 1/2] Add compile flag to force vk performance logging --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 540254f31da..264d0867c24 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -4486,7 +4486,11 @@ static void ggml_vk_instance_init() { vk_instance.pfn_vkCmdInsertDebugUtilsLabelEXT = (PFN_vkCmdInsertDebugUtilsLabelEXT) vkGetInstanceProcAddr(vk_instance.instance, "vkCmdInsertDebugUtilsLabelEXT"); } +#ifndef FORCE_GGML_VK_PERF_LOGGER vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr; +#else + vk_perf_logger_enabled = true; +#endif std::vector devices = vk_instance.instance.enumeratePhysicalDevices(); From 650120310b1dd90225a8451a73d791921b89d02d Mon Sep 17 00:00:00 2001 From: Juan Pablo Garibotti Arias Date: Thu, 9 Oct 2025 15:06:18 +0200 Subject: [PATCH 2/2] Enable the FORCE_GGML_VK_PERF_LOGGER flag through an option --- CMakeLists.txt | 3 +++ ggml/src/ggml-vulkan/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0436acd999..527603c0002 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,9 @@ option(LLAMA_MTMD "llama: multimodal support" ${LLAMA_BUILD_TOOLS}) option(LLAMA_CURL "llama: use libcurl to download model from an URL" ON) option(LLAMA_LLGUIDANCE "llama-common: include LLGuidance library for structured output in common utils" OFF) +# profiling +option(FORCE_GGML_VK_PERF_LOGGER "Force vk performance logging in ggml" OFF) + # Required for relocatable CMake package include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake) diff --git a/ggml/src/ggml-vulkan/CMakeLists.txt b/ggml/src/ggml-vulkan/CMakeLists.txt index 519c93c9cc8..67007bdb693 100644 --- a/ggml/src/ggml-vulkan/CMakeLists.txt +++ b/ggml/src/ggml-vulkan/CMakeLists.txt @@ -92,6 +92,9 @@ if (Vulkan_FOUND) target_include_directories(ggml-vulkan PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(ggml-vulkan PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vulkan_cpp_wrapper/include") + if (FORCE_GGML_VK_PERF_LOGGER) + add_compile_definitions(FORCE_GGML_VK_PERF_LOGGER) + endif() # Workaround to the "can't dereference invalidated vector iterator" bug in clang-cl debug build # Posssibly relevant: https://stackoverflow.com/questions/74748276/visual-studio-no-displays-the-correct-length-of-stdvector if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")