text
stringlengths
0
2.2M
auto src_m = test::make_memory(init_md(p.base.src, true), eng);
auto weights_m = test::make_memory(init_md(p.base.weights, true), eng);
auto dst_m = test::make_memory(init_md(p.base.dst, true), eng);
// Initialize memory to make sanitizers happy
auto set_to_zero = [](memory &m) {
if (m) {
auto p = map_memory<char>(m);
GTEST_EXPECT_NE(p, nullptr);
memset(p, 0, m.get_desc().get_size());
}
};
set_to_zero(src_m);
set_to_zero(weights_m);
set_to_zero(dst_m);
set_to_zero(bia_m);
matmul_p.execute(strm,
{
{DNNL_ARG_SRC, src_m},
{DNNL_ARG_WEIGHTS, weights_m},
{DNNL_ARG_BIAS, bia_m},
{DNNL_ARG_DST, dst_m},
{DNNL_ARG_ATTR_OUTPUT_SCALES, scales_m},
{DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_SRC,
zero_points_src_m},
{DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS,
zero_points_weights_m},
{DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_DST,
zero_points_dst_m},
});
strm.wait();
}
};
struct attr_test_t
: public ::testing::TestWithParam<std::tuple<memory::dims, memory::dims,
memory::format_tag, memory::data_type, int>> {};
HANDLE_EXCEPTIONS_FOR_TEST_P(
attr_test_t, TestMatmulShouldCallSameImplementationWithAttributes) {
auto engine_kind = get_test_engine_kind();
SKIP_IF(!DNNL_X64 || engine_kind != engine::kind::cpu,
"Binary impl_info_str should be same only on x64 CPU");
engine e {engine_kind, 0};
const auto &tensor_dims = std::get<0>(GetParam());
const auto format_tag = std::get<2>(GetParam());
auto src_md = memory::desc(tensor_dims, memory::data_type::u8, format_tag);
auto weights_md
= memory::desc(tensor_dims, memory::data_type::s8, format_tag);
auto dst_md = memory::desc(tensor_dims, memory::data_type::s8, format_tag);
auto bia_md = memory::desc();
auto matmul_d = matmul::desc(src_md, weights_md, bia_md, dst_md);
std::string impl_info_no_postops;
auto matmul_pd = matmul::primitive_desc(matmul_d, e);
ASSERT_NO_THROW(impl_info_no_postops = matmul_pd.impl_info_str(););
dnnl::primitive_attr attr;
const float scale = 1.f;
const float alpha = 1.f;
const float beta = 1.f;
const float oscale = 1.5f;
const int ndims = std::get<4>(GetParam());
// per-channel output scales
std::vector<float> oscales(tensor_dims[1], oscale);
attr.set_output_scales(1 << (ndims - 1), oscales);
dnnl::post_ops ops;
ops.append_sum(1.0);
ops.append_eltwise(scale, algorithm::eltwise_relu, alpha, beta);
const auto &binary_po_tensor_dims = std::get<1>(GetParam());
const auto &binary_po_mem_dt = std::get<3>(GetParam());
SKIP_IF(unsupported_data_type(binary_po_mem_dt),
"Engine does not support this data type.");
memory::desc src1_po_md(
binary_po_tensor_dims, binary_po_mem_dt, format_tag);
ops.append_binary(algorithm::binary_add, src1_po_md);
attr.set_post_ops(ops);
std::string impl_info_with_postops;
matmul_pd = matmul::primitive_desc(matmul_d, attr, e);
ASSERT_NO_THROW(impl_info_with_postops = matmul_pd.impl_info_str(););
ASSERT_EQ(impl_info_no_postops, impl_info_with_postops);
}
/********************************* TEST CASES *********************************/
using iface = matmul_iface_test_t;
using data_type = memory::data_type;
TEST_P(iface, TestsMatMul) {}