Skip to content

Commit e235094

Browse files
committed
Add support for VK_EXT_debug_utils to add labels to Vulkan objects. In step 1 compute pipelines are getting labeled.
1 parent 797f2ac commit e235094

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

ggml/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ option(GGML_VULKAN_DEBUG "ggml: enable Vulkan debug output"
177177
option(GGML_VULKAN_MEMORY_DEBUG "ggml: enable Vulkan memory debug output" OFF)
178178
option(GGML_VULKAN_SHADER_DEBUG_INFO "ggml: enable Vulkan shader debug info" OFF)
179179
option(GGML_VULKAN_PERF "ggml: enable Vulkan perf output" OFF)
180+
option(GGML_VULKAN_DEBUG_UTILS "ggml: VK_EXT_debug_utils debug information" OFF)
180181
option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation" OFF)
181182
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
182183
option(GGML_KOMPUTE "ggml: use Kompute" OFF)

ggml/src/ggml-vulkan/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ if (Vulkan_FOUND)
113113
add_compile_definitions(GGML_VULKAN_PERF)
114114
endif()
115115

116+
if (GGML_VULKAN_DEBUG_UTILS)
117+
add_compile_definitions(GGML_VULKAN_DEBUG_UTILS)
118+
endif()
119+
116120
if (GGML_VULKAN_VALIDATE)
117121
add_compile_definitions(GGML_VULKAN_VALIDATE)
118122
endif()

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,11 @@ void vk_memory_logger::log_deallocation(vk_buffer_ref buf_ref) {
951951
struct vk_instance_t {
952952
vk::Instance instance;
953953

954+
#ifdef GGML_VULKAN_DEBUG_UTILS
955+
bool debug_utils_support = false; // VK_EXT_debug_utils enabled
956+
PFN_vkSetDebugUtilsObjectNameEXT pfnSetDebugUtilsObjectNameEXT = {};
957+
#endif
958+
954959
std::vector<size_t> device_indices;
955960
vk_device devices[GGML_VK_MAX_DEVICES];
956961
};
@@ -1108,6 +1113,16 @@ static void ggml_vk_create_pipeline_func(vk_device& device, vk_pipeline& pipelin
11081113
}
11091114
pipeline->compiled = true;
11101115

1116+
#ifdef GGML_VULKAN_DEBUG_UTILS
1117+
if (vk_instance.debug_utils_support) {
1118+
vk::DebugUtilsObjectNameInfoEXT duoni;
1119+
duoni.objectType = vk::ObjectType::ePipeline;
1120+
duoni.pObjectName = pipeline->name.c_str();
1121+
duoni.objectHandle = reinterpret_cast<uint64_t>(pipeline->pipeline.operator VkPipeline_T *());
1122+
vk_instance.pfnSetDebugUtilsObjectNameEXT(device->device, &static_cast<VkDebugUtilsObjectNameInfoEXT &>(duoni));
1123+
}
1124+
#endif
1125+
11111126
{
11121127
std::lock_guard<std::mutex> guard(device->mutex);
11131128
device->pipelines.insert({ pipeline->name, pipeline });
@@ -3483,6 +3498,10 @@ static void ggml_vk_print_gpu_info(size_t idx) {
34833498
static bool ggml_vk_instance_validation_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
34843499
static bool ggml_vk_instance_portability_enumeration_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
34853500

3501+
#ifdef GGML_VULKAN_DEBUG_UTILS
3502+
static bool ggml_vk_instance_debug_utils_ext_available(const std::vector<vk::ExtensionProperties> & instance_extensions);
3503+
#endif
3504+
34863505
static void ggml_vk_instance_init() {
34873506
if (vk_instance_initialized) {
34883507
return;
@@ -3503,7 +3522,9 @@ static void ggml_vk_instance_init() {
35033522
#ifdef __APPLE__
35043523
const bool portability_enumeration_ext = ggml_vk_instance_portability_enumeration_ext_available(instance_extensions);
35053524
#endif
3506-
3525+
#ifdef GGML_VULKAN_DEBUG_UTILS
3526+
const bool debug_utils_ext = ggml_vk_instance_debug_utils_ext_available(instance_extensions);
3527+
#endif
35073528
std::vector<const char*> layers;
35083529

35093530
if (validation_ext) {
@@ -3517,6 +3538,11 @@ static void ggml_vk_instance_init() {
35173538
if (portability_enumeration_ext) {
35183539
extensions.push_back("VK_KHR_portability_enumeration");
35193540
}
3541+
#endif
3542+
#ifdef GGML_VULKAN_DEBUG_UTILS
3543+
if (debug_utils_ext) {
3544+
extensions.push_back("VK_EXT_debug_utils");
3545+
}
35203546
#endif
35213547
vk::InstanceCreateInfo instance_create_info(vk::InstanceCreateFlags{}, &app_info, layers, extensions);
35223548
#ifdef __APPLE__
@@ -3541,6 +3567,13 @@ static void ggml_vk_instance_init() {
35413567
vk_instance.instance = vk::createInstance(instance_create_info);
35423568
vk_instance_initialized = true;
35433569

3570+
#ifdef GGML_VULKAN_DEBUG_UTILS
3571+
if (debug_utils_ext) {
3572+
vk_instance.pfnSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT) vkGetInstanceProcAddr(vk_instance.instance, "vkSetDebugUtilsObjectNameEXT");
3573+
vk_instance.debug_utils_support = vk_instance.pfnSetDebugUtilsObjectNameEXT != nullptr;
3574+
}
3575+
#endif
3576+
35443577
size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
35453578

35463579
// Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan
@@ -10066,6 +10099,24 @@ static bool ggml_vk_instance_portability_enumeration_ext_available(const std::ve
1006610099
UNUSED(instance_extensions);
1006710100
}
1006810101

10102+
#ifdef GGML_VULKAN_DEBUG_UTILS
10103+
// Extension availability
10104+
static bool ggml_vk_instance_debug_utils_ext_available(
10105+
const std::vector<vk::ExtensionProperties> & instance_extensions) {
10106+
// Check for portability enumeration extension for MoltenVK support
10107+
for (const auto & properties : instance_extensions) {
10108+
if (strcmp("VK_EXT_debug_utils", properties.extensionName) == 0) {
10109+
return true;
10110+
}
10111+
}
10112+
10113+
std::cerr << "ggml_vulkan: WARNING: Instance extension VK_EXT_debug_utils not found." << std::endl;
10114+
return false;
10115+
10116+
UNUSED(instance_extensions);
10117+
}
10118+
#endif
10119+
1006910120
static bool ggml_vk_khr_cooperative_matrix_support(const vk::PhysicalDeviceProperties& props, const vk::PhysicalDeviceDriverProperties& driver_props, vk_device_architecture arch) {
1007010121
switch (props.vendorID) {
1007110122
case VK_VENDOR_ID_INTEL:

0 commit comments

Comments
 (0)