当我使用cuda时,如何从std :: map中搜索值? [英] How to search the value from a std::map when I use cuda?

查看:449
本文介绍了当我使用cuda时,如何从std :: map中搜索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在std :: map中存储了一些东西,它将字符串映射到向量.它的键和值看起来像

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"]

["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]

问题是,线程如何通过键访问地图并找到值?

起初,我试图将其存储在全局内存中.但是,看起来它只能将数组从主机传递到设备.

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:我不需要修改地图,只需要从中读取数据即可.

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

推荐答案

我相信您不太可能会从GPU上进行任何此类操作中受益,除非您有大量的查询可同时使用,或至少分批进行.

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.

如果您要做有很多查询,则好处仍然是完全不清楚的,并且取决于许多参数.您一直尝试将std::map用于任何事情的事实表明(到目前为止,请参见下面的原因)您到目前为止尚未真正关注性能.如果确实如此,那就不要因为使用GPU而使生活变得困难.

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.

那么std::map怎么了?没什么,但是它即使在CPU上也极其慢,而在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.

这篇关于当我使用cuda时,如何从std :: map中搜索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆