Skip to content

Conversation

@jeffbolznv
Copy link
Collaborator

@jeffbolznv jeffbolznv commented Aug 31, 2025

Use this to query register count for shader compiles on NVIDIA. Currently this is only for performance debug, but it could eventually be used in some heuristics like split_k.

Fixes #15698.

@jeffbolznv jeffbolznv requested a review from 0cc4m as a code owner August 31, 2025 22:03
@github-actions github-actions bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Aug 31, 2025
Use this to query register count for shader compiles on NVIDIA. Currently
this is only for performance debug, but it could eventually be used in some
heuristics like split_k.
Copy link
Collaborator

@0cc4m 0cc4m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay

@0cc4m 0cc4m merged commit b9c9c9f into ggml-org:master Sep 13, 2025
87 of 89 checks passed
vk::PipelineExecutableInfoKHR executableInfo;
executableInfo.pipeline = pipeline->pipeline;

auto statistics = device->device.getPipelineExecutableStatisticsKHR(executableInfo);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug mode is now giving me this warning:

vkGetPipelineExecutableStatisticsKHR(): called on a pipeline created without the VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR flag set.
The Vulkan spec states: The pipeline member of pExecutableInfo must have been created with VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR (https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-vkGetPipelineExecutableStatisticsKHR-pipeline-03274)

@ggerganov
Copy link
Member

I think this report is related to the changes in this PR: ggml-org/ggml#1344 (comment)

Comment on lines +8 to +15
// See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1

#include <vulkan/vulkan.hpp>

// See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this doesn't belong into the ggml library. It can exist once in the whole program.
ggml-org/ggml#1344 (comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I can forgo the macros and define a dispatcher with static linkage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get static to work - vulkan-hpp uses extern to forward declare and it can't be both extern and static.

Choosing a unique namespace ought to work. @dg0yt please try this:

diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
index 0feaf4cb5..bc26ec8f5 100644
--- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp
+++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
@@ -5,6 +5,9 @@
 #include "ggml-cpu.h"
 #endif

+// make vulkan-hpp vk namespace unique for this file, to avoid conflicts when linking
+#define vk ggml_vk
+
 // See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
 #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible alternative that only renames the dispatcher:

namespace vk::detail { class DispatchLoaderDynamic; }
vk::detail::DispatchLoaderDynamic & ggml_vk_default_dispatcher();

#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#define VULKAN_HPP_DEFAULT_DISPATCHER ggml_vk_default_dispatcher()

#include <vulkan/vulkan.hpp>

static vk::detail::DispatchLoaderDynamic ggml_vk_default_dispatcher_instance;
vk::detail::DispatchLoaderDynamic & ggml_vk_default_dispatcher() {
    return ggml_vk_default_dispatcher_instance;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, laundering it through a function call may work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With recent vulkan-hpp, it would be a one-line change, but for my installation I had to deal with KhronosGroup/Vulkan-Hpp#2093.

Scratch that 🤦 I must have tested with a different patch. The macro is good, but the workaround isn't, and then there is vk:: in ggml-vulkan.cpp.

This does work:

diff --git a/src/ggml-vulkan/ggml-vulkan.cpp b/src/ggml-vulkan/ggml-vulkan.cpp
index 5c941e72..a98f29e7 100644
--- a/src/ggml-vulkan/ggml-vulkan.cpp
+++ b/src/ggml-vulkan/ggml-vulkan.cpp
@@ -8,6 +8,9 @@
 // See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
 #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
 
+#define VULKAN_HPP_NAMESPACE ggml_vk
+namespace ggml_vk {}
+namespace vk { using namespace ::ggml_vk; }
 #include <vulkan/vulkan.hpp>
 
 

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can one of you make a PR and discuss it on there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer @Acly's fix. @Acly do you want to make a PR?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! please make a link to PR or just tag me there. 🙏🏻

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, PR is here: #16224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile bug: undefined symbol: vkResetQueryPool for android-ndk-r29-beta3

6 participants