Skip to content

Build operator lookup names without snprintf - #24217

Merged
rascani merged 6 commits into
mainfrom
gh/rascani/49/head
Oct 28, 2026
Merged

rascani merged 6 commits into
mainfrom
gh/rascani/49/head

Conversation

@rascani

@rascani rascani commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Operator lookup uses snprintf to join the operator name and optional overload. Replace it with checked string copies so builds with no other printf users can discard the formatter. The lookup format and error behavior are preserved, including empty overloads and embedded NULs. A named uint64_t needed_size makes the capacity check explicit and keeps the addition safe on 32-bit targets.

With minimal PAL and GNU nano libraries, the measurements below show a reduction of 1,736 bytes for the GNU runtime and 10,224 bytes for Zephyr. Set the runtime size limits to 35,000 bytes for GNU and 50,000 bytes for Zephyr, leaving roughly 8–9% headroom above the measured CI sizes for small runtime changes.

Test plan

Cross-compiled both size targets before and after the helper change on base 0549e1ee61, with the same configuration on both sides: Cortex-M55, C++17, Release, size optimization, logging disabled, and minimal PAL; GNU Arm 15.2.Rel1 with nano.specs and Zephyr SDK 1.0.1 (GCC 14.3.0). Stripped ELF file sizes in bytes:

Configuration Binary Before After Saved
GNU bare-metal size_test 33,372 31,636 1,736
GNU bare-metal size_test_all_ops 1,156,180 1,154,444 1,736
Zephyr size_test 55,800 45,576 10,224
Zephyr size_test_all_ops 1,154,512 1,144,296 10,216

None of the four binaries retains printf-family symbols after the change. Both existing kernel-resolution tests pass. An ad hoc differential harness passed 1,237,804 cases against the original helper, including missing and empty strings, embedded NULs, and buffer boundaries; guard pages detect output overruns. The helper implementation has not changed since those checks. Workflow YAML parsing and embedded shell syntax pass. The updated limits pass against the CI measurements from 320adcd3bf: 32,180 bytes for GNU and 46,112 bytes for Zephyr, leaving 2,820 and 3,888 bytes of headroom respectively.

Authored with AI assistance using Codex.

[ghstack-poisoned]
[ghstack-poisoned]
@rascani

rascani commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Stack from ghstack (oldest at bottom):

@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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 74ccc1d with merge base 149bba5 (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.

@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 Oct 27, 2026
[ghstack-poisoned]
[ghstack-poisoned]
rascani added a commit that referenced this pull request Oct 27, 2026
### Summary

Operator lookup uses `snprintf` to join the operator name and optional overload. Replace it with checked string copies so builds with no other printf users can discard the formatter. The lookup format and error behavior are preserved, including empty overloads and embedded NULs. A named `uint64_t needed_size` makes the capacity check explicit and keeps the addition safe on 32-bit targets.

With the preceding minimal-PAL configuration and GNU nano libraries, this removes 1,736 bytes from the GNU runtime and 10,224 bytes from Zephyr. Lower their runtime size limits from 34,000 to 32,000 bytes and from 57,000 to 47,000 bytes respectively.

### Test plan

Cross-compiled both size targets before and after the helper change on base `0549e1ee61`, with the same configuration on both sides: Cortex-M55, C++17, Release, size optimization, logging disabled, and minimal PAL; GNU Arm 15.2.Rel1 with nano.specs and Zephyr SDK 1.0.1 (GCC 14.3.0). Stripped ELF file sizes in bytes:

| Configuration | Binary | Before | After | Saved |
|---|---|---:|---:|---:|
| GNU bare-metal | `size_test` | 33,372 | 31,636 | 1,736 |
| GNU bare-metal | `size_test_all_ops` | 1,156,180 | 1,154,444 | 1,736 |
| Zephyr | `size_test` | 55,800 | 45,576 | 10,224 |
| Zephyr | `size_test_all_ops` | 1,154,512 | 1,144,296 | 10,216 |

None of the four binaries retains printf-family symbols after the change. Both existing kernel-resolution tests pass. An ad hoc differential harness passed 1,237,804 cases against the original helper, including missing and empty strings, embedded NULs, and buffer boundaries; guard pages detect output overruns. The helper implementation has not changed since those checks. Formatting, workflow YAML parsing, embedded shell syntax, and both size limits pass.

Authored with AI assistance using Codex.

ghstack-source-id: 10178e0
ghstack-comment-id: 6455173898
Pull-Request: #24217
Base automatically changed from gh/rascani/48/head to main October 28, 2026 15:06
@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.

[ghstack-poisoned]
rascani added a commit that referenced this pull request Oct 28, 2026
### Summary

Operator lookup uses `snprintf` to join the operator name and optional overload. Replace it with checked string copies so builds with no other printf users can discard the formatter. The lookup format and error behavior are preserved, including empty overloads and embedded NULs. A named `uint64_t needed_size` makes the capacity check explicit and keeps the addition safe on 32-bit targets.

With minimal PAL and GNU nano libraries, the measurements below show a reduction of 1,736 bytes for the GNU runtime and 10,224 bytes for Zephyr. Set the runtime size limits to 35,000 bytes for GNU and 50,000 bytes for Zephyr, leaving roughly 8–9% headroom above the measured CI sizes for small runtime changes.

### Test plan

Cross-compiled both size targets before and after the helper change on base `0549e1ee61`, with the same configuration on both sides: Cortex-M55, C++17, Release, size optimization, logging disabled, and minimal PAL; GNU Arm 15.2.Rel1 with nano.specs and Zephyr SDK 1.0.1 (GCC 14.3.0). Stripped ELF file sizes in bytes:

| Configuration | Binary | Before | After | Saved |
|---|---|---:|---:|---:|
| GNU bare-metal | `size_test` | 33,372 | 31,636 | 1,736 |
| GNU bare-metal | `size_test_all_ops` | 1,156,180 | 1,154,444 | 1,736 |
| Zephyr | `size_test` | 55,800 | 45,576 | 10,224 |
| Zephyr | `size_test_all_ops` | 1,154,512 | 1,144,296 | 10,216 |

None of the four binaries retains printf-family symbols after the change. Both existing kernel-resolution tests pass. An ad hoc differential harness passed 1,237,804 cases against the original helper, including missing and empty strings, embedded NULs, and buffer boundaries; guard pages detect output overruns. The helper implementation has not changed since those checks. Workflow YAML parsing and embedded shell syntax pass. The updated limits pass against the CI measurements from `320adcd3bf`: 32,180 bytes for GNU and 46,112 bytes for Zephyr, leaving 2,820 and 3,888 bytes of headroom respectively.

Authored with AI assistance using Codex.

ghstack-source-id: 4ee6121
ghstack-comment-id: 6455173898
Pull-Request: #24217
@rascani
rascani merged commit 4e439f6 into main Oct 28, 2026
232 of 233 checks passed
@rascani
rascani deleted the gh/rascani/49/head branch October 28, 2026 17:21

This branch was previously deployed

1 inactive deployment
cadence — 74ccc1d9 Deployed Oct 28, 2026 by rascani via hifi-op-test / hifi4 #35069
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