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