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

#ifndef TVM_TL_OP_GEMM_PY_H_
#define TVM_TL_OP_GEMM_PY_H_

#include "gemm.h"
#include "operator.h"

namespace tvm {

namespace tl {

using namespace tir;

class GemmPyNode : public TileOperatorNode {
public:
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  bool checkWgmma() const;
  bool allowTcgen5Mma(Target target) const;
  bool allowWgmma(int block_size, Target target) const;
  tir::Buffer a_, b_, c_;
  // BufferRegion for A, B and C
  BufferRegion aRegion_, bRegion_, cRegion_;
  bool transA_, transB_;
  int m_, n_, k_;
  int strideA_, strideB_;
  int offsetA_, offsetB_;
  PrimExpr clearAccum_ = const_false();
  PrimExpr mbarPtr_;
  std::optional<tir::Buffer> mbar_; // mbar is optional, only used for TCGEN5MMA
  Array<PrimExpr> cCoords_;
35
36
  // k_pack please ref to bitblas/tl/mfma_macro_generator.py::k_pack
  // only will be enabled under cdna mfma instructions
37
38
39
  int kPack_ = 1;
  int wgWait_ = 0;
  mutable GemmWarpPolicy policy_;
40

41
  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tl.GemmPy", GemmPyNode, TileOperatorNode);
42
43
44
45

  static void RegisterReflection() {
    namespace refl = tvm::ffi::reflection;
    refl::ObjectDef<GemmPyNode>()
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
        .def_ro("a", &GemmPyNode::a_)
        .def_ro("b", &GemmPyNode::b_)
        .def_ro("c", &GemmPyNode::c_)
        .def_ro("aRegion", &GemmPyNode::aRegion_)
        .def_ro("bRegion", &GemmPyNode::bRegion_)
        .def_ro("cRegion", &GemmPyNode::cRegion_)
        .def_ro("transA", &GemmPyNode::transA_)
        .def_ro("transB", &GemmPyNode::transB_)
        .def_ro("m", &GemmPyNode::m_)
        .def_ro("n", &GemmPyNode::n_)
        .def_ro("k", &GemmPyNode::k_)
        .def_ro("strideA", &GemmPyNode::strideA_)
        .def_ro("strideB", &GemmPyNode::strideB_)
        .def_ro("offsetA", &GemmPyNode::offsetA_)
        .def_ro("offsetB", &GemmPyNode::offsetB_)
        .def_ro("clearAccum", &GemmPyNode::clearAccum_)
        .def_ro("mbarPtr", &GemmPyNode::mbarPtr_)
        .def_ro("cCoords", &GemmPyNode::cCoords_)
        .def_ro("kPack", &GemmPyNode::kPack_)
        .def_ro("wgWait", &GemmPyNode::wgWait_)
        .def_ro("policy", &GemmPyNode::policy_);
67
68
69
70
71
72
73
74
75
  }

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

  TileOperator Clone() const;

  // Target GEMM instruction
76
  GemmInst getGemmInst(int block_size, Target target) const;
77

78
private:
79
80
81
82
83
  mutable bool completed_ = false;
};

class GemmPy : public TileOperator {
public:
84
  TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GemmPy, TileOperator, GemmPyNode);
85
86
87
88
89
90
91
  TVM_DLL GemmPy(Array<PrimExpr> args, BufferMap vmap);
  static const Op &Get();
};

} // namespace tl
} // namespace tvm

92
#endif //  TVM_TL_OP_GEMM_PY_H_