@@ -1041,6 +1041,11 @@ void vk_memory_logger::log_deallocation(vk_buffer_ref buf_ref) {
1041
1041
struct vk_instance_t {
1042
1042
vk::Instance instance;
1043
1043
1044
+ #ifdef GGML_VULKAN_DEBUG_UTILS
1045
+ bool debug_utils_support = false; // VK_EXT_debug_utils enabled
1046
+ PFN_vkSetDebugUtilsObjectNameEXT pfnSetDebugUtilsObjectNameEXT = {};
1047
+ #endif
1048
+
1044
1049
std::vector<size_t> device_indices;
1045
1050
vk_device devices[GGML_VK_MAX_DEVICES];
1046
1051
};
@@ -1180,6 +1185,16 @@ static void ggml_vk_create_pipeline_func(vk_device& device, vk_pipeline& pipelin
1180
1185
}
1181
1186
pipeline->compiled = true;
1182
1187
1188
+ #ifdef GGML_VULKAN_DEBUG_UTILS
1189
+ if (vk_instance.debug_utils_support) {
1190
+ vk::DebugUtilsObjectNameInfoEXT duoni;
1191
+ duoni.objectType = vk::ObjectType::ePipeline;
1192
+ duoni.pObjectName = pipeline->name.c_str();
1193
+ duoni.objectHandle = reinterpret_cast<uint64_t>(pipeline->pipeline.operator VkPipeline_T *());
1194
+ vk_instance.pfnSetDebugUtilsObjectNameEXT(device->device, &static_cast<VkDebugUtilsObjectNameInfoEXT &>(duoni));
1195
+ }
1196
+ #endif
1197
+
1183
1198
{
1184
1199
std::lock_guard<std::mutex> guard(device->mutex);
1185
1200
device->pipelines.insert({ pipeline->name, pipeline });
@@ -3561,6 +3576,10 @@ static void ggml_vk_print_gpu_info(size_t idx) {
3561
3576
static bool ggml_vk_instance_validation_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
3562
3577
static bool ggml_vk_instance_portability_enumeration_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
3563
3578
3579
+ #ifdef GGML_VULKAN_DEBUG_UTILS
3580
+ static bool ggml_vk_instance_debug_utils_ext_available(const std::vector<vk::ExtensionProperties> & instance_extensions);
3581
+ #endif
3582
+
3564
3583
static void ggml_vk_instance_init() {
3565
3584
if (vk_instance_initialized) {
3566
3585
return;
@@ -3581,7 +3600,9 @@ static void ggml_vk_instance_init() {
3581
3600
#ifdef __APPLE__
3582
3601
const bool portability_enumeration_ext = ggml_vk_instance_portability_enumeration_ext_available(instance_extensions);
3583
3602
#endif
3584
-
3603
+ #ifdef GGML_VULKAN_DEBUG_UTILS
3604
+ const bool debug_utils_ext = ggml_vk_instance_debug_utils_ext_available(instance_extensions);
3605
+ #endif
3585
3606
std::vector<const char*> layers;
3586
3607
3587
3608
if (validation_ext) {
@@ -3595,6 +3616,11 @@ static void ggml_vk_instance_init() {
3595
3616
if (portability_enumeration_ext) {
3596
3617
extensions.push_back("VK_KHR_portability_enumeration");
3597
3618
}
3619
+ #endif
3620
+ #ifdef GGML_VULKAN_DEBUG_UTILS
3621
+ if (debug_utils_ext) {
3622
+ extensions.push_back("VK_EXT_debug_utils");
3623
+ }
3598
3624
#endif
3599
3625
vk::InstanceCreateInfo instance_create_info(vk::InstanceCreateFlags{}, &app_info, layers, extensions);
3600
3626
#ifdef __APPLE__
@@ -3619,6 +3645,14 @@ static void ggml_vk_instance_init() {
3619
3645
vk_instance.instance = vk::createInstance(instance_create_info);
3620
3646
vk_instance_initialized = true;
3621
3647
3648
+ #ifdef GGML_VULKAN_DEBUG_UTILS
3649
+ if (debug_utils_ext) {
3650
+ vk_instance.pfnSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT) vkGetInstanceProcAddr(vk_instance.instance, "vkSetDebugUtilsObjectNameEXT");
3651
+ vk_instance.debug_utils_support = vk_instance.pfnSetDebugUtilsObjectNameEXT != nullptr;
3652
+ }
3653
+ #endif
3654
+
3655
+ size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
3622
3656
vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr;
3623
3657
3624
3658
// Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan
@@ -10339,6 +10373,24 @@ static bool ggml_vk_instance_portability_enumeration_ext_available(const std::ve
10339
10373
UNUSED(instance_extensions);
10340
10374
}
10341
10375
10376
+ #ifdef GGML_VULKAN_DEBUG_UTILS
10377
+ // Extension availability
10378
+ static bool ggml_vk_instance_debug_utils_ext_available(
10379
+ const std::vector<vk::ExtensionProperties> & instance_extensions) {
10380
+ // Check for portability enumeration extension for MoltenVK support
10381
+ for (const auto & properties : instance_extensions) {
10382
+ if (strcmp("VK_EXT_debug_utils", properties.extensionName) == 0) {
10383
+ return true;
10384
+ }
10385
+ }
10386
+
10387
+ std::cerr << "ggml_vulkan: WARNING: Instance extension VK_EXT_debug_utils not found." << std::endl;
10388
+ return false;
10389
+
10390
+ UNUSED(instance_extensions);
10391
+ }
10392
+ #endif
10393
+
10342
10394
static bool ggml_vk_khr_cooperative_matrix_support(const vk::PhysicalDeviceProperties& props, const vk::PhysicalDeviceDriverProperties& driver_props, vk_device_architecture arch) {
10343
10395
switch (props.vendorID) {
10344
10396
case VK_VENDOR_ID_INTEL:
0 commit comments