OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CpuBufferMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
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 #pragma once
18 
20 
22 
23 namespace CudaMgr_Namespace {
24 class CudaMgr;
25 }
26 
27 namespace Buffer_Namespace {
28 
29 class CpuBufferMgr : public BufferMgr {
30  public:
31  CpuBufferMgr(const int device_id,
32  const size_t max_buffer_pool_size,
34  const size_t min_slab_size,
35  const size_t max_slab_size,
36  const size_t page_size,
37  AbstractBufferMgr* parent_mgr = nullptr)
38  : BufferMgr(device_id,
39  max_buffer_pool_size,
40  min_slab_size,
41  max_slab_size,
42  page_size,
43  parent_mgr)
44  , cuda_mgr_(cuda_mgr) {
45  initializeMem();
46  }
47 
48  ~CpuBufferMgr() override {
49  /* the destruction of the allocator automatically frees all memory */
50  }
51 
52  inline MgrType getMgrType() override { return CPU_MGR; }
53  inline std::string getStringMgrType() override { return ToString(CPU_MGR); }
54 
55  // Used for testing.
56  void setAllocator(std::unique_ptr<DramArena> allocator) {
57  allocator_ = std::move(allocator);
58  }
59 
60  protected:
61  void addSlab(const size_t slab_size) override;
62  void freeAllMem() override;
63  void allocateBuffer(BufferList::iterator segment_iter,
64  const size_t page_size,
65  const size_t initial_size) override;
66  virtual void initializeMem();
67 
69 
70  private:
71  std::unique_ptr<DramArena> allocator_;
72 };
73 
74 } // namespace Buffer_Namespace
void addSlab(const size_t slab_size) override
std::unique_ptr< DramArena > allocator_
Definition: CpuBufferMgr.h:71
void allocateBuffer(BufferList::iterator segment_iter, const size_t page_size, const size_t initial_size) override
MgrType getMgrType() override
Definition: CpuBufferMgr.h:52
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: CpuBufferMgr.h:68
CpuBufferMgr(const int device_id, const size_t max_buffer_pool_size, CudaMgr_Namespace::CudaMgr *cuda_mgr, const size_t min_slab_size, const size_t max_slab_size, const size_t page_size, AbstractBufferMgr *parent_mgr=nullptr)
Definition: CpuBufferMgr.h:31
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:96
This file includes the class specification for the buffer manager (BufferMgr), and related data struc...
std::string getStringMgrType() override
Definition: CpuBufferMgr.h:53
void setAllocator(std::unique_ptr< DramArena > allocator)
Definition: CpuBufferMgr.h:56