Skip to content

Commit

Permalink
[WebNN EP] Fall back resize nearest mode for WebNN CPU backend (#19039)
Browse files Browse the repository at this point in the history
WebNN CPU backend only supports linear mode. Fall back for this case.
  • Loading branch information
zesongw authored Jan 9, 2024
1 parent 52e5601 commit 99a8400
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ResizeOpBuilder : public BaseOpBuilder {
// Operator support related.
private:
bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node,
const WebnnDeviceType /* device_type */, const logging::Logger& logger) const override;
const WebnnDeviceType device_type, const logging::Logger& logger) const override;

// Resize opset 10- is very different than Resize opset 11+, with many key attributes missing.
// We only support Resize opset 11+ here.
Expand Down Expand Up @@ -161,7 +161,7 @@ Status ResizeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,

bool ResizeOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers,
const Node& node,
const WebnnDeviceType /* device_type */,
const WebnnDeviceType device_type,
const logging::Logger& logger) const {
const auto& input_defs = node.InputDefs();

Expand All @@ -181,9 +181,18 @@ bool ResizeOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers
const auto mode = helper.Get("mode", "nearest");
bool is_linear_resize = mode == "linear";
bool is_nearest_resize = mode == "nearest";
if (!is_linear_resize && !is_nearest_resize) {
LOGS(logger, VERBOSE) << "Resize unsupported input mode, " << mode;
return false;
// WebNN CPU backend only supports "linear" mode.
// WebNN GPU backend only supports "linear" and "nearest" modes.
if (device_type == WebnnDeviceType::CPU) {
if (!is_linear_resize) {
LOGS(logger, VERBOSE) << "Resize unsupported input mode, " << mode << " for CPU backend.";
return false;
}
} else {
if (!is_linear_resize && !is_nearest_resize) {
LOGS(logger, VERBOSE) << "Resize unsupported input mode, " << mode << " for GPU backend.";
return false;
}
}

const auto exclude_outside = helper.Get("exclude_outside", 0);
Expand Down

0 comments on commit 99a8400

Please sign in to comment.