Add numeric_limits for MLFloat16 and BFloat16#22197
Conversation
13e2aa7 to
718e05b
Compare
|
Do we want to add a test for Clip or this is separate? |
| void operator()(cudaStream_t stream, const Tensor* X, const Tensor* min, const Tensor* max, Tensor* Y) const { | ||
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<unsigned __int64>::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5).
| void operator()(cudaStream_t stream, const Tensor* X, const Tensor* min, const Tensor* max, Tensor* Y) const { | ||
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<__int64>::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5).
| void operator()(cudaStream_t stream, const Tensor* X, const Tensor* min, const Tensor* max, Tensor* Y) const { | ||
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<unsigned char>::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5).
| void operator()(cudaStream_t stream, const Tensor* X, const Tensor* min, const Tensor* max, Tensor* Y) const { | ||
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<signed char>::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5).
| void operator()(cudaStream_t stream, const Tensor* X, const Tensor* min, const Tensor* max, Tensor* Y) const { | ||
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<double>::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5).
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); | ||
| auto max_default = std::numeric_limits<T>::max(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<__int64>::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5).
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); | ||
| auto max_default = std::numeric_limits<T>::max(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<unsigned char>::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5).
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); | ||
| auto max_default = std::numeric_limits<T>::max(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<signed char>::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5).
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); | ||
| auto max_default = std::numeric_limits<T>::max(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<double>::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5).
| auto min_default = clip_internal::LowMax<T>::low(); | ||
| auto max_default = clip_internal::LowMax<T>::max(); | ||
| auto min_default = std::numeric_limits<T>::lowest(); | ||
| auto max_default = std::numeric_limits<T>::max(); |
Check warning
Code scanning / PREfast
The function 'std::numeric_limits<float>::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5).
Description
Note that the canonical NaN is not consistent in C++ and C#. C# uses negative quiet NaN as canonical NaN, while C++ uses positive quiet NaN. The choice of CSharp Float16.NaN is to be consistent with System.Half.NaN.
FP16 data returns from CUDA might have 7FFF as NaN; FP16 data from CPU provider might have 0x7E00 as NaN. Anyway there is no consistent canonical NaN in ORT right now. Because all these NaNs are aligned with IEEE spec, there shall not an issue in downstream.
Motivation and Context
std::numeric_limits is used in codebase but not defined for MLFloat16 and BFloat16. It causes some bugs like #21957 introduced by #21493.