CIRCT 24.0.0git
Loading...
Searching...
No Matches
FSTTraceEncoder.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// TraceEncoder subclass converting and outputting a stream of raw trace buffers
10// to an FST file.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CIRCT_DIALECT_ARC_RUNTIME_FSTTRACEENCODER_H
15#define CIRCT_DIALECT_ARC_RUNTIME_FSTTRACEENCODER_H
16
20
21#include <filesystem>
22#include <string>
23#include <vector>
24
25struct fstWriterContext;
26
28
29/// A traced signal in the FST file
31 FSTSignalTableEntry(uint64_t index, uint64_t stateOffset, uint32_t numBits)
33
34 /// Get the number of words occupied by the signal value in the trace buffer
35 inline unsigned getStride() const { return (numBits + 63) / 64; }
36
37 /// FST signal handle
38 uint32_t handle;
39 /// Offest of the signal in the model's simulation state
40 uint64_t stateOffset;
41 /// Bit width of the signal
42 uint32_t numBits;
43};
44
45/// Trace buffer encoder producing an FST file
46class FSTTraceEncoder final : public TraceEncoder {
47public:
48 static constexpr unsigned numTraceBuffers = 4;
49
51 const std::filesystem::path &outFilePath, bool debug);
52
53protected:
54 bool initialize(const ArcState *state) override;
55 void startUpWorker() override;
56 void encode(TraceBuffer &work) override;
57 void windDownWorker() override;
58 void finalize(const ArcState *state) override;
59
60private:
61 /// Create the table of signals
62 void initSignalTable();
63 /// Build and dump the signal hierarchy
64 void createHierarchy();
65
66 /// Path to the output file
67 const std::filesystem::path outFilePath;
68 /// Table of signals: The index matches their Trace Tap ID.
69 std::vector<FSTSignalTableEntry> signalTable;
70 /// FST writer context
71 struct ::fstWriterContext *fstWriter = nullptr;
72 /// Current time step of the worker thread
73 int64_t workerStep;
74};
75
76} // namespace circt::arc::runtime::impl
77
78#endif // CIRCT_DIALECT_ARC_RUNTIME_FSTTRACEENCODER_H
struct::fstWriterContext * fstWriter
FST writer context.
const std::filesystem::path outFilePath
Path to the output file.
void windDownWorker() override
Called by the worker thread after leaving the encode loop.
int64_t workerStep
Current time step of the worker thread.
void encode(TraceBuffer &work) override
Encode the given trace buffer. Called by the worker thread.
bool initialize(const ArcState *state) override
Set-up the encoder before starting the worker thread.
std::vector< FSTSignalTableEntry > signalTable
Table of signals: The index matches their Trace Tap ID.
FSTTraceEncoder(const ArcRuntimeModelInfo *modelInfo, ArcState *state, const std::filesystem::path &outFilePath, bool debug)
void startUpWorker() override
Called by the worker thread before entering the encode loop.
void finalize(const ArcState *state) override
Finish trace encoding. Called by the simulation thread.
void createHierarchy()
Build and dump the signal hierarchy.
void initSignalTable()
Create the table of signals.
const ArcRuntimeModelInfo *const modelInfo
Metadata of the traced model.
Definition debug.py:1
Static information for a compiled hardware model, generated by the MLIR lowering.
Definition Common.h:70
Combined runtime and model state for a hardware model instance.
Definition Common.h:44
uint32_t numBits
Bit width of the signal.
FSTSignalTableEntry(uint64_t index, uint64_t stateOffset, uint32_t numBits)
uint64_t stateOffset
Offest of the signal in the model's simulation state.
unsigned getStride() const
Get the number of words occupied by the signal value in the trace buffer.
A heap allocated buffer containing raw trace data and time step markers.