[Cmake] Check that gcc-9.4 or newer is used (#112858)

As this is the oldest gcc that is fully compatible with C++17 standard.
- Replace number of conditional version with simpler `if(CMAKE_COMPILER_IS_GNUCXX)` or `append_cxx_flag_if_supported`.
- As `-Wsuggest-override` condition was hidden before incorrect guard, add missing `override` keywords to `torch::autograd::PyFunctionTensorPostAccGradHooks::apply_with_saved` , `caffe2::python::TensorFeeder::Feed` and `cafee2::NetObserverReporterPrint::report```

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

Pull Request resolved: https://github.com/pytorch/pytorch/pull/112858
Approved by: https://github.com/Skylion007, https://github.com/albanD
This commit is contained in:
Nikita Shulga 2023-11-06 17:19:53 +00:00 committed by PyTorch MergeBot
parent 77d5f0379e
commit 88920b26be
9 changed files with 16 additions and 34 deletions

View File

@ -43,7 +43,12 @@ set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard whose features are reques
# ---[ Utils
include(cmake/public/utils.cmake)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# --- [ Check that minimal gcc version is 9.4+
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.4)
message(FATAL "GCC-9.4 or newer is required to compile PyTorch, but found ${CMAKE_CXX_COMPILER_VERSION}")
endif()
if(LINUX)
include(cmake/CheckAbi.cmake)
string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
string(APPEND CMAKE_CUDA_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
@ -822,7 +827,7 @@ endif()
include(cmake/Allowlist.cmake)
# ---[ Set link flag, handle additional deps for gcc 4.8 and above
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8.0 AND NOT ANDROID)
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
message(STATUS "GCC ${CMAKE_CXX_COMPILER_VERSION}: Adding gcc and gcc_s libs to link line")
list(APPEND Caffe2_DEPENDENCY_LIBS gcc_s gcc)
endif()
@ -851,26 +856,19 @@ if(NOT MSVC)
append_cxx_flag_if_supported("-Wno-unused-result" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-strict-overflow" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-stringop-overflow" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wvla-extension" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wsuggest-override" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wnewline-eof" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Winconsistent-missing-override" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Winconsistent-missing-destructor-override" CMAKE_CXX_FLAGS)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
string(APPEND CMAKE_CXX_FLAGS " -Wno-pass-failed")
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))
string(APPEND CMAKE_CXX_FLAGS " -Wno-stringop-overflow")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
# Suppress "The ABI for passing parameters with 64-byte alignment has changed in GCC 4.6"
string(APPEND CMAKE_CXX_FLAGS " -Wno-psabi")
endif()
if(NOT CMAKE_COMPILER_IS_GNUCXX OR GCC_VERSION VERSION_GREATER_EQUAL 9.2)
# Prior to GCC 9.2, this warning misfires when a method is
# labeled "final".
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
append_cxx_flag_if_supported("-Wsuggest-override" CMAKE_CXX_FLAGS)
endif()
# Use ld.gold if available, fall back to ld.bfd (the default ld) if not
if(USE_GOLD_LINKER)

View File

@ -533,7 +533,7 @@ if(NOT MSVC)
set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS -Wno-noexcept-type)
endif()
# Disable certain warnings for GCC-9.X
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
if(CMAKE_COMPILER_IS_GNUCXX)
# See https://github.com/pytorch/pytorch/issues/38856
set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS "-Wno-redundant-move -Wno-noexcept-type")
set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_codegen.cpp PROPERTIES COMPILE_FLAGS "-Wno-init-list-lifetime")

View File

@ -257,7 +257,7 @@ class TensorFeeder : public BlobFeederBase {
const DeviceOption& option,
PyArrayObject* original_array,
Blob* blob,
bool in_place) {
bool in_place) override {
if (in_place) {
FeedTensor(
option,

View File

@ -325,7 +325,7 @@ if(INTERN_BUILD_ATEN_OPS)
set(EXTRA_FLAGS "-DCPU_CAPABILITY=${CPU_CAPABILITY} -DCPU_CAPABILITY_${CPU_CAPABILITY}")
endif(MSVC)
# Disable certain warnings for GCC-9.X
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
if(CMAKE_COMPILER_IS_GNUCXX)
if(("${NAME}" STREQUAL "native/cpu/GridSamplerKernel.cpp") AND ("${CPU_CAPABILITY}" STREQUAL "DEFAULT"))
# See https://github.com/pytorch/pytorch/issues/38855
set(EXTRA_FLAGS "${EXTRA_FLAGS} -Wno-uninitialized")

View File

@ -633,14 +633,6 @@ if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
# Revert to whatever it was before
set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE_FLAG})
# Workaround for https://github.com/pytorch/pytorch/issues/47292
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.5.0))
# Compiling qu8-requantization/precise-psimd.c without any optimization flags on gcc-7.4 or older i
# Fails with internal compiler error
# Workaround by forcing -O1 for XNNPACK (i.e. build it with RelWithDebInfo)
set_property(TARGET XNNPACK APPEND_STRING PROPERTY COMPILE_FLAGS "-O1")
endif()
endif()
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})

View File

@ -10,7 +10,7 @@ namespace caffe2 {
class CAFFE2_OBSERVER_API NetObserverReporterPrint : public NetObserverReporter {
public:
static const std::string IDENTIFIER;
void report(NetBase* net, std::map<std::string, PerformanceInformation>&);
void report(NetBase* net, std::map<std::string, PerformanceInformation>&) override;
};
} // namespace caffe2

View File

@ -57,14 +57,6 @@ if(USE_CUDA)
target_compile_definitions(test_api PRIVATE "USE_CUDA")
endif()
# Workaround for https://github.com/pytorch/pytorch/issues/40941
if(USE_OPENMP AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0.0))
# Compiling transformer.cpp or pow_test.cpp with -O2+ and both -fuse-openmp and -faligned-newout any optimization
# Fails with internal compiler error in gcc-7.5 or older
# Workaround by compiling the tests without openmp (which they are not using anyway)
set_property(TARGET test_api APPEND_STRING PROPERTY COMPILE_FLAGS "-fno-openmp")
endif()
if(NOT MSVC)
# Clang has an unfixed bug leading to spurious missing braces
# warnings, see https://bugs.llvm.org/show_bug.cgi?id=21629

View File

@ -248,7 +248,7 @@ if(USE_DISTRIBUTED)
append_filelist("libtorch_python_distributed_sources" TORCH_PYTHON_SRCS)
endif()
# Disable certain warnings for GCC-9.X
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
if(CMAKE_COMPILER_IS_GNUCXX)
set_source_files_properties(${TORCH_SRC_DIR}/csrc/distributed/autograd/init.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
set_source_files_properties(${TORCH_SRC_DIR}/csrc/distributed/rpc/testing/init.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
set_source_files_properties(${TORCH_SRC_DIR}/csrc/distributed/c10d/init.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
@ -321,7 +321,7 @@ set_source_files_properties(
)
# Disable certain warnings for GCC-9.X
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
if(CMAKE_COMPILER_IS_GNUCXX)
set_source_files_properties(${TORCH_SRC_DIR}/csrc/Module.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
set_source_files_properties(${TORCH_SRC_DIR}/csrc/autograd/python_variable.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
endif()

View File

@ -49,7 +49,7 @@ struct PyFunctionTensorPostAccGradHooks : public PostAccumulateGradHook {
void compiled_args(torch::dynamo::autograd::CompiledNodeArgs& args) override;
void apply_with_saved(
Variable& tensor,
torch::dynamo::autograd::SwapSavedVariables& saved);
torch::dynamo::autograd::SwapSavedVariables& saved) override;
PyObject* dict;
};