Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"(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"),
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"),
"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),
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
path = [full_read_node, src] + inp_base_path
elif isinstance(src, nodes.AccessNode):
path = [src] + inp_base_path
else:
raise Exception("Src node type for indirection is invalid.")
graph.add_memlet_path(*path,
dst_conn='__ind_' + local_name,
memlet=fullMemlet)
# Memlet to store the final value into the transient, and to load it into
# the tasklet that needs it
# indirectMemlet = Memlet('__' + local_name + '_value', memlet.num_accesses,
# indirectRange, memlet.veclen)
# graph.add_edge(tasklet, 'lookup', dataNode, None, indirectMemlet)
valueMemlet = Memlet(
tmp_name,
1, # memlet.num_accesses,
indirectRange,
memlet.veclen)
if output:
path = [src] + inp_base_path
if isinstance(src, nodes.AccessNode):
src_conn = None
else:
src_conn = local_name
graph.add_memlet_path(*path,
src_conn=src_conn,
dst_conn='lookup',
memlet=valueMemlet)
# Connect original source to the indirected-range-transient
if start_src:
tasklet,
dst_conn="window",
memlet=dace.memlet.Memlet.simple(
window_compute_in, "0:3, 0:3"))
# Output result (conditional write)
out_memlet = dace.memlet.Memlet(
stream_out, dace.symbolic.pystr_to_symbolic("-1"),
dace.properties.SubsetProperty.from_string("0"), 1)
loop_body.add_memlet_path(tasklet,
stream_out,
src_conn="result",
memlet=out_memlet)
# Read row buffer
read_row_memlet = dace.memlet.Memlet(
rows_in,
dace.symbolic.pystr_to_symbolic("2"),
dace.properties.SubsetProperty.from_string("0:2, x"),
1,
other_subset=dace.properties.SubsetProperty.from_string("0:2, 2"))
pre_shift.add_memlet_path(rows_in,
window_buffer_out,
memlet=read_row_memlet)
# Read from memory
read_memory_memlet = dace.memlet.Memlet(
stream_in, dace.symbolic.pystr_to_symbolic("-1"),
dace.properties.SubsetProperty.from_string("0"), 1)
read_memory_tasklet = pre_shift.add_tasklet(
"skip_last", {"read"}, {"window_buffer"},
"if y < H - 1 and x < W - 1:\n\twindow_buffer = read")
"Transpose only implemented for 2D matrices")
sdfg.add_transient(name, dims, basetype, debuginfo=self.context)
resnode = self.get_datanode(sdfg, state)
self.arg.generate_code(sdfg, state)
A = self.arg.get_datanode(sdfg, state)
N = str(dims[0])
M = str(dims[1])
s = sdfg.nodes()[state]
map_entry, map_exit = s.add_map('transpose',
dict(i='0:' + N, j='0:' + M))
map_entry._in_connectors.add('IN_1')
map_entry._out_connectors.add('OUT_1')
s.add_edge(A, None, map_entry, 'IN_1',
dace.memlet.Memlet.simple(A, '0:' + N + ',0:' + M))
tasklet = s.add_tasklet('identity', {'a'}, {'out'}, 'out = a')
s.add_edge(map_entry, "OUT_1", tasklet, "a",
dace.memlet.Memlet.simple(A, 'i,j'))
s.add_edge(tasklet, "out", map_exit, None,
dace.memlet.Memlet.simple(resnode, 'j,i'))
s.add_edge(map_exit, None, resnode, None,
dace.memlet.Memlet.simple(resnode, '0:' + M + ', 0:' + N))
print("The result of expr " + str(self) + " will be stored in " +
str(name))
storage=dace.dtypes.StorageType.FPGA_Global)
hist_host = state.add_array("hist", (num_bins, ), itype)
hist_device = state.add_array(
"hist_device", (num_bins, ),
itype,
transient=True,
storage=dace.dtypes.StorageType.FPGA_Global)
state.add_memlet_path(
a_host,
a_device,
memlet=dace.memlet.Memlet.simple(a_device, "0:H, 0:W", veclen=P.get()))
state.add_memlet_path(
hist_host,
hist_device,
memlet=dace.memlet.Memlet.simple(hist_device, "0:num_bins"))
return state
debuginfo=desc.debuginfo,
allow_conflicts=desc.allow_conflicts,
find_new_name=True)
# Add extra nodes in component boundaries
for edge in edges:
anode = state.add_access(name)
sbs = subsets.Range.from_string(','.join(outer_map.params))
# Offset memlet by map range begin (to fit the transient)
sbs.offset([r[0] for r in outer_map.range], True)
state.add_edge(
edge.src, edge.src_conn, anode, None,
mm.Memlet(name, outer_map.range.num_elements(), sbs, 1))
state.add_edge(
anode, None, edge.dst, edge.dst_conn,
mm.Memlet(name, outer_map.range.num_elements(), sbs, 1))
state.remove_edge(edge)
# Add extra maps around components
new_map_entries = []
for component_in, component_out in components:
me, mx = state.add_map(outer_map.label + '_fission',
[(p, '0:1') for p in outer_map.params],
outer_map.schedule,
unroll=outer_map.unroll,
debuginfo=outer_map.debuginfo)
# Add dynamic input connectors
for conn in map_entry.in_connectors:
if not conn.startswith('IN_'):
me.add_in_connector(conn)