Commits

Antonio Cuni  committed 891cccc

don't include 'identity' in the greens of numpy_axis_reduce: it is useless because it is used only at the first iteration of the loop, and bad because we get a different instance of W_*Box every time we run it, which means that we compile the same loop again and again

  • Participants
  • Parent commits 7ceed94

Comments (0)

Files changed (2)

File pypy/module/micronumpy/loop.py

 
 axis_reduce__driver = jit.JitDriver(name='numpy_axis_reduce',
                                     greens=['shapelen',
-                                            'func', 'dtype',
-                                            'identity'],
+                                            'func', 'dtype'],
                                     reds='auto')
 
 def do_axis_reduce(shape, func, arr, dtype, axis, out, identity, cumultative,
     shapelen = len(shape)
     while not out_iter.done():
         axis_reduce__driver.jit_merge_point(shapelen=shapelen, func=func,
-                                            dtype=dtype, identity=identity,
-                                            )
+                                            dtype=dtype)
         w_val = arr_iter.getitem().convert_to(dtype)
         if out_iter.first_line:
             if identity is not None:

File pypy/module/micronumpy/test/test_zjit.py

 import py
 from rpython.jit.metainterp import pyjitpl
 from rpython.jit.metainterp.test.support import LLJitMixin
-from rpython.jit.metainterp.warmspot import reset_stats
+from rpython.jit.metainterp.warmspot import reset_stats, get_stats
 from pypy.module.micronumpy import interp_boxes
 from pypy.module.micronumpy.compile import FakeSpace, Parser, InterpreterState
 from pypy.module.micronumpy.base import W_NDimArray
         cls.code_mapping = d
         cls.codes = allcodes
 
-    def run(self, name):
+    def compile_graph(self):
+        if self.graph is not None:
+            return
         space = FakeSpace()
-        i = self.code_mapping[name]
         codes = self.codes
 
         def f(i):
             raise TypeError(w_res)
 
         if self.graph is None:
-            interp, graph = self.meta_interp(f, [i],
+            interp, graph = self.meta_interp(f, [0],
                                              listops=True,
                                              backendopt=True,
                                              graph_and_interp_only=True)
             self.__class__.interp = interp
             self.__class__.graph = graph
+
+    def run(self, name):
+        self.compile_graph()
         reset_stats()
         pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+        i = self.code_mapping[name]
         retval = self.interp.eval_graph(self.graph, [i])
         py.test.skip("don't run for now")
         return retval
                                 'int_add': 3,
                                 })
 
+    def test_reduce_compile_only_once(self):
+        self.compile_graph()
+        reset_stats()
+        pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+        i = self.code_mapping['sum']
+        # run it twice
+        retval = self.interp.eval_graph(self.graph, [i])
+        retval = self.interp.eval_graph(self.graph, [i])
+        # check that we got only one loop
+        assert len(get_stats().loops) == 1
+
+    def test_reduce_axis_compile_only_once(self):
+        self.compile_graph()
+        reset_stats()
+        pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+        i = self.code_mapping['axissum']
+        # run it twice
+        retval = self.interp.eval_graph(self.graph, [i])
+        retval = self.interp.eval_graph(self.graph, [i])
+        # check that we got only one loop
+        assert len(get_stats().loops) == 1
+
+
     def define_prod():
         return """
         a = |30|