Skip to content

Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds (#19671)#19671

Open
karan1508 wants to merge 1 commit into
pytorch:mainfrom
karan1508:export-D105701588
Open

Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds (#19671)#19671
karan1508 wants to merge 1 commit into
pytorch:mainfrom
karan1508:export-D105701588

Conversation

@karan1508

@karan1508 karan1508 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary:

Why?

The Zephyr firmware target tycho_t3c-tsn_graph_simulator_mps3_an547_cmake failed
to compile xplat/executorch/kernels/quantized/cpu/embeddingxb.cpp under
-Werror=sign-compare. The loop variable was declared size_t (unsigned) but
compared against Tensor::dim(), which returns ssize_t (signed). On 64-bit
host toolchains the warning is often suppressed or both types match in width, so
the regression slipped in via D90402567 (int32 indices support). On the 32-bit
Zephyr ARM target the mismatch is fatal. Several sibling kernels in the same
directory have the identical latent pattern and would break the moment they get
pulled into a Zephyr build path.

What?

Match the loop variable's type to the signed return type of Tensor::dim() by
switching size_t to ssize_t everywhere this pattern appears in the quantized
cpu kernels and two test files. This is also the safer pattern — casting to
size_t would turn a negative dim() into SIZE_MAX and overflow the
fixed-size stack buffer used for sizes. The change is mirrored across the
xplat and fbcode copies so the diff_train sync stays consistent.

Differential Revision: D105701588

@karan1508 karan1508 requested a review from manuelcandales as a code owner May 19, 2026 15:35
@pytorch-bot

pytorch-bot Bot commented May 19, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit b5fb2ee with merge base 85bd01d (image):
💚 Looks good so far! There are no failures yet. 💚

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 May 19, 2026
@meta-codesync

meta-codesync Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

@karan1508 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105701588.

@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.

pytorch#19671)

Summary:

## Why?
The Zephyr firmware target `tycho_t3c-tsn_graph_simulator_mps3_an547_cmake` failed
to compile `xplat/executorch/kernels/quantized/cpu/embeddingxb.cpp` under
`-Werror=sign-compare`. The loop variable was declared `size_t` (unsigned) but
compared against `Tensor::dim()`, which returns `ssize_t` (signed). On 64-bit
host toolchains the warning is often suppressed or both types match in width, so
the regression slipped in via D90402567 (int32 indices support). On the 32-bit
Zephyr ARM target the mismatch is fatal. Several sibling kernels in the same
directory have the identical latent pattern and would break the moment they get
pulled into a Zephyr build path.

## What?
Match the loop variable's type to the signed return type of `Tensor::dim()` by
switching `size_t` to `ssize_t` everywhere this pattern appears in the quantized
cpu kernels and two test files. This is also the safer pattern — casting to
`size_t` would turn a negative `dim()` into `SIZE_MAX` and overflow the
fixed-size stack buffer used for sizes. The change is mirrored across the
xplat and fbcode copies so the diff_train sync stays consistent.

Differential Revision: D105701588
@meta-codesync meta-codesync Bot changed the title Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds (#19671) May 19, 2026
@karan1508 karan1508 force-pushed the export-D105701588 branch from 2ac5836 to b5fb2ee Compare May 19, 2026 15:37
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. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant