gpu: add coherent qualifier #6037
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #5834 for NVIDIA cards.
How to reproduce
The steps from #5834 works, but the following command catches the issue faster:
Qdrant output:
The issue
Code in question:
qdrant/lib/segment/src/index/hnsw_index/gpu/shaders/run_insert_vector.comp
Lines 68 to 123 in b50a702
In a rough pseudo-code the algorithm is the following:
It appears to be correct: it uses proper locking (steps 1 and 6); it writes the count (step 5) only after writing the values (step 4). However, other threads could see the order differently. In the step 2, it could be possible for them to read the new updated count, but old links (which could contain zero-initialized values). What happens here is an "incoherent memory accesses". To make it coherent, we just need add a
coherent
GLSL qualifier.And actually, this issue happen far more frequently than reported; but in most cases these zero values are filtered out in the step 3.