mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-19 19:00:47 +00:00
[WebNN EP] Fixed build error (#16671)
The build break was caused by enabling `-Wshorten-64-to-32` in https://github.com/microsoft/onnxruntime/pull/16524
This commit is contained in:
parent
b7fd5af48b
commit
d5b76cff60
7 changed files with 24 additions and 21 deletions
|
|
@ -124,13 +124,13 @@ bool IsSupportedDataType(const int32_t data_type, const WebnnDeviceType device_t
|
|||
bool IsValidMultidirectionalBroadcast(std::vector<int64_t>& shape_a,
|
||||
std::vector<int64_t>& shape_b,
|
||||
const logging::Logger& logger) {
|
||||
int64_t size_a = shape_a.size();
|
||||
int64_t size_b = shape_b.size();
|
||||
int64_t smaller_size = std::min(size_a, size_b);
|
||||
for (int64_t i = 0; i < smaller_size; i++) {
|
||||
size_t size_a = shape_a.size();
|
||||
size_t size_b = shape_b.size();
|
||||
size_t smaller_size = std::min(size_a, size_b);
|
||||
for (size_t i = 0; i < smaller_size; i++) {
|
||||
// right alignment
|
||||
int64_t axis_a = size_a - i - 1;
|
||||
int64_t axis_b = size_b - i - 1;
|
||||
size_t axis_a = size_a - i - 1;
|
||||
size_t axis_b = size_b - i - 1;
|
||||
// Broadcastable tensors must either have each dimension the same size or equal to one.
|
||||
if (shape_a[axis_a] != shape_b[axis_b] && shape_a[axis_a] != 1 && shape_b[axis_b] != 1) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ Status ConvOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
|
|||
std::vector<int64_t> input_shape;
|
||||
ORT_RETURN_IF_NOT(GetShape(*input_defs[0], input_shape, logger), "Cannot get shape");
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
total_padding[i] = strides[i] * (input_shape[i + 1] - 1) +
|
||||
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 1]) - 1) +
|
||||
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
|
||||
}
|
||||
pads[0] = total_padding[0] - (total_padding[0] / 2);
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ Status NormalizationOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder
|
|||
if (op_type == "LayerNormalization") {
|
||||
int64_t axis = helper.Get("axis", -1);
|
||||
axis = HandleNegativeAxis(axis, rank);
|
||||
std::vector<int32_t> axes(rank - axis);
|
||||
std::vector<int32_t> axes(rank - narrow<size_t>(axis));
|
||||
std::iota(axes.begin(), axes.end(), axis);
|
||||
options.set("axes", emscripten::val::array(axes));
|
||||
output = model_builder.GetBuilder().call<emscripten::val>("meanVarianceNormalization", input, options);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Copyright (c) Intel Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "core/common/safeint.h"
|
||||
#include "core/providers/common.h"
|
||||
#include "core/providers/shared/utils/utils.h"
|
||||
#include "core/providers/webnn/builders/helper.h"
|
||||
|
|
@ -71,7 +72,7 @@ Status ReductionOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
const auto axes_data_span = axes_initializer.DataAsSpan<int64_t>();
|
||||
std::transform(
|
||||
axes_data_span.begin(), axes_data_span.end(), std::back_inserter(axes_data),
|
||||
[input_rank](int64_t axis) -> int32_t { return HandleNegativeAxis(axis, input_rank); });
|
||||
[input_rank](int64_t axis) -> int32_t { return SafeInt<int32_t>(HandleNegativeAxis(axis, input_rank)); });
|
||||
} else {
|
||||
if (noop_with_empty_axes) {
|
||||
// When axes is empty and this attribute is set to true, input tensor will not be reduced.
|
||||
|
|
@ -85,7 +86,7 @@ Status ReductionOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
auto axes = helper.Get("axes", std::vector<int64_t>{});
|
||||
std::transform(
|
||||
axes.begin(), axes.end(), std::back_inserter(axes_data),
|
||||
[input_rank](int64_t axis) -> int32_t { return HandleNegativeAxis(axis, input_rank); });
|
||||
[input_rank](int64_t axis) -> int32_t { return SafeInt<int32_t>(HandleNegativeAxis(axis, input_rank)); });
|
||||
}
|
||||
}
|
||||
if (axes_data.size() > 0) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Copyright (c) Intel Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "core/common/safeint.h"
|
||||
#include "core/providers/common.h"
|
||||
#include "core/providers/shared/utils/utils.h"
|
||||
#include "core/providers/webnn/builders/helper.h"
|
||||
|
|
@ -36,7 +37,7 @@ Status SoftmaxOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
const auto input_size = input_shape.size();
|
||||
// WebNN Softmax only support 2d input shape, reshape input to 2d.
|
||||
if (input_size != 2) {
|
||||
int32_t new_shape_0 = input_shape.data()[0];
|
||||
int32_t new_shape_0 = SafeInt<int32_t>(input_shape.data()[0]);
|
||||
for (size_t i = 1; i < input_size - 1; i++) {
|
||||
new_shape_0 *= input_shape.data()[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ Status SplitOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
emscripten::val options = emscripten::val::object();
|
||||
|
||||
NodeAttrHelper helper(node);
|
||||
int64_t axis = helper.Get("axis", 0);
|
||||
axis = HandleNegativeAxis(axis, rank);
|
||||
options.set("axis", static_cast<int32_t>(axis));
|
||||
auto axis = helper.Get("axis", 0);
|
||||
axis = SafeInt<int32_t>(HandleNegativeAxis(axis, rank));
|
||||
options.set("axis", axis);
|
||||
|
||||
if (input_defs.size() == 2) {
|
||||
// Inputs contains optional 'split' input
|
||||
|
|
@ -59,7 +59,7 @@ Status SplitOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
"The size of outputs must be equal to the size of 'split' input.");
|
||||
} else {
|
||||
if (helper.HasAttr("num_outputs")) {
|
||||
const int64_t num_outputs = helper.Get("num_outputs", 1);
|
||||
const auto num_outputs = helper.Get("num_outputs", 1);
|
||||
ORT_RETURN_IF_NOT(num_outputs > 0, "The 'num_outputs' must be a positive integer.");
|
||||
if (input_shape[axis] % num_outputs == 0) {
|
||||
// The 'num_outputs' evenly divide the dim value at 'axis' specified.
|
||||
|
|
@ -95,7 +95,7 @@ Status SplitOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
|
|||
"The size of outputs must be equal to the count of output nodes.");
|
||||
}
|
||||
}
|
||||
for (int64_t i = 0, count = output_array["length"].as<int32_t>(); i < count; i++) {
|
||||
for (size_t i = 0, count = output_array["length"].as<int32_t>(); i < count; i++) {
|
||||
model_builder.AddOperand(node.OutputDefs()[i]->Name(), std::move(output_array[i]));
|
||||
}
|
||||
return Status::OK();
|
||||
|
|
@ -121,8 +121,8 @@ bool SplitOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers,
|
|||
const auto rank = input_shape.size();
|
||||
|
||||
NodeAttrHelper helper(node);
|
||||
int64_t axis = helper.Get("axis", 0);
|
||||
axis = HandleNegativeAxis(axis, rank);
|
||||
auto axis = helper.Get("axis", 0);
|
||||
axis = SafeInt<int32_t>(HandleNegativeAxis(axis, rank));
|
||||
|
||||
if (input_defs.size() == 2) {
|
||||
// Inputs contains optional 'split' input
|
||||
|
|
@ -143,7 +143,7 @@ bool SplitOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers,
|
|||
return false;
|
||||
}
|
||||
int64_t sum = 0;
|
||||
for (int64_t i = 0; i < split.size(); i++) {
|
||||
for (size_t i = 0; i < split.size(); i++) {
|
||||
if (split[i] < 0) {
|
||||
LOGS(logger, VERBOSE) << "Value of split should be greater than or equal to 0.";
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Copyright (c) Intel Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "core/common/safeint.h"
|
||||
#include "core/providers/common.h"
|
||||
#include "core/providers/shared/utils/utils.h"
|
||||
#include "core/providers/webnn/builders/helper.h"
|
||||
|
|
@ -65,7 +66,7 @@ Status SqueezeUnsqueezeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_buil
|
|||
const auto output_rank = input_rank + axes_data_span.size();
|
||||
std::transform(
|
||||
axes_data_span.begin(), axes_data_span.end(), std::back_inserter(axes_data),
|
||||
[output_rank](int64_t axis) -> int32_t { return HandleNegativeAxis(axis, output_rank); });
|
||||
[output_rank](int64_t axis) -> int32_t { return SafeInt<int32_t>(HandleNegativeAxis(axis, output_rank)); });
|
||||
} else {
|
||||
NodeAttrHelper helper(node);
|
||||
if (helper.HasAttr("axes")) {
|
||||
|
|
@ -73,7 +74,7 @@ Status SqueezeUnsqueezeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_buil
|
|||
const auto output_rank = input_rank + axes.size();
|
||||
std::transform(
|
||||
axes.begin(), axes.end(), std::back_inserter(axes_data),
|
||||
[output_rank](int64_t axis) -> int32_t { return HandleNegativeAxis(axis, output_rank); });
|
||||
[output_rank](int64_t axis) -> int32_t { return SafeInt<int32_t>(HandleNegativeAxis(axis, output_rank)); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue