From 2dde1b102866e1928e925678951463f2a7051af1 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 20 Apr 2016 18:08:20 -0700 Subject: Don't crash when attempting to reduce empty tensors. --- unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h b/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h index afa5a257a..fd2587dd5 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h @@ -134,9 +134,14 @@ struct FullReducer { typedef typename Self::Index Index; const Index num_coeffs = array_prod(self.m_impl.dimensions()); + // Don't crash when we're called with an input tensor of size 0. + if (num_coeffs == 0) { + return; + } + const int block_size = 256; const int num_per_thread = 128; - const int num_blocks = numext::ceil(static_cast(num_coeffs) / (block_size * num_per_thread)); + const int num_blocks = divup(num_coeffs, block_size * num_per_thread); if (num_blocks > 1) { // We initialize the outputs outside the reduction kernel when we can't be sure that there -- cgit v1.2.3