Skip to content
Merged
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
30 changes: 29 additions & 1 deletion onnxruntime/core/providers/webgpu/nn/conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#include "core/providers/webgpu/nn/grouped_conv.h"
#include "core/providers/webgpu/webgpu_utils.h"
#include "core/providers/webgpu/math/matmul.h"

namespace {

inline uint32_t ceil_div(int64_t numerator, int32_t denominator) {
return static_cast<uint32_t>((numerator + denominator - 1) / denominator);
}

} // namespace

namespace onnxruntime {
namespace webgpu {

Expand All @@ -19,6 +28,24 @@
transposed_kernel_shape_vector[i] = kernel_shape[perm[i]];
}
uint32_t output_size = onnxruntime::narrow<uint32_t>(kernel_shape.Size());

uint32_t dispatch_x = ceil_div(output_size, 64);
uint32_t dispatch_y = 1;
uint32_t dispatch_z = 1;

// This temporary workaround addresses a significant performance bottleneck
// (~12x slower) for the shape (3, 3, 2560, 1280) due to an issue with Intel's
// GPU drivers. We manually normalize the dispatch group size to restore
// performance.
//
// TODO: Revert this change once the driver issue is fixed.

Check warning on line 41 in onnxruntime/core/providers/webgpu/nn/conv.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2] Raw Output: onnxruntime/core/providers/webgpu/nn/conv.cc:41: Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2]

Check warning on line 41 in onnxruntime/core/providers/webgpu/nn/conv.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2] Raw Output: onnxruntime/core/providers/webgpu/nn/conv.cc:41: Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2]
if (context.AdapterInfo().vendor == std::string_view{"intel"}) {
ORT_ENFORCE(rank == static_cast<size_t>(4), "Input tensor must have rank 4.");
dispatch_x = ceil_div(transposed_kernel_shape_vector[0] * transposed_kernel_shape_vector[1], 2);
dispatch_y = ceil_div(transposed_kernel_shape_vector[2], 4);
dispatch_z = ceil_div(transposed_kernel_shape_vector[3], 8);
Comment thread
daijh marked this conversation as resolved.
}

TensorShape transposed_kernel_shape(transposed_kernel_shape_vector);
*transposed_kernel = context.CreateGPUTensor(kernel->DataType(), transposed_kernel_shape);
bool use_shared = false;
Expand All @@ -28,7 +55,8 @@
.AddInput({kernel, ProgramTensorMetadataDependency::TypeAndRank, kernel_shape, 1})
.AddOutput({transposed_kernel, ProgramTensorMetadataDependency::TypeAndRank})
.AddUniformVariable({output_size})
.SetDispatchGroupSize((output_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE);
.SetWorkgroupSize(64)
.SetDispatchGroupSize(dispatch_x, dispatch_y, dispatch_z);
return context.RunProgram(program);
}

Expand Down
Loading