-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.h
executable file
·164 lines (122 loc) · 2.79 KB
/
cpu.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include "common.h"
#include "graph.h"
#include "spmv.h"
namespace spmv {
namespace host {
template <typename T>
class accumulator {
public:
accumulator(): count_(0) {}
void update(const T& value) {
if (0 == count_) {
min_ = value;
max_ = value;
sum_ = value;
} else {
if (value < min_) {
min_ = value;
} else
if (value > max_) {
max_ = value;
}
sum_ += value;
}
++count_;
}
const T& get_min() const {
return min_;
}
const T& get_max() const {
return max_;
}
const T& get_sum() const {
return sum_;
}
uint64_t get_count() const {
return count_;
}
private:
T min_;
T max_;
T sum_;
uint64_t count_;
};
struct rq_data_t {
rq_data_t() {
for (unsigned i = 0; i < sizeof(m); ++i) {
m[i] = 0;
}
}
byte_t m[__div_ceil(qpi::cdata_width, 8)];
};
struct rq_mdata_t {
rq_mdata_t() {
for (unsigned i = 0; i < sizeof(m); ++i) {
m[i] = 0;
}
}
byte_t m[__div_ceil(qpi::mdata_width, 8)];
};
struct request_t {
uint32_t addr;
ch_tick rq_time;
ch_tick rx_time;
ch_tick tx_time;
rq_data_t data;
rq_mdata_t mdata;
request_t(uint32_t _addr, ch_tick _rq_time, ch_tick _rx_time)
: addr(_addr)
, rq_time(_rq_time)
, rx_time(_rx_time)
, tx_time(0)
{}
};
class cpu_device {
public:
enum {
CLOCK_RATE = 200000000, // 200MHz
SHARE_MEM_SIZE = 0x80000000, // 2GB
PARTITION_SIZE = 32,
CACHE_HIT_RATE = 80, // 80%
MIN_RD_RX_CYCLES = 1, // cache hit
MAX_RD_RX_CYCLES = 2,
MIN_RD_TX_CYCLES = 1, // cache hit
MAX_RD_TX_CYCLES = 2,
MIN_RW_RX_CYCLES = 1, // cache hit
MAX_RW_RX_CYCLES = 2,
MIN_RW_TX_CYCLES = 1, // cache hit
MAX_RW_TX_CYCLES = 2,
RQS_BUF_SIZE = 90,
RQS_BUF_FULL_DIST = 4,
};
cpu_device(const char* mtx_file);
~cpu_device();
const auto& get_accelerator() const {
return accelerator_;
}
bool tick(ch_tick t);
void dump_stats(ch_tick t);
private:
void init(const char* mtx_file);
void clear_pulse_signals(ch_tick t);
void process_rd_req(ch_tick t);
void process_wr_req(ch_tick t);
void process_rd_rsp(ch_tick t);
void process_wr_rsp(ch_tick t);
void check_result(ch_tick t);
void check_output(const float* values,
const uint32_t* masks,
bool debug);
ch_device<accelerator::spmv_device> accelerator_;
std::list<request_t*> qpi_read_requests_;
std::list<request_t*> qpi_write_requests_;
byte_t* shared_mem_;
mdcsc_t* matrix_;
vertex_t* vertex_;
accumulator<ch_tick> qpi_rd_stats_;
accumulator<ch_tick> qpi_wr_stats_;
friend class simulator;
};
}
}