• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_LITE_SRC_TRAIN_OPT_ALLOCATOR_H_
18 #define MINDSPORE_LITE_SRC_TRAIN_OPT_ALLOCATOR_H_
19 
20 #include <map>
21 #include "include/api/allocator.h"
22 
23 namespace mindspore {
24 class OptAllocator {
25  public:
align_size_(aligned_size)26   explicit OptAllocator(size_t aligned_size = 32) : align_size_(aligned_size) {}
~OptAllocator()27   ~OptAllocator() {}
28   size_t Malloc(size_t size);
29   void Free(size_t offset);
total_size()30   size_t total_size() { return heap_; }
31 
32  private:
33   size_t FindFree(size_t size);
34   void Reorder(size_t addr);
35   std::map<size_t, size_t> arena_;
36   std::map<size_t, size_t> alloc_;
37   size_t heap_ = 0;
38   size_t align_size_;
39 };
40 };      // namespace mindspore
41 #endif  // MINDSPORE_LITE_SRC_TRAIN_OPT_ALLOCATOR_H_
42