• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MINDDATA_DATASET_UTIL_MEMORY_POOL_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_MEMORY_POOL_H_
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <memory>
22 #include "minddata/dataset/util/status.h"
23 
24 namespace mindspore {
25 namespace dataset {
26 // Abstract class of a memory pool
27 class MemoryPool {
28  public:
29   // Allocate a block of size n
30   virtual Status Allocate(size_t, void **) = 0;
31 
32   // Enlarge or shrink a block from oldSz to newSz
33   virtual Status Reallocate(void **, size_t old_sz, size_t new_sz) = 0;
34 
35   // Free a pointer
36   virtual void Deallocate(void *) = 0;
37 
38   // What is the maximum size I can allocate ?
39   virtual uint64_t get_max_size() const = 0;
40 
41   virtual int PercentFree() const = 0;
42 
43   // Destructor
~MemoryPool()44   virtual ~MemoryPool() {}
45 };
46 
47 Status DeMalloc(std::size_t s, void **p, bool);
48 }  // namespace dataset
49 }  // namespace mindspore
50 
51 void *operator new(std::size_t, mindspore::Status *, std::shared_ptr<mindspore::dataset::MemoryPool>);
52 
53 void *operator new[](std::size_t, mindspore::Status *, std::shared_ptr<mindspore::dataset::MemoryPool>);
54 
55 void operator delete(void *, std::shared_ptr<mindspore::dataset::MemoryPool>);
56 
57 void operator delete[](void *, std::shared_ptr<mindspore::dataset::MemoryPool>);
58 
59 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_MEMORY_POOL_H_
60