-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[PyTorch] Update Synchronized<T>::withLock() to return the type/value from the aceepted callable #74108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… from the aceepted callable 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>`). Differential Revision: [D34822915](https://our.internmc.facebook.com/intern/diff/D34822915/) [ghstack-poisoned]
CI Flow Status⚛️ CI FlowRuleset - Version:
|
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 23e1780 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
… type/value from the aceepted callable" 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>`). Differential Revision: [D34822915](https://our.internmc.facebook.com/intern/diff/D34822915/) [ghstack-poisoned]
… from the aceepted callable (#74108) Summary: Pull Request resolved: #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
Stack from ghstack (oldest at bottom):
Currently,
void c10::Synchronized<T>::withLock(CB)accepts a callback but returnsvoid. 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 asstd::unique_ptr<T>, then this won't work as currently written). To be able to do that, one needs to usestd::enable_if<T>to enable a separate overload that works only for moveable types (detectable usingstd::is_move_constructible<T>).Differential Revision: D34822915