Skip to content

Undefined behavior on the first iteration of all operations #11

Description

@9291Sam
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

if (hashtable[slot].key == key)

as well as the article
https://nosferalatu.com/SimpleGPUHashTable.html

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions