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

Function TEST_F

tensorflow/core/kernels/mkl_qmatmul_op_test.cc:70–139  ·  view source on GitHub ↗

Two small matrices A of type uint8 and B of type int8 are multiplied and the result is added with int32 bias

Source from the content-addressed store, hash-verified

68// Two small matrices A of type uint8 and B of type int8 are multiplied
69// and the result is added with int32 bias
70TEST_F(QuantizedMatMulTest, Small_withBias) {
71 TF_ASSERT_OK(
72 NodeDefBuilder("quantized_mat_mul_op", "_MklQuantizedMatMulWithBias")
73 .Input(FakeInput(DT_QUINT8))
74 .Input(FakeInput(DT_QINT8))
75 .Input(FakeInput(DT_QINT32))
76 .Input(FakeInput(DT_FLOAT))
77 .Input(FakeInput(DT_FLOAT))
78 .Input(FakeInput(DT_FLOAT))
79 .Input(FakeInput(DT_FLOAT))
80 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
81 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
82 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
83 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
84 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
85 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
86 .Input(FakeInput(DT_UINT8)) // OneDNN second tensor
87 .Attr("Toutput", DataTypeToEnum<qint32>::v())
88 .Attr("T", DataTypeToEnum<qint32>::v())
89 .Attr("_kernel", "QuantizedMklOp")
90 .Finalize(node_def()));
91 TF_ASSERT_OK(InitOp());
92 // A matrix is:
93 // | 1 | 2 | 3 |
94 // | 4 | 5 | 6 |
95 AddInputFromArray<quint8>(TensorShape({2, 3}), {1, 2, 3, 4, 5, 6});
96 // B matrix is:
97 // | 7 | 8 | 9 | 10 |
98 // | 11 | 12 | 13 | 14 |
99 // | 15 | 16 | 17 | 18 |
100 AddInputFromArray<qint8>(TensorShape({3, 4}),
101 {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18});
102 AddInputFromArray<qint32>(TensorShape({4}), {1, 2, 3, 4});
103 AddInputFromArray<float>(TensorShape({1}), {0});
104 AddInputFromArray<float>(TensorShape({1}), {255.0f});
105 AddInputFromArray<float>(TensorShape({1}), {-127.0f});
106 AddInputFromArray<float>(TensorShape({1}), {127.0f});
107 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
108 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
109 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
110 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
111 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
112 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
113 AddInputFromArray<uint8>(kDummyShape, kDummyTensor);
114
115 TF_ASSERT_OK(RunOpKernel());
116 // Here are the results we expect, from hand calculations:
117 // (1 * 7) + (2 * 11) + (3 * 15) = 74
118 // (1 * 8) + (2 * 12) + (3 * 16) = 80
119 // (1 * 9) + (2 * 13) + (3 * 17) = 86
120 // (1 * 10) + (2 * 14) + (3 * 18) = 92
121 // (4 * 7) + (5 * 11) + (6 * 15) = 173
122 // (4 * 8) + (5 * 12) + (6 * 16) = 188
123 // (4 * 9) + (5 * 13) + (6 * 17) = 203
124 // (4 * 10) + (5 * 14) + (6 * 18) = 218
125 // Final result after Bias addition:
126 // 74 + 1 = 75 , 80 + 2 = 82 , 86 + 3 = 89 , 92 + 4 = 96,
127 // 173 + 1 = 174, 188 + 2 = 190, 203 + 3 = 206, 218 + 4 = 222

Callers

nothing calls this directly

Calls 9

NodeDefBuilderClass · 0.85
GetOutputFunction · 0.85
DefaultFunction · 0.85
FakeInputFunction · 0.50
TensorShapeClass · 0.50
FinalizeMethod · 0.45
AttrMethod · 0.45
InputMethod · 0.45
NowMicrosMethod · 0.45

Tested by

no test coverage detected