Skip to content

Commit

Permalink
[WebNN EP] Add several new unary Ops (Ceil, Exp, Identity, Reciprocal…
Browse files Browse the repository at this point in the history
…, Tan) (microsoft#16302)

### Description
 - Add new Ops: Ceil, Exp, Identity, Reciprocal, Tan.
 - Set MinSupportedOpSet for unary Ops.



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Support more Ops for other models.
The legacy optimization attribute "consumed_inputs" is not supported in
WebNN EP.
  • Loading branch information
zesongw authored Jun 13, 2023
1 parent 4f23577 commit c5176ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions onnxruntime/core/providers/webnn/builders/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ static const InlinedHashMap<std::string, std::string> op_map = {
{"Mul", "mul"},
{"Div", "div"},
{"Pow", "pow"},
{"Ceil", "ceil"},
{"Cos", "cos"},
{"Equal", "equal"},
{"Erf", "erf"},
{"Exp", "exp"},
{"Not", "logicalNot"},
{"Floor", "floor"},
{"Flatten", "flattenTo2d"},
{"Identity", "identity"},
{"Reciprocal", "reciprocal"},
{"Sin", "sin"},
{"Sqrt", "sqrt"},
{"Tan", "tan"},
{"Relu", "relu"},
{"LeakyRelu", "leakyRelu"},
{"Sigmoid", "sigmoid"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ Status UnaryOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const

emscripten::val input = model_builder.GetOperand(node.InputDefs()[0]->Name());
emscripten::val output = emscripten::val::object();
if (op_type == "Cos") {

if (op_type == "Ceil") {
output = model_builder.GetBuilder().call<emscripten::val>("ceil", input);
} else if (op_type == "Cos") {
output = model_builder.GetBuilder().call<emscripten::val>("cos", input);
} else if (op_type == "Erf") {
output = model_builder.GetBuilder().call<emscripten::val>("erf", input);
} else if (op_type == "Exp") {
output = model_builder.GetBuilder().call<emscripten::val>("exp", input);
} else if (op_type == "Floor") {
output = model_builder.GetBuilder().call<emscripten::val>("floor", input);
} else if (op_type == "Identity") {
output = model_builder.GetBuilder().call<emscripten::val>("identity", input);
} else if (op_type == "Not") {
output = model_builder.GetBuilder().call<emscripten::val>("logicalNot", input);
} else if (op_type == "Reciprocal") {
output = model_builder.GetBuilder().call<emscripten::val>("reciprocal", input);
} else if (op_type == "Sin") {
output = model_builder.GetBuilder().call<emscripten::val>("sin", input);
} else if (op_type == "Sqrt") {
output = model_builder.GetBuilder().call<emscripten::val>("sqrt", input);
} else if (op_type == "Tan") {
output = model_builder.GetBuilder().call<emscripten::val>("tan", input);
} else {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"UnaryOpBuilder::AddToModelBuilderImpl, unknown op: ", op_type);
Expand All @@ -55,12 +66,17 @@ void CreateUnaryOpBuilder(const std::string& op_type, OpBuilderRegistrations& op

static std::vector<std::string> op_types =
{
"Ceil",
"Cos",
"Erf",
"Exp",
"Floor",
"Identity",
"Not",
"Reciprocal",
"Sin",
"Sqrt",
"Tan",
};

op_registrations.builders.push_back(std::make_unique<UnaryOpBuilder>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ static OpBuilderRegistrations CreateOpBuilderRegistrations() {
OpBuilderRegistrations op_registrations;

{ // Unary
CreateUnaryOpBuilder("Ceil", op_registrations);
CreateUnaryOpBuilder("Cos", op_registrations);
CreateUnaryOpBuilder("Erf", op_registrations);
CreateUnaryOpBuilder("Exp", op_registrations);
CreateUnaryOpBuilder("Floor", op_registrations);
CreateUnaryOpBuilder("Identity", op_registrations);
CreateUnaryOpBuilder("Not", op_registrations);
CreateUnaryOpBuilder("Reciprocal", op_registrations);
CreateUnaryOpBuilder("Sin", op_registrations);
CreateUnaryOpBuilder("Sqrt", op_registrations);
CreateUnaryOpBuilder("Tan", op_registrations);
}

{ // Binary
Expand Down

0 comments on commit c5176ed

Please sign in to comment.