OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThrustAllocator Class Reference

#include <ThrustAllocator.h>

+ Collaboration diagram for ThrustAllocator:

Public Types

using value_type = int8_t
 

Public Member Functions

 ThrustAllocator (Data_Namespace::DataMgr *mgr, const int id)
 
 ~ThrustAllocator ()
 
int8_t * allocate (std::ptrdiff_t num_bytes)
 
void deallocate (int8_t *ptr, size_t num_bytes)
 
int8_t * allocateScopedBuffer (std::ptrdiff_t num_bytes)
 
Data_Namespace::DataMgrgetDataMgr () const
 
int getDeviceId () const
 

Private Types

using PtrMapperType = std::unordered_map< int8_t *, Data_Namespace::AbstractBuffer * >
 

Private Attributes

Data_Namespace::DataMgrdata_mgr_
 
const int device_id_
 
PtrMapperType raw_to_ab_ptr_
 
std::vector
< Data_Namespace::AbstractBuffer * > 
scoped_buffers_
 
std::vector< int8_t * > default_alloc_scoped_buffers_
 
size_t num_allocations_ {0}
 

Detailed Description

Definition at line 37 of file ThrustAllocator.h.

Member Typedef Documentation

using ThrustAllocator::PtrMapperType = std::unordered_map<int8_t*, Data_Namespace::AbstractBuffer*>
private

Definition at line 56 of file ThrustAllocator.h.

Definition at line 39 of file ThrustAllocator.h.

Constructor & Destructor Documentation

ThrustAllocator::ThrustAllocator ( Data_Namespace::DataMgr mgr,
const int  id 
)
inline

Definition at line 40 of file ThrustAllocator.h.

41  : data_mgr_(mgr), device_id_(id) {}
Data_Namespace::DataMgr * data_mgr_
const int device_id_
ThrustAllocator::~ThrustAllocator ( )

Definition at line 86 of file ThrustAllocator.cpp.

References CHECK, CHECK_EQ, data_mgr_, default_alloc_scoped_buffers_, device_id_, logger::ERROR, Data_Namespace::DataMgr::free(), LOG, raw_to_ab_ptr_, scoped_buffers_, and VLOG.

86  {
87  for (auto ab : scoped_buffers_) {
88  data_mgr_->free(ab);
89  }
90 #ifdef HAVE_CUDA
91  for (auto ptr : default_alloc_scoped_buffers_) {
92  const auto err = cuMemFree(reinterpret_cast<CUdeviceptr>(ptr));
93  CHECK_EQ(CUDA_SUCCESS, err);
94  }
95 #endif // HAVE_CUDA
96  if (!raw_to_ab_ptr_.empty()) {
97  LOG(ERROR) << "Not all GPU buffers deallocated before destruction of Thrust "
98  "allocator for device "
99  << device_id_ << ". Remaining buffers: ";
100  for (auto& kv : raw_to_ab_ptr_) {
101  auto& ab = kv.second;
102  CHECK(ab);
103  LOG(ERROR) << (ab->pageCount() * ab->pageSize()) / (1024. * 1024.) << " MB";
104  }
105  VLOG(1) << boost::stacktrace::stacktrace();
106  }
107 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define LOG(tag)
Definition: Logger.h:285
std::vector< Data_Namespace::AbstractBuffer * > scoped_buffers_
std::vector< int8_t * > default_alloc_scoped_buffers_
Data_Namespace::DataMgr * data_mgr_
const int device_id_
PtrMapperType raw_to_ab_ptr_
#define CHECK(condition)
Definition: Logger.h:291
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:564
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

Member Function Documentation

int8_t * ThrustAllocator::allocate ( std::ptrdiff_t  num_bytes)

Definition at line 29 of file ThrustAllocator.cpp.

References Data_Namespace::DataMgr::alloc(), CudaAllocator::allocGpuAbstractBuffer(), CHECK, CHECK_EQ, Data_Namespace::CPU_LEVEL, data_mgr_, device_id_, Data_Namespace::AbstractBuffer::getMemoryPtr(), Data_Namespace::AbstractBuffer::getPinCount(), num_allocations_, raw_to_ab_ptr_, and VLOG.

Referenced by Data_Namespace::detail::DataMgrMemoryResource< Pointer >::do_allocate().

29  {
30  VLOG(1) << "Thrust allocation: Device #" << device_id_ << " Allocation #"
31  << ++num_allocations_ << ": " << num_bytes << " bytes";
32 #ifdef HAVE_CUDA
33  if (!data_mgr_) { // only for unit tests
34  CUdeviceptr ptr;
35  const auto err = cuMemAlloc(&ptr, num_bytes);
36  CHECK_EQ(CUDA_SUCCESS, err);
37  return reinterpret_cast<int8_t*>(ptr);
38  }
41 #else
44  CHECK_EQ(ab->getPinCount(), 1);
45 #endif // HAVE_CUDA
46  int8_t* raw_ptr = reinterpret_cast<int8_t*>(ab->getMemoryPtr());
47  CHECK(!raw_to_ab_ptr_.count(raw_ptr));
48  raw_to_ab_ptr_.insert(std::make_pair(raw_ptr, ab));
49  return raw_ptr;
50 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
virtual int8_t * getMemoryPtr()=0
unsigned long long CUdeviceptr
Definition: nocuda.h:28
Data_Namespace::DataMgr * data_mgr_
const int device_id_
PtrMapperType raw_to_ab_ptr_
An AbstractBuffer is a unit of data management for a data manager.
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
#define CHECK(condition)
Definition: Logger.h:291
#define VLOG(n)
Definition: Logger.h:388
AbstractBuffer * alloc(const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
Definition: DataMgr.cpp:555

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t * ThrustAllocator::allocateScopedBuffer ( std::ptrdiff_t  num_bytes)

Definition at line 66 of file ThrustAllocator.cpp.

References Data_Namespace::DataMgr::alloc(), CudaAllocator::allocGpuAbstractBuffer(), CHECK_EQ, Data_Namespace::CPU_LEVEL, data_mgr_, default_alloc_scoped_buffers_, device_id_, Data_Namespace::AbstractBuffer::getMemoryPtr(), Data_Namespace::AbstractBuffer::getPinCount(), and scoped_buffers_.

Referenced by anonymous_namespace{ResultSetSortImpl.cu}::get_device_copy_ptr().

66  {
67 #ifdef HAVE_CUDA
68  if (!data_mgr_) { // only for unit tests
69  CUdeviceptr ptr;
70  const auto err = cuMemAlloc(&ptr, num_bytes);
71  CHECK_EQ(CUDA_SUCCESS, err);
72  default_alloc_scoped_buffers_.push_back(reinterpret_cast<int8_t*>(ptr));
73  return reinterpret_cast<int8_t*>(ptr);
74  }
77 #else
80  CHECK_EQ(ab->getPinCount(), 1);
81 #endif // HAVE_CUDA
82  scoped_buffers_.push_back(ab);
83  return reinterpret_cast<int8_t*>(ab->getMemoryPtr());
84 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< Data_Namespace::AbstractBuffer * > scoped_buffers_
virtual int8_t * getMemoryPtr()=0
unsigned long long CUdeviceptr
Definition: nocuda.h:28
std::vector< int8_t * > default_alloc_scoped_buffers_
Data_Namespace::DataMgr * data_mgr_
const int device_id_
An AbstractBuffer is a unit of data management for a data manager.
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
AbstractBuffer * alloc(const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
Definition: DataMgr.cpp:555

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThrustAllocator::deallocate ( int8_t *  ptr,
size_t  num_bytes 
)

Definition at line 52 of file ThrustAllocator.cpp.

References CHECK, CHECK_EQ, data_mgr_, Data_Namespace::DataMgr::free(), and raw_to_ab_ptr_.

Referenced by Data_Namespace::detail::DataMgrMemoryResource< Pointer >::do_deallocate().

52  {
53 #ifdef HAVE_CUDA
54  if (!data_mgr_) { // only for unit tests
55  const auto err = cuMemFree(reinterpret_cast<CUdeviceptr>(ptr));
56  CHECK_EQ(CUDA_SUCCESS, err);
57  return;
58  }
59 #endif // HAVE_CUDA
60  PtrMapperType::iterator ab_it = raw_to_ab_ptr_.find(ptr);
61  CHECK(ab_it != raw_to_ab_ptr_.end());
62  data_mgr_->free(ab_it->second);
63  raw_to_ab_ptr_.erase(ab_it);
64 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Data_Namespace::DataMgr * data_mgr_
PtrMapperType raw_to_ab_ptr_
#define CHECK(condition)
Definition: Logger.h:291
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:564

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Data_Namespace::DataMgr* ThrustAllocator::getDataMgr ( ) const
inline

Definition at line 49 of file ThrustAllocator.h.

References data_mgr_.

Referenced by anonymous_namespace{ResultSetSortImpl.cu}::get_device_copy_ptr().

49 { return data_mgr_; }
Data_Namespace::DataMgr * data_mgr_

+ Here is the caller graph for this function:

int ThrustAllocator::getDeviceId ( ) const
inline

Definition at line 51 of file ThrustAllocator.h.

References device_id_.

Referenced by anonymous_namespace{ResultSetSortImpl.cu}::get_device_copy_ptr().

51 { return device_id_; }
const int device_id_

+ Here is the caller graph for this function:

Member Data Documentation

Data_Namespace::DataMgr* ThrustAllocator::data_mgr_
private
std::vector<int8_t*> ThrustAllocator::default_alloc_scoped_buffers_
private

Definition at line 59 of file ThrustAllocator.h.

Referenced by allocateScopedBuffer(), and ~ThrustAllocator().

const int ThrustAllocator::device_id_
private

Definition at line 55 of file ThrustAllocator.h.

Referenced by allocate(), allocateScopedBuffer(), getDeviceId(), and ~ThrustAllocator().

size_t ThrustAllocator::num_allocations_ {0}
private

Definition at line 60 of file ThrustAllocator.h.

Referenced by allocate().

PtrMapperType ThrustAllocator::raw_to_ab_ptr_
private

Definition at line 57 of file ThrustAllocator.h.

Referenced by allocate(), deallocate(), and ~ThrustAllocator().

std::vector<Data_Namespace::AbstractBuffer*> ThrustAllocator::scoped_buffers_
private

Definition at line 58 of file ThrustAllocator.h.

Referenced by allocateScopedBuffer(), and ~ThrustAllocator().


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