Skip to content

Commit

Permalink
Fix bug in blockRankedReduce (rapidsai#2226)
Browse files Browse the repository at this point in the history
There was a bug appearing for negative floating point numbers with a max reduce operation. The `std::numeric_limits<T>::min()` is greater than the negative floating point values whereas we want it to be smaller than all representable values.

This PR replaces the `min` with the `lowest`.

Authors:
  - Akif ÇÖRDÜK (https://github.com/akifcorduk)
  - Tamas Bela Feher (https://github.com/tfeher)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Tamas Bela Feher (https://github.com/tfeher)

URL: rapidsai#2226
  • Loading branch information
akifcorduk authored Mar 19, 2024
1 parent bd50c37 commit e53aa0c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cpp/include/raft/util/reduction.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@ DI std::pair<T, i_t> blockRankedReduce(T val,
val = values[lane];
idx = indices[lane];
} else {
// get the min if it is a max op, get the max if it is a min op
val = reduce_op(std::numeric_limits<T>::min(), std::numeric_limits<T>::max()) ==
std::numeric_limits<T>::min()
? std::numeric_limits<T>::max()
: std::numeric_limits<T>::min();
// get the lower_bound of the type if it is a max op,
// get the upper bound of the type if it is a min op
val = reduce_op(lower_bound<T>(), upper_bound<T>()) == lower_bound<T>() ? upper_bound<T>()
: lower_bound<T>();
idx = -1;
}
__syncthreads();
Expand Down

0 comments on commit e53aa0c

Please sign in to comment.