Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)"),
"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
the memlet uninitialized until inserted into an SDFG.
"""
expr = expr.strip()
if '->' not in expr: # Options 1 and 2
self.data, self.subset = self._parse_from_subexpr(expr)
return
# Option 3
src_expr, dst_expr = expr.split('->')
src_expr = src_expr.strip()
dst_expr = dst_expr.strip()
if '[' not in src_expr and not dtypes.validate_name(src_expr):
raise SyntaxError('Expression without data name not yet allowed')
self.data, self.subset = self._parse_from_subexpr(src_expr)
self.other_subset = SubsetProperty.from_string(dst_expr)
"if y < H - 1 and x < W - 1:\n\twindow_buffer = read")
pre_shift.add_memlet_path(stream_in,
read_memory_tasklet,
memlet=read_memory_memlet,
dst_conn="read")
pre_shift.add_memlet_path(read_memory_tasklet,
window_buffer_out,
memlet=dace.memlet.Memlet.simple(
window_buffer_out, "2, 2"),
src_conn="window_buffer")
# Shift window
shift_window_memlet = dace.memlet.Memlet(
window_shift_in,
dace.symbolic.pystr_to_symbolic("6"),
dace.properties.SubsetProperty.from_string("0:3, 1:3"),
1,
other_subset=dace.properties.SubsetProperty.from_string("0:3, 0:2"))
post_shift.add_memlet_path(window_shift_in,
window_shift_out,
memlet=shift_window_memlet)
# To row buffer
write_row_memlet = dace.memlet.Memlet(
window_buffer_in,
dace.symbolic.pystr_to_symbolic("2"),
dace.properties.SubsetProperty.from_string("1:3, 2"),
1,
other_subset=dace.properties.SubsetProperty.from_string("0:2, x"))
post_shift.add_memlet_path(window_buffer_in,
rows_out,
memlet=write_row_memlet)
window_shift_in,
dace.symbolic.pystr_to_symbolic("6"),
dace.properties.SubsetProperty.from_string("0:3, 1:3"),
1,
other_subset=dace.properties.SubsetProperty.from_string("0:3, 0:2"))
post_shift.add_memlet_path(window_shift_in,
window_shift_out,
memlet=shift_window_memlet)
# To row buffer
write_row_memlet = dace.memlet.Memlet(
window_buffer_in,
dace.symbolic.pystr_to_symbolic("2"),
dace.properties.SubsetProperty.from_string("1:3, 2"),
1,
other_subset=dace.properties.SubsetProperty.from_string("0:2, x"))
post_shift.add_memlet_path(window_buffer_in,
rows_out,
memlet=write_row_memlet)
return sdfg
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(
mem,
pipe,
memlet=dace.memlet.Memlet(
pipe,
dace.symbolic.pystr_to_symbolic("1"),
dace.properties.SubsetProperty.from_string("0"),
1,
other_subset=dace.properties.SubsetProperty.from_string("k, m")))
return sdfg
"\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),
src_conn="a_out")
###########################################################################
# Nested SDFG
nested_sdfg = dace.SDFG("gemm_nested")
if_state_c = nested_sdfg.add_state("if_state_c")
then_state_c = nested_sdfg.add_state("then_state_c")
pipes_write,
src_conn="stream_out",
memlet=dace.memlet.Memlet(
pipes_write, dace.symbolic.pystr_to_symbolic("(T/P)*H*W"),
dace.properties.SubsetProperty.from_string("p + 1"), 1))
state.add_memlet_path(pipes_write,
compute_exit,
memlet=dace.memlet.EmptyMemlet())
state.add_memlet_path(pipes_memory_read,
write_sdfg_node,
dst_conn="pipe",
memlet=dace.memlet.Memlet(
pipes_memory_read,
dace.symbolic.pystr_to_symbolic("(T/P)*H*W"),
dace.properties.SubsetProperty.from_string("P"),
1))
state.add_memlet_path(write_sdfg_node,
tmp_out,
src_conn="mem_write",
memlet=dace.memlet.Memlet.simple(
tmp_out, "0:2, 0:H, 0:W"))
return state
def _map_from_ndrange(self,
name,
schedule,
unroll,
ndrange,
debuginfo=None):
# Input can either be a dictionary or a list of pairs
if isinstance(ndrange, list):
params = [k for k, v in ndrange]
ndrange = {k: v for k, v in ndrange}
else:
params = list(ndrange.keys())
map_range = properties.SubsetProperty.from_string(', '.join(
[ndrange[p] for p in params]))
map = nd.Map(
name, params, map_range, schedule, unroll, debuginfo=debuginfo)
return map