reduce.h 1.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*!
 * \file tl/op/reduce.h
 * \brief Define reduce operator.
 *
 */

#ifndef TVM_TL_OP_REDUCE_H_
#define TVM_TL_OP_REDUCE_H_

10
#include "operator.h"
11
12
13
14
15
16

namespace tvm {
namespace tl {

using namespace tir;

17
18
19
20
21
22
23
enum class ReduceType {
  kSum,
  kAbsSum,
  kMax,
  kMin,
  kAbsMax,
};
24

25
26
class ReduceOpNode : public TileOperatorNode {
public:
27
28
  tir::Buffer src, dst;
  int dim;
29
  ReduceType type;
30
31
  bool clear;

32
33
34
35
36
37
38
39
40
41
  static constexpr const char *_type_key = "tl.ReduceOp";
  TVM_DECLARE_FINAL_OBJECT_INFO(ReduceOpNode, TileOperatorNode);

  Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const override;
  LayoutMap InferLayout(const LayoutInferArgs &T,
                        InferLevel level) const override;
  static const Op &Get();
  TileOperator Clone() const;

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

47
class ReduceOp : public TileOperator {
48
public:
49
50
  TVM_DEFINE_OBJECT_REF_METHODS(ReduceOp, TileOperator, ReduceOpNode);
  TVM_DLL ReduceOp(Array<PrimExpr> args, BufferMap vmap);
51
  static const Op &Get();
52
};
53

54
55
class CumSumOpNode : public TileOperatorNode {
public:
56
57
58
  tir::Buffer src, dst;
  int dim;
  bool reverse;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  static constexpr const char *_type_key = "tl.CumSumOp";
  TVM_DECLARE_FINAL_OBJECT_INFO(CumSumOpNode, TileOperatorNode);

  Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const override;
  LayoutMap InferLayout(const LayoutInferArgs &T,
                        InferLevel level) const override;
  static const Op &Get();
  TileOperator Clone() const;
};

class CumSumOp : public TileOperator {
public:
  TVM_DEFINE_OBJECT_REF_METHODS(CumSumOp, TileOperator, CumSumOpNode);
  TVM_DLL CumSumOp(Array<PrimExpr> args, BufferMap vmap);
  static const Op &Get();
74
75
};

76
77
} // namespace tl
} // namespace tvm
78

79
#endif //  TVM_TL_OP_REDUCE_H_