2022-08-31 14:44:53 +08:00
|
|
|
#pragma once
|
|
|
|
#include "core/operator.h"
|
|
|
|
|
|
|
|
namespace infini {
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief The base class for AvgPool and MaxPool.
|
|
|
|
*
|
|
|
|
*/
|
2022-08-31 14:44:53 +08:00
|
|
|
class PoolingObj : public OperatorObj {
|
|
|
|
private:
|
|
|
|
int kh, kw;
|
|
|
|
int dh, dw;
|
|
|
|
int ph, pw;
|
|
|
|
int sh, sw;
|
2023-10-09 20:51:39 +08:00
|
|
|
int ceilMode;
|
2022-08-31 14:44:53 +08:00
|
|
|
int n, c, h, w;
|
|
|
|
|
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Pooling object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param optype Operator type of this pooling operator.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param output The output tensor.
|
|
|
|
* @param kh Kernel height.
|
|
|
|
* @param kw Kernel width.
|
|
|
|
* FIXME: Dilated pooling is not supported for many frameworks?
|
|
|
|
* @param dh Dilation at the height dimension.
|
|
|
|
* @param dw Dilation at the width dimension.
|
|
|
|
* FIXME: Auto padding using padding mode.
|
|
|
|
* @param ph Padding at the height dimension.
|
|
|
|
* @param pw Padding at the width dimension.
|
|
|
|
* @param sh Stride at the height dimension.
|
|
|
|
* @param sw Stride at the width dimension.
|
2023-10-09 20:51:39 +08:00
|
|
|
* @param ceilMode Whether to use ceil(1) or floor(0) to compute the output
|
|
|
|
* shape.
|
2023-02-13 22:48:20 +08:00
|
|
|
*/
|
2022-08-31 14:44:53 +08:00
|
|
|
PoolingObj(GraphObj *graph, OpType optype, Tensor input, Tensor output,
|
2023-10-09 20:51:39 +08:00
|
|
|
int kh, int kw, int dh, int dw, int ph, int pw, int sh, int sw,
|
|
|
|
int ceilMode);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(PoolingObj);
|
2022-08-31 14:44:53 +08:00
|
|
|
|
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) const override;
|
|
|
|
std::string toString() const override;
|
|
|
|
int numInputs() const override { return 1; }
|
|
|
|
int numOutputs() const override { return 1; }
|
|
|
|
|
|
|
|
int getKh() const { return kh; }
|
|
|
|
int getKw() const { return kw; }
|
|
|
|
int getDh() const { return dh; }
|
|
|
|
int getDw() const { return dw; }
|
|
|
|
int getPh() const { return ph; }
|
|
|
|
int getPw() const { return pw; }
|
|
|
|
int getSh() const { return sh; }
|
|
|
|
int getSw() const { return sw; }
|
2023-10-09 20:51:39 +08:00
|
|
|
int getCeilMode() const { return ceilMode; }
|
2022-08-31 14:44:53 +08:00
|
|
|
|
|
|
|
auto getPadStrideDilation() const { return tuple(ph, pw, sh, sw, dh, dw); }
|
|
|
|
auto getNCHWRS() const { return tuple(n, c, h, w, kh, kw); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MaxPoolObj : public PoolingObj {
|
|
|
|
public:
|
|
|
|
MaxPoolObj(GraphObj *graph, Tensor input, Tensor output, int kh, int kw,
|
2023-10-09 20:51:39 +08:00
|
|
|
int dh, int dw, int ph, int pw, int sh, int sw, int ceilMode)
|
2022-08-31 14:44:53 +08:00
|
|
|
: PoolingObj(graph, OpType::MaxPool, input, output, kh, kw, dh, dw, ph,
|
2023-10-09 20:51:39 +08:00
|
|
|
pw, sh, sw, ceilMode) {}
|
2022-08-31 14:44:53 +08:00
|
|
|
};
|
|
|
|
class AvgPoolObj : public PoolingObj {
|
|
|
|
public:
|
|
|
|
AvgPoolObj(GraphObj *graph, Tensor input, Tensor output, int kh, int kw,
|
2023-10-09 20:51:39 +08:00
|
|
|
int dh, int dw, int ph, int pw, int sh, int sw, int ceilMode)
|
2023-08-07 11:17:05 +08:00
|
|
|
: PoolingObj(graph, OpType::AveragePool, input, output, kh, kw, dh, dw,
|
2023-10-09 20:51:39 +08:00
|
|
|
ph, pw, sh, sw, ceilMode) {}
|
2022-08-31 14:44:53 +08:00
|
|
|
};
|
2022-10-15 16:29:28 +08:00
|
|
|
}; // namespace infini
|