I wrote a kernel which has to find the index of the minimum and maximum of a float array (parallel reduction). It works quite fine, but now I stumbled towards a problem for this input:
[2.94375E+019, 1.09146E+019, 2.9629E+019, 1.#INF, 3.08097E+019, 1.#INF, 2.95379E+019, 3.92105E+019, 2.95379E+019, -1.#IND, 3.06701E+019, 1.#INF, 1.#INF]
Problem is, whenever at least one value in the array is -1.#IND, the kernel returns wrong results. That’s because if one value is compared against -1.#IND, it’s neither less, equal, or greater…the partial min/max gets set to the first value, which produces unwanted output.
The -1.#IND probably is a result of a function computing something like exp(, ), I can’t avoid it.
Is there any elegant way to prefer the non-complex value in such a comparison? If not, what do you think would be the best way to make the kernel work the way one would expect it? (maybe checking each value when it’s loaded to shared mem, and setting -1.#IND to infinity?)