Skip to content

Commit 9f51f3e

Browse files
committed
metal : opt mul_mm_id
1 parent 21e100d commit 9f51f3e

File tree

1 file changed

+0
-15
lines changed

1 file changed

+0
-15
lines changed

ggml-metal.metal

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,7 +3974,6 @@ void kernel_mul_mm_impl(device const uchar * src0,
39743974
}
39753975

39763976
// same as kernel_mul_mm_impl, but src1 and dst are accessed via indices stored in src1ids
3977-
// TODO: simplify and optimize constants
39783977
template<typename block_q, short nl, void (*dequantize_func)(device const block_q *, short, thread half4x4 &)>
39793978
void kernel_mul_mm_id_impl(
39803979
device const uchar * src0,
@@ -4042,7 +4041,6 @@ void kernel_mul_mm_id_impl(
40424041
dequantize_func(x, il, temp_a);
40434042
threadgroup_barrier(mem_flags::mem_threadgroup);
40444043

4045-
#pragma unroll(16)
40464044
for (int i = 0; i < 16; i++) {
40474045
*(sa + SG_MAT_SIZE * ((tiitg / THREAD_PER_ROW / 8) \
40484046
+ (tiitg % THREAD_PER_ROW) * 16 + (i / 8) * 8) \
@@ -4061,38 +4059,25 @@ void kernel_mul_mm_id_impl(
40614059
threadgroup half * lsma = (sa + THREAD_MAT_M * SG_MAT_SIZE * (sgitg % 2));
40624060
threadgroup float * lsmb = (sb + THREAD_MAT_N * SG_MAT_SIZE * (sgitg / 2));
40634061

4064-
#pragma unroll(4)
40654062
for (int ik = 0; ik < BLOCK_SIZE_K / 8; ik++) {
4066-
#pragma unroll(4)
40674063
for (int i = 0; i < 4; i++) {
40684064
simdgroup_load(ma[i],lsma + SG_MAT_SIZE * i);
40694065
}
40704066
simdgroup_barrier(mem_flags::mem_none);
4071-
#pragma unroll(2)
40724067
for (int i = 0; i < 2; i++) {
40734068
simdgroup_load(mb[i],lsmb + SG_MAT_SIZE * i);
40744069
}
40754070

40764071
lsma += BLOCK_SIZE_M / SG_MAT_ROW * SG_MAT_SIZE;
40774072
lsmb += BLOCK_SIZE_N / SG_MAT_ROW * SG_MAT_SIZE;
40784073

4079-
#pragma unroll(8)
40804074
for (int i = 0; i < 8; i++){
40814075
simdgroup_multiply_accumulate(c_res[i], mb[i/4], ma[i%4], c_res[i]);
40824076
}
40834077
}
40844078
}
40854079

4086-
// TODO: this branch is invalid - need to fix it
4087-
//if ((r0 + 1) * BLOCK_SIZE_M <= ne0 && (r1 + 1) * BLOCK_SIZE_N <= ne1) {
4088-
// device float * C = dst + (BLOCK_SIZE_M * r0 + 32 * (sgitg & 1)) \
4089-
// + im*ne1*ne0;
4090-
// for (int i = 0; i < 8; i++) {
4091-
// simdgroup_store(c_res[i], C + 8 * (i%4) + ne0*src1ids[8*(i/4) + BLOCK_SIZE_N * r1 + 16 * (sgitg >> 1)], ne0);
4092-
// }
4093-
//} else {
40944080
{
4095-
// block is smaller than 64x32, we should avoid writing data outside of the matrix
40964081
threadgroup_barrier(mem_flags::mem_threadgroup);
40974082
threadgroup float * temp_str = ((threadgroup float *)shared_memory) \
40984083
+ 32 * (sgitg&1) + (16 * (sgitg>>1)) * BLOCK_SIZE_M;

0 commit comments

Comments
 (0)