8000 [10/N] Fix extra warnings brought by clang-tidy-17 (#139385) · pytorch/pytorch@7f387fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f387fa

Browse files
cyyeverpytorchmergebot
authored andcommitted
[10/N] Fix extra warnings brought by clang-tidy-17 (#139385)
Fixes #ISSUE_NUMBER Pull Request resolved: #139385 Approved by: https://github.com/Skylion007
1 parent 3242049 commit 7f387fa

21 files changed

+53
-43
lines changed

.lintrunner.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ exclude_patterns = [
224224
'**/fb/**',
225225
'**/generated/**',
226226
'**/*pb.h',
227+
'**/*inl.h',
228+
'aten/src/ATen/CPUFixedAllocator.h',
229+
'aten/src/ATen/Parallel*.h',
227230
'c10/xpu/**/*.h',
228231
'c10/xpu/**/*.cpp',
229232
'c10/benchmark/intrusive_ptr_benchmark.cpp',
@@ -236,15 +239,12 @@ exclude_patterns = [
236239
'c10/util/strong_type.h',
237240
'c10/util/SmallVector.h',
238241
'c10/util/win32-headers.h',
239-
'c10/util/*inl.h',
240242
'c10/test/**/*.h',
241243
'third_party/**/*',
242244
'torch/csrc/api/include/torch/nn/modules/common.h',
243245
'torch/csrc/api/include/torch/linalg.h',
244-
'torch/csrc/api/include/torch/nn/pimpl-inl.h',
245246
'torch/csrc/autograd/generated/**',
246247
'torch/csrc/distributed/**/*.cu',
247-
'torch/csrc/distributed/c10d/CUDASymmetricMemory-inl.h',
248248
'torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp',
249249
'torch/csrc/distributed/c10d/WinSockUtils.hpp',
250250
'torch/csrc/distributed/c10d/quantization/quantization_gpu.h',
@@ -253,7 +253,6 @@ exclude_patterns = [
253253
'torch/csrc/jit/**/*',
254254
'torch/csrc/jit/serialization/mobile_bytecode_generated.h',
255255
'torch/csrc/utils/pythoncapi_compat.h',
256-
'torch/csrc/utils/throughput_benchmark-inl.h',
257256
]
258257
init_command = [
259258
'python3',

aten/src/ATen/Version.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ std::string get_mkl_version() {
2424
{
2525
// Magic buffer number is from MKL documentation
2626
// https://software.intel.com/en-us/mkl-developer-reference-c-mkl-get-version-string
27-
char buf[198];
28-
mkl_get_version_string(buf, 198);
29-
version = buf;
27+
version.resize(198,'\0');
28+
mkl_get_version_string(version.data(), 198);
29+
version.resize(strlen(version.c_str()));
3030
}
3131
#else
3232
version = "MKL not found";

aten/src/ATen/WrapDimUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline int64_t maybe_wrap_dim(
3535
// if necessary
3636
return dim;
3737
}
38-
return maybe_wrap_dim(dim, tensor_sizes[0].size());
38+
return maybe_wrap_dim(dim, static_cast<int64_t>(tensor_sizes[0].size()));
3939
}
4040

4141
// Given an array of dimensions `dims` of length `ndims`, this function "Wraps"

aten/src/ATen/core/ivalue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ struct TORCH_API IValue final {
13601360
Payload(Payload&&) = delete;
13611361
Payload& operator=(const Payload&) = delete;
13621362
Payload& operator=(Payload&&) = delete;
1363+
// NOLINTNEXTLINE(modernize-use-equals-default)
13631364
~Payload() {}
13641365
};
13651366

aten/src/ATen/cpu/vml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ static_assert(
108108
#define IMPLEMENT_VML_MKL_STUB(op, mklop, type, mkltype) \
109109
template <> \
110110
inline void v##op(type * out, const type * in, int64_t size) { \
111-
int64_t max_mkl_ind = std::numeric_limits<MKL_INT>::max(); \
111+
auto constexpr max_mkl_ind = std::numeric_limits<MKL_INT>::max(); \
112112
if (size <= static_cast<int64_t>(max_mkl_ind)) { \
113113
vm##mkltype##mklop( \
114114
size, in, out, VML_HA | VML_FTZDAZ_OFF | VML_ERRMODE_IGNORE); \
115115
} else { \
116-
MKL_INT ind = 0; \
116+
int64_t ind = 0; \
117117
int64_t chunks = size / max_mkl_ind; \
118118
int64_t rest = size % max_mkl_ind; \
119119
for (; ind < chunks; ind++) { \

aten/src/ATen/cuda/CUDAGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct TORCH_CUDA_CPP_API CUDAGraph {
8282
// in a capture to run on the same device, but this is a limitation of CUDAGraph,
8383
// not CUDA itself. We can straightforwardly modify CUDAGraph to support multi-device
8484
// captures if needed.
85-
int capture_dev_{};
85+
c10::DeviceIndex capture_dev_{};
8686
};
8787

8888
} // namespace cuda

aten/src/ATen/cuda/CachingHostAllocator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct CUDACachingHostAllocatorImpl
9898
pinned_use_cuda_host_register()) {
9999
void* ptr = block->ptr_;
100100
AT_CUDA_CHECK(cudaHostUnregister(ptr));
101+
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
101102
std::free(ptr);
102103
} else {
103104
AT_CUDA_CHECK(cudaFreeHost(block->ptr_));
@@ -136,8 +137,8 @@ struct CUDACachingHostAllocatorImpl
136137

137138
TaskThreadPool* getThreadPool() {
138139
static TaskThreadPool* pool = new TaskThreadPool(
139-
c10::cuda::CUDACachingAllocator::CUDAAllocatorConfig::
140-
pinned_max_register_threads());
140+
static_cast<int>(c10::cuda::CUDACachingAllocator::CUDAAllocatorConfig::
141+
pinned_max_register_threads()));
141142
return pool;
142143
}
143144

@@ -157,6 +158,7 @@ struct CUDACachingHostAllocatorImpl
157158
uintptr_t alignedStart =
158159
(((uintptr_t)start + pageSize - 1) & ~(pageSize - 1));
159160
for (uintptr_t p = alignedStart; p < ((uintptr_t)end); p += pageSize) {
161+
// NOLINTNEXTLINE(performance-no-int-to-ptr)
160162
memset((void*)p, 0, 1);
161163
}
162164
}
@@ -180,6 +182,7 @@ struct CUDACachingHostAllocatorImpl
180182
// Here we do regular allocation, pre-fault/map the pages, and then do
181183
// cudaHostRegister with GPU mapping flags to lock the pages, so we
182184
// can minimize the cost for the cuda global lock.
185+
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
183186
*ptr = std::malloc(roundSize);
184187

185188
// Parallelize the mapping/registering of pages to reduce wall time

aten/src/ATen/cuda/tunable/GemmCommon.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ static bool NumericalCheck(ScalarType dtype, void* c, void* other_c, int64_t siz
8282

8383
template <typename T>
8484
struct GemmParams : OpParams {
85-
GemmParams() {
86-
duplicate_inputs_ = false;
87-
}
85+
GemmParams() = default;
8886

8987
std::string Signature() const override {
9088
return fmt::sprintf("%c%c_%ld_%ld_%ld", transa, transb, m, n, k);
@@ -140,7 +138,9 @@ struct GemmParams : OpParams {
140138
void Delete() {
141139
c10::cuda::CUDACachingAllocator::raw_delete(c);
142140
if (duplicate_inputs_) {
141+
// NOLINTNEXTLINE(*const-cast*)
143142
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<T*>(a));
143+
// NOLINTNEXTLINE(*const-cast*)
144144
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<T*>(b));
145145
}
146146
}
@@ -164,7 +164,7 @@ struct GemmParams : OpParams {
164164
T* c;
165165
int64_t ldc;
166166
private:
167-
bool duplicate_inputs_;
167+
bool duplicate_inputs_{false};
168168
};
169169

170170
template <typename T>
@@ -248,14 +248,14 @@ struct GemmAndBiasParams : OpParams {
248248
const T* bias;
249249
at::cuda::blas::GEMMAndBiasActivationEpilogue activation;
250250
private:
251-
bool duplicate_inputs_;
251+
bool duplicate_inputs_{false};
252252
};
253253

254254
template <typename T>
255255
struct GemmStridedBatchedParams : OpParams {
256-
GemmStridedBatchedParams() {
257-
duplicate_inputs_ = false;
258-
}
256+
GemmStridedBatchedParams() = default;
257+
GemmStridedBatchedParams(const GemmStridedBatchedParams&) = default;
258+
GemmStridedBatchedParams& operator=(const GemmStridedBatchedParams&) = default;
259259

260260
std::string Signature() const override {
261261
return fmt::sprintf("%c%c_%ld_%ld_%ld_B_%ld", transa, transb, m, n, k, batch);
@@ -300,7 +300,9 @@ struct GemmStridedBatchedParams : OpParams {
300300
if (duplicate_inputs) {
301301
size_t a_size = GetSizeA();
302302
size_t b_size = GetSizeB();
303+
// NOLINTNEXTLINE(*const-cast*)
303304
copy->a = static_cast<const T*>(c10::cuda::CUDACachingAllocator::raw_alloc(a_size));
305+
// NOLINTNEXTLINE(*const-cast*)
304306
copy->b = static_cast<const T*>(c10::cuda::CUDACachingAllocator::raw_alloc(b_size));
305307
copy->duplicate_inputs_ = true;
306308
}
@@ -311,7 +313,9 @@ struct GemmStridedBatchedParams : OpParams {
311313
void Delete() {
312314
c10::cuda::CUDACachingAllocator::raw_delete(c);
313315
if (duplicate_inputs_) {
316+
// NOLINTNEXTLINE(*const-cast*)
314317
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<T*>(a));
318+
// NOLINTNEXTLINE(*const-cast*)
315319
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<T*>(b));
316320
}
317321
}
@@ -339,14 +343,12 @@ struct GemmStridedBatchedParams : OpParams {
339343
int64_t stride_c;
340344
int64_t batch;
341345
private:
342-
bool duplicate_inputs_;
346+
bool duplicate_inputs_{false};
343347
};
344348

345349
template <typename T>
346350
struct ScaledGemmParams : OpParams {
347-
ScaledGemmParams() {
348-
duplicate_inputs_ = false;
349-
}
351+
ScaledGemmParams() = default;
350352

351353
std::string Signature() const override {
352354
return fmt::sprintf("%c%c_%ld_%ld_%ld", transa, transb, m, n, k);
@@ -402,7 +404,9 @@ struct ScaledGemmParams : OpParams {
402404
void Delete() {
403405
c10::cuda::CUDACachingAllocator::raw_delete(c);
404406
if (duplicate_inputs_) {
407+
// NOLINTNEXTLINE(*const-cast*)
405408
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<void*>(a));
409+
// NOLINTNEXTLINE(*const-cast*)
406410
c10::cuda::CUDACachingAllocator::raw_delete(const_cast<void*>(b));
407411
}
408412
}
@@ -433,7 +437,7 @@ struct ScaledGemmParams : OpParams {
433437
void* amax_ptr;
434438
bool use_fast_accum;
435439
private:
436-
bool duplicate_inputs_;
440+
bool duplicate_inputs_{false};
437441
};
438442

439443
} // namespace at::cuda::tunable

aten/src/ATen/cuda/tunable/TunableOp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ class TunableOp {
284284
};
285285

286286
struct OpParams {
287-
OpParams() = default;
288287
virtual ~OpParams() = default;
289288
virtual std::string Signature() const = 0;
290289
};

aten/src/ATen/functorch/DynamicLayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ DynamicLayer popDynamicLayer() {
232232

233233
int64_t pushDynamicLayer(DynamicLayer&& dynamic_layer) {
234234
auto& dynamicLayerStack = dynamicLayerStackAccessor();
235-
int64_t layerId = 1 + dynamicLayerStack.size();
235+
int64_t layerId = static_cast<int64_t>(1 + dynamicLayerStack.size());
236236
TORCH_INTERNAL_ASSERT(layerId == dynamic_layer.layerId());
237237
dynamicLayerStack.emplace_back(std::move(dynamic_layer));
238238

@@ -256,7 +256,7 @@ int64_t initAndPushDynamicLayer(
256256
std::optional<bool> prev_fwd_grad_mode,
257257
std::optional<bool> functionalize_add_back_views) {
258258
const auto& dynamicLayerStack = dynamicLayerStackAccessor();
259-
const auto layerId = 1 + dynamicLayerStack.size();
259+
const int64_t layerId = static_cast<int64_t>(1 + dynamicLayerStack.size());
260260
DynamicLayer new_layer(transform_type, layerId, std::move(batch_size), randomness, prev_grad_mode, prev_fwd_grad_mode, functionalize_add_back_views);
261261
// NB: this function should be called while holding the GIL to avoid races
262262
new_layer.interpreter().set_is_alive(true);
@@ -459,7 +459,7 @@ static void dynamicLayerFrontFallback(
459459

460460
// Unwrap escaped GradWrappers
461461
auto num_args = op.schema().arguments().size();
462-
foreachTensorInplace(*stack, stack->size() - num_args, stack->size(), unwrapIfDead);
462+
foreachTensorInplace(*stack, static_cast<int64_t>(stack->size() - num_args), static_cast<int64_t>(stack->size()), unwrapIfDead);
463463

464464
auto& layer = dynamicLayerStack.back();
465465
layer.interpreter().process(op, stack);

0 commit comments

Comments
 (0)
0