Пример #1
0
def deptest_cm_ic(filename):
    print("CM-IC Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim  = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        
        xf1 = Transformation(
            name         = 'cm',
            in_dim       = in_dim,
            out_dim      = out_dim,
            in_dim_type  = in_dim_type,
            in_alp       = in_alp,
            in_ord       = in_ord,
            out_ord      = out_ord)

        # interchange
        dim1_ = 0
        dim2_ = 1

        xf2 = Transformation(
            name         ='ic',
            in_dim       = xf1.out_dim,
            out_dim      = xf1.out_dim,
            in_dim_type  = xf1.out_dim_type,
            in_alp       = xf1.out_alp,
            in_ord       = xf1.out_ord,
            dim_i1       = dim1_,
            dim_i2       = dim2_)

        xf = xf1.compose(xf2)

        xform.analyze.depanalyze()
        
        print(xform.analyze.deps)
        for i, wt in enumerate(xform.analyze.deps):
            Dep = Dependence(wt)
            print("Witness Tuple", i, ": ", Dep.test(xf))
Пример #2
0
def completion_test(filename):
    print("Completion Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        dim = xform.analyze.dims
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # partial order
        partial1 = [['t', 'r'], ['s', 'r', 'r']] # potential cm
        partial2 = [['r', 't'], ['s', 'r', 'r']] # potential cm-cm
        partial3 = [['t', 'r', 'r'], ['s', 'r']] # potential cm-ic

        print("\nCompletion 1")
        comp1 = Completion(dim, in_dim_type, in_alp, in_ord, partial1, [Dependence(wt) for wt in xform.analyze.deps])
        comp1.checks()
        comp1.print_report()
        comp1.completion_search()
        comp1.print_pxforms()
        comp1.completion_valid()
        comp1.print_vxforms()

        print("\nCompletion 2")
        comp2 = Completion(dim, in_dim_type, in_alp, in_ord, partial2, [Dependence(wt) for wt in xform.analyze.deps])
        comp2.checks()
        comp2.print_report()
        comp2.completion_search()
        comp2.print_pxforms()
        comp2.completion_valid()
        comp2.print_vxforms()

        print("\nCompletion 3")
        comp3 = Completion(dim, in_dim_type, in_alp, in_ord, partial3, [Dependence(wt) for wt in xform.analyze.deps])
        comp3.checks()
        comp3.print_report()
        comp3.completion_search()
        comp3.print_pxforms()
        comp3.completion_valid()
        comp3.print_vxforms()
Пример #3
0
def ic_test(filename):
    print("Interchange Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Transform
        xf = Transformation(name='ic',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            dim_i1=0,
                            dim_i2=1)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Пример #4
0
def deptest_ic(filename):
    print("Interchange Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim  = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()

        xf = Transformation(
            name         ='ic',
            in_dim       = in_dim,
            out_dim      = out_dim,
            in_dim_type  = in_dim_type,
            in_alp       = in_alp,
            in_ord       = in_ord,
            dim_i1       = 0,
            dim_i2       = 1)
    
        xform.analyze.depanalyze()
        print(xform.analyze.getdeps())
        for i, wt in enumerate(xform.analyze.deps):
            Dep = Dependence(wt)
            print("Witness Tuple", i, ": ", Dep.test(xf))
Пример #5
0
def sm_test(filename):
    print("Strip Mining Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim + 1
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # strip dimension
        strip_dim = 0
        # strip size
        strip_size = 2
        # Transform
        xf = Transformation(name='sm',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            dim_strip=strip_dim,
                            strip_size=strip_size)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Пример #6
0
def cm_test(filename):
    print("Code Motion Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        # Transform
        xf = Transformation(name='cm',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            out_ord=out_ord)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Пример #7
0
def cm_sm_ic_test(filename):
    print("CM-SM-IC Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())

        # code-motion
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        xf1 = Transformation(name='cm',
                             in_dim=in_dim,
                             out_dim=out_dim,
                             in_dim_type=in_dim_type,
                             in_alp=in_alp,
                             in_ord=in_ord,
                             out_ord=out_ord)
        xform.transform(xf1)

        # strip mining
        # strip dimension
        strip_dim = 0
        # strip size
        strip_size = 2
        # Transform
        xf2 = Transformation(name='sm',
                             in_dim=xf1.out_dim,
                             out_dim=xf1.out_dim + 1,
                             in_dim_type=xf1.in_dim_type,
                             in_alp=xf1.out_alp,
                             in_ord=xf1.out_ord,
                             dim_strip=strip_dim,
                             strip_size=strip_size)
        xform.transform(xf2)

        # interchange
        # dimensions
        dim1 = 1
        dim2 = 2
        xf3 = Transformation(name='ic',
                             in_dim=xf2.out_dim,
                             out_dim=xf2.out_dim,
                             in_dim_type=xf2.out_dim_type,
                             in_alp=xf2.out_alp,
                             in_ord=xf2.out_ord,
                             dim_i1=dim1,
                             dim_i2=dim2)
        xform.transform(xf3)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())