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.

cpu_session.h 3.7 kB

5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_CPU_SESSION_H
  17. #define MINDSPORE_CCSRC_BACKEND_SESSION_CPU_SESSION_H
  18. #include <string>
  19. #include <memory>
  20. #include <map>
  21. #include <vector>
  22. #include "backend/session/session_basic.h"
  23. #include "backend/session/kernel_graph.h"
  24. #include "runtime/device/cpu/cpu_kernel_runtime.h"
  25. #include "backend/session/session_factory.h"
  26. namespace mindspore {
  27. namespace session {
  28. class CPUSession : public SessionBasic {
  29. public:
  30. CPUSession() = default;
  31. ~CPUSession() override = default;
  32. void Init(uint32_t device_id) override;
  33. protected:
  34. void UnifyMindIR(const KernelGraphPtr &graph) override { SessionBasic::UnifyMindIR(graph); }
  35. void CreateOutputTensors(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &input_tensors, VectorRef *,
  36. std::map<tensor::TensorPtr, session::KernelWithIndex> *tensor_to_node,
  37. KernelMapTensor *node_to_tensor) override;
  38. GraphId CompileGraphImpl(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override;
  39. void PreExecuteGraph(const std::shared_ptr<KernelGraph> &kernel_graph, const std::vector<tensor::TensorPtr> &inputs,
  40. VectorRef *const outputs) override;
  41. void PostExecuteGraph(const std::shared_ptr<KernelGraph> &kernel_graph, const std::vector<tensor::TensorPtr> &inputs,
  42. VectorRef *const outputs) override;
  43. void ExecuteGraph(const std::shared_ptr<KernelGraph> &kernel_graph) override;
  44. ParameterPtr CreateNewParameterFromParameter(const AnfNodePtr &anf, KernelGraph *graph) override;
  45. void GraphKernelOptimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  46. void Optimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  47. KernelGraphPtr BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info,
  48. const std::vector<tensor::TensorPtr> &input_tensors,
  49. const std::vector<int64_t> &tensors_mask) override;
  50. void RunOpImpl(const GraphInfo &graph_info, OpRunInfo *op_run_info, std::vector<tensor::TensorPtr> *input_tensors,
  51. VectorRef *outputs, const std::vector<int64_t> &tensors_mask) override;
  52. void RunOpImplOrigin(const GraphInfo &graph_info, OpRunInfo *op_run_info,
  53. std::vector<tensor::TensorPtr> *input_tensors, VectorRef *outputs,
  54. const std::vector<int64_t> &tensors_mask) override;
  55. void LoadInputData(const std::shared_ptr<KernelGraph> &kernel_graph,
  56. const std::vector<tensor::TensorPtr> &inputs_const) const override;
  57. private:
  58. void Reorder(std::vector<CNodePtr> *node_list);
  59. void SetKernelInfo(const KernelGraph *kernel_graph);
  60. void BuildKernel(const KernelGraph *kernel_graph);
  61. void SetOutputFlags(const VectorRef &base_ref);
  62. void UpdateDynamicOutputShape(const std::map<tensor::TensorPtr, KernelWithIndex> &tensor_to_node);
  63. device::cpu::CPUKernelRuntime runtime_;
  64. };
  65. MS_REG_SESSION(kCPUDevice, CPUSession);
  66. } // namespace session
  67. } // namespace mindspore
  68. #endif // MINDSPORE_CCSRC_BACKEND_SESSION_CPU_SESSION_H