User Tools

Site Tools


Schedule Code Generator

Given an affine system and a target mapping, this page shows how to generate the scheduled code based on the given target mapping.


For the Alphabets program for matrix product.

affine matrix_product {P, Q, R|P>0 && Q>0 && R>0}
       given  float A {i,k| 0<=i<P && 0<=k<Q};
              float B {k,j| 0<=k<Q && 0<=j<R}; 
     returns  float C {i,j,k| 0<=i<P && 0<=j<R && k==Q};
   float temp_C {i,j,k|0<=i<P && 0<=j<R && 0<=k<=Q};
   temp_C[i,j,k] = case
                      {|k>0}  : temp_C[i,j,k-1] + A[i,k-1]*B[k-1,j];
                      {|k==0} : 0; 
   C      = temp_C;

The following commands will generate the scheduled code based on the given target mapping.

# Load an alphabets program and store as 'program'
program = ReadAlphabets("../../alphabets/matrix_product.ab");
# Define a variable 'system' to store the system name
system = "matrix_product";
# Specify the output directory
outDir = "../../test-out/scheduleC/";

# Set the target mapping as described in the target mapping section[[Target Mapping]]
setSpaceTimeMap(program, system, "temp_C",  "(i,j,k->i,j,k)");
setSpaceTimeMap(program, system, "C",  "(i,j,k->i,j,k)");
# Ser first and second dimension to be parallel (or generate sequential code by no parallel specification)
setParallel(prog, system, "", "0,1");

# Set the statement ordering
setStatementOrdering(program, system, "temp_C", "C");

# Set the memory map
setMemoryMap(program, system, "temp_C", "matrix_product",  "(i,j,k->i,j)");

# Generate scheduled code according to the target mapping
generateScheduledCode(program, system, outDir);

# Generate the makefile
generateMakefile(program, system, outDir);

# Generate the wrapper to call the generated program
generateWrapper(program, system, outDir);
A Makefile, matrix_product.c and matrix_product-wrapper.c are generated for the above example.
Use the Makefile to compile the 'C' files.

schedule_code_generator.txt · Last modified: 2017/04/19 14:17 by waruna