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_resource_manager.h 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_RESOURCE_MANAGER_H_
  17. #define MINDSPORE_CCSRC_DEVICE_CPU_CPU_RESOURCE_MANAGER_H_
  18. #include <vector>
  19. #include <unordered_map>
  20. #include "session/kernel_graph.h"
  21. #include "session/session_basic.h"
  22. #include "device/device_address.h"
  23. #include "device/cpu/cpu_simple_mem_plan.h"
  24. namespace mindspore {
  25. namespace device {
  26. namespace cpu {
  27. class CPUResourceManager {
  28. public:
  29. CPUResourceManager() = default;
  30. ~CPUResourceManager();
  31. void MemPlan(const session::KernelGraph *graph);
  32. void MemMalloc(const session::KernelGraph *graph);
  33. void IncreaseAddressRefCount(const session::KernelGraph *graph);
  34. void DecreaseAddressRefCount(const AnfNodePtr &kernel);
  35. void *MemMalloc(size_t mem_size);
  36. void MemFree(void *ptr);
  37. void IncreaseSummaryRefCount(const session::NamedSummaryOutputs &summary_outputs);
  38. void DecreaseSummaryRefCount(const session::NamedSummaryOutputs &summary_outputs);
  39. private:
  40. void MemFree();
  41. CPUSimpleMemPlan mem_plan_;
  42. size_t mem_size_{0};
  43. uint8_t *mem_ptr_{nullptr};
  44. bool dynamic_malloc_{false};
  45. std::unordered_map<void *, size_t> dynamic_mem_;
  46. };
  47. } // namespace cpu
  48. } // namespace device
  49. } // namespace mindspore
  50. #endif // MINDSPORE_CCSRC_DEVICE_CPU_CPU_RESOURCE_MANAGER_H_