1 | |
---|
2 | #ifndef _program_hpp_ |
---|
3 | #define _program_hpp_ |
---|
4 | |
---|
5 | #include <iostream> |
---|
6 | #include <sstream> |
---|
7 | #include <stdbool.h> |
---|
8 | |
---|
9 | #include "config.h" |
---|
10 | #include "TestThread.hpp" |
---|
11 | |
---|
12 | |
---|
13 | using namespace std; |
---|
14 | |
---|
15 | class Program { |
---|
16 | |
---|
17 | int nb_threads; |
---|
18 | int nb_max_incr; |
---|
19 | int nb_locks; |
---|
20 | int nb_vars; |
---|
21 | int line_size; |
---|
22 | bool lock_in_line, vars_in_line; |
---|
23 | int tab_size; |
---|
24 | TestThread ** threads; |
---|
25 | |
---|
26 | public: |
---|
27 | |
---|
28 | Program(int nb_procs, int nb_locks, int nb_max_accesses, int line_size, bool lock_in_line, bool vars_in_line){ |
---|
29 | this->nb_threads = nb_procs; |
---|
30 | this->nb_max_incr = nb_max_accesses; |
---|
31 | this->nb_locks = nb_locks; |
---|
32 | this->nb_vars = nb_locks; |
---|
33 | this->line_size = line_size; |
---|
34 | this->lock_in_line = lock_in_line; |
---|
35 | this->vars_in_line = vars_in_line; |
---|
36 | this->tab_size = (lock_in_line ? ceil((float) nb_locks / line_size) * line_size : nb_locks * line_size) + (vars_in_line ? ceil((float) nb_vars / line_size) * line_size : nb_vars * line_size); |
---|
37 | this->threads = new TestThread * [nb_threads]; |
---|
38 | |
---|
39 | for (int i = 0; i < nb_threads; i++){ |
---|
40 | threads[i] = new TestThread(nb_locks, nb_max_accesses, line_size, lock_in_line, vars_in_line, i); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | ~Program(){ |
---|
45 | for (int i = 0; i < nb_threads; i++){ |
---|
46 | delete threads[i]; |
---|
47 | } |
---|
48 | delete [] threads; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | string write_main_task() { |
---|
53 | stringstream res; |
---|
54 | res << "#include \"srl.h\"" << endl; |
---|
55 | res << "#include \"stdio.h\"" << endl; |
---|
56 | res << "#include \"test_llsc_main_proto.h\"" << endl; |
---|
57 | res << "#include \"functions.h\"" << endl; |
---|
58 | res << endl; |
---|
59 | res << "/*" << endl; |
---|
60 | res << " * Test generated for a dsx_vm compilation" << endl; |
---|
61 | res << " * NB_LOCKS : " << nb_locks << endl; |
---|
62 | res << " * NB_VARS : " << nb_vars << endl; |
---|
63 | if (lock_in_line) { |
---|
64 | res << " * LOCKS PLACEMENT : horizontal" << endl; |
---|
65 | } |
---|
66 | else { |
---|
67 | res << " * LOCKS PLACEMENT : vertical" << endl; |
---|
68 | } |
---|
69 | if (vars_in_line) { |
---|
70 | res << " * VARS PLACEMENT : horizontal" << endl; |
---|
71 | } |
---|
72 | else { |
---|
73 | res << " * VARS PLACEMENT : vertical" << endl; |
---|
74 | } |
---|
75 | res << " * NB_MAX_INCRS : " << nb_max_incr << endl; |
---|
76 | res << " * LINE_SIZE : " << LINE_SIZE << endl; |
---|
77 | res << " */" << endl; |
---|
78 | res << endl; |
---|
79 | res << "int * tab;" << endl; |
---|
80 | res << endl; |
---|
81 | res << threads[0]->write_task(); |
---|
82 | res << endl; |
---|
83 | res << endl; |
---|
84 | res << "FUNC(test_llsc_main_func) {" << endl; |
---|
85 | res << endl; |
---|
86 | res << " int i;" << endl; |
---|
87 | res << endl; |
---|
88 | res << " srl_memspace_t memspace = SRL_GET_MEMSPACE(table);" << endl; |
---|
89 | res << " tab = (int *) SRL_MEMSPACE_ADDR(memspace);" << endl; |
---|
90 | res << " srl_barrier_t barrier = SRL_GET_BARRIER(barrier);" << endl; |
---|
91 | res << endl; |
---|
92 | res << " // Initialisation du tableau" << endl; |
---|
93 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
94 | res << " tab[i] = 0;" << endl; |
---|
95 | res << " }" << endl; |
---|
96 | res << endl; |
---|
97 | res << " barrier_wait(barrier);" << endl; |
---|
98 | res << endl; |
---|
99 | res << " run0();" << endl; |
---|
100 | res << endl; |
---|
101 | res << " barrier_wait(barrier);" << endl; |
---|
102 | res << endl; |
---|
103 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
104 | res << " if (tab[i] != 0) {" << endl; |
---|
105 | res << " giet_tty_printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl; |
---|
106 | res << " }" << endl; |
---|
107 | res << " }" << endl; |
---|
108 | res << endl; |
---|
109 | res << " *(unsigned int *) 0x0 = 0xDEADDEAD;" << endl; |
---|
110 | res << endl; |
---|
111 | res << " srl_exit();" << endl; |
---|
112 | res << "}" << endl; |
---|
113 | res << endl; |
---|
114 | |
---|
115 | return res.str(); |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | string write_task_no_tty() { |
---|
120 | stringstream res; |
---|
121 | res << "#include \"srl.h\"" << endl; |
---|
122 | res << "#include \"stdio.h\"" << endl; |
---|
123 | res << "#include \"test_llsc_no_tty_proto.h\"" << endl; |
---|
124 | res << "#include \"functions.h\"" << endl; |
---|
125 | res << endl; |
---|
126 | res << "/*" << endl; |
---|
127 | res << " * Test generated for a dsx_vm compilation" << endl; |
---|
128 | res << " * NB_LOCKS : " << nb_locks << endl; |
---|
129 | res << " * NB_VARS : " << nb_vars << endl; |
---|
130 | if (lock_in_line) { |
---|
131 | res << " * LOCKS PLACEMENT : horizontal" << endl; |
---|
132 | } |
---|
133 | else { |
---|
134 | res << " * LOCKS PLACEMENT : vertical" << endl; |
---|
135 | } |
---|
136 | if (vars_in_line) { |
---|
137 | res << " * VARS PLACEMENT : horizontal" << endl; |
---|
138 | } |
---|
139 | else { |
---|
140 | res << " * VARS PLACEMENT : vertical" << endl; |
---|
141 | } |
---|
142 | res << " * NB_MAX_INCRS : " << nb_max_incr << endl; |
---|
143 | res << " * LINE_SIZE : " << LINE_SIZE << endl; |
---|
144 | res << " */" << endl; |
---|
145 | res << endl; |
---|
146 | res << "int * tab;" << endl; |
---|
147 | res << endl; |
---|
148 | |
---|
149 | for (int i = 1; i < nb_threads; i++) { |
---|
150 | res << threads[i]->write_task(); |
---|
151 | } |
---|
152 | |
---|
153 | res << endl; |
---|
154 | res << endl; |
---|
155 | res << "FUNC(test_llsc_no_tty_func) {" << endl; |
---|
156 | res << endl; |
---|
157 | res << " srl_memspace_t memspace = SRL_GET_MEMSPACE(table);" << endl; |
---|
158 | res << " tab = (int *) SRL_MEMSPACE_ADDR(memspace);" << endl; |
---|
159 | res << " srl_barrier_t barrier = SRL_GET_BARRIER(barrier);" << endl; |
---|
160 | res << " int thread_id = SRL_GET_CONST(id);" << endl; |
---|
161 | res << endl; |
---|
162 | res << " barrier_wait(barrier);" << endl; |
---|
163 | res << endl; |
---|
164 | res << " if (thread_id == 1) {" << endl; |
---|
165 | res << " run1();" << endl; |
---|
166 | res << " }" << endl; |
---|
167 | for (int i = 2; i < nb_threads; i++) { |
---|
168 | res << " else if (thread_id == " << i << ") {" << endl; |
---|
169 | res << " run" << i << "();" << endl; |
---|
170 | res << " }" << endl; |
---|
171 | } |
---|
172 | res << " else {" << endl; |
---|
173 | res << " srl_assert(0);" << endl; |
---|
174 | res << " }" << endl; |
---|
175 | res << endl; |
---|
176 | res << " barrier_wait(barrier);" << endl; |
---|
177 | res << endl; |
---|
178 | res << " srl_exit();" << endl; |
---|
179 | res << endl; |
---|
180 | res << "}" << endl; |
---|
181 | res << endl; |
---|
182 | |
---|
183 | return res.str(); |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | string write_output() { |
---|
188 | cout << tab_size; |
---|
189 | stringstream res; |
---|
190 | res << endl; |
---|
191 | res << "#include <stdio.h>" << endl; |
---|
192 | res << "#include <assert.h>" << endl; |
---|
193 | res << endl; |
---|
194 | res << "/*" << endl; |
---|
195 | res << " * Test generated for a posix execution" << endl; |
---|
196 | res << " * NB_LOCKS : " << nb_locks << endl; |
---|
197 | res << " * NB_VARS : " << nb_vars << endl; |
---|
198 | if (lock_in_line) { |
---|
199 | res << " * LOCKS PLACEMENT : horizontal" << endl; |
---|
200 | } |
---|
201 | else { |
---|
202 | res << " * LOCKS PLACEMENT : vertical" << endl; |
---|
203 | } |
---|
204 | if (vars_in_line) { |
---|
205 | res << " * VARS PLACEMENT : horizontal" << endl; |
---|
206 | } |
---|
207 | else { |
---|
208 | res << " * VARS PLACEMENT : vertical" << endl; |
---|
209 | } |
---|
210 | res << " * NB_MAX_INCRS : " << nb_max_incr << endl; |
---|
211 | res << " * LINE_SIZE : " << LINE_SIZE << endl; |
---|
212 | res << " */" << endl; |
---|
213 | res << endl; |
---|
214 | res << "volatile int tab[" << tab_size << "];" << endl; |
---|
215 | res << endl; |
---|
216 | res << endl; |
---|
217 | |
---|
218 | |
---|
219 | for (int i = 0; i < nb_threads; i++) { |
---|
220 | res << threads[i]->write_output(); |
---|
221 | } |
---|
222 | |
---|
223 | res << "int main() {" << endl; |
---|
224 | res << endl; |
---|
225 | res << " int i;" << endl; |
---|
226 | res << endl; |
---|
227 | res << " /* Version native séquentielle */" << endl; |
---|
228 | res << endl; |
---|
229 | res << " // Initialisation du tableau" << endl; |
---|
230 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
231 | res << " tab[i] = 0;" << endl; |
---|
232 | res << " }" << endl; |
---|
233 | res << endl; |
---|
234 | res << " run0();" << endl; |
---|
235 | for (int i = 1; i < nb_threads; i++){ |
---|
236 | res << " run" << i << "();" << endl; |
---|
237 | } |
---|
238 | res << endl; |
---|
239 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
240 | res << " if (tab[i] != 0) {" << endl; |
---|
241 | res << " printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl; |
---|
242 | res << " }" << endl; |
---|
243 | res << " }" << endl; |
---|
244 | res << endl; |
---|
245 | res << " return 0;" << endl; |
---|
246 | res << "}" << endl; |
---|
247 | res << endl; |
---|
248 | |
---|
249 | return res.str(); |
---|
250 | } |
---|
251 | |
---|
252 | }; |
---|
253 | |
---|
254 | #endif |
---|
255 | |
---|
256 | |
---|
257 | |
---|
258 | |
---|
259 | |
---|