infrt_phi_tensor.td 4.1 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 33 34 35 36
def CreateHostInitedDenseTensorOp : PDT_Op<"create_host_inited_dense_tensor.f32", [NoSideEffect]> {
  let arguments = (ins
    Context:$context,
    I64ArrayAttr:$dims,
    LayoutAttr:$layout,
    I64ArrayAttr:$lod,
W
Wilber 已提交
37 38
    F32ArrayAttr:$values,
    DefaultValuedAttr<BoolAttr, "true">:$run_once
39 40 41 42
  );
  let results = (outs DenseTensor:$output);
}

43 44 45 46 47 48 49
def CreateInitedCpuFLOAT32DenseTensorOp
      : PDT_Op<"create_inited_dense_tensor.cpu.f32", [NoSideEffect]> {
  let arguments = (ins Context:$context, I64ArrayAttr:$dims, 
    LayoutAttr:$layout, I64ArrayAttr:$lod, F32Attr:$value);
  let results = (outs DenseTensor:$output);
}

50 51
class FillDenseTensorOp<Attr attr_type, string dtype> :
      PDT_Op<"fill_dense_tensor." # dtype> {
52
  let arguments = (ins
53
      DenseTensor:$input,
54 55 56
      attr_type:$value
  );
  let results = (outs);
57 58 59 60 61 62 63 64
  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";
65 66
}

67 68
class CreateContextOp<string target>
      : PDT_Op<"create_context." # target, [NoSideEffect]> {
69
  let arguments = (ins);
70
  let results = (outs Context:$output);
71 72
}

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
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 已提交
106 107
def PDT_CreateCPUDenseTensorOp : CreateDenseTensorOp<"cpu">;
def PDT_CreateGPUDenseTensorOp : CreateDenseTensorOp<"gpu">;
108
def PDT_FillDenseTensorOp_f32 : FillDenseTensorOp<F32ArrayAttr, "f32">;
109
def PDT_CreateCPUContextOp : CreateContextOp<"cpu">;
W
Wilber 已提交
110
def PDT_CreateGPUContextOp : CreateContextOp<"gpu">;
111
def PDT_PrintDenseTensor : PrintDenseTensorOp;
112
def PDT_TensorMapGetTensorOp: TensorMapGetTensorOp;
113

114
def FakeKernelOp : PDT_Op<"fake_phi_kernel"> {
115
  let arguments = (ins Context:$dev_ctx, DenseTensor:$x, DenseTensor:$y, BoolAttr:$transpose_x, BoolAttr:$transpose_y);
116 117 118
  let results = (outs DenseTensor:$output);
}

W
Wilber 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131
// 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);
}

132
#endif