mbaudier commited on
Commit
623b74d
·
1 Parent(s): 966a7bb

Disable GL_KHR_cooperative_matrix Vulkan extension if not available. (llama/11117)

Browse files

* Disable GL_KHR_cooperative_matrix Vulkan extension if not available.

* Perform Vulkan extensions checks in a more sensible order

* Remove unnecessary #ifdef directive

ggml/src/ggml-vulkan/CMakeLists.txt CHANGED
@@ -8,6 +8,20 @@ if (Vulkan_FOUND)
8
  ../../include/ggml-vulkan.h
9
  )
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported.
12
  # If it's not, there will be an error to stderr.
13
  # If it's supported, set a define to indicate that we should compile those shaders
 
8
  ../../include/ggml-vulkan.h
9
  )
10
 
11
+ # Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported.
12
+ # If it's not, there will be an error to stderr.
13
+ # If it's supported, set a define to indicate that we should compile those shaders
14
+ execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
15
+ OUTPUT_VARIABLE glslc_output
16
+ ERROR_VARIABLE glslc_error)
17
+
18
+ if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*")
19
+ message(STATUS "GL_KHR_cooperative_matrix not supported by glslc")
20
+ else()
21
+ message(STATUS "GL_KHR_cooperative_matrix supported by glslc")
22
+ add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
23
+ endif()
24
+
25
  # Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported.
26
  # If it's not, there will be an error to stderr.
27
  # If it's supported, set a define to indicate that we should compile those shaders
ggml/src/ggml-vulkan/ggml-vulkan.cpp CHANGED
@@ -1645,6 +1645,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
1645
  #undef CREATE_MM2
1646
  } else
1647
  #endif // defined(VK_NV_cooperative_matrix2) && defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
 
1648
  if (device->coopmat_support) {
1649
  // Create 6 variants, {s,m,l}x{unaligned,aligned}
1650
  #define CREATE_MM(PIPELINE_NAME, NAMELC, F16ACC, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT, ID) \
@@ -1739,7 +1740,9 @@ static void ggml_vk_load_shaders(vk_device& device) {
1739
  }
1740
  #undef CREATE_MM2
1741
  #undef CREATE_MM
1742
- } else if (device->fp16) {
 
 
1743
  // Create 6 variants, {s,m,l}x{unaligned,aligned}
1744
  #define CREATE_MM(PIPELINE_NAME, NAMELC, F16ACC, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT, ID) \
1745
  if (device->mul_mat ## ID ## _l) \
@@ -2242,6 +2245,7 @@ static vk_device ggml_vk_get_device(size_t idx) {
2242
  last_struct = (VkBaseOutStructure *)&subgroup_size_control_features;
2243
  }
2244
 
 
2245
  VkPhysicalDeviceCooperativeMatrixFeaturesKHR coopmat_features;
2246
  coopmat_features.pNext = nullptr;
2247
  coopmat_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR;
@@ -2251,6 +2255,7 @@ static vk_device ggml_vk_get_device(size_t idx) {
2251
  last_struct->pNext = (VkBaseOutStructure *)&coopmat_features;
2252
  last_struct = (VkBaseOutStructure *)&coopmat_features;
2253
  }
 
2254
 
2255
  #if defined(VK_NV_cooperative_matrix2)
2256
  VkPhysicalDeviceCooperativeMatrix2FeaturesNV coopmat2_features {};
@@ -2283,7 +2288,9 @@ static vk_device ggml_vk_get_device(size_t idx) {
2283
  device_extensions.push_back("VK_EXT_subgroup_size_control");
2284
  }
2285
 
 
2286
  device->coopmat_support = device->coopmat_support && coopmat_features.cooperativeMatrix;
 
2287
 
2288
  if (coopmat2_support) {
2289
  #if defined(VK_NV_cooperative_matrix2) && defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
@@ -2376,6 +2383,7 @@ static vk_device ggml_vk_get_device(size_t idx) {
2376
  device_extensions.push_back("VK_KHR_shader_float16_int8");
2377
  }
2378
 
 
2379
  if (device->coopmat_support) {
2380
  // Query supported shapes
2381
  std::vector<VkCooperativeMatrixPropertiesKHR> cm_props;
@@ -2442,7 +2450,7 @@ static vk_device ggml_vk_get_device(size_t idx) {
2442
  if (device->coopmat_support) {
2443
  device_extensions.push_back("VK_KHR_cooperative_matrix");
2444
  }
2445
-
2446
  device->name = GGML_VK_NAME + std::to_string(idx);
2447
 
2448
  device_create_info = {
@@ -2553,9 +2561,11 @@ static void ggml_vk_print_gpu_info(size_t idx) {
2553
  fp16_storage = true;
2554
  } else if (strcmp("VK_KHR_shader_float16_int8", properties.extensionName) == 0) {
2555
  fp16_compute = true;
2556
- } else if (strcmp("VK_KHR_cooperative_matrix", properties.extensionName) == 0 &&
 
2557
  !getenv("GGML_VK_DISABLE_COOPMAT")) {
2558
  coopmat_support = true;
 
2559
  #if defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
2560
  } else if (strcmp("VK_NV_cooperative_matrix2", properties.extensionName) == 0 &&
2561
  !getenv("GGML_VK_DISABLE_COOPMAT2")) {
@@ -2593,6 +2603,7 @@ static void ggml_vk_print_gpu_info(size_t idx) {
2593
  // Pointer to the last chain element
2594
  VkBaseOutStructure * last_struct = (VkBaseOutStructure *)&vk12_features;
2595
 
 
2596
  VkPhysicalDeviceCooperativeMatrixFeaturesKHR coopmat_features;
2597
  coopmat_features.pNext = nullptr;
2598
  coopmat_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR;
@@ -2608,6 +2619,7 @@ static void ggml_vk_print_gpu_info(size_t idx) {
2608
  fp16 = fp16 && vk12_features.shaderFloat16;
2609
 
2610
  coopmat_support = coopmat_support && coopmat_features.cooperativeMatrix;
 
2611
 
2612
  std::string matrix_cores = coopmat2_support ? "NV_coopmat2" : coopmat_support ? "KHR_coopmat" : "none";
2613
 
 
1645
  #undef CREATE_MM2
1646
  } else
1647
  #endif // defined(VK_NV_cooperative_matrix2) && defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
1648
+ #if defined(VK_KHR_cooperative_matrix) && defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
1649
  if (device->coopmat_support) {
1650
  // Create 6 variants, {s,m,l}x{unaligned,aligned}
1651
  #define CREATE_MM(PIPELINE_NAME, NAMELC, F16ACC, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT, ID) \
 
1740
  }
1741
  #undef CREATE_MM2
1742
  #undef CREATE_MM
1743
+ } else
1744
+ #endif // defined(VK_KHR_cooperative_matrix) && defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
1745
+ if (device->fp16) {
1746
  // Create 6 variants, {s,m,l}x{unaligned,aligned}
1747
  #define CREATE_MM(PIPELINE_NAME, NAMELC, F16ACC, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT, ID) \
1748
  if (device->mul_mat ## ID ## _l) \
 
2245
  last_struct = (VkBaseOutStructure *)&subgroup_size_control_features;
2246
  }
2247
 
2248
+ #if defined(VK_KHR_cooperative_matrix)
2249
  VkPhysicalDeviceCooperativeMatrixFeaturesKHR coopmat_features;
2250
  coopmat_features.pNext = nullptr;
2251
  coopmat_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR;
 
2255
  last_struct->pNext = (VkBaseOutStructure *)&coopmat_features;
2256
  last_struct = (VkBaseOutStructure *)&coopmat_features;
2257
  }
2258
+ #endif
2259
 
2260
  #if defined(VK_NV_cooperative_matrix2)
2261
  VkPhysicalDeviceCooperativeMatrix2FeaturesNV coopmat2_features {};
 
2288
  device_extensions.push_back("VK_EXT_subgroup_size_control");
2289
  }
2290
 
2291
+ #if defined(VK_KHR_cooperative_matrix)
2292
  device->coopmat_support = device->coopmat_support && coopmat_features.cooperativeMatrix;
2293
+ #endif
2294
 
2295
  if (coopmat2_support) {
2296
  #if defined(VK_NV_cooperative_matrix2) && defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
 
2383
  device_extensions.push_back("VK_KHR_shader_float16_int8");
2384
  }
2385
 
2386
+ #if defined(VK_KHR_cooperative_matrix)
2387
  if (device->coopmat_support) {
2388
  // Query supported shapes
2389
  std::vector<VkCooperativeMatrixPropertiesKHR> cm_props;
 
2450
  if (device->coopmat_support) {
2451
  device_extensions.push_back("VK_KHR_cooperative_matrix");
2452
  }
2453
+ #endif
2454
  device->name = GGML_VK_NAME + std::to_string(idx);
2455
 
2456
  device_create_info = {
 
2561
  fp16_storage = true;
2562
  } else if (strcmp("VK_KHR_shader_float16_int8", properties.extensionName) == 0) {
2563
  fp16_compute = true;
2564
+ #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
2565
+ } else if (strcmp("VK_KHR_cooperative_matrix", properties.extensionName) == 0 &&
2566
  !getenv("GGML_VK_DISABLE_COOPMAT")) {
2567
  coopmat_support = true;
2568
+ #endif
2569
  #if defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
2570
  } else if (strcmp("VK_NV_cooperative_matrix2", properties.extensionName) == 0 &&
2571
  !getenv("GGML_VK_DISABLE_COOPMAT2")) {
 
2603
  // Pointer to the last chain element
2604
  VkBaseOutStructure * last_struct = (VkBaseOutStructure *)&vk12_features;
2605
 
2606
+ #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
2607
  VkPhysicalDeviceCooperativeMatrixFeaturesKHR coopmat_features;
2608
  coopmat_features.pNext = nullptr;
2609
  coopmat_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR;
 
2619
  fp16 = fp16 && vk12_features.shaderFloat16;
2620
 
2621
  coopmat_support = coopmat_support && coopmat_features.cooperativeMatrix;
2622
+ #endif
2623
 
2624
  std::string matrix_cores = coopmat2_support ? "NV_coopmat2" : coopmat_support ? "KHR_coopmat" : "none";
2625
 
ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat_support.comp ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #version 460
2
+
3
+ #extension GL_KHR_cooperative_matrix : require
4
+
5
+ void main()
6
+ {
7
+ }
ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp CHANGED
@@ -342,9 +342,11 @@ void process_shaders() {
342
  matmul_shaders(true, matmul_id, false, false, false);
343
  matmul_shaders(true, matmul_id, false, false, true);
344
 
 
345
  // Coopmat, fp32acc and fp16acc
346
  matmul_shaders(true, matmul_id, true, false, false);
347
  matmul_shaders(true, matmul_id, true, false, true);
 
348
 
349
  #if defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
350
  // Coopmat2, fp32acc and fp16acc
 
342
  matmul_shaders(true, matmul_id, false, false, false);
343
  matmul_shaders(true, matmul_id, false, false, true);
344
 
345
+ #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
346
  // Coopmat, fp32acc and fp16acc
347
  matmul_shaders(true, matmul_id, true, false, false);
348
  matmul_shaders(true, matmul_id, true, false, true);
349
+ #endif
350
 
351
  #if defined(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
352
  // Coopmat2, fp32acc and fp16acc