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_kernel_runtime.h 3.1 kB

5 years ago
5 years ago
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_DEVICE_CPU_CPU_KERNEL_RUNTIME_H_
  17. #define MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_RUNTIME_H_
  18. #include <memory>
  19. #include <vector>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <set>
  23. #include "device/kernel_runtime.h"
  24. #include "session/kernel_graph.h"
  25. #include "session/session_basic.h"
  26. #include "device/cpu/cpu_resource_manager.h"
  27. #include "session/anf_runtime_algorithm.h"
  28. #include "utils/any.h"
  29. namespace mindspore {
  30. namespace device {
  31. namespace cpu {
  32. class CPUKernelRuntime : public KernelRuntime {
  33. public:
  34. CPUKernelRuntime() = default;
  35. ~CPUKernelRuntime() override = default;
  36. bool Init() override { return true; }
  37. bool Run(session::KernelGraph *graph) override;
  38. void AssignKernelAddress(session::KernelGraph *kernel_graph);
  39. void BindInputOutput(const session::KernelGraph *kernel_graph, const std::vector<tensor::TensorPtr> &inputs,
  40. VectorRef *outputs, std::vector<tensor::TensorPtr> *need_sync_outputs);
  41. void IncreaseSummaryRefCount(const session::NamedSummaryOutputs &summary_outputs);
  42. void DecreaseSummaryRefCount(const session::NamedSummaryOutputs &summary_outputs);
  43. protected:
  44. bool SyncStream() override { return true; };
  45. DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format,
  46. TypeId type_id) override;
  47. private:
  48. tensor::TensorPtr CreatTensorForOutput(const CNodePtr &node, size_t index,
  49. std::set<DeviceAddressPtr> *bound_addresses,
  50. std::vector<tensor::TensorPtr> *need_sync_outputs);
  51. BaseRef CreatTensorForOutput(const session::KernelWithIndex &kernel_with_index,
  52. const std::unordered_map<AnfNode *, tensor::TensorPtr> &input_map,
  53. std::set<DeviceAddressPtr> *bound_addresses,
  54. std::vector<tensor::TensorPtr> *need_sync_outputs);
  55. void AssignValueNodeAddress(session::KernelGraph *kernel_graph);
  56. void AssignInputNodeAddress(const session::KernelGraph *kernel_graph);
  57. void AssignKernelOutputAddress(const session::KernelGraph *kernel_graph);
  58. void AddRuntimeAddress(DeviceAddress *address, std::vector<kernel::AddressPtr> *input_list);
  59. CPUResourceManager resource_manager_;
  60. };
  61. } // namespace cpu
  62. } // namespace device
  63. } // namespace mindspore
  64. #endif // MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_RUNTIME_H_