Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/web/docs/webnn-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 |
Expand Down Expand Up @@ -81,6 +82,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim
| Resize | ai.onnx(11-12, 13-17, 18, 19+) | resample2d | ✓ | ✓ | Only supports 4-D input, antialias == 0, coordinate_transformation_mode == 'half_pixel', exclude_outside == 0, keep_aspect_ratio_policy == 'stretch', 'linear' and 'nearest' modes, input 'scales' and 'sizes' if present must be a constant |
| 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 | ✓ | ✓ | |
Expand Down
16 changes: 8 additions & 8 deletions js/web/test/suite-test-list.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/providers/webnn/builders/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ static const InlinedHashMap<std::string, std::string> op_map = {
{"ConvInteger", "conv2dInteger"},
{"ConvTranspose", "convTranspose2d"},
{"Cos", "cos"},
{"CumSum", "cumulativeSum"},
{"Div", "div"},
{"DequantizeLinear", "dequantizeLinear"},
{"Dropout", "identity"},
Expand Down Expand Up @@ -262,6 +263,7 @@ static const InlinedHashMap<std::string, std::string> op_map = {
{"Resize", "resample2d"},
{"Shape", "slice"},
{"Sigmoid", "sigmoid"},
{"Sign", "sign"},
{"Softplus", "softplus"},
{"Softsign", "softsign"},
{"Sin", "sin"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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"

Check warning on line 14 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Include the directory when naming header files [build/include_subdir] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:14: Include the directory when naming header files [build/include_subdir] [4]

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 logging::Logger& logger) const override;
};

// Add operator related.
Status CumSumOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
const Node& node,

Check warning on line 34 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Do not indent within a namespace. [whitespace/indent_namespace] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:34: Do not indent within a namespace. [whitespace/indent_namespace] [4]
const logging::Logger& logger) const {

Check warning on line 35 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Do not indent within a namespace. [whitespace/indent_namespace] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:35: Do not indent within a namespace. [whitespace/indent_namespace] [4]
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, narrow<uint32_t>(axis), options);
model_builder.AddOperand(node.OutputDefs()[0]->Name(), std::move(output));

Check warning on line 56 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <utility> for move [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:56: Add #include <utility> for move [build/include_what_you_use] [4]
return Status::OK();
}

// Operator support related.
bool CumSumOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& /* initializers */,
const Node& node,

Check warning on line 62 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Do not indent within a namespace. [whitespace/indent_namespace] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:62: Do not indent within a namespace. [whitespace/indent_namespace] [4]
const logging::Logger& logger) const {

Check warning on line 63 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Do not indent within a namespace. [whitespace/indent_namespace] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:63: Do not indent within a namespace. [whitespace/indent_namespace] [4]
const auto& input_defs = node.InputDefs();

std::vector<int64_t> input_shape;

Check warning on line 66 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <vector> for vector<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:66: Add #include <vector> for vector<> [build/include_what_you_use] [4]
if (!GetShape(*input_defs[0], input_shape, logger))
return false;

return true;
}

void CreateCumSumOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations) {

Check warning on line 73 in onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc:73: Add #include <string> for string [build/include_what_you_use] [4]
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
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -82,6 +84,7 @@ void CreateUnaryOpBuilder(const std::string& op_type, OpBuilderRegistrations& op
"Log",
"Neg",
"Reciprocal",
"Sign",
"Sin",
"Sqrt",
"Tan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -80,6 +81,10 @@ static OpBuilderRegistrations CreateOpBuilderRegistrations() {
CreateConcatOpBuilder("Concat", op_registrations);
}

{ // CumSum
CreateConcatOpBuilder("CumSum", op_registrations);
}

{ // Dropout
CreateDropoutOpBuilder("Dropout", op_registrations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading