lab5: add print_stats() per requirements
This commit is contained in:
@@ -59,6 +59,7 @@ private:
|
||||
std::vector<Command> *program_memory;
|
||||
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
||||
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
||||
std::vector<std::pair<int, int>> layer_util;
|
||||
unsigned int pc {0};
|
||||
unsigned int system_time;
|
||||
|
||||
@@ -72,6 +73,7 @@ private:
|
||||
public:
|
||||
void init(const std::vector<Command> * const prg, const std::array<double, DYN_PIPELINE_MEM_SIZE>& mem, const int init_mem_size);
|
||||
void run(void);
|
||||
void print_stats(void) const;
|
||||
};
|
||||
|
||||
class SystemOOE
|
||||
@@ -80,6 +82,7 @@ private:
|
||||
std::vector<CommandOOE> *program_memory;
|
||||
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
||||
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
||||
std::vector<std::pair<int, int>> layer_util;
|
||||
unsigned int system_time;
|
||||
|
||||
void print_program_memory(void) const;
|
||||
@@ -92,6 +95,7 @@ private:
|
||||
public:
|
||||
void init(const std::vector<CommandOOE> * const prg, const std::array<double, DYN_PIPELINE_MEM_SIZE>& mem, const int init_mem_size);
|
||||
void run(void);
|
||||
void print_stats(void) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Expression::Token::Operator>(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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-2
@@ -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<Expression::Token::Operator>(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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,4 +40,5 @@ int main(int argc, char **argv)
|
||||
machine.init(&program, memory, mem_used);
|
||||
#endif
|
||||
machine.run();
|
||||
machine.print_stats();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user