18#ifndef TMVA_DNN_ARCHITECTURES_CUDA
19#define TMVA_DNN_ARCHITECTURES_CUDA
45template<
typename AFloat = Real_t>
119 template<
typename AMatrix_t>
132 template<
typename AMatrix_t>
134 const std::vector<AMatrix_t> &
B);
326 size_t zeroPaddingHeight,
327 size_t zeroPaddingWidth);
330 size_t ,
size_t ,
size_t ,
331 size_t ,
size_t ,
size_t ,
334 const std::vector<int> & ) {}
340 size_t filterHeight,
size_t filterWidth,
size_t numFilters);
372 size_t inputHeight,
size_t inputWidth,
size_t depth,
size_t height,
size_t width,
373 size_t filterDepth,
size_t filterHeight,
size_t filterWidth,
size_t nLocalViews);
380 size_t inputHeight,
size_t inputWidth,
size_t depth,
size_t height,
381 size_t width,
size_t filterDepth,
size_t filterHeight,
388 size_t batchSize,
size_t inputHeight,
size_t inputWidth,
size_t depth,
389 size_t height,
size_t width,
size_t filterDepth,
size_t filterHeight,
390 size_t filterWidth,
size_t nLocalViews);
395 size_t batchSize,
size_t depth,
size_t nLocalViews);
411 size_t imgHeight,
size_t imgWidth,
size_t fltHeight,
size_t fltWidth,
412 size_t strideRows,
size_t strideCols);
537template <
typename AFloat>
538template <
typename AMatrix_t>
549template <
typename AFloat>
550template <
typename AMatrix_t>
552 const std::vector<AMatrix_t> &
A)
554 for (
size_t i = 0; i <
B.size(); ++i) {
555 CopyDiffArch(
B[i],
A[i]);
include TDocParser_001 C image html pict1_TDocParser_001 png width
The TCuda architecture class.
static TRandom * fgRandomGen
static void RotateWeights(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, size_t filterDepth, size_t filterHeight, size_t filterWidth, size_t numFilters)
Rotates the matrix B, which is representing a weights, and stores them in the matrix A.
static void CalculateConvActivationGradients(std::vector< TCudaMatrix< AFloat > > &activationGradientsBackward, std::vector< TCudaMatrix< AFloat > > &df, const TCudaMatrix< AFloat > &weights, size_t batchSize, size_t inputHeight, size_t inputWidth, size_t depth, size_t height, size_t width, size_t filterDepth, size_t filterHeight, size_t filterWidth)
Utility function for calculating the activation gradients of the layer before the convolutional layer...
static void MultiplyTranspose(TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &input, const TCudaMatrix< AFloat > &weights)
Matrix-multiply input with the transpose of \pweights and write the results into output.
static void Multiply(TCudaMatrix< AFloat > &C, const TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B)
Standard multiplication of two matrices A and B with the result being written into C.
static void Softmax(TCudaMatrix< AFloat > &YHat, const TCudaMatrix< AFloat > &)
static void AddL2RegularizationGradients(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &W, AFloat weightDecay)
static void Im2col(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, size_t imgHeight, size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols, size_t zeroPaddingHeight, size_t zeroPaddingWidth)
Transform the matrix B in local view format, suitable for convolution, and store it in matrix A.
static void Copy(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
Copy the elements of matrix A into matrix B.
static void Rearrange(std::vector< TCudaMatrix< AFloat > > &out, const std::vector< TCudaMatrix< AFloat > > &in)
Rearrage data accoring to time fill B x T x D out with T x B x D matrix in.
static void Copy(std::vector< TCudaMatrix< Scalar_t > > &A, const std::vector< TCudaMatrix< Scalar_t > > &B)
static void InitializeGlorotNormal(TCudaMatrix< AFloat > &A)
static void InitializeGlorotUniform(TCudaMatrix< AFloat > &A)
static void Downsample(TCudaMatrix< AFloat > &A, TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &C, size_t imgHeight, size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols)
Downsample the matrix C to the matrix A, using max operation, such that the winning indices are store...
static Matrix_t & RecurrentLayerBackward(TCudaMatrix< AFloat > &state_gradients_backward, TCudaMatrix< AFloat > &input_weight_gradients, TCudaMatrix< AFloat > &state_weight_gradients, TCudaMatrix< AFloat > &bias_gradients, TCudaMatrix< AFloat > &df, const TCudaMatrix< AFloat > &state, const TCudaMatrix< AFloat > &weights_input, const TCudaMatrix< AFloat > &weights_state, const TCudaMatrix< AFloat > &input, TCudaMatrix< AFloat > &input_gradient)
Backward pass for Recurrent Networks.
static AFloat SoftmaxCrossEntropy(const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
Softmax transformation is implicitly applied, thus output should hold the linear activations of the l...
static void GaussDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static void Relu(TCudaMatrix< AFloat > &B)
static void PrepareInternals(std::vector< TCudaMatrix< AFloat > > &inputPrime)
Attaches a cuda stream to each matrix in order to accomodate parallel kernel launches.
static void ConstAdd(TCudaMatrix< AFloat > &A, AFloat beta)
Add the constant beta to all the elements of matrix A and write the result into A.
static void SumColumns(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
Sum columns of (m x n) matrix A and write the results into the first m elements in B.
static void InitializeZero(TCudaMatrix< AFloat > &A)
static void ScaleAdd(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, Scalar_t beta=1.0)
Adds a the elements in matrix B scaled by c to the elements in the matrix A.
static void SoftSign(TCudaMatrix< AFloat > &B)
static void ConvLayerBackward(std::vector< TCudaMatrix< AFloat > > &activationGradientsBackward, TCudaMatrix< AFloat > &weightGradients, TCudaMatrix< AFloat > &biasGradients, std::vector< TCudaMatrix< AFloat > > &df, const std::vector< TCudaMatrix< AFloat > > &activationGradients, const TCudaMatrix< AFloat > &weights, const std::vector< TCudaMatrix< AFloat > > &activationBackward, size_t batchSize, size_t inputHeight, size_t inputWidth, size_t depth, size_t height, size_t width, size_t filterDepth, size_t filterHeight, size_t filterWidth, size_t nLocalViews)
Perform the complete backward propagation step in a Convolutional Layer.
static void SymmetricReluDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static void MaxPoolLayerBackward(TCudaMatrix< AFloat > &activationGradientsBackward, const TCudaMatrix< AFloat > &activationGradients, const TCudaMatrix< AFloat > &indexMatrix, size_t imgHeight, size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols, size_t nLocalViews)
Perform the complete backward propagation step in a Pooling Layer.
static size_t calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride)
Calculate how many neurons "fit" in the output layer, given the input as well as the layer's hyperpar...
static void Hadamard(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B)
In-place Hadamard (element-wise) product of matrices A and B with the result being written into A.
static AFloat L2Regularization(const TCudaMatrix< AFloat > &W)
static void Im2colIndices(std::vector< int > &, const TCudaMatrix< AFloat > &, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t)
static void MeanSquaredErrorGradients(TCudaMatrix< AFloat > &dY, const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
static void Flatten(TCudaMatrix< AFloat > &A, const std::vector< TCudaMatrix< AFloat > > &B, size_t size, size_t nRows, size_t nCols)
Flattens the tensor B, such that each matrix, is stretched in one row, resulting with a matrix A.
static void AdamUpdateFirstMom(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, AFloat beta)
static AFloat CrossEntropy(const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
Sigmoid transformation is implicitly applied, thus output should hold the linear activations of the l...
static void CalculateConvBiasGradients(TCudaMatrix< AFloat > &biasGradients, std::vector< TCudaMatrix< AFloat > > &df, size_t batchSize, size_t depth, size_t nLocalViews)
Utility function for calculating the bias gradients of the convolutional layer.
static void CopyDiffArch(TCudaMatrix< Scalar_t > &B, const AMatrix_t &A)
static bool AlmostEquals(const TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, double epsilon=0.1)
Check two matrices for equality, taking floating point arithmetic errors into account.
static void SquareElementWise(TCudaMatrix< AFloat > &A)
Square each element of the matrix A and write the result into A.
static void IdentityDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static AFloat MeanSquaredError(const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
static void SumRows(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
Sum rows of (m x n) matrix A and write the results into the first m elements in B.
static void Tanh(TCudaMatrix< AFloat > &B)
static void SigmoidDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static void ConvLayerForward(std::vector< TCudaMatrix< AFloat > > &output, std::vector< TCudaMatrix< AFloat > > &derivatives, const std::vector< TCudaMatrix< AFloat > > &input, const TCudaMatrix< AFloat > &weights, const TCudaMatrix< AFloat > &biases, const DNN::CNN::TConvParams ¶ms, EActivationFunction activFunc, std::vector< TCudaMatrix< AFloat > > &inputPrime)
Forward propagation in the Convolutional layer.
static void AdamUpdate(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &M, const TCudaMatrix< AFloat > &V, AFloat alpha, AFloat eps)
static void ConstMult(TCudaMatrix< AFloat > &A, AFloat beta)
Multiply the constant beta to all the elements of matrix A and write the result into A.
static void ReciprocalElementWise(TCudaMatrix< AFloat > &A)
Reciprocal each element of the matrix A and write the result into A.
static void Identity(TCudaMatrix< AFloat > &B)
static void SoftSignDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static AFloat Sum(const TCudaMatrix< AFloat > &A)
Compute the sum of all elements in A.
static void SqrtElementWise(TCudaMatrix< AFloat > &A)
Square root each element of the matrix A and write the result into A.
static void AddL1RegularizationGradients(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &W, AFloat weightDecay)
static void Reshape(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B)
Transform the matrix B to a matrix with different dimensions A.
static void TanhDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static void SetRandomSeed(size_t seed)
static void AdamUpdateSecondMom(TCudaMatrix< AFloat > &A, const TCudaMatrix< AFloat > &B, AFloat beta)
static void Im2colFast(TCudaMatrix< AFloat > &, const TCudaMatrix< AFloat > &, const std::vector< int > &)
static AFloat L1Regularization(const TCudaMatrix< AFloat > &W)
static void Dropout(TCudaMatrix< AFloat > &A, AFloat p)
Apply dropout with activation probability p to the given matrix A and scale the result by reciprocal ...
static void AddRowWise(TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &biases)
Add the vectors biases row-wise to the matrix output.
static void TransposeMultiply(TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &input, const TCudaMatrix< AFloat > &Weights)
Matrix multiplication of two matrices A and B^T (transposed) with the result being written into C.
static void InitializeGauss(TCudaMatrix< AFloat > &A)
static void InitializeIdentity(TCudaMatrix< AFloat > &A)
static TRandom & GetRandomGenerator()
static void ScaleAdd(std::vector< TCudaMatrix< Scalar_t > > &A, const std::vector< TCudaMatrix< Scalar_t > > &B, Scalar_t beta=1.0)
Above functions extended to vectors.
static void Sigmoid(TCudaMatrix< AFloat > &B)
static void Gauss(TCudaMatrix< AFloat > &B)
static void ReluDerivative(TCudaMatrix< AFloat > &B, const TCudaMatrix< AFloat > &A)
static void CalculateConvWeightGradients(TCudaMatrix< AFloat > &weightGradients, std::vector< TCudaMatrix< AFloat > > &df, const std::vector< TCudaMatrix< AFloat > > &activations_backward, size_t batchSize, size_t inputHeight, size_t inputWidth, size_t depth, size_t height, size_t width, size_t filterDepth, size_t filterHeight, size_t filterWidth, size_t nLocalViews)
Utility function for calculating the weight gradients of the convolutional layer.
static void InitializeUniform(TCudaMatrix< AFloat > &A)
static void Deflatten(std::vector< TCudaMatrix< AFloat > > &A, const TCudaMatrix< AFloat > &B, size_t index, size_t nRows, size_t nCols)
Transforms each row of B to a matrix and stores it in the tensor B.
static void Backward(TCudaMatrix< AFloat > &activationGradientsBackward, TCudaMatrix< AFloat > &weightGradients, TCudaMatrix< AFloat > &biasGradients, TCudaMatrix< AFloat > &df, const TCudaMatrix< AFloat > &activationGradients, const TCudaMatrix< AFloat > &weights, const TCudaMatrix< AFloat > &activationBackward)
Perform the complete backward propagation step.
static void SymmetricRelu(TCudaMatrix< AFloat > &B)
static void SoftmaxCrossEntropyGradients(TCudaMatrix< AFloat > &dY, const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
static void Sigmoid(TCudaMatrix< AFloat > &YHat, const TCudaMatrix< AFloat > &)
static void AddConvBiases(TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &biases)
Add the biases in the Convolutional Layer.
static void CrossEntropyGradients(TCudaMatrix< AFloat > &dY, const TCudaMatrix< AFloat > &Y, const TCudaMatrix< AFloat > &output, const TCudaMatrix< AFloat > &weights)
This is the base class for the ROOT Random number generators.
double beta(double x, double y)
Calculates the beta function.
void Copy(void *source, void *dest)
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
EActivationFunction
Enum that represents layer activation functions.
Abstract ClassifierFactory template that handles arbitrary types.