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

Hoist reduction loops #104

Merged
merged 31 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5031f78
Drop precompute routine
FabioLuporini Nov 2, 2016
19fb417
Fix ast_update_rank utility function
FabioLuporini Nov 2, 2016
88373a5
Fix loop fusion in presence of empty loops
FabioLuporini Oct 26, 2016
875b4a0
Fix substituion after loop fusion
FabioLuporini Oct 26, 2016
a7a8ac0
Add block property to For nodes
FabioLuporini Oct 28, 2016
678cade
Make Symbol's rank an actual class (Rank)
FabioLuporini Nov 5, 2016
d110454
Add is_number property to Symbols
FabioLuporini Nov 11, 2016
61757ec
Add more properties to expressions
FabioLuporini Oct 28, 2016
893a4a7
Use lists, not sets, in loops_analysis if possible
FabioLuporini Nov 8, 2016
0e6144f
Add utility to get urepr of (iterable of) nodes
FabioLuporini Oct 31, 2016
ccb798c
Add utils summands function
FabioLuporini Nov 7, 2016
702ab2a
Capture more COFFEE expressions
FabioLuporini Oct 28, 2016
5060a67
Fix operands() for Decl
FabioLuporini Nov 17, 2016
1984750
Generalise CSE's cost model
FabioLuporini Oct 28, 2016
244a7fe
Drop expression graph wherever possible
FabioLuporini Nov 3, 2016
7dd9b23
Generalize and simplify code hoister routines
FabioLuporini Oct 28, 2016
9f62168
Generalize sharing-graph-based expr rewriting
FabioLuporini Nov 3, 2016
ce9ca5d
Add function to hoist reducible loops
FabioLuporini Nov 5, 2016
36d0445
Simplify hoister routines and interface
FabioLuporini Nov 10, 2016
74804a6
Improve sharing-graph-based rewriting
FabioLuporini Nov 14, 2016
8cbcb6f
Introduce ast_reconstructor to avoid deep_copy
FabioLuporini Nov 17, 2016
064ab50
Add utility in_read routine
FabioLuporini Nov 17, 2016
fec3baa
fix expression's reduction_loops property
FabioLuporini Nov 17, 2016
b3b99ff
Simplify ast_replace and update invocations
FabioLuporini Nov 23, 2016
3337830
Speed COFFEE up.
FabioLuporini Nov 23, 2016
6a344e8
minor fixes: flake8, test, cyclic imports
FabioLuporini Nov 25, 2016
c49166b
Merge branch 'master' into hoist-reduction-loops
FabioLuporini Nov 28, 2016
b92f96c
More Python3 compatibility
FabioLuporini Nov 28, 2016
c1cdaae
Avoid assigning utility functions to self
FabioLuporini Nov 28, 2016
2fdef6b
Fix insertion of reducible loops
FabioLuporini Nov 29, 2016
d8f2f0e
Fix conditional handling in rewriter
FabioLuporini Nov 29, 2016
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
3 changes: 0 additions & 3 deletions coffee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import sys

from coffee.citations import update_citations
from coffee.vectorizer import VectStrategy
from coffee.logger import LOG_DEFAULT, set_log_level, warn
from coffee.system import set_architecture, set_compiler, set_isa

Expand Down Expand Up @@ -169,8 +168,6 @@ def set_opt_level(optlevel):
O1 = OptimizationLevel('O1', rewrite=1)
O2 = OptimizationLevel('O2', rewrite=2, dead_ops_elimination=True)
O3 = OptimizationLevel('O3', align_pad=True, **O2)
Ofast = OptimizationLevel('Ofast', vectorize=(VectStrategy.SPEC_UAJ_PADD, 2),
precompute='noloops', **O3)

initialized = False

Expand Down
42 changes: 38 additions & 4 deletions coffee/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ class Symbol(Expr):
a[i][3*j + 2].
"""

def __init__(self, symbol, rank=(), offset=()):
def __init__(self, symbol, rank=None, offset=None):
super(Symbol, self).__init__([])
self.symbol = symbol
self.rank = rank
self.offset = offset or tuple([(1, 0) for r in rank])
self.rank = Rank(rank or ())
self.offset = offset or tuple([(1, 0) for r in self.rank])

def operands(self):
return [self.symbol, self.rank, self.offset], {}
Expand All @@ -465,6 +465,14 @@ def is_const(self):
from .utils import is_const_dim
return not self.rank or all(is_const_dim(r) for r in self.rank)

@property
def is_number(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a specific number type if you wish...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a list of changes for COFFEE in mind including a restructuring of base.py, as well as the addition of new types (eg Number) and class attributes (eg is_Symbol, is_Incr). I'll do this in another PR

try:
float(self.symbol)
return True
except ValueError:
return False

@property
def is_const_offset(self):
from .utils import is_const_dim, flatten
Expand Down Expand Up @@ -715,7 +723,8 @@ def __init__(self, typ, sym, init=None, qualifiers=None, attributes=None,
self._scope = scope or UNKNOWN

def operands(self):
return [self.typ, self.sym, self.init, self.qual, self.attr], {}
return [self.typ, self.sym, self.init, self.qual, self.attr,
self.pointers], {}

def pad(self, new_rank):
self.sym.rank = new_rank
Expand Down Expand Up @@ -893,6 +902,10 @@ def increment(self, value):
def header(self):
return (self.start, self.size, self.increment)

@property
def block(self):
return self.children[0]

@property
def body(self):
return self.children[0].children
Expand Down Expand Up @@ -1209,6 +1222,26 @@ def gencode(self, not_scope=False):
return self.children[0].gencode()


class Rank(tuple):

def __contains__(self, val):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you happy with the usage that sticks an COFFEE expression into rank?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm "kinda happy", in the sense that this Rank class acts as a work around, although there's probably a cleaner solution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, I do not mind having the interface cleanup (which will require corresponding changes in other components) in a separate PR after this one is merged.

from coffee.visitors import FindInstances
if isinstance(val, Node):
val, search = str(val), type(Node)
elif isinstance(val, str):
val, search = val, Symbol
else:
return False
for i in self:
if isinstance(i, Node):
items = FindInstances(search).visit(i)
if any(val == str(i) for i in items[search]):
return True
elif isinstance(i, str) and val == i:
return True
return False


# Utility functions ###


Expand Down Expand Up @@ -1306,6 +1339,7 @@ def __init__(self, scope):
def __str__(self):
return self._scope


LOCAL = Scope("LOCAL")
EXTERNAL = Scope("EXTERNAL")
BUFFER = Scope("BUFFER")
Expand Down
Loading