You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::min(a,b) returns the smaller of a and b. If the values are equivalent, returns a. It seems libstdc++/libc++ behavior is correct. CUDA/HIP std::min/max needs to be fixed.
The std::min behaves like 'a<b?a:b', which does not match libstdc++/libc++
behavior like 'b<a?b:a' when input is NaN.
Make it consistent with libstdc++/libc++.
Fixes: llvm#93962Fixes: ROCm/HIP#3502
The std::min behaves like 'a<b?a:b', which does not match
libstdc++/libc++ behavior like 'b<a?b:a' when input is NaN.
Make it consistent with libstdc++/libc++.
Fixes: #93962Fixes: ROCm/HIP#3502
CUDA/HIP defines overloaded version of host device std::min/max with higher precedence than those in standard C++ headers:
llvm-project/clang/lib/Headers/cuda_wrappers/algorithm
Line 101 in 6ee845d
https://github.com/gcc-mirror/gcc/blob/d9c90c82d900fdae95df4499bf5f0a4ecb903b53/libstdc%2B%2B-v3/include/bits/stl_algobase.h#L233
llvm-project/libcxx/include/__algorithm/min.h
Line 36 in 6ee845d
However, there is a subtle difference of the CUDA/HIP version compared to libstdc++/libc++ version.
CUDA/HIP version is like
__a < __b ? __a : __b
. If there is NaN, it chooese__b
.libstdc++/libc++ version is like
__b < __a ? __b : __a
. If there is NaN, it chooses__a
.This difference causes annoyance for PyTorch
ROCm/HIP#2209 (comment)
according to https://en.cppreference.com/w/cpp/algorithm/min
std::min(a,b) returns the smaller of a and b. If the values are equivalent, returns a. It seems libstdc++/libc++ behavior is correct. CUDA/HIP std::min/max needs to be fixed.
@Artem-B
The text was updated successfully, but these errors were encountered: