… 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
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)
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)
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)