JIT: Difference between revisions

From Octave
Jump to navigation Jump to search
(→‎recommended reading: fixed closing url bracket)
(Update)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== JIT development in octave ==
This page should help interested persons who want to start hacking on the JIT implementation in octave. It's '''NOT''' intended for octave users.


This page should help interested persons which want to start hacking on the current JIT implementation in octave. It's '''NOT''' intended for octave users.
Thanks to Max Brister's work for GSoC 2012, an initial implement of a just-in-time compiler (JITC) was coded in LLVM. [https://web.archive.org/web/20220124015319/http://planet.octave.org/octconf2012/jit.pdf Here] is Max's [[OctConf 2012]] presentation about his implementation.


Last year, thanks to Max Brister's work, an initial implement of a just-in-time compiler (JITC) in LLVM for GSoC 2012. [http://planet.octave.org/octconf2012/jit.pdf Here] is Max's OctConf 2012 presentation about his current implementation.
The JIT was removed from Octave sources in 2021, see [http://hg.savannah.gnu.org/hgweb/octave/rev/f254c302bb9c here] for the details and justification. It can still be accessed by looking at an older revision of the Octave repository.


=== recommended reading ===
=== Recommended reading ===
* [http://en.wikipedia.org/wiki/Abstract_syntax_tree AST (Abstract Syntax Tree)]
* [http://en.wikipedia.org/wiki/Abstract_syntax_tree AST (Abstract Syntax Tree)]
* [http://en.wikipedia.org/wiki/Static_single_assignment_form SSA form (Static single assignment form)]
* [http://en.wikipedia.org/wiki/Static_single_assignment_form SSA form (Static single assignment form)]
Line 15: Line 15:
If the conversion fails at any stage, we give up and use the interpreter. Normally, this is done by throwing a jit_fail_exception. The reason why we can't go directly to the LLVM IR, is because Octave's AST does not contain any type information, but LLVM's IR requires it. For example, A = B+C. If B and C are matrices, this has as a drastically different meaning than if B and C are scalars. We use the current types of variables to determine the types of the rest of the variables in the loop.
If the conversion fails at any stage, we give up and use the interpreter. Normally, this is done by throwing a jit_fail_exception. The reason why we can't go directly to the LLVM IR, is because Octave's AST does not contain any type information, but LLVM's IR requires it. For example, A = B+C. If B and C are matrices, this has as a drastically different meaning than if B and C are scalars. We use the current types of variables to determine the types of the rest of the variables in the loop.


=== source code entries ===
=== Source code entries ===


* libinterp/parse-tree/pt-eval.cc line 317
* libinterp/parse-tree/pt-eval.cc line 317
* libinterp/octave-value/ov-usr-fcn.cc line 385
* libinterp/octave-value/ov-usr-fcn.cc line 385
That just invokes the jit code, which you can find in pt-jit.cc
That just invokes the jit code, which you can find in pt-jit.cc
===Notes by Amod Mulay(white)===
The snippets above define the point in execution where the jit code is called.
All of the files for jit implementation are in libinterp/interp-core, the main files are:
*pt-jit.cc (& pt-jit.h)
*jit-ir.cc (& jit-ir.h)
*jit-typeinfo.cc (& jit-typeinfo.h)
*jit-util.cc (& jit-util.h)
I haven't gone through all parts of the code yet and don't understand a lot of it, but my first impression is that it feels like more of a text dump. The various parts need to be separated into different files based on functionality. The current files are a tad too big IMHO. Right now all of the jit parts are in 4 files(+4 header files) which are quite large and a lot of it has no documentation to explain how the different parts come together.
To be fair my impressions/opinions are that of a beginner level user and you are welcome to have a look and post your own comments.
=== LLVM Compatibility ===
It seems that LLVM APIs change on a fairly regular basis and this creates build issues for Octave. See [https://savannah.gnu.org/bugs/?41061 Octave fails to build with LLVM 3.5]
{| class="wikitable"
|-
! Octave Version
! LLVM Version
! Successful Build (Y/N)
|-
| 3.8
| 3.3
| Y
|-
| 3.8
| 3.4.2
| N
|}
[[Category:Development]]

Latest revision as of 18:34, 15 February 2024

This page should help interested persons who want to start hacking on the JIT implementation in octave. It's NOT intended for octave users.

Thanks to Max Brister's work for GSoC 2012, an initial implement of a just-in-time compiler (JITC) was coded in LLVM. Here is Max's OctConf 2012 presentation about his implementation.

The JIT was removed from Octave sources in 2021, see here for the details and justification. It can still be accessed by looking at an older revision of the Octave repository.

Recommended reading[edit]

Both the intermediate Octave IR and LLVM's IR are in SSA form

IRC snippets[edit]

JIT currently only is invoked at the start of loops. Basically, JIT works by converting Octave's AST to the LLVM Internal Representation (IR). This code is in libinterp/interp-core/pt-jit.cc. This is achieved by constructing an intermediate IR, which is used for type inference, then converting that intermediate IR to LLVM's IR. If the conversion fails at any stage, we give up and use the interpreter. Normally, this is done by throwing a jit_fail_exception. The reason why we can't go directly to the LLVM IR, is because Octave's AST does not contain any type information, but LLVM's IR requires it. For example, A = B+C. If B and C are matrices, this has as a drastically different meaning than if B and C are scalars. We use the current types of variables to determine the types of the rest of the variables in the loop.

Source code entries[edit]

  • libinterp/parse-tree/pt-eval.cc line 317
  • libinterp/octave-value/ov-usr-fcn.cc line 385

That just invokes the jit code, which you can find in pt-jit.cc

Notes by Amod Mulay(white)[edit]

The snippets above define the point in execution where the jit code is called. All of the files for jit implementation are in libinterp/interp-core, the main files are:

  • pt-jit.cc (& pt-jit.h)
  • jit-ir.cc (& jit-ir.h)
  • jit-typeinfo.cc (& jit-typeinfo.h)
  • jit-util.cc (& jit-util.h)

I haven't gone through all parts of the code yet and don't understand a lot of it, but my first impression is that it feels like more of a text dump. The various parts need to be separated into different files based on functionality. The current files are a tad too big IMHO. Right now all of the jit parts are in 4 files(+4 header files) which are quite large and a lot of it has no documentation to explain how the different parts come together.

To be fair my impressions/opinions are that of a beginner level user and you are welcome to have a look and post your own comments.

LLVM Compatibility[edit]

It seems that LLVM APIs change on a fairly regular basis and this creates build issues for Octave. See Octave fails to build with LLVM 3.5

Octave Version LLVM Version Successful Build (Y/N)
3.8 3.3 Y
3.8 3.4.2 N