Simplify handling of max jobs in CMake builds (#145820)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/145820
Approved by: https://github.com/malfet
This commit is contained in:
cyy
2025-01-31 00:55:35 +00:00
committed by PyTorch MergeBot
parent c70362fac8
commit d94d816d96
2 changed files with 4 additions and 13 deletions

View File

@ -377,15 +377,6 @@ class CMake:
# os.sched_getaffinity(0) on platforms that support it.
max_jobs = max_jobs or str(multiprocessing.cpu_count())
# This ``if-else'' clause would be unnecessary when cmake
# 3.12 becomes minimum, which provides a '-j' option:
# build_args += ['-j', max_jobs] would be sufficient by
# then. Until then, we use "--" to pass parameters to the
# underlying build system.
build_args += ["--"]
if IS_WINDOWS and not USE_NINJA:
# We are likely using msbuild here
build_args += [f"/p:CL_MPCount={max_jobs}"]
else:
build_args += ["-j", max_jobs]
# CMake 3.12 provides a '-j' option.
build_args += ["-j", max_jobs]
self.run(build_args, my_env)

View File

@ -30,8 +30,8 @@ class TestCMake(unittest.TestCase):
((None, False, False), ["-j", "13"]), # noqa: E201,E241
(("6", True, True), ["-j", "6"]), # noqa: E201,E241
((None, True, True), None), # noqa: E201,E241
(("11", False, True), ["/p:CL_MPCount=11"]), # noqa: E201,E241
((None, False, True), ["/p:CL_MPCount=13"]), # noqa: E201,E241
(("11", False, True), ["-j", "11"]), # noqa: E201,E241
((None, False, True), ["-j", "13"]), # noqa: E201,E241
]
for (max_jobs, use_ninja, is_windows), want in cases:
with self.subTest(