OmniSciDB  a5dc49c757
 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 default_slab_size,
37  const size_t page_size,
38  AbstractBufferMgr* parent_mgr = nullptr)
39  : BufferMgr(device_id,
40  max_buffer_pool_size,
41  min_slab_size,
42  max_slab_size,
43  default_slab_size,
44  page_size,
45  parent_mgr)
46  , cuda_mgr_(cuda_mgr) {
47  initializeMem();
48  }
49 
50  ~CpuBufferMgr() override {
51  /* the destruction of the allocator automatically frees all memory */
52  }
53 
54  inline MgrType getMgrType() override { return CPU_MGR; }
55  inline std::string getStringMgrType() override { return ToString(CPU_MGR); }
56 
57  // Used for testing.
58  void setAllocator(std::unique_ptr<DramArena> allocator) {
59  allocator_ = std::move(allocator);
60  }
61 
62  protected:
63  void addSlab(const size_t slab_size) override;
64  void freeAllMem() override;
65  void allocateBuffer(BufferList::iterator segment_iter,
66  const size_t page_size,
67  const size_t initial_size) override;
68  virtual void initializeMem();
69 
71 
72  private:
73  std::unique_ptr<DramArena> allocator_;
74 };
75 
76 } // namespace Buffer_Namespace
void addSlab(const size_t slab_size) override
std::unique_ptr< DramArena > allocator_
Definition: CpuBufferMgr.h:73
void allocateBuffer(BufferList::iterator segment_iter, const size_t page_size, const size_t initial_size) override
MgrType getMgrType() override
Definition: CpuBufferMgr.h:54
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: CpuBufferMgr.h:70
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:55
void setAllocator(std::unique_ptr< DramArena > allocator)
Definition: CpuBufferMgr.h:58
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 default_slab_size, const size_t page_size, AbstractBufferMgr *parent_mgr=nullptr)
Definition: CpuBufferMgr.h:31