OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CudaAllocator Class Reference

#include <CudaAllocator.h>

+ Inheritance diagram for CudaAllocator:
+ Collaboration diagram for CudaAllocator:

Public Member Functions

 CudaAllocator (Data_Namespace::DataMgr *data_mgr, const int device_id, CUstream cuda_stream)
 
 ~CudaAllocator () override
 
int8_t * alloc (const size_t num_bytes) override
 
void free (Data_Namespace::AbstractBuffer *ab) const override
 
void copyToDevice (void *device_dst, const void *host_src, const size_t num_bytes) const override
 
void copyFromDevice (void *host_dst, const void *device_src, const size_t num_bytes) const override
 
void zeroDeviceMem (int8_t *device_ptr, const size_t num_bytes) const override
 
void setDeviceMem (int8_t *device_ptr, unsigned char uc, const size_t num_bytes) const override
 
- Public Member Functions inherited from Allocator
 Allocator ()
 
virtual ~Allocator ()
 

Static Public Member Functions

static
Data_Namespace::AbstractBuffer
allocGpuAbstractBuffer (Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
 
static void freeGpuAbstractBuffer (Data_Namespace::DataMgr *data_mgr, Data_Namespace::AbstractBuffer *ab)
 

Private Attributes

std::vector
< Data_Namespace::AbstractBuffer * > 
owned_buffers_
 
Data_Namespace::DataMgrdata_mgr_
 
int device_id_
 
CUstream cuda_stream_
 

Detailed Description

Definition at line 42 of file CudaAllocator.h.

Constructor & Destructor Documentation

CudaAllocator::CudaAllocator ( Data_Namespace::DataMgr data_mgr,
const int  device_id,
CUstream  cuda_stream 
)

Definition at line 24 of file CudaAllocator.cpp.

References CHECK, data_mgr_, and Data_Namespace::DataMgr::getCudaMgr().

27  : data_mgr_(data_mgr), device_id_(device_id), cuda_stream_(cuda_stream) {
29 #ifdef HAVE_CUDA
30  const auto cuda_mgr = data_mgr_->getCudaMgr();
31  CHECK(cuda_mgr);
32  cuda_mgr->setContext(device_id);
33 #endif // HAVE_CUDA
34 }
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:177
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
#define CHECK(condition)
Definition: Logger.h:291
CUstream cuda_stream_
Definition: CudaAllocator.h:81

+ Here is the call graph for this function:

CudaAllocator::~CudaAllocator ( )
override

Definition at line 36 of file CudaAllocator.cpp.

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

36  {
38  for (auto& buffer_ptr : owned_buffers_) {
39  data_mgr_->free(buffer_ptr);
40  }
41 }
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
std::vector< Data_Namespace::AbstractBuffer * > owned_buffers_
Definition: CudaAllocator.h:77
#define CHECK(condition)
Definition: Logger.h:291
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:614

+ Here is the call graph for this function:

Member Function Documentation

int8_t * CudaAllocator::alloc ( const size_t  num_bytes)
overridevirtual

Implements Allocator.

Definition at line 59 of file CudaAllocator.cpp.

References allocGpuAbstractBuffer(), CHECK, data_mgr_, device_id_, and owned_buffers_.

59  {
61  owned_buffers_.emplace_back(
63  return owned_buffers_.back()->getMemoryPtr();
64 }
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
std::vector< Data_Namespace::AbstractBuffer * > owned_buffers_
Definition: CudaAllocator.h:77
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

+ Here is the call graph for this function:

Data_Namespace::AbstractBuffer * CudaAllocator::allocGpuAbstractBuffer ( Data_Namespace::DataMgr data_mgr,
const size_t  num_bytes,
const int  device_id 
)
static

Definition at line 43 of file CudaAllocator.cpp.

References Data_Namespace::DataMgr::alloc(), CHECK, CHECK_EQ, and Data_Namespace::GPU_LEVEL.

Referenced by alloc(), ThrustAllocator::allocate(), PerfectHashTable::allocateGpuMemory(), ThrustAllocator::allocateScopedBuffer(), BaselineHashTable::BaselineHashTable(), TreeModelPredictionMgr::createKernelBuffers(), and StringDictionaryTranslationMgr::createKernelBuffers().

46  {
47  CHECK(data_mgr);
48  auto ab = data_mgr->alloc(Data_Namespace::GPU_LEVEL, device_id, num_bytes);
49  CHECK_EQ(ab->getPinCount(), 1);
50  return ab;
51 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define CHECK(condition)
Definition: Logger.h:291
AbstractBuffer * alloc(const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
Definition: DataMgr.cpp:605

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CudaAllocator::copyFromDevice ( void *  host_dst,
const void *  device_src,
const size_t  num_bytes 
) const
overridevirtual

Implements DeviceAllocator.

Definition at line 79 of file CudaAllocator.cpp.

References CHECK, cuda_stream_, data_mgr_, and Data_Namespace::DataMgr::getCudaMgr().

Referenced by anonymous_namespace{BoundingBoxIntersectJoinHashTable.cpp}::compute_bucket_sizes().

81  {
82  const auto cuda_mgr = data_mgr_->getCudaMgr();
83  CHECK(cuda_mgr);
84  cuda_mgr->copyDeviceToHost(
85  (int8_t*)host_dst, (int8_t*)device_src, num_bytes, cuda_stream_);
86 }
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:177
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
#define CHECK(condition)
Definition: Logger.h:291
CUstream cuda_stream_
Definition: CudaAllocator.h:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CudaAllocator::copyToDevice ( void *  device_dst,
const void *  host_src,
const size_t  num_bytes 
) const
overridevirtual

Implements DeviceAllocator.

Definition at line 70 of file CudaAllocator.cpp.

References CHECK, cuda_stream_, data_mgr_, device_id_, and Data_Namespace::DataMgr::getCudaMgr().

72  {
73  const auto cuda_mgr = data_mgr_->getCudaMgr();
74  CHECK(cuda_mgr);
75  cuda_mgr->copyHostToDevice(
76  (int8_t*)device_dst, (int8_t*)host_src, num_bytes, device_id_, cuda_stream_);
77 }
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:177
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
#define CHECK(condition)
Definition: Logger.h:291
CUstream cuda_stream_
Definition: CudaAllocator.h:81

+ Here is the call graph for this function:

void CudaAllocator::free ( Data_Namespace::AbstractBuffer ab) const
overridevirtual

Implements DeviceAllocator.

Definition at line 66 of file CudaAllocator.cpp.

References data_mgr_, and Data_Namespace::DataMgr::free().

66  {
67  data_mgr_->free(ab);
68 }
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:614

+ Here is the call graph for this function:

void CudaAllocator::freeGpuAbstractBuffer ( Data_Namespace::DataMgr data_mgr,
Data_Namespace::AbstractBuffer ab 
)
static

Definition at line 53 of file CudaAllocator.cpp.

References CHECK, and Data_Namespace::DataMgr::free().

54  {
55  CHECK(data_mgr);
56  data_mgr->free(ab);
57 }
#define CHECK(condition)
Definition: Logger.h:291
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:614

+ Here is the call graph for this function:

void CudaAllocator::setDeviceMem ( int8_t *  device_ptr,
unsigned char  uc,
const size_t  num_bytes 
) const
overridevirtual

Implements DeviceAllocator.

Definition at line 94 of file CudaAllocator.cpp.

References CHECK, cuda_stream_, data_mgr_, device_id_, and Data_Namespace::DataMgr::getCudaMgr().

96  {
97  const auto cuda_mgr = data_mgr_->getCudaMgr();
98  CHECK(cuda_mgr);
99  cuda_mgr->setDeviceMem(device_ptr, uc, num_bytes, device_id_, cuda_stream_);
100 }
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:177
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
#define CHECK(condition)
Definition: Logger.h:291
CUstream cuda_stream_
Definition: CudaAllocator.h:81

+ Here is the call graph for this function:

void CudaAllocator::zeroDeviceMem ( int8_t *  device_ptr,
const size_t  num_bytes 
) const
overridevirtual

Implements DeviceAllocator.

Definition at line 88 of file CudaAllocator.cpp.

References CHECK, cuda_stream_, data_mgr_, device_id_, and Data_Namespace::DataMgr::getCudaMgr().

88  {
89  const auto cuda_mgr = data_mgr_->getCudaMgr();
90  CHECK(cuda_mgr);
91  cuda_mgr->zeroDeviceMem(device_ptr, num_bytes, device_id_, cuda_stream_);
92 }
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:177
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:79
#define CHECK(condition)
Definition: Logger.h:291
CUstream cuda_stream_
Definition: CudaAllocator.h:81

+ Here is the call graph for this function:

Member Data Documentation

CUstream CudaAllocator::cuda_stream_
private

Definition at line 81 of file CudaAllocator.h.

Referenced by copyFromDevice(), copyToDevice(), setDeviceMem(), and zeroDeviceMem().

Data_Namespace::DataMgr* CudaAllocator::data_mgr_
private
int CudaAllocator::device_id_
private

Definition at line 80 of file CudaAllocator.h.

Referenced by alloc(), copyToDevice(), setDeviceMem(), and zeroDeviceMem().

std::vector<Data_Namespace::AbstractBuffer*> CudaAllocator::owned_buffers_
private

Definition at line 77 of file CudaAllocator.h.

Referenced by alloc(), and ~CudaAllocator().


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