interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / irqlease_ref.py

153 lines · 5676 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2"""Independent executable reference for lifecycle facts, not a physical-device oracle."""
3import struct
4
5
6def reference(data):
7 bad, *ops = data
8 state = 6 if bad == 1 else 7 if bad == 2 else 1
9 registered = allocated = int(bad != 1)
10 valid = bad != 1
11 live = 1
12 active = waiting = snapshot = work = queued = effects = releases = 0
13 enabled = cancelled = stopped = owner_seq = owner = old = waiter = wait_seq = 0
14 backing = epoch = disabled = stop_request = proof = lock = register_value = 0
15 output = bytearray()
16
17 def emit(result):
18 output.extend(struct.pack('<16Q', result + 128, state, registered, allocated,
19 active, waiting, snapshot, work, queued, live,
20 effects, releases, enabled, cancelled, stopped,
21 owner_seq))
22
23 emit(-5 if bad in (1, 2) else 0)
24 for op in ops:
25 result = -1
26 if op == 0:
27 result = -4
28 if valid and live and state == 1 and not backing:
29 backing = 1
30 result = 0
31 elif op == 1:
32 result = -4
33 if valid and state == 1 and backing:
34 result = -14 if lock else 0
35 if not lock:
36 enabled, state = 1, 2
37 elif op == 2:
38 old, owner = owner, 0
39 result = -4
40 if valid and state == 2 and not lock and not active:
41 owner_seq += 1
42 owner = owner_seq
43 active, result = 1, 0
44 elif op in (3, 19):
45 selected = owner if op == 3 else old
46 result = -4
47 if valid and active == 1 and selected and selected == owner_seq:
48 result = -16 if snapshot else 0
49 if not snapshot:
50 active = 0
51 elif op == 4:
52 waiter, result = 0, -4
53 if valid and state == 2 and not lock and not waiting:
54 wait_seq += 1
55 waiter = wait_seq
56 waiting, result = 1, 0
57 elif op == 5:
58 result = -4
59 if valid and waiting == 1 and waiter and waiter == wait_seq:
60 if state == 2:
61 waiting, result = 0, 0
62 elif cancelled:
63 waiting, result = 0, -125
64 else:
65 result = -16
66 elif op == 6:
67 result = -4
68 if valid and state == 2:
69 result = -14 if lock else 0
70 if not lock:
71 queued += 1
72 elif op == 7:
73 result = -4
74 if valid and state in (1, 2):
75 state, epoch = 3, 1
76 if bad == 3:
77 state, result = 7, -5
78 else:
79 enabled, disabled = 0, 1
80 if bad == 4:
81 state, result = 7, -5
82 else:
83 cancelled = 1
84 if bad == 7 or not backing:
85 state, result = 7, -5 if bad == 7 else -1
86 else:
87 stop_request, result = 1, 0
88 elif op == 8:
89 result = -4
90 if valid and state == 3:
91 result = -16
92 if not (active or waiting or snapshot or enabled) and disabled and cancelled:
93 state, result = 4, 0
94 elif op == 9:
95 result = 0
96 if bad != 5:
97 if work:
98 work -= 1
99 elif queued:
100 queued -= 1
101 work = 1
102 elif stop_request:
103 stopped, proof, result = 1, epoch, 1
104 elif op == 10:
105 result = -4
106 if valid and state == 4:
107 result = -16
108 if stopped and proof == epoch and backing and not (work or queued):
109 state, result = 5, 0
110 elif op == 11:
111 result = -4
112 if valid and live and state == 5 and backing:
113 result = -16
114 if not (active or waiting or snapshot):
115 if not (stopped and proof == epoch and not (work or queued)):
116 state = 7
117 elif bad == 6:
118 state, result = 7, -5
119 else:
120 live = registered = allocated = 0
121 releases += 1
122 state, result = 6, 0
123 elif op == 12:
124 lock, result = 1, 0
125 elif op in (13, 14, 21, 22, 23, 24):
126 result = -4
127 if live and op != 21:
128 if lock:
129 result = -14
130 elif active == 1 and owner and owner == owner_seq and state in (2, 3):
131 if op in (22, 23):
132 result = -1
133 else:
134 effects += 1
135 result = register_value if op == 13 else 0
136 if op == 14:
137 register_value = 64
138 elif op == 15:
139 result = -4
140 if active == 1 and state == 2 and not snapshot:
141 snapshot, result = 1, 0
142 elif op == 16:
143 result = -4
144 if snapshot:
145 snapshot, result = 0, 0
146 elif op == 25:
147 result = -4 if stop_request else 0
148 if not stop_request:
149 work += 1
150 elif op == 20:
151 result = -4
152 emit(result)
153 return bytes(output)