OmniSciDB  c07336695a
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 
17 #include "CpuBufferMgr.h"
18 #include "../../../CudaMgr/CudaMgr.h"
19 #include "CpuBuffer.h"
20 
21 namespace Buffer_Namespace {
22 
23 CpuBufferMgr::CpuBufferMgr(const int deviceId,
24  const size_t maxBufferSize,
26  const size_t bufferAllocIncrement,
27  const size_t pageSize,
28  AbstractBufferMgr* parentMgr)
29  : BufferMgr(deviceId, maxBufferSize, bufferAllocIncrement, pageSize, parentMgr)
30  , cudaMgr_(cudaMgr) {}
31 
33  freeAllMem();
34 }
35 
36 void CpuBufferMgr::addSlab(const size_t slabSize) {
37  slabs_.resize(slabs_.size() + 1);
38  try {
39  slabs_.back() = new int8_t[slabSize];
40  } catch (std::bad_alloc&) {
41  slabs_.resize(slabs_.size() - 1);
42  throw FailedToCreateSlab(slabSize);
43  }
44  slabSegments_.resize(slabSegments_.size() + 1);
45  slabSegments_[slabSegments_.size() - 1].push_back(BufferSeg(0, slabSize / pageSize_));
46 }
47 
49  for (auto bufIt = slabs_.begin(); bufIt != slabs_.end(); ++bufIt) {
50  delete[] * bufIt;
51  }
52 }
53 
54 void CpuBufferMgr::allocateBuffer(BufferList::iterator segIt,
55  const size_t pageSize,
56  const size_t initialSize) {
57  new CpuBuffer(this,
58  segIt,
59  deviceId_,
60  cudaMgr_,
61  pageSize,
62  initialSize); // this line is admittedly a bit weird but
63  // the segment iterator passed into buffer
64  // takes the address of the new Buffer in its
65  // buffer member
66 }
67 
68 } // namespace Buffer_Namespace
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: CpuBufferMgr.h:46
void allocateBuffer(BufferList::iterator segIt, const size_t pageSize, const size_t initialSize) override
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:96
void addSlab(const size_t slabSize) override
CpuBufferMgr(const int deviceId, const size_t maxBufferSize, CudaMgr_Namespace::CudaMgr *cudaMgr, const size_t bufferAllocIncrement=2147483648, const size_t pageSize=512, AbstractBufferMgr *parentMgr=0)
std::vector< int8_t * > slabs_
Definition: BufferMgr.h:176
std::vector< BufferList > slabSegments_
Definition: BufferMgr.h:178