15#include "dawn/io/ddata.hxx"
16#include "dawn/io/common.hxx"
17#include "dawn/porting/config.hxx"
18#include "dawn/prog/common.hxx"
19#include "dawn/prog/process.hxx"
30 PROG_THRESHOLD_CFG_MODE = 2,
31 PROG_THRESHOLD_CFG_LOW = 3,
32 PROG_THRESHOLD_CFG_HIGH = 4,
64 size_t &offset)
override
74 DAWNERR(
"threshold: invalid config size %u\n", item->
cfgid.
s.
size);
83 case PROG_THRESHOLD_CFG_MODE:
85 if (val > MODE_WINDOW)
87 DAWNERR(
"threshold: invalid mode %" PRIu32
"\n", val);
95 case PROG_THRESHOLD_CFG_LOW:
101 case PROG_THRESHOLD_CFG_HIGH:
120 bool &initsample)
override
126 DAWNERR(
"threshold: invalid output dtype %d for input dtype %d\n",
134#ifdef CONFIG_DAWN_DTYPE_INT8
137 handleTyped<int8_t>(output,
141 static_cast<int8_t
>(low),
142 static_cast<int8_t
>(high));
147#ifdef CONFIG_DAWN_DTYPE_UINT8
150 handleTyped<uint8_t>(output,
154 static_cast<uint8_t
>(low),
155 static_cast<uint8_t
>(high));
160#ifdef CONFIG_DAWN_DTYPE_INT16
163 handleTyped<int16_t>(output,
167 static_cast<int16_t
>(low),
168 static_cast<int16_t
>(high));
173#ifdef CONFIG_DAWN_DTYPE_UINT16
176 handleTyped<uint16_t>(output,
180 static_cast<uint16_t
>(low),
181 static_cast<uint16_t
>(high));
186#ifdef CONFIG_DAWN_DTYPE_INT32
189 handleTyped<int32_t>(output,
199#ifdef CONFIG_DAWN_DTYPE_UINT32
202 handleTyped<uint32_t>(output,
212#ifdef CONFIG_DAWN_DTYPE_INT64
215 handleTyped<int64_t>(output,
219 static_cast<int64_t
>(low),
220 static_cast<int64_t
>(high));
225#ifdef CONFIG_DAWN_DTYPE_UINT64
228 handleTyped<uint64_t>(output,
232 static_cast<uint64_t
>(low),
233 static_cast<uint64_t
>(high));
238#ifdef CONFIG_DAWN_DTYPE_FLOAT
247#ifdef CONFIG_DAWN_DTYPE_DOUBLE
250 handleTyped<double>(output,
262 DAWNERR(
"threshold: unsupported dtype %d\n", data->
getDtype());
275 virtual bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const = 0;
276 virtual int emitOutput(
CIOCommon *output,
286 std::vector<uint8_t> last;
290 bool evaluate(T x, T lowT, T highT, uint8_t prev)
const
301 return x >= lowT && x <= highT;
303 case MODE_HYSTERESIS:
322 void handleTyped(CIOCommon *output,
325 io_ddata_t *outputData,
329 const size_t batches = std::min(data->getBatch(), ioData->getBatch());
333 SState &st = state[outputId];
334 const size_t items = ioData->getItems();
336 if (st.items != items || st.last.size() != items)
339 st.last.assign(items, 0);
344 this->
alerts.resize(batches * items);
346 for (
size_t b = 0; b < batches; b++)
348 std::memcpy(ioData->getDataPtr(b), data->getDataPtr(b), ioData->getDataSize());
350 for (
size_t i = 0; i < items; i++)
352 const T x = ioData->get<T>(i, b);
354 st.last[i] = evaluate(x, lowT, highT, st.last[i]) ? 1 : 0;
355 this->
alerts[b * items + i] = st.last[i];
359 ret = emitOutput(output, data->getDtype(), items, ioData, outputData);
362 DAWNERR(
"threshold: emit failed %d\n", ret);
380 std::map<SObjectId::ObjectId, SState> state;
387class CProgThreshold :
public CProgThresholdBase
391 : CProgThresholdBase(desc)
395#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
396 const char *getClassNameStr()
const override
425 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_MODE);
430 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_LOW);
435 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_HIGH);
439 bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const override
451 const size_t first =
firstBatch(items, outputData);
456 for (
size_t b = 0; b < outputData->
getBatch(); b++)
458 for (
size_t i = 0; i < items; i++)
460 outputData->
get<uint8_t>(i, b) = this->
alerts[(first + b) * items + i];
464 return output->
setData(*outputData);
472class CProgThresholdValue :
public CProgThresholdBase
476 : CProgThresholdBase(desc)
480#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
481 const char *getClassNameStr()
const override
483 return "thresholdvalue";
513 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_MODE);
518 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_LOW);
523 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_HIGH);
527 bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const override
529 return outputDtype == inputDtype;
540#ifdef CONFIG_DAWN_DTYPE_INT8
543 return emitOutputTyped<int8_t>(output, items, ioData, outputData);
547#ifdef CONFIG_DAWN_DTYPE_UINT8
550 return emitOutputTyped<uint8_t>(output, items, ioData, outputData);
554#ifdef CONFIG_DAWN_DTYPE_INT16
557 return emitOutputTyped<int16_t>(output, items, ioData, outputData);
561#ifdef CONFIG_DAWN_DTYPE_UINT16
564 return emitOutputTyped<uint16_t>(output, items, ioData, outputData);
568#ifdef CONFIG_DAWN_DTYPE_INT32
571 return emitOutputTyped<int32_t>(output, items, ioData, outputData);
575#ifdef CONFIG_DAWN_DTYPE_UINT32
578 return emitOutputTyped<uint32_t>(output, items, ioData, outputData);
582#ifdef CONFIG_DAWN_DTYPE_INT64
585 return emitOutputTyped<int64_t>(output, items, ioData, outputData);
589#ifdef CONFIG_DAWN_DTYPE_UINT64
592 return emitOutputTyped<uint64_t>(output, items, ioData, outputData);
596#ifdef CONFIG_DAWN_DTYPE_FLOAT
599 return emitOutputTyped<float>(output, items, ioData, outputData);
603#ifdef CONFIG_DAWN_DTYPE_DOUBLE
606 return emitOutputTyped<double>(output, items, ioData, outputData);
621 const size_t first =
firstBatch(items, outputData);
623 for (
size_t b = 0; b < outputData->
getBatch(); b++)
625 for (
size_t i = 0; i < items; i++)
627 const size_t src = first + b;
629 if (this->
alerts[src * items + i] != 0)
631 outputData->
get<T>(i, b) = ioData->
get<T>(i, src);
635 outputData->
get<T>(i, b) =
static_cast<T
>(0);
640 return output->
setData(*outputData);
Descriptor wrapper for individual object configuration.
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).
@ CMD_RESET
Reset object internal state.
@ PROG_CLASS_THRESHOLD_VALUE
Threshold comparator returning gated source value.
@ PROG_CLASS_THRESHOLD
Threshold and hysteresis comparator.
CProgProcess(CDescObject &desc)
Construct a a Program from descriptor.
int trigger(uint8_t cmd)
Execute a trigger command.
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
int trigger(uint8_t cmd)
Execute a trigger command.
bool isBatchAware() const
Whether handle() consumes every batch of a batched source.
int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
size_t firstBatch(size_t items, io_ddata_t *outputData) const
First alert batch for an output holding fewer batches.
std::vector< uint8_t > alerts
Alert per sample, items per batch.
void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)
Process incoming sample.
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
uint32_t ObjectCfgData_t
Configuration data element - single 32-bit word.
static float cfgToF(ObjectCfgData_t x)
Convert ObjectCfgData_t to float.
static uint32_t cfgToU32(ObjectCfgData_t x)
Convert ObjectCfgData_t to uint32_t.
static int32_t cfgtoi32(ObjectCfgData_t x)
Convert ObjectCfgData_t to int32_t.
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).
@ OBJTYPE_PROG
Program/algorithm object type.
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
@ DTYPE_ANY
Wildcard data type (matches any actual type).
@ DTYPE_UINT64
Unsigned 64-bit integer.
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
@ DTYPE_INT64
Signed 64-bit integer.
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
uint32_t ObjectId
ObjectID type - single 32-bit value.
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Heap-allocated dynamic I/O data buffer.
uint8_t getDtype() const
Get data type enum for introspection.
T & get(size_t index, size_t batch=0)
Get data element by index and batch (type-safe).
size_t getBatch()
Get number of batches.
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).