6#include "simdb/schema/Schema.hpp"
7#include "sparta/report/db/Schema.hpp"
15 vec = std::vector<double>(vec.size(), NAN);
53 const Clock & root_clk) :
55 scheduler_(*root_clk.getScheduler()),
62 for (
const auto si : stats_) {
63 si->disableSnapshotLogging();
74 "Cannot change row/column-major ordering when "
75 "SIValuesBuffer contains buffered data");
86 "Cannot change row/column-major ordering when "
87 "SIValuesBuffer contains buffered data");
89 is_row_major_ =
false;
95 return is_row_major_ ?
96 db::MajorOrdering::ROW_MAJOR :
97 db::MajorOrdering::COLUMN_MAJOR;
109 si_values_buffer_.resize(num_si_buffers * stats_.size());
110 max_num_si_buffers_ = num_si_buffers;
137 "SIValuesBuffer with zero SI capacity");
138 updated_num_si_buffers_ = num_si_buffers;
147 return (current_buffer_write_idx_ == max_num_si_buffers_);
152 return (current_buffer_write_idx_ == 0);
158 return current_buffer_write_idx_;
168 current_buffer_write_idx_ = 0;
169 if (updated_num_si_buffers_.
isValid()) {
174 if (fill_with_nans) {
178 si_buffer_beginning_picoseconds_.
clearValid();
180 si_buffer_beginning_clock_cycles_.
clearValid();
218 sparta_assert(current_buffer_write_idx_ < max_num_si_buffers_);
224 si_buffer_beginning_clock_cycles_ = root_clk_.
currentCycle();
233 current_buffer_write_idx_ * stats_.size() :
234 current_buffer_write_idx_;
235 for (
const auto si : stats_) {
236 si_values_buffer_[buffer_idx] = si->getValue();
240 buffer_idx += is_row_major_ ? 1 : max_num_si_buffers_;
242 ++current_buffer_write_idx_;
247 si_buffer_ending_clock_cycles_ = root_clk_.
currentCycle();
270 return si_values_buffer_;
275 return si_values_buffer_;
278 const size_t num_filled_buffers = current_buffer_write_idx_;
279 squeezed_si_values_.resize(num_filled_buffers * stats_.size());
280 auto read_iter = si_values_buffer_.begin();
285 memcpy(&squeezed_si_values_[0],
286 &si_values_buffer_[0],
287 squeezed_si_values_.size() *
sizeof(
double));
291 for (
size_t si_idx = 0; si_idx < stats_.size(); ++si_idx) {
294 read_iter + num_filled_buffers,
295 squeezed_si_values_.begin() + (si_idx * num_filled_buffers));
299 std::advance(read_iter, max_num_si_buffers_);
303 return squeezed_si_values_;
313 uint64_t & starting_picoseconds,
314 uint64_t & ending_picoseconds,
315 uint64_t & starting_cycles,
316 uint64_t & ending_cycles)
const
318 starting_picoseconds = si_buffer_beginning_picoseconds_;
319 ending_picoseconds = si_buffer_ending_picoseconds_;
320 starting_cycles = si_buffer_beginning_clock_cycles_;
321 ending_cycles = si_buffer_ending_clock_cycles_;
325 const std::vector<const StatisticInstance*> stats_;
326 std::vector<double> si_values_buffer_;
327 std::vector<double> squeezed_si_values_;
328 size_t current_buffer_write_idx_ = 0;
329 size_t max_num_si_buffers_ = 0;
331 bool is_row_major_ =
true;
342 const Clock & root_clk_;
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Contains a StatisticInstance which refers to a StatisticDef or Counter and some local state to comput...
A representation of simulated time.
Cycle currentCycle() const
Get the current cycle (uses current tick from the Scheduler)
A class that lets you schedule events now and in the future.
Tick getSimulatedPicoSeconds() const noexcept
Used to construct and throw a standard C++ exception. Inherits from std::exception.
This class helps organize contiguous blocks of SI values. These values are buffered at each report up...
void useRowMajorOrdering()
size_t getNumBufferedSIBlocks() const
db::MajorOrdering getMajorOrdering() const
void resetSIBuffers(const bool fill_with_nans=true)
void bufferCurrentSIValues()
void getBeginningAndEndingTimestampsForBufferedSIs(uint64_t &starting_picoseconds, uint64_t &ending_picoseconds, uint64_t &starting_cycles, uint64_t &ending_cycles) const
void useColumnMajorOrdering()
void updateNumSIBuffers(const size_t num_si_buffers)
const std::vector< double > & getBufferedSIValues()
bool buffersAreFilled() const
bool buffersAreEmpty() const
Ask if this buffer is completely empty.
SIValuesBuffer(const std::vector< const StatisticInstance * > &stats, const Clock &root_clk)
void initializeNumSIBuffers(const size_t num_si_buffers)
Provides a wrapper around a value to ensure that the value is assigned.
void clearValid()
Clear the validity of this object.
bool isValid() const
Is this value valid.
void refillWithNaNs(std::vector< double > &vec)
Utility to set all elements of a vector to NaN.
Macros for handling exponential backoff.