mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-23 19:32:23 +00:00
[WebNN EP] Support Sign and CumSum operators (#22616)
This PR supports Sign and CumSum operators for WebNN EP. @Honry @fdwr PTAL, thanks.
This commit is contained in:
parent
ac6fe48375
commit
777fe7922c
7 changed files with 101 additions and 8 deletions
|
|
@ -25,6 +25,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim
|
|||
| Conv | ai.onnx(7-10, 11+) | conv2d | ✓ | ✓ | Only supports 3-D or 4-D input and 'W' (weight) |
|
||||
| ConvTranspose | ai.onnx(7-10, 11+) | convTranspose2d | ✓ | ✓ | Only supports 3-D or 4-D input and 'W' (weight). WebNN CPU backend only supports default dilations and group |
|
||||
| Cos | ai.onnx(7+) | cos | ✓ | ✓ | |
|
||||
| CumSum | ai.onnx(11-13, 14+) | cumulativeSum | ✓ | ✓ | |
|
||||
| Div | ai.onnx(7-12, 13, 14+) | div | ✓ | ✓ | |
|
||||
| DequantizeLinear | ai.onnx(10-12, 13-18, 19-20, 21-22, 23+) | dequantizeLinear | ✗ | ✓ | |
|
||||
| Dropout | ai.onnx(7-9, 10-11, 12, 13-21, 22+) | identity | ✓ | ✓ | Only supports test mode |
|
||||
|
|
@ -87,6 +88,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim
|
|||
| ScatterND | ai.onnx(11-12, 13-15, 16-17, 18+) | scatterND | ✗ | ✓ | Only supports 'reduction' == 'none' |
|
||||
| Shape | ai.onnx(7-12, 13-14, 15-18, 19-20, 21+) | slice | ✓ | ✓ | |
|
||||
| Sigmoid | ai.onnx(7-12, 13+) | sigmoid | ✓ | ✓ | |
|
||||
| Sign | ai.onnx(9-12, 13+) | sign | ✓ | ✓ | |
|
||||
| Softplus | ai.onnx(7+) | softplus | ✓ | ✓ | |
|
||||
| Softsign | ai.onnx(7+) | softsign | ✓ | ✓ | |
|
||||
| Sin | ai.onnx(7+) | sin | ✓ | ✓ | |
|
||||
|
|
|
|||
|
|
@ -1699,13 +1699,13 @@
|
|||
"test_cos",
|
||||
// "test_cosh_example",
|
||||
// "test_cosh",
|
||||
// "test_cumsum_1d_exclusive",
|
||||
// "test_cumsum_1d_reverse_exclusive",
|
||||
// "test_cumsum_1d_reverse",
|
||||
// "test_cumsum_1d",
|
||||
// "test_cumsum_2d_axis_0",
|
||||
// "test_cumsum_2d_axis_1",
|
||||
// "test_cumsum_2d_negative_axis",
|
||||
"test_cumsum_1d_exclusive",
|
||||
"test_cumsum_1d_reverse_exclusive",
|
||||
"test_cumsum_1d_reverse",
|
||||
"test_cumsum_1d",
|
||||
"test_cumsum_2d_axis_0",
|
||||
"test_cumsum_2d_axis_1",
|
||||
"test_cumsum_2d_negative_axis",
|
||||
// "test_depthtospace_crd_mode_example",
|
||||
// "test_depthtospace_crd_mode",
|
||||
// "test_depthtospace_dcr_mode",
|
||||
|
|
@ -2352,7 +2352,7 @@
|
|||
// "test_shrink_soft",
|
||||
"test_sigmoid_example",
|
||||
"test_sigmoid",
|
||||
// "test_sign",
|
||||
"test_sign",
|
||||
// "test_simple_rnn_batchwise",
|
||||
// "test_simple_rnn_defaults",
|
||||
// "test_simple_rnn_with_initial_bias",
|
||||
|
|
|
|||
|
|
@ -204,6 +204,7 @@ static const InlinedHashMap<std::string, std::string> op_map = {
|
|||
{"ConvInteger", "conv2dInteger"},
|
||||
{"ConvTranspose", "convTranspose2d"},
|
||||
{"Cos", "cos"},
|
||||
{"CumSum", "cumulativeSum"},
|
||||
{"Div", "div"},
|
||||
{"DequantizeLinear", "dequantizeLinear"},
|
||||
{"Dropout", "identity"},
|
||||
|
|
@ -268,6 +269,7 @@ static const InlinedHashMap<std::string, std::string> op_map = {
|
|||
{"ScatterND", "scatterND"},
|
||||
{"Shape", "slice"},
|
||||
{"Sigmoid", "sigmoid"},
|
||||
{"Sign", "sign"},
|
||||
{"Softplus", "softplus"},
|
||||
{"Softsign", "softsign"},
|
||||
{"Sin", "sin"},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Intel Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "core/common/safeint.h"
|
||||
#include "core/framework/tensorprotoutils.h"
|
||||
#include "core/optimizer/initializer.h"
|
||||
#include "core/providers/common.h"
|
||||
#include "core/providers/shared/utils/utils.h"
|
||||
#include "core/providers/webnn/builders/helper.h"
|
||||
#include "core/providers/webnn/builders/model_builder.h"
|
||||
#include "core/providers/webnn/builders/op_builder_factory.h"
|
||||
|
||||
#include "base_op_builder.h"
|
||||
|
||||
namespace onnxruntime {
|
||||
namespace webnn {
|
||||
|
||||
class CumSumOpBuilder : public BaseOpBuilder {
|
||||
// Add operator related.
|
||||
|
||||
private:
|
||||
Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node,
|
||||
const logging::Logger& logger) const override ORT_MUST_USE_RESULT;
|
||||
|
||||
// Operator support related.
|
||||
private:
|
||||
bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node,
|
||||
const WebnnDeviceType /* device_type */, const logging::Logger& logger) const override;
|
||||
};
|
||||
|
||||
// Add operator related.
|
||||
Status CumSumOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
||||
const Node& node,
|
||||
const logging::Logger& logger) const {
|
||||
const auto& input_defs = node.InputDefs();
|
||||
emscripten::val input = model_builder.GetOperand(input_defs[0]->Name());
|
||||
std::vector<int64_t> input_shape;
|
||||
ORT_RETURN_IF_NOT(GetShape(*input_defs[0], input_shape, logger), "Cannot get input shape");
|
||||
const auto input_rank = input_shape.size();
|
||||
|
||||
NodeAttrHelper helper(node);
|
||||
int64_t axis = helper.Get("axis", 0);
|
||||
axis = HandleNegativeAxis(axis, input_rank);
|
||||
|
||||
const auto exclusive = helper.Get("exclusive", 0);
|
||||
const auto reverse = helper.Get("reverse", 0);
|
||||
|
||||
emscripten::val options = emscripten::val::object();
|
||||
options.set("exclusive", exclusive == 1);
|
||||
options.set("reversed", reverse == 1);
|
||||
options.set("label", node.Name());
|
||||
|
||||
emscripten::val output = emscripten::val::object();
|
||||
output = model_builder.GetBuilder().call<emscripten::val>("cumulativeSum", input, gsl::narrow<uint32_t>(axis), options);
|
||||
model_builder.AddOperand(node.OutputDefs()[0]->Name(), std::move(output));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// Operator support related.
|
||||
bool CumSumOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& /* initializers */,
|
||||
const Node& node,
|
||||
WebnnDeviceType /* device_type */,
|
||||
const logging::Logger& logger) const {
|
||||
const auto& input_defs = node.InputDefs();
|
||||
|
||||
std::vector<int64_t> input_shape;
|
||||
if (!GetShape(*input_defs[0], input_shape, logger))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreateCumSumOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations) {
|
||||
op_registrations.builders.push_back(std::make_unique<CumSumOpBuilder>());
|
||||
op_registrations.op_builder_map.emplace(op_type, op_registrations.builders.back().get());
|
||||
}
|
||||
|
||||
} // namespace webnn
|
||||
} // namespace onnxruntime
|
||||
|
|
@ -51,6 +51,8 @@ Status UnaryOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const
|
|||
output = model_builder.GetBuilder().call<emscripten::val>("neg", input, options);
|
||||
} else if (op_type == "Reciprocal") {
|
||||
output = model_builder.GetBuilder().call<emscripten::val>("reciprocal", input, options);
|
||||
} else if (op_type == "Sign") {
|
||||
output = model_builder.GetBuilder().call<emscripten::val>("sign", input, options);
|
||||
} else if (op_type == "Sin") {
|
||||
output = model_builder.GetBuilder().call<emscripten::val>("sin", input, options);
|
||||
} else if (op_type == "Sqrt") {
|
||||
|
|
@ -82,6 +84,7 @@ void CreateUnaryOpBuilder(const std::string& op_type, OpBuilderRegistrations& op
|
|||
"Log",
|
||||
"Neg",
|
||||
"Reciprocal",
|
||||
"Sign",
|
||||
"Sin",
|
||||
"Sqrt",
|
||||
"Tan",
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ static OpBuilderRegistrations CreateOpBuilderRegistrations() {
|
|||
CreateUnaryOpBuilder("Log", op_registrations);
|
||||
CreateUnaryOpBuilder("Neg", op_registrations);
|
||||
CreateUnaryOpBuilder("Reciprocal", op_registrations);
|
||||
CreateUnaryOpBuilder("Sign", op_registrations);
|
||||
CreateUnaryOpBuilder("Sin", op_registrations);
|
||||
CreateUnaryOpBuilder("Sqrt", op_registrations);
|
||||
CreateUnaryOpBuilder("Tan", op_registrations);
|
||||
|
|
@ -80,6 +81,10 @@ static OpBuilderRegistrations CreateOpBuilderRegistrations() {
|
|||
CreateConcatOpBuilder("Concat", op_registrations);
|
||||
}
|
||||
|
||||
{ // CumSum
|
||||
CreateConcatOpBuilder("CumSum", op_registrations);
|
||||
}
|
||||
|
||||
{ // Dropout
|
||||
CreateDropoutOpBuilder("Dropout", op_registrations);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ void CreateCastOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_
|
|||
void CreateClipOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateConvOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateConcatOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateCumSumOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateDropoutOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateDynamicQuantizeLinearOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
void CreateExpandOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations);
|
||||
|
|
|
|||
Loading…
Reference in a new issue