-
Couldn't load subscription status.
- Fork 74.9k
fix(core): Add MSVC patch for 64-bit integer comparison #102327
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,35 @@ | |||
| // Platform-specific fix for MSVC 64-bit integer comparison bug in minimum/maximum functors. | |||
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.
Start with the license header
| #if defined(_MSC_VER) | ||
| // Specialize maximum for int64_t on MSVC to avoid 32-bit truncation. | ||
| template <> | ||
| struct maximum<int64_t> { | ||
| EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int64_t operator()(const int64_t& x, const int64_t& y) const { | ||
| // Use explicit cast to ensure 64-bit comparison | ||
| return (static_cast<uint64_t>(x) > static_cast<uint64_t>(y)) ? x : y; | ||
| } | ||
| }; | ||
|
|
||
| template <> | ||
| struct minimum<int64_t> { | ||
| EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int64_t operator()(const int64_t& x, const int64_t& y) const { | ||
| // Use explicit cast to ensure 64-bit comparison | ||
| return (static_cast<uint64_t>(x) < static_cast<uint64_t>(y)) ? x : y; | ||
| } | ||
| }; | ||
| #endif | ||
|
|
||
| } // namespace functor | ||
| } // namespace tensorflow |
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.
Why not add these directly to cwise_ops.h?
This PR resolves a platform-specific bug where
int64_tcomparisons could produce incorrect results on MSVC (Windows builds) due to potential 32-bit truncation.The Problem: Operations like
tf.minimumandtf.maximumwere not behaving correctly for 64-bit integers in some cases on Windows.The Fix: This change introduces a patch that specializes the
minimumandmaximumfunctors forint64_ton MSVC, ensuring a true 64-bit comparison is always performed. This improves numerical stability and correctness on Windows.