-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <typename T> | ||
struct Clip::ComputeImpl { | ||
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::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5). Warning
template <typename T> | ||
struct Clip::ComputeImpl { | ||
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). Warning
template <typename T> | ||
struct Clip::ComputeImpl { | ||
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::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5). Warning
template <typename T> | ||
struct Clip::ComputeImpl { | ||
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::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5). Warning
template <typename T> | ||
struct Clip::ComputeImpl { | ||
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::lowest' is constexpr, mark variable 'min_default' constexpr if compile-time evaluation is desired (con.5). Warning
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). Warning
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::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5). Warning
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::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5). Warning
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::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5). Warning
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::max' is constexpr, mark variable 'max_default' constexpr if compile-time evaluation is desired (con.5). Warning
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.