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.

kernel_adjust.h 4.4 kB

5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright 2020 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_RUNTIME_DEVICE_KERNEL_ADJUST_H_
  17. #define MINDSPORE_CCSRC_RUNTIME_DEVICE_KERNEL_ADJUST_H_
  18. #include <memory>
  19. #include <map>
  20. #include <string>
  21. #include <vector>
  22. #include <unordered_set>
  23. #include "ir/anf.h"
  24. #include "backend/session/kernel_graph.h"
  25. #include "backend/kernel_compiler/kernel_build_info.h"
  26. #include "backend/session/session_context.h"
  27. #include "ir/tensor.h"
  28. #include "runtime/device/ascend/profiling/profiling_utils.h"
  29. #include "runtime/device/kernel_info.h"
  30. using mindspore::device::ascend::ProfilingTraceInfo;
  31. using mindspore::device::ascend::ProfilingUtils;
  32. namespace mindspore {
  33. constexpr auto kCurLoopCountParamName = "cur_loop_count";
  34. constexpr auto kNextLoopCountParamName = "next_loop_count";
  35. constexpr auto kIterLoopParamName = "iter_loop";
  36. constexpr auto kOneParamName = "one";
  37. constexpr auto kEpochParamName = "loop_epoch";
  38. constexpr auto kStreamNeedActivedFirst = "stream_need_active_first";
  39. constexpr uint32_t kSecondStreamSwitchLabel = 2;
  40. enum StreamSwitchKind {
  41. kFpBpStreamSwitch = 0,
  42. kGetNextStreamSwitch = 1,
  43. kEosStreamSwitch = 2,
  44. kIndependentStreamSwitch = 3
  45. };
  46. namespace device {
  47. class KernelAdjust {
  48. public:
  49. static KernelAdjust &GetInstance() {
  50. static KernelAdjust instance;
  51. return instance;
  52. }
  53. void InsertSwitchLoop(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  54. bool StepLoadCtrlInputs(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  55. void Profiling(NotNull<session::KernelGraph *> kernel_graph_ptr);
  56. static bool NeedInsertSwitch();
  57. CNodePtr CreateStreamActiveOp(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  58. private:
  59. KernelAdjust() = default;
  60. ~KernelAdjust() = default;
  61. void ReorderGetNext(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  62. CNodePtr CreateRecvApplyKernel(const std::shared_ptr<session::KernelGraph> &graph_ptr, uint32_t event_id);
  63. CNodePtr CreateSendApplyKernel(const std::shared_ptr<session::KernelGraph> &graph_ptr, uint32_t event_id);
  64. void CreateSwitchOpParameters(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  65. std::map<std::string, mindspore::ParameterPtr> *switch_loop_input);
  66. CNodePtr CreateStreamSwitchOp(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  67. const std::map<std::string, mindspore::ParameterPtr> &switch_loop_input,
  68. StreamSwitchKind kind);
  69. CNodePtr CreatTupleGetItemNode(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr, const CNodePtr &node,
  70. size_t output_idx);
  71. CNodePtr CreateEndOfSequenceOP(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  72. const CNodePtr &getnext_cnode);
  73. CNodePtr CreateStreamAssignAddnOP(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  74. const std::map<std::string, mindspore::ParameterPtr> &switch_loop_input,
  75. bool cur_loop);
  76. kernel::KernelBuildInfo::KernelBuildInfoBuilder CreateMngKernelBuilder(const std::vector<std::string> &formats,
  77. const std::vector<TypeId> &type_ids);
  78. void LoadSwitchInputs(std::vector<tensor::TensorPtr> *inputs);
  79. void InsertProfilingKernel(const ProfilingTraceInfo &profiling_trace_info,
  80. NotNull<session::KernelGraph *> kernel_graph_ptr);
  81. bool ExistIndependent(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  82. bool ExistGetNext(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  83. };
  84. } // namespace device
  85. } // namespace mindspore
  86. #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_KERNEL_ADJUST_H_