Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave JIT compiler. Current state, and minimal example demonstrating effect

Tags:

jit

octave

I hear very conflicting information about Octave's experimental JIT compiler feature, ranging from "it was a toy project but it basically doesn't work" to "I've used it and I get a significant speedup".

I'm aware that in order to use it successfully one needs to

  • Compile octave with the --enable-jit at configure time
  • Launch octave with the --jit-compiler option
  • Specify jit compilation preference at runtime using jit_enable and jit_startcnt commands

but I have been unable to reproduce the effects convincingly; not sure if this is because I've missed out any other steps I'm unaware of, or it simply doesn't have much of an effect on my machine.

Q: Can someone who has used the feature successfully provide a minimal working example demonstrating its proper use and the effect it has (if any) on their machine?

like image 486
Tasos Papastylianou Avatar asked Feb 07 '23 10:02

Tasos Papastylianou


1 Answers

In short:

  • you don't need to do anything to use JIT, it should just work and speed up your code if it can;
  • it's mostly useless because it only works for simple loops;
  • it's little more than a proof of a concept;
  • there is no one currently working on improving it because:
    • it's a complicated problem;
    • it's mostly a fix for sloppy Octave code;
    • uses LLVM which is too unstable.

Q: Can someone who has used the feature successfully provide a minimal working example demonstrating its proper use and the effect it has (if any) on their machine?

There is nothing to show. If you build Octave with JIT support, Octave will automatically use faster code for some loops. The only difference is on the speed, and you don't have to change your code (although you can disable jit at runtime):

octave> jit_enable (1) # confirm JIT is enabled
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.00490594 seconds.
octave> jit_enable (0) # disable JIT
octave> tic; x = 0; for i=1:100000, x += i; endfor, toc
Elapsed time is 0.747599 seconds.

## but you should probably write it like this
octave> tic; x = sum (1:100000); toc
Elapsed time is 0.00327611 seconds.

## If Octave was built without JIT support, you will get the following
octave> jit_enable (1)
warning: jit_enable: support for JIT was unavailable or disabled when Octave was built

This is a simple example but you can see better examples and more details on the blog of the only person that worked on it, as well as his presentation at OctConf 2012. More details on the (outdated), Octave's JIT wiki page

Note that Octave's JIT works only for very simple loops. So simple loops that no one familiar with the language would write them in the first place. The feature is there as proof of concept, and a starting point for anyone that may want to extend it (I personally prefer to write vectorized code, that's what the language is designed for).

Octave's JIT has one other problem which is that it uses LLVM. Octave developers have found it too unreliable for this purpose because it keeps breaking backwards compatibility. Every minor release of LLVM has broken Octave builds so Octave developers stopped fixing when LLVM 3.5 got released and disabled it by default.

like image 101
carandraug Avatar answered May 08 '23 12:05

carandraug