OmniSciDB  c07336695a
Buffer_Namespace::CpuBuffer Class Reference

#include <CpuBuffer.h>

+ Inheritance diagram for Buffer_Namespace::CpuBuffer:
+ Collaboration diagram for Buffer_Namespace::CpuBuffer:

Public Member Functions

 CpuBuffer (BufferMgr *bm, BufferList::iterator segIt, const int deviceId, CudaMgr_Namespace::CudaMgr *cudaMgr, const size_t pageSize=512, const size_t numBytes=0)
 
Data_Namespace::MemoryLevel getType () const override
 
- Public Member Functions inherited from Buffer_Namespace::Buffer
 Buffer (BufferMgr *bm, BufferList::iterator segIt, const int deviceId, const size_t pageSize=512, const size_t numBytes=0)
 Constructs a Buffer object. The constructor requires a memory address (provided by BufferMgr), number of pages, and the size in bytes of each page. Additionally, the Buffer can be initialized with an epoch. More...
 
 ~Buffer () override
 Destructor. More...
 
void read (int8_t *const dst, const size_t numBytes, const size_t offset=0, const MemoryLevel dstBufferType=CPU_LEVEL, const int deviceId=-1) override
 Reads (copies) data from the buffer to the destination (dst) memory location. Reads (copies) nbytes of data from the buffer, beginning at the specified byte offset, into the destination (dst) memory location. More...
 
void reserve (const size_t numBytes) override
 
void write (int8_t *src, const size_t numBytes, const size_t offset=0, const MemoryLevel srcBufferType=CPU_LEVEL, const int deviceId=-1) override
 Writes (copies) data from src into the buffer. Writes (copies) nbytes of data into the buffer at the specified byte offset, from the source (src) memory location. More...
 
void append (int8_t *src, const size_t numBytes, const MemoryLevel srcBufferType=CPU_LEVEL, const int deviceId=-1) override
 
int8_t * getMemoryPtr () override
 Returns a raw, constant (read-only) pointer to the underlying buffer. More...
 
size_t size () const override
 
size_t reservedSize () const override
 Returns the total number of bytes allocated for the buffer. More...
 
size_t pageCount () const override
 Returns the number of pages in the buffer. More...
 
size_t pageSize () const override
 Returns the size in bytes of each page in the buffer. More...
 
bool isDirty () const override
 Returns whether or not the buffer has been modified since the last flush/checkpoint. More...
 
int pin () override
 
int unPin () override
 
int getPinCount () override
 
- Public Member Functions inherited from Data_Namespace::AbstractBuffer
 AbstractBuffer (const int deviceId)
 
 AbstractBuffer (const int deviceId, const SQLTypeInfo sqlType)
 
virtual ~AbstractBuffer ()
 
virtual int getDeviceId () const
 
virtual bool isAppended () const
 
virtual bool isUpdated () const
 
virtual void setDirty ()
 
virtual void setUpdated ()
 
virtual void setAppended ()
 
void setSize (const size_t size)
 
void clearDirtyBits ()
 
void initEncoder (const SQLTypeInfo tmpSqlType)
 
void syncEncoder (const AbstractBuffer *srcBuffer)
 

Private Member Functions

void readData (int8_t *const dst, const size_t numBytes, const size_t offset=0, const MemoryLevel dstMemoryLevel=CPU_LEVEL, const int dstDeviceId=-1) override
 
void writeData (int8_t *const src, const size_t numBytes, const size_t offset=0, const MemoryLevel srcMemoryLevel=CPU_LEVEL, const int srcDeviceId=-1) override
 

Private Attributes

CudaMgr_Namespace::CudaMgrcudaMgr_
 

Additional Inherited Members

- Public Attributes inherited from Data_Namespace::AbstractBuffer
std::unique_ptr< Encoderencoder
 
bool hasEncoder
 
SQLTypeInfo sqlType
 
- Protected Attributes inherited from Buffer_Namespace::Buffer
int8_t * mem_
 
- Protected Attributes inherited from Data_Namespace::AbstractBuffer
size_t size_
 
bool isDirty_
 
bool isAppended_
 
bool isUpdated_
 
int deviceId_
 

Detailed Description

Definition at line 27 of file CpuBuffer.h.

Constructor & Destructor Documentation

◆ CpuBuffer()

Buffer_Namespace::CpuBuffer::CpuBuffer ( BufferMgr bm,
BufferList::iterator  segIt,
const int  deviceId,
CudaMgr_Namespace::CudaMgr cudaMgr,
const size_t  pageSize = 512,
const size_t  numBytes = 0 
)

Definition at line 25 of file CpuBuffer.cpp.

31  : Buffer(bm, segIt, deviceId, pageSize, numBytes), cudaMgr_(cudaMgr) {}
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: CpuBuffer.h:49
Buffer(BufferMgr *bm, BufferList::iterator segIt, const int deviceId, const size_t pageSize=512, const size_t numBytes=0)
Constructs a Buffer object. The constructor requires a memory address (provided by BufferMgr)...
Definition: Buffer.cpp:35
size_t pageSize() const override
Returns the size in bytes of each page in the buffer.
Definition: Buffer.h:129

Member Function Documentation

◆ getType()

Data_Namespace::MemoryLevel Buffer_Namespace::CpuBuffer::getType ( ) const
inlineoverridevirtual

Implements Data_Namespace::AbstractBuffer.

Definition at line 36 of file CpuBuffer.h.

References Data_Namespace::CPU_LEVEL, and src.

◆ readData()

void Buffer_Namespace::CpuBuffer::readData ( int8_t *const  dst,
const size_t  numBytes,
const size_t  offset = 0,
const MemoryLevel  dstMemoryLevel = CPU_LEVEL,
const int  dstDeviceId = -1 
)
overrideprivatevirtual

Implements Buffer_Namespace::Buffer.

Definition at line 33 of file CpuBuffer.cpp.

References CudaMgr_Namespace::CudaMgr::copyHostToDevice(), Data_Namespace::CPU_LEVEL, cudaMgr_, logger::FATAL, Data_Namespace::GPU_LEVEL, LOG, and Buffer_Namespace::Buffer::mem_.

37  {
38  if (dstMemoryLevel == CPU_LEVEL) {
39  memcpy(dst, mem_ + offset, numBytes);
40  } else if (dstMemoryLevel == GPU_LEVEL) {
41  //@todo: use actual device id in next call
42  assert(dstDeviceId >= 0);
44  dst, mem_ + offset, numBytes, dstDeviceId); // need to replace 0 with gpu num
45  } else {
46  LOG(FATAL) << "Unsupported buffer type";
47  }
48 }
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: CpuBuffer.h:49
#define LOG(tag)
Definition: Logger.h:182
void copyHostToDevice(int8_t *device_ptr, const int8_t *host_ptr, const size_t num_bytes, const int device_num)
Definition: CudaMgr.cpp:71
+ Here is the call graph for this function:

◆ writeData()

void Buffer_Namespace::CpuBuffer::writeData ( int8_t *const  src,
const size_t  numBytes,
const size_t  offset = 0,
const MemoryLevel  srcMemoryLevel = CPU_LEVEL,
const int  srcDeviceId = -1 
)
overrideprivatevirtual

Implements Buffer_Namespace::Buffer.

Definition at line 50 of file CpuBuffer.cpp.

References CudaMgr_Namespace::CudaMgr::copyDeviceToHost(), Data_Namespace::CPU_LEVEL, cudaMgr_, logger::FATAL, Data_Namespace::GPU_LEVEL, LOG, and Buffer_Namespace::Buffer::mem_.

54  {
55  if (srcMemoryLevel == CPU_LEVEL) {
56  // std::cout << "Writing to CPU from source CPU" << std::endl;
57  memcpy(mem_ + offset, src, numBytes);
58  } else if (srcMemoryLevel == GPU_LEVEL) {
59  // std::cout << "Writing to CPU from source GPU" << std::endl;
60  //@todo: use actual device id in next call
61  assert(srcDeviceId >= 0);
63  mem_ + offset, src, numBytes, srcDeviceId); // need to replace 0 with gpu num
64  } else {
65  LOG(FATAL) << "Unsupported buffer type";
66  }
67 }
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: CpuBuffer.h:49
void copyDeviceToHost(int8_t *host_ptr, const int8_t *device_ptr, const size_t num_bytes, const int device_num)
Definition: CudaMgr.cpp:80
#define LOG(tag)
Definition: Logger.h:182
int64_t * src
+ Here is the call graph for this function:

Member Data Documentation

◆ cudaMgr_

CudaMgr_Namespace::CudaMgr* Buffer_Namespace::CpuBuffer::cudaMgr_
private

Definition at line 49 of file CpuBuffer.h.

Referenced by readData(), and writeData().


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