-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_ddr3.py
More file actions
executable file
·166 lines (129 loc) · 5.6 KB
/
example_ddr3.py
File metadata and controls
executable file
·166 lines (129 loc) · 5.6 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
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
165
166
#!/usr/bin/env python3
"""
DRAMBench DDR3 Example
Demonstrates:
- Loading DDR3 memory standard
- Exploring command sequences (timed and untimed)
- Visualizing Petri net state machine
"""
from drampyml.standards.ddr3 import create_standard
from drampyml.memspecs.ddr3 import DDR3_1600
from drampyml.algorithms.transitions import explore_next_transitions
from drampyml.algorithms.state import current_state, restore_state
def main():
print("=" * 80)
print("DRAMBench DDR3 Example")
print("=" * 80)
# ========================================================================
# 1. Load DDR3-1600 Standard
# ========================================================================
print("\n[1] Loading DDR3-1600 standard...")
standard = create_standard(DDR3_1600)
petri_net = standard.petri_net
print(f" Loaded: {len(petri_net.graph.nodes())} nodes, {len(petri_net.graph.edges())} edges")
print(f" Config: {DDR3_1600['nbrOfRanks']} rank(s), {DDR3_1600['nbrOfBanks']} bank(s)")
# ========================================================================
# 2. Check Available Commands
# ========================================================================
print("\n" + "=" * 80)
print("[2] Available Commands")
print("=" * 80)
fireable = petri_net.who_can_fire()
print(f"\n {len(fireable)} commands can fire:\n")
for idx in fireable:
cmd = petri_net.graph[idx]
coord_str = f"Rank{cmd.coordinate.rank}"
if cmd.coordinate.bank is not None:
coord_str += f" Bank{cmd.coordinate.bank}"
print(f" - {cmd.command:6s} @ {coord_str}")
# ========================================================================
# 3. Explore Untimed Command Sequences
# ========================================================================
print("\n" + "=" * 80)
print("[3] Untimed Command Sequences")
print("=" * 80)
print("\n Note: Ignores timing constraints, shows structural possibilities\n")
initial = current_state(petri_net)
petri_net.ignore_timing_constraints = True
untimed_paths = explore_next_transitions(petri_net, k_max=3, include_timings=False)
print(f" Found {len(untimed_paths)} sequences (k=3)\n")
petri_net.ignore_timing_constraints = False
restore_state(petri_net, initial)
# ========================================================================
# 4. Explore Timed Command Sequences (FIXED!)
# ========================================================================
print("\n" + "=" * 80)
print("[4] Timed Command Sequences (Fixed)")
print("=" * 80)
print("\n Note: Uses explore_next_transitions() with time advancement\n")
timed_paths = explore_next_transitions(petri_net, k_max=3, include_timings=True)
print(f" Found {len(timed_paths)} sequences (k=3)\n")
restore_state(petri_net, initial)
# ========================================================================
# 5. Visualize Petri Net
# ========================================================================
print("\n" + "=" * 80)
print("[5] Petri Net Visualization")
print("=" * 80)
restore_state(petri_net, initial)
petri_net.write_img("ddr3_initial.svg", image_type='svg')
print("\n Initial State:")
print(f" - Time: {petri_net.current_time}")
print(f" - Fireable: {len(petri_net.who_can_fire())} transitions")
print(" - Saved: ddr3_initial.svg")
# ========================================================================
# 6. Execute Commands
# ========================================================================
print("\n" + "=" * 80)
print("[6] Command Execution Example")
print("=" * 80)
restore_state(petri_net, initial)
act_transitions = [idx for idx in petri_net.who_can_fire()
if petri_net.graph[idx].command.name == 'ACT'
and petri_net.graph[idx].coordinate.bank == 0]
if act_transitions:
print("\n Firing: ACT to Bank 0")
petri_net.ignore_timing_constraints = True
petri_net.fire_transition(act_transitions[0])
petri_net.write_img("ddr3_after_act.svg", image_type='svg')
print(f" After ACT (untimed mode):")
print(f" - Fireable: {len(petri_net.who_can_fire())} transitions")
print(" - Saved: ddr3_after_act.svg")
fireable_after = petri_net.who_can_fire()
if fireable_after:
print("\n Now available:")
for idx in list(fireable_after)[:12]:
cmd = petri_net.graph[idx]
coord_str = f"R{cmd.coordinate.rank}"
if cmd.coordinate.bank is not None:
coord_str += f"B{cmd.coordinate.bank}"
print(f" - {cmd.command:6s} @ {coord_str}")
petri_net.ignore_timing_constraints = False
# ========================================================================
# Summary
# ========================================================================
print("\n" + "=" * 80)
print("Summary")
print("=" * 80)
print(f"""
Results:
- Untimed sequences: {len(untimed_paths)}
- Timed sequences: {len(timed_paths)}
- SVG files: ddr3_initial.svg, ddr3_after_act.svg
DDR3 Commands:
ACT - Activate row
RD - Read
WR - Write
PRE - Precharge
REF - Refresh
Timing Parameters (DDR3-1600):
tRCD = 10 (ACT to RD/WR delay)
tRAS = 28 (Min row active time)
tRP = 10 (Row precharge time)
tRC = 38 (Row cycle time)
""")
print("=" * 80)
print("Complete")
print("=" * 80)
if __name__ == "__main__":
main()