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

5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 { InitDevice(kCPUDevice, device_id); }
  33. protected:
  34. void CreateOutputTensors(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &input_tensors, VectorRef *,
  35. std::map<tensor::TensorPtr, session::KernelWithIndex> *tensor_to_node) override;
  36. GraphId CompileGraphImpl(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override;
  37. void RunGraphImpl(const GraphId &graph_id, const std::vector<tensor::TensorPtr> &inputs, VectorRef *outputs) override;
  38. ParameterPtr CreateNewParameterFromParameter(const AnfNodePtr &anf, KernelGraph *graph) override;
  39. void Optimize(const std::shared_ptr<KernelGraph> &kernel_graph);
  40. private:
  41. void SetKernelInfo(const KernelGraph *kernel_graph);
  42. void BuildKernel(const KernelGraph *kernel_graph);
  43. device::cpu::CPUKernelRuntime runtime_;
  44. };
  45. MS_REG_SESSION(kCPUDevice, CPUSession);
  46. } // namespace session
  47. } // namespace mindspore
  48. #endif // MINDSPORE_CCSRC_BACKEND_SESSION_CPU_SESSION_H