MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/kernels/eigen_dnnl_contraction_kernel_test.cc:43–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41using Index = Eigen::Index;
42
43TEST(EigenMkldnnTest, GemmPackColMajor) {
44 // Packing with gemm_pack_colmajor_block is the same as taking a slice of 2
45 // dimensional Tensor.
46
47 // OneDNN pack and gemm are used only in Tensor contractions, and it's
48 // guaranteed that Tensors will have ColMajor layout.
49 static const int Options = ColMajor;
50
51 using DataMapper = blas_data_mapper<Scalar, Index, ColMajor>;
52 using GemmPackColMajor =
53 gemm_pack_colmajor_block<Scalar, Index, DataMapper, ColMajor>;
54 using Tensor2d = Tensor<Scalar, 2, Options, Index>;
55
56 Eigen::array<Index, 2> dims = RandomDims<Index, 2>(1, 500);
57
58 // Create a tensor initialized with random data.
59 Tensor2d src(dims);
60 src.setRandom();
61
62 // Pick a random slice of src tensor.
63 Eigen::array<Index, 2> slice_start = RandomDims<Index, 2>(0, 250);
64 Eigen::array<Index, 2> slice_size = RandomDims<Index, 2>(100, 500);
65
66 // Make sure that slice start + size do not overflow tensor dims.
67 for (int i = 0; i < 2; ++i) {
68 slice_start[i] = numext::mini(dims[i] - 1, slice_start[i]);
69 slice_size[i] = numext::mini(slice_size[i], dims[i] - slice_start[i]);
70 }
71
72 // Prepare tensors for packing and slicing results.
73 Tensor2d pack_dst(slice_size[0], slice_size[1]);
74 Tensor2d slice_dst(slice_size[0], slice_size[1]);
75
76 // Pack memory using gemm_pack_colmajor_block.
77 DataMapper data_mapper(src.data(), dims[0]);
78 GemmPackColMajor gemm_pack;
79 gemm_pack(pack_dst.data(),
80 data_mapper.getSubMapper(slice_start[0], slice_start[1]),
81 slice_size[0], slice_size[1]);
82
83 // Slice the source tensor.
84 slice_dst = src.slice(slice_start, slice_size);
85
86 // Verify that dst tensors are equal.
87 EXPECT_EQ(pack_dst.dimensions().TotalSize(),
88 slice_dst.dimensions().TotalSize());
89 for (size_t i = 0; i < pack_dst.dimensions().TotalSize(); ++i) {
90 Scalar packed = pack_dst.coeff(i);
91 Scalar sliced = slice_dst.coeff(i);
92 EXPECT_EQ(packed, sliced);
93 }
94}
95
96TEST(EigenMkldnnTest, MkldnnGemm) {
97 // OneDNN pack and gemm are used only in Tensor contractions, and it's

Callers

nothing calls this directly

Calls 8

ScalarFunction · 0.85
epsilonFunction · 0.85
sliceMethod · 0.80
coeffMethod · 0.80
absClass · 0.70
dataMethod · 0.45
getSubMapperMethod · 0.45
dimensionsMethod · 0.45

Tested by

no test coverage detected