[334] | 1 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : main.c (for convol application) |
---|
| 3 | // Date : june 2014 |
---|
| 4 | // author : Alain Greiner |
---|
| 5 | // |
---|
| 6 | // The "convol" application implements a 2D convolution product. |
---|
| 7 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 8 | |
---|
| 9 | #include "hard_config.h" |
---|
| 10 | #include "stdio.h" |
---|
[353] | 11 | #include "stdlib.h" |
---|
[334] | 12 | #include "barrier.h" |
---|
| 13 | |
---|
[353] | 14 | #define VERBOSE 0 |
---|
| 15 | #define SUPER_VERBOSE 0 |
---|
[334] | 16 | |
---|
[353] | 17 | #define INITIAL_DISPLAY_ENABLE 0 |
---|
[334] | 18 | #define FINAL_DISPLAY_ENABLE 1 |
---|
| 19 | |
---|
[353] | 20 | #define NB_CLUSTERS (X_SIZE * Y_SIZE) |
---|
[334] | 21 | #define PIXEL_SIZE 2 |
---|
| 22 | #define NL 1024 |
---|
| 23 | #define NP 1024 |
---|
| 24 | #define NB_PIXELS (NP * NL) |
---|
| 25 | #define FRAME_SIZE (NB_PIXELS * PIXEL_SIZE) |
---|
| 26 | |
---|
| 27 | #define TA(c,l,p) (A[c][((NP) * (l)) + (p)]) |
---|
| 28 | #define TB(c,p,l) (B[c][((NL) * (p)) + (l)]) |
---|
| 29 | #define TC(c,l,p) (C[c][((NP) * (l)) + (p)]) |
---|
| 30 | #define TD(c,l,p) (D[c][((NP) * (l)) + (p)]) |
---|
| 31 | #define TZ(c,l,p) (Z[c][((NP) * (l)) + (p)]) |
---|
| 32 | |
---|
| 33 | #define max(x,y) ((x) > (y) ? (x) : (y)) |
---|
| 34 | #define min(x,y) ((x) < (y) ? (x) : (y)) |
---|
| 35 | |
---|
| 36 | // instrumentation counters indexed by (cluster_id, lpid] |
---|
[353] | 37 | unsigned int START[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 38 | unsigned int H_BEG[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 39 | unsigned int H_END[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 40 | unsigned int V_BEG[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 41 | unsigned int V_END[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 42 | unsigned int D_BEG[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
| 43 | unsigned int D_END[NB_CLUSTERS][NB_PROCS_MAX]; |
---|
[334] | 44 | |
---|
| 45 | // synchronization barriers |
---|
| 46 | giet_barrier_t barrier_1; |
---|
| 47 | giet_barrier_t barrier_2; |
---|
| 48 | giet_barrier_t barrier_3; |
---|
| 49 | giet_barrier_t barrier_4; |
---|
| 50 | |
---|
| 51 | volatile unsigned int init_ok = 0; |
---|
| 52 | volatile unsigned int exit_ok = 0; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /////////////////////////////////////////// |
---|
| 56 | __attribute__ ((constructor)) void main() |
---|
| 57 | /////////////////////////////////////////// |
---|
| 58 | { |
---|
| 59 | ////////////////////////////////// |
---|
| 60 | // convolution kernel parameters |
---|
| 61 | // The content of this section is |
---|
| 62 | // Philips proprietary information. |
---|
| 63 | /////////////////////////////////// |
---|
| 64 | |
---|
| 65 | int vnorm = 115; |
---|
| 66 | int vf[35] = { 1, 1, 2, 2, 2, |
---|
| 67 | 2, 3, 3, 3, 4, |
---|
| 68 | 4, 4, 4, 5, 5, |
---|
| 69 | 5, 5, 5, 5, 5, |
---|
| 70 | 5, 5, 4, 4, 4, |
---|
| 71 | 4, 3, 3, 3, 2, |
---|
| 72 | 2, 2, 2, 1, 1 }; |
---|
| 73 | |
---|
| 74 | int hrange = 100; |
---|
| 75 | int hnorm = 201; |
---|
| 76 | |
---|
| 77 | unsigned int date = 0; |
---|
| 78 | |
---|
| 79 | int c; // cluster index for loops |
---|
| 80 | int l; // line index for loops |
---|
| 81 | int p; // pixel index for loops |
---|
| 82 | int z; // vertical filter index for loops |
---|
| 83 | |
---|
[353] | 84 | int file = 0; // file descriptor |
---|
[334] | 85 | unsigned int pid = giet_procid(); // processor id |
---|
| 86 | unsigned int nprocs = NB_PROCS_MAX; // procs per cluster |
---|
[353] | 87 | unsigned int nclusters = NB_CLUSTERS; // number of clusters |
---|
[334] | 88 | unsigned int lpid = pid % nprocs; // local task id |
---|
| 89 | unsigned int cluster_xy = pid / nprocs; // cluster index |
---|
| 90 | unsigned int x = cluster_xy >> Y_WIDTH; // x coordinate |
---|
| 91 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); // y coordinate |
---|
| 92 | unsigned int cluster_id = (x * Y_SIZE) + y; // continuous cluster index |
---|
| 93 | unsigned int task_id = (cluster_id * nprocs) + lpid; // continuous task index |
---|
| 94 | unsigned int ntasks = nclusters * nprocs; // number of tasks |
---|
| 95 | unsigned int npixels = NB_PIXELS; // pixels per frame |
---|
| 96 | unsigned int frame_size = FRAME_SIZE; // total size (bytes) |
---|
| 97 | unsigned int nblocks = frame_size / 512; // number of blocks per frame |
---|
| 98 | |
---|
| 99 | unsigned int lines_per_task = NL / ntasks; // lines per task |
---|
| 100 | unsigned int lines_per_cluster = NL / nclusters; // lines per cluster |
---|
| 101 | unsigned int pixels_per_task = NP / ntasks; // columns per task |
---|
| 102 | unsigned int pixels_per_cluster = NP / nclusters; // columns per cluster |
---|
| 103 | |
---|
| 104 | int first, last; |
---|
| 105 | |
---|
| 106 | date = giet_proctime(); |
---|
| 107 | START[cluster_id][lpid] = date; |
---|
| 108 | |
---|
[353] | 109 | #if VERBOSE |
---|
| 110 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts at cycle %d\n", x,y,lpid, date ); |
---|
| 111 | #endif |
---|
| 112 | |
---|
[334] | 113 | // parameters checking |
---|
| 114 | |
---|
| 115 | if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4)) |
---|
| 116 | giet_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2 or 4\n"); |
---|
| 117 | |
---|
| 118 | if ((X_SIZE!=1) && (X_SIZE!=2) && (X_SIZE!=4) && (X_SIZE!=8)) |
---|
| 119 | giet_exit( "[CONVOL ERROR] X_SIZE must be 1, 2, 4, 8\n"); |
---|
| 120 | |
---|
| 121 | if ((Y_SIZE!=1) && (Y_SIZE!=2) && (Y_SIZE!=4) && (Y_SIZE!=8)) |
---|
| 122 | giet_exit( "[CONVOL ERROR] X_SIZE must be 1, 2, 4, 8\n"); |
---|
| 123 | |
---|
| 124 | if ( NL % nclusters != 0 ) |
---|
| 125 | giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NL"); |
---|
| 126 | |
---|
| 127 | if ( NP % nclusters != 0 ) |
---|
| 128 | giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NP"); |
---|
| 129 | |
---|
| 130 | /////////////////////////////////////////////////////////////////// |
---|
| 131 | // All tasks initialise in their private stack five |
---|
| 132 | // arrays of pointers on the shared, distributed buffers, |
---|
| 133 | // containing the image. These buffers are indexed by cluster_id, |
---|
| 134 | // as there one set of 5 buffers per cluster. |
---|
| 135 | /////////////////////////////////////////////////////////////////// |
---|
| 136 | |
---|
[353] | 137 | unsigned short * A[NB_CLUSTERS]; |
---|
| 138 | int * B[NB_CLUSTERS]; |
---|
| 139 | int * C[NB_CLUSTERS]; |
---|
| 140 | int * D[NB_CLUSTERS]; |
---|
| 141 | unsigned char * Z[NB_CLUSTERS]; |
---|
[334] | 142 | |
---|
| 143 | // get heap vaddr in cluster[0,0] |
---|
| 144 | unsigned int base; |
---|
| 145 | giet_vobj_get_vbase( "convol", "conv_heap_0_0", &base ); |
---|
| 146 | |
---|
| 147 | // size allocated to each cluster depends on the number of clusters |
---|
| 148 | unsigned int size = 0x01000000 / nclusters; |
---|
| 149 | |
---|
| 150 | // initialise pointers on distributed buffers |
---|
| 151 | for (c = 0; c < nclusters; c++) |
---|
| 152 | { |
---|
| 153 | unsigned int cluster_offset = base + (size * c); |
---|
| 154 | A[c] = (unsigned short *) (cluster_offset); |
---|
| 155 | B[c] = (int *) (cluster_offset + (frame_size * 1 / nclusters)); |
---|
| 156 | C[c] = (int *) (cluster_offset + (frame_size * 3 / nclusters)); |
---|
| 157 | D[c] = (int *) (cluster_offset + (frame_size * 5 / nclusters)); |
---|
| 158 | Z[c] = (unsigned char *) (cluster_offset + (frame_size * 7 / nclusters)); |
---|
| 159 | |
---|
[353] | 160 | #if VERBOSE |
---|
| 161 | if ( pid == 0 ) giet_shr_printf( "\n########################################\n" |
---|
| 162 | "### A[%d] = %x\n" |
---|
| 163 | "### B[%d] = %x\n" |
---|
| 164 | "### C[%d] = %x\n" |
---|
| 165 | "### D[%d] = %x\n" |
---|
| 166 | "### Z[%d] = %x\n" |
---|
| 167 | "########################################\n", |
---|
| 168 | c,A[c],c,B[c],c,C[c],c,D[c],c,Z[c] ); |
---|
| 169 | #endif |
---|
[334] | 170 | } |
---|
| 171 | |
---|
| 172 | /////////////////////////////////////////////////////////////////////////// |
---|
| 173 | // task[0,0,0] makes barrier initialisation, |
---|
| 174 | // open the file containing image, and load it from disk to A[c] buffers |
---|
| 175 | // (nblocks / nclusters loaded in each cluster). |
---|
| 176 | // Other tasks are waiting on the init_ok condition. |
---|
| 177 | ////////////////////////////////////////////////////////////////////////// |
---|
| 178 | if ( pid == 0 ) |
---|
| 179 | { |
---|
| 180 | giet_shr_printf("\n[CONVOL] task[0,0,0] starts barrier init at cycle %d\n" |
---|
| 181 | "- NB_CLUSTERS = %d\n" |
---|
| 182 | "- NB_LOCAL_PROCS = %d\n" |
---|
| 183 | "- NB_TASKS = %d\n" |
---|
| 184 | "- NB_PIXELS = %x\n" |
---|
| 185 | "- FRAME_SIZE = %x\n" |
---|
| 186 | "- NB_BLOCKS = %x\n", |
---|
| 187 | giet_proctime(), nclusters, nprocs, ntasks, |
---|
| 188 | npixels, frame_size, nblocks ); |
---|
| 189 | |
---|
| 190 | // barriers initialization |
---|
| 191 | barrier_init( &barrier_1, ntasks ); |
---|
| 192 | barrier_init( &barrier_2, ntasks ); |
---|
| 193 | barrier_init( &barrier_3, ntasks ); |
---|
| 194 | barrier_init( &barrier_4, ntasks ); |
---|
| 195 | |
---|
| 196 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes barrier init at cycle %d\n", |
---|
| 197 | giet_proctime() ); |
---|
| 198 | |
---|
| 199 | // open file |
---|
| 200 | file = giet_fat_open("misc/philips_image.raw", 0 ); |
---|
| 201 | if ( file < 0 ) giet_exit( "[CONVOL ERROR] task[0,0,0] cannot open" |
---|
| 202 | " file misc/philips_image.raw" ); |
---|
| 203 | |
---|
| 204 | giet_shr_printf( "\n[CONVOL] task[0,0,0] open file misc/philips_image.raw" |
---|
| 205 | " at cycle %d\n", giet_proctime() ); |
---|
| 206 | |
---|
[353] | 207 | for ( c = 0 ; c < NB_CLUSTERS ; c++ ) |
---|
[334] | 208 | { |
---|
[353] | 209 | giet_shr_printf( "\n[CONVOL] task[0,0,0] starts load " |
---|
| 210 | "for cluster %d at cycle %d\n", c, giet_proctime() ); |
---|
| 211 | |
---|
[334] | 212 | giet_fat_read( file, |
---|
| 213 | A[c], |
---|
| 214 | nblocks/nclusters, |
---|
| 215 | (nblocks/nclusters)*c ); |
---|
| 216 | |
---|
[353] | 217 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes load " |
---|
| 218 | "for cluster %d at cycle %d\n", c, giet_proctime() ); |
---|
[334] | 219 | } |
---|
| 220 | init_ok = 1; |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | while ( init_ok == 0 ); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 228 | // Optionnal parallel display of the initial image stored in A[c] buffers. |
---|
| 229 | // Eah task displays (NL/ntasks) lines. (one byte per pixel). |
---|
| 230 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 231 | |
---|
| 232 | if ( INITIAL_DISPLAY_ENABLE ) |
---|
| 233 | { |
---|
| 234 | |
---|
[353] | 235 | #if VERBOSE |
---|
| 236 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts initial display" |
---|
| 237 | " at cycle %d\n", |
---|
| 238 | x, y, lpid, giet_proctime() ); |
---|
| 239 | #endif |
---|
| 240 | |
---|
[334] | 241 | unsigned int line; |
---|
| 242 | unsigned int offset = lines_per_task * lpid; |
---|
| 243 | |
---|
| 244 | for ( l = 0 ; l < lines_per_task ; l++ ) |
---|
| 245 | { |
---|
| 246 | line = offset + l; |
---|
| 247 | |
---|
| 248 | for ( p = 0 ; p < NP ; p++ ) |
---|
| 249 | { |
---|
| 250 | TZ(cluster_id, line, p) = (unsigned char)(TA(cluster_id, line, p) >> 8); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | giet_fb_sync_write( NP*(l + (task_id * lines_per_task) ), |
---|
| 254 | &TZ(cluster_id, line, 0), |
---|
| 255 | NP); |
---|
| 256 | } |
---|
| 257 | |
---|
[353] | 258 | #if VERBOSE |
---|
| 259 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes initial display" |
---|
| 260 | " at cycle %d\n", |
---|
| 261 | x, y, lpid, giet_proctime() ); |
---|
| 262 | #endif |
---|
[334] | 263 | |
---|
| 264 | /////////////////////////// |
---|
| 265 | barrier_wait( &barrier_1 ); |
---|
| 266 | |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | //////////////////////////////////////////////////////// |
---|
| 270 | // parallel horizontal filter : |
---|
| 271 | // B <= transpose(FH(A)) |
---|
| 272 | // D <= A - FH(A) |
---|
| 273 | // Each task computes (NL/ntasks) lines |
---|
| 274 | // The image must be extended : |
---|
| 275 | // if (z<0) TA(cluster_id,l,z) == TA(cluster_id,l,0) |
---|
| 276 | // if (z>NP-1) TA(cluster_id,l,z) == TA(cluster_id,l,NP-1) |
---|
| 277 | //////////////////////////////////////////////////////// |
---|
| 278 | |
---|
| 279 | date = giet_proctime(); |
---|
| 280 | H_BEG[cluster_id][lpid] = date; |
---|
| 281 | |
---|
[353] | 282 | #if VERBOSE |
---|
| 283 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts horizontal filter" |
---|
| 284 | " at cycle %d\n", |
---|
| 285 | x, y, lpid, date ); |
---|
| 286 | #else |
---|
| 287 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] starts horizontal filter" |
---|
| 288 | " at cycle %d\n", date ); |
---|
| 289 | #endif |
---|
| 290 | |
---|
[334] | 291 | // l = absolute line index / p = absolute pixel index |
---|
| 292 | // first & last define which lines are handled by a given task |
---|
| 293 | |
---|
| 294 | first = task_id * lines_per_task; |
---|
| 295 | last = first + lines_per_task; |
---|
| 296 | |
---|
| 297 | for (l = first; l < last; l++) |
---|
| 298 | { |
---|
| 299 | // src_c and src_l are the cluster index and the line index for A & D |
---|
| 300 | int src_c = l / lines_per_cluster; |
---|
| 301 | int src_l = l % lines_per_cluster; |
---|
| 302 | |
---|
| 303 | // We use the specific values of the horizontal ep-filter for optimisation: |
---|
| 304 | // sum(p) = sum(p-1) + TA[p+hrange] - TA[p-hrange-1] |
---|
| 305 | // To minimize the number of tests, the loop on pixels is split in three domains |
---|
| 306 | |
---|
| 307 | int sum_p = (hrange + 2) * TA(src_c, src_l, 0); |
---|
| 308 | for (z = 1; z < hrange; z++) |
---|
| 309 | { |
---|
| 310 | sum_p = sum_p + TA(src_c, src_l, z); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | // first domain : from 0 to hrange |
---|
| 314 | for (p = 0; p < hrange + 1; p++) |
---|
| 315 | { |
---|
| 316 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
| 317 | int dst_c = p / pixels_per_cluster; |
---|
| 318 | int dst_p = p % pixels_per_cluster; |
---|
| 319 | sum_p = sum_p + (int) TA(src_c, src_l, p + hrange) - (int) TA(src_c, src_l, 0); |
---|
| 320 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
| 321 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
| 322 | } |
---|
| 323 | // second domain : from (hrange+1) to (NP-hrange-1) |
---|
| 324 | for (p = hrange + 1; p < NP - hrange; p++) |
---|
| 325 | { |
---|
| 326 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
| 327 | int dst_c = p / pixels_per_cluster; |
---|
| 328 | int dst_p = p % pixels_per_cluster; |
---|
| 329 | sum_p = sum_p + (int) TA(src_c, src_l, p + hrange) |
---|
| 330 | - (int) TA(src_c, src_l, p - hrange - 1); |
---|
| 331 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
| 332 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
| 333 | } |
---|
| 334 | // third domain : from (NP-hrange) to (NP-1) |
---|
| 335 | for (p = NP - hrange; p < NP; p++) |
---|
| 336 | { |
---|
| 337 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
| 338 | int dst_c = p / pixels_per_cluster; |
---|
| 339 | int dst_p = p % pixels_per_cluster; |
---|
| 340 | sum_p = sum_p + (int) TA(src_c, src_l, NP - 1) |
---|
| 341 | - (int) TA(src_c, src_l, p - hrange - 1); |
---|
| 342 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
| 343 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
| 344 | } |
---|
| 345 | |
---|
[353] | 346 | #if SUPER_VERBOSE |
---|
| 347 | giet_shr_printf(" - line %d computed at cycle %d\n", l, giet_proctime() ); |
---|
| 348 | #endif |
---|
| 349 | |
---|
[334] | 350 | } |
---|
| 351 | |
---|
| 352 | date = giet_proctime(); |
---|
| 353 | H_END[cluster_id][lpid] = date; |
---|
| 354 | |
---|
[353] | 355 | #if VERBOSE |
---|
| 356 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes horizontal filter" |
---|
| 357 | " at cycle %d\n", |
---|
| 358 | x, y, lpid, date ); |
---|
| 359 | #else |
---|
| 360 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] completes horizontal filter" |
---|
| 361 | " at cycle %d\n", date ); |
---|
| 362 | #endif |
---|
| 363 | |
---|
[334] | 364 | /////////////////////////// |
---|
| 365 | barrier_wait( &barrier_2 ); |
---|
| 366 | |
---|
[353] | 367 | /////////////////////////////////////////////////////////////// |
---|
[334] | 368 | // parallel vertical filter : |
---|
| 369 | // C <= transpose(FV(B)) |
---|
| 370 | // Each task computes (NP/ntasks) columns |
---|
| 371 | // The image must be extended : |
---|
| 372 | // if (l<0) TB(cluster_id,p,l) == TB(cluster_id,p,0) |
---|
| 373 | // if (l>NL-1) TB(cluster_id,p,l) == TB(cluster_id,p,NL-1) |
---|
[353] | 374 | /////////////////////////////////////////////////////////////// |
---|
[334] | 375 | |
---|
| 376 | date = giet_proctime(); |
---|
| 377 | V_BEG[cluster_id][lpid] = date; |
---|
| 378 | |
---|
[353] | 379 | #if VERBOSE |
---|
| 380 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts vertical filter" |
---|
| 381 | " at cycle %d\n", |
---|
| 382 | x, y, lpid, date ); |
---|
| 383 | #else |
---|
| 384 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] starts vertical filter" |
---|
| 385 | " at cycle %d\n", date ); |
---|
| 386 | #endif |
---|
| 387 | |
---|
[334] | 388 | // l = absolute line index / p = absolute pixel index |
---|
| 389 | // first & last define which pixels are handled by a given task |
---|
| 390 | |
---|
| 391 | first = task_id * pixels_per_task; |
---|
| 392 | last = first + pixels_per_task; |
---|
| 393 | |
---|
| 394 | for (p = first; p < last; p++) |
---|
| 395 | { |
---|
| 396 | // src_c and src_p are the cluster index and the pixel index for B |
---|
| 397 | int src_c = p / pixels_per_cluster; |
---|
| 398 | int src_p = p % pixels_per_cluster; |
---|
| 399 | |
---|
| 400 | int sum_l; |
---|
| 401 | |
---|
| 402 | // We use the specific values of the vertical ep-filter |
---|
| 403 | // To minimize the number of tests, the NL lines are split in three domains |
---|
| 404 | |
---|
| 405 | // first domain : explicit computation for the first 18 values |
---|
| 406 | for (l = 0; l < 18; l++) |
---|
| 407 | { |
---|
| 408 | // dst_c and dst_l are the cluster index and the line index for C |
---|
| 409 | int dst_c = l / lines_per_cluster; |
---|
| 410 | int dst_l = l % lines_per_cluster; |
---|
| 411 | |
---|
| 412 | for (z = 0, sum_l = 0; z < 35; z++) |
---|
| 413 | { |
---|
| 414 | sum_l = sum_l + vf[z] * TB(src_c, src_p, max(l - 17 + z,0) ); |
---|
| 415 | } |
---|
| 416 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
| 417 | } |
---|
| 418 | // second domain |
---|
| 419 | for (l = 18; l < NL - 17; l++) |
---|
| 420 | { |
---|
| 421 | // dst_c and dst_l are the cluster index and the line index for C |
---|
| 422 | int dst_c = l / lines_per_cluster; |
---|
| 423 | int dst_l = l % lines_per_cluster; |
---|
| 424 | |
---|
| 425 | sum_l = sum_l + TB(src_c, src_p, l + 4) |
---|
| 426 | + TB(src_c, src_p, l + 8) |
---|
| 427 | + TB(src_c, src_p, l + 11) |
---|
| 428 | + TB(src_c, src_p, l + 15) |
---|
| 429 | + TB(src_c, src_p, l + 17) |
---|
| 430 | - TB(src_c, src_p, l - 5) |
---|
| 431 | - TB(src_c, src_p, l - 9) |
---|
| 432 | - TB(src_c, src_p, l - 12) |
---|
| 433 | - TB(src_c, src_p, l - 16) |
---|
| 434 | - TB(src_c, src_p, l - 18); |
---|
| 435 | |
---|
| 436 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
| 437 | } |
---|
| 438 | // third domain |
---|
| 439 | for (l = NL - 17; l < NL; l++) |
---|
| 440 | { |
---|
| 441 | // dst_c and dst_l are the cluster index and the line index for C |
---|
| 442 | int dst_c = l / lines_per_cluster; |
---|
| 443 | int dst_l = l % lines_per_cluster; |
---|
| 444 | |
---|
| 445 | sum_l = sum_l + TB(src_c, src_p, min(l + 4, NL - 1)) |
---|
| 446 | + TB(src_c, src_p, min(l + 8, NL - 1)) |
---|
| 447 | + TB(src_c, src_p, min(l + 11, NL - 1)) |
---|
| 448 | + TB(src_c, src_p, min(l + 15, NL - 1)) |
---|
| 449 | + TB(src_c, src_p, min(l + 17, NL - 1)) |
---|
| 450 | - TB(src_c, src_p, l - 5) |
---|
| 451 | - TB(src_c, src_p, l - 9) |
---|
| 452 | - TB(src_c, src_p, l - 12) |
---|
| 453 | - TB(src_c, src_p, l - 16) |
---|
| 454 | - TB(src_c, src_p, l - 18); |
---|
| 455 | |
---|
| 456 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
| 457 | } |
---|
| 458 | |
---|
[353] | 459 | #if SUPER_VERBOSE |
---|
| 460 | giet_shr_printf(" - column %d computed at cycle %d\n", p, giet_proctime()); |
---|
| 461 | #endif |
---|
| 462 | |
---|
[334] | 463 | } |
---|
| 464 | |
---|
| 465 | date = giet_proctime(); |
---|
| 466 | V_END[cluster_id][lpid] = date; |
---|
| 467 | |
---|
[353] | 468 | #if VERBOSE |
---|
| 469 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes vertical filter" |
---|
| 470 | " at cycle %d\n", |
---|
| 471 | x, y, lpid, date ); |
---|
| 472 | #else |
---|
| 473 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] completes vertical filter" |
---|
| 474 | " at cycle %d\n", date ); |
---|
| 475 | #endif |
---|
| 476 | |
---|
[334] | 477 | /////////////////////////// |
---|
| 478 | barrier_wait( &barrier_3 ); |
---|
| 479 | |
---|
| 480 | //////////////////////////////////////////////////////////////// |
---|
| 481 | // Optional parallel display of the final image Z <= D + C |
---|
| 482 | // Eah task displays (NL/ntasks) lines. (one byte per pixel). |
---|
| 483 | //////////////////////////////////////////////////////////////// |
---|
| 484 | |
---|
| 485 | if ( FINAL_DISPLAY_ENABLE ) |
---|
| 486 | { |
---|
| 487 | date = giet_proctime(); |
---|
| 488 | D_BEG[cluster_id][lpid] = date; |
---|
| 489 | |
---|
[353] | 490 | #if VERBOSE |
---|
| 491 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts final display" |
---|
| 492 | " at cycle %d\n", |
---|
| 493 | x, y, lpid, date); |
---|
| 494 | #else |
---|
| 495 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] starts final display" |
---|
| 496 | " at cycle %d\n", date ); |
---|
| 497 | #endif |
---|
| 498 | |
---|
[334] | 499 | unsigned int line; |
---|
| 500 | unsigned int offset = lines_per_task * lpid; |
---|
| 501 | |
---|
| 502 | for ( l = 0 ; l < lines_per_task ; l++ ) |
---|
| 503 | { |
---|
| 504 | line = offset + l; |
---|
| 505 | |
---|
| 506 | for ( p = 0 ; p < NP ; p++ ) |
---|
| 507 | { |
---|
| 508 | TZ(cluster_id, line, p) = |
---|
| 509 | (unsigned char)( (TD(cluster_id, line, p) + |
---|
| 510 | TC(cluster_id, line, p) ) >> 8 ); |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | giet_fb_sync_write( NP*(l + (task_id * lines_per_task) ), |
---|
| 514 | &TZ(cluster_id, line, 0), |
---|
| 515 | NP); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | date = giet_proctime(); |
---|
| 519 | D_END[cluster_id][lpid] = date; |
---|
[353] | 520 | |
---|
| 521 | #if VERBOSE |
---|
| 522 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes final display" |
---|
| 523 | " at cycle %d\n", |
---|
| 524 | x, y, lpid, date); |
---|
| 525 | #else |
---|
| 526 | if ( pid == 0 ) giet_shr_printf( "\n[CONVOL] task[0,0,0] completes final display" |
---|
| 527 | " at cycle %d\n", date ); |
---|
| 528 | #endif |
---|
[334] | 529 | |
---|
| 530 | /////////////////////////// |
---|
| 531 | barrier_wait( &barrier_4 ); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | ///////////////////////////////////////////////////////// |
---|
| 535 | // Task[0,0,0] makes the instrumentation |
---|
| 536 | ///////////////////////////////////////////////////////// |
---|
| 537 | |
---|
| 538 | if ( pid == 0 ) |
---|
| 539 | { |
---|
| 540 | date = giet_proctime(); |
---|
[353] | 541 | giet_shr_printf("\n[CONVOL] task[0,0,0] starts instrumentation" |
---|
| 542 | " at cycle %d\n\n", date ); |
---|
[334] | 543 | |
---|
| 544 | int cc, pp; |
---|
| 545 | |
---|
| 546 | unsigned int min_start = 0xFFFFFFFF; |
---|
| 547 | unsigned int max_start = 0; |
---|
| 548 | |
---|
| 549 | unsigned int min_h_beg = 0xFFFFFFFF; |
---|
| 550 | unsigned int max_h_beg = 0; |
---|
| 551 | |
---|
| 552 | unsigned int min_h_end = 0xFFFFFFFF; |
---|
| 553 | unsigned int max_h_end = 0; |
---|
| 554 | |
---|
| 555 | unsigned int min_v_beg = 0xFFFFFFFF; |
---|
| 556 | unsigned int max_v_beg = 0; |
---|
| 557 | |
---|
| 558 | unsigned int min_v_end = 0xFFFFFFFF; |
---|
| 559 | unsigned int max_v_end = 0; |
---|
| 560 | |
---|
| 561 | unsigned int min_d_beg = 0xFFFFFFFF; |
---|
| 562 | unsigned int max_d_beg = 0; |
---|
| 563 | |
---|
| 564 | unsigned int min_d_end = 0xFFFFFFFF; |
---|
| 565 | unsigned int max_d_end = 0; |
---|
| 566 | |
---|
| 567 | for (cc = 0; cc < nclusters; cc++) |
---|
| 568 | { |
---|
| 569 | for (pp = 0; pp < nprocs; pp++ ) |
---|
| 570 | { |
---|
| 571 | if (START[cc][pp] < min_start) min_start = START[cc][pp]; |
---|
| 572 | if (START[cc][pp] > max_start) max_start = START[cc][pp]; |
---|
| 573 | |
---|
| 574 | if (H_BEG[cc][pp] < min_h_beg) min_h_beg = H_BEG[cc][pp]; |
---|
| 575 | if (H_BEG[cc][pp] > max_h_beg) max_h_beg = H_BEG[cc][pp]; |
---|
| 576 | |
---|
| 577 | if (H_END[cc][pp] < min_h_end) min_h_end = H_END[cc][pp]; |
---|
| 578 | if (H_END[cc][pp] > max_h_end) max_h_end = H_END[cc][pp]; |
---|
| 579 | |
---|
| 580 | if (V_BEG[cc][pp] < min_v_beg) min_v_beg = V_BEG[cc][pp]; |
---|
| 581 | if (V_BEG[cc][pp] > max_v_beg) max_v_beg = V_BEG[cc][pp]; |
---|
| 582 | |
---|
| 583 | if (V_END[cc][pp] < min_v_end) min_v_end = V_END[cc][pp]; |
---|
| 584 | if (V_END[cc][pp] > max_v_end) max_v_end = V_END[cc][pp]; |
---|
| 585 | |
---|
| 586 | if (D_BEG[cc][pp] < min_d_beg) min_d_beg = D_BEG[cc][pp]; |
---|
| 587 | if (D_BEG[cc][pp] > max_d_beg) max_d_beg = D_BEG[cc][pp]; |
---|
| 588 | |
---|
| 589 | if (D_END[cc][pp] < min_d_end) min_d_end = D_END[cc][pp]; |
---|
| 590 | if (D_END[cc][pp] > max_d_end) max_d_end = D_END[cc][pp]; |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | giet_shr_printf(" - START : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 595 | min_start, max_start, (min_start+max_start)/2, max_start-min_start); |
---|
| 596 | |
---|
| 597 | giet_shr_printf(" - H_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 598 | min_h_beg, max_h_beg, (min_h_beg+max_h_beg)/2, max_h_beg-min_h_beg); |
---|
| 599 | |
---|
[353] | 600 | giet_shr_printf(" - H_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
[334] | 601 | min_h_end, max_h_end, (min_h_end+max_h_end)/2, max_h_end-min_h_end); |
---|
| 602 | |
---|
| 603 | giet_shr_printf(" - V_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 604 | min_v_beg, max_v_beg, (min_v_beg+max_v_beg)/2, max_v_beg-min_v_beg); |
---|
| 605 | |
---|
[353] | 606 | giet_shr_printf(" - V_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
[334] | 607 | min_v_end, max_v_end, (min_v_end+max_v_end)/2, max_v_end-min_v_end); |
---|
| 608 | |
---|
| 609 | giet_shr_printf(" - D_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 610 | min_d_beg, max_d_beg, (min_d_beg+max_d_beg)/2, max_d_beg-min_d_beg); |
---|
| 611 | |
---|
[353] | 612 | giet_shr_printf(" - D_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
[334] | 613 | min_d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end); |
---|
| 614 | |
---|
| 615 | giet_shr_printf( "\n General Scenario (Kcycles for each step)\n" ); |
---|
[353] | 616 | giet_shr_printf( " - BOOT OS = %d\n", (min_start )/1000 ); |
---|
| 617 | giet_shr_printf( " - LOAD IMAGE = %d\n", (min_h_beg - min_start)/1000 ); |
---|
| 618 | giet_shr_printf( " - H_FILTER = %d\n", (max_h_end - min_h_beg)/1000 ); |
---|
| 619 | giet_shr_printf( " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 ); |
---|
| 620 | giet_shr_printf( " - V_FILTER = %d\n", (max_v_end - min_v_beg)/1000 ); |
---|
| 621 | giet_shr_printf( " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 ); |
---|
| 622 | giet_shr_printf( " - DISPLAY = %d\n", (max_d_end - min_d_beg)/1000 ); |
---|
[334] | 623 | |
---|
| 624 | exit_ok = 1; |
---|
| 625 | } |
---|
| 626 | else |
---|
| 627 | { |
---|
| 628 | while ( exit_ok == 0 ); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | giet_exit( "completed"); |
---|
| 632 | |
---|
| 633 | } // end main() |
---|
| 634 | |
---|
| 635 | // Local Variables: |
---|
| 636 | // tab-width: 3 |
---|
| 637 | // c-basic-offset: 3 |
---|
| 638 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 639 | // indent-tabs-mode: nil |
---|
| 640 | // End: |
---|
| 641 | |
---|
| 642 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 |
---|
| 643 | |
---|
| 644 | |
---|