1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Grouped matrix multiplication with device-side group boundaries.
use GemmActivation;
use crateResult;
use crateRuntime;
use crateTensor;
/// One independent matmul per group, with the row boundaries held on device.
///
/// Rows of `a` are partitioned into consecutive groups and each group is
/// multiplied by its own matrix:
///
/// ```text
/// c[offsets[g] .. offsets[g+1]] = a[offsets[g] .. offsets[g+1]] @ b[g]
/// ```
///
/// # Layout
///
/// - `a`: `[total_rows, k]`
/// - `b`: `[num_groups, k, n]`
/// - `group_offsets`: `[num_groups + 1]`, I32, monotonically non-decreasing,
/// first entry `0` and last entry `total_rows`
/// - output: `[total_rows, n]`
///
/// # Why the offsets are a tensor
///
/// They live wherever the tensors live. A caller that already knew the group
/// sizes on the host could launch one matmul per group instead; this operation
/// exists for the case where the partition was produced on the device and
/// reading it back would stall the queue.