6.4 Assignment: NonLinearOp Component and Driver

Image noteNote

Although you have been looking at the source code in $TUTORIAL_SRC, this exercise should be done in the Bocca project you created in Chapter 3.

$ cd $WORKDIR/demo

In this section, you will use the LinearOp components and driver described earlier as a template to develop a driver and a component that provides the NonLinearOp port. The specification of this port is in $STUDENT_SRC/ports/sidl/arrayop.NonLinearOp.sidl, and is repeated here for convenience.

 /** This port can be used to evaluate a linear matrix operation 
   * of the form
   *  R = Sum[i=1, N] {Alpha_i log(A_i)} + Sum[j=1, N] {Beta_j A_j .* M_j}
   * Where:
   *    alpha_i, Beta_j   Double scalar
   *    A_i, M_j          Double array of size [m, n]
   *    log(A_i)          Elementwise log (base 10) of matrix A_i
   *    A_j .* M_j        Elementwise multiplication of A_j and M_j
   */
   interface NonLinearOp extends gov.cca.Port 
   {
 /** Initialize (or Re-Initialize) internal state in preparation
   * for accumulation.
   */
      void  init();
   
 /** Evaluate Acc = Acc + alpha log(A) where
   *   log(A)  Elementwise log (base 10) of array A
   *   Acc     The internal accumulator maintained by implementors 
   *           of this interafce
   * return the result  in array R
   */
      int logMat (in double                alpha, 
                  in rarray<double, 2>     A(m, n), 
                  inout rarray<double, 2>  R(m, n),
                  in int                   m,
                  in int                   n);
   
 /** Evaluate Acc = Acc + beta A .* M, where 
   *   .*   denotes elementwise multiplications of arrays
   *   Acc  the internal accumulator maintained by implementors 
   *        of this interafce
   * return the result  in array R
   */
      int mulMatMat ( in double            beta,
                      in array<double, 2>  A,  
                      in array<double, 2>  M,  
                      out array<, 2> R);
   
 /** Get result of nonlinear operation accumulation.
   *
      int getResult (inout rarray<double, 2>  R(m, n),
                     in    int                m,
                     in    int                n);
   }

  1. Use Bocca to create your own version of the NonLinearOp port specification by importing the existing definition from $STUDENT_SRC. This can be done using the command:

    $ bocca create port arrayop.NonLinearOp \
    --import-sidl=arrayop.NonLinearOp@\
    $STUDENT_SRC/ports/sidl/arrayop.NonLinearOp.sidl

  2. Next you will create a component that provides the NonLinearOp port using the Bocca command:

    $ bocca create component arrayOps.NonLinearOp \
    --provides=arrayop.NonLinearOp@NonLinearPort \
    --lang=LANG
    where LANG is your development language of choice from the list of languages supported by Babel .

  3. In this step, you will use Bocca to create a driver for the arrayDrivers.NLinearDriver component, using the command:

    $ bocca create component arrayDrivers.NLinearDriver \
    --provides=gov.cca.ports.GoPort@Go \
    --uses=arrayop.NonLinearOp@NonLinearPort --lang=LANG
    where LANG is your development language of choice for the driver.

  4. Edit the newly generated Impl files to implement the methods in the newly created driver component (in the directory components/arrayDrivers.NLinearDriver) and the nonlinear matrix operation component (in the directory components/arrayOps.NonLinearOp). Build the new components (by running  make in the top level directory of your project (this will also build the required port code for the languages you use).

  5. You can run the application using the technique you used in Chapter 2.

2010-08-11