From 1c2e774a9e50d76d5ad37d58a90db4c90bdb967e Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Fri, 2 Jan 2026 17:33:08 +0100 Subject: [PATCH 1/2] vulkan: fix SIGSEGV on Android when using buffer_device_address vkGetBufferDeviceAddress is not loaded without explicit VK_KHR_buffer_device_address extension Also init disaptcher with device as (optionally) documented in https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers- ``` ********** Crash dump: ********** #00 0x0000000000000000 #01 0x000000000317c7b4 libggml-vulkan.so vk::Device::getBufferAddress(vk::BufferDeviceAddressInfo const&, vk::DispatchLoaderDynamic const&) const vulkan/vulkan_funcs.hpp:6563:30 ggml_vk_create_buffer(std::shared_ptr&, unsigned long, std::initializer_list> const&) ggml/src/ggml-vulkan/ggml-vulkan.cpp:2469:40 #02 0x000000000317b728 libggml-vulkan.so ggml_vk_create_buffer_device(std::shared_ptr&, unsigned long) ggml/src/ggml-vulkan/ggml-vulkan.cpp:2497:19 #03 0x000000000317b4b0 libggml-vulkan.so ggml_backend_vk_buffer_type_alloc_buffer(ggml_backend_buffer_type*, unsigned long) ggml/src/ggml-vulkan/ggml-vulkan.cpp:12591:22 #04 0x000000000006f3a8 libggml-base.so alloc_tensor_range ggml/src/ggml-alloc.c:1135:36 #05 0x000000000006e608 libggml-base.so ggml_backend_alloc_ctx_tensors_from_buft_impl ggml/src/ggml-alloc.c:1206:27 #06 0x000000000006e70c libggml-base.so ggml_backend_alloc_ctx_tensors_from_buft ggml/src/ggml-alloc.c:1244:12 #07 0x0000000000037d04 libwhisper.so whisper_model_load(whisper_model_loader*, whisper_context&) src/whisper.cpp:1852:37 #08 0x000000000003653c libwhisper.so whisper_init_with_params_no_state src/whisper.cpp:3723:10 #09 0x0000000000038768 libwhisper.so whisper_init_with_params src/whisper.cpp:3766:29 ``` --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 493ee9c9a44..bb1ecee0a8b 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -4353,6 +4353,7 @@ static vk_device ggml_vk_get_device(size_t idx) { device->coopmat_support = false; device->integer_dot_product = false; bool bfloat16_support = false; + bool buffer_device_address_khr = false; for (const auto& properties : ext_props) { if (strcmp("VK_KHR_maintenance4", properties.extensionName) == 0) { @@ -4397,6 +4398,8 @@ static vk_device ggml_vk_get_device(size_t idx) { } else if (strcmp("VK_EXT_memory_priority", properties.extensionName) == 0 && getenv("GGML_VK_ENABLE_MEMORY_PRIORITY")) { device->memory_priority = true; + } else if (strcmp("VK_KHR_buffer_device_address", properties.extensionName) == 0) { + buffer_device_address_khr = true; } } @@ -4801,6 +4804,11 @@ static vk_device ggml_vk_get_device(size_t idx) { device_extensions.push_back("VK_KHR_shader_float16_int8"); } + // Required for physical devices that only support Vulkan 1.1 + if (device->buffer_device_address && buffer_device_address_khr) { + device_extensions.push_back("VK_KHR_buffer_device_address"); + } + #if defined(VK_KHR_cooperative_matrix) if (device->coopmat_support) { // Query supported shapes @@ -4924,6 +4932,10 @@ static vk_device ggml_vk_get_device(size_t idx) { device_create_info.setPNext(&device_features2); device->device = device->physical_device.createDevice(device_create_info); + // optionally initialize the dispatcher with a vk::Device to get + // device-specific function pointers (needed on Android) + VULKAN_HPP_DEFAULT_DISPATCHER.init(device->device); + // Queues ggml_vk_create_queue(device, device->compute_queue, compute_queue_family_index, 0, { vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eTransfer }, false); From 2d7a110dd1a67f8c05d941b494c6aaa7e29eebe0 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Sat, 3 Jan 2026 17:16:48 +0100 Subject: [PATCH 2/2] vulkan: don't load core extensions Fix SIGABRT on Android emulator: ``` terminating due to uncaught exception of type vk::ExtensionNotPresentError: vk::PhysicalDevice::createDevice: ErrorExtensionNotPresent ``` --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index bb1ecee0a8b..0af127fabb0 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -4794,7 +4794,9 @@ static vk_device ggml_vk_get_device(size_t idx) { throw std::runtime_error("Unsupported device"); } - device_extensions.push_back("VK_KHR_16bit_storage"); + if (fp16_storage) { + device_extensions.push_back("VK_KHR_16bit_storage"); + } #ifdef GGML_VULKAN_VALIDATE device_extensions.push_back("VK_KHR_shader_non_semantic_info");