Skip to content

[ExecuTorch][WebGPU] Port clamp + hardtanh (clamp-family unary ops)#21156

Merged
meta-codesync[bot] merged 2 commits into
gh/JCNTH/116/basefrom
gh/JCNTH/116/head
Jul 24, 2026
Merged

[ExecuTorch][WebGPU] Port clamp + hardtanh (clamp-family unary ops)#21156
meta-codesync[bot] merged 2 commits into
gh/JCNTH/116/basefrom
gh/JCNTH/116/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Ports the Vulkan delegate's clamp-family activations. clamp and hardtanh share one clamp(x, min, max) shader (mirroring how Vulkan reuses its clamp shader for both), built on the shared unary helper. Bounds come from the op's scalar args, with None -> +/-inf matching Vulkan get_val_or_inf (backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp:72).

Key changes:

  • runtime/ops/unary/clamp.wgsl (+ generated _wgsl.h) — output[idx] = clamp(input[idx], params.minimum, params.maximum); the minimum/maximum member names mirror Vulkan unary_op.glsl.
  • runtime/ops/unary/Activations.cppclamp_impl / hardtanh_impl (args [in, min, max, out]) + get_val_or_inf (reads an Int/Double scalar, substitutes +/-inf for None, throws on any other type).
  • runtime/ops/unary/UnaryOp.cpp — the shared helper now rejects int operands (fail-loud): the fp32-only backend would otherwise reinterpret int bits as f32, and clamp is the one unary the Vulkan partitioner (op_registry.py) tags for integer tensors.

relu6 is excluded: the Vulkan partitioner does not tag it, so it cannot be delegated without a separate partitioner change.
@exported-using-ghexport

Differential Revision: D112257672

Differential Revision: D112257672

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21156

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 New Failures

As of commit c57c0c5 with merge base 4a26c64 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

This was referenced Jul 22, 2026
@JCNTH
JCNTH requested a review from psiddh July 23, 2026 02:10

@psiddh psiddh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving full WebGPU stack

[ghstack-poisoned]
@meta-codesync
meta-codesync Bot merged commit 9feadfe into gh/JCNTH/116/base Jul 24, 2026
182 of 191 checks passed
@meta-codesync
meta-codesync Bot deleted the gh/JCNTH/116/head branch July 24, 2026 07:05
@meta-codesync
meta-codesync Bot temporarily deployed to cherry-pick-bot July 24, 2026 07:05 Inactive
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21156

Ports the Vulkan delegate's clamp-family activations. `clamp` and `hardtanh` share one `clamp(x, min, max)` shader (mirroring how Vulkan reuses its clamp shader for both), built on the shared unary helper. Bounds come from the op's scalar args, with `None -> +/-inf` matching Vulkan `get_val_or_inf` (`backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp:72`).

Key changes:
- `runtime/ops/unary/clamp.wgsl` (+ generated `_wgsl.h`) — `output[idx] = clamp(input[idx], params.minimum, params.maximum)`; the `minimum`/`maximum` member names mirror Vulkan `unary_op.glsl`.
- `runtime/ops/unary/Activations.cpp` — `clamp_impl` / `hardtanh_impl` (args `[in, min, max, out]`) + `get_val_or_inf` (reads an Int/Double scalar, substitutes `+/-inf` for `None`, throws on any other type).
- `runtime/ops/unary/UnaryOp.cpp` — the shared helper now rejects int operands (fail-loud): the fp32-only backend would otherwise reinterpret int bits as f32, and `clamp` is the one unary the Vulkan partitioner (`op_registry.py`) tags for integer tensors.

`relu6` is excluded: the Vulkan partitioner does not tag it, so it cannot be delegated without a separate partitioner change.
ghstack-source-id: 406360830
@exported-using-ghexport

Differential Revision: [D112257672](https://our.internmc.facebook.com/intern/diff/D112257672/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21156

Ports the Vulkan delegate's clamp-family activations. `clamp` and `hardtanh` share one `clamp(x, min, max)` shader (mirroring how Vulkan reuses its clamp shader for both), built on the shared unary helper. Bounds come from the op's scalar args, with `None -> +/-inf` matching Vulkan `get_val_or_inf` (`backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp:72`).

Key changes:
- `runtime/ops/unary/clamp.wgsl` (+ generated `_wgsl.h`) — `output[idx] = clamp(input[idx], params.minimum, params.maximum)`; the `minimum`/`maximum` member names mirror Vulkan `unary_op.glsl`.
- `runtime/ops/unary/Activations.cpp` — `clamp_impl` / `hardtanh_impl` (args `[in, min, max, out]`) + `get_val_or_inf` (reads an Int/Double scalar, substitutes `+/-inf` for `None`, throws on any other type).
- `runtime/ops/unary/UnaryOp.cpp` — the shared helper now rejects int operands (fail-loud): the fp32-only backend would otherwise reinterpret int bits as f32, and `clamp` is the one unary the Vulkan partitioner (`op_registry.py`) tags for integer tensors.

`relu6` is excluded: the Vulkan partitioner does not tag it, so it cannot be delegated without a separate partitioner change.
ghstack-source-id: 406360830
@exported-using-ghexport

Differential Revision: [D112257672](https://our.internmc.facebook.com/intern/diff/D112257672/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21156

Ports the Vulkan delegate's clamp-family activations. `clamp` and `hardtanh` share one `clamp(x, min, max)` shader (mirroring how Vulkan reuses its clamp shader for both), built on the shared unary helper. Bounds come from the op's scalar args, with `None -> +/-inf` matching Vulkan `get_val_or_inf` (`backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp:72`).

Key changes:
- `runtime/ops/unary/clamp.wgsl` (+ generated `_wgsl.h`) — `output[idx] = clamp(input[idx], params.minimum, params.maximum)`; the `minimum`/`maximum` member names mirror Vulkan `unary_op.glsl`.
- `runtime/ops/unary/Activations.cpp` — `clamp_impl` / `hardtanh_impl` (args `[in, min, max, out]`) + `get_val_or_inf` (reads an Int/Double scalar, substitutes `+/-inf` for `None`, throws on any other type).
- `runtime/ops/unary/UnaryOp.cpp` — the shared helper now rejects int operands (fail-loud): the fp32-only backend would otherwise reinterpret int bits as f32, and `clamp` is the one unary the Vulkan partitioner (`op_registry.py`) tags for integer tensors.

`relu6` is excluded: the Vulkan partitioner does not tag it, so it cannot be delegated without a separate partitioner change.
ghstack-source-id: 406360830
@exported-using-ghexport

Differential Revision: [D112257672](https://our.internmc.facebook.com/intern/diff/D112257672/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants