diff --git a/dace/codegen/targets/cpp.py b/dace/codegen/targets/cpp.py index c34c829c31..82d57c9a99 100644 --- a/dace/codegen/targets/cpp.py +++ b/dace/codegen/targets/cpp.py @@ -277,7 +277,8 @@ def emit_memlet_reference(dispatcher: 'TargetDispatcher', ancestor: int = 1, is_write: bool = None, device_code: bool = False, - decouple_array_interfaces: bool = False) -> Tuple[str, str, str]: + decouple_array_interfaces: bool = False, + use_offset: bool = False) -> Tuple[str, str, str]: """ Returns a tuple of three strings with a definition of a reference to an existing memlet. Used in nested SDFG arguments. @@ -289,7 +290,7 @@ def emit_memlet_reference(dispatcher: 'TargetDispatcher', """ desc = sdfg.arrays[memlet.data] typedef = conntype.ctype - offset = cpp_offset_expr(desc, memlet.subset) + offset = cpp_offset_expr(desc, memlet.subset) if use_offset else '0' offset_expr = '[' + offset + ']' is_scalar = not isinstance(conntype, dtypes.pointer) ptrname = ptr(memlet.data, desc, sdfg, dispatcher.frame) @@ -368,7 +369,7 @@ def make_const(expr: str) -> str: is_scalar = True elif defined_type == DefinedType.StreamArray: # Stream array to stream (reference) - if memlet.subset.num_elements() == 1: + if use_offset and memlet.subset.num_elements() == 1: ref = '&' typedef = defined_ctype is_scalar = True # Avoid "&" in expression below diff --git a/dace/codegen/targets/cpu.py b/dace/codegen/targets/cpu.py index 51daaa432b..9d2719e6e5 100644 --- a/dace/codegen/targets/cpu.py +++ b/dace/codegen/targets/cpu.py @@ -233,7 +233,8 @@ def allocate_view(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: SDFGState, stat name, dtypes.pointer(nodedesc.dtype), ancestor=0, - is_write=is_write) + is_write=is_write, + use_offset=True) # Test for views of container arrays and structs if isinstance(sdfg.arrays[viewed_dnode.data], (data.Structure, data.ContainerArray, data.ContainerView)): diff --git a/dace/codegen/targets/intel_fpga.py b/dace/codegen/targets/intel_fpga.py index 513dc0bbfc..79b1c52c35 100644 --- a/dace/codegen/targets/intel_fpga.py +++ b/dace/codegen/targets/intel_fpga.py @@ -921,7 +921,8 @@ def allocate_view(self, sdfg: dace.SDFG, cfg: ControlFlowRegion, dfg: SDFGState, name, dtypes.pointer(nodedesc.dtype), ancestor=0, - device_code=self._in_device_code) + device_code=self._in_device_code, + use_offset=True) else: qualifier = "" atype, aname, value = cpp.emit_memlet_reference(self._dispatcher, @@ -929,7 +930,8 @@ def allocate_view(self, sdfg: dace.SDFG, cfg: ControlFlowRegion, dfg: SDFGState, edge.data, name, dtypes.pointer(nodedesc.dtype), - ancestor=0) + ancestor=0, + use_offset=True) declaration_stream.write(f'{qualifier}{atype} {aname} = {value};', cfg, state_id, node) def generate_memlet_definition(self, sdfg, cfg, dfg, state_id, src_node, dst_node, edge, callsite_stream):