summaryrefslogtreecommitdiff
path: root/ggml/src/iqk/iqk_mul_mat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ggml/src/iqk/iqk_mul_mat.cpp')
-rw-r--r--ggml/src/iqk/iqk_mul_mat.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/ggml/src/iqk/iqk_mul_mat.cpp b/ggml/src/iqk/iqk_mul_mat.cpp
index e39c27d9..8d6b45da 100644
--- a/ggml/src/iqk/iqk_mul_mat.cpp
+++ b/ggml/src/iqk/iqk_mul_mat.cpp
@@ -340,6 +340,56 @@ bool iqk_mul_mat(long Nx, long Ny, long ne00,
return true;
}
+namespace {
+inline uint32_t simple_gcd(uint32_t a, uint32_t b) {
+ while (a != b) {
+ if (a > b) a -= b;
+ else b -= a;
+ }
+ return a;
+}
+}
+
+bool iqk_mul_mat_4d(long Nx, long Ny, long ne00,
+ long ne02, long ne03, long ne12, long ne13,
+ long nb02, long nb03, long nb12, long nb13, long nb2, long nb3,
+ int typeA, const void * A, long strideA,
+ int typeB, const void * B, long strideB,
+ float * C, long stride_C, int ith, int nth) {
+
+ auto r2 = ne12 / ne02;
+ auto r3 = ne13 / ne03;
+
+ if (ne13 == 1 && Ny == 1 && r2 > 1) {
+ int gcd = simple_gcd(ne02, nth);
+ int counter = 0;
+ for (int64_t i12 = 0; i12 < ne02; i12++) {
+ if ((counter++ % gcd) == (ith%gcd)) {
+ if (!iqk_mul_mat(Nx, r2, ne00,
+ typeA, (const char *)A + i12*nb02, strideA,
+ typeB, (const char *)B + i12*r2*nb12, nb12,
+ C + r2*i12*nb2, nb2,
+ ith/gcd, nth/gcd)) return false;
+ }
+ }
+ return true;
+ }
+ int gcd = simple_gcd(ne12*ne13, nth);
+ int counter = 0;
+ for (int64_t i13 = 0; i13 < ne13; i13++) {
+ for (int64_t i12 = 0; i12 < ne12; i12++) {
+ if ((counter++ % gcd) == (ith%gcd)) {
+ if (!iqk_mul_mat(Nx, Ny, ne00,
+ typeA, (const char *)A + i12/r2*nb02 + i13/r3*nb03, strideA,
+ typeB, (const char *)B + i12*nb12 + i13*nb13, strideB,
+ C + i12*nb2 + i13*nb3, stride_C,
+ ith/gcd, nth/gcd)) return false;
+ }
+ }
+ }
+ return true;
+}
+
bool iqk_mul_mat_moe(long Nx, long Ny, long ne00, int ne11,
int typeA, const void * A, long strideA,
int typeB, const void * B, long strideB,
@@ -16292,6 +16342,15 @@ bool iqk_mul_mat(int, long, long, long, int, const void *, long, int, const void
return false;
}
+bool iqk_mul_mat_4d(long /*Nx*/, long /*Ny*/, long /*ne00*/,
+ long /*ne02*/, long /*ne03*/, long /*ne12*/, long /*ne13*/,
+ long /*nb02*/, long /*nb03*/, long /*nb12*/, long /*nb13*/, long /*nb2*/, long /*nb3*/,
+ int /*typeA*/, const void * /*A*/, long /*strideA*/,
+ int /*typeB*/, const void * /*B*/, long /*strideB*/,
+ float * /*C*/, long /*stride_C*/, int /*ith*/, int /*nth*/) {
+ return false;
+}
+
bool iqk_mul_mat_moe(long, long, long, int, int, const void *, long, int, const void *, long, float *, long, long,
const void *, int, int) {
return false;