schedule_code_generator_for_code_with_subsystem

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

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

schedule_code_generator_for_code_with_subsystem [2014/07/07 14:04] yun [Example program with subsystem] |
schedule_code_generator_for_code_with_subsystem [2017/04/19 13:31] (current) |
||
---|---|---|---|

Line 1: | Line 1: | ||

======Schedule Code Generator for SubSystem====== | ======Schedule Code Generator for SubSystem====== | ||

Given an affine system with subsystems/ | Given an affine system with subsystems/ | ||

- | ====Example program with subsystem==== | + | ====Matrix Multiplication with subsystem==== |

The following code is the alpha program for matrix matrix multiplication with dot-product subsystem. | The following code is the alpha program for matrix matrix multiplication with dot-product subsystem. | ||

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

affine matrix_product_SubSyst {N,K,M | N>0 && K>0 && M > 0} // Product between a N*K matrix and a K*M matrix | affine matrix_product_SubSyst {N,K,M | N>0 && K>0 && M > 0} // Product between a N*K matrix and a K*M matrix | ||

input | input | ||

Line 35: | Line 35: | ||

The program contains two systems. The dot_product system takes two vectors as inputs and computes the doc product of these two vectors. The matrix_product_SubSyst computes matrix C=A*B, the (ip,jp)th element for the answer matrix C is computed by calling the dot product subsystem, and the (ip)th row of A, and (jp)th column of B is passed as input to the subsystem call. | The program contains two systems. The dot_product system takes two vectors as inputs and computes the doc product of these two vectors. The matrix_product_SubSyst computes matrix C=A*B, the (ip,jp)th element for the answer matrix C is computed by calling the dot product subsystem, and the (ip)th row of A, and (jp)th column of B is passed as input to the subsystem call. | ||

+ | ====TargetMapping for the Matrix Multiplication Example==== | ||

+ | The schedule code generator treats every subsystem call (an instance of the subsystem) as an function call in C. In order to ensure the correctness of the code, each instance of the subsystem call is attached with three special statement by default. The three statements are memory allocation statement, value copy statement and memory free statement. The memory allocation statement allocates a temporary variable for the corresponding input, and the value copy statement copies the corresponding values into the temporary variable before it is passed into the function call, and the memory free statement frees the memory when the temproary is not useful. | ||

+ | |||

+ | In order for schedule code generator to generate the code, other than specify the schedule for the useEquation, | ||

+ | |||

+ | The following command set the SpaceTimeMap for the (n)th input/ | ||

+ | <sxh cs; gutter: | ||

+ | setSpaceTimeMapForUseEquationOptimization(program, | ||

+ | </ | ||

+ | The parameter isInput sepcifies whether the SpaceTimeMap is specified for input or not, and the last three prarameter specifies the space time map for the three special statement attached to the current input/ | ||

+ | <sxh cs; gutter: | ||

+ | setSpaceTimeMapForMemoryAllocation(program, | ||

+ | setSpaceTimeMapForValueCopy(program, | ||

+ | setSpaceTimeMapForMemoryFree(program, | ||

+ | </ | ||

+ | |||

+ | The following script consists all the commands that specifies the TargetMapping for the matrix multiplication example and generates the code. | ||

+ | <sxh cs; gutter: | ||

+ | prog = ReadAlphabets(" | ||

+ | rootSystem = " | ||

+ | subSystem = " | ||

+ | outDir = " | ||

+ | CheckProgram(prog); | ||

+ | |||

+ | #set the spacetimeMap for the subSystem first | ||

+ | setSpaceTimeMap(prog, | ||

+ | setSpaceTimeMap(prog, | ||

+ | |||

+ | #the identification lable for the useEquation | ||

+ | label = " | ||

+ | |||

+ | #set the spacetimeMap for the rootSystem | ||

+ | #set the spacetimeMap for the main subsystem call | ||

+ | setSpaceTimeMap(prog, | ||

+ | |||

+ | #set the SpaceTimeMap for the first input of the useEquation | ||

+ | setSpaceTimeMapForMemoryAllocation(prog, | ||

+ | setSpaceTimeMapForValueCopy(prog, | ||

+ | setSpaceTimeMapForMemoryFree(prog, | ||

+ | |||

+ | #set the SpaceTimeMap for the second input of the useEquation | ||

+ | setSpaceTimeMapForUseEquationOptimization(prog, | ||

+ | |||

+ | #set the spaceTimeMap for the first output of the useEquation | ||

+ | setSpaceTimeMapForUseEquationOptimization(prog, | ||

+ | |||

+ | #command for generating the code | ||

+ | generateScheduledCode(prog, | ||

+ | generateWrapper(prog, | ||

+ | generateMakefile(prog, | ||

+ | </ | ||

+ | |||

+ | ====TargetMapping for Optimization==== | ||

+ | The schedule code generator generates three special statements for each input/ | ||

+ | by the <iP, jP>th instance of the use equation. Assume that the memory for matrix A, B and C are all allocated in row-wise major, the < | ||

+ | |||

+ | The following command is the command that specifies the optimization for the first input of the useEquation C. | ||

+ | <sxh cs; gutter: | ||

+ | setMemorySpaceForUseEuqationOptimization(prog, | ||

+ | </ | ||

+ | The code generated passes the corresponding pointer of A is passed into the function call. | ||

schedule_code_generator_for_code_with_subsystem.1404763468.txt.gz ยท Last modified: 2014/07/07 14:04 by yun