aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/cwise_op_div.cc
diff options
context:
space:
mode:
authorGravatar Geoffrey Irving <geoffreyi@google.com>2016-05-03 15:32:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-05-03 16:41:35 -0700
commit1ed0e764c8ca84d45823f2fd172dc8d40f89e3e2 (patch)
tree8b5ab4224bbaa27f5eb340cddee2931d2421333b /tensorflow/core/kernels/cwise_op_div.cc
parent2863cc1361e061d36061368df66feda32c2790a8 (diff)
Catch integer division by zero on CPU to avoid SIGFPE
We let it through on GPU since the behavior is bizarre but harmless. On the CPU, we have to turn off packet math in Eigen and use a special binary functor that sets an error bit on division by zero. Ideally we'd be able to use packet math too; all it would take is a nice way for checking if a packet contains a zero. Fixes #2163. Change: 121429857
Diffstat (limited to 'tensorflow/core/kernels/cwise_op_div.cc')
-rw-r--r--tensorflow/core/kernels/cwise_op_div.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/tensorflow/core/kernels/cwise_op_div.cc b/tensorflow/core/kernels/cwise_op_div.cc
index 0af0fc21e5..c4899473e6 100644
--- a/tensorflow/core/kernels/cwise_op_div.cc
+++ b/tensorflow/core/kernels/cwise_op_div.cc
@@ -16,8 +16,9 @@ limitations under the License.
#include "tensorflow/core/kernels/cwise_ops_common.h"
namespace tensorflow {
-REGISTER8(BinaryOp, CPU, "Div", functor::div, float, Eigen::half, double, uint8,
- int16, int32, int64, complex64);
+REGISTER4(BinaryOp, CPU, "Div", functor::div, float, Eigen::half, double,
+ complex64);
+REGISTER4(BinaryOp, CPU, "Div", functor::safe_div, uint8, int16, int32, int64);
#if GOOGLE_CUDA
REGISTER6(BinaryOp, GPU, "Div", functor::div, float, Eigen::half, double, uint8,
int16, int64);
@@ -31,7 +32,7 @@ REGISTER_KERNEL_BUILDER(Name("Div")
.HostMemory("y")
.HostMemory("z")
.TypeConstraint<int32>("T"),
- BinaryOp<CPUDevice, functor::div<int32>>);
+ BinaryOp<CPUDevice, functor::safe_div<int32>>);
#endif
} // namespace tensorflow