Skip to content

Commit 88920b2

Browse files
malfetpytorchmergebot
authored andcommitted
[Cmake] Check that gcc-9.4 or newer is used (pytorch#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 pytorch#101839 Pull Request resolved: pytorch#112858 Approved by: https://github.com/Skylion007, https://github.com/albanD
1 parent 77d5f03 commit 88920b2

File tree

9 files changed

+16
-34
lines changed

9 files changed

+16
-34
lines changed

CMakeLists.txt

+9-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard whose features are reques
4343
# ---[ Utils
4444
include(cmake/public/utils.cmake)
4545

46-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
46+
# --- [ Check that minimal gcc version is 9.4+
47+
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.4)
48+
message(FATAL "GCC-9.4 or newer is required to compile PyTorch, but found ${CMAKE_CXX_COMPILER_VERSION}")
49+
endif()
50+
51+
if(LINUX)
4752
include(cmake/CheckAbi.cmake)
4853
string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
4954
string(APPEND CMAKE_CUDA_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
@@ -822,7 +827,7 @@ endif()
822827
include(cmake/Allowlist.cmake)
823828

824829
# ---[ Set link flag, handle additional deps for gcc 4.8 and above
825-
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8.0 AND NOT ANDROID)
830+
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
826831
message(STATUS "GCC ${CMAKE_CXX_COMPILER_VERSION}: Adding gcc and gcc_s libs to link line")
827832
list(APPEND Caffe2_DEPENDENCY_LIBS gcc_s gcc)
828833
endif()
@@ -851,26 +856,19 @@ if(NOT MSVC)
851856
append_cxx_flag_if_supported("-Wno-unused-result" CMAKE_CXX_FLAGS)
852857
append_cxx_flag_if_supported("-Wno-strict-overflow" CMAKE_CXX_FLAGS)
853858
append_cxx_flag_if_supported("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
859+
append_cxx_flag_if_supported("-Wno-stringop-overflow" CMAKE_CXX_FLAGS)
854860
append_cxx_flag_if_supported("-Wvla-extension" CMAKE_CXX_FLAGS)
861+
append_cxx_flag_if_supported("-Wsuggest-override" CMAKE_CXX_FLAGS)
855862
append_cxx_flag_if_supported("-Wnewline-eof" CMAKE_CXX_FLAGS)
856863
append_cxx_flag_if_supported("-Winconsistent-missing-override" CMAKE_CXX_FLAGS)
857864
append_cxx_flag_if_supported("-Winconsistent-missing-destructor-override" CMAKE_CXX_FLAGS)
858865
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
859866
string(APPEND CMAKE_CXX_FLAGS " -Wno-pass-failed")
860867
endif()
861-
if(CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))
862-
string(APPEND CMAKE_CXX_FLAGS " -Wno-stringop-overflow")
863-
endif()
864868
if(CMAKE_COMPILER_IS_GNUCXX)
865869
# Suppress "The ABI for passing parameters with 64-byte alignment has changed in GCC 4.6"
866870
string(APPEND CMAKE_CXX_FLAGS " -Wno-psabi")
867871
endif()
868-
if(NOT CMAKE_COMPILER_IS_GNUCXX OR GCC_VERSION VERSION_GREATER_EQUAL 9.2)
869-
# Prior to GCC 9.2, this warning misfires when a method is
870-
# labeled "final".
871-
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
872-
append_cxx_flag_if_supported("-Wsuggest-override" CMAKE_CXX_FLAGS)
873-
endif()
874872

875873
# Use ld.gold if available, fall back to ld.bfd (the default ld) if not
876874
if(USE_GOLD_LINKER)

caffe2/CMakeLists.txt

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

caffe2/python/pybind_state.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class TensorFeeder : public BlobFeederBase {
257257
const DeviceOption& option,
258258
PyArrayObject* original_array,
259259
Blob* blob,
260-
bool in_place) {
260+
bool in_place) override {
261261
if (in_place) {
262262
FeedTensor(
263263
option,

cmake/Codegen.cmake

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

cmake/Dependencies.cmake

-8
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,6 @@ if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
633633

634634
# Revert to whatever it was before
635635
set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE_FLAG})
636-
637-
# Workaround for https://github.com/pytorch/pytorch/issues/47292
638-
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.5.0))
639-
# Compiling qu8-requantization/precise-psimd.c without any optimization flags on gcc-7.4 or older i
640-
# Fails with internal compiler error
641-
# Workaround by forcing -O1 for XNNPACK (i.e. build it with RelWithDebInfo)
642-
set_property(TARGET XNNPACK APPEND_STRING PROPERTY COMPILE_FLAGS "-O1")
643-
endif()
644636
endif()
645637

646638
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})

modules/observers/net_observer_reporter_print.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace caffe2 {
1010
class CAFFE2_OBSERVER_API NetObserverReporterPrint : public NetObserverReporter {
1111
public:
1212
static const std::string IDENTIFIER;
13-
void report(NetBase* net, std::map<std::string, PerformanceInformation>&);
13+
void report(NetBase* net, std::map<std::string, PerformanceInformation>&) override;
1414
};
1515

1616
} // namespace caffe2

test/cpp/api/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ if(USE_CUDA)
5757
target_compile_definitions(test_api PRIVATE "USE_CUDA")
5858
endif()
5959

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

torch/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ if(USE_DISTRIBUTED)
248248
append_filelist("libtorch_python_distributed_sources" TORCH_PYTHON_SRCS)
249249
endif()
250250
# Disable certain warnings for GCC-9.X
251-
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
251+
if(CMAKE_COMPILER_IS_GNUCXX)
252252
set_source_files_properties(${TORCH_SRC_DIR}/csrc/distributed/autograd/init.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
253253
set_source_files_properties(${TORCH_SRC_DIR}/csrc/distributed/rpc/testing/init.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
254254
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(
321321
)
322322

323323
# Disable certain warnings for GCC-9.X
324-
if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0))
324+
if(CMAKE_COMPILER_IS_GNUCXX)
325325
set_source_files_properties(${TORCH_SRC_DIR}/csrc/Module.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
326326
set_source_files_properties(${TORCH_SRC_DIR}/csrc/autograd/python_variable.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-function-type")
327327
endif()

torch/csrc/autograd/python_hook.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct PyFunctionTensorPostAccGradHooks : public PostAccumulateGradHook {
4949
void compiled_args(torch::dynamo::autograd::CompiledNodeArgs& args) override;
5050
void apply_with_saved(
5151
Variable& tensor,
52-
torch::dynamo::autograd::SwapSavedVariables& saved);
52+
torch::dynamo::autograd::SwapSavedVariables& saved) override;
5353
PyObject* dict;
5454
};
5555

0 commit comments

Comments
 (0)