1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
| // Copyright (c) Microsoft Corporation. All rights reserved.
| // Licensed under the MIT License.
|
| #include "test_conv2d.h"
| #include "test_conv2d_fixture.h"
|
| TEST(Conv2d_HalfConv, PrepareRespectsBackendSelectorConfig) {
| const int64_t input_shape[] = {5, 5};
| const int64_t kernel_shape[] = {3, 3};
| const int64_t dilation_shape[] = {1, 1};
| const int64_t padding[] = {1, 1, 1, 1};
| const int64_t stride_shape[] = {1, 1};
| const int64_t output_shape[] = {5, 5};
|
| MLAS_ACTIVATION activation;
| activation.ActivationKind = MlasIdentityActivation;
|
| MLAS_CONV_PARAMETERS parameters{};
| size_t working_buffer_size = 0;
| if (!MlasHalfConvPrepare(¶meters,
| 2,
| 1,
| 1,
| 4,
| input_shape,
| kernel_shape,
| dilation_shape,
| padding,
| stride_shape,
| output_shape,
| 8,
| &activation,
| &working_buffer_size,
| 0.0f,
| false,
| nullptr,
| nullptr)) {
| GTEST_SKIP() << "HalfConv prepare path unavailable";
| }
|
| MLAS_BACKEND_KERNEL_SELECTOR_CONFIG selector_config;
| selector_config.use_kleidiai = false;
|
| MLAS_CONV_PARAMETERS disabled_parameters{};
| EXPECT_FALSE(MlasHalfConvPrepare(&disabled_parameters,
| 2,
| 1,
| 1,
| 4,
| input_shape,
| kernel_shape,
| dilation_shape,
| padding,
| stride_shape,
| output_shape,
| 8,
| &activation,
| &working_buffer_size,
| 0.0f,
| false,
| nullptr,
| &selector_config));
| }
|
| TEST(Conv2d_HalfConv, PrepareReportsWorkingBufferSizeInBytes) {
| const int64_t input_shape[] = {5, 5};
| const int64_t kernel_shape[] = {3, 3};
| const int64_t dilation_shape[] = {1, 1};
| const int64_t padding[] = {1, 1, 1, 1};
| const int64_t stride_shape[] = {1, 1};
| const int64_t output_shape[] = {5, 5};
|
| MLAS_ACTIVATION activation;
| activation.ActivationKind = MlasIdentityActivation;
|
| MLAS_CONV_PARAMETERS parameters{};
| size_t working_buffer_size = 0;
| if (!MlasHalfConvPrepare(¶meters,
| 2,
| 1,
| 1,
| 4,
| input_shape,
| kernel_shape,
| dilation_shape,
| padding,
| stride_shape,
| output_shape,
| 8,
| &activation,
| &working_buffer_size,
| 0.0f,
| false,
| nullptr,
| nullptr)) {
| GTEST_SKIP() << "HalfConv prepare path unavailable";
| }
|
| EXPECT_EQ(working_buffer_size, parameters.OutputSize * parameters.FilterCount * sizeof(uint16_t));
| }
|
| TEST(Conv2d_HalfConv, PrepareInitializesLayoutFlags) {
| const int64_t input_shape[] = {5, 5};
| const int64_t kernel_shape[] = {3, 3};
| const int64_t dilation_shape[] = {1, 1};
| const int64_t padding[] = {1, 1, 1, 1};
| const int64_t stride_shape[] = {1, 1};
| const int64_t output_shape[] = {5, 5};
|
| MLAS_ACTIVATION activation;
| activation.ActivationKind = MlasIdentityActivation;
|
| MLAS_CONV_PARAMETERS nchw_parameters{};
| nchw_parameters.ChannelsLast = true;
| nchw_parameters.InputOutputChannelsLast = true;
| size_t nchw_working_buffer_size = 0;
| if (!MlasHalfConvPrepare(&nchw_parameters,
| 2,
| 1,
| 1,
| 4,
| input_shape,
| kernel_shape,
| dilation_shape,
| padding,
| stride_shape,
| output_shape,
| 8,
| &activation,
| &nchw_working_buffer_size,
| 0.0f,
| false,
| nullptr,
| nullptr)) {
| GTEST_SKIP() << "HalfConv prepare path unavailable";
| }
|
| EXPECT_FALSE(nchw_parameters.ChannelsLast);
| EXPECT_FALSE(nchw_parameters.InputOutputChannelsLast);
|
| MLAS_CONV_PARAMETERS nhwc_parameters{};
| size_t nhwc_working_buffer_size = 0;
| ASSERT_TRUE(MlasHalfConvPrepare(&nhwc_parameters,
| 2,
| 1,
| 1,
| 4,
| input_shape,
| kernel_shape,
| dilation_shape,
| padding,
| stride_shape,
| output_shape,
| 8,
| &activation,
| &nhwc_working_buffer_size,
| 0.0f,
| true,
| nullptr,
| nullptr));
|
| EXPECT_TRUE(nhwc_parameters.ChannelsLast);
| EXPECT_TRUE(nhwc_parameters.InputOutputChannelsLast);
| EXPECT_EQ(nhwc_working_buffer_size, size_t{0});
| }
|
| static size_t Conv2dRegistLongExecute() {
| size_t count = MlasLongExecuteTests<MlasConv2DTest<false>>::RegisterLongExecute();
| if (GetMlasThreadPool() != nullptr) {
| count += MlasLongExecuteTests<MlasConv2DTest<true>>::RegisterLongExecute();
| }
| return count;
| }
|
| static size_t Conv2dRegistShortExecute() {
| size_t count = Conv2dShortExecuteTest<MlasConv2DTest<false>>::RegisterShortExecuteTests();
| count += MlasDirectShortExecuteTests<MlasConv2DTest<false>>::RegisterShortExecute();
| if (GetMlasThreadPool() != nullptr) {
| count += Conv2dShortExecuteTest<MlasConv2DTest<true>>::RegisterShortExecuteTests();
| count += MlasDirectShortExecuteTests<MlasConv2DTest<true>>::RegisterShortExecute();
| }
| return count;
| }
|
| static UNUSED_VARIABLE bool added_to_main = AddTestRegister([](bool is_short_execute) {
| return is_short_execute ? Conv2dRegistShortExecute() : Conv2dRegistLongExecute();
| });
|
|