Skip to content

Commit 5d43f0a

Browse files
authored
[WebNN] Replace narrow with SafeInt for consistently in integer handling (microsoft#24059)
Remove redundant header files BTW.
1 parent 4d5e274 commit 5d43f0a

28 files changed

+11
-36
lines changed

onnxruntime/core/providers/webnn/builders/impl/argmax_min_op_builder.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ Status ArgMaxMinOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
5454

5555
const auto& op_type = node.OpType();
5656
if (op_type == "ArgMax") {
57-
output = model_builder.GetBuilder().call<emscripten::val>("argMax", input, narrow<uint32_t>(axis), options);
57+
output = model_builder.GetBuilder().call<emscripten::val>("argMax", input, SafeInt<uint32_t>(axis).Ref(), options);
5858
} else if (op_type == "ArgMin") {
59-
output = model_builder.GetBuilder().call<emscripten::val>("argMin", input, narrow<uint32_t>(axis), options);
59+
output = model_builder.GetBuilder().call<emscripten::val>("argMin", input, SafeInt<uint32_t>(axis).Ref(), options);
6060
} else {
6161
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "ArgMaxMinOpBuilder, unknown op: ", op_type);
6262
}

onnxruntime/core/providers/webnn/builders/impl/builder_utils.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include <core/common/safeint.h>
65
#include <core/providers/common.h>
76
#include "core/providers/shared/utils/utils.h"
87

onnxruntime/core/providers/webnn/builders/impl/concat_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/providers/common.h"
76
#include "core/providers/shared/utils/utils.h"
87
#include "core/providers/webnn/builders/helper.h"

onnxruntime/core/providers/webnn/builders/impl/conv_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/optimizer/initializer.h"
76
#include "core/providers/common.h"
87
#include "core/providers/shared/utils/utils.h"

onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/framework/tensorprotoutils.h"
76
#include "core/optimizer/initializer.h"
87
#include "core/providers/common.h"
@@ -64,8 +63,8 @@ Status CumSumOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const
6463
options.set("label", node.Name());
6564

6665
emscripten::val output = emscripten::val::object();
67-
output = model_builder.GetBuilder().call<emscripten::val>("cumulativeSum", input, gsl::narrow<uint32_t>(webnn_axis),
68-
options);
66+
output = model_builder.GetBuilder().call<emscripten::val>("cumulativeSum", input,
67+
SafeInt<uint32_t>(webnn_axis).Ref(), options);
6968
model_builder.AddOperand(node.OutputDefs()[0]->Name(), std::move(output));
7069
return Status::OK();
7170
}

onnxruntime/core/providers/webnn/builders/impl/dynamicQuantizeLinear_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/optimizer/initializer.h"
76
#include "core/providers/common.h"
87
#include "core/providers/shared/utils/utils.h"

onnxruntime/core/providers/webnn/builders/impl/einsum_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/framework/tensorprotoutils.h"
76
#include "core/optimizer/initializer.h"
87
#include "core/providers/common.h"

onnxruntime/core/providers/webnn/builders/impl/expand_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/framework/tensorprotoutils.h"
76
#include "core/optimizer/initializer.h"
87
#include "core/providers/common.h"

onnxruntime/core/providers/webnn/builders/impl/flatten_op_builder.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/providers/common.h"
76
#include "core/providers/shared/utils/utils.h"
87
#include "core/providers/webnn/builders/helper.h"

onnxruntime/core/providers/webnn/builders/impl/gemm_op_builder.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Intel Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
#include "core/common/safeint.h"
65
#include "core/providers/common.h"
76
#include "core/providers/shared/utils/utils.h"
87
#include "core/providers/webnn/builders/helper.h"
@@ -86,9 +85,9 @@ Status GemmOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
8685
else if (extended_a_shape) {
8786
std::vector<uint32_t> new_shape;
8887
for (size_t i = 0; i < b_shape.size() - 2; i++) {
89-
new_shape.push_back(narrow<uint32_t>(b_shape[i]));
88+
new_shape.push_back(SafeInt<uint32_t>(b_shape[i]));
9089
}
91-
new_shape.push_back(narrow<uint32_t>(b_shape.back()));
90+
new_shape.push_back(SafeInt<uint32_t>(b_shape.back()));
9291
output = model_builder.GetBuilder().call<emscripten::val>("reshape",
9392
output,
9493
emscripten::val::array(new_shape),
@@ -98,7 +97,7 @@ Status GemmOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
9897
else if (extended_b_shape) {
9998
std::vector<uint32_t> new_shape;
10099
for (size_t i = 0; i < a_shape.size() - 1; i++) {
101-
new_shape.push_back(narrow<uint32_t>(a_shape[i]));
100+
new_shape.push_back(SafeInt<uint32_t>(a_shape[i]));
102101
}
103102
output = model_builder.GetBuilder().call<emscripten::val>("reshape",
104103
output,

0 commit comments

Comments
 (0)