mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 20:56:00 +08:00
Makingt default numeric_list works with sycl.
This commit is contained in:
parent
7ff26ddcbb
commit
592acc5bfa
@ -25,6 +25,15 @@
|
|||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
namespace TensorSycl {
|
namespace TensorSycl {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
template <typename Expr, typename Dims>
|
||||||
|
struct DeviceFixedSizeTensor;
|
||||||
|
|
||||||
|
template <typename Expr, typename std::ptrdiff_t... Indices>
|
||||||
|
struct DeviceFixedSizeTensor<Expr, Eigen::Sizes<Indices...>>{
|
||||||
|
template<typename Data>
|
||||||
|
static EIGEN_ALWAYS_INLINE Expr instantiate(Data& dt) {return Expr(ConvertToActualTypeSycl(typename Expr::Scalar, dt), Indices...);}
|
||||||
|
};
|
||||||
/// this class is used by EvalToOp in order to create an lhs expression which is
|
/// this class is used by EvalToOp in order to create an lhs expression which is
|
||||||
/// a pointer from an accessor on device-only buffer
|
/// a pointer from an accessor on device-only buffer
|
||||||
template <typename PtrType, size_t N, typename... Params>
|
template <typename PtrType, size_t N, typename... Params>
|
||||||
@ -61,6 +70,23 @@ TENSORMAP(const)
|
|||||||
TENSORMAP()
|
TENSORMAP()
|
||||||
#undef TENSORMAP
|
#undef TENSORMAP
|
||||||
|
|
||||||
|
/// specialisation of the \ref ExprConstructor struct when the node type is
|
||||||
|
/// TensorMap
|
||||||
|
#define TENSORMAPFIXEDSIZE(CVQual)\
|
||||||
|
template <typename Scalar_, typename Dimensions_, int Options_2, typename IndexType, int Options_,\
|
||||||
|
template <class> class MakePointer_, size_t N, typename... Params>\
|
||||||
|
struct ExprConstructor< CVQual TensorMap<TensorFixedSize<Scalar_, Dimensions_, Options_2, IndexType>, Options_, MakeGlobalPointer>,\
|
||||||
|
CVQual PlaceHolder<CVQual TensorMap<TensorFixedSize<Scalar_, Dimensions_, Options_2, IndexType>, Options_, MakePointer_>, N>, Params...>{\
|
||||||
|
typedef CVQual TensorMap<TensorFixedSize<Scalar_, Dimensions_, Options_2, IndexType>, Options_, MakeGlobalPointer> Type;\
|
||||||
|
Type expr;\
|
||||||
|
template <typename FuncDetector>\
|
||||||
|
ExprConstructor(FuncDetector &, const utility::tuple::Tuple<Params...> &t)\
|
||||||
|
: expr(DeviceFixedSizeTensor<Type,Dimensions_>::instantiate(utility::tuple::get<N>(t))){}\
|
||||||
|
};
|
||||||
|
TENSORMAPFIXEDSIZE(const)
|
||||||
|
TENSORMAPFIXEDSIZE()
|
||||||
|
#undef TENSORMAPFIXEDSIZE
|
||||||
|
|
||||||
#define UNARYCATEGORY(CVQual)\
|
#define UNARYCATEGORY(CVQual)\
|
||||||
template <template<class, class> class UnaryCategory, typename OP, typename OrigRHSExpr, typename RHSExpr, typename... Params>\
|
template <template<class, class> class UnaryCategory, typename OP, typename OrigRHSExpr, typename RHSExpr, typename... Params>\
|
||||||
struct ExprConstructor<CVQual UnaryCategory<OP, OrigRHSExpr>, CVQual UnaryCategory<OP, RHSExpr>, Params...> {\
|
struct ExprConstructor<CVQual UnaryCategory<OP, OrigRHSExpr>, CVQual UnaryCategory<OP, RHSExpr>, Params...> {\
|
||||||
|
@ -41,6 +41,17 @@ template <typename Evaluator> struct FunctorExtractor{
|
|||||||
: m_dimensions(expr.dimensions()) {}
|
: m_dimensions(expr.dimensions()) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define SYCLEXTRTENSORMAPFIXEDSIZE(CVQual)\
|
||||||
|
template <typename Scalar_, typename Dimensions_, int Options_2, typename IndexType, int Options_, template <class> class MakePointer_, typename Dev>\
|
||||||
|
struct FunctorExtractor< TensorEvaluator <CVQual TensorMap<TensorFixedSize<Scalar_, Dimensions_, Options_2, IndexType>, Options_, MakePointer_> , Dev> >{\
|
||||||
|
FunctorExtractor(const TensorEvaluator <CVQual TensorMap<TensorFixedSize<Scalar_, Dimensions_, Options_2, IndexType>, Options_, MakePointer_> , Dev>& ){}\
|
||||||
|
};
|
||||||
|
|
||||||
|
SYCLEXTRTENSORMAPFIXEDSIZE(const)
|
||||||
|
SYCLEXTRTENSORMAPFIXEDSIZE()
|
||||||
|
#undef SYCLEXTRTENSORMAPFIXEDSIZE
|
||||||
|
|
||||||
/// specialisation of the \ref FunctorExtractor struct when the node type is
|
/// specialisation of the \ref FunctorExtractor struct when the node type is
|
||||||
/// TensorCwiseNullaryOp, TensorCwiseUnaryOp, and TensorBroadcastingOp
|
/// TensorCwiseNullaryOp, TensorCwiseUnaryOp, and TensorBroadcastingOp
|
||||||
#define SYCLEXTRFUNCUNARY(CVQual)\
|
#define SYCLEXTRFUNCUNARY(CVQual)\
|
||||||
|
@ -36,27 +36,12 @@ struct type_list { constexpr static int count = sizeof...(tt); };
|
|||||||
template<typename t, typename... tt>
|
template<typename t, typename... tt>
|
||||||
struct type_list<t, tt...> { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; };
|
struct type_list<t, tt...> { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; };
|
||||||
|
|
||||||
#ifndef EIGEN_USE_SYCL
|
|
||||||
template<typename T, T... nn>
|
template<typename T, T... nn>
|
||||||
struct numeric_list { constexpr static std::size_t count = sizeof...(nn); };
|
struct numeric_list { constexpr static std::size_t count = sizeof...(nn); };
|
||||||
|
|
||||||
template<typename T, T n, T... nn>
|
template<typename T, T n, T... nn>
|
||||||
struct numeric_list<T, n, nn...> { static const std::size_t count = sizeof...(nn) + 1; const static T first_value = n; };
|
struct numeric_list<T, n, nn...> { static const std::size_t count = sizeof...(nn) + 1; const static T first_value = n; };
|
||||||
|
|
||||||
#else
|
|
||||||
template<typename T, T... nn>
|
|
||||||
struct numeric_list {
|
|
||||||
static constexpr std::size_t count = sizeof...(nn);
|
|
||||||
const T values[count] = {nn...};
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
struct numeric_list<T>{
|
|
||||||
static constexpr std::size_t count = 0;
|
|
||||||
//Array of size zero strictly forbiden in ISO C++
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* numeric list constructors
|
/* numeric list constructors
|
||||||
*
|
*
|
||||||
* equivalencies:
|
* equivalencies:
|
||||||
@ -138,19 +123,9 @@ template<typename a, typename... as> struct get<0, type_lis
|
|||||||
template<typename T, int n, T a, T... as> struct get<n, numeric_list<T, a, as...>> : get<n-1, numeric_list<T, as...>> {};
|
template<typename T, int n, T a, T... as> struct get<n, numeric_list<T, a, as...>> : get<n-1, numeric_list<T, as...>> {};
|
||||||
template<typename T, T a, T... as> struct get<0, numeric_list<T, a, as...>> { constexpr static T value = a; };
|
template<typename T, T a, T... as> struct get<0, numeric_list<T, a, as...>> { constexpr static T value = a; };
|
||||||
|
|
||||||
#ifndef EIGEN_USE_SYCL
|
|
||||||
template<std::size_t n, typename T, T a, T... as> constexpr T array_get(const numeric_list<T, a, as...>&) {
|
template<std::size_t n, typename T, T a, T... as> constexpr T array_get(const numeric_list<T, a, as...>&) {
|
||||||
return get<(int)n, numeric_list<T, a, as...>>::value;
|
return get<(int)n, numeric_list<T, a, as...>>::value;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
template<std::size_t n, typename T, T... as> constexpr T array_get(const numeric_list<T, as...>& l) {
|
|
||||||
return l.values[n];
|
|
||||||
}
|
|
||||||
template<std::size_t n, typename T> constexpr T array_get(const numeric_list<T>& ) {
|
|
||||||
return T(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* always get type, regardless of dummy; good for parameter pack expansion */
|
/* always get type, regardless of dummy; good for parameter pack expansion */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user