mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Merged in deven-amd/eigen (pull request PR-402)
Adding support for using Eigen in HIP kernels.
This commit is contained in:
@@ -11,9 +11,18 @@
|
||||
#ifndef EIGEN_META_H
|
||||
#define EIGEN_META_H
|
||||
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
#include <cfloat>
|
||||
#include <math_constants.h>
|
||||
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
#include <math_constants.h>
|
||||
#endif
|
||||
|
||||
#if defined(EIGEN_HIP_DEVICE_COMPILE)
|
||||
#include "Eigen/src/Core/arch/HIP/hcc/math_constants.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if EIGEN_COMP_ICC>=1600 && __cplusplus >= 201103L
|
||||
@@ -177,7 +186,7 @@ template<bool Condition, typename T=void> struct enable_if;
|
||||
template<typename T> struct enable_if<true,T>
|
||||
{ typedef T type; };
|
||||
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
||||
#if !defined(__FLT_EPSILON__)
|
||||
#define __FLT_EPSILON__ FLT_EPSILON
|
||||
#define __DBL_EPSILON__ DBL_EPSILON
|
||||
@@ -199,13 +208,31 @@ template<> struct numeric_limits<float>
|
||||
EIGEN_DEVICE_FUNC
|
||||
static float epsilon() { return __FLT_EPSILON__; }
|
||||
EIGEN_DEVICE_FUNC
|
||||
static float (max)() { return CUDART_MAX_NORMAL_F; }
|
||||
static float (max)() {
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
return CUDART_MAX_NORMAL_F;
|
||||
#else
|
||||
return HIPRT_MAX_NORMAL_F;
|
||||
#endif
|
||||
}
|
||||
EIGEN_DEVICE_FUNC
|
||||
static float (min)() { return FLT_MIN; }
|
||||
EIGEN_DEVICE_FUNC
|
||||
static float infinity() { return CUDART_INF_F; }
|
||||
static float infinity() {
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
return CUDART_INF_F;
|
||||
#else
|
||||
return HIPRT_INF_F;
|
||||
#endif
|
||||
}
|
||||
EIGEN_DEVICE_FUNC
|
||||
static float quiet_NaN() { return CUDART_NAN_F; }
|
||||
static float quiet_NaN() {
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
return CUDART_NAN_F;
|
||||
#else
|
||||
return HIPRT_NAN_F;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
template<> struct numeric_limits<double>
|
||||
{
|
||||
@@ -216,9 +243,21 @@ template<> struct numeric_limits<double>
|
||||
EIGEN_DEVICE_FUNC
|
||||
static double (min)() { return DBL_MIN; }
|
||||
EIGEN_DEVICE_FUNC
|
||||
static double infinity() { return CUDART_INF; }
|
||||
static double infinity() {
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
return CUDART_INF;
|
||||
#else
|
||||
return HIPRT_INF;
|
||||
#endif
|
||||
}
|
||||
EIGEN_DEVICE_FUNC
|
||||
static double quiet_NaN() { return CUDART_NAN; }
|
||||
static double quiet_NaN() {
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
return CUDART_NAN;
|
||||
#else
|
||||
return HIPRT_NAN;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
template<> struct numeric_limits<int>
|
||||
{
|
||||
@@ -531,13 +570,13 @@ template<typename T, typename U> struct scalar_product_traits
|
||||
|
||||
namespace numext {
|
||||
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
||||
template<typename T> EIGEN_DEVICE_FUNC void swap(T &a, T &b) { T tmp = b; b = a; a = tmp; }
|
||||
#else
|
||||
template<typename T> EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b); }
|
||||
#endif
|
||||
|
||||
#if defined(EIGEN_CUDA_ARCH)
|
||||
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
||||
using internal::device::numeric_limits;
|
||||
#else
|
||||
using std::numeric_limits;
|
||||
@@ -557,7 +596,7 @@ T div_ceil(const T &a, const T &b)
|
||||
template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool equal_strict(const X& x,const Y& y) { return x == y; }
|
||||
|
||||
#if !defined(EIGEN_CUDA_ARCH) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)
|
||||
#if !defined(EIGEN_GPU_COMPILE_PHASE) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)
|
||||
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool equal_strict(const float& x,const float& y) { return std::equal_to<float>()(x,y); }
|
||||
|
||||
@@ -568,7 +607,7 @@ bool equal_strict(const double& x,const double& y) { return std::equal_to<double
|
||||
template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool not_equal_strict(const X& x,const Y& y) { return x != y; }
|
||||
|
||||
#if !defined(EIGEN_CUDA_ARCH) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)
|
||||
#if !defined(EIGEN_GPU_COMPILE_PHASE) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)
|
||||
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool not_equal_strict(const float& x,const float& y) { return std::not_equal_to<float>()(x,y); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user