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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "device/kernel_runtime.h"
  23. #include "session/kernel_graph.h"
  24. #include "device/cpu/cpu_resource_manager.h"
  25. #include "utils/any.h"
  26. namespace mindspore {
  27. namespace device {
  28. namespace cpu {
  29. class CPUKernelRuntime : public KernelRuntime {
  30. public:
  31. CPUKernelRuntime() = default;
  32. ~CPUKernelRuntime() override = default;
  33. bool Init() override { return true; }
  34. bool Run(session::KernelGraph *graph) override;
  35. void AssignKernelAddress(session::KernelGraph *kernel_graph);
  36. void BindInputOutput(const session::KernelGraph *kernel_graph, const std::vector<tensor::TensorPtr> &inputs,
  37. VectorRef *outputs);
  38. protected:
  39. bool SyncStream() override { return true; };
  40. DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format,
  41. TypeId type_id) override;
  42. private:
  43. BaseRef CreatTensorForOutput(const AnfNodePtr &input_node, size_t index,
  44. const std::unordered_map<AnfNode *, tensor::TensorPtr> &input_map);
  45. void AssignValueNodeAddress(session::KernelGraph *kernel_graph);
  46. void AssignInputNodeAddress(const session::KernelGraph *kernel_graph);
  47. void AssignKernelOutputAddress(const session::KernelGraph *kernel_graph);
  48. void AddRuntimeAddress(DeviceAddress *address, std::vector<kernel::AddressPtr> *input_list);
  49. CPUResourceManager resource_manager_;
  50. };
  51. } // namespace cpu
  52. } // namespace device
  53. } // namespace mindspore
  54. #endif // MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_RUNTIME_H_