Example #1
0
def fs_rk1(rel, SIMPLIFY, indt):

    rk = rel.power()  #Rk
    if (rk[1] == 0):
        print "rk approximated..."
    rk = rk[0].coalesce()
    #print rk

    rk = isl.Map(iscc.RepairRk(str(rk), 0))  # przesun k do symb

    print "RK"
    print rk
    uds = rel.domain().subtract(rel.range()).coalesce()

    # ADD INDEPENDENT TILES TO UDS
    #uds = uds.union(indt).coalesce()

    print "UDS"
    print uds

    rel_plus = rel.transitive_closure()[0]
    sk = uds.apply(rk).subtract(uds.apply(rk).apply(rel_plus)).coalesce()

    sk = sk.insert_dims(isl.dim_type.set, 0, 1)
    sk = sk.set_dim_name(isl.dim_type.set, 0, "ink")

    c = isl.Constraint.eq_from_names(sk.get_space(), {"k": -1, "ink": 1})
    sk = sk.add_constraint(c)
    sk = tiling_v3.Project(sk, ["k"])

    uds = uds.insert_dims(isl.dim_type.set, 0, 1)
    uds = uds.set_dim_name(isl.dim_type.set, 0, "ink")

    c = isl.Constraint.eq_from_names(sk.get_space(), {1: 0, "ink": 1})
    uds = uds.add_constraint(c)

    #x = isl.Set("{ [0, 0, 0, 6]}")
    #uds = uds.union(x).coalesce()

    print "TUDS"
    print uds

    sk = sk.union(uds).coalesce()

    if (SIMPLIFY):
        sk = imperf_tile.SimplifySlice(sk)

    return sk
Example #2
0
def tile_par(isl_TILEprim, isl_TILEbis, sym_exvars, symb, isl_rel, isl_relplus,
             isl_relclosure):

    nloop = ""
    srepr = ""
    with open('sources_of_slices.txt') as f:
        content = f.readlines()
        srepr = content[0]

    srepr = isl.Set(srepr)

    srepr = srepr.insert_dims(isl.dim_type.set, 0, len(sym_exvars))
    for i in range(0, len(sym_exvars)):
        srepr = srepr.set_dim_name(isl.dim_type.set, i, sym_exvars[i])

    Rel_Z = "{["
    for i in range(0, 2 * len(sym_exvars)):
        Rel_Z = Rel_Z + "i" + str(i) + ","
    Rel_Z = Rel_Z + "m] -> ["
    for i in range(0, len(sym_exvars)):
        Rel_Z = Rel_Z + "i" + str(i) + ","
    Rel_Z = Rel_Z[:-1] + "] };"

    Rel_Z = isl.Map(Rel_Z)

    Bis_Combo = isl_TILEbis[0]
    for j in range(1, len(isl_TILEbis)):
        Bis_Combo = Bis_Combo.union(isl_TILEbis[j]).coalesce()

    TILE_SOUR = Bis_Combo.intersect(srepr).coalesce()
    print TILE_SOUR

    fs = 0
    if (TILE_SOUR.lexmax() == TILE_SOUR.lexmin()):
        print "FS"
        fs = 1
    else:
        print "SLICING"

    rplus = tiling_v3.ExtendMap(isl_relplus, sym_exvars)
    rstar = tiling_v3.ExtendMap(isl_relclosure, sym_exvars)
    rt_red = tiling_v3.ExtendMap(isl_rel, sym_exvars)

    rs = isl.Map.from_domain_and_range(Bis_Combo, Bis_Combo)

    rs = rs.intersect(rplus)
    rt_red = rs.intersect(rs)

    if (fs != 1):
        z = TILE_SOUR.apply(Rel_Z)

        srepr_loop = iscc.iscc_communicate("L :=" + str(z) + "; codegen L;")

        rs = iscc.iscc_communicate(str(rs) + ";", 1).split('\n')[0]
        rs = iscc.RelationExists(rs, len(sym_exvars), symb)

        srepr_loop = srepr_loop.split('\n')

        for i in range(0, len(srepr_loop)):
            if "for" in srepr_loop[i]:
                srepr_loop.insert(i, "#pragma omp parallel for")
                break

        st_reg = re.compile('\s*\(.*\);')
        vecs = []
        taby = []
        for line in srepr_loop:
            if (st_reg.match(line)):
                vecs.append(iscc.s1_to_vec(line, len(vecs)))
                taby.append(iscc.correct.whites(line))

        #R_T = iscc_communicate("RS := " + rs + ";RS;")
        cmd = "RT :=" + rs + ";"
        for i in range(0, len(vecs)):
            cmd = cmd + vecs[i] + "codegen RT(S" + str(i) + ');print "###";'

        cmd = iscc.iscc_communicate(cmd)

        cmd = cmd.split('"###"')
        new_loop = []
        i = 0
        for line in srepr_loop:
            if (st_reg.match(line)):
                petla = cmd[i].split('\n')
                for s in petla:
                    new_loop.append(taby[i] + s)
                i = i + 1
            else:
                new_loop.append(line)

        #print new_loop

        nloop = ""
        for line in new_loop:
            if line != '':
                nloop = nloop + line + "\n"
        nloop = nloop[:-1]

        isl_TILEprim_ = isl_TILEprim[0].union(isl_TILEprim[1])

        bl_2half = iscc.iscc_communicate("L :=" + str(isl_TILEprim[0]) +
                                         "; codegen L;")
        slice_tiling(nloop, bl_2half, sym_exvars)
    else:

        I = isl.Map.identity(
            isl.Space.create_from_names(ctx, in_=sym_exvars,
                                        out=sym_exvars)).coalesce()

        sym_tmp = []
        rlex = "{["
        for s in sym_exvars:
            rlex = rlex + s + ","
            sym_tmp.append(s + "'")
        rlex = rlex[:-1] + '] -> ['
        for s in sym_exvars:
            rlex = rlex + s + "',"
        rlex = rlex[:-1] + '] : '
        rlex = rlex + tiling_v3.CreateLex(sym_tmp, sym_exvars) + "};"

        rlex = isl.Map(rlex)

        UDS = isl_rel.domain().subtract(isl_rel.range())

        UDS = UDS.insert_dims(isl.dim_type.set, 0, len(sym_exvars))
        for i in range(0, len(sym_exvars)):
            UDS = UDS.set_dim_name(isl.dim_type.set, i, sym_exvars[i])

        tuds = UDS.intersect(isl_TILEbis[0]).coalesce().apply(Rel_Z).coalesce()

        rt_red = iscc.iscc_communicate(str(rt_red) + ";", 1).split('\n')[0]
        rt_red = iscc.RelationExists(rt_red, len(sym_exvars), symb)

        #rk = iscc_communicate(rlex + 'RT_RED := ' + rt_red + "*RLEX;pow RT_RED;")
        rt_red = isl.Map(rt_red).intersect(rlex).coalesce()
        rk = rt_red.power()

        rk = rk[0]
        rk = isl.Map(iscc.RepairRk(str(rk), 0))

        rp = rt_red.transitive_closure()[0]

        sk = tuds.apply(rk).subtract(tuds.apply(rk).apply(rp)).coalesce()

        sk = sk.insert_dims(isl.dim_type.set, 0, 1)

        sk = sk.set_dim_name(isl.dim_type.set, 0, "ink")

        c = isl.Constraint.eq_from_names(sk.get_space(), {"k": -1, "ink": 1})

        sk = sk.add_constraint(c)

        sk = tiling_v3.Project(sk, ["k"])

        tuds = tuds.insert_dims(isl.dim_type.set, 0, 1)
        tuds = tuds.set_dim_name(isl.dim_type.set, 0, "ink")

        c = isl.Constraint.eq_from_names(sk.get_space(), {1: 0, "ink": 1})
        tuds = tuds.add_constraint(c)

        sk = sk.union(tuds)

        fsloop = iscc.iscc_communicate("L :=" + str(sk) + "; codegen L;")

        bl_2half = iscc.iscc_communicate("L :=" + str(isl_TILEprim[0]) +
                                         "; codegen L;")
        slice_tiling(fsloop, bl_2half, sym_exvars, 1)
Example #3
0
def tile_par2(isl_TILEbis, sym_exvars, isl_rel, isl_relplus, isl_relclosure,
              Extend, _rap, Dodatek, SIMPLIFY):

    #with open('sources_of_slices.txt') as f:
    #    content = f.readlines()
    #    srepr = content[0]

    #srepr = isl.Set(srepr)

    #with open('rucs.txt') as f:
    #    content = f.readlines()
    #    rucs = content[0]

    #_rel = _rel.remove_dims(isl.dim_type.in_, 0,1)
    #_rel = _rel.remove_dims(isl.dim_type.out, 0,1)
    #print _rel
    '''
    ir = isl_rel
    print ir
    ir = ir.insert_dims(isl.dim_type.in_, 0, len(sym_exvars))
    ir = ir.insert_dims(isl.dim_type.out, 0, len(sym_exvars))


    print ir

    ir2 = ir.from_domain_and_range(isl_TILEbis, isl_TILEbis).coalesce()
    ir = ir2.intersect(ir).coalesce()
    print ir
    ir = ir.remove_dims(isl.dim_type.in_, len(sym_exvars),len(sym_exvars))
    ir = ir.remove_dims(isl.dim_type.out, len(sym_exvars),len(sym_exvars))
    ir = ir.coalesce()
    print ir

    sys.exit(0);
    '''

    srepr, rucs = slicing.Create_Srepr(isl_rel, isl_relclosure)
    print srepr

    ir = isl_rel.domain().union(isl_rel.range()).coalesce()
    ir = ir.insert_dims(isl.dim_type.set, 0, len(sym_exvars))
    for i in range(0, len(sym_exvars)):
        ir = ir.set_dim_name(isl.dim_type.set, i, sym_exvars[i])

    if (Extend):
        for i in range(0, 2 * len(sym_exvars)):
            ir = ir.insert_dims(isl.dim_type.set, 2 * i + 1, 1)

    srepr = srepr.insert_dims(isl.dim_type.set, 0, len(sym_exvars))
    for i in range(0, len(sym_exvars)):
        srepr = srepr.set_dim_name(isl.dim_type.set, i, sym_exvars[i])

    if (Extend):
        for i in range(0, 2 * len(sym_exvars)):
            srepr = srepr.insert_dims(isl.dim_type.set, 2 * i + 1, 1)

    x = 1
    if (Extend):
        x = 2

    #relacja do obliczenia poczatkow
    Rel_Z = "{["
    for i in range(0, 2 * x * len(sym_exvars)):
        Rel_Z = Rel_Z + "i" + str(i) + ","
    Rel_Z = Rel_Z + "m] -> ["
    for i in range(0, x * len(sym_exvars)):
        Rel_Z = Rel_Z + "i" + str(i) + ","
    Rel_Z = Rel_Z[:-1] + "] };"

    Rel_Z = isl.Map(Rel_Z)

    #relacja do wylapania instrukcji z blokow
    Rel_Y = "{["
    for i in range(0, x * len(sym_exvars)):
        Rel_Y = Rel_Y + "i" + str(i) + ","
    for i in range(0, x * len(sym_exvars) + 1):
        Rel_Y = Rel_Y + "j" + str(i) + ","
    Rel_Y = Rel_Y[:-1] + "] -> ["
    for i in range(0, x * len(sym_exvars)):
        Rel_Y = Rel_Y + "i" + str(i) + ","
    for i in range(0, x * len(sym_exvars) + 1):
        Rel_Y = Rel_Y + "k" + str(i) + ","
    Rel_Y = Rel_Y[:-1] + "] };"

    Rel_Y = isl.Map(Rel_Y)

    TILE_SOUR = isl_TILEbis.intersect(srepr).coalesce()

    TILE_IND = isl_TILEbis.subtract(isl_TILEbis.intersect(ir)).coalesce()

    indloop = iscc.iscc_communicate("L :=" + str(TILE_IND) + "; codegen L;")

    fs = 0
    if (TILE_SOUR.lexmax() == TILE_SOUR.lexmin()):
        print "FS"
        fs = 1
    else:
        print "SLICING"
        if (rucs.is_empty()):
            isl_rel = isl_rel.union(rucs)
            isl_relclosure = isl_relclosure.union(rucs)
            isl_relplus = isl_relplus.union(rucs)

    rplus = tiling_v3.ExtendMap(isl_relplus, sym_exvars, Extend)
    rstar = tiling_v3.ExtendMap(isl_relclosure, sym_exvars, Extend)
    rel_ = tiling_v3.ExtendMap(isl_rel, sym_exvars, Extend)
    #rucs = tiling_v3.ExtendMap(rucs, sym_exvars, Extend)

    rbis = isl.Map.from_domain_and_range(isl_TILEbis, isl_TILEbis)

    rs = rbis.intersect(rstar)
    rt_red = rbis.intersect(rplus)

    if (fs != 1):

        if (rucs.is_empty()):
            TILE_SOUR = TILE_SOUR.subtract(TILE_SOUR.apply(
                rplus)).coalesce()  # remove dependent blocks with srepr

        TILE_RUCS = slicing.Create_RUCS(rel_, rs, TILE_SOUR, TILE_SOUR, 1,
                                        Rel_Y)

        TILE_SOUR = TILE_SOUR.subtract(TILE_RUCS.range()).coalesce()

        z = TILE_SOUR.apply(Rel_Z).coalesce()

        if (SIMPLIFY):
            z = imperf_tile.SimplifySlice(z)

        srepr_loop = iscc.iscc_communicate("L :=" + str(z) +
                                           "; codegen L;")  # albo omega
        #srepr_loop = iscc.oc_communicate(z)
        print srepr_loop
        srepr_loop = srepr_loop.split('\n')

        for i in range(0, len(srepr_loop)):
            if "for" in srepr_loop[i]:
                srepr_loop.insert(i, "#pragma omp parallel for")
                break

        st_reg = re.compile('\s*\(.*\);')
        vecs = []
        taby = []
        for line in srepr_loop:
            if (st_reg.match(line)):
                vecs.append(isl.Set(iscc.s1_to_vec2(line, len(vecs))))
                taby.append(iscc.correct.whites(line))

        #print vecs

        permutate_maps = Dodatek[6]
        permutate_list = Dodatek[5]

        slices = []

        for i in range(0, len(vecs)):
            vecs[i] = vecs[i].intersect(z).coalesce()

        for vec in vecs:
            vec = vec.insert_dims(isl.dim_type.set, x * len(sym_exvars),
                                  x * len(sym_exvars) + 1)
            slice = vec  #.apply(rs)
            slice = slice.apply(Rel_Y)
            slice = slice.apply(rs).coalesce()

            # experimental permutate

            if (len(permutate_list) > 0):
                print "Tiling + slicing + permutation - experimental"
                RP = permutate_maps[0]

                RIDENT = RP.identity(RP.get_space())

                if (not RP.is_equal(RIDENT)
                    ):  #permute map is not an identity map
                    strRP = str(RP)
                    strh = ""
                    for i in range(0, x * len(sym_exvars)):
                        strh = strh + "xx" + str(i) + ","

                    if (Extend):
                        strkoma = strRP.split(",")
                        strRP = ""
                        for i in range(0, 2 * len(sym_exvars)):
                            strRP = strRP + strkoma[i] + ", yy" + str(
                                i % len(sym_exvars)) + ", "
                        strRP = strRP + strkoma[2 * len(sym_exvars)]

                    strRP = strRP.replace("[", "[" + strh)
                    RP = isl.Map(strRP)

                    slice = slice.apply(RP).coalesce()
            # ---------------------------------------------------------

            if (SIMPLIFY):
                slice = imperf_tile.SimplifySlice(slice)
            slices.append(slice)
            print slice

        cmd = ""
        for i in range(0, len(vecs)):
            cmd = cmd + "codegen " + str(slices[i]) + ';print "###";'

        cmd = iscc.iscc_communicate(cmd)

        cmd = cmd.split('"###"')

        new_loop = []
        i = 0
        for line in srepr_loop:
            if (st_reg.match(line)):
                petla = cmd[i].split('\n')
                for s in petla:
                    new_loop.append(taby[i] + s)
                i = i + 1
            else:
                new_loop.append(line)

        nloop = ""
        for line in new_loop:
            if line != '':
                nloop = nloop + line + "\n"
        nloop = nloop[:-1]

        #nloop = nloop + indloop
        nloop = nloop.split('\n')

        # Dodatek = [LPetit, dane,  maxl, step, nazwapar, permutate_list, permutate_maps]

        #permutate list
        nloop = tiling_v3.postprocess_loop(nloop)
        lines = nloop.split('\n')

        loop = imperf_tile.RestoreStatements(lines, Dodatek[0], Dodatek[1],
                                             Dodatek[2], Dodatek[3],
                                             Dodatek[5])

        text_file = open(Dodatek[4], "w")
        text_file.write(loop)
        text_file.close()
        return ""
    else:
        print "fs (EXPERIMENTAL) ..."

        sym_tmp = []
        rlex = "{["
        for s in sym_exvars:
            rlex = rlex + s + ","
            sym_tmp.append(s + "'")
        rlex = rlex[:-1] + '] -> ['
        for s in sym_exvars:
            rlex = rlex + s + "',"
        rlex = rlex[:-1] + '] : '
        rlex = rlex + tiling_v3.CreateLex(sym_tmp, sym_exvars) + "};"

        rlex = isl.Map(rlex)

        rlex = rlex.insert_dims(isl.dim_type.in_, len(sym_exvars),
                                len(sym_exvars) + 1)
        rlex = rlex.insert_dims(isl.dim_type.out, len(sym_exvars),
                                len(sym_exvars) + 1)

        UDS = isl_rel.domain().subtract(isl_rel.range())

        UDS = UDS.insert_dims(isl.dim_type.set, 0, len(sym_exvars))
        for i in range(0, len(sym_exvars)):
            UDS = UDS.set_dim_name(isl.dim_type.set, i, sym_exvars[i])

        if (Extend):
            for i in range(0, 2 * len(sym_exvars)):
                UDS = UDS.insert_dims(isl.dim_type.set, 2 * i + 1, 1)
                rlex = rlex.insert_dims(isl.dim_type.in_, 2 * i + 1, 1)
                rlex = rlex.insert_dims(isl.dim_type.out, 2 * i + 1, 1)

        tuds = UDS.intersect(isl_TILEbis).coalesce()
        #tuds = tuds.insert_dims(isl.dim_type.set, len(sym_exvars), len(sym_exvars)+1)

        rt_red = rt_red.intersect(rlex).coalesce()

        rk = rt_red.power()
        rk = rk[0]
        rk = isl.Map(iscc.RepairRk(str(rk), 0))

        rp = rt_red.transitive_closure()[0]
        sk = tuds.apply(rk).subtract(tuds.apply(rk).apply(rp)).coalesce()

        sk = sk.apply(Rel_Y).intersect(isl_TILEbis)
        sk = sk.insert_dims(isl.dim_type.set, 0, 1)
        sk = sk.set_dim_name(isl.dim_type.set, 0, "ink")

        c = isl.Constraint.eq_from_names(sk.get_space(), {"k": -1, "ink": 1})
        sk = sk.add_constraint(c)
        sk = tiling_v3.Project(sk, ["k"])

        tuds = tuds.apply(Rel_Y).intersect(isl_TILEbis)
        tuds = tuds.insert_dims(isl.dim_type.set, 0, 1)
        tuds = tuds.set_dim_name(isl.dim_type.set, 0, "ink")

        c = isl.Constraint.eq_from_names(sk.get_space(), {1: 0, "ink": 1})
        tuds = tuds.add_constraint(c)

        sk = sk.union(tuds)

        print sk

        fsloop = iscc.iscc_communicate("L :=" + str(sk) + "; codegen L;")

        nloop = fsloop.split('\n')
        nloop = tiling_v3.postprocess_loop(nloop)
        lines = fs_pragma(nloop)

        #Dodatek[2]+1 shift + 1  for k
        #if extend first shift shoud be one smaller
        if (Extend):
            sh = 1
        else:
            sh = 0

        loop = imperf_tile.RestoreStatements(lines, Dodatek[0], Dodatek[1],
                                             Dodatek[2] + 1, Dodatek[3],
                                             Dodatek[5], sh)

        text_file = open(Dodatek[4], "w")
        text_file.write(loop)
        text_file.close()
        return ""
Example #4
0
Rplus = rplus[0]

print Rplus

rpow = rel.power()

print colored('R^k', 'green')

if (rpow[1] == 1):
    print colored('exact', 'green')
else:
    print colored('approx', 'red')

Rpow = rpow[0]

Rpow = isl.Map(iscc.RepairRk(str(Rpow), 0))  # przesun k do symb
print Rpow
uds = rel.domain().subtract(rel.range()).coalesce()
print "UDS"
print uds
sk = uds.apply(Rpow).subtract(uds.apply(Rpow).apply(Rplus)).coalesce()
sk = sk.insert_dims(isl.dim_type.set, 0, 1)
sk = sk.set_dim_name(isl.dim_type.set, 0, "ink")
c = isl.Constraint.eq_from_names(sk.get_space(), {"k": -1, "ink": 1})
sk = sk.add_constraint(c)
sk = tiling_v3.Project(sk, ["k"])
uds = uds.insert_dims(isl.dim_type.set, 0, 1)
uds = uds.set_dim_name(isl.dim_type.set, 0, "ink")
c = isl.Constraint.eq_from_names(sk.get_space(), {1: 0, "ink": 1})
uds = uds.add_constraint(c)
sk = sk.union(uds).coalesce()
Example #5
0
def fs_rk(rel, rel_plus, uds, LPetit, dane, plik, SIMPLIFY, rap, acc, loop):

    aprox = 0
    rk = rel.power()  #Rk
    if (rk[1] == 0):
        print "rk approximated..."
        aprox = 1
    rk = rk[0].coalesce()

    rk = isl.Map(iscc.RepairRk(str(rk), 0))  # przesun k do symb
    sk = uds.apply(rk).subtract(uds.apply(rk).apply(rel_plus)).coalesce()

    sq_sk = sk

    sk = sk.insert_dims(isl.dim_type.set, 0, 1)
    sk = sk.set_dim_name(isl.dim_type.set, 0, "ink")

    c = isl.Constraint.eq_from_names(sk.get_space(), {"k": -1, "ink": 1})
    sk = sk.add_constraint(c)
    sk = tiling_v3.Project(sk, ["k"])

    sq_sk2 = sk

    SQ = False
    if (SQ):
        sk = get_sq(sq_sk, sq_sk2, uds)
    else:

        uds = uds.insert_dims(isl.dim_type.set, 0, 1)
        uds = uds.set_dim_name(isl.dim_type.set, 0, "ink")

        c = isl.Constraint.eq_from_names(sk.get_space(), {1: 0, "ink": 1})
        uds = uds.add_constraint(c)

        sk = sk.union(uds).coalesce()

    #if(SIMPLIFY):
    sk = imperf_tile.SimplifySlice(sk)

    rap = rap.insert_dims(isl.dim_type.in_, 0, 1)
    rap = rap.insert_dims(isl.dim_type.out, 0, 1)
    rap = rap.set_dim_name(isl.dim_type.in_, 0, 'ik1')
    rap = rap.set_dim_name(isl.dim_type.out, 0, 'ok1')

    c = isl.Constraint.eq_from_names(rap.get_space(), {'ik1': -1, 'ok1': 1})
    rap = rap.add_constraint(c)
    rap = rap.coalesce()

    #print rap

    sk = sk.apply(rap)

    print sk

    if (aprox == 1):
        if (sk.is_bounded()):
            print "Approximation (no perfect FS) but Sk is bounded"
        else:
            print "Sk is not bounded. The result may not be valid!"
    else:
        print 'Rk exact'
        if (sk.is_bounded()):
            print 'Sk bounded.'
        else:
            print 'Sk NOT bounded'

    nloop = iscc.iscc_communicate("L :=" + str(sk) + "; codegen L;")

    # CODEGEN
    nloop = tiling_v3.postprocess_loop(nloop.split('\n'))

    lines = tiling_schedule.fs_pragma(nloop)

    if (acc):
        lines = openacc.CreateACCCode(lines, loop.var_st)

    loop = imperf_tile.RestoreStatements(lines, LPetit, dane, 1, 1, [], 1)

    for i in range(0, 5):
        if (loop[-1] == '\n'):
            loop = loop[:-1]
    loop = loop + "\n"

    base = os.path.basename(plik)
    nazwa = os.path.splitext(base)[0] + "_fs" + os.path.splitext(base)[1]

    text_file = open(nazwa, "w")
    text_file.write(loop)
    text_file.close()

    print nazwa + ' was created.'