Skip to content

Commit 3643f2d

Browse files
committed
benchdnn: matmul: adjust filling to incorporate zero-points
1 parent 571abc1 commit 3643f2d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/benchdnn/matmul/matmul.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,20 @@ int fill_data(data_kind_t kind, const prb_t *prb, const cfg_t &cfg,
413413
density_args.n_acc = prb->k;
414414
const auto density = cfg.get_density(density_args);
415415

416+
const auto &e_zp_src = prb->attr.zero_points.get(DNNL_ARG_SRC);
417+
const bool has_src_zp = !e_zp_src.is_def();
418+
const int src_zp_mask = attr_t::get_default_mask(e_zp_src.policy);
419+
// Apply src_zp for source tensor only.
420+
int src_zp = kind == SRC && has_src_zp && src_zp_mask == 0 ? e_zp_src.value
421+
: 0;
422+
423+
const auto &e_zp_wei = prb->attr.zero_points.get(DNNL_ARG_WEIGHTS);
424+
const bool has_wei_zp = !e_zp_wei.is_def();
425+
const int wei_zp_mask = attr_t::get_default_mask(e_zp_wei.policy);
426+
// Apply wei_zp for weights tensor only.
427+
int wei_zp = kind == WEI && has_wei_zp && wei_zp_mask == 0 ? e_zp_wei.value
428+
: 0;
429+
416430
/* Do fixed partitioning to have same filling for any number of threads */
417431
const int64_t chunk_size = 64;
418432
const int64_t n_chunks = div_up(nelems, chunk_size);
@@ -438,6 +452,7 @@ int fill_data(data_kind_t kind, const prb_t *prb, const cfg_t &cfg,
438452
float val = 0;
439453
while (val <= 0)
440454
val = gen(int_seed);
455+
val += src_zp + wei_zp; // Add zp so that it will be subtracted.
441456
mem_fp.set_elem(
442457
0, round_to_nearest_representable(cfg.get_dt(kind), val));
443458
idx_start += 1;
@@ -453,6 +468,7 @@ int fill_data(data_kind_t kind, const prb_t *prb, const cfg_t &cfg,
453468
val *= is_one;
454469
} else {
455470
val = is_one * gen(int_seed);
471+
val += src_zp + wei_zp; // Add zp so that it will be subtracted.
456472
}
457473
mem_fp.set_elem(
458474
idx, round_to_nearest_representable(cfg.get_dt(kind), val));

0 commit comments

Comments
 (0)