Skip to content

Commit 32b17ab

Browse files
authored
vulkan: disable coopmat1 fa on Nvidia Turing (ggml-org#19290)
1 parent 8bece2e commit 32b17ab

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ enum vk_device_architecture {
254254
AMD_RDNA3,
255255
INTEL_XE2,
256256
NVIDIA_PRE_TURING,
257+
NVIDIA_TURING,
257258
};
258259

259260
static vk_device_architecture get_device_architecture(const vk::PhysicalDevice& device) {
@@ -336,18 +337,34 @@ static vk_device_architecture get_device_architecture(const vk::PhysicalDevice&
336337
const std::vector<vk::ExtensionProperties> ext_props = device.enumerateDeviceExtensionProperties();
337338

338339
bool cooperative_matrix = false;
340+
bool sm_builtins = false;
339341

340342
// Detect "pre-turing" based on lack of coopmat support.
341343
for (const auto& properties : ext_props) {
342344
if (strcmp("VK_KHR_cooperative_matrix", properties.extensionName) == 0) {
343345
cooperative_matrix = true;
344-
break;
346+
} else if (strcmp("VK_NV_shader_sm_builtins", properties.extensionName) == 0) {
347+
sm_builtins = true;
345348
}
346349
}
347350

348351
if (!cooperative_matrix) {
349352
return vk_device_architecture::NVIDIA_PRE_TURING;
350353
}
354+
355+
if (sm_builtins) {
356+
vk::PhysicalDeviceProperties2 props2;
357+
vk::PhysicalDeviceShaderSMBuiltinsPropertiesNV sm_props;
358+
359+
props2.pNext = &sm_props;
360+
361+
device.getProperties2(&props2);
362+
363+
// Turing has 32, following architectures have 48
364+
if (sm_props.shaderWarpsPerSM == 32) {
365+
return vk_device_architecture::NVIDIA_TURING;
366+
}
367+
}
351368
}
352369
return vk_device_architecture::OTHER;
353370
}
@@ -8460,6 +8477,11 @@ static void ggml_vk_flash_attn(ggml_backend_vk_context * ctx, vk_context& subctx
84608477
FaCodePath path = ctx->device->coopmat2 ? FA_COOPMAT2 :
84618478
ctx->device->coopmat1_fa_support ? FA_COOPMAT1 : FA_SCALAR;
84628479

8480+
if (path == FA_COOPMAT1 && ctx->device->architecture == vk_device_architecture::NVIDIA_TURING) {
8481+
// Nvidia compiler bug, see https://github.com/ggml-org/llama.cpp/pull/19075#issuecomment-3820716090
8482+
path = FA_SCALAR;
8483+
}
8484+
84638485
if (path == FA_COOPMAT1) {
84648486
const bool coopmat_shape_supported = (dst->op_params[3] == GGML_PREC_F32 && ctx->device->coopmat_support_16x16x16_f32acc) ||
84658487
(dst->op_params[3] != GGML_PREC_F32 && ctx->device->coopmat_support_16x16x16_f16acc);

0 commit comments

Comments
 (0)