@@ -1041,6 +1041,11 @@ void vk_memory_logger::log_deallocation(vk_buffer_ref buf_ref) {
10411041struct vk_instance_t {
10421042 vk::Instance instance;
10431043
1044+ #ifdef GGML_VULKAN_DEBUG_UTILS
1045+ bool debug_utils_support = false; // VK_EXT_debug_utils enabled
1046+ PFN_vkSetDebugUtilsObjectNameEXT pfnSetDebugUtilsObjectNameEXT = {};
1047+ #endif
1048+
10441049 std::vector<size_t> device_indices;
10451050 vk_device devices[GGML_VK_MAX_DEVICES];
10461051};
@@ -1180,6 +1185,16 @@ static void ggml_vk_create_pipeline_func(vk_device& device, vk_pipeline& pipelin
11801185 }
11811186 pipeline->compiled = true;
11821187
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+
11831198 {
11841199 std::lock_guard<std::mutex> guard(device->mutex);
11851200 device->pipelines.insert({ pipeline->name, pipeline });
@@ -3561,6 +3576,10 @@ static void ggml_vk_print_gpu_info(size_t idx) {
35613576static bool ggml_vk_instance_validation_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
35623577static bool ggml_vk_instance_portability_enumeration_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
35633578
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+
35643583static void ggml_vk_instance_init() {
35653584 if (vk_instance_initialized) {
35663585 return;
@@ -3581,7 +3600,9 @@ static void ggml_vk_instance_init() {
35813600#ifdef __APPLE__
35823601 const bool portability_enumeration_ext = ggml_vk_instance_portability_enumeration_ext_available(instance_extensions);
35833602#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
35853606 std::vector<const char*> layers;
35863607
35873608 if (validation_ext) {
@@ -3595,6 +3616,11 @@ static void ggml_vk_instance_init() {
35953616 if (portability_enumeration_ext) {
35963617 extensions.push_back("VK_KHR_portability_enumeration");
35973618 }
3619+ #endif
3620+ #ifdef GGML_VULKAN_DEBUG_UTILS
3621+ if (debug_utils_ext) {
3622+ extensions.push_back("VK_EXT_debug_utils");
3623+ }
35983624#endif
35993625 vk::InstanceCreateInfo instance_create_info(vk::InstanceCreateFlags{}, &app_info, layers, extensions);
36003626#ifdef __APPLE__
@@ -3619,6 +3645,14 @@ static void ggml_vk_instance_init() {
36193645 vk_instance.instance = vk::createInstance(instance_create_info);
36203646 vk_instance_initialized = true;
36213647
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();
36223656 vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr;
36233657
36243658 // Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan
@@ -10339,6 +10373,24 @@ static bool ggml_vk_instance_portability_enumeration_ext_available(const std::ve
1033910373 UNUSED(instance_extensions);
1034010374}
1034110375
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+
1034210394static bool ggml_vk_khr_cooperative_matrix_support(const vk::PhysicalDeviceProperties& props, const vk::PhysicalDeviceDriverProperties& driver_props, vk_device_architecture arch) {
1034310395 switch (props.vendorID) {
1034410396 case VK_VENDOR_ID_INTEL:
0 commit comments