OmniSciDB  04ee39c94c
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_
 

Detailed Description

Definition at line 36 of file ThrustAllocator.h.

Member Typedef Documentation

◆ PtrMapperType

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

Definition at line 55 of file ThrustAllocator.h.

◆ value_type

Definition at line 38 of file ThrustAllocator.h.

Constructor & Destructor Documentation

◆ ThrustAllocator()

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

Definition at line 39 of file ThrustAllocator.h.

40  : data_mgr_(mgr), device_id_(id) {}
Data_Namespace::DataMgr * data_mgr_
const int device_id_

◆ ~ThrustAllocator()

ThrustAllocator::~ThrustAllocator ( )

Definition at line 71 of file ThrustAllocator.cpp.

References CHECK_EQ, data_mgr_, default_alloc_scoped_buffers_, Data_Namespace::DataMgr::free(), and scoped_buffers_.

71  {
72  for (auto ab : scoped_buffers_) {
73  data_mgr_->free(ab);
74  }
75 #ifdef HAVE_CUDA
76  for (auto ptr : default_alloc_scoped_buffers_) {
77  const auto err = cuMemFree(reinterpret_cast<CUdeviceptr>(ptr));
78  CHECK_EQ(CUDA_SUCCESS, err);
79  }
80 #endif // HAVE_CUDA
81 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::vector< Data_Namespace::AbstractBuffer * > scoped_buffers_
std::vector< int8_t * > default_alloc_scoped_buffers_
Data_Namespace::DataMgr * data_mgr_
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:382
+ Here is the call graph for this function:

Member Function Documentation

◆ allocate()

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

Definition at line 24 of file ThrustAllocator.cpp.

References CudaAllocator::allocGpuAbstractBuffer(), CHECK, CHECK_EQ, data_mgr_, device_id_, Data_Namespace::AbstractBuffer::getMemoryPtr(), and raw_to_ab_ptr_.

Referenced by BaselineJoinHashTable::fetchColumn(), and JoinHashTable::fetchFragments().

24  {
25 #ifdef HAVE_CUDA
26  if (!data_mgr_) { // only for unit tests
27  CUdeviceptr ptr;
28  const auto err = cuMemAlloc(&ptr, num_bytes);
29  CHECK_EQ(CUDA_SUCCESS, err);
30  return reinterpret_cast<int8_t*>(ptr);
31  }
32 #endif // HAVE_CUDA
35  int8_t* raw_ptr = reinterpret_cast<int8_t*>(ab->getMemoryPtr());
36  CHECK(!raw_to_ab_ptr_.count(raw_ptr));
37  raw_to_ab_ptr_.insert(std::make_pair(raw_ptr, ab));
38  return raw_ptr;
39 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
virtual int8_t * getMemoryPtr()=0
unsigned long long CUdeviceptr
Definition: nocuda.h:27
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:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allocateScopedBuffer()

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

Definition at line 55 of file ThrustAllocator.cpp.

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

Referenced by OverlapsJoinHashTable::approximateTupleCount(), BaselineJoinHashTable::approximateTupleCount(), OverlapsJoinHashTable::initHashTableOnGpu(), BaselineJoinHashTable::initHashTableOnGpu(), transfer_object_to_gpu(), and transfer_pod_vector_to_gpu().

55  {
56 #ifdef HAVE_CUDA
57  if (!data_mgr_) { // only for unit tests
58  CUdeviceptr ptr;
59  const auto err = cuMemAlloc(&ptr, num_bytes);
60  CHECK_EQ(CUDA_SUCCESS, err);
61  default_alloc_scoped_buffers_.push_back(reinterpret_cast<int8_t*>(ptr));
62  return reinterpret_cast<int8_t*>(ptr);
63  }
64 #endif // HAVE_CUDA
67  scoped_buffers_.push_back(ab);
68  return reinterpret_cast<int8_t*>(ab->getMemoryPtr());
69 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::vector< Data_Namespace::AbstractBuffer * > scoped_buffers_
virtual int8_t * getMemoryPtr()=0
unsigned long long CUdeviceptr
Definition: nocuda.h:27
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deallocate()

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

Definition at line 41 of file ThrustAllocator.cpp.

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

41  {
42 #ifdef HAVE_CUDA
43  if (!data_mgr_) { // only for unit tests
44  const auto err = cuMemFree(reinterpret_cast<CUdeviceptr>(ptr));
45  CHECK_EQ(CUDA_SUCCESS, err);
46  return;
47  }
48 #endif // HAVE_CUDA
49  PtrMapperType::iterator ab_it = raw_to_ab_ptr_.find(ptr);
50  CHECK(ab_it != raw_to_ab_ptr_.end());
51  data_mgr_->free(ab_it->second);
52  raw_to_ab_ptr_.erase(ab_it);
53 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
Data_Namespace::DataMgr * data_mgr_
PtrMapperType raw_to_ab_ptr_
#define CHECK(condition)
Definition: Logger.h:187
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:382
+ Here is the call graph for this function:

◆ getDataMgr()

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

Definition at line 48 of file ThrustAllocator.h.

Referenced by transfer_object_to_gpu(), and transfer_pod_vector_to_gpu().

48 { return data_mgr_; }
Data_Namespace::DataMgr * data_mgr_
+ Here is the caller graph for this function:

◆ getDeviceId()

int ThrustAllocator::getDeviceId ( ) const
inline

Definition at line 50 of file ThrustAllocator.h.

Referenced by transfer_object_to_gpu(), and transfer_pod_vector_to_gpu().

50 { return device_id_; }
const int device_id_
+ Here is the caller graph for this function:

Member Data Documentation

◆ data_mgr_

Data_Namespace::DataMgr* ThrustAllocator::data_mgr_
private

Definition at line 53 of file ThrustAllocator.h.

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

◆ default_alloc_scoped_buffers_

std::vector<int8_t*> ThrustAllocator::default_alloc_scoped_buffers_
private

Definition at line 58 of file ThrustAllocator.h.

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

◆ device_id_

const int ThrustAllocator::device_id_
private

Definition at line 54 of file ThrustAllocator.h.

Referenced by allocate(), and allocateScopedBuffer().

◆ raw_to_ab_ptr_

PtrMapperType ThrustAllocator::raw_to_ab_ptr_
private

Definition at line 56 of file ThrustAllocator.h.

Referenced by allocate(), and deallocate().

◆ scoped_buffers_

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

Definition at line 57 of file ThrustAllocator.h.

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


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