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

5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_MINDSPORE_CCSRC_DEVICE_KERNEL_ADJUST_H_
  17. #define MINDSPORE_MINDSPORE_CCSRC_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 "session/kernel_graph.h"
  25. #include "kernel/kernel_build_info.h"
  26. #include "session/session_context.h"
  27. #include "ir/tensor.h"
  28. #include "device/ascend/profiling/profiling_utils.h"
  29. #include "device/kernel_info.h"
  30. using mindspore::device::ascend::ProfilingTraceInfo;
  31. using mindspore::device::ascend::ProfilingUtils;
  32. namespace mindspore {
  33. constexpr auto kLoopCountParamName = "loop_count";
  34. constexpr auto kIterLoopParamName = "iter_loop";
  35. constexpr auto kZeroParamName = "zero";
  36. constexpr auto kOneParamName = "one";
  37. constexpr auto kStreamNeedActivedFirst = "stream_need_active_first";
  38. constexpr uint32_t kSecondStreamSwitchLabel = 2;
  39. namespace device {
  40. class KernelAdjust {
  41. public:
  42. static KernelAdjust &GetInstance() {
  43. static KernelAdjust instance;
  44. return instance;
  45. }
  46. void InsertSwitchLoop(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  47. bool StepLoadCtrlInputs(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  48. void Profiling(NotNull<session::KernelGraph *> kernel_graph_ptr);
  49. static bool NeedInsertSwitch();
  50. CNodePtr CreateStreamActiveOp(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  51. private:
  52. KernelAdjust() = default;
  53. ~KernelAdjust() = default;
  54. void ReorderGetNext(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr);
  55. CNodePtr CreateRecvApplyKernel(const std::shared_ptr<session::KernelGraph> &graph_ptr, uint32_t event_id);
  56. CNodePtr CreateSendApplyKernel(const std::shared_ptr<session::KernelGraph> &graph_ptr, uint32_t event_id);
  57. void CreateSwitchOpParameters(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  58. std::map<std::string, mindspore::ParameterPtr> *switch_loop_input);
  59. CNodePtr CreateStreamSwitchOp(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  60. const std::map<std::string, mindspore::ParameterPtr> &switch_loop_input);
  61. CNodePtr CreatTupleGetItemNode(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr, const CNodePtr &node,
  62. size_t output_idx);
  63. CNodePtr CreateEndOfSequenceOP(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  64. const CNodePtr &getnext_cnode);
  65. CNodePtr CreateStreamAssignAddnOP(const std::shared_ptr<session::KernelGraph> &kernel_graph_ptr,
  66. const std::map<std::string, mindspore::ParameterPtr> &switch_loop_input);
  67. kernel::KernelBuildInfo::KernelBuildInfoBuilder CreateMngKernelBuilder(const std::vector<std::string> &formats,
  68. const std::vector<TypeId> &type_ids);
  69. void LoadSwitchInputs(std::vector<tensor::TensorPtr> *inputs);
  70. void InsertProfilingKernel(const ProfilingTraceInfo &profiling_trace_info,
  71. NotNull<session::KernelGraph *> kernel_graph_ptr);
  72. };
  73. } // namespace device
  74. } // namespace mindspore
  75. #endif // MINDSPORE_MINDSPORE_CCSRC_DEVICE_KERNEL_ADJUST_H_