-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Reduce code duplication in OperatorEntry by keying hash map on optional<DispatchKey> #33817
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
…al<DispatchKey> Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
…al<DispatchKey> Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 85a6be7 Pull Request resolved: #33817
💊 CircleCI build failures summary and remediationsAs of commit 70ec5ef (more details on the Dr. CI page): ✅ None of the build failures appear to be your fault 💚
❄️ 2 tentatively flaky failures2 failures tentatively classified as flaky but have not launched reruns to confirm:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooo nice simplification!
I can't see how pushing the catchall/non-catchall distinction down costs us anything important - can't imagine the fatter keys will ever make a noticeable difference, and it's reversible if we ever need to hoist the distinction back out to the top level for some reason.
One question about a std::move
removal inline and definitely worth @smessmer putting the magnifying glass to whatever seething nest of implicit conversions I'm probably glossing over
RegistrationHandleRAII Dispatcher::registerKernel(const OperatorHandle& op, DispatchKey dispatch_key, KernelFunction kernel) { | ||
// note: this doesn't need the mutex to protect the iterator because write operations on the list keep iterators intact. | ||
return op.operatorIterator_->op.registerKernel(std::move(dispatch_key), std::move(kernel)); | ||
return op.operatorIterator_->op.registerKernel(dispatch_key, std::move(kernel)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need the move bc now implicitly converting to optional? or never needed the move?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never needed the move, dispatch keys are small
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is a move in the right direction. Shouldn't we start using CompoundOpKey and use that to get rid of catchall kernels entirely instead of merging the catchall kernel API into the regular kernel API?
Two reasons:
|
If IIUC and CompoundOpKey is a kind of DispatchKey - so the new API would be unitary in the same way as it is here, just trading CompoundOpKey for |
Ok I guess I'm fine with this. We'd have to revert the API changes introduced here once we start using CompoundOpKey, but that's not much effort. |
Just to make sure I'm not missing anything though, we'd only have to revert the change to |
yes that's correct |
…p on optional<DispatchKey>" Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20125163](https://our.internmc.facebook.com/intern/diff/D20125163) [ghstack-poisoned]
…al<DispatchKey> Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 6d2a7ae Pull Request resolved: #33817
I updated this to plumb the change all the way through, turns out it was only a few more lines. |
…p on optional<DispatchKey>" Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20125163](https://our.internmc.facebook.com/intern/diff/D20125163) [ghstack-poisoned]
…al<DispatchKey> (pytorch#33817) Summary: Pull Request resolved: pytorch#33817 Then, nullopt denotes catch all, whereas everything else is specific to a DispatchKey. I can delete the second copy of methods when I do this. This refactor should be pushed all the way to the frontend but I am doing it one step at a time. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Test Plan: Imported from OSS Differential Revision: D20125163 Pulled By: ezyang fbshipit-source-id: 026075a4bab81b0bd88b07f0800f6e6bbeb2166a
Stack from ghstack:
Then, nullopt denotes catch all, whereas everything else is specific to
a DispatchKey. I can delete the second copy of methods when I do this.
This refactor should be pushed all the way to the frontend but I am doing
it one step at a time.
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D20125163