PyTorch -> C++17 (#98209)

This diff locks in C++17 as the minimum standard with which PyTorch can be compiled.

This makes it possible to use all C++17 features in PyTorch.

This breaks backward compatibility in the sense that users with older compilers may find their compilers no longer are sufficient for the job.

Summary: #buildmore

Differential Revision: D44356879

Pull Request resolved: https://github.com/pytorch/pytorch/pull/98209
Approved by: https://github.com/ezyang, https://github.com/malfet, https://github.com/PaliC
This commit is contained in:
Richard Barnes 2023-05-02 19:41:50 +00:00 committed by PyTorch MergeBot
parent 50b0fff060
commit 8f0c825d36
8 changed files with 15 additions and 15 deletions

View File

@ -1 +1 @@
7dd29931fa8e9bb7c970f05f8c0dc13b69e17494
1a88dde37444c0dc99c58b35c7f0f9ba1f82e684

View File

@ -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:

View File

@ -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 <ATen/Context.h>

View File

@ -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)

View File

@ -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})

View File

@ -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))

View File

@ -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.

View File

@ -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 <torch/autograd.h>