lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Drp::Gpu::MemPoolGpu Class Reference

Memory pool of the GPU DRP. More...

#include <MemPool.hh>

Inherits Drp::MemPool.

Public Types

using vecpu32_t = std::vector< uint32_t * >
 Vector of uint32_t pointers; not used in drpGpu.
 

Public Member Functions

 MemPoolGpu (Parameters &para)
 Read the dmaBufSize (rounded up to a multiple of 64 kB, default 64 kB), dmaBufCount (power of 2, default 4) and gpuId kwargs, set up the CUDA context and check the required device attributes.
 
virtual ~MemPoolGpu ()
 Release the driver's GPU memory registration, then free the DMA buffers and the host write, calibration and reduce buffers.
 
int initialize (Parameters &para)
 Declared but not defined in MemPool.cc.
 
int fd () const override
 Return the file descriptor of the device panel's DataDev.
 
int setMaskBytes (uint8_t laneMask, unsigned virtChan) override
 Set the driver DMA mask to the destinations (dmaDest of lane and virtChan) of the lanes in laneMask; once a call has succeeded, later calls only log that the earlier setting is in effect.
 
const CudaContext & context () const
 Return the CUDA context.
 
const std::shared_ptr< DetPanel > panel () const
 Return the device panel.
 
void createHostBuffers (size_t size)
 Allocate nbuffers() zeroed pinned host buffers of size bytes each, for the DMA descriptors, TimingHeaders and TEB input data (per the code comment).
 
void destroyHostBuffers ()
 Free the host write buffers if they exist.
 
void createCalibBuffers (unsigned nElements)
 Allocate nbuffers() zeroed device buffers of nElements floats each for calibrated data.
 
void destroyCalibBuffers ()
 Free the calibration buffers if they exist.
 
void createReduceBuffers (size_t nBytes, size_t reserved)
 Allocate nbuffers() zeroed device buffers of reserved plus nBytes bytes each (both rounded up to multiples of 8); the reserved part at the front of each is for the datagram header.
 
void destroyReduceBuffers ()
 Free the reduce buffers if they exist.
 
const auto & hostWrtBufs () const
 Return the pinned host write buffers: nbuffers() contiguous buffers of hostWrtBufsSize() bytes.
 
const auto & calibBuffers_d () const
 Return the device calibration buffers: nbuffers() contiguous buffers of calibBufsSize() bytes.
 
const auto & reduceBuffers_d () const
 Return the device address of the data part of reduce buffer 0; each further buffer starts reduceBufsReserved() plus reduceBufsSize() bytes later.
 
size_t hostWrtBufsSize () const
 Return the size in bytes of one host write buffer (0 if none).
 
size_t calibBufsSize () const
 Return the size in bytes of one calibration buffer (0 if none).
 
size_t reduceBufsSize () const
 Return the size in bytes of the data part of one reduce buffer, without the reserved part (0 if none).
 
size_t reduceBufsReserved () const
 Return the size in bytes of the reserved header part at the front of each reduce buffer.
 
int64_t nPgpInUser () const
 Return the driver's count of receive buffers held by the user (dmaGetRxBuffinUserCount()).
 
int64_t nPgpInHw () const
 Return the driver's count of receive buffers in hardware (dmaGetRxBuffinHwCount()).
 
int64_t nPgpInPreHw () const
 Return the driver's count of receive buffers in the pre-hardware queue (dmaGetRxBuffinPreHwQCount()).
 
int64_t nPgpInRx () const
 Return the driver's count of receive buffers in the software queue (dmaGetRxBuffinSwQCount()).
 
- Public Member Functions inherited from Drp::MemPool
 MemPool (const Parameters &para)
 Create the transition buffer queue (TEB_TR_BUFFERS rounded up to a power of 2) and zero the counters.
 
virtual ~MemPool ()
 Does nothing; empty body.
 
unsigned dmaCount () const
 Return the number of DMA buffers reported by the driver.
 
unsigned nDmaBuffers () const
 Return dmaCount() rounded up to a power of 2.
 
unsigned dmaSize () const
 Return the size of one DMA buffer.
 
unsigned nbuffers () const
 Return the number of pebble (L1Accept) buffers.
 
size_t bufferSize () const
 Return the size of one pebble L1Accept buffer.
 
void shutdown ()
 Shut down the transition buffer queue and log how often DMA reads and returns failed.
 
Pds::EbDgram * allocateTr ()
 Pop a free transition buffer as an EbDgram pointer, or return nullptr if none is available.
 
void freeTr (Pds::EbDgram *dgram)
 Check the overrun sentinels of transition buffer dgram (logging the first overrun), then push it back onto the free queue.
 
unsigned allocateDma ()
 Count one DMA buffer allocation (the firmware does the actual allocation) and return the count before the increment.
 
ssize_t readDma (uint32_t count, int32_t *ret, uint32_t *index, uint32_t *flags, uint32_t *errors, uint32_t *dest)
 Read up to count DMA buffers with dmaReadBulkIndex() on fd(), filling the per-buffer return sizes, indices, flags, errors and destinations.
 
ssize_t freeDma (unsigned count, uint32_t *indices)
 Return count DMA buffers (by index) to the driver through the subclass and log errors; on success the frees are counted.
 
unsigned allocate ()
 Allocate the next pebble buffer index in order, blocking while all buffers are in use.
 
void freePebble (unsigned)
 Free the oldest pebble buffer (logging if the index is not the expected one), wake a blocked allocate() if the pool was full, and check that buffer's overrun sentinels.
 
void flushPebble ()
 Free pebble buffers in order until none is in use.
 
int64_t dmaInUse () const
 Return the number of DMA allocations minus frees.
 
int64_t inUse () const
 Return the number of pebble allocations minus frees.
 
int64_t trInUse () const
 Return guess_size() of the transition buffer queue.
 
void resetCounters ()
 Reset the DMA counters (only if no DMA buffer is in use, otherwise warn), the pebble counters (with a warning if buffers are still in use), the overrun flags and the error counts.
 
template<typename T >
T * getAs ()
 Return this pool cast with static_cast to T*.
 

Additional Inherited Members

- Public Attributes inherited from Drp::MemPool
Pebble pebble
 Pebble holding the L1Accept and transition buffers.
 
std::vector< PGPEvent > pgpEvents
 Events being assembled, indexed by event counter modulo nDmaBuffers().
 
std::vector< Pds::EbDgram * > transitionDgrams
 Transition datagram assigned to each pebble buffer index (set for non-L1Accept events).
 
void ** dmaBuffers
 DMA buffer addresses mapped from the driver.
 
- Protected Member Functions inherited from Drp::MemPool
void _initialize (const Parameters &)
 
- Protected Attributes inherited from Drp::MemPool
unsigned m_nDmaBuffers
 
unsigned m_nbuffers
 
unsigned m_dmaCount
 
unsigned m_dmaSize
 
SPSCQueue< void * > m_transitionBuffers
 
std::atomic< uint64_t > m_dmaAllocs
 
std::atomic< uint64_t > m_dmaFrees
 
std::atomic< uint64_t > m_allocs
 
std::atomic< uint64_t > m_frees
 
std::mutex m_lock
 
std::condition_variable m_condition
 
uint8_t m_dmaOverrun
 
uint8_t m_l1Overrun
 
uint8_t m_trOverrun
 
uint8_t m_pad
 
unsigned m_nDmaReadErr
 
unsigned m_nDmaRetErr
 

Detailed Description

Memory pool of the GPU DRP.

It opens the PGP device, or runs in simulator mode if the device is /dev/null, allocates the DMA buffers on the GPU and gives them to the FPGA. It also manages the pinned host write buffers and the calibration and reduce buffers on the GPU.

Member Typedef Documentation

◆ vecpu32_t

using Drp::Gpu::MemPoolGpu::vecpu32_t = std::vector<uint32_t*>

Vector of uint32_t pointers; not used in drpGpu.

Constructor & Destructor Documentation

◆ MemPoolGpu()

Drp::Gpu::MemPoolGpu::MemPoolGpu ( Parameters &  para)

Read the dmaBufSize (rounded up to a multiple of 64 kB, default 64 kB), dmaBufCount (power of 2, default 4) and gpuId kwargs, set up the CUDA context and check the required device attributes.

Then set up the device registers (or simulated ones) and the DMA buffers, stop FPGA writes, set the write count and DMA target, and initialize the base pool. Aborts on errors.

◆ ~MemPoolGpu()

virtual Drp::Gpu::MemPoolGpu::~MemPoolGpu ( )
virtual

Release the driver's GPU memory registration, then free the DMA buffers and the host write, calibration and reduce buffers.

Member Function Documentation

◆ calibBuffers_d()

const auto & Drp::Gpu::MemPoolGpu::calibBuffers_d ( ) const
inline

Return the device calibration buffers: nbuffers() contiguous buffers of calibBufsSize() bytes.

◆ calibBufsSize()

size_t Drp::Gpu::MemPoolGpu::calibBufsSize ( ) const
inline

Return the size in bytes of one calibration buffer (0 if none).

◆ context()

const CudaContext & Drp::Gpu::MemPoolGpu::context ( ) const
inline

Return the CUDA context.

◆ createCalibBuffers()

void Drp::Gpu::MemPoolGpu::createCalibBuffers ( unsigned  nElements)

Allocate nbuffers() zeroed device buffers of nElements floats each for calibrated data.

Logs an error and does nothing if they already exist.

◆ createHostBuffers()

void Drp::Gpu::MemPoolGpu::createHostBuffers ( size_t  size)

Allocate nbuffers() zeroed pinned host buffers of size bytes each, for the DMA descriptors, TimingHeaders and TEB input data (per the code comment).

Logs an error and does nothing if they already exist.

◆ createReduceBuffers()

void Drp::Gpu::MemPoolGpu::createReduceBuffers ( size_t  nBytes,
size_t  reserved 
)

Allocate nbuffers() zeroed device buffers of reserved plus nBytes bytes each (both rounded up to multiples of 8); the reserved part at the front of each is for the datagram header.

Logs an error and does nothing if they already exist.

◆ destroyCalibBuffers()

void Drp::Gpu::MemPoolGpu::destroyCalibBuffers ( )

Free the calibration buffers if they exist.

◆ destroyHostBuffers()

void Drp::Gpu::MemPoolGpu::destroyHostBuffers ( )

Free the host write buffers if they exist.

◆ destroyReduceBuffers()

void Drp::Gpu::MemPoolGpu::destroyReduceBuffers ( )

Free the reduce buffers if they exist.

◆ fd()

int Drp::Gpu::MemPoolGpu::fd ( ) const
inlineoverridevirtual

Return the file descriptor of the device panel's DataDev.

Implements Drp::MemPool.

◆ hostWrtBufs()

const auto & Drp::Gpu::MemPoolGpu::hostWrtBufs ( ) const
inline

Return the pinned host write buffers: nbuffers() contiguous buffers of hostWrtBufsSize() bytes.

◆ hostWrtBufsSize()

size_t Drp::Gpu::MemPoolGpu::hostWrtBufsSize ( ) const
inline

Return the size in bytes of one host write buffer (0 if none).

◆ initialize()

int Drp::Gpu::MemPoolGpu::initialize ( Parameters &  para)

Declared but not defined in MemPool.cc.

◆ nPgpInHw()

int64_t Drp::Gpu::MemPoolGpu::nPgpInHw ( ) const
inline

Return the driver's count of receive buffers in hardware (dmaGetRxBuffinHwCount()).

◆ nPgpInPreHw()

int64_t Drp::Gpu::MemPoolGpu::nPgpInPreHw ( ) const
inline

Return the driver's count of receive buffers in the pre-hardware queue (dmaGetRxBuffinPreHwQCount()).

◆ nPgpInRx()

int64_t Drp::Gpu::MemPoolGpu::nPgpInRx ( ) const
inline

Return the driver's count of receive buffers in the software queue (dmaGetRxBuffinSwQCount()).

◆ nPgpInUser()

int64_t Drp::Gpu::MemPoolGpu::nPgpInUser ( ) const
inline

Return the driver's count of receive buffers held by the user (dmaGetRxBuffinUserCount()).

◆ panel()

const std::shared_ptr< DetPanel > Drp::Gpu::MemPoolGpu::panel ( ) const
inline

Return the device panel.

◆ reduceBuffers_d()

const auto & Drp::Gpu::MemPoolGpu::reduceBuffers_d ( ) const
inline

Return the device address of the data part of reduce buffer 0; each further buffer starts reduceBufsReserved() plus reduceBufsSize() bytes later.

◆ reduceBufsReserved()

size_t Drp::Gpu::MemPoolGpu::reduceBufsReserved ( ) const
inline

Return the size in bytes of the reserved header part at the front of each reduce buffer.

◆ reduceBufsSize()

size_t Drp::Gpu::MemPoolGpu::reduceBufsSize ( ) const
inline

Return the size in bytes of the data part of one reduce buffer, without the reserved part (0 if none).

◆ setMaskBytes()

int Drp::Gpu::MemPoolGpu::setMaskBytes ( uint8_t  laneMask,
unsigned  virtChan 
)
overridevirtual

Set the driver DMA mask to the destinations (dmaDest of lane and virtChan) of the lanes in laneMask; once a call has succeeded, later calls only log that the earlier setting is in effect.

Returns 1 if dmaSetMaskBytes fails, else 0.

Implements Drp::MemPool.


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