Repository navigation
Set the C++ standard on the exported CMake target. - #190784
AnthonyBarbier wants to merge 10 commits into
Conversation
This is needed so that downstream targets inherits the c++20 requirement. Without it it fails with for example:
pytorch/torch/include/ATen/core/TensorBase.h:1041:5: note: ‘requires’ only available with ‘-std=c++20’ or ‘-fconcepts’
pytorch/torch/include/ATen/core/TensorBase.h:1044:5: error: ‘requires’ does not name a type
1044 | requires std::is_same_v<T, int64_t>
| ^~~~~~~~
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190784
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit dd2239b with merge base b4bd4b7 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Pull request overview
This PR updates the exported CMake package config so downstream projects that consume find_package(Torch) inherit PyTorch’s C++20 requirement via target usage requirements.
Changes:
- Adds
target_compile_features(torch INTERFACE cxx_std_20)to the exportedtorchCMake target to propagate the C++20 requirement to dependents.
…E ...), since that is also not ideal for older CMake/imported targets. It now uses the older set_property(TARGET torch APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ...) form.
|
@Skylion007 Could you please have another look at this PR? |
|
@claude review this PR |
|
Claude finished @Skylion007's task in 21m 6s —— View job Reviewed — the core change (propagating C++20 via the imported target's Full review of #190784PR Review: #190784SummaryMakes the exported Answering the open question in this thread (@Skylion007's "what is our actual minimum CMake?")The repo minimum (
So the guard is genuinely needed, and Copilot's "3.10" is the right floor to design against, not an out-of-date example. Worth noting the guard is implicitly self-consistent: Code Quality
API Design
Two behaviours are also conflated in one branch: "CMake is too old to know
Consumers compiling TestingNo test exercises the new propagation. Every libtorch consumer built in CI pins the standard itself, so all of them would keep passing if this propagation were reverted or silently broken:
Backward CompatibilityThe Separately: adding a hard C++20 usage requirement will now break consumers who deliberately compile at a lower standard against libtorch headers that happen to work for them. That breakage is intentional and correct (those builds are already UB-adjacent), but it is a behaviour change for anyone currently relying on RecommendationRequest Changes Blocking: no test exercises the propagation (all CI consumers self-pin), and the fallback silently downgrades a C++23 consumer to C++20 instead of expressing a minimum. Also please drop the dead |
|
@claude review this again, are the prior issues fixed? |
|
Claude finished @AnthonyBarbier's task in 11m 39s —— View job Re-reviewed: all four blocking items from my previous pass are addressed, and I verified in the CI log that Re-review of #190784 — status of prior issuesChecklist
Prior issues: status
Verification of the new test coverage
I confirmed it works rather than assuming it, by reading the
The Remaining gaps (non-blocking, but worth a line in the PR description)1. 2. Static libtorch consumers get nothing. The propagation only reaches consumers who link the 3. Also worth doing separately
RecommendationPrior blocking issues resolved. The mechanism is right, the fallback is now observable and toolchain-correct, and there is real CI coverage that a revert would break. Nothing left that I'd block on — I'd just ask you to note the CUDA and static-libtorch scope limits in the PR description so the next person hitting either doesn't file it as a regression. |
|
@Skylion007 All the comments should now have been addressed. |
|
@claude review |
|
Claude finished @Skylion007's task in 10m 22s —— View job Re-reviewed the current branch state: the mechanism is right and the prior blocking items stay fixed, but the fallback Review of #190784PR Review: #190784SummaryMakes the exported Code Quality
Since you are already emitting a InfrastructureDownstream CUDA consumers now get an unset CUDA standard — this is sharper than it was before the PR. if("X${CMAKE_CUDA_STANDARD}" STREQUAL "X" )
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
endif()
set(CMAKE_CUDA_STANDARD_REQUIRED ON)It derives the CUDA standard from the consumer's Both the API Design
TestingThe For the propagation path itself the new coverage is real: Backward Compatibility
RecommendationApprove The prior blocking items remain resolved and CI is green (4/4 runs, 0 failures). Nothing here blocks merge, but I'd ask for the two cheap changes before landing: reword the fallback diagnostic at |
TorchConfig hardcoded C++20 even though the standard used to configure PyTorch can be overridden. Substitute the build-time CMAKE_CXX_STANDARD in the exported compile feature, diagnostic, and compatibility flags so the package consistently propagates the configured requirement. Test Plan: ``` spin quicklint lintrunner -a cmake -P agent_space/check_torch_config_standard.cmake git diff --check ``` Authored with assistance from Codex, an AI coding assistant.
CMAKE_CXX_COMPILE_FEATURES depends on both CMake's feature vocabulary and the detected compiler's capabilities. Describe both reasons that the configured standard may be absent and warn that forcing the standard flag will fail when the compiler is too old. Test Plan: ``` spin quicklint lintrunner -a git diff --check ``` Authored with assistance from Codex, an AI coding assistant.
The FAQ forced consumers to C++17, which conflicts with Torch's C++20 header requirements, while the installation guide redundantly forced C++20. Remove both overrides now that the exported Torch target propagates its configured minimum standard. Test Plan: ``` spin quicklint lintrunner -a git diff --check ``` Authored with assistance from Codex, an AI coding assistant.
|
@claude review this again, are the prior issues fixed? |
|
Claude finished @AnthonyBarbier's task in 5m 10s —— View job Re-reviewed: all four items I flagged last round are fixed, and the new Re-review of #190784 — status of prior issuesChecklist
Prior issues: status
Answering @Skylion007's review comment: "instead of hard coding can we set it to whatever torch is currently set to?"Yes, and that is what
To your parenthetical ("or that doesn't work because these are out-of-tree usages?") — the distinction that matters is when the value is captured. Reading the consumer's CMake cache would not work, since it is a different cache; but capturing PyTorch's value at its configure time and freezing it into the generated One edge case, non-blocking: if New observations from this diff
To be precise about severity — and to correct an overstatement in my earlier reviews: on the On documenting rather than fixing the CUDA gap — I think that is the right call, and here is the reason it is safe. Fallback still has no CI coverage on any path (every CI consumer runs a CMake and compiler where
CIThe regression test is intact: RecommendationApprove — all prior blocking items are resolved and the hardcoding question is answered properly. The only thing I would still ask for in this PR is deleting |
|
@claude review this again, are the prior issues fixed? |
|
Claude finished @AnthonyBarbier's task in 2m 33s —— View job Re-reviewed: the one item I asked for last round is done, and the whole Re-review of #190784 — status of prior issuesChecklist
Prior issues: status
I also swept for any remaining doc/test example that pins a standard while consuming One nit introduced by
|
|
@Skylion007 Should be all good now I think? |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.0-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8) Details for Dev Infra teamRaised by workflow job |
|
@claude identify merge failure. Is it related to this PR? |
|
Claude finished @AnthonyBarbier's task in 2m 9s —— View job Merge failure: unrelated to this PR
Short answer: no, it is not related. The merge was blocked by a stale Analysis of the merge failureThe failing check
Every other benchmark in the job passed, and the job reported Why this is a "WIN", not a regression
The margin is as thin as it gets: Why it cannot be caused by this PRThis PR touches four files, and none of them are on any code path the benchmark executes:
What actually happened
and That also explains the timing: this same PR's Suggested next stepTwo options, both cheap:
I would not add the CSV update to this PR: |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 0 checks: Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
This is needed so that downstream targets inherits the c++20 requirement.
This change propagates the required standard only to CXX translation units; downstream consumers compiling CUDA sources must explicitly set CMAKE_CUDA_STANDARD (for example, to 20), because the Torch target does not propagate a CUDA standard.
Without it, downstream C++ code fails with for example:
```
pytorch/torch/include/ATen/core/TensorBase.h:1041:5: note: ‘requires’ only available with ‘-std=c++20’ or ‘-fconcepts’ pytorch/torch/include/ATen/core/TensorBase.h:1044:5: error: ‘requires’ does not name a type
1044 | requires std::is_same_v<T, int64_t>
| ^~~~~~~~
```
Pull Request resolved: pytorch#190784
Approved by: https://github.com/Skylion007
This is needed so that downstream targets inherits the c++20 requirement.
This change propagates the required standard only to CXX translation units; downstream consumers compiling CUDA sources must explicitly set CMAKE_CUDA_STANDARD (for example, to 20), because the Torch target does not propagate a CUDA standard.
Without it, downstream C++ code fails with for example: