Skip to content

Commit

Permalink
Add Object to defined types in code generation and some documentation (
Browse files Browse the repository at this point in the history
…#1343)

Co-authored-by: acalotoiu <61420859+acalotoiu@users.noreply.github.com>
  • Loading branch information
tbennun and acalotoiu committed Aug 4, 2023
1 parent 7171ecc commit 425fed6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions dace/codegen/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class DefinedType(aenum.AutoNumberEnum):
:see: DefinedMemlets
"""
Pointer = ()
Scalar = ()
Stream = ()
StreamArray = ()
FPGA_ShiftRegister = ()
ArrayInterface = ()
Pointer = () # Pointer
Scalar = () # A copyable scalar moved by value (e.g., POD)
Object = () # An object moved by reference
Stream = () # A stream object moved by reference and accessed via a push/pop API
StreamArray = () # An array of Streams
FPGA_ShiftRegister = () # A shift-register object used in FPGA code generation
ArrayInterface = () # An object representing an interface to an array, used mostly in FPGA


class DefinedMemlets:
Expand Down
6 changes: 3 additions & 3 deletions dace/codegen/targets/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def copy_expr(
elif def_type == DefinedType.FPGA_ShiftRegister:
return expr

elif def_type in [DefinedType.Scalar, DefinedType.Stream]:
elif def_type in [DefinedType.Scalar, DefinedType.Stream, DefinedType.Object]:

if add_offset:
raise TypeError("Tried to offset address of scalar {}: {}".format(data_name, offset_cppstr))
Expand Down Expand Up @@ -327,7 +327,7 @@ def make_const(expr: str) -> str:
ref = '&' if is_scalar else ''
defined_type = DefinedType.Scalar if is_scalar else DefinedType.Pointer
offset_expr = ''
elif defined_type == DefinedType.Stream:
elif defined_type in (DefinedType.Stream, DefinedType.Object):
typedef = defined_ctype
ref = '&'
offset_expr = ''
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def visit_Name(self, node: ast.Name):
defined_type = None
if (self.allow_casts and isinstance(dtype, dtypes.pointer) and memlet.subset.num_elements() == 1):
return ast.parse(f"{name}[0]").body[0].value
elif (self.allow_casts and (defined_type == DefinedType.Stream or defined_type == DefinedType.StreamArray)
elif (self.allow_casts and (defined_type in (DefinedType.Stream, DefinedType.StreamArray))
and memlet.dynamic):
return ast.parse(f"{name}.pop()").body[0].value
else:
Expand Down
2 changes: 1 addition & 1 deletion dace/codegen/targets/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def memlet_ctor(self, sdfg, memlet, dtype, is_output):
ptrname = cpp.ptr(memlet.data, sdfg.arrays[memlet.data], sdfg, self._frame)
def_type, _ = self._dispatcher.defined_vars.get(ptrname)

if def_type in [DefinedType.Stream, DefinedType.StreamArray]:
if def_type in [DefinedType.Stream, DefinedType.Object, DefinedType.StreamArray]:
return self.memlet_stream_ctor(sdfg, memlet)

elif def_type in [DefinedType.Pointer, DefinedType.Scalar]:
Expand Down
2 changes: 1 addition & 1 deletion samples/codegen/tensor_cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def allocate_array(self, sdfg: dace.SDFG, dfg: StateSubgraphView, state_id: int,

# Add the ctype to defined_vars so that the codegen can properly pass
# fragments to functions as an object reference.
self._dispatcher.defined_vars.add(name, DefinedType.Stream, ctype)
self._dispatcher.defined_vars.add(name, DefinedType.Object, ctype)

def deallocate_array(self, sdfg: dace.SDFG, dfg: StateSubgraphView, state_id: int, node: nodes.AccessNode,
nodedesc: dt.Array, function_stream: CodeIOStream, callsite_stream: CodeIOStream):
Expand Down

0 comments on commit 425fed6

Please sign in to comment.