-
Notifications
You must be signed in to change notification settings - Fork 5.9k
refine OpKernelType #6879
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
refine OpKernelType #6879
Conversation
paddle/framework/op_kernel_type.h
Outdated
| int library_type = static_cast<int>(key.library_type_); | ||
|
|
||
| size_t seed = 0; | ||
| hash_combine(seed, place); |
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.
how about combine these four fields as one integer, then make a hash_combine function call?
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 can not simply combine these four fields together. HashCombine is the function to do such work.
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.
我的意思是,四次HashCombine调用开销可以省略。
KernelType种类并不多,不会发生碰撞,hash只是让分布均匀一下。
防止碰撞可以这样
constexpr int SHIFT = 8; // every kind of type less than 2^8
int data_type = static_cast<int>(key.data_type_) + 1<<(SHIFT);
int data_layout = static_cast<int>(key.data_layout_) + 1 <<(SHIFT + 1);
int library_type = static_cast<int>(key.library_type_) + 1 << (SHIFT + 2);
int kernel_id = data_type + data_layout + library_type + place.which();
std::hash<int> hasher;
return hasher(kernel_id);
paddle/framework/op_kernel_type.h
Outdated
| c-why-is-boosthash-combine-the-best-way-to-combine-hash-values | ||
| */ | ||
| template <class T> | ||
| inline void hash_combine(std::size_t& seed, const T& v) { |
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.
Google Style.
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.
Done
paddle/framework/op_kernel_type.h
Outdated
| c-why-is-boosthash-combine-the-best-way-to-combine-hash-values | ||
| */ | ||
| template <class T> | ||
| inline void HashCombine(std::size_t& seed, const T& v) { |
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.
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.
Done
dzhwinter
left a comment
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.
This PR is a core part of our KernelKey design. We can merge it ASAP, and I will give a small fix.
@QiJune @jacquesqiao
Fix #6769