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 << " srl_barrier_t barrier2 = SRL_GET_BARRIER(barrier2);" << endl; |
---|
92 | res << endl; |
---|
93 | res << " // Initialisation du tableau" << endl; |
---|
94 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
95 | res << " tab[i] = 0;" << endl; |
---|
96 | res << " }" << endl; |
---|
97 | res << endl; |
---|
98 | res << " barrier_wait(barrier);" << endl; |
---|
99 | res << endl; |
---|
100 | res << " run0();" << endl; |
---|
101 | res << endl; |
---|
102 | res << " barrier_wait(barrier2);" << endl; |
---|
103 | res << endl; |
---|
104 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
105 | res << " if (tab[i] != 0) {" << endl; |
---|
106 | res << " giet_tty_printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl; |
---|
107 | res << " }" << endl; |
---|
108 | res << " }" << endl; |
---|
109 | res << endl; |
---|
110 | res << " giet_raise_sigint();" << endl; |
---|
111 | res << endl; |
---|
112 | res << " srl_exit();" << endl; |
---|
113 | res << "}" << endl; |
---|
114 | res << endl; |
---|
115 | |
---|
116 | return res.str(); |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | string write_task_no_tty() { |
---|
121 | stringstream res; |
---|
122 | res << "#include \"srl.h\"" << endl; |
---|
123 | res << "#include \"stdio.h\"" << endl; |
---|
124 | res << "#include \"test_llsc_no_tty_proto.h\"" << endl; |
---|
125 | res << "#include \"functions.h\"" << endl; |
---|
126 | res << endl; |
---|
127 | res << "/*" << endl; |
---|
128 | res << " * Test generated for a dsx_vm compilation" << endl; |
---|
129 | res << " * NB_LOCKS : " << nb_locks << endl; |
---|
130 | res << " * NB_VARS : " << nb_vars << endl; |
---|
131 | if (lock_in_line) { |
---|
132 | res << " * LOCKS PLACEMENT : horizontal" << endl; |
---|
133 | } |
---|
134 | else { |
---|
135 | res << " * LOCKS PLACEMENT : vertical" << endl; |
---|
136 | } |
---|
137 | if (vars_in_line) { |
---|
138 | res << " * VARS PLACEMENT : horizontal" << endl; |
---|
139 | } |
---|
140 | else { |
---|
141 | res << " * VARS PLACEMENT : vertical" << endl; |
---|
142 | } |
---|
143 | res << " * NB_MAX_INCRS : " << nb_max_incr << endl; |
---|
144 | res << " * LINE_SIZE : " << LINE_SIZE << endl; |
---|
145 | res << " */" << endl; |
---|
146 | res << endl; |
---|
147 | res << "int * tab;" << endl; |
---|
148 | res << endl; |
---|
149 | |
---|
150 | for (int i = 1; i < nb_threads; i++) { |
---|
151 | res << threads[i]->write_task(); |
---|
152 | } |
---|
153 | |
---|
154 | res << endl; |
---|
155 | res << endl; |
---|
156 | res << "FUNC(test_llsc_no_tty_func) {" << endl; |
---|
157 | res << endl; |
---|
158 | res << " srl_memspace_t memspace = SRL_GET_MEMSPACE(table);" << endl; |
---|
159 | res << " tab = (int *) SRL_MEMSPACE_ADDR(memspace);" << endl; |
---|
160 | res << " srl_barrier_t barrier = SRL_GET_BARRIER(barrier);" << endl; |
---|
161 | res << " srl_barrier_t barrier2 = SRL_GET_BARRIER(barrier2);" << endl; |
---|
162 | res << " int thread_id = SRL_GET_CONST(id);" << endl; |
---|
163 | res << endl; |
---|
164 | res << " barrier_wait(barrier);" << endl; |
---|
165 | res << endl; |
---|
166 | res << " if (thread_id == 1) {" << endl; |
---|
167 | res << " run1();" << endl; |
---|
168 | res << " }" << endl; |
---|
169 | for (int i = 2; i < nb_threads; i++) { |
---|
170 | res << " else if (thread_id == " << i << ") {" << endl; |
---|
171 | res << " run" << i << "();" << endl; |
---|
172 | res << " }" << endl; |
---|
173 | } |
---|
174 | res << " else {" << endl; |
---|
175 | res << " srl_assert(0);" << endl; |
---|
176 | res << " }" << endl; |
---|
177 | res << endl; |
---|
178 | res << " barrier_wait(barrier2);" << endl; |
---|
179 | res << endl; |
---|
180 | res << " srl_exit();" << endl; |
---|
181 | res << endl; |
---|
182 | res << "}" << endl; |
---|
183 | res << endl; |
---|
184 | |
---|
185 | return res.str(); |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | string write_output() { |
---|
190 | cout << tab_size; |
---|
191 | stringstream res; |
---|
192 | res << endl; |
---|
193 | res << "#include <stdio.h>" << endl; |
---|
194 | res << "#include <assert.h>" << endl; |
---|
195 | res << endl; |
---|
196 | res << "/*" << endl; |
---|
197 | res << " * Test generated for a posix execution" << endl; |
---|
198 | res << " * NB_LOCKS : " << nb_locks << endl; |
---|
199 | res << " * NB_VARS : " << nb_vars << endl; |
---|
200 | if (lock_in_line) { |
---|
201 | res << " * LOCKS PLACEMENT : horizontal" << endl; |
---|
202 | } |
---|
203 | else { |
---|
204 | res << " * LOCKS PLACEMENT : vertical" << endl; |
---|
205 | } |
---|
206 | if (vars_in_line) { |
---|
207 | res << " * VARS PLACEMENT : horizontal" << endl; |
---|
208 | } |
---|
209 | else { |
---|
210 | res << " * VARS PLACEMENT : vertical" << endl; |
---|
211 | } |
---|
212 | res << " * NB_MAX_INCRS : " << nb_max_incr << endl; |
---|
213 | res << " * LINE_SIZE : " << LINE_SIZE << endl; |
---|
214 | res << " */" << endl; |
---|
215 | res << endl; |
---|
216 | res << "volatile int tab[" << tab_size << "];" << endl; |
---|
217 | res << endl; |
---|
218 | res << endl; |
---|
219 | |
---|
220 | |
---|
221 | for (int i = 0; i < nb_threads; i++) { |
---|
222 | res << threads[i]->write_output(); |
---|
223 | } |
---|
224 | |
---|
225 | res << "int main() {" << endl; |
---|
226 | res << endl; |
---|
227 | res << " int i;" << endl; |
---|
228 | res << endl; |
---|
229 | res << " /* Version native séquentielle */" << endl; |
---|
230 | res << endl; |
---|
231 | res << " // Initialisation du tableau" << endl; |
---|
232 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
233 | res << " tab[i] = 0;" << endl; |
---|
234 | res << " }" << endl; |
---|
235 | res << endl; |
---|
236 | res << " run0();" << endl; |
---|
237 | for (int i = 1; i < nb_threads; i++){ |
---|
238 | res << " run" << i << "();" << endl; |
---|
239 | } |
---|
240 | res << endl; |
---|
241 | res << " for (i = 0; i < " << tab_size << "; i++) {" << endl; |
---|
242 | res << " if (tab[i] != 0) {" << endl; |
---|
243 | res << " printf(\"tab[%d] final : %d\\n\", i, tab[i]);" << endl; |
---|
244 | res << " }" << endl; |
---|
245 | res << " }" << endl; |
---|
246 | res << endl; |
---|
247 | res << " return 0;" << endl; |
---|
248 | res << "}" << endl; |
---|
249 | res << endl; |
---|
250 | |
---|
251 | return res.str(); |
---|
252 | } |
---|
253 | |
---|
254 | }; |
---|
255 | |
---|
256 | #endif |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | |
---|