Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Regularization.cu
Go to the documentation of this file.
1// @(#)root/tmva/tmva/dnn:$Id$
2// Author: Simon Pfreundschuh 13/07/16
3
4/*************************************************************************
5 * Copyright (C) 2016, Simon Pfreundschuh *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////
13// Contains the definitions of the kernel calling functions for //
14// computation of regularization functionals and gradients //
15// functions for CUDA architectures. //
16//////////////////////////////////////////////////////////////////
17
20#include "Kernels.cuh"
21
22namespace TMVA {
23namespace DNN {
24
25//______________________________________________________________________________
26template<typename AFloat>
28{
29 dim3 blockDims = TDevice::BlockDims2D();
30 dim3 gridDims = TDevice::GridDims2D(A);
31 cudaStream_t s = A.GetComputeStream();
33 ::TMVA::DNN::Cuda::AbsoluteSum<<<gridDims, blockDims, 0, s>>>(
36 (int) A.GetNrows(),
37 (int) A.GetNcols());
39}
40
41//______________________________________________________________________________
42template<typename AFloat>
44 const TCudaMatrix<AFloat> & A,
46{
47 dim3 blockDims = TDevice::BlockDims2D();
48 dim3 gridDims = TDevice::GridDims2D(B);
49 cudaStream_t s = A.GetComputeStream();
50 ::TMVA::DNN::Cuda::AddL1RegularizationGradients<<<gridDims, blockDims, 0, s>>>(
54 (int) A.GetNrows(),
55 (int) A.GetNcols());
56}
57
58//______________________________________________________________________________
59template<typename AFloat>
61{
62 dim3 blockDims = TDevice::BlockDims2D();
63 dim3 gridDims = TDevice::GridDims2D(A);
64 cudaStream_t s = A.GetComputeStream();
66 ::TMVA::DNN::Cuda::SquaredSum<<<gridDims, blockDims, 0, s>>>(
69 (int) A.GetNrows(),
70 (int) A.GetNcols());
72}
73
74//______________________________________________________________________________
75template<typename AFloat>
77 const TCudaMatrix<AFloat> & A,
79{
80 dim3 blockDims = TDevice::BlockDims2D();
81 dim3 gridDims = TDevice::GridDims2D(B);
82 cudaStream_t s = A.GetComputeStream();
83 ::TMVA::DNN::Cuda::AddL2RegularizationGradients<<<gridDims, blockDims, 0, s>>>(
87 (int) A.GetNrows(),
88 (int) A.GetNcols());
89}
90
91} // namspace DNN
92} // namspace TMVA
TCudaMatrix Class.
Definition CudaMatrix.h:103
size_t GetNcols() const
Definition CudaMatrix.h:160
static AFloat GetDeviceReturn()
Transfer the value in the device return buffer to the host.
Definition CudaMatrix.h:301
cudaStream_t GetComputeStream() const
Definition CudaMatrix.h:268
static AFloat * GetDeviceReturnPointer()
Return device pointer to the device return buffer.
Definition CudaMatrix.h:151
static void ResetDeviceReturn(AFloat value=0.0)
Set the return buffer on the device to the specified value.
Definition CudaMatrix.h:293
const AFloat * GetDataPointer() const
Definition CudaMatrix.h:163
size_t GetNrows() const
Definition CudaMatrix.h:159
static Scalar_t L1Regularization(const Matrix_t &W)
static void AddL2RegularizationGradients(Matrix_t &A, const Matrix_t &W, Scalar_t weightDecay)
static Scalar_t L2Regularization(const Matrix_t &W)
static void AddL1RegularizationGradients(Matrix_t &A, const Matrix_t &W, Scalar_t weightDecay)
static dim3 BlockDims2D()
Definition Device.h:55
static dim3 GridDims2D(int nrows, int ncols)
Definition Device.h:74
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
create variable transformations