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

Writes event data that is already in GPU memory to a file with NVIDIA cuFile. More...

#include <FileWriter.hh>

Inherits Drp::FileWriterBase.

Inherited by Drp::Gpu::FileWriterAsync.

Public Member Functions

 FileWriter (size_t bufferSize, bool dio)
 Open the cuFile driver and allocate a GPU buffer of bufferSize bytes, reduced to the driver's maximum pinned memory size if larger.
 
 ~FileWriter () override
 Close the file, free the GPU buffer and close the cuFile driver, exiting if that fails.
 
int registerStream (cudaStream_t)
 Use stream for the buffer copies and register it with cuFile (flags 0x7).
 
int deregisterStream (cudaStream_t)
 Deregister the stream set by registerStream(), if any, and forget it; the argument is not used.
 
int open (const std::string &fileName) override
 Close any open file, log the cuFile properties, create or truncate fileName (with O_DIRECT if dio was set), take a write lock and register the file and the GPU buffer with cuFile, then reset the buffer count and file offset.
 
int close () override
 If a file is open, write out the buffered data, deregister the file and the GPU buffer from cuFile and close the descriptor.
 
void writeEvent (const void *devPtr, size_t size, const XtcData::TimeStamp) override
 Copy size bytes from device pointer devPtr into the GPU buffer (asynchronously on the registered stream), first writing the buffer to the file with cuFileWrite when the event does not fit or the batch is more than 2 seconds old.
 
- Public Member Functions inherited from Drp::FileWriterBase
 FileWriterBase ()
 Start with the writing counter at 0.
 
virtual ~FileWriterBase ()
 Does nothing; empty body.
 
virtual uint64_t writing () const
 Return the writing counter (non-zero while an implementation is inside a write).
 

Static Public Member Functions

static void dumpProperties ()
 Log the cuFile driver properties: versions, supported file systems, control and feature flags and size limits.
 

Protected Attributes

cudaStream_t m_stream
 
CUfileHandle_t m_handle
 
XtcData::TimeStamp m_batch_starttime
 
uint8_t * m_buffer_d
 
off_t m_fileOffset
 
size_t m_bufferSize
 
int m_fd
 
bool m_dio
 
- Protected Attributes inherited from Drp::FileWriterBase
volatile uint64_t m_writing
 

Detailed Description

Writes event data that is already in GPU memory to a file with NVIDIA cuFile.

Events are copied device to device into a GPU buffer, which is written to the file when the next event would not fit or the oldest buffered event is more than 2 seconds older than the new one.

Constructor & Destructor Documentation

◆ FileWriter()

Drp::Gpu::FileWriter::FileWriter ( size_t  bufferSize,
bool  dio 
)

Open the cuFile driver and allocate a GPU buffer of bufferSize bytes, reduced to the driver's maximum pinned memory size if larger.

Exits if bufferSize is not a power of 2 or the driver cannot be opened; dio adds O_DIRECT when open() creates a file.

◆ ~FileWriter()

Drp::Gpu::FileWriter::~FileWriter ( )
override

Close the file, free the GPU buffer and close the cuFile driver, exiting if that fails.

Member Function Documentation

◆ close()

int Drp::Gpu::FileWriter::close ( )
overridevirtual

If a file is open, write out the buffered data, deregister the file and the GPU buffer from cuFile and close the descriptor.

Returns the close() result (-1 on error), or 0 if no file was open.

Implements Drp::FileWriterBase.

◆ deregisterStream()

int Drp::Gpu::FileWriter::deregisterStream ( cudaStream_t  )

Deregister the stream set by registerStream(), if any, and forget it; the argument is not used.

Returns -1 on failure, else 0.

◆ dumpProperties()

static void Drp::Gpu::FileWriter::dumpProperties ( )
static

Log the cuFile driver properties: versions, supported file systems, control and feature flags and size limits.

◆ open()

int Drp::Gpu::FileWriter::open ( const std::string &  fileName)
overridevirtual

Close any open file, log the cuFile properties, create or truncate fileName (with O_DIRECT if dio was set), take a write lock and register the file and the GPU buffer with cuFile, then reset the buffer count and file offset.

Returns -1 if the file cannot be created, non-zero (after closing the file) if a cuFile registration fails, else 0; a failed lock is only logged.

Implements Drp::FileWriterBase.

◆ registerStream()

int Drp::Gpu::FileWriter::registerStream ( cudaStream_t  )

Use stream for the buffer copies and register it with cuFile (flags 0x7).

Returns -1 on failure, else 0.

◆ writeEvent()

void Drp::Gpu::FileWriter::writeEvent ( const void *  devPtr,
size_t  size,
const XtcData::TimeStamp   
)
overridevirtual

Copy size bytes from device pointer devPtr into the GPU buffer (asynchronously on the registered stream), first writing the buffer to the file with cuFileWrite when the event does not fit or the batch is more than 2 seconds old.

Returns early, logging an error, if that write is short; exits if the event is larger than the buffer.

Implements Drp::FileWriterBase.

Reimplemented in Drp::Gpu::FileWriterAsync.

Member Data Documentation

◆ m_batch_starttime

XtcData::TimeStamp Drp::Gpu::FileWriter::m_batch_starttime
protected

◆ m_buffer_d

uint8_t* Drp::Gpu::FileWriter::m_buffer_d
protected

◆ m_bufferSize

size_t Drp::Gpu::FileWriter::m_bufferSize
protected

◆ m_dio

bool Drp::Gpu::FileWriter::m_dio
protected

◆ m_fd

int Drp::Gpu::FileWriter::m_fd
protected

◆ m_fileOffset

off_t Drp::Gpu::FileWriter::m_fileOffset
protected

◆ m_handle

CUfileHandle_t Drp::Gpu::FileWriter::m_handle
protected

◆ m_stream

cudaStream_t Drp::Gpu::FileWriter::m_stream
protected

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