ggml-cpu: Enable tiled matmul on AIX (#25199)
The matmul_tiled path uses large local stack buffers for A_pack and B_pack. On AIX this can trigger a segmentation fault, so reduce the buffer footprint there to keep the tiled path usable.
Performance Impact:
~ 2x gains in PP_Speed for FP32, Q4_0 and Q8_0 models tested with llama-bench, llama-batched-bench and llama-cli.
Models used: Llama3.2 3b Instruct F32, qwen 2.5 3b Q4_0 and Q8_0
This commit is contained in:
@@ -2321,24 +2321,28 @@ class tinyBLAS_Q0_PPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void matmul(int64_t m, int64_t n) {
|
void matmul(int64_t m, int64_t n) {
|
||||||
#if defined(_AIX) || defined(__BIG_ENDIAN__)
|
int64_t mc = 64;
|
||||||
mnpack(0, m, 0, n);
|
|
||||||
#else
|
|
||||||
const int64_t mc = 64;
|
|
||||||
const int64_t kc = 64;
|
|
||||||
int64_t nc = 64;
|
int64_t nc = 64;
|
||||||
|
int64_t kc = 64;
|
||||||
|
int64_t n_chunk = 64;
|
||||||
|
#if defined(_AIX) || defined(__BIG_ENDIAN__)
|
||||||
|
mc = 32;
|
||||||
|
nc = 32;
|
||||||
|
kc = 32;
|
||||||
|
n_chunk = 32
|
||||||
|
#endif
|
||||||
int64_t n_aligned = 0;
|
int64_t n_aligned = 0;
|
||||||
if (n % 64 == 0) {
|
if (n % n_chunk == 0) {
|
||||||
n_aligned = n;
|
n_aligned = n;
|
||||||
} else if (n == 4) {
|
} else if (n == 4) {
|
||||||
n_aligned = 4;
|
n_aligned = 4;
|
||||||
} else if (n < 64) {
|
} else if (n < n_chunk) {
|
||||||
n_aligned = (n / 8) * 8;
|
n_aligned = (n / 8) * 8;
|
||||||
} else {
|
} else {
|
||||||
n_aligned = (n / 64) * 64;
|
n_aligned = (n / n_chunk) * n_chunk;
|
||||||
}
|
}
|
||||||
if (n_aligned > 0) {
|
if (n_aligned > 0) {
|
||||||
if (n_aligned % 64 == 0) nc = 64;
|
if (n_aligned % n_chunk == 0) nc = n_chunk;
|
||||||
else if (n_aligned == n) nc = n;
|
else if (n_aligned == n) nc = n;
|
||||||
else if (n_aligned % 32 == 0) nc = 32;
|
else if (n_aligned % 32 == 0) nc = 32;
|
||||||
else if (n_aligned % 24 == 0) nc = 24;
|
else if (n_aligned % 24 == 0) nc = 24;
|
||||||
@@ -2354,7 +2358,6 @@ class tinyBLAS_Q0_PPC {
|
|||||||
} else {
|
} else {
|
||||||
mnpack(0, m, 0, n);
|
mnpack(0, m, 0, n);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -3195,16 +3198,19 @@ class tinyBLAS_PPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void matmul(int64_t m, int64_t n) {
|
void matmul(int64_t m, int64_t n) {
|
||||||
|
int64_t mc = 256;
|
||||||
|
int64_t nc = 256;
|
||||||
|
int64_t kc = 256;
|
||||||
#if defined(_AIX) || defined(__BIG_ENDIAN__)
|
#if defined(_AIX) || defined(__BIG_ENDIAN__)
|
||||||
mnpack(0, m, 0, n);
|
mc = 128;
|
||||||
#else
|
nc = 128;
|
||||||
int64_t mc = 256; int64_t nc = 256; int64_t kc = 256;
|
kc = 128;
|
||||||
|
#endif
|
||||||
if (m % mc == 0 && n % nc == 0 && k % kc == 0) {
|
if (m % mc == 0 && n % nc == 0 && k % kc == 0) {
|
||||||
matmul_tiled(m, n, mc, nc, kc);
|
matmul_tiled(m, n, mc, nc, kc);
|
||||||
} else {
|
} else {
|
||||||
mnpack(0, m, 0, n);
|
mnpack(0, m, 0, n);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user