-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsv_logger.cpp
More file actions
66 lines (56 loc) · 2.03 KB
/
Copy pathsv_logger.cpp
File metadata and controls
66 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "sv_logger.h"
#include <iostream>
// Static global variables to store the counters
static long long total_instructions = 0;
static long long utilized_lanes = 0;
static long long total_latency = 0;
// Resets all performance counters
void sv_logger_init() {
total_instructions = 0;
utilized_lanes = 0;
total_latency = 0;
}
// Records a masked vector operation
void sv_logger_record_op(sv_mask mask, int latency) {
total_instructions++;
total_latency += latency;
for (int i = 0; i < VECTOR_WIDTH; i++) {
if (mask.data[i]) {
utilized_lanes++;
}
}
}
// Records a full-width vector operation (all lanes active)
void sv_logger_record_unmasked_op(int latency) {
total_instructions++;
utilized_lanes += VECTOR_WIDTH;
total_latency += latency;
}
// Records a scalar (SimFloat) operation — 1 lane utilized
void sv_logger_record_scalar_op(int latency) {
total_instructions++;
utilized_lanes += 1;
total_latency += latency;
}
// Prints a summary of the collected statistics
void sv_logger_print_stats() {
long long total_lanes = total_instructions * VECTOR_WIDTH;
double utilization_rate = (total_lanes > 0) ? ((double)utilized_lanes / total_lanes * 100.0) : 0.0;
std::cout << "\n========== Performance Statistics ==========" << std::endl;
std::cout << "Total instructions: " << total_instructions << std::endl;
std::cout << "Total lanes: " << total_lanes << std::endl;
std::cout << "Utilized lanes: " << utilized_lanes << std::endl;
std::cout << "Lane utilization rate: " << utilization_rate << "%" << std::endl;
std::cout << "Total latency: " << total_latency << " cycles" << std::endl;
std::cout << "============================================" << std::endl;
}
// Implementation for getter functions
long long sv_logger_get_total_instructions() {
return total_instructions;
}
long long sv_logger_get_utilized_lanes() {
return utilized_lanes;
}
long long sv_logger_get_total_latency() {
return total_latency;
}