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

#ifndef TVM_TL_OP_GEMM_H_
#define TVM_TL_OP_GEMM_H_

#include "op.h"

namespace tvm {
namespace tl {

using namespace tir;

class Gemm : public Operator {
18
public:
19
  Gemm(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
28
  enum class GemmWarpPolicy {
    kSquare = 0,
    kFullRow = 1,
    kFullCol = 2,
  } policy;

29
30
31
32
  std::unique_ptr<Operator> Clone() const final {
    return std::make_unique<Gemm>(*this);
  }

33
private:
34
35
36
37
38
39
  // Target GEMM instruction
  enum class GemmInst { kMMA, kWGMMA, kUTCMMA, kMFMA };
  GemmInst GetGemmInst(int block_size, Target target) const;

  std::pair<int, int> ComputeWarpPartition(int num_warps, GemmInst gemm_inst,
                                           Target target) const;
40

41
  bool CheckWGMMA() const;
42
43
  Array<PrimExpr> call_args;
  tir::Buffer A, B, C;
44
45
  // pointer to the A, B, C
  PrimExpr Aptr, Bptr, Cptr;
46
47
  bool trans_A, trans_B;
  int M, N, K;
48
49
  int stride_A, stride_B;
  int offset_A, offset_B;
50
  bool clear_accum = false;
51
52
  // k_pack please ref to bitblas/tl/mfma_macro_generator.py::k_pack
  // only will be enabled under cdna mfma instructions
53
  int kPack = 1;
54
  int wg_wait = 0;
55
56
57
  bool completed_ = false;
};

58
59
} // namespace tl
} // namespace tvm
60

61
#endif //  TVM_TL_OP_GEMM_H_