diff --git a/onnxruntime/core/providers/webnn/builders/helper.h b/onnxruntime/core/providers/webnn/builders/helper.h index aa84fb0bd43af..500c1c1b07e5e 100644 --- a/onnxruntime/core/providers/webnn/builders/helper.h +++ b/onnxruntime/core/providers/webnn/builders/helper.h @@ -82,7 +82,7 @@ inline std::string GetTensorName(const ConstPointerContainer index) ? std::string(input_defs[index]->Name()) : ""; } -inline std::vector GetVecUint32FromVecInt64(const std::vector& int64_vec) { +inline std::vector GetVecUint32FromVecInt64(gsl::span int64_vec) { std::vector uint32_vec; uint32_vec.reserve(int64_vec.size()); std::transform(int64_vec.begin(), int64_vec.end(), @@ -340,6 +340,13 @@ bool IsDataTypeSupportedByOp(const std::string& onnx_op_type, const std::string& onnx_input_output_name, const logging::Logger& logger); +bool IsDataTypeSupportedByWebNNOp(const std::string& onnx_op_type, const std::string& webnn_op_type, + const int32_t onnx_data_type, + const emscripten::val& wnn_limits, + const std::string& webnn_input_output_name, + const std::string& onnx_input_output_name, + const logging::Logger& logger); + bool GetBidirectionalBroadcastShape(std::vector& shape_a, std::vector& shape_b, std::vector& output_shape); diff --git a/onnxruntime/core/providers/webnn/builders/impl/slice_op_builder.cc b/onnxruntime/core/providers/webnn/builders/impl/slice_op_builder.cc index 0cb9de0a17381..49d59707adcae 100644 --- a/onnxruntime/core/providers/webnn/builders/impl/slice_op_builder.cc +++ b/onnxruntime/core/providers/webnn/builders/impl/slice_op_builder.cc @@ -62,9 +62,11 @@ Status SliceOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const std::string input_name; // This is an optional input, return empty vector. if (!is_required) { - if (input_defs.size() <= input_idx) return Status::OK(); + if (input_defs.size() <= input_idx) + return Status::OK(); input_name = input_defs[input_idx]->Name(); - if (input_name.empty()) return Status::OK(); + if (input_name.empty()) + return Status::OK(); } input_name = input_defs[input_idx]->Name(); const auto& initializers(model_builder.GetInitializerTensors()); @@ -112,15 +114,11 @@ Status SliceOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const emscripten::val output = reverse_output; if (is_slice_required) { - std::vector starts(rank); + std::vector starts = GetVecUint32FromVecInt64(compute_metadata.starts_); + std::vector steps = GetVecUint32FromVecInt64(compute_metadata.steps_);; std::vector sizes(rank); - std::vector steps(rank); - std::transform(compute_metadata.starts_.cbegin(), compute_metadata.starts_.cend(), starts.begin(), - [](int64_t i) { return SafeInt(i); }); std::transform(compute_metadata.ends_.cbegin(), compute_metadata.ends_.cend(), compute_metadata.starts_.cbegin(), sizes.begin(), [](int64_t i, int64_t j) { return SafeInt(i - j); }); - std::transform(compute_metadata.steps_.cbegin(), compute_metadata.steps_.cend(), steps.begin(), - [](int64_t i) { return SafeInt(i); }); emscripten::val options = emscripten::val::object(); options.set("strides", emscripten::val::array(steps));