Skip to content

Commit 3409ab8

Browse files
authored
vulkan: Set k_load_shmem to false when K is too large (ggml-org#19301)
1 parent c342c3b commit 3409ab8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,9 +3204,10 @@ static void ggml_vk_load_shaders(vk_device& device) {
32043204
const uint32_t D_lsb = D ^ (D & (D-1));
32053205
uint32_t D_split = std::min(std::min(device->subgroup_size, 8u), D_lsb / 4);
32063206

3207-
// Nvidia prefers shared memory use to load large tiles of K
3207+
// Nvidia prefers shared memory use to load large tiles of K.
3208+
// Switch to loading from global memory when it would use too much shared memory.
32083209
// AMD prefers loading K directly from global memory
3209-
const uint32_t k_load_shmem = device->vendor_id == VK_VENDOR_ID_NVIDIA ? 1 : 0;
3210+
const uint32_t k_load_shmem = device->vendor_id == VK_VENDOR_ID_NVIDIA && hsk < 256 ? 1 : 0;
32103211

32113212
return {wg_size, rows_cols[0], rows_cols[1], hsk, hsv, clamp, D_split, device->subgroup_size, k_load_shmem};
32123213
};
@@ -8412,7 +8413,7 @@ static bool ggml_vk_flash_attn_coopmat_shmem_support(const vk_device& device, co
84128413
const uint32_t sfshstride = (hsk <= 128) ? (Br + 8) : Br;
84138414
const uint32_t sfsh = Bc * sfshstride * acctype;
84148415

8415-
const bool k_load_shmem = device->vendor_id == VK_VENDOR_ID_NVIDIA;
8416+
const bool k_load_shmem = device->vendor_id == VK_VENDOR_ID_NVIDIA && hsk < 256;
84168417
const uint32_t kshstride = (k_load_shmem ? hsk_pad : MatBr) / 4 + 2;
84178418
const uint32_t vsh_stride = MatBc / 4 * row_split;
84188419
const uint32_t ksh = ((kshstride >= vsh_stride) ? (Bc * kshstride) : (Bc * vsh_stride)) * f16vec4;

0 commit comments

Comments
 (0)