Skip to content

Commit d46e076

Browse files
Revert "[11/N] Fix clang-tidy warnings in aten/src/ATen (pytorch#133298)"
This reverts commit 3578598. Reverted pytorch#133298 on behalf of https://github.com/izaitsevfb due to causes build time regression in aten/src/ATen/native/cpu/ReduceOpsKernel.cpp ([comment](pytorch#133298 (comment)))
1 parent 07c73a9 commit d46e076

19 files changed

+67
-59
lines changed

aten/src/ATen/native/cpu/CatKernel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <ATen/native/DispatchStub.h>
55
#include <ATen/core/IListRef.h>
66

7-
namespace at::native {
7+
namespace at { namespace native {
88

99
using cat_serial_fn = void(*)(const Tensor &, const MaterializedITensorListRef&, int64_t);
1010
DECLARE_DISPATCH(cat_serial_fn, cat_serial_stub);
1111

12-
} // namespace at::native
12+
}} // namespace at::native

aten/src/ATen/native/cpu/ChannelShuffleKernel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace at {
66
class TensorBase;
77
}
88

9-
namespace at::native {
9+
namespace at { namespace native {
1010

1111
using channel_shuffle_fn = void(*)(TensorBase&, const TensorBase&, int64_t);
1212
DECLARE_DISPATCH(channel_shuffle_fn, channel_shuffle_kernel);
1313

14-
} // at::native
14+
}} // at::native

aten/src/ATen/native/cpu/CopyKernel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <ATen/native/TensorIterator.h>
4-
53
namespace at {
64
struct TensorIteratorBase;
75

aten/src/ATen/native/cpu/DistributionTemplates.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
#include <ATen/core/DistributionsHelper.h>
88
#include <ATen/native/TensorIterator.h>
99
#include <ATen/native/cpu/Loops.h>
10+
#include <limits>
1011
#include <mutex>
1112

1213
#ifdef CPU_CAPABILITY_AVX2
1314
#include <ATen/native/cpu/avx_mathfun.h>
1415
#include <c10/util/irange.h>
1516
#endif
1617

17-
18-
19-
20-
namespace at::native::templates::cpu {
18+
namespace at {
19+
namespace native {
20+
namespace templates {
21+
namespace cpu {
2122
namespace {
2223

2324
// ==================================================== Random ========================================================
@@ -39,10 +40,10 @@ void random_from_to_kernel(TensorIteratorBase& iter, uint64_t range, int64_t bas
3940
template<typename RNG>
4041
void random_full_64_bits_range_kernel(TensorIteratorBase& iter, RNG generator) {
4142
AT_DISPATCH_ALL_TYPES_AND(at::ScalarType::BFloat16, iter.dtype(), "random_full_64_bits_range_kernel_cpu", [&] {
42-
if constexpr (std::is_same_v<scalar_t, int64_t> ||
43-
std::is_same_v<scalar_t, double> ||
44-
std::is_same_v<scalar_t, float> ||
45-
std::is_same_v<scalar_t, at::BFloat16>) {
43+
if constexpr (std::is_same<scalar_t, int64_t>::value ||
44+
std::is_same<scalar_t, double>::value ||
45+
std::is_same<scalar_t, float>::value ||
46+
std::is_same<scalar_t, at::BFloat16>::value) {
4647
std::lock_guard<std::mutex> lock(generator->mutex_);
4748
cpu_serial_kernel(iter, [generator]() -> scalar_t {
4849
uniform_int_full_range_distribution<scalar_t> random;
@@ -422,4 +423,4 @@ struct BernoulliKernel {
422423
}
423424
};
424425

425-
}}
426+
}}}}}

aten/src/ATen/native/cpu/GridSamplerKernel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace at {
99
class TensorBase;
1010
}
1111

12-
namespace at::native {
12+
namespace at { namespace native {
1313

1414
using forward_2d_fn = void (*) (
1515
const TensorBase &output,
@@ -31,4 +31,4 @@ using backward_2d_fn = void (*) (
3131
DECLARE_DISPATCH(forward_2d_fn, grid_sampler_2d_cpu_kernel);
3232
DECLARE_DISPATCH(backward_2d_fn, grid_sampler_2d_backward_cpu_kernel);
3333

34-
} // namespace at::native
34+
}} // namespace at::native

aten/src/ATen/native/cpu/IndexKernelUtils.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include <ATen/native/TensorIterator.h>
33
#include <c10/util/irange.h>
44

5-
namespace at::native {
5+
namespace at {
6+
namespace native {
67

7-
inline bool is_constant_index(int ntensor, const int64_t* strides) {
8+
namespace {
9+
static bool is_constant_index(int ntensor, const int64_t* strides) {
810
AT_ASSERT(ntensor >= 3);
911
for (const auto arg : c10::irange(2, ntensor)) {
1012
if (strides[arg] != 0) {
@@ -48,6 +50,7 @@ struct Indexer {
4850
return offset;
4951
}
5052
};
53+
} // anonymous namespace
5154

5255
template <typename scalar_t, typename func_t>
5356
void cpu_index_kernel(TensorIteratorBase& iter, IntArrayRef index_size, IntArrayRef index_stride,
@@ -82,4 +85,4 @@ void cpu_index_kernel(TensorIteratorBase& iter, IntArrayRef index_size, IntArray
8285
}
8386
}
8487
} // at
85-
// native
88+
} // native

aten/src/ATen/native/cpu/IsContiguous.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
namespace at::native { inline namespace CPU_CAPABILITY {
3+
namespace at { namespace native { inline namespace CPU_CAPABILITY {
44

55
// n: number of function arguments (arity)
66
// traits: function_traits (see FunctionTraits.h)
@@ -59,4 +59,4 @@ static inline bool is_contiguous_scalar(const int64_t* strides) {
5959
return IsContiguous<traits::arity, traits::arity, traits, s>::eval(strides);
6060
}
6161

62-
}}
62+
}}}

aten/src/ATen/native/cpu/LogAddExp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <c10/util/complex.h>
44
#include <ATen/NumericUtils.h>
55

6-
namespace at::native {
6+
namespace at { namespace native {
77
inline namespace CPU_CAPABILITY {
88

99
// custom min and max to be used in logcumsumexp for complex arguments
@@ -58,4 +58,4 @@ c10::complex<scalar_t> _log_add_exp_helper(const c10::complex<scalar_t>& x, cons
5858
}
5959

6060
} // end namespace
61-
} //end at::native
61+
}} //end at::native

aten/src/ATen/native/cpu/PixelShuffleKernel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace at {
55
class TensorBase;
66
}
77

8-
namespace at::native {
8+
namespace at { namespace native {
99

1010
using pixel_shuffle_fn = void(*)(TensorBase&, const TensorBase&, int64_t);
1111
DECLARE_DISPATCH(pixel_shuffle_fn, pixel_shuffle_kernel);
1212
DECLARE_DISPATCH(pixel_shuffle_fn, pixel_unshuffle_kernel);
1313

14-
} // at::native
14+
}} // at::native

aten/src/ATen/native/cpu/Reduce.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include <c10/core/Scalar.h>
77
#include <c10/util/irange.h>
88

9+
#include <sstream>
910
#include <type_traits>
1011

11-
namespace at::native { inline namespace CPU_CAPABILITY {
12+
namespace at { namespace native { inline namespace CPU_CAPABILITY {
1213

1314
using namespace vec;
1415

@@ -33,9 +34,9 @@ inline bool is_outer_reduction(const int64_t* strides) {
3334
strides[3] == sizeof(typename traits::arg2_t);
3435
}
3536

36-
template <typename func_t, typename vec_func_t, bool reduce>
37+
template <typename func_t, typename vec_func_t>
3738
inline void vectorized_reduction(char** data, int64_t n, int64_t stride,
38-
func_t op [[maybe_unused]], vec_func_t vop) {
39+
func_t op, vec_func_t vop, bool reduce) {
3940
VEC_LOOP_HEADER(func_t, data)
4041
const char* in1_ptr = data[1];
4142
Vec acc[4];
@@ -49,7 +50,7 @@ inline void vectorized_reduction(char** data, int64_t n, int64_t stride,
4950
acc[2] = vop(acc[2], Vec::loadu(ptr + (2 * Vec::size() * sizeof(scalar_t))));
5051
acc[3] = vop(acc[3], Vec::loadu(ptr + (3 * Vec::size() * sizeof(scalar_t))));
5152
}
52-
if constexpr (reduce) {
53+
if (reduce) {
5354
scalar_t buffer[Vec::size()];
5455
acc[0] = vop(vop(acc[0], acc[1]), vop(acc[2], acc[3]));
5556
acc[0].store(buffer);
@@ -80,10 +81,10 @@ inline void UNARY_OUTER_LOOP(char* data[2], const int64_t strides[2], int64_t n,
8081
template <typename func_t, typename vec_func_t>
8182
inline void vectorized_inner_reduction(char** data, int64_t n, func_t op, vec_func_t vop) {
8283
VEC_LOOP_HEADER(func_t, data)
83-
constexpr int64_t vector_stride = 4 * Vec::size() * sizeof(scalar_t);
84+
int64_t vector_stride = 4 * Vec::size() * sizeof(scalar_t);
8485
int64_t count = n / (4 * Vec::size());
8586
if (count > 0) {
86-
vectorized_reduction<func_t, vec_func_t, true>(data, count, vector_stride, op, vop);
87+
vectorized_reduction(data, count, vector_stride, op, vop, /*reduce=*/true);
8788
}
8889
char* ptrs[3] = { data[0], data[0], data[1] };
8990
int64_t strides[] = { 0, 0, sizeof(scalar_t) };
@@ -102,7 +103,7 @@ inline void vectorized_outer_reduction(char** data, int64_t inner_stride, int64_
102103
int64_t outer_stride[2] = { 128, 128 };
103104
#endif
104105
UNARY_OUTER_LOOP(data, outer_stride, size1 / (4 * Vec::size()), [&] {
105-
vectorized_reduction<func_t, vec_func_t, false>(data, size0, inner_stride, op, vop);
106+
vectorized_reduction(data, size0, inner_stride, op, vop, /*reduce=*/false);
106107
});
107108

108109
// reduce down the remaining columns
@@ -131,13 +132,13 @@ static void set_results(const res_t result, const TensorIteratorBase &iter, cons
131132
}
132133

133134
template<typename traits, std::size_t i = 0, typename... tuple_t>
134-
inline std::enable_if_t<i == sizeof...(tuple_t), std::size_t>
135+
inline typename std::enable_if<i == sizeof...(tuple_t), std::size_t>::type
135136
for_each_in_tuple(const std::tuple<tuple_t...>& /*t*/, const TensorIteratorBase& /*iter*/, const int /*num_outputs*/) {
136137
return i;
137138
}
138139

139140
template<typename traits, std::size_t i = 0, typename... tuple_t>
140-
inline std::enable_if_t<i < sizeof...(tuple_t), std::size_t>
141+
inline typename std::enable_if<i < sizeof...(tuple_t), std::size_t>::type
141142
for_each_in_tuple(const std::tuple<tuple_t...>& t, const TensorIteratorBase &iter, const int num_outputs) {
142143
if (i < (size_t)num_outputs) {
143144
set_result<traits>(i, std::get<i>(t), iter, num_outputs);
@@ -310,4 +311,4 @@ void binary_kernel_reduce_lastdim(TensorIteratorBase& iter, reduce_func_t reduce
310311
sub_iter.for_each(loop, grain_size);
311312
}
312313

313-
}} // namespace at::native::<anonymous>
314+
}}} // namespace at::native::<anonymous>

0 commit comments

Comments
 (0)