哈希表的GPU实现



我正在寻找一个哈希表的实现,我可以使用CUDA编码。有好的吗?就像Python字典一样。我将使用字符串作为键

Alcantara等人演示了在GPU上构建哈希表的数据并行算法。我相信这个实现是作为CUDPP的一部分提供的。

也就是说,您可能需要重新考虑您最初选择的哈希表。按键对数据排序,然后在大规模并行设置中执行大量查询应该会产生更好的性能。你想解决什么问题?

当我编写一个OpenCL内核来为字符串创建一个简单的哈希表时,我使用了Java的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;

当然,我手动处理冲突,当我提前知道字符串的数量时,这种方法工作得很好。

最新更新