Caffe
cudnn_pooling_layer.hpp
1 #ifndef CAFFE_CUDNN_POOLING_LAYER_HPP_
2 #define CAFFE_CUDNN_POOLING_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/pooling_layer.hpp"
11 
12 namespace caffe {
13 
14 #ifdef USE_CUDNN
15 /*
16  * @brief cuDNN implementation of PoolingLayer.
17  * Fallback to PoolingLayer for CPU mode.
18 */
19 template <typename Dtype>
20 class CuDNNPoolingLayer : public PoolingLayer<Dtype> {
21  public:
22  explicit CuDNNPoolingLayer(const LayerParameter& param)
23  : PoolingLayer<Dtype>(param), handles_setup_(false) {}
24  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
25  const vector<Blob<Dtype>*>& top);
26  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
27  const vector<Blob<Dtype>*>& top);
28  virtual ~CuDNNPoolingLayer();
29  // Currently, cuDNN does not support the extra top blob.
30  virtual inline int MinTopBlobs() const { return -1; }
31  virtual inline int ExactNumTopBlobs() const { return 1; }
32 
33  protected:
34  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
35  const vector<Blob<Dtype>*>& top);
36  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
37  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
38 
39  bool handles_setup_;
40  cudnnHandle_t handle_;
41  cudnnTensorDescriptor_t bottom_desc_, top_desc_;
42  cudnnPoolingDescriptor_t pooling_desc_;
43  cudnnPoolingMode_t mode_;
44 };
45 #endif
46 
47 } // namespace caffe
48 
49 #endif // CAFFE_CUDNN_POOLING_LAYER_HPP_
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14