Caffe
All Classes Namespaces Functions Variables Typedefs
cudnn_deconv_layer.hpp
1 #ifndef CAFFE_CUDNN_DECONV_LAYER_HPP_
2 #define CAFFE_CUDNN_DECONV_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/layer.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 #include "caffe/layers/deconv_layer.hpp"
11 
12 namespace caffe {
13 
14 #ifdef USE_CUDNN
15 /*
16  * @brief cuDNN implementation of DeConvolutionLayer.
17  * Fallback to DeConvolutionLayer for CPU mode.
18  *
19  * cuDNN accelerates deconvolution through forward kernels for filtering and
20  * bias plus backward kernels for the gradient w.r.t. the filters, biases, and
21  * inputs. Caffe + cuDNN further speeds up the computation through forward
22  * parallelism across groups and backward parallelism across gradients.
23 */
24 template <typename Dtype>
25 class CuDNNDeconvolutionLayer : public DeconvolutionLayer<Dtype> {
26  public:
27  explicit CuDNNDeconvolutionLayer(const LayerParameter& param)
28  : DeconvolutionLayer<Dtype>(param), handles_setup_(false) {}
29  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
30  const vector<Blob<Dtype>*>& top);
31  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
32  const vector<Blob<Dtype>*>& top);
33  virtual ~CuDNNDeconvolutionLayer();
34 
35  protected:
36  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
37  const vector<Blob<Dtype>*>& top);
38  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
39  const vector<bool>& propagate_down,
40  const vector<Blob<Dtype>*>& bottom);
41 
42  bool handles_setup_;
43  cudnnHandle_t* handle_;
44  cudaStream_t* stream_;
45 
46  // algorithms for forward and backwards convolutions
47  cudnnConvolutionFwdAlgo_t *fwd_algo_;
48  cudnnConvolutionBwdFilterAlgo_t *bwd_filter_algo_;
49  cudnnConvolutionBwdDataAlgo_t *bwd_data_algo_;
50 
51  vector<cudnnTensorDescriptor_t> bottom_descs_, top_descs_;
52  cudnnTensorDescriptor_t bias_desc_;
53  cudnnFilterDescriptor_t filter_desc_;
54  vector<cudnnConvolutionDescriptor_t> conv_descs_;
55  int bottom_offset_, top_offset_, bias_offset_;
56 
57  size_t *workspace_fwd_sizes_;
58  size_t *workspace_bwd_data_sizes_;
59  size_t *workspace_bwd_filter_sizes_;
60  size_t workspaceSizeInBytes; // size of underlying storage
61  void *workspaceData; // underlying storage
62  void **workspace; // aliases into workspaceData
63 };
64 #endif
65 
66 } // namespace caffe
67 
68 #endif // CAFFE_CUDNN_DECONV_LAYER_HPP_
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14