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