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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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<bool> &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 AssignStream(const std::shared_ptr<KernelGraph> &kernel_graph);
  46. void BuildKernel(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  47. void AllocateMemory(KernelGraph *kernel_graph) const;
  48. void RunOpAllocateMemory(const std::vector<tensor::TensorPtr> &input_tensors, KernelGraph *kernel_graph) const;
  49. void Execute(const std::shared_ptr<KernelGraph> &kernel_graph) const;
  50. };
  51. using GPUSessionPtr = std::shared_ptr<GPUSession>;
  52. MS_REG_SESSION(kGPUDevice, GPUSession);
  53. } // namespace gpu
  54. } // namespace session
  55. } // namespace mindspore
  56. #endif // MINDSPORE_CCSRC_SESSION_GPU_SESSION_H