Repository navigation
gpu: add coherent qualifier - #6037
Merged
Merged
Conversation
IvanPleshkov
approved these changes
Feb 21, 2025
IvanPleshkov
left a comment
Contributor
There was a problem hiding this comment.
Great finding! I also propose to add this qualifier into all shared buffers which are writable.
There are:
layout(set = VISITED_FLAGS_LAYOUT_SET, binding = 1)
buffer VisitedFlagsBuffer {
uint8_t data[];
} visited_flags;
layout(set = 0, binding = 1) buffer NewEntries {
uint data[];
} new_entries;
layout(set = 0, binding = 2) buffer Atomics {
uint data[];
} atomics;
layout(set = 0, binding = 1) buffer SearchResults {
uint data[];
} search_results;
timvisee
approved these changes
Feb 21, 2025
timvisee
left a comment
Member
There was a problem hiding this comment.
Nice!
Approved based on my understanding from the description, and on what you explained before during one of our dailies.
Member
Author
@IvanPleshkov Update: I've added an explicit qualifier ( |
IvanPleshkov
approved these changes
Feb 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
coherentGLSL 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.