The static_map of custom type becomes very slow after modifying the custom_key_equal function. #558
-
As a key with two member variables, it is reasonable to require both values to match when matching the key. In large-scale hash tables, it is common for many keys to have the same first member variable but different second member variables. However, I modified custom_key_equal to require that both member variables are equal means that the key is equal, and the insertion speed of static_map became so slow that I could not wait until the end of the program execution. I modified the key generation rules so that the first member variable key.a of some keys is the same, but key.b is different to distinguish them.
The modified function for judging key equality is as follows.
The complete code is as follows:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
auto pairs_begin = thrust::make_transform_iterator(
thrust::make_counting_iterator<int32_t>(0),
cuda::proclaim_return_type<cuco::pair<custom_key_type, custom_value_type>>(
[] __device__(auto i) {
return cuco::pair{ custom_key_type{i%100,i}, custom_value_type{i} };
})); By doing so, you are adding more duplicates to the input. Thus more hash collisions. To solve the problem, you may want to update your hash function accordingly to minimize collisions, e.g. // User-defined device hash callable
struct custom_hash {
__device__ uint32_t operator()(custom_key_type const& k) const noexcept { return k.a + k.b; };
}; Or hash your struct properly like https://stackoverflow.com/questions/19195183/how-to-properly-hash-the-custom-struct |
Beta Was this translation helpful? Give feedback.
-
Did the operation finish at all or are we running into an infinite (probing) loop? Briefly reading through your code, I can't spot anything wrong with it apart from what @PointKernel already mentioned. We had some recent changes/bugfixes to our insertion backend. Can you pull the latest |
Beta Was this translation helpful? Give feedback.
By doing so, you are adding more duplicates to the input. Thus more hash collisions. To solve the problem, you may want to update your hash function accordingly to minimize collisions, e.g.
Or hash your struct properly like https://stackoverflow.com/questions/1919518…