gemm function
yst = wrows, cols * xst for t < n, with xs packed as n, cols and
ys as n, rows. Falls back to gemv per vector for the last n % 4
vectors and when rows is odd.
Implementation
void gemm(
Float32List w,
Float32List xs,
Float32List ys,
int rows,
int cols,
int n,
) {
if (cols % 4 != 0 ||
w.length < rows * cols ||
xs.length < n * cols ||
ys.length < n * rows ||
w.offsetInBytes % 16 != 0 ||
xs.offsetInBytes % 16 != 0) {
throw ArgumentError(
'gemm: bad shapes rows=$rows cols=$cols n=$n w=${w.length} '
'xs=${xs.length} ys=${ys.length}',
);
}
final blocked = rows.isEven ? n - n % 4 : 0;
if (blocked > 0) {
_gemmUnchecked(
Float32x4List.sublistView(w, 0, rows * cols),
Float32x4List.sublistView(xs, 0, blocked * cols),
ys,
rows,
cols ~/ 4,
blocked,
);
}
for (var t = blocked; t < n; t++) {
gemv(
w,
Float32List.sublistView(xs, t * cols, (t + 1) * cols),
Float32List.sublistView(ys, t * rows, (t + 1) * rows),
rows,
cols,
);
}
}