fix infinite loop when get_max_threads is nonzero but num_threads is 1
authorBrennan Vincent <btv@fb.com>
Wed, 12 Dec 2018 17:58:54 +0000 (09:58 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 12 Dec 2018 18:04:18 +0000 (10:04 -0800)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15114

Differential Revision: D13431891

Pulled By: umanwizard

fbshipit-source-id: f968b8e50cf776c346d4a28d72b12e7856c95839

aten/src/ATen/native/TensorIteratorReduce.cpp

index 41c0aa0..b5898c1 100644 (file)
@@ -125,7 +125,7 @@ void TensorIterator::foreach_reduced_elt(const loop_subiter_t &loop) {
   if (tensor(0).numel() == 1) {
     loop(*this);
   }
-  else if (numel() < at::internal::GRAIN_SIZE || at::get_max_threads() == 1 || at::in_parallel_region()) {
+  else if (numel() < at::internal::GRAIN_SIZE || at::get_num_threads() <= 1 || at::in_parallel_region()) {
     auto reduce_dims = num_reduce_dims();
 
     auto non_reduced_shape = shape.slice(reduce_dims, shape.size() - reduce_dims);