Skip to content

vulkan: fix storageBuffer16BitAccess detection on some adreno driver #8837

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ggml/src/ggml-vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,16 +1743,21 @@ static vk_device ggml_vk_get_device(size_t idx) {
vk11_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
device_features2.pNext = &vk11_features;

VkPhysicalDevice16BitStorageFeatures storage_16bit;
storage_16bit.pNext = nullptr;
storage_16bit.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES;
vk11_features.pNext = &storage_16bit;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this is against the Vulkan Specification and causes a validation error when run with Validation layers enabled:

vkCreateDevice():  If the pNext chain includes a VkPhysicalDeviceVulkan11Features structure, then it must not include a VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES structure.

I'm not sure how to handle this properly, we could avoid VkPhysicalDeviceVulkan11Features entirely, but I don't want to do that just cause of Qualcomm driver issues. Do you have an idea?


VkPhysicalDeviceVulkan12Features vk12_features;
vk12_features.pNext = nullptr;
vk12_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
vk11_features.pNext = &vk12_features;
storage_16bit.pNext = &vk12_features;

vkGetPhysicalDeviceFeatures2(device->physical_device, &device_features2);

device->fp16 = device->fp16 && vk12_features.shaderFloat16;

if (!vk11_features.storageBuffer16BitAccess) {
if (!(vk11_features.storageBuffer16BitAccess && storage_16bit.storageBuffer16BitAccess)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!(vk11_features.storageBuffer16BitAccess && storage_16bit.storageBuffer16BitAccess)) {
if (!vk11_features.storageBuffer16BitAccess || !storage_16bit.storageBuffer16BitAccess) {

Just a nitpick, but I think it's more readable this way.

std::cerr << "ggml_vulkan: device " << GGML_VK_NAME << idx << " does not support 16-bit storage." << std::endl;
throw std::runtime_error("Unsupported device");
}
Expand Down Expand Up @@ -1860,15 +1865,10 @@ static void ggml_vk_print_gpu_info(size_t idx) {
device_features2.pNext = nullptr;
device_features2.features = (VkPhysicalDeviceFeatures)device_features;

VkPhysicalDeviceVulkan11Features vk11_features;
vk11_features.pNext = nullptr;
vk11_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
device_features2.pNext = &vk11_features;

VkPhysicalDeviceVulkan12Features vk12_features;
vk12_features.pNext = nullptr;
vk12_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
vk11_features.pNext = &vk12_features;
device_features2.pNext = &vk12_features;

vkGetPhysicalDeviceFeatures2(physical_device, &device_features2);

Expand Down
Loading