Split StimulusProducer=>StimulusBuffer+StimulusProducer

We're getting ready for the last mile of the StimulusBuffer API
and the proto-completion of the LivoxGen1 StimBuffApi.
This commit is contained in:
2025-11-14 20:44:37 -04:00
parent 70c0175a8b
commit 8a7dc10892
5 changed files with 96 additions and 46 deletions
+4 -3
View File
@@ -170,6 +170,7 @@ public:
// Parse history buffer duration from quale-iface-api-params
int histbuffMs = 30000; // Default: 30000ms (30 seconds)
(void)histbuffMs;
const std::vector<std::string> histbuffParamNames = {
"history-buffer-duration-ms",
"hist-buff-duration-ms",
@@ -194,10 +195,10 @@ public:
}
// Create and add PcloudDataProducer to collection now that device is ready
StimulusProducer::PcloudFormatDesc formatDesc;
formatDesc.format = StimulusProducer::PcloudFormatDesc::Format::XYZI;
PcloudDataProducer::PcloudFormatDesc formatDesc;
formatDesc.format = PcloudDataProducer::PcloudFormatDesc::Format::XYZI;
auto pcloudDataProducer = std::make_shared<PcloudDataProducer>(
context->spec, context->deviceTmp, formatDesc, histbuffMs, 30);
context->spec, context->deviceTmp, formatDesc, 30);
context->stimProducer = pcloudDataProducer;
context->deviceTmp->nAttachedStimBuffs++;
+15 -18
View File
@@ -23,12 +23,9 @@ PcloudDataProducer::PcloudDataProducer(
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
std::shared_ptr<livoxProto1::Device> &device,
const PcloudFormatDesc& formatDesc,
int histbuffMs,
size_t nDgramsPerStagingBufferFrame)
: StimulusProducer(
deviceAttachmentSpec,
static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS),
openClInputConstraints,
device->componentThread->getIoService()),
device(device),
formatDesc(formatDesc),
@@ -112,25 +109,25 @@ class PcloudDataProducer::ProduceFrameReq
: public PostedAsynchronousContinuation<produceFrameReqCbFn>
{
private:
PcloudDataProducer& stimBuff;
PcloudDataProducer& pcloudProducer;
AsynchronousLoop frameAssemblyResult;
StimulusFrame& stimulusFrame;
public:
ProduceFrameReq(
PcloudDataProducer& buffer,
PcloudDataProducer& producer,
const std::shared_ptr<ComponentThread>& caller,
Callback<produceFrameReqCbFn> cb)
: PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
stimBuff(buffer),
pcloudProducer(producer),
frameAssemblyResult(0),
stimulusFrame(buffer.frames_[0])
stimulusFrame(producer.tempStimulusFrame)
{}
public:
void callOriginalCallback()
{
stimBuff.allowNextStimulusFrame();
pcloudProducer.allowNextStimulusFrame();
callOriginalCb();
}
@@ -138,14 +135,14 @@ public:
void produceFrameReq1_doAssemble_posted(
std::shared_ptr<ProduceFrameReq> context)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
SpinLock::Guard lock(pcloudProducer.shouldContinueLock);
if (!pcloudProducer.shouldContinue)
{
callOriginalCallback();
return;
}
stimBuff.ioUringAssemblyEngine.assembleFrameReq(
pcloudProducer.ioUringAssemblyEngine.assembleFrameReq(
{context, std::bind(
&ProduceFrameReq::produceFrameReq2_assembleDone,
context.get(), context,
@@ -156,8 +153,8 @@ public:
std::shared_ptr<ProduceFrameReq> context,
bool success, AsynchronousLoop loop)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
SpinLock::Guard lock(pcloudProducer.shouldContinueLock);
if (!pcloudProducer.shouldContinue)
{
callOriginalCallback();
return;
@@ -172,7 +169,7 @@ public:
context->frameAssemblyResult = loop;
stimBuff.openClCollatingAndMeshingEngine.compactCollateAndMeshFrameReq(
pcloudProducer.openClCollatingAndMeshingEngine.compactCollateAndMeshFrameReq(
loop, stimulusFrame,
{context, std::bind(
&ProduceFrameReq::produceFrameReq3_compactCollateDone,
@@ -184,8 +181,8 @@ public:
[[maybe_unused]] std::shared_ptr<ProduceFrameReq> context,
bool success, StimulusFrame& /*stimulusFrame*/)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
SpinLock::Guard lock(pcloudProducer.shouldContinueLock);
if (!pcloudProducer.shouldContinue)
{
callOriginalCallback();
return;
@@ -198,8 +195,8 @@ public:
}
// Print kernel execution durations
auto compactDuration = stimBuff.openClCollatingAndMeshingEngine.getCompactKernelDuration();
auto collateDuration = stimBuff.openClCollatingAndMeshingEngine.getCollateKernelDuration();
auto compactDuration = pcloudProducer.openClCollatingAndMeshingEngine.getCompactKernelDuration();
auto collateDuration = pcloudProducer.openClCollatingAndMeshingEngine.getCollateKernelDuration();
std::cout << __func__ << ": compactKernelDuration=" << compactDuration.count()
<< "ms, collateKernelDuration=" << collateDuration.count() << "ms" << std::endl;
+16 -1
View File
@@ -4,6 +4,7 @@
#include <functional>
#include <atomic>
#include <user/stimulusProducer.h>
#include <user/stimulusFrame.h>
#include <livoxProto1/device.h>
#include <asynchronousContinuation.h>
#include <callback.h>
@@ -25,12 +26,25 @@ namespace stim_buff {
class PcloudDataProducer
: public StimulusProducer
{
public:
class PcloudFormatDesc
{
public:
enum class Format
{
XYZ,
XYZI,
};
public:
Format format;
};
public:
explicit PcloudDataProducer(
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
std::shared_ptr<livoxProto1::Device> &device,
const PcloudFormatDesc& formatDesc,
int histbuffMs,
size_t nDgramsPerStagingBufferFrame);
~PcloudDataProducer() = default;
@@ -61,6 +75,7 @@ public:
IoUringAssemblyEngine ioUringAssemblyEngine;
StagingBuffer collationBuffer;
std::atomic<size_t> nAttachedStimBuffs{0};
StimulusFrame tempStimulusFrame;
private:
class ProduceFrameReq;