OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data_Namespace::DataMgr Class Reference

#include <DataMgr.h>

+ Collaboration diagram for Data_Namespace::DataMgr:

Public Member Functions

 DataMgr (const std::string &dataDir, const MapDParameters &mapd_parameters, const bool useGpus, const int numGpus, const int startGpu=0, const size_t reservedGpuMem=(1<< 27), const size_t numReaderThreads=0)
 
 ~DataMgr ()
 
AbstractBuffercreateChunkBuffer (const ChunkKey &key, const MemoryLevel memoryLevel, const int deviceId=0, const size_t page_size=0)
 
AbstractBuffergetChunkBuffer (const ChunkKey &key, const MemoryLevel memoryLevel, const int deviceId=0, const size_t numBytes=0)
 
void deleteChunksWithPrefix (const ChunkKey &keyPrefix)
 
void deleteChunksWithPrefix (const ChunkKey &keyPrefix, const MemoryLevel memLevel)
 
AbstractBufferalloc (const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
 
void free (AbstractBuffer *buffer)
 
void freeAllBuffers ()
 
void copy (AbstractBuffer *destBuffer, AbstractBuffer *srcBuffer)
 
bool isBufferOnDevice (const ChunkKey &key, const MemoryLevel memLevel, const int deviceId)
 
std::vector< MemoryInfogetMemoryInfo (const MemoryLevel memLevel)
 
std::string dumpLevel (const MemoryLevel memLevel)
 
void clearMemory (const MemoryLevel memLevel)
 
const std::map< ChunkKey,
File_Namespace::FileBuffer * > & 
getChunkMap ()
 
void checkpoint (const int db_id, const int tb_id)
 
void getChunkMetadataVec (std::vector< std::pair< ChunkKey, ChunkMetadata >> &chunkMetadataVec)
 
void getChunkMetadataVecForKeyPrefix (std::vector< std::pair< ChunkKey, ChunkMetadata >> &chunkMetadataVec, const ChunkKey &keyPrefix)
 
bool gpusPresent ()
 
void removeTableRelatedDS (const int db_id, const int tb_id)
 
void setTableEpoch (const int db_id, const int tb_id, const int start_epoch)
 
size_t getTableEpoch (const int db_id, const int tb_id)
 
CudaMgr_Namespace::CudaMgrgetCudaMgr () const
 
File_Namespace::GlobalFileMgrgetGlobalFileMgr () const
 

Public Attributes

std::vector< int > levelSizes_
 

Private Member Functions

size_t getTotalSystemMemory ()
 
void populateMgrs (const MapDParameters &mapd_parameters, const size_t userSpecifiedNumReaderThreads)
 
void convertDB (const std::string basePath)
 
void checkpoint ()
 
void createTopLevelMetadata () const
 

Private Attributes

std::vector< std::vector
< AbstractBufferMgr * > > 
bufferMgrs_
 
std::unique_ptr
< CudaMgr_Namespace::CudaMgr
cudaMgr_
 
std::string dataDir_
 
bool hasGpus_
 
size_t reservedGpuMem_
 
std::map< ChunkKey,
std::shared_ptr
< mapd_shared_mutex > > 
chunkMutexMap_
 
mapd_shared_mutex chunkMutexMapMutex_
 

Friends

class GlobalFileMgr
 

Detailed Description

Definition at line 66 of file DataMgr.h.

Constructor & Destructor Documentation

Data_Namespace::DataMgr::DataMgr ( const std::string &  dataDir,
const MapDParameters mapd_parameters,
const bool  useGpus,
const int  numGpus,
const int  startGpu = 0,
const size_t  reservedGpuMem = (1 << 27),
const size_t  numReaderThreads = 0 
)

Definition at line 46 of file DataMgr.cpp.

References createTopLevelMetadata(), cudaMgr_, hasGpus_, populateMgrs(), and reservedGpuMem_.

53  : dataDir_(dataDir) {
54  if (useGpus) {
55  try {
56  cudaMgr_ = std::make_unique<CudaMgr_Namespace::CudaMgr>(numGpus, startGpu);
57  reservedGpuMem_ = reservedGpuMem;
58  hasGpus_ = true;
59  } catch (std::runtime_error& error) {
60  hasGpus_ = false;
61  }
62  } else {
63  hasGpus_ = false;
64  }
65 
66  populateMgrs(mapd_parameters, numReaderThreads);
68 }
void createTopLevelMetadata() const
Definition: DataMgr.cpp:165
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132
void populateMgrs(const MapDParameters &mapd_parameters, const size_t userSpecifiedNumReaderThreads)
Definition: DataMgr.cpp:98
std::string dataDir_
Definition: DataMgr.h:133

+ Here is the call graph for this function:

Data_Namespace::DataMgr::~DataMgr ( )

Definition at line 70 of file DataMgr.cpp.

References bufferMgrs_.

70  {
71  int numLevels = bufferMgrs_.size();
72  for (int level = numLevels - 1; level >= 0; --level) {
73  for (size_t device = 0; device < bufferMgrs_[level].size(); device++) {
74  delete bufferMgrs_[level][device];
75  }
76  }
77 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131

Member Function Documentation

AbstractBuffer * Data_Namespace::DataMgr::alloc ( const MemoryLevel  memoryLevel,
const int  deviceId,
const size_t  numBytes 
)

Definition at line 374 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by CudaAllocator::allocGpuAbstractBuffer().

376  {
377  const auto level = static_cast<int>(memoryLevel);
378  CHECK_LT(deviceId, levelSizes_[level]);
379  return bufferMgrs_[level][deviceId]->alloc(numBytes);
380 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( const int  db_id,
const int  tb_id 
)

Definition at line 406 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Catalog_Namespace::Catalog::checkpoint().

406  {
407  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
408  // use reverse iterator so we start at GPU level, then CPU then DISK
409  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
410  (*deviceIt)->checkpoint(db_id, tb_id);
411  }
412  }
413 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( )
private

Definition at line 415 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by convertDB().

415  {
416  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
417  // use reverse iterator so we start at GPU level, then CPU then DISK
418  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
419  (*deviceIt)->checkpoint();
420  }
421  }
422 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::clearMemory ( const MemoryLevel  memLevel)

Definition at line 300 of file DataMgr.cpp.

References bufferMgrs_, cudaMgr_, Data_Namespace::GPU_LEVEL, logger::INFO, and LOG.

Referenced by Executor::clearMemory().

300  {
301  // if gpu we need to iterate through all the buffermanagers for each card
302  if (memLevel == MemoryLevel::GPU_LEVEL) {
303  if (cudaMgr_) {
304  int numGpus = cudaMgr_->getDeviceCount();
305  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
306  LOG(INFO) << "clear slabs on gpu " << gpuNum;
307  bufferMgrs_[memLevel][gpuNum]->clearSlabs();
308  }
309  } else {
310  throw std::runtime_error("Unable to clear GPU memory: No GPUs detected");
311  }
312  } else {
313  bufferMgrs_[memLevel][0]->clearSlabs();
314  }
315 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
#define LOG(tag)
Definition: Logger.h:185
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::convertDB ( const std::string  basePath)
private

Definition at line 139 of file DataMgr.cpp.

References bufferMgrs_, checkpoint(), logger::FATAL, File_Namespace::GlobalFileMgr::getDefaultPageSize(), logger::INFO, and LOG.

139  {
140  /* check that "mapd_data" directory exists and it's empty */
141  std::string mapdDataPath(basePath + "/../mapd_data/");
142  boost::filesystem::path path(mapdDataPath);
143  if (boost::filesystem::exists(path)) {
144  if (!boost::filesystem::is_directory(path)) {
145  LOG(FATAL) << "Path to directory mapd_data to convert DB is not a directory.";
146  }
147  } else { // data directory does not exist
148  LOG(FATAL) << "Path to directory mapd_data to convert DB does not exist.";
149  }
150 
151  GlobalFileMgr* gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
152  size_t defaultPageSize = gfm->getDefaultPageSize();
153  LOG(INFO) << "Database conversion started.";
154  FileMgr* fm_base_db =
155  new FileMgr(gfm,
156  defaultPageSize,
157  basePath); // this call also copies data into new DB structure
158  delete fm_base_db;
159 
160  /* write content of DB into newly created/converted DB structure & location */
161  checkpoint(); // outputs data files as well as metadata files
162  LOG(INFO) << "Database conversion completed.";
163 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
#define LOG(tag)
Definition: Logger.h:185
size_t getDefaultPageSize() const

+ Here is the call graph for this function:

void Data_Namespace::DataMgr::copy ( AbstractBuffer destBuffer,
AbstractBuffer srcBuffer 
)

Definition at line 392 of file DataMgr.cpp.

References Data_Namespace::AbstractBuffer::getDeviceId(), Data_Namespace::AbstractBuffer::getMemoryPtr(), Data_Namespace::AbstractBuffer::getType(), Data_Namespace::AbstractBuffer::size(), and Data_Namespace::AbstractBuffer::write().

392  {
393  destBuffer->write(srcBuffer->getMemoryPtr(),
394  srcBuffer->size(),
395  0,
396  srcBuffer->getType(),
397  srcBuffer->getDeviceId());
398 }
virtual size_t size() const =0
virtual int8_t * getMemoryPtr()=0
virtual MemoryLevel getType() const =0
virtual void write(int8_t *src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1)=0
virtual int getDeviceId() const

+ Here is the call graph for this function:

AbstractBuffer * Data_Namespace::DataMgr::createChunkBuffer ( const ChunkKey key,
const MemoryLevel  memoryLevel,
const int  deviceId = 0,
const size_t  page_size = 0 
)

Definition at line 336 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Chunk_NS::Chunk::createChunkBuffer().

339  {
340  int level = static_cast<int>(memoryLevel);
341  return bufferMgrs_[level][deviceId]->createBuffer(key, page_size);
342 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::createTopLevelMetadata ( ) const
private

Definition at line 165 of file DataMgr.cpp.

References bufferMgrs_, File_Namespace::FileMgr::createTopLevelMetadata(), and File_Namespace::GlobalFileMgr::getFileMgr().

Referenced by DataMgr().

166  { // create metadata shared by all tables of all DBs
167  ChunkKey chunkKey(2);
168  chunkKey[0] = 0; // top level db_id
169  chunkKey[1] = 0; // top level tb_id
170 
171  GlobalFileMgr* gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
172  FileMgr* fm_top = gfm->getFileMgr(chunkKey);
173  fm_top->createTopLevelMetadata();
174 }
std::vector< int > ChunkKey
Definition: types.h:35
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
FileMgr * getFileMgr(const int db_id, const int tb_id)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::deleteChunksWithPrefix ( const ChunkKey keyPrefix)

Definition at line 354 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

Referenced by freeAllBuffers().

354  {
355  int numLevels = bufferMgrs_.size();
356  for (int level = numLevels - 1; level >= 0; --level) {
357  for (int device = 0; device < levelSizes_[level]; ++device) {
358  bufferMgrs_[level][device]->deleteBuffersWithPrefix(keyPrefix);
359  }
360  }
361 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::deleteChunksWithPrefix ( const ChunkKey keyPrefix,
const MemoryLevel  memLevel 
)

Definition at line 364 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

365  {
366  if (bufferMgrs_.size() <= memLevel) {
367  return;
368  }
369  for (int device = 0; device < levelSizes_[memLevel]; ++device) {
370  bufferMgrs_[memLevel][device]->deleteBuffersWithPrefix(keyPrefix);
371  }
372 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121
std::string Data_Namespace::DataMgr::dumpLevel ( const MemoryLevel  memLevel)

Definition at line 286 of file DataMgr.cpp.

References bufferMgrs_, cudaMgr_, and Data_Namespace::GPU_LEVEL.

286  {
287  // if gpu we need to iterate through all the buffermanagers for each card
288  if (memLevel == MemoryLevel::GPU_LEVEL) {
289  int numGpus = cudaMgr_->getDeviceCount();
290  std::ostringstream tss;
291  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
292  tss << bufferMgrs_[memLevel][gpuNum]->printSlabs();
293  }
294  return tss.str();
295  } else {
296  return bufferMgrs_[memLevel][0]->printSlabs();
297  }
298 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132
void Data_Namespace::DataMgr::free ( AbstractBuffer buffer)

Definition at line 382 of file DataMgr.cpp.

References bufferMgrs_, Data_Namespace::AbstractBuffer::getDeviceId(), and Data_Namespace::AbstractBuffer::getType().

Referenced by ThrustAllocator::deallocate(), CudaAllocator::free(), CudaAllocator::freeGpuAbstractBuffer(), and ThrustAllocator::~ThrustAllocator().

382  {
383  int level = static_cast<int>(buffer->getType());
384  bufferMgrs_[level][buffer->getDeviceId()]->free(buffer);
385 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
virtual MemoryLevel getType() const =0
virtual int getDeviceId() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::freeAllBuffers ( )

Definition at line 387 of file DataMgr.cpp.

References deleteChunksWithPrefix().

Referenced by Executor::executeWorkUnitImpl().

387  {
388  ChunkKey keyPrefix = {-1};
389  deleteChunksWithPrefix(keyPrefix);
390 }
std::vector< int > ChunkKey
Definition: types.h:35
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:354

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AbstractBuffer * Data_Namespace::DataMgr::getChunkBuffer ( const ChunkKey key,
const MemoryLevel  memoryLevel,
const int  deviceId = 0,
const size_t  numBytes = 0 
)

Definition at line 344 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by Chunk_NS::Chunk::getChunkBuffer().

347  {
348  const auto level = static_cast<size_t>(memoryLevel);
349  CHECK_LT(level, levelSizes_.size()); // make sure we have a legit buffermgr
350  CHECK_LT(deviceId, levelSizes_[level]); // make sure we have a legit buffermgr
351  return bufferMgrs_[level][deviceId]->getBuffer(key, numBytes);
352 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the caller graph for this function:

const std::map<ChunkKey, File_Namespace::FileBuffer*>& Data_Namespace::DataMgr::getChunkMap ( )
void Data_Namespace::DataMgr::getChunkMetadataVec ( std::vector< std::pair< ChunkKey, ChunkMetadata >> &  chunkMetadataVec)

Definition at line 323 of file DataMgr.cpp.

References bufferMgrs_.

324  {
325  // Can we always assume this will just be at the disklevel bc we just
326  // started?
327  bufferMgrs_[0][0]->getChunkMetadataVec(chunkMetadataVec);
328 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
void Data_Namespace::DataMgr::getChunkMetadataVecForKeyPrefix ( std::vector< std::pair< ChunkKey, ChunkMetadata >> &  chunkMetadataVec,
const ChunkKey keyPrefix 
)

Definition at line 330 of file DataMgr.cpp.

References bufferMgrs_.

332  {
333  bufferMgrs_[0][0]->getChunkMetadataVecForKeyPrefix(chunkMetadataVec, keyPrefix);
334 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
CudaMgr_Namespace::CudaMgr* Data_Namespace::DataMgr::getCudaMgr ( ) const
inline

Definition at line 117 of file DataMgr.h.

References cudaMgr_.

Referenced by copy_from_gpu(), copy_to_gpu(), CudaAllocator::copyFromDevice(), CudaAllocator::copyToDevice(), CudaAllocator::CudaAllocator(), get_available_gpus(), Executor::isArchPascalOrLater(), CudaAllocator::setDeviceMem(), and CudaAllocator::zeroDeviceMem().

117 { return cudaMgr_.get(); }
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132

+ Here is the caller graph for this function:

GlobalFileMgr * Data_Namespace::DataMgr::getGlobalFileMgr ( ) const

Definition at line 437 of file DataMgr.cpp.

References bufferMgrs_, and CHECK().

Referenced by Catalog_Namespace::Catalog::dumpTable(), Catalog_Namespace::Catalog::getTableDataDirectories(), Catalog_Namespace::Catalog::renameTableDirectories(), and Catalog_Namespace::Catalog::restoreTable().

437  {
438  auto global_file_mgr = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
439  CHECK(global_file_mgr);
440  return global_file_mgr;
441 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< MemoryInfo > Data_Namespace::DataMgr::getMemoryInfo ( const MemoryLevel  memLevel)

Definition at line 176 of file DataMgr.cpp.

References bufferMgrs_, Data_Namespace::MemoryData::chunk_key, Data_Namespace::CPU_LEVEL, cudaMgr_, Buffer_Namespace::BufferMgr::getAllocated(), Buffer_Namespace::BufferMgr::getMaxSize(), Buffer_Namespace::BufferMgr::getPageSize(), Buffer_Namespace::BufferMgr::getSlabSegments(), Data_Namespace::GPU_LEVEL, hasGpus_, Data_Namespace::MemoryInfo::isAllocationCapped, Buffer_Namespace::BufferMgr::isAllocationCapped(), Data_Namespace::MemoryData::isFree, Data_Namespace::MemoryInfo::maxNumPages, Data_Namespace::MemoryInfo::nodeMemoryData, Data_Namespace::MemoryInfo::numPageAllocated, Data_Namespace::MemoryData::numPages, Data_Namespace::MemoryInfo::pageSize, Data_Namespace::MemoryData::slabNum, Data_Namespace::MemoryData::startPage, and Data_Namespace::MemoryData::touch.

Referenced by Executor::executeWorkUnitImpl().

176  {
177  // TODO (vraj) : Reduce the duplicate code
178  std::vector<MemoryInfo> memInfo;
179  if (memLevel == MemoryLevel::CPU_LEVEL) {
180  CpuBufferMgr* cpuBuffer =
181  dynamic_cast<CpuBufferMgr*>(bufferMgrs_[MemoryLevel::CPU_LEVEL][0]);
182  MemoryInfo mi;
183 
184  mi.pageSize = cpuBuffer->getPageSize();
185  mi.maxNumPages = cpuBuffer->getMaxSize() / mi.pageSize;
186  mi.isAllocationCapped = cpuBuffer->isAllocationCapped();
187  mi.numPageAllocated = cpuBuffer->getAllocated() / mi.pageSize;
188 
189  const std::vector<BufferList> slab_segments = cpuBuffer->getSlabSegments();
190  size_t numSlabs = slab_segments.size();
191 
192  for (size_t slabNum = 0; slabNum != numSlabs; ++slabNum) {
193  for (auto segIt : slab_segments[slabNum]) {
194  MemoryData md;
195  md.slabNum = slabNum;
196  md.startPage = segIt.start_page;
197  md.numPages = segIt.num_pages;
198  md.touch = segIt.last_touched;
199  md.isFree = segIt.mem_status;
200  md.chunk_key.insert(
201  md.chunk_key.end(), segIt.chunk_key.begin(), segIt.chunk_key.end());
202  mi.nodeMemoryData.push_back(md);
203  }
204  }
205  memInfo.push_back(mi);
206  } else if (hasGpus_) {
207  int numGpus = cudaMgr_->getDeviceCount();
208  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
209  GpuCudaBufferMgr* gpuBuffer =
210  dynamic_cast<GpuCudaBufferMgr*>(bufferMgrs_[MemoryLevel::GPU_LEVEL][gpuNum]);
211  MemoryInfo mi;
212 
213  mi.pageSize = gpuBuffer->getPageSize();
214  mi.maxNumPages = gpuBuffer->getMaxSize() / mi.pageSize;
215  mi.isAllocationCapped = gpuBuffer->isAllocationCapped();
216  mi.numPageAllocated = gpuBuffer->getAllocated() / mi.pageSize;
217  const std::vector<BufferList> slab_segments = gpuBuffer->getSlabSegments();
218  size_t numSlabs = slab_segments.size();
219 
220  for (size_t slabNum = 0; slabNum != numSlabs; ++slabNum) {
221  for (auto segIt : slab_segments[slabNum]) {
222  MemoryData md;
223  md.slabNum = slabNum;
224  md.startPage = segIt.start_page;
225  md.numPages = segIt.num_pages;
226  md.touch = segIt.last_touched;
227  md.chunk_key.insert(
228  md.chunk_key.end(), segIt.chunk_key.begin(), segIt.chunk_key.end());
229  md.isFree = segIt.mem_status;
230  mi.nodeMemoryData.push_back(md);
231  }
232  }
233  memInfo.push_back(mi);
234  }
235  }
236  return memInfo;
237 }
size_t getAllocated() override
Definition: BufferMgr.cpp:483
std::vector< MemoryData > nodeMemoryData
Definition: DataMgr.h:63
size_t getMaxSize() override
Definition: BufferMgr.cpp:478
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
Buffer_Namespace::MemStatus isFree
Definition: DataMgr.h:55
bool isAllocationCapped() override
Definition: BufferMgr.cpp:488
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132
const std::vector< BufferList > & getSlabSegments()
Definition: BufferMgr.cpp:878
std::vector< int32_t > chunk_key
Definition: DataMgr.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t Data_Namespace::DataMgr::getTableEpoch ( const int  db_id,
const int  tb_id 
)

Definition at line 433 of file DataMgr.cpp.

References bufferMgrs_.

433  {
434  return dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])->getTableEpoch(db_id, tb_id);
435 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
size_t getTableEpoch(const int db_id, const int tb_id)
Definition: DataMgr.cpp:433
size_t Data_Namespace::DataMgr::getTotalSystemMemory ( )
private

Definition at line 79 of file DataMgr.cpp.

Referenced by populateMgrs().

79  {
80 #ifdef __APPLE__
81  int mib[2];
82  size_t physical_memory;
83  size_t length;
84  // Get the Physical memory size
85  mib[0] = CTL_HW;
86  mib[1] = HW_MEMSIZE;
87  length = sizeof(size_t);
88  sysctl(mib, 2, &physical_memory, &length, NULL, 0);
89  return physical_memory;
90 
91 #else
92  long pages = sysconf(_SC_PHYS_PAGES);
93  long page_size = sysconf(_SC_PAGE_SIZE);
94  return pages * page_size;
95 #endif
96 }

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::gpusPresent ( )
inline

Definition at line 112 of file DataMgr.h.

References hasGpus_.

Referenced by get_available_gpus().

112 { return hasGpus_; }

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::isBufferOnDevice ( const ChunkKey key,
const MemoryLevel  memLevel,
const int  deviceId 
)

Definition at line 317 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Chunk_NS::Chunk::isChunkOnDevice().

319  {
320  return bufferMgrs_[memLevel][deviceId]->isBufferOnDevice(key);
321 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::populateMgrs ( const MapDParameters mapd_parameters,
const size_t  userSpecifiedNumReaderThreads 
)
private

Definition at line 98 of file DataMgr.cpp.

References bufferMgrs_, MapDParameters::cpu_buffer_mem_bytes, cudaMgr_, dataDir_, getTotalSystemMemory(), GlobalFileMgr, MapDParameters::gpu_buffer_mem_bytes, hasGpus_, logger::INFO, levelSizes_, LOG, and reservedGpuMem_.

Referenced by DataMgr().

99  {
100  bufferMgrs_.resize(2);
101  bufferMgrs_[0].push_back(new GlobalFileMgr(0, dataDir_, userSpecifiedNumReaderThreads));
102  levelSizes_.push_back(1);
103  size_t cpuBufferSize = mapd_parameters.cpu_buffer_mem_bytes;
104  if (cpuBufferSize == 0) { // if size is not specified
105  cpuBufferSize = getTotalSystemMemory() *
106  0.8; // should get free memory instead of this ugly heuristic
107  }
108  size_t cpuSlabSize = std::min(static_cast<size_t>(1L << 32), cpuBufferSize);
109  // cpuSlabSize -= cpuSlabSize % 512 == 0 ? 0 : 512 - (cpuSlabSize % 512);
110  cpuSlabSize = (cpuSlabSize / 512) * 512;
111  LOG(INFO) << "cpuSlabSize is " << (float)cpuSlabSize / (1024 * 1024) << "M";
112  if (hasGpus_) {
113  LOG(INFO) << "reserved GPU memory is " << (float)reservedGpuMem_ / (1024 * 1024)
114  << "M includes render buffer allocation";
115  bufferMgrs_.resize(3);
116  bufferMgrs_[1].push_back(new CpuBufferMgr(
117  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
118  levelSizes_.push_back(1);
119  int numGpus = cudaMgr_->getDeviceCount();
120  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
121  size_t gpuMaxMemSize =
122  mapd_parameters.gpu_buffer_mem_bytes != 0
123  ? mapd_parameters.gpu_buffer_mem_bytes
124  : (cudaMgr_->getDeviceProperties(gpuNum)->globalMem) - (reservedGpuMem_);
125  size_t gpuSlabSize = std::min(static_cast<size_t>(1L << 31), gpuMaxMemSize);
126  gpuSlabSize -= gpuSlabSize % 512 == 0 ? 0 : 512 - (gpuSlabSize % 512);
127  LOG(INFO) << "gpuSlabSize is " << (float)gpuSlabSize / (1024 * 1024) << "M";
128  bufferMgrs_[2].push_back(new GpuCudaBufferMgr(
129  gpuNum, gpuMaxMemSize, cudaMgr_.get(), gpuSlabSize, 512, bufferMgrs_[1][0]));
130  }
131  levelSizes_.push_back(numGpus);
132  } else {
133  bufferMgrs_[1].push_back(new CpuBufferMgr(
134  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
135  levelSizes_.push_back(1);
136  }
137 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121
#define LOG(tag)
Definition: Logger.h:185
size_t gpu_buffer_mem_bytes
size_t getTotalSystemMemory()
Definition: DataMgr.cpp:79
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:132
size_t cpu_buffer_mem_bytes
friend class GlobalFileMgr
Definition: DataMgr.h:67
std::string dataDir_
Definition: DataMgr.h:133

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::removeTableRelatedDS ( const int  db_id,
const int  tb_id 
)

Definition at line 424 of file DataMgr.cpp.

References bufferMgrs_.

424  {
425  dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])->removeTableRelatedDS(db_id, tb_id);
426 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
void removeTableRelatedDS(const int db_id, const int tb_id)
Definition: DataMgr.cpp:424
void Data_Namespace::DataMgr::setTableEpoch ( const int  db_id,
const int  tb_id,
const int  start_epoch 
)

Definition at line 428 of file DataMgr.cpp.

References bufferMgrs_.

428  {
429  dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])
430  ->setTableEpoch(db_id, tb_id, start_epoch);
431 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
void setTableEpoch(const int db_id, const int tb_id, const int start_epoch)
Definition: DataMgr.cpp:428

Friends And Related Function Documentation

friend class GlobalFileMgr
friend

Definition at line 67 of file DataMgr.h.

Referenced by populateMgrs().

Member Data Documentation

std::map<ChunkKey, std::shared_ptr<mapd_shared_mutex> > Data_Namespace::DataMgr::chunkMutexMap_
private

Definition at line 136 of file DataMgr.h.

mapd_shared_mutex Data_Namespace::DataMgr::chunkMutexMapMutex_
private

Definition at line 137 of file DataMgr.h.

std::unique_ptr<CudaMgr_Namespace::CudaMgr> Data_Namespace::DataMgr::cudaMgr_
private

Definition at line 132 of file DataMgr.h.

Referenced by clearMemory(), DataMgr(), dumpLevel(), getCudaMgr(), getMemoryInfo(), and populateMgrs().

std::string Data_Namespace::DataMgr::dataDir_
private

Definition at line 133 of file DataMgr.h.

Referenced by populateMgrs().

bool Data_Namespace::DataMgr::hasGpus_
private

Definition at line 134 of file DataMgr.h.

Referenced by DataMgr(), getMemoryInfo(), gpusPresent(), and populateMgrs().

std::vector<int> Data_Namespace::DataMgr::levelSizes_

Definition at line 121 of file DataMgr.h.

Referenced by alloc(), deleteChunksWithPrefix(), getChunkBuffer(), and populateMgrs().

size_t Data_Namespace::DataMgr::reservedGpuMem_
private

Definition at line 135 of file DataMgr.h.

Referenced by DataMgr(), and populateMgrs().


The documentation for this class was generated from the following files: