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
|
from pySoftMC import *
import numpy as np
# Initialize SoftMC platform
platform = SoftMCPlatform()
err = platform.init()
if (err != 0):
print("SoftMC platform initialization failed!")
exit(-1)
platform.reset_fpga()
# Define registers
CASR = 0
BASR = 1
RASR = 2
BAR = 3
RAR = 4
CAR = 5
PATTERN_REG = 6
def initialize_row(platform: SoftMCPlatform, data32: int, bank: int, row: int):
p = Program()
p.add_inst(SMC_LI(bank, BAR))
p.add_inst(SMC_LI(row, RAR))
p.add_inst(SMC_LI(8, CASR))
p.add_inst(SMC_LI(data32, PATTERN_REG))
for i in range(16):
p.add_inst(SMC_LDWD(PATTERN_REG, i))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_LI(0, CAR))
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_ACT(BAR, 0, RAR, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
for i in range(128):
p.add_inst(SMC_WRITE(BAR, 0, CAR, 1, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_SLEEP(3))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_END())
platform.execute(p)
def read_row(platform: SoftMCPlatform, bank: int, row: int):
p = Program()
p.add_inst(SMC_LI(bank, BAR))
p.add_inst(SMC_LI(row, RAR))
p.add_inst(SMC_LI(8, CASR))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_LI(0, CAR))
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_ACT(BAR, 0, RAR, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
for i in range(128):
p.add_inst(SMC_READ(BAR, 0, CAR, 1, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_SLEEP(3))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_END())
platform.execute(p)
def hammer_row_double(bank, aggressor_row_1, aggressor_row_2, hammer_count, RAS_scale, RP_scale):
HMR_COUNTER_REG = 7
NUM_HMR_REG = 8
p = Program()
p.add_inst(SMC_LI(bank, BAR))
p.add_inst(SMC_LI(aggressor_row_1, RAR))
p.add_inst(SMC_LI(0, HMR_COUNTER_REG))
p.add_inst(SMC_LI(hammer_count, NUM_HMR_REG))
p.add_label("HMR_BEGIN")
if (RAS_scale > 1):
p.add_inst(SMC_SLEEP(5 * (RAS_scale - 1)))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_LI(aggressor_row_1, RAR))
if (RP_scale > 1):
p.add_inst(SMC_SLEEP(3 * (RP_scale - 1)))
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_ACT(BAR, 0, RAR, 0))
p.add_inst(SMC_LI(aggressor_row_2, RAR))
p.add_inst(SMC_SLEEP(5))
if (RAS_scale > 1):
p.add_inst(SMC_SLEEP(5 * (RAS_scale - 1)))
p.add_inst(SMC_PRE(BAR, 0, 0), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_ADDI(HMR_COUNTER_REG, 1, HMR_COUNTER_REG))
if (RP_scale > 1):
p.add_inst(SMC_SLEEP(3 * (RP_scale - 1)))
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_ACT(BAR, 0, RAR, 0))
p.add_branch(Program.BR_TYPE.BL, HMR_COUNTER_REG, NUM_HMR_REG, "HMR_BEGIN")
p.add_inst(SMC_NOP(), SMC_NOP(), SMC_NOP(), SMC_NOP())
p.add_inst(SMC_END())
platform.execute(p)
def check_flips(buffer, pattern):
d = []
out = np.bitwise_xor(buffer, pattern)
for cl in range(128):
for w in range(8):
if (out[cl * 8 + w]) != 0:
_w = out[cl * 8 + w]
for byte in range(8):
for bit in range(8):
bit_id = np.uint64(byte * 8 + bit)
if ((np.right_shift(_w, bit_id)) & np.uint64(0x1)):
d.append((i, cl, w, byte, bit))
print(f"ITR {i}\tCL {cl}\t Word {w}\t Byte {byte}\t Bit {bit}")
# Get the buffer from the underlying C++ API
buffer = np.frombuffer(platform.get_buffer_memoryview()[:8192], dtype=np.uint64)
ITR_COUNT=10
ACT_COUNT = 100000
pattern = 0xFFFFFFFF
for i in range(ITR_COUNT):
initialize_row(platform, 0xFFFFFFFF, 0, 233)
initialize_row(platform, 0x0, 0, 234)
initialize_row(platform, 0xFFFFFFFF, 0, 235)
hammer_row_double(0, 233, 235, ACT_COUNT, 1, 1)
read_row(platform, 0, 234)
platform.receiveData(8*1024)
check_flips(buffer, 0x0)
|