-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinalKernek.cl
233 lines (208 loc) · 9.09 KB
/
FinalKernek.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
__kernel void
logicsimulation(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;
#pragma unroll 16
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
{
pattern1_1 = p1[output_offset + edges[c_node].x];
pattern1_2 = p1[output_offset + edges[c_node].y];
pattern2_1 = p2[output_offset + edges[c_node].x];
pattern2_2 = p2[output_offset + edges[c_node].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;
}
// else
// {
// p1[output_offset + c_node] =
// boost::dynamic_bitset<>(generate4bit()).to_ulong(); p2[output_offset +
// c_node] = boost::dynamic_bitset<>(generate4bit()).to_ulong();
// }
}
/* traverse over the graph in reverse topological order */
#pragma unroll 16
for (int i = size - 1; i >= 0; i--) {
const unsigned int c_node = i;
if ((out_edges[c_node].x != 0) &&
(out_edges[c_node].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;
/*if (edges[out_edges[c_node].x].x == c_node)
{
r1 = robust_result1[output_offset + out_edges[c_node].x];
path_po = is_robust_path_to_po[output_offset +
out_edges[c_node].x];
}
else
{
r1 = robust_result2[output_offset + out_edges[c_node].x];
path_po = is_robust_path_to_po[output_offset +
out_edges[c_node].x];
}*/
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);
/*if (edges[out_edges[c_node].y].x == c_node)
{
r1 = robust_result1[output_offset + out_edges[c_node].y];
path_po = is_robust_path_to_po[output_offset +
out_edges[c_node].y];
}
else
{
r1 = robust_result2[output_offset + out_edges[c_node].y];
path_po = is_robust_path_to_po[output_offset +
out_edges[c_node].y];
}*/
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 16
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;
/* robust_result[output_offset + c_node].x; */
if (out_edges[edges[c_node].x].x == c_node)
btrofr = belongs_to_robust_path_final_result1[output_offset +
edges[c_node].x];
else
btrofr = 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;
/* robust_result[output_offset + c_node].y; */
if (out_edges[edges[c_node].y].x == c_node)
btrofr = belongs_to_robust_path_final_result1[output_offset +
edges[c_node].y];
else
btrofr = 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;
/*out_edges[c_node].x; */
if (edges[out_edges[c_node].x].x == c_node)
t = robust_result1[output_offset + out_edges[c_node].x];
else
t = 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];
if (edges[out_edges[c_node].y].x == c_node)
t = robust_result1[output_offset + out_edges[c_node].y];
else
t = 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];
}
}
}