[CPP] Update GCC minversion check to 9 or newer (#120126)

It's already a requirement for building PyTorch, but should be a
requirement for linking extensions with it, as that can lead to runtime
crashes, as `std::optional` template layout is incompatible between
gcc-9 and older compilers.

Also, update minimum supported clang version to 9.x(used to build Android), as clang-5 is clearly not C++17 compliant.

Fixes https://github.com/pytorch/pytorch/issues/120020

Pull Request resolved: https://github.com/pytorch/pytorch/pull/120126
Approved by: https://github.com/Skylion007
This commit is contained in:
Nikita Shulga 2024-02-19 22:04:56 +00:00 committed by PyTorch MergeBot
parent 48bdd0fb47
commit 3ad067fe2b
2 changed files with 12 additions and 1 deletions

View File

@ -158,7 +158,7 @@ They require JetPack 4.2 and above, and [@dusty-nv](https://github.com/dusty-nv)
#### Prerequisites #### Prerequisites
If you are installing from source, you will need: If you are installing from source, you will need:
- Python 3.8 or later (for Linux, Python 3.8.1+ is needed) - Python 3.8 or later (for Linux, Python 3.8.1+ is needed)
- A compiler that fully supports C++17, such as clang or gcc (especially for aarch64, gcc 9.4.0 or newer is required) - A compiler that fully supports C++17, such as clang or gcc (gcc 9.4.0 or newer is required)
We highly recommend installing an [Anaconda](https://www.anaconda.com/download) environment. You will get a high-quality BLAS library (MKL) and you get controlled dependency versions regardless of your Linux distro. We highly recommend installing an [Anaconda](https://www.anaconda.com/download) environment. You will get a high-quality BLAS library (MKL) and you get controlled dependency versions regardless of your Linux distro.

View File

@ -8,6 +8,17 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \
__GNUC__ < 9
#error \
"You're trying to build PyTorch with a too old version of GCC. We need GCC 9 or later."
#endif
#if defined(__clang__) && __clang_major__ < 9
#error \
"You're trying to build PyTorch with a too old version of Clang. We need Clang 9 or later."
#endif
#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ #if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \
(!defined(_MSC_VER) && __cplusplus < 201703L) (!defined(_MSC_VER) && __cplusplus < 201703L)
#error You need C++17 to compile PyTorch #error You need C++17 to compile PyTorch