text
stringlengths
0
2.2M
case DNNL_ARG_DST:
ASSERT_TRUE((flags & P::MATRIX_MASK) == P::DST);
break;
default: ASSERT_TRUE(!"unreachable");
}
unsigned zero_points_mask = flags & P::MASK_MASK;
ASSERT_TRUE(zero_points_mask == P::COMMON
|| zero_points_mask == P::PER_N);
int mask = zero_points_mask == P::PER_N ? 1 << (ndims - 1) : 0;
memory::dim zero_points_size = mask ? md.dims[ndims - 1] : 1;
if (flags & P::RUNTIME) {
attr.set_zero_points(arg, mask, {DNNL_RUNTIME_S32_VAL});
zero_points_m = test::make_memory(
{{zero_points_size}, memory::data_type::s32, {1}}, eng);
auto z = map_memory<int32_t>(zero_points_m);
GTEST_EXPECT_NE(z, nullptr);
for (memory::dim i = 0; i < zero_points_size; ++i)
z[i] = (arg % 7) - 3;
} else {
std::vector<int32_t> zero_points(
zero_points_size, (arg % 7) - 3);
attr.set_zero_points(arg, mask, zero_points);
}
};
handle_zero_points(DNNL_ARG_SRC, p.attr.zero_points.src, p.base.src,
zero_points_src_m);
handle_zero_points(DNNL_ARG_WEIGHTS, p.attr.zero_points.weights,
p.base.weights, zero_points_weights_m);
handle_zero_points(DNNL_ARG_DST, p.attr.zero_points.dst, p.base.dst,
zero_points_dst_m);
// post ops
post_ops po;
for (auto post_op : p.attr.post_ops) {
switch (post_op.kind) {
case primitive::kind::sum: po.append_sum(); break;
case primitive::kind::eltwise:
po.append_eltwise(1.f, post_op.alg, 0.f, 0.f);
break;
default: ASSERT_TRUE(!"unknown post op kind");
}
}
attr.set_post_ops(po);
}
void Test() {
matmul_test_params_t p
= ::testing::TestWithParam<matmul_test_params_t>::GetParam();
auto eng = get_test_engine();
auto strm = make_stream(eng);
auto check_matrix_flags = [](unsigned flags, unsigned matrix) {
if (flags) { ASSERT_EQ(flags & P::MATRIX_MASK, matrix); }
};
check_matrix_flags(p.base.src.flags, P::SRC);
check_matrix_flags(p.base.weights.flags, P::WEIGHTS);
check_matrix_flags(p.base.dst.flags, P::DST);
auto src_md = init_md(p.base.src);
auto weights_md = init_md(p.base.weights);
auto dst_md = init_md(p.base.dst);
auto bia_md = memory::desc();
memory bia_m;
if (p.base.bia_dt != memory::data_type::undef) {
memory::dims bia_dims(p.base.dst.dims.size() - 1, 1);
bia_dims.push_back(p.base.dst.dims.back());
tag bia_tag = bia_dims.size() == 2 ? tag::ab : tag::abc;
bia_md = init_md({bia_dims, p.base.bia_dt, bia_tag,
p.base.dst.flags & P::RUNTIME});
bia_m = test::make_memory(
init_md({bia_dims, p.base.bia_dt, bia_tag}), eng);
}
auto matmul_d = matmul::desc(src_md, weights_md, bia_md, dst_md);
primitive_attr attr;
memory scales_m, zero_points_src_m, zero_points_weights_m,
zero_points_dst_m;
create_attr(p, attr, scales_m, zero_points_src_m, zero_points_weights_m,
zero_points_dst_m, eng);
auto matmul_pd = matmul::primitive_desc(matmul_d, attr, eng);
ASSERT_TRUE(matmul_pd.query_md(query::exec_arg_md, DNNL_ARG_SRC)
== matmul_pd.src_desc());
ASSERT_TRUE(matmul_pd.query_md(query::exec_arg_md, DNNL_ARG_WEIGHTS)
== matmul_pd.weights_desc());
ASSERT_TRUE(matmul_pd.query_md(query::exec_arg_md, DNNL_ARG_BIAS)
== matmul_pd.bias_desc());
ASSERT_TRUE(matmul_pd.query_md(query::exec_arg_md, DNNL_ARG_DST)
== matmul_pd.dst_desc());
EXPECT_ANY_THROW(matmul(matmul_pd, {}));
auto matmul_p = matmul(matmul_pd);