Skip to content

Convert DispatchTable to a flat-indexed array rather than a hashtable.#29902

Closed
resistor wants to merge 1 commit intopytorch:masterfrom
resistor:dispatch1
Closed

Convert DispatchTable to a flat-indexed array rather than a hashtable.#29902
resistor wants to merge 1 commit intopytorch:masterfrom
resistor:dispatch1

Conversation

@resistor
Copy link
Contributor

No description provided.

@resistor resistor closed this Nov 16, 2019
@resistor resistor reopened this Nov 22, 2019
@resistor resistor changed the title [WIP] Convert KernelTable to a flat-indexed array rather than a hashtable. Convert KernelTable to a flat-indexed array rather than a hashtable. Nov 22, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@resistor has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@resistor resistor changed the title Convert KernelTable to a flat-indexed array rather than a hashtable. Convert DispatchTable to a flat-indexed array rather than a hashtable. Nov 22, 2019
if (!emplaced.second) {
// Element already existed. Overwrite it.
emplaced.first->second = kernel;
auto& slot = kernels_[(uint8_t)dispatchKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: static_cast is better than c-style cast

public:
DispatchTable(const FunctionSchema& schema)
: kernels_()
, catchallKernel_(c10::nullopt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: static_cast

@smessmer smessmer closed this Nov 22, 2019
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants