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.

ascend_kernel_runtime.h 2.7 kB

6 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_DEVICE_ASCEND_ASCEND_KERNEL_RUNTIME_H_
  17. #define MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_KERNEL_RUNTIME_H_
  18. #include <memory>
  19. #include <vector>
  20. #include <string>
  21. #include <unordered_map>
  22. #include "device/kernel_runtime.h"
  23. #include "runtime/context.h"
  24. #include "framework/ge_runtime/davinci_model.h"
  25. #include "device/kernel_runtime_manager.h"
  26. #include "session/session_basic.h"
  27. using ge::model_runner::TaskInfo;
  28. using std::unordered_map;
  29. using std::vector;
  30. namespace mindspore {
  31. namespace device {
  32. namespace ascend {
  33. class AscendKernelRuntime : public KernelRuntime {
  34. public:
  35. AscendKernelRuntime() = default;
  36. ~AscendKernelRuntime() override;
  37. bool Init() override;
  38. bool DumpData(session::KernelGraph *graph) override;
  39. bool LoadData(session::KernelGraph *graph, Debugger *debugger) override;
  40. bool GenTask(const session::KernelGraph *graph) override;
  41. bool RunTask(const session::KernelGraph *graph) override;
  42. bool LoadTask(const session::KernelGraph *graph) override;
  43. void ClearGraphRuntimeResource(uint32_t graph_id) override;
  44. bool SyncStream() override;
  45. protected:
  46. DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format,
  47. TypeId type_id) override;
  48. bool NodeOutputDeviceAddressExist(const AnfNodePtr &node, size_t index) override;
  49. private:
  50. bool InitDevice();
  51. bool ResetDevice();
  52. bool HcclInit();
  53. bool NeedDestroyHccl();
  54. bool DestroyHccl();
  55. void ClearGraphModelMap();
  56. void ReleaseDeviceRes() override;
  57. bool GraphWithEmptyTaskList(const session::KernelGraph *graph) const;
  58. bool CheckGraphIdValid(GraphId graph_id) const;
  59. static void DebugTaskIdName(GraphId graph_id);
  60. rtContext_t rt_context_{nullptr};
  61. bool initialized_{false};
  62. unordered_map<GraphId, vector<std::shared_ptr<TaskInfo>>> task_map_;
  63. unordered_map<GraphId, std::shared_ptr<ge::model_runner::DavinciModel>> graph_model_map_;
  64. };
  65. MS_REG_KERNEL_RUNTIME(kAscendDevice, AscendKernelRuntime);
  66. } // namespace ascend
  67. } // namespace device
  68. } // namespace mindspore
  69. #endif // MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_KERNEL_RUNTIME_H_