Logo ROOT   6.21/01
Reference Guide
TMVA::DNN::TCudaTensor< AFloat > Class Template Reference

template<typename AFloat>
class TMVA::DNN::TCudaTensor< AFloat >

TCudaTensor Class.

The TCudaTensor class extends the TCudaMatrix class for dimensions > 2.

Definition at line 74 of file CudaTensor.h.

Classes

struct  TensorDescriptor
 

Public Types

using MemoryLayout = TMVA::Experimental::MemoryLayout
 
using Scalar_t = AFloat
 
using Shape_t = std::vector< size_t >
 

Public Member Functions

 TCudaTensor ()
 
 TCudaTensor (const AFloat *data, const std::vector< size_t > &shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (TCudaDeviceBuffer< AFloat > buffer, const std::vector< size_t > &shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (const std::vector< size_t > &shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (size_t bsize, size_t csize, size_t hwsize, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (size_t bsize, size_t csize, size_t hsize, size_t wsize, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (size_t n, size_t m, MemoryLayout memlayout=MemoryLayout::ColumnMajor, int deviceIndx=0, int streamIndx=0)
 
 TCudaTensor (const TCudaMatrix< AFloat > &m, size_t dim=2)
 
 TCudaTensor (TCudaDeviceBuffer< AFloat > buffer, size_t n, size_t m)
 
 TCudaTensor (const TCudaTensor &)=default
 
 TCudaTensor (TCudaTensor &&)=default
 
 ~TCudaTensor ()
 
TCudaTensor< AFloat > At (size_t i) const
 
cudaStream_t GetComputeStream () const
 
size_t GetCSize () const
 
const cudnnHandle_t & GetCudnnHandle () const
 
const AFloat * GetData () const
 
AFloat * GetData ()
 
const AFloat * GetDataPointer () const
 
AFloat * GetDataPointer ()
 
const AFloat * GetDataPointerAt (size_t i) const
 
AFloat * GetDataPointerAt (size_t i)
 
const TCudaDeviceBuffer< AFloat > & GetDeviceBuffer () const
 
TCudaDeviceBuffer< AFloat > & GetDeviceBuffer ()
 
size_t GetDimAt (size_t i) const
 
size_t GetFirstSize () const
 
size_t GetFirstStride () const
 
size_t GetHSize () const
 
MemoryLayout GetLayout () const
 
TCudaMatrix< AFloat > GetMatrix () const
 
size_t GetNcols () const
 
size_t GetNDim () const
 
size_t GetNrows () const
 
const Shape_tGetShape () const
 
size_t GetSize () const
 
const Shape_tGetStrides () const
 
const cudnnTensorDescriptor_t & GetTensorDescriptor () const
 
size_t GetWSize () const
 
bool isEqual (TCudaTensor< AFloat > &other)
 
bool isEqual (const AFloat *hostBufferOther, size_t otherSize)
 
 operator TMatrixT< AFloat > () const
 Convert cuda matrix to Root TMatrix. More...
 
TCudaDeviceReference< AFloat > operator() (size_t i, size_t j) const
 
TCudaDeviceReference< AFloat > operator() (size_t i, size_t j, size_t k) const
 
TCudaDeviceReference< AFloat > operator() (size_t i, size_t j, size_t k, size_t l) const
 
TCudaTensoroperator= (const TCudaTensor &)=default
 
TCudaTensoroperator= (TCudaTensor &&)=default
 
void Print (const char *name="Tensor", bool truncate=false) const
 
void PrintShape (const char *name="Tensor") const
 
TCudaTensor< AFloat > Reshape (const Shape_t &newShape) const
 
void ReshapeInPlace (const Shape_t &newShape)
 
void SetComputeStream (cudaStream_t stream)
 
void SetConstVal (const AFloat constVal)
 
void SetTensorDescriptor ()
 
void Zero ()
 

Static Public Member Functions

static std::vector< std::size_t > ComputeStridesFromShape (const std::vector< std::size_t > &shape, bool rowmajorLayout)
 
static cudnnDataType_t GetDataType ()
 

Private Member Functions

void InitializeCuda ()
 Initializes all shared devices resource and makes sure that a sufficient number of curand states are allocated on the device and initialized as well as that the one-vector for the summation over columns has the right size. More...
 
void InitializeCurandStates ()
 

Private Attributes

int fDevice
 Device associated with current tensor instance. More...
 
TCudaDeviceBuffer< AFloat > fElementBuffer
 
MemoryLayout fMemoryLayout
 
size_t fNDim
 Dimension of the tensor (first dimension is the batch size, second is the no. channels) More...
 
Shape_t fShape
 The shape vector (size of dimensions) needs to be ordered as no. More...
 
size_t fSize
 No. of elements. More...
 
int fStreamIndx
 Cuda stream associated with current instance. More...
 
Shape_t fStrides
 Strides between tensor dimensions (always assume dense, non overlapping tensor) More...
 
std::shared_ptr< TensorDescriptorfTensorDescriptor
 

Static Private Attributes

static std::vector< cudnnHandle_t > fCudnnHandle
 Holds the cuddn library context (one for every CUDA stream) More...
 
static cudnnDataType_t fDataType
 Cudnn datatype used for the tensor. More...
 
static std::vector< int > fInstances
 For each GPU device keep the CUDA streams in which tensors are used. More...
 

#include <TMVA/DNN/Architectures/Cuda/CudaTensor.h>

Member Typedef Documentation

◆ MemoryLayout

template<typename AFloat>
using TMVA::DNN::TCudaTensor< AFloat >::MemoryLayout = TMVA::Experimental:: MemoryLayout

Definition at line 79 of file CudaTensor.h.

◆ Scalar_t

template<typename AFloat>
using TMVA::DNN::TCudaTensor< AFloat >::Scalar_t = AFloat

Definition at line 80 of file CudaTensor.h.

◆ Shape_t

template<typename AFloat>
using TMVA::DNN::TCudaTensor< AFloat >::Shape_t = std::vector<size_t>

Definition at line 78 of file CudaTensor.h.

Constructor & Destructor Documentation

◆ TCudaTensor() [1/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( )

◆ TCudaTensor() [2/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( const AFloat *  data,
const std::vector< size_t > &  shape,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)

◆ TCudaTensor() [3/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( TCudaDeviceBuffer< AFloat >  buffer,
const std::vector< size_t > &  shape,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)

◆ TCudaTensor() [4/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( const std::vector< size_t > &  shape,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)

◆ TCudaTensor() [5/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( size_t  bsize,
size_t  csize,
size_t  hwsize,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)
inline

Definition at line 134 of file CudaTensor.h.

◆ TCudaTensor() [6/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( size_t  bsize,
size_t  csize,
size_t  hsize,
size_t  wsize,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)
inline

Definition at line 139 of file CudaTensor.h.

◆ TCudaTensor() [7/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( size_t  n,
size_t  m,
MemoryLayout  memlayout = MemoryLayout::ColumnMajor,
int  deviceIndx = 0,
int  streamIndx = 0 
)
inline

Definition at line 147 of file CudaTensor.h.

◆ TCudaTensor() [8/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( const TCudaMatrix< AFloat > &  m,
size_t  dim = 2 
)

◆ TCudaTensor() [9/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( TCudaDeviceBuffer< AFloat >  buffer,
size_t  n,
size_t  m 
)
inline

Definition at line 154 of file CudaTensor.h.

◆ TCudaTensor() [10/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( const TCudaTensor< AFloat > &  )
default

◆ TCudaTensor() [11/11]

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::TCudaTensor ( TCudaTensor< AFloat > &&  )
default

◆ ~TCudaTensor()

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::~TCudaTensor ( )

Member Function Documentation

◆ At()

template<typename AFloat>
TCudaTensor<AFloat> TMVA::DNN::TCudaTensor< AFloat >::At ( size_t  i) const
inline

Definition at line 341 of file CudaTensor.h.

◆ ComputeStridesFromShape()

template<typename AFloat>
static std::vector<std::size_t> TMVA::DNN::TCudaTensor< AFloat >::ComputeStridesFromShape ( const std::vector< std::size_t > &  shape,
bool  rowmajorLayout 
)
inlinestatic

◆ GetComputeStream()

template<typename AFloat>
cudaStream_t TMVA::DNN::TCudaTensor< AFloat >::GetComputeStream ( ) const
inline

Definition at line 192 of file CudaTensor.h.

◆ GetCSize()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetCSize ( ) const
inline

Definition at line 258 of file CudaTensor.h.

◆ GetCudnnHandle()

template<typename AFloat>
const cudnnHandle_t& TMVA::DNN::TCudaTensor< AFloat >::GetCudnnHandle ( ) const
inline

Definition at line 187 of file CudaTensor.h.

◆ GetData() [1/2]

template<typename AFloat>
const AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetData ( ) const
inline

Definition at line 177 of file CudaTensor.h.

◆ GetData() [2/2]

template<typename AFloat>
AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetData ( )
inline

Definition at line 178 of file CudaTensor.h.

◆ GetDataPointer() [1/2]

template<typename AFloat>
const AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetDataPointer ( ) const
inline

Definition at line 175 of file CudaTensor.h.

◆ GetDataPointer() [2/2]

template<typename AFloat>
AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetDataPointer ( )
inline

Definition at line 176 of file CudaTensor.h.

◆ GetDataPointerAt() [1/2]

template<typename AFloat>
const AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetDataPointerAt ( size_t  i) const
inline

Definition at line 180 of file CudaTensor.h.

◆ GetDataPointerAt() [2/2]

template<typename AFloat>
AFloat* TMVA::DNN::TCudaTensor< AFloat >::GetDataPointerAt ( size_t  i)
inline

Definition at line 182 of file CudaTensor.h.

◆ GetDataType()

template<typename AFloat>
static cudnnDataType_t TMVA::DNN::TCudaTensor< AFloat >::GetDataType ( )
inlinestatic

Definition at line 190 of file CudaTensor.h.

◆ GetDeviceBuffer() [1/2]

template<typename AFloat>
const TCudaDeviceBuffer<AFloat>& TMVA::DNN::TCudaTensor< AFloat >::GetDeviceBuffer ( ) const
inline

Definition at line 185 of file CudaTensor.h.

◆ GetDeviceBuffer() [2/2]

template<typename AFloat>
TCudaDeviceBuffer<AFloat>& TMVA::DNN::TCudaTensor< AFloat >::GetDeviceBuffer ( )
inline

Definition at line 186 of file CudaTensor.h.

◆ GetDimAt()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetDimAt ( size_t  i) const
inline

Definition at line 171 of file CudaTensor.h.

◆ GetFirstSize()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetFirstSize ( ) const
inline

Definition at line 253 of file CudaTensor.h.

◆ GetFirstStride()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetFirstStride ( ) const
inline

Definition at line 255 of file CudaTensor.h.

◆ GetHSize()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetHSize ( ) const
inline

Definition at line 262 of file CudaTensor.h.

◆ GetLayout()

template<typename AFloat>
MemoryLayout TMVA::DNN::TCudaTensor< AFloat >::GetLayout ( ) const
inline

Definition at line 167 of file CudaTensor.h.

◆ GetMatrix()

template<typename AFloat>
TCudaMatrix<AFloat> TMVA::DNN::TCudaTensor< AFloat >::GetMatrix ( ) const
inline

Definition at line 283 of file CudaTensor.h.

◆ GetNcols()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetNcols ( ) const
inline

Definition at line 279 of file CudaTensor.h.

◆ GetNDim()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetNDim ( ) const
inline

Definition at line 172 of file CudaTensor.h.

◆ GetNrows()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetNrows ( ) const
inline

Definition at line 278 of file CudaTensor.h.

◆ GetShape()

template<typename AFloat>
const Shape_t& TMVA::DNN::TCudaTensor< AFloat >::GetShape ( ) const
inline

Definition at line 169 of file CudaTensor.h.

◆ GetSize()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetSize ( ) const
inline

Definition at line 173 of file CudaTensor.h.

◆ GetStrides()

template<typename AFloat>
const Shape_t& TMVA::DNN::TCudaTensor< AFloat >::GetStrides ( ) const
inline

Definition at line 170 of file CudaTensor.h.

◆ GetTensorDescriptor()

template<typename AFloat>
const cudnnTensorDescriptor_t& TMVA::DNN::TCudaTensor< AFloat >::GetTensorDescriptor ( ) const
inline

Definition at line 188 of file CudaTensor.h.

◆ GetWSize()

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::GetWSize ( ) const
inline

Definition at line 268 of file CudaTensor.h.

◆ InitializeCuda()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::InitializeCuda ( )
private

Initializes all shared devices resource and makes sure that a sufficient number of curand states are allocated on the device and initialized as well as that the one-vector for the summation over columns has the right size.

◆ InitializeCurandStates()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::InitializeCurandStates ( )
private

◆ isEqual() [1/2]

template<typename AFloat>
bool TMVA::DNN::TCudaTensor< AFloat >::isEqual ( TCudaTensor< AFloat > &  other)
inline

Definition at line 199 of file CudaTensor.h.

◆ isEqual() [2/2]

template<typename AFloat>
bool TMVA::DNN::TCudaTensor< AFloat >::isEqual ( const AFloat *  hostBufferOther,
size_t  otherSize 
)
inline

Definition at line 217 of file CudaTensor.h.

◆ operator TMatrixT< AFloat >()

template<typename AFloat>
TMVA::DNN::TCudaTensor< AFloat >::operator TMatrixT< AFloat > ( ) const

Convert cuda matrix to Root TMatrix.

Performs synchronous data transfer.

◆ operator()() [1/3]

template<typename AFloat>
TCudaDeviceReference<AFloat> TMVA::DNN::TCudaTensor< AFloat >::operator() ( size_t  i,
size_t  j 
) const
inline

Definition at line 357 of file CudaTensor.h.

◆ operator()() [2/3]

template<typename AFloat>
TCudaDeviceReference<AFloat> TMVA::DNN::TCudaTensor< AFloat >::operator() ( size_t  i,
size_t  j,
size_t  k 
) const
inline

Definition at line 371 of file CudaTensor.h.

◆ operator()() [3/3]

template<typename AFloat>
TCudaDeviceReference<AFloat> TMVA::DNN::TCudaTensor< AFloat >::operator() ( size_t  i,
size_t  j,
size_t  k,
size_t  l 
) const
inline

Definition at line 386 of file CudaTensor.h.

◆ operator=() [1/2]

template<typename AFloat>
TCudaTensor& TMVA::DNN::TCudaTensor< AFloat >::operator= ( const TCudaTensor< AFloat > &  )
default

◆ operator=() [2/2]

template<typename AFloat>
TCudaTensor& TMVA::DNN::TCudaTensor< AFloat >::operator= ( TCudaTensor< AFloat > &&  )
default

◆ Print()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::Print ( const char *  name = "Tensor",
bool  truncate = false 
) const

◆ PrintShape()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::PrintShape ( const char *  name = "Tensor") const

◆ Reshape()

template<typename AFloat>
TCudaTensor<AFloat> TMVA::DNN::TCudaTensor< AFloat >::Reshape ( const Shape_t newShape) const
inline

Definition at line 326 of file CudaTensor.h.

◆ ReshapeInPlace()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::ReshapeInPlace ( const Shape_t newShape)
inline

Definition at line 314 of file CudaTensor.h.

◆ SetComputeStream()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::SetComputeStream ( cudaStream_t  stream)
inline

Definition at line 195 of file CudaTensor.h.

◆ SetConstVal()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::SetConstVal ( const AFloat  constVal)
inline

Definition at line 240 of file CudaTensor.h.

◆ SetTensorDescriptor()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::SetTensorDescriptor ( )

◆ Zero()

template<typename AFloat>
void TMVA::DNN::TCudaTensor< AFloat >::Zero ( )
inline

Definition at line 236 of file CudaTensor.h.

Member Data Documentation

◆ fCudnnHandle

template<typename AFloat>
std::vector<cudnnHandle_t> TMVA::DNN::TCudaTensor< AFloat >::fCudnnHandle
staticprivate

Holds the cuddn library context (one for every CUDA stream)

Definition at line 89 of file CudaTensor.h.

◆ fDataType

template<typename AFloat>
cudnnDataType_t TMVA::DNN::TCudaTensor< AFloat >::fDataType
staticprivate

Cudnn datatype used for the tensor.

Definition at line 91 of file CudaTensor.h.

◆ fDevice

template<typename AFloat>
int TMVA::DNN::TCudaTensor< AFloat >::fDevice
private

Device associated with current tensor instance.

Definition at line 105 of file CudaTensor.h.

◆ fElementBuffer

template<typename AFloat>
TCudaDeviceBuffer<AFloat> TMVA::DNN::TCudaTensor< AFloat >::fElementBuffer
private

Definition at line 109 of file CudaTensor.h.

◆ fInstances

template<typename AFloat>
std::vector<int> TMVA::DNN::TCudaTensor< AFloat >::fInstances
staticprivate

For each GPU device keep the CUDA streams in which tensors are used.

Instances belonging to the same stream on the same deviceshare a cudnn library handel to keep cudnn contexts seperated

Definition at line 96 of file CudaTensor.h.

◆ fMemoryLayout

template<typename AFloat>
MemoryLayout TMVA::DNN::TCudaTensor< AFloat >::fMemoryLayout
private

Definition at line 111 of file CudaTensor.h.

◆ fNDim

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::fNDim
private

Dimension of the tensor (first dimension is the batch size, second is the no. channels)

Definition at line 103 of file CudaTensor.h.

◆ fShape

template<typename AFloat>
Shape_t TMVA::DNN::TCudaTensor< AFloat >::fShape
private

The shape vector (size of dimensions) needs to be ordered as no.

channels, image dimensions.spatial subdimensions

Definition at line 101 of file CudaTensor.h.

◆ fSize

template<typename AFloat>
size_t TMVA::DNN::TCudaTensor< AFloat >::fSize
private

No. of elements.

Definition at line 104 of file CudaTensor.h.

◆ fStreamIndx

template<typename AFloat>
int TMVA::DNN::TCudaTensor< AFloat >::fStreamIndx
private

Cuda stream associated with current instance.

Definition at line 106 of file CudaTensor.h.

◆ fStrides

template<typename AFloat>
Shape_t TMVA::DNN::TCudaTensor< AFloat >::fStrides
private

Strides between tensor dimensions (always assume dense, non overlapping tensor)

Definition at line 102 of file CudaTensor.h.

◆ fTensorDescriptor

template<typename AFloat>
std::shared_ptr<TensorDescriptor> TMVA::DNN::TCudaTensor< AFloat >::fTensorDescriptor
private

Definition at line 108 of file CudaTensor.h.


The documentation for this class was generated from the following file: