Commit fd16aad
committed
[ExecuTorch][WebGPU] Dynamic resize hooks for add and mul
Pull Request resolved: #20577
**Make the elementwise add and mul ops serve any live shape from one graph.**
**Problem:** `aten.add.Tensor` and `aten.mul.Tensor` baked their element count + param UBO(s) + output shape at `build()` for the max shape. On a dynamic-shape graph at a smaller live shape they would over-dispatch and leave the output sized at the max.
**Solution:**
- Before: one fixed dispatch sized for the build-time shape.
- After: each registers a resize hook on BOTH operands (the dynamic one may be either operand by arg order). The hook recomputes the live element count, rewrites the param UBO(s), updates the dispatch `workgroup_count_x`, and sets the output `cur_dims`. Inert until an operand is resized.
**Implementation:**
- `add`: out follows the larger operand (robust when one input is a static residual and the other is the dynamic-S tensor); rewrites `AddParams`.
- `mul`: recomputes the broadcast output shape and rebuilds all three `TensorMeta` UBOs via `fill_tensor_meta_broadcast`.
- Each keeps its uniform buffer(s) alive via `own_uniform_buffer` instead of releasing at build.
- Mirrors Vulkan per-op `resize_*_node` (recompute sizes + dispatch each execute).
**Constraints:** Behavior-neutral on static graphs (the hook fires only when an operand's live shape differs from the max). No kernel/WGSL/numerics change.
Co-authored-with: Claude Code.
ghstack-source-id: 399812828
@exported-using-ghexport
Differential Revision: [D109906093](https://our.internmc.facebook.com/intern/diff/D109906093/)1 parent ae22389 commit fd16aad
2 files changed
Lines changed: 82 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
162 | 197 | | |
163 | 198 | | |
164 | 199 | | |
165 | 200 | | |
166 | 201 | | |
167 | | - | |
168 | | - | |
| 202 | + | |
| 203 | + | |
169 | 204 | | |
170 | 205 | | |
171 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
167 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
168 | 208 | | |
169 | 209 | | |
170 | 210 | | |
171 | 211 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
176 | 216 | | |
177 | 217 | | |
178 | 218 | | |
| |||
0 commit comments