2using System.Collections.Generic;
28 bool m_bNeedPermute =
false;
44 m_blobPermuteOrder =
new Blob<T>(cuda, log);
46 m_blobNewSteps =
new Blob<T>(cuda, log);
48 m_blobOldSteps =
new Blob<T>(cuda, log);
55 if (m_blobPermuteOrder !=
null)
57 m_blobPermuteOrder.Dispose();
58 m_blobPermuteOrder =
null;
61 if (m_blobNewSteps !=
null)
64 m_blobNewSteps =
null;
67 if (m_blobOldSteps !=
null)
70 m_blobOldSteps =
null;
82 col.
Add(m_blobPermuteOrder);
83 col.
Add(m_blobNewSteps);
84 col.
Add(m_blobOldSteps);
113 m_nNumAxes = colBottom[0].num_axes;
116 List<int> rgOrders =
new List<int>();
117 foreach (
int nOrder
in permute_param.order)
119 m_log.
CHECK_LT(nOrder, m_nNumAxes,
"The order should be less than the input dimension '" + m_nNumAxes.ToString() +
"'!");
121 if (rgOrders.Contains(nOrder))
122 m_log.
FAIL(
"The order '" + nOrder.ToString() +
"' is a duplicate order!");
124 rgOrders.Add(nOrder);
128 for (
int i = 0; i < m_nNumAxes; i++)
130 if (!rgOrders.Contains(i))
134 m_log.
CHECK_EQ(rgOrders.Count, m_nNumAxes,
"The order count should be the same as the input dimension of '" + m_nNumAxes.ToString() +
"'!");
137 m_bNeedPermute =
false;
139 for (
int i = 0; i < m_nNumAxes; i++)
141 if (rgOrders[i] != i)
145 m_bNeedPermute =
true;
152 m_blobPermuteOrder.Reshape(m_nNumAxes, 1, 1, 1);
156 T[] rgOrder1 =
new T[m_nNumAxes];
157 for (
int i = 0; i < m_nNumAxes; i++)
159 int nOrder = rgOrders[i];
160 rgOrder1[i] =
Utility.ConvertVal<T>(nOrder);
161 int nShape = colBottom[0].shape(nOrder);
162 rgTopShape[i] = nShape;
165 m_blobPermuteOrder.mutable_cpu_data = rgOrder1;
166 colTop[0].Reshape(rgTopShape);
176 T[] rgOldSteps =
new T[m_nNumAxes];
177 T[] rgNewSteps =
new T[m_nNumAxes];
178 T[] rgOrder1 = m_blobPermuteOrder.mutable_cpu_data;
179 List<int> rgOrder =
new List<int>();
181 for (
int i = 0; i < rgOrder1.Length; i++)
185 if (i == m_nNumAxes - 1)
188 rgOldSteps[i] =
Utility.ConvertVal<T>(colBottom[0].count(i + 1));
191 rgOrder.Add((
int)
Utility.ConvertVal<T>(rgOrder1[i]));
198 for (
int i = 0; i < m_nNumAxes; i++)
200 if (i == m_nNumAxes - 1)
203 rgNewSteps[i] =
Utility.ConvertVal<T>(colTop[0].count(i + 1));
220 long hBottomData = colBottom[0].mutable_gpu_data;
221 long hTopData = colTop[0].mutable_gpu_data;
222 int nCount = colTop[0].count();
223 long hPermuteOrder = m_blobPermuteOrder.gpu_data;
224 long hNewSteps = m_blobNewSteps.
gpu_data;
225 long hOldSteps = m_blobOldSteps.
gpu_data;
226 bool bForward =
true;
228 m_cuda.permute(nCount, hBottomData, bForward, hPermuteOrder, hOldSteps, hNewSteps, m_nNumAxes, hTopData);
232 colTop[0].ShareData(colBottom[0]);
248 long hTopDiff = colTop[0].mutable_gpu_diff;
249 long hBottomDiff = colBottom[0].mutable_gpu_diff;
250 int nCount = colTop[0].count();
251 long hPermuteOrder = m_blobPermuteOrder.gpu_data;
252 long hNewSteps = m_blobNewSteps.
gpu_data;
253 long hOldSteps = m_blobOldSteps.
gpu_data;
254 bool bForward =
false;
256 m_cuda.permute(nCount, hBottomDiff, bForward, hPermuteOrder, hOldSteps, hNewSteps, m_nNumAxes, hTopDiff);
260 colBottom[0].ShareDiff(colTop[0]);
The Log class provides general output in text form.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void CHECK_LT(double df1, double df2, string str)
Test whether one number is less than another.
The Utility class provides general utility funtions.
static List< int > Create(int nCount, int nStart, int nInc)
Create a new List and fill it with values starting with start and incrementing by inc.
The BlobCollection contains a list of Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
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 Blob is the main holder of data that moves through the Layers of the Net.
T[] mutable_cpu_data
Get data from the GPU and bring it over to the host, or Set data from the Host and send it over to th...
void ReshapeLike(Blob< T > b, bool? bUseHalfSize=null)
Reshape this Blob to have the same shape as another Blob.
string Name
Get/set the name of the Blob.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
long gpu_data
Returns the data GPU handle used by the CudaDnn connection.
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.
T m_tOne
Specifies a generic type equal to 1.0.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
LayerParameter layer_param
Returns the LayerParameter for this Layer.
The PermuteLayer performs permutation on the input blob by changing the memory order of the data whic...
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: data
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: permute
PermuteLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The PermuteLayer 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 void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t the inputs.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Computes the forward calculation.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
PermuteParameter permute_param
Returns the parameter set when initialized with LayerType.PERMUTE
LayerType
Specifies the layer type.
Specifies the parameters for the PermuteLayer.
static List< int > Reshape(List< int > rgOrder, List< int > rgShape, int nNumAxes)
Calculates the top shape by running the Reshape calculation.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.fillers namespace contains all fillers including the Filler class.
The MyCaffe.layers.ssd namespace contains all Single-Shot MultiBox (SSD) related layers.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
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-...