<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 20, 2018 at 11:10 PM, Serge Guelton <span dir="ltr"><<a href="mailto:serge.guelton@telecom-bretagne.eu" target="_blank">serge.guelton@telecom-<wbr>bretagne.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Scipy-dev,<br>
<br>
= Context<br>
<br>
I've started the experiment of compiling some of the scipy kernels with<br>
the Pythran[0] compiler.<br>
<br>
The approach was basically to pick some easy .pyx file, turn them back<br>
to high-level Python + Numpy files then processing them with Pythran.<br>
This results in easier to maintain, Python-compatible files that run at<br>
the same speed as their Cython alternative up to 10 times faster<br>
depending on the kernels and whether SIMD instructions are activated or<br>
not (I did not play with parallelization in that experiment).<br>
<br>
This required a few improvement to Pythran, but not that much, see<br>
<br>
<a href="https://github.com/serge-sans-paille/pythran/pull/770" rel="noreferrer" target="_blank">https://github.com/serge-sans-<wbr>paille/pythran/pull/770</a><br>
<br>
for the associated PR on pythran, which includes the following scipy<br>
kernels:<br>
<br>
hausdorff.py<br>
max_len_seq_inner.py<br>
solve_toeplitz.py<br>
spectral.py<br>
<br>
= Why bother?<br>
<br>
According to that first round of experiments, using Pythran can bring<br>
extra speed improvements while remaining at a higher level than Cython.<br>
Both points looks like an improvement to me.<br></blockquote><div><br></div><div>Another potential benefit is to decrease the size of the binary distribution of SciPy. Cython extensions are quite expensive in this respect. Do you have an idea of how Pythran compares? Both in case of only float64 inputs, and with templated inputs? A good example of the latter is scipy.ndimage.label, which is a straightforward function that ends up being a 700kb .so<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
= Cost?<br>
<br>
This adds an extra dependency on Pythran, which uses C++ as backend.<br></blockquote><div><br></div><div>Only a build-time dependency. That's not my major worry from the maintenance point of view.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This increases the failure surface. Although alive since 2012 and being<br>
tested a lot [1] on Linux (but scarcely on Windows), its is obviously<br>
less mature than cython<br></blockquote><div><br></div><div>This is a worry. We need Windows, Linux, macOS (officially supported, also the 32-bit flavors) as well as less commonly used Unix/BSD-like platforms.</div><div><br></div><div>I guess Windows needs separate testing, both with gcc and MSVC. But for all other platforms, can you say something about portability based on the kind of C++ Pythran generates?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
= Alternatives<br>
<br>
There is an experimental Pythran mode in cython[2] that uses Pythran as<br>
a backend for numpy operations. Unfortunately it is still at early<br>
stages and cannot translate calls to ``np.roll`` or ``np.sum(a[i,:] - b[j, :])`` while Pythran supports it.<br>
<br>
Instead of translating Cython files, I could also focus on some<br>
pure-python functions. I tested Pythran on the rosenbrock function and I<br>
get good speedup (from 1.5x to 4x depending on vectorization being<br>
enabled or not) there too.<br>
<br>
So yeah, that's a rather long introduction to probe the interest here<br>
around that idea :-)<br></blockquote><div><br></div><div>Interest in general, but there's a long way to go - our requirements are pretty demanding. I have seen some comparisons between Cython, Pythran and Numba in terms of performance and ease of use, but never a comprehensive comparison from the point of view of library authors. I know Travis O. has an interest in seeing Numba being adopted more widely, which will also need such a comparison. It should cover at least:</div><div><br></div><div></div><div>- portability</div><div>- performance<br></div><div>- maturity<br></div><div>- maintenance status (active devs, how quick do bugs get fixed after a release with an issue)</div><div>- ease of use (@jit vs. Pythran comments vs. translate to .pyx syntax)</div><div>- size of generated binaries</div><div>- templating support for multiple dtypes</div><div>- debugging and optimization experience/tools<br></div><div><br></div><div>Is anyone aware of such a comparison? Or interested in putting it together?</div><div><br></div><div>Cheers,<br></div><div>Ralf</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Best,<br>
Serge<br>
<br>
PS: I started <a href="https://github.com/scipy/scipy/pull/8306" rel="noreferrer" target="_blank">https://github.com/scipy/scipy<wbr>/pull/8306</a> meanwhile, but<br>
let's discuss here first :-)<br>
<br>
<br>
<br>
[0] <a href="https://github.com/serge-sans-paille/pythran" rel="noreferrer" target="_blank">https://github.com/serge-sans-<wbr>paille/pythran</a><br>
[1] <a href="https://travis-ci.org/serge-sans-paille/pythran/builds/330052310" rel="noreferrer" target="_blank">https://travis-ci.org/serge-sa<wbr>ns-paille/pythran/builds/33005<wbr>2310</a><br>
[2] <a href="http://cython.readthedocs.io/en/latest/src/userguide/numpy_pythran.html" rel="noreferrer" target="_blank">http://cython.readthedocs.io/e<wbr>n/latest/src/userguide/numpy_p<wbr>ythran.html</a><br>
______________________________<wbr>_________________<br>
SciPy-Dev mailing list<br>
<a href="mailto:SciPy-Dev@python.org" target="_blank">SciPy-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/scipy-dev</a><br>
</blockquote></div><br></div></div>