OmniSciDB  eee9fa949c
 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:171
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 380 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by CudaAllocator::allocGpuAbstractBuffer().

382  {
383  const auto level = static_cast<int>(memoryLevel);
384  CHECK_LT(deviceId, levelSizes_[level]);
385  return bufferMgrs_[level][deviceId]->alloc(numBytes);
386 }
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:207

+ Here is the caller graph for this function:

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

Definition at line 412 of file DataMgr.cpp.

References bufferMgrs_.

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

412  {
413  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
414  // use reverse iterator so we start at GPU level, then CPU then DISK
415  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
416  (*deviceIt)->checkpoint(db_id, tb_id);
417  }
418  }
419 }
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 421 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by convertDB().

421  {
422  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
423  // use reverse iterator so we start at GPU level, then CPU then DISK
424  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
425  (*deviceIt)->checkpoint();
426  }
427  }
428 }
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 306 of file DataMgr.cpp.

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

Referenced by Executor::clearMemory().

306  {
307  // if gpu we need to iterate through all the buffermanagers for each card
308  if (memLevel == MemoryLevel::GPU_LEVEL) {
309  if (cudaMgr_) {
310  int numGpus = cudaMgr_->getDeviceCount();
311  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
312  LOG(INFO) << "clear slabs on gpu " << gpuNum;
313  bufferMgrs_[memLevel][gpuNum]->clearSlabs();
314  }
315  } else {
316  throw std::runtime_error("Unable to clear GPU memory: No GPUs detected");
317  }
318  } else {
319  bufferMgrs_[memLevel][0]->clearSlabs();
320  }
321 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
#define LOG(tag)
Definition: Logger.h:188
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 145 of file DataMgr.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 398 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().

398  {
399  destBuffer->write(srcBuffer->getMemoryPtr(),
400  srcBuffer->size(),
401  0,
402  srcBuffer->getType(),
403  srcBuffer->getDeviceId());
404 }
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 342 of file DataMgr.cpp.

References bufferMgrs_.

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

345  {
346  int level = static_cast<int>(memoryLevel);
347  return bufferMgrs_[level][deviceId]->createBuffer(key, page_size);
348 }
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 171 of file DataMgr.cpp.

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

Referenced by DataMgr().

172  { // create metadata shared by all tables of all DBs
173  ChunkKey chunkKey(2);
174  chunkKey[0] = 0; // top level db_id
175  chunkKey[1] = 0; // top level tb_id
176 
177  GlobalFileMgr* gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
178  FileMgr* fm_top = gfm->getFileMgr(chunkKey);
179  fm_top->createTopLevelMetadata();
180 }
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 360 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

Referenced by freeAllBuffers().

360  {
361  int numLevels = bufferMgrs_.size();
362  for (int level = numLevels - 1; level >= 0; --level) {
363  for (int device = 0; device < levelSizes_[level]; ++device) {
364  bufferMgrs_[level][device]->deleteBuffersWithPrefix(keyPrefix);
365  }
366  }
367 }
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 370 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

371  {
372  if (bufferMgrs_.size() <= memLevel) {
373  return;
374  }
375  for (int device = 0; device < levelSizes_[memLevel]; ++device) {
376  bufferMgrs_[memLevel][device]->deleteBuffersWithPrefix(keyPrefix);
377  }
378 }
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 292 of file DataMgr.cpp.

References bufferMgrs_, cudaMgr_, and Data_Namespace::GPU_LEVEL.

292  {
293  // if gpu we need to iterate through all the buffermanagers for each card
294  if (memLevel == MemoryLevel::GPU_LEVEL) {
295  int numGpus = cudaMgr_->getDeviceCount();
296  std::ostringstream tss;
297  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
298  tss << bufferMgrs_[memLevel][gpuNum]->printSlabs();
299  }
300  return tss.str();
301  } else {
302  return bufferMgrs_[memLevel][0]->printSlabs();
303  }
304 }
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 388 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().

388  {
389  int level = static_cast<int>(buffer->getType());
390  bufferMgrs_[level][buffer->getDeviceId()]->free(buffer);
391 }
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 393 of file DataMgr.cpp.

References deleteChunksWithPrefix().

Referenced by Executor::executeWorkUnitImpl().

393  {
394  ChunkKey keyPrefix = {-1};
395  deleteChunksWithPrefix(keyPrefix);
396 }
std::vector< int > ChunkKey
Definition: types.h:35
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:360

+ 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 350 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

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

353  {
354  const auto level = static_cast<size_t>(memoryLevel);
355  CHECK_LT(level, levelSizes_.size()); // make sure we have a legit buffermgr
356  CHECK_LT(deviceId, levelSizes_[level]); // make sure we have a legit buffermgr
357  return bufferMgrs_[level][deviceId]->getBuffer(key, numBytes);
358 }
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:207

+ 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 329 of file DataMgr.cpp.

References bufferMgrs_.

330  {
331  // Can we always assume this will just be at the disklevel bc we just
332  // started?
333  bufferMgrs_[0][0]->getChunkMetadataVec(chunkMetadataVec);
334 }
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 336 of file DataMgr.cpp.

References bufferMgrs_.

338  {
339  bufferMgrs_[0][0]->getChunkMetadataVecForKeyPrefix(chunkMetadataVec, keyPrefix);
340 }
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 443 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().

443  {
444  auto global_file_mgr = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
445  CHECK(global_file_mgr);
446  return global_file_mgr;
447 }
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 182 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::MemoryInfo::maxNumPages, Data_Namespace::MemoryData::memStatus, 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().

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

References bufferMgrs_.

439  {
440  return dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])->getTableEpoch(db_id, tb_id);
441 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
size_t getTableEpoch(const int db_id, const int tb_id)
Definition: DataMgr.cpp:439
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 323 of file DataMgr.cpp.

References bufferMgrs_.

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

325  {
326  return bufferMgrs_[memLevel][deviceId]->isBufferOnDevice(key);
327 }
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, reservedGpuMem_, and VLOG.

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  const auto total_system_memory = getTotalSystemMemory();
106  VLOG(1) << "Detected " << (float)total_system_memory / (1024 * 1024)
107  << "M of total system memory.";
108  cpuBufferSize = total_system_memory *
109  0.8; // should get free memory instead of this ugly heuristic
110  }
111  size_t cpuSlabSize = std::min(static_cast<size_t>(1L << 32), cpuBufferSize);
112  // cpuSlabSize -= cpuSlabSize % 512 == 0 ? 0 : 512 - (cpuSlabSize % 512);
113  cpuSlabSize = (cpuSlabSize / 512) * 512;
114  LOG(INFO) << "cpuSlabSize is " << (float)cpuSlabSize / (1024 * 1024) << "M";
115  LOG(INFO) << "memory pool for CPU is " << (float)cpuBufferSize / (1024 * 1024) << "M";
116  if (hasGpus_) {
117  LOG(INFO) << "reserved GPU memory is " << (float)reservedGpuMem_ / (1024 * 1024)
118  << "M includes render buffer allocation";
119  bufferMgrs_.resize(3);
120  bufferMgrs_[1].push_back(new CpuBufferMgr(
121  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
122  levelSizes_.push_back(1);
123  int numGpus = cudaMgr_->getDeviceCount();
124  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
125  size_t gpuMaxMemSize =
126  mapd_parameters.gpu_buffer_mem_bytes != 0
127  ? mapd_parameters.gpu_buffer_mem_bytes
128  : (cudaMgr_->getDeviceProperties(gpuNum)->globalMem) - (reservedGpuMem_);
129  size_t gpuSlabSize = std::min(static_cast<size_t>(1L << 31), gpuMaxMemSize);
130  gpuSlabSize -= gpuSlabSize % 512 == 0 ? 0 : 512 - (gpuSlabSize % 512);
131  LOG(INFO) << "gpuSlabSize is " << (float)gpuSlabSize / (1024 * 1024) << "M";
132  LOG(INFO) << "memory pool for GPU " << gpuNum << " is "
133  << (float)gpuMaxMemSize / (1024 * 1024) << "M";
134  bufferMgrs_[2].push_back(new GpuCudaBufferMgr(
135  gpuNum, gpuMaxMemSize, cudaMgr_.get(), gpuSlabSize, 512, bufferMgrs_[1][0]));
136  }
137  levelSizes_.push_back(numGpus);
138  } else {
139  bufferMgrs_[1].push_back(new CpuBufferMgr(
140  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
141  levelSizes_.push_back(1);
142  }
143 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:131
std::vector< int > levelSizes_
Definition: DataMgr.h:121
#define LOG(tag)
Definition: Logger.h:188
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
#define VLOG(n)
Definition: Logger.h:291
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 430 of file DataMgr.cpp.

References bufferMgrs_.

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

Definition at line 434 of file DataMgr.cpp.

References bufferMgrs_.

434  {
435  dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])
436  ->setTableEpoch(db_id, tb_id, start_epoch);
437 }
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:434

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: