source: trunk/softs/soft_transpose_giet/main.c @ 244

Last change on this file since 244 was 244, checked in by meunier, 12 years ago

soft_transpose update to match platform changes

File size: 12.3 KB
Line 
1
2#include "stdio.h"
3#include "limits.h"
4#include "../giet_tsar/block_device.h"
5
6#define NL              512
7#define NP              512
8#define NB_IMAGES       1
9#define NB_CLUSTER_MAX  256
10
11#define PRINTF(...)      ({ if (local_id == 0) { tty_printf(__VA_ARGS__); } })
12
13///////////////////////////////////////////
14// tricks to read parameters from ldscript
15///////////////////////////////////////////
16
17struct plaf;
18
19extern struct plouf seg_ioc_base;
20extern struct plaf seg_heap_base;
21extern struct plaf NB_PROCS;
22extern struct plaf NB_CLUSTERS;
23
24/////////////
25void main(){
26   unsigned int frame = 0;
27   unsigned int date  = 0;
28
29   unsigned int c; // cluster index for loops
30   unsigned int l; // line index for loops
31   unsigned int p; // pixel index for loops
32
33   unsigned int proc_id       = procid();                      // processor id
34   unsigned int nlocal_procs  = (unsigned int) &NB_PROCS;      // number of processors per cluster
35   unsigned int nclusters     = (unsigned int) &NB_CLUSTERS;   // number of clusters
36   unsigned int local_id      = proc_id % nlocal_procs;        // local processor id
37   unsigned int cluster_id    = proc_id / nlocal_procs;        // cluster id
38   unsigned int base          = (unsigned int) &seg_heap_base; // base address for shared buffers
39   unsigned int increment     = 0x80000000 / nclusters * 2;    // cluster increment
40   unsigned int nglobal_procs = nclusters * nlocal_procs;      // number of tasks
41   unsigned int npixels       = NP * NL;                       // number of pixel per frame
42   
43   unsigned int * ioc_address = (unsigned int *) &seg_ioc_base;
44   unsigned int block_size    = ioc_address[BLOCK_DEVICE_BLOCK_SIZE];
45   unsigned int nblocks       = npixels / block_size;   // number of blocks per frame
46
47   PRINTF("\n *** Entering main at cycle %d ***\n\n", proctime());
48
49   //  parameters checking
50   if ((nlocal_procs != 1) && (nlocal_procs != 2) && (nlocal_procs != 4)){
51      PRINTF("NB_PROCS must be 1, 2 or 4\n");
52      exit(1);
53   }
54   if ((nclusters != 1) && (nclusters != 2) && (nclusters != 4) && (nclusters != 8) &&
55         (nclusters != 16) && (nclusters != 32) && (nclusters != 64) && (nclusters != 128) &&
56         (nclusters != 256)){
57      PRINTF("NB_CLUSTERS must be a power of 1 between 1 and 256\n");
58      exit(1);
59   }
60   if (nglobal_procs > 1024){
61      PRINTF("NB_PROCS * NB_CLUSTERS cannot be larger than 1024\n");
62      exit(1);
63   }
64   if (proc_id >= nglobal_procs){
65      PRINTF("processor id %d larger than NB_CLUSTERS*NB_PROCS\n", proc_id);
66      exit(1);
67   }
68
69   // Arrays of pointers on the shared, distributed buffers containing the frames
70   // These arrays are indexed by the cluster index (sized for the worst case : 256 clusters)
71   unsigned char * A[NB_CLUSTER_MAX];
72   unsigned char * B[NB_CLUSTER_MAX];
73
74   // Arrays of pointers on the instrumentation arrays
75   // These arrays are indexed by the cluster index (sized for the worst case : 256 clusters)
76   // each pointer points on the base adress of an array of NPROCS unsigned int
77   unsigned int * LOAD_START[NB_CLUSTER_MAX];
78   unsigned int * LOAD_END[NB_CLUSTER_MAX];
79   unsigned int * TRSP_START[NB_CLUSTER_MAX];
80   unsigned int * TRSP_END[NB_CLUSTER_MAX];
81   unsigned int * DISP_START[NB_CLUSTER_MAX];
82   unsigned int * DISP_END[NB_CLUSTER_MAX];
83
84   // shared buffers address definition
85   // from the seg_heap_base and increment depending on the cluster index
86   // These arrays of pointers are identical and replicated in the stack of each task
87   for (c = 0; c < nclusters; c++){
88      A[c]          = (unsigned char *) (base                                  + increment * c);
89      B[c]          = (unsigned char *) (base +     npixels                    + increment * c);
90      LOAD_START[c] = (unsigned int *)  (base + 2 * npixels                    + increment * c);
91      LOAD_END[c]   = (unsigned int *)  (base + 2 * npixels +     nlocal_procs + increment * c);
92      TRSP_START[c] = (unsigned int *)  (base + 2 * npixels + 2 * nlocal_procs + increment * c);
93      TRSP_END[c]   = (unsigned int *)  (base + 2 * npixels + 3 * nlocal_procs + increment * c);
94      DISP_START[c] = (unsigned int *)  (base + 2 * npixels + 4 * nlocal_procs + increment * c);
95      DISP_END[c]   = (unsigned int *)  (base + 2 * npixels + 5 * nlocal_procs + increment * c);
96   }
97
98   PRINTF("NB_CLUSTERS     = %d\n", nclusters); 
99   PRINTF("NB_LOCAL_PROCS  = %d\n", nlocal_procs); 
100   PRINTF("NB_GLOBAL_PROCS = %d\n", nglobal_procs);
101   PRINTF("NB_PIXELS       = %d\n", npixels);
102   PRINTF("BLOCK_SIZE      = %d\n", block_size);
103   PRINTF("NB_BLOCKS       = %d\n\n", nblocks);
104
105
106   PRINTF("*** starting barrier init at cycle %d ***\n", proctime());
107
108   //  barriers initialization
109   barrier_init(0, nglobal_procs);
110   barrier_init(1, nglobal_procs);
111   barrier_init(2, nglobal_procs);
112
113   PRINTF("*** completing barrier init at cycle %d ***\n", proctime());
114
115   // Main loop (on frames)
116   while (frame < NB_IMAGES){
117      // pseudo parallel load from disk to A[c] buffer : nblocks/nclusters blocks
118      // only task running on processor with (local_id == 0) does it
119
120      if (local_id == 0){
121         int p;
122
123         date = proctime();
124         PRINTF("\n*** Starting load for frame %d at cycle %d\n", frame, date);
125         
126         for (p = 0; p < nlocal_procs; p++){
127            LOAD_START[cluster_id][p] = date;
128         }
129         tty_printf("    block_device offset : %d\n", nblocks * cluster_id / nclusters);
130         if (ioc_read(frame * nblocks + nblocks * cluster_id / nclusters, A[cluster_id], nblocks / nclusters)){
131            tty_printf("echec ioc_read\n");
132            exit();
133         }
134         if (ioc_completed()){
135            tty_printf("echec ioc_completed\n");
136            exit();
137         }
138
139         date = proctime();
140         PRINTF("*** Completing load for frame %d at cycle %d\n", frame, date);
141         for (p = 0; p < nlocal_procs; p++){
142            LOAD_END[cluster_id][p] = date;
143         }
144      }
145
146      barrier_wait(0);
147
148      // parallel transpose from A to B buffers
149      // each processor makes the transposition for (NL/nglobal_procs) lines
150      // (p,l) are the (x,y) pixel coordinates in the source frame
151
152      date = proctime();
153      PRINTF("\n*** Starting transpose for frame %d at cycle %d\n", frame, date);
154      TRSP_START[cluster_id][local_id] = date;
155
156      unsigned int nlt   = NL / nglobal_procs; // Nombre de ligne à traiter par processeur
157      unsigned int first = proc_id * nlt;      // Index de la premiÚre ligne à traiter pour le proc courant (celui qui exécute le code)
158      unsigned int last  = first + nlt;        // Index de la derniÚre ligne
159      unsigned int nlines_clusters = NL / nclusters; // Nombre de lignes à traiter par cluster
160      unsigned int npix_clusters   = NP / nclusters; // Nombre de pixels par ligne à traiter par cluster
161
162      for (l = first; l < last; l++){
163         PRINTF("    - processing line %d\n", l);
164         for (p = 0; p < NP; p++){
165            unsigned int source_index   = (l % nlines_clusters) * NP + p;
166            unsigned int dest_cluster   = p / npix_clusters;
167            unsigned int dest_index     = (p % npix_clusters) * NL + l;
168            B[dest_cluster][dest_index] = A[cluster_id][source_index];
169         }
170      }
171
172      date = proctime();
173      PRINTF("*** Completing transpose for frame %d at cycle %d\n", frame, date);
174      TRSP_END[cluster_id][local_id] = date;
175
176      barrier_wait(1);
177
178      // parallel display from B[c] to frame buffer
179      // each processor uses its private dma to display NL*NP/nglobal_procs pixels
180
181      date = proctime();
182      PRINTF("\n*** Starting display for frame %d at cycle %d\n", frame, date);
183      DISP_START[cluster_id][local_id] = date;
184
185      unsigned int npxt = npixels / nglobal_procs;   // number of pixels per proc
186      if (npixels - npxt * nglobal_procs != 0){
187         tty_printf("*** Error line %d\n", __LINE__);
188         exit();
189      }
190      tty_printf("    npxt : %d\n", npxt);
191
192      if (fb_write(npxt * proc_id, B[cluster_id] + npxt * local_id, npxt)){
193         tty_printf("[%d]: echec fb_sync_write\n", proc_id);
194         exit();
195      }
196     
197      PRINTF("    After fb_write and before fb_completed\n");
198
199      if (fb_completed()){
200         tty_printf("[%d]: echec fb_completed\n", proc_id);
201         exit();
202      }
203
204      date = proctime();
205      PRINTF("*** Completing display for frame %d at cycle %d\n", frame, date);
206      DISP_END[cluster_id][local_id] = date;
207
208      barrier_wait(2);
209
210      // Instrumentation (done by processor 0 in cluster 0)
211      if (local_id == 0){ 
212         date = proctime();
213         PRINTF("\n*** Starting Instrumentation for frame %d at cycle %d\n\n", frame, date);
214
215         int cc, pp;
216         unsigned int min_load_start = INT_MAX;
217         unsigned int max_load_start = 0;
218         unsigned int min_load_ended = INT_MAX;
219         unsigned int max_load_ended = 0;
220         unsigned int min_trsp_start = INT_MAX;
221         unsigned int max_trsp_start = 0;
222         unsigned int min_trsp_ended = INT_MAX;
223         unsigned int max_trsp_ended = 0;
224         unsigned int min_disp_start = INT_MAX;
225         unsigned int max_disp_start = 0;
226         unsigned int min_disp_ended = INT_MAX;
227         unsigned int max_disp_ended = 0;
228
229         for (cc = 0; cc < nclusters; cc++){
230            for (pp = 0; pp < nlocal_procs; pp++){
231               if (LOAD_START[cc][pp] < min_load_start){
232                  min_load_start = LOAD_START[cc][pp];
233               }
234               if (LOAD_START[cc][pp] > max_load_start){
235                  max_load_start = LOAD_START[cc][pp];
236               }
237               if (LOAD_END[cc][pp] < min_load_ended){
238                  min_load_ended = LOAD_END[cc][pp];
239               }
240               if (LOAD_END[cc][pp] > max_load_ended){
241                  max_load_ended = LOAD_END[cc][pp];
242               }
243
244               if (TRSP_START[cc][pp] < min_trsp_start){
245                  min_trsp_start = TRSP_START[cc][pp];
246               }
247               if (TRSP_START[cc][pp] > max_trsp_start){
248                  max_trsp_start = TRSP_START[cc][pp];
249               }
250               if (TRSP_END[cc][pp] < min_trsp_ended){
251                  min_trsp_ended = TRSP_END[cc][pp];
252               }
253               if (TRSP_END[cc][pp] > max_trsp_ended){
254                  max_trsp_ended = TRSP_END[cc][pp];
255               }
256
257               if (DISP_START[cc][pp] < min_disp_start){
258                  min_disp_start = DISP_START[cc][pp];
259               }
260               if (DISP_START[cc][pp] > max_disp_start){
261                  max_disp_start = DISP_START[cc][pp];
262               }
263               if (DISP_END[cc][pp] < min_disp_ended){
264                  min_disp_ended = DISP_END[cc][pp];
265               }
266               if (DISP_END[cc][pp] > max_disp_ended){
267                  max_disp_ended = DISP_END[cc][pp];
268               }
269            }
270         }
271
272         PRINTF(" - LOAD_START : min = %d / max = %d / med = %d / delta = %d\n",
273               min_load_start, max_load_start, (min_load_start+max_load_start)/2, max_load_start-min_load_start); 
274         PRINTF(" - LOAD_END   : min = %d / max = %d / med = %d / delta = %d\n",
275               min_load_ended, max_load_ended, (min_load_ended+max_load_ended)/2, max_load_ended-min_load_ended); 
276
277         PRINTF(" - TRSP_START : min = %d / max = %d / med = %d / delta = %d\n",
278               min_trsp_start, max_trsp_start, (min_trsp_start+max_trsp_start)/2, max_trsp_start-min_trsp_start); 
279         PRINTF(" - TRSP_END   : min = %d / max = %d / med = %d / delta = %d\n",
280               min_trsp_ended, max_trsp_ended, (min_trsp_ended+max_trsp_ended)/2, max_trsp_ended-min_trsp_ended); 
281
282         PRINTF(" - DISP_START : min = %d / max = %d / med = %d / delta = %d\n",
283               min_disp_start, max_disp_start, (min_disp_start+max_disp_start)/2, max_disp_start-min_disp_start); 
284         PRINTF(" - DISP_END   : min = %d / max = %d / med = %d / delta = %d\n",
285               min_disp_ended, max_disp_ended, (min_disp_ended+max_disp_ended)/2, max_disp_ended-min_disp_ended); 
286
287         PRINTF(" - BARRIER TRSP/DISP = %d\n", min_disp_start - max_trsp_ended);
288      }
289      frame++;
290
291   } // end while frame     
292
293   PRINTF("*** End of main ***\n");
294
295   while(1);
296} // end main()
297
298// Local Variables:
299// tab-width: 3
300// c-basic-offset: 3
301// c-file-offsets:((innamespace . 0)(inline-open . 0))
302// indent-tabs-mode: nil
303// End:
304
305// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
306
307
308
Note: See TracBrowser for help on using the repository browser.