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

Last change on this file since 762 was 736, checked in by alain, 9 years ago

Modify the mjpeg application to support an optional
DCT hardware coprocessor.

File size: 4.7 KB
RevLine 
[736]1/////////////////////////////////////////////////////////////////////////////////////
[708]2//  file   : coproc.c
[555]3//  date   : avril 2015
4//  author : Alain Greiner
[736]5/////////////////////////////////////////////////////////////////////////////////////
[555]6//  This file describes the single thread "coproc" application.
[708]7//  It uses the GCD (Greater Common Divider) hardware coprocessor
8//  to make the GCD computation between two vectors of 32 bits integers.
[736]9//  It supports two coprocessor operating modes: MODE_DMA_IRQ or MODE_DMA_NO_IRQ.
[555]10//  The vectors size is defined by the VECTOR_SIZE parameter.
[736]11/////////////////////////////////////////////////////////////////////////////////////
[555]12
13
[533]14#include "stdio.h"
[589]15#include "mapping_info.h"       // for coprocessors types an modes
[533]16
[555]17#define  VECTOR_SIZE 128   
[533]18
[555]19#define  DMA_MODE    MODE_DMA_IRQ
[533]20
[708]21#define  VERBOSE     1
[555]22
[533]23// Memory buffers for coprocessor
24unsigned int opa[VECTOR_SIZE] __attribute__((aligned(64)));
25unsigned int opb[VECTOR_SIZE] __attribute__((aligned(64)));
26unsigned 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
[669]37    // get a private TTY terminal
38    giet_tty_alloc( 0 );
39
40    giet_tty_printf("\n*** Starting coproc application on processor"
[533]41                    "[%d,%d,%d] at cycle %d\n", 
42                    x, y, lpid, giet_proctime() );
43
[736]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
[533]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;
[736]57    unsigned int cluster_xy  = (x << 4) + y;
58    unsigned int coproc_type = MWR_SUBTYPE_GCD;
[533]59
[736]60    // get a GCD coprocessor in local cluster
61    giet_coproc_alloc( cluster_xy,
62                       coproc_type,
63                       &coproc_info );
[533]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;
[708]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" );
[533]75
[708]76#if  VERBOSE
[669]77giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
[708]78#endif
[533]79
[736]80    // initializes OPA channel
[555]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;
[736]85    giet_coproc_channel_init( cluster_xy,
86                              coproc_type,
87                              0, 
88                              &opa_desc );
[533]89   
[736]90    // initializes OPB channel
[555]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;
[736]95    giet_coproc_channel_init( cluster_xy,
96                              coproc_type,
97                              1, 
98                              &opb_desc );
[533]99   
[736]100    // initializes RES channel
[555]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;
[736]105    giet_coproc_channel_init( cluster_xy,
106                              coproc_type,
107                              2, 
108                              &res_desc );
[533]109   
[708]110#if  VERBOSE
[669]111giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
[708]112#endif
[533]113
[736]114    // starts coprocessor
115    giet_coproc_run( cluster_xy,
116                     coproc_type );
[533]117
[708]118#if  VERBOSE
[669]119giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
[708]120#endif
[533]121
[736]122    // wait coprocessor completion
[555]123    if ( DMA_MODE == MODE_DMA_NO_IRQ )
124    {
[736]125        giet_coproc_completed( cluster_xy,
126                               coproc_type );
[555]127    }
[533]128
[708]129#if  VERBOSE
[669]130giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
[708]131#endif
[533]132
133    // display result
134    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
135    {
[669]136        giet_tty_printf("pgcd( %d , %d ) = %d\n",
[533]137        opa[word] , opb[word] , res[word] );
138    }
139
[736]140    // release GCD coprocessor
141    giet_coproc_release( cluster_xy,
142                         coproc_type );
[555]143
[708]144    giet_pthread_exit("completed");
[533]145
146} // end main
147
Note: See TracBrowser for help on using the repository browser.