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

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_SESSION_GPU_SESSION_H
  17. #define MINDSPORE_CCSRC_SESSION_GPU_SESSION_H
  18. #include <vector>
  19. #include <memory>
  20. #include "session/session_basic.h"
  21. #include "session/kernel_graph.h"
  22. #include "session/session_factory.h"
  23. using KernelGraph = mindspore::session::KernelGraph;
  24. namespace mindspore {
  25. namespace session {
  26. namespace gpu {
  27. class GPUSession : public SessionBasic {
  28. public:
  29. GPUSession() = default;
  30. ~GPUSession() override = default;
  31. void Init(uint32_t device_id) override {
  32. SessionBasic::Init(device_id);
  33. context_ = std::make_shared<Context>(kGPUDevice, device_id);
  34. }
  35. GraphId CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override;
  36. void RunGraph(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &inputs, VectorRef *outputs) override;
  37. void BuildOp(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  38. const std::vector<tensor::TensorPtr> &input_tensors, const std::vector<int> &tensors_mask) override;
  39. py::tuple RunOp(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  40. const std::vector<tensor::TensorPtr> &input_tensors) override;
  41. private:
  42. void SelectKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  43. void StartKernelRT() const;
  44. void Optimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  45. void HardwareOptimize(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 std::vector<tensor::TensorPtr> &input_tensors, KernelGraph *kernel_graph) const;
  50. void RunOpClearMemory(KernelGraph *kernel_graph) const;
  51. void LoadInputData(const std::shared_ptr<KernelGraph> &kernel_graph,
  52. const std::vector<tensor::TensorPtr> &inputs_const) const override;
  53. void Execute(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  54. };
  55. using GPUSessionPtr = std::shared_ptr<GPUSession>;
  56. MS_REG_SESSION(kGPUDevice, GPUSession);
  57. } // namespace gpu
  58. } // namespace session
  59. } // namespace mindspore
  60. #endif // MINDSPORE_CCSRC_SESSION_GPU_SESSION_H