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.5 kB

6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 GenTask(const session::KernelGraph *graph) override;
  40. bool RunTask(const session::KernelGraph *graph) override;
  41. bool LoadTask(const session::KernelGraph *graph) override;
  42. protected:
  43. DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format,
  44. TypeId type_id) override;
  45. bool SyncStream() override;
  46. private:
  47. bool InitDevice();
  48. bool ResetDevice();
  49. bool HcclInit();
  50. bool NeedDestroyHccl();
  51. bool DestroyHccl();
  52. void ClearGraphModelMap();
  53. void ReleaseDeviceRes() override;
  54. bool GraphWithEmptyTaskList(const session::KernelGraph *graph) const;
  55. bool CheckGraphIdValid(GraphId graph_id) const;
  56. rtContext_t rt_context_{nullptr};
  57. bool initialized_{false};
  58. unordered_map<GraphId, vector<std::shared_ptr<TaskInfo>>> task_map_;
  59. unordered_map<GraphId, std::shared_ptr<ge::model_runner::DavinciModel>> graph_model_map_;
  60. };
  61. MS_REG_KERNEL_RUNTIME(kAscendDevice, AscendKernelRuntime);
  62. } // namespace ascend
  63. } // namespace device
  64. } // namespace mindspore
  65. #endif // MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_KERNEL_RUNTIME_H_