diff --git a/.circleci/docker/build.sh b/.circleci/docker/build.sh index b41d5fe2c8c1b..ebea9eda85a6a 100755 --- a/.circleci/docker/build.sh +++ b/.circleci/docker/build.sh @@ -75,9 +75,8 @@ elif [[ "$image" == *rocm* ]]; then DOCKERFILE="${OS}-rocm/Dockerfile" fi -if [[ "$image" == *bionic* ]]; then - CMAKE_VERSION=3.13.5 -fi +# CMake 3.18 is needed to support CUDA17 language variant +CMAKE_VERSION=3.18.5 TRAVIS_DL_URL_PREFIX="https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/14.04/x86_64" _UCX_COMMIT=31e74cac7bee0ef66bef2af72e7d86d9c282e5ab @@ -209,7 +208,6 @@ case "$image" in ;; pytorch-linux-focal-py3.7-gcc7) ANACONDA_PYTHON_VERSION=3.7 - CMAKE_VERSION=3.16.9 # Required for precompiled header support GCC_VERSION=7 PROTOBUF=yes DB=yes diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d70f6ef58161..d2f5e8158804e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.13 FATAL_ERROR) +cmake_minimum_required(VERSION 3.18 FATAL_ERROR) #cmake_policy(SET CMP0022 NEW) #cmake_policy(SET CMP0023 NEW) @@ -11,13 +11,9 @@ cmake_policy(SET CMP0025 NEW) # Suppress warning flags in default MSVC configuration. It's not # mandatory that we do this (and we don't if cmake is old), but it's # nice when it's possible, and it's possible on our Windows configs. -if(NOT CMAKE_VERSION VERSION_LESS 3.15.0) - cmake_policy(SET CMP0092 NEW) -endif() +cmake_policy(SET CMP0092 NEW) -if(NOT CMAKE_VERSION VERSION_LESS 3.10) - set(FIND_CUDA_MODULE_DEPRECATED ON) -endif() +set(FIND_CUDA_MODULE_DEPRECATED ON) # ---[ Project and semantic versioning. project(Torch CXX C) @@ -35,9 +31,9 @@ string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard) if(env_cxx_standard GREATER -1) message( WARNING "C++ standard version definition detected in environment variable." - "PyTorch requires -std=c++14. Please remove -std=c++ settings in your environment.") + "PyTorch requires -std=c++17. Please remove -std=c++ settings in your environment.") endif() -set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.") +set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.") set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard whose features are requested to build this target.") if(DEFINED GLIBCXX_USE_CXX11_ABI) @@ -888,7 +884,6 @@ if(NOT MSVC) append_cxx_flag_if_supported("-Wno-unused-private-field" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-inconsistent-missing-override" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-aligned-allocation-unavailable" CMAKE_CXX_FLAGS) - append_cxx_flag_if_supported("-Wno-c++14-extensions" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-constexpr-not-const" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-missing-braces" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wunused-lambda-capture" CMAKE_CXX_FLAGS) @@ -993,7 +988,6 @@ if(APPLE) endif() append_cxx_flag_if_supported("-Wno-unused-private-field" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-missing-braces" CMAKE_CXX_FLAGS) - append_cxx_flag_if_supported("-Wno-c++14-extensions" CMAKE_CXX_FLAGS) append_cxx_flag_if_supported("-Wno-constexpr-not-const" CMAKE_CXX_FLAGS) endif() diff --git a/aten/src/ATen/Dispatch.h b/aten/src/ATen/Dispatch.h index d2f5a244ad573..08d4832b33a2b 100644 --- a/aten/src/ATen/Dispatch.h +++ b/aten/src/ATen/Dispatch.h @@ -51,8 +51,6 @@ TORCH_API void record_kernel_function_dtype(std::string name); #define RECORD_KERNEL_FUNCTION_DTYPE(NAME, enum_type) #endif -// Avoid if_constexpr if possble, as it's more expensive to compile -#if defined __cpp_if_constexpr #define AT_PRIVATE_CHECK_SELECTIVE_BUILD(enum_type) \ do { \ if constexpr (!at::should_include_kernel_dtype( \ @@ -64,17 +62,6 @@ TORCH_API void record_kernel_function_dtype(std::string name); at_dispatch_name); \ } \ } while (0) -#else // defined __cpp_if_constexpr -#define AT_PRIVATE_CHECK_SELECTIVE_BUILD(enum_type) \ - at::guts::if_constexpr([&] { \ - AT_ERROR( \ - "dtype '", \ - toString(enum_type), \ - "' not selected for kernel tag ", \ - at_dispatch_name); \ - }) -#endif // Workaround for C10_UNUSED because CUDA 10.2 and below fails to handle unused // attribute in the type aliasing context. Keep name long and verbose to avoid diff --git a/aten/src/ATen/core/boxing/impl/boxing.h b/aten/src/ATen/core/boxing/impl/boxing.h index ccac9ebe8f61b..20ad7dbdba057 100644 --- a/aten/src/ATen/core/boxing/impl/boxing.h +++ b/aten/src/ATen/core/boxing/impl/boxing.h @@ -226,20 +226,17 @@ struct BoxedKernelWrapper< torch::jit::Stack stack = boxArgs(std::forward(args)...); boxed_kernel_func.callBoxed(opHandle, dispatchKeySet, &stack); - return guts::if_constexpr::value>( - [&] (auto delay_check) { - // op has pushed one or more values onto the stack. - return delay_check(PopResult::call(stack)); - }, - [&] { - // op returns void, boxed kernel has pushed nothing onto stack. - TORCH_INTERNAL_ASSERT_DEBUG_ONLY( - stack.size() == 0, - "Boxed kernel was expected to return no values on the stack, ", - "but instead returned ", stack.size(), " values." - ); - } - ); + if constexpr (!std::is_same_v) { + // op has pushed one or more values onto the stack. + return PopResult::call(stack); + } else { + // op returns void, boxed kernel has pushed nothing onto stack. + TORCH_INTERNAL_ASSERT_DEBUG_ONLY( + stack.size() == 0, + "Boxed kernel was expected to return no values on the stack, ", + "but instead returned ", stack.size(), " values." + ); + } } }; diff --git a/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h b/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h index a99f45040788d..84514ab6d0e1e 100644 --- a/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h +++ b/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h @@ -103,12 +103,12 @@ namespace impl { template struct assert_is_valid_input_type { assert_is_valid_input_type() { - guts::if_constexpr::value>([] { + if constexpr (guts::typelist::contains::value) { /* everything is ok, this is a primitive type */ - }, /* else */ [] { + } else { /* otherwise this must be an instance of a valid custom class, since it can only have been created via IValue(x), which ensures this. */ - }); + }; } }; @@ -209,12 +209,12 @@ namespace impl { template struct assert_is_valid_output_type { assert_is_valid_output_type() { - guts::if_constexpr::value>([] { + if constexpr (guts::typelist::contains::value) { /* everything is ok, this is a primitive type */ - }, /* else */ [] { + } else { /* otherwise T is verified to be a registered custom class in the IValue constructor, so no benefit in double-checking here */ - }); + } } }; @@ -569,34 +569,17 @@ namespace impl { using ArgTypes = typename c10::remove_DispatchKeySet_arg_from_func::parameter_types; constexpr bool has_outputs = !std::is_same::value; constexpr size_t num_inputs = guts::typelist::size::value; -#ifdef __cpp_if_constexpr if constexpr (has_outputs) { -#else - guts::if_constexpr([&] (auto delay_check) { -#endif // Decay ReturnType to ReturnType_ so that if a reference gets returned, we actually store it by value // and don't get a dangling reference. This is only required because some kernels still return `Tensor&`. -#ifdef __cpp_if_constexpr using ReturnType_ = std::decay_t; ReturnType_ output = call_functor_with_args_from_stack(functor, dispatchKeySet, stack); -#else - using ReturnType_ = std::decay_t>; - ReturnType_ output = call_functor_with_args_from_stack(functor, dispatchKeySet, delay_check(stack)); -#endif torch::jit::drop(*stack, num_inputs); push_outputs::call(std::move(output), stack); -#ifdef __cpp_if_constexpr } else { -#else - }, /* else */ [&] { -#endif call_functor_with_args_from_stack(functor, dispatchKeySet, stack); torch::jit::drop(*stack, num_inputs); -#ifdef __cpp_if_constexpr } -#else - }); -#endif } }; } // namespace impl diff --git a/aten/src/ATen/core/ivalue_inl.h b/aten/src/ATen/core/ivalue_inl.h index bea795c8d81e8..4ad066e1ce49f 100644 --- a/aten/src/ATen/core/ivalue_inl.h +++ b/aten/src/ATen/core/ivalue_inl.h @@ -975,11 +975,9 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target { */ template void addCallback(T callback) { -#if __cpp_lib_is_invocable >= 201703 static_assert( std::is_invocable_r::value, "The callback must have signature void(Future&)"); -#endif std::unique_lock lock(mutex_); if (completed()) { lock.unlock(); @@ -997,30 +995,26 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target { template c10::intrusive_ptr then(T callback, TypePtr type) { using IValueWithStorages = std::tuple>; -#if __cpp_lib_is_invocable >= 201703 static_assert( guts::disjunction< std::is_invocable_r, std::is_invocable_r>::value, "The callback must have signature IValue(Future&) or " "std::tuple>(Future&)"); -#endif auto childFut = createInstance(std::move(type)); addCallback([childFut, cb = std::move(callback)](Future& parentFut) mutable { try { - guts::if_constexpr, - IValueWithStorages>::value>( - [&](auto identity) { + IValueWithStorages>) { IValue value; std::vector storages; - std::tie(value, storages) = identity(cb)(parentFut); + std::tie(value, storages) = cb(parentFut); childFut->markCompleted(std::move(value), std::move(storages)); - }, - [&](auto identity) { - childFut->markCompleted(identity(cb)(parentFut)); - }); + } else { + childFut->markCompleted(cb(parentFut)); + }; } catch (std::exception&) { childFut->setError(std::current_exception()); } @@ -1030,11 +1024,9 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target { template c10::intrusive_ptr thenAsync(T callback, TypePtr type) { -#if __cpp_lib_is_invocable >= 201703 static_assert( std::is_invocable_r, T, Future&>::value, "The callback must have signature c10::intrusive_ptr(Future&)"); -#endif auto childFut = createInstance(std::move(type)); addCallback( [childFut, cb = std::move(callback)](Future& parentFut) mutable { @@ -1111,11 +1103,9 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target { // synchronize them with the value, and so on (if needed). template void invokeCallback(T callback) { -#if __cpp_lib_is_invocable >= 201703 static_assert( std::is_invocable_r::value, "The callback must have signature void(Future&)"); -#endif c10::OptionalDeviceGuard deviceGuard(currentDevice_); diff --git a/aten/src/ATen/mps/MPSGuardImpl.h b/aten/src/ATen/mps/MPSGuardImpl.h index 27d32bf652e7a..b6002497d223d 100644 --- a/aten/src/ATen/mps/MPSGuardImpl.h +++ b/aten/src/ATen/mps/MPSGuardImpl.h @@ -109,12 +109,12 @@ struct TORCH_API MPSGuardImpl final : public c10::impl::DeviceGuardImplInterface struct OptionalMPSGuard { explicit OptionalMPSGuard() : guard_() {} - explicit OptionalMPSGuard(optional device_opt) + explicit OptionalMPSGuard(c10::optional device_opt) : guard_(device_opt) {} /// Set the current MPS device to the passed device index, if it is not /// nullopt - explicit OptionalMPSGuard(optional device_index_opt) + explicit OptionalMPSGuard(c10::optional device_index_opt) : guard_(device_index_opt) {} // Copy is not allowed @@ -144,14 +144,14 @@ struct OptionalMPSGuard { /// Returns the device that was set immediately prior to initialization of the /// guard, or nullopt if the guard is uninitialized. - optional original_device() const { + c10::optional original_device() const { return guard_.original_device(); } /// Returns the most recent device that was set using this device guard, /// either from construction, or via set_device, if the guard is initialized, /// or nullopt if the guard is uninitialized. - optional current_device() const { + c10::optional current_device() const { return guard_.current_device(); } diff --git a/aten/src/ATen/native/ReduceOpsUtils.h b/aten/src/ATen/native/ReduceOpsUtils.h index 9db9802ea788b..2b46eb683f1c9 100644 --- a/aten/src/ATen/native/ReduceOpsUtils.h +++ b/aten/src/ATen/native/ReduceOpsUtils.h @@ -102,7 +102,7 @@ static inline void check_scalar_type_device_layout_equal(const Tensor& out, cons OPTION_TYPE_EQUALITY_CHECK(layout, out.options(), self.options()); } -static inline Tensor integer_upcast(const Tensor& self, optional dtype) { +static inline Tensor integer_upcast(const Tensor& self, c10::optional dtype) { ScalarType scalarType = self.scalar_type(); ScalarType upcast_scalarType = dtype.value_or(at::isIntegralType(scalarType, /*includeBool=*/true) ? ScalarType::Long : scalarType); return self.toType(upcast_scalarType); diff --git a/aten/src/ATen/native/cuda/jit_utils.cpp b/aten/src/ATen/native/cuda/jit_utils.cpp index a1266fb1b5044..870e980bb69ee 100644 --- a/aten/src/ATen/native/cuda/jit_utils.cpp +++ b/aten/src/ATen/native/cuda/jit_utils.cpp @@ -1532,7 +1532,7 @@ NvrtcFunction jit_pwise_function( &program, code.c_str(), nullptr, 0, nullptr, nullptr)); #ifdef USE_ROCM - std::vector args = {"--std=c++14"}; + std::vector args = {"--std=c++17"}; #else // Constructs nvrtc build arguments // CUDA 11.1 allows going directly to SASS (sm_) instead of PTX (compute_) @@ -1547,7 +1547,7 @@ NvrtcFunction jit_pwise_function( std::to_string(cuda_minor); // NOLINTNEXTLINE(cppcoreguidelines-init-variables) std::vector args = { - "--std=c++14", compute.c_str(), "-default-device"}; + "--std=c++17", compute.c_str(), "-default-device"}; #endif #ifndef NDEBUG diff --git a/aten/src/ATen/native/mps/operations/Distributions.mm b/aten/src/ATen/native/mps/operations/Distributions.mm index 1da2457f3a37e..99d01c6825b35 100644 --- a/aten/src/ATen/native/mps/operations/Distributions.mm +++ b/aten/src/ATen/native/mps/operations/Distributions.mm @@ -273,7 +273,7 @@ Tensor normal_mps(const Tensor& mean, const Tensor& std, c10::optional to_opt, c10::optional gen) { +Tensor& random_mps_(Tensor& self, int64_t from, c10::optional to_opt, c10::optional gen) { auto input_dtype = self.scalar_type(); int64_t to = 0; diff --git a/aten/src/ATen/native/mps/operations/ReduceOps.mm b/aten/src/ATen/native/mps/operations/ReduceOps.mm index 39680240f7f21..d905107b8ffd4 100644 --- a/aten/src/ATen/native/mps/operations/ReduceOps.mm +++ b/aten/src/ATen/native/mps/operations/ReduceOps.mm @@ -331,7 +331,7 @@ Tensor trace_mps_out(const Tensor& self) { // Taken from ReduceOps.cpp inline ScalarType get_dtype_from_self( const Tensor& self, - const optional& dtype, + const c10::optional& dtype, bool promote_integers) { if (dtype.has_value()) { return dtype.value(); diff --git a/aten/src/ATen/native/mps/operations/View.mm b/aten/src/ATen/native/mps/operations/View.mm index 70c7d50b730f3..0e35c7b2f642d 100644 --- a/aten/src/ATen/native/mps/operations/View.mm +++ b/aten/src/ATen/native/mps/operations/View.mm @@ -274,7 +274,7 @@ Tensor gatherViewTensor(const at::Tensor& src, at::Tensor& dst) } // namespace mps // implementation of as_strided() op -Tensor as_strided_tensorimpl_mps(const Tensor& self, IntArrayRef size, IntArrayRef stride, optional storage_offset_) +Tensor as_strided_tensorimpl_mps(const Tensor& self, IntArrayRef size, IntArrayRef stride, c10::optional storage_offset_) { auto storage_offset = storage_offset_.value_or(self.storage_offset()); auto result = detail::make_tensor(c10::TensorImpl::VIEW, Storage(self.storage()), self.key_set(), self.dtype()); diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt index 0309d7a2d712e..9c80fa9051ab6 100644 --- a/c10/CMakeLists.txt +++ b/c10/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(c10 CXX) -set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.") +set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Main build file for the C10 library. diff --git a/c10/util/C++17.h b/c10/util/C++17.h index c51275721e584..f374b86aa31f9 100644 --- a/c10/util/C++17.h +++ b/c10/util/C++17.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -22,9 +23,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)) @@ -37,14 +38,8 @@ namespace c10 { -// in c++17 std::result_of has been superceded by std::invoke_result. Since -// c++20, std::result_of is removed. template -#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703L using invoke_result = typename std::invoke_result; -#else -using invoke_result = typename std::result_of; -#endif template using invoke_result_t = typename invoke_result::type; @@ -60,8 +55,6 @@ make_unique_base(Args&&... args) { return std::unique_ptr(new Child(std::forward(args)...)); } -#if defined(__cpp_lib_logical_traits) && !(defined(_MSC_VER) && _MSC_VER < 1920) - template using conjunction = std::conjunction; template @@ -71,55 +64,9 @@ using bool_constant = std::bool_constant; template using negation = std::negation; -#else - -// Implementation taken from http://en.cppreference.com/w/cpp/types/conjunction -template -struct conjunction : std::true_type {}; -template -struct conjunction : B1 {}; -template -struct conjunction - : std::conditional_t, B1> {}; - -// Implementation taken from http://en.cppreference.com/w/cpp/types/disjunction -template -struct disjunction : std::false_type {}; -template -struct disjunction : B1 {}; -template -struct disjunction - : std::conditional_t> {}; - -// Implementation taken from -// http://en.cppreference.com/w/cpp/types/integral_constant -template -using bool_constant = std::integral_constant; - -// Implementation taken from http://en.cppreference.com/w/cpp/types/negation -template -struct negation : bool_constant {}; - -#endif - -#ifdef __cpp_lib_void_t - template using void_t = std::void_t; -#else - -// Implementation taken from http://en.cppreference.com/w/cpp/types/void_t -// (it takes CWG1558 into account and also works for older compilers) -template -struct make_void { - typedef void type; -}; -template -using void_t = typename make_void::type; - -#endif - #if defined(USE_ROCM) // rocm doesn't like the C10_HOST_DEVICE #define CUDA_HOST_DEVICE @@ -127,51 +74,11 @@ using void_t = typename make_void::type; #define CUDA_HOST_DEVICE C10_HOST_DEVICE #endif -#ifdef __cpp_lib_apply - template CUDA_HOST_DEVICE inline constexpr decltype(auto) apply(F&& f, Tuple&& t) { return std::apply(std::forward(f), std::forward(t)); } -#else - -// Implementation from http://en.cppreference.com/w/cpp/utility/apply (but -// modified) -// TODO This is an incomplete implementation of std::apply, not working for -// member functions. -namespace detail { -template -#if defined(_MSC_VER) -// MSVC has a problem with the decltype() return type, but it also doesn't need -// it -C10_HOST_DEVICE constexpr auto apply_impl( - F&& f, - Tuple&& t, - std::index_sequence) -#else -// GCC/Clang need the decltype() return type -CUDA_HOST_DEVICE constexpr decltype(auto) apply_impl( - F&& f, - Tuple&& t, - std::index_sequence) -#endif -{ - return std::forward(f)(std::get(std::forward(t))...); -} -} // namespace detail - -template -CUDA_HOST_DEVICE constexpr decltype(auto) apply(F&& f, Tuple&& t) { - return detail::apply_impl( - std::forward(f), - std::forward(t), - std::make_index_sequence< - std::tuple_size>::value>{}); -} - -#endif - #undef CUDA_HOST_DEVICE template @@ -219,68 +126,6 @@ struct function_takes_identity_argument< void_t()(_identity()))>> : std::true_type {}; #endif -template -struct _if_constexpr; - -template <> -struct _if_constexpr final { - template < - class ThenCallback, - class ElseCallback, - std::enable_if_t< - function_takes_identity_argument::value, - void*> = nullptr> - static decltype(auto) call( - ThenCallback&& thenCallback, - ElseCallback&& /* elseCallback */) { - // The _identity instance passed in can be used to delay evaluation of an - // expression, because the compiler can't know that it's just the identity - // we're passing in. - return thenCallback(_identity()); - } - - template < - class ThenCallback, - class ElseCallback, - std::enable_if_t< - !function_takes_identity_argument::value, - void*> = nullptr> - static decltype(auto) call( - ThenCallback&& thenCallback, - ElseCallback&& /* elseCallback */) { - return thenCallback(); - } -}; - -template <> -struct _if_constexpr final { - template < - class ThenCallback, - class ElseCallback, - std::enable_if_t< - function_takes_identity_argument::value, - void*> = nullptr> - static decltype(auto) call( - ThenCallback&& /* thenCallback */, - ElseCallback&& elseCallback) { - // The _identity instance passed in can be used to delay evaluation of an - // expression, because the compiler can't know that it's just the identity - // we're passing in. - return elseCallback(_identity()); - } - - template < - class ThenCallback, - class ElseCallback, - std::enable_if_t< - !function_takes_identity_argument::value, - void*> = nullptr> - static decltype(auto) call( - ThenCallback&& /* thenCallback */, - ElseCallback&& elseCallback) { - return elseCallback(); - } -}; } // namespace detail /* @@ -341,7 +186,6 @@ template decltype(auto) if_constexpr( ThenCallback&& thenCallback, ElseCallback&& elseCallback) { -#if defined(__cpp_if_constexpr) // If we have C++17, just use it's "if constexpr" feature instead of wrapping // it. This will give us better error messages. if constexpr (Condition) { @@ -363,17 +207,10 @@ decltype(auto) if_constexpr( return static_cast(elseCallback)(); } } -#else - // C++14 implementation of if constexpr - return detail::_if_constexpr::call( - static_cast(thenCallback), - static_cast(elseCallback)); -#endif } template decltype(auto) if_constexpr(ThenCallback&& thenCallback) { -#if defined(__cpp_if_constexpr) // If we have C++17, just use it's "if constexpr" feature instead of wrapping // it. This will give us better error messages. if constexpr (Condition) { @@ -388,11 +225,6 @@ decltype(auto) if_constexpr(ThenCallback&& thenCallback) { return static_cast(thenCallback)(); } } -#else - // C++14 implementation of if constexpr - return if_constexpr( - static_cast(thenCallback), [](auto) {}); -#endif } // GCC 4.8 doesn't define std::to_string, even though that's in C++11. Let's diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 104056ee07240..8472e7bfc5ae9 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1687,7 +1687,7 @@ if(NOT INTERN_BUILD_MOBILE) string(APPEND CMAKE_CUDA_FLAGS " -Wno-deprecated-gpu-targets --expt-extended-lambda") if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.") + set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.") endif() # use cub in a safe manner, see: diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index 5944a5a1a6269..9ad0a2f96f88f 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -407,7 +407,7 @@ endmacro() # Usage: # torch_compile_options(lib_name) function(torch_compile_options libname) - set_property(TARGET ${libname} PROPERTY CXX_STANDARD 14) + set_property(TARGET ${libname} PROPERTY CXX_STANDARD 17) set(private_compile_options "") # ---[ Check if warnings should be errors. diff --git a/functorch/CMakeLists.txt b/functorch/CMakeLists.txt index d203043243829..911f251e88623 100644 --- a/functorch/CMakeLists.txt +++ b/functorch/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.12) project(functorch) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) include(GNUInstallDirs) include(CMakePackageConfigHelpers) diff --git a/test/custom_backend/CMakeLists.txt b/test/custom_backend/CMakeLists.txt index 71f83442e085f..835f17850a842 100644 --- a/test/custom_backend/CMakeLists.txt +++ b/test/custom_backend/CMakeLists.txt @@ -9,9 +9,9 @@ endif() find_package(Torch REQUIRED) add_library(custom_backend SHARED custom_backend.cpp) -set_property(TARGET custom_backend PROPERTY CXX_STANDARD 14) +set_property(TARGET custom_backend PROPERTY CXX_STANDARD 17) target_link_libraries(custom_backend "${TORCH_LIBRARIES}") add_executable(test_custom_backend test_custom_backend.cpp) -set_property(TARGET test_custom_backend PROPERTY CXX_STANDARD 14) +set_property(TARGET test_custom_backend PROPERTY CXX_STANDARD 17) target_link_libraries(test_custom_backend custom_backend) diff --git a/test/custom_operator/CMakeLists.txt b/test/custom_operator/CMakeLists.txt index 47c1c9d45e814..6d1a4988fe382 100644 --- a/test/custom_operator/CMakeLists.txt +++ b/test/custom_operator/CMakeLists.txt @@ -9,12 +9,12 @@ endif() find_package(Torch REQUIRED) add_library(custom_ops SHARED op.cpp) -set_property(TARGET custom_ops PROPERTY CXX_STANDARD 14) +set_property(TARGET custom_ops PROPERTY CXX_STANDARD 17) target_compile_features(custom_ops PUBLIC cxx_range_for) target_link_libraries(custom_ops "${TORCH_LIBRARIES}") target_compile_definitions(custom_ops PRIVATE custom_ops_EXPORTS) add_executable(test_custom_ops test_custom_ops.cpp) -set_property(TARGET test_custom_ops PROPERTY CXX_STANDARD 14) +set_property(TARGET test_custom_ops PROPERTY CXX_STANDARD 17) target_link_libraries(test_custom_ops custom_ops) diff --git a/test/jit_hooks/CMakeLists.txt b/test/jit_hooks/CMakeLists.txt index 546a3040f49bc..91d5a2bf4e01c 100644 --- a/test/jit_hooks/CMakeLists.txt +++ b/test/jit_hooks/CMakeLists.txt @@ -9,5 +9,5 @@ endif() find_package(Torch REQUIRED) add_executable(test_jit_hooks test_jit_hooks.cpp) -set_property(TARGET test_jit_hooks PROPERTY CXX_STANDARD 14) +set_property(TARGET test_jit_hooks PROPERTY CXX_STANDARD 17) target_link_libraries(test_jit_hooks "${TORCH_LIBRARIES}") diff --git a/test/mobile/custom_build/CMakeLists.txt b/test/mobile/custom_build/CMakeLists.txt index 521569176c307..426371f4d2965 100644 --- a/test/mobile/custom_build/CMakeLists.txt +++ b/test/mobile/custom_build/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1) project(custom_build_project) -set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.") +set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.") # Find torch library find_package(Torch REQUIRED)