Repository navigation
[REVIEW] Define and Implement new multi-search API - #3427
Conversation
Codecov Report
@@ Coverage Diff @@
## branch-0.11 #3427 +/- ##
============================================
Coverage 87.35% 87.35%
============================================
Files 49 49
Lines 9329 9329
============================================
Hits 8149 8149
Misses 1180 1180Continue to review full report at Codecov.
|
harrism
left a comment
There was a problem hiding this comment.
Cool approach. Does it support strings?
Yes, it supports strings. I included several string unit tests. |
jrhemstad
left a comment
There was a problem hiding this comment.
My gut feeling is that we should be using concurrent_unordered_map instead of introducing another hash data structure. It's a little memory inefficient because you have to store <key,value> when you only really need keys in this problem, but the build phase should be much simpler and require fewer kernel invocations.
|
|
||
| auto d_column = column_device_view::create(col); | ||
| auto d_col = *d_column; | ||
|
|
There was a problem hiding this comment.
Why 2*d_col.size()? Is that in attempt to reduce collisions?
| size_type *d_hash_bins_end = thrust::raw_pointer_cast(hash_bins_end.data()); | ||
| Element *d_hash_data = thrust::raw_pointer_cast(hash_data.data()); | ||
|
|
||
| thrust::for_each(rmm::exec_policy(stream)->on(stream), |
There was a problem hiding this comment.
This is basically just a histogram of the hash of each key mod the capacity, yes? I'm wondering if you could use a CUB histogram instead.
There was a problem hiding this comment.
Perhaps. Since we're going to look at reworking this a different way is it worth worrying about this?
To use the CUB histogram, I think I would need to write a transform iterator that computed the hash. I'm not sure how I would handle the invalid entries. Seems like a lot of work for something that ultimately we'll throw away.
|
Also, since it is small, I'm guessing we'd see a nice benefit of putting the hash map/set in constant memory. |
|
Constant memory is intended for uniform access. The constant cache can serve up one 32-bit value per cycle per SM. So performance is great if all threads in a warp access the same address. But if all threads access different addresses (e.g. probing different "needles" in the hash table), then it would be 32x slower. Shared memory, on the other hand, can serve up one value per bank per cycle, so it's better when all threads of a warp access different addresses at the same time (assuming bank conflicts are minimized). So I don't think constant memory would be a good idea for this kernel, unless you use a whole warp to probe each needle at 32 haystack locations at once. In general, I think we should optimize later, after we have a benchmark for this feature. For now, please take the most expedient path forward. Using concurrent_hash_map does make sense, if that is an easy change to make. |
I looked briefly at concurrent_unordered_map (in fact, I mimicked the template construct of it in my implementation), it seemed a little heavy for my purpose which is why I implemented my own. I can easily change to using concurrent_unordered_map. |
jrhemstad
left a comment
There was a problem hiding this comment.
For the sake of expediency, it's fine to keep this hash data structure.
I'm a little uneasy about it because it isn't really a generic data structure like concurrent_hash_map and is ad hoc for this algorithm. But it can be future work to develop a more generic unordered_multiset. For now, just put it in the detail namespace.
| */ | ||
| template <typename Element, typename Hasher = default_hash<Element>, | ||
| typename Equality = equal_to<Element>> | ||
| class fixed_hash_set { |
There was a problem hiding this comment.
Should be renamed because set implies ordered, unique values.
| class fixed_hash_set { | |
| class unordered_multiset{ |
There was a problem hiding this comment.
I have renamed it. AFAIK, only C++ treats the term set as implying ordered elements. Most other languages add an ordered set if you want that assumption.
Of course, this is C++ code... so I suppose we should follow the backwards way that the C++ standard interpreted this.
Quick follow-up. I experimented with using concurrent_unordered_map for this (started before you suggested we not worry about it for now, thought I might as well finish the experiment). It appears to me that concurrent_unordered_map cannot use strings as a key (at least at the moment). It does an atomicCAS to solve the race condition of multiple threads attempting to insert into the same position in the hash table. atomicCAS can't operate on a string_view. Not sure if there would be other issues with trying to use strings in concurrent_unordered_map. For now, I'll make the edits you suggest in my set implementation and we can address this later. |
But surely it can use hashed strings as keys. Otherwise we wouldn't be able to use it for joins on string keys. |
harrism
left a comment
There was a problem hiding this comment.
Looks great. Just one doc request.
How would you handle hash collisions? We're using a 32-bit hashing function. It shouldn't take too many strings in a column to have a good probability of a hash collision (if I've done the math correctly a column with 77,000 strings has about a 50% chance of a 32-bit hash collision). Now, if we want to limit the number of strings that can go in the needles column we could reduce that probability, but you would still have a non-zero probability of two needles colliding or of a false positive on a string in the haystack. I looked through the legacy join logic. We could do it indirectly using the index of the element in the column. A hasher and comparator that looked up the element in the underlying column but stored the index as the key in the array could work. |
Yes, this is exactly what you would do. |
Definition and implementation of a multi-search capability.
closes #3077