CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
convolution_ops.hpp
1 //*LB*
2 // Copyright (c) 2010, University of Bonn, Institute for Computer Science VI
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the University of Bonn
14 // nor the names of its contributors may be used to endorse or promote
15 // products derived from this software without specific prior written
16 // permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //*LE*
29 
30 
31 
32 
33 
34 #ifndef __CONVOLUTION_OPS_HPP__
35 #define __CONVOLUTION_OPS_HPP__
36 
37 #include <cuv/basics/tensor.hpp>
38 namespace cuv{
39 
40 /*
41  * Wrappers for Alex' CUDA convolution functions
42  */
43 
50 namespace alex_conv{
51 
61 template<class V,class M, class T>
62  void reorder_for_conv(tensor<V,M,T>& dst, const tensor<V,M,T>& src);
63 
68 template<class V,class M, class T>
69  void reorder_from_conv(tensor<V,M,T>& dst, const tensor<V,M,T>& src);
70 
79 template<class V, class M, class T>
80  void
81  convolve2d(tensor<V,M,T>& dst, const tensor<V,M,T>& img, const tensor<V,M,T>& filter, int paddingStart=0, unsigned int moduleStride=0, unsigned int nGroups=0, float factNew=1.f,float factOld=0.f);
82 
90 template<class V, class M, class T>
91  void
92  d_conv2d_dimg(tensor<V,M,T>& dst, const tensor<V,M,T>& delta, const tensor<V,M,T>& filter,
93  int paddingStart=0, unsigned int moduleStride=0, unsigned int nGroups=0, float factNew=1.f, float factOld=0.f);
94 
103 template<class V, class M, class T>
104  void
105  d_conv2d_dfilt(tensor<V,M,T>& dst, const tensor<V,M,T>& delta, const tensor<V,M,T>& input,
106  int paddingStart=0,
107  unsigned int moduleStride=0, unsigned int nGroups=0, unsigned int partialSum=1, float factNew=1.f,float factOld=0.f);
108 
112 enum pool_type {
115 };
116 
123 template<class V, class M, class T>
124 void local_pool(tensor<V,M,T>& dst, const tensor<V,M,T>& images,
125  int subsX, int startX, int strideX, int outputsX, pool_type pooler);
126 
130 template<class V, class M, class T>
131 void local_max_pool_grad(tensor<V,M,T>& target, const tensor<V,M,T>& images, const tensor<V,M,T>& maxGrads,
132  const tensor<V,M,T>& maxActs, int subsX, int startX, int strideX, float factNew=1.f, float factOld=0.f);
133 
137 template<class V, class M, class T>
138 void local_avg_pool_grad(tensor<V,M,T>& target, const tensor<V,M,T>& avgGrads,
139  int subsX, int startX, int strideX);
140 
154 template<class V, class M, class T>
155 void response_normalization(tensor<V,M,T>& target, tensor<V,M,T>& denoms, const tensor<V,M,T>& images, int patchSize, float addScale, float powScale);
156 
168 template<class V, class M, class T>
169 void response_normalization_grad(tensor<V,M,T>& input_gradients, tensor<V,M,T>& original_outputs, const tensor<V,M,T>& original_inputs,
170  const tensor<V,M,T>& delta, const tensor<V,M,T>& denoms, int patchSize, float addScale, float powScale, float factNew=1.f, float factOld=0.f);
171 
186 template<class V, class M, class T>
187 void contrast_normalization(tensor<V,M,T>& target, tensor<V,M,T>& denoms, const tensor<V,M,T>& meanDiffs, const tensor<V,M,T>& images, int patchSize, float addScale, float powScale);
188 
201 template<class V, class M, class T>
202 void contrast_normalization_grad(tensor<V,M,T>& input_gradients, tensor<V,M,T>& original_outputs, const tensor<V,M,T>& meanDiffs,
203  const tensor<V,M,T>& delta, const tensor<V,M,T>& denoms, int patchSize, float addScale, float powScale, float factNew=1.f, float factOld=0.f);
204 
212 template<class V, class M, class T>
213 void response_norm_cross_map(tensor<V,M,T>& target, tensor<V,M,T>& denoms, const tensor<V,M,T>& images, int sizeF, float addScale, float powScale, bool blocked);
214 
218 template<class V, class M, class T>
219 void response_norm_cross_map_grad(tensor<V,M,T>& input_gradients, tensor<V,M,T>& original_outputs, const tensor<V,M,T>& original_inputs,
220  const tensor<V,M,T>& delta, const tensor<V,M,T>& denoms, int sizeF, float addScale, float powScale, bool blocked, float factNew=1.f, float factOld=0.f);
221 
232 template<class V, class M, class T>
233 void gaussian_blur(tensor<V,M,T>& target, const tensor<V,M,T>& images, const tensor<V,M,T>& filter, bool horiz, float factNew=1.f, float factOld=0.f);
234 
245 template<class V, class M, class T>
246 void bed_of_nails(tensor<V,M,T>& target, const tensor<V,M,T>& images, int startX, int strideX, float factNew=1.f, float factOld=0.f);
247 
258 template<class V, class M, class T>
259 void bed_of_nails_grad(tensor<V,M,T>& target, const tensor<V,M,T>& delta, int startX, int strideX, float factNew=1.f, float factOld=0.f);
260 
264 template<class V, class M, class T>
265 void crop(tensor<V,M,T>& cropped, const tensor<V,M,T>& images, int startY, int startX);
266 
270 template<class V, class M, class T>
271 void resize_bilinear(tensor<V,M,T>& dest, const tensor<V,M,T>& images, float scale);
272 
283 template<class V, class M, class T>
284 void pairwise_norm(tensor<V,M,T>& dst, const tensor<V,M,T>& src, unsigned int dim);
285 
303 template<class V, class M, class T>
304 void pairwise_norm_grad(tensor<V,M,T>& dst, const tensor<V,M,T>& X, const tensor<V,M,T>& D, unsigned int dim);
305 } //end group convolution_ops
307 }
308 #endif /* __CONVOLUTION_OPS_HPP__ */