Skip to content

Commit

Permalink
blacklist mesa vulkan cooperative matrix feature (#5739)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Oct 17, 2024
1 parent 8105c75 commit bd1f39e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 9 deletions.
67 changes: 58 additions & 9 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ class GpuInfoPrivate
char device_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
uint8_t pipeline_cache_uuid[VK_UUID_SIZE];

// driver properties
uint32_t driver_id;
char driver_name[VK_MAX_DRIVER_NAME_SIZE];

// 0 = discrete gpu
// 1 = integrated gpu
// 2 = virtual gpu
Expand Down Expand Up @@ -349,6 +353,7 @@ class GpuInfoPrivate
int support_VK_KHR_cooperative_matrix;
int support_VK_KHR_dedicated_allocation;
int support_VK_KHR_descriptor_update_template;
int support_VK_KHR_driver_properties;
int support_VK_KHR_external_memory;
int support_VK_KHR_get_memory_requirements2;
int support_VK_KHR_maintenance1;
Expand Down Expand Up @@ -434,6 +439,16 @@ uint8_t* GpuInfo::pipeline_cache_uuid() const
return d->pipeline_cache_uuid;
}

uint32_t GpuInfo::driver_id() const
{
return d->driver_id;
}

const char* GpuInfo::driver_name() const
{
return d->driver_name;
}

int GpuInfo::type() const
{
return d->type;
Expand Down Expand Up @@ -709,6 +724,11 @@ int GpuInfo::support_VK_KHR_descriptor_update_template() const
return d->support_VK_KHR_descriptor_update_template;
}

int GpuInfo::support_VK_KHR_driver_properties() const
{
return d->support_VK_KHR_driver_properties;
}

int GpuInfo::support_VK_KHR_external_memory() const
{
return d->support_VK_KHR_external_memory;
Expand Down Expand Up @@ -1438,15 +1458,15 @@ int create_gpu_instance(const char* driver_path)
VkPhysicalDeviceProperties physicalDeviceProperties;
vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties);

// NCNN_LOGE("[%u] apiVersion = %u.%u.%u", i, VK_VERSION_MAJOR(physicalDeviceProperties.apiVersion),
// VK_VERSION_MINOR(physicalDeviceProperties.apiVersion), VK_VERSION_PATCH(physicalDeviceProperties.apiVersion));
// NCNN_LOGE("[%u] driverVersion = %u.%u.%u", i, VK_VERSION_MAJOR(physicalDeviceProperties.driverVersion),
// VK_VERSION_MINOR(physicalDeviceProperties.driverVersion), VK_VERSION_PATCH(physicalDeviceProperties.driverVersion));
// NCNN_LOGE("[%u] vendorID = %x", i, physicalDeviceProperties.vendorID);
// NCNN_LOGE("[%u] deviceID = %x", i, physicalDeviceProperties.deviceID);
// NCNN_LOGE("[%u] deviceType = %x", i, physicalDeviceProperties.deviceType);
// NCNN_LOGE("[%u] deviceName = %s", i, physicalDeviceProperties.deviceName);
// NCNN_LOGE("[%u] pipelineCacheUUID = %u", i, physicalDeviceProperties.pipelineCacheUUID);
// NCNN_LOGE("[%u] apiVersion = %u.%u.%u", i, VK_VERSION_MAJOR(physicalDeviceProperties.apiVersion),
// VK_VERSION_MINOR(physicalDeviceProperties.apiVersion), VK_VERSION_PATCH(physicalDeviceProperties.apiVersion));
// NCNN_LOGE("[%u] driverVersion = %u.%u.%u", i, VK_VERSION_MAJOR(physicalDeviceProperties.driverVersion),
// VK_VERSION_MINOR(physicalDeviceProperties.driverVersion), VK_VERSION_PATCH(physicalDeviceProperties.driverVersion));
// NCNN_LOGE("[%u] vendorID = %x", i, physicalDeviceProperties.vendorID);
// NCNN_LOGE("[%u] deviceID = %x", i, physicalDeviceProperties.deviceID);
// NCNN_LOGE("[%u] deviceType = %x", i, physicalDeviceProperties.deviceType);
// NCNN_LOGE("[%u] deviceName = %s", i, physicalDeviceProperties.deviceName);
// NCNN_LOGE("[%u] pipelineCacheUUID = %u", i, physicalDeviceProperties.pipelineCacheUUID);

// mali
// t760 = 0x13b5 0x7500001 / 0x7501000
Expand Down Expand Up @@ -1676,6 +1696,7 @@ int create_gpu_instance(const char* driver_path)
gpu_info.support_VK_KHR_cooperative_matrix = 0;
gpu_info.support_VK_KHR_dedicated_allocation = 0;
gpu_info.support_VK_KHR_descriptor_update_template = 0;
gpu_info.support_VK_KHR_driver_properties = 0;
gpu_info.support_VK_KHR_external_memory = 0;
gpu_info.support_VK_KHR_get_memory_requirements2 = 0;
gpu_info.support_VK_KHR_maintenance1 = 0;
Expand Down Expand Up @@ -1720,6 +1741,8 @@ int create_gpu_instance(const char* driver_path)
gpu_info.support_VK_KHR_dedicated_allocation = exp.specVersion;
else if (strcmp(exp.extensionName, "VK_KHR_descriptor_update_template") == 0)
gpu_info.support_VK_KHR_descriptor_update_template = exp.specVersion;
else if (strcmp(exp.extensionName, "VK_KHR_driver_properties") == 0)
gpu_info.support_VK_KHR_driver_properties = exp.specVersion;
else if (strcmp(exp.extensionName, "VK_KHR_external_memory") == 0)
gpu_info.support_VK_KHR_external_memory = exp.specVersion;
else if (strcmp(exp.extensionName, "VK_KHR_get_memory_requirements2") == 0)
Expand Down Expand Up @@ -1793,6 +1816,8 @@ int create_gpu_instance(const char* driver_path)
gpu_info.support_cooperative_matrix_16_8_8 = false;
gpu_info.support_cooperative_matrix_16_8_16 = false;
gpu_info.support_cooperative_matrix_16_16_16 = false;
gpu_info.driver_id = 0;
gpu_info.driver_name[0] = '\0';
if (support_VK_KHR_get_physical_device_properties2)
{
void* queryExtensionFeatures = 0;
Expand Down Expand Up @@ -1855,6 +1880,16 @@ int create_gpu_instance(const char* driver_path)
queryExtensionFeatures = &queryCooperativeMatrixFeaturesNV;
}

// query driver properties
VkPhysicalDeviceDriverPropertiesKHR queryDriverProperties;
queryDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
queryDriverProperties.pNext = 0;
if (gpu_info.support_VK_KHR_driver_properties)
{
queryDriverProperties.pNext = queryExtensionFeatures;
queryExtensionFeatures = &queryDriverProperties;
}

VkPhysicalDeviceFeatures2KHR queryFeatures;
queryFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
queryFeatures.pNext = queryExtensionFeatures;
Expand Down Expand Up @@ -1889,6 +1924,11 @@ int create_gpu_instance(const char* driver_path)
{
gpu_info.support_cooperative_matrix = queryCooperativeMatrixFeaturesNV.cooperativeMatrix;
}
if (gpu_info.support_VK_KHR_driver_properties)
{
gpu_info.driver_id = queryDriverProperties.driverID;
memcpy(gpu_info.driver_name, queryDriverProperties.driverName, VK_MAX_DRIVER_NAME_SIZE);
}
}
else
{
Expand Down Expand Up @@ -1921,6 +1961,13 @@ int create_gpu_instance(const char* driver_path)
gpu_info.support_fp16_arithmetic = false;
}

if (gpu_info.driver_id == VK_DRIVER_ID_MESA_RADV || gpu_info.driver_id == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA)
{
// cooperative matrix produces wrong result on mesa vulkan drivers :(
// https://gitlab.freedesktop.org/mesa/mesa/-/issues/10847
gpu_info.support_cooperative_matrix = false;
}

if (gpu_info.support_cooperative_matrix)
{
// query supported cooperative matrix types and operations
Expand Down Expand Up @@ -2462,6 +2509,8 @@ VulkanDevice::VulkanDevice(int device_index)
enabledExtensions.push_back("VK_KHR_dedicated_allocation");
if (info.support_VK_KHR_descriptor_update_template())
enabledExtensions.push_back("VK_KHR_descriptor_update_template");
if (info.support_VK_KHR_driver_properties())
enabledExtensions.push_back("VK_KHR_driver_properties");
if (info.support_VK_KHR_external_memory())
enabledExtensions.push_back("VK_KHR_external_memory");
if (info.support_VK_KHR_get_memory_requirements2())
Expand Down
5 changes: 5 additions & 0 deletions src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class NCNN_EXPORT GpuInfo
const char* device_name() const;
uint8_t* pipeline_cache_uuid() const;

// driver properties
uint32_t driver_id() const;
const char* driver_name() const;

// 0 = discrete gpu
// 1 = integrated gpu
// 2 = virtual gpu
Expand Down Expand Up @@ -287,6 +291,7 @@ class NCNN_EXPORT GpuInfo
int support_VK_KHR_cooperative_matrix() const;
int support_VK_KHR_dedicated_allocation() const;
int support_VK_KHR_descriptor_update_template() const;
int support_VK_KHR_driver_properties() const;
int support_VK_KHR_external_memory() const;
int support_VK_KHR_get_memory_requirements2() const;
int support_VK_KHR_maintenance1() const;
Expand Down
59 changes: 59 additions & 0 deletions src/vulkan_header_fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,4 +1219,63 @@ typedef struct VkPhysicalDeviceCooperativeMatrixPropertiesKHR
typedef VkResult(VKAPI_PTR* PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkCooperativeMatrixPropertiesKHR* pProperties);
#endif // VK_KHR_cooperative_matrix

#ifndef VK_KHR_driver_properties
#define VK_KHR_driver_properties 1
#define VK_MAX_DRIVER_NAME_SIZE 256U
#define VK_MAX_DRIVER_INFO_SIZE 256U
#define VK_MAX_DRIVER_NAME_SIZE_KHR VK_MAX_DRIVER_NAME_SIZE
#define VK_MAX_DRIVER_INFO_SIZE_KHR VK_MAX_DRIVER_INFO_SIZE
#define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES (VkStructureType)1000196000
#define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES
typedef enum VkDriverId
{
VK_DRIVER_ID_AMD_PROPRIETARY = 1,
VK_DRIVER_ID_AMD_OPEN_SOURCE = 2,
VK_DRIVER_ID_MESA_RADV = 3,
VK_DRIVER_ID_NVIDIA_PROPRIETARY = 4,
VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS = 5,
VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA = 6,
VK_DRIVER_ID_IMAGINATION_PROPRIETARY = 7,
VK_DRIVER_ID_QUALCOMM_PROPRIETARY = 8,
VK_DRIVER_ID_ARM_PROPRIETARY = 9,
VK_DRIVER_ID_GOOGLE_SWIFTSHADER = 10,
VK_DRIVER_ID_GGP_PROPRIETARY = 11,
VK_DRIVER_ID_BROADCOM_PROPRIETARY = 12,
VK_DRIVER_ID_MESA_LLVMPIPE = 13,
VK_DRIVER_ID_MOLTENVK = 14,
VK_DRIVER_ID_COREAVI_PROPRIETARY = 15,
VK_DRIVER_ID_JUICE_PROPRIETARY = 16,
VK_DRIVER_ID_VERISILICON_PROPRIETARY = 17,
VK_DRIVER_ID_MESA_TURNIP = 18,
VK_DRIVER_ID_MESA_V3DV = 19,
VK_DRIVER_ID_MESA_PANVK = 20,
VK_DRIVER_ID_SAMSUNG_PROPRIETARY = 21,
VK_DRIVER_ID_MESA_VENUS = 22,
VK_DRIVER_ID_MESA_DOZEN = 23,
VK_DRIVER_ID_MESA_NVK = 24,
VK_DRIVER_ID_IMAGINATION_OPEN_SOURCE_MESA = 25,
VK_DRIVER_ID_MESA_AGXV = 26,
VK_DRIVER_ID_MAX_ENUM = 0x7FFFFFFF
} VkDriverId;
typedef struct VkConformanceVersion
{
uint8_t major;
uint8_t minor;
uint8_t subminor;
uint8_t patch;
} VkConformanceVersion;
typedef struct VkPhysicalDeviceDriverProperties
{
VkStructureType sType;
void* pNext;
VkDriverId driverID;
char driverName[VK_MAX_DRIVER_NAME_SIZE];
char driverInfo[VK_MAX_DRIVER_INFO_SIZE];
VkConformanceVersion conformanceVersion;
} VkPhysicalDeviceDriverProperties;
typedef VkDriverId VkDriverIdKHR;
typedef VkConformanceVersion VkConformanceVersionKHR;
typedef VkPhysicalDeviceDriverProperties VkPhysicalDeviceDriverPropertiesKHR;
#endif // VK_KHR_driver_properties

#endif // NCNN_VULKAN_HEADER_FIX_H

0 comments on commit bd1f39e

Please sign in to comment.