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

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