6#include "dawn/prog/vecpack.hxx"
11#include "dawn/debug.hxx"
12#include "dawn/io/common.hxx"
13#include "dawn/io/virt.hxx"
22 , lastOutputData(nullptr)
28CProgVecPack::~CProgVecPack()
42 input.usesSetCallback =
false;
43 inputs.push_back(input);
48int CProgVecPack::configureDesc(
const CDescObject &desc)
54 for (
size_t i = 0; i < desc.
getSize(); i++)
58 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_VECPACK)
60 DAWNERR(
"vecpack: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
66 case PROG_VECPACK_CFG_INPUTS:
70 DAWNERR(
"vecpack: INPUTS must not be empty\n");
75 for (
size_t j = 0; j < item->
cfgid.
s.
size; j++)
77 int ret = allocInput(ids[j].v);
87 case PROG_VECPACK_CFG_OUTPUT:
91 DAWNERR(
"vecpack: OUTPUT must have one item\n");
103 DAWNERR(
"vecpack: unsupported cfg id %u\n", item->
cfgid.
s.
id);
109 if (inputs.empty() || outputId == 0)
111 DAWNERR(
"vecpack: inputs and output are required\n");
120 return configureDesc(
getDesc());
128 output =
getIO(outputId);
129 if (output ==
nullptr)
131 DAWNERR(
"vecpack: output IO 0x%" PRIx32
" not found\n", outputId);
135 for (
size_t i = 0; i < inputs.size(); i++)
137 inputs[i].io =
getIO(inputs[i].ioId);
138 if (inputs[i].io ==
nullptr)
140 DAWNERR(
"vecpack: input IO 0x%" PRIx32
" not found\n", inputs[i].ioId);
144 if (inputs[i].io->getDataDim() == 0)
146 ret = prepareWritableTarget(inputs[i].io, 1,
false);
149 DAWNERR(
"vecpack: input prepare failed %d\n", ret);
154 if (!inputs[i].io->isRead() || inputs[i].io->getDtype() != output->
getDtype())
156 DAWNERR(
"vecpack: input 0x%" PRIx32
" incompatible with output 0x%" PRIx32
"\n",
162 inputs[i].offset = dim;
163 dim += inputs[i].io->getDataDim();
164 inputs[i].data = inputs[i].io->ddata_alloc(1);
165 if (inputs[i].data ==
nullptr)
167 DAWNERR(
"vecpack: input data allocation failed\n");
172 ret = prepareWritableTarget(output, dim,
true);
175 DAWNERR(
"vecpack: output prepare failed %d\n", ret);
182 "vecpack: output dimension mismatch expected %zu got %zu\n", dim, output->
getDataDim());
188 if (outputData ==
nullptr || lastOutputData ==
nullptr)
190 DAWNERR(
"vecpack: output data allocation failed\n");
202 for (
auto &input : inputs)
205 input.data =
nullptr;
210 outputData =
nullptr;
211 delete lastOutputData;
212 lastOutputData =
nullptr;
218int CProgVecPack::ioNotifierCb(
void *priv,
io_ddata_t *data)
220 SVecInput *input =
static_cast<SVecInput *
>(priv);
222 if (input ==
nullptr || input->owner ==
nullptr || !input->owner->active)
227 if (data !=
nullptr && input->data !=
nullptr)
229 std::memcpy(input->data->getDataPtr(), data->
getDataPtr(), input->data->getDataSize());
232 input->owner->updateOutput();
236void CProgVecPack::ioSetCb(
CIOVirt *io,
void *priv)
238 SVecInput *input =
static_cast<SVecInput *
>(priv);
242 if (input ==
nullptr || input->owner ==
nullptr || !input->owner->active)
247 input->owner->updateOutput();
256 for (
auto &input : inputs)
258 if (input.io->isNotify())
260 ret = input.io->setNotifier(ioNotifierCb, 0, &input);
263 DAWNERR(
"vecpack: setNotifier failed for 0x%" PRIx32
": %d\n", input.ioId, ret);
275 ret =
reinterpret_cast<CIOVirt *
>(input.io)->setCallbackSet(ioSetCb, &input);
278 DAWNERR(
"vecpack: setCallbackSet failed for 0x%" PRIx32
": %d\n", input.ioId, ret);
282 input.usesSetCallback =
true;
297 for (
auto &input : inputs)
299 if (input.io ==
nullptr)
304 if (input.io->isNotify())
306 input.io->setNotifier(
nullptr, 0,
nullptr);
310 reinterpret_cast<CIOVirt *
>(input.io)->setCallbackSet(
nullptr,
nullptr);
311 input.usesSetCallback =
false;
327void CProgVecPack::updateOutput()
331 if (outputData ==
nullptr || lastOutputData ==
nullptr || output ==
nullptr)
336 for (
auto &input : inputs)
338 if (input.io->getData(*input.data, 1) != OK)
343 std::memcpy(
static_cast<uint8_t *
>(outputData->
getDataPtr()) +
344 input.offset * input.io->getDtypeSize(),
345 input.data->getDataPtr(),
346 input.data->getDataSize());
356 ret = output->
setData(*outputData);
359 DAWNERR(
"vecpack: output setData failed %d\n", ret);
CIOCommon * getIO(SObjectId::ObjectId id)
Get an I/O object by ID.
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
virtual size_t getDataDim() const =0
Get data vector dimension.
io_ddata_t * ddata_alloc(size_t batch, size_t chunk_size=0)
Allocate data buffer for this I/O.
@ IO_CLASS_VIRT
Virtual I/O.
Virtual I/O type for user-provided data and callbacks.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
Base class for all PROG (processing) objects.
int doStop()
Stop implementation hook.
int deinit()
De-initialize object.
bool hasThread() const
Check if a background thread is active.
int configure()
Configure object from descriptor data.
int doStart()
Start implementation hook.
int init()
One-time initialize object after bindings are resolved.
Out-of-tree user-extension hooks for Dawn.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
uint32_t ObjectId
ObjectID type - single 32-bit value.
Heap-allocated dynamic I/O data buffer.
size_t getDataSize()
Get data size in bytes.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.
32-bit encoded object identifier (union with bit field).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).