Skip to content

Commit 4c1f50a

Browse files
cyyeverpytorchmergebot
authored andcommitted
Modernize C++ code in aten/src/ATen/ (pytorch#141424)
Clang-tidy modernize checkers were applied, and most changes were concatenation of namespaces. Pull Request resolved: pytorch#141424 Approved by: https://github.com/eqy
1 parent ba5253d commit 4c1f50a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+131
-277
lines changed

aten/src/ATen/core/boxing/impl/boxing.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#include <c10/util/Metaprogramming.h>
1313
#include <type_traits>
1414

15-
namespace c10 {
16-
namespace impl {
15+
namespace c10::impl {
1716

1817
//
1918
// utils
@@ -391,5 +390,4 @@ struct BoxedKernelWrapper<
391390
}
392391
};
393392

394-
} // impl
395393
} // c10

aten/src/ATen/core/op_registration/infer_schema.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace c10 {
66

7-
namespace detail {
8-
namespace infer_schema {
7+
namespace detail::infer_schema {
98
namespace {
109

1110
std::vector<Argument> createArgumentVector(c10::ArrayRef<ArgumentDef> args) {
@@ -40,7 +39,6 @@ FunctionSchema make_function_schema(
4039
c10::ArrayRef<ArgumentDef> returns) {
4140
return make_function_schema("", "", arguments, returns);
4241
}
43-
} // namespace infer_schema
4442
} // namespace detail
4543

4644
std::optional<std::string> findSchemaDifferences(

aten/src/ATen/core/op_registration/infer_schema.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
#include <c10/util/Metaprogramming.h>
1010

1111
namespace c10 {
12-
namespace detail {
13-
14-
namespace infer_schema {
12+
namespace detail::infer_schema {
1513

1614
/// The templated inference code creates `ArgumentDef` instead of `Argument`,
1715
/// because that can be constructed at compile time and has a much smaller
@@ -142,7 +140,6 @@ FunctionSchema createFunctionSchemaFromTraitsSingleReturn(std::string&& name, st
142140
return make_function_schema(std::move(name), std::move(overload_name), arguments, returns);
143141
}
144142

145-
}
146143
}
147144

148145
template<class FuncType>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ATen/cuda/nvrtc_stub/ATenNVRTC.h>
22
#include <iostream>
33

4-
namespace at { namespace cuda {
4+
namespace at::cuda {
55

66
NVRTC* load_nvrtc() {
77
auto self = new NVRTC();
@@ -10,4 +10,4 @@ NVRTC* load_nvrtc() {
1010
return self;
1111
}
1212

13-
}} // at::cuda
13+
} // at::cuda

aten/src/ATen/cuda/nvrtc_stub/ATenNVRTC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <cuda.h>
55
#include <nvrtc.h>
66

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

99

1010
// NOTE [ USE OF NVRTC AND DRIVER API ]
@@ -132,4 +132,4 @@ extern "C" typedef struct NVRTC {
132132
} NVRTC;
133133

134134
extern "C" TORCH_CUDA_CPP_API NVRTC* load_nvrtc();
135-
}} // at::cuda
135+
} // at::cuda

aten/src/ATen/hip/impl/HIPAllocatorMasqueradingAsCUDA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Use of c10::hip namespace here makes hipification easier, because
77
// I don't have to also fix namespaces. Sorry!
8-
namespace c10 { namespace hip {
8+
namespace c10::hip {
99

1010
// Takes a valid HIPAllocator (of any sort) and turns it into
1111
// an allocator pretending to be a CUDA allocator. See
@@ -28,4 +28,4 @@ class HIPAllocatorMasqueradingAsCUDA final : public Allocator {
2828
}
2929
};
3030

31-
}} // namespace c10::hip
31+
} // namespace c10::hip

aten/src/ATen/native/Distributions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ C10_DEVICE scalar_t binomial_inversion(scalar_t count, scalar_t prob, BaseSample
155155

156156
accscalar_t logprob = compat_log1p(-prob);
157157

158-
while (1) {
158+
while (true) {
159159
U = standard_uniform.sample();
160160
accscalar_t geom = compat_ceil(compat_log(U) / logprob);
161161
geom_sum += geom;
@@ -185,7 +185,7 @@ C10_DEVICE scalar_t btrs(scalar_t count, scalar_t prob, BaseSampler<accscalar_t,
185185
const accscalar_t alpha = (2.83 + 5.1 / b) * stddev;
186186
const accscalar_t m = compat_floor((count + 1) * prob);
187187

188-
while (1) {
188+
while (true) {
189189
U = standard_uniform.sample() - 0.5;
190190
V = standard_uniform.sample();
191191

aten/src/ATen/native/PixelShuffle.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <ATen/core/Tensor.h>
22
#include <c10/util/Exception.h>
33

4-
namespace at {
5-
namespace native {
4+
namespace at::native {
65

76
inline void check_pixel_shuffle_shapes(const Tensor& self, int64_t upscale_factor) {
87
TORCH_CHECK(self.dim() >= 3,
@@ -44,4 +43,4 @@ inline void check_pixel_unshuffle_shapes(const Tensor& self, int64_t downscale_f
4443
downscale_factor);
4544
}
4645

47-
}} // namespace at::native
46+
} // namespace at::native

aten/src/ATen/native/SharedReduceOps.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inline C10_DEVICE scalar_t min_propagate_nan(scalar_t a, scalar_t b) {
6363
#define compat_pow std::pow
6464
#endif
6565

66-
namespace at { namespace native {
66+
namespace at::native {
6767

6868
namespace detail {
6969

@@ -539,7 +539,7 @@ struct MinMaxOps {
539539
#endif
540540
};
541541

542-
}} // namespace at::native
542+
} // namespace at::native
543543

544544
#undef MAX
545545
#undef MIN

aten/src/ATen/native/ao_sparse/quantized/cpu/fbgemm_utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <ATen/native/ao_sparse/quantized/cpu/packed_params.h>
99
#include <ATen/native/ao_sparse/quantized/cpu/qnnpack_utils.h>
1010

11-
namespace ao {
12-
namespace sparse {
11+
namespace ao::sparse {
1312
int register_linear_params() {
1413
static auto register_linear_params =
1514
torch::selective_class_<LinearPackedParamsBase>(
@@ -42,4 +41,4 @@ int register_linear_params() {
4241
namespace {
4342
[[maybe_unused]] static auto linear_params = register_linear_params();
4443
} // namespace
45-
}} // namespace ao::sparse
44+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/fbgemm_utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ struct TORCH_API PackedLinearWeight
9090

9191
#endif // USE_FBGEMM
9292

93-
namespace ao {
94-
namespace sparse {
93+
namespace ao::sparse {
9594
int register_linear_params();
96-
}} // namespace ao::sparse
95+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/packed_params.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#include <ATen/core/ivalue.h>
66

7-
namespace ao {
8-
namespace sparse {
7+
namespace ao::sparse {
98

109
// <Weight, bias, out_features_block_size, in_features_block_size>
1110
using LinearPackedSerializationType =
@@ -72,4 +71,4 @@ struct LinearPackedParamsBase : public torch::jit::CustomClassHolder {
7271
const int64_t out_features_block_size_, in_features_block_size_;
7372
};
7473

75-
}} // namespace ao::sparse
74+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <ATen/ops/empty.h>
1616
#endif
1717

18-
namespace ao {
19-
namespace sparse {
18+
namespace ao::sparse {
2019

2120
int register_linear_params();
2221

@@ -257,4 +256,4 @@ TORCH_LIBRARY_IMPL(sparse, QuantizedCPU, m) {
257256
}
258257

259258
} // namespace
260-
}} // namespace ao::sparse
259+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear_deserialize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include <ATen/native/ao_sparse/quantized/cpu/qnnpack_utils.h>
88
#endif
99

10-
namespace ao {
11-
namespace sparse {
10+
namespace ao::sparse {
1211

1312
namespace {
1413
constexpr int64_t serialization_version_index [[maybe_unused]] = 0;
@@ -317,5 +316,4 @@ PackedLinearWeightQnnp::PackedLinearWeightQnnp(
317316
}
318317
#endif // USE_PYTORCH_QNNPACK
319318

320-
} // namespace sparse
321319
} // namespace ao

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear_dynamic.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
#include <ATen/ops/empty.h>
1919
#endif
2020

21-
namespace ao {
22-
namespace sparse {
21+
namespace ao::sparse {
2322

2423
int register_linear_params();
2524

@@ -195,4 +194,4 @@ TORCH_LIBRARY_IMPL(sparse, CPU, m) {
195194
}
196195

197196
} // namespace
198-
}} // namespace ao::sparse
197+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear_prepack.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
#include <algorithm>
2020

21-
namespace ao {
22-
namespace sparse {
21+
namespace ao::sparse {
2322

2423
int register_linear_params();
2524

@@ -246,4 +245,4 @@ TORCH_LIBRARY_IMPL(sparse, QuantizedCPU, m) {
246245
TORCH_FN(QLinearPackWeightInt8::run));
247246
}
248247
} // namespace
249-
}} // namespace ao::sparse
248+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear_serialize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <utility>
1010
#endif
1111

12-
namespace ao {
13-
namespace sparse {
12+
namespace ao::sparse {
1413

1514
namespace {
1615
/**
@@ -245,5 +244,4 @@ BCSRSerializationType PackedLinearWeightQnnp::serialize() {
245244

246245
#endif // USE_PYTORCH_QNNPACK
247246

248-
} // namespace sparse
249247
} // namespace ao

aten/src/ATen/native/ao_sparse/quantized/cpu/qlinear_unpack.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <ATen/ops/from_blob.h>
1616
#endif
1717

18-
namespace ao {
19-
namespace sparse {
18+
namespace ao::sparse {
2019
int register_linear_params();
2120

2221
#ifdef USE_FBGEMM
@@ -139,4 +138,4 @@ TORCH_LIBRARY_IMPL(sparse, CatchAll, m) {
139138
TORCH_FN(QLinearUnpackWeightInt8::run));
140139
}
141140
} // namespace
142-
}} // namespace ao::sparse
141+
} // namespace ao::sparse

aten/src/ATen/native/ao_sparse/quantized/cpu/qnnpack_utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include <pack_block_sparse.h>
1212
#include <ATen/native/ao_sparse/quantized/cpu/packed_params.h>
1313

14-
namespace ao {
15-
namespace sparse {
14+
namespace ao::sparse {
1615

1716
struct TORCH_API PackedLinearWeightQnnp
1817
: public LinearPackedParamsBase {
@@ -87,6 +86,6 @@ struct TORCH_API PackedLinearWeightQnnp
8786
at::Tensor apply_dynamic_impl(const at::Tensor& input);
8887
};
8988

90-
}} // namespace ao::sparse
89+
} // namespace ao::sparse
9190

9291
#endif // USE_PYTORCH_QNNPACK

aten/src/ATen/native/cuda/Activation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct TensorIteratorBase;
77
class TensorBase;
88
}
99

10-
namespace at { namespace native {
10+
namespace at::native {
1111

1212
void launch_glu_backward_kernel(const TensorIteratorBase& iter,
1313
int64_t gI_stride, int64_t I_stride);
@@ -17,4 +17,4 @@ void launch_log_sigmoid_forward_kernel(TensorIteratorBase& iter);
1717
void GeluCUDAKernelImpl(TensorIteratorBase& it, GeluType approximate);
1818
void GeluBackwardCUDAKernelImpl(TensorIteratorBase& it, GeluType approximate);
1919

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

aten/src/ATen/native/cuda/GridSampler.h

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

9-
namespace at {
10-
namespace native {
9+
namespace at::native {
1110

1211
void launch_grid_sampler_2d_forward_kernel(
1312
const TensorBase &output, const TensorBase &input, const TensorBase &grid,
@@ -29,4 +28,4 @@ void launch_grid_sampler_3d_backward_kernel(
2928
const TensorBase &grid, int64_t interpolation_mode, int64_t padding_mode,
3029
bool align_corners, std::array<bool, 2> output_mask);
3130

32-
}} // namespace at::native
31+
} // namespace at::native

aten/src/ATen/native/cuda/IndexKernel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ struct TensorIteratorBase;
77
class TensorBase;
88
}
99

10-
namespace at {
11-
namespace native {
10+
namespace at::native {
1211
/// @param maskPrefixSum[in,out]
1312
void launch_masked_scatter_kernel(
1413
const TensorBase &self, const TensorBase &mask,
1514
const TensorBase &maskPrefixSum, const TensorBase &source);
16-
}}
15+
}

aten/src/ATen/native/cuda/ReduceOps.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace c10 {
77
class Scalar;
88
}
99

10-
namespace at { namespace native {
10+
namespace at::native {
1111

1212
void norm_launch_kernel(TensorIterator &iter, double val);
1313
void min_launch_kernel(TensorIterator &iter);
@@ -17,4 +17,4 @@ void min_all_launch_kernel(TensorIterator &iter);
1717
void max_all_launch_kernel(TensorIterator &iter);
1818
void aminmax_allreduce_launch_kernel(TensorIterator &iter);
1919

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

aten/src/ATen/native/cuda/Sorting.h

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

8-
namespace at {
9-
namespace native {
8+
namespace at::native {
109

1110
void launch_kthvalue_kernel(
1211
const TensorBase &values, const TensorBase &indices,
@@ -15,4 +14,4 @@ void launch_median_kernel(
1514
const TensorBase &vals, const TensorBase &inds,
1615
const TensorBase &in, int64_t dim, bool ignore_nan);
1716

18-
}} // namespace at::native
17+
} // namespace at::native

aten/src/ATen/native/cuda/TensorModeKernel.h

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

8-
namespace at {
9-
namespace native {
8+
namespace at::native {
109

1110
void launch_fused_mode_kernel(
1211
const TensorBase &values, const TensorBase &indices,
@@ -16,4 +15,4 @@ void launch_apply_mode_kernel(
1615
const TensorBase &values, const TensorBase &indices,
1716
const TensorBase &self, int64_t dim, int64_t ndim);
1817

19-
}} // namespace at::native
18+
} // namespace at::native

0 commit comments

Comments
 (0)