How to use the dace.symbolic.pystr_to_symbolic function in dace

To help you get started, we’ve selected a few dace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spcl / dace / dace / transformation / dataflow / distributed_storage.py View on Github external
if (not isinstance(e2.src, nodes.CodeNode) and
                                    not isinstance(e2.dst, nodes.CodeNode)):
                                visited_edges.add(e2)
                                continue
                            if e2.data.data != self.array:
                                visited_edges.add(e2)
                                continue
                            edges.add(e2)
                            visited_edges.add(e2)

        for e in edges:
            local_ranges = [(0, 0, 1)] * 2 * dims
            dist_ranges = [(0, 0, 1)] * pdims
            for k, v in self.arrayspace_mapping.items():
                local_ranges[k] = (
                    symbolic.pystr_to_symbolic(
                        "({}) // (({}) * ({}))".format(
                            e.data.subset[k][0],
                            space.block_sizes[v],
                            space.process_grid[v])),
                    symbolic.pystr_to_symbolic(
                        "({}) // (({}) * ({}))".format(
                            e.data.subset[k][1],
                            space.block_sizes[v],
                            space.process_grid[v])), 1)
                local_ranges[k + dims] = (
                    symbolic.pystr_to_symbolic(
                        "({}) % ({})".format(e.data.subset[k][0],
                                             space.block_sizes[v])),
                    symbolic.pystr_to_symbolic(
                        "({}) % ({})".format(e.data.subset[k][1],
                                             space.block_sizes[v])), 1)
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
dace.properties.SubsetProperty.from_string("p + 1"), 1))
    state.add_memlet_path(
        compute_sdfg_node,
        C_pipe_out,
        src_conn="C_stream_out",
        memlet=dace.memlet.Memlet(
            C_pipe_out,
            dace.symbolic.pystr_to_symbolic("(N / P) * M * (p + 1)"),
            dace.properties.SubsetProperty.from_string("p + 1"), 1))

    state.add_memlet_path(
        A,
        read_A_sdfg_node,
        dst_conn="mem",
        memlet=dace.memlet.Memlet(
            A, dace.symbolic.pystr_to_symbolic("N * K"),
            dace.properties.SubsetProperty.from_string("0:N, 0:K"), 1))
    state.add_memlet_path(
        read_A_sdfg_node,
        A_pipe_read,
        src_conn="pipe",
        memlet=dace.memlet.Memlet(
            A_pipe_out, dace.symbolic.pystr_to_symbolic("N * K"),
            dace.properties.SubsetProperty.from_string("0"), 1))

    state.add_memlet_path(
        B,
        read_B_sdfg_node,
        dst_conn="mem",
        memlet=dace.memlet.Memlet(
            B, dace.symbolic.pystr_to_symbolic("(N / P) * K * M"),
            dace.properties.SubsetProperty.from_string("0:K, 0:M"), 1))
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
A_pipe_in,
            dace.symbolic.pystr_to_symbolic("(N / P) * K * (P - p)"),
            dace.properties.SubsetProperty.from_string("p"), 1))
    state.add_memlet_path(
        B_pipe_in,
        compute_sdfg_node,
        dst_conn="B_stream_in",
        memlet=dace.memlet.Memlet(
            B_pipe_in, dace.symbolic.pystr_to_symbolic("N * K * M / P"),
            dace.properties.SubsetProperty.from_string("p"), 1))
    state.add_memlet_path(
        C_pipe_in,
        compute_sdfg_node,
        dst_conn="C_stream_in",
        memlet=dace.memlet.Memlet(
            C_pipe_in, dace.symbolic.pystr_to_symbolic("(N / P) * M * p"),
            dace.properties.SubsetProperty.from_string("p"), 1))
    state.add_memlet_path(
        compute_sdfg_node,
        A_pipe_out,
        src_conn="A_stream_out",
        memlet=dace.memlet.Memlet(
            A_pipe_out,
            dace.symbolic.pystr_to_symbolic("(N / P) * K * (P - p - 1)"),
            dace.properties.SubsetProperty.from_string("p + 1"), 1))
    state.add_memlet_path(
        compute_sdfg_node,
        B_pipe_out,
        src_conn="B_stream_out",
        memlet=dace.memlet.Memlet(
            B_pipe_out,
            dace.symbolic.pystr_to_symbolic(
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
B_pipe_out, dace.symbolic.pystr_to_symbolic("(N / P) * K * M"),
            dace.properties.SubsetProperty.from_string("0"), 1))

    state.add_memlet_path(
        C_pipe_write,
        write_C_sdfg_node,
        dst_conn="pipe",
        memlet=dace.memlet.Memlet(
            C_pipe_out, dace.symbolic.pystr_to_symbolic("N * M"),
            dace.properties.SubsetProperty.from_string("P"), 1))
    state.add_memlet_path(
        write_C_sdfg_node,
        C,
        src_conn="mem",
        memlet=dace.memlet.Memlet(
            C, dace.symbolic.pystr_to_symbolic("N * M"),
            dace.properties.SubsetProperty.from_string("0:N, 0:M"), 1))

    return state
github spcl / dace / dace / transformation / dataflow / strip_mining.py View on Github external
tile_stride))
        nd_step = 1
        new_dim_range = (nd_from, nd_to, nd_step)
        new_map = nodes.Map(new_dim + '_' + map_entry.map.label, [new_dim],
                            subsets.Range([new_dim_range]))
        new_map_entry = nodes.MapEntry(new_map)
        new_map_exit = nodes.MapExit(new_map)

        # Change the range of the selected dimension to iterate over a single
        # tile
        if strided:
            td_from_new = symbolic.pystr_to_symbolic(new_dim)
            td_to_new_approx = td_to
            td_step = symbolic.pystr_to_symbolic(tile_size)
        else:
            td_from_new = symbolic.pystr_to_symbolic(
                '%s + %s * %s' %
                (symbolic.symstr(td_from), str(new_dim), tile_stride))
            td_to_new_exact = symbolic.pystr_to_symbolic(
                'min(%s + 1, %s + %s * %s + %s) - 1' %
                (symbolic.symstr(td_to), symbolic.symstr(td_from), tile_stride,
                 str(new_dim), tile_size))
            td_to_new_approx = symbolic.pystr_to_symbolic(
                '%s + %s * %s + %s - 1' %
                (symbolic.symstr(td_from), tile_stride, str(new_dim),
                 tile_size))
        if divides_evenly or strided:
            td_to_new = td_to_new_approx
        else:
            td_to_new = dace.symbolic.SymExpr(td_to_new_exact,
                                              td_to_new_approx)
        # Special case: If range is 1 and no prefix was specified, skip range
github spcl / dace / dace / frontend / python / astutils.py View on Github external
missing_slices = len(arrdesc.shape) - len(astrange)
        if missing_slices < 0:
            raise ValueError(
                'Mismatching shape {} - range {} dimensions'.format(
                    arrdesc.shape, astrange))
        for i in range(missing_slices):
            astrange.append((None, None, None))

    result = [None] * len(astrange)
    for i, r in enumerate(astrange):
        if isinstance(r, tuple):
            begin, end, skip = r
            # Default values
            if begin is None:
                begin = symbolic.pystr_to_symbolic(0)
            else:
                begin = symbolic.pystr_to_symbolic(unparse(begin))
            if end is None and arrname is None:
                raise SyntaxError('Cannot define range without end')
            elif end is not None:
                end = symbolic.pystr_to_symbolic(unparse(end)) - 1
            else:
                end = symbolic.pystr_to_symbolic(
                    symbolic.symbol_name_or_value(arrdesc.shape[i])) - 1
            if skip is None:
                skip = symbolic.pystr_to_symbolic(1)
            else:
                skip = symbolic.pystr_to_symbolic(unparse(skip))
        else:
            # In the case where a single element is given
            begin = symbolic.pystr_to_symbolic(unparse(r))
github spcl / dace / dace / frontend / python / memlet_parser.py View on Github external
return node

    syms = {}
    syms.update(defined)
    if additional_syms is not None:
        syms.update(additional_syms)

    # First try to evaluate normally
    try:
        return eval(code, syms)
    except:  # Literally anything can happen here
        # If doesn't work, try to evaluate as a sympy expression
        # Replace subscript expressions with function calls (sympy support)
        code = code.replace('[', '(')
        code = code.replace(']', ')')
        return pystr_to_symbolic(code)
github spcl / dace / dace / transformation / dataflow / strip_mining.py View on Github external
# Change the range of the selected dimension to iterate over a single
        # tile
        if strided:
            td_from_new = symbolic.pystr_to_symbolic(new_dim)
            td_to_new_approx = td_to
            td_step = symbolic.pystr_to_symbolic(tile_size)
        else:
            td_from_new = symbolic.pystr_to_symbolic(
                '%s + %s * %s' %
                (symbolic.symstr(td_from), str(new_dim), tile_stride))
            td_to_new_exact = symbolic.pystr_to_symbolic(
                'min(%s + 1, %s + %s * %s + %s) - 1' %
                (symbolic.symstr(td_to), symbolic.symstr(td_from), tile_stride,
                 str(new_dim), tile_size))
            td_to_new_approx = symbolic.pystr_to_symbolic(
                '%s + %s * %s + %s - 1' %
                (symbolic.symstr(td_from), tile_stride, str(new_dim),
                 tile_size))
        if divides_evenly or strided:
            td_to_new = td_to_new_approx
        else:
            td_to_new = dace.symbolic.SymExpr(td_to_new_exact,
                                              td_to_new_approx)
        # Special case: If range is 1 and no prefix was specified, skip range
        if td_from_new == td_to_new_approx and target_dim == new_dim:
            map_entry.map.range = subsets.Range(
                [r for i, r in enumerate(map_entry.map.range) if i != dim_idx])
            map_entry.map.params = [
                p for i, p in enumerate(map_entry.map.params) if i != dim_idx
            ]
            if len(map_entry.map.params) == 0:
github spcl / dace / dace / sdfg / sdfg.py View on Github external
def free_symbols(self) -> Set[str]:
        """ Returns a set of symbols used in this edge's properties. """
        # Symbols in conditions and assignments
        result = set(
            map(str, dace.symbolic.symbols_in_ast(self.condition.code[0])))
        for assign in self.assignments.values():
            result |= set(
                map(str,
                    symbolic.pystr_to_symbolic(assign).free_symbols))

        return result - set(self.assignments.keys())
github spcl / dace / dace / sdfg.py View on Github external
if not isinstance(name, str):
            raise TypeError(
                'Array name must be a string. Got %s' % type(name).__name__)

        # If exists, fail
        if name in self._arrays:
            raise NameError('Array or Stream with name "%s" already exists '
                            'in SDFG' % name)

        # convert strings to int if possible
        newshape = []
        for s in shape:
            try:
                newshape.append(int(s))
            except:
                newshape.append(dace.symbolic.pystr_to_symbolic(s))
        shape = newshape

        if isinstance(dtype, type) and dtype in types._CONSTANT_TYPES[:-1]:
            dtype = types.typeclass(dtype)

        desc = dt.Array(
            dtype,
            shape,
            storage=storage,
            materialize_func=materialize_func,
            allow_conflicts=allow_conflicts,
            access_order=access_order,
            transient=transient,
            strides=strides,
            offset=offset,
            toplevel=toplevel,