Skip to content

Commit 3a66a1c

Browse files
malfetfacebook-github-bot
authored andcommitted
[clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (pytorch#57841)
Summary: Add cppcoreguidelines-avoid-magic-numbers exclusion to clang-tidy Remove existing nolint warnings using following script: ``` for file in `git ls-files | grep -v \.py`; do gsed '/^ *\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)/d' -i $file; done ``` Pull Request resolved: pytorch#57841 Reviewed By: samestep Differential Revision: D28295045 Pulled By: malfet fbshipit-source-id: 7c6e8d1213c9593f169ed3df6a916498f1a97163
1 parent bc2540f commit 3a66a1c

File tree

458 files changed

+1
-9602
lines changed

Some content is hidden

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

458 files changed

+1
-9602
lines changed

.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bugprone-*,
88
-bugprone-lambda-function-name,
99
-bugprone-reserved-identifier,
1010
cppcoreguidelines-*,
11+
-cppcoreguidelines-avoid-magic-numbers,
1112
-cppcoreguidelines-interfaces-global-init,
1213
-cppcoreguidelines-macro-usage,
1314
-cppcoreguidelines-owning-memory,

aten/src/ATen/CPUGeneratorImpl.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Generator createCPUGenerator(uint64_t seed_val) {
7171
* and return them as a 64 bit unsigned int
7272
*/
7373
inline uint64_t make64BitsFrom32Bits(uint32_t hi, uint32_t lo) {
74-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7574
return (static_cast<uint64_t>(hi) << 32) | lo;
7675
}
7776

@@ -157,7 +156,6 @@ void CPUGeneratorImpl::set_state(const c10::TensorImpl& new_state) {
157156
// intermediate values.
158157
if (legacy_pod->normal_is_valid) {
159158
auto r = legacy_pod->normal_rho;
160-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
161159
auto theta = 2.0 * c10::pi<double> * legacy_pod->normal_x;
162160
// we return the sin version of the normal sample when in caching mode
163161
double_normal_sample = c10::optional<double>(r * ::sin(theta));

aten/src/ATen/Context.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ bool Context::checkCuBLASConfigDeterministic() {
101101
bool cublas_config_deterministic = true;
102102
// If using CUDA 10.2 or greater, need to make sure CuBLAS workspace config
103103
// is set to deterministic setting
104-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
105104
if (hasCUDART() && (versionCUDART() >= 10020)) {
106105
char* workspace_config = std::getenv(cublas_config_var_name);
107106
cublas_config_deterministic = (workspace_config != nullptr) && (
@@ -277,7 +276,6 @@ void Context::setDefaultMobileCPUAllocator() {
277276
"Cannot set another allocator.");
278277
// Setting the priority high to make sure no other allocator gets used instead of this.
279278
prev_allocator_ptr_ = c10::GetCPUAllocator();
280-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
281279
c10::SetCPUAllocator(c10::GetDefaultMobileCPUAllocator(), /*priority*/ 100);
282280
}
283281

@@ -286,7 +284,6 @@ void Context::unsetDefaultMobileCPUAllocator() {
286284
"setDefaultMobileCPUAllocator must have been called "
287285
"before unsetDefaultMobileCPUAllocator.");
288286
// Setting the priority high to make sure no other allocator gets used instead of this.
289-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
290287
c10::SetCPUAllocator(prev_allocator_ptr_ , /*priority*/ 100);
291288
prev_allocator_ptr_ = nullptr;
292289
}

aten/src/ATen/DLConvertor.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace at {
1010
DLDataType getDLDataType(const Tensor& t) {
1111
DLDataType dtype;
1212
dtype.lanes = 1;
13-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
1413
dtype.bits = t.element_size() * 8;
1514
switch (t.scalar_type()) {
1615
case ScalarType::Byte:
@@ -126,7 +125,6 @@ ScalarType toScalarType(const DLDataType& dtype) {
126125
switch (dtype.code) {
127126
case DLDataTypeCode::kDLUInt:
128127
switch (dtype.bits) {
129-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
130128
case 8:
131129
stype = ScalarType::Byte;
132130
break;
@@ -137,19 +135,15 @@ ScalarType toScalarType(const DLDataType& dtype) {
137135
break;
138136
case DLDataTypeCode::kDLInt:
139137
switch (dtype.bits) {
140-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
141138
case 8:
142139
stype = ScalarType::Char;
143140
break;
144-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
145141
case 16:
146142
stype = ScalarType::Short;
147143
break;
148-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
149144
case 32:
150145
stype = ScalarType::Int;
151146
break;
152-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
153147
case 64:
154148
stype = ScalarType::Long;
155149
break;
@@ -160,15 +154,12 @@ ScalarType toScalarType(const DLDataType& dtype) {
160154
break;
161155
case DLDataTypeCode::kDLFloat:
162156
switch (dtype.bits) {
163-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
164157
case 16:
165158
stype = ScalarType::Half;
166159
break;
167-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
168160
case 32:
169161
stype = ScalarType::Float;
170162
break;
171-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
172163
case 64:
173164
stype = ScalarType::Double;
174165
break;

aten/src/ATen/SparseTensorUtils.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Tensor coo_to_csr(const int64_t* indices, int64_t dim, int64_t nnz) {
9595
if (nnz > 0) {
9696
auto csr_accessor = csr.accessor<int64_t, 1>();
9797
// Convert the sparse matrix to CSR format
98-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
9998
at::parallel_for(0, nnz, 10000, [&](int64_t start, int64_t end) {
10099
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
101100
int64_t h, hp0, hp1;

aten/src/ATen/benchmarks/quantize_per_channel.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ static void quantize_per_channel_4d_contiguous(benchmark::State& state) {
1212
at::Tensor a = at::rand({batches, channels, height, width});
1313
at::Tensor scales = at::rand({channels});
1414
at::Tensor zero_points = at::randint(
15-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
1615
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int));
1716

1817
at::Tensor qa;
@@ -33,7 +32,6 @@ static void quantize_per_channel_4d_channels_last(benchmark::State& state) {
3332
at::TensorOptions().memory_format(at::MemoryFormat::ChannelsLast));
3433
at::Tensor scales = at::rand({channels});
3534
at::Tensor zero_points = at::randint(
36-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
3735
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int));
3836

3937
at::Tensor qa;
@@ -50,7 +48,6 @@ static void quantize_per_channel_2d(benchmark::State& state) {
5048
at::Tensor a = at::rand({channels, nelem});
5149
at::Tensor scales = at::rand({channels});
5250
at::Tensor zero_points = at::randint(
53-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
5451
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int));
5552

5653
at::Tensor qa;
@@ -63,11 +60,8 @@ static void quantize_per_channel_2d(benchmark::State& state) {
6360
static void GenerateSizes4d(benchmark::internal::Benchmark* b) {
6461
b->ArgNames({"N", "C", "H", "W"});
6562

66-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
6763
for (size_t n = 16; n < 256; n *= 2) {
68-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
6964
for (size_t c = 4; c < 256; c *= 2) {
70-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7165
for (size_t hw = 4; hw < 256; hw *= 2) {
7266
b->Args({n, c, hw, hw});
7367
}
@@ -78,9 +72,7 @@ static void GenerateSizes4d(benchmark::internal::Benchmark* b) {
7872
static void GenerateSizes2d(benchmark::internal::Benchmark* b) {
7973
b->ArgNames({"C", "N"});
8074

81-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
8275
for (size_t c = 4; c < 512; c *= 2) {
83-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
8476
for (size_t n = 4; n < 512; n *= 2) {
8577
b->Args({c, n});
8678
}

aten/src/ATen/benchmarks/stateful_conv1d.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static void stateful_conv1d(benchmark::State& state) {
3333
)");
3434

3535
std::vector<std::vector<torch::jit::IValue>> inputs;
36-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
3736
for (int i = 0; i < 10; ++i) {
3837
std::vector<torch::jit::IValue> input;
3938
// NOLINTNEXTLINE(modernize-use-emplace)
@@ -69,15 +68,10 @@ static void GenerateSizes(benchmark::internal::Benchmark* b) {
6968
"Width",
7069
"Optimized"});
7170

72-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7371
for (size_t input_channels = 32; input_channels < 256; input_channels *= 2) {
74-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7572
for (size_t output_channels = 32; output_channels < 256; output_channels *= 2) {
76-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7773
for (size_t kernel = 3; kernel < 8; ++kernel) {
78-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
7974
for (size_t batch_size = 1; batch_size < 5; ++batch_size) {
80-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
8175
for (size_t width = 32; width < 256; width *= 2) {
8276
b->Args({input_channels, output_channels, kernel, batch_size, width, true});
8377
b->Args({input_channels, output_channels, kernel, batch_size, width, false});

aten/src/ATen/benchmarks/tensor_add.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ static void tensor_add(benchmark::State& state) {
1717
static void GenerateSizes(benchmark::internal::Benchmark* b) {
1818
b->ArgNames({"N", "C"});
1919

20-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
2120
for (size_t n = 8; n < 1024;) {
22-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
2321
for (size_t c = 8; c < 1024;) {
2422
b->Args({n, c});
2523
c *= 2;

aten/src/ATen/core/Formatting.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ static std::tuple<double, int64_t> __printFormat(std::ostream& stream, const Ten
9696
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
9797
int64_t sz;
9898
if(intMode) {
99-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
10099
if(expMax > 9) {
101-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
102100
sz = 11;
103101
stream << std::scientific << std::setprecision(4);
104102
} else {
@@ -107,27 +105,20 @@ static std::tuple<double, int64_t> __printFormat(std::ostream& stream, const Ten
107105
}
108106
} else {
109107
if(expMax-expMin > 4) {
110-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
111108
sz = 11;
112-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
113109
if(std::fabs(expMax) > 99 || std::fabs(expMin) > 99) {
114110
sz = sz + 1;
115111
}
116112
stream << std::scientific << std::setprecision(4);
117113
} else {
118-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
119114
if(expMax > 5 || expMax < 0) {
120-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
121115
sz = 7;
122-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
123116
scale = std::pow(10, expMax-1);
124117
stream << std::fixed << std::setprecision(4);
125118
} else {
126119
if(expMax == 0) {
127-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
128120
sz = 7;
129121
} else {
130-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
131122
sz = expMax+6;
132123
}
133124
stream << std::fixed << std::setprecision(4);

0 commit comments

Comments
 (0)