From 44ac399750546ea31be6a4c5c16ea3e5958163e2 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Sat, 8 Aug 2026 00:05:32 -0700 Subject: [PATCH] Build the custom ops AOT libs as C++20 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. --- extension/llm/custom_ops/CMakeLists.txt | 2 ++ tools/cmake/Codegen.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/extension/llm/custom_ops/CMakeLists.txt b/extension/llm/custom_ops/CMakeLists.txt index 8a43a5ddf5c..a0ba0a2eb42 100644 --- a/extension/llm/custom_ops/CMakeLists.txt +++ b/extension/llm/custom_ops/CMakeLists.txt @@ -130,6 +130,8 @@ if(EXECUTORCH_BUILD_KERNELS_LLM_AOT) ${CMAKE_CURRENT_SOURCE_DIR}/op_tile_crop.cpp ${CMAKE_CURRENT_SOURCE_DIR}/op_tile_crop_aot.cpp ) + # This lib compiles real PyTorch headers, which require C++20. + set_target_properties(custom_ops_aot_lib PROPERTIES CXX_STANDARD 20) target_include_directories( custom_ops_aot_lib PRIVATE "${_common_include_directories}" ) diff --git a/tools/cmake/Codegen.cmake b/tools/cmake/Codegen.cmake index 4253fa44dc5..05d1af9725a 100644 --- a/tools/cmake/Codegen.cmake +++ b/tools/cmake/Codegen.cmake @@ -254,6 +254,8 @@ function(gen_custom_ops_aot_lib) find_package_torch() # This lib uses ATen lib, so we explicitly enable rtti and exceptions. target_compile_options(${GEN_LIB_NAME} PRIVATE -frtti -fexceptions) + # ATen headers require C++20. + set_target_properties(${GEN_LIB_NAME} PROPERTIES CXX_STANDARD 20) target_compile_definitions(${GEN_LIB_NAME} PRIVATE USE_ATEN_LIB=1) include_directories(${TORCH_INCLUDE_DIRS}) target_link_libraries(${GEN_LIB_NAME} PRIVATE torch)