fix illegal access when there are more orientations than allocated #150
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 also resolves #105.
I am also attaching a sample image where this error happens. 1.pgm.txt
Description
This PR resolves an issue with illegal memory access when there are more orientations/descriptors than allocated. This error happens when there at least 2 times more orientations than there are extremas. There must also be at least 100k extremas for this crash to happen. You can reduce this value to get this error easier.
popsift/src/popsift/sift_conf.cu
Line 33 in 4b4b247
I'm pasting some link for easier understanding which parts are relevant for memory allocation and its amount.
popsift/src/popsift/sift_constants.cu
Lines 30 to 31 in 4b4b247
popsift/src/popsift/sift_pyramid.cu
Line 154 in 4b4b247
popsift/src/popsift/sift_pyramid.cu
Line 192 in 4b4b247
This part here is interesting because there is a constant
max_orientations = max_extrema + max_extrema/4;
but the amount allocated is thenmax( 2 * h_consts.max_extrema, h_consts.max_orientations )
which does not make much sense. But that in itself is not a problem. The problem is that excess orientations are never pruned which causes problem later in the process. This makes it mandatory for checking if orientation index is within allocated memory.Implementation remarks
Instead of pruning excess orientations I've implemented index checking at relevant places. Pruning might be better solution but it is not as easy to implement (maybe I am wrong). If pruning was to happen I think it should be done here:
popsift/src/popsift/s_orientation.cu
Lines 328 to 331 in 4b4b247