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

Last change on this file since 721 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
RevLine 
[555]1///////////////////////////////////////////////////////////////////////////////////////
[708]2//  file   : coproc.c
[555]3//  date   : avril 2015
4//  author : Alain Greiner
5///////////////////////////////////////////////////////////////////////////////////////
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.
[555]9//  The vectors size is defined by the VECTOR_SIZE parameter.
10///////////////////////////////////////////////////////////////////////////////////////
11
12
[533]13#include "stdio.h"
[589]14#include "mapping_info.h"       // for coprocessors types an modes
[533]15
[555]16#define  VECTOR_SIZE 128   
[533]17
[555]18#define  DMA_MODE    MODE_DMA_IRQ
[533]19
[708]20#define  VERBOSE     1
[555]21
[533]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
[669]36    // get a private TTY terminal
37    giet_tty_alloc( 0 );
38
39    giet_tty_printf("\n*** Starting coproc application on processor"
[533]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
[555]53    /////////////////////// request a GCD coprocessor
54    giet_coproc_alloc( MWR_SUBTYPE_GCD, &coproc_info );
[533]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;
[708]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" );
[533]66
[708]67#if  VERBOSE
[669]68giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
[708]69#endif
[533]70
[555]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 );
[533]77   
[555]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 );
[533]84   
[555]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 );
[533]91   
[708]92#if  VERBOSE
[669]93giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
[708]94#endif
[533]95
[555]96    /////////////////////// starts communication channels
97    giet_coproc_run( 0 );
[533]98
[708]99#if  VERBOSE
[669]100giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
[708]101#endif
[533]102
[555]103    /////////////////////// wait coprocessor completion
104    if ( DMA_MODE == MODE_DMA_NO_IRQ )
105    {
106        giet_coproc_completed( );
107    }
[533]108
[708]109#if  VERBOSE
[669]110giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
[708]111#endif
[533]112
113    // display result
114    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
115    {
[669]116        giet_tty_printf("pgcd( %d , %d ) = %d\n",
[533]117        opa[word] , opb[word] , res[word] );
118    }
119
[555]120    ////////////////////// release GCD coprocessor
121    giet_coproc_release( 0 );
122
[708]123    giet_pthread_exit("completed");
[533]124
125} // end main
126
Note: See TracBrowser for help on using the repository browser.