Skip to content
Snippets Groups Projects
Commit 43cc6dbd authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Use straight integer division if isl can show the operands are nonnegative.

parent 28e5c125
No related branches found
No related tags found
No related merge requests found
...@@ -41,9 +41,6 @@ To-do ...@@ -41,9 +41,6 @@ To-do
- Automatically generate testing code vs. sequential. - Automatically generate testing code vs. sequential.
- If isl can prove that all operands are positive, may use '/' instead of
'floor_div'.
- Fix all tests - Fix all tests
- Deal with equality constraints. - Deal with equality constraints.
...@@ -86,6 +83,9 @@ Future ideas ...@@ -86,6 +83,9 @@ Future ideas
Dealt with Dealt with
^^^^^^^^^^ ^^^^^^^^^^
- If isl can prove that all operands are positive, may use '/' instead of
'floor_div'.
- For forced workgroup sizes: check that at least one iname - For forced workgroup sizes: check that at least one iname
maps to them. maps to them.
......
...@@ -227,4 +227,21 @@ def duplicate_axes(isl_obj, duplicate_inames, new_inames): ...@@ -227,4 +227,21 @@ def duplicate_axes(isl_obj, duplicate_inames, new_inames):
def is_nonnegative(expr, over_set):
space = over_set.get_space()
from loopy.symbolic import aff_from_expr
try:
aff = aff_from_expr(space, -expr-1)
except:
return None
expr_neg_set = isl.BasicSet.universe(space).add_constraint(
isl.Constraint.inequality_from_aff(aff))
return over_set.intersect(expr_neg_set).is_empty()
# vim: foldmethod=marker # vim: foldmethod=marker
...@@ -355,10 +355,16 @@ class LoopyCCodeMapper(CCodeMapper): ...@@ -355,10 +355,16 @@ class LoopyCCodeMapper(CCodeMapper):
raise RuntimeError("nothing known about variable '%s'" % expr.aggregate.name) raise RuntimeError("nothing known about variable '%s'" % expr.aggregate.name)
def map_floor_div(self, expr, prec): def map_floor_div(self, expr, prec):
if isinstance(expr.denominator, int) and expr.denominator > 0: from loopy.isl_helpers import is_nonnegative
return ("int_floor_div_pos_b(%s, %s)" num_nonneg = is_nonnegative(expr.numerator, self.kernel.domain)
% (self.rec(expr.numerator, PREC_NONE), den_nonneg = is_nonnegative(expr.denominator, self.kernel.domain)
expr.denominator)) if den_nonneg:
if num_nonneg:
return CCodeMapper.map_quotient(self, expr, prec)
else:
return ("int_floor_div_pos_b(%s, %s)"
% (self.rec(expr.numerator, PREC_NONE),
expr.denominator))
else: else:
return ("int_floor_div(%s, %s)" return ("int_floor_div(%s, %s)"
% (self.rec(expr.numerator, PREC_NONE), % (self.rec(expr.numerator, PREC_NONE),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment