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.

gpu_session.h 3.7 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_BACKEND_SESSION_GPU_SESSION_H
  17. #define MINDSPORE_CCSRC_BACKEND_SESSION_GPU_SESSION_H
  18. #include <vector>
  19. #include <memory>
  20. #include <algorithm>
  21. #include "backend/session/session_basic.h"
  22. #include "backend/session/kernel_graph.h"
  23. #include "backend/session/session_factory.h"
  24. using KernelGraph = mindspore::session::KernelGraph;
  25. namespace mindspore {
  26. namespace session {
  27. namespace gpu {
  28. class GPUSession : public SessionBasic {
  29. public:
  30. GPUSession() = default;
  31. ~GPUSession() override = default;
  32. void Init(uint32_t device_id) override;
  33. void SyncStream() override;
  34. protected:
  35. void UnifyMindIR(const KernelGraphPtr &graph) override { return; }
  36. GraphId CompileGraphImpl(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override;
  37. GraphId CompileGraphImpl(NotNull<FuncGraphPtr> func_graph) override;
  38. void RunGraphImpl(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &inputs, VectorRef *outputs) override;
  39. void BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  40. const std::vector<tensor::TensorPtr> &input_tensors,
  41. const std::vector<int64_t> &tensors_mask) override;
  42. void RunOpImpl(const GraphInfo &graph_info, OpRunInfo *op_run_info, std::vector<tensor::TensorPtr> *input_tensors,
  43. VectorRef *outputs, const std::vector<int64_t> &tensors_mask) override;
  44. private:
  45. void SelectKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  46. void StartKernelRT() const;
  47. void Optimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  48. void HardwareOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  49. void RunOpHardwareOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  50. void GraphKernelOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  51. void AssignStream(const std::shared_ptr<KernelGraph> &kernel_graph);
  52. void BuildKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  53. void AllocateMemory(KernelGraph *kernel_graph) const;
  54. void RunOpAllocateMemory(const std::vector<tensor::TensorPtr> &input_tensors, KernelGraph *kernel_graph) const;
  55. void RunOpClearMemory(KernelGraph *kernel_graph) const;
  56. void LoadInputData(const std::shared_ptr<KernelGraph> &kernel_graph,
  57. const std::vector<tensor::TensorPtr> &inputs_const) const override;
  58. void Execute(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  59. void Dump(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  60. bool DumpDataEnabledIteration() const;
  61. void PostIterationDbg(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  62. void SyncValueNodeDeviceAddr(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  63. void CleanValueNodeDeviceAddr(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  64. GraphId CompileGraphImpl(KernelGraphPtr kernel_graph);
  65. };
  66. using GPUSessionPtr = std::shared_ptr<GPUSession>;
  67. MS_REG_SESSION(kGPUDevice, GPUSession);
  68. } // namespace gpu
  69. } // namespace session
  70. } // namespace mindspore
  71. #endif // MINDSPORE_CCSRC_BACKEND_SESSION_GPU_SESSION_H