infrt_phi_tensor.td 3.5 KB
Newer Older
1
#ifdef PHI_TENSOR
2
#else
3
#define PHI_TENSOR
4

5
include "paddle/infrt/dialect/phi/ir/infrt_phi_base.td"
6 7
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpBase.td"
8
include "paddle/infrt/dialect/infrt/ir/infrt_base.td"
9

10 11
def PHI_DenseTensorDialect : Dialect {
  let name = "phi_dt";
12 13

  let description = [{
14
    The PHI DenseTensor dialect.
15 16
  }];

17
  let cppNamespace = "::infrt::phi";
18 19
}

20
// PHI DenseTensor related Op.
21 22
class PDT_Op<string mnemonic, list<OpTrait> traits = []> : Op<PHI_DenseTensorDialect,
  mnemonic, !listconcat(traits, [PhiOpTrait, IsolatedFromAbove])> {}
23

W
Wilber 已提交
24 25
class CreateDenseTensorOp<string target>
      : PDT_Op<"create_dense_tensor." # target, [NoSideEffect]> {
26 27
  let arguments = (ins Context:$context, I64ArrayAttr:$dims, 
    LayoutAttr:$layout, I64ArrayAttr:$lod, PrecisionAttr:$precision);
28
  let results = (outs DenseTensor:$output);
29 30
}

31 32
class FillDenseTensorOp<Attr attr_type, string dtype> :
      PDT_Op<"fill_dense_tensor." # dtype> {
33
  let arguments = (ins
34
      DenseTensor:$input,
35 36 37
      attr_type:$value
  );
  let results = (outs);
38 39 40 41 42 43 44 45
  let assemblyFormat = "`(` $input `:` type($input) `)` attr-dict";
}

class PrintDenseTensorOp:
      PDT_Op<"print_tensor"> {
  let arguments = (ins DenseTensor:$input);
  let results = (outs);
  let assemblyFormat = "`(` $input `:` type($input) `)` attr-dict";
46 47
}

48 49
class CreateContextOp<string target>
      : PDT_Op<"create_context." # target, [NoSideEffect]> {
50
  let arguments = (ins);
51
  let results = (outs Context:$output);
52 53
}

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
def PDT_LoadParamsOp : PDT_Op<"load_params", [NoSideEffect]> {
  // input path of model params.
  let arguments = (ins StrAttr:$path);
  let results = (outs PD_DenseTensorMap:$out);

  let assemblyFormat = "`(``)`attr-dict";
}

def PDT_LoadCombinedParamsOp : PDT_Op<"load_combined_params", [NoSideEffect]> {
  // input path of model params.
  let arguments = (ins StrAttr:$model_path, StrAttr:$params_path);
  let results = (outs PD_DenseTensorMap:$out);

  let assemblyFormat = "`(``)`attr-dict";
}

def PDT_TensorMapGetSizeOp : PDT_Op<"tensor_map_get_size", [NoSideEffect]> {
  let arguments = (ins PD_DenseTensorMap:$map);
  let results = (outs I32:$size);
  let assemblyFormat = "`(` $map `)` attr-dict `->` type($size)";
}

class TensorMapGetTensorOp:
      PDT_Op<"tensor_map_get_tensor"> {
  let arguments = (ins
          PD_DenseTensorMap:$map,
          StrAttr:$name
          );
  let results = (outs DenseTensor:$output);
  let assemblyFormat = "`(` operands `)` attr-dict `->` type($output)";
  let verifier = ?;
}

W
Wilber 已提交
87 88
def PDT_CreateCPUDenseTensorOp : CreateDenseTensorOp<"cpu">;
def PDT_CreateGPUDenseTensorOp : CreateDenseTensorOp<"gpu">;
89
def PDT_FillDenseTensorOp_f32 : FillDenseTensorOp<F32ArrayAttr, "f32">;
90
def PDT_CreateCPUContextOp : CreateContextOp<"cpu">;
W
Wilber 已提交
91
def PDT_CreateGPUContextOp : CreateContextOp<"gpu">;
92
def PDT_PrintDenseTensor : PrintDenseTensorOp;
93
def PDT_TensorMapGetTensorOp: TensorMapGetTensorOp;
94

95
def FakeKernelOp : PDT_Op<"fake_phi_kernel"> {
96
  let arguments = (ins Context:$dev_ctx, DenseTensor:$x, DenseTensor:$y, BoolAttr:$transpose_x, BoolAttr:$transpose_y);
97 98 99
  let results = (outs DenseTensor:$output);
}

W
Wilber 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112
// TODO(wilber): Add a infrt_gpu dialect.
def PDT_GpuMemCopyOp : PDT_Op<"memcpy.gpu", [NoSideEffect]> {
  let summary = "phi_dt.gpu.memcpy";
  let description = [{gpu memcpy d2h or h2d}];
  // TODO(wilber): add context argument to support stream.
  let arguments = (ins
    DenseTensor:$input,
    Context:$context,
    BoolAttr:$d2h
  );
  let results = (outs DenseTensor:$output);
}

113
#endif