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 21 kB

5 years ago
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /**
  2. * Copyright 2019 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_UTILS_UTILS_H_
  17. #define MINDSPORE_CCSRC_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 "utils/log_adapter.h"
  26. #include "ir/dtype/type.h"
  27. namespace mindspore {
  28. // op name. Op which not exists in operator/ops.h, so define it's name here
  29. constexpr auto kFour2FiveOpName = "Four2Five";
  30. constexpr auto kFive2FourOpName = "Five2Four";
  31. constexpr auto kConv2DOpName = "Conv2D";
  32. constexpr auto kConvBN1OpName = "ConvBN1";
  33. constexpr auto kBN2AddReluOpName = "BN2AddRelu";
  34. constexpr auto kBN2ReLUOpName = "BN2Relu";
  35. constexpr auto kBN2OpName = "BN2";
  36. constexpr auto kFusedBN1OpName = "FusedBN1";
  37. constexpr auto kFusedBN2OpName = "FusedBN2";
  38. constexpr auto kFusedBN3OpName = "FusedBN3";
  39. constexpr auto kBNGrad1OpName = "BNGrad1";
  40. constexpr auto kBNGrad2OpName = "BNGrad2";
  41. constexpr auto kBNGrad3OpName = "BNGrad3";
  42. constexpr auto kFusedBatchNormEx = "FusedBatchNormEx";
  43. constexpr auto kFusedBatchNormExWithActivation = "FusedBatchNormExWithActivation";
  44. constexpr auto kFusedBatchNormExWithAddAndActivation = "FusedBatchNormExWithAddAndActivation";
  45. constexpr auto kFusedBatchNormGradEx = "FusedBatchNormGradEx";
  46. constexpr auto kFusedBatchNormGradExWithActivation = "FusedBatchNormGradExWithActivation";
  47. constexpr auto kFusedBatchNormGradExWithAddAndActivation = "FusedBatchNormGradExWithAddAndActivation";
  48. constexpr auto kClearZeroOpName = "ClearZero";
  49. constexpr auto kAtomicAddrCleanOpName = "AtomicAddrClean";
  50. constexpr auto kGetNextOpName = "GetNext";
  51. constexpr auto kEndOfSequence = "EndOfSequence";
  52. constexpr auto kAllReduceOpName = "AllReduce";
  53. constexpr auto kAllGatherOpName = "AllGather";
  54. constexpr auto kHostAllGatherOpName = "HostAllGather";
  55. constexpr auto kBroadcastOpName = "Broadcast";
  56. constexpr auto kReduceScatterOpName = "ReduceScatter";
  57. constexpr auto kHostReduceScatterOpName = "HostReduceScatter";
  58. constexpr auto kMemCpyAsyncOpName = "memcpy_async";
  59. constexpr auto kTopKOpName = "TopK";
  60. constexpr auto kExtractImagePatchesOpName = "ExtractImagePatches";
  61. constexpr auto kBNTrainingReduceOpName = "BNTrainingReduce";
  62. constexpr auto kBNTrainingUpdateOpName = "BNTrainingUpdate";
  63. constexpr auto kBNTrainingUpdateV2OpName = "BNTrainingUpdateV2";
  64. constexpr auto kBNTrainingUpdateV3OpName = "BNTrainingUpdateV3";
  65. constexpr auto kSimpleMeanGradOpName = "SimpleMeanGrad";
  66. constexpr auto kMeanGradOpName = "MeanGrad";
  67. constexpr auto kSliceOpName = "Slice";
  68. constexpr auto kSliceGradOpName = "SliceGrad";
  69. constexpr auto kTileOpName = "Tile";
  70. constexpr auto kScatterNdOpName = "ScatterNd";
  71. constexpr auto kStridedSliceAssignOpName = "StridedSliceAssign";
  72. constexpr auto kStridedSliceOpName = "StridedSlice";
  73. constexpr auto kStridedSliceGradOpName = "StridedSliceGrad";
  74. constexpr auto kSparseGatherV2 = "SparseGatherV2";
  75. constexpr auto kUnsortedSegmentProdOpName = "UnsortedSegmentProd";
  76. constexpr auto kUnsortedSegmentMinOpName = "UnsortedSegmentMin";
  77. constexpr auto kFlattenGradOpName = "FlattenGrad";
  78. constexpr auto kExpandDimsOpName = "ExpandDims";
  79. constexpr auto kSplitOpName = "Split";
  80. constexpr auto kSplitVOpName = "SplitV";
  81. constexpr auto kSparseApplyAdagradOpName = "SparseApplyAdagrad";
  82. constexpr auto kMomentumOpName = "Momentum";
  83. constexpr auto kApplyMomentumOpName = "ApplyMomentum";
  84. constexpr auto kApplyAdadeltaOpName = "ApplyAdadelta";
  85. constexpr auto kApplyAdagradOpName = "ApplyAdagrad";
  86. constexpr auto kApplyAdagradDAName = "ApplyAdagradDA";
  87. constexpr auto kApplyAdamOpName = "Adam";
  88. constexpr auto kApplyAdaMaxOpName = "ApplyAdaMax";
  89. constexpr auto kApplyAddSignOpName = "ApplyAddSign";
  90. constexpr auto kApplyCenteredRMSPOpName = "ApplyCenteredRMSP";
  91. constexpr auto kApplyCenteredRMSPropOpName = "ApplyCenteredRMSProp";
  92. constexpr auto kApplyFtrlOpName = "ApplyFtrl";
  93. constexpr auto kApplyFtrlV2OpName = "ApplyFtrlV2";
  94. constexpr auto kApplyGradientDescentOpName = "ApplyGradientDescent";
  95. constexpr auto kApplyPowerSignOpName = "ApplyPowerSign";
  96. constexpr auto kApplyProximalAdagradOpName = "ApplyProximalAdagrad ";
  97. constexpr auto kApplyProximalGradientDescentOpName = "ApplyProximalGradientDescent";
  98. constexpr auto kApplyRMSPropOpName = "ApplyRMSProp";
  99. constexpr auto kTransDataOpName = "TransData";
  100. constexpr auto kBNTrainingUpdateGradOpName = "BNTrainingUpdateGrad";
  101. constexpr auto kBNTrainingReduceGradOpName = "BNTrainingReduceGrad";
  102. constexpr auto kSquareSumV1OpName = "SquareSumV1";
  103. constexpr auto kSquareSumV2OpName = "SquareSumV2";
  104. constexpr auto kClipByNormNoDivSumOpName = "ClipByNormNoDivSum";
  105. constexpr auto kGreaterOpName = "Greater";
  106. constexpr auto kSqrtOpName = "Sqrt";
  107. constexpr auto kRsqrtOpName = "Rsqrt";
  108. constexpr auto kErfOpName = "Erf";
  109. constexpr auto kRealDivOpName = "RealDiv";
  110. constexpr auto kLambUpdateWithLROpName = "LambUpdateWithLR";
  111. constexpr auto kLambNextMVWithDecayOpName = "LambNextMVWithDecay";
  112. constexpr auto kLambNextMVWithDecayV1OpName = "LambNextMVWithDecayV1";
  113. constexpr auto kClipByValueOpName = "ClipByValue";
  114. constexpr auto kLambNextRightOpName = "LambNextRight";
  115. constexpr auto kConfusionSoftmaxGradOpName = "ConfusionSoftmaxGrad";
  116. constexpr auto kLambUpdateWithLrV2OpName = "LambUpdateWithLrV2";
  117. constexpr auto kLayerNormXBackpropOpName = "LayerNormXBackprop";
  118. constexpr auto kLayerNormBetaGammaBackpropOpName = "LayerNormBetaGammaBackprop";
  119. constexpr auto kLambNextMVOpName = "LambNextMV";
  120. constexpr auto kConfusionTransposeDOpName = "ConfusionTransposeD";
  121. constexpr auto kAdamApplyOneWithDecayOpName = "AdamApplyOneWithDecay";
  122. constexpr auto kAdamApplyOneWithDecayAssignOpName = "AdamApplyOneWithDecayAssign";
  123. constexpr auto kBatchNormGradOpName = "BatchNormGrad";
  124. constexpr auto kBNInferOpName = "BNInfer";
  125. constexpr auto kAdamApplyOneOpName = "AdamApplyOne";
  126. constexpr auto kAdamApplyOneAssignOpName = "AdamApplyOneAssign";
  127. constexpr auto kResizeNearestNeighborGradOpName = "ResizeNearestNeighborGrad";
  128. constexpr auto kFusedMulAddOpName = "FusedMulAdd";
  129. constexpr auto kFusedMulAddNOpName = "FusedMulAddN";
  130. constexpr auto kFusedMulApplyMomentumOpName = "FusedMulApplyMomentum";
  131. constexpr auto kBiasAddOpName = "BiasAdd";
  132. constexpr auto kConfusionMulGradOpName = "ConfusionMulGrad";
  133. constexpr auto kStreamSwitchOpName = "StreamSwitch";
  134. constexpr auto kStreamActiveOpName = "StreamActive";
  135. constexpr auto kAssignAddOpName = "AssignAdd";
  136. constexpr auto kSendOpName = "Send";
  137. constexpr auto kRecvOpName = "Recv";
  138. constexpr auto kReluV2OpName = "ReLUV2";
  139. constexpr auto kReluGradV2OpName = "ReluGradV2";
  140. constexpr auto kAddNOpName = "AddN";
  141. constexpr auto kResizeNearestNeighborV2OpName = "ResizeNearestNeighborV2";
  142. constexpr auto kResizeNearestNeighborV2GradOpName = "ResizeNearestNeighborV2Grad";
  143. constexpr auto kApplyRMSPropOpname = "ApplyRMSProp";
  144. constexpr auto kCumsumOpName = "Cumsum";
  145. constexpr auto kInplaceAddOpName = "InplaceAdd";
  146. constexpr auto kInplaceSubOpName = "InplaceSub";
  147. constexpr auto kResizeBilinearV2OpName = "kResizeBilinearV2";
  148. constexpr auto kReduceProdOpName = "ReduceProd";
  149. constexpr auto kCumprodOpName = "Cumprod";
  150. constexpr auto kSpaceToBatchOpName = "SpaceToBatch";
  151. constexpr auto kBatchToSpaceOpName = "BatchToSpace";
  152. constexpr auto kPadOpName = "Pad";
  153. constexpr auto kConv2DBackpropInputOpName = "Conv2DBackpropInput";
  154. constexpr auto kFusionOpConv2DBackpropInputReluGradV2Name = "FusionOp_Conv2DBackpropInput_ReluGradV2";
  155. constexpr auto kFusionOpConv2DBackpropInputAddNReluGradV2Name = "FusionOp_Conv2DBackpropInput_AddN_ReluGradV2";
  156. constexpr auto kLabelSetOpName = "LabelSet";
  157. constexpr auto kLabelSwitchOpName = "LabelSwitch";
  158. constexpr auto kLabelGotoOpName = "LabelGoto";
  159. constexpr auto kBNInferGradOpName = "BNInferGrad";
  160. constexpr auto kCallOpName = "call";
  161. constexpr auto kPartialOpName = "partial";
  162. constexpr auto kSwitchOpName = "switch";
  163. constexpr auto kReturnOpName = "return";
  164. constexpr auto kLarsV2OpName = "LarsV2";
  165. constexpr auto kLarsV2UpdateOpName = "LarsV2Update";
  166. constexpr auto kSquareSumAllOpName = "SquareSumAll";
  167. constexpr auto kNMSWithMaskOpName = "NMSWithMask";
  168. constexpr auto kSoftmaxGradExtOpName = "SoftmaxGradExt";
  169. constexpr auto kStridedReadOpName = "StridedRead";
  170. constexpr auto kStridedWriteOpName = "StridedWrite";
  171. constexpr auto kFusedAdamWeightDecayName = "FusedAdamWeightDecay";
  172. constexpr auto kFusedAdamName = "FusedAdam";
  173. constexpr auto kApplyAdagradV2OpName = "ApplyAdagradV2";
  174. constexpr auto kSparseApplyAdagradV2OpName = "SparseApplyAdagradV2";
  175. constexpr auto kSparseApplyFtrlOpName = "SparseApplyFtrl";
  176. constexpr auto kSparseApplyFtrlV2OpName = "SparseApplyFtrlV2";
  177. constexpr auto kApplyKerasMomentumOpName = "ApplyKerasMomentum";
  178. constexpr auto kSparseApplyProximalAdagradOpName = "SparseApplyProximalAdagrad";
  179. constexpr auto kSparseApplyRMSPropOpName = "SparseApplyRMSProp";
  180. constexpr auto kSparseApplyAdadeltaOpName = "SparseApplyAdadelta";
  181. constexpr auto kApplyAdamWithAmsgradOpName = "ApplyAdamWithAmsgrad";
  182. constexpr auto kTensorMoveOpName = "TensorMove";
  183. constexpr auto kTensorScatterUpdateOpName = "TensorScatterUpdate";
  184. constexpr auto kScatterNdUpdateOpName = "ScatterNdUpdate";
  185. constexpr auto kPushOpName = "Push";
  186. constexpr auto kPullOpName = "Pull";
  187. constexpr auto kEmbeddingLookupOpName = "EmbeddingLookup";
  188. constexpr auto kEmbeddingLookupProxyOpName = "EmbeddingLookupProxy";
  189. constexpr auto kPaddingOpName = "Padding";
  190. constexpr auto kAvgPoolOpName = "AvgPool";
  191. constexpr auto kAvgPoolGradGpuOpName = "AvgPoolGradGpu";
  192. constexpr auto kmaxPoolGradOpName = "MaxPoolGrad";
  193. constexpr auto kTensorAddOpName = "TensorAdd";
  194. constexpr auto kCastOpName = "Cast";
  195. constexpr auto kGreaterEqualOpName = "GreaterEqual";
  196. constexpr auto kAbsOpName = "Abs";
  197. constexpr auto kExpOpName = "Exp";
  198. constexpr auto kNegOpName = "Neg";
  199. constexpr auto kMinimumOpName = "Minimum";
  200. constexpr auto kMaximumOpName = "Maximum";
  201. constexpr auto kMulOpName = "Mul";
  202. constexpr auto kSubOpName = "Sub";
  203. constexpr auto kLogOpName = "Log";
  204. constexpr auto kPowOpName = "Pow";
  205. constexpr auto kReciprocalOpName = "Reciprocal";
  206. constexpr auto kEqualOpName = "Equal";
  207. constexpr auto kLessOpName = "Less";
  208. constexpr auto kLessEqualOpName = "LessEqual";
  209. constexpr auto kSquareOpName = "Square";
  210. constexpr auto kSelectOpName = "Select";
  211. constexpr auto kReduceSumOpName = "ReduceSum";
  212. constexpr auto kReduceMinOpName = "ReduceMin";
  213. constexpr auto kReduceMaxOpName = "ReduceMax";
  214. constexpr auto kFusedWeightScaleApplyMomentum = "FusedWeightScaleApplyMomentum";
  215. constexpr auto kFusedScaleApplyMomentum = "FusedScaleApplyMomentum";
  216. constexpr auto kBasicLSTMCellWeightGradOpName = "BasicLSTMCellWeightGrad";
  217. constexpr auto kBasicLSTMCellInputGradOpName = "BasicLSTMCellInputGrad";
  218. constexpr auto kBasicLSTMCellOpName = "BasicLSTMCell";
  219. constexpr auto kDynamicRNNOpName = "DynamicRNN";
  220. constexpr auto kLSTMInputGradOpName = "LSTMInputGrad";
  221. // Hcom Op Type
  222. constexpr auto kHcomOpTypeAllReduce = "HcomAllReduce";
  223. constexpr auto kHcomOpTypeAllGather = "HcomAllGather";
  224. constexpr auto kHcomOpTypeBroadcast = "HcomBroadcast";
  225. constexpr auto kHcomOpTypeReduceScatter = "HcomReduceScatter";
  226. // attr key name
  227. constexpr auto kAttrInputNames = "input_names";
  228. constexpr auto kAttrIsAICPUKernel = "is_AICPU_kernel";
  229. constexpr auto kIsBackendCast = "is_backed_cast";
  230. constexpr auto kAttrOutputNames = "output_names";
  231. constexpr auto kAttrVisited = "visited";
  232. constexpr auto kAttrShape = "shape";
  233. constexpr auto kAttrMomentum = "momentum";
  234. constexpr auto kAttrEps = "eps";
  235. constexpr auto kAttrEpsilon = "epsilon";
  236. constexpr auto kAttrFactor = "factor";
  237. constexpr auto kAttrIsRef = "isRef";
  238. constexpr auto kAttrDataShape = "data_shape";
  239. constexpr auto kAttrAxis = "axis";
  240. constexpr auto kAttrKeepDims = "keep_dims";
  241. constexpr auto kAttrShapeGamma = "shape_gamma";
  242. constexpr auto kAttrPerm = "perm";
  243. constexpr auto kAttrTransposeFirst = "transpose_first";
  244. constexpr auto kAttrAtomicAddMemSize = "automic_add_mem_size";
  245. constexpr auto kAttrAtomicOutputIndexs = "atomic_output_clean_indexs";
  246. constexpr auto kAttrAtomicWorkspaceIndexs = "atomic_workspace_clean_indexs";
  247. constexpr auto kAttrSwitchCondition = "switch_condition";
  248. constexpr auto kAttrDataType = "data_type";
  249. constexpr auto kAttrActiveTarget = "active_target";
  250. constexpr auto kAttrActiveStreamList = "active_stream_list";
  251. constexpr auto kAttrTrueBranchStream = "true_branch_stream";
  252. constexpr auto kAttrStreamSwitchKind = "stream_switch_kind";
  253. constexpr auto kAttrEventId = "event_id";
  254. constexpr auto kAttrDynInput = "dynamic";
  255. constexpr auto kAttrDynInputSizes = "dyn_input_sizes";
  256. constexpr auto kAttrSrcFormat = "src_format";
  257. constexpr auto kAttrDstFormat = "dst_format";
  258. constexpr auto kAttrMultiples = "multiples";
  259. constexpr auto kAttrFixPrecision = "fix_precision";
  260. constexpr auto kAttrOutputPrecision = "output_precision";
  261. constexpr auto kAttrOutputUsedNum = "output_used_num";
  262. constexpr auto kAttrHasBias = "has_bias";
  263. constexpr auto kAttrN = "n";
  264. constexpr auto kAttrLabelForInsertStreamActive = "label_for_insert_stream_active";
  265. constexpr auto kAttrFusion = "fusion";
  266. constexpr auto kAttrGroup = "group";
  267. constexpr auto kAttrOp = "op";
  268. constexpr auto kAttrRootRank = "root_rank";
  269. constexpr auto kAttrIsTraining = "is_training";
  270. constexpr auto kAttrFusionId = "fusion_id";
  271. constexpr auto kAttrLabelIndex = "label_index";
  272. constexpr auto kAttrLabelSwitchList = "label_switch_list";
  273. constexpr auto kAttrNewAxisMask = "new_axis_mask";
  274. constexpr auto kAttrShrinkAxisMask = "shrink_axis_mask";
  275. constexpr auto kAttrDatadumpOriginalNames = "_datadump_original_names";
  276. constexpr auto kAttrDatadumpIsMultiop = "_datadump_is_multiop";
  277. constexpr auto kAttrStreamId = "stream_id";
  278. constexpr auto kAttrRecordEvent = "record_event";
  279. constexpr auto kAttrWaitEvent = "wait_event";
  280. constexpr auto kAttrRecordEventStream = "record_event_stream";
  281. constexpr auto kAttrWaitEventStream = "wait_event_stream";
  282. constexpr auto kAttrIndex = "index";
  283. constexpr auto kAttrSplitDim = "split_dim";
  284. constexpr auto kAttrNumSplit = "num_split";
  285. constexpr auto kAttrOutputNum = "output_num";
  286. constexpr auto kAttrSizeSplits = "size_splits";
  287. constexpr auto kAttrOutputDefault = "output_default";
  288. constexpr auto kAttrPrimitiveTarget = "primitive_target";
  289. constexpr auto kAttrUseLocking = "use_locking";
  290. constexpr auto kAttrReduceScatterFlag = "reduce_scatter_flag";
  291. constexpr auto kAttrOffset = "offset";
  292. constexpr auto kAttrPsKey = "ps_key";
  293. constexpr auto kAttrOptimizerType = "optim_type";
  294. constexpr auto kAttrChildGraph = "child_graph";
  295. constexpr auto kAttrInputNums = "inputNums";
  296. constexpr auto kAttrT = "T";
  297. constexpr auto kAttrNum = "num";
  298. constexpr auto kAttrRankSize = "rank_size";
  299. constexpr auto kAttrPadDimSize = "pad_dim_size";
  300. constexpr auto kAttrNumSegments = "num_segments";
  301. constexpr auto kAttrBegin = "begin";
  302. constexpr auto kAttrSize = "size";
  303. constexpr auto kAttrIsDynamicShape = "is_dynamic_shape";
  304. constexpr auto kAttrInputIsDynamicShape = "input_is_dynamic_shape";
  305. constexpr auto kAttrOutputIsDynamicShape = "output_is_dynamic_shape";
  306. constexpr auto kAttrCompileInfo = "compile_info";
  307. constexpr auto kAttrFusionType = "fusion_type";
  308. // attr value
  309. constexpr auto kValueTargetSwitch = "target_switch";
  310. constexpr auto kValueTargetOther = "target_other";
  311. // some size
  312. const size_t kShape4dDims = 4;
  313. const size_t kShape2dDims = 2;
  314. const size_t kShape5dDims = 5;
  315. const size_t kShape1dDims = 1;
  316. const size_t kCubeSize = 16;
  317. const size_t kMemAlignSize = 512;
  318. const int kParameterDataTensorMask = 0;
  319. const int kParameterWeightTensorMask = 1;
  320. const int kValueNodeTensorMask = 2;
  321. // define special index in special node
  322. constexpr auto kAnfPrimitiveIndex = 0;
  323. constexpr auto kFirstDataInputIndex = 1;
  324. constexpr auto kRealInputNodeIndexInTupleGetItem = 1;
  325. constexpr auto kInputNodeOutputIndexInTupleGetItem = 2;
  326. constexpr auto kTupleGetItemInputSize = 3;
  327. constexpr auto kSwitchInputSize = 4;
  328. constexpr auto kFirstBranchInSwitch = 2;
  329. constexpr auto kCallKernelGraphIndex = 1;
  330. constexpr auto kSwitchTrueKernelGraphIndex = 2;
  331. constexpr auto kSwitchFalseKernelGraphIndex = 3;
  332. // index define of control depend
  333. constexpr auto kControlDependPriorIndex = 1;
  334. constexpr auto kControlDependBehindIndex = 2;
  335. constexpr auto kControlDependMode = "depend_mode";
  336. // index define of depend
  337. constexpr auto kRealInputIndexInDepend = 1;
  338. constexpr auto kDependAttachNodeIndex = 2;
  339. constexpr auto kDependInputSize = 3;
  340. // format
  341. constexpr auto kOpFormat_DEFAULT = "DefaultFormat";
  342. constexpr auto kOpFormat_NC1KHKWHWC0 = "NC1KHKWHWC0";
  343. constexpr auto kOpFormat_ND = "ND";
  344. constexpr auto kOpFormat_NCHW = "NCHW";
  345. constexpr auto kOpFormat_NHWC = "NHWC";
  346. constexpr auto kOpFormat_HWCN = "HWCN";
  347. constexpr auto kOpFormat_NC1HWC0 = "NC1HWC0";
  348. constexpr auto kOpFormat_FRAC_Z = "FracZ";
  349. constexpr auto kOpFormat_FRAC_NZ = "FRACTAL_NZ";
  350. constexpr auto kOpFormat_C1HWNCoC0 = "C1HWNCoC0";
  351. constexpr auto kOpFormat_NC1HWC0_C04 = "NC1HWC0_C04";
  352. constexpr auto kOpFormat_FRACTAL_Z_C04 = "FRACTAL_Z_C04";
  353. constexpr auto kOpFormat_NDHWC = "NDHWC";
  354. constexpr auto kOpFormat_FRACTAL_ZN_LSTM = "FRACTAL_ZN_LSTM";
  355. const std::set<std::string> kOpFormatList = {
  356. kOpFormat_DEFAULT, kOpFormat_NC1KHKWHWC0, kOpFormat_ND, kOpFormat_NCHW, kOpFormat_NHWC,
  357. kOpFormat_HWCN, kOpFormat_NC1HWC0, kOpFormat_FRAC_Z, kOpFormat_C1HWNCoC0, kOpFormat_FRAC_NZ,
  358. kOpFormat_NC1HWC0_C04, kOpFormat_FRACTAL_Z_C04, kOpFormat_NDHWC, kOpFormat_FRACTAL_ZN_LSTM};
  359. const std::set<std::string> kDefaultCompatibleFormat = {kOpFormat_ND, kOpFormat_NCHW, kOpFormat_NHWC, kOpFormat_HWCN};
  360. const std::set<std::string> kOptOperatorSet = {
  361. kMomentumOpName,
  362. kApplyMomentumOpName,
  363. kApplyAdadeltaOpName,
  364. kApplyAdagradOpName,
  365. kApplyAdagradDAName,
  366. kApplyAdamOpName,
  367. kApplyAdaMaxOpName,
  368. kApplyAddSignOpName,
  369. kApplyCenteredRMSPOpName,
  370. kApplyFtrlOpName,
  371. kApplyFtrlV2OpName,
  372. kApplyGradientDescentOpName,
  373. kApplyPowerSignOpName,
  374. kApplyProximalAdagradOpName,
  375. kApplyProximalGradientDescentOpName,
  376. kApplyRMSPropOpName,
  377. kFusedAdamWeightDecayName,
  378. kFusedAdamName,
  379. kFusedWeightScaleApplyMomentum,
  380. kFusedScaleApplyMomentum,
  381. kPullOpName,
  382. };
  383. const std::set<std::string> kHWSpecialFormatSet = {
  384. kOpFormat_FRAC_Z, kOpFormat_NC1KHKWHWC0, kOpFormat_NC1HWC0, kOpFormat_FRAC_NZ,
  385. kOpFormat_C1HWNCoC0, kOpFormat_NC1HWC0_C04, kOpFormat_FRACTAL_Z_C04, kOpFormat_FRACTAL_ZN_LSTM};
  386. const std::set<TypeId> kFloatDataTypeSet = {kNumberTypeFloat16, kNumberTypeFloat32};
  387. static inline void ChangeFileMode(const std::string &file_name, mode_t mode) {
  388. try {
  389. if (chmod(file_name.c_str(), mode) != 0) {
  390. MS_LOG(DEBUG) << "Change file `" << file_name << "` to mode " << std::oct << mode << " fail.";
  391. }
  392. } catch (std::exception &e) {
  393. MS_LOG(DEBUG) << "File `" << file_name << "` change mode failed! May be not exist.";
  394. }
  395. }
  396. static inline uint64_t GetCurrentUSec() {
  397. struct timeval tv;
  398. int ret = gettimeofday(&tv, nullptr);
  399. if (ret != 0) {
  400. MS_LOG(EXCEPTION) << "Fail gettimeofday, ret = " << ret;
  401. }
  402. return static_cast<uint64_t>(tv.tv_usec + tv.tv_sec * 1000000);
  403. }
  404. #define PROF_START(stage) uint64_t start_usec_##stage = mindspore::GetCurrentUSec()
  405. #define PROF_END(stage) \
  406. do { \
  407. uint64_t end_usec_##stage = mindspore::GetCurrentUSec(); \
  408. MS_LOG(INFO) << #stage << " costs " << (end_usec_##stage - start_usec_##stage) << " usec."; \
  409. } while (0)
  410. #define PROF_MULTI_DEFINE(stage) \
  411. static uint64_t total_##stage = 0; \
  412. static uint64_t count_##stage = 0;
  413. #define PROF_LOCAL_DEFINE(stage) \
  414. uint64_t total_##stage = 0; \
  415. uint64_t count_##stage = 0;
  416. #define PROF_MULTI_START(stage) uint64_t start_usec_##stage = mindspore::GetCurrentUSec()
  417. #define PROF_MULTI_END(stage) \
  418. do { \
  419. ++count_##stage; \
  420. uint64_t end_usec_##stage = mindspore::GetCurrentUSec(); \
  421. total_##stage += (end_usec_##stage - start_usec_##stage); \
  422. } while (0)
  423. #define PROF_MULTI_PRINT(stage) \
  424. do { \
  425. MS_LOG(INFO) << #stage << " called " << count_##stage << " times, costs " << total_##stage << " usec."; \
  426. } while (0)
  427. } // namespace mindspore
  428. #endif // MINDSPORE_CCSRC_UTILS_UTILS_H_