24 ArcState *state,
unsigned numBuffers,
26 : numBuffers(numBuffers), modelInfo(modelInfo),
debug(
debug),
27 activeBuffer(modelInfo->traceInfo->traceBufferCapacity) {
70 std::cout <<
"[ArcRuntime] Starting trace worker thread." << std::endl;
71 std::thread newWorker([
this]() { this->
workLoop(); });
72 worker = std::move(newWorker);
77 std::optional<TraceBuffer> work = {};
119 if (!offsets.empty() && offsets.back().offset == state->
traceBufferSize) {
121 offsets.back().numSteps++;
148 std::cout <<
"[ArcRuntime] Trace worker thread finished." << std::endl;
155 if (oldBufferSize == 0)
assert(baseType &&"element must be base type")
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.
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.
uint64_t numTraceTaps
Number of trace taps in the array.
uint64_t traceBufferCapacity
Required capacity in 8 byte increments of the trace buffer.
Static information for a compiled hardware model, generated by the MLIR lowering.
struct ArcModelTraceInfo * traceInfo
Signal tracing information. NULL iff the model is not trace instrumented.
Combined runtime and model state for a hardware model instance.
uint64_t * traceBuffer
Pointer to the active trace buffer's storage.
uint32_t traceBufferSize
Number of valid elements in the active trace buffer.
A heap allocated buffer containing raw trace data and time step markers.
int64_t firstStep
Time step of the buffer's first entry.
std::vector< TraceBufferMarker > stepMarkers
Time step markers.
uint32_t size
Number of valid elements, set on dispatch.
void assertSentinel() const
Assert that the buffer's sentinel value has not been overwritten.
uint64_t * getData() const
Get the pointer to the buffer's storage.