// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #if !defined(ORT_MINIMAL_BUILD) #include #include #include "core/graph/node_attr_utils.h" #include "test/providers/qnn/qnn_test_utils.h" #include "test/unittest_util/qdq_test_utils.h" #include "core/graph/onnx_protobuf.h" #include "gtest/gtest.h" namespace onnxruntime { namespace test { // Returns a function that creates a graph with a single Pad operator. static GetTestModelFn BuildPadTestCase(const TestInputDef& data_def, const TestInputDef& pads_def, const TestInputDef& constant_value_def, const std::vector& attrs, bool has_constant_value = true, int opset = 18) { return [data_def, pads_def, constant_value_def, attrs, has_constant_value, opset](ModelTestBuilder& builder) { NodeArg* data = MakeTestInput(builder, data_def); std::vector inputs{data}; std::vector pad_attrs{attrs}; if (2 <= opset && opset < 11) { // For opsets < 11, "pads" and "value" are attrs. const auto& pads_data = pads_def.IsRawData() ? pads_def.GetRawData() : builder.rand_gen_.Uniform(pads_def.GetShape(), pads_def.GetRandomDataInfo().min, pads_def.GetRandomDataInfo().max); pad_attrs.push_back(utils::MakeAttribute("pads", pads_data)); if (has_constant_value) { const auto value = constant_value_def.IsRawData() ? constant_value_def.GetRawData()[0] : builder.rand_gen_.Uniform(constant_value_def.GetShape(), constant_value_def.GetRandomDataInfo().min, constant_value_def.GetRandomDataInfo().max)[0]; pad_attrs.push_back(utils::MakeAttribute("value", value)); } } else { // For opsets >= 11, "pads" and "constant_value" are inputs rather than attrs. NodeArg* pads = MakeTestInput(builder, pads_def); inputs.push_back(pads); if (has_constant_value) { NodeArg* constant_value = MakeTestInput(builder, constant_value_def); inputs.push_back(constant_value); } } NodeArg* output = builder.MakeOutput(); Node& pad_node = builder.AddNode("Pad", inputs, {output}); for (const auto& attr : pad_attrs) { pad_node.AddAttributeProto(attr); } }; } // Returns a function that creates a graph with a QDQ Pad operator. template GetTestQDQModelFn BuildPadQDQTestCase(const TestInputDef& data_def, const TestInputDef& pads_def, const TestInputDef& constant_value_def, const std::vector& attrs, bool has_constant_value, bool constant_value_quantized) { return [data_def, pads_def, constant_value_def, attrs, has_constant_value, constant_value_quantized](ModelTestBuilder& builder, std::vector>& output_qparams) { std::vector inputs; // data -> Q -> DQ -> NodeArg* data = MakeTestInput(builder, data_def); QuantParams data_qparams = GetTestInputQuantParams(data_def); NodeArg* data_qdq = AddQDQNodePair(builder, data, data_qparams.scale, data_qparams.zero_point); inputs.push_back(data_qdq); // pads NodeArg* pads = MakeTestInput(builder, pads_def); inputs.push_back(pads); // constant_value -- QNN support both quantized and non-quantized if (has_constant_value) { if (constant_value_quantized) { // constant_value -> Q -> DQ -> NodeArg* constant_value = MakeTestInput(builder, constant_value_def); QuantParams constant_value_qparams = GetTestInputQuantParams(constant_value_def); NodeArg* constant_value_qdq = AddQDQNodePair(builder, constant_value, constant_value_qparams.scale, constant_value_qparams.zero_point); inputs.push_back(constant_value_qdq); } else { NodeArg* constant_value = MakeTestInput(builder, constant_value_def); inputs.push_back(constant_value); } } NodeArg* output = builder.MakeIntermediate(); Node& pad_node = builder.AddNode("Pad", inputs, {output}); for (const auto& attr : attrs) { pad_node.AddAttributeProto(attr); } // op_output -> Q -> DQ -> output AddQDQNodePairWithOutputAsGraphOutput(builder, output, output_qparams[0].scale, output_qparams[0].zero_point); }; } // Runs an Pad model on the QNN CPU backend. Checks the graph node assignment, and that inference // outputs for QNN and CPU match. static void RunPadOpTest(const TestInputDef& data_def, const TestInputDef& pads_def, const TestInputDef& constant_value_def, const std::vector& attrs, ExpectedEPNodeAssignment expected_ep_assignment, const std::string& backend_name = "cpu", bool has_constant_value = true, int opset = 18, bool enable_fp16_precision = false, float f32_abs_err = 1e-5f) { ProviderOptions provider_options; provider_options["backend_type"] = backend_name; provider_options["offload_graph_io_quantization"] = "0"; if (enable_fp16_precision) { provider_options["enable_htp_fp16_precision"] = "1"; } RunQnnModelTest(BuildPadTestCase(data_def, pads_def, constant_value_def, attrs, has_constant_value, opset), provider_options, opset, expected_ep_assignment, f32_abs_err); } // Runs a QDQ Pad model on the QNN HTP backend. Checks the graph node assignment, and that inference // outputs for QNN and CPU match. template static void RunQDQPadOpTest(const TestInputDef& data_def, const TestInputDef& pads_def, const TestInputDef& constant_value_def, const std::vector& attrs, ExpectedEPNodeAssignment expected_ep_assignment, bool has_constant_value = true, bool constant_value_quantized = true, int opset = 18) { ProviderOptions provider_options; provider_options["backend_type"] = "htp"; provider_options["offload_graph_io_quantization"] = "0"; TestQDQModelAccuracy(BuildPadTestCase(data_def, pads_def, constant_value_def, attrs), BuildPadQDQTestCase(data_def, pads_def, constant_value_def, attrs, has_constant_value, constant_value_quantized), provider_options, opset, expected_ep_assignment); } // // CPU tests: // // Pad 2d TEST_F(QnnCPUBackendTests, Pad2d) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnCPUBackendTests, Pad2dOpset7) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "cpu", true, // has_constant_value 7); // opset } TEST_F(QnnCPUBackendTests, Pad2dNeg) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, -1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnCPUBackendTests, Pad2dMix) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {1, -1, -1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } // Pad 2d, pads input not initializer TEST_F(QnnCPUBackendTests, Pad2dPadsNotIni) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, false, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::None); } // Pad reflect mode // Expected: contains 12 values, where each value and its corresponding value in 16-byte object <0C-00 00-00 00-00 00-00 40-01 23-05 EC-01 00-00> are an almost-equal pair // Actual: 16-byte object <0C-00 00-00 00-00 00-00 40-01 12-05 EC-01 00-00>, where the value pair (1.2, 0) at index #1 don't match, which is -1.2 from 1.2 // fixed by QNN 2.32 TEST_F(QnnCPUBackendTests, PadModeReflect) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, "cpu", has_constant_value); } TEST_F(QnnCPUBackendTests, PadModeReflectNeg) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, // reflect mode doesn't support negative padding value. ExpectedEPNodeAssignment::None, "cpu", has_constant_value); } // Pad edge mode TEST_F(QnnCPUBackendTests, PadModeEdge) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "edge")}, ExpectedEPNodeAssignment::All, "cpu", has_constant_value); } // Pad wrap mode not supported TEST_F(QnnCPUBackendTests, PadModeWrap) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "wrap")}, ExpectedEPNodeAssignment::None, // not supported "cpu", has_constant_value); } // Pad 4d TEST_F(QnnCPUBackendTests, Pad4d) { RunPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}), TestInputDef({8}, true, {0, 0, 0, 1, 0, 0, 0, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnCPUBackendTests, Pad4dNeg) { RunPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}), TestInputDef({8}, true, {0, 0, 0, -1, 0, 0, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnCPUBackendTests, Pad4dMix) { RunPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}), TestInputDef({8}, true, {1, 0, 0, -1, 0, 0, -1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } // Pad 5d supported TEST_F(QnnCPUBackendTests, Pad5d) { RunPadOpTest(TestInputDef({1, 2, 2, 2, 2}, false, GetFloatDataInRange(1.0f, 10.0f, 16)), TestInputDef({10}, true, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0}), TestInputDef({1}, true, {5.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } // Pad 6d supported TEST_F(QnnCPUBackendTests, Pad6d) { RunPadOpTest(TestInputDef({1, 2, 2, 2, 2, 2}, false, GetFloatDataInRange(1.0f, 10.0f, 32)), TestInputDef({12}, true, {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::None); } #if defined(__aarch64__) || defined(_M_ARM64) || defined(__linux__) // // HTP tests: TEST_F(QnnHTPBackendTests, PadNoConstantValue_fp16_test) { bool has_constant_value_input = false; bool enable_fp16_precision = true; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "htp", has_constant_value_input, 18, // opset enable_fp16_precision, 2e-3f); } TEST_F(QnnHTPBackendTests, PadReflectMode_fp16) { bool has_constant_value_input = false; bool enable_fp16_precision = true; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, "htp", has_constant_value_input, 18, // opset enable_fp16_precision, 2e-3f); } // HTP\HTP\src\hexagon\prepare\graph_prepare.cc:203:ERROR:could not create op: q::flat_from_vtcm // HTP\HTP\src\hexagon\prepare\graph_prepare.cc:1238:ERROR:Op 0x104100000011 preparation failed with err:-1 // Completed stage: Graph Transformations and Optimizations (13372 us) // QnnDsp "node" generated: could not create op // QnnDsp RouterWindows graph prepare failed 12 // QnnDsp Failed to finalize graph (id: 1) with err 1002 TEST_F(QnnHTPBackendTests, DISABLED_PadReflectMode_FP16_big_data) { bool has_constant_value_input = false; bool enable_fp16_precision = true; RunPadOpTest(TestInputDef({1, 4, 512, 512}, false, GetFloatDataInRange(1.0f, 10.0f, 4 * 512 * 512)), TestInputDef({8}, true, {0, 0, 3, 3, 0, 0, 3, 3}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, "htp", has_constant_value_input, 18, // opset enable_fp16_precision, 2e-3f); } TEST_F(QnnHTPBackendTests, PadNoConstantNegValue_fp16_test) { bool has_constant_value_input = false; bool enable_fp16_precision = true; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, -1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "htp", has_constant_value_input, 18, // opset enable_fp16_precision, 2e-3f); } TEST_F(QnnHTPBackendTests, PadNoConstantMixValue_fp16_test) { bool has_constant_value_input = false; bool enable_fp16_precision = true; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {1, -1, -1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "htp", has_constant_value_input, 18, // opset enable_fp16_precision, 2e-3f); } // // QDQ Pad TEST_F(QnnHTPBackendTests, PadNoConstantValue) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } TEST_F(QnnHTPBackendTests, PadNoConstantNegValue) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, -1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } TEST_F(QnnHTPBackendTests, PadNoConstantMixValue) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {1, -1, -1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } TEST_F(QnnHTPBackendTests, PadHasConstantValueNonQuantized) { bool has_constant_value_input = true; bool constant_value_quantized = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, has_constant_value_input, constant_value_quantized); } TEST_F(QnnHTPBackendTests, PadHasConstantValueQuantized) { bool has_constant_value_input = true; bool constant_value_quantized = true; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, has_constant_value_input, constant_value_quantized); } TEST_F(QnnHTPBackendTests, PadReflectMode) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } TEST_F(QnnHTPBackendTests, PadReflectModeNeg) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, -1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::None, // reflect mode doesn't support negative padding value. has_constant_value_input); } /// Issue filed: https://github.com/microsoft/onnxruntime/issues/27683 /// QNN accepts invalid input. However, this test runs CPU f32 first to get reference input /// which is no longer possible with invalid pads. The real issue is that QNN accepts invalid pads for reflect mode, /// which should be rejected as per ONNX spec. // Pad amount should not be greater than shape(input[0])[i] - 1 TEST_F(QnnHTPBackendTests, DISABLED_PadReflectModeOutOfRangePadAmount) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::None, has_constant_value_input); } TEST_F(QnnHTPBackendTests, Pad4dReflectMode) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}), TestInputDef({8}, true, {0, 1, 1, 1, 0, 1, 1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } TEST_F(QnnHTPBackendTests, PadEdgeMode) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "edge")}, ExpectedEPNodeAssignment::All, has_constant_value_input); } // wrap mode not supported TEST_F(QnnHTPBackendTests, PadWrapMode) { bool has_constant_value_input = false; RunQDQPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "wrap")}, ExpectedEPNodeAssignment::None, has_constant_value_input); } TEST_F(QnnHTPBackendTests, Pad4d) { RunQDQPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}), TestInputDef({8}, true, {0, 0, 0, 1, 0, 0, 0, 1}), TestInputDef({1}, true, {5.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnHTPBackendTests, Pad4dNeg) { RunQDQPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}), TestInputDef({8}, true, {0, 0, 0, -1, 0, 0, -1, 0}), TestInputDef({1}, true, {5.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnHTPBackendTests, Pad4dMix) { RunQDQPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}), TestInputDef({8}, true, {0, 1, 0, -1, 0, 1, 0, 1}), TestInputDef({1}, true, {5.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } // Inaccuracy detected for output 'output', element 0. // Output quant params: scale=0.035294119268655777, zero_point=0. // Expected val: 9 // QNN QDQ val: 8.0117654800415039 (err 0.98823451995849609) // CPU QDQ val: 9 (err 0) // QNN limitation? pad_constant_value has to be within the range of input[0]. // Here pad_constant_value = 9.0 > max(input[0]) = 8.0 TEST_F(QnnHTPBackendTests, DISABLED_Pad4dOutOfRangePadConstantValue) { RunQDQPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}), TestInputDef({8}, true, {0, 0, 0, 1, 0, 0, 0, 1}), TestInputDef({1}, true, {9.0f}), // pad_constant_value out of input[0] range {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } TEST_F(QnnHTPBackendTests, Pad5d) { RunQDQPadOpTest(TestInputDef({1, 2, 2, 2, 2}, false, GetFloatDataInRange(1.0f, 10.0f, 16)), TestInputDef({10}, true, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0}), TestInputDef({1}, true, {2.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All); } #endif // defined(__aarch64__) || defined(_M_ARM64) || defined(__linux__) #if defined(_M_ARM64) // // GPU tests: // // Pad 2d TEST_F(QnnGPUBackendTests, Pad2d) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu"); } TEST_F(QnnGPUBackendTests, Pad2dOpset7) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu", true, // has_constant_value 7); // opset } TEST_F(QnnGPUBackendTests, Pad2dNeg) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, -1, -1, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu"); } TEST_F(QnnGPUBackendTests, Pad2dMix) { RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {1, -1, -1, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu"); } // Pad reflect mode // Disabled reason: GPU supplement - "MIRROR_REFLECT can only be used when rank(in[0]) is 4" TEST_F(QnnGPUBackendTests, DISABLED_PadModeReflect) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "reflect")}, ExpectedEPNodeAssignment::All, "gpu", has_constant_value); } // Pad edge mode TEST_F(QnnGPUBackendTests, PadModeEdge) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "edge")}, ExpectedEPNodeAssignment::All, "gpu", has_constant_value); } // Pad wrap mode not supported TEST_F(QnnGPUBackendTests, PadModeWrap) { bool has_constant_value = false; RunPadOpTest(TestInputDef({3, 2}, false, {1.0f, 1.2f, 2.3f, 3.4f, 4.5f, 5.6f}), TestInputDef({4}, true, {0, 2, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "wrap")}, ExpectedEPNodeAssignment::None, // not supported "gpu", has_constant_value); } // Pad 4d TEST_F(QnnGPUBackendTests, Pad4d) { RunPadOpTest(TestInputDef({1, 2, 2, 2}, false, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}), TestInputDef({8}, true, {0, 0, 0, 1, 0, 0, 0, 1}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu"); } // Pad 5d supported TEST_F(QnnGPUBackendTests, Pad5d) { RunPadOpTest(TestInputDef({1, 2, 2, 2, 2}, false, GetFloatDataInRange(1.0f, 10.0f, 16)), TestInputDef({10}, true, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0}), TestInputDef({1}, true, {5.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::All, "gpu"); } // Pad 6d supported TEST_F(QnnGPUBackendTests, Pad6d) { RunPadOpTest(TestInputDef({1, 2, 2, 2, 2, 2}, false, GetFloatDataInRange(1.0f, 10.0f, 32)), TestInputDef({12}, true, {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0}), TestInputDef({1}, true, {0.0f}), {utils::MakeAttribute("mode", "constant")}, ExpectedEPNodeAssignment::None, "gpu"); } #endif // defined(_M_ARM64) GPU tests } // namespace test } // namespace onnxruntime #endif // !defined(ORT_MINIMAL_BUILD)