mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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:
committed by
Rasmus Munk Larsen
parent
7adc1545b4
commit
3dc42eeaec
@@ -12,6 +12,28 @@
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
// Portable replacements for certain functors.
|
||||
namespace numext {
|
||||
|
||||
template<typename T = void>
|
||||
struct equal_to {
|
||||
typedef bool result_type;
|
||||
EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T = void>
|
||||
struct not_equal_to {
|
||||
typedef bool result_type;
|
||||
EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
|
||||
return lhs != rhs;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace internal {
|
||||
|
||||
// default functor traits for STL functors:
|
||||
@@ -68,10 +90,18 @@ template<typename T>
|
||||
struct functor_traits<std::equal_to<T> >
|
||||
{ enum { Cost = 1, PacketAccess = false }; };
|
||||
|
||||
template<typename T>
|
||||
struct functor_traits<numext::equal_to<T> >
|
||||
: functor_traits<std::equal_to<T> > {};
|
||||
|
||||
template<typename T>
|
||||
struct functor_traits<std::not_equal_to<T> >
|
||||
{ enum { Cost = 1, PacketAccess = false }; };
|
||||
|
||||
template<typename T>
|
||||
struct functor_traits<numext::not_equal_to<T> >
|
||||
: functor_traits<std::not_equal_to<T> > {};
|
||||
|
||||
#if (EIGEN_COMP_CXXVER < 11)
|
||||
// std::binder* are deprecated since c++11 and will be removed in c++17
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user