CudnnPoolLayer.h 2.0 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include "PoolLayer.h"

namespace paddle {

21 22 23 24 25 26
/**
 * @brief CudnnPoolLayer is subclass of PoolLayer, which is implemented by
 * cudnn api and only supports GPU.
 *
 * The config file api is img_pool_layer.
 */
Z
zhangjinchao01 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

class CudnnPoolLayer : public PoolLayer {
protected:
  int windowHeight, windowWidth;
  int heightPadding, widthPadding, strideHeight, strideWidth;
  int imageH_, imageW_, outputH_, outputW_;
  /// mode_ is poolint type, inlcuding "cudnn-max-pool", "cudnn-avg-pool"
  /// "cudnn-avg-excl-pad-pool".
  hl_pooling_mode_t mode_;
  /// cudnn tensor descriptor for input.
  hl_tensor_descriptor inputDesc_;
  /// cudnn tensor descriptor for output.
  hl_tensor_descriptor outputDesc_;
  /// A description of a pooling operation.
  hl_pooling_descriptor poolingDesc_;

public:
  static bool typeCheck(const std::string& poolType,
                        hl_pooling_mode_t* mode = nullptr);
  explicit CudnnPoolLayer(const LayerConfig& config);
  ~CudnnPoolLayer();
Y
Yu Yang 已提交
48 49
  bool init(const LayerMap& layerMap,
            const ParameterMap& parameterMap) override;
Z
zhangjinchao01 已提交
50 51 52 53 54 55 56

  /**
   * Reshape input and output tensor descriptor.
   * The batch size maybe change during training in last batch of each pass.
   * So reshaping is needed.
   */
  void reshape(int batchSize);
Y
Yu Yang 已提交
57 58
  virtual void forward(PassType passType) override;
  virtual void backward(const UpdateCallback& callback = nullptr) override;
Z
zhangjinchao01 已提交
59 60 61
};

}  // namespace paddle