Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container Groups #1719

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0a1fb65
Add auxiliary functions for data group name demangling
ThrudPrimrose Oct 18, 2024
c1d1bd7
Clean imports, minor reformatting
ThrudPrimrose Oct 18, 2024
b305098
Improve data group name demangling functionality
ThrudPrimrose Oct 21, 2024
d8141fd
Merge branch 'master' into data_groups
ThrudPrimrose Oct 22, 2024
96befbf
Minor updates to SDFG
ThrudPrimrose Oct 24, 2024
941ba14
Merge branch 'master' into data_groups
ThrudPrimrose Oct 24, 2024
64b4fb8
Merge branch 'main' into data_groups
ThrudPrimrose Oct 31, 2024
beb0cb8
Merge branch 'main' into container-groups
ThrudPrimrose Nov 1, 2024
29ec264
Add struct to container group transformation to container groups
ThrudPrimrose Nov 1, 2024
23021f2
Rename DataGroup to ContainerGroup add flattening mode
ThrudPrimrose Nov 1, 2024
6728396
Rename DataGroup to ContainerGroup add flattening mode
ThrudPrimrose Nov 1, 2024
7550522
Try to improve flattening
ThrudPrimrose Nov 1, 2024
7da1715
Merge branch 'main' into container-groups
ThrudPrimrose Dec 13, 2024
5fc17b7
Minor refactor, add a test
ThrudPrimrose Dec 13, 2024
39d3db2
Add sdfg that uses container array
ThrudPrimrose Dec 13, 2024
e35496b
attempt to support container arrays
ThrudPrimrose Dec 16, 2024
78dd0f5
Various fixes to view chains
ThrudPrimrose Dec 16, 2024
49c1a20
Updates to struct to container transformation
ThrudPrimrose Dec 17, 2024
ee411d8
View removal fixes
ThrudPrimrose Dec 17, 2024
a132843
More fixes and test improvements
ThrudPrimrose Dec 17, 2024
e431372
Merge branch 'main' into container-groups
ThrudPrimrose Dec 17, 2024
166f843
Refactor
ThrudPrimrose Dec 17, 2024
2f53cbf
Bring back webclient
ThrudPrimrose Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
url = https://github.com/spcl/dace-webclient.git
[submodule "dace/external/rtllib"]
path = dace/external/rtllib
url = https://github.com/carljohnsen/rtllib.git
url = https://github.com/carljohnsen/rtllib.git
173 changes: 173 additions & 0 deletions dace/sdfg/container_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved.
from collections import OrderedDict
from typing import Set, Union
import typing
from dace import data
from dace.data import Data
from dace import serialize, symbolic
from dace.properties import ListProperty, OrderedDictProperty, Property, make_properties
from enum import Enum

import numpy
import sympy


class ContainerGroupFlatteningMode(Enum):
ArrayOfStructs = 1
StructOfArrays = 2


def _members_to_json(members):
if members is None:
return None
return [(k, serialize.to_json(v)) for k, v in members.items()]


def _members_from_json(obj, context=None):
if obj is None:
return {}
return OrderedDict((k, serialize.from_json(v, context)) for k, v in obj)


@make_properties
class ContainerGroup:
name = Property(dtype=str, default="", allow_none=False)
members = OrderedDictProperty(
default=OrderedDict(),
desc="Dictionary of structure members",
from_json=_members_from_json,
to_json=_members_to_json,
)
is_cg = Property(dtype=bool, default=False, allow_none=False)
is_ca = Property(dtype=bool, default=False, allow_none=False)
shape = Property(dtype=tuple, default=(1, ), allow_none=False)

def __init__(self, name, is_cg, is_ca, shape):
self.name = name
self.members = OrderedDict()
self.is_cg = is_cg
self.is_ca = is_ca
self.shape = shape
self._validate()

def add_member(self, name: str, member: Union[Data, "ContainerGroup"]):
if name is None or name == "":
name = len(self.members)
self.members[name] = member

@property
def free_symbols(self) -> Set[symbolic.SymbolicType]:
"""Returns a set of undefined symbols in this data descriptor."""
result = set()
for k, v in self.members.items():
result |= v.free_symbols
return result

def __call__(self):
return self

def validate(self):
self._validate()

def _validate(self):
return True

def to_json(self):
attrs = serialize.all_properties_to_json(self)
retdict = {"type": type(self).__name__, "attributes": attrs}
return retdict

def is_equivalent(self, other):
raise NotImplementedError

def __eq__(self, other):
return serialize.dumps(self) == serialize.dumps(other)

def __hash__(self):
return hash(serialize.dumps(self))

def __repr__(self):
members_repr = ", ".join(
f"{k}: {v.__repr__()}" for k, v in self.members.items()
)
return f"ContainerGroup(name='{self.name}', is_cg={self.is_cg}, is_ca={self.is_ca}, shape={self.shape}, members={{ {members_repr} }})"

def __str__(self):
return self.__repr__()

def _soa_from_struct(self, name, structure, acc_shape):
self._add_members(name, structure, acc_shape=None)

@classmethod
def from_struct(
cls,
name: str,
struct_or_container_array: typing.Union[data.Structure, data.ContainerArray],
is_cg: bool,
is_ca: bool,
shape: tuple
) -> "ContainerGroup":
dg = cls(name=name, is_cg=is_cg, is_ca=is_ca, shape=shape)
assert is_cg ^ is_ca

if isinstance(struct_or_container_array, data.Structure):
struct = struct_or_container_array
for member_name, member in struct.members.items():
new_member = None
if isinstance(member, data.Structure):
new_member = cls.from_struct(
name = member_name,
struct_or_container_array = member,
is_cg = True,
is_ca = False,
shape = (1, ))
elif isinstance(member, data.ContainerArray):
new_member = cls.from_struct(name=member_name,
struct_or_container_array = member,
is_cg = False,
is_ca = True,
shape = member.shape)
elif isinstance(member, (data.Array, data.Scalar)):
new_member = member
elif isinstance(
member, (sympy.Basic, symbolic.SymExpr, int, numpy.integer)
):
new_member = data.Scalar(symbolic.symtype(member))
else:
raise TypeError(f"Unsupported member type in Structure: {type(member)}")

dg.add_member(
name=f"{member_name}",
member=new_member
)
else:
assert isinstance(struct_or_container_array, data.ContainerArray)
container_array = struct_or_container_array
member = container_array.stype
member_name = None
new_member = None

if isinstance(member, data.Structure):
# Recursively convert nested Structures
member_name = member.name
new_member = cls.from_struct(name=member.name,
struct_or_container_array=member,
is_cg=True,
is_ca=False,
shape=(1,))
elif isinstance(member, data.ContainerArray):
raise Exception("Two container arrays in a row is currently not supported")
elif isinstance(member, (data.Array, data.Scalar)):
new_member = member
elif isinstance(
member, (sympy.Basic, symbolic.SymExpr, int, numpy.integer)
):
new_member = data.Scalar(symbolic.symtype(member))
else:
raise TypeError(f"Unsupported member type in Structure: {type(member)}")
dg.add_member(
name=member_name if member_name is not None else "Leaf",
member=new_member
)

return dg
Loading
Loading