-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[WebNN EP] Support Sign and CumSum operators #22616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, 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, | ||
miaobin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.