2using System.Collections.Generic;
22 int m_nOrderMajorAxis = 0;
24 int m_nSrcStartIdx1 = 0;
25 int m_nDstStartIdx1 = 0;
27 int m_nSrcStartIdx2 = 0;
28 int m_nDstStartIdx2 = 0;
30 int m_nSrcSpatialDim1 = 1;
31 int m_nSrcSpatialDim2 = 1;
32 int m_nSrcSpatialDimStartIdx1 = 0;
33 int m_nDstSpatialDimStartIdx1 = 0;
34 int m_nSrcSpatialDimStartIdx2 = 0;
35 int m_nDstSpatialDimStartIdx2 = 0;
36 int m_nSpatialDimCopyCount = -1;
37 int m_nDstSpatialDim = 1;
91 m_nSrcSpatialDim1 =
Utility.
GetSpatialDim(colBottom[0].shape(), Math.Max(m_nCopyAxis, m_nOrderMajorAxis) + 1);
92 m_nSrcSpatialDim2 =
Utility.
GetSpatialDim(colBottom[1].shape(), Math.Max(m_nCopyAxis, m_nOrderMajorAxis) + 1);
94 if (m_nDstSpatialDim <= 0)
103 m_log.
CHECK_GT(m_nCopyCount, 0,
"The copy_count must be > 0!");
107 m_log.
CHECK_GE(m_nSrcStartIdx1, 0,
"The start_idx1 must be >= 0!");
108 m_log.
CHECK_GE(m_nSrcStartIdx2, 0,
"The start_idx1 must be >= 0!");
109 m_log.
CHECK_GE(m_nDstStartIdx1, 0,
"The start_idx1 must be >= 0!");
110 m_log.
CHECK_GE(m_nDstStartIdx2, 0,
"The start_idx1 must be >= 0!");
112 m_log.
CHECK_GE(m_nCopyAxis, 0,
"The copy axis must be >= 0!");
113 m_log.
CHECK_LE(m_nCopyAxis, 1,
"The copy axis must be <= 1!");
114 m_log.
CHECK_EQ(m_nOrderMajorAxis, 1,
"Currently, only order_major_axis=1 is supported.");
139 long hBtmData0 = colBottom[0].gpu_data;
140 long hBtmData1 = colBottom[1].gpu_data;
141 long hTopData = colTop[0].mutable_gpu_data;
143 int nDstStep = colTop[0].shape()[m_nCopyAxis];
144 int nSrcStep1 = colBottom[0].shape()[m_nCopyAxis];
145 m_cuda.copy_sequence(colBottom[0].count(), hBtmData0, nSrcStep1, m_nSrcStartIdx1, m_nCopyCount, m_nCopyDim1, hTopData, nDstStep, m_nDstStartIdx1, m_nSrcSpatialDim1, m_nDstSpatialDim, m_nSrcSpatialDimStartIdx1, m_nDstSpatialDimStartIdx1, m_nSpatialDimCopyCount);
147 int nSrcStep2 = colBottom[1].shape()[m_nCopyAxis];
148 m_cuda.copy_sequence(colBottom[1].count(), hBtmData1, nSrcStep2, m_nSrcStartIdx2, m_nCopyCount, m_nCopyDim2, hTopData, nDstStep, m_nDstStartIdx2, m_nSrcSpatialDim2, m_nDstSpatialDim, m_nSrcSpatialDimStartIdx2, m_nDstSpatialDimStartIdx2, m_nSpatialDimCopyCount);
163 long hBtmDiff0 = colBottom[0].mutable_gpu_diff;
164 long hBtmDiff1 = colBottom[1].mutable_gpu_diff;
165 long hTopData = colTop[0].gpu_diff;
167 int nSrcStep = colTop[0].shape()[m_nCopyAxis];
168 int nDstStep1 = colBottom[0].shape()[m_nCopyAxis];
169 m_cuda.copy_sequence(colTop[0].count(), hTopData, nSrcStep, m_nDstStartIdx1, m_nCopyCount, m_nCopyDim1, hBtmDiff0, nDstStep1, m_nSrcStartIdx1, m_nDstSpatialDim, m_nSrcSpatialDim1, m_nDstSpatialDimStartIdx1, m_nSrcSpatialDimStartIdx1, m_nSpatialDimCopyCount);
171 int nDstStep2 = colBottom[1].shape()[m_nCopyAxis];
172 m_cuda.copy_sequence(colTop[0].count(), hTopData, nSrcStep, m_nDstStartIdx2, m_nCopyCount, m_nCopyDim2, hBtmDiff1, nDstStep2, m_nSrcStartIdx2, m_nDstSpatialDim, m_nSrcSpatialDim2, m_nDstSpatialDimStartIdx2, m_nSrcSpatialDimStartIdx2, m_nSpatialDimCopyCount);
The Log class provides general output in text form.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
void CHECK_LE(double df1, double df2, string str)
Test whether one number is less than or equal to another.
void CHECK_GE(double df1, double df2, string str)
Test whether one number is greater than or equal to another.
The Utility class provides general utility funtions.
static int CanonicalAxisIndex(int nIdx, int nNumAxes)
Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e...
static int GetSpatialDim(List< int > rg, int nStartIdx=0)
Calculate the spatial dimension of an array starting at a given axis.
The BlobCollection contains a list of Blobs.
void SetDiff(double df)
Set all blob diff to the value specified.
int Count
Returns the number of items in the collection.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
An interface for the units of computation which can be composed into a Net.
Log m_log
Specifies the Log for output.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
The MergeLayer merges two bottom blobs with a specified copy pattern and outputs a single blob result...
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input1 and input2
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t the inputs.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Computes the forward calculation.
MergeLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The MergeLayer constructor.
override void dispose()
Releases all GPU and host resources used by the Layer.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: merge
Specifies the base parameter for all layers.
MergeParameter merge_param
Returns the parameter set when initialized with LayerType.MERGE
LayerType
Specifies the layer type.
Specifies the parameters for the MergeLayer.
static List< int > Reshape(Log log, MergeParameter p, List< int > rgShape1, List< int > rgShape2)
Calculate the new shape based on the merge parameter settings and the specified input shapes.
int dst_spatialdim_start_idx1
Specifies the dst1 spatial dim start index (only used when > 0).
int dst_start_idx2
Specifies the dst start index where copying begins for the second copy to dst blob in top(0).
int order_major_axis
Specifies axis providing the major ordering (e.g. axis=1 uses axis 1 as the major ordering with axis ...
int spatialdim_copy_count
Specifies the spatial dim copy count, used when less than the entire spatial dim is to be copied.
int copy_dim1
Specifies the dimension (sans the spatial dimension) to be copied (the full copy size = copy_dim * sp...
int src_start_idx2
Specifies the src start index where copying begins in the second input blob in bottom(1).
int src_start_idx1
Specifies the src start index where copying begins in the first blob in bottom(0).
int copy_dim2
Specifies the dimension (sans the spatial dimension) to be copied (the full copy size = copy_dim * sp...
int copy_axis
Specifies axis along which the indexing is applied when copying.
int dst_start_idx1
Specifies the dst start index where copying begins in the destination blob in top(0).
int copy_count
Specifies the number of skip copies along the copy_axis to copy (e.g. this is the number of skips to ...
int dst_spatialdim
Specifies the dst spatial dim which if not copied into is set to zero.
int src_spatialdim_start_idx1
Specifies the src1 spatial dim start index (only used when > 0).
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.layers.beta namespace contains all beta stage layers.
The MyCaffe.param.beta parameters are used by the MyCaffe.layer.beta layers.
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...