6#include "dawn/io/virt.hxx"
12#ifdef CONFIG_DAWN_IO_NOTIFY
67 if (blen > 1 && len > blen)
72 for (
size_t i = 0; i < len; i++)
78 get_cb(
this, get_cb_priv);
89#ifdef CONFIG_DAWN_IO_TIMESTAMP
90 data.
getTs(i) = iodata->hasTs ? iodata->
getTs(b) : ts;
101void CIOVirt::copyBatches(uint8_t *dst,
107 size_t size = dlen * tlen;
111 if (dstStride == size && srcStride == size)
113 std::memcpy(dst, src, size * n);
117 for (
size_t b = 0; b < n; b++)
119 std::memcpy(dst + b * dstStride, src + b * srcStride, size);
123size_t CIOVirt::batchStride(
IODataCmn &data)
133int CIOVirt::store(
const void *src,
size_t stride,
IODataCmn *tsSrc)
139#ifdef CONFIG_DAWN_IO_TIMESTAMP
146 copyBatches(
static_cast<uint8_t *
>(iodata->
getDataPtr(0)),
148 static_cast<const uint8_t *
>(src),
156 for (b = 0; b < blen; b++)
162#ifdef CONFIG_DAWN_IO_TIMESTAMP
165 iodata->
getTs(b) = ts;
173#ifdef CONFIG_DAWN_IO_NOTIFY
196 DAWNERR(
"virt batch mismatch: expected %zu got %zu\n", blen, data.
getBatch());
202 ret = store(data.
getDataPtr(0), batchStride(data), blen > 1 ? &data :
nullptr);
208 set_cb(
this, set_cb_priv);
214#ifdef CONFIG_DAWN_IO_NOTIFY
241#ifdef CONFIG_DAWN_IO_NOTIFY
242 DAWNASSERT(n.
io !=
nullptr,
"nullptr pointer");
260int CIOVirt::unregNotifier(
const SIONotifier &n)
262#ifdef CONFIG_DAWN_IO_NOTIFY
263 DAWNASSERT(n.io !=
nullptr,
"nullptr pointer");
267 for (
auto it = vnote.begin(); it != vnote.end(); ++it)
269 if (it->io == n.io && it->cb == n.cb && it->priv == n.priv)
285int CIOVirt::initialize(
size_t dim,
size_t batch,
bool notify)
289 noteSupport = notify;
293 if (data ==
nullptr || !data->isAllocated())
296 DAWNERR(
"failed to allocate data\n");
305#ifdef CONFIG_DAWN_IO_NOTIFY
306 setNotifyBatch(batch);
315int CIOVirt::setCallbackSet(CIOVirt::virtCB cb,
void *priv)
325int CIOVirt::setCallbackGet(CIOVirt::virtCB cb,
void *priv)
333int CIOVirt::getVal(
void *v,
size_t d)
340 DAWNASSERT(dlen * tlen * blen == d,
"invalid input");
344 copyBatches(
static_cast<uint8_t *
>(v),
346 static_cast<const uint8_t *
>(iodata->
getDataPtr(0)),
355int CIOVirt::setVal(
const void *v,
size_t d)
364 DAWNASSERT(dlen * tlen * blen == d,
"invalid input");
366 return store(v, dlen * tlen,
nullptr);
virtual int getFd() const
Get file descriptor for notifications.
uint64_t getTimestamp()
Get current timestamp.
bool isTimestamp() const
Check if I/O supports timestamp.
size_t getDataSize() const
Get data size in bytes.
int regNotifier(SIONotifier n)
Register I/O notification callback.
int configure()
Configure object from descriptor data.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int deinit()
De-initialize object.
size_t getDataDim() const
Get data vector dimension.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
int init()
One-time initialize object after bindings are resolved.
uint8_t getDtype() const
Get data type field.
Out-of-tree user-extension hooks for Dawn.
Notifier registration structure.
CIOCommon * io
I/O object pointer.
int(* cb)(void *priv, io_ddata_t *data)
Notifier callback function type.
Base interface for I/O data buffers (static and dynamic).
virtual bool hasTimestamp()=0
Check if this data buffer has per-batch timestamp storage.
virtual size_t getBatch()=0
Get number of batches.
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
Heap-allocated dynamic I/O data buffer.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
io_ts_t & getTs(size_t batch=0)
Get timestamp reference for batch.