Use dynamic CPU count for cmake --build -j in docs and test scripts - #20436
Conversation
🔗 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 SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ You can merge normally! (1 Unrelated Failure)As of commit 3e079a1 with merge base 266e0dc ( 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. |
|
|
This PR needs a
|
|
|
||
| ```bash | ||
| cmake --build cmake-out -j9 --target install --config Release | ||
| cmake --build cmake-out -j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 )) --target install --config Release |
There was a problem hiding this comment.
will this work on a macos?
There was a problem hiding this comment.
Hi @ShamSaleem, could you clarify on this review comment?
There was a problem hiding this comment.
Sorry for the late reply, I was on vacation. But yeah, it should work on macOS. nproc isn't available there by default, so nproc 2>/dev/null fails quietly and it falls back to sysctl -n hw.ncpu, which is the macOS equivalent. The $(( ... + 1 )) is POSIX arithmetic, so it's fine in both bash and zsh.
I don't have a Mac to test on though — if someone can confirm, that'd be great.
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.
b340e88 to
3e079a1
Compare
Summary
Several build docs and
test/scripts hardcode thecmake --build -jparallelism (
-j9,-j10), which assumes a fixed machine. This replacesthem with a portable expression that derives "core count + 1" at runtime —
nprocon Linux,sysctl -n hw.ncpuon macOS:"core count + 1" matches the guidance already documented in
docs/source/using-executorch-building-from-source.md. Thenproc → sysctlfallback keeps the commands working on both Linux and macOS, and the
arithmetic degrades gracefully to
-j1if 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-jflags are intentionally left for follow-ups.Test plan
lintrunnerpasses on all changed files.bash -npasses on the three modified shell scripts.17on a 16-core machine.
cc @GregoryComer @digantdesai @cbilgin @JakeStevens @larryliu0820