@@ -152,6 +152,22 @@ TEST_F(QnnCPUBackendTests, Pad2d) {
152152 ExpectedEPNodeAssignment::All);
153153}
154154
155+ TEST_F (QnnCPUBackendTests, Pad2dNeg) {
156+ RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
157+ TestInputDef<int64_t >({4 }, true , {0 , -1 , -1 , 0 }),
158+ TestInputDef<float >({1 }, true , {0 .0f }),
159+ {utils::MakeAttribute (" mode" , " constant" )},
160+ ExpectedEPNodeAssignment::All);
161+ }
162+
163+ TEST_F (QnnCPUBackendTests, Pad2dMix) {
164+ RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
165+ TestInputDef<int64_t >({4 }, true , {1 , -1 , -1 , 1 }),
166+ TestInputDef<float >({1 }, true , {0 .0f }),
167+ {utils::MakeAttribute (" mode" , " constant" )},
168+ ExpectedEPNodeAssignment::All);
169+ }
170+
155171// Pad 2d, pads input not initializer
156172TEST_F (QnnCPUBackendTests, Pad2dPadsNotIni) {
157173 RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
@@ -175,6 +191,15 @@ TEST_F(QnnCPUBackendTests, PadModeReflect) {
175191 has_constant_value);
176192}
177193
194+ TEST_F (QnnCPUBackendTests, PadModeReflectNeg) {
195+ bool has_constant_value = false ;
196+ RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
197+ TestInputDef<int64_t >({4 }, true , {0 , 1 , -1 , 0 }),
198+ TestInputDef<float >({1 }, true , {0 .0f }),
199+ {utils::MakeAttribute (" mode" , " reflect" )}, // reflect mode doesn't support negative padding value.
200+ ExpectedEPNodeAssignment::None,
201+ has_constant_value);
202+ }
178203// Pad edge mode
179204TEST_F (QnnCPUBackendTests, PadModeEdge) {
180205 bool has_constant_value = false ;
@@ -210,6 +235,30 @@ TEST_F(QnnCPUBackendTests, Pad4d) {
210235 ExpectedEPNodeAssignment::All);
211236}
212237
238+ TEST_F (QnnCPUBackendTests, Pad4dNeg) {
239+ RunPadOpTest (TestInputDef<float >({1 , 2 , 2 , 2 }, false ,
240+ {1 .0f , 1 .0f ,
241+ 1 .0f , 1 .0f ,
242+ 1 .0f , 1 .0f ,
243+ 1 .0f , 1 .0f }),
244+ TestInputDef<int64_t >({8 }, true , {0 , 0 , 0 , -1 , 0 , 0 , -1 , 0 }),
245+ TestInputDef<float >({1 }, true , {0 .0f }),
246+ {utils::MakeAttribute (" mode" , " constant" )},
247+ ExpectedEPNodeAssignment::All);
248+ }
249+
250+ TEST_F (QnnCPUBackendTests, Pad4dMix) {
251+ RunPadOpTest (TestInputDef<float >({1 , 2 , 2 , 2 }, false ,
252+ {1 .0f , 1 .0f ,
253+ 1 .0f , 1 .0f ,
254+ 1 .0f , 1 .0f ,
255+ 1 .0f , 1 .0f }),
256+ TestInputDef<int64_t >({8 }, true , {1 , 0 , 0 , -1 , 0 , 0 , -1 , 1 }),
257+ TestInputDef<float >({1 }, true , {0 .0f }),
258+ {utils::MakeAttribute (" mode" , " constant" )},
259+ ExpectedEPNodeAssignment::All);
260+ }
261+
213262// Pad 5d supported
214263TEST_F (QnnCPUBackendTests, Pad5d) {
215264 RunPadOpTest (TestInputDef<float >({1 , 2 , 2 , 2 , 2 }, false , GetFloatDataInRange (1 .0f , 10 .0f , 16 )),
@@ -285,6 +334,38 @@ TEST_F(QnnHTPBackendTests, DISABLED_PadReflectMode_FP16_big_data) {
285334 2e-3f );
286335}
287336
337+ TEST_F (QnnHTPBackendTests, PadNoConstantNegValue_fp16_test) {
338+ bool has_constant_value_input = false ;
339+ bool use_htp = true ;
340+ bool enable_fp16_precision = true ;
341+ RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
342+ TestInputDef<int64_t >({4 }, true , {0 , -1 , -1 , 0 }),
343+ TestInputDef<float >({1 }, true , {0 .0f }),
344+ {utils::MakeAttribute (" mode" , " constant" )},
345+ ExpectedEPNodeAssignment::All,
346+ has_constant_value_input,
347+ 18 , // opset
348+ use_htp,
349+ enable_fp16_precision,
350+ 2e-3f );
351+ }
352+
353+ TEST_F (QnnHTPBackendTests, PadNoConstantMixValue_fp16_test) {
354+ bool has_constant_value_input = false ;
355+ bool use_htp = true ;
356+ bool enable_fp16_precision = true ;
357+ RunPadOpTest (TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
358+ TestInputDef<int64_t >({4 }, true , {1 , -1 , -1 , 1 }),
359+ TestInputDef<float >({1 }, true , {0 .0f }),
360+ {utils::MakeAttribute (" mode" , " constant" )},
361+ ExpectedEPNodeAssignment::All,
362+ has_constant_value_input,
363+ 18 , // opset
364+ use_htp,
365+ enable_fp16_precision,
366+ 2e-3f );
367+ }
368+
288369//
289370// QDQ Pad
290371TEST_F (QnnHTPBackendTests, PadNoConstantValue) {
@@ -297,6 +378,26 @@ TEST_F(QnnHTPBackendTests, PadNoConstantValue) {
297378 has_constant_value_input);
298379}
299380
381+ TEST_F (QnnHTPBackendTests, PadNoConstantNegValue) {
382+ bool has_constant_value_input = false ;
383+ RunQDQPadOpTest<uint8_t >(TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
384+ TestInputDef<int64_t >({4 }, true , {0 , -1 , -1 , 0 }),
385+ TestInputDef<float >({1 }, true , {0 .0f }),
386+ {utils::MakeAttribute (" mode" , " constant" )},
387+ ExpectedEPNodeAssignment::All,
388+ has_constant_value_input);
389+ }
390+
391+ TEST_F (QnnHTPBackendTests, PadNoConstantMixValue) {
392+ bool has_constant_value_input = false ;
393+ RunQDQPadOpTest<uint8_t >(TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
394+ TestInputDef<int64_t >({4 }, true , {1 , -1 , -1 , 1 }),
395+ TestInputDef<float >({1 }, true , {0 .0f }),
396+ {utils::MakeAttribute (" mode" , " constant" )},
397+ ExpectedEPNodeAssignment::All,
398+ has_constant_value_input);
399+ }
400+
300401TEST_F (QnnHTPBackendTests, PadHasConstantValueNonQuantized) {
301402 bool has_constant_value_input = true ;
302403 bool constant_value_quantized = false ;
@@ -331,6 +432,16 @@ TEST_F(QnnHTPBackendTests, PadReflectMode) {
331432 has_constant_value_input);
332433}
333434
435+ TEST_F (QnnHTPBackendTests, PadReflectModeNeg) {
436+ bool has_constant_value_input = false ;
437+ RunQDQPadOpTest<uint8_t >(TestInputDef<float >({3 , 2 }, false , {1 .0f , 1 .2f , 2 .3f , 3 .4f , 4 .5f , 5 .6f }),
438+ TestInputDef<int64_t >({4 }, true , {0 , -1 , -1 , 0 }),
439+ TestInputDef<float >({1 }, true , {0 .0f }),
440+ {utils::MakeAttribute (" mode" , " reflect" )},
441+ ExpectedEPNodeAssignment::None, // reflect mode doesn't support negative padding value.
442+ has_constant_value_input);
443+ }
444+
334445// Pad amount should not be greater than shape(input[0])[i] - 1
335446TEST_F (QnnHTPBackendTests, PadReflectModeOutOfRangePadAmount) {
336447 bool has_constant_value_input = false ;
@@ -389,6 +500,30 @@ TEST_F(QnnHTPBackendTests, Pad4d) {
389500 ExpectedEPNodeAssignment::All);
390501}
391502
503+ TEST_F (QnnHTPBackendTests, Pad4dNeg) {
504+ RunQDQPadOpTest<uint8_t >(TestInputDef<float >({1 , 2 , 2 , 2 }, false ,
505+ {1 .0f , 2 .0f ,
506+ 3 .0f , 4 .0f ,
507+ 5 .0f , 6 .0f ,
508+ 7 .0f , 8 .0f }),
509+ TestInputDef<int64_t >({8 }, true , {0 , 0 , 0 , -1 , 0 , 0 , -1 , 0 }),
510+ TestInputDef<float >({1 }, true , {5 .0f }),
511+ {utils::MakeAttribute (" mode" , " constant" )},
512+ ExpectedEPNodeAssignment::All);
513+ }
514+
515+ TEST_F (QnnHTPBackendTests, Pad4dMix) {
516+ RunQDQPadOpTest<uint8_t >(TestInputDef<float >({1 , 2 , 2 , 2 }, false ,
517+ {1 .0f , 2 .0f ,
518+ 3 .0f , 4 .0f ,
519+ 5 .0f , 6 .0f ,
520+ 7 .0f , 8 .0f }),
521+ TestInputDef<int64_t >({8 }, true , {0 , 1 , 0 , -1 , 0 , 1 , 0 , 1 }),
522+ TestInputDef<float >({1 }, true , {5 .0f }),
523+ {utils::MakeAttribute (" mode" , " constant" )},
524+ ExpectedEPNodeAssignment::All);
525+ }
526+
392527// Inaccuracy detected for output 'output', element 0.
393528// Output quant params: scale=0.035294119268655777, zero_point=0.
394529// Expected val: 9
0 commit comments