5.4. Assignment: NonLinearOp Component and Driver

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 can be found in the SIDL file $TUTORIAL_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);
   }

Note that you can continue to work in the project directory created earlier, or you can create a new project just for this exercise, since it does not rely on any of the components developed earlier in the tutorial.

  1. Create NonLinearOp port

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

    
    bocca create port arrayop.NonLinearOp \
    --import-sidl=arrayop.NonLinearOp:$TUTORIAL_SRC/ports/sidl/arrayop.NonLinearOp.sidl
    
  2. Create arrayOps.NonLinearOp component

    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. Create arrayDrivers.NLinearDriver component

    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 components implementation file(s)

    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. Running the New NonLinearOp Component Application

    You can run the application using the technique you used in Chapter 2, Assembling and Running a CCA Application.