How to use dace - 10 common examples

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 / tests / intel_fpga / gemm_systolic_array.py View on Github external
"(p // (P - 1)) * (N / P) * K * M"),
            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"),
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 / samples / fpga / gemm_fpga_systolic.py View on Github external
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(
                "(p // (P - 1)) * (N / P) * K * M"),
            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)"),
github spcl / dace / tests / cuda_blockreduce.py View on Github external
# Nodes
A = state.add_array('A', (128, ), dace.float32)
B = state.add_array('B', (2, ), dace.float32)
me, mx = state.add_map('mymap', dict(bi='0:2'))
mei, mxi = state.add_map('mymap2', dict(i='0:32'))
red = state.add_reduce('lambda a,b: a+b', None, 0,
                       dace.ScheduleType.GPU_ThreadBlock)
tA = state.add_transient('tA', (2, ), dace.float32)
tB = state.add_transient('tB', (1, ), dace.float32)
write_tasklet = state.add_tasklet('writeout', {'inp'}, {'out'},
                                  'if i == 0: out = inp')

# Edges
state.add_edge(A, None, me, None, Memlet.simple(A, '0:128'))
state.add_edge(me, None, mei, None, Memlet.simple(A, '(64*bi):(64*bi+64)'))
state.add_edge(mei, None, tA, None,
               Memlet.simple('A', '(64*bi+2*i):(64*bi+2*i+2)'))
state.add_edge(tA, None, red, None, Memlet.simple(tA, '0:2'))
state.add_edge(red, None, tB, None, Memlet.simple(tB, '0'))
state.add_edge(tB, None, write_tasklet, 'inp', Memlet.simple(tB, '0'))
state.add_edge(write_tasklet, 'out', mxi, None,
               Memlet('B', -1, dace.subsets.Indices(['bi']), 1))
state.add_edge(mxi, None, mx, None, Memlet.simple(B, 'bi'))
state.add_edge(mx, None, B, None, Memlet.simple(B, '0:2'))
sdfg.fill_scope_connectors()

if __name__ == '__main__':
    print('Block reduction test')

    sdfg.draw_to_file()
github spcl / dace / tests / intel_fpga / veclen_conversion.py View on Github external
state = sdfg.add_state("copy_to_device")

    A_host = sdfg.add_array("A", [SIZE], dtype=DTYPE)

    A_device = sdfg.add_array("A_device", [SIZE],
                              dtype=DTYPE,
                              transient=True,
                              storage=dace.dtypes.StorageType.FPGA_Global)

    read = state.add_read("A")
    write = state.add_write("A_device")

    state.add_memlet_path(read,
                          write,
                          memlet=dace.memlet.Memlet.simple(
                              "A_device",
                              "0:N",
                              veclen=VECTOR_LENGTH.get(),
                              num_accesses=SIZE))

    return state
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
"B_stream_in", dace.float32, storage=dace.dtypes.StorageType.FPGA_Local)
    B_pipe_out = state.add_stream(
        "B_stream_out",
        dace.float32,
        storage=dace.dtypes.StorageType.FPGA_Local)

    # N-loop
    sdfg.add_edge(
        n_begin,
        n_entry,
        dace.graph.edges.InterstateEdge(assignments={"n0": 0}))
    sdfg.add_edge(
        n_entry,
        k_begin,
        dace.graph.edges.InterstateEdge(
            condition=dace.properties.CodeProperty.from_string(
                "n0 < N / P", language=dace.dtypes.Language.Python)))
    sdfg.add_edge(
        n_entry,
        n_end,
        dace.graph.edges.InterstateEdge(
            condition=dace.properties.CodeProperty.from_string(
                "n0 >= N / P", language=dace.dtypes.Language.Python)))

    # K-loop
    sdfg.add_edge(
        k_begin,
        k_entry,
        dace.graph.edges.InterstateEdge(assignments={"k": 0}))
    sdfg.add_edge(
        k_entry,
        a_begin,
github spcl / dace / tests / intel_fpga / simple_systolic_array.py View on Github external
memlet=dace.memlet.EmptyMemlet())

    # Connect data nodes
    state.add_memlet_path(A_pipe_in,
                          compute_sdfg_node,
                          dst_conn="A_stream_in",
                          memlet=dace.memlet.Memlet(
                              A_pipe_in,
                              dace.symbolic.pystr_to_symbolic("N/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"),
            dace.properties.SubsetProperty.from_string("p + 1"), 1))

    state.add_memlet_path(
        A_IN,
        read_A_sdfg_node,
        dst_conn="mem",
        memlet=dace.memlet.Memlet(
            A_IN, dace.symbolic.pystr_to_symbolic("N"),
            dace.properties.SubsetProperty.from_string("0:N"), 1))
    state.add_memlet_path(read_A_sdfg_node,
                          A_pipe_read,
                          src_conn="pipe",
                          memlet=dace.memlet.Memlet(
                              A_pipe_in, dace.symbolic.pystr_to_symbolic("N"),
                              dace.properties.SubsetProperty.from_string("0"),
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
"A_reg",
        dtype=dace.float32,
        transient=True,
        storage=dace.dtypes.StorageType.FPGA_Registers)
    buffer_a_tasklet = buffer_a_state.add_tasklet(
        "buffer_a", {"a_in"}, {"a_reg", "a_out"}, "a_input = float(0)" 
        "\nif n1 == P-p-1 or p < P - 1: a_input = a_in"
        "\nif n1 == P - p - 1:"
        "\n\ta_reg = a_input"
        "\nelse:"
        "\n\tif p < P - 1:"
        "\n\t\ta_out = a_input")
    buffer_a_state.add_memlet_path(
        A_pipe_in,
        buffer_a_tasklet,
        memlet=dace.memlet.Memlet(
            A_pipe_in, dace.symbolic.pystr_to_symbolic("-1"),
            dace.properties.SubsetProperty.from_string("0"), 1),
        dst_conn="a_in")
    buffer_a_state.add_memlet_path(
        buffer_a_tasklet,
        A_reg_out,
        memlet=dace.memlet.Memlet(
            A_reg_out, dace.symbolic.pystr_to_symbolic("-1"),
            dace.properties.SubsetProperty.from_string("0"), 1),
        src_conn="a_reg")
    buffer_a_state.add_memlet_path(
        buffer_a_tasklet,
        A_pipe_out,
        memlet=dace.memlet.Memlet(
            A_pipe_out, dace.symbolic.pystr_to_symbolic("-1"),
            dace.properties.SubsetProperty.from_string("0"), 1),
github spcl / dace / tests / intel_fpga / gemm_systolic_array.py View on Github external
dace.graph.edges.InterstateEdge(
            condition=dace.properties.CodeProperty.from_string(
                "m >= M", language=dace.dtypes.Language.Python)))

    mem = loop_body.add_array(
        "mem", [N, M],
        dtype=dace.float32,
        storage=dace.dtypes.StorageType.FPGA_Global)

    pipe = loop_body.add_stream(
        "pipe", dace.float32, storage=dace.dtypes.StorageType.FPGA_Local)

    loop_body.add_memlet_path(
        pipe,
        mem,
        memlet=dace.memlet.Memlet(
            mem,
            dace.symbolic.pystr_to_symbolic("1"),
            dace.properties.SubsetProperty.from_string("n, m"),
            1,
            other_subset=dace.properties.SubsetProperty.from_string("0")))

    return sdfg
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))