[533] | 1 | #include "stdio.h" |
---|
| 2 | #include "mapping_info.h" // for coprocessors types an modes |
---|
| 3 | |
---|
| 4 | #define VECTOR_SIZE 32 |
---|
| 5 | |
---|
| 6 | #define VERBOSE 1 |
---|
| 7 | |
---|
| 8 | // Memory buffers for coprocessor |
---|
| 9 | unsigned int opa[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
| 10 | unsigned int opb[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
| 11 | unsigned int res[VECTOR_SIZE] __attribute__((aligned(64))); |
---|
| 12 | |
---|
| 13 | ///////////////////////////////////////// |
---|
| 14 | __attribute__ ((constructor)) void main() |
---|
| 15 | { |
---|
| 16 | // get processor identifiers |
---|
| 17 | unsigned int x; |
---|
| 18 | unsigned int y; |
---|
| 19 | unsigned int lpid; |
---|
| 20 | giet_proc_xyp( &x, &y, &lpid ); |
---|
| 21 | |
---|
| 22 | giet_shr_printf("\n*** Starting coproc application on processor" |
---|
| 23 | "[%d,%d,%d] at cycle %d\n", |
---|
| 24 | x, y, lpid, giet_proctime() ); |
---|
| 25 | |
---|
| 26 | // initializes opa & opb buffers |
---|
| 27 | unsigned int word; |
---|
| 28 | for ( word = 0 ; word < VECTOR_SIZE ; word++ ) |
---|
| 29 | { |
---|
| 30 | opa[word] = giet_rand() + 1; |
---|
| 31 | opb[word] = giet_rand() + 1; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | // request a GCD coprocessor |
---|
| 35 | unsigned int coproc_info; |
---|
| 36 | unsigned int cluster_xy; |
---|
| 37 | |
---|
| 38 | giet_coproc_alloc( MWR_SUBTYPE_GCD, |
---|
| 39 | &coproc_info, |
---|
| 40 | &cluster_xy ); |
---|
| 41 | |
---|
| 42 | // check coprocessor ports |
---|
| 43 | unsigned int nb_to_coproc = (coproc_info ) & 0xFF; |
---|
| 44 | unsigned int nb_from_coproc = (coproc_info>> 8) & 0xFF; |
---|
| 45 | unsigned int nb_config = (coproc_info>>16) & 0xFF; |
---|
| 46 | unsigned int nb_status = (coproc_info>>24) & 0xFF; |
---|
| 47 | |
---|
| 48 | giet_assert( ((nb_to_coproc == 2) && |
---|
| 49 | (nb_from_coproc == 1) && |
---|
| 50 | (nb_config == 1) && |
---|
| 51 | (nb_status == 0) ) , |
---|
| 52 | "wrong GCD coprocessor interface" ); |
---|
| 53 | |
---|
| 54 | if ( VERBOSE ) |
---|
| 55 | giet_shr_printf("\n*** get GCD coprocessor at cycle %d\n", |
---|
| 56 | giet_proctime() ); |
---|
| 57 | |
---|
| 58 | // initializes communication channels |
---|
| 59 | giet_coproc_channel_t desc; |
---|
| 60 | |
---|
| 61 | desc.channel_mode = MODE_DMA_NO_IRQ; |
---|
| 62 | desc.buffer_size = VECTOR_SIZE<<2; |
---|
| 63 | desc.buffer_vaddr = (unsigned int)opa; |
---|
| 64 | |
---|
| 65 | giet_coproc_channel_init( cluster_xy , 0 , &desc ); |
---|
| 66 | |
---|
| 67 | desc.channel_mode = MODE_DMA_NO_IRQ; |
---|
| 68 | desc.buffer_size = VECTOR_SIZE<<2; |
---|
| 69 | desc.buffer_vaddr = (unsigned int)opb; |
---|
| 70 | |
---|
| 71 | giet_coproc_channel_init( cluster_xy , 1 , &desc ); |
---|
| 72 | |
---|
| 73 | desc.channel_mode = MODE_DMA_IRQ; |
---|
| 74 | desc.buffer_size = VECTOR_SIZE<<2; |
---|
| 75 | desc.buffer_vaddr = (unsigned int)res; |
---|
| 76 | |
---|
| 77 | giet_coproc_channel_init( cluster_xy , 2 , &desc ); |
---|
| 78 | |
---|
| 79 | if ( VERBOSE ) |
---|
| 80 | giet_shr_printf("\n*** initialise coomunication channels at cycle %d\n", |
---|
| 81 | giet_proctime() ); |
---|
| 82 | |
---|
| 83 | // starts communication channels |
---|
| 84 | giet_coproc_channel_start( cluster_xy , 0 ); |
---|
| 85 | giet_coproc_channel_start( cluster_xy , 1 ); |
---|
| 86 | giet_coproc_channel_start( cluster_xy , 2 ); |
---|
| 87 | |
---|
| 88 | if ( VERBOSE ) |
---|
| 89 | giet_shr_printf("\n*** start communication channels at cycle %d\n", |
---|
| 90 | giet_proctime() ); |
---|
| 91 | |
---|
| 92 | // starts GCD coprocessor |
---|
| 93 | giet_coproc_register_set( cluster_xy , 0 , 1 ); |
---|
| 94 | |
---|
| 95 | if ( VERBOSE ) |
---|
| 96 | giet_shr_printf("\n*** start GCD coprocessor at cycle %d\n", |
---|
| 97 | giet_proctime() ); |
---|
| 98 | |
---|
| 99 | // wait coprocessor completion |
---|
| 100 | giet_coproc_completed( cluster_xy ); |
---|
| 101 | |
---|
| 102 | if ( VERBOSE ) |
---|
| 103 | giet_shr_printf("\n*** GCD computation completed at cycle %d\n", |
---|
| 104 | giet_proctime() ); |
---|
| 105 | |
---|
| 106 | // display result |
---|
| 107 | for ( word = 0 ; word < VECTOR_SIZE ; word++ ) |
---|
| 108 | { |
---|
| 109 | giet_shr_printf("pgcd( %d , %d ) = %d\n", |
---|
| 110 | opa[word] , opb[word] , res[word] ); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | giet_exit("completed"); |
---|
| 114 | |
---|
| 115 | } // end main |
---|
| 116 | |
---|