Skip to content

Use dynamic CPU count for cmake --build -j in docs and test scripts#20436

Open
ShamSaleem wants to merge 1 commit into
pytorch:mainfrom
ShamSaleem:fix-10887-portable-cmake-jobs
Open

Use dynamic CPU count for cmake --build -j in docs and test scripts#20436
ShamSaleem wants to merge 1 commit into
pytorch:mainfrom
ShamSaleem:fix-10887-portable-cmake-jobs

Conversation

@ShamSaleem

Copy link
Copy Markdown

Summary

Several build docs and test/ scripts hardcode the cmake --build -j
parallelism (-j9, -j10), which assumes a fixed machine. This replaces
them with a portable expression that derives "core count + 1" at runtime —
nproc on Linux, sysctl -n hw.ncpu on macOS:

-j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 ))

"core count + 1" matches the guidance already documented in
docs/source/using-executorch-building-from-source.md. The nproc → sysctl
fallback keeps the commands working on both Linux and macOS, and the
arithmetic degrades gracefully to -j1 if neither tool is available.

Partial fix for #10887. Scope is limited to general (non-vendor) docs and
contributor-facing test/ build scripts (9 files). Vendor-backend scripts
(cadence, vulkan, coreml, qualcomm, mediatek, samsung, mps, nxp), CI scripts
under .ci/, and non-cmake -j flags are intentionally left for follow-ups.

Test plan

  • lintrunner passes on all changed files.
  • bash -n passes on the three modified shell scripts.
  • Verified the expression evaluates to a valid integer on Linux, e.g. 17
    on a 16-core machine.

Replace hardcoded -j values (-j9, -j10) in the general build
documentation and the test/ build scripts with a portable expression
that derives "core count + 1" at runtime: nproc on Linux and
sysctl -n hw.ncpu on macOS. This matches the recommendation already
stated in docs/source/using-executorch-building-from-source.md and
avoids machine-specific job counts that don't fit the user's hardware.

Scope is limited to general (non-vendor) docs and contributor-facing
test/ scripts. Vendor-backend scripts, CI scripts under .ci/, and
non-cmake -j flags are intentionally left for a follow-up.

Partially addresses pytorch#10887.
@pytorch-bot

pytorch-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

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

⚠️ 15 Awaiting Approval

As of commit b340e88 with merge base 484f72c (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Jun 22, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: ShamSaleem / name: ShamSaleem (b340e88)

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

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