pd_ops.td 5.9 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8
#ifndef PD_OPS
#define PD_OPS

include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/IR/OpBase.td"
include "paddle/infrt/dialect/pd_op_base.td"

9
def PD_FeedOp : PD_Op<"feed"> {
Y
Yan Chunwei 已提交
10 11 12 13 14 15
  let summary = "Feed Op";

  let description = [{
    Feed a tensor into the model.
  }];

16
  let arguments = (ins StrAttr:$name);
Y
Yan Chunwei 已提交
17 18 19 20 21 22 23
  let results = (outs PD_Tensor:$out);

  let assemblyFormat = [{
      `(` `)` attr-dict `:` type($out)
  }];
}

24 25 26
def PD_FetchOp : PD_Op<"fetch", [Terminator]> {
  let summary = "fetch Op";

27 28 29 30 31 32 33 34 35 36
  let description = [{
    Return the output tensor from the subgraph.
  }];

  let arguments = (ins PD_Tensor :$inputs, StrAttr:$name);
}

def PD_ReturnOp : PD_Op<"return", [Terminator]> {
  let summary = "return Op";

37 38 39 40 41 42 43
  let description = [{
    Fetch tensor from the graph.
  }];

  let arguments = (ins Variadic<PD_Tensor>:$inputs);
}

44
def PD_GraphOp : PD_Op<"graph", [SingleBlockImplicitTerminator<"ReturnOp">]> {
45 46 47 48 49 50 51 52 53
  let summary = "paddle graph Op";
  let description = [{
    Describe a paddle graph or subgraph.
  }];
  let regions = (region SizedRegion<1>:$body);
  let arguments = (ins Variadic<PD_Tensor>:$inputs);
  let results = (outs Variadic<PD_Tensor>:$outputs);
}

54
def PD_ConstantOp : PD_Op<"constant", [NoSideEffect, ConstantLike, DeclareOpInterfaceMethods<InferTypeOpInterface>, AllTypesMatch<["value", "output"]>]> {
Y
Yan Chunwei 已提交
55 56 57 58 59 60 61 62
  let summary = "constant Op";
  let description = [{}];

  let arguments = (ins ElementsAttr:$value);
  let results = (outs PD_Tensor:$output);
  let hasFolder = 1;

  let builders = [
63
    OpBuilder<(ins "Attribute":$value)>,
Y
Yan Chunwei 已提交
64 65 66
  ];
}

67
def PD_AbsOp : PD_Op<"abs", [NoSideEffect, SameOperandsAndResultType]> {
Y
Yan Chunwei 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  let summary = "Computes the absolute value of a tensor";

  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x);
  let results = (outs PD_Tensor:$y);
}

def PD_SqrtOp : PD_Op<"sqrt", [NoSideEffect, SameOperandsAndResultType]> {
  let summary = "Computes the sqrt value of a tensor";

  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x);
  let results = (outs PD_Tensor:$y);
}

87
def PD_ReluOp : PD_Op<"relu", [NoSideEffect, SameOperandsAndResultType]> {
Y
Yan Chunwei 已提交
88 89 90 91 92 93 94 95 96 97
  let summary = "Computes the Relu of a tensor";

  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x);
  let results = (outs PD_Tensor:$y);
  let hasCanonicalizer = 1;
}

98
def PD_Relu6Op : PD_Op<"relu6", [NoSideEffect, SameOperandsAndResultType]> {
Y
Yan Chunwei 已提交
99 100 101 102 103 104 105 106 107
  let summary = "Computes the Relu6 of a tensor";

  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x);
  let results = (outs PD_Tensor:$y);
}

108
def PD_ElementwiseAdd : PD_Op<"elementwise_add", [NoSideEffect, Commutative, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
Y
Yan Chunwei 已提交
109 110 111 112 113 114 115 116 117 118
  let summary = "ElementwiseAdd Op";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y, DefaultValuedAttr<I32Attr, "-1">:$axis);
  let results = (outs PD_Tensor:$out);
  let hasCanonicalizer = 1;
  let hasFolder = 1;
}

119
def PD_ElementwiseSub : PD_Op<"elementwise_sub", [NoSideEffect, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
Y
Yan Chunwei 已提交
120 121 122 123 124 125 126 127
  let summary = "ElementwiseSub Op";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y, DefaultValuedAttr<I32Attr, "-1">:$axis);
  let results = (outs PD_Tensor:$out);
}

128
def PD_ElementwiseMul : PD_Op<"elementwise_mul", [NoSideEffect, Commutative, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
Y
Yan Chunwei 已提交
129 130 131 132 133 134 135 136
  let summary = "ElementwiseMul Op";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y, DefaultValuedAttr<I32Attr, "-1">:$axis);
  let results = (outs PD_Tensor:$out);
}

137
def PD_ElementwiseDiv : PD_Op<"elementwise_div", [NoSideEffect, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
Y
Yan Chunwei 已提交
138 139 140 141 142 143 144 145
  let summary = "ElementwiseDiv Op";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y, DefaultValuedAttr<I32Attr, "-1">:$axis);
  let results = (outs PD_Tensor:$out);
}

146
def PD_MatmulOp : PD_Op<"matmul", [NoSideEffect]> {
Y
Yan Chunwei 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
  let summary = "Computes the matrix mulplication result of two tensors";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y,
                  DefaultValuedAttr<BoolAttr, "false">:$transpose_x,
                  DefaultValuedAttr<BoolAttr, "false">:$transpose_y,
                  DefaultValuedAttr<F32Attr, "1.0">:$alpha);
  let results = (outs PD_Tensor:$out);

  //let hasCanonicalizer = 1;
}

def PD_MulOp : PD_Op<"mul", [NoSideEffect, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
  let summary = "paddle mul op";
  let description = [{}];

  let arguments = (ins PD_Tensor:$x, PD_Tensor:$y);
  let results = (outs PD_Tensor:$out);

  //let hasCanonicalizer = 1;
}

def PD_Conv2dOp : PD_Op<"conv2d", [NoSideEffect]> {
  let summary = "paddle conv2d operation";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$Input, PD_Tensor:$Filter, PD_Tensor:$Bias);
  let results = (outs PD_Tensor:$Output);

  //let hasCanonicalizer = 1;
}

def PD_BatchNormOp : PD_Op<"batch_norm", [NoSideEffect]> {
  let summary = "paddle batch_norm operation";
  let description = [{
  }];

  let arguments = (ins PD_Tensor:$X, PD_Tensor:$Scale, PD_Tensor:$Bias,
                   PD_Tensor:$Mean, PD_Tensor:$Variance,
                   DefaultValuedAttr<F32Attr, "1e-05">:$epsilon);
  let results = (outs PD_Tensor:$Y);

  let hasCanonicalizer = 1;
}

194
def PD_FusedFC : PD_Op<"fc", [NoSideEffect]> {
Y
Yan Chunwei 已提交
195 196 197 198 199 200 201 202
    let summary = "Computes the Fully Connected result of two tensors";
    let description = [{
    }];

    let arguments = (ins PD_Tensor:$input, PD_Tensor:$w, PD_Tensor:$bias, DefaultValuedAttr<I32Attr, "1">:$in_num_col_dims);
    let results = (outs PD_Tensor:$out);
}

203
def PD_FusedRepeatedFCRelu : PD_Op<"fusion_repeated_fc_relu", [SameVariadicOperandSize, NoSideEffect]> {
Y
Yan Chunwei 已提交
204 205 206 207 208 209 210 211 212
    let summary = "";
    let description = [{ }];

    let arguments = (ins PD_Tensor:$input, Variadic<PD_Tensor>:$w, Variadic<PD_Tensor>:$bias);
    let results = (outs PD_Tensor:$out);
    let hasCanonicalizer = 1;
}

#endif  // PD_OPS