1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_GRAPPLER_OP_TYPES_H_ 17 #define TENSORFLOW_CORE_GRAPPLER_OP_TYPES_H_ 18 19 #include "tensorflow/core/framework/node_def.pb.h" 20 #include "tensorflow/core/framework/op.h" 21 #include "tensorflow/core/lib/core/status.h" 22 23 namespace tensorflow { 24 namespace grappler { 25 bool IsAdd(const NodeDef& node); 26 bool IsAddN(const NodeDef& node); 27 bool IsAll(const NodeDef& node); 28 bool IsAngle(const NodeDef& node); 29 bool IsAny(const NodeDef& node); 30 bool IsAnyDiv(const NodeDef& node); 31 bool IsAnyBatchMatMul(const NodeDef& node); 32 bool IsAnyMatMul(const NodeDef& node); 33 bool IsAnyMax(const NodeDef& node); 34 bool IsAnyMaxPool(const NodeDef& node); 35 bool IsAnyMin(const NodeDef& node); 36 bool IsAnyMul(const NodeDef& node); 37 bool IsAnySparseSegmentReduction(const NodeDef& node); 38 bool IsApproximateEqual(const NodeDef& node); 39 bool IsArg(const NodeDef& node); 40 bool IsArgMax(const NodeDef& node); 41 bool IsArgMin(const NodeDef& node); 42 bool IsAssert(const NodeDef& node); 43 bool IsAssign(const NodeDef& node); 44 bool IsAsString(const NodeDef& node); 45 bool IsAtan2(const NodeDef& node); 46 bool IsAvgPoolGrad(const NodeDef& node); 47 bool IsBetainc(const NodeDef& node); 48 bool IsBiasAdd(const NodeDef& node); 49 bool IsBiasAddV2(const NodeDef& node); 50 bool IsBiasAddGrad(const NodeDef& node); 51 bool IsBitcast(const NodeDef& node); 52 bool IsBroadcastTo(const NodeDef& node); 53 bool IsCast(const NodeDef& node); 54 bool IsCheckNumerics(const NodeDef& node); 55 bool IsCollective(const NodeDef& node); 56 bool IsComplex(const NodeDef& node); 57 bool IsComplexAbs(const NodeDef& node); 58 bool IsConcat(const NodeDef& node); 59 bool IsConcatOffset(const NodeDef& node); 60 bool IsConj(const NodeDef& node); 61 bool IsConjugateTranspose(const NodeDef& node); 62 bool IsConstant(const NodeDef& node); 63 bool IsControlFlow(const NodeDef& node); 64 bool IsConv2D(const NodeDef& node); 65 bool IsConv2DBackpropFilter(const NodeDef& node); 66 bool IsConv2DBackpropInput(const NodeDef& node); 67 bool IsConv3D(const NodeDef& node); 68 bool IsConv3DBackpropFilterV2(const NodeDef& node); 69 bool IsConv3DBackpropInputV2(const NodeDef& node); 70 bool IsDepthwiseConv2dNative(const NodeDef& node); 71 bool IsDepthwiseConv2dNativeBackpropFilter(const NodeDef& node); 72 bool IsDepthwiseConv2dNativeBackpropInput(const NodeDef& node); 73 bool IsDequeueOp(const NodeDef& node); 74 bool IsDiv(const NodeDef& node); 75 bool IsDivNoNan(const NodeDef& node); 76 bool IsElementWiseMonotonic(const NodeDef& node, bool* is_non_decreasing); 77 bool IsElu(const NodeDef& node); 78 bool IsEluGrad(const NodeDef& node); 79 bool IsQuantizationEmulation(const NodeDef& node); 80 bool IsEnter(const NodeDef& node); 81 bool IsEqual(const NodeDef& node); 82 bool IsExit(const NodeDef& node); 83 bool IsExp(const NodeDef& node); 84 bool IsFakeParam(const NodeDef& node); 85 bool IsFill(const NodeDef& node); 86 bool IsFloorDiv(const NodeDef& node); 87 bool IsFloorMod(const NodeDef& node); 88 bool IsFusedBatchNorm(const NodeDef& node); 89 bool IsFusedBatchNormEx(const NodeDef& node); 90 bool IsFusedBatchNormGrad(const NodeDef& node); 91 bool IsGather(const NodeDef& node); 92 bool IsGreater(const NodeDef& node); 93 bool IsGreaterEqual(const NodeDef& node); 94 bool IsHistogramSummary(const NodeDef& node); 95 bool IsHostConstant(const NodeDef& node); 96 bool IsIdentity(const NodeDef& node); 97 bool IsIdentityN(const NodeDef& node); 98 bool IsIdentityNSingleInput(const NodeDef& node); 99 bool IsIf(const NodeDef& node); 100 bool IsIgamma(const NodeDef& node); 101 bool IsIgammac(const NodeDef& node); 102 bool IsImag(const NodeDef& node); 103 bool IsImmutableConst(const NodeDef& node); 104 bool IsInvGrad(const NodeDef& node); 105 bool IsLeakyRelu(const NodeDef& node); 106 bool IsLeakyReluGrad(const NodeDef& node); 107 bool IsLess(const NodeDef& node); 108 bool IsLessEqual(const NodeDef& node); 109 bool IsLog(const NodeDef& node); 110 bool IsLogicalAnd(const NodeDef& node); 111 bool IsLogicalNot(const NodeDef& node); 112 bool IsLogicalOr(const NodeDef& node); 113 bool IsLoopCond(const NodeDef& node); 114 bool IsMatMul(const NodeDef& node); 115 bool IsMax(const NodeDef& node); 116 bool IsMaxPoolGrad(const NodeDef& node); 117 bool IsMaximum(const NodeDef& node); 118 bool IsMean(const NodeDef& node); 119 bool IsMerge(const NodeDef& node); 120 bool IsMin(const NodeDef& node); 121 bool IsMinimum(const NodeDef& node); 122 bool IsMirrorPad(const NodeDef& node); 123 bool IsMirrorPadGrad(const NodeDef& node); 124 bool IsMod(const NodeDef& node); 125 bool IsMul(const NodeDef& node); 126 bool IsMulNoNan(const NodeDef& node); 127 bool IsNeg(const NodeDef& node); 128 bool IsNextIteration(const NodeDef& node); 129 bool IsNoOp(const NodeDef& node); 130 bool IsNotEqual(const NodeDef& node); 131 bool IsOnesLike(const NodeDef& node); 132 bool IsPack(const NodeDef& node); 133 bool IsPack(const NodeDef& node); 134 bool IsPad(const NodeDef& node); 135 bool IsPartitionedCall(const NodeDef& node); 136 bool IsPlaceholder(const NodeDef& node); 137 bool IsPolygamma(const NodeDef& node); 138 bool IsPow(const NodeDef& node); 139 bool IsPrint(const NodeDef& node); 140 bool IsProd(const NodeDef& node); 141 bool IsQuantizedMatMul(const NodeDef& node); 142 bool IsQueue(const NodeDef& node); 143 bool IsRandomShuffle(const NodeDef& node); 144 bool IsRank(const NodeDef& node); 145 bool IsReadVariableOp(const NodeDef& node); 146 bool IsReadVariablesOp(const NodeDef& node); 147 bool IsReal(const NodeDef& node); 148 bool IsRealDiv(const NodeDef& node); 149 bool IsReciprocalGrad(const NodeDef& node); 150 bool IsRecv(const NodeDef& node); 151 bool IsReduction(const NodeDef& node); 152 bool IsRelu(const NodeDef& node); 153 bool IsRelu6(const NodeDef& node); 154 bool IsRelu6Grad(const NodeDef& node); 155 bool IsReluGrad(const NodeDef& node); 156 bool IsReshape(const NodeDef& node); 157 bool IsRestore(const NodeDef& node); 158 bool IsRetval(const NodeDef& node); 159 bool IsReverse(const NodeDef& node); 160 bool IsReverseV2(const NodeDef& node); 161 bool IsRsqrt(const NodeDef& node); 162 bool IsRsqrtGrad(const NodeDef& node); 163 bool IsSelect(const NodeDef& node); 164 bool IsSeluGrad(const NodeDef& node); 165 bool IsSend(const NodeDef& node); 166 bool IsShape(const NodeDef& node); 167 bool IsShapeN(const NodeDef& node); 168 bool IsShuffle(const NodeDef& node); 169 bool IsSigmoid(const NodeDef& node); 170 bool IsSigmoidGrad(const NodeDef& node); 171 bool IsSize(const NodeDef& node); 172 bool IsSlice(const NodeDef& node); 173 bool IsSnapshot(const NodeDef& node); 174 bool IsSoftmax(const NodeDef& node); 175 bool IsSoftplusGrad(const NodeDef& node); 176 bool IsSoftsignGrad(const NodeDef& node); 177 bool IsSplit(const NodeDef& node); 178 bool IsSplitV(const NodeDef& node); 179 bool IsSqrt(const NodeDef& node); 180 bool IsSqrtGrad(const NodeDef& node); 181 bool IsSquare(const NodeDef& node); 182 bool IsSquaredDifference(const NodeDef& node); 183 bool IsSqueeze(const NodeDef& node); 184 bool IsStackCloseOp(const NodeDef& node); 185 bool IsStackOp(const NodeDef& node); 186 bool IsStackPopOp(const NodeDef& node); 187 bool IsStackPushOp(const NodeDef& node); 188 bool IsStatefulPartitionedCall(const NodeDef& node); 189 bool IsStopGradient(const NodeDef& node); 190 bool IsStridedSlice(const NodeDef& node); 191 bool IsStridedSliceGrad(const NodeDef& node); 192 bool IsStringToHashBucketFast(const NodeDef& node); 193 bool IsSub(const NodeDef& node); 194 bool IsSum(const NodeDef& node); 195 bool IsSwitch(const NodeDef& node); 196 bool IsSymbolicGradient(const NodeDef& node); 197 bool IsTanh(const NodeDef& node); 198 bool IsTanhGrad(const NodeDef& node); 199 bool IsTensorArray(const NodeDef& node); 200 bool IsTile(const NodeDef& node); 201 bool IsTranspose(const NodeDef& node); 202 bool IsTruncateDiv(const NodeDef& node); 203 bool IsTruncateMod(const NodeDef& node); 204 bool IsUnique(const NodeDef& node); 205 bool IsUnpack(const NodeDef& node); 206 bool IsVariable(const NodeDef& node); 207 bool IsWhile(const NodeDef& node); 208 bool IsXdivy(const NodeDef& node); 209 bool IsXlaLaunch(const NodeDef& node); 210 bool IsZerosLike(const NodeDef& node); 211 bool IsZeta(const NodeDef& node); 212 213 // Return true if the op is an aggregation (e.g. Add, AddN). 214 // Returns false if it could not be determined to be so. 215 bool IsAggregate(const NodeDef& node); 216 217 // Return true if the op is commutative (e.g. Mul, Add). 218 // Returns false if it could not be determined to be so. 219 bool IsCommutative(const NodeDef& node); 220 221 // Returns true if the node is known to use persistent memory to store its 222 // value. 223 bool IsPersistent(const NodeDef& node); 224 225 // Returns true if the node belongs to the NC_DATASET class (see graph/graph.h). 226 bool IsDataset(const NodeDef& node); 227 228 // Returns true if the node op is marked as stateful, or if it was not found in 229 // op_registry. 230 bool IsStateful(const NodeDef node, const OpRegistryInterface* op_registry); 231 bool IsStateful(const NodeDef node); // use OpRegistry::Global() 232 233 bool IsFreeOfSideEffect(const NodeDef& node, 234 const OpRegistryInterface* op_registry); 235 bool IsFreeOfSideEffect(const NodeDef& node); // use OpRegistry::Global() 236 237 // Returns true if the takes a tensor reference as input. 238 // Returns false if the op type is unknown. 239 bool HasRefInput(const NodeDef& node); 240 241 bool ModifiesFrameInfo(const NodeDef& node); 242 243 // Returns true if the op is known to write to one or more of its inputs. 244 bool ModifiesInputsInPlace(const NodeDef& node); 245 246 // Returns true if the op is an element-wise involution, i.e. if it is its 247 // own inverse such that f(f(x)) == x. 248 bool IsInvolution(const NodeDef& node); 249 250 // Returns true if the op preserves the order and value of elements 251 // and shape of its first input tensor. 252 bool IsValueAndOrderAndShapePreserving(const NodeDef& node); 253 254 // Returns true if the op preserves the order and value of elements in its 255 // first input tensor and possible changes its shape. 256 bool IsValueAndOrderPreserving(const NodeDef& node); 257 258 // Returns true if the op in node only rearranges the order of elements in its 259 // first input tensor and possible changes its shape. More precisely, this 260 // function returns true if the op commutes with all element-wise operations. 261 bool IsValuePreserving(const NodeDef& node); 262 263 // Returns true if node is idempotent w.r.t. its first input, i.e. if 264 // Op(Op(x, y, z), y, z) = Op(x, y, z). 265 bool IsIdempotent(const NodeDef& node); 266 267 bool IsUnaryElementWise(const NodeDef& node); 268 269 // Returns true if we can find an opdef corresponding to the op of the node. 270 bool HasOpDef(const NodeDef& node); 271 272 // Returns true if the op changes the scalar type of its first input elements 273 // and preserves the number of elements. 274 bool IsCastLike(const NodeDef& node); 275 276 // Returns true if this op never forwards any of its inputs, i.e. always 277 // allocates buffers for its inputs. 278 bool NeverForwardsInputs(const NodeDef& node); 279 280 } // end namespace grappler 281 } // end namespace tensorflow 282 283 #endif // TENSORFLOW_CORE_GRAPPLER_OP_TYPES_H_ 284