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

fix webgpu precision errors #22718

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion onnxruntime/contrib_ops/webgpu/bert/skip_layer_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Status SkipLayerNorm<simplified>::ComputeInternal(onnxruntime::webgpu::ComputeCo
auto* output = context.Output(0, x_shape);
auto* input_skip_bias_sum = context.Output(3, x_shape);

size_t data_size = x_shape.Size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to understand the issue - the fix is for android/32bit?

size_t data_size = static_cast<size_t>(x_shape.Size());
if (data_size == 0) {
return Status::OK();
}
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/webgpu/buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SimpleCacheManager : public IBufferCacheManager {

void OnRefresh() override {
for (auto& buffer : pending_buffers_) {
buffers_[wgpuBufferGetSize(buffer)].push_back(buffer);
buffers_[static_cast<unsigned int>(wgpuBufferGetSize(buffer))].push_back(buffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wgpuBufferGetSize() returns uint64_t. casting to size_t should work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same to the other occurrence.

}
pending_buffers_.clear();
}
Expand Down Expand Up @@ -167,7 +167,7 @@ class BucketCacheManager : public IBufferCacheManager {
// TODO: consider graph capture. currently not supported

for (auto& buffer : pending_buffers_) {
auto buffer_size = wgpuBufferGetSize(buffer);
auto buffer_size = static_cast<unsigned int>(wgpuBufferGetSize(buffer));

auto it = buckets_.find(buffer_size);
if (it != buckets_.end() && it->second.size() < buckets_limit_[buffer_size]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
} else {
size_t shared_dimension = 1;
for (size_t i = 1; i < output_shape.NumDimensions(); i++) {
size_t dimA = lhs_shape.NumDimensions() >= i ? lhs_shape[lhs_shape.NumDimensions() - i] : 1;
size_t dimB = rhs_shape.NumDimensions() >= i ? rhs_shape[rhs_shape.NumDimensions() - i] : 1;
size_t dimA = lhs_shape.NumDimensions() >= i ? static_cast<size_t>(lhs_shape[lhs_shape.NumDimensions() - i]) : 1;

Check warning on line 128 in onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.cc:128: Lines should be <= 120 characters long [whitespace/line_length] [2]
size_t dimB = rhs_shape.NumDimensions() >= i ? static_cast<size_t>(rhs_shape[rhs_shape.NumDimensions() - i]) : 1;

Check warning on line 129 in onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.cc:129: Lines should be <= 120 characters long [whitespace/line_length] [2]
if (dimA == dimB) {
shared_dimension *= dimA;
num_shared_dimension++;
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/webgpu/nn/layer_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Status LayerNorm<simplified>::ComputeInternal(onnxruntime::webgpu::ComputeContex

auto* output = context.Output(0, x_shape);

size_t data_size = x_shape.Size();
size_t data_size = static_cast<size_t>(x_shape.Size());
if (data_size == 0) {
return Status::OK();
}
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/webgpu/tensor/concat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Status Concat::ComputeInternal(ComputeContext& context) const {

uint32_t output_size = gsl::narrow_cast<int32_t>(prepare.output_tensor->Shape().Size());

ConcatProgram program{prepare.axis};
ConcatProgram program{static_cast<size_t>(prepare.axis)};

std::vector<uint32_t> sizes_in_concat_axis;
sizes_in_concat_axis.reserve(input_count);
Expand All @@ -118,7 +118,7 @@ Status Concat::ComputeInternal(ComputeContext& context) const {
}
program.AddInput({input.tensor, ProgramTensorMetadataDependency::TypeAndRank});

auto axis_size = input.tensor->Shape()[prepare.axis];
auto axis_size = input.tensor->Shape()[static_cast<size_t>(prepare.axis)];
sum += static_cast<uint32_t>(axis_size);
sizes_in_concat_axis.push_back(sum);
}
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/webgpu/webgpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void WebGpuContext::CollectProfilingData(profiling::Events& events) {

ORT_ENFORCE(Wait(query_read_buffer.MapAsync(wgpu::MapMode::Read,
0,
query_read_buffer.GetSize(),
static_cast<size_t>(query_read_buffer.GetSize()),
wgpu::CallbackMode::WaitAnyOnly,
[](wgpu::MapAsyncStatus status, const char* message) {
ORT_ENFORCE(status == wgpu::MapAsyncStatus::Success, "Failed to download data from buffer: ", message);
Expand Down
Loading