User Tools

Site Tools


Sidebar

<menu col=1,align=center>

<item>Documentation||[[lara:documentation]]|{{:lara:img:dictionary.png?25}}</item>
<item>Downloads||[[lara:downloads]]| {{:lara:img:projects.png?25}}</item>
<item>Tutorials||[[lara:tutorial]]|{{:lara:img:books.png?25}}</item>
<item>Other uses of LARA||[[lara:other]]|{{:lara:img:globe.png?25}}</item>
<item>About Us||[[https://sites.google.com/site/specsfeup/]]| {{:lara:img:specslogo.png?25}}</item>
<item>Projects||[[lara:usage]]| {{:lara:img:math.png?25}}</item>

</menu>

/* They are empty */ /* <item>FAQ||faq|</item> */ /* <item>Dev. Team||team| </item> */ /* <item>About LARA||about|</item> */

lara:docs:sheet

This is an old revision of the document!


LARA Fundamentals

Aspects

Aspectdef definition

aspectdef MyFirstAspect // The main aspect is the first declared in the file
   // aspect code
end
 
aspectdef ASecondAspect // An aspect that can be called in the main aspect
   // aspect code
end

Select

Select with full join point chain:

select program.file.function.body.loop end

Select with only last join point. The chain is induced, produces the same result as above:

select loop end

Assign the selected join points to a variable for later use:

LOOPS: select loop end

Assign an alias for specific join points:

select ($p=loop).($c=loop) end

Apply

Apply after a select:

select loop end
apply
    println($loop.rank);
end

Apply on a previously selected set of join points:

apply to LOOPS
    println($loop.rank);
end

It is possible to perform a natural join on two sets of join points:

LOOP_START: 	select function.body.loop.($loop_start = first) end
FUNCTION_FIRST: select function.body.first end
 
apply to LOOP_START::FUNCTION_FIRST  
    // Init counters at the beginning of the function
    $first.insert before%{counter_[[$loop.uid]] = 0;}%;
 
    // Increment counters when entering the loop
    $loop_start.insert before%{counter_[[$loop.uid]] = counter_[[$loop.uid]] +1;}%;
 
    // ...
end

Use of join points with aliases inside the apply statement:

select ($p=loop).($c=loop) end
apply
   $p.exec Interchange($c);
end

Conditions

Using a condition block:

select function end
apply
    // ...
end
condition
    $function.name == 'kernel'
end

Combining conditions using && (and) and || (or) operators:

select loop end
apply
    $loop.exec Unroll(2);
end
condition
    $loop.is_innermost &&
    $loop.type=="for"
end

Using “filter” conditions on the join point chain:

select function{name=='kernel'} end
apply
    // ...
end
 
// OR
select function{'kernel'} end // uses the default attribute of the join point
apply
    // ...
end

Aspect Inputs and Outputs

Input parameter definition:

input
    funcs,
    opt
end

Input parameter definition with default values:

input
    funcs = ['kernel'],
    opt = ['unroll', 'interchange', 'tile']
end

Output definition. Output cannot be initialized inside the output block:

output
    optFuncs,
    code
end
 
optFuncs = [];
code = '';

Calling Aspects

Simple aspect call:

call OptimizeProgram();

Calling an aspect with arguments:

call OptimizeFunctions(functions, optimizations);

Calling an aspect with named arguments:

call OptimizeFunctions(opt: optimizations, funcs: ['gridIterate']);

Calling an aspect and retrieving the outputs:

call optimizer: OptimizeFunctions(functions, optimizations);
 
var changedFuncs = optimizer.optFuncs;
var finalCode = optimizer.code;

Assigning an aspect call to a variable for later use. Can still use input arguments and outputs as shown before:

var optimizer = new OptimizeFunctions(functions, optimizations);
 
call optimizer();
 
var changedFuncs = optimizer.optFuncs;
var finalCode = optimizer.code;

Using LARA Actions

Actions are used inside apply statements. There are two default actions, insert and def. Then, it is possible to use weaver-specific actions, which are called with the exec keyword:

select function{'kernel'} end
apply
    insert before '/* Creating a clone. */';  // add a comment before the function
    def name = 'original_kernel';  // redefine the name of the kernel function
    exec clone('cloned_kernel');  // use a MANET-specific action to create a 'kernel' clone named 'cloned_kernel'
end

When calling an action we can specify any join point in the chain to be the action target:

select function.loop end
apply
    $loop.exec tile(8);
    $function.insert before '/* This function was transformed. */';
end

It is possible to omit the target, the last join point in the chain is used:

select function.loop end
apply
    exec unroll(2);  // performed on the same loop as below
    $loop.exec tile(8);  // performed on the same loop as above
end
lara/docs/sheet.1471432169.txt.gz · Last modified: 2019/09/22 15:46 (external edit)