22
22
23
23
namespace matmul {
24
24
25
+ int64_t wei_ab_off_f (const prb_t *prb, int64_t mb, int64_t k, int64_t n) {
26
+ return (mb * prb->k + k) * prb->n + n;
27
+ }
28
+ int64_t wei_ba_off_f (const prb_t *prb, int64_t mb, int64_t k, int64_t n) {
29
+ return (mb * prb->n + n) * prb->k + k;
30
+ }
31
+
25
32
void compute_ref_matmul (const prb_t *prb, const args_t &args) {
26
33
const dnn_mem_t &src_m = args.find (DNNL_ARG_SRC);
27
34
const dnn_mem_t &wei_m = args.find (DNNL_ARG_WEIGHTS);
@@ -130,8 +137,9 @@ void compute_ref_matmul(const prb_t *prb, const args_t &args) {
130
137
for (int64_t gK = 0 ; gK < n_k_groups; gK ++) {
131
138
const auto src_gK_off
132
139
= src_off_f (prb, src_mb, m, gK * smallest_k_group);
140
+ // Note: scales/zero-points are still always in `tag::abx` format.
133
141
const auto wei_gK_off
134
- = wei_off_f (prb, wei_mb, gK * smallest_k_group, n);
142
+ = wei_ab_off_f (prb, wei_mb, gK * smallest_k_group, n);
135
143
136
144
if (has_src_zp && !has_src_single_zp) {
137
145
const auto src_zp_idx = src_m.get_idx (
@@ -158,8 +166,8 @@ void compute_ref_matmul(const prb_t *prb, const args_t &args) {
158
166
for (int64_t k = 0 ; k < smallest_k_group; ++k) {
159
167
const auto src_off
160
168
= src_off_f (prb, src_mb, m, gK * smallest_k_group + k);
161
- const auto wei_off
162
- = wei_off_f ( prb, wei_mb, gK * smallest_k_group + k, n);
169
+ const auto wei_off = wei_ba_off_f (
170
+ prb, wei_mb, gK * smallest_k_group + k, n);
163
171
164
172
auto s = src_scale * (src_m.get_elem (src_off) - src_zp);
165
173
auto w = wei_scale * (wei_m.get_elem (wei_off) - wei_zp);
@@ -292,7 +300,7 @@ void compute_ref_sparse_matmul(const prb_t *prb, const args_t &args) {
292
300
293
301
for (int64_t k = row_start; k < row_end; k++) {
294
302
const int64_t wei_idx
295
- = wei_off_f (prb, mb, src_indices[k], n);
303
+ = wei_ba_off_f (prb, mb, src_indices[k], n);
296
304
const float src_val = src_m.get_elem (k, 0 );
297
305
const float wei_val = wei_m.get_elem (wei_idx);
298
306
dst_val += src_val * wei_val;
0 commit comments