OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CpuBufferMgr.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
18 
19 #include "CudaMgr/CudaMgr.h"
21 
22 namespace Buffer_Namespace {
23 
24 CpuBufferMgr::CpuBufferMgr(const int device_id,
25  const size_t max_buffer_size,
27  const size_t buffer_alloc_increment,
28  const size_t page_size,
29  AbstractBufferMgr* parent_mgr)
30  : BufferMgr(device_id, max_buffer_size, buffer_alloc_increment, page_size, parent_mgr)
31  , cuda_mgr_(cuda_mgr) {}
32 
34  freeAllMem();
35 }
36 
37 void CpuBufferMgr::addSlab(const size_t slab_size) {
38  slabs_.resize(slabs_.size() + 1);
39  try {
40  slabs_.back() = new int8_t[slab_size];
41  } catch (std::bad_alloc&) {
42  slabs_.resize(slabs_.size() - 1);
43  throw FailedToCreateSlab(slab_size);
44  }
45  slab_segments_.resize(slab_segments_.size() + 1);
46  slab_segments_[slab_segments_.size() - 1].push_back(
47  BufferSeg(0, slab_size / page_size_));
48 }
49 
51  for (auto buf_it = slabs_.begin(); buf_it != slabs_.end(); ++buf_it) {
52  delete[] * buf_it;
53  }
54 }
55 
56 void CpuBufferMgr::allocateBuffer(BufferList::iterator seg_it,
57  const size_t page_size,
58  const size_t initial_size) {
59  new CpuBuffer(this,
60  seg_it,
61  device_id_,
62  cuda_mgr_,
63  page_size,
64  initial_size); // this line is admittedly a bit weird but
65  // the segment iterator passed into buffer
66  // takes the address of the new Buffer in its
67  // buffer member
68 }
69 
70 } // namespace Buffer_Namespace
void addSlab(const size_t slab_size) override
void allocateBuffer(BufferList::iterator segment_iter, const size_t page_size, const size_t initial_size) override
std::vector< BufferList > slab_segments_
Definition: BufferMgr.h:177
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: CpuBufferMgr.h:46
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:97
CpuBufferMgr(const int device_id, const size_t max_buffer_size, CudaMgr_Namespace::CudaMgr *cuda_mgr, const size_t buffer_alloc_increment=2147483648, const size_t page_size=512, AbstractBufferMgr *parent_mgr=0)
std::vector< int8_t * > slabs_
Definition: BufferMgr.h:175