[244] | 1 | |
---|
[158] | 2 | #include "stdio.h" |
---|
[244] | 3 | #include "limits.h" |
---|
| 4 | #include "../giet_tsar/block_device.h" |
---|
[158] | 5 | |
---|
[244] | 6 | #define NL 512 |
---|
| 7 | #define NP 512 |
---|
| 8 | #define NB_IMAGES 1 |
---|
| 9 | #define NB_CLUSTER_MAX 256 |
---|
[158] | 10 | |
---|
[244] | 11 | #define PRINTF(...) ({ if (local_id == 0) { tty_printf(__VA_ARGS__); } }) |
---|
[158] | 12 | |
---|
| 13 | /////////////////////////////////////////// |
---|
| 14 | // tricks to read parameters from ldscript |
---|
| 15 | /////////////////////////////////////////// |
---|
| 16 | |
---|
| 17 | struct plaf; |
---|
| 18 | |
---|
[244] | 19 | extern struct plouf seg_ioc_base; |
---|
[158] | 20 | extern struct plaf seg_heap_base; |
---|
| 21 | extern struct plaf NB_PROCS; |
---|
| 22 | extern struct plaf NB_CLUSTERS; |
---|
| 23 | |
---|
| 24 | ///////////// |
---|
[244] | 25 | void main(){ |
---|
| 26 | unsigned int frame = 0; |
---|
| 27 | unsigned int date = 0; |
---|
[158] | 28 | |
---|
[244] | 29 | unsigned int c; // cluster index for loops |
---|
| 30 | unsigned int l; // line index for loops |
---|
| 31 | unsigned int p; // pixel index for loops |
---|
[158] | 32 | |
---|
[244] | 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 |
---|
[158] | 46 | |
---|
[244] | 47 | PRINTF("\n *** Entering main at cycle %d ***\n\n", proctime()); |
---|
[158] | 48 | |
---|
[244] | 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 | } |
---|
[158] | 68 | |
---|
[244] | 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]; |
---|
[158] | 73 | |
---|
[244] | 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]; |
---|
[158] | 83 | |
---|
[244] | 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 | } |
---|
[158] | 97 | |
---|
[244] | 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); |
---|
[158] | 104 | |
---|
| 105 | |
---|
[244] | 106 | PRINTF("*** starting barrier init at cycle %d ***\n", proctime()); |
---|
[158] | 107 | |
---|
[244] | 108 | // barriers initialization |
---|
| 109 | barrier_init(0, nglobal_procs); |
---|
| 110 | barrier_init(1, nglobal_procs); |
---|
| 111 | barrier_init(2, nglobal_procs); |
---|
[158] | 112 | |
---|
[244] | 113 | PRINTF("*** completing barrier init at cycle %d ***\n", proctime()); |
---|
[171] | 114 | |
---|
[244] | 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 |
---|
[171] | 119 | |
---|
[244] | 120 | if (local_id == 0){ |
---|
| 121 | int p; |
---|
[158] | 122 | |
---|
[244] | 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 | } |
---|
[158] | 138 | |
---|
[244] | 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 | } |
---|
[158] | 145 | |
---|
[244] | 146 | barrier_wait(0); |
---|
[158] | 147 | |
---|
[244] | 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 |
---|
[158] | 151 | |
---|
[244] | 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; |
---|
[158] | 155 | |
---|
[244] | 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 |
---|
[158] | 161 | |
---|
[244] | 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 | } |
---|
[158] | 171 | |
---|
[244] | 172 | date = proctime(); |
---|
| 173 | PRINTF("*** Completing transpose for frame %d at cycle %d\n", frame, date); |
---|
| 174 | TRSP_END[cluster_id][local_id] = date; |
---|
[158] | 175 | |
---|
[244] | 176 | barrier_wait(1); |
---|
[158] | 177 | |
---|
[244] | 178 | // parallel display from B[c] to frame buffer |
---|
| 179 | // each processor uses its private dma to display NL*NP/nglobal_procs pixels |
---|
[158] | 180 | |
---|
[244] | 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; |
---|
[158] | 184 | |
---|
[244] | 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); |
---|
[158] | 191 | |
---|
[244] | 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"); |
---|
[158] | 198 | |
---|
[244] | 199 | if (fb_completed()){ |
---|
| 200 | tty_printf("[%d]: echec fb_completed\n", proc_id); |
---|
| 201 | exit(); |
---|
| 202 | } |
---|
[158] | 203 | |
---|
[244] | 204 | date = proctime(); |
---|
| 205 | PRINTF("*** Completing display for frame %d at cycle %d\n", frame, date); |
---|
| 206 | DISP_END[cluster_id][local_id] = date; |
---|
[171] | 207 | |
---|
[244] | 208 | barrier_wait(2); |
---|
[171] | 209 | |
---|
[244] | 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); |
---|
[171] | 214 | |
---|
[244] | 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; |
---|
[171] | 228 | |
---|
[244] | 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 | } |
---|
[171] | 243 | |
---|
[244] | 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 | } |
---|
[171] | 269 | } |
---|
[244] | 270 | } |
---|
[171] | 271 | |
---|
[244] | 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); |
---|
[171] | 276 | |
---|
[244] | 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); |
---|
[171] | 281 | |
---|
[244] | 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); |
---|
[171] | 286 | |
---|
[244] | 287 | PRINTF(" - BARRIER TRSP/DISP = %d\n", min_disp_start - max_trsp_ended); |
---|
| 288 | } |
---|
| 289 | frame++; |
---|
[171] | 290 | |
---|
[244] | 291 | } // end while frame |
---|
| 292 | |
---|
| 293 | PRINTF("*** End of main ***\n"); |
---|
| 294 | |
---|
| 295 | while(1); |
---|
[158] | 296 | } // end main() |
---|
| 297 | |
---|
[244] | 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 | |
---|