aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/cwise_ops_gpu_common.cu.h
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_ops_gpu_common.cu.h
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_ops_gpu_common.cu.h')
-rw-r--r--tensorflow/core/kernels/cwise_ops_gpu_common.cu.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/tensorflow/core/kernels/cwise_ops_gpu_common.cu.h b/tensorflow/core/kernels/cwise_ops_gpu_common.cu.h
index 00fd517ed3..d91d0faa86 100644
--- a/tensorflow/core/kernels/cwise_ops_gpu_common.cu.h
+++ b/tensorflow/core/kernels/cwise_ops_gpu_common.cu.h
@@ -45,18 +45,18 @@ struct UnaryFunctor<GPUDevice, Functor> {
};
// Partial specialization of BinaryFunctor<Device=GPUDevice, Functor>.
-template <typename Functor, int NDIMS>
-struct BinaryFunctor<GPUDevice, Functor, NDIMS> {
+template <typename Functor, int NDIMS, bool has_errors>
+struct BinaryFunctor<GPUDevice, Functor, NDIMS, has_errors> {
void operator()(const GPUDevice& d, typename Functor::tout_type out,
typename Functor::tin_type in0,
- typename Functor::tin_type in1) {
+ typename Functor::tin_type in1, bool* error) {
To32Bit(out).device(d) =
To32Bit(in0).binaryExpr(in1, typename Functor::func());
}
void Left(const GPUDevice& d, typename Functor::tout_type out,
typename Functor::tscalar_type scalar,
- typename Functor::tin_type in) {
+ typename Functor::tin_type in, bool* error) {
typedef typename Functor::out_type Tout;
typedef typename Functor::in_type Tin;
typedef typename Functor::func Binary;
@@ -66,7 +66,7 @@ struct BinaryFunctor<GPUDevice, Functor, NDIMS> {
void Right(const GPUDevice& d, typename Functor::tout_type out,
typename Functor::tin_type in,
- typename Functor::tscalar_type scalar) {
+ typename Functor::tscalar_type scalar, bool* error) {
typedef typename Functor::out_type Tout;
typedef typename Functor::in_type Tin;
typedef typename Functor::func Binary;
@@ -79,7 +79,8 @@ struct BinaryFunctor<GPUDevice, Functor, NDIMS> {
typename TTypes<typename Functor::in_type, NDIMS>::ConstTensor in0,
typename Eigen::array<Eigen::DenseIndex, NDIMS> bcast0,
typename TTypes<typename Functor::in_type, NDIMS>::ConstTensor in1,
- typename Eigen::array<Eigen::DenseIndex, NDIMS> bcast1) {
+ typename Eigen::array<Eigen::DenseIndex, NDIMS> bcast1,
+ bool* error) {
typedef typename Functor::in_type T;
typename Functor::func func;
if ((NDIMS == 2) && Functor::use_bcast_optimization &&