[158] | 1 | #include "stdio.h" |
---|
| 2 | |
---|
[171] | 3 | #define NL 512 |
---|
| 4 | #define NP 512 |
---|
| 5 | #define NB_IMAGES 1 |
---|
| 6 | #define BLOCK_SIZE 512 |
---|
[158] | 7 | |
---|
| 8 | #define PRINTF if(local_id == 0) tty_printf |
---|
| 9 | |
---|
| 10 | /////////////////////////////////////////// |
---|
| 11 | // tricks to read parameters from ldscript |
---|
| 12 | /////////////////////////////////////////// |
---|
| 13 | |
---|
| 14 | struct plaf; |
---|
| 15 | |
---|
| 16 | extern struct plaf seg_heap_base; |
---|
| 17 | extern struct plaf NB_PROCS; |
---|
| 18 | extern struct plaf NB_CLUSTERS; |
---|
| 19 | |
---|
| 20 | ///////////// |
---|
| 21 | void main() |
---|
| 22 | { |
---|
| 23 | unsigned int image = 0; |
---|
| 24 | unsigned int date = 0; |
---|
| 25 | |
---|
| 26 | unsigned int c; // cluster index for loops |
---|
| 27 | unsigned int l; // line index for loops |
---|
| 28 | unsigned int p; // pixel index for loops |
---|
| 29 | |
---|
| 30 | unsigned int proc_id = procid(); // processor id |
---|
| 31 | unsigned int nprocs = (unsigned int)&NB_PROCS; // number of processors per cluster |
---|
| 32 | unsigned int nclusters = (unsigned int)&NB_CLUSTERS; // number of clusters |
---|
| 33 | unsigned int local_id = proc_id%nprocs; // local processor id |
---|
| 34 | unsigned int cluster_id = proc_id/nprocs; // cluster id |
---|
| 35 | unsigned int base = (unsigned int)&seg_heap_base; // base address for shared buffers |
---|
| 36 | unsigned int increment = (0x80000000 / nclusters) * 2; // cluster increment |
---|
| 37 | unsigned int ntasks = nclusters * nprocs; // number of tasks |
---|
| 38 | unsigned int nblocks = (NP*NL) / BLOCK_SIZE; // number of blocks per image |
---|
| 39 | |
---|
| 40 | PRINTF("\n *** Entering main at cycle %d ***\n\n", proctime()); |
---|
| 41 | |
---|
| 42 | // parameters checking |
---|
| 43 | if( (nprocs != 1) && (nprocs != 2) && (nprocs != 4) ) |
---|
| 44 | { |
---|
| 45 | PRINTF("NB_PROCS must be 1, 2 or 4\n"); |
---|
| 46 | } |
---|
| 47 | if( (nclusters != 1) && (nclusters != 2) && (nclusters != 4) && (nclusters != 8) && |
---|
[171] | 48 | (nclusters != 16) && (nclusters != 32) && (nclusters != 64) && (nclusters !=128) && |
---|
| 49 | (nclusters != 256) ) |
---|
[158] | 50 | { |
---|
[171] | 51 | PRINTF("NB_CLUSTERS must be a power of 1 between 1 and 256\n"); |
---|
[158] | 52 | } |
---|
[171] | 53 | if( ntasks > 1024 ) |
---|
[158] | 54 | { |
---|
[171] | 55 | PRINTF("NB_PROCS * NB_CLUSTERS cannot be larger than 1024\n"); |
---|
[158] | 56 | } |
---|
| 57 | if( proc_id >= ntasks ) |
---|
| 58 | { |
---|
| 59 | PRINTF("processor id %d larger than NB_CLUSTERS*NB_PROCS\n", proc_id); |
---|
| 60 | } |
---|
| 61 | |
---|
[171] | 62 | // Arrays of pointers on the shared, distributed buffers containing the images |
---|
| 63 | // These arrays are indexed by the cluster index (sized for the worst case : 256 clusters) |
---|
| 64 | unsigned char* A[256]; |
---|
| 65 | unsigned char* B[256]; |
---|
[158] | 66 | |
---|
[171] | 67 | // Arrays of pointers on the instrumentation arrays |
---|
| 68 | // These arrays are indexed by the cluster index (sized for the worst case : 256 clusters) |
---|
| 69 | // each pointer points on the base adress of an array of NPROCS unsigned int |
---|
| 70 | unsigned int* LOAD_START[256]; |
---|
| 71 | unsigned int* LOAD_ENDED[256]; |
---|
| 72 | unsigned int* TRSP_START[256]; |
---|
| 73 | unsigned int* TRSP_ENDED[256]; |
---|
| 74 | unsigned int* DISP_START[256]; |
---|
| 75 | unsigned int* DISP_ENDED[256]; |
---|
| 76 | |
---|
[158] | 77 | // shared buffers address definition |
---|
[171] | 78 | // from the seg_heap_base and increment depending on the cluster index |
---|
| 79 | // These arrays of pointers are identical and replicated in the stack of each task |
---|
[158] | 80 | for( c=0 ; c<nclusters ; c++) |
---|
| 81 | { |
---|
[171] | 82 | A[c] = (unsigned char*)(base + increment*c); |
---|
| 83 | B[c] = (unsigned char*)(base + NL*NP + increment*c); |
---|
| 84 | LOAD_START[c] = (unsigned int*) (base + 2*NL*NP + increment*c); |
---|
| 85 | LOAD_ENDED[c] = (unsigned int*) (base + 3*NL*NP + increment*c); |
---|
| 86 | TRSP_START[c] = (unsigned int*) (base + 4*NL*NP + increment*c); |
---|
| 87 | TRSP_ENDED[c] = (unsigned int*) (base + 5*NL*NP + increment*c); |
---|
| 88 | DISP_START[c] = (unsigned int*) (base + 6*NL*NP + increment*c); |
---|
| 89 | DISP_ENDED[c] = (unsigned int*) (base + 7*NL*NP + increment*c); |
---|
[158] | 90 | } |
---|
| 91 | |
---|
| 92 | PRINTF("NB_CLUSTERS = %d\n", nclusters); |
---|
| 93 | PRINTF("NB_PROCS = %d\n\n", nprocs); |
---|
| 94 | |
---|
| 95 | PRINTF("*** starting barrier init at cycle %d ***\n", proctime()); |
---|
| 96 | |
---|
| 97 | // barriers initialization |
---|
| 98 | barrier_init(0, ntasks); |
---|
| 99 | barrier_init(1, ntasks); |
---|
| 100 | barrier_init(2, ntasks); |
---|
| 101 | |
---|
| 102 | PRINTF("*** completing barrier init at cycle %d ***\n", proctime()); |
---|
| 103 | |
---|
| 104 | // Main loop (on images) |
---|
| 105 | while(image < NB_IMAGES) |
---|
| 106 | { |
---|
| 107 | // pseudo parallel load from disk to A[c] buffer : nblocks/nclusters blocks |
---|
| 108 | // only task running on processor with (local_id == 0) does it |
---|
| 109 | |
---|
| 110 | if ( local_id == 0 ) |
---|
| 111 | { |
---|
[171] | 112 | int p; |
---|
[158] | 113 | |
---|
[171] | 114 | date = proctime(); |
---|
| 115 | PRINTF("\n*** Starting load for image %d at cycle %d\n", image, date); |
---|
| 116 | for ( p=0 ; p<nprocs ; p++ ) LOAD_START[cluster_id][p] = date; |
---|
| 117 | |
---|
[158] | 118 | if( ioc_read(image*nblocks + nblocks*cluster_id/nclusters , A[cluster_id], nblocks/nclusters) ) |
---|
| 119 | { |
---|
| 120 | tty_printf("echec ioc_read\n"); |
---|
| 121 | exit(); |
---|
| 122 | } |
---|
| 123 | if ( ioc_completed() ) |
---|
| 124 | { |
---|
| 125 | tty_printf("echec ioc_completed\n"); |
---|
| 126 | exit(); |
---|
| 127 | } |
---|
[171] | 128 | |
---|
| 129 | date = proctime(); |
---|
| 130 | PRINTF("*** Completing load for image %d at cycle %d\n", image, date); |
---|
| 131 | for ( p=0 ; p<nprocs ; p++ ) LOAD_ENDED[cluster_id][p] = date; |
---|
[158] | 132 | } |
---|
| 133 | |
---|
| 134 | barrier_wait(0); |
---|
| 135 | |
---|
| 136 | // parallel transpose from A to B buffers |
---|
| 137 | // each processor makes the transposition for (NL/ntasks) lines |
---|
| 138 | // (p,l) are the (x,y) pixel coordinates in the source image |
---|
| 139 | |
---|
| 140 | |
---|
[171] | 141 | date = proctime(); |
---|
| 142 | PRINTF("\n*** Starting transpose for image %d at cycle %d\n", image, date); |
---|
| 143 | TRSP_START[cluster_id][local_id] = date; |
---|
[158] | 144 | |
---|
| 145 | unsigned int nlt = NL/ntasks; |
---|
| 146 | unsigned int first = (cluster_id*nprocs + local_id)*nlt; |
---|
| 147 | unsigned int last = first + nlt; |
---|
| 148 | |
---|
| 149 | for ( l=first ; l<last ; l++) |
---|
| 150 | { |
---|
| 151 | PRINTF( " - processing line %d\n", l); |
---|
| 152 | for ( p=0 ; p<NP ; p++) |
---|
| 153 | { |
---|
| 154 | unsigned int source_cluster = l/(NL/nclusters); |
---|
| 155 | unsigned int source_index = (l%(NL/nclusters))*NP + p; |
---|
| 156 | unsigned int dest_cluster = p / (NP/nclusters); |
---|
| 157 | unsigned int dest_index = (p%(NP/nclusters))*NL + l; |
---|
| 158 | B[dest_cluster][dest_index] = A[source_cluster][source_index]; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | } |
---|
[171] | 162 | date = proctime(); |
---|
| 163 | PRINTF("*** Completing transpose for image %d at cycle %d\n", image, date); |
---|
| 164 | TRSP_ENDED[cluster_id][local_id] = date; |
---|
[158] | 165 | |
---|
| 166 | barrier_wait(1); |
---|
| 167 | |
---|
| 168 | // parallel display from B[c] to frame buffer |
---|
| 169 | // each processor uses its private dma to display NL*NP/ntasks pixels |
---|
| 170 | |
---|
[171] | 171 | date = proctime(); |
---|
| 172 | PRINTF("\n*** Starting display for image %d at cycle %d\n", image, date); |
---|
| 173 | DISP_START[cluster_id][local_id] = date; |
---|
[158] | 174 | |
---|
| 175 | unsigned int npxt = NL*NP/ntasks; // number of pixels per task |
---|
| 176 | |
---|
| 177 | if ( fb_write(npxt*proc_id, B[cluster_id] + npxt*local_id, npxt) ) |
---|
| 178 | { |
---|
| 179 | PRINTF("echec fb_sync_write\n"); |
---|
| 180 | exit(); |
---|
| 181 | } |
---|
| 182 | if ( fb_completed() ) |
---|
| 183 | { |
---|
| 184 | PRINTF("echec fb_completed\n"); |
---|
| 185 | exit(); |
---|
| 186 | } |
---|
| 187 | |
---|
[171] | 188 | date = proctime(); |
---|
| 189 | PRINTF("*** Completing display for image %d at cycle %d\n", image, date); |
---|
| 190 | DISP_ENDED[cluster_id][local_id] = date; |
---|
[158] | 191 | |
---|
| 192 | barrier_wait(2); |
---|
| 193 | |
---|
[171] | 194 | // Instrumentation (done by processor 0 in cluster 0) |
---|
| 195 | if ( local_id == 0 ) |
---|
| 196 | { |
---|
| 197 | date = proctime(); |
---|
| 198 | PRINTF("\n*** Starting Instrumentation for image %d at cycle %d\n\n", image, date); |
---|
| 199 | |
---|
| 200 | int cc, pp; |
---|
| 201 | unsigned int min_load_start = 1000000000; |
---|
| 202 | unsigned int max_load_start = 0; |
---|
| 203 | unsigned int min_load_ended = 1000000000; |
---|
| 204 | unsigned int max_load_ended = 0; |
---|
| 205 | unsigned int min_trsp_start = 1000000000; |
---|
| 206 | unsigned int max_trsp_start = 0; |
---|
| 207 | unsigned int min_trsp_ended = 1000000000; |
---|
| 208 | unsigned int max_trsp_ended = 0; |
---|
| 209 | unsigned int min_disp_start = 1000000000; |
---|
| 210 | unsigned int max_disp_start = 0; |
---|
| 211 | unsigned int min_disp_ended = 1000000000; |
---|
| 212 | unsigned int max_disp_ended = 0; |
---|
| 213 | |
---|
| 214 | for ( cc=0 ; cc<nclusters ; cc++ ) |
---|
| 215 | { |
---|
| 216 | for ( pp=0 ; pp<nprocs ; pp++ ) |
---|
| 217 | { |
---|
| 218 | if ( LOAD_START[cc][pp] < min_load_start ) min_load_start = LOAD_START[cc][pp]; |
---|
| 219 | if ( LOAD_START[cc][pp] > max_load_start ) max_load_start = LOAD_START[cc][pp]; |
---|
| 220 | if ( LOAD_ENDED[cc][pp] < min_load_ended ) min_load_ended = LOAD_ENDED[cc][pp]; |
---|
| 221 | if ( LOAD_ENDED[cc][pp] > max_load_ended ) max_load_ended = LOAD_ENDED[cc][pp]; |
---|
| 222 | |
---|
| 223 | if ( TRSP_START[cc][pp] < min_trsp_start ) min_trsp_start = TRSP_START[cc][pp]; |
---|
| 224 | if ( TRSP_START[cc][pp] > max_trsp_start ) max_trsp_start = TRSP_START[cc][pp]; |
---|
| 225 | if ( TRSP_ENDED[cc][pp] < min_trsp_ended ) min_trsp_ended = TRSP_ENDED[cc][pp]; |
---|
| 226 | if ( TRSP_ENDED[cc][pp] > max_trsp_ended ) max_trsp_ended = TRSP_ENDED[cc][pp]; |
---|
| 227 | |
---|
| 228 | if ( DISP_START[cc][pp] < min_disp_start ) min_disp_start = DISP_START[cc][pp]; |
---|
| 229 | if ( DISP_START[cc][pp] > max_disp_start ) max_disp_start = DISP_START[cc][pp]; |
---|
| 230 | if ( DISP_ENDED[cc][pp] < min_disp_ended ) min_disp_ended = DISP_ENDED[cc][pp]; |
---|
| 231 | if ( DISP_ENDED[cc][pp] > max_disp_ended ) max_disp_ended = DISP_ENDED[cc][pp]; |
---|
| 232 | |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | PRINTF(" - LOAD_START : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 236 | min_load_start, max_load_start, (min_load_start+max_load_start)/2, max_load_start-min_load_start); |
---|
| 237 | PRINTF(" - LOAD_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 238 | min_load_ended, max_load_ended, (min_load_ended+max_load_ended)/2, max_load_ended-min_load_ended); |
---|
| 239 | |
---|
| 240 | PRINTF(" - TRSP_START : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 241 | min_trsp_start, max_trsp_start, (min_trsp_start+max_trsp_start)/2, max_trsp_start-min_trsp_start); |
---|
| 242 | PRINTF(" - TRSP_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 243 | min_trsp_ended, max_trsp_ended, (min_trsp_ended+max_trsp_ended)/2, max_trsp_ended-min_trsp_ended); |
---|
| 244 | |
---|
| 245 | PRINTF(" - DISP_START : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 246 | min_disp_start, max_disp_start, (min_disp_start+max_disp_start)/2, max_disp_start-min_disp_start); |
---|
| 247 | PRINTF(" - DISP_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
| 248 | min_disp_ended, max_disp_ended, (min_disp_ended+max_disp_ended)/2, max_disp_ended-min_disp_ended); |
---|
| 249 | |
---|
| 250 | PRINTF(" - BARRIER TRSP/DISP = %d\n", min_disp_start - max_trsp_ended); |
---|
| 251 | } |
---|
[158] | 252 | // next image |
---|
| 253 | image++; |
---|
[171] | 254 | |
---|
[158] | 255 | } // end while image |
---|
[171] | 256 | |
---|
[158] | 257 | while(1); |
---|
| 258 | } // end main() |
---|
| 259 | |
---|