• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 
17 #ifndef MINDSPORE_CCSRC_RUNTIME_HARDWARE_CPU_CPU_MEMORY_POOL_H_
18 #define MINDSPORE_CCSRC_RUNTIME_HARDWARE_CPU_CPU_MEMORY_POOL_H_
19 
20 #include <memory>
21 #include <string>
22 #include "utils/ms_utils.h"
23 #include "include/backend/mem_reuse/mem_dynamic_allocator.h"
24 
25 namespace mindspore {
26 namespace device {
27 namespace cpu {
28 class BACKEND_EXPORT CPUMemoryPool : public DynamicMemPoolBestFit {
29  public:
30   ~CPUMemoryPool() override = default;
31 
GetInstance()32   static CPUMemoryPool &GetInstance() {
33     static CPUMemoryPool instance;
34     return instance;
35   }
36 
37   size_t AllocDeviceMem(size_t size, DeviceMemPtr *addr) override;
38   bool FreeDeviceMem(const DeviceMemPtr &addr) override;
39   size_t free_mem_size() override;
GetMemoryPoolType()40   std::string GetMemoryPoolType() const override { return "CPU"; }
41 
42  private:
43   CPUMemoryPool() = default;
44   DISABLE_COPY_AND_ASSIGN(CPUMemoryPool);
45 
46   size_t total_used_memory_{0};
47 };
48 }  // namespace cpu
49 }  // namespace device
50 }  // namespace mindspore
51 
52 #endif  // MINDSPORE_CCSRC_RUNTIME_HARDWARE_CPU_CPU_MEMORY_POOL_H_
53