Skip to content

Conversation

@mergennachin
Copy link
Contributor

No description provided.

@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 19, 2025
@github-actions
Copy link

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.

@mergennachin
Copy link
Contributor Author

#15673 (comment)

@meta-codesync
Copy link

meta-codesync bot commented Nov 19, 2025

@mergennachin has imported this pull request. If you are a Meta employee, you can view this in D87451202.

Copilot finished reviewing on behalf of mergennachin November 19, 2025 17:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for bitwise left shift (<<) and right shift (>>) operations to the ExecutorTorch portable kernel library, following the existing pattern for bitwise operations (and, or, xor).

Key Changes:

  • Implementation of bitwise_left_shift and bitwise_right_shift operators with both Tensor and Scalar variants
  • Comprehensive test coverage for both operations including edge cases (zero shift, different data types)
  • Build system integration across Buck (bzl), CMake, and YAML configuration files

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl Adds Buck build targets for the new shift operators (ordering needs correction)
kernels/test/targets.bzl Registers test targets for both shift operations (correctly ordered)
kernels/test/CMakeLists.txt Adds test source files to CMake build (correctly ordered)
kernels/portable/functions.yaml Defines kernel function signatures (should use - op: instead of - func:)
kernels/portable/cpu/pattern/bitwise_op.h Adds shift operation functors and templates (contains redundant code)
kernels/portable/cpu/op_bitwise_left_shift.cpp Implements left shift operation using the bitwise pattern
kernels/portable/cpu/op_bitwise_right_shift.cpp Implements right shift operation using the bitwise pattern
kernels/test/op_bitwise_left_shift_test.cpp Provides comprehensive test coverage for left shift
kernels/test/op_bitwise_right_shift_test.cpp Provides comprehensive test coverage for right shift

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +386 to +395
op_target(
name = "op_bitwise_right_shift",
deps = [
":scalar_utils",
"//executorch/kernels/portable/cpu/pattern:bitwise_op",
"//executorch/kernels/portable/cpu/util:broadcast_util",
"//executorch/kernels/portable/cpu/util:dtype_util",
"//executorch/kernels/portable/cpu/util:elementwise_util",
],
),
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The op_bitwise_right_shift target is placed out of alphabetical order. It should be positioned between op_bitwise_or (line 357) and op_bitwise_xor (line 367) to maintain alphabetical ordering of the op targets.

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +225
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out

- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out

- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out

- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The shift operations should use - op: instead of - func: to be consistent with the other bitwise operations (and, or, xor, not) which are ATen library operations. The - func: syntax is typically reserved for custom operations not in the ATen library.

Change to:

- op: bitwise_left_shift.Tensor_out
  kernels:
    - arg_meta: null
      kernel_name: torch::executor::bitwise_left_shift_Tensor_out
Suggested change
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
- op: bitwise_left_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- op: bitwise_left_shift.Scalar_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- op: bitwise_right_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- op: bitwise_right_shift.Scalar_out

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +225
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out

- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out

- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out

- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The shift operations should use - op: instead of - func: to be consistent with the other bitwise operations (and, or, xor, not) which are ATen library operations. The - func: syntax is typically reserved for custom operations not in the ATen library.

Change to:

- op: bitwise_right_shift.Tensor_out
  kernels:
    - arg_meta: null
      kernel_name: torch::executor::bitwise_right_shift_Tensor_out
Suggested change
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
- op: bitwise_left_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- op: bitwise_left_shift.Scalar_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- op: bitwise_right_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- op: bitwise_right_shift.Scalar_out

Copilot uses AI. Check for mistakes.
Comment on lines +376 to +385
op_target(
name = "op_bitwise_left_shift",
deps = [
":scalar_utils",
"//executorch/kernels/portable/cpu/pattern:bitwise_op",
"//executorch/kernels/portable/cpu/util:broadcast_util",
"//executorch/kernels/portable/cpu/util:dtype_util",
"//executorch/kernels/portable/cpu/util:elementwise_util",
],
),
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The op_bitwise_left_shift target is placed out of alphabetical order. It should be positioned between op_bitwise_and (line 339) and op_bitwise_not (line 349) to maintain alphabetical ordering of the op targets.

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +225
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out

- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out

- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out

- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The shift operations should use - op: instead of - func: to be consistent with the other bitwise operations (and, or, xor, not) which are ATen library operations. The - func: syntax is typically reserved for custom operations not in the ATen library.

Change to:

- op: bitwise_left_shift.Scalar_out
  kernels:
    - arg_meta: null
      kernel_name: torch::executor::bitwise_left_shift_Scalar_out
Suggested change
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
- op: bitwise_left_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- op: bitwise_left_shift.Scalar_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- op: bitwise_right_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- op: bitwise_right_shift.Scalar_out

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +225
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out

- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out

- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out

- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The shift operations should use - op: instead of - func: to be consistent with the other bitwise operations (and, or, xor, not) which are ATen library operations. The - func: syntax is typically reserved for custom operations not in the ATen library.

Change to:

- op: bitwise_right_shift.Scalar_out
  kernels:
    - arg_meta: null
      kernel_name: torch::executor::bitwise_right_shift_Scalar_out
Suggested change
- func: bitwise_left_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- func: bitwise_left_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- func: bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- func: bitwise_right_shift.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
- op: bitwise_left_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Tensor_out
- op: bitwise_left_shift.Scalar_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_left_shift_Scalar_out
- op: bitwise_right_shift.Tensor_out
kernels:
- arg_meta: null
kernel_name: torch::executor::bitwise_right_shift_Tensor_out
- op: bitwise_right_shift.Scalar_out

Copilot uses AI. Check for mistakes.
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 19, 2025

🔗 Helpful Links

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

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

❌ 2 New Failures, 2 Unrelated Failures

As of commit 6861b0a with merge base 6e4e8fa (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.

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