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