Julia Compilation versus Interpretation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Julia Compilation versus Interpretation

rprechelt
Hi All,

I've been working on and exploring some aspects of Julia's internals over the past few days - mainly codegen.cpp, toplevel.cpp and interpreter.cpp. I was curious if anyone could shed some light on the heuristics that Julia uses to determine whether to compile an expression using codegen.cpp (LLVM) or interpret it directly using interpreter.cpp.

I have checked the developer docs but the only information is:

:c:func:jl_toplevel_eval_flex then uses some simple heuristics to decide whether to JIT compiler the AST or to interpret it directly.

 Does anyone have any insights into what these "simple heuristics" are?

---
Background: I am attempting to develop a new LLVM pass for Julia (in the style of @simd) that is enabled on a basic block basis by expressions added by a macro (all very much similar to the way @simd currently works). However, as I change the location of my pass-enabling expression within a broader quote, Julia will sometimes interpret the expression (so the LLVM pass doesn't get called), and sometimes it will compile the expression (and the LLVM pass runs successfully). Clearly there is logic behind this choice, however despite some digging through jl_toplevel_eval_flex, I have been unable to decipher the conditions that lead to interpretation (my knowledge of the Julia internal DSL is still somewhat limited).
Reply | Threaded
Open this post in threaded view
|

Re: Julia Compilation versus Interpretation

Jameson Nash
Currently all functions are compiled, so the simplest heuristic is simply to put your test code in a function. That also gives you the benefit of being able to use code_llvm / code_native to review what the pass did.

At the toplevel, the heuristic is also quite simplistic: it compiles the expression if it uses intrinsics or has a backward branch.


On Mon, May 2, 2016 at 11:36 AM <[hidden email]> wrote:
Hi All,

I've been working on and exploring some aspects of Julia's internals over the past few days - mainly codegen.cpp, toplevel.cpp and interpreter.cpp. I was curious if anyone could shed some light on the heuristics that Julia uses to determine whether to compile an expression using codegen.cpp (LLVM) or interpret it directly using interpreter.cpp.

I have checked the developer docs but the only information is:

:c:func:jl_toplevel_eval_flex then uses some simple heuristics to decide whether to JIT compiler the AST or to interpret it directly.

 Does anyone have any insights into what these "simple heuristics" are?

---
Background: I am attempting to develop a new LLVM pass for Julia (in the style of @simd) that is enabled on a basic block basis by expressions added by a macro (all very much similar to the way @simd currently works). However, as I change the location of my pass-enabling expression within a broader quote, Julia will sometimes interpret the expression (so the LLVM pass doesn't get called), and sometimes it will compile the expression (and the LLVM pass runs successfully). Clearly there is logic behind this choice, however despite some digging through jl_toplevel_eval_flex, I have been unable to decipher the conditions that lead to interpretation (my knowledge of the Julia internal DSL is still somewhat limited).