patchGNU Octave - Patches: patch #8395, Work-in-progress port of Octave...

 
 

patch #8395: Work-in-progress port of Octave JIT to libgccjit

Submitter:  David Malcolm <dmalcolm>
Submitted:  Fri 14 Mar 2014 10:52:30 PM UTC
   
 
Category:  Core : new feature Priority:  3 - Low
Status:  Wont Do Privacy:  Public
Assigned to:  None Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 18 Jan 2020 11:55:12 AM UTC, comment #11: 

Review for Octave 6.

No progress since 5 years.  I do not assume that anyone can catch up on this approach.  libgccjit is still marked as experimental. 

https://gcc.gnu.org/onlinedocs/jit/

Closing item.

Kai Torben Ohlhus <siko1056>
Group Member
Thu 11 Dec 2014 05:21:58 PM UTC, comment #10: 

The build failure I ran into appears to be:
  https://savannah.gnu.org/bugs/?43646
I didn't have qrupdate-devel installed.

Presumably the hg bookmark doesn't have the fix for that yet.

In the meantime, I'm trying again with qrupdate-devel installed.

David Malcolm <dmalcolm>
Thu 11 Dec 2014 03:26:34 PM UTC, comment #9: 

Thanks Stefan.

I'm attempting to build from your bookmark with the latest gcc jit from svn, but running into a build failure:

$ hg summary
parent: 19367:da90756b00e8 tip
 dmalcom gcc jit import
branch: default
bookmarks: *gccjit
commit: 5216 unknown (clean)
update: 34 new changesets, 3 branch heads (merge)

Configured with:
$ LIBGCCJIT_PREFIX=/home/david/coding-3/gcc-git-jit-octave/install \
    ../../configure \
       --enable-jit

I get this compilation failure (which appears to be independent of the JIT):

libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../../../liboctave -I.. -I../../../liboctave/array -I../../../liboctave/cruft/misc -Inumeric -I../../../liboctave/numeric -Ioperators -I../../../liboctave/operators -I../../../liboctave/system -I../../../liboctave/util -I../libgnu -I../../../libgnu -Wall -W -Wshadow -Wold-style-cast -Wformat -Wpointer-arith -Wwrite-strings -Wcast-align -Wcast-qual -g -O2 -pthread -MT array/array_libarray_la-CMatrix.lo -MD -MP -MF array/.deps/array_libarray_la-CMatrix.Tpo -c ../../../liboctave/array/CMatrix.cc  -fPIC -DPIC -o array/.libs/array_libarray_la-CMatrix.o
../../../liboctave/array/CMatrix.cc: In member function 'ComplexMatrix ComplexMatrix::fourier() const':
../../../liboctave/array/CMatrix.cc:1362:30: error: no matching function for call to 'Array<std::complex<double> >::Array(octave_idx_type&, int)'
   Array<Complex> wsave (nn, 1);
                              ^
../../../liboctave/array/CMatrix.cc:1362:30: note: candidates are:
In file included from ../../../liboctave/array/Array-util.h:26:0,
                 from ../../../liboctave/array/CMatrix.cc:38:
../../../liboctave/array/Array.h:212:3: note: Array<T>::Array(const Array<T>&) [with T = std::complex<double>]
   Array (const Array<T>& a)
   ^
../../../liboctave/array/Array.h:212:3: note:   candidate expects 1 argument, 2 provided
../../../liboctave/array/Array.h:205:3: note: template<class U> Array<T>::Array(const Array<U>&)
   Array (const Array<U>& a)
   ^
../../../liboctave/array/Array.h:205:3: note:   template argument deduction/substitution failed:
../../../liboctave/array/CMatrix.cc:1362:30: note:   mismatched types 'const Array<T>' and 'octave_idx_type {aka int}'
   Array<Complex> wsave (nn, 1);
                              ^
In file included from ../../../liboctave/array/Array-util.h:26:0,
                 from ../../../liboctave/array/CMatrix.cc:38:
../../../liboctave/array/Array.h:201:3: note: Array<T>::Array(const Array<T>&, const dim_vector&) [with T = std::complex<double>]
   Array (const Array<T>& a, const dim_vector& dv);
   ^
../../../liboctave/array/Array.h:201:3: note:   no known conversion for argument 1 from 'octave_idx_type {aka int}' to 'const Array<std::complex<double> >&'
../../../liboctave/array/Array.h:191:12: note: Array<T>::Array(const dim_vector&, const T&) [with T = std::complex<double>]
   explicit Array (const dim_vector& dv, const T& val)
            ^
../../../liboctave/array/Array.h:191:12: note:   no known conversion for argument 1 from 'octave_idx_type {aka int}' to 'const dim_vector&'
../../../liboctave/array/Array.h:182:12: note: Array<T>::Array(const dim_vector&) [with T = std::complex<double>]
   explicit Array (const dim_vector& dv)
            ^
../../../liboctave/array/Array.h:182:12: note:   candidate expects 1 argument, 2 provided
../../../liboctave/array/Array.h:174:3: note: Array<T>::Array() [with T = std::complex<double>]
   Array (void)
   ^
../../../liboctave/array/Array.h:174:3: note:   candidate expects 0 arguments, 2 provided
../../../liboctave/array/Array.h:166:3: note: Array<T>::Array(T*, octave_idx_type, octave_idx_type*, void*) [with T = std::complex<double>; octave_idx_type = int]
   Array (T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
   ^
../../../liboctave/array/Array.h:166:3: note:   candidate expects 4 arguments, 2 provided
../../../liboctave/array/Array.h:143:3: note: Array<T>::Array(const Array<T>&, const dim_vector&, octave_idx_type, octave_idx_type) [with T = std::complex<double>; octave_idx_type = int]
   Array (const Array<T>& a, const dim_vector& dv,
   ^
../../../liboctave/array/Array.h:143:3: note:   candidate expects 4 arguments, 2 provided

There are some followup errors.

David Malcolm <dmalcolm>
Tue 18 Nov 2014 05:07:59 PM UTC, comment #8: 

Ups, I forgot to post the link.

pull (or clone) from http://hg.octave.org/octave-nkf/ with bookmark gccjit

Here the direct link:
http://hg.octave.org/octave-nkf/rev/da90756b00e8
(The link becomes invalid once I push a new version)

Stefan Mahr <dac922>
Tue 18 Nov 2014 04:56:45 PM UTC, comment #7: 

Thanks Stefan.  Can you post your current patch please?

David Malcolm <dmalcolm>
Tue 18 Nov 2014 04:53:01 PM UTC, comment #6: 

I rebased your patch and added some autoconf magic. Compiling is successful, but running octave leads to SIGABRT.


libgccjit.so: error: gcc_jit_context_new_call: mismatching types for argument 3 of function "octave_jit_call": assignment to param arg2 (type: struct octave_base_value * *) from tmp_array (type: struct octave_base_value *[1])
gcc_jit_rvalue_as_object: NULL rvalue
terminate called after throwing an instance of 'gccjit::error'

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffb9fae700 (LWP 26805)]
0x00007ffff44b9bb9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56        ../nptl/sysdeps/unix/sysv/linux/raise.c: Datei oder Verzeichnis nicht gefunden.
(gdb) bt
#0  0x00007ffff44b9bb9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff44bcfc8 in __GI_abort () at abort.c:89
#2  0x00007ffff4dcd6b5 in __gnu_cxx::__verbose_terminate_handler() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff4dcb836 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff4dcb863 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff4dcbaa2 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff720ded9 in gccjit::object::object (this=0x7fffb9fa9af0, obj=0x0)
    at /arb/devel/octave/gccjit/gccjit-install/include/libgccjit++.h:1063
#7  0x00007ffff720e814 in gccjit::rvalue::rvalue (this=0x7fffb9fa9af0, inner=0x0)
    at /arb/devel/octave/gccjit/gccjit-install/include/libgccjit++.h:1385
#8  0x00007ffff720d983 in gccjit::context::new_call (this=0x7fffb9fa9b40, func=..., args=..., loc=...)
    at /arb/devel/octave/gccjit/gccjit-install/include/libgccjit++.h:941
#9  0x00007ffff71f704e in jit_function::call (this=0x7fffa055a9f8, ctxt=..., block=..., in_args=...)
    at ../../octave-src/libinterp/corefcn/jit-typeinfo.cc:912
#10 0x00007ffff720ba4b in jit_typeinfo::register_generic (this=0x7fffa055a2e0, name=..., result=0x7fffa055cde0,
    args=...) at ../../octave-src/libinterp/corefcn/jit-typeinfo.cc:2912


I built gccjit and octave with this script:


CURDIR=$(pwd)

# clone repositories
cd ${CURDIR}
git clone git://gcc.gnu.org/git/gcc.git gcc-src
cd gcc-src
git checkout dmalcolm/jit

cd ${CURDIR}
hg clone http://octave.org/hg/octave octave-src
cd octave-src
hg pull http://hg.octave.org/octave-nkf
hg up gccjit
./bootstrap


LIBGCCJIT_PREFIX=${CURDIR}/gccjit-install

# gccjit
cd ${CURDIR}
rm -rf gcc-build
mkdir -p gcc-build
cd gcc-build
../gcc-src/configure \
        --prefix=${LIBGCCJIT_PREFIX} \
        --enable-host-shared \
        --enable-languages=jit \
        --disable-bootstrap

make -j8
make install


# octave
cd ${CURDIR}
export LD_LIBRARY_PATH=${LIBGCCJIT_PREFIX}/lib:$LD_LIBRARY_PATH
rm -rf octave-build
mkdir -p octave-build
cd octave-build
../octave-src/configure \
        --prefix=${LIBGCCJIT_PREFIX} \
        --enable-jit \
        --disable-gui \
        FFLAGS=-g CFLAGS=-g CXXFLAGS=-g --enable-bounds-check \
        LIBGCCJIT_PREFIX=${LIBGCCJIT_PREFIX}

make -j8

./run-octave -g


Stefan Mahr <dac922>
Wed 12 Nov 2014 05:03:01 PM UTC, comment #5: 

FWIW I merged the libgccjit branch into gcc svn yesterday, so the relevant code this depends on should be in GCC 5 onwards:
https://gcc.gnu.org/ml/gcc/2014-11/msg00163.html

David Malcolm <dmalcolm>
Tue 29 Jul 2014 03:23:09 PM UTC, comment #4: 


> * there's a name-mangling issue with gripe_divide_by_zero,
> which for me gets name-mangled by the C++ compiler (to
> "_Z20gripe_divide_by_zerov").
> For now I have a horrible hack I'm applying on the libgccjit
> side which
> special-cases this, and applies the mangling when referencing
> this symbol (am attaching it)


I had a look at fixing this properly from the libgccjit end, by having a flag to enable name-mangling on a function's name, but it's not going to be easy (the name-mangling support in gcc is all inside the C++ frontend, so it's non-trivial to refactor that out).

I think the simplest solution for this is to wrap the decl of
  gripe_divide_by_zero
in gripes.h within an extern "C" thusly:
  extern "C" {
    extern OCTINTERP_API void
    gripe_divide_by_zero (void);
  }
though I'm not sure if that's going to require changes to the LLVM JIT code.

David Malcolm <dmalcolm>
Mon 17 Mar 2014 08:29:30 PM UTC, comment #3: 

Thanks; yes, the type-inference issue appears to be:
  https://savannah.gnu.org/bugs/?41312

David Malcolm <dmalcolm>
Sun 16 Mar 2014 11:23:38 PM UTC, comment #2: 


> ASSERT errors for: assert (jit_failure_count,0)
> in type-inference on the id (1, 2) I believe, before my code;
> do other people see this?


Yes, it's the same for LLVM JIT


Stefan Mahr <dac922>
Sun 16 Mar 2014 12:40:46 AM UTC, comment #1: 

Max, could you comment a little on this?

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Fri 14 Mar 2014 10:52:30 PM UTC, original submission:  

I've been experimentally porting Octave's existing JIT to libgccjit:
  http://gcc.gnu.org/wiki/JIT

I thought it was time I posted what I have.  It compiles and runs, though
there are plenty of issues.

Notes:
  * I split out HAVE_LLVM to HAVE_JIT, HAVE_LLVM, and HAVE_GCCJIT

  both the LLVM *and gccjit implementations are built within the same
    build.  This is clearly overkill, but is handy for debugging in that
    one can compare what each of the two implementation produces.

    The resulting preprocessor gunk is deeply ugly.  Perhaps it could be
    simplified by making choice of JIT backend be a configure-time thing,
    rather than trying to support both within one process.

  * jit.tst runs, but I had to hack out some of the tests for now.  It
    tries to run both the LLVM and gccjit compiler on the IR.  It then
    tries to run the gccjit-built code, if that succeeded; failing that
    the LLVM-built code.

    It fails near the end here:
      jit fail: Too many parameter to function
        *** testif HAVE_JIT
       jit_failure_count (0)
       assert (id (1), 1);
       assert (id (1+1i), 1+1i);
       assert (id (1, 2), 1);
       assert (jit_failure_count, 0);
      !!!!! test failed
      ASSERT errors for:  assert (jit_failure_count,0)
    in type-inference on the id (1, 2) I believe, before my code; do other
    people see this?

  * I've only implemented JIT-compilation of loops for now, not functions.
    I hope the latter is fairly easy to add, but I wanted to post
    something.

  * lots of FIXMEs, TODOs and other cruft; sorry (e.g. the configure.ac
    "test", which for now just hardcodes a location of a libgccjit
    checkout)

  * libgccjit currently requires function names to be valid C
    identifiers, so I changed some functions to obey this restriction

  * there's a name-mangling issue with gripe_divide_by_zero, which for me
    gets name-mangled by the C++ compiler (to "_Z20gripe_divide_by_zerov").
    For now I have a horrible hack I'm applying on the libgccjit side which
    special-cases this, and applies the mangling when referencing this
    symbol (am attaching it)

Clearly this isn't ready yet, but I wanted some feedback from the Octave
maintainers on the direction of this.

David Malcolm <dmalcolm>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #30907:  horrible-name-mangling-hack-to-libgccjit.patch added by dmalcolm (781B - text/x-patch - Horrible name-manging hack to patch libgccjit to mangle gripe_divide_by_zero at the receiving end)
file #30906:  port-of-octave-jit-to-libgccjit.patch added by dmalcolm (121KiB - text/x-patch - Work-in-progress port of Octave JIT to libgccjit (patch against "default"))

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by dac922 (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by jordigh
  • -email is unavailable- added by jordigh
  • -email is unavailable- added by dmalcolm (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-18 siko1056 CategoryNone Core : new feature
        Priority5 - Normal 3 - Low
        StatusNone Wont Do
        Open/ClosedOpen Closed
    2014-03-16 jordigh Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
    2014-03-14 dmalcolm Attached File- Added horrible-name-mangling-hack-to-libgccjit.patch, #30907
    2014-03-14 dmalcolm Attached File- Added port-of-octave-jit-to-libgccjit.patch, #30906

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code