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;
32CProgBitPack::~CProgBitPack()
45 inp.currentData =
nullptr;
47 inputs.push_back(inp);
52int CProgBitPack::configureDesc(
const CDescObject &desc)
62 for (ii = 0; ii < desc.
getSize(); ii++)
66 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_BITPACK)
68 DAWNERR(
"bitpack: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
74 case PROG_BITPACK_CFG_INPUTS:
77 if (n == 0 || n % INPUT_WORDS != 0)
79 DAWNERR(
"bitpack: invalid INPUTS size %zu\n", n);
83 vals =
reinterpret_cast<const uint32_t *
>(item->
data);
84 for (
size_t j = 0; j < n; j += INPUT_WORDS)
87 int ret = allocInput(ids[0].v, vals[j + 1]);
96 case PROG_BITPACK_CFG_OUTPUT:
100 DAWNERR(
"bitpack: OUTPUT must have 1 entry\n");
112 DAWNERR(
"bitpack: unsupported cfg id %u\n", item->
cfgid.
s.
id);
120 DAWNERR(
"bitpack: at least one input required\n");
126 DAWNERR(
"bitpack: output IO not configured\n");
135 return configureDesc(
getDesc());
143 size_t outputBitsPerElement;
148 for (i = 0; i < inputs.size(); i++)
150 io =
getIO(inputs[i].ioId);
153 DAWNERR(
"bitpack: input IO 0x%" PRIx32
" not found\n", inputs[i].ioId);
159 DAWNERR(
"bitpack: input 0x%" PRIx32
" is not readable\n", inputs[i].ioId);
163 if (!isBitwiseDtype(io->
getDtype()))
166 "bitpack: input 0x%" PRIx32
" unsupported dtype %u\n", inputs[i].ioId, io->
getDtype());
171 inputs[i].currentData = inputs[i].io->ddata_alloc(1);
172 if (inputs[i].currentData ==
nullptr)
174 DAWNERR(
"bitpack: currentData allocation failed for input %zu\n", i);
179 std::max(requiredBits,
static_cast<size_t>(inputs[i].bit) + getLogicalBits(inputs[i].io));
182 io =
getIO(outputId);
185 DAWNERR(
"bitpack: output IO 0x%" PRIx32
" not found\n", outputId);
190 if (!isBitwiseDtype(output->
getDtype()))
192 DAWNERR(
"bitpack: output 0x%" PRIx32
" unsupported dtype %u\n", outputId, output->
getDtype());
197 outputDim = (requiredBits + outputBitsPerElement - 1) / outputBitsPerElement;
203 ret = prepareWritableTarget(output, outputDim,
true);
206 DAWNERR(
"bitpack: output target prepare failed %d\n", ret);
211 if (outputData ==
nullptr)
213 DAWNERR(
"bitpack: outputData allocation failed\n");
224 for (
size_t i = 0; i < inputs.size(); i++)
226 delete inputs[i].currentData;
227 inputs[i].currentData =
nullptr;
233 outputData =
nullptr;
239int CProgBitPack::ioNotifierCb(
void *priv,
io_ddata_t *data)
241 SBitInput *inp =
static_cast<SBitInput *
>(priv);
243 if (data && data->
getItems() >= 1 && inp->currentData)
246 inp->currentData->getDataPtr(), data->
getDataPtr(), inp->currentData->getDataSize());
249 if (inp->owner && inp->owner->active)
251 inp->owner->updateOutput();
271 for (i = 0; i < inputs.size(); i++)
273 if (!inputs[i].io->isNotify())
278 ret = inputs[i].io->setNotifier(ioNotifierCb, 0, &inputs[i]);
281 DAWNERR(
"bitpack: setNotifier failed on input %zu: %d\n", i, ret);
288 for (i = 0; i < inputs.size(); i++)
290 ret = inputs[i].io->getData(*inputs[i].currentData, 1);
293 DAWNERR(
"bitpack: initial getData failed on input %zu: %d\n", i, ret);
306 for (
size_t i = 0; i < inputs.size(); i++)
308 if (inputs[i].io && inputs[i].io->isNotify())
310 inputs[i].io->setNotifier(
nullptr, 0,
nullptr);
326void CProgBitPack::updateOutput()
332 if (output ==
nullptr || outputData ==
nullptr)
339 for (i = 0; i < inputs.size(); i++)
341 if (inputs[i].currentData ==
nullptr)
346 inputs[i].io->getData(*inputs[i].currentData, 1);
348 for (bit = 0; bit < getLogicalBits(inputs[i].io); bit++)
350 if (readLogicalBit(inputs[i].io, inputs[i].currentData->getDataPtr(), bit))
353 output, outputData->
getDataPtr(),
static_cast<size_t>(inputs[i].bit) + bit,
true);
358 ret = output->
setData(*outputData);
361 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.
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
io_ddata_t * ddata_alloc(size_t batch, size_t chunk_size=0)
Allocate data buffer for this I/O.
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.
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).
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).
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).