15#ifndef CIRCT_DIALECT_ARC_RUNTIME_TRACEENCODER_H
16#define CIRCT_DIALECT_ARC_RUNTIME_TRACEENCODER_H
23#include <condition_variable>
115 uint64_t *
dispatch(uint32_t oldBufferSize);
~DummyTraceEncoder() override=default
bool initialize(const ArcState *state) override
Set-up the encoder before starting the worker thread.
DummyTraceEncoder(const ArcRuntimeModelInfo *modelInfo, ArcState *state)
virtual bool initialize(const ArcState *state)=0
Set-up the encoder before starting the worker thread.
std::atomic< bool > isFinished
Flag signaling that no more buffers will be enqueued.
std::queue< TraceBuffer > bufferQueue
virtual void startUpWorker()
Called by the worker thread before entering the encode loop.
virtual ~TraceEncoder()=default
uint64_t simTime
Current simulation time in femtoseconds.
int64_t getTimeStep() const
Return the value of the internal step counter.
void workLoop()
The encoder thread's work loop.
std::mutex bufferQueueMutex
Queue and synchronization primitives for buffers to be processed by the encoder thread.
virtual void finalize(const ArcState *state)
Finish trace encoding. Called by the simulation thread.
void step(const ArcState *state)
Signal the start of a new simulation time step.
std::mutex availableBuffersMutex
Return stack and synchronization primitives for processed buffers.
virtual void windDownWorker()
Called by the worker thread after leaving the encode loop.
virtual void encode(TraceBuffer &work)
Encode the given trace buffer. Called by the worker thread.
void run(ArcState *state)
Begin tracing.
std::condition_variable availableBuffersCv
const unsigned numBuffers
Number of trace buffers in rotation.
std::vector< TraceBuffer > availableBuffers
void enqueueBuffer(TraceBuffer &&buffer)
int64_t timeStep
Current simulation time step.
const ArcRuntimeModelInfo *const modelInfo
Metadata of the traced model.
TraceBuffer activeBuffer
Trace buffer currently in use by the hardware model.
std::condition_variable bufferQueueCv
void finish(const ArcState *state)
Stop tracing.
uint64_t * dispatch(uint32_t oldBufferSize)
Dispatch the currently active trace buffer containing oldBufferSize valid entries to the encoder thre...
std::optional< std::thread > worker
Trace encoder worker thread. If empty, tracing is disabled.
static void fatalError(const char *message)
Raise an irrecoverable error.
Static information for a compiled hardware model, generated by the MLIR lowering.
Combined runtime and model state for a hardware model instance.
uint64_t simTime
Simulation time in femtoseconds at this marker.
uint32_t offset
Offset within the buffer in number of elements.
uint32_t numSteps
Number of time steps to advance at the given offset.
TraceBufferMarker()=delete
TraceBufferMarker(uint32_t offset, uint64_t simTime)
A heap allocated buffer containing raw trace data and time step markers.
TraceBuffer(const TraceBuffer &other)=delete
TraceBuffer(TraceBuffer &&other) noexcept=default
int64_t firstStep
Time step of the buffer's first entry.
std::unique_ptr< uint64_t[]> storage
void clear()
Reset the buffer.
std::vector< TraceBufferMarker > stepMarkers
Time step markers.
TraceBuffer(uint32_t capacity)
TraceBuffer & operator=(TraceBuffer &&other) noexcept=default
uint32_t size
Number of valid elements, set on dispatch.
void assertSentinel() const
Assert that the buffer's sentinel value has not been overwritten.
static constexpr uint64_t sentinelValue
uint64_t * getData() const
Get the pointer to the buffer's storage.
TraceBuffer operator=(const TraceBuffer &other)=delete
uint32_t capacity
Available storage in number of elements.
uint64_t firstSimTime
Simulation time in femtoseconds at the buffer's first entry.