“Doesn’t work” means slow? Or it returns the wrong answers?
Your code will be horribly inefficient on the GPU due to the random, uncoalesced, and even repeated memory accesses.
The efficient way of searching such an array likely depends on the size of the array, whether multiple threads are searching the same range, and whether the data can be rearranged from a flat list to a hierarchical table instead of a flat list.
I found my bug.
It has nothing to do with Cuda but with the class provided with it.
An array was empty so Cuda crashed.
i rushed myself at blame Cuda before the programer who given me the class… Error
An array was not allocated.