From bcb4444cecc6bad23cc4dfd40eb79f0b66310293 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Fri, 19 May 2023 00:49:08 +0000 Subject: [PATCH] PyTorch -> C++17 (#98209) (#100557) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 🤖 Generated by Copilot at 4f0b524 This pull request updates the codebase and the documentation to use C++17 instead of C++14 as the minimum required C++ standard. This affects the `ATen`, `c10`, and `torch` libraries and their dependencies, as well as the CI system and the `conda` package metadata. Pull Request resolved: https://github.com/pytorch/pytorch/pull/100557 Approved by: https://github.com/malfet --- aten/conda/meta.yaml | 2 +- aten/src/ATen/ATen.h | 4 ++-- aten/src/ATen/cpu/tbb/CMakeLists.txt | 6 +++--- aten/src/ATen/test/test_install/CMakeLists.txt | 4 ++-- c10/util/C++17.h | 6 +++--- caffe2/contrib/aten/README.md | 2 +- torch/csrc/api/include/torch/all.h | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/aten/conda/meta.yaml b/aten/conda/meta.yaml index a502690a5447..446c07aa572f 100644 --- a/aten/conda/meta.yaml +++ b/aten/conda/meta.yaml @@ -26,7 +26,7 @@ requirements: about: home: https://github.com/pytorch/pytorch license: BSD - summary: A TENsor library for C++14 + summary: A TENsor library for C++17 extra: recipe-maintainers: diff --git a/aten/src/ATen/ATen.h b/aten/src/ATen/ATen.h index 4a5a949f0dd7..effdd469d19b 100644 --- a/aten/src/ATen/ATen.h +++ b/aten/src/ATen/ATen.h @@ -1,7 +1,7 @@ #pragma once -#if !defined(_MSC_VER) && __cplusplus < 201402L -#error C++14 or later compatible compiler is required to use ATen. +#if !defined(_MSC_VER) && __cplusplus < 201703L +#error C++17 or later compatible compiler is required to use ATen. #endif #include diff --git a/aten/src/ATen/cpu/tbb/CMakeLists.txt b/aten/src/ATen/cpu/tbb/CMakeLists.txt index f769c7b3a0ec..6e946d5d13d5 100644 --- a/aten/src/ATen/cpu/tbb/CMakeLists.txt +++ b/aten/src/ATen/cpu/tbb/CMakeLists.txt @@ -121,9 +121,9 @@ endif() if(UNIX) add_definitions(-DUSE_PTHREAD) - check_cxx_compiler_flag("-std=c++14" SUPPORTS_STDCXX14) - if(SUPPORTS_STDCXX14) - set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}") + check_cxx_compiler_flag("-std=c++17" SUPPORTS_STDCXX17) + if(SUPPORTS_STDCXX17) + set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}") endif() check_cxx_compiler_flag("-mrtm -Werror" SUPPORTS_MRTM) diff --git a/aten/src/ATen/test/test_install/CMakeLists.txt b/aten/src/ATen/test/test_install/CMakeLists.txt index 2add3bffa23a..50e2ce80ba7c 100644 --- a/aten/src/ATen/test/test_install/CMakeLists.txt +++ b/aten/src/ATen/test/test_install/CMakeLists.txt @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0) find_package(ATen REQUIRED) include_directories(${ATEN_INCLUDE_DIR}) -# C++14 +# C++17 if(not MSVC) - set(CMAKE_CXX_FLAGS "--std=c++14 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "--std=c++17 ${CMAKE_CXX_FLAGS}") endif() add_executable(main main.cpp) target_link_libraries(main ${ATEN_LIBRARIES}) diff --git a/c10/util/C++17.h b/c10/util/C++17.h index 09259ab840be..48a7b84710ef 100644 --- a/c10/util/C++17.h +++ b/c10/util/C++17.h @@ -22,9 +22,9 @@ "You're trying to build PyTorch with a too old version of Clang. We need Clang 4 or later." #endif -#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201402L)) || \ - (!defined(_MSC_VER) && __cplusplus < 201402L) -#error You need C++14 to compile PyTorch +#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ + (!defined(_MSC_VER) && __cplusplus < 201703L) +#error You need C++17 to compile PyTorch #endif #if defined(_WIN32) && (defined(min) || defined(max)) diff --git a/caffe2/contrib/aten/README.md b/caffe2/contrib/aten/README.md index 79a4276a65f8..df8901ae318a 100644 --- a/caffe2/contrib/aten/README.md +++ b/caffe2/contrib/aten/README.md @@ -1,7 +1,7 @@ # An ATen operator for Caffe2 ATen is a simple tensor library thats exposes the Tensor operations in Torch -and PyTorch directly in C++14. This library provides a generated wrapper around the ATen API +and PyTorch directly in C++17. This library provides a generated wrapper around the ATen API that makes these functions available in Caffe2 as an operator. It also makes it accessible using the ToffeeIR. diff --git a/torch/csrc/api/include/torch/all.h b/torch/csrc/api/include/torch/all.h index 21adf64a5709..0d2eca31889c 100644 --- a/torch/csrc/api/include/torch/all.h +++ b/torch/csrc/api/include/torch/all.h @@ -1,7 +1,7 @@ #pragma once -#if !defined(_MSC_VER) && __cplusplus < 201402L -#error C++14 or later compatible compiler is required to use PyTorch. +#if !defined(_MSC_VER) && __cplusplus < 201703L +#error C++17 or later compatible compiler is required to use PyTorch. #endif #include