From 1d1d074072ecb0aa6ca95e3f43221d2275e16d74 Mon Sep 17 00:00:00 2001 From: cyy Date: Sat, 20 Jul 2024 23:31:03 +0000 Subject: [PATCH] [3/N] Fix Wunused-parameter warnings (#131271) Follows #131170 Pull Request resolved: https://github.com/pytorch/pytorch/pull/131271 Approved by: https://github.com/ezyang --- aten/src/ATen/EmptyTensor.cpp | 2 +- aten/src/ATen/FunctionalizeFallbackKernel.cpp | 12 +++++------ aten/src/ATen/LegacyBatchingRegistrations.cpp | 2 +- aten/src/ATen/TensorMeta.h | 20 +++++++++---------- aten/src/ATen/core/jit_type.h | 6 +++--- aten/src/ATen/detail/MTIAHooksInterface.h | 3 ++- .../ATen/detail/PrivateUse1HooksInterface.h | 2 ++ aten/src/ATen/native/TensorFactories.h | 2 +- c10/core/ConstantSymNodeImpl.h | 12 ++++++++--- c10/core/SymBool.h | 5 ++++- c10/core/TensorImpl.h | 2 +- torch/library.h | 4 ++-- 12 files changed, 42 insertions(+), 30 deletions(-) diff --git a/aten/src/ATen/EmptyTensor.cpp b/aten/src/ATen/EmptyTensor.cpp index 8238dcc000b6..356e5da928ac 100644 --- a/aten/src/ATen/EmptyTensor.cpp +++ b/aten/src/ATen/EmptyTensor.cpp @@ -330,7 +330,7 @@ struct MetaAllocator final : public at::Allocator { static void deleter(void* const pointer) { TORCH_INTERNAL_ASSERT(!pointer); } - DataPtr allocate(const size_t nbytes) override { + DataPtr allocate(const size_t nbytes [[maybe_unused]]) override { return {nullptr, nullptr, &deleter, at::Device(DeviceType::Meta)}; } DeleterFnPtr raw_deleter() const override { diff --git a/aten/src/ATen/FunctionalizeFallbackKernel.cpp b/aten/src/ATen/FunctionalizeFallbackKernel.cpp index d24885d38b93..36b6f91c1d99 100644 --- a/aten/src/ATen/FunctionalizeFallbackKernel.cpp +++ b/aten/src/ATen/FunctionalizeFallbackKernel.cpp @@ -28,7 +28,7 @@ #endif namespace { - void functionalizeFallback(const c10::OperatorHandle& op, c10::DispatchKeySet dispatchKeySet, torch::jit::Stack* stack) { + void functionalizeFallback(const c10::OperatorHandle& op, c10::DispatchKeySet dispatchKeySet [[maybe_unused]], torch::jit::Stack* stack) { const auto& schema = op.schema(); // NB: auto_functionalize handles the case where outputs do not have alias info. // This error message therefore suggests users to modify their custom op to the @@ -125,7 +125,7 @@ namespace { // - when we resize to a larger size, it acts as a mutation // - when we resize to a smaller size, it acts as a view // See Note [resize_ in Functionalization] for more dtails -static const at::Tensor & resize__functionalization(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::IntArrayRef size, std::optional memory_format) { +static const at::Tensor & resize__functionalization(c10::DispatchKeySet dispatchKeySet [[maybe_unused]], const at::Tensor & self, at::IntArrayRef size, std::optional memory_format) { // First unwrap the tensor arguments at::Tensor self_; if (at::functionalization::impl::isFunctionalTensor(self)) { @@ -169,14 +169,14 @@ static const at::Tensor & resize__functionalization(c10::DispatchKeySet dispatch // We have to emulate this "slicing" with an as_strided call. auto reapply_views = at::functionalization::impl::getFunctionalizationReapplyViewsTLS(); at::functionalization::ViewMeta view_meta = at::functionalization::ViewMeta( - [reapply_views = reapply_views, size = size.vec()](const at::Tensor & base, int64_t mutated_view_idx) -> at::Tensor { + [reapply_views = reapply_views, size = size.vec()](const at::Tensor & base, int64_t mutated_view_idx [[maybe_unused]]) -> at::Tensor { if (reapply_views) { return base.as_strided(size, c10::contiguous_strides(size)); } else { return at::as_strided_copy(base, size, c10::contiguous_strides(size)); } }, - [size = size.vec()](const at::Tensor & base, const at::Tensor & mutated_view, int64_t mutated_view_idx) -> at::Tensor { + [size = size.vec()](const at::Tensor & base, const at::Tensor & mutated_view, int64_t mutated_view_idx [[maybe_unused]]) -> at::Tensor { return base.as_strided_scatter(mutated_view, size, c10::contiguous_strides(size)); }, /*has_symbolic_inputs=*/false @@ -302,10 +302,10 @@ static at::Tensor _unsafe_view_functionalize(const at::Tensor & self, at::SymInt bool has_symbolic_inputs = std::any_of(size.begin(), size.end(), [=](auto& s) { return s.is_symbolic(); }); at::functionalization::ViewMeta view_meta = at::functionalization::ViewMeta( - [size = size.vec()](const at::Tensor & base, int64_t mutated_view_idx) -> at::Tensor { + [size = size.vec()](const at::Tensor & base, int64_t mutated_view_idx [[maybe_unused]]) -> at::Tensor { return at::_unsafe_view_symint(base, size); }, - [size = size.vec()](const at::Tensor & base, const at::Tensor & mutated_view, int64_t mutated_view_idx) -> at::Tensor { + [size = size.vec()](const at::Tensor & base, const at::Tensor & mutated_view, int64_t mutated_view_idx [[maybe_unused]]) -> at::Tensor { return at::_unsafe_view_symint(mutated_view, base.sym_sizes()); }, /*has_symbolic_inputs=*/has_symbolic_inputs diff --git a/aten/src/ATen/LegacyBatchingRegistrations.cpp b/aten/src/ATen/LegacyBatchingRegistrations.cpp index 83f1d6463b48..a51c25663dde 100644 --- a/aten/src/ATen/LegacyBatchingRegistrations.cpp +++ b/aten/src/ATen/LegacyBatchingRegistrations.cpp @@ -558,7 +558,7 @@ static void checkBasicAsStridedValidForSlice( "rewrite the `as_strided` call as a sequence of PyTorch view operations"); } -Tensor _reshape_alias_batching_rule(const Tensor& self, IntArrayRef sizes, IntArrayRef strides) { +Tensor _reshape_alias_batching_rule(const Tensor& self, IntArrayRef sizes, IntArrayRef strides [[maybe_unused]]) { return reshape_batching_rule(self, sizes); } diff --git a/aten/src/ATen/TensorMeta.h b/aten/src/ATen/TensorMeta.h index 8c5003a676d8..7576d1fd1fdd 100644 --- a/aten/src/ATen/TensorMeta.h +++ b/aten/src/ATen/TensorMeta.h @@ -93,11 +93,11 @@ struct TORCH_API MetaBase { // output. If `strides` does not match the given output strides, proxy outputs // will be created and passed to the IMPL function. virtual void set_output_strided( - int64_t output_idx, - IntArrayRef sizes, - IntArrayRef strides, - TensorOptions options, - DimnameList names = {}) { + int64_t output_idx [[maybe_unused]], + IntArrayRef sizes [[maybe_unused]], + IntArrayRef strides [[maybe_unused]], + TensorOptions options [[maybe_unused]], + DimnameList names [[maybe_unused]] = {}) { TORCH_INTERNAL_ASSERT(false, "set_output_strided not implemented."); } @@ -105,11 +105,11 @@ struct TORCH_API MetaBase { // outputs. This function has the same behavior as the old `set_output`: it // will only re-stride if the given output was resized. virtual void set_output_raw_strided( - int64_t output_idx, - IntArrayRef sizes, - IntArrayRef strides_hint, - TensorOptions options, - DimnameList names = {}) { + int64_t output_idx [[maybe_unused]], + IntArrayRef sizes [[maybe_unused]], + IntArrayRef strides_hint [[maybe_unused]], + TensorOptions options [[maybe_unused]], + DimnameList names [[maybe_unused]] = {}) { TORCH_INTERNAL_ASSERT(false, "set_output_strided not implemented."); } diff --git a/aten/src/ATen/core/jit_type.h b/aten/src/ATen/core/jit_type.h index f4706c9b4b80..01839231db36 100644 --- a/aten/src/ATen/core/jit_type.h +++ b/aten/src/ATen/core/jit_type.h @@ -1348,7 +1348,7 @@ struct TORCH_API SymIntType : public Type { std::string str() const override { return "SymInt"; } - std::string annotation_str_impl(const TypePrinter& printer = nullptr) const override { + std::string annotation_str_impl(const TypePrinter& printer [[maybe_unused]] = nullptr) const override { return "int"; } static const TypeKind Kind = TypeKind::SymIntType; @@ -1368,7 +1368,7 @@ struct TORCH_API SymFloatType : public Type { std::string str() const override { return "SymFloat"; } - std::string annotation_str_impl(const TypePrinter& printer = nullptr) const override { + std::string annotation_str_impl(const TypePrinter& printer [[maybe_unused]] = nullptr) const override { return "float"; } static const TypeKind Kind = TypeKind::SymFloatType; @@ -1388,7 +1388,7 @@ struct TORCH_API SymBoolType : public Type { std::string str() const override { return "SymBool"; } - std::string annotation_str_impl(const TypePrinter& printer = nullptr) const override { + std::string annotation_str_impl(const TypePrinter& printer [[maybe_unused]] = nullptr) const override { return "bool"; } static const TypeKind Kind = TypeKind::SymBoolType; diff --git a/aten/src/ATen/detail/MTIAHooksInterface.h b/aten/src/ATen/detail/MTIAHooksInterface.h index 0457402ae856..9b93d30fcc8a 100644 --- a/aten/src/ATen/detail/MTIAHooksInterface.h +++ b/aten/src/ATen/detail/MTIAHooksInterface.h @@ -9,7 +9,7 @@ #include #include - +C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter") namespace at { class Context; } @@ -101,3 +101,4 @@ TORCH_API const MTIAHooksInterface& getMTIAHooks(); TORCH_API bool isMTIAHooksBuilt(); } // namespace detail } // namespace at +C10_DIAGNOSTIC_POP() diff --git a/aten/src/ATen/detail/PrivateUse1HooksInterface.h b/aten/src/ATen/detail/PrivateUse1HooksInterface.h index ecca39665834..b6310ec66b32 100644 --- a/aten/src/ATen/detail/PrivateUse1HooksInterface.h +++ b/aten/src/ATen/detail/PrivateUse1HooksInterface.h @@ -6,6 +6,7 @@ #include #include #include +C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter") namespace at { struct TORCH_API PrivateUse1HooksInterface : AcceleratorHooksInterface { @@ -59,3 +60,4 @@ TORCH_API const at::PrivateUse1HooksInterface& getPrivateUse1Hooks(); } // namespace detail } // namespace at +C10_DIAGNOSTIC_POP() diff --git a/aten/src/ATen/native/TensorFactories.h b/aten/src/ATen/native/TensorFactories.h index d7a4d6483f6e..32d0a1dc5356 100644 --- a/aten/src/ATen/native/TensorFactories.h +++ b/aten/src/ATen/native/TensorFactories.h @@ -130,7 +130,7 @@ struct ZeroTensorAllocator final : public at::Allocator { DeleterFnPtr raw_deleter() const override { return deleter; } - void copy_data(void* dest, const void* src, std::size_t count) const final {} + void copy_data(void* dest [[maybe_unused]], const void* src [[maybe_unused]], std::size_t count [[maybe_unused]]) const final {} at::Device device_; }; diff --git a/c10/core/ConstantSymNodeImpl.h b/c10/core/ConstantSymNodeImpl.h index 791a81cace41..c371a860645c 100644 --- a/c10/core/ConstantSymNodeImpl.h +++ b/c10/core/ConstantSymNodeImpl.h @@ -33,15 +33,21 @@ class C10_API ConstantSymNodeImpl : public SymNodeImpl { bool is_float() override { return false; } - int64_t guard_int(const char* file, int64_t line) override { + int64_t guard_int( + const char* file [[maybe_unused]], + int64_t line [[maybe_unused]]) override { TORCH_CHECK(is_int(), "not an int"); return int_(); } - bool guard_bool(const char* file, int64_t line) override { + bool guard_bool( + const char* file [[maybe_unused]], + int64_t line [[maybe_unused]]) override { TORCH_CHECK(is_bool(), "not a bool"); return bool_(); } - double guard_float(const char* file, int64_t line) override { + double guard_float( + const char* file [[maybe_unused]], + int64_t line [[maybe_unused]]) override { TORCH_CHECK(false, "not a float"); } int64_t int_() override { diff --git a/c10/core/SymBool.h b/c10/core/SymBool.h index 06ce32c1a716..7227c1aa829c 100644 --- a/c10/core/SymBool.h +++ b/c10/core/SymBool.h @@ -90,7 +90,10 @@ C10_API std::ostream& operator<<(std::ostream& os, const SymBool& s); #define TORCH_SYM_INTERNAL_ASSERT(cond, ...) \ TORCH_INTERNAL_ASSERT((cond).expect_true(__FILE__, __LINE__), __VA_ARGS__) -inline bool guard_size_oblivious(bool b, const char* file, int64_t line) { +inline bool guard_size_oblivious( + bool b, + const char* file [[maybe_unused]], + int64_t line [[maybe_unused]]) { return b; } diff --git a/c10/core/TensorImpl.h b/c10/core/TensorImpl.h index e037311fe9a4..09af2f21a60d 100644 --- a/c10/core/TensorImpl.h +++ b/c10/core/TensorImpl.h @@ -1891,7 +1891,7 @@ struct C10_API TensorImpl : public c10::intrusive_ptr_target { * storage / storage_offset). See NOTE [ Metadata Change for a Detached Tensor * ] for details. */ - void set_allow_tensor_metadata_change(bool value) { + void set_allow_tensor_metadata_change(bool value [[maybe_unused]]) { // TODO: at some point, we should kill this field completely. allow_tensor_metadata_change_ = true; } diff --git a/torch/library.h b/torch/library.h index d75e6b019821..6c8059260f94 100644 --- a/torch/library.h +++ b/torch/library.h @@ -737,14 +737,14 @@ class TORCH_API Library final { // These overloads cover cases when a SelectiveStr (see Note [Selective // build]) has been disabled at compile time. In that case, don't generate // any code referencing the passed in functions at all. - Library& def(detail::SelectiveStr, const std::vector& tags = {}) & { + Library& def(detail::SelectiveStr, const std::vector& tags [[maybe_unused]] = {}) & { return *this; } Library& def(detail::SelectiveStr raw_schema, const std::vector& tags = {}) & { return def(raw_schema.operator const char*(), tags); } template - Library& def(detail::SelectiveStr, Func&& /*raw_f*/, const std::vector& tags = {}) & { + Library& def(detail::SelectiveStr, Func&& /*raw_f*/, const std::vector& tags [[maybe_unused]] = {}) & { return *this; } template