Skip to content
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

[WebNN EP] Use both MLOperandDescriptor.dimensions and MLOperandDescriptor.shape #22121

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Status DropoutOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
emscripten::val desc = emscripten::val::object();
desc.set("dataType", "uint8");
desc.set("dimensions", emscripten::val::array(dims));
desc.set("shape", emscripten::val::array(dims));
const auto num_elements = narrow<uint32_t>(Product(mask_shape));
emscripten::val ones_buffer = emscripten::val::global("Uint8Array").new_(num_elements);
ones_buffer.call<void>("fill", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Status ShapeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
emscripten::val dims = emscripten::val::array();
dims.call<void>("push", rank);
desc.set("dimensions", dims);
desc.set("shape", dims);
emscripten::val shape_buffer = emscripten::val::global("BigInt64Array").new_(emscripten::val::array(input_shape));
emscripten::val shape_constant = model_builder.GetBuilder().call<emscripten::val>("constant", desc, shape_buffer);

Expand Down
7 changes: 7 additions & 0 deletions onnxruntime/core/providers/webnn/builders/model_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
[](int64_t dim) -> int32_t { return SafeInt<int32_t>(dim); });

emscripten::val desc = emscripten::val::object();
// TODO: @Honry, remove all MLOperandDescriptor.dimensions usage in the future.

Check warning on line 103 in onnxruntime/core/providers/webnn/builders/model_builder.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2] Raw Output: onnxruntime/core/providers/webnn/builders/model_builder.cc:103: Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2]
// MLOperandDescriptor.dimensions is deprecated in WebNN API, we need to keep it
// in WebNN EP for a while to support older Chromium versions.
desc.set("dimensions", emscripten::val::array(dims));
desc.set("shape", emscripten::val::array(dims));
auto data_type = tensor.data_type();
emscripten::val operand = emscripten::val::object();
if (IsSupportedDataType(data_type, wnn_limits_["constant"]["dataTypes"])) {
Expand Down Expand Up @@ -203,6 +207,7 @@
emscripten::val desc = emscripten::val::object();

desc.set("dimensions", emscripten::val::array(dims));
desc.set("shape", emscripten::val::array(dims));

int32_t data_type;
{ // type
Expand Down Expand Up @@ -303,6 +308,7 @@
}

desc.set("dimensions", emscripten::val::array(shape));
desc.set("shape", emscripten::val::array(shape));
emscripten::val operand = emscripten::val::object();
// Wasm memory grow will cause all array buffers reallocation, which will be treated as detached
// buffers in JS side. Simply create a copy to fix it.
Expand Down Expand Up @@ -361,6 +367,7 @@
emscripten::val desc = emscripten::val::object();
emscripten::val dims = emscripten::val::array();
desc.set("dimensions", dims);
desc.set("shape", dims);
emscripten::val zero_buffer = emscripten::val::undefined();
if (!SetWebnnDataType(desc, data_type)) {
ORT_THROW("Unsupported data type: " + std::to_string(data_type));
Expand Down
Loading