示例#1
0
    def Preprocess(self, imp='-1'):

        self.isl_rel = isl.Map("{[i] : false}")
        self.isl_tmp = isl.Map("{[i] : false}")

        ii = 1
        w = -1
        for dep in self.Deps:

            if (dep.prep == 1):
                continue

            in_size = dep.Relation.dim(isl.dim_type.in_)

            out_size = dep.Relation.dim(isl.dim_type.out)

            dep.Relation = dep.Relation.insert_dims(isl.dim_type.in_, in_size,
                                                    self.maxl - in_size + 1)
            dep.Relation = dep.Relation.insert_dims(isl.dim_type.out, out_size,
                                                    self.maxl - out_size + 1)

            dep.Relation = dep.Relation.set_dim_name(isl.dim_type.in_,
                                                     self.maxl, "_v1")
            dep.Relation = dep.Relation.set_dim_name(isl.dim_type.out,
                                                     self.maxl, "_v2")

            invar = []
            outvar = []
            for i in range(0, in_size):
                invar.append("i" + str(i))
            for i in range(in_size, self.maxl):
                invar.append(imp)
            for i in range(0, out_size):
                outvar.append("o" + str(i))
            for i in range(out_size, self.maxl):
                outvar.append(imp)
            tmp = str("{[" + ",".join(invar) + "," + dep.from_ + "] -> [" +
                      ",".join(outvar) + "," + dep.to + "]}")
            tmp = isl.Map(tmp)

            dep.Relation = dep.Relation.intersect(tmp).coalesce()
            dep.prep = 1

            if self.isl_rel.is_empty():
                self.isl_rel = dep.Relation
            else:
                self.isl_rel = self.isl_rel.union(dep.Relation).coalesce()

        self.symb = isl_symb = self.isl_rel.get_var_names(isl.dim_type.param)
示例#2
0
def Create_LD_petit(L, petit_loop):
    file = open("tmp/LD_petit_loop_" + L + ".t", 'w')
    file.write("integer xxyyyx" + "\n")
    in_loop = 0
    for line in petit_loop:
        if ('! start' in line):
            continue
        if ('for ' in line):
            in_loop = 1
        if in_loop == 0:
            file.write(line + "\n")
        else:
            if (('for' in line) or ('if ' in line) or (line.isspace())
                    or (line == '')):
                file.write(line + "\n")
            else:
                file.write("xxyyyx = 1" + "\n")
    file.close()

    LD_inp = "tmp/LD_petit_loop_" + L + ".t"
    dane2 = gen.RelPrint(LD_inp, 1)
    dane2 = dane2.split("#")

    rel2 = dane2[0]
    if rel2 != '':
        isl_rel2 = isl.Map(str(rel2))
    else:
        isl_rel2 = None
    return isl_rel2
示例#3
0
def augment_set_with_processor(r_S, nb_processors):
    name = r_S.get_tuple_name()
    dim_number = r_S.dim(isl.dim_type.set)
    dims_str = ""
    for i in range(0, dim_number):
        dims_str += "i" + str(i)
        if (i < dim_number - 1):
            dims_str += ", "
    params = ""
    processor_dims = ""
    processor_constraints = ""
    for i in range(0, nb_processors):
        params += "r" + str(i) + ", "
        processor_dims += "p" + str(i)
        processor_constraints += " p" + str(i) + " = rp" + str(i)
        if (i < nb_processors - 1):
            processor_dims += ","
            processor_constraints += " and "
    for i in range(0, nb_processors):
        params += "rp" + str(i)
        if (i < nb_processors - 1):
            params += ","

    map_str = "[" + params + "]->{" + name + "[" + dims_str + "]->" + name + "[" + processor_dims + "," + dims_str + "]: " + processor_constraints + "}"
    print "Augmentation map (adds news dimensions) : ", map_str
    # Add a new dimension p0 to the set.
    augmentation_map = isl.Map(map_str)
    augmented_r_S = r_S.apply(augmentation_map)

    print "Projecting out 1 dimension of the parameters starting from the dimension 1. This dimension represents the parameter rp."
    augmented_r_S = augmented_r_S.project_out(isl.dim_type.param,
                                              nb_processors,
                                              nb_processors).coalesce()

    return augmented_r_S
示例#4
0
def ReduceR(R):
    str = islMaptoOmegaStr(R)
    str = str.split(':')[0]
    str = str.replace('[', '')
    str = str.replace(']', '')
    str = str.replace('{', '')
    str = str.replace(' ', '')

    sets = str.split('->')
    inp = sets[0]
    outp = sets[1]

    inp = inp.split(',')
    outp = outp.split(',')

    exp = []
    for s in inp:
        exp.append('_ex_' + s)



    isl_symb = R.get_var_names(isl.dim_type.param)
    symb = ','.join(isl_symb)

    R2 = ''

    # symbolic variables
    if (len(isl_symb) > 0):
        R2 = R2 + '[' + symb + '] -> { '
    else:
        R2 = R2 + '{ '
    # tuple variables
    R2 = R2 + '[' + ','.join(inp) + '] -> [' + ','.join(outp) + '] : '

    if not R.is_empty():
        R2 = R2 + copyconstr.GetConstrSet(inp, R.domain()) + ' && '

    if not R.is_empty():
        R2 = R2 +  copyconstr.GetConstr(inp, outp, R) + ' && '



    R2 = R2 + ' not ( Exists ' + ','.join(exp) + ' : ( '

    R2 = R2 + tiling_v3.CreateLex(exp, inp) + ' && '

    #if not R.is_empty():
    #    R2 = R2 +  copyconstr.GetConstr(inp, exp, R.transitive_closure()[0]) + ' && '


    R2 = R2 + copyconstr.GetConstr(exp, outp, R)



    R2 = R2 + ' )) }'


    R2 = isl.Map(R2).coalesce()

    return R2
示例#5
0
def GetRapply(vars, instrukcje, i):
    R = "{["
    for s in vars:
        R = R + s + ","
    R = R + "v] -> ["
    for s in vars:
        R = R + s + "v," + s + ","
    R = R + "v] : "

    z = ""

    z = z + "("

    for l in range(0, i + 1):
        for st in instrukcje[l]['st']:
            z = z + " (v = " + str(st) + " and "
            j = 0
            for s in vars:
                pos = -1
                if j < len(instrukcje[l]['path']
                           ):  #poprawka bo niektore nie maja max zagniezdzen
                    pos = instrukcje[l]['path'][j]
                else:
                    codegen.calculate_position2(l, instrukcje, len(vars))[j]

                z = z + s + "v = " + str(pos) + " and "
                j = j + 1
            z = z[:-4] + ") or "

    R = R + z[:-3] + ")}"
    isl_Rapply = isl.Map(R)
    #print isl_Rapply
    return isl_Rapply
示例#6
0
文件: agent.py 项目: lshadown/traco
def remote_tc(rel):
#rel = "[N] -> { [i, j, k, m, _v1 = 14] -> [i', j', i, j, _v2 = 14] : k > i and k < m < j and 0 <= i' < i and j < j' < N; [i, j, k, m, _v1 = 14] -> [i' = i, j' = j, o2, o3, _v2 = 14] : i >= 0 and j < N and k > i and k < m < j and o2 > k and o2 < o3 < j; [i, j, k, m, _v1 = 14] -> [i', j' = i + j - i', 0, 0, _v2] : k > i and k < m < j and i' >= 0 and -N + i + j < i' <= i and 23 <= _v2 <= 24 - i + i'; [i, j, k, m = 0, _v1 = 20] -> [i', j', 0, 0, _v2 = 24] : i < k <= -3 + j and 0 <= i' <= i and j <= j' <= 1 - i + j + i' and j' < N; [i, j, k, m, _v1 = 14] -> [i' = i, j' = j, o2, 0, _v2 = 17] : i >= 0 and j < N and k > i and k < m < j and k <= o2 <= -4 + j; [i, j, k, m = 0, _v1 = 17] -> [i', j', i, j, _v2 = 14] : i < k <= -4 + j and 0 <= i' < i and j < j' < N; [i, j, k, m = 0, _v1 = 17] -> [i' = i, j' = j, o2, o3, _v2 = 14] : i >= 0 and j < N and i < k <= -4 + j and o2 > k and o2 < o3 < j; [i, j, k, m, _v1 = 14] -> [i' = i, j' = j, k, o3, _v2 = 14] : i >= 0 and j < N and k > i and m > k and m < o3 < j; [i, j, k = 0, m = 0, _v1] -> [i', j', 0, 0, _v2 = 1 - i + _v1 + i'] : j > i and i' >= 0 and 24 - N + i + j - _v1 <= i' <= 23 + i - _v1 and 23 + i + j - _v1 - i' <= j' <= 24 + j - _v1 and j' <= i + j - i'; [i, j, k, m = 0, _v1 = 17] -> [i', j' = i + j - i', 0, 0, _v2] : i < k <= -4 + j and i' >= 0 and -N + i + j < i' <= i and 23 <= _v2 <= 24 - i + i'; [i, j, k, m = 0, _v1 = 20] -> [i' = i, j', j, 0, _v2 = 20] : i >= 0 and i < k <= -3 + j and 3 + j <= j' < N; [i, j, k, m = 0, _v1 = 20] -> [i' = i, j' = j, o2, 0, _v2 = 20] : i >= 0 and j < N and k > i and k < o2 <= -3 + j; [i, j, k, m = 0, _v1 = 20] -> [i', j' = j, -1 + i, 0, _v2 = 20] : j < N and i < k <= -3 + j and 0 <= i' <= -2 + i; [i, j, k, m = 0, _v1 = 20] -> [i' = -1 + i, j', j, 0, _v2 = 17] : i > 0 and i < k <= -3 + j and 4 + j <= j' < N; [i, j, k, m = 0, _v1 = 17] -> [i' = i, j' = j, o2, 0, _v2 = 17] : i >= 0 and j < N and k > i and k < o2 <= -4 + j; [i, j, k, m = 0, _v1 = 20] -> [i', j' = 1 + j, -1 + i, 0, _v2 = 17] : j <= -2 + N and i < k <= -3 + j and 0 <= i' <= -2 + i; [i, j, k = 0, m = 0, _v1 = 23] -> [i', j', i, j, _v2 = 14] : j > i and 0 <= i' < i and j < j' < N; [i, j, k = 0, m = 0, _v1 = 24] -> [i' = i, j', j, 0, _v2 = 20] : i >= 0 and j > i and 3 + j <= j' < N; [i, j, k = 0, m = 0, _v1 = 24] -> [i', j' = j, -1 + i, 0, _v2 = 20] : 2 + i <= j < N and 0 <= i' <= -2 + i; [i, j, k = 0, m = 0, _v1 = 24] -> [i' = -1 + i, j', j, 0, _v2 = 17] : i > 0 and j > i and 4 + j <= j' < N; [i, j, k = 0, m = 0, _v1 = 24] -> [i', j' = 1 + j, -1 + i, 0, _v2 = 17] : 2 + i <= j <= -2 + N and 0 <= i' <= -2 + i; [i, j, k = 0, m = 0, _v1 = 24] -> [i' = i, j' = 1 + j, 0, 0, _v2 = 24] : i >= 0 and i < j <= -2 + N };"
#isl.Map(rel)

    text_file = open('tmp/_rel.txt', 'w')
    text_file.write('R := ' + str(rel) + ';R^+;')
    text_file.close()

    ssh = sshconnect()

    ftp = ssh.open_sftp()
    ftp.put('tmp/_rel.txt', '_rel.txt')
    ftp.close()

    stdin, stdout, stderr = ssh.exec_command("barvinok/iscc < _rel.txt")

    wynik = stdout.readlines()[0]

    sep = ', False)'
    exact = False
    if(sep not in wynik):
        sep = ', True)'
        exact = True


    wynik = wynik.split(sep)

    relp = wynik[0][1:]

    relp = isl.Map(relp)

    ssh.close()

    return relp, exact
示例#7
0
def oc_IterateClosure(R):


    isl_symb = R.get_var_names(isl.dim_type.param)
    outFile = open('tmp/oc.txt', 'w')
    for sym in isl_symb:
        outFile.write('symbolic ' + sym + ";")

    outFile.write('R :=')
    str = islMaptoOmegaStr(R)

    str = str.replace('_', 'ul0')
    outFile.write(str)
    #sys.exit(0)
    outFile.write(';IterateClosure R;')
    #outFile.write(';R^+;')
    outFile.close()

    stdout_data = ''
    remote = 0

    if(remote == 0):
        cmd = oc_proc
        p= Popen(cmd, shell=True, stdout=PIPE, stdin=PIPE)
        stdout_data = p.communicate(input='')[0]
    else:
        ri = agent.remote_iterate()
        stdout_data = ri.iterate_closure()
        ri.disconnect()


    stdout_data = stdout_data.split('\n')

    relcl = ''
    now = False
    for i in range(0, len(stdout_data)):
        if 'Iterate' in stdout_data[i]:
            now = True
            continue
        if now:
            relcl += stdout_data[i]

    symprefix = ''
    if len(isl_symb) > 0:
        symprefix = '[' + ','.join(isl_symb) + '] -> '

    w = symprefix + relcl
    w = w.replace('} union {', ';')

    #print w

    if 'UNKNOWN' in w:
        print colored('Iterate Closure Failed !!!! Abort !!!', 'red')
        print 'ISL approximation can be still used'
        sys.exit(0)

    rcl = isl.Map(w)

    return rcl
示例#8
0
def vec_add():
    S0_dom = isl.Set("[N]->{S0[i]: 0 <= i <= N}")
    Access_A = isl.Map("{S0[i]->A[i]}")
    Access_B = isl.Map("{S0[i]->B[i]}")
    Access_C = isl.Map("{S0[i]->C[i]}")
    A = isl.Set("[N]->{A[i]: 0<=i<N}")
    B = isl.Set("[N]->{B[i]: 0<=i<N}")
    C = isl.Set("[N]->{C[i]: 0<=i<N}")
    return {
        'S0_dom': S0_dom,
        'Access_A': Access_A,
        'Access_B': Access_B,
        'Access_C': Access_C,
        'A': A,
        'B': B,
        'C': C
    }
示例#9
0
def matrix_matrix_add_fixed():
    S0_dom = isl.Set("{S0[i,k]: 0 <= i < 9 and 0 <= k < 9}")
    Access_A = isl.Map("{S0[i,k]->A[i,k]}")
    Access_B = isl.Map("{S0[i,k]->B[i,k]}")
    Access_C = isl.Map("{S0[i,k]->C[i]}")
    A = isl.Set("{A[i,k]: 0<=i<9 and 0<=k<9}")
    B = isl.Set("{B[i,k]: 0<=i<9 and 0<=k<9}")
    C = isl.Set("{C[i]: 0<=i<9}")
    return {
        'S0_dom': S0_dom,
        'Access_A': Access_A,
        'Access_B': Access_B,
        'Access_C': Access_C,
        'A': A,
        'B': B,
        'C': C
    }
示例#10
0
def mat_mul_2D_fixed():
    S0_dom = isl.Set(
        "{S0[i, j, k]: 0 <= i < 12 and 0 <= j < 12 and 0 <= k < 12}")
    Access_A = isl.Map("{S0[i, j, k]->A[i, k]}")
    Access_B = isl.Map("{S0[i, j, k]->B[k, j]}")
    Access_C = isl.Map("{S0[i, j, k]->C[i, j, k]}")
    A = isl.Set("{A[i,j]: 0<=i<12 and 0<=j<12}")
    B = isl.Set("{B[i,j]: 0<=i<12 and 0<=j<12}")
    C = isl.Set("{C[i,j,k]: 0<=i<12 and 0<=j<12 and 0<=k<12}")
    return {
        'S0_dom': S0_dom,
        'Access_A': Access_A,
        'Access_B': Access_B,
        'Access_C': Access_C,
        'A': A,
        'B': B,
        'C': C
    }
示例#11
0
def mat_mul_2D():
    S0_dom = isl.Set(
        "[N]->{S0[i, j, k]: 0 <= i < N and 0 <= j < N and 0 <= k < N}")
    Access_A = isl.Map("{S0[i, j, k]->A[i, k]}")
    Access_B = isl.Map("{S0[i, j, k]->B[k, j]}")
    Access_C = isl.Map("{S0[i, j, k]->C[i, j, k]}")
    A = isl.Set("[N]->{A[i,j]: 0<=i<N and 0<=j<N}")
    B = isl.Set("[N]->{B[i,j]: 0<=i<N and 0<=j<N}")
    C = isl.Set("[N]->{C[i,j,k]: 0<=i<N and 0<=j<N and 0<=k<N}")
    return {
        'S0_dom': S0_dom,
        'Access_A': Access_A,
        'Access_B': Access_B,
        'Access_C': Access_C,
        'A': A,
        'B': B,
        'C': C
    }
示例#12
0
def test_structure_yields():
    rel = isl.Map(
        "{ A[i,j] -> B[k] : 0 <= i < 10 and 0 <= j < 3 and k = i + j }")
    rel_ast = isl_map_to_ast(rel)
    structure = (ndims_in, ndims_out) = tuple(
        rel.space.dim(x) for x in (isl.dim_type.in_, isl.dim_type.out))
    py = isl2py_fn(rel_ast, "foo")
    print("Before:\n", pyastor.to_source(py))
    StructureTupleYields(structure).visit(py)
    print("After:\n", pyastor.to_source(py))
示例#13
0
    def __init__(self, plik, short_mode=0):
        isl.Map("{[i] : false}")
        self.plik = plik

        self.Load_Deps()

        self.Load_instrukcje()
        if (short_mode == 0):
            self.Preprocess()
            self.Get_Arrays()
示例#14
0
文件: fs_new.py 项目: lshadown/traco
def GetR2(re, rrplus):

    isl_symb = re.get_var_names(isl.dim_type.param)
    dim = rrplus.dim(isl.dim_type.out)

    in_ = []
    out_ = []
    ex_ = []

    for i in range(0, dim):
        in_.append('_in' + str(i))
        out_.append('_out' + str(i))
        ex_.append('_ex' + str(i))

    symb = ','.join(isl_symb)

    R2 = ''

    # symbolic variables
    if (len(isl_symb) > 0):
        R2 = R2 + '[' + symb + '] -> { '
    else:
        R2 = R2 + '{ '
    #tuple variables
    R2 = R2 + '[' + ','.join(in_) + '] -> [' + ','.join(out_) + '] : '

    #s2 in Re(s1)
    if not re.is_empty():
        R2 = R2 + copyconstr.GetConstr(in_, out_, re) + ' and '

    #  if not re.is_empty():
    #      R2 = R2 + copyconstr.GetConstr(out_, in_, re) + ' and '

    #s2 in RR+(s1)
    if not rrplus.is_empty():
        R2 = R2 + copyconstr.GetConstr(in_, out_, rrplus) + ' and '

    #s1 in Domain(Re)
    if not re.is_empty():
        R2 = R2 + copyconstr.GetConstrSet(in_, re.domain())
    else:
        R2 = R2 + ' 1=1 '

    R2 = R2 + '}'

    print R2

    R2 = isl.Map(R2)
    #R2.coalesce()

    #print "### R2"
    #print R2

    return R2
示例#15
0
def GetRapply3(vars, sym_exvars, _SYM, instrukcje, i, scat=[]):

    R = "{["
    for s in sym_exvars:
        R = R + s + ","
    for s in vars:
        R = R + s + ","
    R = R + "v] -> ["
    for s in sym_exvars:
        R = R + s + "p," + s + ","
    for s in vars:
        R = R + s + "v," + s + ","
    R = R + "v] : "

    z = ""

    j = 0
    for s in sym_exvars:
        pos = -1
        if j < len(instrukcje[i]
                   ['path']):  #poprawka bo niektore nie maja max zagniezdzen
            pos = instrukcje[i]['path'][j]
        else:
            pos = codegen.calculate_position2(
                i, instrukcje, len(sym_exvars))[j]  #pobierz tab[j]
        z = z + s + "p = " + str(pos) + " and "
        j = j + 1

    z = z + "("

    for l in range(0, i + 1):
        for st in instrukcje[l]['st']:
            z = z + " (v = " + str(st) + " and "
            j = 0
            for s in vars:
                pos = -1
                if j < len(instrukcje[l]['path']
                           ):  #poprawka bo niektore nie maja max zagniezdzen
                    pos = instrukcje[l]['path'][j]
                else:
                    pos = codegen.calculate_position2(
                        l, instrukcje, len(sym_exvars))[j]  #pobierz tab[j]
                z = z + s + "v = " + str(pos) + " and "
                j = j + 1
            z = z[:-4] + ") or "

    R = R + z[:-3] + ")}"

    isl_Rapply = isl.Map(R)

    return isl_Rapply
示例#16
0
def test_schedule():
    schedule = isl.Map("{S[t,i,j] -> [t,i,j]: 0 < t < 20 and 0 < i < j < 100}")
    accesses = isl.Map("{S[t,i,j] -> bar[t%2, i+1, j-1]}")
    context = isl.Set("{:}")
    build = isl.AstBuild.from_context(context)

    def callback(node, build):
        schedulemap = build.get_schedule()
        accessmap = accesses.apply_domain(schedulemap)
        aff = isl.PwMultiAff.from_map(isl.Map.from_union_map(accessmap))
        access = build.call_from_pw_multi_aff(aff)
        return isl.AstNode.alloc_user(access)

    build, callback_handle = build.set_at_each_domain(callback)

    ast = build.ast_from_schedule(schedule)

    def cb_print_user(printer, options, node):
        print("Callback user called")
        printer = printer.print_str("Callback user")
        return printer

    def cb_print_for(printer, options, node):
        print("Callback for called")
        printer = printer.print_str("Callback For")
        return printer

    opts = isl.AstPrintOptions.alloc(isl.DEFAULT_CONTEXT)
    opts, cb_print_user_handle = opts.set_print_user(cb_print_user)
    opts, cb_print_for_handle = opts.set_print_for(cb_print_for)

    printer = isl.Printer.to_str(isl.DEFAULT_CONTEXT)
    printer = printer.set_output_format(isl.format.C)
    printer.print_str("// Start\n")
    printer = ast.print_(printer, opts)
    printer.print_str("// End")

    print(printer.get_str())
示例#17
0
def Relation_Inner(dim, c):

    invar = []
    outvar = []

    for i in range(0, dim):
        invar.append("i" + str(i))
    for i in range(0, c):
        outvar.append("i" + str(i))
    for i in range(c, dim):
        outvar.append("o" + str(i))
    tmp = str("{[" + ",".join(invar) + "] -> [" + ",".join(outvar) + "]}")

    return isl.Map(tmp)
示例#18
0
def GetRapply4(vars, sym_exvars, _SYM, instrukcje, i):

    R = "{["
    for s in sym_exvars:
        R = R + s + ","
    for s in vars:
        R = R + s + ","
    R = R + "v] -> ["
    for s in sym_exvars:
        R = R + s + "p," + s + ","
    for s in vars:
        R = R + s + "v," + s + ","
    R = R + "v] : "

    z = ""

    j = 0
    for s in sym_exvars:
        pos = -1
        if j < len(instrukcje[i]['scatter']
                   ):  #poprawka bo niektore nie maja max zagniezdzen
            pos = instrukcje[i]['scatter'][j]
        else:
            pos = "0"
        z = z + s + "p = " + str(pos) + " and "
        j = j + 1

    z = z + "("

    for l in range(0, i + 1):
        for st in instrukcje[l]['st']:
            z = z + " (v = " + str(st) + " and "
            j = 0
            for s in vars:
                pos = -1
                if j < len(instrukcje[l]['scatter']
                           ):  #poprawka bo niektore nie maja max zagniezdzen
                    pos = instrukcje[l]['scatter'][j]
                else:
                    pos = "0"
                z = z + s + "v = " + str(pos) + " and "
                j = j + 1
            z = z[:-4] + ") or "

    R = R + z[:-3] + ")}"

    isl_Rapply = isl.Map(R)

    return isl_Rapply
示例#19
0
    def PreprocessPet(self):

        for i in range(0, len(self.Deps)):
            from_ = 'S' + str(self.Deps[i].from_)
            to = 'S' + str(self.Deps[i].to)
            rel = str(self.Deps[i].Relation)
            rel = rel.replace('{ [', '{ ' + from_ + '[')  #like aka Pet
            rel = rel.replace('> [', '> ' + to + '[')
            self.Deps[i].Relation = isl.Map(rel)
            print self.Deps[i].Relation

        self.isl_rel = isl.UnionMap(str(self.Deps[0].Relation))
        for i in range(1, len(self.Deps)):
            self.isl_rel = self.isl_rel.union(self.Deps[i].Relation)
            self.isl_rel = self.isl_rel.coalesce()
示例#20
0
文件: fs_rk.py 项目: lshadown/traco
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
示例#21
0
def main():

    ctx = isl.Context()

    a_s = isl.Map.read_from_str(
        ctx,
        "{ a_4_s[i0, i1, i2] -> [i0 + i2, i1, 10 + i2, 13] : i0 >= 0 and i1 >= 0 and i1 <= 9 and i2 >= 0 and i2 <= 63 and i0 < 20}"
    )
    f1_s = isl.Map.read_from_str(
        ctx,
        "{ folding_4_s1[i0, i1, i2] -> [i0 + i2, 9 + i1, 18 + i2, 11] : i0 >= 0 and i1 >= 0 and i1 <= 9 and i2 >= 1 and i2 <= 63  and i0 < 20}"
    )
    f0_s = isl.Map.read_from_str(
        ctx,
        "{ folding_4_s0[i0, i1, 0] -> [i0, 9, 10 + i1, 2] : i0 >= 0 and i1 >= 0 and i1 <= 9  and i0 < 20}"
    )

    a_f0 = isl.Map.read_from_str(
        ctx,
        "{ a_4_s[i0, i1, 0] -> folding_4_s0[i0, i1, 0] : i0 >= 0 and i1 >= 0 and i1 <= 9 }"
    )
    a_f1 = isl.Map.read_from_str(
        ctx,
        "{ a_4_s[i0, i1, i2] -> folding_4_s1[i0, i1, i2] : i0 >= 0 and i1 >= 0 and i1 <= 9 and i2 >= 1 and i2 <= 63 }"
    )

    a_t = a_s.range()
    f1_t = f1_s.range()
    f0_t = f0_s.range()

    a_f0_t = a_f0.apply_domain(a_s).apply_range(f0_s)
    a_f1_t = a_f1.apply_domain(a_s).apply_range(f1_s)

    print a_t
    print f1_t
    print f0_t
    print a_f0_t
    #islplot.plotter.plot_set_points(a_t.project_out(isl.dim_type.set, 0, 1), 'blue')
    #islplot.plotter.plot_set_points(f0_t.project_out(isl.dim_type.set, 0, 1), 'red')
    #islplot.plotter.plot_set_points(f1_t.project_out(isl.dim_type.set, 0, 1), 'green')
    #islplot.plotter.plot_map(a_f0_t)
    islplot.plotter.plot_map(isl.Map(
        "{ [i0, i1] -> [i0, 9] : i0 >= 0 and i1 >= 0 and i1 <= 9 and i0 <= 19 }"
    ),
                             edge_width=3)
    #islplot.plotter.plot_map(isl.Map.read_from_str(ctx, "{[2,8] -> [x,y]: 1 < x < 9 and 1 < y < 9 and x = y}"))
    #islplot.plotter.plot_map(a_f1_t)
    pylab.show()
示例#22
0
def DynamicRTILE(rtile, TILE_VLD_ext, n, cl, vars, RFS):

    RFS = isl.Map(RFS).coalesce()

    I0 = rtile.domain()
    text_file = open("Output.txt", "w")

    for i in range(0, 10000):
        if (i == 0):
            J0 = rtile.range()
            FS0 = I0.subtract(J0).coalesce()
            L0 = FS0
        else:
            L0 = Lay0.apply(rtile)
            J0 = J0.subtract(Lay0)

        D0 = J0.apply(rtile)

        Lay0 = L0.subtract(D0).coalesce()

        if (Lay0.is_empty()):
            break

        Lay = Lay0.insert_dims(isl.dim_type.set, 2 * n, 2 * n)
        Lay = Lay.intersect(TILE_VLD_ext).coalesce()

        Lay = Lay.apply(RFS).coalesce()

        Lay = imperf_tile.SimplifySlice(Lay)

        loop = iscc.isl_ast_codegen(Lay)
        loop = loop.split('\n')
        if 'for' in loop[0]:
            if ((('int c1') in loop[0]) or (('int c3') in loop[0])
                    or (('int c5') in loop[0])):
                loop.insert(0, "#pragma omp parallel for")

        loop_str = RestoreStatements2(loop, cl, n, vars)

        text_file.write(loop_str)

        # for line in loop_str:
        #     if '#pragma' in line:
        #         print colored(line, 'green')
        #     else:
        #         print line

    text_file.close()
示例#23
0
def Create_RUCS(isl_rel, isl_relclosure, uds, udsi, dl=0, Rel_Y=""):

    n = uds.dim(isl.dim_type.set)

    symb_tuple = SymbolicTuple(n)
    _symb = symb_tuple[1]
    symb_tuple = symb_tuple[0]

    Sx = udsi.intersect(symb_tuple)
    Si = Sx.apply(isl_relclosure)

    if (dl == 1):
        Si = Si.apply(Rel_Y).coalesce()

    ris = isl_relclosure.fixed_power_val(-1)

    S2 = Si.apply(ris).intersect(uds).coalesce(
    )  # Intersection(Range(Restrict_Domain(copy(Ris), copy(S1))), copy(UDS));   // All_UDS?
    rucs = isl.Map.from_domain_and_range(
        Sx,
        S2).coalesce()  # Relation RUCS = Cross_Product(copy(Sx), copy(S2));

    inp = []
    outp = []
    inp2 = []
    outp2 = []

    if (dl == 0):
        zakres = n
    else:
        zakres = n / 2

    for i in range(0, n):
        inp.append("i" + str(i))
        outp.append("o" + str(i))
        if (i < zakres):
            inp2.append("i" + str(i))
            outp2.append("o" + str(i))

    rlex = "{[" + ",".join(inp) + "] -> [" + ",".join(
        outp) + "] : " + tiling_v3.CreateLex(outp2, inp2) + "}"
    rlex = isl.Map(rlex)

    rucs = rucs.intersect(rlex)
    rucs = tiling_v3.Project(rucs, _symb).coalesce()

    return rucs
示例#24
0
def GetRe1(re, relplus):

    isl_symb = relplus.get_var_names(isl.dim_type.param)
    dim = relplus.dim(isl.dim_type.out)

    in_ = []
    out_ = []
    ex_ = []

    for i in range(0, dim):
        in_.append('_in' + str(i))
        out_.append('_out' + str(i))
        ex_.append('_ex' + str(i))

    symb = ','.join(isl_symb)

    Re1 = ''

    # symbolic variables
    if (len(isl_symb) > 0):
        Re1 = Re1 + '[' + symb + '] -> { '
    else:
        Re1 = Re1 + '{ '
    #tuple variables
    Re1 = Re1 + '[' + ','.join(in_) + '] -> [' + ','.join(out_) + '] : '

    #s2 in Re(s1)
    Re1 = Re1 + copyconstr.GetConstr(in_, out_, re)

    #exists s1' :
    Re1 = Re1 + 'and exists ' + ','.join(ex_) + ' : ('

    # s1' in Re(s1)
    Re1 = Re1 + copyconstr.GetConstr(in_, ex_, re)

    # s2 in R+(s1')
    Re1 = Re1 + ' and ' + copyconstr.GetConstr(ex_, out_, relplus)

    Re1 = Re1 + ') }'

    Re1 = isl.Map(Re1)
    Re1.coalesce()

    print "### Re1"
    print Re1

    return Re1
示例#25
0
def get_RTILE(isl_TILEbis, sym_exvars, isl_rel, Extend, opt=0):

    x = 1
    if (Extend):
        x = 2

    rbis = isl.Map.from_domain_and_range(isl_TILEbis, isl_TILEbis)
    rel_ = tiling_v3.ExtendMap(isl_rel, sym_exvars, Extend)

    if (opt == 0):
        Rel_W = "{["
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "i" + str(i) + ","
        Rel_W = Rel_W + "m1] -> ["
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "o" + str(i) + ","
        Rel_W = Rel_W + "m2] : not ("
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "i" + str(i) + " = " + "o" + str(i) + " and "
        Rel_W = Rel_W[:-4] + ")}"
    else:
        Rel_W = "{["
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "i" + str(i) + ","
        Rel_W = Rel_W[:-1] + "] -> ["
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "o" + str(i) + ","
        Rel_W = Rel_W[:-1] + "] : not ("
        for i in range(0, x * len(sym_exvars)):
            Rel_W = Rel_W + "i" + str(i) + " = " + "o" + str(i) + " and "
        Rel_W = Rel_W[:-4] + ")}"

    rel_simple = rbis.intersect(rel_)
    rel_simple = rel_simple.project_out(isl.dim_type.in_, x * len(sym_exvars),
                                        x * len(sym_exvars))
    rel_simple = rel_simple.project_out(isl.dim_type.out, x * len(sym_exvars),
                                        x * len(sym_exvars))

    relw = isl.Map(Rel_W)

    rel_simple = rel_simple.intersect(relw).coalesce()

    rel_simple = rel_simple.coalesce()

    #get_RCYCLE(rel_simple, 0)

    return rel_simple
示例#26
0
def GetRapply(vars, sym_exvars, _SYM):
    R = "R := ["
    R = R + _SYM

    R = R[:-1] + "] -> {["
    for s in vars:
        R = R + s + ","
    R = R + "v] -> ["
    for s in sym_exvars:
        R = R + s + ","
    for s in vars:
        R = R + s + ","
    R = R + "v] : "
    R = R + " true };\n"

    print R
    isl_Rapply = isl.Map(R.replace('R := ', ''))
    return isl_Rapply
示例#27
0
    def Load_Deps(self):

        lines = Petit_Rel(self.plik).split('\n')
        lines2 = []

        if (False):
            for line in lines:
                if 'must' in line:
                    continue
                else:
                    lines2.append(line)

        else:
            allow_to_add = True

            for i in range(0, len(lines)):
                if 'must' in lines[i]:
                    allow_to_add = False  # nie dodawaj lini po must chyba ze bedzie  nowa zaleznosc

                if '-->' in lines[i]:
                    allow_to_add = True

                if allow_to_add:
                    lines2.append(lines[i])

        lines = lines2

        for i in range(0, len(lines), 4):
            dep = Dependence()
            info = lines[i].split()
            if len(info) == 0:
                continue
            #print lines[i]
            dep.kind = info[0]
            dep.var_in = info[2]
            #print info
            dep.var_out = info[5]
            dep.from_ = info[1].replace(':', '')
            dep.to = info[4].replace(':', '')
            dep.vector = info[6]
            dep.Relation = isl.Map(str(lines[i + 2]))
            dep.delta = (str(lines[i + 3]))
            self.Deps.append(dep)
            self.lines_deps.append(lines[i])  # dla priv
示例#28
0
    def __init__(self, ty: str, acc: typing.Union[str, isl.Map]):
        if ty not in ("RD", "WR"):
            raise ValueError(
                "Invalid access type: %s. Expecting 'RD' or 'WR'" % (ty, ))

        if isinstance(acc, str):
            try:
                acc = isl.Map(acc)
            except:
                print("Failed to create an isl.Map from %s" % (acc, ))
                raise

        if not isinstance(acc, isl.Map):
            raise ValueError(
                "Invalid access type: %s. Expecting str or isl.Map" %
                (type(acc), ))

        self.a_ty = ty
        self.access = acc
示例#29
0
    def GetRapply(self, vars, sym_exvars, _SYM):

        sym = ','.join(_SYM)

        if (len(_SYM) > 0):
            sym = sym + ','

        sym = sym + ','.join(sym_exvars)
        R = "[" + sym + "] -> {["

        R = R + ','.join(vars)

        R = R + "] -> ["
        R = R + ','.join(sym_exvars) + ','
        R = R + ','.join(vars)
        R = R + "] : "
        R = R + " true };\n"

        isl_Rapply = isl.Map(R)
        return isl_Rapply
示例#30
0
def get_RCYCLE(rel_simple, orig):

    #rel_simple = isl.Map("[n] -> {[i,j] -> [i',j'] : 1 <= i <= n && 1 <= j <= n && 1 <= i' <= n && 1 <= j' <= n}")

    rplus = rel_simple.transitive_closure()[0].coalesce()
    inp = []
    outp = []
    symb = []

    n = rel_simple.dim(isl.dim_type.in_)

    for i in range(0, n):
        inp.append("i" + str(i))
        outp.append("o" + str(i))
        symb.append("s" + str(i))

    rlex = "{[" + ",".join(inp) + "] -> [" + ",".join(
        outp) + "] : " + tiling_v3.CreateLex(outp, inp) + "}"
    rlex = isl.Map(rlex)

    invert_rel = rel_simple.fixed_power_val(-1).coalesce()

    r_out = rlex.intersect(rplus.intersect(invert_rel)).coalesce()

    print 'R_CYCLE'
    print r_out

    if orig == 1:
        print "Oryginal TILES"

    print '#nowa prosta implementacja R_CYCLE'

    S = "[" + ",".join(symb) + "] -> {[" + ",".join(symb) + "]}"
    S = isl.Set(S)

    R_CYCLE2 = S.apply(rplus).intersect(S).coalesce()

    print R_CYCLE2

    return r_out