source: trunk/platforms/tsarv4_generic_xbar/soft_transpose/main.c @ 154

Last change on this file since 154 was 154, checked in by alain, 13 years ago

Introducing the tsarv4_generic_xbar platform

File size: 6.1 KB
Line 
1#include "stdio.h"
2
3#define NL              128
4#define NP              128
5#define NB_IMAGES       2
6#define BLOCK_SIZE      128
7
8#define PRINTF          if(local_id == 0) tty_printf
9
10///////////////////////////////////////////
11// tricks to read parameters from ldscript
12///////////////////////////////////////////
13
14struct plaf;
15
16extern struct plaf seg_heap_base;
17extern struct plaf NB_PROCS;
18extern struct plaf NB_CLUSTERS;
19
20/////////////
21void main()
22{
23    unsigned int        image     = 0;
24    unsigned int        date      = 0;
25    unsigned int        delta     = 0;
26
27    unsigned int        c;                                              // cluster index for loops
28    unsigned int        l;                                              // line index for loops
29    unsigned int        p;                                              // pixel index for loops
30
31    unsigned int        proc_id     = procid();                         // processor id
32    unsigned int        nprocs      = (unsigned int)&NB_PROCS;          // number of processors per cluster
33    unsigned int        nclusters   = (unsigned int)&NB_CLUSTERS;       // number of clusters
34    unsigned int        local_id    = proc_id%nprocs;                   // local processor id
35    unsigned int        cluster_id  = proc_id/nprocs;                   // local processor id
36    unsigned int        base        = (unsigned int)&seg_heap_base;     // base address for shared buffers
37    unsigned int        increment   = (0x80000000 / nclusters) * 2;     // cluster increment
38    unsigned int        ntasks      = nclusters * nprocs;               // number of tasks
39    unsigned int        nblocks     = (NP*NL) / BLOCK_SIZE;             // number of blocks per image
40
41    PRINTF("\n *** Entering main at cycle %d ***\n\n", proctime());
42
43    //  parameters checking
44    if( (nprocs != 1) && (nprocs != 2) && (nprocs != 4) )
45    {
46        PRINTF("NB_PROCS must be 1, 2 or 4\n");
47
48        exit();
49    }
50    if( (nclusters !=  1) && (nclusters !=  2) && (nclusters !=  4) && (nclusters !=  8) &&
51        (nclusters != 16) && (nclusters != 32) && (nclusters != 64) && (nclusters !=128) )
52    {
53        PRINTF("NB_CLUSTERS must be a power of 2 between 1 and 128\n");
54        exit();
55    }
56    if( ntasks > 128 )
57    {
58        PRINTF("NB_PROCS * NB_CLUSTERS cannot be larger than 128 4\n");
59        exit();
60    }
61    if( proc_id >= ntasks )
62    {
63        PRINTF("processor id %d larger than NB_CLUSTERS*NB_PROCS\n", proc_id);
64    }
65
66    // Arrays of pointers on the shared, distributed buffers 
67    // containing the images (sized for the worst case : 128 clusters)
68    unsigned char*      A[128];
69    unsigned char*      B[128];
70   
71    // shared buffers address definition
72    // from the seg_heap_base and segment_increment
73    // values defined in the ldscript file.
74    // These arrays of pointers are identical and
75    // replicated in the stack of each task
76    for( c=0 ; c<nclusters ; c++)
77    {
78        A[c] = (unsigned char*)(base + increment*c);
79        B[c] = (unsigned char*)(base + NL*NP + increment*c);
80    }
81
82    PRINTF("NB_CLUSTERS = %d\n", nclusters); 
83    PRINTF("NB_PROCS    = %d\n\n", nprocs); 
84
85    PRINTF("*** starting barrier init at cycle %d ***\n", proctime());
86
87    //  barriers initialization
88    barrier_init(0, ntasks);
89    barrier_init(1, ntasks);
90    barrier_init(2, ntasks);
91
92    PRINTF("*** completing barrier init at cycle %d ***\n", proctime());
93
94    // Main loop (on images)
95    while(image < NB_IMAGES) 
96    {
97        // pseudo parallel load from disk to A[c] buffer : nblocks/nclusters blocks
98        // only task running on processor with (local_id == 0) does it
99
100        delta = proctime() - date;
101        date  = date + delta;
102
103        if ( local_id == 0 )
104        {
105            PRINTF("\n*** Starting load for image %d *** at cycle %d (%d)\n", image, date, delta);
106
107            if( ioc_read(image*nblocks + nblocks*cluster_id/nclusters , A[cluster_id], nblocks/nclusters) )
108            {
109                tty_printf("echec ioc_read\n");
110                exit();
111            }
112            if ( ioc_completed() )
113            {
114                tty_printf("echec ioc_completed\n");
115                exit();
116            }
117            delta = proctime() - date;
118            date  = date + delta;
119            PRINTF("*** Completing load for image %d *** at cycle %d (%d)\n", image, date, delta);
120        }
121
122        barrier_wait(0);
123
124        // parallel transpose from A to B buffers
125        // each processor makes the transposition for (NL/ntasks) lines
126        // (p,l) are the (x,y) pixel coordinates in the source image
127
128        delta = proctime() - date;
129        date  = date + delta;
130
131        PRINTF("\n*** starting transpose for image %d at cycle %d (%d)\n", image, date, delta);
132
133        unsigned int nlt = NL/ntasks;
134
135        for ( l = nlt*local_id ; l < nlt*(local_id+1) ; l++)
136        {
137            PRINTF( "    - processing line %d at cycle %d\n", l + NL*cluster_id/nclusters, proctime() );
138            for ( p=0 ; p<NP ; p++)
139            {
140//                unsigned int source_cluster = l/(NL/nclusters);
141//                unsigned int source_index   = (l%(NL/nclusters))*NP + p;
142//                unsigned int dest_cluster   = p / (NP/nclusters);
143//                unsigned int dest_index     = (p%(NP/nclusters))*NL + l;
144//                B[dest_cluster][dest_index] = A[source_cluster][source_index];
145
146                B[cluster_id][l*NP+p] = A[cluster_id][l*NP+p];
147            }
148
149        }
150        delta = proctime() - date;
151        date  = date + delta;
152        PRINTF("*** Completing transpose for image %d *** at cycle %d (%d)\n", image, date, delta);
153
154        barrier_wait(1);
155
156        // parallel display from B[c] to frame buffer
157        // each processor uses its private dma to display NL*NP/ntasks pixels
158
159        delta = proctime() - date;
160        date  = date + delta;
161
162        PRINTF("\n *** starting display for image %d at cycle %d (%d)\n", image, date, delta);
163
164        unsigned int npxt = NL*NP/ntasks;       // number of pixels per task
165
166        if ( fb_write(npxt*proc_id, B[cluster_id] + npxt*local_id, npxt) )
167        {
168            PRINTF("echec fb_sync_write\n");
169            exit();
170        }
171        if ( fb_completed() )
172        {
173            PRINTF("echec fb_completed\n");
174            exit();
175        }
176
177        delta = proctime() - date;
178        date  = date + delta;
179        PRINTF(" *** completing display for image %d at cycle %d (%d)\n", image, date, delta);
180
181        barrier_wait(2);
182
183        // next image
184        image++;
185    } // end while image     
186    while(1);
187} // end main()
188
Note: See TracBrowser for help on using the repository browser.