Skip to content

Commit 8ac30df

Browse files
pytorchbotJCNTH
andauthored
[ExecuTorch][WebGPU] Fold remaining hardcoded 65535 dispatch-limit checks into queried_max_workgroups (#20950)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #20916 by @JCNTH ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/JCNTH/55/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/JCNTH/55/head Merge bot PR base: https://github.com/pytorch/executorch/tree/main Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/JCNTH/55/orig @diff-train-skip-merge Co-authored-by: Julian Ng-Thow-Hing <juliannth@meta.com> Co-authored-by: Julian Ng-Thow-Hing <107437036+JCNTH@users.noreply.github.com>
1 parent e51f1a9 commit 8ac30df

3 files changed

Lines changed: 7 additions & 23 deletions

File tree

backends/webgpu/runtime/WebGPUUtils.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,7 @@ make_uniform(WGPUDevice device, const void* data, size_t size) {
142142
// Clamp a 1D workgroup count to the device limit, for grid-stride kernels that
143143
// loop over any excess work (vs compute_1d_workgroup_count, which throws).
144144
inline uint32_t clamp_workgroup_count(WGPUDevice device, uint32_t desired) {
145-
WGPULimits limits = {};
146-
uint32_t max_count =
147-
wgpuDeviceGetLimits(device, &limits) == WGPUStatus_Success &&
148-
limits.maxComputeWorkgroupsPerDimension > 0
149-
? limits.maxComputeWorkgroupsPerDimension
150-
: 65535u; // WebGPU spec-default floor
151-
return std::min(desired, max_count);
145+
return std::min(desired, queried_max_workgroups(device));
152146
}
153147

154148
} // namespace executorch::backends::webgpu::utils

backends/webgpu/runtime/ops/quantized_linear/QuantizedLinear.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ constexpr uint32_t kQ4gswSteelTile = 64u;
6262
constexpr uint32_t kQ4gswSteelBK = 16u;
6363
constexpr uint32_t kQ4gswSteelInvocations = 256u;
6464

65-
// Max workgroups per 1D dispatch dimension: the device limit, or 65535 when the
66-
// query fails / reports 0.
67-
uint32_t max_workgroups_per_dim(WGPUDevice device) {
68-
WGPULimits limits = {};
69-
return (wgpuDeviceGetLimits(device, &limits) == WGPUStatus_Success &&
70-
limits.maxComputeWorkgroupsPerDimension > 0)
71-
? limits.maxComputeWorkgroupsPerDimension
72-
: 65535u;
73-
}
74-
7565
// One workgroup per (tile_m x tile_n) tile, no grid-stride: throw when the tile
7666
// count would exceed the 1D dispatch limit. Shared by the steel + shmem GEMM
7767
// routes; `kind` names the route in the error message.
@@ -85,7 +75,7 @@ uint32_t tiled_wg_count(
8575
const char* kind) {
8676
const int64_t total_wgs =
8777
utils::div_up<int64_t>(m, tile_m) * utils::div_up<int64_t>(n, tile_n);
88-
if (total_wgs > static_cast<int64_t>(max_workgroups_per_dim(device))) {
78+
if (total_wgs > static_cast<int64_t>(utils::queried_max_workgroups(device))) {
8979
throw std::runtime_error(
9080
std::string("WebGPU ") + op_name + ": " + kind +
9181
" tile count exceeds the 1D dispatch limit");
@@ -109,7 +99,7 @@ steel_workgroup_count(WGPUDevice device, uint32_t m, uint32_t n, uint32_t K) {
10999
const uint64_t total =
110100
static_cast<uint64_t>((m + kQ4gswSteelTile - 1u) / kQ4gswSteelTile) *
111101
static_cast<uint64_t>((n + kQ4gswSteelTile - 1u) / kQ4gswSteelTile);
112-
const uint32_t max_count = max_workgroups_per_dim(device);
102+
const uint32_t max_count = utils::queried_max_workgroups(device);
113103
return (total == 0u || total > max_count) ? 0u : static_cast<uint32_t>(total);
114104
}
115105

backends/webgpu/runtime/ops/rms_norm/RmsNorm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ void resize_rms_norm(
5252
if (rows == 0) {
5353
throw std::runtime_error("WebGPU rms_norm: zero rows");
5454
}
55-
if (rows > 65535u) {
55+
if (rows > utils::queried_max_workgroups(g.device())) {
5656
throw std::runtime_error(
57-
"WebGPU rms_norm: num_rows exceeds the 1D dispatch limit (65535)");
57+
"WebGPU rms_norm: num_rows exceeds the 1D dispatch limit");
5858
}
5959
RmsNormParams p = {};
6060
p.num_rows = rows;
@@ -104,9 +104,9 @@ void rms_norm_impl(WebGPUGraph& graph, const std::vector<int>& args) {
104104
throw std::runtime_error("WebGPU rms_norm: zero rows");
105105
}
106106
// Validate the 1D dispatch limit before allocating any GPU objects.
107-
if (num_rows > 65535u) {
107+
if (num_rows > utils::queried_max_workgroups(device)) {
108108
throw std::runtime_error(
109-
"WebGPU rms_norm: num_rows exceeds the 1D dispatch limit (65535)");
109+
"WebGPU rms_norm: num_rows exceeds the 1D dispatch limit");
110110
}
111111

112112
// Create uniform buffer for params

0 commit comments

Comments
 (0)