1 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // file : coproc.c |
---|
3 | // date : avril 2015 |
---|
4 | // author : Alain Greiner |
---|
5 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
6 | // This file describes the single thread "coproc" application. |
---|
7 | // It uses the GCD (Greater Common Divider) hardware coprocessor |
---|
8 | // to make the GCD computation between two vectors of 32 bits integers. |
---|
9 | // It supports two coprocessor operating modes: MODE_DMA_IRQ or MODE_DMA_NO_IRQ. |
---|
10 | // The vectors size is defined by the VECTOR_SIZE parameter. |
---|
11 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
12 | |
---|
13 | |
---|
14 | #include "stdio.h" |
---|
15 | #include "mapping_info.h" // for coprocessors types an modes |
---|
16 | |
---|
17 | #define VECTOR_SIZE 128 |
---|
18 | |
---|
19 | #define DMA_MODE MODE_DMA_IRQ |
---|
20 | |
---|
21 | #define VERBOSE 1 |
---|
22 | |
---|
23 | // Memory buffers for coprocessor |
---|
24 | unsigned int opa[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
25 | unsigned int opb[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
26 | unsigned int res[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
27 | |
---|
28 | ///////////////////////////////////////// |
---|
29 | __attribute__ ((constructor)) void main() |
---|
30 | { |
---|
31 | // get processor identifiers |
---|
32 | unsigned int x; |
---|
33 | unsigned int y; |
---|
34 | unsigned int lpid; |
---|
35 | giet_proc_xyp( &x, &y, &lpid ); |
---|
36 | |
---|
37 | // get a private TTY terminal |
---|
38 | giet_tty_alloc( 0 ); |
---|
39 | |
---|
40 | giet_tty_printf("\n*** Starting coproc application on processor" |
---|
41 | "[%d,%d,%d] at cycle %d\n", |
---|
42 | x, y, lpid, giet_proctime() ); |
---|
43 | |
---|
44 | // check coprocessor operating mode |
---|
45 | giet_pthread_assert( (DMA_MODE == MODE_DMA_IRQ) || (DMA_MODE == MODE_DMA_NO_IRQ), |
---|
46 | "\n[COPROC ERROR] only MODE_DMA_IRQ and MODE_DMA_NO_IRQ modes are supported"); |
---|
47 | |
---|
48 | // initializes opa & opb buffers |
---|
49 | unsigned int word; |
---|
50 | for ( word = 0 ; word < VECTOR_SIZE ; word++ ) |
---|
51 | { |
---|
52 | opa[word] = giet_rand() + 1; |
---|
53 | opb[word] = giet_rand() + 1; |
---|
54 | } |
---|
55 | |
---|
56 | unsigned int coproc_info; |
---|
57 | unsigned int cluster_xy = (x << 4) + y; |
---|
58 | unsigned int coproc_type = MWR_SUBTYPE_GCD; |
---|
59 | |
---|
60 | // get a GCD coprocessor in local cluster |
---|
61 | giet_coproc_alloc( cluster_xy, |
---|
62 | coproc_type, |
---|
63 | &coproc_info ); |
---|
64 | |
---|
65 | // check coprocessor ports |
---|
66 | unsigned int nb_to_coproc = (coproc_info ) & 0xFF; |
---|
67 | unsigned int nb_from_coproc = (coproc_info>> 8) & 0xFF; |
---|
68 | unsigned int nb_config = (coproc_info>>16) & 0xFF; |
---|
69 | unsigned int nb_status = (coproc_info>>24) & 0xFF; |
---|
70 | giet_pthread_assert( ((nb_to_coproc == 2) && |
---|
71 | (nb_from_coproc == 1) && |
---|
72 | (nb_config == 1) && |
---|
73 | (nb_status == 0) ) , |
---|
74 | "wrong GCD coprocessor interface" ); |
---|
75 | |
---|
76 | #if VERBOSE |
---|
77 | giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() ); |
---|
78 | #endif |
---|
79 | |
---|
80 | // initializes OPA channel |
---|
81 | giet_coproc_channel_t opa_desc; |
---|
82 | opa_desc.channel_mode = DMA_MODE; |
---|
83 | opa_desc.buffer_size = VECTOR_SIZE<<2; |
---|
84 | opa_desc.buffer_vaddr = (unsigned int)opa; |
---|
85 | giet_coproc_channel_init( cluster_xy, |
---|
86 | coproc_type, |
---|
87 | 0, |
---|
88 | &opa_desc ); |
---|
89 | |
---|
90 | // initializes OPB channel |
---|
91 | giet_coproc_channel_t opb_desc; |
---|
92 | opb_desc.channel_mode = DMA_MODE; |
---|
93 | opb_desc.buffer_size = VECTOR_SIZE<<2; |
---|
94 | opb_desc.buffer_vaddr = (unsigned int)opb; |
---|
95 | giet_coproc_channel_init( cluster_xy, |
---|
96 | coproc_type, |
---|
97 | 1, |
---|
98 | &opb_desc ); |
---|
99 | |
---|
100 | // initializes RES channel |
---|
101 | giet_coproc_channel_t res_desc; |
---|
102 | res_desc.channel_mode = DMA_MODE; |
---|
103 | res_desc.buffer_size = VECTOR_SIZE<<2; |
---|
104 | res_desc.buffer_vaddr = (unsigned int)res; |
---|
105 | giet_coproc_channel_init( cluster_xy, |
---|
106 | coproc_type, |
---|
107 | 2, |
---|
108 | &res_desc ); |
---|
109 | |
---|
110 | #if VERBOSE |
---|
111 | giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() ); |
---|
112 | #endif |
---|
113 | |
---|
114 | // starts coprocessor |
---|
115 | giet_coproc_run( cluster_xy, |
---|
116 | coproc_type ); |
---|
117 | |
---|
118 | #if VERBOSE |
---|
119 | giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() ); |
---|
120 | #endif |
---|
121 | |
---|
122 | // wait coprocessor completion |
---|
123 | if ( DMA_MODE == MODE_DMA_NO_IRQ ) |
---|
124 | { |
---|
125 | giet_coproc_completed( cluster_xy, |
---|
126 | coproc_type ); |
---|
127 | } |
---|
128 | |
---|
129 | #if VERBOSE |
---|
130 | giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() ); |
---|
131 | #endif |
---|
132 | |
---|
133 | // display result |
---|
134 | for ( word = 0 ; word < VECTOR_SIZE ; word++ ) |
---|
135 | { |
---|
136 | giet_tty_printf("pgcd( %d , %d ) = %d\n", |
---|
137 | opa[word] , opb[word] , res[word] ); |
---|
138 | } |
---|
139 | |
---|
140 | // release GCD coprocessor |
---|
141 | giet_coproc_release( cluster_xy, |
---|
142 | coproc_type ); |
---|
143 | |
---|
144 | giet_pthread_exit("completed"); |
---|
145 | |
---|
146 | } // end main |
---|
147 | |
---|