GPU的哈希表实现

时间:2011-09-19 16:20:34

标签: hash cuda gpgpu gpu-programming

我正在寻找可用于CUDA编码的哈希表实现。哪里有好人。类似Python字典的东西。我将使用字符串作为我的键

2 个答案:

答案 0 :(得分:4)

Alcantara et al已经演示了一种用于在GPU上构建哈希表的数据并行算法。我相信实施是CUDPP的一部分。

那就是说,您可能想重新考虑一下哈希表的原始选择。按键对数据进行排序,然后大量执行大量查询,可以在大规模并行设置中产生更好的性能。你想解决什么问题?

答案 1 :(得分:2)

当我编写一个OpenCL内核来为字符串创建一个简单的哈希表时,我使用了来自Java's String.hashCode()的哈希算法,然后只是在表中的行数上修改了它以获得行索引。

哈希函数

uint getWordHash(__global char* str, uint len) {
  uint hash = 0, multiplier = 1;
  for(int i = len - 1; i >= 0; i--) {
    hash += str[i] * multiplier;
    int shifted = multiplier << 5;
    multiplier = shifted - multiplier;
  }
  return hash;
}

索引

uint hash = getWordHash(word, len);
uint row = hash % nRows;

我当然是手动处理碰撞,当我提前知道字符串的数量时,这种方法很有效。