source: soft/giet_vm/applications/coproc/coproc.c @ 732

Last change on this file since 732 was 708, checked in by alain, 9 years ago

Adapt the following application to the POSIX threads API

  • convol
  • classif
  • raycast
  • coproc
  • display
  • gameoflife
  • transpose
  • shell
File size: 4.0 KB
Line 
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//  The vectors size is defined by the VECTOR_SIZE parameter.
10///////////////////////////////////////////////////////////////////////////////////////
11
12
13#include "stdio.h"
14#include "mapping_info.h"       // for coprocessors types an modes
15
16#define  VECTOR_SIZE 128   
17
18#define  DMA_MODE    MODE_DMA_IRQ
19
20#define  VERBOSE     1
21
22// Memory buffers for coprocessor
23unsigned int opa[VECTOR_SIZE] __attribute__((aligned(64)));
24unsigned int opb[VECTOR_SIZE] __attribute__((aligned(64)));
25unsigned int res[VECTOR_SIZE] __attribute__((aligned(64)));
26
27/////////////////////////////////////////
28__attribute__ ((constructor)) void main()
29{
30    // get processor identifiers
31    unsigned int    x;
32    unsigned int    y;
33    unsigned int    lpid;
34    giet_proc_xyp( &x, &y, &lpid );
35
36    // get a private TTY terminal
37    giet_tty_alloc( 0 );
38
39    giet_tty_printf("\n*** Starting coproc application on processor"
40                    "[%d,%d,%d] at cycle %d\n", 
41                    x, y, lpid, giet_proctime() );
42
43    // initializes opa & opb buffers
44    unsigned int word;
45    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
46    {
47        opa[word] = giet_rand() + 1;
48        opb[word] = giet_rand() + 1;
49    }
50
51    unsigned int coproc_info;
52
53    /////////////////////// request a GCD coprocessor
54    giet_coproc_alloc( MWR_SUBTYPE_GCD, &coproc_info );
55
56    // check coprocessor ports
57    unsigned int nb_to_coproc   = (coproc_info    ) & 0xFF;
58    unsigned int nb_from_coproc = (coproc_info>> 8) & 0xFF;
59    unsigned int nb_config      = (coproc_info>>16) & 0xFF;
60    unsigned int nb_status      = (coproc_info>>24) & 0xFF;
61    giet_pthread_assert( ((nb_to_coproc   == 2) &&
62                         (nb_from_coproc == 1) &&
63                         (nb_config      == 1) &&
64                         (nb_status      == 0) ) ,
65                         "wrong GCD coprocessor interface" );
66
67#if  VERBOSE
68giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
69#endif
70
71    //////////////////////// initializes channel for OPA
72    giet_coproc_channel_t opa_desc;
73    opa_desc.channel_mode = DMA_MODE;
74    opa_desc.buffer_size  = VECTOR_SIZE<<2;
75    opa_desc.buffer_vaddr = (unsigned int)opa;
76    giet_coproc_channel_init( 0 , &opa_desc );
77   
78    //////////////////////// initializes channel for OPB
79    giet_coproc_channel_t opb_desc;
80    opb_desc.channel_mode = DMA_MODE;
81    opb_desc.buffer_size  = VECTOR_SIZE<<2;
82    opb_desc.buffer_vaddr = (unsigned int)opb;
83    giet_coproc_channel_init( 1 , &opb_desc );
84   
85    //////////////////////// initializes channel for RES
86    giet_coproc_channel_t res_desc;
87    res_desc.channel_mode = DMA_MODE;
88    res_desc.buffer_size  = VECTOR_SIZE<<2;
89    res_desc.buffer_vaddr = (unsigned int)res;
90    giet_coproc_channel_init( 2 , &res_desc );
91   
92#if  VERBOSE
93giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
94#endif
95
96    /////////////////////// starts communication channels
97    giet_coproc_run( 0 );
98
99#if  VERBOSE
100giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
101#endif
102
103    /////////////////////// wait coprocessor completion
104    if ( DMA_MODE == MODE_DMA_NO_IRQ )
105    {
106        giet_coproc_completed( );
107    }
108
109#if  VERBOSE
110giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
111#endif
112
113    // display result
114    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
115    {
116        giet_tty_printf("pgcd( %d , %d ) = %d\n",
117        opa[word] , opb[word] , res[word] );
118    }
119
120    ////////////////////// release GCD coprocessor
121    giet_coproc_release( 0 );
122
123    giet_pthread_exit("completed");
124
125} // end main
126
Note: See TracBrowser for help on using the repository browser.