CIRCT 22.0.0git
Loading...
Searching...
No Matches
VCDTraceEncoder.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 a VCD file.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CIRCT_DIALECT_ARC_RUNTIME_VCDTRACEENCODER_H
15#define CIRCT_DIALECT_ARC_RUNTIME_VCDTRACEENCODER_H
16
20
21#include <array>
22#include <filesystem>
23#include <fstream>
24#include <memory>
25#include <vector>
26
28
29/// String identifier for a signal in a VCD file consisting of characters in
30/// the ASCII range from '!' to '~'.
32 VCDSignalId() = delete;
33 /// Create the string ID from an integer ID
34 explicit VCDSignalId(uint64_t index);
35
36 /// Get the ID as null terminated string
37 inline const char *cStr() const { return raw.data(); }
38 /// Get the number of characters in the ID
39 inline unsigned getNumChars() const { return numChars; }
40
41private:
42 unsigned numChars;
43 std::array<char, 16> raw;
44};
45
46/// A traced signal in the VCD file
48 VCDSignalTableEntry(uint64_t index, uint64_t stateOffset, uint32_t numBits)
50
51 /// Get the number of characters required to dump this signal's ID and value
52 inline unsigned getDumpSize() const {
53 return id.getNumChars() + numBits + ((numBits > 1) ? 3 : 1);
54 }
55
56 /// Get the number of words occupied by the signal value in the trace buffer
57 inline unsigned getStride() const { return (numBits + 63) / 64; }
58
59 /// VCD signal ID
61 /// Offest of the signal in the model's simulation state
62 uint64_t stateOffset;
63 /// Bit width of the signal
64 uint32_t numBits;
65};
66
67/// Trace buffer encoder producing a VCD file
68class VCDTraceEncoder final : public TraceEncoder {
69public:
70 static constexpr unsigned numTraceBuffers = 4;
71
73 const std::filesystem::path &outFilePath, bool debug);
74
75protected:
76 bool initialize(const ArcState *state) override;
77 void startUpWorker() override;
78 void encode(TraceBuffer &work) override;
79 void windDownWorker() override;
80 void finalize(const ArcState *state) override;
81
82private:
83 /// Create the table of signals
84 void initSignalTable();
85 /// Build and dump the signal hierarchy
86 void createHierarchy();
87
88 /// Path to the output file
89 const std::filesystem::path outFilePath;
90 /// Table of signals: The index matches their Trace Tap ID.
91 std::vector<VCDSignalTableEntry> signalTable;
92 /// Output file stream
93 std::ofstream outFile;
94 /// Internal buffer of the output stream.
95 /// Do not access directly. Do not release until outFile is closed.
96 std::unique_ptr<char[]> fileBuffer;
97 /// Concatenation buffer of the worker thread
98 std::vector<char> workerOutBuffer;
99 /// Current time step of the worker thread
100 int64_t workerStep;
101};
102
103} // namespace circt::arc::runtime::impl
104
105#endif // CIRCT_DIALECT_ARC_RUNTIME_VCDTRACEENCODER_H
Abstract TraceEncoder managing trace buffers and the encoder thread.
const ArcRuntimeModelInfo *const modelInfo
Metadata of the traced model.
Trace buffer encoder producing a VCD file.
void startUpWorker() override
Called by the worker thread before entering the encode loop.
std::ofstream outFile
Output file stream.
std::vector< char > workerOutBuffer
Concatenation buffer of the worker thread.
std::unique_ptr< char[]> fileBuffer
Internal buffer of the output stream.
void windDownWorker() override
Called by the worker thread after leaving the encode loop.
void createHierarchy()
Build and dump the signal hierarchy.
const std::filesystem::path outFilePath
Path to the output file.
void encode(TraceBuffer &work) override
Encode the given trace buffer. Called by the worker thread.
std::vector< VCDSignalTableEntry > signalTable
Table of signals: The index matches their Trace Tap ID.
bool initialize(const ArcState *state) override
Set-up the encoder before starting the worker thread.
int64_t workerStep
Current time step of the worker thread.
void initSignalTable()
Create the table of signals.
void finalize(const ArcState *state) override
Finish trace encoding. Called by the simulation thread.
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
A heap allocated buffer containing raw trace data and time step markers.
String identifier for a signal in a VCD file consisting of characters in the ASCII range from '!...
const char * cStr() const
Get the ID as null terminated string.
unsigned getNumChars() const
Get the number of characters in the ID.
uint64_t stateOffset
Offest of the signal in the model's simulation state.
unsigned getDumpSize() const
Get the number of characters required to dump this signal's ID and value.
unsigned getStride() const
Get the number of words occupied by the signal value in the trace buffer.
VCDSignalTableEntry(uint64_t index, uint64_t stateOffset, uint32_t numBits)
uint32_t numBits
Bit width of the signal.