diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 60cebe494..8ff376a3a 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -1256,6 +1256,10 @@ static vk_fa_tuning_params get_fa_tuning_params_scalar(const vk_device& device, result.d_split = std::min(std::min(result.subgroup_size, 8u), D_lsb / 4); + // Staging K/V through shared memory is a loss on AMD GCN: measured -6.7% at depth 16k and + // -7.4% at 32k on Polaris (head size 128). The kvsh stride of D/4+1 dwords is 4 mod 32, which + // costs an 8-way LDS bank conflict on wave64, and the extra shared memory cuts into occupancy + // that this shader is already short of. Keep it to NVIDIA. result.shmem_staging = (device->vendor_id == VK_VENDOR_ID_NVIDIA && hsk < 256 && hsv < 256) ? 1 : 0; if (!reduce_block_rows && result.block_rows > 1 && !ggml_vk_flash_attn_scalar_shmem_support(device, result, hsk, hsv, f32acc, k_type, v_type)) { @@ -9200,8 +9204,10 @@ void ggml_vk_flash_attn(ggml_backend_vk_context * ctx, vk_context& subctx, const } // Only use mask opt when the mask is fairly large. This hasn't been tuned extensively. + // GCN with large head size (>= 256) benefits in high-context prefill (skipping the + // per-block mask add on fully-visible blocks dominates), so enable it there too. bool use_mask_opt = mask && !use_sparse && nem1 >= 32 && nem0 * nem1 > 32768 && nem0 >= tuning_params.block_cols * 16 - && (ctx->device->architecture != vk_device_architecture::AMD_GCN || HSK > 256 || HSV > 256); + && (ctx->device->architecture != vk_device_architecture::AMD_GCN || HSK >= 256 || HSV >= 256); vk_fa_pipeline_state fa_pipeline_state = get_fa_pipeline_state(ctx->device, tuning_params, HSK, HSV, aligned, f32acc, mask != nullptr, use_mask_opt, logit_softcap != 0, use_sparse, k_type_eff, v_type_eff);