mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Remove some pre-cpp17 stuff (#138410)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/138410 Approved by: https://github.com/Skylion007
This commit is contained in:
committed by
PyTorch MergeBot
parent
f4b3813989
commit
d428d81c7f
@ -8,6 +8,17 @@
|
||||
|
||||
namespace c10 {
|
||||
|
||||
namespace detail {
|
||||
template <typename Base, typename Child, typename... Args>
|
||||
std::enable_if_t<
|
||||
!std::is_array_v<Base> && !std::is_array_v<Child> &&
|
||||
std::is_base_of_v<Base, Child>,
|
||||
std::unique_ptr<Base>>
|
||||
make_unique_base(Args&&... args) {
|
||||
return std::unique_ptr<Base>(new Child(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
|
||||
inline KernelFunction::KernelFunction()
|
||||
: boxed_kernel_func_()
|
||||
, unboxed_kernel_func_(nullptr)
|
||||
@ -183,7 +194,7 @@ inline KernelFunction KernelFunction::makeFromUnboxedFunction(FuncPtr func_ptr)
|
||||
#if !defined(C10_MOBILE)
|
||||
(void)func_ptr; // Suppress unused variable warning
|
||||
return makeFromUnboxedFunctor<AllowLegacyTypes, typename impl::WrapFunctionIntoFunctor<FuncPtr>::type>(
|
||||
guts::make_unique_base<OperatorKernel, typename impl::WrapFunctionIntoFunctor<FuncPtr>::type>()
|
||||
detail::make_unique_base<OperatorKernel, typename impl::WrapFunctionIntoFunctor<FuncPtr>::type>()
|
||||
);
|
||||
#else
|
||||
// On mobile, we rather want to optimize for binary size than for performance,
|
||||
@ -200,7 +211,7 @@ inline KernelFunction KernelFunction::makeFromUnboxedRuntimeFunction(FuncType* f
|
||||
TORCH_INTERNAL_ASSERT(func != nullptr, "Kernel function cannot be nullptr");
|
||||
|
||||
return makeFromUnboxedFunctor<AllowLegacyTypes, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<FuncType>>>(
|
||||
guts::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<FuncType>>>(func)
|
||||
detail::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<FuncType>>>(func)
|
||||
);
|
||||
}
|
||||
|
||||
@ -210,7 +221,7 @@ inline std::enable_if_t<guts::is_stateless_lambda<std::decay_t<Lambda>>::value,
|
||||
|
||||
#if !defined(C10_MOBILE)
|
||||
return makeFromUnboxedFunctor<AllowLegacyTypes, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(
|
||||
guts::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(std::forward<Lambda>(lambda))
|
||||
detail::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(std::forward<Lambda>(lambda))
|
||||
);
|
||||
#else
|
||||
// On mobile, we rather want to optimize for binary size than for performance,
|
||||
@ -226,7 +237,7 @@ inline std::enable_if_t<!guts::is_stateless_lambda<std::decay_t<Lambda>>::value,
|
||||
static_assert(guts::is_functor<std::decay_t<Lambda>>::value, "Tried to call KernelFunction::makeFromUnboxedLambda with a non-lambda type.");
|
||||
|
||||
return makeFromUnboxedFunctor<AllowLegacyTypes, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(
|
||||
guts::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(std::forward<Lambda>(lambda))
|
||||
detail::make_unique_base<OperatorKernel, impl::WrapFunctionIntoRuntimeFunctor<std::decay_t<Lambda>>>(std::forward<Lambda>(lambda))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <ATen/native/TensorIteratorDynamicCasting.h>
|
||||
#include <ATen/cpu/vec/vec.h>
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
namespace at::native { inline namespace CPU_CAPABILITY {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <ATen/native/cuda/MemoryAccess.cuh>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace at::native {
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <ATen/ops/tensor.h>
|
||||
#endif
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -45,15 +45,6 @@ constexpr bool is_pod_v = is_pod<T>::value;
|
||||
|
||||
namespace guts {
|
||||
|
||||
template <typename Base, typename Child, typename... Args>
|
||||
std::enable_if_t<
|
||||
!std::is_array_v<Base> && !std::is_array_v<Child> &&
|
||||
std::is_base_of_v<Base, Child>,
|
||||
std::unique_ptr<Base>>
|
||||
make_unique_base(Args&&... args) {
|
||||
return std::unique_ptr<Base>(new Child(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
#if defined(__cpp_lib_apply) && !defined(__CUDA_ARCH__) && !defined(__HIP__)
|
||||
|
||||
template <class F, class Tuple>
|
||||
@ -69,21 +60,10 @@ C10_HOST_DEVICE inline constexpr decltype(auto) apply(F&& f, Tuple&& t) {
|
||||
// member functions.
|
||||
namespace detail {
|
||||
template <class F, class Tuple, std::size_t... INDEX>
|
||||
#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<INDEX...>)
|
||||
#else
|
||||
// GCC/Clang need the decltype() return type
|
||||
C10_HOST_DEVICE constexpr decltype(auto) apply_impl(
|
||||
F&& f,
|
||||
Tuple&& t,
|
||||
std::index_sequence<INDEX...>)
|
||||
#endif
|
||||
{
|
||||
std::index_sequence<INDEX...>) {
|
||||
return std::forward<F>(f)(std::get<INDEX>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
} // namespace detail
|
||||
@ -99,44 +79,8 @@ C10_HOST_DEVICE constexpr decltype(auto) apply(F&& f, Tuple&& t) {
|
||||
|
||||
#endif
|
||||
|
||||
template <typename Functor, typename... Args>
|
||||
std::enable_if_t<
|
||||
std::is_member_pointer_v<std::decay_t<Functor>>,
|
||||
typename std::invoke_result_t<Functor, Args...>>
|
||||
invoke(Functor&& f, Args&&... args) {
|
||||
return std::mem_fn(std::forward<Functor>(f))(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename Functor, typename... Args>
|
||||
std::enable_if_t<
|
||||
!std::is_member_pointer_v<std::decay_t<Functor>>,
|
||||
typename std::invoke_result_t<Functor, Args...>>
|
||||
invoke(Functor&& f, Args&&... args) {
|
||||
return std::forward<Functor>(f)(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
struct _identity final {
|
||||
template <class T>
|
||||
using type_identity = T;
|
||||
|
||||
template <class T>
|
||||
decltype(auto) operator()(T&& arg) {
|
||||
return std::forward<T>(arg);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Func, class Enable = void>
|
||||
struct function_takes_identity_argument : std::false_type {};
|
||||
|
||||
template <class Func>
|
||||
struct function_takes_identity_argument<
|
||||
Func,
|
||||
std::void_t<decltype(std::declval<Func>()(_identity()))>> : std::true_type {
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
} // namespace guts
|
||||
|
||||
} // namespace c10
|
||||
|
||||
#endif // C10_UTIL_CPP17_H_
|
||||
|
@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/C++17.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
namespace c10 {
|
||||
|
||||
// custom c10 call_once implementation to avoid the deadlock in std::call_once.
|
||||
@ -47,7 +48,7 @@ class once_flag {
|
||||
if (init_.load(std::memory_order_relaxed)) {
|
||||
return;
|
||||
}
|
||||
c10::guts::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
init_.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ auto wrap_pybind_function_impl_(
|
||||
return [f = std::forward<Func>(f)](Arg<Func, Is>... args) {
|
||||
HANDLE_TH_ERRORS
|
||||
conditional_gil_scoped_release<release_gil> no_gil;
|
||||
return c10::guts::invoke(f, std::forward<Arg<Func, Is>>(args)...);
|
||||
return std::invoke(f, std::forward<Arg<Func, Is>>(args)...);
|
||||
END_HANDLE_TH_ERRORS_PYBIND
|
||||
};
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <c10/util/TypeTraits.h>
|
||||
#include <torch/custom_class_detail.h>
|
||||
#include <torch/library.h>
|
||||
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
namespace torch {
|
||||
@ -117,7 +119,7 @@ class class_ : public ::torch::detail::class_base {
|
||||
c10::tagged_capsule<CurClass> self,
|
||||
ParameterTypes... arg) {
|
||||
c10::intrusive_ptr<CurClass> classObj =
|
||||
at::guts::invoke(func, std::forward<ParameterTypes>(arg)...);
|
||||
std::invoke(func, std::forward<ParameterTypes>(arg)...);
|
||||
auto object = self.ivalue.toObject();
|
||||
object->setSlot(0, c10::IValue::make_capsule(classObj));
|
||||
};
|
||||
@ -325,7 +327,7 @@ class class_ : public ::torch::detail::class_base {
|
||||
c10::tagged_capsule<CurClass> self,
|
||||
SetStateArg arg) {
|
||||
c10::intrusive_ptr<CurClass> classObj =
|
||||
at::guts::invoke(set_state, std::move(arg));
|
||||
std::invoke(set_state, std::move(arg));
|
||||
auto object = self.ivalue.toObject();
|
||||
object->setSlot(0, c10::IValue::make_capsule(classObj));
|
||||
};
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <c10/util/TypeTraits.h>
|
||||
#include <c10/util/irange.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace torch {
|
||||
|
||||
namespace detail {
|
||||
@ -80,7 +82,7 @@ struct WrapMethod<R (CurrClass::*)(Args...)> {
|
||||
WrapMethod(R (CurrClass::*m)(Args...)) : m(std::move(m)) {}
|
||||
|
||||
R operator()(c10::intrusive_ptr<CurrClass> cur, Args... args) {
|
||||
return c10::guts::invoke(m, *cur, args...);
|
||||
return std::invoke(m, *cur, args...);
|
||||
}
|
||||
|
||||
R (CurrClass::*m)(Args...);
|
||||
@ -91,7 +93,7 @@ struct WrapMethod<R (CurrClass::*)(Args...) const> {
|
||||
WrapMethod(R (CurrClass::*m)(Args...) const) : m(std::move(m)) {}
|
||||
|
||||
R operator()(c10::intrusive_ptr<CurrClass> cur, Args... args) {
|
||||
return c10::guts::invoke(m, *cur, args...);
|
||||
return std::invoke(m, *cur, args...);
|
||||
}
|
||||
|
||||
R (CurrClass::*m)(Args...) const;
|
||||
|
Reference in New Issue
Block a user