-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathDelayFault.cl
386 lines (339 loc) · 15.6 KB
/
PathDelayFault.cl
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
__kernel void
logicsimulationv1(ulong length, __global uint *top_order,
__global uint *reverse_top_order, __global uint *gate_type,
__global uint2 *edges, __global uint2 *out_edges,
__global uint *p1, __global uint *p2,
__global uint *robust_result1, __global uint *robust_result2,
__global uint *is_robust_or_non_robust_result1,
__global uint *is_robust_or_non_robust_result2,
__global uint *is_robust_path_to_po,
__global uint *belongs_to_robust_path_final_result1,
__global uint *belongs_to_robust_path_final_result2) {
const unsigned int output_offset = length * get_global_id(0);
// const ulong size = length;
unsigned int result1 = 0;
unsigned int result2 = 0;
unsigned int pattern1_1;
unsigned int pattern1_2;
unsigned int pattern2_1;
unsigned int pattern2_2;
unsigned int isRobust_1;
unsigned int isRobust_2;
unsigned int isRobustOrNonRobust_l;
unsigned int isRobustOrNonRobust_2;
for (int i = 0; i < SIZE; i++) {
const unsigned int c_node = i;
result1 = 0;
result2 = 0;
const unsigned int g = gate_type[c_node];
if (g) // All other gates, if node is an input the else is executed, the
// gate type can also be used to determine the in_degree
{
const uint2 e = edges[c_node];
pattern1_1 = p1[output_offset + e.x];
pattern1_2 = p1[output_offset + e.y];
pattern2_1 = p2[output_offset + e.x];
pattern2_2 = p2[output_offset + e.y];
if (g == 1) {
result1 = ~(pattern1_1 & pattern1_2);
result2 = ~(pattern2_1 & pattern2_2);
} else if (g == 2) {
result1 = ~(pattern1_1 | pattern1_2);
result2 = ~(pattern2_1 | pattern2_2);
} else if (g == 4) {
result1 = pattern1_1 & pattern1_2;
result2 = pattern2_1 & pattern2_2;
} else if (g == 5) {
result1 = pattern1_1 | pattern1_2;
result2 = pattern2_1 | pattern2_2;
} else if (g == 6) {
result1 = ~pattern1_1;
result2 = ~pattern2_1;
}
if (g == 1 || g == 4) // AND NAND case
{
// isRobustAND NAND
isRobust_1 = ((~pattern1_1) & pattern1_2 & pattern2_2) |
(pattern1_1 & (~pattern1_2) & pattern2_1 & pattern2_2);
isRobust_2 = ((~pattern2_1) & pattern2_2 & pattern1_2) |
(pattern2_1 & (~pattern2_2) & pattern1_1 & pattern1_2);
isRobustOrNonRobust_l = (pattern1_1 ^ pattern1_2) & pattern2_2;
isRobustOrNonRobust_2 = (pattern2_1 ^ pattern2_2) & pattern1_2;
} else if (g == 5 || g == 2) // Or Nor
{
isRobust_1 =
(pattern1_1 & (~pattern1_2) & (~pattern2_2)) |
((~pattern1_1) & pattern1_2 & (~pattern2_1) & (~pattern2_2));
isRobust_2 =
(pattern2_1 & (~pattern2_2) & (~pattern1_2)) |
((~pattern2_1) & pattern2_2 & (~pattern1_1) & (~pattern1_2));
isRobustOrNonRobust_l = (pattern1_1 ^ pattern1_2) & (~pattern2_2);
isRobustOrNonRobust_2 = (pattern2_1 ^ pattern2_2) & (~pattern1_2);
} else if (g == 6) {
isRobust_1 = pattern1_1 ^ pattern2_1;
isRobust_2 = pattern1_1 ^ pattern2_1;
isRobustOrNonRobust_l = pattern1_1 ^ pattern2_1;
isRobustOrNonRobust_2 = pattern1_1 ^ pattern2_1;
}
p1[output_offset + c_node] = result1;
p2[output_offset + c_node] = result2;
robust_result1[output_offset + c_node] = isRobust_1;
robust_result2[output_offset + c_node] = isRobust_2;
is_robust_or_non_robust_result1[output_offset + c_node] =
isRobustOrNonRobust_l;
is_robust_or_non_robust_result2[output_offset + c_node] =
isRobustOrNonRobust_2;
}
}
/* traverse over the graph in reverse topological order */
//#pragma unroll 32
for (int i = SIZE - 1; i >= 0; i--) {
const unsigned int c_node = i;
const uint2 e = out_edges[c_node];
if ((e.x != 0) && (e.y != 0)) // Node is not an output
// if (out_edges[c_node])
{
unsigned int result = 0;
unsigned int r1 = 0;
unsigned int path_po = 0;
r1 = (edges[out_edges[c_node].x].x == c_node)
? robust_result1[output_offset + out_edges[c_node].x]
: robust_result2[output_offset + out_edges[c_node].x];
path_po = is_robust_path_to_po[output_offset + out_edges[c_node].x];
result |= (r1 & path_po);
r1 = (edges[out_edges[c_node].y].x == c_node)
? robust_result1[output_offset + out_edges[c_node].y]
: robust_result2[output_offset + out_edges[c_node].y];
path_po = is_robust_path_to_po[output_offset + out_edges[c_node].y];
result |= (r1 & path_po);
is_robust_path_to_po[output_offset + c_node] = result;
} else {
is_robust_path_to_po[output_offset + c_node] =
~0; // set the bits of all outputs to 1
} // Node is an output because no out edges
// case of output set all bits to "1"
}
/* Last Interation over the circuit in topological order*/
//#pragma unroll 32
for (int i = 0; i < SIZE; i++) {
const unsigned int c_node = i;
const unsigned int g = gate_type[c_node];
if (g) {
/* Check all input edges */
unsigned int temp_final_result = 0;
unsigned int btrofr = 0;
btrofr = (out_edges[edges[c_node].x].x == c_node)
? belongs_to_robust_path_final_result1[output_offset +
edges[c_node].x]
: belongs_to_robust_path_final_result2[output_offset +
edges[c_node].x];
temp_final_result |=
is_robust_path_to_po[output_offset + edges[c_node].x] &
robust_result1[output_offset + c_node] & btrofr;
btrofr = (out_edges[edges[c_node].y].x == c_node)
? belongs_to_robust_path_final_result1[output_offset +
edges[c_node].y]
: belongs_to_robust_path_final_result2[output_offset +
edges[c_node].y];
temp_final_result |=
is_robust_path_to_po[output_offset + edges[c_node].y] &
robust_result2[output_offset + c_node] & btrofr;
/* Check all output edges */
if ((out_edges[c_node].x != 0) && (out_edges[c_node].y != 0)) {
result1 = 0;
result2 = 0;
unsigned int t = 0;
t = (edges[out_edges[c_node].x].x == c_node)
? robust_result1[output_offset + out_edges[c_node].x]
: robust_result2[output_offset + out_edges[c_node].x];
result1 = t & temp_final_result &
is_robust_path_to_po[output_offset + out_edges[c_node].x];
t = (edges[out_edges[c_node].y].x == c_node)
? robust_result1[output_offset + out_edges[c_node].y]
: robust_result2[output_offset + out_edges[c_node].y];
result2 = t & temp_final_result &
is_robust_path_to_po[output_offset + out_edges[c_node].y];
belongs_to_robust_path_final_result1[output_offset + c_node] = result1;
belongs_to_robust_path_final_result2[output_offset + c_node] = result2;
} else {
belongs_to_robust_path_final_result1[output_offset + c_node] =
temp_final_result;
belongs_to_robust_path_final_result2[output_offset + c_node] =
temp_final_result;
}
} else {
belongs_to_robust_path_final_result1[output_offset + c_node] =
is_robust_path_to_po[output_offset + c_node];
belongs_to_robust_path_final_result2[output_offset + c_node] =
is_robust_path_to_po[output_offset + c_node];
}
}
}
__kernel void
logicsimulationv2(__global uint *gate_type, __global uint2 *edges,
__global uint2 *out_edges, __global uint *p1,
__global uint *p2, __global uint *robust_result1,
__global uint *robust_result2,
__global uint *is_robust_or_non_robust_result1,
__global uint *is_robust_or_non_robust_result2,
__global uint *is_robust_path_to_po,
__global uint *belongs_to_robust_path_final_result1,
__global uint *belongs_to_robust_path_final_result2) {
const unsigned int output_offset = SIZE * get_global_id(0);
unsigned int result1 = 0;
unsigned int result2 = 0;
unsigned int pattern1_1;
unsigned int pattern1_2;
unsigned int pattern2_1;
unsigned int pattern2_2;
unsigned int isRobust_1;
unsigned int isRobust_2;
unsigned int isRobustOrNonRobust_l;
unsigned int isRobustOrNonRobust_2;
for (int i = 0; i < SIZE; i++) {
const unsigned int c_node = i;
result1 = 0;
result2 = 0;
const unsigned int g = gate_type[c_node];
if (g) // All other gates, if node is an input the else is executed, the
// gate type can also be used to determine the in_degree
{
const uint2 e = edges[c_node];
pattern1_1 = p1[output_offset + e.x];
pattern1_2 = p1[output_offset + e.y];
pattern2_1 = p2[output_offset + e.x];
pattern2_2 = p2[output_offset + e.y];
if (g == 1) {
result1 = ~(pattern1_1 & pattern1_2);
result2 = ~(pattern2_1 & pattern2_2);
} else if (g == 2) {
result1 = ~(pattern1_1 | pattern1_2);
result2 = ~(pattern2_1 | pattern2_2);
} else if (g == 4) {
result1 = pattern1_1 & pattern1_2;
result2 = pattern2_1 & pattern2_2;
} else if (g == 5) {
result1 = pattern1_1 | pattern1_2;
result2 = pattern2_1 | pattern2_2;
} else if (g == 6) {
result1 = ~pattern1_1;
result2 = ~pattern2_1;
}
if (g == 1 || g == 4) // AND NAND case
{
// isRobustAND NAND
isRobust_1 = ((~pattern1_1) & pattern1_2 & pattern2_2) |
(pattern1_1 & (~pattern1_2) & pattern2_1 & pattern2_2);
isRobust_2 = ((~pattern2_1) & pattern2_2 & pattern1_2) |
(pattern2_1 & (~pattern2_2) & pattern1_1 & pattern1_2);
isRobustOrNonRobust_l = (pattern1_1 ^ pattern1_2) & pattern2_2;
isRobustOrNonRobust_2 = (pattern2_1 ^ pattern2_2) & pattern1_2;
} else if (g == 5 || g == 2) // Or Nor
{
isRobust_1 =
(pattern1_1 & (~pattern1_2) & (~pattern2_2)) |
((~pattern1_1) & pattern1_2 & (~pattern2_1) & (~pattern2_2));
isRobust_2 =
(pattern2_1 & (~pattern2_2) & (~pattern1_2)) |
((~pattern2_1) & pattern2_2 & (~pattern1_1) & (~pattern1_2));
isRobustOrNonRobust_l = (pattern1_1 ^ pattern1_2) & (~pattern2_2);
isRobustOrNonRobust_2 = (pattern2_1 ^ pattern2_2) & (~pattern1_2);
} else if (g == 6) {
isRobust_1 = pattern1_1 ^ pattern2_1;
isRobust_2 = pattern1_1 ^ pattern2_1;
isRobustOrNonRobust_l = pattern1_1 ^ pattern2_1;
isRobustOrNonRobust_2 = pattern1_1 ^ pattern2_1;
}
const uint o = output_offset + c_node;
p1[o] = result1;
p2[o] = result2;
robust_result1[o] = isRobust_1;
robust_result2[o] = isRobust_2;
is_robust_or_non_robust_result1[o] = isRobustOrNonRobust_l;
is_robust_or_non_robust_result2[o] = isRobustOrNonRobust_2;
}
}
/* traverse over the graph in reverse topological order */
//#pragma unroll 32
for (int i = SIZE - 1; i >= 0; i--) {
const unsigned int c_node = i;
const uint2 e = out_edges[c_node];
if ((e.x != 0) && (e.y != 0)) // Node is not an output
// if (out_edges[c_node])
{
unsigned int result = 0;
unsigned int r1 = 0;
unsigned int path_po = 0;
r1 = (edges[out_edges[c_node].x].x == c_node)
? robust_result1[output_offset + out_edges[c_node].x]
: robust_result2[output_offset + out_edges[c_node].x];
path_po = is_robust_path_to_po[output_offset + out_edges[c_node].x];
result |= (r1 & path_po);
r1 = (edges[out_edges[c_node].y].x == c_node)
? robust_result1[output_offset + out_edges[c_node].y]
: robust_result2[output_offset + out_edges[c_node].y];
path_po = is_robust_path_to_po[output_offset + out_edges[c_node].y];
result |= (r1 & path_po);
is_robust_path_to_po[output_offset + c_node] = result;
} else {
is_robust_path_to_po[output_offset + c_node] =
~0; // set the bits of all outputs to 1
} // Node is an output because no out edges
// case of output set all bits to "1"
}
/* Last Interation over the circuit in topological order*/
//#pragma unroll 32
for (int i = 0; i < SIZE; i++) {
const unsigned int c_node = i;
const unsigned int g = gate_type[c_node];
if (g) {
/* Check all input edges */
unsigned int temp_final_result = 0;
unsigned int btrofr = 0;
btrofr = (out_edges[edges[c_node].x].x == c_node)
? belongs_to_robust_path_final_result1[output_offset +
edges[c_node].x]
: belongs_to_robust_path_final_result2[output_offset +
edges[c_node].x];
temp_final_result |=
is_robust_path_to_po[output_offset + edges[c_node].x] &
robust_result1[output_offset + c_node] & btrofr;
btrofr = (out_edges[edges[c_node].y].x == c_node)
? belongs_to_robust_path_final_result1[output_offset +
edges[c_node].y]
: belongs_to_robust_path_final_result2[output_offset +
edges[c_node].y];
temp_final_result |=
is_robust_path_to_po[output_offset + edges[c_node].y] &
robust_result2[output_offset + c_node] & btrofr;
/* Check all output edges */
if ((out_edges[c_node].x != 0) && (out_edges[c_node].y != 0)) {
result1 = 0;
result2 = 0;
unsigned int t = 0;
t = (edges[out_edges[c_node].x].x == c_node)
? robust_result1[output_offset + out_edges[c_node].x]
: robust_result2[output_offset + out_edges[c_node].x];
result1 = t & temp_final_result &
is_robust_path_to_po[output_offset + out_edges[c_node].x];
t = (edges[out_edges[c_node].y].x == c_node)
? robust_result1[output_offset + out_edges[c_node].y]
: robust_result2[output_offset + out_edges[c_node].y];
result2 = t & temp_final_result &
is_robust_path_to_po[output_offset + out_edges[c_node].y];
belongs_to_robust_path_final_result1[output_offset + c_node] = result1;
belongs_to_robust_path_final_result2[output_offset + c_node] = result2;
} else {
belongs_to_robust_path_final_result1[output_offset + c_node] =
temp_final_result;
belongs_to_robust_path_final_result2[output_offset + c_node] =
temp_final_result;
}
} else {
belongs_to_robust_path_final_result1[output_offset + c_node] =
is_robust_path_to_po[output_offset + c_node];
belongs_to_robust_path_final_result2[output_offset + c_node] =
is_robust_path_to_po[output_offset + c_node];
}
}
}