Skip to content

[ET-VK][ops] Consolidate binary scalar shaders behind op_type - #24777

Merged
SS-JIA merged 1 commit into
gh/SS-JIA/695/origfrom
gh/SS-JIA/696/orig
Nov 7, 2026
Merged

SS-JIA merged 1 commit into
gh/SS-JIA/695/origfrom
gh/SS-JIA/696/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #24756 by @SS-JIA
^ 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/SS-JIA/696/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/696/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/695/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/696/orig
Differential Revision: D130297164
@diff-train-skip-merge

Pull Request resolved: #24756

## Ulterior Motive

Make buffer storage behave more like texture storage, so one shader can service
both storage types. Earlier commits in this stack gave unary and binary
tensor-tensor ops one shader each, selected by an `op_type` specialization
constant. This commit does the same for tensor-scalar ops.

## Rationale

**What**: The tensor-scalar ops (`pow.Tensor_Scalar`, `mul.Scalar`, and `eq`,
`ne`, `lt`, `le`, `gt`, `ge` `.Scalar`) share one arithmetic and one comparison
shader variant family. The op is selected at dispatch through an `op_type`
specialization constant.

**Why**: Each op had its own variant family, which multiplied the number of
compiled shaders by the number of ops for no change in the code each one runs.

## Details

- Shader variants
  - **Before**: one family per op, `{op}_scalar_{storage}_{dtype}_{scalar}`,
    with the op inlined through an `OPERATOR` yaml parameter: 8 ops × 2
    storages × 4 dtype pairs = 64 shaders.
  - **After**: `binary_scalar_op` (`pow`, `mul`) and `binary_scalar_cmp`
    (comparisons, which write uint8): 2 × 2 × 4 = 16 shaders. A host `dev`
    build of `etvk_ops_bench` shrinks by 514 KiB.
- Op selection
  - `apply_binary_scalar_op(op_type, X, Y)` in `binary_scalar.glsl` switches on
    the spec constant, which the compiler folds. Each op computes what its
    `OPERATOR` expression did, in the same promoted type.
  - `op_type` takes `BinaryOpType` values, which gains `kNe`. Only the
    tensor-scalar shader implements `kNe`.
- Dispatch
  - `add_binary_scalar_op_node` takes a `BinaryOpType` instead of an op name
    and picks the comparison family for every op other than `mul` and `pow`.
- `test_vulkan_shader_names.py` checks that every name the tensor-scalar
  dispatch can build is generated.

Authored with Claude Code.
ghstack-source-id: 467556317
@exported-using-ghexport

Differential Revision: [D130297164](https://our.internmc.facebook.com/intern/diff/D130297164/)
@pytorchbot
pytorchbot requested a review from SS-JIA as a code owner November 7, 2026 07:29
@pytorch-bot

pytorch-bot Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 4 New Failures, 2 Unrelated Failures

As of commit 9a1f7cd with merge base 9517b6b (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 Nov 7, 2026
@SS-JIA
SS-JIA added this pull request to stack #24779 November 7, 2026 15:43
@SS-JIA
SS-JIA merged commit a84676e into main Nov 7, 2026
217 of 229 checks passed
@SS-JIA
SS-JIA deleted the gh/SS-JIA/696/orig branch November 7, 2026 15:44

This branch was previously deployed

1 inactive deployment
cadence — 9a1f7cd9 Deployed Nov 7, 2026 by pytorchbot via hifi-op-test / hifi4 #37224
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants