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

5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 { InitDevice(kGPUDevice, device_id); }
  33. protected:
  34. GraphId CompileGraphImpl(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override;
  35. void RunGraphImpl(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &inputs, VectorRef *outputs) override;
  36. void BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  37. const std::vector<tensor::TensorPtr> &input_tensors, const std::vector<int> &tensors_mask) override;
  38. void RunOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  39. const std::vector<tensor::TensorPtr> &input_tensors, VectorRef *outputs) override;
  40. private:
  41. void SelectKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  42. void StartKernelRT() const;
  43. void Optimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  44. void HardwareOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  45. void GraphKernelOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  46. void AssignStream(const std::shared_ptr<KernelGraph> &kernel_graph);
  47. void BuildKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  48. void AllocateMemory(KernelGraph *kernel_graph) const;
  49. void RunOpAllocateMemory(const ValuePtr &pre_output_value, const std::vector<tensor::TensorPtr> &input_tensors,
  50. KernelGraph *kernel_graph) const;
  51. void RunOpClearMemory(KernelGraph *kernel_graph) const;
  52. void LoadInputData(const std::shared_ptr<KernelGraph> &kernel_graph,
  53. const std::vector<tensor::TensorPtr> &inputs_const) const override;
  54. void Execute(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  55. void Dump(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  56. bool DumpDataEnabledIteration() const;
  57. void PreIterationDbg(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  58. void PostIterationDbg(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  59. void PreLoadTensor(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  60. void PostLoadTensor(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  61. };
  62. using GPUSessionPtr = std::shared_ptr<GPUSession>;
  63. MS_REG_SESSION(kGPUDevice, GPUSession);
  64. } // namespace gpu
  65. } // namespace session
  66. } // namespace mindspore
  67. #endif // MINDSPORE_CCSRC_BACKEND_SESSION_GPU_SESSION_H