Skip to content

Commit 71a6498

Browse files
authored
vulkan: skip integer div/mod in get_offsets for batch_idx==0 (ggml-org#10506)
1 parent 4a57d36 commit 71a6498

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.comp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ void get_offsets(out uint a_offset, out uint b_offset, out uint d_offset) {
5252
#endif
5353

5454
#ifndef MUL_MAT_ID
55-
const uint i13 = batch_idx / p.ne12;
56-
const uint i12 = batch_idx % p.ne12;
55+
uint batch_idx_a = 0;
56+
if (batch_idx != 0) {
57+
const uint i13 = batch_idx / p.ne12;
58+
const uint i12 = batch_idx % p.ne12;
5759

58-
const uint i03 = i13 / p.broadcast3;
59-
const uint i02 = i12 / p.broadcast2;
60+
const uint i03 = i13 / p.broadcast3;
61+
const uint i02 = i12 / p.broadcast2;
6062

61-
const uint batch_idx_a = i03 * p.ne02 + i02;
63+
batch_idx_a = i03 * p.ne02 + i02;
64+
}
6265
#else
6366
const uint expert_id = data_ids[expert_idx];
6467
#endif

0 commit comments

Comments
 (0)