Live data from Hacker News

Let's Write an LLVM Specializer for Python

dev.stephendiehl.com

31–40 of 45 posts

Re: Let's Write an LLVM Specializer for Python

#31
post #11

Earlier quoted context omitted.

(process(line) for line in open('giantfile.txt') if line.lstrip()[0] != '#') Is that line really using any new features in Python 3? The lazy evaluation there is in the file object and the generator expression, both of which have long been present in python2.

No, it wasn't. I added map(str.upper, xxx), now it does.

  (process(line.upper()) for line in open('giantfile.txt') if line.lstrip()[0] != '#')

Re: Let's Write an LLVM Specializer for Python

#33
post #3

Very nice article! :) Storing types via traces could be another step for gathering types. As well as using the more advanced static type checking code that is around for python. Now I have something to work through on the weekend. Looking forward to part 2!

The numba code-base implements quite a bit of this. We actually moved away from the AST approach and went back to the byte-code approach because the AST approach quickly becomes unwieldy as the number of Visitors that you apply grows. Compile times are also slower.

The author is definitely helping people learn about LLVM and how it can be used with Python --- which is great, because this is exactly what Numba is: http://numba.pydata.org. But, please don't start another "Numba". Just come help us improve the current one.

Re: Let's Write an LLVM Specializer for Python

#34
post #17

Interesting. I currently use Python's AST to convert some nested logical query expression (in a syntax unique to my application) into bytecode executed by a specialized VM (I originally tried using V8 and LuaJit for this but performance wise that was unsuccessful; the project replaced some old Boost::Python C++ code). This article should make it easy to get started attempting an LLVM replacement.

Yes, LLVM is a great approach for doing code-gen from arbitrary specialized VMs. And the Python interface to it makes it easy to experiment. We no longer use llvmpy for Numba (we use a simpler interface llvmlite) and so llvmpy could use a maintainer.

Re: Let's Write an LLVM Specializer for Python

#35
post #31
post #11

Earlier quoted context omitted.

No, it wasn't. I added map(str.upper, xxx), now it does.

(process(line.upper()) for line in open('giantfile.txt') if line.lstrip()[0] != '#')

That's besides the point. It's trivial to write that as a for loop or in a million different ways to avoid the issue. It's a contrived example written to demonstrate a difference.

Here's another one you can't change that easily:

    tests_pass = all(process(input) == output for (input, output) in zip(open('inputs.txt'), open('outputs.txt'))

Re: Let's Write an LLVM Specializer for Python

#36
I did something similar in Ruby but using GCC as a "JIT" compiler for image processing (software [1], thesis [2]). I can really recommend JIT compilation for doing array processing.

[1] http://www.wedesoft.de/hornetseye-api/ [2] http://www.wedesoft.de/downloads/thesis_wedekind.pdf

EDIT: In my approach I didn't go through the Ruby AST though. Rather I used the approach of injecting "GCCVariables" which emit C code instead of doing the actual computation.

Re: Let's Write an LLVM Specializer for Python

#37

I did something similar in Ruby but using GCC as a "JIT" compiler for image processing (software [1], thesis [2]). I can really recommend JIT compilation for doing array processing. [1] http://www.wedesoft.de/hornetseye-api/ [2] http://www.wedesoft.de/downloads/thesis_wedekind.pdf EDIT: In my approach I didn't go through the Ruby AST though. Rather I used the approach of injecting "GCCVariables" which emit C code ins…

You should submit your thesis to the Ruby Bibliography http://rubybib.org

Re: Let's Write an LLVM Specializer for Python

#38
post #35
post #31

Earlier quoted context omitted.

(process(line.upper()) for line in open('giantfile.txt') if line.lstrip()[0] != '#')

That's besides the point. It's trivial to write that as a for loop or in a million different ways to avoid the issue. It's a contrived example written to demonstrate a difference. Here's another one you can't change that easily: tests_pass = all(process(input) == output for (input, output) in zip(open('inputs.txt'), open('outputs.txt'))

You can change that easily, with izip from itertools.

The fact that a bunch of builtins and the values/items methods of dictionaries have become iterators is not very siginificant IMHO. Python 2 code could already be written to use iterators or generator expressions, so in the parts where it was crucial it was already done. In this regard Python 3 has not added new functionality but only changed defaults.

The unicode change is the big one.

Re: Let's Write an LLVM Specializer for Python

#39
post #4

An excellent article! I had wanted to get back into some python recently after seeing the changes in 3.4, I had also wanted to become more familiar with LLVM, and this does both.

there is this discussion (flame war?) about python3 not bringing too many benefits. i haven't made my mind yet. could you elaborate what you saw in 3.4 that was nice?

I can't say I disagree with such sentiments, but over time I've ran into a few issues (features and performance improvements) which where only addressed in Python 3. This is reason enough to try working with Python 3.

Re: Let's Write an LLVM Specializer for Python

#40

This is a great tutorial about first-generation Numba. The author learned a lot about LLVM and llvmpy while working with several of our devs. If you are interested in the "Further work" in his article, come join the Numba project.

What is second generation numba? And any plans to branch numba out of pure numeric application s?
Post reply on HN