reduce.h 1.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*!
 * \file tl/op/reduce.h
 * \brief Define reduce operator.
 *
 */

#ifndef TVM_TL_OP_REDUCE_H_
#define TVM_TL_OP_REDUCE_H_

#include "op.h"

namespace tvm {
namespace tl {

using namespace tir;

class ReduceOp : public Operator {
18
public:
19
  ReduceOp(Array<PrimExpr> args, BufferMap vmap);
20
21
22
  Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const final;
  LayoutMap InferLayout(const LayoutInferArgs &T, InferLevel level) final;
  static const Op &Get();
23

24
25
26
27
  std::unique_ptr<Operator> Clone() const final {
    return std::make_unique<ReduceOp>(*this);
  }

28
private:
29
30
31
32
33
34
35
  tir::Buffer src, dst;
  int dim;
  enum class ReduceType {
    kSum,
    kAbsSum,
    kMax,
    kMin,
36
    kAbsMax,
37
38
39
40
  } type;
  bool clear;

  PrimExpr MakeInitValue() const;
41
  PrimExpr MakeReduce(const PrimExpr &a, const PrimExpr &b) const;
42
43
44
  std::string MakeCodegenReducer() const;
};

45
46
47
48
49
50
51
class CumSumOp : public Operator {
public:
  CumSumOp(Array<PrimExpr> args, BufferMap vmap);
  Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const final;
  LayoutMap InferLayout(const LayoutInferArgs &T, InferLevel level) final;
  static const Op &Get();

52
53
54
55
  std::unique_ptr<Operator> Clone() const final {
    return std::make_unique<CumSumOp>(*this);
  }

56
57
58
59
60
61
private:
  tir::Buffer src, dst;
  int dim;
  bool reverse;
};

62
63
} // namespace tl
} // namespace tvm
64

65
#endif //  TVM_TL_OP_REDUCE_H_