How to search the value from a std::map when I use

2019-12-16 19:25发布

问题:

I have something stored in std::map, which maps string to vector. Its keys and values looks like

 key      value
 "a"-----[1,2,3]
 "b"-----[8,100]
"cde"----[7,10]

For each thread, it needs to process one query. The query looks like

["a", "b"]

or

["cde", "a"]

So I need to get the value from the map and then do some other jobs like combine them. So as for the first query, the result will be

[1,2,3,8,100]

The problem is, how can threads access the map and find the value by a key?

At first, I tried to store it in global memory. However, It looks like it can only pass arrays from host to device.

Then I tried to use thrust, but I can only use it to store vector.

Is there any other way I can use? Or maybe I ignored some methods in thrust? Thanks!

**Ps: I do not need to modify the map, I just need to read data from it.

回答1:

I believe it's unlikely you will benefit from doing any of this on the GPU, unless you have a huge number of queries which are all available to you at once, or at least in batches.

If you do not have that many queries, then just transferring the data (regardless of its exact format/structure) will likely be a waste.

If you do have that many queries, the benefit is still entirely unclear, and depends on a lot of parameters. The fact that you've been trying to use std::map for anything suggests (see below for the reason) that you haven't been seriously concerned with performance so far. If that's indeed the case, just don't make your life difficult by using a GPU.


So what's wrong what std::map? Nothing, but it's extremely slow even on the CPU, and this is even worse on the GPU.