Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds (#19671)#19671
Fix sign-compare errors in quantized cpu kernels for Zephyr/GCC builds (#19671)#19671karan1508 wants to merge 1 commit into
Conversation
🔗 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 SEVsThere are 2 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit b5fb2ee with merge base 85bd01d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@karan1508 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105701588. |
This PR needs a
|
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
2ac5836 to
b5fb2ee
Compare
Summary:
Why?
The Zephyr firmware target
tycho_t3c-tsn_graph_simulator_mps3_an547_cmakefailedto compile
xplat/executorch/kernels/quantized/cpu/embeddingxb.cppunder-Werror=sign-compare. The loop variable was declaredsize_t(unsigned) butcompared against
Tensor::dim(), which returnsssize_t(signed). On 64-bithost 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()byswitching
size_ttossize_teverywhere this pattern appears in the quantizedcpu kernels and two test files. This is also the safer pattern — casting to
size_twould turn a negativedim()intoSIZE_MAXand overflow thefixed-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