Enable equality comparisons on GPU.

Since `std::equal_to::operator()` is not a device function, it
fails on GPU.  On my device, I seem to get a silent crash in the
kernel (no reported error, but the kernel does not complete).

Replacing this with a portable version enables comparisons on device.

Addresses #2292 - would need to be cherry-picked.  The 3.3 branch
also requires adding `EIGEN_DEVICE_FUNC` in `BooleanRedux.h` to get
fully working.


(cherry picked from commit 7880f10526)
This commit is contained in:
Antonio Sanchez
2021-07-20 13:53:41 -07:00
committed by Rasmus Munk Larsen
parent 7adc1545b4
commit 3dc42eeaec
3 changed files with 41 additions and 12 deletions

View File

@@ -197,18 +197,17 @@ struct complex_operators {
res.segment(block_idx, size) = x1; res.segment(block_idx, size).array() /= x2.array();
block_idx += size;
// Equality comparisons currently not functional on device
// (std::equal_to<T> is host-only).
// const T true_vector = T::Constant(true_value);
// const T false_vector = T::Constant(false_value);
// res.segment(block_idx, size) = (x1 == x2 ? true_vector : false_vector);
// block_idx += size;
const T true_vector = T::Constant(true_value);
const T false_vector = T::Constant(false_value);
res.segment(block_idx, size) = (x1 == x2 ? true_vector : false_vector);
block_idx += size;
// Mixing types in equality comparison does not work.
// res.segment(block_idx, size) = (x1 == x2.real() ? true_vector : false_vector);
// block_idx += size;
// res.segment(block_idx, size) = (x1.real() == x2 ? true_vector : false_vector);
// block_idx += size;
// res.segment(block_idx, size) = (x1 != x2 ? true_vector : false_vector);
// block_idx += size;
res.segment(block_idx, size) = (x1 != x2 ? true_vector : false_vector);
block_idx += size;
// res.segment(block_idx, size) = (x1 != x2.real() ? true_vector : false_vector);
// block_idx += size;
// res.segment(block_idx, size) = (x1.real() != x2 ? true_vector : false_vector);