From 0b32df937fbd17f80f080b8d312348e4a2685c9f Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sun, 8 Nov 2026 20:25:43 +0200 Subject: [PATCH] lab5: add print_stats() per requirements --- inc/dyn-pipeline.hpp | 4 ++++ src/dyn-pipeline-ooe.cpp | 33 ++++++++++++++++++++++++++++++--- src/dyn-pipeline.cpp | 31 +++++++++++++++++++++++++++++-- src/main.cpp | 1 + 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/inc/dyn-pipeline.hpp b/inc/dyn-pipeline.hpp index ca1bf9c..5c5d883 100644 --- a/inc/dyn-pipeline.hpp +++ b/inc/dyn-pipeline.hpp @@ -59,6 +59,7 @@ private: std::vector *program_memory; std::array data_memory; std::array layer_cmd {-1}; + std::vector> layer_util; unsigned int pc {0}; unsigned int system_time; @@ -72,6 +73,7 @@ private: public: void init(const std::vector * const prg, const std::array& mem, const int init_mem_size); void run(void); + void print_stats(void) const; }; class SystemOOE @@ -80,6 +82,7 @@ private: std::vector *program_memory; std::array data_memory; std::array layer_cmd {-1}; + std::vector> layer_util; unsigned int system_time; void print_program_memory(void) const; @@ -92,6 +95,7 @@ private: public: void init(const std::vector * const prg, const std::array& mem, const int init_mem_size); void run(void); + void print_stats(void) const; }; } diff --git a/src/dyn-pipeline-ooe.cpp b/src/dyn-pipeline-ooe.cpp index 224023e..59f86bc 100644 --- a/src/dyn-pipeline-ooe.cpp +++ b/src/dyn-pipeline-ooe.cpp @@ -6,7 +6,7 @@ namespace DynamicPipeline { -static int weight_op(DynamicPipeline::CommandType o) +[[nodiscard]] static int weight_op(DynamicPipeline::CommandType o) { return Expression::Token::weight_op(static_cast(o + 2)); } @@ -159,8 +159,9 @@ void SystemOOE::step(void) { pr_info("Step start time: " << system_time << " ticks"); - // count time - int time_taken = 1; + // count time + record layer_util + int time_taken = 0; + int util = 0; for (int i = 0; i < DYN_PIPELINE_LAYERS; i++) { if (layer_cmd[i] == -1) @@ -168,11 +169,14 @@ void SystemOOE::step(void) continue; } + util++; // layer is loaded with operation + if (const int d = weight_op((*program_memory)[layer_cmd[i]].t); d > time_taken) { time_taken = d; } } + layer_util.emplace_back(util, time_taken); system_time += time_taken; @@ -221,4 +225,27 @@ void SystemOOE::run(void) pr_info("System finished in " << system_time << " ticks"); } +void SystemOOE::print_stats(void) const +{ + int total_prog_time = 0; + + for (unsigned int i = 0; i < program_memory->size(); i++) + { + total_prog_time += weight_op((*program_memory)[i].t) * DYN_PIPELINE_LAYERS; + } + + pr_info("S = " << total_prog_time << " / " << system_time + << " = " << (float) total_prog_time / system_time); + + int total_pipeline_used = 0; + + for (unsigned int i = 0; i < layer_util.size(); i++) + { + total_pipeline_used += layer_util[i].first * layer_util[i].second; + } + + pr_info("E = " << total_pipeline_used << " / " << system_time * DYN_PIPELINE_LAYERS + << " = " << (float) total_pipeline_used / (system_time * DYN_PIPELINE_LAYERS)); +} + } diff --git a/src/dyn-pipeline.cpp b/src/dyn-pipeline.cpp index 7a226a2..d6a5f21 100644 --- a/src/dyn-pipeline.cpp +++ b/src/dyn-pipeline.cpp @@ -6,7 +6,7 @@ namespace DynamicPipeline { -static int weight_op(DynamicPipeline::CommandType o) +[[nodiscard]] static int weight_op(DynamicPipeline::CommandType o) { return Expression::Token::weight_op(static_cast(o + 2)); } @@ -145,8 +145,9 @@ void System::step(void) { pr_info("Step start time: " << system_time << " ticks"); - // count time + // count time + record layer_util int time_taken = 1; + int util = 0; for (int i = 0; i < DYN_PIPELINE_LAYERS; i++) { if (layer_cmd[i] == -1) @@ -154,11 +155,14 @@ void System::step(void) continue; } + util++; // layer is loaded with operation + if (const int d = weight_op((*program_memory)[layer_cmd[i]].t); d > time_taken) { time_taken = d; } } + layer_util.emplace_back(util, time_taken); system_time += time_taken; @@ -207,4 +211,27 @@ void System::run(void) pr_info("System finished in " << system_time << " ticks"); } +void System::print_stats(void) const +{ + int total_prog_time = 0; + + for (unsigned int i = 0; i < program_memory->size(); i++) + { + total_prog_time += weight_op((*program_memory)[i].t) * DYN_PIPELINE_LAYERS; + } + + pr_info("S = " << total_prog_time << " / " << system_time + << " = " << (float) total_prog_time / system_time); + + int total_pipeline_used = 0; + + for (unsigned int i = 0; i < layer_util.size(); i++) + { + total_pipeline_used += layer_util[i].first * layer_util[i].second; + } + + pr_info("E = " << total_pipeline_used << " / " << system_time * DYN_PIPELINE_LAYERS + << " = " << (float) total_pipeline_used / (system_time * DYN_PIPELINE_LAYERS)); +} + } diff --git a/src/main.cpp b/src/main.cpp index 9f027c1..bc5a510 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,4 +40,5 @@ int main(int argc, char **argv) machine.init(&program, memory, mem_used); #endif machine.run(); + machine.print_stats(); }