Skip to content

Commit 64b5642

Browse files
[QNN EP] Add Support for ScatterND Op in QNN EP (#24592)
- Registered the ScatterND Op in QNN EP - Created the op as part of the Simple Op Builder - Added unit test to verify the Op runs on QNN - Skipping ScatterND on QNN CPU (To Do) ### Description Add ScatterND Op Support in QNN EP ### Motivation and Context Performance improvement as ScatterND Op falls to ORT CPU due to missing support
1 parent 9564ed1 commit 64b5642

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

onnxruntime/core/providers/qnn/builder/op_builder_factory.cc

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ OpBuilderRegistrations::OpBuilderRegistrations() {
4343
CreateSimpleOpBuilder("Elu", *this);
4444
CreateSimpleOpBuilder("Round", *this);
4545
CreateSimpleOpBuilder("Where", *this);
46+
CreateSimpleOpBuilder("ScatterND", *this);
4647
CreateSimpleOpBuilder("Sigmoid", *this);
4748
CreateSimpleOpBuilder("Sin", *this);
4849
CreateSimpleOpBuilder("Sqrt", *this);

onnxruntime/core/providers/qnn/builder/opbuilder/base_op_builder.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class BaseOpBuilder : public IOpBuilder {
155155
{"ReduceSum", QNN_OP_REDUCE_SUM},
156156
{"Round", QNN_OP_ELEMENT_WISE_ROUND},
157157
{"Where", QNN_OP_ELEMENT_WISE_SELECT},
158+
{"ScatterND", QNN_OP_SCATTER_ND},
158159
{"Sigmoid", QNN_OP_SIGMOID},
159160
{"Sin", QNN_OP_ELEMENT_WISE_SIN},
160161
{"Slice", QNN_OP_STRIDED_SLICE},

onnxruntime/core/providers/qnn/builder/opbuilder/simple_op_builder.cc

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ Status SimpleOpBuilder::ExplicitOpCheck(QnnModelWrapper& qnn_model_wrapper,
5656
padding_mode.c_str());
5757
}
5858

59+
// To DO: Remove once QNN CPU supports ScatterND
60+
const auto qnn_backend_type = qnn_model_wrapper.GetQnnBackendType();
61+
if (op_type == "ScatterND") {
62+
ORT_RETURN_IF_NOT(qnn_backend_type == QnnBackendType::HTP,
63+
"QNN EP only supports ScatterND op on HTP backend. Falling back to ORT CPU.");
64+
}
65+
5966
// ONNX's Min, Max, and Sum operators accept a variable number of inputs (i.e., variadic).
6067
// However, QNN's Min, Max, and Add operators must take in exactly two inputs.
6168
if (op_type == "Min" || op_type == "Max") {

onnxruntime/test/providers/qnn/simple_op_htp_test.cc

+16
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,22 @@ TEST_F(QnnHTPBackendTests, BinaryOp_And4D) {
991991
ExpectedEPNodeAssignment::All);
992992
}
993993

994+
// Test ScatterND op on HTP
995+
TEST_F(QnnHTPBackendTests, ScatterND_int64_int64) {
996+
std::vector<int64_t> data = {0, 1, 2, 3};
997+
std::vector<int64_t> indices = {1};
998+
std::vector<int64_t> updates = {10};
999+
RunOpTest<int64_t>("ScatterND",
1000+
{
1001+
TestInputDef<int64_t>({4}, false, std::move(data)),
1002+
TestInputDef<int64_t>({1, 1}, false, std::move(indices)),
1003+
TestInputDef<int64_t>({1}, false, std::move(updates)),
1004+
},
1005+
{},
1006+
17,
1007+
ExpectedEPNodeAssignment::All);
1008+
}
1009+
9941010
// Test that Or is not yet supported on CPU backend.
9951011
TEST_F(QnnHTPBackendTests, BinaryOp_HTP_Or_Unsupported) {
9961012
RunOpTest<bool>("Or",

0 commit comments

Comments
 (0)