infrt_phi_tensor.td 2.2 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 8 9
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpBase.td"
include "paddle/infrt/dialect/infrt_base.td"

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
class PDT_Op<string mnemonic, list<OpTrait> traits = []> : Op<PHI_DenseTensorDialect, mnemonic, !listconcat(traits, [PhiOpTrait, IsolatedFromAbove])> {
22 23
}

24 25
class CreateDenseTensorOp<string place, string dtype, string layout> 
      : PDT_Op<"create_dense_tensor." # place # "." # dtype # "." # layout, [NoSideEffect]> {
26
  let arguments = (ins Allocator:$allocator, I64ArrayAttr:$dims, I64ArrayAttr:$lod);
27
  let results = (outs DenseTensor:$output);
28 29
}

30 31
class FillDenseTensorOp<Attr attr_type, string dtype> :
      PDT_Op<"fill_dense_tensor." # dtype> {
32
  let arguments = (ins
33
      DenseTensor:$input,
34 35 36
      attr_type:$value
  );
  let results = (outs);
37 38 39 40 41 42 43 44
  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";
45 46
}

47 48 49
class CreateCPUAllocatorOp
      : PDT_Op<"create_allocator." # "cpu", [NoSideEffect]> {
  let arguments = (ins);
50
  let results = (outs Allocator:$output);
51 52
}

53 54
class CreateCPUContextOp
      : PDT_Op<"create_context." # "cpu", [NoSideEffect]> {
55 56
  let arguments = (ins Allocator:$input);
  let results = (outs Context:$output);
57 58
}

59 60 61 62
def PDT_CreateDenseTensorOp_cpu_f32_nchw : CreateDenseTensorOp<"cpu", "f32", "nchw">;
def PDT_FillDenseTensorOp_f32 : FillDenseTensorOp<F32ArrayAttr, "f32">;
def PDT_CreateAllocatorOp_cpu : CreateCPUAllocatorOp;
def PDT_CreateContextOp_cpu : CreateCPUContextOp;
63
def PDT_PrintDenseTensor_cpu : PrintDenseTensorOp;
64

65
def FakeKernelOp : PDT_Op<"fake_phi_kernel"> {
66
  let arguments = (ins Context:$dev_ctx, DenseTensor:$x, DenseTensor:$y, BoolAttr:$transpose_x, BoolAttr:$transpose_y);
67 68 69
  let results = (outs DenseTensor:$output);
}

70
#endif