From f8cf1829b5fb044ca5bcdf179385df75f1902344 Mon Sep 17 00:00:00 2001 From: cyy Date: Sat, 17 Aug 2024 23:09:44 +0000 Subject: [PATCH] [Reland] [11/N] Fix clang-tidy warnings in aten/src/ATen (#133758) Reland of #133298. Remove possible changes that may increase the build time. Pull Request resolved: https://github.com/pytorch/pytorch/pull/133758 Approved by: https://github.com/Skylion007, https://github.com/ezyang --- aten/src/ATen/native/cpu/CatKernel.h | 4 ++-- .../ATen/native/cpu/ChannelShuffleKernel.h | 4 ++-- aten/src/ATen/native/cpu/CopyKernel.h | 2 ++ .../ATen/native/cpu/DistributionTemplates.h | 19 +++++++++---------- aten/src/ATen/native/cpu/GridSamplerKernel.h | 4 ++-- aten/src/ATen/native/cpu/IndexKernelUtils.h | 5 ++--- aten/src/ATen/native/cpu/IsContiguous.h | 4 ++-- aten/src/ATen/native/cpu/LogAddExp.h | 4 ++-- aten/src/ATen/native/cpu/PixelShuffleKernel.h | 4 ++-- aten/src/ATen/native/cpu/SampledAddmmKernel.h | 4 ++-- aten/src/ATen/native/cpu/SerialStackImpl.h | 4 ++-- aten/src/ATen/native/cpu/StackKernel.h | 4 ++-- aten/src/ATen/native/cpu/WeightNormKernel.h | 4 ++-- aten/src/ATen/native/cpu/mixed_data_type.h | 4 ++-- aten/src/ATen/native/cpu/moments_utils.h | 12 ++++-------- aten/src/ATen/native/cpu/utils.h | 7 +++---- aten/src/ATen/native/cpu/zmath.h | 4 ++-- 17 files changed, 44 insertions(+), 49 deletions(-) diff --git a/aten/src/ATen/native/cpu/CatKernel.h b/aten/src/ATen/native/cpu/CatKernel.h index aedb4aec4f5..5afa1add4da 100644 --- a/aten/src/ATen/native/cpu/CatKernel.h +++ b/aten/src/ATen/native/cpu/CatKernel.h @@ -4,9 +4,9 @@ #include #include -namespace at { namespace native { +namespace at::native { using cat_serial_fn = void(*)(const Tensor &, const MaterializedITensorListRef&, int64_t); DECLARE_DISPATCH(cat_serial_fn, cat_serial_stub); -}} // namespace at::native +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/ChannelShuffleKernel.h b/aten/src/ATen/native/cpu/ChannelShuffleKernel.h index 10e592cf59e..387c301c25f 100644 --- a/aten/src/ATen/native/cpu/ChannelShuffleKernel.h +++ b/aten/src/ATen/native/cpu/ChannelShuffleKernel.h @@ -6,9 +6,9 @@ namespace at { class TensorBase; } -namespace at { namespace native { +namespace at::native { using channel_shuffle_fn = void(*)(TensorBase&, const TensorBase&, int64_t); DECLARE_DISPATCH(channel_shuffle_fn, channel_shuffle_kernel); -}} // at::native +} // at::native diff --git a/aten/src/ATen/native/cpu/CopyKernel.h b/aten/src/ATen/native/cpu/CopyKernel.h index 9d2affd6101..3378e16f93d 100644 --- a/aten/src/ATen/native/cpu/CopyKernel.h +++ b/aten/src/ATen/native/cpu/CopyKernel.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace at { struct TensorIteratorBase; diff --git a/aten/src/ATen/native/cpu/DistributionTemplates.h b/aten/src/ATen/native/cpu/DistributionTemplates.h index 961c0a3811e..8171ae8e79a 100644 --- a/aten/src/ATen/native/cpu/DistributionTemplates.h +++ b/aten/src/ATen/native/cpu/DistributionTemplates.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #ifdef CPU_CAPABILITY_AVX2 @@ -15,10 +14,10 @@ #include #endif -namespace at { -namespace native { -namespace templates { -namespace cpu { + + + +namespace at::native::templates::cpu { namespace { // ==================================================== Random ======================================================== @@ -40,10 +39,10 @@ void random_from_to_kernel(TensorIteratorBase& iter, uint64_t range, int64_t bas template void random_full_64_bits_range_kernel(TensorIteratorBase& iter, RNG generator) { AT_DISPATCH_ALL_TYPES_AND(at::ScalarType::BFloat16, iter.dtype(), "random_full_64_bits_range_kernel_cpu", [&] { - if constexpr (std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value) { + if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v) { std::lock_guard lock(generator->mutex_); cpu_serial_kernel(iter, [generator]() -> scalar_t { uniform_int_full_range_distribution random; @@ -423,4 +422,4 @@ struct BernoulliKernel { } }; -}}}}} +}} diff --git a/aten/src/ATen/native/cpu/GridSamplerKernel.h b/aten/src/ATen/native/cpu/GridSamplerKernel.h index b1830fcd391..3d332f88fc7 100644 --- a/aten/src/ATen/native/cpu/GridSamplerKernel.h +++ b/aten/src/ATen/native/cpu/GridSamplerKernel.h @@ -9,7 +9,7 @@ namespace at { class TensorBase; } -namespace at { namespace native { +namespace at::native { using forward_2d_fn = void (*) ( const TensorBase &output, @@ -31,4 +31,4 @@ using backward_2d_fn = void (*) ( DECLARE_DISPATCH(forward_2d_fn, grid_sampler_2d_cpu_kernel); DECLARE_DISPATCH(backward_2d_fn, grid_sampler_2d_backward_cpu_kernel); -}} // namespace at::native +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/IndexKernelUtils.h b/aten/src/ATen/native/cpu/IndexKernelUtils.h index cc19ce995da..876f759e130 100644 --- a/aten/src/ATen/native/cpu/IndexKernelUtils.h +++ b/aten/src/ATen/native/cpu/IndexKernelUtils.h @@ -2,8 +2,7 @@ #include #include -namespace at { -namespace native { +namespace at::native { namespace { static bool is_constant_index(int ntensor, const int64_t* strides) { @@ -85,4 +84,4 @@ void cpu_index_kernel(TensorIteratorBase& iter, IntArrayRef index_size, IntArray } } } // at -} // native +// native diff --git a/aten/src/ATen/native/cpu/IsContiguous.h b/aten/src/ATen/native/cpu/IsContiguous.h index 192177cc9bc..ddbbb6fb8f5 100644 --- a/aten/src/ATen/native/cpu/IsContiguous.h +++ b/aten/src/ATen/native/cpu/IsContiguous.h @@ -1,6 +1,6 @@ #pragma once -namespace at { namespace native { inline namespace CPU_CAPABILITY { +namespace at::native { inline namespace CPU_CAPABILITY { // n: number of function arguments (arity) // traits: function_traits (see FunctionTraits.h) @@ -59,4 +59,4 @@ static inline bool is_contiguous_scalar(const int64_t* strides) { return IsContiguous::eval(strides); } -}}} +}} diff --git a/aten/src/ATen/native/cpu/LogAddExp.h b/aten/src/ATen/native/cpu/LogAddExp.h index c03cbebafaf..e2b80a648df 100644 --- a/aten/src/ATen/native/cpu/LogAddExp.h +++ b/aten/src/ATen/native/cpu/LogAddExp.h @@ -3,7 +3,7 @@ #include #include -namespace at { namespace native { +namespace at::native { inline namespace CPU_CAPABILITY { // custom min and max to be used in logcumsumexp for complex arguments @@ -58,4 +58,4 @@ c10::complex _log_add_exp_helper(const c10::complex& x, cons } } // end namespace -}} //end at::native +} //end at::native diff --git a/aten/src/ATen/native/cpu/PixelShuffleKernel.h b/aten/src/ATen/native/cpu/PixelShuffleKernel.h index c015e674a24..d5eee58c1ab 100644 --- a/aten/src/ATen/native/cpu/PixelShuffleKernel.h +++ b/aten/src/ATen/native/cpu/PixelShuffleKernel.h @@ -5,10 +5,10 @@ namespace at { class TensorBase; } -namespace at { namespace native { +namespace at::native { using pixel_shuffle_fn = void(*)(TensorBase&, const TensorBase&, int64_t); DECLARE_DISPATCH(pixel_shuffle_fn, pixel_shuffle_kernel); DECLARE_DISPATCH(pixel_shuffle_fn, pixel_unshuffle_kernel); -}} // at::native +} // at::native diff --git a/aten/src/ATen/native/cpu/SampledAddmmKernel.h b/aten/src/ATen/native/cpu/SampledAddmmKernel.h index 04dba4b9b61..e1d75b17698 100644 --- a/aten/src/ATen/native/cpu/SampledAddmmKernel.h +++ b/aten/src/ATen/native/cpu/SampledAddmmKernel.h @@ -3,10 +3,10 @@ #include #include -namespace at { namespace native { +namespace at::native { using sampled_addmm_sparse_csr_fn = void(*)(const Tensor&, const Tensor&, const Scalar&, const Scalar&, const Tensor&); DECLARE_DISPATCH(sampled_addmm_sparse_csr_fn, sampled_addmm_sparse_csr_stub); -}} // at::native +} // at::native diff --git a/aten/src/ATen/native/cpu/SerialStackImpl.h b/aten/src/ATen/native/cpu/SerialStackImpl.h index 57d0dd73daf..88ba1c91b6c 100644 --- a/aten/src/ATen/native/cpu/SerialStackImpl.h +++ b/aten/src/ATen/native/cpu/SerialStackImpl.h @@ -10,7 +10,7 @@ #include #include -namespace at { namespace native { namespace detail { +namespace at::native::detail { struct InputMeta { void* data_ptr; @@ -143,4 +143,4 @@ struct CanUseNativeSerialStack { } }; -}}} // namespace at::native::detail +} // namespace at::native::detail diff --git a/aten/src/ATen/native/cpu/StackKernel.h b/aten/src/ATen/native/cpu/StackKernel.h index 4e9a45e4dd1..6c96d83b9ea 100644 --- a/aten/src/ATen/native/cpu/StackKernel.h +++ b/aten/src/ATen/native/cpu/StackKernel.h @@ -4,9 +4,9 @@ #include #include -namespace at { namespace native { +namespace at::native { using stack_serial_fn = void(*)(Tensor &, TensorList, int64_t); DECLARE_DISPATCH(stack_serial_fn, stack_serial_stub); -}} // namespace at::native +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/WeightNormKernel.h b/aten/src/ATen/native/cpu/WeightNormKernel.h index 6e1f3ec3b02..1fd8c75cc73 100644 --- a/aten/src/ATen/native/cpu/WeightNormKernel.h +++ b/aten/src/ATen/native/cpu/WeightNormKernel.h @@ -6,7 +6,7 @@ namespace at { class TensorBase; } -namespace at { namespace native { +namespace at::native { using weight_norm_fn = void(*)( TensorBase&, TensorBase&, const TensorBase&, const TensorBase&, int64_t); @@ -17,4 +17,4 @@ using weight_norm_backward_fn = void(*)( DECLARE_DISPATCH(weight_norm_fn, weight_norm_stub); DECLARE_DISPATCH(weight_norm_backward_fn, weight_norm_backward_stub); -}} // namespace at::native +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/mixed_data_type.h b/aten/src/ATen/native/cpu/mixed_data_type.h index ef598b281a9..13244af3b34 100644 --- a/aten/src/ATen/native/cpu/mixed_data_type.h +++ b/aten/src/ATen/native/cpu/mixed_data_type.h @@ -2,7 +2,7 @@ #include -namespace at { namespace native { +namespace at::native { inline ScalarType first_type() { return ScalarType::Undefined; @@ -38,4 +38,4 @@ inline ScalarType param_scalar_type(const Tensor& t, bool is_mixed_type) { return is_mixed_type ? ScalarType::Float : t.scalar_type(); } -}} // namespace at::native +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/moments_utils.h b/aten/src/ATen/native/cpu/moments_utils.h index f5337f5ff4e..6f403d60ea7 100644 --- a/aten/src/ATen/native/cpu/moments_utils.h +++ b/aten/src/ATen/native/cpu/moments_utils.h @@ -2,9 +2,7 @@ #include #include -#include #include -#include #include #include @@ -13,8 +11,7 @@ #include #include -namespace at { -namespace native { +namespace at::native { inline namespace CPU_CAPABILITY { template using opmath_t = at::opmath_type; @@ -56,7 +53,7 @@ C10_ALWAYS_INLINE void AddMomentsVec( } template -inline typename std::enable_if>::value, void>::type +inline std::enable_if_t>, void> UpdateMomentsVec( int64_t m0, const T* X_ptr, @@ -79,7 +76,7 @@ UpdateMomentsVec( // each bfloat16/half vector will be converted to two float vectors, // and accumulated successively on m1_stk0/m2_stk0. template -inline typename std::enable_if>::value, void>::type +inline std::enable_if_t>, void> UpdateMomentsVec( int64_t m0, const T* X_ptr, @@ -202,5 +199,4 @@ std::pair, opmath_t> RowwiseMoments(const T* X, int64_t N, int64_ } } // namespace CPU_CAPABILITY -} // namespace native -} // namespace at +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/utils.h b/aten/src/ATen/native/cpu/utils.h index bf6af9a1247..e74621bef67 100644 --- a/aten/src/ATen/native/cpu/utils.h +++ b/aten/src/ATen/native/cpu/utils.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -8,8 +9,7 @@ #include #endif -namespace at { -namespace native { +namespace at::native { template inline void _store(T* dst, at::vec::Vectorized src) { @@ -203,5 +203,4 @@ inline void parallel_sparse_csr( } // namespace utils -} // namespace native -} // namespace at +} // namespace at::native diff --git a/aten/src/ATen/native/cpu/zmath.h b/aten/src/ATen/native/cpu/zmath.h index 9b52039e84f..2b4f44db085 100644 --- a/aten/src/ATen/native/cpu/zmath.h +++ b/aten/src/ATen/native/cpu/zmath.h @@ -5,7 +5,7 @@ #include #include -namespace at { namespace native { +namespace at::native { inline namespace CPU_CAPABILITY { template @@ -247,4 +247,4 @@ inline TYPE min_impl (TYPE a, TYPE b) { } } // end namespace -}} //end at::native +} //end at::native