The Sparta Modeling Framework
Loading...
Searching...
No Matches
Scoreboard.hpp
Go to the documentation of this file.
1// <Scoreboard.hpp> -*- C++ -*-
2
8#pragma once
9
10#include <vector>
11#include <cinttypes>
12#include <string>
13#include <map>
14#include <list>
15
20
21namespace sparta
22{
23 class ScoreboardView;
24
41 class Scoreboard : public sparta::Unit
42 {
43 public:
44 using UnitID = uint32_t;
45 using InstID = uint64_t;
46
47 static constexpr UnitID INVALID_UNIT_ID = std::numeric_limits<UnitID>::max();
48 static constexpr uint32_t INVALID_LATENCY = static_cast<uint32_t>(-1);
49 static constexpr uint32_t MAX_REGISTERS = 512;
50
51 using RegisterBitMask = std::bitset<MAX_REGISTERS>;
52
54 static const char name[];
55
57 {
58 public:
59 using LatencyMatrixParameterType = std::vector<std::vector<std::string>>;
60
62
63 //
64 // Example table:
65 //
66 // [ # FROM
67 // # |
68 // # V
69 // ["" ,"ALU0", "ALU1", "LSU", "FPU"], # <- TO
70 // ["ALU0", "0", "1", "1", "3"],
71 // ["ALU1", "1", "0", "1", "3"],
72 // ["LSU", "1", "1", "0", "1"],
73 // ["FPU", "3", "3", "1", "0"]
74 // ]
75 //
76 PARAMETER(LatencyMatrixParameterType, latency_matrix, {},
77 "The forwarding latency matrix. See the Scoreboard test for format example")
78 };
79
87 Scoreboard(sparta::TreeNode * container, const ScoreboardParameters * params);
88
97 void set(const RegisterBitMask & bits);
98
109 void set(const RegisterBitMask & bits, UnitID producer);
110
119 void clearBits(const RegisterBitMask & bits);
120
128 UnitID registerView(const std::string & producer_name,
129 ScoreboardView * view);
130
132 bool isSet(const RegisterBitMask & bits) const;
133
134 private:
135
136 // Allow the ScoreboardView to access the above structure
137 friend class ScoreboardView;
138
139 // 0 means the register is not ready.
140 RegisterBitMask global_reg_ready_mask_{0xffffffff};
141
142 // Setting up the forwarding matrix based on integer lookups
143 using ForwardingLatency = uint32_t;
144 using ForwardingLatencyConsumers = std::vector<ForwardingLatency>;
145 using ForwardingLatencyProducers = std::vector<ForwardingLatencyConsumers>;
146
147 // A vector of producers, with each producing row having a list of consumers
148 ForwardingLatencyProducers forwarding_latencies_;
149
150 // Units found in the latency table, first column, second row onward
151 using UnitToIDMap = std::map<std::string, uint32_t>;
152 UnitToIDMap unit_name_to_id_;
153
154 // UnitID to the ScoreboardViews
155 // Single unit can have multiple ScorboardViews
156 using UnitIDToSBVs = std::vector<std::vector<ScoreboardView *>>;
157 UnitIDToSBVs unit_id_to_scoreboard_views_;
158
159 // Producer UnitID to consumer ScoreboardViews
160 using ConsumerSBV = std::tuple<ScoreboardView *, ForwardingLatency>;
161 using ConsumerSBVs = std::vector<ConsumerSBV>;
162 using ProducerToConsumerSBVs = std::vector<ConsumerSBVs>;
163 ProducerToConsumerSBVs producer_to_consumer_scoreboard_views_;
164
165 // Unit ID count
166 uint32_t unit_id_ = 0;
167
168 // Structure to hold a forwarded scoreboard update
169 struct ScoreboardUpdate {
170 RegisterBitMask bits;
171 UnitID producer;
172 };
173
174 // PayloadEvent used to deliver the Scoreboard contents to the views
175 struct ScoreboardViewUpdate
176 {
177 ScoreboardUpdate first;
178 ScoreboardView *second;
179 bool is_canceled;
180 };
182 void deliverScoreboardUpdate_(const ScoreboardViewUpdate &);
183 };
184
194 {
195 public:
197 using ReadinessCallback = std::function<void(const Scoreboard::RegisterBitMask&)>;
198
206 ScoreboardView(const std::string & unit_name,
207 const std::string & scoreboard_type,
208 sparta::TreeNode * node);
209
224 void registerReadyCallback(const Scoreboard::RegisterBitMask & bits,
225 const Scoreboard::InstID inst_id,
226 const ReadinessCallback & callback);
227
235 void clearCallbacks(const Scoreboard::InstID inst_id);
236
242 bool isSet(const Scoreboard::RegisterBitMask & bits) const
243 {
244 return bits == (local_ready_mask_ & bits);
245 }
246
251 void setReady(const Scoreboard::RegisterBitMask & bits);
252
257 std::string getType() const {
258 return scoreboard_type_;
259 }
260
265 std::string getName() const {
266 return unit_name_;
267 }
268
269 private:
270
271 // Make the Scoreboard a friend to clear bits in the view
272 friend Scoreboard;
273
280 void receiveScoreboardUpdate_(const Scoreboard::RegisterBitMask & bits,
281 const Scoreboard::UnitID producer);
282
283 // Find a Scoreboard that matches this view in the node hierarchy
284 Scoreboard::UnitID findMasterScoreboard_(const std::string & unit_name,
285 const std::string & scoreboard_type,
286 sparta::TreeNode * parent);
287
292 void clearBits_(const Scoreboard::RegisterBitMask & bits);
293
294 Scoreboard::RegisterBitMask local_ready_mask_{0xffffffff};
295
297 Scoreboard * master_scoreboard_ = nullptr;
298
299 struct CallbackData
300 {
301 CallbackData(const Scoreboard::RegisterBitMask & bv,
302 const Scoreboard::InstID iid,
303 const ReadinessCallback & cb,
304 sparta::Clock::Cycle cyc) :
305 needed_bits(bv), inst_id(iid), callback(cb), registered_time(cyc)
306
307 {}
308
309 CallbackData(CallbackData&&) = default;
310
311 const Scoreboard::RegisterBitMask needed_bits;
312 const Scoreboard::InstID inst_id;
313 ReadinessCallback callback;
314 sparta::Clock::Cycle registered_time;
315 };
316
317 using ReadinessCallbacks = std::list<CallbackData>;
318 ReadinessCallbacks ready_callbacks_;
319
320 const sparta::Clock * clock_;
321 const std::string unit_name_;
322 const Scoreboard::UnitID unit_id_;
323 const std::string scoreboard_type_;
324 };
325
326 // This override (implementation in Scoreboard.cpp) will provide a
327 // friendlier scoreboard output
328 extern std::string printBitSet(const Scoreboard::RegisterBitMask & bits);
329}
A set of sparta::Parameters per sparta::ResourceTreeNode.
#define PARAMETER(type, name, def, doc)
Parameter declaration.
File that defines the PayloadEvent class.
Basic Node framework in sparta device tree composite pattern.
File that defines the Unit class, a common grouping of sets and loggers.
A representation of simulated time.
Definition Clock.hpp:51
Generic container of Parameters.
Class to schedule a Scheduleable in the future with a payload, typed on both the data type and the sc...
A ScoreboardView is a view into the master Scoreboard for operand readiness.
std::string getType() const
Get the scoreboard type identifier.
std::string getName() const
Get the name of this view.
void registerReadyCallback(const Scoreboard::RegisterBitMask &bits, const Scoreboard::InstID inst_id, const ReadinessCallback &callback)
Register a ready callback to be called when the bits are ready.
bool isSet(const Scoreboard::RegisterBitMask &bits) const
See if the given bits are set.
std::function< void(const Scoreboard::RegisterBitMask &)> ReadinessCallback
Typedef for the callbacks.
ScoreboardView(const std::string &unit_name, const std::string &scoreboard_type, sparta::TreeNode *node)
Create a ScoreboardView.
void setReady(const Scoreboard::RegisterBitMask &bits)
Set the given bits as ready in the Scoreboard.
void clearCallbacks(const Scoreboard::InstID inst_id)
On a flush any registered callback needs to be "forgotten".
Class used to track operand dependencies (timed) between units.
static const char name[]
Name of this resource. Required by sparta::ResourceFactory.
Scoreboard(sparta::TreeNode *container, const ScoreboardParameters *params)
Construct a Scoreboard.
UnitID registerView(const std::string &producer_name, ScoreboardView *view)
Register a view with this Scoreboard based on producer's name. The producer name MUST be listed in co...
bool isSet(const RegisterBitMask &bits) const
Look at the master scoreboard's view of ready.
void set(const RegisterBitMask &bits, UnitID producer)
Set Ready bits on the master scoreboard.
void clearBits(const RegisterBitMask &bits)
Clear the given bits from the Scoreboard.
void set(const RegisterBitMask &bits)
Set Ready bits on the master scoreboard.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
Macros for handling exponential backoff.