diff --git a/aten/src/ATen/core/ivalue_inl.h b/aten/src/ATen/core/ivalue_inl.h index f384a3ea46f..1d17fe06906 100644 --- a/aten/src/ATen/core/ivalue_inl.h +++ b/aten/src/ATen/core/ivalue_inl.h @@ -1829,7 +1829,7 @@ c10::intrusive_ptr IValue::toCustomClass() const& { template T generic_to(IValue ivalue, _fake_type /*unused*/) { - using ElemType = typename std::remove_pointer::type::element_type; + using ElemType = typename std::remove_pointer_t::element_type; return std::move(ivalue).template toCustomClass(); } @@ -1941,7 +1941,7 @@ Tuple generic_to_tuple_impl( const ivalue::TupleElements& t, std::index_sequence /*unused*/) { return std::make_tuple( - t[INDEX].to::type>()...); + t[INDEX].to>()...); } } // namespace detail diff --git a/aten/src/ATen/core/jit_type.h b/aten/src/ATen/core/jit_type.h index 5378bd0b3d1..b2236dbb688 100644 --- a/aten/src/ATen/core/jit_type.h +++ b/aten/src/ATen/core/jit_type.h @@ -2243,7 +2243,7 @@ static const TypeKind Kind = TypeKind::ScalarTypeType; static ScalarTypeTypePtr get(); private: -ScalarTypeType() {} +ScalarTypeType() = default; }; struct MemoryFormatType; @@ -2257,7 +2257,7 @@ static const TypeKind Kind = TypeKind::MemoryFormatType; static MemoryFormatTypePtr get(); private: -MemoryFormatType() {} +MemoryFormatType() = default; }; struct LayoutType; @@ -2271,7 +2271,7 @@ static const TypeKind Kind = TypeKind::LayoutType; static LayoutTypePtr get(); private: -LayoutType() {} +LayoutType() = default; }; namespace detail { diff --git a/aten/src/ATen/cpu/vec/vec256/vec256_qint.h b/aten/src/ATen/cpu/vec/vec256/vec256_qint.h index 31a881ff286..353d3a1219c 100644 --- a/aten/src/ATen/cpu/vec/vec256/vec256_qint.h +++ b/aten/src/ATen/cpu/vec/vec256/vec256_qint.h @@ -989,7 +989,7 @@ struct VectorizedQuantizedConverter { } protected: - VectorizedQuantizedConverter() {} + VectorizedQuantizedConverter() = default; }; template <> diff --git a/aten/src/ATen/cuda/CUDABlas.cpp b/aten/src/ATen/cuda/CUDABlas.cpp index 44787914873..de5f481c2d0 100644 --- a/aten/src/ATen/cuda/CUDABlas.cpp +++ b/aten/src/ATen/cuda/CUDABlas.cpp @@ -419,7 +419,7 @@ static inline bool bgemm_internal_cublaslt(CUDABLAS_BGEMM_ARGTYPES_AND_C_DTYPE(D } #endif abType = CUDA_R_16F; - cType = (std::is_same_v) ? CUDA_R_32F : CUDA_R_16F; + cType = std::is_same_v ? CUDA_R_32F : CUDA_R_16F; #ifndef USE_ROCM auto fp16_reduction = at::globalContext().allowFP16ReductionCuBLAS(); if (fp16_reduction != @@ -436,7 +436,7 @@ static inline bool bgemm_internal_cublaslt(CUDABLAS_BGEMM_ARGTYPES_AND_C_DTYPE(D #endif } else if constexpr (std::is_same_v) { abType = CUDA_R_16BF; - cType = (std::is_same_v) ? CUDA_R_32F : CUDA_R_16BF; + cType = std::is_same_v ? CUDA_R_32F : CUDA_R_16BF; #ifndef USE_ROCM auto bf16_reduction = at::globalContext().allowBF16ReductionCuBLAS(); if (bf16_reduction != @@ -1628,7 +1628,7 @@ bool gemm_and_bias( } #endif abType = CUDA_R_16F; - cType = (std::is_same_v) ? CUDA_R_32F : CUDA_R_16F; + cType = std::is_same_v ? CUDA_R_32F : CUDA_R_16F; #ifndef USE_ROCM auto fp16_reduction = at::globalContext().allowFP16ReductionCuBLAS(); if (fp16_reduction != @@ -1645,7 +1645,7 @@ bool gemm_and_bias( #endif } else if constexpr (std::is_same_v) { abType = CUDA_R_16BF; - cType = (std::is_same_v) ? CUDA_R_32F : CUDA_R_16BF; + cType = std::is_same_v ? CUDA_R_32F : CUDA_R_16BF; #ifndef USE_ROCM auto bf16_reduction = at::globalContext().allowBF16ReductionCuBLAS(); if (bf16_reduction != diff --git a/aten/src/ATen/cuda/CUDAGreenContext.cpp b/aten/src/ATen/cuda/CUDAGreenContext.cpp index a579e45e160..65d9c54b2b2 100644 --- a/aten/src/ATen/cuda/CUDAGreenContext.cpp +++ b/aten/src/ATen/cuda/CUDAGreenContext.cpp @@ -26,7 +26,7 @@ GreenContext::GreenContext(uint32_t device_id, uint32_t num_sms) { "Attempted to create a green context but" " there was no primary context! Creating a primary context..."); - cudaFree(0); + cudaFree(nullptr); } CUdevice device; diff --git a/aten/src/ATen/cuda/CUDAScaledBlas.cpp b/aten/src/ATen/cuda/CUDAScaledBlas.cpp index aa409b0e04e..0eb4cbaace4 100644 --- a/aten/src/ATen/cuda/CUDAScaledBlas.cpp +++ b/aten/src/ATen/cuda/CUDAScaledBlas.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #define TORCH_ASSERT_ONLY_METHOD_OPERATORS #include #include diff --git a/aten/src/ATen/cuda/CUDAScaledBlas.h b/aten/src/ATen/cuda/CUDAScaledBlas.h index 0da297f0da6..a8f699048ff 100644 --- a/aten/src/ATen/cuda/CUDAScaledBlas.h +++ b/aten/src/ATen/cuda/CUDAScaledBlas.h @@ -4,7 +4,6 @@ #include #include #include -#include #define TORCH_ASSERT_ONLY_METHOD_OPERATORS #include #include diff --git a/aten/src/ATen/cuda/CachingHostAllocator.cpp b/aten/src/ATen/cuda/CachingHostAllocator.cpp index 8560cfe2726..2a4c59e6be9 100644 --- a/aten/src/ATen/cuda/CachingHostAllocator.cpp +++ b/aten/src/ATen/cuda/CachingHostAllocator.cpp @@ -222,7 +222,7 @@ struct CUDACachingHostAllocatorImpl // pre-fault/map the pages by setting the first byte of the page uintptr_t alignedStart = ((start + pageSize - 1) & ~(pageSize - 1)); - for (uintptr_t p = alignedStart; p < (end); p += pageSize) { + for (uintptr_t p = alignedStart; p < end; p += pageSize) { // NOLINTNEXTLINE(performance-no-int-to-ptr) memset((void*)p, 0, 1); } diff --git a/aten/src/ATen/cuda/tunable/Tunable.h b/aten/src/ATen/cuda/tunable/Tunable.h index 17b4ea34ddf..4075fdf4aa7 100644 --- a/aten/src/ATen/cuda/tunable/Tunable.h +++ b/aten/src/ATen/cuda/tunable/Tunable.h @@ -245,7 +245,7 @@ class TORCH_CUDA_CPP_API TuningContext { size_t results_count_from_input_file_; bool is_shutting_down_; - NumericalCheckConfig numerics_cfg_{}; + NumericalCheckConfig numerics_cfg_; }; TORCH_CUDA_CPP_API TuningContext* getTuningContext(); diff --git a/aten/src/ATen/detail/FunctionTraits.h b/aten/src/ATen/detail/FunctionTraits.h index c9212cb75a4..21a27f9773b 100644 --- a/aten/src/ATen/detail/FunctionTraits.h +++ b/aten/src/ATen/detail/FunctionTraits.h @@ -51,7 +51,7 @@ struct function_traits { template struct arg { - using type = typename std::tuple_element>::type; + using type = std::tuple_element_t>; // the i-th argument is equivalent to the i-th tuple element of a tuple // composed of those arguments. }; diff --git a/aten/src/ATen/detail/MTIAHooksInterface.h b/aten/src/ATen/detail/MTIAHooksInterface.h index bf488011d87..6e39a8a47b0 100644 --- a/aten/src/ATen/detail/MTIAHooksInterface.h +++ b/aten/src/ATen/detail/MTIAHooksInterface.h @@ -148,7 +148,7 @@ struct TORCH_API MTIAHooksInterface : AcceleratorHooksInterface { return; } - virtual bool isAvailable() const override; + bool isAvailable() const override; /* MTIAGraph related APIs */ virtual int64_t mtiagraphCreate(bool keep_graph = false) const { @@ -188,13 +188,13 @@ struct TORCH_API MTIAHooksInterface : AcceleratorHooksInterface { FAIL_MTIAHOOKS_FUNC(__func__); } - virtual const Generator& getDefaultGenerator(DeviceIndex) const override { + const Generator& getDefaultGenerator(DeviceIndex /*device_index*/) const override { FAIL_MTIAHOOKS_FUNC(__func__); static Generator dummy_generator; return dummy_generator; } - virtual Generator getNewGenerator(DeviceIndex) const override { + Generator getNewGenerator(DeviceIndex /*device_index*/) const override { FAIL_MTIAHOOKS_FUNC(__func__); static Generator dummy_generator; return dummy_generator; diff --git a/aten/src/ATen/detail/XLAHooksInterface.h b/aten/src/ATen/detail/XLAHooksInterface.h index cd3be063ca5..6a2b1ce9aa4 100644 --- a/aten/src/ATen/detail/XLAHooksInterface.h +++ b/aten/src/ATen/detail/XLAHooksInterface.h @@ -44,7 +44,7 @@ struct TORCH_API XLAHooksInterface : AcceleratorHooksInterface { TORCH_CHECK(false, "Cannot get XLA generator without torch_xla library. ", XLA_HELP); } - virtual DeviceIndex getCurrentDevice() const override { + DeviceIndex getCurrentDevice() const override { TORCH_CHECK(false, "Cannot get current XLA device without torch_xla library. ", XLA_HELP); } diff --git a/aten/src/ATen/functorch/BatchRulesLinearAlgebra.cpp b/aten/src/ATen/functorch/BatchRulesLinearAlgebra.cpp index 804d6953bd4..edb7fc44e01 100644 --- a/aten/src/ATen/functorch/BatchRulesLinearAlgebra.cpp +++ b/aten/src/ATen/functorch/BatchRulesLinearAlgebra.cpp @@ -6,6 +6,8 @@ #include +#include + namespace at::functorch { typedef std::tuple> oneOutput; @@ -315,7 +317,7 @@ oneOutput linalg_lu_solve_batch_rule( const auto LU_num_batch_dims = rankWithoutBatchDim(LU_, LU_bdim) - LU_min_rank; const auto pivots_num_batch_dims = rankWithoutBatchDim(pivots_, pivots_bdim) - pivots_min_rank; const auto B_num_batch_dims = rankWithoutBatchDim(B_, B_bdim) - B_min_rank; - const auto max_num_batch_dims = std::max(std::max(LU_num_batch_dims, pivots_num_batch_dims), B_num_batch_dims); + const auto max_num_batch_dims = std::max({LU_num_batch_dims, pivots_num_batch_dims, B_num_batch_dims}); LU_ = maybePadToLogicalRank(LU_, LU_bdim, max_num_batch_dims + LU_min_rank); pivots_ = maybePadToLogicalRank(pivots_, pivots_bdim, max_num_batch_dims + pivots_min_rank); diff --git a/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp b/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp index bba7a61aeb5..c4d7e1fdfe9 100644 --- a/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp +++ b/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp @@ -16,6 +16,8 @@ #else #include #include + +#include #endif namespace at::native { @@ -567,7 +569,7 @@ void apply_lstsq(const Tensor& A, Tensor& B, Tensor& rank, Tensor& singular_valu auto n = A.size(-1); auto nrhs = B.size(-1); auto lda = std::max(1, m); - auto ldb = std::max(1, std::max(m, n)); + auto ldb = std::max({static_cast(1), m, n}); auto infos_data = infos.data_ptr(); // only 'gels' driver does not compute the rank diff --git a/aten/src/ATen/native/GridSampler.cpp b/aten/src/ATen/native/GridSampler.cpp index 9ad138b3a66..c4de3a67ae5 100644 --- a/aten/src/ATen/native/GridSampler.cpp +++ b/aten/src/ATen/native/GridSampler.cpp @@ -28,6 +28,8 @@ #include #include #include + +#include #endif namespace at::native { @@ -991,10 +993,10 @@ grid_sampler_2d_backward_cpu(const Tensor& grad_output, const Tensor& input, con const auto grid_sW = grid.strides()[2]; // NOTE: Gather offsets are only used for the height and width dimensions auto max_gather_offset = std::max( - std::max( + { (isizes[2] - 1) * istrides[2] + (isizes[3] - 1) * istrides[3], - (gsizes[2] - 1) * gstrides[2] + (gsizes[3] - 1) * gstrides[3]), - grid_sW * (vec::Vectorized::size() - 1)); + (gsizes[2] - 1) * gstrides[2] + (gsizes[3] - 1) * gstrides[3], + grid_sW * (vec::Vectorized::size() - 1)}); if (max_gather_offset > std::numeric_limits::max()) { return native::_grid_sampler_2d_cpu_fallback_backward( diff --git a/aten/src/ATen/native/cuda/GroupedBlas.cpp b/aten/src/ATen/native/cuda/GroupedBlas.cpp index 2052f344adf..19ed7bedd12 100644 --- a/aten/src/ATen/native/cuda/GroupedBlas.cpp +++ b/aten/src/ATen/native/cuda/GroupedBlas.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #define TORCH_ASSERT_ONLY_METHOD_OPERATORS #include #include @@ -522,7 +521,7 @@ _scaled_grouped_mm_cuda_v2( // NOTE(slayton): For sub-1B formats want contraction_dim argument? if (!a_is_2d || !b_is_2d) { - if (contraction_dim.size() > 0) { + if (!contraction_dim.empty()) { const int dim_a = contraction_dim[0], dim_b = mat_b.size(contraction_dim[1]); TORCH_CHECK_VALUE(mat_a.size(dim_a) == mat_b.size(dim_b), "Contraction dimensions (", dim_a, ",", dim_b, ") of mat_a and mat_b must match, got: ", mat_a.size(dim_a), " and ", diff --git a/aten/src/ATen/native/cuda/ScaledBlas.cpp b/aten/src/ATen/native/cuda/ScaledBlas.cpp index d61e0750296..76be8d5f055 100644 --- a/aten/src/ATen/native/cuda/ScaledBlas.cpp +++ b/aten/src/ATen/native/cuda/ScaledBlas.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #define TORCH_ASSERT_ONLY_METHOD_OPERATORS #include #include @@ -433,12 +432,12 @@ _scaled_gemm( // to help cleanup v1 call structure. Tensor& _scaled_rowwise_rowwise( - const Tensor&, const Tensor&, - const Tensor&, const Tensor&, - const std::optional&, - const c10::ScalarType, - bool, - Tensor&); + const Tensor& /*mat_a*/, const Tensor& /*mat_b*/, + const Tensor& /*scale_a*/, const Tensor& /*scale_b*/, + const std::optional& /*bias*/, + const c10::ScalarType /*out_dtype*/, + bool /*use_fast_accum*/, + Tensor& /*out*/); // Computes matrix multiply + bias while applying scaling to input and output matrices @@ -740,7 +739,7 @@ _scaled_rowwise_rowwise( auto dprops = at::cuda::getCurrentDeviceProperties(); if (((dprops->major < 9 || CUBLAS_VERSION < 120900 || cublasLtGetVersion() < 120900) // cuBLAS only supports tiled 1D factor layout for 1D block scaling, no 2D block scales - || (dprops->major == 10 && (scale_a.sizes().size() || scale_b.sizes().size())))) { + || (dprops->major == 10 && (!scale_a.sizes().empty() || !scale_b.sizes().empty())))) { TORCH_CHECK_VALUE(out.dtype() == kBFloat16 || out.dtype() == kHalf, "Only bf16 and fp16 high precision output types are supported for row-wise scaling."); at::cuda::detail::f8f8bf16_rowwise( mat_a, @@ -1287,7 +1286,7 @@ _scaled_mm_cuda_v2_out( // Check if the input matrix sizes can be multiplied // - if optional contraction dims are provided, use those // -- mostly for < 1B formats (i.e. nvfp4x2) where cheap .t() is not available. - if (contraction_dim.size() > 0) { + if (!contraction_dim.empty()) { TORCH_CHECK_VALUE(contraction_dim.size() == 2, "contraction_dim must have exactly 2 elements"); auto mat_a_dim = contraction_dim[0]; auto mat_b_dim = contraction_dim[1]; diff --git a/aten/src/ATen/native/cuda/linalg/BatchLinearAlgebraLib.cpp b/aten/src/ATen/native/cuda/linalg/BatchLinearAlgebraLib.cpp index 32dc296e589..4ec771e8702 100644 --- a/aten/src/ATen/native/cuda/linalg/BatchLinearAlgebraLib.cpp +++ b/aten/src/ATen/native/cuda/linalg/BatchLinearAlgebraLib.cpp @@ -988,7 +988,7 @@ static void apply_geqrf(const Tensor& A, const Tensor& tau) { #ifdef USE_CUSOLVER_64_BIT size_t worksize_device; // workspaceInBytesOnDevice size_t worksize_host; // workspaceInBytesOnHost - cusolverDnParams_t params = NULL; // use default algorithm (currently it's the only option) + cusolverDnParams_t params = nullptr; // use default algorithm (currently it's the only option) at::cuda::solver::xgeqrf_bufferSize( at::cuda::getCurrentCUDASolverDnHandle(), params, @@ -1346,7 +1346,7 @@ static void apply_syevd(const Tensor& values, const Tensor& vectors, const Tenso #ifdef USE_CUSOLVER_64_BIT size_t worksize_device; // workspaceInBytesOnDevice size_t worksize_host; // workspaceInBytesOnHost - cusolverDnParams_t params = NULL; // use default algorithm (currently it's the only option) + cusolverDnParams_t params = nullptr; // use default algorithm (currently it's the only option) at::cuda::solver::xsyevd_bufferSize( at::cuda::getCurrentCUDASolverDnHandle(), params, diff --git a/aten/src/ATen/native/cudnn/AffineGridGenerator.cpp b/aten/src/ATen/native/cudnn/AffineGridGenerator.cpp index f13c16b8031..34f5748f02b 100644 --- a/aten/src/ATen/native/cudnn/AffineGridGenerator.cpp +++ b/aten/src/ATen/native/cudnn/AffineGridGenerator.cpp @@ -55,8 +55,7 @@ Tensor cudnn_affine_grid_generator_backward( #include -namespace at { -namespace native { +namespace at::native { namespace { @@ -122,7 +121,6 @@ Tensor cudnn_affine_grid_generator_backward( return grad_theta_t; } -} // namespace native -} // namespace at +} // namespace at::native #endif // AT_CUDNN_ENABLED() diff --git a/aten/src/ATen/native/cudnn/BatchNorm.cpp b/aten/src/ATen/native/cudnn/BatchNorm.cpp index 371b77722cd..7556de8245a 100644 --- a/aten/src/ATen/native/cudnn/BatchNorm.cpp +++ b/aten/src/ATen/native/cudnn/BatchNorm.cpp @@ -87,8 +87,7 @@ size_t _get_cudnn_batch_norm_reserve_space_size( #include #endif -namespace at { -namespace native { +namespace at::native { namespace { @@ -442,7 +441,6 @@ std::tuple cudnn_batch_norm_backward( grad_input_t, grad_weight_t, grad_bias_t}; } -} // namespace native -} // namespace at +} // namespace at::native #endif diff --git a/aten/src/ATen/native/cudnn/ConvShared.cpp b/aten/src/ATen/native/cudnn/ConvShared.cpp index 1584d5e9acd..1adf440b269 100644 --- a/aten/src/ATen/native/cudnn/ConvShared.cpp +++ b/aten/src/ATen/native/cudnn/ConvShared.cpp @@ -71,8 +71,7 @@ // - Things that happen in TensorArg // - Check arguments (type, GPU, shape) -namespace at { -namespace native { +namespace at::native { // --------------------------------------------------------------------- // @@ -825,7 +824,6 @@ REGISTER_CUDA_DISPATCH( cudnn_convolution_transpose_backward_stub, &cudnn_convolution_transpose_backward) -} // namespace native -} // namespace at +} // namespace at::native #endif // AT_CUDNN_ENABLED diff --git a/aten/src/ATen/native/cudnn/Conv_v7.cpp b/aten/src/ATen/native/cudnn/Conv_v7.cpp index 74a3f0afb9c..6e473542edb 100644 --- a/aten/src/ATen/native/cudnn/Conv_v7.cpp +++ b/aten/src/ATen/native/cudnn/Conv_v7.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -27,8 +28,8 @@ #include #include -#include #include +#include #include #include #include @@ -67,8 +68,7 @@ constexpr size_t operator"" _TiB(unsigned long long n) { return static_cast(n) * 1024 * 1024 * 1024 * 1024; } -namespace at { -namespace native { +namespace at::native { // Convenience struct for passing around descriptors and data // pointers @@ -80,11 +80,8 @@ struct ConvolutionArgs { const Tensor &input, output, weight; ConvolutionDescriptor cdesc; - ConvolutionArgs( - const Tensor& input, - const Tensor& output, - const Tensor& weight) - : input(input), output(output), weight(weight) {} + ConvolutionArgs(const Tensor& input, Tensor output, Tensor weight) + : input(input), output(std::move(output)), weight(std::move(weight)) {} }; std::ostream& operator<<(std::ostream& out, const ConvolutionArgs& args) { @@ -141,7 +138,7 @@ BenchmarkCache bwd_filter_algos; // TODO: Stop manually allocating CUDA memory; allocate an ATen byte // tensor instead. struct Workspace { - Workspace(size_t size) : size(size), data(NULL) { + Workspace(size_t size) : size(size), data(nullptr) { // Sometimes cuDNN returns a workspace size > 2^63, this could makes the // allocation of workspace fail with some 64bit indexing error instead of an // OOM error. In such case, we manually fail with OOM. @@ -1236,7 +1233,6 @@ void raw_cudnn_convolution_add_relu_fallback_out( output.relu_(); } -} // namespace native -} // namespace at +} // namespace at::native #endif diff --git a/aten/src/ATen/native/cudnn/Conv_v8.cpp b/aten/src/ATen/native/cudnn/Conv_v8.cpp index 7bc7a80cbb8..7337a511f5b 100644 --- a/aten/src/ATen/native/cudnn/Conv_v8.cpp +++ b/aten/src/ATen/native/cudnn/Conv_v8.cpp @@ -39,8 +39,7 @@ C10_DIAGNOSTIC_POP() #include #endif -namespace at { -namespace native { +namespace at::native { namespace { @@ -1200,8 +1199,8 @@ void raw_cudnn_convolution_forward_out( if (output.numel() == 0) { return; } - for (auto it = dilation.begin(); it != dilation.end(); it++) { - TORCH_CHECK_VALUE(*it > 0, "Expected positive dilation in convolution."); + for (long it : dilation) { + TORCH_CHECK_VALUE(it > 0, "Expected positive dilation in convolution."); } if (at::native::cudnnv8_enabled_check_debug()) { run_single_conv( @@ -1368,7 +1367,6 @@ void raw_cudnn_convolution_add_relu_out( } } -} // namespace native -} // namespace at +} // namespace at::native #endif // AT_CUDNN_ENABLED diff --git a/aten/src/ATen/native/cudnn/GridSampler.cpp b/aten/src/ATen/native/cudnn/GridSampler.cpp index fc41957bb7c..21ac35ff723 100644 --- a/aten/src/ATen/native/cudnn/GridSampler.cpp +++ b/aten/src/ATen/native/cudnn/GridSampler.cpp @@ -51,8 +51,7 @@ std::tuple cudnn_grid_sampler_backward( // TODO: descriptor checking -namespace at { -namespace native { +namespace at::native { namespace { @@ -187,7 +186,6 @@ std::tuple cudnn_grid_sampler_backward( return std::tuple{grad_input_t, grad_grid_t}; } -} // namespace native -} // namespace at +} // namespace at::native #endif diff --git a/aten/src/ATen/native/cudnn/LossCTC.cpp b/aten/src/ATen/native/cudnn/LossCTC.cpp index 35d5a64685f..1b617199330 100644 --- a/aten/src/ATen/native/cudnn/LossCTC.cpp +++ b/aten/src/ATen/native/cudnn/LossCTC.cpp @@ -82,8 +82,7 @@ std::tuple _cudnn_ctc_loss_tensor( #include #include -namespace at { -namespace native { +namespace at::native { bool _use_cudnn_ctc_loss( const Tensor& log_probs, @@ -346,7 +345,6 @@ std::tuple _cudnn_ctc_loss_tensor( return std::make_tuple(costs, grad); } -} // namespace native -} // namespace at +} // namespace at::native #endif diff --git a/aten/src/ATen/native/cudnn/MHA.cpp b/aten/src/ATen/native/cudnn/MHA.cpp index 58dd0552cab..47409266c8d 100644 --- a/aten/src/ATen/native/cudnn/MHA.cpp +++ b/aten/src/ATen/native/cudnn/MHA.cpp @@ -139,8 +139,7 @@ void run_cudnn_SDP_bprop_nestedtensor( #include -namespace at { -namespace native { +namespace at::native { namespace fe = cudnn_frontend; @@ -1882,6 +1881,6 @@ void run_cudnn_SDP_bprop_nestedtensor( mha_graph.execute(handle, variant_pack, workspace_ptr.get()).is_good()); } -} // namespace native -} // namespace at +} // namespace at::native + #endif diff --git a/aten/src/ATen/native/cudnn/RNN.cpp b/aten/src/ATen/native/cudnn/RNN.cpp index e7030a00c71..f916eb53368 100644 --- a/aten/src/ATen/native/cudnn/RNN.cpp +++ b/aten/src/ATen/native/cudnn/RNN.cpp @@ -115,8 +115,7 @@ Tensor _cudnn_init_dropout_state( #include -namespace at { -namespace native { +namespace at::native { namespace { // DropoutDescriptor @@ -1284,7 +1283,7 @@ int64_t _cudnn_rnn_flatten_weight_prologue( #endif } -} // namespace native +} // namespace at::native // Utilities exposed in RNNUtils.h namespace cudnn_rnn { @@ -1679,7 +1678,7 @@ std::tuple _cudnn_rnn( CUDNN_FWD_MODE_INFERENCE, x_descs_arr.desc(), &workspace_size, - NULL)); + nullptr)); #endif workspace = at::empty(workspace_size, input.options().dtype(kByte)); reserve = at::empty({0}, input.options().dtype(kByte)); @@ -1899,7 +1898,7 @@ std::tuple _cudnn_rnn_backward_input( CUDNN_FWD_MODE_TRAINING, x_descs_arr.desc(), &workspace_size, - NULL)); + nullptr)); #endif // TODO: put this in the correct device??? Tensor workspace = at::empty(workspace_size, input.options().dtype(kByte)); @@ -2087,7 +2086,7 @@ std::vector _cudnn_rnn_backward_weight( CUDNN_FWD_MODE_TRAINING, x_descs_arr.desc(), &workspace_size, - NULL)); + nullptr)); #endif Tensor workspace = at::empty(workspace_size, input.options().dtype(kByte)); #ifndef USE_CUDNN_RNN_V8_API @@ -2819,7 +2818,6 @@ TORCH_LIBRARY_IMPL(aten, Meta, m) { } // namespace -} // namespace at -} // namespace at +} // namespace at::native #endif // AT_CUDNN_ENABLED() diff --git a/aten/src/ATen/native/miopen/Conv_miopen.cpp b/aten/src/ATen/native/miopen/Conv_miopen.cpp index 328daffa408..7d1dd2e5179 100644 --- a/aten/src/ATen/native/miopen/Conv_miopen.cpp +++ b/aten/src/ATen/native/miopen/Conv_miopen.cpp @@ -27,7 +27,7 @@ #if !AT_ROCM_ENABLED() -namespace at { namespace native { +namespace at::native { // See Note [ATen preprocessor philosophy] @@ -134,7 +134,7 @@ at::Tensor miopen_convolution_relu( TORCH_CHECK(false, "miopen_convolution_relu: ATen not compiled with MIOpen support"); } -}} +} #else // AT_ROCM_ENABLED diff --git a/aten/src/ATen/native/mkldnn/MkldnnTensorMath.cpp b/aten/src/ATen/native/mkldnn/MkldnnTensorMath.cpp index 831603d576b..19c16ee196c 100644 --- a/aten/src/ATen/native/mkldnn/MkldnnTensorMath.cpp +++ b/aten/src/ATen/native/mkldnn/MkldnnTensorMath.cpp @@ -27,8 +27,8 @@ Tensor& mkldnn_zero_(Tensor& self) { #include -namespace at { -namespace native { + +namespace at::native { Tensor& mkldnn_zero_(Tensor& self) { using Vec = vec::Vectorized; @@ -48,7 +48,7 @@ Tensor& mkldnn_zero_(Tensor& self) { return self; } -} // namespace native -} // namespace at +} // namespace at::native + #endif // AT_MKLDNN_ENABLED diff --git a/aten/src/ATen/native/quantized/cpu/qconv.cpp b/aten/src/ATen/native/quantized/cpu/qconv.cpp index c054d576516..69f91429ba2 100644 --- a/aten/src/ATen/native/quantized/cpu/qconv.cpp +++ b/aten/src/ATen/native/quantized/cpu/qconv.cpp @@ -1919,13 +1919,13 @@ namespace at::native { }; if (act.dim() == 3) { // Conv1D post op - supported_postop.push_back("relu"); + supported_postop.emplace_back("relu"); } else if (act.dim() == 4) { // Conv2D post op - supported_postop.push_back("relu"); - supported_postop.push_back("hardtanh"); - supported_postop.push_back("hardswish"); - supported_postop.push_back("swish"); + supported_postop.emplace_back("relu"); + supported_postop.emplace_back("hardtanh"); + supported_postop.emplace_back("hardswish"); + supported_postop.emplace_back("swish"); } TORCH_CHECK( std::find(supported_postop.begin(), supported_postop.end(), attr) != supported_postop.end(), diff --git a/aten/src/ATen/native/quantized/cpu/qlinear.cpp b/aten/src/ATen/native/quantized/cpu/qlinear.cpp index ea1e6456d22..9dbec3c4658 100644 --- a/aten/src/ATen/native/quantized/cpu/qlinear.cpp +++ b/aten/src/ATen/native/quantized/cpu/qlinear.cpp @@ -1177,7 +1177,7 @@ static at::Tensor linear_int8_with_onednn_weight( // Fast path with cache of params static const char* env_var = std::getenv(CACHE_ONEDNN_CONTEXT_FLAG); static const std::string cache_flag_str = env_var ? std::string(env_var) : ""; - static const bool context_cache_enabled = cache_flag_str != "" && cache_flag_str == "1"; + static const bool context_cache_enabled = !cache_flag_str.empty() && cache_flag_str == "1"; static std::unordered_map qlinear_forward_params_map; int64_t weight_addr = at::native::data_ptr_from_mkldnn(onednn_weight); if (context_cache_enabled) { diff --git a/aten/src/ATen/test/vec_test_all_types.cpp b/aten/src/ATen/test/vec_test_all_types.cpp index c0c05c14841..69cafabb51a 100644 --- a/aten/src/ATen/test/vec_test_all_types.cpp +++ b/aten/src/ATen/test/vec_test_all_types.cpp @@ -1463,7 +1463,6 @@ namespace { CACHE_ALIGN underlying qint_vals[vec::size()]; // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays) CACHE_ALIGN underlying qint_b[vec::size()]; - typename vec::int_vec_return_type expected_int_ret; auto seed = TestSeed(); ValueGen generator(min_val, max_val, seed); for ([[maybe_unused]] const auto i : c10::irange(trials)) { diff --git a/c10/core/DispatchKeySet.h b/c10/core/DispatchKeySet.h index 934fa1be896..0aab8a80641 100644 --- a/c10/core/DispatchKeySet.h +++ b/c10/core/DispatchKeySet.h @@ -536,10 +536,10 @@ class DispatchKeySet final { using reference = value_type&; using pointer = value_type*; // final mask value should mask out the entire keyset - static const uint8_t end_iter_mask_val = + static constexpr uint8_t end_iter_mask_val = num_backends + num_functionality_keys; // final key value should be the last DispatchKey - static const uint8_t end_iter_key_val = num_functionality_keys; + static constexpr uint8_t end_iter_key_val = num_functionality_keys; // current_dispatchkey_idx_ will iterate through all functionality bits. // current_backendcomponent_idx_ will iterate through all backend bits. @@ -549,11 +549,7 @@ class DispatchKeySet final { uint8_t next_backend = 0) : data_ptr_(data_ptr), next_functionality_(next_functionality), - next_backend_(next_backend), - // These are in an invalid state at construction time, and set by the - // first increment call - current_dispatchkey_idx_(end_iter_key_val), - current_backendcomponent_idx_(end_iter_key_val) { + next_backend_(next_backend) { // Go to the first key in the set TORCH_INTERNAL_ASSERT( next_functionality_ >= num_backends, @@ -615,8 +611,10 @@ class DispatchKeySet final { const uint64_t* data_ptr_; uint8_t next_functionality_; uint8_t next_backend_; - uint8_t current_dispatchkey_idx_; - uint8_t current_backendcomponent_idx_; + // These are in an invalid state at construction time, and set by the + // first increment call + uint8_t current_dispatchkey_idx_{end_iter_key_val}; + uint8_t current_backendcomponent_idx_{end_iter_key_val}; }; public: diff --git a/c10/core/StorageImpl.h b/c10/core/StorageImpl.h index 8df32f552c7..7dfb8d310c3 100644 --- a/c10/core/StorageImpl.h +++ b/c10/core/StorageImpl.h @@ -105,11 +105,11 @@ struct C10_API StorageImpl : public c10::intrusive_ptr_target { data_ptr_.clear(); } - void incref_pyobject() const noexcept override final; + void incref_pyobject() const noexcept final; - void decref_pyobject() const noexcept override final; + void decref_pyobject() const noexcept final; - bool try_incref_pyobject() const noexcept override final; + bool try_incref_pyobject() const noexcept final; size_t nbytes() const { // OK to do this instead of maybe_as_int as nbytes is guaranteed positive diff --git a/c10/core/TensorImpl.h b/c10/core/TensorImpl.h index 42b6bb1e80d..f2112584c29 100644 --- a/c10/core/TensorImpl.h +++ b/c10/core/TensorImpl.h @@ -2178,11 +2178,11 @@ struct C10_API TensorImpl : public c10::intrusive_ptr_target { return &pyobj_slot_; } - void incref_pyobject() const noexcept override final; + void incref_pyobject() const noexcept final; - void decref_pyobject() const noexcept override final; + void decref_pyobject() const noexcept final; - bool try_incref_pyobject() const noexcept override final; + bool try_incref_pyobject() const noexcept final; private: // See NOTE [std::optional operator usage in CUDA] diff --git a/c10/util/C++17.h b/c10/util/C++17.h index 8e88a1ec50c..98cdffcbef4 100644 --- a/c10/util/C++17.h +++ b/c10/util/C++17.h @@ -32,9 +32,7 @@ * This header adds some polyfills with C++17 functionality */ -namespace c10 { - -namespace guts { +namespace c10::guts { #if defined(__HIP__) @@ -63,8 +61,6 @@ C10_HOST_DEVICE constexpr auto apply(F&& f, Tuple&& t) { #endif -} // namespace guts - -} // namespace c10 +} // namespace c10::guts #endif // C10_UTIL_CPP17_H_ diff --git a/c10/util/SmallVector.h b/c10/util/SmallVector.h index d47f37cdf7e..2af31560466 100644 --- a/c10/util/SmallVector.h +++ b/c10/util/SmallVector.h @@ -815,8 +815,8 @@ class SmallVectorImpl : public SmallVectorTemplateBase { iterator insert_one_impl(iterator I, ArgType&& Elt) { // Callers ensure that ArgType is derived from T. static_assert( - std::is_same>, T>:: - value, + std:: + is_same_v>, T>, "ArgType must be derived from T!"); if (I == this->end()) { // Important special case for empty vector. diff --git a/c10/util/strong_type.h b/c10/util/strong_type.h index c7d2fc0ecdd..d84db052053 100644 --- a/c10/util/strong_type.h +++ b/c10/util/strong_type.h @@ -391,25 +391,25 @@ namespace impl template struct require_copy_constructible { - static constexpr bool value = std::is_copy_constructible>::value; + static constexpr bool value = std::is_copy_constructible_v>; static_assert(value, "underlying type must be copy constructible"); }; template struct require_move_constructible { - static constexpr bool value = std::is_move_constructible>::value; + static constexpr bool value = std::is_move_constructible_v>; static_assert(value, "underlying type must be move constructible"); }; template struct require_copy_assignable { - static constexpr bool value = std::is_copy_assignable>::value; + static constexpr bool value = std::is_copy_assignable_v>; static_assert(value, "underlying type must be copy assignable"); }; template struct require_move_assignable { - static constexpr bool value = std::is_move_assignable>::value; + static constexpr bool value = std::is_move_assignable_v>; static_assert(value, "underlying type must be move assignable"); }; @@ -820,7 +820,7 @@ class affine_point::modifier<::strong::type> using base_diff_type = decltype(std::declval() - std::declval()); public: using difference = std::conditional_t{}, strong::type, D>; - static_assert(std::is_constructible_v, ""); + static_assert(std::is_constructible_v ); [[nodiscard]] friend constexpr @@ -1584,12 +1584,12 @@ namespace std { template struct hash<::strong::type> : std::conditional_t< - std::is_base_of< + std::is_base_of_v< ::strong::hashable::modifier< ::strong::type >, ::strong::type - >::value, + >, hash, std::false_type> { diff --git a/caffe2/serialize/file_adapter.h b/caffe2/serialize/file_adapter.h index 23307abc904..710121929cf 100644 --- a/caffe2/serialize/file_adapter.h +++ b/caffe2/serialize/file_adapter.h @@ -7,8 +7,8 @@ #include "caffe2/serialize/istream_adapter.h" #include "caffe2/serialize/read_adapter_interface.h" -namespace caffe2 { -namespace serialize { + +namespace caffe2::serialize { class TORCH_API FileAdapter final : public ReadAdapterInterface { public: @@ -32,5 +32,4 @@ class TORCH_API FileAdapter final : public ReadAdapterInterface { uint64_t size_; }; -} // namespace serialize -} // namespace caffe2 +} // namespace caffe2::serialize diff --git a/caffe2/serialize/inline_container.h b/caffe2/serialize/inline_container.h index 7c13b2d6ec5..29576da0a90 100644 --- a/caffe2/serialize/inline_container.h +++ b/caffe2/serialize/inline_container.h @@ -90,8 +90,8 @@ typedef struct mz_zip_archive mz_zip_archive; // model.json as the last file when writing after we have accumulated all // other information. -namespace caffe2 { -namespace serialize { + +namespace caffe2::serialize { static constexpr const char* kSerializationIdRecordName = ".data/serialization_id"; @@ -306,5 +306,4 @@ getOffset(size_t cursor, size_t filename_size, size_t size, uint64_t alignment); } // namespace detail -} // namespace serialize -} // namespace caffe2 +} // namespace caffe2::serialize diff --git a/caffe2/serialize/istream_adapter.h b/caffe2/serialize/istream_adapter.h index 680c288a15f..696e2488a21 100644 --- a/caffe2/serialize/istream_adapter.h +++ b/caffe2/serialize/istream_adapter.h @@ -5,8 +5,8 @@ #include "c10/macros/Macros.h" #include "caffe2/serialize/read_adapter_interface.h" -namespace caffe2 { -namespace serialize { + +namespace caffe2::serialize { // this is a reader implemented by std::istream class TORCH_API IStreamAdapter final : public ReadAdapterInterface { @@ -23,5 +23,4 @@ class TORCH_API IStreamAdapter final : public ReadAdapterInterface { void validate(const char* what) const; }; -} // namespace serialize -} // namespace caffe2 +} // namespace caffe2::serialize diff --git a/caffe2/serialize/read_adapter_interface.h b/caffe2/serialize/read_adapter_interface.h index 0a6b5b74a76..8afe1e06a39 100644 --- a/caffe2/serialize/read_adapter_interface.h +++ b/caffe2/serialize/read_adapter_interface.h @@ -5,8 +5,8 @@ #include "c10/macros/Macros.h" -namespace caffe2 { -namespace serialize { + +namespace caffe2::serialize { // this is the interface for the (file/stream/memory) reader in // PyTorchStreamReader. with this interface, we can extend the support @@ -19,5 +19,4 @@ class TORCH_API ReadAdapterInterface { virtual ~ReadAdapterInterface(); }; -} // namespace serialize -} // namespace caffe2 +} // namespace caffe2::serialize diff --git a/caffe2/serialize/versions.h b/caffe2/serialize/versions.h index 6e2c27adc8f..8584a0bbf81 100644 --- a/caffe2/serialize/versions.h +++ b/caffe2/serialize/versions.h @@ -1,8 +1,8 @@ #pragma once #include -namespace caffe2 { -namespace serialize { + +namespace caffe2::serialize { constexpr uint64_t kMinSupportedFileFormatVersion = 0x1L; @@ -129,5 +129,4 @@ constexpr uint64_t kProducedBytecodeVersion = 0x8L; constexpr uint64_t kMinSupportedBytecodeVersion = 0x4L; constexpr uint64_t kMaxSupportedBytecodeVersion = 0x9L; -} // namespace serialize -} // namespace caffe2 +} // namespace caffe2::serialize diff --git a/torch/csrc/Exceptions.cpp b/torch/csrc/Exceptions.cpp index 32b9a4664f6..a65ce20b5a5 100644 --- a/torch/csrc/Exceptions.cpp +++ b/torch/csrc/Exceptions.cpp @@ -241,8 +241,7 @@ void PyWarningHandler::InternalHandler::process(const c10::Warning& warning) { } PyWarningHandler::PyWarningHandler() noexcept(true) - : prev_handler_(c10::WarningUtils::get_warning_handler()), - in_exception_(false) { + : prev_handler_(c10::WarningUtils::get_warning_handler()) { c10::WarningUtils::set_warning_handler(&internal_handler_); } diff --git a/torch/csrc/Exceptions.h b/torch/csrc/Exceptions.h index adba98beb27..a9c7f1bdca9 100644 --- a/torch/csrc/Exceptions.h +++ b/torch/csrc/Exceptions.h @@ -335,7 +335,7 @@ struct PyWarningHandler { private: InternalHandler internal_handler_; at::WarningHandler* prev_handler_; - bool in_exception_; + bool in_exception_{false}; }; namespace detail { diff --git a/torch/csrc/api/include/torch/data/samplers/distributed.h b/torch/csrc/api/include/torch/data/samplers/distributed.h index 64be81645dc..bf3e85cc596 100644 --- a/torch/csrc/api/include/torch/data/samplers/distributed.h +++ b/torch/csrc/api/include/torch/data/samplers/distributed.h @@ -91,9 +91,9 @@ class TORCH_API DistributedRandomSampler : public DistributedSampler<> { private: void populate_indices(); - size_t begin_index_; - size_t end_index_; - size_t sample_index_; + size_t begin_index_{0}; + size_t end_index_{0}; + size_t sample_index_{0}; std::vector all_indices_; }; @@ -124,9 +124,9 @@ class TORCH_API DistributedSequentialSampler : public DistributedSampler<> { private: void populate_indices(); - size_t begin_index_; - size_t end_index_; - size_t sample_index_; + size_t begin_index_{0}; + size_t end_index_{0}; + size_t sample_index_{0}; std::vector all_indices_; }; diff --git a/torch/csrc/api/src/data/samplers/distributed.cpp b/torch/csrc/api/src/data/samplers/distributed.cpp index 8b59d691d6c..a2f0ca690fe 100644 --- a/torch/csrc/api/src/data/samplers/distributed.cpp +++ b/torch/csrc/api/src/data/samplers/distributed.cpp @@ -15,10 +15,7 @@ DistributedRandomSampler::DistributedRandomSampler( size_t num_replicas, size_t rank, bool allow_duplicates) - : DistributedSampler(size, num_replicas, rank, allow_duplicates), - begin_index_(0), - end_index_(0), - sample_index_(0) { + : DistributedSampler(size, num_replicas, rank, allow_duplicates) { // shuffle first time. DistributedRandomSampler::reset(size_); } @@ -99,10 +96,7 @@ DistributedSequentialSampler::DistributedSequentialSampler( size_t num_replicas, size_t rank, bool allow_duplicates) - : DistributedSampler(size, num_replicas, rank, allow_duplicates), - begin_index_(0), - end_index_(0), - sample_index_(0) { + : DistributedSampler(size, num_replicas, rank, allow_duplicates) { populate_indices(); } diff --git a/torch/csrc/autograd/engine.cpp b/torch/csrc/autograd/engine.cpp index 0b70aae489e..91c138ba3c8 100644 --- a/torch/csrc/autograd/engine.cpp +++ b/torch/csrc/autograd/engine.cpp @@ -272,8 +272,7 @@ bool ReadyQueue::empty() const { return heap_.empty(); } -Engine::Engine() - : max_recursion_depth_(MAX_DEPTH), non_reentrant_device_thread_count_(0) {} +Engine::Engine() : non_reentrant_device_thread_count_(0) {} Engine::~Engine() { stop(); @@ -664,7 +663,7 @@ GraphTask::GraphTask( bool exit_on_error) : keep_graph_(keep_graph), graph_roots_(std::move(graph_roots)), - owner_(NO_DEVICE), + reentrant_depth_(reentrant_depth), exit_on_error_(exit_on_error), cpu_ready_queue_(std::move(cpu_ready_queue)), diff --git a/torch/csrc/autograd/engine.h b/torch/csrc/autograd/engine.h index 79ca41367e8..a326b0ecacb 100644 --- a/torch/csrc/autograd/engine.h +++ b/torch/csrc/autograd/engine.h @@ -243,7 +243,7 @@ struct TORCH_API Engine { // How many nested reentrant calls are allowed until a new thread is used // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) - int max_recursion_depth_; + int max_recursion_depth_{MAX_DEPTH}; struct ThreadPoolShared { // Data structures used by the threads for executing reentrant backwards diff --git a/torch/csrc/autograd/graph_task.h b/torch/csrc/autograd/graph_task.h index b34d15c7d05..de66184b20a 100644 --- a/torch/csrc/autograd/graph_task.h +++ b/torch/csrc/autograd/graph_task.h @@ -142,7 +142,7 @@ struct GraphTask : std::enable_shared_from_this { // The value of worker_device in the thread that created this task. // See Note [Reentrant backwards] // Safe to read owner_ and reentrant_depth_ without synchronization - int owner_; + int owner_{NO_DEVICE}; // The number of parent graph tasks for this graph task // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const int reentrant_depth_; diff --git a/torch/csrc/autograd/python_variable.cpp b/torch/csrc/autograd/python_variable.cpp index 000367de7a0..efa5eacfa2e 100644 --- a/torch/csrc/autograd/python_variable.cpp +++ b/torch/csrc/autograd/python_variable.cpp @@ -1355,11 +1355,11 @@ static bool get_local_results( " in DTensor op is not supported"); result.push_back(default_tensor(item)); } - stack->push_back(std::move(result)); + stack->emplace_back(std::move(result)); }; if (py::isinstance(spec, get_dtensor_spec_class())) { - stack->push_back(default_tensor(spec)); + stack->emplace_back(default_tensor(spec)); } else if (PyList_Check(spec.ptr())) { handle_sequence(py::reinterpret_borrow(spec)); } else if (PyTuple_Check(spec.ptr())) { diff --git a/torch/csrc/cuda/CUDAPluggableAllocator.h b/torch/csrc/cuda/CUDAPluggableAllocator.h index ab9e2e84cd7..04fd9940566 100644 --- a/torch/csrc/cuda/CUDAPluggableAllocator.h +++ b/torch/csrc/cuda/CUDAPluggableAllocator.h @@ -91,14 +91,14 @@ struct TORCH_CUDA_CPP_API CUDAPluggableAllocator std::vector getExpandableSegmentSizes(c10::DeviceIndex device) override; void emptyCache(c10::cuda::MempoolId_t mempool_id = {0, 0}) override; - void enable(bool) override {} + void enable(bool /*value*/) override {} bool isEnabled() const override { return true; } void cacheInfo(c10::DeviceIndex device, size_t* largestBlock) override; void* getBaseAllocation(void* ptr, size_t* size) override; - void recordStream(const c10::DataPtr&, streamType stream) override; + void recordStream(const c10::DataPtr& /*ptr*/, streamType stream) override; c10::CachingDeviceAllocator::DeviceStats getDeviceStats( c10::DeviceIndex device) override; @@ -109,7 +109,7 @@ struct TORCH_CUDA_CPP_API CUDAPluggableAllocator void beginAllocateToPool( c10::DeviceIndex device, c10::cuda::MempoolId_t mempool_id, - std::function) override; + std::function /*filter*/) override; void endAllocateToPool( c10::DeviceIndex device, c10::cuda::MempoolId_t mempool_id) override; @@ -117,7 +117,7 @@ struct TORCH_CUDA_CPP_API CUDAPluggableAllocator override; std::shared_ptr getIpcDevPtr(std::string handle) override; c10::cuda::CUDACachingAllocator::ShareableHandle shareIpcHandle( - void*) override; + void* /*ptr*/) override; void recordHistory( bool enabled, c10::cuda::CUDACachingAllocator::CreateContextFn context_recorder, diff --git a/torch/csrc/cuda/Module.cpp b/torch/csrc/cuda/Module.cpp index ec7e5be7eef..1160f150876 100644 --- a/torch/csrc/cuda/Module.cpp +++ b/torch/csrc/cuda/Module.cpp @@ -1488,7 +1488,7 @@ static void registerCudaPluggableAllocator(PyObject* module) { if (!allocd_set.count(ptr)) { definite_freed_count += 1; } - freed_pointer_set.insert((ptr)); + freed_pointer_set.insert(ptr); } // that block has already been freed, // so even those this will error, so too will the allocator diff --git a/torch/csrc/cuda/nccl.cpp b/torch/csrc/cuda/nccl.cpp index ee80c8b13f1..1f06c9570ea 100644 --- a/torch/csrc/cuda/nccl.cpp +++ b/torch/csrc/cuda/nccl.cpp @@ -146,7 +146,7 @@ ncclDataType_t to_nccl_data_type(const at::Tensor& t) { } ncclRedOp_t to_nccl_red_op(int var) { - return (ncclRedOp_t)(var); + return (ncclRedOp_t)var; } namespace torch::cuda::nccl { diff --git a/torch/csrc/distributed/c10d/ProcessGroupGloo.cpp b/torch/csrc/distributed/c10d/ProcessGroupGloo.cpp index 9eb7770381c..1dd0e554e5e 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupGloo.cpp +++ b/torch/csrc/distributed/c10d/ProcessGroupGloo.cpp @@ -384,7 +384,7 @@ ProcessGroupGloo::RecvWork::RecvWork( std::optional>({tensor})), tensor_(tensor), buffer_(std::move(buffer)), - srcRank_(-1), + seq_(seq) {} uint64_t ProcessGroupGloo::RecvWork::getSequencenumber() const { @@ -424,7 +424,7 @@ void ProcessGroupGloo::RecvWork::abort() { } ProcessGroupGloo::Options::Options(std::chrono::milliseconds timeout) - : Backend::Options(GLOO_BACKEND_NAME, timeout), threads(2) {} + : Backend::Options(GLOO_BACKEND_NAME, timeout) {} namespace { @@ -580,8 +580,7 @@ ProcessGroupGloo::ProcessGroupGloo( : Backend(rank, size), store_(new GlooStore(store)), options_(std::move(options)), - stop_(false), - collectiveCounter_(0), + local_id_(process_group_id++) { auto& devices = options_->devices; if (devices.empty()) { diff --git a/torch/csrc/distributed/c10d/ProcessGroupGloo.hpp b/torch/csrc/distributed/c10d/ProcessGroupGloo.hpp index 1a0b7c41b38..f0b37ffa5ca 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupGloo.hpp +++ b/torch/csrc/distributed/c10d/ProcessGroupGloo.hpp @@ -242,7 +242,7 @@ class TORCH_API ProcessGroupGloo : public Backend { protected: at::Tensor tensor_; std::unique_ptr<::gloo::transport::UnboundBuffer> buffer_; - int srcRank_; + int srcRank_{-1}; const uint64_t seq_; }; @@ -260,7 +260,7 @@ class TORCH_API ProcessGroupGloo : public Backend { std::chrono::milliseconds timeout = kBackendDefaultTimeout); std::vector> devices; - int threads; + int threads{2}; }; const std::string getBackendName() const override { @@ -454,13 +454,13 @@ class TORCH_API ProcessGroupGloo : public Backend { // a single device), you need multiple contexts. std::vector> contexts_; std::vector threads_; - bool stop_; + bool stop_{false}; // Incremented for every collective we kick off. // The value is used as tag for collective operations. Collectives are kicked // off in identical order across processes. Therefore the tag can be used // to match up operations during concurrent execution. - uint32_t collectiveCounter_; + uint32_t collectiveCounter_{0}; // Returns next collective tag to use (uses collectiveCounter_). uint32_t nextTag(); diff --git a/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp b/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp index 9a2acef3ff1..420e95c23bb 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp +++ b/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp @@ -316,7 +316,7 @@ c10::intrusive_ptr ProcessGroupMPI::createProcessGroupMPI( } ProcessGroupMPI::ProcessGroupMPI(int rank, int size, MPI_Comm pgComm) - : Backend(rank, size), stop_(false), pgComm_(pgComm) { + : Backend(rank, size), pgComm_(pgComm) { if (pgComm_ == MPI_COMM_NULL) { TORCH_CHECK(false, "pgComm_ must not be MPI_COMM_NULL"); } diff --git a/torch/csrc/distributed/c10d/ProcessGroupMPI.hpp b/torch/csrc/distributed/c10d/ProcessGroupMPI.hpp index 33bb696cf2a..01c8afdbd69 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupMPI.hpp +++ b/torch/csrc/distributed/c10d/ProcessGroupMPI.hpp @@ -249,7 +249,7 @@ class TORCH_API ProcessGroupMPI : public Backend { const std::optional>& inputTensors = std::nullopt); - bool stop_; + bool stop_{false}; std::mutex pgMutex_; std::thread workerThread_; diff --git a/torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp b/torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp index 22d9245b13e..e35ae40ce10 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp +++ b/torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp @@ -1391,7 +1391,8 @@ class TORCH_API ProcessGroupNCCL : public Backend { std::list completedWorkList_; // Add Work Pointer to workVector - void workEnqueue(const c10::intrusive_ptr&); + void workEnqueue( + const c10::intrusive_ptr& /*work*/); // The CUDA streams used by NCCL kernels std::unordered_map ncclStreams_; diff --git a/torch/csrc/distributed/c10d/ProcessGroupWrapper.cpp b/torch/csrc/distributed/c10d/ProcessGroupWrapper.cpp index a5ab14ce08f..8ae01da970b 100644 --- a/torch/csrc/distributed/c10d/ProcessGroupWrapper.cpp +++ b/torch/csrc/distributed/c10d/ProcessGroupWrapper.cpp @@ -350,9 +350,9 @@ std::ostream& operator<<( ", TensorShape=[", c10::Join(", ", size_strs), "], TensorDtypes=", - (dtype_strs), + dtype_strs, ", TensorDeviceTypes=", - (device_type_strs), + device_type_strs, ")"); } else { collectiveInfo = c10::str( diff --git a/torch/csrc/distributed/c10d/control_plane/Handlers.cpp b/torch/csrc/distributed/c10d/control_plane/Handlers.cpp index 138dc9b0fe2..2f75ed56952 100644 --- a/torch/csrc/distributed/c10d/control_plane/Handlers.cpp +++ b/torch/csrc/distributed/c10d/control_plane/Handlers.cpp @@ -98,13 +98,13 @@ RegisterHandler pyspyHandler{ pid_t target = getpid(); std::string cmd = "py-spy dump"; cmd += " --pid " + std::to_string(target); - if (req.getParam("native") != "") { + if (!req.getParam("native").empty()) { cmd += " --native"; } - if (req.getParam("subprocesses") != "") { + if (!req.getParam("subprocesses").empty()) { cmd += " --subprocesses"; } - if (req.getParam("nonblocking") != "") { + if (!req.getParam("nonblocking").empty()) { cmd += " --nonblocking"; } cmd += " 2>&1"; diff --git a/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.cpp b/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.cpp index 51a5d5e7244..fdece16fa38 100644 --- a/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.cpp +++ b/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.cpp @@ -83,7 +83,7 @@ void IpcChannel::send_fd(int dst_pid, int fd) { // Prepare data to send // Data being sent is "fd", the value of fd will be sent as auxiliary data // (control message) - struct iovec io = {.iov_base = (void*)("fd"), .iov_len = 2}; + struct iovec io = {.iov_base = (void*)"fd", .iov_len = 2}; // Prepare control message data buffer and zero it out // NOLINTNEXTLINE(*array*) diff --git a/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.hpp b/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.hpp index e246620df31..f4240d6c1a0 100644 --- a/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.hpp +++ b/torch/csrc/distributed/c10d/symm_mem/CUDASymmetricMemoryUtils.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace c10d { namespace symmetric_memory { @@ -45,8 +46,8 @@ class IpcChannel { // SymmetricMemory implementation files. class StoreExchange { public: - StoreExchange(const std::string& store_prefix) - : store_prefix_(store_prefix) {} + StoreExchange(std::string store_prefix) + : store_prefix_(std::move(store_prefix)) {} // Put template function in header file so that compiler can easily access it. template diff --git a/torch/csrc/distributed/rpc/python_rpc_handler.cpp b/torch/csrc/distributed/rpc/python_rpc_handler.cpp index 24d0862197b..a84ff93fae0 100644 --- a/torch/csrc/distributed/rpc/python_rpc_handler.cpp +++ b/torch/csrc/distributed/rpc/python_rpc_handler.cpp @@ -94,7 +94,7 @@ void PythonRpcHandler::init() { } } -PythonRpcHandler::PythonRpcHandler() : initialized_(false) {} +PythonRpcHandler::PythonRpcHandler() = default; void PythonRpcHandler::cleanup() { std::lock_guard guard(init_lock_); diff --git a/torch/csrc/distributed/rpc/python_rpc_handler.h b/torch/csrc/distributed/rpc/python_rpc_handler.h index 0772a6b7fbb..ce923cff298 100644 --- a/torch/csrc/distributed/rpc/python_rpc_handler.h +++ b/torch/csrc/distributed/rpc/python_rpc_handler.h @@ -120,7 +120,7 @@ class PYBIND11_EXPORT PythonRpcHandler { std::shared_ptr typeParser_; // Indicates whether or not we have properly initialized the handler. - bool initialized_; + bool initialized_{false}; // Lock to protect initialization. std::mutex init_lock_; diff --git a/torch/csrc/dynamo/guards.cpp b/torch/csrc/dynamo/guards.cpp index 55ab8988700..2db3a817bca 100644 --- a/torch/csrc/dynamo/guards.cpp +++ b/torch/csrc/dynamo/guards.cpp @@ -2730,7 +2730,7 @@ class GuardManager { public: GuardManager() = delete; GuardManager(RootGuardManager* root, std::string source) - : _root(root), _source(std::move(source)), _is_dict(false) {} + : _root(root), _source(std::move(source)) {} GuardManager( RootGuardManager* root, @@ -2874,7 +2874,7 @@ class GuardManager { _source(std::move(source)), _is_dict(is_dict), _is_immutable(is_immutable), - _weak_type(weak_type) {} + _weak_type(std::move(weak_type)) {} void clone_common( RootGuardManager* cloned_root, @@ -3770,8 +3770,8 @@ class RootGuardManager : public GuardManager { } void record_dict_pointer(PyObject* dict_pointer) { - _recorded_dict_pointers.push_back( - std::make_pair(dict_pointer, get_dict_version_unchecked(dict_pointer))); + _recorded_dict_pointers.emplace_back( + dict_pointer, get_dict_version_unchecked(dict_pointer)); } void record_tensor_pointer(PyObject* tensor_pointer) { diff --git a/torch/csrc/jit/codegen/onednn/kernel.cpp b/torch/csrc/jit/codegen/onednn/kernel.cpp index 2d6d4892184..d750973057f 100644 --- a/torch/csrc/jit/codegen/onednn/kernel.cpp +++ b/torch/csrc/jit/codegen/onednn/kernel.cpp @@ -126,18 +126,18 @@ std::tuple LlgaKernel::prepareRunArgs( for (const auto i : c10::irange(numInputs)) { auto spec = inputSpecs_[i]; const auto& input = inputs[runArgsIdx_[i]]; - runInputs.push_back( - {spec.logical_tensor(), Engine::getEngine(), input.data_ptr()}); + runInputs.emplace_back( + spec.logical_tensor(), Engine::getEngine(), input.data_ptr()); } auto numConstantInputs = constantInputs_.size(); for (size_t i = 0; i < numConstantInputs; i++) { // constantInputSpecs are placed after graphInputSpecs auto constantInputSpecIdx = nGraphInputs_ + i; auto constantInputSpec = inputSpecs_[constantInputSpecIdx]; - runInputs.push_back( - {constantLogicalTensors_[i], - Engine::getEngine(), - constantInputs_[i].data_ptr()}); + runInputs.emplace_back( + constantLogicalTensors_[i], + Engine::getEngine(), + constantInputs_[i].data_ptr()); } for (const auto i : c10::irange(nOutputs_)) { @@ -174,10 +174,8 @@ std::tuple LlgaKernel::prepareRunArgs( } } outputs.push_back(inputTensor); - runOutputs.push_back( - {spec.logical_tensor(), - Engine::getEngine(), - inputTensor.data_ptr()}); + runOutputs.emplace_back( + spec.logical_tensor(), Engine::getEngine(), inputTensor.data_ptr()); return std::make_tuple(runInputs, runOutputs); } } @@ -197,8 +195,8 @@ std::tuple LlgaKernel::prepareRunArgs( #endif auto tensor = at::empty_strided(spec.sizes(), spec.strides(), opt); outputs.push_back(tensor); - runOutputs.push_back( - {spec.logical_tensor(), Engine::getEngine(), tensor.data_ptr()}); + runOutputs.emplace_back( + spec.logical_tensor(), Engine::getEngine(), tensor.data_ptr()); } } diff --git a/torch/csrc/jit/ir/ir.cpp b/torch/csrc/jit/ir/ir.cpp index 5a9abcab8e8..9b85b090982 100644 --- a/torch/csrc/jit/ir/ir.cpp +++ b/torch/csrc/jit/ir/ir.cpp @@ -1288,10 +1288,9 @@ void Node::assignTopoPosition() { Node::Node(Graph* graph_, NodeKind kind_) : kind_(kind_), graph_(graph_), - owning_block_(nullptr), + scope_(graph_->current_scope_), - callstack_(std::nullopt), - op_(nullptr) { + callstack_(std::nullopt) { graph_->all_nodes.emplace(this); } diff --git a/torch/csrc/jit/ir/ir.h b/torch/csrc/jit/ir/ir.h index 1169934def9..57c6d9ef89d 100644 --- a/torch/csrc/jit/ir/ir.h +++ b/torch/csrc/jit/ir/ir.h @@ -328,7 +328,7 @@ struct TORCH_API Node { // subblocks std::vector blocks_; Graph* graph_; - Block* owning_block_; + Block* owning_block_{nullptr}; std::optional source_range_; ScopePtr scope_; std::optional callstack_; @@ -336,7 +336,7 @@ struct TORCH_API Node { // This field is effective a cache that's populated on attribute lookups and // invalidated every time we perform an operation that could potentially // change the schema. note: mutable because schema_ is effectively a cache - mutable const Operator* op_; + mutable const Operator* op_{nullptr}; topo_position_t topo_position_ = 0; // a managing wrapper for Python to allow invalidation std::shared_ptr> wrap_; diff --git a/torch/csrc/jit/runtime/instruction.h b/torch/csrc/jit/runtime/instruction.h index fbaca4b6ea7..95345b4cbc1 100644 --- a/torch/csrc/jit/runtime/instruction.h +++ b/torch/csrc/jit/runtime/instruction.h @@ -83,12 +83,11 @@ enum OpCode : uint8_t { struct Instruction { OpCode op; - uint8_t unused; + uint8_t unused{0}; uint16_t N; int32_t X; // TODO: check for overflow - Instruction(OpCode op, int32_t X, uint16_t N) - : op(op), unused(0), N(N), X(X) {} + Instruction(OpCode op, int32_t X, uint16_t N) : op(op), N(N), X(X) {} }; std::ostream& operator<<(std::ostream& out, Instruction inst); diff --git a/torch/csrc/jit/runtime/static/memory_planner.cpp b/torch/csrc/jit/runtime/static/memory_planner.cpp index d1051b94b63..db313170a5a 100644 --- a/torch/csrc/jit/runtime/static/memory_planner.cpp +++ b/torch/csrc/jit/runtime/static/memory_planner.cpp @@ -131,8 +131,7 @@ std::vector assignStorageToManagedTensors( return managed_tensor_groups; } -ManagedStorages::ManagedStorages() - : storages_(nullptr), size_(0), capacity_(0) {} +ManagedStorages::ManagedStorages() = default; ManagedStorages::~ManagedStorages() { deallocate(); diff --git a/torch/csrc/jit/runtime/static/memory_planner.h b/torch/csrc/jit/runtime/static/memory_planner.h index d9755d83048..84352137247 100644 --- a/torch/csrc/jit/runtime/static/memory_planner.h +++ b/torch/csrc/jit/runtime/static/memory_planner.h @@ -81,13 +81,13 @@ class ManagedStorages { private: // We will use placement-new to add new storages to this buffer - at::StorageImpl* storages_; + at::StorageImpl* storages_{nullptr}; // Current number of storages that have been placed into the storage buffer - size_t size_; + size_t size_{0}; // Total allocated capacity of the storage buffer - size_t capacity_; + size_t capacity_{0}; }; TORCH_API std::vector assignStorageToManagedTensors( diff --git a/torch/csrc/jit/serialization/mobile_bytecode_generated.h b/torch/csrc/jit/serialization/mobile_bytecode_generated.h index b61fad2ab7a..06f527d56a2 100644 --- a/torch/csrc/jit/serialization/mobile_bytecode_generated.h +++ b/torch/csrc/jit/serialization/mobile_bytecode_generated.h @@ -602,7 +602,7 @@ struct TensorMetadata FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { bool requires_grad() const { return GetField(VT_REQUIRES_GRAD, 0) != 0; } - bool mutate_requires_grad(bool _requires_grad = 0) { + bool mutate_requires_grad(bool _requires_grad = false) { return SetField(VT_REQUIRES_GRAD, static_cast(_requires_grad), 0); } const torch::jit::mobile::serialization::QuantizedSchema *quantized_schema() const { diff --git a/torch/csrc/jit/tensorexpr/cpp_codegen.cpp b/torch/csrc/jit/tensorexpr/cpp_codegen.cpp index 6b03b939ace..87e428a21ec 100644 --- a/torch/csrc/jit/tensorexpr/cpp_codegen.cpp +++ b/torch/csrc/jit/tensorexpr/cpp_codegen.cpp @@ -43,7 +43,7 @@ static std::string declareExternalFunction(const std::string& func_name) { "int64_t* extra_args);"; } -CppPrinter::CppPrinter(std::ostream* os) : IRPrinter(*os), lane_(0) {} +CppPrinter::CppPrinter(std::ostream* os) : IRPrinter(*os) {} CppPrinter::~CppPrinter() = default; diff --git a/torch/csrc/jit/tensorexpr/cpp_codegen.h b/torch/csrc/jit/tensorexpr/cpp_codegen.h index 6b6011b66a3..b2f8c5d4505 100644 --- a/torch/csrc/jit/tensorexpr/cpp_codegen.h +++ b/torch/csrc/jit/tensorexpr/cpp_codegen.h @@ -57,7 +57,7 @@ class TORCH_API CppPrinter : public IRPrinter { void visit(const BroadcastPtr& /*v*/) override; private: - int lane_; + int lane_{0}; std::unordered_map vector_vars_; }; diff --git a/torch/csrc/lazy/backend/backend_device.h b/torch/csrc/lazy/backend/backend_device.h index 3a4a722323f..e8dca5dfed9 100644 --- a/torch/csrc/lazy/backend/backend_device.h +++ b/torch/csrc/lazy/backend/backend_device.h @@ -21,7 +21,7 @@ struct TORCH_API BackendDeviceType { // Note: previous default value was '0', which actually maps to at::kCPU, at // least now it is explicit, we may want to make default/undefined semantics // more clear though - BackendDeviceType() : type((int8_t)at::kCPU) {} + BackendDeviceType() = default; BackendDeviceType(int8_t type) : type(type) {} virtual ~BackendDeviceType() = default; diff --git a/torch/csrc/profiler/standalone/execution_trace_observer.cpp b/torch/csrc/profiler/standalone/execution_trace_observer.cpp index 03c480cc821..450d7b821d1 100644 --- a/torch/csrc/profiler/standalone/execution_trace_observer.cpp +++ b/torch/csrc/profiler/standalone/execution_trace_observer.cpp @@ -112,7 +112,7 @@ struct TORCH_API ExecutionTraceObserver { // NOLINT // Uses the underlying TensorImpl object pointer as the key and map to its // unique id. - std::map objectId{}; + std::map objectId; // Observer run state. enum class RunState { uninitialized, disabled, enabled }; diff --git a/torch/csrc/profiler/stubs/cuda.cpp b/torch/csrc/profiler/stubs/cuda.cpp index 45c288b976a..1290721a737 100644 --- a/torch/csrc/profiler/stubs/cuda.cpp +++ b/torch/csrc/profiler/stubs/cuda.cpp @@ -64,8 +64,8 @@ struct CUDAMethods : public ProfilerStubs { float elapsed( const ProfilerVoidEventStub* event_, const ProfilerVoidEventStub* event2_) const override { - auto event = (const ProfilerEventStub*)(event_); - auto event2 = (const ProfilerEventStub*)(event2_); + auto event = (const ProfilerEventStub*)event_; + auto event2 = (const ProfilerEventStub*)event2_; TORCH_CUDA_CHECK(cudaEventSynchronize(event->get())); TORCH_CUDA_CHECK(cudaEventSynchronize(event2->get())); float ms = 0; diff --git a/torch/csrc/stable/library.h b/torch/csrc/stable/library.h index 9c8424ac16b..2bca33179b4 100644 --- a/torch/csrc/stable/library.h +++ b/torch/csrc/stable/library.h @@ -150,7 +150,7 @@ using unbox_type_t = template std::tuple unbox_to_tuple_impl( StableIValue* stack, - std::index_sequence) { + std::index_sequence /*unused*/) { return std::make_tuple(to(stack[I])...); } @@ -164,7 +164,7 @@ template void box_from_tuple_impl( StableIValue* stack, std::tuple vals, - std::index_sequence) { + std::index_sequence /*unused*/) { ((stack[I] = from(std::get(vals))), ...); } diff --git a/torch/csrc/utils/generated_serialization_types.h b/torch/csrc/utils/generated_serialization_types.h index 706d7940ee7..bc26aa6293c 100644 --- a/torch/csrc/utils/generated_serialization_types.h +++ b/torch/csrc/utils/generated_serialization_types.h @@ -45,8 +45,8 @@ struct adl_serializer> { }; NLOHMANN_JSON_NAMESPACE_END -namespace torch { -namespace _export { + +namespace torch::_export { template class ForwardRef { @@ -1944,8 +1944,8 @@ class Graph { std::unordered_map sym_int_values; std::unordered_map sym_bool_values; bool is_single_tensor_return = false; - std::unordered_map custom_obj_values = {}; - std::unordered_map sym_float_values = {}; + std::unordered_map custom_obj_values; + std::unordered_map sym_float_values; public: @@ -3066,8 +3066,8 @@ class GraphModule { Graph graph; GraphSignature signature; std::vector module_call_graph; - std::unordered_map metadata = {}; - std::unordered_map treespec_namedtuple_fields = {}; + std::unordered_map metadata; + std::unordered_map treespec_namedtuple_fields; public: @@ -3148,9 +3148,9 @@ class ExportedProgram { std::unordered_map opset_version; std::unordered_map range_constraints; SchemaVersion schema_version; - std::vector verifiers = {}; + std::vector verifiers; std::string torch_version = "<=2.4"; - std::vector guards_code = {}; + std::vector guards_code; public: @@ -3866,7 +3866,6 @@ inline void from_json(const nlohmann::json& nlohmann_json_j, UserOutputSpec& nlo template ForwardRef::ForwardRef(ForwardRef&&) = default; template ForwardRef& ForwardRef::operator=(ForwardRef&&) = default; template ForwardRef::~ForwardRef() = default; -} // namespace _export -} // namespace torch +} // namespace torch::_export // clang-format on diff --git a/torch/csrc/utils/python_arg_parser.cpp b/torch/csrc/utils/python_arg_parser.cpp index 5fa0986cc81..999bd00b3bc 100644 --- a/torch/csrc/utils/python_arg_parser.cpp +++ b/torch/csrc/utils/python_arg_parser.cpp @@ -127,11 +127,7 @@ bool should_allow_numbers_as_tensors(const std::string& name) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) FunctionParameter::FunctionParameter(const std::string& fmt, bool keyword_only) - : optional(false), - allow_none(false), - keyword_only(keyword_only), - size(0), - default_scalar(0) { + : keyword_only(keyword_only), default_scalar(0) { auto space = fmt.find(' '); TORCH_CHECK( space != std::string::npos, "FunctionParameter(): missing type: " + fmt); @@ -1473,12 +1469,7 @@ void FunctionParameter::set_default_str(const std::string& str) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) FunctionSignature::FunctionSignature(const std::string& fmt, int index) - : min_args(0), - max_args(0), - max_pos_args(0), - index(index), - hidden(false), - deprecated(false) { + : index(index) { auto open_paren = fmt.find('('); if (open_paren == std::string::npos) { TORCH_CHECK(false, "missing opening parenthesis: " + fmt); @@ -1820,7 +1811,7 @@ bool FunctionSignature::parse( PythonArgParser::PythonArgParser( const std::vector& fmts, bool traceable) - : max_args(0), traceable(traceable) { + : traceable(traceable) { int index = 0; for (auto& fmt : fmts) { signatures_.emplace_back(fmt, index); diff --git a/torch/csrc/utils/python_arg_parser.h b/torch/csrc/utils/python_arg_parser.h index 4a73a219167..55a59024509 100644 --- a/torch/csrc/utils/python_arg_parser.h +++ b/torch/csrc/utils/python_arg_parser.h @@ -177,7 +177,7 @@ struct PYBIND11_EXPORT PythonArgParser { std::vector signatures_; std::string function_name; - size_t max_args; + size_t max_args{0}; bool traceable; }; @@ -200,12 +200,12 @@ struct FunctionSignature { std::string name; std::vector params; - size_t min_args; - size_t max_args; - size_t max_pos_args; + size_t min_args{0}; + size_t max_args{0}; + size_t max_pos_args{0}; int index; - bool hidden; - bool deprecated; + bool hidden{false}; + bool deprecated{false}; }; // PythonArgs contains bound Python arguments for an actual invocation @@ -332,11 +332,11 @@ struct FunctionParameter { TORCH_PYTHON_API std::string type_name() const; ParameterType type_; - bool optional; - bool allow_none; + bool optional{false}; + bool allow_none{false}; bool keyword_only; bool allow_numbers_as_tensors = false; - int size; + int size{0}; std::string name; // having this as a raw PyObject * will presumably leak it, but these are only // held by static objects anyway, and Py_Finalize can already be called when @@ -621,7 +621,7 @@ inline std::vector PythonArgs::symintlist(int i) { if (is_symint(py::handle(obj))) { res.push_back(py::handle(obj).cast()); } else if (is_dynint(py::handle(obj))) { - res.push_back(py::handle(obj).cast()); + res.emplace_back(py::handle(obj).cast()); } else { res.emplace_back(THPUtils_unpackIndex(obj)); } diff --git a/torch/csrc/utils/pythoncapi_compat.h b/torch/csrc/utils/pythoncapi_compat.h index cdfdafa84eb..8df17424bdf 100644 --- a/torch/csrc/utils/pythoncapi_compat.h +++ b/torch/csrc/utils/pythoncapi_compat.h @@ -1743,7 +1743,7 @@ static inline void _PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size) { #if PY_VERSION_HEX >= 0x030C0000 - op->long_value.lv_tag = (uintptr_t)(1 - sign) | ((uintptr_t)(size) << 3); + op->long_value.lv_tag = (uintptr_t)(1 - sign) | ((uintptr_t)size << 3); #elif PY_VERSION_HEX >= 0x030900A4 Py_SET_SIZE(op, sign * size); #else diff --git a/torch/lib/libshm/manager.cpp b/torch/lib/libshm/manager.cpp index 5647f5a350c..5d2c318c251 100644 --- a/torch/lib/libshm/manager.cpp +++ b/torch/lib/libshm/manager.cpp @@ -27,10 +27,10 @@ const int SHUTDOWN_TIMEOUT = 2000; // 2s #endif struct ClientSession { - ClientSession(ManagerSocket s) : socket(std::move(s)), pid(0) {} + ClientSession(ManagerSocket s) : socket(std::move(s)) {} ManagerSocket socket; - pid_t pid; + pid_t pid{0}; }; static std::vector pollfds; diff --git a/torch/nativert/executor/DelegateExecutor.h b/torch/nativert/executor/DelegateExecutor.h index 7d88f989877..4566e662e6d 100644 --- a/torch/nativert/executor/DelegateExecutor.h +++ b/torch/nativert/executor/DelegateExecutor.h @@ -22,7 +22,7 @@ using MakeProxyExecutorFn = // This is the extension point for delegation backends. class DelegateExecutor { public: - virtual ~DelegateExecutor() {} + virtual ~DelegateExecutor() = default; // Runtime calls processWeights() to pass the weights to the delegate backend. // Typically, a backend would perform some form of validation and processing, diff --git a/torch/nativert/executor/memory/FunctionSchema.h b/torch/nativert/executor/memory/FunctionSchema.h index 713df508058..6cf013227f3 100644 --- a/torch/nativert/executor/memory/FunctionSchema.h +++ b/torch/nativert/executor/memory/FunctionSchema.h @@ -3,6 +3,8 @@ #include #include +#include + namespace torch::nativert { struct InputOutputIdxPair { @@ -15,12 +17,12 @@ using AliasingSpec = std::vector; class FunctionSchema { public: explicit FunctionSchema( - const c10::FunctionSchema& schema, + c10::FunctionSchema schema, AliasingSpec&& aliasing_spec = {}, OpKernelKind kernel_kind = OpKernelKind::kInterpreterFallbackKernel) : aliasing_spec_(std::move(aliasing_spec)), kernel_kind_(kernel_kind), - c10_fn_schema_(schema) {} + c10_fn_schema_(std::move(schema)) {} c10::FunctionSchema& base_schema() { return c10_fn_schema_; diff --git a/torch/nativert/graph/Graph.h b/torch/nativert/graph/Graph.h index c713df94018..7ac14d38903 100644 --- a/torch/nativert/graph/Graph.h +++ b/torch/nativert/graph/Graph.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -112,7 +113,10 @@ using ValueId = int; class Value { public: explicit Value(ValueId id, std::string name, Type t, Node* producer) - : name_(std::move(name)), id_(id), type_(t), producer_(producer) { + : name_(std::move(name)), + id_(id), + type_(std::move(t)), + producer_(producer) { TORCH_INTERNAL_ASSERT_DEBUG_ONLY(name_ == this->name()); } diff --git a/torch/nativert/graph/passes/SubgraphRewriter.h b/torch/nativert/graph/passes/SubgraphRewriter.h index b2018a1f7f3..a03e04055cb 100644 --- a/torch/nativert/graph/passes/SubgraphRewriter.h +++ b/torch/nativert/graph/passes/SubgraphRewriter.h @@ -3,6 +3,8 @@ #include #include +#include + namespace torch::nativert { /* @@ -138,7 +140,7 @@ struct RewriteRule { **/ class SubgraphRewriter { public: - SubgraphRewriter(const std::string& name) : name_(name) {} + SubgraphRewriter(std::string name) : name_(std::move(name)) {} /** * Registers the rewrite pattern. diff --git a/torch/nativert/kernels/AutoFunctionalizeKernel.h b/torch/nativert/kernels/AutoFunctionalizeKernel.h index f9d6e6e58c6..62b7af0c1d9 100644 --- a/torch/nativert/kernels/AutoFunctionalizeKernel.h +++ b/torch/nativert/kernels/AutoFunctionalizeKernel.h @@ -14,7 +14,7 @@ class UnsafeAutoFunctionalizeKernel : public OpKernel { UnsafeAutoFunctionalizeKernel() = delete; // deleted default constructor UnsafeAutoFunctionalizeKernel(const Node* node); - void computeInternal(ExecutionFrame& executionFrame) const override final; + void computeInternal(ExecutionFrame& executionFrame) const final; private: c10::OperatorHandle op_; diff --git a/torch/nativert/kernels/CallTorchBindKernel.h b/torch/nativert/kernels/CallTorchBindKernel.h index acddf019d38..847162553e4 100644 --- a/torch/nativert/kernels/CallTorchBindKernel.h +++ b/torch/nativert/kernels/CallTorchBindKernel.h @@ -13,7 +13,7 @@ class CallTorchBindKernel : public OpKernel { CallTorchBindKernel() = delete; // deleted default constructor CallTorchBindKernel(const Node* node); - void computeInternal(ExecutionFrame& executionFrame) const override final; + void computeInternal(ExecutionFrame& executionFrame) const final; private: std::string methodName_; diff --git a/torch/nativert/kernels/ETCallDelegateKernel.h b/torch/nativert/kernels/ETCallDelegateKernel.h index c7eefc3b4ee..fc62d859204 100644 --- a/torch/nativert/kernels/ETCallDelegateKernel.h +++ b/torch/nativert/kernels/ETCallDelegateKernel.h @@ -13,7 +13,7 @@ class ETCallDelegateKernel : public OpKernel { const Node* node, ETDelegateExecutor& delegateExecutor); - void computeInternal(ExecutionFrame& executionFrame) const override final; + void computeInternal(ExecutionFrame& executionFrame) const final; private: ETDelegateExecutor& delegateExecutor_; diff --git a/torch/nativert/kernels/KernelRegistry.cpp b/torch/nativert/kernels/KernelRegistry.cpp index f157257e733..27ffc761a88 100644 --- a/torch/nativert/kernels/KernelRegistry.cpp +++ b/torch/nativert/kernels/KernelRegistry.cpp @@ -1318,7 +1318,7 @@ class OpKernel_aten__to_copy : public C10Kernel { } } - void computeInternal(ExecutionFrame& executionFrame) const override final { + void computeInternal(ExecutionFrame& executionFrame) const final { const auto& self = KernelInput(0).toTensor(); auto& out = KernelOutput(0); diff --git a/torch/nativert/kernels/PrimKernelRegistry.cpp b/torch/nativert/kernels/PrimKernelRegistry.cpp index d9251da2cb1..21d61203548 100644 --- a/torch/nativert/kernels/PrimKernelRegistry.cpp +++ b/torch/nativert/kernels/PrimKernelRegistry.cpp @@ -32,7 +32,7 @@ class OpKernel_prim_listpack : public OpKernel { } } - void computeInternal(ExecutionFrame& executionFrame) const override final { + void computeInternal(ExecutionFrame& executionFrame) const final { RECORD_USER_SCOPE("nativert::OpKernel_prim_listpack"); c10::List list(type_); list.reserve(numInputs()); @@ -79,7 +79,7 @@ class OpKernel_variadic_concat : public OpKernel { ? constantToIValue(node_->getAttribute("dim").value).toInt() : 0; } - void computeInternal(ExecutionFrame& executionFrame) const override final { + void computeInternal(ExecutionFrame& executionFrame) const final { { const size_t numNodeInps = numInputs(); auto numCatInps = numNodeInps; @@ -124,7 +124,7 @@ class OpKernel_variadic_stack : public OpKernel { ? constantToIValue(node_->getAttribute("dim").value).toInt() : 0; } - void computeInternal(ExecutionFrame& executionFrame) const override final { + void computeInternal(ExecutionFrame& executionFrame) const final { { const size_t numNodeInps = numInputs(); auto numStackInps = numNodeInps; diff --git a/torch/nativert/python/Bindings.cpp b/torch/nativert/python/Bindings.cpp index 77939702a2d..0cb861cd356 100644 --- a/torch/nativert/python/Bindings.cpp +++ b/torch/nativert/python/Bindings.cpp @@ -10,8 +10,7 @@ namespace py = pybind11; template using shared_ptr_class_ = py::class_>; -namespace torch { -namespace nativert { +namespace torch::nativert { using torch::nativert::detail::argsToIValue; @@ -76,5 +75,4 @@ void initModelRunnerPybind(py::module& m) { #endif // !defined(OVRSOURCE) } -} // namespace nativert -} // namespace torch +} // namespace torch::nativert