Move a number of ATen checks out of Dependencies.cmake (#12990)

Summary:
cc Yangqing mingzhe09088 anderspapitto mingzhe09088
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12990

Differential Revision: D10862301

Pulled By: orionr

fbshipit-source-id: 62ba09cf0725f29692fac71bc30173469283390b
This commit is contained in:
Orion Reblitz-Richardson
2018-10-25 17:24:01 -07:00
committed by Facebook Github Bot
parent 852d6e8b65
commit 99d24aefc3
5 changed files with 85 additions and 71 deletions

View File

@ -285,7 +285,7 @@ else()
target_link_libraries(ATen_cpu PRIVATE ATEN_CPU_FILES_GEN_LIB)
caffe2_interface_library(ATen_cpu ATen_cpu_library)
# Set standard properties on the target
aten_set_target_props(ATen_cpu)
torch_set_target_props(ATen_cpu)
# Make sure these don't get built by parent
set(ATen_CPU_SRCS)
@ -326,7 +326,7 @@ if(USE_CUDA OR USE_ROCM)
ATen_cuda PUBLIC ATen_cpu ${ATen_PUBLIC_CUDA_DEPENDENCY_LIBS})
# Set standard properties on the target
aten_set_target_props(ATen_cuda)
torch_set_target_props(ATen_cuda)
caffe2_interface_library(ATen_cuda ATen_cuda_library)
@ -344,9 +344,9 @@ if(NOT AT_LINK_STYLE STREQUAL "INTERFACE")
endif()
if(NOT MSVC)
aten_compile_options(ATen_cpu)
torch_compile_options(ATen_cpu)
if(USE_CUDA OR USE_ROCM)
aten_compile_options(ATen_cuda)
torch_compile_options(ATen_cuda)
endif()
endif()

View File

@ -222,7 +222,7 @@ target_include_directories(caffe2 INTERFACE $<INSTALL_INTERFACE:include>)
target_include_directories(caffe2 PRIVATE ${Caffe2_CPU_INCLUDE})
target_include_directories(caffe2 SYSTEM PRIVATE "${Caffe2_DEPENDENCY_INCLUDE}")
# Set standard properties on the target
aten_set_target_props(caffe2)
torch_set_target_props(caffe2)
if (MSVC)
target_compile_options(caffe2 INTERFACE "-std=c++11")
@ -346,7 +346,7 @@ if(USE_CUDA)
endif()
# Set standard properties on the target
aten_set_target_props(caffe2_gpu)
torch_set_target_props(caffe2_gpu)
install(TARGETS caffe2_gpu EXPORT Caffe2Targets DESTINATION lib)
caffe2_interface_library(caffe2_gpu caffe2_gpu_library)
@ -383,7 +383,7 @@ if(USE_ROCM)
target_include_directories(caffe2_hip INTERFACE $<INSTALL_INTERFACE:include>)
# Set standard properties on the target
aten_set_target_props(caffe2_hip)
torch_set_target_props(caffe2_hip)
# When a library has object files that contain device code, it needs to use hipcc/hcc to link.
set_target_properties(caffe2_hip PROPERTIES LINKER_LANGUAGE HIP)

View File

@ -860,46 +860,6 @@ if (NOT BUILD_ATEN_MOBILE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
INCLUDE(CheckCXXSourceCompiles)
# disable some verbose warnings
IF (MSVC)
set(CMAKE_CXX_FLAGS "/wd4267 /wd4251 /wd4522 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275 ${CMAKE_CXX_FLAGS}")
ENDIF()
# windef.h will define max/min macros if NOMINMAX is not defined
IF (MSVC)
add_definitions(/DNOMINMAX)
ENDIF()
#Check if certain std functions are supported. Sometimes
#_GLIBCXX_USE_C99 macro is not defined and some functions are missing.
CHECK_CXX_SOURCE_COMPILES("
#include <cmath>
#include <string>
int main() {
int a = std::isinf(3.0);
int b = std::isnan(0.0);
std::string s = std::to_string(1);
return 0;
}" SUPPORT_GLIBCXX_USE_C99)
if (NOT SUPPORT_GLIBCXX_USE_C99)
message(FATAL_ERROR
"The C++ compiler does not support required functions. "
"This is very likely due to a known bug in GCC 5 "
"(and maybe other versions) on Ubuntu 17.10 and newer. "
"For more information, see: "
"https://github.com/pytorch/pytorch/issues/5229"
)
endif()
# Top-level build config
############################################
# Flags
@ -1046,24 +1006,6 @@ if (NOT BUILD_ATEN_MOBILE)
add_compile_options(-mcpu=cortex-a9)
ENDIF()
# Check that our programs run. This is different from the native CMake compiler
# check, which just tests if the program compiles and links. This is important
# because with ASAN you might need to help the compiled library find some
# dynamic libraries.
CHECK_C_SOURCE_RUNS("
int main() { return 0; }
" COMPILER_WORKS)
IF (NOT COMPILER_WORKS)
# Force cmake to retest next time around
unset(COMPILER_WORKS CACHE)
MESSAGE(FATAL_ERROR
"Could not run a simple program built with your compiler. "
"If you are trying to use -fsanitize=address, make sure "
"libasan is properly installed on your system (you can confirm "
"if the problem is this by attempting to build and run a "
"small program.)")
ENDIF()
CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
# Check for a cpuid intrinsic
IF (HAVE_CPUID_H)

View File

@ -37,6 +37,57 @@ if(EXISTS "/etc/os-release")
endif()
endif()
if (NOT BUILD_ATEN_MOBILE)
# ---[ Check that our programs run. This is different from the native CMake
# compiler check, which just tests if the program compiles and links. This is
# important because with ASAN you might need to help the compiled library find
# some dynamic libraries.
cmake_push_check_state(RESET)
CHECK_C_SOURCE_RUNS("
int main() { return 0; }
" COMPILER_WORKS)
if (NOT COMPILER_WORKS)
# Force cmake to retest next time around
unset(COMPILER_WORKS CACHE)
message(FATAL_ERROR
"Could not run a simple program built with your compiler. "
"If you are trying to use -fsanitize=address, make sure "
"libasan is properly installed on your system (you can confirm "
"if the problem is this by attempting to build and run a "
"small program.)")
endif()
cmake_pop_check_state()
endif()
if (NOT BUILD_ATEN_MOBILE)
# ---[ Check if certain std functions are supported. Sometimes
# _GLIBCXX_USE_C99 macro is not defined and some functions are missing.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
CHECK_CXX_SOURCE_COMPILES("
#include <cmath>
#include <string>
int main() {
int a = std::isinf(3.0);
int b = std::isnan(0.0);
std::string s = std::to_string(1);
return 0;
}" SUPPORT_GLIBCXX_USE_C99)
if (NOT SUPPORT_GLIBCXX_USE_C99)
# Force cmake to retest next time around
unset(SUPPORT_GLIBCXX_USE_C99 CACHE)
message(FATAL_ERROR
"The C++ compiler does not support required functions. "
"This is very likely due to a known bug in GCC 5 "
"(and maybe other versions) on Ubuntu 17.10 and newer. "
"For more information, see: "
"https://github.com/pytorch/pytorch/issues/5229")
endif()
cmake_pop_check_state()
endif()
# ---[ Check if std::exception_ptr is supported.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
@ -154,6 +205,7 @@ endif()
# totally necessary, and only add when you see fit. If it is needed due to
# a third party library (like Protobuf), mention it in the comment as
# "THIRD_PARTY_NAME related"
# From https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
add_compile_options(
##########################################
@ -183,6 +235,22 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
# Eigen related.
/wd4805 # (1): Unsafe mix of types in gtest/gtest.h. Gtest related.
##########################################
# These are directly ATen related. However, several are covered by
# the above now. We leave them here for documentation purposes only.
#/wd4267 # Conversion from 'size_t' to 'type', possible loss of data.
/wd4522 # (3): 'class' : multiple assignment operators specified
/wd4838 # (1): conversion from 'type_1' to 'type_2' requires a
# narrowing conversion
#/wd4305 # 'identifier' : truncation from 'type1' to 'type2'
#/wd4244 # Conversion from 'type1' to 'type2', possible loss of data.
/wd4190 # (1): 'identifier1' has C-linkage specified, but returns UDT
# 'identifier2' which is incompatible with C
/wd4101 # (3): 'identifier' : unreferenced local variable
#/wd4996 # (3): Use of deprecated POSIX functions. Since we develop
# # mainly on Linux, this is ignored.
/wd4275 # (2): non - DLL-interface classkey 'identifier' used as
# base for DLL-interface classkey 'identifier'
##########################################
# These are directly Caffe2 related. However, several are covered by
# protobuf now. We leave them here for documentation purposes only.
##########################################
@ -198,6 +266,10 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
# dllexport in cc file. The strategy is copied from gflags.
)
# Make sure windef.h does not define max/min macros.
# Required by ATen among others.
add_definitions("/DNOMINMAX")
# Exception handing for compiler warining C4530, see
# https://msdn.microsoft.com/en-us/library/2axwkyt4.aspx
add_definitions("/EHsc")

View File

@ -194,10 +194,10 @@ endmacro()
##############################################################################
# Add ATen compile options.
# Add standard compile options.
# Usage:
# aten_compile_options(lib_name)
function(aten_compile_options libname)
# torch_compile_options(lib_name)
function(torch_compile_options libname)
target_compile_options(${libname}
PRIVATE
-Wall
@ -216,10 +216,10 @@ endfunction()
##############################################################################
# Set ATen target properties.
# Set standard target properties.
# Usage:
# aten_set_target_props(lib_name)
function(aten_set_target_props libname)
# torch_set_target_props(lib_name)
function(torch_set_target_props libname)
if(MSVC AND AT_MKL_MT)
set_target_properties(${libname} PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB:${VCOMP_LIB}")
set_target_properties(${libname} PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:${VCOMP_LIB}")