Skip to content

[ExecuTorch][WebGPU] slice_copy Double-arg scalar handling + view_copy/alias glue#20865

Open
JCNTH wants to merge 1 commit into
gh/JCNTH/40/basefrom
gh/JCNTH/40/head
Open

[ExecuTorch][WebGPU] slice_copy Double-arg scalar handling + view_copy/alias glue#20865
JCNTH wants to merge 1 commit into
gh/JCNTH/40/basefrom
gh/JCNTH/40/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 10, 2026

Copy link
Copy Markdown

Stack from ghstack (oldest at bottom):

Hardens slice_copy scalar-arg decoding against edge-dialect Double-serialized indices and adds the view_copy / alias / clone reshape pass-throughs needed for graph glue.

Problem — two graph-glue gaps: (1) the edge dialect sometimes serializes an integer slice index (dim / start / end / step) as a floating-point Double (e.g. a 0 start), which the slice handler rejected as unsupported; (2) contiguous reshape / aliasing ops (view_copy, alias_copy, clone, _clone_dim_order) had no handler, breaking otherwise-delegatable subgraphs.

Solution — Before — a Double-typed slice index threw, and reshape/alias ops had no handler. After — slice_copy scalar reads accept an integral Double (truncating to the int index) and reject only a genuinely fractional one, while SymInt (dynamic start/end) and Null (default) still resolve as before; and view_copy / alias_copy / clone / _clone_dim_order all lower to a single contiguous flat copy (or an in-place no-op when input and output alias the same buffer).

Implementation:

  • read_scalar (dim / step) and read_index (start / end) switch on the value type: Int (INT64_MAX -> default), Double -> truncated int iff it round-trips (static_cast<int64_t>(d) back to d) else throw "non-integral ..." (NaN and out-of-int64-range doubles are rejected before the cast, since casting them is UB), Null -> default; read_index additionally resolves a SymInt via read_symint.
  • The slice kernel is an index gather: out_bufi -> in_bufi by walking per-dim strides, with the sliced dim's input coord = start + coord*step; dynamic start / end / SymInt are handled by a resize hook that recomputes the live out[dim] length (ceiling division) and rewrites the meta/params uniforms plus the dispatch count (mirrors Vulkan resize_slice_copy_node).
  • add_flat_copy (shared by all the reshape/alias ops) type-checks both args are tensors, guards 4-byte alignment and equal nbytes (a view preserves numel, so this also prevents an OOB copy), then either skips the copy when in.buffer == out.buffer (aliased, already in place; CopyBufferToBuffer rejects src == dst) or emits a buffer-to-buffer copy; a resize hook keeps the live output shape and copy byte-count in sync under dynamic shapes.
  • _clone_dim_order ignores its dim_order arg (the AOT pass elides it via shape and dtype).
  • Mirrors Vulkan backends/vulkan/runtime/graph/ops/impl/Slice.cpp (normalize_idx / INT64_MAX default and the ceiling-division length) and backends/vulkan/runtime/graph/ops/impl/View.cpp (the view_buffer no-remap contiguous reshape).

Constraints — fp32 (4-byte-aligned) operands; slice requires step >= 1 and an in-range dim; a fractional Double index is a hard error, not truncated; view / alias / clone require equal input/output numel (contiguous reshape only, no layout remap).

Co-authored-with: Claude Code.

Differential Revision: D110836670

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit f35d269 with merge base aceeb40 (image):

BROKEN TRUNK - The following job 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.

@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 10, 2026
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