Convert DispatchTable to a flat-indexed array rather than a hashtable.#29902
Closed
resistor wants to merge 1 commit intopytorch:masterfrom
Closed
Convert DispatchTable to a flat-indexed array rather than a hashtable.#29902resistor wants to merge 1 commit intopytorch:masterfrom
resistor wants to merge 1 commit intopytorch:masterfrom
Conversation
Contributor
facebook-github-bot
left a comment
There was a problem hiding this comment.
@resistor has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
smessmer
approved these changes
Nov 22, 2019
| if (!emplaced.second) { | ||
| // Element already existed. Overwrite it. | ||
| emplaced.first->second = kernel; | ||
| auto& slot = kernels_[(uint8_t)dispatchKey]; |
Contributor
There was a problem hiding this comment.
nit: static_cast is better than c-style cast
| public: | ||
| DispatchTable(const FunctionSchema& schema) | ||
| : kernels_() | ||
| , catchallKernel_(c10::nullopt) |
Contributor
There was a problem hiding this comment.
let's keep those initializers, but possibly remove the c10::nullopt (i.e. call default constructor instead) since it's not an optional anymore.
| str << toString(kernels_.begin()->first); | ||
| for (auto iter = ++kernels_.begin(); iter != kernels_.end(); ++iter) { | ||
| str << ", " << toString(iter->first); | ||
| if (kernelCount_ != 0) { |
Contributor
There was a problem hiding this comment.
Since this is the only place where we need kernelCount_, it might be better to not store that in an extra field (allowing for a potential invariant violation between kernelCount_ and the content of kernels_), but instead rewrite the logic here to not need kernelCount_.
|
|
||
| ska::flat_hash_map<TensorTypeId, KernelFunction> kernels_; | ||
| c10::optional<KernelFunction> catchallKernel_; | ||
| std::array<KernelFunction, (uint8_t)TensorTypeId::NumTensorIds> kernels_; |
smessmer
added a commit
that referenced
this pull request
Nov 23, 2019
…rather than a hashtable." re-export of #29902 Differential Revision: [D18660421](https://our.internmc.facebook.com/intern/diff/D18660421/) [ghstack-poisoned]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.