tutorial_lud

This shows you the differences between two versions of the page.

Both sides previous revision Previous revision Next revision | Previous revision | ||

tutorial_lud [2015/03/02 12:09] guillaume Modifying the latex code delete it => old version restored + temp note added |
tutorial_lud [2019/04/05 09:02] (current) sanjay |
||
---|---|---|---|

Line 1: | Line 1: | ||

- | In this tutorial, we write an Alphabets program, starting from a mathematical equation for LU decomposition. alphabets program, and test the generated code for correctness. | + | In this tutorial, we write an Alphabets (or Alpha, for now the two are synonymous) program, starting from a mathematical equation for LU decomposition. alpha program, and test the generated code for correctness. |

The equation for LU Decomposition, | The equation for LU Decomposition, | ||

- | < | + | |

- | $U_{i, | + | /*<*/ |

+ | $$ | ||

+ | U_{i, | ||

1=i\le j & A_{i,j}\\ | 1=i\le j & A_{i,j}\\ | ||

1<i\le j & A_{i, | 1<i\le j & A_{i, | ||

- | \end{cases} | + | \end{cases}\\ |

L_{i, | L_{i, | ||

- | 1=j\le i & \frac{A_{i, | + | 1 = i\le j & \frac{A_{i, |

- | 1<i\le j & \frac{1}{U_{j, | + | 1< i\le j & \frac{1}{U_{j, |

- | \end{cases}$ | + | \end{cases} |

- | </latex> | + | $$ |

+ | /*<\latex>*/ | ||

- | [Temp note: in the last case of L, the condition is "1 < j <= i"] | ||

- | =====Writing Alphabets===== | + | =====Writing Alpha===== |

====Step 1 : Affine System and Parameters ==== | ====Step 1 : Affine System and Parameters ==== | ||

- | Let's start from an empty alphabets file, with LUD as the name of the system, and a positive integer N as its parameter. | + | Let's start from an empty alpha file, with LUD as the name of the system, and a positive integer N as its parameter. |

- | A system (Affine System) takes its name from system of affine recurrence equations, and represents a block of computation. An Alphabets program may contain multiple systems. | + | A system (Affine System) takes its name from system of affine recurrence equations, and represents a block of computation. An Alpha program may contain multiple systems. |

**Caveat: | **Caveat: | ||

Parameters are runtime constants represented with some symbol in the code. In this example, parameter N will be used to define the size of the matrices, which is not known until runtime. | Parameters are runtime constants represented with some symbol in the code. In this example, parameter N will be used to define the size of the matrices, which is not known until runtime. | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

. | . | ||

Line 30: | Line 32: | ||

====Step 2 : Variable Declarations==== | ====Step 2 : Variable Declarations==== | ||

- | In most cases, a computation uses some inputs and produces outputs. Such variables must be declared with a name, a data type, and a shape/Alphabets, the shape/size is represented with polyhedral domains. | + | In most cases, a computation uses some inputs and produces outputs. Such variables must be declared with a name, a data type, and a shape/Alpha, the shape/size is represented with polyhedral domains. |

For this example, the '' | For this example, the '' | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

float A {i, | float A {i, | ||

</ | </ | ||

Similarly, '' | Similarly, '' | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

// The convention is that i is the vertical axis going down, and j is the horizontal axis | // The convention is that i is the vertical axis going down, and j is the horizontal axis | ||

float L {i, | float L {i, | ||

Line 42: | Line 44: | ||

</ | </ | ||

Now these variable declarations need to be placed at appropriate places to specify whether they are input/ | Now these variable declarations need to be placed at appropriate places to specify whether they are input/ | ||

- | '' | + | '''''''''''' |

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

- | given | + | input float A {i, |

- | float A {i, | + | output |

- | returns | + | |

float L {i, | float L {i, | ||

float U {i, | float U {i, | ||

Line 144: | Line 145: | ||

L = case | L = case | ||

| | ||

- | i,i)@U; | + | j,j)@U; |

esac; | esac; | ||

</ | </ | ||

====Final Alphabets Program==== | ====Final Alphabets Program==== | ||

- | Combine all of the above, and you will get the Alphabets program for LU decomposition. Don't forget the keyword '' | + | Combine all of the above, and you will get the Alphabets program for LU decomposition. Don't forget the keyword '''' |

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

- | given | + | input |

float A {i, | float A {i, | ||

- | returns | + | output |

float L {i, | float L {i, | ||

float U {i, | float U {i, | ||

- | through | + | let |

| | ||

{|1==i} : A[i,j]; | {|1==i} : A[i,j]; | ||

Line 170: | Line 171: | ||

Analyses, transformations, | Analyses, transformations, | ||

Given below is an example script for that does several things using the LUD program we wrote above. | Given below is an example script for that does several things using the LUD program we wrote above. | ||

- | <sxh cs; gutter:false> | + | <sxh cs; gutter:true> |

# read program and store the internal representation in variable prog | # read program and store the internal representation in variable prog | ||

prog = ReadAlphabets(" | prog = ReadAlphabets(" | ||

Line 226: | Line 227: | ||

====OOPS WHAT HAPPENED==== | ====OOPS WHAT HAPPENED==== | ||

You will see that when you execute the code, **//it will produce an error// | You will see that when you execute the code, **//it will produce an error// | ||

+ |

tutorial_lud.1425323394.txt.gz · Last modified: 2015/03/02 12:09 by guillaume