SimpleGPUHashTable
SimpleGPUHashTable copied to clipboard
Undefined behavior on the first iteration of all operations
void gpu_hashtable_insert(KeyValue* hashtable, uint32_t key, uint32_t value)
{
uint32_t slot = hash(key);
while (true)
{
uint32_t prev = atomicCAS(&hashtable[slot].key, kEmpty, key);
if (prev == kEmpty || prev == key)
{
hashtable[slot].value = value;
break;
}
slot = (slot + 1) & (kHashTableCapacity-1);
}
}
Take a sample function like this. It is highly likely that slot will be greater than kHashTableCapacity and thus invoke undefined behavior on the first iteration.
This is an issue in both the cuda implementation https://github.com/nosferalatu/SimpleGPUHashTable/blob/d3f5b74f3176f40120cd5dc61a8d4811302eb829/src/linearprobing.cu#L166 as well as the article https://nosferalatu.com/SimpleGPUHashTable.html