-
Notifications
You must be signed in to change notification settings - Fork 228
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
[RFC] compiler: Add new HaloSpot optimization #2475
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,39 @@ class HaloLabel(Tag): | |
STENCIL = HaloLabel('stencil') | ||
|
||
|
||
HaloSchemeEntry = namedtuple('HaloSchemeEntry', 'loc_indices loc_dirs halos dims') | ||
class HaloSchemeEntry: | ||
|
||
def __init__(self, loc_indices, loc_dirs, halos, dims): | ||
self.loc_indices = loc_indices | ||
self.loc_dirs = loc_dirs | ||
self.halos = halos | ||
self.dims = dims | ||
|
||
def __repr__(self): | ||
return (f"HaloSchemeEntry(loc_indices={self.loc_indices}, " | ||
f"loc_dirs={self.loc_dirs}, halos={self.halos}, dims={self.dims})") | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, HaloSchemeEntry): | ||
return False | ||
return (self.loc_indices == other.loc_indices and | ||
self.loc_dirs == other.loc_dirs and | ||
self.halos == other.halos and | ||
self.dims == other.dims) | ||
|
||
def __hash__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was autocompleted by copilot. |
||
return hash((frozenset(self.loc_indices.items()), | ||
frozenset(self.loc_dirs.items()), | ||
frozenset(self.halos), | ||
frozenset(self.dims))) | ||
|
||
def rebuild(self, **kwargs): | ||
loc_indices = kwargs.get('loc_indices', self.loc_indices) | ||
loc_dirs = kwargs.get('loc_dirs', self.loc_dirs) | ||
halos = kwargs.get('halos', self.halos) | ||
dims = kwargs.get('dims', self.dims) | ||
return HaloSchemeEntry(loc_indices, loc_dirs, halos, dims) | ||
|
||
|
||
Halo = namedtuple('Halo', 'dim side') | ||
|
||
|
@@ -95,8 +127,20 @@ def __init__(self, exprs, ispace): | |
self._honored = frozendict(self._honored) | ||
|
||
def __repr__(self): | ||
fnames = ",".join(i.name for i in set(self._mapper)) | ||
return "HaloScheme<%s>" % fnames | ||
fstrings = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same w above |
||
for f in self.fmapper: | ||
loc_indices = set().union(*[self._mapper[f].loc_indices.values()]) | ||
loc_indices = list(loc_indices) | ||
if loc_indices: | ||
loc_indices_str = str(loc_indices) | ||
else: | ||
loc_indices_str = "" | ||
|
||
fstrings.append(f"{f.name}{loc_indices_str}") | ||
|
||
functions = ",".join(fstrings) | ||
|
||
return "%s<%s>" % (self.__class__.__name__, functions) | ||
|
||
def __eq__(self, other): | ||
return (isinstance(other, HaloScheme) and | ||
|
@@ -366,6 +410,10 @@ def distributed_aindices(self): | |
def loc_indices(self): | ||
return set().union(*[i.loc_indices.keys() for i in self.fmapper.values()]) | ||
|
||
@cached_property | ||
def loc_values(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way to get the values of loc_indices? |
||
return set().union(*[i.loc_indices.values() for i in self.fmapper.values()]) | ||
|
||
@cached_property | ||
def arguments(self): | ||
return self.dimensions | set(flatten(self.honored.values())) | ||
|
@@ -635,9 +683,8 @@ def _uxreplace_dispatch_haloscheme(hs0, rule): | |
# Nope, let's try with the next Indexed, if any | ||
continue | ||
|
||
hse = HaloSchemeEntry(frozendict(loc_indices), | ||
frozendict(loc_dirs), | ||
hse0.halos, hse0.dims) | ||
hse = hse0.rebuild(loc_indices=frozendict(loc_indices), | ||
loc_dirs=frozendict(loc_dirs)) | ||
|
||
else: | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we also print the slice for each halospot
i.e. v[t0] instead of just v.
What do you think?