Skip to content

Build the custom ops AOT libs as C++20 - #21689

Open
shoumikhin wants to merge 1 commit into
mainfrom
cxx20-custom-ops-aot
Open

Build the custom ops AOT libs as C++20#21689
shoumikhin wants to merge 1 commit into
mainfrom
cxx20-custom-ops-aot

Conversation

@shoumikhin

Copy link
Copy Markdown
Contributor

Summary

A few ExecuTorch build targets compile real PyTorch headers, instead of the small copy of c10 that ships inside this repo. ATen (the PyTorch tensor library) now needs C++20, so every one of those targets has to ask for C++20 explicitly.

Most already do: util, portable_lib, _training_lib, and the LLM runner all set CXX_STANDARD 20. Two were missed:

  • custom_ops_aot_lib in extension/llm/custom_ops/CMakeLists.txt. It compiles op_sdpa_aot.cpp, which includes <torch/library.h>.
  • The library built by gen_custom_ops_aot_lib in tools/cmake/Codegen.cmake. It compiles the generated RegisterSchema.cpp, which includes the same header.

Both still build at C++17 against the currently pinned PyTorch, so nothing is broken today. The problem shows up when building against a newer PyTorch, where the compile fails inside c10/util/intrusive_ptr.h, which uses std::strong_ordering, a C++20 feature:

c10/util/intrusive_ptr.h:775:8: error: 'strong_ordering' is not a member of 'std'

The fix is two lines, in the same form the other targets already use:

set_target_properties(custom_ops_aot_lib PROPERTIES CXX_STANDARD 20)

Test plan

Configured on Linux x86_64 with EXECUTORCH_BUILD_KERNELS_LLM_AOT=ON and EXECUTORCH_BUILD_KERNELS_QUANTIZED=ON, then compared the compile flags in compile_commands.json before and after the change:

target                     before     after
custom_ops                 gnu++17    gnu++17
custom_ops_aot_lib         gnu++17    gnu++20   <== changed
quantized_ops_aot_lib      gnu++17    gnu++20   <== changed
quantized_ops_lib          gnu++17    gnu++17
portable_lib               gnu++20    gnu++20
util                       gnu++20    gnu++20

Exactly the two intended targets change, and no other target is affected.

Also compiled every source file shared by these targets under C++20 to confirm none of them relies on C++17-only behavior (7 files, all pass).

ATen requires C++20, so every target that compiles a real PyTorch header
needs to opt in. Most already do, but the two custom ops AOT libs were
missed: custom_ops_aot_lib compiles torch/library.h through
op_sdpa_aot.cpp, and the lib built by gen_custom_ops_aot_lib compiles the
generated RegisterSchema.cpp, which includes the same header.

Both still build at C++17 against the pinned PyTorch, so this is only
visible when building against a newer PyTorch, where they fail on
std::strong_ordering in c10/util/intrusive_ptr.h.
Copilot AI lite review requested due to automatic review settings August 8, 2026 12:27
@pytorch-bot

pytorch-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 3 Unrelated Failures

As of commit 44ac399 with merge base 48741ac (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs 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 Aug 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Aug 8, 2026

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