6#include "dawn/prog/bitpack.hxx"
13#include "dawn/debug.hxx"
14#include "dawn/io/common.hxx"
15#include "dawn/io/ddata.hxx"
18using namespace dawn::prog;
20static const size_t INPUT_WORDS = 2;
34CProgBitPack::~CProgBitPack()
47 inp.currentData =
nullptr;
52 inputs.push_back(inp);
57int CProgBitPack::configureDesc(
const CDescObject &desc)
59 const SObjectCfg::SObjectCfgItem *item;
60 const SObjectId::UObjectId *ids;
67 for (ii = 0; ii < desc.
getSize(); ii++)
71 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_BITPACK)
73 DAWNERR(
"bitpack: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
79 case PROG_BITPACK_CFG_INPUTS:
82 if (n == 0 || n % INPUT_WORDS != 0)
84 DAWNERR(
"bitpack: invalid INPUTS size %zu\n", n);
88 vals =
reinterpret_cast<const uint32_t *
>(item->
data);
89 for (
size_t j = 0; j < n; j += INPUT_WORDS)
91 ids =
reinterpret_cast<const SObjectId::UObjectId *
>(&vals[j]);
92 int ret = allocInput(ids[0].v, vals[j + 1]);
101 case PROG_BITPACK_CFG_OUTPUT:
105 DAWNERR(
"bitpack: OUTPUT must have 1 entry\n");
109 ids =
reinterpret_cast<const SObjectId::UObjectId *
>(item->
data);
117 DAWNERR(
"bitpack: unsupported cfg id %u\n", item->
cfgid.
s.
id);
125 DAWNERR(
"bitpack: at least one input required\n");
131 DAWNERR(
"bitpack: output IO not configured\n");
140 return configureDesc(
getDesc());
148 size_t outputBitsPerElement;
153 for (i = 0; i < inputs.size(); i++)
155 io =
getIO(inputs[i].ioId);
158 DAWNERR(
"bitpack: input IO 0x%" PRIx32
" not found\n", inputs[i].ioId);
164 DAWNERR(
"bitpack: input 0x%" PRIx32
" is not readable\n", inputs[i].ioId);
168 if (!isBitwiseDtype(io->
getDtype()))
171 "bitpack: input 0x%" PRIx32
" unsupported dtype %u\n", inputs[i].ioId, io->
getDtype());
180 inputs[i].nbits = getLogicalBits(io);
181 inputs[i].currentData = inputs[i].io->ddata_alloc(1);
182 if (inputs[i].currentData ==
nullptr)
184 DAWNERR(
"bitpack: currentData allocation failed for input %zu\n", i);
188 requiredBits = std::max(requiredBits,
static_cast<size_t>(inputs[i].bit) + inputs[i].nbits);
191 io =
getIO(outputId);
194 DAWNERR(
"bitpack: output IO 0x%" PRIx32
" not found\n", outputId);
199 outSize = output->getDtypeSize();
201 if (!isBitwiseDtype(outDtype))
203 DAWNERR(
"bitpack: output 0x%" PRIx32
" unsupported dtype %u\n", outputId, output->getDtype());
207 outputBitsPerElement = getLogicalElementBits(output->getDtype(), output->getDtypeSize());
208 outputDim = (requiredBits + outputBitsPerElement - 1) / outputBitsPerElement;
217 DAWNERR(
"bitpack: output target prepare failed %d\n", ret);
221 outputData = output->ddata_alloc(1);
222 if (outputData ==
nullptr)
224 DAWNERR(
"bitpack: outputData allocation failed\n");
235 for (
size_t i = 0; i < inputs.size(); i++)
237 delete inputs[i].currentData;
238 inputs[i].currentData =
nullptr;
244 outputData =
nullptr;
250int CProgBitPack::ioNotifierCb(
void *priv,
io_ddata_t *data)
252 SBitInput *inp =
static_cast<SBitInput *
>(priv);
254 if (data && data->
getItems() >= 1 && inp->currentData)
257 inp->currentData->getDataPtr(), data->
getDataPtr(), inp->currentData->getDataSize());
260 if (inp->owner && inp->owner->active)
262 inp->owner->updateOutput();
282 for (i = 0; i < inputs.size(); i++)
284 if (!inputs[i].io->isNotify())
289 ret = inputs[i].io->setNotifier(ioNotifierCb, 0, &inputs[i]);
292 DAWNERR(
"bitpack: setNotifier failed on input %zu: %d\n", i, ret);
299 for (i = 0; i < inputs.size(); i++)
301 ret = inputs[i].io->getData(*inputs[i].currentData, 1);
304 DAWNERR(
"bitpack: initial getData failed on input %zu: %d\n", i, ret);
317 for (
size_t i = 0; i < inputs.size(); i++)
319 if (inputs[i].io && inputs[i].io->isNotify())
321 inputs[i].io->setNotifier(
nullptr, 0,
nullptr);
337void CProgBitPack::updateOutput()
343 if (output ==
nullptr || outputData ==
nullptr)
350 for (i = 0; i < inputs.size(); i++)
352 if (inputs[i].currentData ==
nullptr)
357 inputs[i].io->getData(*inputs[i].currentData, 1);
359 for (bit = 0; bit < inputs[i].nbits; bit++)
362 inputs[i].dtype, inputs[i].size, inputs[i].currentData->getDataPtr(), bit))
364 writeLogicalBit(outDtype,
366 outputData->getDataPtr(),
367 static_cast<size_t>(inputs[i].bit) + bit,
373 ret = output->setData(*outputData);
376 DAWNERR(
"bitpack: setData on output 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.
Base class for all I/O objects.
virtual bool isRead() const =0
Check if IO supports read operations.
CDescObject & getDesc()
Get descriptor object for this object.
size_t getDtypeSize() const
Get size of this object's data type.
uint8_t getDtype() const
Get data type field.
int doStart()
Start implementation hook.
int configure()
Configure object from descriptor data.
int init()
One-time initialize object after bindings are resolved.
int doStop()
Stop implementation hook.
int deinit()
De-initialize object.
bool hasThread() const
Check if a background thread is active.
Base class for all PROG (processing) objects.
int prepareWritableTarget(CIOCommon *io, size_t dim, bool notify, size_t batch=1)
Check a writable output; shape a deferred virt output or check an already shaped one.
Out-of-tree user-extension hooks for Dawn.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
32-bit encoded Object ID with type, class, data type, and instance.
@ DTYPE_ANY
Wildcard data type (matches any actual type).
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).
size_t getItems()
Get number of items per batch.
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).
struct dawn::SObjectCfg::UObjectCfgId::@334307326077356333363326153167141302007100111136 s
Bit-field structure for named member access.
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).