8 Commits

Author SHA1 Message Date
cyy
383d9e3de6 [4/N] Fix cppcoreguidelines-special-member-functions warnings (#139027)
Follows #138796
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139027
Approved by: https://github.com/ezyang
2024-10-29 00:18:18 +00:00
cyy
9a0c217a0a [9/N] Fixes clang-tidy warnings in c10/util/*.h (#116185)
Continued work to clean headers in c10/util.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/116185
Approved by: https://github.com/Skylion007
2023-12-22 09:35:44 +00:00
64b8d20a5c Fix typos under c10 directory (#98079)
This PR fixes typos in comments and messages of files under `c10` directory

Pull Request resolved: https://github.com/pytorch/pytorch/pull/98079
Approved by: https://github.com/Skylion007
2023-03-31 18:31:11 +00:00
5af48581b5 In order to make pytorch headers consumable from cpp20 code bases, … (#79985)
… all instances of std::result_of and std:result_of_t are conditionally replaced by std::invoke_result and std::invoke_result_t if __cpp_lib_is_invocable >= 201703L.  std::invoke_result was only introduced in c++17, so it should probably not be required yet.

Fixes #71657  and a small part of #69290

Tested on Centos 7 / gcc11 + a private project that requires cpp20.

I think the main questions to check by a maintainer are,
- whether my choices of preprocessor blocks are appropriate
- whether there are any very subtle differences between std::result_of and std::invoke_result that I have missed
- whether in any of the replacements  the 'new' side can/should be simplified further

Pull Request resolved: https://github.com/pytorch/pytorch/pull/79985
Approved by: https://github.com/ezyang
2022-07-04 20:14:36 +00:00
e1eb876ade [PyTorch] Update Synchronized<T>::withLock() to return the type/value from the aceepted callable (#74108)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74108

Currently, `void c10::Synchronized<T>::withLock(CB)` accepts a callback but returns `void`. For a callback (CB) returning a value, `withLock()` can not be used to retrieve the returned value. This change makes it possible for the caller to retrieve that value. The only gotcha is that if the value has only move semantics (such as `std::unique_ptr<T>`, then this won't work as currently written). To be able to do that, one needs to use `std::enable_if<T>` to enable a separate overload that works only for moveable types (detectable using `std::is_move_constructible<T>`).
ghstack-source-id: 151471745

Test Plan:
Built model tracer using the command:

```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```

Reviewed By: malfet

Differential Revision: D34822915

fbshipit-source-id: 2ade3d963d1e997a791508ec54a930827f7849b5
(cherry picked from commit d5429073137b33978882299c5ee5cc7ffb964f8e)
2022-03-16 16:18:36 +00:00
a554fc6836 Revert D34645509: [PyTorch] Update Synchronized<T>::withLock() to return the type/value from the aceepted callable
Test Plan: revert-hammer

Differential Revision:
D34645509 (de4a87fb48)

Original commit changeset: 9a4bd5d1d78a

Original Phabricator Diff: D34645509 (de4a87fb48)

fbshipit-source-id: 3a1737cda866085fc0dec9997d0ce659f636a0c2
(cherry picked from commit 46d3300009ef965c29be94730ac38d549c46ade2)
2022-03-11 15:38:11 +00:00
de4a87fb48 [PyTorch] Update Synchronized<T>::withLock() to return the type/value from the aceepted callable (#74060)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74060

Currently, `void c10::Synchronized<T>::withLock(CB)` accepts a callback but returns `void`. For a callback (CB) returning a value, `withLock()` can not be used to retrieve the returned value. This change makes it possible for the caller to retrieve that value. The only gotcha is that if the value has only move semantics (such as `std::unique_ptr<T>`, then this won't work as currently written). To be able to do that, one needs to use `std::enable_if<T>` to enable a separate overload that works only for moveable types (detectable using `std::is_move_constructible<T>`).
ghstack-source-id: 150555297

Test Plan:
Built model tracer using the command:

```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```

Reviewed By: JacobSzwejbka

Differential Revision: D34645509

fbshipit-source-id: 9a4bd5d1d78a5026826c7ed9ee04ea743cafcc10
(cherry picked from commit f3893dec44cb361ef1ffc1f56b9b6f94be5c9b83)
2022-03-11 07:59:50 +00:00
154f0ace72 [RFC] Implement c10::Synchronized<T>, a basic error-avoiding synchronization wrapper for data (#73407)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73407

After adding mutex/lock in a previous change, I realized that `folly::Synchronized<T>` exists for this reason. However, we can't use it, so I have implemented a basic version for use in `c10` in this change.

Reviewers, please check if this looks reasonable as a minimal first step to enforce that data that is supposed to be used in a multi-threaded context ends up being locked before use. i.e. don't rely on the developer to do the right thing, instead enforce it using this abstraction.
ghstack-source-id: 150327548

Test Plan: See the next diff in this stack for the text plan.

Reviewed By: pavithranrao

Differential Revision: D34465420

fbshipit-source-id: 76c921e9b78ff2dfc82a0bfc83ffc8fb232e2f21
(cherry picked from commit 5882fe2022dd4a83ed259e6b6fe255e8b37e7d81)
2022-03-02 20:56:23 +00:00