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

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. BaseRef CreatTensorForOutput(const session::KernelWithIndex &kernel_with_index,
  49. const std::unordered_map<AnfNode *, tensor::TensorPtr> &input_map,
  50. std::set<DeviceAddressPtr> *bound_addresses,
  51. std::vector<tensor::TensorPtr> *need_sync_outputs);
  52. void AssignValueNodeAddress(session::KernelGraph *kernel_graph);
  53. void AssignInputNodeAddress(const session::KernelGraph *kernel_graph);
  54. void AssignKernelOutputAddress(const session::KernelGraph *kernel_graph);
  55. void AddRuntimeAddress(DeviceAddress *address, std::vector<kernel::AddressPtr> *input_list);
  56. CPUResourceManager resource_manager_;
  57. };
  58. } // namespace cpu
  59. } // namespace device
  60. } // namespace mindspore
  61. #endif // MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_RUNTIME_H_