operator.h 2.62 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_attr_types.h>
15
#include <tvm/tir/stmt.h>
16
17
18
19
20
21
22
23
24
25
26
27

#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>;

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

struct LowerArgs {
  Target target;
36
  Range thread_bounds;
37
38
39
40
  Var thread_var;
  AddWorkspaceCallback AddWorkspace;
  LayoutMap layout_map;
  Map<Buffer, Buffer> buffer_remap;
41
  Array<Var> buffer_var_gemm;
42
43
44
45
};

struct LayoutInferArgs {
  Target target;
46
  Range thread_bounds;
47
48
49
50
  LayoutMap layout_map;
  Map<Buffer, Buffer> buffer_remap;
};

51
52
class TileOperatorNode;
class TileOperator;
53

54
55
class TileOperatorNode : public Object {
public:
56
  virtual Stmt Lower(const LowerArgs &T, arith::Analyzer *analyzer) const = 0;
57

58
  virtual LayoutMap InferLayout(const LayoutInferArgs &T,
59
                                InferLevel level) const = 0;
60

61
62
  virtual TileOperator Clone() const = 0;

63
  static constexpr const char *_type_key = "tl.TileOperator";
64
65
66

  TVM_DECLARE_BASE_OBJECT_INFO(TileOperatorNode, Object);
};
67

68
class TileOperator : public ObjectRef {
69
70
public:
  TVM_DEFINE_OBJECT_REF_METHODS(TileOperator, ObjectRef, TileOperatorNode);
71
72
};

73
Var GetVarFromAccessPtr(const PrimExpr &expr);
74

75
76
77
TileOperator ParseOperator(Call call, BufferMap vmap);
TileOperator ParseOperator(Stmt stmt, BufferMap vmap);

78
79
using OpBuilderFunc =
    ffi::TypedFunction<TileOperator(Array<PrimExpr>, BufferMap)>;
80
81
82
83
84
85
86
87
88

#define TIR_REGISTER_TL_OP(Entry, OpName)                                      \
  const Op &Entry::Get() {                                                     \
    static const Op &op = Op::Get("tl." #OpName);                              \
    return op;                                                                 \
  }                                                                            \
  TVM_REGISTER_OP("tl." #OpName)                                               \
      .set_attr<TScriptPrinterName>("TScriptPrinterName", #OpName)             \
      .set_attr<OpBuilderFunc>("TLOpBuilder",                                  \
89
90
                               [](Array<PrimExpr> args, BufferMap vmap) {      \
                                 return Entry(args, vmap);                     \
91
92
                               })

93
94
} // namespace tl
} // namespace tvm
95

96
#endif // TVM_TL_OP_OP_H_