cart-elc

Source code for CART-ELC
git clone git://git.laack.co/cart-elc.git
Log | Files | Refs | README | LICENSE

TensorForwardDeclarations.h (8320B)


      1 // This file is part of Eigen, a lightweight C++ template library
      2 // for linear algebra.
      3 //
      4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
      5 //
      6 // This Source Code Form is subject to the terms of the Mozilla
      7 // Public License v. 2.0. If a copy of the MPL was not distributed
      8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
      9 
     10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H
     11 #define EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H
     12 
     13 namespace Eigen {
     14 
     15 // MakePointer class is used as a container of the address space of the pointer
     16 // on the host and on the device. From the host side it generates the T* pointer
     17 // and when EIGEN_USE_SYCL is used it construct a buffer with a map_allocator to
     18 // T* m_data on the host. It is always called on the device.
     19 // Specialisation of MakePointer class for creating the sycl buffer with
     20 // map_allocator.
     21 template<typename T> struct MakePointer {
     22   typedef T* Type;
     23   typedef const T* ConstType;
     24 };
     25 
     26 template <typename T>
     27 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* constCast(const T* data) {
     28   return const_cast<T*>(data);
     29 }
     30 
     31 // The StorageMemory class is a container of the device specific pointer
     32 // used for refering to a Pointer on TensorEvaluator class. While the TensorExpression
     33 // is a device-agnostic type and need MakePointer class for type conversion,
     34 // the TensorEvaluator class can be specialized for a device, hence it is possible
     35 // to construct different types of temproray storage memory in TensorEvaluator
     36 // for different devices by specializing the following StorageMemory class.
     37 template<typename T, typename device> struct StorageMemory: MakePointer <T> {};
     38 
     39 namespace internal{
     40 template<typename A, typename B> struct Pointer_type_promotion {
     41   static const bool val=false;
     42 };
     43 template<typename A> struct Pointer_type_promotion<A, A> {
     44   static const bool val = true;
     45 };
     46 template<typename A, typename B> struct TypeConversion {
     47   typedef A* type;
     48 };
     49 }
     50 
     51 
     52 template<typename PlainObjectType, int Options_ = Unaligned, template <class> class MakePointer_ = MakePointer> class TensorMap;
     53 template<typename Scalar_, int NumIndices_, int Options_ = 0, typename IndexType = DenseIndex> class Tensor;
     54 template<typename Scalar_, typename Dimensions, int Options_ = 0, typename IndexType = DenseIndex> class TensorFixedSize;
     55 template<typename PlainObjectType> class TensorRef;
     56 template<typename Derived, int AccessLevel> class TensorBase;
     57 
     58 template<typename NullaryOp, typename PlainObjectType> class TensorCwiseNullaryOp;
     59 template<typename UnaryOp, typename XprType> class TensorCwiseUnaryOp;
     60 template<typename BinaryOp, typename LeftXprType, typename RightXprType> class TensorCwiseBinaryOp;
     61 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> class TensorCwiseTernaryOp;
     62 template<typename IfXprType, typename ThenXprType, typename ElseXprType> class TensorSelectOp;
     63 template<typename Op, typename Dims, typename XprType, template <class> class MakePointer_ = MakePointer > class TensorReductionOp;
     64 template<typename XprType> class TensorIndexTupleOp;
     65 template<typename ReduceOp, typename Dims, typename XprType> class TensorTupleReducerOp;
     66 template<typename Axis, typename LeftXprType, typename RightXprType> class TensorConcatenationOp;
     67 template<typename Dimensions, typename LeftXprType, typename RightXprType, typename OutputKernelType> class TensorContractionOp;
     68 template<typename TargetType, typename XprType> class TensorConversionOp;
     69 template<typename Dimensions, typename InputXprType, typename KernelXprType> class TensorConvolutionOp;
     70 template<typename FFT, typename XprType, int FFTDataType, int FFTDirection> class TensorFFTOp;
     71 template<typename PatchDim, typename XprType> class TensorPatchOp;
     72 template<DenseIndex Rows, DenseIndex Cols, typename XprType> class TensorImagePatchOp;
     73 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> class TensorVolumePatchOp;
     74 template<typename Broadcast, typename XprType> class TensorBroadcastingOp;
     75 template<DenseIndex DimId, typename XprType> class TensorChippingOp;
     76 template<typename NewDimensions, typename XprType> class TensorReshapingOp;
     77 template<typename XprType> class TensorLayoutSwapOp;
     78 template<typename StartIndices, typename Sizes, typename XprType> class TensorSlicingOp;
     79 template<typename ReverseDimensions, typename XprType> class TensorReverseOp;
     80 template<typename PaddingDimensions, typename XprType> class TensorPaddingOp;
     81 template<typename Shuffle, typename XprType> class TensorShufflingOp;
     82 template<typename Strides, typename XprType> class TensorStridingOp;
     83 template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> class TensorStridingSlicingOp;
     84 template<typename Strides, typename XprType> class TensorInflationOp;
     85 template<typename Generator, typename XprType> class TensorGeneratorOp;
     86 template<typename LeftXprType, typename RightXprType> class TensorAssignOp;
     87 template<typename Op, typename XprType> class TensorScanOp;
     88 template<typename Dims, typename XprType> class TensorTraceOp;
     89 
     90 template<typename CustomUnaryFunc, typename XprType> class TensorCustomUnaryOp;
     91 template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> class TensorCustomBinaryOp;
     92 
     93 template<typename XprType, template <class> class MakePointer_ = MakePointer> class TensorEvalToOp;
     94 template<typename XprType> class TensorForcedEvalOp;
     95 
     96 template<typename ExpressionType, typename DeviceType> class TensorDevice;
     97 template<typename ExpressionType, typename DeviceType, typename DoneCallback> class TensorAsyncDevice;
     98 template<typename Derived, typename Device> struct TensorEvaluator;
     99 
    100 struct NoOpOutputKernel;
    101 
    102 struct DefaultDevice;
    103 struct ThreadPoolDevice;
    104 struct GpuDevice;
    105 struct SyclDevice;
    106 
    107 #ifdef EIGEN_USE_SYCL
    108 
    109 template <typename T> struct MakeSYCLPointer {
    110   typedef Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T> Type;
    111 };
    112 
    113 template <typename T>
    114 EIGEN_STRONG_INLINE const Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T>&
    115 constCast(const Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T>& data) {
    116   return data;
    117 }
    118 
    119 template <typename T>
    120 struct StorageMemory<T, SyclDevice> : MakeSYCLPointer<T> {};
    121 template <typename T>
    122 struct StorageMemory<T, const SyclDevice> : StorageMemory<T, SyclDevice> {};
    123 
    124 namespace TensorSycl {
    125 namespace internal{
    126 template <typename Evaluator, typename Op> class GenericNondeterministicReducer;
    127 }
    128 }
    129 #endif
    130 
    131 
    132 enum FFTResultType {
    133   RealPart = 0,
    134   ImagPart = 1,
    135   BothParts = 2
    136 };
    137 
    138 enum FFTDirection {
    139     FFT_FORWARD = 0,
    140     FFT_REVERSE = 1
    141 };
    142 
    143 
    144 namespace internal {
    145 
    146 template <typename Device, typename Expression>
    147 struct IsVectorizable {
    148   static const bool value = TensorEvaluator<Expression, Device>::PacketAccess;
    149 };
    150 
    151 template <typename Expression>
    152 struct IsVectorizable<GpuDevice, Expression> {
    153   static const bool value = TensorEvaluator<Expression, GpuDevice>::PacketAccess &&
    154                             TensorEvaluator<Expression, GpuDevice>::IsAligned;
    155 };
    156 
    157 // Tiled evaluation strategy.
    158 enum TiledEvaluation {
    159   Off = 0,    // tiled evaluation is not supported
    160   On = 1,     // still work in progress (see TensorBlock.h)
    161 };
    162 
    163 template <typename Device, typename Expression>
    164 struct IsTileable {
    165   // Check that block evaluation is supported and it's a preferred option (at
    166   // least one sub-expression has much faster block evaluation, e.g.
    167   // broadcasting).
    168   static const bool BlockAccess =
    169       TensorEvaluator<Expression, Device>::BlockAccess &&
    170       TensorEvaluator<Expression, Device>::PreferBlockAccess;
    171 
    172   static const TiledEvaluation value =
    173       BlockAccess ? TiledEvaluation::On : TiledEvaluation::Off;
    174 };
    175 
    176 template <typename Expression, typename Device,
    177           bool Vectorizable      = IsVectorizable<Device, Expression>::value,
    178           TiledEvaluation Tiling = IsTileable<Device, Expression>::value>
    179 class TensorExecutor;
    180 
    181 template <typename Expression, typename Device, typename DoneCallback,
    182           bool Vectorizable = IsVectorizable<Device, Expression>::value,
    183           TiledEvaluation Tiling = IsTileable<Device, Expression>::value>
    184 class TensorAsyncExecutor;
    185 
    186 
    187 }  // end namespace internal
    188 
    189 }  // end namespace Eigen
    190 
    191 #endif // EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H