You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.h 44 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /**
  2. * Copyright 2019-2022 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_UTILS_H_
  17. #define MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_UTILS_H_
  18. #include <unistd.h>
  19. #include <fcntl.h>
  20. #include <sys/stat.h>
  21. #include <sys/time.h>
  22. #include <string>
  23. #include <vector>
  24. #include <set>
  25. #include <map>
  26. #include <algorithm>
  27. #include "utils/log_adapter.h"
  28. #include "ir/dtype/type.h"
  29. namespace mindspore {
  30. // op name. Op which not exists in operator/ops.h, so define it's name here
  31. constexpr auto kConcatOpName = "Concat";
  32. constexpr auto kUniqueOpName = "Unique";
  33. constexpr auto kMaskedSelectOpName = "MaskedSelect";
  34. constexpr auto kComputeAccidentalHitsOpName = "ComputeAccidentalHits";
  35. constexpr auto kCTCGreedyDecoderOpName = "CTCGreedyDecoder";
  36. constexpr auto kDynamicStitchOpName = "DynamicStitch";
  37. constexpr auto kFour2FiveOpName = "Four2Five";
  38. constexpr auto kFive2FourOpName = "Five2Four";
  39. constexpr auto kConv3DOpName = "Conv3D";
  40. constexpr auto kConv3DBackpropFilterOpName = "Conv3DBackpropFilter";
  41. constexpr auto kConv3DBackpropInputOpName = "Conv3DBackpropInput";
  42. constexpr auto kConv2DOpName = "Conv2D";
  43. constexpr auto kConvBN1OpName = "ConvBN1";
  44. constexpr auto kBN2AddReluOpName = "BN2AddRelu";
  45. constexpr auto kBN2ReLUOpName = "BN2Relu";
  46. constexpr auto kBN2OpName = "BN2";
  47. constexpr auto kFusedBN1OpName = "FusedBN1";
  48. constexpr auto kFusedBN2OpName = "FusedBN2";
  49. constexpr auto kFusedBN3OpName = "FusedBN3";
  50. constexpr auto kBNGrad1OpName = "BNGrad1";
  51. constexpr auto kBNGrad2OpName = "BNGrad2";
  52. constexpr auto kBNGrad3OpName = "BNGrad3";
  53. constexpr auto kBatchNorm = "BatchNorm";
  54. constexpr auto kInstanceNorm = "InstanceNorm";
  55. constexpr auto kBatchNormWithActivation = "BatchNormWithActivation";
  56. constexpr auto kBatchNormWithAddAndActivation = "BatchNormWithAddAndActivation";
  57. constexpr auto kBatchNormGradWithActivation = "BatchNormGradWithActivation";
  58. constexpr auto kBatchNormGradWithAddAndActivation = "BatchNormGradWithAddAndActivation";
  59. constexpr auto kClearZeroOpName = "ClearZero";
  60. constexpr auto kAtomicAddrCleanOpName = "AtomicAddrClean";
  61. constexpr auto kGetNextOpName = "GetNext";
  62. constexpr auto kInitDatasetQueueOpName = "InitDataSetQueue";
  63. constexpr auto kEndOfSequence = "EndOfSequence";
  64. constexpr auto kAllToAllVOpName = "AllToAllv";
  65. constexpr auto kAllReduceOpName = "AllReduce";
  66. constexpr auto kAllGatherOpName = "AllGather";
  67. constexpr auto kHostAllGatherOpName = "HostAllGather";
  68. constexpr auto kBroadcastOpName = "Broadcast";
  69. constexpr auto kReceiveOpName = "Receive";
  70. constexpr auto kHcomSendOpName = "Send";
  71. constexpr auto kReduceScatterOpName = "ReduceScatter";
  72. constexpr auto kHostReduceScatterOpName = "HostReduceScatter";
  73. constexpr auto kMemCpyAsyncOpName = "memcpy_async";
  74. constexpr auto kTopKOpName = "TopK";
  75. constexpr auto kLinSpaceOpName = "LinSpace";
  76. constexpr auto kExtractImagePatchesOpName = "ExtractImagePatches";
  77. constexpr auto kBNTrainingReduceOpName = "BNTrainingReduce";
  78. constexpr auto kBNTrainingUpdateOpName = "BNTrainingUpdate";
  79. constexpr auto kBNTrainingUpdateV2OpName = "BNTrainingUpdateV2";
  80. constexpr auto kBNTrainingUpdateV3OpName = "BNTrainingUpdateV3";
  81. constexpr auto kNonMaxSuppressionV3OpName = "NonMaxSuppressionV3";
  82. constexpr auto kSimpleMeanGradOpName = "SimpleMeanGrad";
  83. constexpr auto kMeanGradOpName = "MeanGrad";
  84. constexpr auto kSliceOpName = "Slice";
  85. constexpr auto kSliceGradOpName = "SliceGrad";
  86. constexpr auto kCoalesceOpName = "Coalesce";
  87. constexpr auto kTileOpName = "Tile";
  88. constexpr auto kScatterNdOpName = "ScatterNd";
  89. constexpr auto kStridedSliceAssignOpName = "StridedSliceAssign";
  90. constexpr auto kStridedSliceOpName = "StridedSlice";
  91. constexpr auto kStridedSliceGradOpName = "StridedSliceGrad";
  92. constexpr auto kSparseGatherV2OpName = "SparseGatherV2";
  93. constexpr auto kUnsortedSegmentProdOpName = "UnsortedSegmentProd";
  94. constexpr auto kUnsortedSegmentMinOpName = "UnsortedSegmentMin";
  95. constexpr auto kFlattenGradOpName = "FlattenGrad";
  96. constexpr auto kExpandDimsOpName = "ExpandDims";
  97. constexpr auto kReshapeOpName = "Reshape";
  98. constexpr auto kTransposeOpName = "Transpose";
  99. constexpr auto kTransposeNODOpName = "TransposeNOD";
  100. constexpr auto kSplitOpName = "Split";
  101. constexpr auto kSplitVOpName = "SplitV";
  102. constexpr auto kSparseApplyAdagradOpName = "SparseApplyAdagrad";
  103. constexpr auto kMomentumOpName = "Momentum";
  104. constexpr auto kApplyMomentumOpName = "ApplyMomentum";
  105. constexpr auto kCombineMomentumOpName = "CombineMomentum";
  106. constexpr auto kCombineMomentumWeightOpName = "CombineMomentumWeight";
  107. constexpr auto kApplyAdadeltaOpName = "ApplyAdadelta";
  108. constexpr auto kApplyAdagradOpName = "ApplyAdagrad";
  109. constexpr auto kApplyAdagradDAName = "ApplyAdagradDA";
  110. constexpr auto kApplyAdamOpName = "Adam";
  111. constexpr auto kApplyAdaMaxOpName = "ApplyAdaMax";
  112. constexpr auto kApplyAddSignOpName = "ApplyAddSign";
  113. constexpr auto kApplyCenteredRMSPOpName = "ApplyCenteredRMSP";
  114. constexpr auto kApplyCenteredRMSPropOpName = "ApplyCenteredRMSProp";
  115. constexpr auto kApplyFtrlOpName = "ApplyFtrl";
  116. constexpr auto kApplyFtrlV2OpName = "ApplyFtrlV2";
  117. constexpr auto kApplyGradientDescentOpName = "ApplyGradientDescent";
  118. constexpr auto kApplyPowerSignOpName = "ApplyPowerSign";
  119. constexpr auto kApplyProximalAdagradOpName = "ApplyProximalAdagrad ";
  120. constexpr auto kApplyProximalGradientDescentOpName = "ApplyProximalGradientDescent";
  121. constexpr auto kApplyRMSPropOpName = "ApplyRMSProp";
  122. constexpr auto kTransDataOpName = "TransData";
  123. constexpr auto kTransDataRNNOpName = "TransDataRNN";
  124. constexpr auto kStackInitOpName = "StackInit";
  125. constexpr auto kStackPushOpName = "StackPush";
  126. constexpr auto kStackPopOpName = "StackPop";
  127. constexpr auto kStackOpName = "Stack";
  128. constexpr auto kStackDestroyOpName = "StackDestroy";
  129. constexpr auto kBNTrainingUpdateGradOpName = "BNTrainingUpdateGrad";
  130. constexpr auto kBNTrainingReduceGradOpName = "BNTrainingReduceGrad";
  131. constexpr auto kSquareSumV1OpName = "SquareSumV1";
  132. constexpr auto kSquareSumV2OpName = "SquareSumV2";
  133. constexpr auto kClipByNormNoDivSumOpName = "ClipByNormNoDivSum";
  134. constexpr auto kPReluOpName = "PReLU";
  135. constexpr auto kGreaterOpName = "Greater";
  136. constexpr auto kSqrtOpName = "Sqrt";
  137. constexpr auto kRsqrtOpName = "Rsqrt";
  138. constexpr auto kRsqrtGradOpName = "RsqrtGrad";
  139. constexpr auto kErfOpName = "Erf";
  140. constexpr auto kRealDivOpName = "RealDiv";
  141. constexpr auto kLambUpdateWithLROpName = "LambUpdateWithLR";
  142. constexpr auto kLambNextMVWithDecayOpName = "LambNextMVWithDecay";
  143. constexpr auto kLambNextMVWithDecayV1OpName = "LambNextMVWithDecayV1";
  144. constexpr auto kClipByValueOpName = "ClipByValue";
  145. constexpr auto kLambNextRightOpName = "LambNextRight";
  146. constexpr auto kConfusionSoftmaxGradOpName = "ConfusionSoftmaxGrad";
  147. constexpr auto kLambUpdateWithLrV2OpName = "LambUpdateWithLrV2";
  148. constexpr auto kLayerNormXBackpropOpName = "LayerNormXBackprop";
  149. constexpr auto kLayerNormXBackpropV2OpName = "LayerNormXBackpropV2";
  150. constexpr auto kLayerNormBetaGammaBackpropOpName = "LayerNormBetaGammaBackprop";
  151. constexpr auto kLayerNormBetaGammaBackpropV2OpName = "LayerNormBetaGammaBackpropV2";
  152. constexpr auto kLambNextMVOpName = "LambNextMV";
  153. constexpr auto kConfusionTransposeDOpName = "ConfusionTransposeD";
  154. constexpr auto kAdamApplyOneWithDecayOpName = "AdamApplyOneWithDecay";
  155. constexpr auto kAdamApplyOneWithDecayAssignOpName = "AdamApplyOneWithDecayAssign";
  156. constexpr auto kBatchNormGradOpName = "BatchNormGrad";
  157. constexpr auto kBNInferOpName = "BNInfer";
  158. constexpr auto kAdamApplyOneOpName = "AdamApplyOne";
  159. constexpr auto kAdamApplyOneAssignOpName = "AdamApplyOneAssign";
  160. constexpr auto kResizeNearestNeighborGradOpName = "ResizeNearestNeighborGrad";
  161. constexpr auto kFusedMulAddOpName = "FusedMulAdd";
  162. constexpr auto kFusedMulAddNOpName = "FusedMulAddN";
  163. constexpr auto kFusedMulApplyMomentumOpName = "FusedMulApplyMomentum";
  164. constexpr auto kBiasAddOpName = "BiasAdd";
  165. constexpr auto kConfusionMulGradOpName = "ConfusionMulGrad";
  166. constexpr auto kStreamSwitchOpName = "StreamSwitch";
  167. constexpr auto kStreamActiveOpName = "StreamActive";
  168. constexpr auto kAssignAddOpName = "AssignAdd";
  169. constexpr auto kSendOpName = "StreamSend";
  170. constexpr auto kRecvOpName = "StreamRecv";
  171. constexpr auto kRpcSendOpName = "RpcSend";
  172. constexpr auto kRpcRecvOpName = "RpcRecv";
  173. constexpr auto kReluV2OpName = "ReLUV2";
  174. constexpr auto kReluGradV2OpName = "ReluGradV2";
  175. constexpr auto kAddOpName = "Add";
  176. constexpr auto kAddNOpName = "AddN";
  177. constexpr auto kResizeNearestNeighborV2OpName = "ResizeNearestNeighborV2";
  178. constexpr auto kResizeNearestNeighborV2GradOpName = "ResizeNearestNeighborV2Grad";
  179. constexpr auto kApplyRMSPropOpname = "ApplyRMSProp";
  180. constexpr auto kCumsumOpName = "Cumsum";
  181. constexpr auto kInplaceAddOpName = "InplaceAdd";
  182. constexpr auto kInplaceSubOpName = "InplaceSub";
  183. constexpr auto kResizeBilinearV2OpName = "kResizeBilinearV2";
  184. constexpr auto kReduceProdOpName = "ReduceProd";
  185. constexpr auto kCumprodOpName = "Cumprod";
  186. constexpr auto kSpaceToBatchOpName = "SpaceToBatch";
  187. constexpr auto kBatchToSpaceOpName = "BatchToSpace";
  188. constexpr auto kSpaceToDepthOpName = "SpaceToDepth";
  189. constexpr auto kPadOpName = "Pad";
  190. constexpr auto kConv2DTransposeOpName = "Conv2DTranspose";
  191. constexpr auto kConv2DBackpropInputOpName = "Conv2DBackpropInput";
  192. constexpr auto kConv2DBackpropFilterOpName = "Conv2DBackpropFilter";
  193. constexpr auto kDepthwiseConv2dNativeOpName = "DepthwiseConv2dNative";
  194. constexpr auto kDepthwiseConv2dNativeBackpropInputOpName = "DepthwiseConv2dNativeBackpropInput";
  195. constexpr auto kDepthwiseConv2dNativeBackpropFilterOpName = "DepthwiseConv2dNativeBackpropFilter";
  196. constexpr auto kFusionOpConv2DBackpropInputReluGradV2Name = "FusionOp_Conv2DBackpropInput_ReluGradV2";
  197. constexpr auto kFusionOpConv2DBackpropInputAddNReluGradV2Name = "FusionOp_Conv2DBackpropInput_AddN_ReluGradV2";
  198. constexpr auto kLabelSetOpName = "LabelSet";
  199. constexpr auto kLabelSwitchOpName = "LabelSwitch";
  200. constexpr auto kLabelGotoOpName = "LabelGoto";
  201. constexpr auto kBNInferGradOpName = "BNInferGrad";
  202. constexpr auto kCallOpName = "call";
  203. constexpr auto kPartialOpName = "partial";
  204. constexpr auto kSwitchOpName = "Switch";
  205. constexpr auto kReturnOpName = "Return";
  206. constexpr auto kBpropCutOpName = "bprop_cut";
  207. constexpr auto kLarsV2OpName = "LarsV2";
  208. constexpr auto kLarsV2UpdateOpName = "LarsV2Update";
  209. constexpr auto kSquareSumAllOpName = "SquareSumAll";
  210. constexpr auto kNMSWithMaskOpName = "NMSWithMask";
  211. constexpr auto kSoftmaxGradExtOpName = "SoftmaxGradExt";
  212. constexpr auto kStridedReadOpName = "StridedRead";
  213. constexpr auto kStridedWriteOpName = "StridedWrite";
  214. constexpr auto kFusedAdamWeightDecayName = "FusedAdamWeightDecay";
  215. constexpr auto kAdamWeightDecayName = "AdamWeightDecay";
  216. constexpr auto kFusedCastAdamWeightDecayName = "FusedCastAdamWeightDecay";
  217. constexpr auto kFusedAdamName = "FusedAdam";
  218. constexpr auto kFusedAdaFactorName = "FusedAdaFactor";
  219. constexpr auto kFusedAdaFactorWithGlobalNormName = "FusedAdaFactorWithGlobalNorm";
  220. constexpr auto kFusedSparseAdamName = "FusedSparseAdam";
  221. constexpr auto kFusedMatMulBiasAddName = "FusedMatMulBiasAdd";
  222. constexpr auto kDeadNodeName = "DeadNode";
  223. constexpr auto kPolyNodeName = "PolyNode";
  224. constexpr auto kApplyAdagradV2OpName = "ApplyAdagradV2";
  225. constexpr auto kSparseApplyAdagradV2OpName = "SparseApplyAdagradV2";
  226. constexpr auto kSparseApplyFtrlOpName = "SparseApplyFtrl";
  227. constexpr auto kSparseApplyFtrlV2OpName = "SparseApplyFtrlV2";
  228. constexpr auto kApplyKerasMomentumOpName = "ApplyKerasMomentum";
  229. constexpr auto kSparseApplyProximalAdagradOpName = "SparseApplyProximalAdagrad";
  230. constexpr auto kSparseApplyRMSPropOpName = "SparseApplyRMSProp";
  231. constexpr auto kSparseApplyAdadeltaOpName = "SparseApplyAdadelta";
  232. constexpr auto kApplyAdamWithAmsgradOpName = "ApplyAdamWithAmsgrad";
  233. constexpr auto kTensorMoveOpName = "TensorMove";
  234. constexpr auto kTensorCopySlicesOpName = "TensorCopySlices";
  235. constexpr auto kTensorScatterUpdateOpName = "TensorScatterUpdate";
  236. constexpr auto kScatterNdUpdateOpName = "ScatterNdUpdate";
  237. constexpr auto kPushOpName = "Push";
  238. constexpr auto kPullOpName = "Pull";
  239. constexpr auto kPushWeightOpName = "PushWeight";
  240. constexpr auto kPullWeightOpName = "PullWeight";
  241. constexpr auto kFusedPushWeightOpName = "FusedPushWeight";
  242. constexpr auto kFusedPullWeightOpName = "FusedPullWeight";
  243. constexpr auto kUpdateCacheOpName = "UpdateCache";
  244. constexpr auto kCacheSwapTableOpName = "CacheSwapTable";
  245. constexpr auto kEmbeddingLookupOpName = "EmbeddingLookup";
  246. constexpr auto kEmbeddingLookupProxyOpName = "EmbeddingLookupProxy";
  247. constexpr auto kGatherV2OpName = "Gather";
  248. constexpr auto kPaddingOpName = "Padding";
  249. constexpr auto kAvgPoolOpName = "AvgPool";
  250. constexpr auto kAvgPoolGradOpName = "AvgPoolGrad";
  251. constexpr auto kAvgPool3DOpName = "AvgPool3D";
  252. constexpr auto kAvgPool3DGradOpName = "AvgPool3DGrad";
  253. constexpr auto kAvgPoolGradVmOpName = "AvgPoolGradVm";
  254. constexpr auto kMaxPoolOpName = "MaxPool";
  255. constexpr auto kMaxPoolGradOpName = "MaxPoolGrad";
  256. constexpr auto kMaxPool3DOpName = "MaxPool3D";
  257. constexpr auto kMaxPool3DGradOpName = "MaxPool3DGrad";
  258. constexpr auto kMaxPoolWithArgmaxOpName = "MaxPoolWithArgmax";
  259. constexpr auto kMaxPoolGradWithArgmaxOpName = "MaxPoolGradWithArgmax";
  260. constexpr auto kTensorAddOpName = "Add";
  261. constexpr auto kMaxPool3DGradGradOpName = "MaxPool3DGradGrad";
  262. constexpr auto kCastOpName = "Cast";
  263. constexpr auto kGreaterEqualOpName = "GreaterEqual";
  264. constexpr auto kAbsOpName = "Abs";
  265. constexpr auto kExpOpName = "Exp";
  266. constexpr auto kNegOpName = "Neg";
  267. constexpr auto kMinimumOpName = "Minimum";
  268. constexpr auto kMaximumOpName = "Maximum";
  269. constexpr auto kMulOpName = "Mul";
  270. constexpr auto kSubOpName = "Sub";
  271. constexpr auto kLogOpName = "Log";
  272. constexpr auto kPowOpName = "Pow";
  273. constexpr auto kReciprocalOpName = "Reciprocal";
  274. constexpr auto kEqualOpName = "Equal";
  275. constexpr auto kLessOpName = "Less";
  276. constexpr auto kLessEqualOpName = "LessEqual";
  277. constexpr auto kSquareOpName = "Square";
  278. constexpr auto kSelectOpName = "Select";
  279. constexpr auto kReduceSumOpName = "ReduceSum";
  280. constexpr auto kReduceMinOpName = "ReduceMin";
  281. constexpr auto kReduceMaxOpName = "ReduceMax";
  282. constexpr auto kReduceMeanOpName = "ReduceMean";
  283. constexpr auto kReduceAnyOpName = "ReduceAny";
  284. constexpr auto kReduceAllOpName = "ReduceAll";
  285. constexpr auto kFusedWeightScaleApplyMomentum = "FusedWeightScaleApplyMomentum";
  286. constexpr auto kFusedWeightApplyMomentum = "FusedWeightApplyMomentum";
  287. constexpr auto kFusedScaleApplyMomentum = "FusedScaleApplyMomentum";
  288. constexpr auto kBasicLSTMCellWeightGradOpName = "BasicLSTMCellWeightGrad";
  289. constexpr auto kBasicLSTMCellInputGradOpName = "BasicLSTMCellInputGrad";
  290. constexpr auto kBasicLSTMCellOpName = "BasicLSTMCell";
  291. constexpr auto kDynamicRNNOpName = "DynamicRNN";
  292. constexpr auto kLSTMOpName = "LSTM";
  293. constexpr auto kLSTMGradOpName = "LSTMGrad";
  294. constexpr auto kLSTMInputGradOpName = "LSTMInputGrad";
  295. constexpr auto kDynamicGRUV2OpName = "DynamicGRUV2";
  296. constexpr auto kGRUV2HiddenGradOpName = "GRUV2HiddenGrad";
  297. constexpr auto kGRUV2HiddenGradCellOpName = "GRUV2HiddenGradCell";
  298. constexpr auto kFusedSparseFtrlName = "FusedSparseFtrl";
  299. constexpr auto kFusedSparseProximalAdagradName = "FusedSparseProximalAdagrad";
  300. constexpr auto kFusedSparseLazyAdamName = "FusedSparseLazyAdam";
  301. constexpr auto kSparseApplyFtrlName = "SparseApplyFtrl";
  302. constexpr auto kSparseApplyFtrlV2Name = "SparseApplyFtrlV2";
  303. constexpr auto kSGDName = "SGD";
  304. constexpr auto kLARSUpdateName = "LARSUpdate";
  305. constexpr auto kBasicLSTMCellCStateGradOpName = "BasicLSTMCellCStateGrad";
  306. constexpr auto kBasicLSTMCellCStateGradV2OpName = "BasicLSTMCellCStateGradV2";
  307. constexpr auto kMatMulOpName = "MatMul";
  308. constexpr auto kMatMulV2OpName = "MatMulV2";
  309. constexpr auto kBatchMatMulOpName = "BatchMatMul";
  310. constexpr auto kBatchMatMulV2OpName = "BatchMatMulV2";
  311. constexpr auto kBroadcastToOpName = "BroadcastTo";
  312. constexpr auto kFusedAddReluV2Name = "FusedAddReluV2";
  313. constexpr auto kFusedAddReluGradV2Name = "FusedAddReluGradV2";
  314. constexpr auto kDropoutOpName = "Dropout";
  315. constexpr auto kDropoutGradOpName = "DropoutGrad";
  316. constexpr auto kDropoutGenMaskOpName = "DropoutGenMask";
  317. constexpr auto kDropoutGenMaskV3OpName = "DropoutGenMaskV3";
  318. constexpr auto kDropoutDoMaskOpName = "DropoutDoMask";
  319. constexpr auto kDropoutDoMaskV3OpName = "DropoutDoMaskV3";
  320. constexpr auto kSoftmaxV2WithDropoutDoMaskV3OpName = "SoftmaxV2WithDropoutDoMaskV3";
  321. constexpr auto kGammaOpName = "Gamma";
  322. constexpr auto kPoissonOpName = "Poisson";
  323. constexpr auto kStandardLaplaceOpName = "StandardLaplace";
  324. constexpr auto kStandardNormalOpName = "StandardNormal";
  325. constexpr auto kUniformIntOpName = "UniformInt";
  326. constexpr auto kUniformRealOpName = "UniformReal";
  327. constexpr auto kSubAndFilterOpName = "SubAndFilter";
  328. constexpr auto kPadAndShiftOpName = "PadAndShift";
  329. constexpr auto kSparseSoftmaxCrossEntropyWithLogitsOpName = "SparseSoftmaxCrossEntropyWithLogits";
  330. constexpr auto kOneHotOpName = "OneHot";
  331. constexpr auto kSoftmaxCrossEntropyWithLogitsOpName = "SoftmaxCrossEntropyWithLogits";
  332. constexpr auto kUniformCandidateSamplerOpName = "UniformCandidateSampler";
  333. constexpr auto kLogSoftmaxGradOpName = "LogSoftmaxGrad";
  334. constexpr auto kLayerNormGradOpName = "LayerNormGrad";
  335. constexpr auto kMinimumGradOpName = "MinimumGrad";
  336. constexpr auto kMaximumGradOpName = "MaximumGrad";
  337. constexpr auto kFusedDbnDwOpName = "FusedDbnDw";
  338. constexpr auto kNPUAllocFloatStatusOpName = "NPUAllocFloatStatus";
  339. constexpr auto kNPUGetFloatStatusOpName = "NPUGetFloatStatus";
  340. constexpr auto kNPUClearFloatStatusOpName = "NPUClearFloatStatus";
  341. constexpr auto kAssignOpName = "Assign";
  342. constexpr auto kScatterAddOpName = "ScatterAdd";
  343. constexpr auto kScatterUpdateOpName = "ScatterUpdate";
  344. constexpr auto kEnvironCreateOpName = "EnvironCreate";
  345. constexpr auto kEnvironSetOpName = "EnvironSet";
  346. constexpr auto kEnvironGetOpName = "EnvironGet";
  347. constexpr auto kEnvironDestroyAllOpName = "EnvironDestroyAll";
  348. constexpr auto kUpdateStateOpName = "UpdateState";
  349. constexpr auto kPriorityReplayBufferCreate = "PriorityReplayBufferCreate";
  350. constexpr auto kPriorityReplayBufferPush = "PriorityReplayBufferPush";
  351. constexpr auto kPriorityReplayBufferSample = "PriorityReplayBufferSample";
  352. constexpr auto kPriorityReplayBufferUpdate = "PriorityReplayBufferUpdate";
  353. // Communication world group
  354. constexpr auto kNcclWorldGroup = "nccl_world_group";
  355. constexpr auto kHcclWorldGroup = "hccl_world_group";
  356. constexpr auto kSyncBnGroup = "sync_bn_group";
  357. constexpr auto kRankID = "RANK_ID";
  358. // Hcom Op Type
  359. constexpr auto kHcomOpTypeAllReduce = "HcomAllReduce";
  360. constexpr auto kHcomOpTypeAllGather = "HcomAllGather";
  361. constexpr auto kHcomOpTypeBroadcast = "HcomBroadcast";
  362. constexpr auto kHcomOpTypeSend = "HcomSend";
  363. constexpr auto kHcomOpTypeReceive = "HcomReceive";
  364. constexpr auto kHcomOpTypeReduceScatter = "HcomReduceScatter";
  365. // attr key name
  366. constexpr auto kAttrInputNames = "input_names";
  367. constexpr auto kAttrAttrNames = "attr_names";
  368. constexpr auto kAttrIsAiCpuKernel = "is_AICPU_kernel";
  369. constexpr auto kIsBackendCast = "is_backed_cast";
  370. constexpr auto kAttrOutputNames = "output_names";
  371. constexpr auto kAttrAsync = "async";
  372. constexpr auto kAttrOffload = "offload";
  373. constexpr auto kAttrVisited = "visited";
  374. constexpr auto kAttrShape = "shape";
  375. constexpr auto kAttrMomentum = "momentum";
  376. constexpr auto kAttrEps = "eps";
  377. constexpr auto kAttrEpsilon = "epsilon";
  378. constexpr auto kAttrFactor = "factor";
  379. constexpr auto kAttrIsRef = "isRef";
  380. constexpr auto kAttrDataShape = "data_shape";
  381. constexpr auto kAttrFormat = "format";
  382. constexpr auto kAttrReshapeType = "reshape_type";
  383. constexpr auto kAttrAxis = "axis";
  384. constexpr auto kAttrAxes = "axes";
  385. constexpr auto kAttrKeepDims = "keep_dims";
  386. constexpr auto kAttrShapeGamma = "shape_gamma";
  387. constexpr auto kAttrPerm = "perm";
  388. constexpr auto kAttrTransposeFirst = "transpose_first";
  389. constexpr auto kAttrAtomicAddMemSize = "automic_add_mem_size";
  390. constexpr auto kAttrAtomicOutputIndexs = "atomic_output_clean_indexs";
  391. constexpr auto kAttrNeedAtomic = "need_atomic";
  392. constexpr auto kAttrAtomicWorkspaceIndexs = "atomic_workspace_clean_indexs";
  393. constexpr auto kAttrSwitchCondition = "switch_condition";
  394. constexpr auto kAttrDataType = "data_type";
  395. constexpr auto kAttrDType = "dtype";
  396. constexpr auto kAttrActiveTarget = "active_target";
  397. constexpr auto kAttrActiveStreamId = "active_stream_id";
  398. constexpr auto kAttrActiveStreamList = "active_stream_list";
  399. constexpr auto kAttrTrueBranchStream = "true_branch_stream";
  400. constexpr auto kAttrStreamSwitchKind = "stream_switch_kind";
  401. constexpr auto kAttrEventId = "event_id";
  402. constexpr auto kAttrLabelId = "label_id";
  403. constexpr auto kAttrLogicId = "logic_id";
  404. constexpr auto kAttrNodeInfo = "node_info";
  405. constexpr auto kAttrNodeName = "node_name";
  406. constexpr auto kAttrDynInput = "dynamic";
  407. constexpr auto kAttrDynInputSizes = "dyn_input_sizes";
  408. constexpr auto kAttrSrcFormat = "src_format";
  409. constexpr auto kAttrDstFormat = "dst_format";
  410. constexpr auto kAttrMultiples = "multiples";
  411. constexpr auto kAttrFixPrecision = "fix_precision";
  412. constexpr auto kAttrOutputPrecision = "output_precision";
  413. constexpr auto kAttrOutputUsedNum = "output_used_num";
  414. constexpr auto kAttrHasBias = "has_bias";
  415. constexpr auto kAttrN = "n";
  416. constexpr auto kAttrLabelForInsertStreamActive = "label_for_insert_stream_active";
  417. constexpr auto kAttrFpBpEnd = "fpbp_end";
  418. constexpr auto kAttrFusion = "fusion";
  419. constexpr auto kAttrNotDelayFusion = "not_delay_fusion";
  420. constexpr auto kAttrGroup = "group";
  421. constexpr auto kAttrGroups = "groups";
  422. constexpr auto kAttrGroupBack = "group_back";
  423. constexpr auto kAttrFracZGroup = "fracz_group";
  424. constexpr auto kAttrFracZGroupIdx = "fracz_group_idx";
  425. constexpr auto kAttrOp = "op";
  426. constexpr auto kAttrDestRank = "dest_rank";
  427. constexpr auto kAttrSrcRank = "src_rank";
  428. constexpr auto kAttrSrTag = "sr_tag";
  429. constexpr auto kAttrRootRank = "root_rank";
  430. constexpr auto kAttrIsTraining = "is_training";
  431. constexpr auto kAttrFusionId = "fusion_id";
  432. constexpr auto kAttrDuplicated = "duplicated";
  433. constexpr auto kAttrBucketId = "bucket_id";
  434. constexpr auto kAttrGradOutputIndex = "grad_output_index";
  435. constexpr auto kAttrLabelIndex = "label_index";
  436. constexpr auto kAttrLabelSwitchList = "label_switch_list";
  437. constexpr auto kAttrBeginMask = "begin_mask";
  438. constexpr auto kAttrEndMask = "end_mask";
  439. constexpr auto kAttrEllipsisMask = "ellipsis_mask";
  440. constexpr auto kAttrNewAxisMask = "new_axis_mask";
  441. constexpr auto kAttrShrinkAxisMask = "shrink_axis_mask";
  442. constexpr auto kAttrDatadumpOriginalNames = "_datadump_original_names";
  443. constexpr auto kAttrDatadumpIsMultiop = "_datadump_is_multiop";
  444. constexpr auto kAttrNeedRecordEvent = "need_record_event";
  445. constexpr auto kAttrStreamId = "stream_id";
  446. constexpr auto kAttrRecordEvent = "record_event";
  447. constexpr auto kAttrWaitEvent = "wait_event";
  448. constexpr auto kAttrRecordEventStream = "record_event_stream";
  449. constexpr auto kAttrWaitEventStream = "wait_event_stream";
  450. constexpr auto kAttrIndex = "index";
  451. constexpr auto kAttrSplitDim = "split_dim";
  452. constexpr auto kAttrNumSplit = "num_split";
  453. constexpr auto kAttrReduction = "reduction";
  454. constexpr auto kAttrOutputNum = "output_num";
  455. constexpr auto kAttrSizeSplits = "size_splits";
  456. constexpr auto kAttrOutputDefault = "output_default";
  457. constexpr auto kAttrPrimitiveTarget = "primitive_target";
  458. constexpr auto kAttrUseLocking = "use_locking";
  459. constexpr auto kAttrReduceScatterFlag = "reduce_scatter_flag";
  460. constexpr auto kAttrOffset = "offset";
  461. constexpr auto kAttrCacheEnable = "cache_enable";
  462. constexpr auto kAttrPsKey = "ps_key";
  463. constexpr auto kAttrOptimizerType = "optim_type";
  464. constexpr auto kAttrChildGraph = "child_graph";
  465. constexpr auto kAttrInputNums = "inputNums";
  466. constexpr auto kAttrT = "T";
  467. constexpr auto kAttrNum = "num";
  468. constexpr auto kAttrRecvType = "recv_type";
  469. constexpr auto kAttrConcatDim = "concat_dim";
  470. constexpr auto kAttrSplitCount = "split_count";
  471. constexpr auto kAttrSendRankIds = "send_rank_ids";
  472. constexpr auto kAttrRecvRankIds = "recv_rank_ids";
  473. constexpr auto kAttrSendLens = "send_lens";
  474. constexpr auto kAttrRecvLens = "recv_lens";
  475. constexpr auto kAttrRankSize = "rank_size";
  476. constexpr auto kAttrPadDimSize = "pad_dim_size";
  477. constexpr auto kAttrPaddings = "paddings";
  478. constexpr auto kAttrNumSegments = "num_segments";
  479. constexpr auto kAttrStackOpName = "stack_op_name";
  480. constexpr auto kAttrBegin = "begin";
  481. constexpr auto kAttrEnd = "end";
  482. constexpr auto kAttrSize = "size";
  483. constexpr auto kAttrIsDynamicShape = "is_dynamic_shape";
  484. constexpr auto kAttrInputIsDynamicShape = "input_is_dynamic_shape";
  485. constexpr auto kAttrOutputIsDynamicShape = "output_is_dynamic_shape";
  486. constexpr auto kAttrPynativeNextOpName = "next_op";
  487. constexpr auto kAttrPynativeNextIndex = "next_index";
  488. constexpr auto kAttrCompileInfo = "compile_info";
  489. constexpr auto kAttrFusionType = "fusion_type";
  490. constexpr auto kAttrStride = "stride";
  491. constexpr auto kAttrStrides = "strides";
  492. constexpr auto kAttrKernelSize = "kernel_size";
  493. constexpr auto kAttrDilation = "dilation";
  494. constexpr auto kAttrPadMode = "pad_mode";
  495. constexpr auto kAttrPad = "pad";
  496. constexpr auto kAttrPadding = "padding";
  497. constexpr auto kAttrNonTask = "non_task";
  498. constexpr auto kAttrIsGrad = "is_grad";
  499. constexpr auto kAttrRecompute = "recompute";
  500. constexpr auto kAttrSliceActivation = "slice_activation";
  501. constexpr auto kAttrNeedCseAfterRecompute = "need_cse_after_recompute";
  502. constexpr auto kAttrParallelDimInfo = "parallel_dim_info";
  503. constexpr auto kAttrParallelFusionType = "parallel_fusion_type";
  504. constexpr auto kAttrParallelTypeInfo = "parallel_type_info";
  505. constexpr auto kAttrCompositeType = "composite_type";
  506. constexpr auto kAttrStitch = "stitch";
  507. constexpr auto kAttrTopoSortRhsFirst = "topo_sort_rhs_first";
  508. constexpr auto kAttrIgnoreSideEffect = "ignore_side_effect";
  509. constexpr auto kAttrSwitchLayer = "switch_layer";
  510. constexpr auto kAttrReturn = "return";
  511. constexpr auto kAttrRecursiveStart = "recursive_start";
  512. constexpr auto kAttrRecursiveEnd = "recursive_end";
  513. constexpr auto kAttrRecursive = "recursive";
  514. constexpr auto kAttrMultiCallEnd = "multicall_end";
  515. constexpr auto kAttrProfilingIterEnd = "PROFILING_ITER_END";
  516. constexpr auto kAttrHiddenSize = "hidden_size";
  517. constexpr auto kAttrInputSize = "input_size";
  518. constexpr auto kAttrDstType = "dst_type";
  519. constexpr auto kAttrDump = "dump";
  520. constexpr auto kAttrSkipNopOpAddr = "skip_nop_op_addr";
  521. constexpr auto kAttrSkipNopOpExecution = "skip_nop_op_execution";
  522. constexpr auto kAttrFixedInputFormat = "fixed_input_format";
  523. constexpr auto kAttrFixedOutputFormat = "fixed_output_format";
  524. constexpr auto kAttrFixedInputDeviceShape = "fixed_input_device_shape";
  525. constexpr auto kAttrFixedOutputDeviceShape = "fixed_output_device_shape";
  526. constexpr auto kAttrFuncType = "func_type";
  527. constexpr auto kAttrCustAicpu = "cust_aicpu";
  528. constexpr auto kAttrIsInternalOutputNopNode = "is_internal_output_nop_node";
  529. constexpr auto kAttrIsUBFusionOp = "is_ub_fusion_op";
  530. constexpr auto kAttrNopOp = "nop_op";
  531. constexpr auto kAttrPlaceHolderIndex = "placeholder_index";
  532. constexpr auto kAttrMicro = "micro";
  533. constexpr auto kAttrJsonFileName = "json_file_name";
  534. constexpr auto kAttrNeedDropInput = "need_drop_input";
  535. constexpr auto kAttrNeedConvertToValueNode = "need_convert_to_value_node";
  536. constexpr auto kAttrSendSrcNodeName = "send_src_node_name";
  537. constexpr auto kAttrSendDstNodeName = "send_dst_node_name";
  538. constexpr auto kAttrSendDstRanks = "send_dst_ranks";
  539. constexpr auto kAttrSendDstRoles = "send_dst_roles";
  540. constexpr auto kAttrRecvSrcNodeName = "recv_src_node_name";
  541. constexpr auto kAttrRecvDstNodeName = "recv_dst_node_name";
  542. constexpr auto kAttrRecvSrcRanks = "recv_src_ranks";
  543. constexpr auto kAttrRecvSrcRoles = "recv_src_roles";
  544. constexpr auto kAttrInterProcessEdgeName = "inter_process_edge_name";
  545. constexpr auto kAttrForwardOpOutputId = "forward_op_output_id";
  546. constexpr auto kAttrGroupRankIds = "group_rank_ids";
  547. // TODO(dsj): for ms_function running in graph_mode. should be delete later
  548. constexpr auto kAttrMSFunction = "ms_function_graph";
  549. // for single_op_compile_and_run condition and set_context GraphMode. should be delete later
  550. constexpr auto kAttrSingleOpCompile = "compile_and_run_in_single_op";
  551. // custom operator func type
  552. constexpr auto kCustomTypeAOT = "aot";
  553. constexpr auto kCustomTypeJULIA = "julia";
  554. constexpr auto kCustomTypePyfunc = "pyfunc";
  555. constexpr auto kCustomTypeTbe = "tbe";
  556. constexpr auto kCustomTypeAICPU = "aicpu";
  557. constexpr auto kCustomTypeHybrid = "hybrid";
  558. const std::set<std::string> kCustomTypeAkg = {"ir_builder", "tvm_compute", "hybrid"};
  559. // primal attr key name
  560. constexpr auto kPrimalAttrForwardNodeName = "forward_node_name";
  561. // attr value
  562. constexpr auto kValueTargetSwitch = "target_switch";
  563. constexpr auto kValueTargetOther = "target_other";
  564. constexpr auto kValueTrue = "true";
  565. // env key
  566. constexpr auto kGraphOpRun = "GRAPH_OP_RUN";
  567. // some size
  568. const size_t kShape4dDims = 4;
  569. const size_t kShape3dDims = 3;
  570. const size_t kShape2dDims = 2;
  571. const size_t kShape5dDims = 5;
  572. const size_t kShape1dDims = 1;
  573. const size_t kCubeSize = 16;
  574. const size_t kCubeSize_C04 = 4;
  575. const size_t kNiSize = 16;
  576. const size_t kMemAlignSize = 512;
  577. const size_t kBNChannelMultipleFactor = 4;
  578. const int kParameterDataTensorMask = 0;
  579. const int kParameterWeightTensorMask = 1;
  580. const int kValueNodeTensorMask = 2;
  581. constexpr auto kNCHWShapeSize = 4;
  582. // define special index in special node
  583. constexpr auto kDefaultStreamIndex = 0;
  584. constexpr auto kIndependentStreamIndex = 1;
  585. constexpr auto kWorldGroupStreamIndex = 2;
  586. constexpr auto kAnfPrimitiveIndex = 0;
  587. constexpr auto kFirstDataInputIndex = 1;
  588. constexpr auto kRealInputNodeIndexInTupleGetItem = 1;
  589. constexpr auto kInputNodeOutputIndexInTupleGetItem = 2;
  590. constexpr auto kTupleGetItemInputSize = 3;
  591. // index define of partial
  592. constexpr auto kPartialMinInputSize = 2;
  593. constexpr auto kPartialGraphIndex = 1;
  594. // index define of switch
  595. constexpr auto kSwitchInputSize = 4;
  596. constexpr auto kSwitchTrueBranchIndex = 2;
  597. constexpr auto kSwitchFalseBranchIndex = 3;
  598. constexpr auto kSwitchBranchesNum = 2;
  599. // index define of switch_layer
  600. constexpr auto kSwitchLayerInputSize = 3;
  601. constexpr auto kSwitchLayerSelectIndex = 1;
  602. constexpr auto kSwitchLayerBranchesIndex = 2;
  603. // index define of depend
  604. constexpr auto kRealInputIndexInDepend = 1;
  605. constexpr auto kDependAttachNodeIndex = 2;
  606. constexpr auto kDependInputSize = 3;
  607. // index define of UpdateState
  608. constexpr auto kUpdateStateStateInput = 1;
  609. constexpr auto kUpdateStateRealInput = 2;
  610. // index define of Load
  611. constexpr auto kLoadRealInput = 1;
  612. constexpr auto kLoadStateInput = 2;
  613. // time transfer unit
  614. constexpr int kBasicTimeTransferUnit = 1000;
  615. constexpr int kMaxVectorSize = 10000;
  616. // index of input or output
  617. constexpr size_t kIndex0 = 0;
  618. constexpr size_t kIndex1 = 1;
  619. constexpr size_t kIndex2 = 2;
  620. constexpr size_t kIndex3 = 3;
  621. constexpr size_t kIndex4 = 4;
  622. constexpr size_t kIndex5 = 5;
  623. constexpr size_t kIndex6 = 6;
  624. constexpr size_t kIndex7 = 7;
  625. constexpr size_t kIndex8 = 8;
  626. constexpr size_t kIndex9 = 9;
  627. constexpr size_t kIndex10 = 10;
  628. constexpr size_t kIndex11 = 11;
  629. constexpr size_t kIndex12 = 12;
  630. constexpr size_t kIndex13 = 13;
  631. constexpr size_t kIndex14 = 14;
  632. constexpr size_t kIndex15 = 15;
  633. constexpr size_t kIndex16 = 16;
  634. // dim of shape
  635. constexpr size_t kDim0 = 0;
  636. constexpr size_t kDim1 = 1;
  637. constexpr size_t kDim2 = 2;
  638. constexpr size_t kDim3 = 3;
  639. constexpr size_t kDim4 = 4;
  640. constexpr size_t kDim5 = 5;
  641. constexpr size_t kDim6 = 6;
  642. // format
  643. constexpr auto kOpFormat_DEFAULT = "DefaultFormat";
  644. constexpr auto kOpFormat_ChannelFirst = "ChannelFirst";
  645. constexpr auto kOpFormat_ChannelLast = "ChannelLast";
  646. constexpr auto kOpFormat_NC1KHKWHWC0 = "NC1KHKWHWC0";
  647. constexpr auto kOpFormat_ND = "ND";
  648. constexpr auto kOpFormat_NCHW = "NCHW";
  649. constexpr auto kOpFormat_NHWC = "NHWC";
  650. constexpr auto kOpFormat_HWCN = "HWCN";
  651. constexpr auto kOpFormat_NC1HWC0 = "NC1HWC0";
  652. constexpr auto kOpFormat_FRAC_Z = "FracZ";
  653. constexpr auto kOpFormat_FRACTAL_Z = "FRACTAL_Z";
  654. constexpr auto kOpFormat_FRAC_NZ = "FRACTAL_NZ";
  655. constexpr auto kOpFormat_C1HWNCoC0 = "C1HWNCoC0";
  656. constexpr auto kOpFormat_NC1HWC0_C04 = "NC1HWC0_C04";
  657. constexpr auto kOpFormat_FRACTAL_Z_C04 = "FRACTAL_Z_C04";
  658. constexpr auto kOpFormat_NDHWC = "NDHWC";
  659. constexpr auto kOpFormat_NCDHW = "NCDHW";
  660. constexpr auto kOpFormat_DHWNC = "DHWNC";
  661. constexpr auto kOpFormat_DHWCN = "DHWCN";
  662. constexpr auto kOpFormat_NDC1HWC0 = "NDC1HWC0";
  663. constexpr auto kOpFormat_FRACTAL_Z_3D = "FRACTAL_Z_3D";
  664. constexpr auto kOpFormat_FRACTAL_ZN_LSTM = "FRACTAL_ZN_LSTM";
  665. constexpr auto kOpFormat_FRACTAL_ZN_RNN = "FRACTAL_ZN_RNN";
  666. constexpr auto kOpFormat_ND_RNN_BIAS = "ND_RNN_BIAS";
  667. const std::set<std::string> kOpFormatList = {kOpFormat_DEFAULT,
  668. kOpFormat_NC1KHKWHWC0,
  669. kOpFormat_ND,
  670. kOpFormat_NCHW,
  671. kOpFormat_NHWC,
  672. kOpFormat_HWCN,
  673. kOpFormat_NC1HWC0,
  674. kOpFormat_FRAC_Z,
  675. kOpFormat_C1HWNCoC0,
  676. kOpFormat_FRAC_NZ,
  677. kOpFormat_NC1HWC0_C04,
  678. kOpFormat_FRACTAL_Z_C04,
  679. kOpFormat_NDHWC,
  680. kOpFormat_FRACTAL_ZN_LSTM,
  681. kOpFormat_FRACTAL_ZN_RNN,
  682. kOpFormat_ND_RNN_BIAS,
  683. kOpFormat_NDC1HWC0,
  684. kOpFormat_NCDHW,
  685. kOpFormat_FRACTAL_Z_3D,
  686. kOpFormat_DHWNC,
  687. kOpFormat_DHWCN};
  688. constexpr auto kSliceStart = "start";
  689. constexpr auto kSliceStop = "stop";
  690. constexpr auto kSliceStep = "step";
  691. const std::map<std::string, size_t> kSliceAttrToIndex = {{kSliceStart, 1}, {kSliceStop, 2}, {kSliceStep, 3}};
  692. const std::set<std::string> kDefaultCompatibleFormat = {kOpFormat_ND, kOpFormat_NCHW, kOpFormat_NHWC, kOpFormat_HWCN,
  693. kOpFormat_NCDHW};
  694. const std::set<std::string> kOptOperatorSet = {kMomentumOpName,
  695. kApplyMomentumOpName,
  696. kApplyAdadeltaOpName,
  697. kApplyAdagradOpName,
  698. kApplyAdagradDAName,
  699. kApplyAdamOpName,
  700. kApplyAdaMaxOpName,
  701. kApplyAddSignOpName,
  702. kApplyCenteredRMSPOpName,
  703. kApplyFtrlOpName,
  704. kApplyFtrlV2OpName,
  705. kApplyGradientDescentOpName,
  706. kApplyPowerSignOpName,
  707. kApplyProximalAdagradOpName,
  708. kApplyProximalGradientDescentOpName,
  709. kApplyRMSPropOpName,
  710. kAdamApplyOneWithDecayOpName,
  711. kAdamApplyOneWithDecayAssignOpName,
  712. kFusedAdamWeightDecayName,
  713. kAdamWeightDecayName,
  714. kFusedCastAdamWeightDecayName,
  715. kFusedAdamName,
  716. kFusedAdaFactorName,
  717. kFusedAdaFactorWithGlobalNormName,
  718. kFusedSparseAdamName,
  719. kFusedMulApplyMomentumOpName,
  720. kFusedWeightScaleApplyMomentum,
  721. kFusedScaleApplyMomentum,
  722. kApplyCenteredRMSPropOpName,
  723. kFusedSparseFtrlName,
  724. kFusedSparseProximalAdagradName,
  725. kFusedSparseLazyAdamName,
  726. kSparseApplyFtrlName,
  727. kSparseApplyFtrlV2Name,
  728. kSGDName,
  729. kLARSUpdateName,
  730. kCombineMomentumWeightOpName,
  731. kCombineMomentumOpName,
  732. kScatterAddOpName,
  733. kScatterUpdateOpName,
  734. kSparseApplyProximalAdagradOpName};
  735. const std::set<std::string> kNodeWithSeedOperators = {kGammaOpName, kPoissonOpName, kStandardLaplaceOpName,
  736. kStandardNormalOpName, kUniformIntOpName, kUniformRealOpName};
  737. const std::set<std::string> kPosteriorOperatorSet = {kPullOpName};
  738. const std::set<std::string> kOpCacheBlackList = {kUniformCandidateSamplerOpName, kInitDatasetQueueOpName,
  739. kGetNextOpName};
  740. const std::set<std::string> kOpNotSupportMultiThreadExecList = {kAvgPoolOpName, kAvgPoolGradOpName, kMaxPoolOpName,
  741. kBatchNorm, kBatchNormGradOpName};
  742. const std::set<std::string> kHWSpecialFormatSet = {
  743. kOpFormat_FRACTAL_Z_3D, kOpFormat_NC1KHKWHWC0, kOpFormat_NC1HWC0, kOpFormat_FRAC_NZ,
  744. kOpFormat_C1HWNCoC0, kOpFormat_NC1HWC0_C04, kOpFormat_FRACTAL_Z_C04, kOpFormat_FRACTAL_ZN_LSTM,
  745. kOpFormat_FRACTAL_ZN_RNN, kOpFormat_NDC1HWC0, kOpFormat_FRAC_Z};
  746. const std::set<TypeId> kFloatDataTypeSet = {kNumberTypeFloat16, kNumberTypeFloat32};
  747. const std::set<std::string> kComputeDepend = {
  748. kUniqueOpName, kComputeAccidentalHitsOpName, kSubAndFilterOpName, kPadAndShiftOpName,
  749. kCTCGreedyDecoderOpName, kDropoutGenMaskOpName, kMaskedSelectOpName, kDynamicStitchOpName,
  750. kGetNextOpName, kNonMaxSuppressionV3OpName, kCoalesceOpName};
  751. const std::set<std::string> k3DFormatSet = {kOpFormat_NCDHW, kOpFormat_NDC1HWC0, kOpFormat_FRACTAL_Z_3D,
  752. kOpFormat_NDHWC, kOpFormat_DHWCN, kOpFormat_DHWNC};
  753. const std::set<std::string> kNoPaddingFormatSet = {kOpFormat_ChannelLast, kOpFormat_FRAC_NZ, kOpFormat_FRACTAL_ZN_RNN,
  754. kOpFormat_ND_RNN_BIAS};
  755. const std::set<std::string> DynamicShapeConstInputToAttr = {kCastOpName, kExpandDimsOpName, kEmbeddingLookupOpName,
  756. kReduceMinOpName, kReduceMeanOpName, kReduceMaxOpName,
  757. kReduceAllOpName, kReduceAnyOpName, kConcatOpName};
  758. const std::set<std::string> NeedConvertToValueNodeSet = {kStridedSliceGradOpName};
  759. const std::set<std::string> DynamicShapeConstInputToAttrCPU = {
  760. kCastOpName, kExpandDimsOpName, kEmbeddingLookupOpName, kReduceMinOpName, kReduceMeanOpName,
  761. kReduceMaxOpName, kReduceAllOpName, kReduceAnyOpName, kConcatOpName, kReduceSumOpName};
  762. const std::set<std::string> DynamicShapeConstInputToAttrGPU = {kCastOpName,
  763. kExpandDimsOpName,
  764. kReshapeOpName,
  765. kEmbeddingLookupOpName,
  766. kTransposeOpName,
  767. kReduceSumOpName,
  768. kReduceMinOpName,
  769. kReduceMeanOpName,
  770. kReduceMaxOpName,
  771. kReduceAllOpName,
  772. kReduceAnyOpName,
  773. kConcatOpName,
  774. kConv2DBackpropFilterOpName};
  775. // The map between kernel's output and input ref relationship.
  776. // Key is the output index while the value is input index which will be used as the reference of output.
  777. using OutputInputRefMap = std::map<size_t, size_t>;
  778. static inline void ChangeFileMode(const std::string &file_name, mode_t mode) {
  779. if (access(file_name.c_str(), F_OK) == -1) {
  780. return;
  781. }
  782. try {
  783. if (chmod(common::SafeCStr(file_name), mode) != 0) {
  784. MS_LOG(WARNING) << "Change file `" << file_name << "` to mode " << std::oct << mode << " fail.";
  785. }
  786. } catch (std::exception &e) {
  787. MS_LOG(WARNING) << "File `" << file_name << "` change mode failed! May be not exist.";
  788. }
  789. }
  790. static inline uint64_t GetCurrentUSec() {
  791. struct timeval tv;
  792. int ret = gettimeofday(&tv, nullptr);
  793. if (ret != 0) {
  794. MS_LOG(EXCEPTION) << "Fail gettimeofday, ret = " << ret;
  795. }
  796. return static_cast<uint64_t>(tv.tv_usec + tv.tv_sec * 1000000);
  797. }
  798. #define PROF_START(stage) uint64_t start_usec_##stage = mindspore::GetCurrentUSec()
  799. #define PROF_END(stage) \
  800. do { \
  801. uint64_t end_usec_##stage = mindspore::GetCurrentUSec(); \
  802. MS_LOG(INFO) << "[PROF]" << #stage << " costs " << (end_usec_##stage - start_usec_##stage) << " usec."; \
  803. } while (0)
  804. #define PROF_MULTI_DEFINE(stage) \
  805. do { \
  806. static uint64_t total_##stage = 0; \
  807. static uint64_t count_##stage = 0; \
  808. } while (0)
  809. #define PROF_LOCAL_DEFINE(stage) \
  810. do { \
  811. uint64_t total_##stage = 0; \
  812. uint64_t count_##stage = 0; \
  813. } while (0)
  814. #define PROF_MULTI_START(stage) uint64_t start_usec_##stage = mindspore::GetCurrentUSec()
  815. #define PROF_MULTI_END(stage) \
  816. do { \
  817. ++count_##stage; \
  818. uint64_t end_usec_##stage = mindspore::GetCurrentUSec(); \
  819. total_##stage += (end_usec_##stage - start_usec_##stage); \
  820. } while (0)
  821. #define PROF_MULTI_PRINT(stage) \
  822. do { \
  823. MS_LOG(INFO) << #stage << " called " << count_##stage << " times, costs " << total_##stage << " usec."; \
  824. } while (0)
  825. } // namespace mindspore
  826. #endif // MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_UTILS_H_