diff --git a/loopy/__init__.py b/loopy/__init__.py index 34d417f90fa9afd15f3fd689bea7338e3f8de743..0389fb8644872adde8ca30b3c17078ff7ec134be 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -23,14 +23,6 @@ THE SOFTWARE. """ -def register_mpz_with_pymbolic(): - from pymbolic.primitives import register_constant_class - import gmpy - mpz_type = type(gmpy.mpz(1)) - register_constant_class(mpz_type) - -register_mpz_with_pymbolic() - import islpy as isl from islpy import dim_type @@ -364,7 +356,7 @@ def join_inames(kernel, inames, new_iname=None, tag=None, within=None): for i, iname in enumerate(inames): iname_dt, iname_idx = zero.get_space().get_var_dict()[iname] - iname_aff = zero.add_coefficient(iname_dt, iname_idx, 1) + iname_aff = zero.add_coefficient_val(iname_dt, iname_idx, 1) joint_aff = joint_aff + base_divisor*iname_aff diff --git a/loopy/check.py b/loopy/check.py index 6435c7a3fca267698f4eecec75251d7c846fff91..ab45de8b6f07469d903d35f794f1eb951cf361f2 100644 --- a/loopy/check.py +++ b/loopy/check.py @@ -36,7 +36,7 @@ logger = logging.getLogger(__name__) def check_temp_variable_shapes_are_constant(kernel): for tv in kernel.temporary_variables.itervalues(): - if any(not isinstance(s_i, int) for s_i in tv.shape): + if any(not isinstance(s_i, (int, long)) for s_i in tv.shape): raise LoopyError("shape of temporary variable '%s' is not " "constant (but has to be since the size of " "the temporary needs to be known at build time). " @@ -531,7 +531,8 @@ def check_implemented_domains(kernel, implemented_domains, code=None): point_axes = [] for iname in kernel.insn_inames(insn) | parameter_inames: tp, dim = iname_to_dim[iname] - point_axes.append("%s=%d" % (iname, pt.get_coordinate(tp, dim))) + point_axes.append("%s=%d" % ( + iname, pt.get_coordinate_val(tp, dim).to_python())) lines.append( "sample point %s: %s" % (kind, ", ".join(point_axes))) diff --git a/loopy/codegen/expression.py b/loopy/codegen/expression.py index 322a7c3aecebe1ec4367f15f1c00148c08e61b66..a996f7d1461adb8cd628116932a9dcbd6786e307 100644 --- a/loopy/codegen/expression.py +++ b/loopy/codegen/expression.py @@ -84,7 +84,7 @@ class TypeInferenceMapper(CombineMapper): small_integer_dtypes = [] for child in expr.children: dtype = self.rec(child) - if isinstance(child, (int, np.integer)) and abs(child) < 1024: + if isinstance(child, (int, long, np.integer)) and abs(child) < 1024: small_integer_dtypes.append(dtype) else: dtypes.append(dtype) @@ -109,7 +109,7 @@ class TypeInferenceMapper(CombineMapper): return self.combine([n_dtype, d_dtype]) def map_constant(self, expr): - if isinstance(expr, int): + if isinstance(expr, (int, long)): for tp in [np.int32, np.int64]: iinfo = np.iinfo(tp) if iinfo.min <= expr <= iinfo.max: @@ -258,7 +258,8 @@ def get_opencl_vec_member(idx): if idx is None: return idx - return "s%s" % hex(idx)[2:] + # The 'int' avoids an 'L' suffix for long ints. + return "s%s" % hex(int(idx))[2:] class SeenFunction(Record): @@ -625,8 +626,8 @@ class LoopyCCodeMapper(RecursiveMapper): elif type_context == "i": return str(int(expr)) else: - if isinstance(expr, int): - return str(int(expr)) + if isinstance(expr, (int, long)): + return str(expr) raise RuntimeError("don't know how to generated code " "for constant '%s'" % expr) diff --git a/loopy/isl_helpers.py b/loopy/isl_helpers.py index f8c52b2a0c0802b991aa86362e93d0ecf5bcd900..a0b94cce0089ae56e06b131589968cebde8a714e 100644 --- a/loopy/isl_helpers.py +++ b/loopy/isl_helpers.py @@ -139,7 +139,7 @@ def make_slab(space, iname, start, stop): else: iname_dt, iname_idx = iname - iname_aff = zero.add_coefficient(iname_dt, iname_idx, 1) + iname_aff = zero.add_coefficient_val(iname_dt, iname_idx, 1) result = (isl.BasicSet.universe(space) # start <= iname @@ -164,13 +164,13 @@ def iname_rel_aff(space, iname, rel, aff): aff = align_spaces(aff, isl.Aff.zero_on_domain(space)) if rel in ["==", "<="]: - return aff.add_coefficient(dt, pos, -1) + return aff.add_coefficient_val(dt, pos, -1) elif rel == ">=": - return aff.neg().add_coefficient(dt, pos, 1) + return aff.neg().add_coefficient_val(dt, pos, 1) elif rel == "<": - return (aff-1).add_coefficient(dt, pos, -1) + return (aff-1).add_coefficient_val(dt, pos, -1) elif rel == ">": - return (aff+1).neg().add_coefficient(dt, pos, 1) + return (aff+1).neg().add_coefficient_val(dt, pos, 1) else: raise ValueError("unknown value of 'rel': %s" % rel) @@ -342,7 +342,7 @@ def boxify(cache_manager, domain, box_inames, context): zero = isl.Aff.zero_on_domain(result.space) for i in xrange(len(box_iname_indices)): - iname_aff = zero.add_coefficient(dim_type.in_, i, 1) + iname_aff = zero.add_coefficient_val(dim_type.in_, i, 1) def add_in_dims(aff): return aff.add_dims(dim_type.in_, len(box_inames)) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 9c21a04e62f455cadc7b06a3b4d60bb35a14802c..4a500eff593c6cfea44165259a9e9fb172297697 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -980,7 +980,7 @@ def get_access_info(ary, index, eval_expr): elif isinstance(dim_tag, VectorArrayDimTag): idx = eval_expr_wrapper(i, idx) - if not isinstance(idx, int): + if not isinstance(idx, (int, long)): raise LoopyError("subscript '%s[%s]' has non-constant " "index for separate-array axis %d (0-based)" % ( ary.name, index, i)) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 15d2000325af02a988f8fe07fa6a51885161d4e1..dc9329dc0110d4b54db4ad50cf72bcdd0478b056 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -33,6 +33,7 @@ import islpy as isl from islpy import dim_type import re +import sys import logging logger = logging.getLogger(__name__) @@ -861,7 +862,7 @@ def guess_arg_shape_if_requested(kernel, default_order): armap.access_range, i) + 1, constants_only=False))) except: - print "While trying to find shape axis %d of "\ + print>>sys.stderr, "While trying to find shape axis %d of "\ "argument '%s', the following " \ "exception occurred:" % (i, arg.name) raise diff --git a/loopy/symbolic.py b/loopy/symbolic.py index c0ce808c1e08d97c7d57609205143f47b2730e35..8baa28ed1731bf82933e8e65b9f2a5bdbe0cac3e 100644 --- a/loopy/symbolic.py +++ b/loopy/symbolic.py @@ -754,10 +754,12 @@ def aff_to_expr(aff, except_name=None, error_on_name=None): except_coeff = 0 - result = int(aff.get_constant()) + denom = aff.get_denominator_val().to_python() + + result = (aff.get_constant_val()*denom).to_python() for dt in [dim_type.in_, dim_type.param]: for i in xrange(aff.dim(dt)): - coeff = int(aff.get_coefficient(dt, i)) + coeff = (aff.get_coefficient_val(dt, i)*denom).to_python() if coeff: dim_name = aff.get_dim_name(dt, i) if dim_name == except_name: @@ -771,11 +773,10 @@ def aff_to_expr(aff, except_name=None, error_on_name=None): error_on_name = error_on_name or except_name for i in xrange(aff.dim(dim_type.div)): - coeff = int(aff.get_coefficient(dim_type.div, i)) + coeff = (aff.get_coefficient_val(dim_type.div, i)*denom).to_python() if coeff: result += coeff*aff_to_expr(aff.get_div(i), error_on_name=error_on_name) - denom = int(aff.get_denominator()) if except_name is not None: if except_coeff % denom != 0: raise RuntimeError("coefficient of '%s' is not divisible by " @@ -810,7 +811,7 @@ def aff_from_expr(space, expr, vars_to_zero=set()): if dt == dim_type.set: dt = dim_type.in_ - context[name] = zero.set_coefficient(dt, pos, 1) + context[name] = zero.set_coefficient_val(dt, pos, 1) for name in vars_to_zero: context[name] = zero @@ -961,7 +962,7 @@ def get_access_range(domain, subscript, assumptions): for idim in xrange(dims): idx_aff = aff_from_expr(access_map.get_space(), subscript[idim]) - idx_aff = idx_aff.set_coefficient( + idx_aff = idx_aff.set_coefficient_val( dim_type.in_, dn+idim, -1) access_map = access_map.add_constraint( diff --git a/setup.py b/setup.py index 0a2edd5aafc157fd10c466994ef5ef3c4166f641..a2527a1578afaacf8c260f847166931446d78093 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ setup(name="loo.py", "pyopencl>=2013.1", "pymbolic>=2013.2", "cgen", - "islpy>=2013.2" + "islpy>=2014.1" ], author="Andreas Kloeckner", diff --git a/test/test_isl.py b/test/test_isl.py index b9fd4dbc2b88acea71a99993b460033693db00f6..54759234b8b2976b1e3b896323c70fb890c47a43 100644 --- a/test/test_isl.py +++ b/test/test_isl.py @@ -20,20 +20,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - - - import islpy as isl - - def test_aff_to_expr(): s = isl.Space.create_from_names(isl.Context(), ["a", "b"]) zero = isl.Aff.zero_on_domain(isl.LocalSpace.from_space(s)) - one = zero.set_constant(1) - a = zero.set_coefficient(isl.dim_type.in_, 0, 1) - b = zero.set_coefficient(isl.dim_type.in_, 1, 1) + one = zero.set_constant_val(1) # noqa + a = zero.set_coefficient_val(isl.dim_type.in_, 0, 1) + b = zero.set_coefficient_val(isl.dim_type.in_, 1, 1) x = (5*a + 3*b) % 17 % 5 print x @@ -41,8 +36,6 @@ def test_aff_to_expr(): print aff_to_expr(x) - - if __name__ == "__main__": import sys if len(sys.argv) > 1: