Author: Richard Plangger <planri...@gmail.com> Branch: vecopt-merge Changeset: r79929:232d93b7d261 Date: 2015-10-02 13:10 +0200 http://bitbucket.org/pypy/pypy/changeset/232d93b7d261/
Log: same operation for iter states failed if index and _indices where not the same (fixed) concrete type of a loaded singlefloat was f, but singlefloat_to_float demands i as parameter diff --git a/pypy/module/micronumpy/iterators.py b/pypy/module/micronumpy/iterators.py --- a/pypy/module/micronumpy/iterators.py +++ b/pypy/module/micronumpy/iterators.py @@ -84,7 +84,9 @@ self.offset = offset def same(self, other): - if self.offset == other.offset: + if self.offset == other.offset and \ + self.index == other.index and \ + self._indices == other._indices: return self.iterator.same_shape(other.iterator) return False @@ -119,9 +121,9 @@ self.factors = factors def same_shape(self, other): - """ if two iterators share the same shape, - next() only needs to be called on one! - """ + """ Iterating over the same element """ + if not self.contiguous or not other.contiguous: + return False return (self.contiguous == other.contiguous and self.array.dtype is self.array.dtype and self.shape_m1 == other.shape_m1 and diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -895,7 +895,8 @@ a = [[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8], [7, 8, 9, 10], [9, 10, 11, 12], [11, 12, 13, 14], [13, 14, 15, 16], [16, 17, 18, 19]] b = a -> ::2 c = b + b - c -> 1 -> 1 + d = c -> 1 + d -> 1 """ def test_multidim_slice(self): @@ -904,7 +905,7 @@ self.check_trace_count(3) # ::2 creates a view object -> needs an inner loop # that iterates continous chunks of the matrix - self.check_vectorized(1,1) + self.check_vectorized(1,0) def define_dot_matrix(): return """ @@ -930,7 +931,6 @@ """ def test_pow(self): - py.test.skip("Not implemented CDefinedIntSymbolic('RPY_TLOFS_rpy_errno')") result = self.run("pow") assert result == 29 ** 2 self.check_trace_count(1) @@ -944,20 +944,6 @@ """ def test_pow_int(self): - py.test.skip("Not implemented CDefinedIntSymbolic('RPY_TLOFS_rpy_errno')") result = self.run("pow_int") assert result == 15 ** 2 self.check_trace_count(4) # extra one for the astype - - - def define_take(): - return """ - a = |10| - b = take(a, [1, 1, 3, 2]) - b -> 2 - """ - - def test_take(self): - py.test.skip("key error get item?") - result = self.run("take") - assert result == 3 diff --git a/rpython/jit/metainterp/optimizeopt/schedule.py b/rpython/jit/metainterp/optimizeopt/schedule.py --- a/rpython/jit/metainterp/optimizeopt/schedule.py +++ b/rpython/jit/metainterp/optimizeopt/schedule.py @@ -10,6 +10,7 @@ from rpython.jit.metainterp.jitexc import NotAProfitableLoop from rpython.rlib.objectmodel import specialize, always_inline from rpython.jit.metainterp.jitexc import NotAVectorizeableLoop, NotAProfitableLoop +from rpython.rtyper.lltypesystem.lloperation import llop class SchedulerState(object): @@ -162,6 +163,14 @@ for node in state.graph.nodes: assert node.emitted +def failnbail_transformation(msg): + msg = '%s\n' % msg + if we_are_translated(): + llop.debug_print(lltype.Void, msg) + else: + import pdb; pdb.set_trace() + raise NotImplementedError(msg) + class TypeRestrict(object): ANY_TYPE = '\x00' ANY_SIZE = -1 @@ -191,15 +200,27 @@ def check(self, value): assert value.datatype != '\x00' if self.type != TypeRestrict.ANY_TYPE: - assert self.type == value.datatype + if self.type != value.datatype: + msg = "type mismatch %s != %s" % \ + (self.type, value.datatype) + failnbail_transformation(msg) assert value.bytesize > 0 if not self.any_size(): - assert self.bytesize == value.bytesize + if self.bytesize != value.bytesize: + msg = "bytesize mismatch %s != %s" % \ + (self.bytesize, value.bytesize) + failnbail_transformation(msg) assert value.count > 0 if self.count != TypeRestrict.ANY_COUNT: - assert value.count >= self.count + if value.count < self.count: + msg = "count mismatch %s < %s" % \ + (self.count, value.count) + failnbail_transformation(msg) if self.sign != TypeRestrict.ANY_SIGN: - assert bool(self.sign) == value.sign + if bool(self.sign) == value.sign: + msg = "sign mismatch %s < %s" % \ + (self.sign, value.sign) + failnbail_transformation(msg) def max_input_count(self, count): """ How many """ diff --git a/rpython/jit/metainterp/resoperation.py b/rpython/jit/metainterp/resoperation.py --- a/rpython/jit/metainterp/resoperation.py +++ b/rpython/jit/metainterp/resoperation.py @@ -125,8 +125,8 @@ type = self.type if descr.is_array_of_floats(): type = 'f' - if isinstance(descr, ArrayDescr) and descr.getconcrete_type() == 'f': - type = 'f' + #if isinstance(descr, ArrayDescr) and descr.getconcrete_type() == 'f': + # type = 'f' self.bytesize = descr.get_item_size_in_bytes() self.signed = descr.is_item_signed() self.datatype = type diff --git a/rpython/jit/metainterp/test/test_resoperation.py b/rpython/jit/metainterp/test/test_resoperation.py --- a/rpython/jit/metainterp/test/test_resoperation.py +++ b/rpython/jit/metainterp/test/test_resoperation.py @@ -5,6 +5,7 @@ from rpython.jit.metainterp.history import ConstInt from rpython.jit.backend.llsupport.symbolic import (WORD as INT_WORD, SIZEOF_FLOAT as FLOAT_WORD) +from rpython.jit.backend.llsupport.descr import ArrayDescr def test_arity_mixins(): cases = [ @@ -108,10 +109,22 @@ assert op.cast_to() == kwargs['cast_to'] def test_unpack_1(): - op = rop.ResOperation(rop.rop.VEC_UNPACK_I, [rop.InputArgVector(), ConstInt(0), ConstInt(1)]) - assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('i', 'i', 8, False) - op = rop.ResOperation(rop.rop.VEC_UNPACK_I, [rop.InputArgVector(), ConstInt(0), ConstInt(2)]) - assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('i', 'i', 8, True) + op = rop.ResOperation(rop.rop.VEC_UNPACK_I, + [rop.InputArgVector(), ConstInt(0), ConstInt(1)]) + assert (op.type, op.datatype, op.bytesize, op.is_vector()) == \ + ('i', 'i', 8, False) + op = rop.ResOperation(rop.rop.VEC_UNPACK_I, + [rop.InputArgVector(), ConstInt(0), ConstInt(2)]) + assert (op.type, op.datatype, op.bytesize, op.is_vector()) == \ + ('i', 'i', 8, True) + +def test_load_singlefloat(): + descr = ArrayDescr(8,4, None, 'S', concrete_type='f') + op = rop.ResOperation(rop.rop.VEC_RAW_LOAD_I, + [rop.InputArgInt(), ConstInt(0)], + descr=descr) + assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('i', 'i', 4, True) + def test_types(): op = rop.ResOperation(rop.rop.INT_ADD, [ConstInt(0),ConstInt(1)]) diff --git a/rpython/jit/metainterp/test/test_vector.py b/rpython/jit/metainterp/test/test_vector.py --- a/rpython/jit/metainterp/test/test_vector.py +++ b/rpython/jit/metainterp/test/test_vector.py @@ -12,7 +12,9 @@ from rpython.rlib.rarithmetic import r_uint, intmask from rpython.rlib.rawstorage import (alloc_raw_storage, raw_storage_setitem, free_raw_storage, raw_storage_getitem) +from rpython.rlib.objectmodel import specialize, is_annotation_constant +@specialize.argtype(0,1) def malloc(T,n): return lltype.malloc(T, n, flavor='raw', zero=True) def free(mem): @@ -409,5 +411,106 @@ res = self.meta_interp(f, [128], vec_all=True) assert res == f(128) + + def combinations(types, operators): + import itertools + size = 22 + + class Typ(object): + def __init__(self, type, storecast, loadcast): + self.type = type + self.storecast = storecast + self.loadcast = loadcast + def __repr__(self): + return self.type.replace(".","_") + + sizes = [22] + for t1, t2, t3, op, size in itertools.product(types, types, types, operators, sizes): + yield (size, Typ(*t1), Typ(*t2), Typ(*t3), op[0], op[1]) + types = [('rffi.DOUBLE', 'float', 'float'), + ('rffi.SIGNED', 'int', 'int'), + ('rffi.FLOAT', 'rffi.r_singlefloat', 'float'), + ] + operators = [('add', '+'), + ] + for size, typ1, typ2, typ3, opname, op in combinations(types, operators): + _source = """ + def test_binary_operations_{name}(self): + myjitdriver = JitDriver(greens = [], reds = 'auto') + T1 = lltype.Array({type_a}, hints={{'nolength': True}}) + T2 = lltype.Array({type_b}, hints={{'nolength': True}}) + T3 = lltype.Array({type_c}, hints={{'nolength': True}}) + def f(size): + vector_a = lltype.malloc(T1, size, flavor='raw') + vector_b = lltype.malloc(T2, size, flavor='raw') + vector_c = lltype.malloc(T3, size, flavor='raw') + for i in range(size): + vector_a[i] = {type_a_storecast}(i+1) + for i in range(size): + vector_b[i] = {type_b_storecast}(i+1) + for i in range(size): + vector_c[i] = {type_c_storecast}(i+1) + i = 0 + while i < size: + myjitdriver.jit_merge_point() + a = {type_a_loadcast}(vector_a[i]) + b = {type_b_loadcast}(vector_b[i]) + c = (a {op} b) + vector_c[i] = {type_c_storecast}(c) + i += 1 + lltype.free(vector_a, flavor='raw') + lltype.free(vector_b, flavor='raw') + c = {type_c_loadcast}(0.0) + for i in range(size): + c += {type_c_loadcast}(vector_c[i]) + lltype.free(vector_c, flavor='raw') + return c + res = self.meta_interp(f, [{size}], vec_all=True) + assert res == f({size}) + """ + env = { + 'type_a': typ1.type, + 'type_b': typ2.type, + 'type_c': typ3.type, + 'type_a_loadcast': typ1.loadcast, + 'type_b_loadcast': typ2.loadcast, + 'type_c_loadcast': typ3.loadcast, + 'type_a_storecast': typ1.storecast, + 'type_b_storecast': typ2.storecast, + 'type_c_storecast': typ3.storecast, + 'size': size, + 'name': str(typ1) + '__' + str(typ2) + '__' + str(typ3) + \ + '__' + str(size) + '__' + opname, + 'op': op, + } + formatted = _source.format(**env) + exec py.code.Source(formatted).compile() + + def test_binary_operations_aa(self): + myjitdriver = JitDriver(greens = [], reds = 'auto') + T1 = lltype.Array(rffi.DOUBLE, hints={'nolength': True}) + T3 = lltype.Array(rffi.SIGNED, hints={'nolength': True}) + def f(size): + vector_a = lltype.malloc(T1, size, flavor='raw', zero=True) + vector_b = lltype.malloc(T1, size, flavor='raw', zero=True) + vector_c = lltype.malloc(T3, size, flavor='raw', zero=True) + i = 0 + while i < size: + myjitdriver.jit_merge_point() + a = (vector_a[i]) + b = (vector_b[i]) + c = (a + b) + vector_c[i] = int(c) + i += 1 + free(vector_a) + free(vector_b) + #c = 0.0 + #for i in range(size): + # c += vector_c[i] + lltype.free(vector_c, flavor='raw') + return 0 + res = self.meta_interp(f, [22], vec_all=True) + assert res == f(22) + class TestLLtype(LLJitMixin, VectorizeTests): pass _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit