1 /* $Id: ApplicationGenerator.java 1 2010-02-24 13:03:05Z haidw $ */
\r
4 import java.io.BufferedWriter;
\r
6 import java.io.FileWriter;
\r
7 import java.util.Random;
\r
8 import java.util.Vector;
\r
9 import java.util.regex.Matcher;
\r
10 import java.util.regex.Pattern;
\r
12 import dol.datamodel.architecture.Processor;
\r
13 import dol.datamodel.architecture.ReadPath;
\r
14 import dol.datamodel.architecture.WritePath;
\r
15 import dol.datamodel.mapping.CommunicationBinding;
\r
16 import dol.datamodel.mapping.ComputationBinding;
\r
17 import dol.datamodel.mapping.Mapping;
\r
18 import dol.datamodel.mapping.Schedule;
\r
19 import dol.datamodel.mapping.ScheduleEntry;
\r
20 import dol.datamodel.mapping.SchedulingPolicy;
\r
21 import dol.datamodel.pn.Channel;
\r
22 import dol.datamodel.pn.Connection;
\r
23 import dol.datamodel.pn.Port;
\r
24 import dol.datamodel.pn.Process;
\r
25 import dol.datamodel.pn.ProcessNetwork;
\r
26 import dol.datamodel.pn.ProfilingConfiguration;
\r
27 import dol.datamodel.pn.SourceCode;
\r
28 import dol.visitor.xml.MapXmlVisitor;
\r
29 import dol.visitor.xml.PNXmlVisitor;
\r
34 public class ApplicationGenerator {
\r
36 protected String _processes[] =
\r
37 {"producer", "consumer"};
\r
39 protected int _computation[] =
\r
42 protected int _communication[][] =
\r
45 protected String _binding[] =
\r
46 {"tile_0.arm", "tile_0.arm"};
\r
48 protected int _iterations = 1000;
\r
52 protected String _processes[] =
\r
53 {"producer", "forwarder", "consumer"};
\r
55 protected int _computation[] =
\r
58 protected int _communication[][] =
\r
63 protected String _binding[] =
\r
64 {"tile_0.arm", "tile_0.arm", "tile_0.arm"};
\r
66 protected int _iterations = 10;
\r
70 protected String _processes[] =
\r
71 {"stageA", "stageB", "stageC", "stageD",
\r
72 "stageE", "stageF", "stageG", "stageH",
\r
73 "stageI", "stageJ", "stageK", "stageL",
\r
74 "stageM", "stageN", "stageO", "stageP"};
\r
76 protected int _computation[] =
\r
77 {1, 2, 3, 4, 5, 6, 7, 8,
\r
78 9, 10, 11, 12, 13, 14, 15, 16};
\r
80 protected int _communication[][] =
\r
81 {{ 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
82 {-1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
83 { 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
84 { 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
85 { 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
86 { 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
87 { 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0},
\r
88 { 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0, 0},
\r
89 { 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0, 0},
\r
90 { 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0, 0},
\r
91 { 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0, 0},
\r
92 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0, 0},
\r
93 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0, 0},
\r
94 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024, 0},
\r
95 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0, 1024},
\r
96 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1024, 0}};
\r
99 //protected String _binding[] =
\r
100 // {"tile_0.arm", "tile_0.arm", "tile_1.arm", "tile_1.arm",
\r
101 // "tile_2.arm", "tile_2.arm", "tile_3.arm", "tile_3.arm",
\r
102 // "tile_4.arm", "tile_4.arm", "tile_5.arm", "tile_5.arm",
\r
103 // "tile_6.arm", "tile_6.arm", "tile_7.arm", "tile_7.arm"};
\r
105 //protected String _binding[] =
\r
106 // {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",
\r
107 // "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",
\r
108 // "tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",
\r
109 // "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm"};
\r
111 protected String _binding[] =
\r
112 {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",
\r
113 "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",
\r
114 "tile_7.arm", "tile_6.arm", "tile_5.arm", "tile_4.arm",
\r
115 "tile_3.arm", "tile_2.arm", "tile_1.arm", "tile_0.arm"};
\r
117 protected int _iterations = 10;
\r
120 protected String _processes[] =
\r
121 {"splitAA", "splitBA", "splitBB",
\r
122 "pipeAA", "pipeBA", "pipeCA", "pipeDA",
\r
123 "pipeEA", "pipeFA", "pipeAB", "pipeBB",
\r
124 "pipeCB", "pipeDB", "pipeEB", "pipeFB",
\r
125 "mergeBA", "mergeBB", "mergeAA"};
\r
127 protected int _armComputation[] =
\r
128 {1, 2, 3, 4, 5, 6, 7, 8,
\r
129 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
\r
130 protected int _magicComputation[] =
\r
131 {1, 2, 3, 4, 5, 6, 7, 8,
\r
132 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
\r
135 protected int _communication[][] =
\r
136 {{ 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
137 { -4, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
138 { -4, 0, 0, 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0},
\r
139 { 0, -4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0},
\r
140 { 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0},
\r
141 { 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0},
\r
142 { 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0},
\r
143 { 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0},
\r
144 { 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0},
\r
145 { 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
\r
146 { 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
\r
147 { 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
\r
148 { 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0},
\r
149 { 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0},
\r
150 { 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 4, 0},
\r
151 { 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, -4, -4, 0, 0, 0, 0, 0, 4},
\r
152 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, -4, -4, 0, 0, 4},
\r
153 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, -4, 0}};
\r
157 protected String _binding[] =
\r
158 {"tile_0.arm", "tile_1.arm", "tile_4.arm",
\r
159 "tile_1.arm", "tile_2.arm", "tile_3.arm", "tile_4.arm",
\r
160 "tile_5.arm", "tile_6.arm", "tile_1.arm", "tile_2.arm",
\r
161 "tile_3.arm", "tile_4.arm", "tile_5.arm", "tile_6.arm",
\r
162 "tile_3.arm", "tile_7.arm", "tile_0.arm"};
\r
165 protected String _binding[] =
\r
166 {"tile_0.arm", "tile_1.arm", "tile_3.arm",
\r
167 "tile_1.arm", "tile_1.arm", "tile_2.arm", "tile_2.arm",
\r
168 "tile_3.arm", "tile_3.arm", "tile_4.arm", "tile_4.arm",
\r
169 "tile_5.arm", "tile_5.arm", "tile_6.arm", "tile_6.arm",
\r
170 "tile_7.arm", "tile_7.arm", "tile_0.arm"};
\r
172 protected String _binding[] =
\r
173 {"tile_0.arm", "tile_1.arm", "tile_7.arm",
\r
174 "tile_1.arm", "tile_1.arm", "tile_2.arm", "tile_2.arm",
\r
175 "tile_3.arm", "tile_3.arm", "tile_4.arm", "tile_4.arm",
\r
176 "tile_5.arm", "tile_5.arm", "tile_6.arm", "tile_6.arm",
\r
177 "tile_7.arm", "tile_3.arm", "tile_0.arm"};
\r
182 protected String _binding[] =
\r
183 {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",
\r
184 "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",
\r
185 "tile_7.arm", "tile_6.arm", "tile_5.arm", "tile_4.arm",
\r
186 "tile_3.arm", "tile_2.arm", "tile_1.arm", "tile_0.arm",
\r
187 "tile_0.arm", "tile_0.arm"};
\r
190 protected int _iterations = 10;
\r
192 public String getStringEncoding(int i, int total) {
\r
193 if (total > 26 * 26) {
\r
194 System.out.println("\"total\" needs to be less than "
\r
197 } else if (total <= 26) {
\r
198 return Character.toString((char)('A' + (i % 26)));
\r
200 return Character.toString((char)('A' + (i / 26)))
\r
201 + Character.toString((char)('A' + (i % 26)));
\r
207 * @param communication
\r
209 public void generateIndependentTasks(int numberOfTasks) {
\r
210 _processes = new String[numberOfTasks];
\r
211 _armComputation = new int[numberOfTasks];
\r
212 _magicComputation = new int[numberOfTasks];
\r
213 _communication = new int[numberOfTasks][numberOfTasks];
\r
214 _binding = new String[numberOfTasks];
\r
215 _iterations = 1000;
\r
217 for (int i = 0; i < numberOfTasks; i++) {
\r
218 _processes[i] = ((i < numberOfTasks / 2) ? "armProcess"
\r
220 + getStringEncoding(i, numberOfTasks);
\r
221 System.out.println(_processes[i]);
\r
222 _armComputation[i] =
\r
223 (i < numberOfTasks / 2) ? 100000000 : 200000000;
\r
224 _magicComputation[i] =
\r
225 (i < numberOfTasks / 2) ? 200000000 : 100000000;
\r
226 _binding[i] = (i < numberOfTasks / 2) ? "tile_0.arm"
\r
231 for (int i = 0; i < numberOfTasks; i++) {
\r
232 for (int j = 0; j < numberOfTasks; j++) {
\r
233 _communication[i][j] = 0;
\r
242 * @param communication
\r
244 public void generateIndpendentPipelines(int pipelines, int stages, int communication) {
\r
245 Random random = new Random();
\r
246 _processes = new String[stages * pipelines];
\r
247 _armComputation = new int[stages * pipelines];
\r
248 _magicComputation = new int[stages * pipelines];
\r
249 _communication = new int[stages * pipelines][stages * pipelines];
\r
250 _binding = new String[stages * pipelines];
\r
251 _iterations = 1000;
\r
253 for (int i = 0; i < pipelines; i++) {
\r
254 for (int j = 0; j < stages; j++) {
\r
255 _processes[i * stages + j] =
\r
256 ((i < pipelines / 2) ? "arm" : "magic")
\r
258 + getStringEncoding(i, pipelines) + "x"
\r
259 + getStringEncoding(j, stages);
\r
260 System.out.println(_processes[i * stages + j]);
\r
261 _armComputation[i * stages + j] =
\r
262 0 * random.nextInt(10000000) +
\r
263 ((i < pipelines / 2) ? 100000000 : 200000000);
\r
264 _magicComputation[i * stages + j] =
\r
265 0 * random.nextInt(10000000) +
\r
266 ((i < pipelines / 2) ? 200000000 : 100000000);
\r
267 _binding[i * stages + j] = "tile_0.arm";
\r
271 for (int i = 0; i < pipelines; i++) {
\r
272 for (int j = 0; j < stages; j++) {
\r
273 for (int k = 0; k < pipelines; k++) {
\r
274 for (int l = 0; l < stages; l++) {
\r
275 _communication[i * stages + j][k * stages + l] = 0;
\r
276 if (i == k && l == j + 1) {
\r
277 _communication[i * stages + j][k * stages + l] = communication;
\r
278 } else if (i == k && j == l + 1) {
\r
279 _communication[i * stages + j][k * stages + l] = -communication;
\r
292 * @param communication
\r
294 public void generateIndpendentPipelines2(int pipelines, int stages, int communication) {
\r
295 Random random = new Random();
\r
296 _processes = new String[stages * pipelines];
\r
297 _armComputation = new int[stages * pipelines];
\r
298 _magicComputation = new int[stages * pipelines];
\r
299 _communication = new int[stages * pipelines][stages * pipelines];
\r
300 _binding = new String[stages * pipelines];
\r
301 _iterations = 1000;
\r
303 for (int i = 0; i < pipelines; i++) {
\r
304 for (int j = 0; j < stages; j++) {
\r
305 _processes[i * stages + j] =
\r
306 ((j < stages / 2) ? "arm" : "magic")
\r
308 + getStringEncoding(i, pipelines) + "x"
\r
309 + getStringEncoding(j, stages);
\r
310 System.out.println(_processes[i * stages + j]);
\r
311 _armComputation[i * stages + j] =
\r
312 0 * random.nextInt(10000000) +
\r
313 ((j < stages / 2) ? 100000000 : 200000000);
\r
314 _magicComputation[i * stages + j] =
\r
315 0 * random.nextInt(10000000) +
\r
316 ((j < stages / 2) ? 200000000 : 100000000);
\r
317 _binding[i * stages + j] = "tile_0.arm";
\r
321 for (int i = 0; i < pipelines; i++) {
\r
322 for (int j = 0; j < stages; j++) {
\r
323 for (int k = 0; k < pipelines; k++) {
\r
324 for (int l = 0; l < stages; l++) {
\r
325 _communication[i * stages + j][k * stages + l] = 0;
\r
326 if (i == k && l == j + 1) {
\r
327 _communication[i * stages + j][k * stages + l] = communication;
\r
328 } else if (i == k && j == l + 1) {
\r
329 _communication[i * stages + j][k * stages + l] = -communication;
\r
341 * @param communication
\r
343 public void generatePipeline(int stages, int communication) {
\r
344 _processes = new String[stages];
\r
345 _armComputation = new int[stages];
\r
346 _magicComputation = new int[stages];
\r
347 _communication = new int[stages][stages];
\r
348 _binding = new String[stages];
\r
349 //_iterations = 1000;
\r
350 _iterations = 1000;
\r
352 for (int i = 0; i < stages; i++) {
\r
353 _processes[i] = ((i % 8 < 4) ? "arm" : "magic")
\r
354 + "stage" + getStringEncoding(i, stages);
\r
355 System.out.println(_processes[i]);
\r
356 _armComputation[i] =
\r
357 (i % 8 < 4) ? 100 : 200;
\r
358 _magicComputation[i] =
\r
359 (i % 8 < 4) ? 200 : 100;
\r
360 _binding[i] = "tile_0.arm";
\r
363 for (int i = 0; i < stages; i++) {
\r
364 for (int j = 0; j < stages; j++) {
\r
365 _communication[i][j] = 0;
\r
367 _communication[i][j] = communication;
\r
368 } else if (i == j + 1) {
\r
369 _communication[i][j] = -communication;
\r
380 public void generateProcessNetwork(ProcessNetwork pn) {
\r
381 System.out.print("Generate process network. ");
\r
382 int numberOfProcesses = 0;
\r
383 int numberOfChannels = 0;
\r
385 for (int j = 0; j < _processes.length; j++) {
\r
386 String processName = _processes[j];
\r
387 Process p = new Process(processName);
\r
388 SourceCode srcCode = new SourceCode(processName);
\r
389 srcCode.setLocality(processName + ".c");
\r
390 srcCode.setType("c");
\r
391 p.getSrcList().add(srcCode);
\r
392 pn.getProcessList().add(p);
\r
393 numberOfProcesses++;
\r
394 for (int i = 0; i < 8; i++) {
\r
395 ProfilingConfiguration c = new ProfilingConfiguration(
\r
396 "BCED tile_" + i + ".arm");
\r
397 c.setValue(Integer.toString(_armComputation[j]));
\r
398 p.getProfilingList().add(c);
\r
399 c = new ProfilingConfiguration(
\r
400 "BCED tile_" + i + ".magic");
\r
401 c.setValue(Integer.toString(_magicComputation[j]));
\r
402 p.getProfilingList().add(c);
\r
406 //check whether communication matrix is symmetric
\r
407 if (_communication[0].length != numberOfProcesses) {
\r
408 System.out.println();
\r
409 System.out.println("Error: Size of communication matrix ("
\r
410 + _communication[0].length + " columns) must match "
\r
411 + "number of processes (" + numberOfProcesses + ").");
\r
414 for (int row = 0; row < numberOfProcesses; row++) {
\r
415 for (int col = 0; col < numberOfProcesses; col++) {
\r
416 if (row == col && _communication[row][col] != 0) {
\r
417 System.out.println();
\r
418 System.out.println("Error: No self-channels allowed. "
\r
419 + "Problem for process " + row + " ("
\r
420 + _processes[row] + ").");
\r
423 if (_communication[row][col] !=
\r
424 -_communication[col][row]) {
\r
425 System.out.println();
\r
426 System.out.println("Error: Communication matrix "
\r
427 + "needs to be symmetric. Mismatch for row "
\r
428 + row + " column " + col + ".");
\r
434 for (int row = 0; row < numberOfProcesses; row++) {
\r
435 for (int col = row; col < numberOfProcesses; col++) {
\r
436 if (_communication[row][col] == 0) {
\r
442 if (_communication[row][col] < 0) {
\r
447 Channel c = new Channel("channel" + _processes[src]
\r
448 + _processes[dst]);
\r
449 c.setSize(Math.abs(2 * _communication[src][dst]));
\r
451 ProfilingConfiguration p = new ProfilingConfiguration(
\r
453 p.setValue(Integer.toString(_communication[row][col]));
\r
454 c.getProfilingList().add(p);
\r
455 pn.getChannelList().add(c);
\r
456 numberOfChannels++;
\r
458 Port channelPort0 = new Port("0", Port.INPORT);
\r
459 Port channelPort1 = new Port("1", Port.OUTPORT);
\r
460 c.getPortList().add(channelPort0);
\r
461 c.getPortList().add(channelPort1);
\r
463 Connection c1 = new Connection(
\r
464 "c1" + _processes[src] + _processes[dst]);
\r
465 Connection c2 = new Connection(
\r
466 "c2" + _processes[src] + _processes[dst]);
\r
467 pn.getConnectionList().add(c1);
\r
468 pn.getConnectionList().add(c2);
\r
470 Port p0 = new Port(Integer.toString(pn.getProcess(
\r
471 _processes[src]).getPortList().size()),
\r
473 Port p1 = new Port(Integer.toString(pn.getProcess(
\r
474 _processes[dst]).getPortList().size()),
\r
476 pn.getProcess(_processes[src]).getPortList().add(p0);
\r
477 pn.getProcess(_processes[dst]).getPortList().add(p1);
\r
479 c1.setOriginPort(p0);
\r
480 c1.setTargetPort(channelPort0);
\r
481 c1.setOrigin(pn.getProcess(_processes[src]));
\r
483 p0.setPeerResource(c);
\r
484 p0.setPeerPort(channelPort0);
\r
485 channelPort0.setPeerResource(pn.getProcess(
\r
487 channelPort0.setPeerPort(p0);
\r
489 c2.setOriginPort(channelPort1);
\r
490 c2.setTargetPort(p1);
\r
492 c2.setTarget(pn.getProcess(_processes[dst]));
\r
493 channelPort1.setPeerResource(pn.getProcess(
\r
495 channelPort1.setPeerPort(p1);
\r
496 p1.setPeerResource(c);
\r
497 p1.setPeerPort(channelPort1);
\r
499 c.setOrigin(pn.getProcess(_processes[src]));
\r
500 c.setTarget(pn.getProcess(_processes[dst]));
\r
504 System.out.println("Finished.");
\r
511 public void generateProcessNetworkXml(ProcessNetwork pn,
\r
513 System.out.print("Generate process network XML. ");
\r
514 StringBuffer buffer = new StringBuffer();
\r
515 pn.accept(new PNXmlVisitor(buffer));
\r
517 java.io.BufferedWriter writer =
\r
518 new java.io.BufferedWriter(
\r
519 new java.io.FileWriter(filename));
\r
520 writer.write(buffer.toString());
\r
522 } catch (java.io.IOException e) {
\r
523 System.out.println();
\r
524 System.out.println("Error: Could not write XML file.");
\r
527 System.out.println("Finished.");
\r
535 public void generateCode(ProcessNetwork pn, String path) {
\r
536 System.out.print("Generate source code of processes. ");
\r
538 String newline = System.getProperty("line.separator");
\r
539 int maxProcessNameLength = 0;
\r
540 for (String processName : _processes) {
\r
541 maxProcessNameLength = Math.max(maxProcessNameLength,
\r
542 processName.length());
\r
545 String global = "";
\r
546 global += "#ifndef GLOBAL_H" + newline;
\r
547 global += "#define GLOBAL_H" + newline;
\r
550 global += "#define ITERATIONS " + _iterations + newline;
\r
553 for (int i = 0; i < _processes.length; i++) {
\r
554 global += "#define LOOPS_ARM_" + _processes[i].toUpperCase()
\r
555 + " " + _armComputation[i] + newline;
\r
556 global += "#define LOOPS_MAGIC_" + _processes[i].toUpperCase()
\r
557 + " " + _magicComputation[i] + newline;
\r
560 for (int row = 0; row < _communication[0].length; row++) {
\r
561 for (int col = row; col < _communication[0].length; col++) {
\r
562 if (_communication[row][col] == 0) {
\r
568 if (_communication[row][col] < 0) {
\r
573 global += "#define TOKEN_SIZE_"
\r
574 + _processes[src].toUpperCase() + "_"
\r
575 + _processes[dst].toUpperCase() + " "
\r
576 + _communication[src][dst] + newline;
\r
580 global += "#endif" + newline;
\r
583 BufferedWriter out = new BufferedWriter(
\r
584 new FileWriter(path + "global.h"));
\r
587 } catch (Exception e) {
\r
588 System.out.println();
\r
589 System.out.println("Error: While writing global.h file.");
\r
594 for (Process p : pn.getProcessList()) {
\r
595 String state = p.getName().substring(0, 1).toUpperCase()
\r
596 + p.getName().substring(1) + "_State";
\r
599 h += "#ifndef " + p.getName().toUpperCase() + "_H" + newline;
\r
600 h += "#define " + p.getName().toUpperCase() + "_H" + newline;
\r
602 h += "#include <dol.h>" + newline;
\r
604 for (Port port : p.getPortList()) {
\r
605 h += "#define PORT_" + p.getName().toUpperCase() + "_"
\r
606 + (port.isInPort() ? "IN_" : "OUT_" )
\r
607 + port.getName() + " " + port.getName() + newline;
\r
610 h += "typedef struct {" + newline;
\r
611 h += " int iterations;" + newline;
\r
612 h += "} " + state + ";" + newline;
\r
614 h += "void " + p.getName() + "_init(DOLProcess *p);"
\r
616 h += "int " + p.getName() + "_fire(DOLProcess *p);" + newline;
\r
618 h += "#endif" + newline;
\r
621 String printPrefix = String.format(" printf(\"[%-"
\r
622 + maxProcessNameLength + "s] ", p.getName());
\r
623 c += "#include <stdio.h>" + newline;
\r
625 c += "#include \"" + p.getName() + ".h\"" + newline;
\r
626 c += "#include \"global.h\"" + newline;
\r
628 c += "void " + p.getName() + "_init(DOLProcess *p) {"
\r
630 c += " " + state + " *state = (" + state + "*)p->local;"
\r
632 c += " state->iterations = 0;" + newline;
\r
633 c += "}" + newline;
\r
635 c += "int " + p.getName() + "_fire(DOLProcess *p) {"
\r
638 int processIndex = getProcessIndex(p.getName());
\r
640 for (int i = 0; i < _communication[processIndex].length; i++) {
\r
641 maxBuffer = Math.max(maxBuffer,
\r
642 Math.abs(_communication[processIndex][i]));
\r
644 c += " int buffer[" + ((maxBuffer + (4 - 1)) / 4) + "];" + newline;
\r
645 c += " int i;" + newline;
\r
646 c += " " + state + " *state = (" + state + "*)p->local;";
\r
647 c += newline + newline;
\r
649 for (Port port : p.getPortList()) {
\r
650 if (port.isInPort()) {
\r
651 int originIndex = getProcessIndex(
\r
652 ((Channel)port.getPeerResource()).getOrigin()
\r
654 String tokenSize = "TOKEN_SIZE_"
\r
655 + _processes[originIndex].toUpperCase() + "_"
\r
656 + _processes[processIndex].toUpperCase();
\r
657 c += printPrefix + "read %d bytes from "
\r
658 + _processes[originIndex] + ".\\n\", " + tokenSize
\r
660 c += " DOL_read((void*)"
\r
661 + "PORT_" + p.getName().toUpperCase() + "_IN_"
\r
662 + port.getName() + ", buffer, " + tokenSize
\r
663 + ", p);" + newline;
\r
667 //c += " printf(\"[%-20s ] iteration %d/n\", \""
\r
668 // + p.getName() + "\", state->iterations);" + newline;
\r
669 c += printPrefix + "iteration %d.\\n\" , "
\r
670 + "state->iterations);" + newline;
\r
672 c += "#ifdef __arm__" + newline;
\r
673 c += " for (i = 0; i < LOOPS_ARM_" + p.getName().toUpperCase()
\r
674 + "; i++) { ; }" + newline;
\r
675 c += "#else" + newline;
\r
676 c += " for (i = 0; i < LOOPS_MAGIC_" + p.getName().toUpperCase()
\r
677 + "; i++) { ; }" + newline;
\r
678 c += "#endif" + newline;
\r
679 for (Port port : p.getPortList()) {
\r
680 if (port.isOutPort()) {
\r
681 int targetIndex = getProcessIndex(
\r
682 ((Channel)port.getPeerResource()).getTarget()
\r
684 String tokenSize = "TOKEN_SIZE_"
\r
685 + _processes[processIndex].toUpperCase() + "_"
\r
686 + _processes[targetIndex].toUpperCase();
\r
687 c += printPrefix + "write %d bytes to "
\r
688 + _processes[targetIndex] + ".\\n\", " + tokenSize
\r
690 c += " DOL_write((void*)"
\r
691 + "PORT_" + p.getName().toUpperCase() + "_OUT_"
\r
692 + port.getName() + ", buffer, "+ tokenSize
\r
693 + ", p);" + newline;
\r
697 c += " state->iterations++;" + newline;
\r
698 c += " if (state->iterations >= ITERATIONS) {"
\r
700 c += " DOL_detach(p);" + newline;
\r
701 c += " return -1;" + newline;
\r
702 c += " }" + newline;
\r
704 c += " return 0;" + newline;
\r
705 c += "}" + newline;
\r
708 BufferedWriter out = new BufferedWriter(
\r
709 new FileWriter(path + p.getName() + ".h"));
\r
712 out = new BufferedWriter(
\r
713 new FileWriter(path + p.getName() + ".c"));
\r
716 } catch (Exception e) {
\r
717 System.out.println();
\r
718 System.out.println("Error: While writing source files.");
\r
722 System.out.println("Finished.");
\r
731 public void generateMapping(ProcessNetwork pn, Mapping map) {
\r
732 System.out.print("Generate mapping. ");
\r
735 //binding of processes
\r
736 Vector<Processor> processors = new Vector<Processor>();
\r
737 for (int i = 0; i < _binding.length; i++) {
\r
738 String processName = _processes[i];
\r
739 String processorName = _binding[i];
\r
740 Processor processor = null;
\r
742 boolean processorExists = false;
\r
743 for (Processor proc : processors) {
\r
744 if (proc.getName().equals(processorName)) {
\r
746 processorExists = true;
\r
751 if (!processorExists) {
\r
752 processor = new Processor(processorName);
\r
753 processors.add(processor);
\r
756 ComputationBinding compBinding = new ComputationBinding(
\r
757 processName + "binding");
\r
758 compBinding.setProcess(pn.getProcess(processName));
\r
759 compBinding.setProcessor(processor);
\r
760 processor.getProcessList().add(pn.getProcess(processName));
\r
761 map.getCompBindList().add(compBinding);
\r
765 for (Processor p : processors) {
\r
766 Schedule s = new Schedule(p.getName() + "schedule");
\r
767 s.setSchedPolicy(SchedulingPolicy.FIFO);
\r
769 for (Process process : p.getProcessList()) {
\r
770 ScheduleEntry entry = new ScheduleEntry(
\r
771 process.getName());
\r
772 entry.setConsumer(process);
\r
773 s.getEntryList().add(entry);
\r
775 map.getScheduleList().add(s);
\r
778 //binding of channels
\r
779 for (Channel c : pn.getChannelList()) {
\r
780 String originProcess = c.getOrigin().getName();
\r
781 String targetProcess = c.getTarget().getName();
\r
783 String originBinding = _binding[getProcessIndex(
\r
785 String targetBinding = _binding[getProcessIndex(
\r
788 Pattern pattern0 = Pattern.compile(
\r
789 "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");
\r
790 Matcher matcher0 = pattern0.matcher(originBinding);
\r
791 Pattern pattern1 = Pattern.compile(
\r
792 "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");
\r
793 Matcher matcher1 = pattern1.matcher(targetBinding);
\r
795 if (!matcher0.matches() || !matcher1.matches()) {
\r
796 System.out.println("binding needs to comply to the"
\r
797 + " following regular expression: "
\r
798 + "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");
\r
802 int srcIndex = Integer.valueOf(matcher0.group(1));
\r
803 int dstIndex = Integer.valueOf(matcher1.group(1));
\r
804 String srcProcessor = matcher0.group(2);
\r
805 String dstProcessor = matcher1.group(2);
\r
807 String writePath = "";
\r
808 String readPath = "";
\r
810 if (srcIndex == dstIndex) {
\r
811 if (srcProcessor.equals("arm")) {
\r
812 writePath = "tile_" + srcIndex + ".rdmtodxm";
\r
814 writePath = "tile_" + srcIndex + ".ddmtodxm";
\r
817 if (srcProcessor.equals("arm")) {
\r
818 writePath = "tile_" + srcIndex + ".rdmtodnp_"
\r
821 writePath = "tile_" + srcIndex + ".ddmtodnp_"
\r
826 if (dstProcessor.equals("arm")) {
\r
827 readPath = "tile_" + dstIndex + ".rdmfromdxm";
\r
829 readPath = "tile_" + dstIndex + ".ddmfromdxm";
\r
832 CommunicationBinding commBinding = new CommunicationBinding(
\r
833 c.getName() + "binding");
\r
834 commBinding.setChannel(c);
\r
835 commBinding.setWritePath(new WritePath(writePath));
\r
836 commBinding.setReadPath(new ReadPath(readPath));
\r
837 map.getCommBindList().add(commBinding);
\r
839 System.out.println("Finished.");
\r
844 * @param processName
\r
847 protected int getProcessIndex(String processName) {
\r
848 for (int i = 0; i < _processes.length; i++) {
\r
849 if (_processes[i].equals(processName)) {
\r
853 System.out.println("Error: Could not find process "
\r
854 + processName + ".");
\r
863 public void generateMappingXml(Mapping map, String filename) {
\r
864 System.out.print("Generate mapping XML. ");
\r
865 StringBuffer buffer = new StringBuffer();
\r
866 map.accept(new MapXmlVisitor(buffer));
\r
868 java.io.BufferedWriter writer =
\r
869 new java.io.BufferedWriter(
\r
870 new java.io.FileWriter(filename));
\r
871 writer.write(buffer.toString());
\r
873 } catch (java.io.IOException e) {
\r
874 System.out.println("Could not write XML file.");
\r
877 System.out.println("Finished.");
\r
884 public static void main(String args[]) {
\r
886 Pattern pattern = Pattern.compile("tile_(\\d)\\.");
\r
887 Matcher matcher = pattern.matcher("tile_3.");
\r
889 System.out.println(matcher.group(1));
\r
892 String appName = "exampleAuto";
\r
893 String path = System.getProperty("user.dir") + "/" + appName + "/";
\r
894 File dir = new File(path);
\r
896 dir = new File(path + "src/");
\r
899 System.out.println("Generate application \"" + appName + "\""
\r
900 + " in directory \"" + path + "\".");
\r
901 ApplicationGenerator appGen = new ApplicationGenerator();
\r
902 //appGen.generateIndpendentPipelines2(16, 4, 10000000);
\r
903 appGen.generatePipeline(64, 10);
\r
904 //appGen.generateIndependentTasks(64);
\r
905 ProcessNetwork pn = new ProcessNetwork(appName);
\r
906 appGen.generateProcessNetwork(pn);
\r
907 appGen.generateProcessNetworkXml(pn, path + appName + ".xml");
\r
908 appGen.generateCode(pn, path + "src/");
\r
909 Mapping map = new Mapping("mapping");
\r
910 appGen.generateMapping(pn, map);
\r
911 appGen.generateMappingXml(map, path + "mapping.xml");
\r
912 System.out.println("Done.");
\r