Skip to content

Commit 2949725

Browse files
committed
q4_0c: prefetch on AVX-512 and ARM
Seems significant especially for evaluation time
1 parent 1b49d26 commit 2949725

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ggml.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,10 +3126,17 @@ static void ggml_vec_dot_q4_0c_q8_0c(const int n, float * restrict s, const void
31263126
float sumf = 0.0;
31273127

31283128
#if defined(__ARM_NEON)
3129+
const int ahead=80;
31293130
float32x4_t sumv0 = vdupq_n_f32(0.0f);
31303131
float32x4_t sumv1 = vdupq_n_f32(0.0f);
31313132

31323133
for (int i = 0; i < nb/2; i++) {
3134+
__builtin_prefetch(&xqs[i*QK4_0 + 64*ahead]);
3135+
__builtin_prefetch(&yqs[2*i*QK8_0C + 64*ahead]);
3136+
__builtin_prefetch(&yqs[2*i*QK8_0C + 64*ahead + 64]);
3137+
__builtin_prefetch(&xds[2*i + 64/4*ahead]);
3138+
__builtin_prefetch(&yds[2*i + 64/4*ahead]);
3139+
31333140
const int dst0 = i + i/2*2; // 0, 1, 4, 5, 8, 9, ...
31343141
const int dst1 = i + i/2*2 + 2; // 2, 3, 6, 7, 10, 11 ...
31353142

@@ -3188,9 +3195,15 @@ static void ggml_vec_dot_q4_0c_q8_0c(const int n, float * restrict s, const void
31883195
sumf = vaddvq_f32(sumv0) + vaddvq_f32(sumv1);
31893196

31903197
#elif defined(__AVX512F__)
3198+
const int ahead = 64;
31913199
// Initialize accumulator with zeros
31923200
__m512 acc = _mm512_setzero_ps();
31933201
for (int i = 0; i < nb; i += 4) {
3202+
_mm_prefetch(xqs + i*QK4_0/2 + 64*ahead, _MM_HINT_T0);
3203+
_mm_prefetch(yqs + i*QK8_0 + 64*ahead, _MM_HINT_T0);
3204+
_mm_prefetch(yqs + i*QK8_0 + 64*ahead + 64, _MM_HINT_T0);
3205+
_mm_prefetch(xds + i + 64/4*ahead, _MM_HINT_T0);
3206+
_mm_prefetch(yds + i + 64/4*ahead, _MM_HINT_T0);
31943207
acc = dot_q4_0c_fourblocks_avx512(acc, xqs + i*QK4_0/2, xds + i, yqs + i*QK8_0, yds + i);
31953208
}
31963209
// Horizontal sum of all lanes of the accumulator

0 commit comments

Comments
 (0)