22 Commits

Author SHA1 Message Date
f231be25c6 Mark unused parameters in C++ code (#164912)
This PR adds unused parameter name comments in C++ declarations to improve code readability.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164912
Approved by: https://github.com/Skylion007
2025-10-09 06:23:25 +00:00
cyy
ad507789d1 [Reland] [11/N] Enable clang-tidy warnings on c10/util/*.h (#116751)
Reland of #116353 with C++ diagnostic macros restored.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116751
Approved by: https://github.com/albanD
2024-01-08 11:07:58 +00:00
1c69d0bdb5 Revert "[11/N] Enable clang-tidy warnings on c10/util/*.h (#116353)"
This reverts commit 37aae5932c26c3729d68b6ebdf00e618fe229b1c.

Reverted https://github.com/pytorch/pytorch/pull/116353 on behalf of https://github.com/izaitsevfb due to Reverting, breaks internal builds: error: implicit conversion from 'long long' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion] ([comment](https://github.com/pytorch/pytorch/pull/116353#issuecomment-1876045800))
2024-01-03 22:22:11 +00:00
cyy
37aae5932c [11/N] Enable clang-tidy warnings on c10/util/*.h (#116353)
This PR enables clang-tidy coverage on c10/util/*.h
Pull Request resolved: https://github.com/pytorch/pytorch/pull/116353
Approved by: https://github.com/albanD
2023-12-30 14:38:39 +00:00
cyy
968b94bef2 [8/N] Fixes clang-tidy warnings in c10/{core,util}/*.h (#116082)
This patch enables clang-tidy coverage on c10/**/*.h and contains other fixes.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/116082
Approved by: https://github.com/Skylion007
2023-12-20 12:22:21 +00:00
e7115dbecf [pytorch] Suppress C4624 warnings on Windows (#106348)
Summary:
Building on Microsoft Visual Studio can show excessive warnings of the form:
```
caffe2\c10\util\Optional.h(212): warning C4624: 'c10::constexpr_storage_t<T>': destructor was implicitly defined as deleted
        with
        [
            T=std::string
        ]
caffe2\c10\util\Optional.h(411): note: see reference to class template instantiation 'c10::constexpr_storage_t<T>' being compiled
        with
        [
            T=std::string
        ]
caffe2\c10\util\Optional.h(549): note: see reference to class template instantiation 'c10::trivially_copyable_optimization_optional_base<T>' being compiled
        with
        [
            T=std::string
        ]
```

While we have macros such as `C10_CLANG_DIAGNOSTIC_{PUSH,POP,IGNORE}`, no there's no equivalent `C10_MSVC_DIAGNOSTIC_*`, so just do the suppressions explicitly.

Test Plan: CI should complete, but Windows build log will no longer contain C4624 warnings

Differential Revision: D47736268

Pull Request resolved: https://github.com/pytorch/pytorch/pull/106348
Approved by: https://github.com/albanD
2023-08-02 01:57:21 +00:00
cyy
1a32db15e7 Some performance fixes (#94034)
Applies some performance fixes

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94034
Approved by: https://github.com/Skylion007
2023-02-04 02:17:48 +00:00
5b2afaaca8 Fix Vulkan compiling issues on Windows (#92207)
PR based on #61431
Fix USE_VULKAN=1 and USE_VULKAN_WRAPPER=0 not compiling on Windows.
Change designated initializers since they require C++20.
Rename Hasher typename since it's not compiling due to https://developercommunity.visualstudio.com/t/1397858

Fixes #59519

Pull Request resolved: https://github.com/pytorch/pytorch/pull/92207
Approved by: https://github.com/ezyang
2023-01-31 18:58:15 +00:00
a34a9c3471 Perf: Apply more clang-tidy fixups to torch headers (#91445)
Applies so more fixes to headers that may have been missed before for performance optimization.cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @EikanWang @ezyang since this more in the series of the clang-tidy fixup

This is PR fixes 3 main issues:
1. Use emplacement more in headers
1. Avoid unnecessary copies and use const ref when possible
1. Default any special functions when possible to make them potentially trivial and more readable.
1. There is also one change in this PR that tries to prevent unnecessary math promotion, the rest of these changes are in another PR
Pull Request resolved: https://github.com/pytorch/pytorch/pull/91445
Approved by: https://github.com/ezyang
2022-12-29 23:43:45 +00:00
7591444cf1 [caffe2] Fix shadowed variable warnings in clang (#80902)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80902

This resolves build errors when using [-Werror,-Wshadow] under MSVC.

Manually rename method parameters to avoid shadowing instance members - suffix parameters w/ _ (would prefer to suffix members, but that's a bigger change).

Renaming parameters instead of member variables should reduce unintended side-effects.

Remove `pragma ignore("-Wshadow")` now that shadowed variables are resolved.

Test Plan:

Build as dependent library using clang asan for windows using MSVC.

Before: Build Failure when using warnings as errors (due to `-Wshadow` remaining enabled under MSVC with above mentioned shadowing warnings)

```
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2036,22): error: declaration shadows a field of 'ska_ordered::fibonacci_hash_policy' [-Werror,-Wshadow]
  void commit(int8_t shift) {
                     ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2044,10): note: previous declaration is here
  int8_t shift = 63;
         ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(986,16): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
      uint64_t num_slots_minus_one,
               ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2053,7): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::~sherwood_v3_table' requested here
class order_preserving_flat_hash_map
      ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(795,12): note: previous declaration is here
  uint64_t num_slots_minus_one = 0;
           ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(987,14): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
      int8_t max_lookups) {
             ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(797,10): note: previous declaration is here
  int8_t max_lookups = detailv3::min_lookups - 1;
         ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(830,45): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
  uint64_t num_buckets_for_reserve(uint64_t num_elements) const {
                                            ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(367,5): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::rehash_for_other_container' requested here
    rehash_for_other_container(other);
    ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(358,9): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::sherwood_v3_table' requested here
      : sherwood_v3_table(
        ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2053,7): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::sherwood_v3_table' requested here
class order_preserving_flat_hash_map
      ^
xplat/caffe2\c10/util/intrusive_ptr.h(574,44): note: in instantiation of function template specialization 'c10::intrusive_ptr<c10::detail::DictImpl, c10::detail::intrusive_target_default_null_type<c10::detail::DictImpl> >::make<const ska_ordered::order_preserving_flat_hash_map<c10::IValue, c10::IValue, c10::detail::DictKeyHash, c10::detail::DictKeyEqualTo, std::allocator<std::pair<c10::IValue, c10::IValue> > > &, const c10::detail::DictImpl::DictElementTypes &>' requested here
  return intrusive_ptr<TTarget, NullType>::make(std::forward<Args>(args)...);
                                           ^
xplat/caffe2/aten/src\ATen/core/Dict_inl.h(62,10): note: in instantiation of function template specialization 'c10::make_intrusive<c10::detail::DictImpl, c10::detail::intrusive_target_default_null_type<c10::detail::DictImpl>, const ska_ordered::order_preserving_flat_hash_map<c10::IValue, c10::IValue, c10::detail::DictKeyHash, c10::detail::DictKeyEqualTo, std::allocator<std::pair<c10::IValue, c10::IValue> > > &, const c10::detail::DictImpl::DictElementTypes &>' requested here
  return make_intrusive<DictImpl>(dict, elementTypes);
         ^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(799,12): note: previous declaration is here
  uint64_t num_elements = 0;
           ^
5 errors generated.
```

After:
`BUILD SUCCEEDED`

Run dependent tests on applications with these changes - confirm all tests pass.

Reviewed By: malfet

Differential Revision: D30517712

Pull Request resolved: https://github.com/pytorch/pytorch/pull/80902
Approved by: https://github.com/malfet
2022-07-07 16:07:41 +00:00
a383d01774 [fbcode][warnings] Suppress warnings in caffe2/c10 (#71356)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71356

Suppress remaining header based warnings in `caffe2/c10` when building with `clang`

Test Plan: CI pass

Reviewed By: r-barnes

Differential Revision: D33600097

fbshipit-source-id: e1c0d84a0bad768eb03e047d62b5379cf28b48e2
2022-01-15 18:34:08 -08:00
44cc873fba [PyTorch] Autoformat c10 (#56830)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56830

Opt into formatting on GitHub and format everything. This is a trial run before turning on formatting for more and eventually all of the codebase.

Test Plan: CI

Reviewed By: zertosh

Differential Revision: D27979080

fbshipit-source-id: a80f0c48691c08ae8ca0af06377b87e6a2351151
2021-04-30 21:23:28 -07:00
23f2fb0aec #include <stdexcept> into flat_hash_map.h (#27478)
Summary:
Fixing https://github.com/pytorch/pytorch/issues/27266

In general we should not rely on transitively included headers, we should implicitly include all headers if their members are used in the source file.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27478

Differential Revision: D17799522

Pulled By: pbelevich

fbshipit-source-id: 5818394a212c947cfac3a6cf042af9ebb8b9d9a0
2019-10-07 19:24:07 -07:00
6b07612cef Fix verbose compiler warning in flat_hash_map (#17562)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17562

fixes https://github.com/pytorch/pytorch/issues/17332

Reviewed By: ezyang

Differential Revision: D14254499

fbshipit-source-id: 9d5d7408c2ce510ac20cd438c6514dc2bbe3a854
2019-02-28 16:38:43 -08:00
35a52aa33f Fix diagnostic pragmas (#17561)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17561

The push at the top of the file was missing a corresponding pop

Reviewed By: ezyang

Differential Revision: D14254500

fbshipit-source-id: ff20359b563d6d6dcc68273dc754ab31aa8fad12
2019-02-28 16:38:42 -08:00
4b454c3bdd Revert unneeded fixes in flat_hash_map (#16907)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16907

The begin()/end() fix actually doesn't make sense, see my comment on https://github.com/skarupke/flat_hash_map/pull/8
This diff removes it.

Reviewed By: ezyang

Differential Revision: D13985779

fbshipit-source-id: f08b02c941069e2a4e728e02a19b65dc72f96b41
2019-02-11 13:28:25 -08:00
6750e1e3e9 C10_REGISTER_CAFFE2_OPERATOR: Macro for registering c2 kernels (#16548)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16548

With this macro, a caffe2 operator can now directly be registered with c10.
No need to write custom wrapper kernels anymore.

Differential Revision: D13877076

fbshipit-source-id: e56846238c5bb4b1989b79855fd44d5ecf089c9c
2019-02-07 13:58:14 -08:00
16468a9f45 Automatically register c10 ops with JIT (#16534)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16534

All c10 ops from the c10 dispatcher are now automatically registered with JIT

Reviewed By: dzhulgakov

Differential Revision: D13869275

fbshipit-source-id: 5ab5dec5b983fe661f977f9d29d8036768cdcab6
2019-02-06 21:21:33 -08:00
11708cbd7b Update flat_hash_map (#15367)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15367

This updates flat_hash_map and fixes an issue with singletons across library boundaries
(see the PRs linked at the top of the file)

Reviewed By: ezyang

Differential Revision: D13510912

fbshipit-source-id: e90a297a7a2d69ae3fe48e4fcd8a44ad4b81292a
2019-01-08 20:31:46 -08:00
82903dda9b Fixes for some Windows compiler warnings (#14490)
Summary:
Implement some simple fixes to clean up windows build by fixing compiler warnings. Three main types of warnings were fixes:

1. GCC specific pragmas were changed to not be used on windows.
2. cmake flags that don't exist on windows were removed from windows build
3. Fix a macro that was defined multiple times on Windows.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14490

Differential Revision: D13241988

Pulled By: ezyang

fbshipit-source-id: 38da8354f0e3a3b9c97e33309cdda9fd23c08247
2018-12-05 21:27:07 -08:00
e3bb6ff334 Move c10 dispatcher prototype to c10/
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/13690

Reviewed By: dzhulgakov

Differential Revision: D12912235

fbshipit-source-id: 974b85790c23335be8130a50aa4692e3ddcd2bf9
2018-11-14 18:04:36 -08:00
b1c57caaf9 Move flat_hash_map to c10/util
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/13527

Reviewed By: ezyang

Differential Revision: D12912239

fbshipit-source-id: bb44d3ff87c4ca94943ec2667acf1e7ce2b3c914
2018-11-05 17:39:18 -08:00