Skip to content

[REVIEW] Define and Implement new multi-search API - #3427

Merged
jrhemstad merged 12 commits into
NVIDIA:branch-0.11from
ChuckHastings:fea_multi_search
Nov 26, 2019
Merged

jrhemstad merged 12 commits into
NVIDIA:branch-0.11from
ChuckHastings:fea_multi_search

Conversation

@ChuckHastings

Copy link
Copy Markdown
Contributor

Definition and implementation of a multi-search capability.

closes #3077

@ChuckHastings
ChuckHastings requested a review from a team as a code owner November 20, 2019 15:53
Comment thread cpp/src/search/search.cu Resolved
Comment thread cpp/include/cudf/search.hpp Resolved
@codecov

codecov Bot commented Nov 20, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #3427 into branch-0.11 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           branch-0.11    #3427   +/-   ##
============================================
  Coverage        87.35%   87.35%           
============================================
  Files               49       49           
  Lines             9329     9329           
============================================
  Hits              8149     8149           
  Misses            1180     1180

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c021a74...5f3b615. Read the comment docs.

Comment thread cpp/include/cudf/search.hpp Resolved
Comment thread cpp/src/hash/fixed_hash_set.cuh Resolved

@harrism harrism left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool approach. Does it support strings?

Comment thread cpp/include/cudf/search.hpp Resolved
Comment thread cpp/src/hash/fixed_hash_set.cuh Resolved
Comment thread cpp/src/search/search.cu Resolved
Comment thread cpp/tests/search/search_test.cu Resolved
@ChuckHastings

Copy link
Copy Markdown
Contributor Author

Cool approach. Does it support strings?

Yes, it supports strings. I included several string unit tests.

@jrhemstad jrhemstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread cpp/src/hash/fixed_hash_set.cuh Resolved

auto d_column = column_device_view::create(col);
auto d_col = *d_column;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 2*d_col.size()? Is that in attempt to reduce collisions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes.

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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread cpp/src/search/search.cu Resolved
Comment thread cpp/include/cudf/search.hpp Resolved
Comment thread cpp/src/search/search.cu Resolved
@jrhemstad

Copy link
Copy Markdown
Contributor

Also, since it is small, I'm guessing we'd see a nice benefit of putting the hash map/set in constant memory.

@harrism

harrism commented Nov 21, 2019

Copy link
Copy Markdown
Contributor

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.

@ChuckHastings

Copy link
Copy Markdown
Contributor Author

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.

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 jrhemstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread cpp/src/hash/fixed_hash_set.cuh Outdated
*/
template <typename Element, typename Hasher = default_hash<Element>,
typename Equality = equal_to<Element>>
class fixed_hash_set {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be renamed because set implies ordered, unique values.

Suggested change
class fixed_hash_set {
class unordered_multiset{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread cpp/src/hash/fixed_hash_set.cuh Resolved
@ChuckHastings

Copy link
Copy Markdown
Contributor Author

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.

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.

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.

@ChuckHastings
ChuckHastings requested a review from a team as a code owner November 22, 2019 17:45
@harrism

harrism commented Nov 24, 2019

Copy link
Copy Markdown
Contributor

It appears to me that concurrent_unordered_map cannot use strings as a key (at least at the moment).

But surely it can use hashed strings as keys. Otherwise we wouldn't be able to use it for joins on string keys.

@harrism harrism left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great. Just one doc request.

Comment thread cpp/include/cudf/search.hpp Resolved
@ChuckHastings

ChuckHastings commented Nov 25, 2019 •

Copy link
Copy Markdown
Contributor Author

It appears to me that concurrent_unordered_map cannot use strings as a key (at least at the moment).

But surely it can use hashed strings as keys. Otherwise we wouldn't be able to use it for joins on string keys.

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.

@jrhemstad

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Multiple value search

6 participants