Fix NaN handling in GPU cast operations for int32/int64 conversions (#12345)#106214
Fix NaN handling in GPU cast operations for int32/int64 conversions (#12345)#106214Mohataseem89 wants to merge 1 commit intotensorflow:masterfrom
Conversation
|
Please don't use "add file"/"update file"/"fix file"/etc. commit messages. These are hard to reason about when looking at the history of the file/repository. Instead, please write explanatory git commit messages. The commit message is also the title of the PR if the PR has only one commit. It is thus twice important to have commit messages that are relevant, as PRs would be easier to understand and easier to analyze in search results. For how to write good quality git commit messages, please consult https://cbea.ms/git-commit/ Please collapse both commits into just the first one ( |
Add explicit IsNan helpers and update GPU CastFunctor implementations to safely handle NaN values when casting floating-point tensors to integer types on GPU devices, aligning behavior with CPU and NumPy.
cff5dba to
25ac479
Compare
Thanks for the guidance |
|
Waiting for review from @cantonios or someone else with more GPU kernels expertise |
Added IsNan function templates for different types and updated CastFunctor implementations to handle NaN values during type casting.
This PR addresses Issue #12345, which reported incorrect behavior when casting floating-point tensors containing NaN values to integer types on GPU devices.
Previously, GPU cast functors directly used
isnan(v)in device lambdas. This caused undefined behavior for types likeEigen::halfandbfloat16on CUDA/ROCm, and NaN inputs were not safely handled when converting toint32orint64.Changes
IsNan()utility function that supportsfloat,double,Eigen::half, andbfloat16.CastFunctors to useIsNan(v):CastFunctor<GPUDevice, int32, float>CastFunctor<GPUDevice, int64, float>CastFunctor<GPUDevice, int32, double>CastFunctor<GPUDevice, int64, double>0during casting.Files Affected
tensorflow/core/kernels/cast_op_gpu.cu.ccThis PR resolves Issue #12345 by adding safe NaN handling in GPU casting.