ops.td 6.22 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2020 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
//
17
// This is the nGraph Dialect operation definition file.
18 19 20
//
//===----------------------------------------------------------------------===//

21 22 23
// NOTE: This file follows nGraph format style and MLIR naming convention since it does
// not expose public API to the rest of nGraph codebase and heavily depends on MLIR API.

24
include "core/ngraph_dialect/ops_interfaces.td"
25 26
include "mlir/IR/OpBase.td"

27
// nGraph Dialect operations definitions
28
//
29
// This files declares nGraph operations that table-gen uses to create C++ code
30 31 32 33 34 35 36 37 38 39 40 41
// For more information about tablegen. See https://llvm.org/docs/TableGen/index.html
//
// The output files are ops.h.inc and ops.cpp.inc and are generated at build time
// The file declares base classes to ease opcode definitions and hoist common parts out.
// Each class fixes a set of attributes. For example:
// class NG_Unary_Arith_Op defines a base class for all unary arithmetic ops without side-effects
//
// An opcode is a record definition of the form
//      def AbsOp      : NG_Unary_Arith_Op<"abs">;
//
// Each def will corresponding to a C++ class

42 43 44 45 46 47 48
def NG_Dialect : Dialect {
  let name = "ng";
  // TODO: Have the dialect under its own mlir::ngraph namespace
  // At mlir top-level for now
  let cppNamespace = "";
}

49 50
// nGraph Types
// This defines records equivalent to nGraph types. It doesn't generate code.
51 52
// This is used as a type in the DAG input/outputs.
// Constraints (CPred) are used to type-check args/results of that type during op verification
53
def NG_TensorType : Type<CPred<"$_self.isa<mlir::NGTensorType>()">,
54
                     "nGraph Tensor Type">;
55

56 57 58
// A generic un-typed MemRef. Used for Fake instructions inserted during dialect lowering
def NG_MemRefType : Type<IsMemRefTypePred, "MemRef Type">;

59
// nGraph operation base class.
60 61
// Prepends "ng." to operation name
class NG_Op<string mnemonic, list<OpTrait> traits = []> :
62
    Op<NG_Dialect, mnemonic, traits> {}
63 64 65 66 67 68 69 70 71 72

// Operations producing single result.
// Will set OneResult trait based on Results out dag.
class NG_OneResult_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_Op<mnemonic, traits>, Results<(outs NG_TensorType:$res)> {}

// Operations producing no results
class NG_ZeroResult_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_Op<mnemonic, traits>, Results<(outs)> {}

73
// Base class for arithmetic unary operations without side effects.
74
class NG_Unary_Arith_Op<string mnemonic, list<OpTrait> traits = []> :
75
      NG_OneResult_Op<mnemonic, !listconcat([NoSideEffect], traits)>,
76 77 78
      Arguments<(ins NG_TensorType:$arg)>
{
  // TODO: Implement
79
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
80

81
  let verifier = [{ return verifyUnaryArithOp(*this); }];
82 83
}

84
// Base class for arithmetic binary operations without side effects.
85
class NG_Binary_Op<string mnemonic, list<OpTrait> traits = []> :
86
      NG_OneResult_Op<mnemonic, !listconcat([NoSideEffect], traits)>,
87
      Arguments<(ins NG_TensorType:$lhs, NG_TensorType:$rhs)>
88 89
{
  // TODO: Implement
90
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
91 92 93 94 95 96
}

// Base class for arithmetic binary operations with verifier.
class NG_Binary_Arith_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_OneResult_Op<mnemonic, traits>,
      Arguments<(ins NG_TensorType:$lhs, NG_TensorType:$rhs)>
97 98
{
  // TODO: Implement
99
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
100

101
  let verifier = [{ return verifyBinaryArithOp(*this); }];
102 103
}

104 105 106 107 108 109
// Base class for comparison operations with verifier.
class NG_Cmp_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_OneResult_Op<mnemonic, traits>,
      Arguments<(ins NG_TensorType:$lhs, NG_TensorType:$rhs)>
{
  // TODO: Implement
110
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
111

112
  let verifier = [{ return verifyCmpOp(*this); }];
113 114 115 116 117 118 119 120
}

// Base class for ternary operations without side effects.
class NG_Ternary_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_OneResult_Op<mnemonic, !listconcat([NoSideEffect], traits)>,
      Arguments<(ins NG_TensorType:$op0, NG_TensorType:$op1, NG_TensorType:$op2)>
{
  // TODO: Implement
121
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
122 123 124
}


125 126 127 128 129 130
class NG_Axis_Reduction_Op<string mnemonic, list<OpTrait> traits = []> :
      NG_OneResult_Op<mnemonic, !listconcat([NoSideEffect], traits)>,
      Arguments<(ins NG_TensorType:$operand, I64ArrayAttr:$axes)>
{
  let summary = "Base class for reduction operations that perform a reduction "
                "across the axes of a  single tensor.";
nmostafa's avatar
nmostafa committed
131
  let description = [{Axes are represented as an array of I64 attributes.}];
132

133
  let parser = [{ NGRAPH_CHECK(false, "No parser support"); return mlir::failure(); }];
134 135

  // TODO
136
  let verifier = [{ return verifyAxisReductionOp(*this); }];
137 138
}

139 140 141 142
// Base class for terminator operations.
class NG_Terminator_Op<string mnemonic, list<OpTrait> traits = []> :
    NG_Op<mnemonic, !listconcat(traits, [Terminator])>,
    Arguments<(ins Variadic<NG_TensorType>:$args)>, Results<(outs)> {}
143

144 145 146
class NG_Variadic_Result_Op<string mnemonic, list<OpTrait> traits = []> :
    NG_Op<mnemonic, !listconcat(traits, [])>,
    Results<(outs Variadic<NG_TensorType>:$args)> {}
nmostafa's avatar
nmostafa committed
147

148 149
// Terminator Ops
def NGReturnOp : NG_Terminator_Op<"return">;
nmostafa's avatar
nmostafa committed
150

151 152
// ops attributes
include "core/ngraph_dialect/ops_attributes.td"
nmostafa's avatar
nmostafa committed
153

154 155
// Version 0 Ops
include "core/ngraph_dialect/ops_v0.td"
156

157 158
// Version 1 Ops
include "core/ngraph_dialect/ops_v1.td"
159

160 161
// Fused Ops
include "core/ngraph_dialect/fused_ops.td"