-
Notifications
You must be signed in to change notification settings - Fork 13.4k
vulkan: initialize vulkan-hpp to allow using extension function pointers #15705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+43
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,14 @@ | |
| #include "ggml-cpu.h" | ||
| #endif | ||
|
|
||
| // 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 | ||
|
|
||
| #include <algorithm> | ||
| #include <cmath> | ||
| #include <iomanip> | ||
|
|
@@ -121,6 +127,8 @@ struct vk_pipeline_struct { | |
| bool needed {}; | ||
| // set to true when the shader has been compiled | ||
| bool compiled {}; | ||
| // number of registers used, extracted from pipeline executable properties | ||
| uint32_t register_count {}; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<vk_pipeline_struct> vk_pipeline; | ||
|
|
@@ -429,6 +437,8 @@ struct vk_device_struct { | |
|
|
||
| bool coopmat2; | ||
|
|
||
| bool pipeline_executable_properties_support {}; | ||
|
|
||
| size_t idx; | ||
|
|
||
| bool mul_mat_l[GGML_TYPE_COUNT]; | ||
|
|
@@ -1519,6 +1529,20 @@ static void ggml_vk_create_pipeline_func(vk_device& device, vk_pipeline& pipelin | |
| vk_instance.pfn_vkSetDebugUtilsObjectNameEXT(device->device, &static_cast<VkDebugUtilsObjectNameInfoEXT &>(duoni)); | ||
| } | ||
|
|
||
| if (device->pipeline_executable_properties_support) { | ||
| vk::PipelineExecutableInfoKHR executableInfo; | ||
| executableInfo.pipeline = pipeline->pipeline; | ||
|
|
||
| auto statistics = device->device.getPipelineExecutableStatisticsKHR(executableInfo); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug mode is now giving me this warning: |
||
| for (auto & s : statistics) { | ||
| // "Register Count" is reported by NVIDIA drivers. | ||
| if (strcmp(s.name, "Register Count") == 0) { | ||
| VK_LOG_DEBUG(pipeline->name << " " << s.name << ": " << s.value.u64 << " registers"); | ||
| pipeline->register_count = (uint32_t)s.value.u64; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| { | ||
| std::lock_guard<std::recursive_mutex> guard(device->mutex); | ||
| device->all_pipelines.push_back(pipeline); | ||
|
|
@@ -3509,6 +3533,7 @@ static vk_device ggml_vk_get_device(size_t idx) { | |
| bool amd_shader_core_properties2 = false; | ||
| bool pipeline_robustness = false; | ||
| bool coopmat2_support = false; | ||
| bool pipeline_executable_properties_support = false; | ||
| device->coopmat_support = false; | ||
| device->integer_dot_product = false; | ||
| bool bfloat16_support = false; | ||
|
|
@@ -3551,6 +3576,8 @@ static vk_device ggml_vk_get_device(size_t idx) { | |
| !getenv("GGML_VK_DISABLE_BFLOAT16")) { | ||
| bfloat16_support = true; | ||
| #endif | ||
| } else if (strcmp("VK_KHR_pipeline_executable_properties", properties.extensionName) == 0) { | ||
| pipeline_executable_properties_support = true; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -3771,8 +3798,18 @@ static vk_device ggml_vk_get_device(size_t idx) { | |
| device_extensions.push_back("VK_KHR_shader_integer_dot_product"); | ||
| } | ||
|
|
||
| VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR pep_features {}; | ||
| pep_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR; | ||
| if (pipeline_executable_properties_support) { | ||
| last_struct->pNext = (VkBaseOutStructure *)&pep_features; | ||
| last_struct = (VkBaseOutStructure *)&pep_features; | ||
| device_extensions.push_back("VK_KHR_pipeline_executable_properties"); | ||
| } | ||
|
|
||
| vkGetPhysicalDeviceFeatures2(device->physical_device, &device_features2); | ||
|
|
||
| device->pipeline_executable_properties_support = pipeline_executable_properties_support; | ||
|
|
||
| device->fp16 = device->fp16 && vk12_features.shaderFloat16; | ||
|
|
||
| #if defined(VK_KHR_shader_bfloat16) | ||
|
|
@@ -4288,6 +4325,9 @@ static void ggml_vk_instance_init() { | |
| } | ||
| VK_LOG_DEBUG("ggml_vk_instance_init()"); | ||
|
|
||
| // See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers- | ||
| VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); | ||
|
|
||
| uint32_t api_version = vk::enumerateInstanceVersion(); | ||
|
|
||
| if (api_version < VK_API_VERSION_1_2) { | ||
|
|
@@ -4355,6 +4395,9 @@ static void ggml_vk_instance_init() { | |
|
|
||
| vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr; | ||
|
|
||
| // See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers- | ||
| VULKAN_HPP_DEFAULT_DISPATCHER.init(vk_instance.instance); | ||
|
|
||
| std::vector<vk::PhysicalDevice> devices = vk_instance.instance.enumeratePhysicalDevices(); | ||
|
|
||
| // Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get
staticto work - vulkan-hpp usesexternto forward declare and it can't be both extern and static.Choosing a unique namespace ought to work. @dg0yt please try this:
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that 🤦 I must have tested with a different patch. The macro is good, but the workaround isn't, and then there is
vk::inggml-vulkan.cpp.This does work:
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. 🙏🏻
There was a problem hiding this comment.
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