operator.h 2.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*!
 * \file tl/op/op.h
 * \brief Tile library operations.
 *
 */

#ifndef TVM_TL_OP_OP_H_
#define TVM_TL_OP_OP_H_

#include <tvm/arith/analyzer.h>
#include <tvm/ir/op.h>
#include <tvm/target/target.h>
#include <tvm/tir/buffer.h>
14
#include <tvm/tir/op.h>
15
#include <tvm/tir/op_attr_types.h>
16
#include <tvm/tir/stmt.h>
17
18
19
20
21
22
23
24
25
26
27
28

#include "../layout/layout.h"

namespace tvm {
namespace tl {

using namespace tir;

using AddWorkspaceCallback = std::function<PrimExpr(int, DataType)>;
using LayoutMap = Map<Buffer, Layout>;
using BufferMap = Map<Var, Buffer>;

29
enum class InferLevel : uint8_t {
30
31
32
33
34
35
36
  kFree = 0,
  kCommon = 1,
  kStrict = 2,
};

struct LowerArgs {
  Target target;
37
  Range thread_bounds;
38
39
40
41
  Var thread_var;
  AddWorkspaceCallback AddWorkspace;
  LayoutMap layout_map;
  Map<Buffer, Buffer> buffer_remap;
42
43
44
  // Map from LetStmt variable to its bound expression, for resolving
  // fragment buffer accesses through let bindings
  Map<Var, PrimExpr> let_var_to_expr;
45
46
47
48
};

struct LayoutInferArgs {
  Target target;
49
  Range thread_bounds;
50
  LayoutMap layout_map;
51
52
  arith::Analyzer *analyzer;
  bool buffer_oob = false;
53
  Map<Buffer, Buffer> buffer_remap;
54
55
56
  // Map from LetStmt variable to its bound expression, for resolving
  // fragment buffer accesses through let bindings
  Map<Var, PrimExpr> let_var_to_expr;
57
58
};

59
class TileOperator;
60

61
62
class TileOperatorNode : public Object {
public:
63
  virtual Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const = 0;
64

65
  virtual LayoutMap InferLayout(const LayoutInferArgs &T,
66
                                InferLevel level) const = 0;
67

68
69
  virtual TileOperator Clone() const = 0;

70
  TVM_FFI_DECLARE_OBJECT_INFO("tl.TileOperator", TileOperatorNode, Object);
71
};
72

73
class TileOperator : public ObjectRef {
74
public:
75
76
  TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(TileOperator, ObjectRef,
                                             TileOperatorNode);
77
78
};

79
Var GetVarFromAccessPtr(const PrimExpr &expr);
80

81
82
TileOperator ParseOperator(Call call);
TileOperator ParseOperator(Stmt stmt);
83

84
using OpBuilderFunc = ffi::TypedFunction<TileOperator(Array<PrimExpr>)>;
85

86
#define TIR_REGISTER_TL_TILE_OP(Entry, OpName)                                 \
87
  const Op &Entry::Get() {                                                     \
88
    static const Op &op = Op::Get("tl.tileop." #OpName);                       \
89
90
    return op;                                                                 \
  }                                                                            \
91
  TVM_REGISTER_OP("tl.tileop." #OpName)                                        \
92
      .set_attr<TScriptPrinterName>("TScriptPrinterName", #OpName)             \
93
94
      .set_attr<OpBuilderFunc>(                                                \
          "TLOpBuilder", [](Array<PrimExpr> args) { return Entry(args); })
95

96
97
} // namespace tl
} // namespace tvm
98

99
#endif // TVM_TL_OP_OP_H_