Skip to content

Commit 6858af7

Browse files
committed
Initialize HalfConv layout flags
Set MLAS_CONV_PARAMETERS::ChannelsLast in the HalfConv prepare path so Prepare fully initializes the convolution parameter layout state. Add a focused MLAS test that verifies Prepare overwrites stale layout flag values for both NCHW and NHWC HalfConv configurations. Signed-off-by: Cathal Lawlor <cathal.lawlor@arm.com>
1 parent e60a7a6 commit 6858af7

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

onnxruntime/core/mlas/lib/kleidiai/halfconv_kleidiai.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ bool
915915
Parameters->InputChannels = InputChannels;
916916
Parameters->FilterCount = FilterCount;
917917
Parameters->Beta = Beta;
918+
Parameters->ChannelsLast = InputOutputChannelsLast;
918919
Parameters->InputOutputChannelsLast = InputOutputChannelsLast;
919920

920921
size_t input_size = 1;

onnxruntime/test/mlas/unittest/test_conv2d.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,71 @@ TEST(Conv2d_HalfConv, PrepareReportsWorkingBufferSizeInBytes) {
9999
EXPECT_EQ(working_buffer_size, parameters.OutputSize * parameters.FilterCount * sizeof(uint16_t));
100100
}
101101

102+
TEST(Conv2d_HalfConv, PrepareInitializesLayoutFlags) {
103+
const int64_t input_shape[] = {5, 5};
104+
const int64_t kernel_shape[] = {3, 3};
105+
const int64_t dilation_shape[] = {1, 1};
106+
const int64_t padding[] = {1, 1, 1, 1};
107+
const int64_t stride_shape[] = {1, 1};
108+
const int64_t output_shape[] = {5, 5};
109+
110+
MLAS_ACTIVATION activation;
111+
activation.ActivationKind = MlasIdentityActivation;
112+
113+
MLAS_CONV_PARAMETERS nchw_parameters{};
114+
nchw_parameters.ChannelsLast = true;
115+
nchw_parameters.InputOutputChannelsLast = true;
116+
size_t nchw_working_buffer_size = 0;
117+
if (!MlasHalfConvPrepare(&nchw_parameters,
118+
2,
119+
1,
120+
1,
121+
4,
122+
input_shape,
123+
kernel_shape,
124+
dilation_shape,
125+
padding,
126+
stride_shape,
127+
output_shape,
128+
8,
129+
&activation,
130+
&nchw_working_buffer_size,
131+
0.0f,
132+
false,
133+
nullptr,
134+
nullptr)) {
135+
GTEST_SKIP() << "HalfConv prepare path unavailable";
136+
}
137+
138+
EXPECT_FALSE(nchw_parameters.ChannelsLast);
139+
EXPECT_FALSE(nchw_parameters.InputOutputChannelsLast);
140+
141+
MLAS_CONV_PARAMETERS nhwc_parameters{};
142+
size_t nhwc_working_buffer_size = 0;
143+
ASSERT_TRUE(MlasHalfConvPrepare(&nhwc_parameters,
144+
2,
145+
1,
146+
1,
147+
4,
148+
input_shape,
149+
kernel_shape,
150+
dilation_shape,
151+
padding,
152+
stride_shape,
153+
output_shape,
154+
8,
155+
&activation,
156+
&nhwc_working_buffer_size,
157+
0.0f,
158+
true,
159+
nullptr,
160+
nullptr));
161+
162+
EXPECT_TRUE(nhwc_parameters.ChannelsLast);
163+
EXPECT_TRUE(nhwc_parameters.InputOutputChannelsLast);
164+
EXPECT_EQ(nhwc_working_buffer_size, size_t{0});
165+
}
166+
102167
static size_t Conv2dRegistLongExecute() {
103168
size_t count = MlasLongExecuteTests<MlasConv2DTest<false>>::RegisterLongExecute();
104169
if (GetMlasThreadPool() != nullptr) {

0 commit comments

Comments
 (0)