unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* "AIscm" array JIT
@ 2016-06-08 21:16 Jan Wedekind
  2016-06-09  9:02 ` tomas
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Jan Wedekind @ 2016-06-08 21:16 UTC (permalink / raw
  To: guile-user

Hi,
   I am working on a compact library [1] for JIT compilation of array 
operations. It only runs on AMD64 processors. Currently it supports array 
operations using booleans, integers, and integer RGB and integer complex 
numbers.
   There are still important things missing: floating point numbers, 
compiling calls to C methods (e.g. sin, cos, ...), tensor operations, 
convolutions, ... I would like to eventually do numerical processing 
similar to Python's NumPy (but more generic), Theano (but more compact 
syntax as facilitated by macros), and OpenCV.
   Here is an example adding an integer to each element of a 2D array and 
returning the result:

     scheme@(guile-user)> (use-modules (oop goops) (aiscm jit) (aiscm int)
                                       (aiscm pointer) (aiscm sequence))
     scheme@(guile-user)> (+ (arr (2 3 5) (7 11 13)) 3)
     $1 = #<sequence<sequence<int<8,unsigned>>>>:
     ((5 6 8)
      (10 14 16))

   The fallback method for the GOOPS generic "+" adds a JIT compiled plus 
operation for the specific array types to the generic and then calls "+" 
again.
   The corresponding machine code to produce the unsigned byte array is 
shown below:

      0:   4c 89 64 24 f0          mov    QWORD PTR [rsp-0x10],r12
      5:   48 89 6c 24 e8          mov    QWORD PTR [rsp-0x18],rbp
      a:   4c 89 7c 24 e0          mov    QWORD PTR [rsp-0x20],r15
      f:   4c 89 74 24 d8          mov    QWORD PTR [rsp-0x28],r14
     14:   4c 89 6c 24 d0          mov    QWORD PTR [rsp-0x30],r13
     19:   48 89 5c 24 c8          mov    QWORD PTR [rsp-0x38],rbx
     1e:   48 89 7c 24 f8          mov    QWORD PTR [rsp-0x8],rdi
     23:   4c 8b 64 24 08          mov    r12,QWORD PTR [rsp+0x8]
     28:   48 8b 7c 24 18          mov    rdi,QWORD PTR [rsp+0x18]
     2d:   48 8b 6c 24 20          mov    rbp,QWORD PTR [rsp+0x20]
     32:   8a 44 24 28             mov    al,BYTE PTR [rsp+0x28]
     36:   48 6b de 01             imul   rbx,rsi,0x1
     3a:   49 8b f0                mov    rsi,r8
     3d:   4d 6b cc 01             imul   r9,r12,0x1
     41:   4c 8b fd                mov    r15,rbp
     44:   49 be 00 00 00 00 00    movabs r14,0x0
     4b:   00 00 00
     4e:   4c 8b 44 24 f8          mov    r8,QWORD PTR [rsp-0x8]
     53:   4d 3b f0                cmp    r14,r8
     56:   74 3e                   je     0x96
     58:   49 ff c6                inc    r14
     5b:   4c 6b d9 01             imul   r11,rcx,0x1
     5f:   4c 8b ee                mov    r13,rsi
     62:   4c 6b d7 01             imul   r10,rdi,0x1
     66:   4d 8b e7                mov    r12,r15
     69:   48 bd 00 00 00 00 00    movabs rbp,0x0
     70:   00 00 00
     73:   48 3b ea                cmp    rbp,rdx
     76:   74 16                   je     0x8e
     78:   48 ff c5                inc    rbp
     7b:   45 8a 04 24             mov    r8b,BYTE PTR [r12]
     7f:   44 02 c0                add    r8b,al
     82:   45 88 45 00             mov    BYTE PTR [r13+0x0],r8b
     86:   4d 03 eb                add    r13,r11
     89:   4d 03 e2                add    r12,r10
     8c:   eb e5                   jmp    0x73
     8e:   48 03 f3                add    rsi,rbx
     91:   4d 03 f9                add    r15,r9
     94:   eb b8                   jmp    0x4e
     96:   4c 8b 64 24 f0          mov    r12,QWORD PTR [rsp-0x10]
     9b:   48 8b 6c 24 e8          mov    rbp,QWORD PTR [rsp-0x18]
     a0:   4c 8b 7c 24 e0          mov    r15,QWORD PTR [rsp-0x20]
     a5:   4c 8b 74 24 d8          mov    r14,QWORD PTR [rsp-0x28]
     aa:   4c 8b 6c 24 d0          mov    r13,QWORD PTR [rsp-0x30]
     af:   48 8b 5c 24 c8          mov    rbx,QWORD PTR [rsp-0x38]
     b4:   c3                      ret



   Any comments,suggestions, and feedback are welcome!

Regards
Jan

[1] https://github.com/wedesoft/aiscm



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-08 21:16 "AIscm" array JIT Jan Wedekind
@ 2016-06-09  9:02 ` tomas
  2016-06-09 11:48   ` Jan Wedekind
  2016-06-10 13:33 ` Ludovic Courtès
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: tomas @ 2016-06-09  9:02 UTC (permalink / raw
  To: Jan Wedekind; +Cc: guile-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, Jun 08, 2016 at 10:16:04PM +0100, Jan Wedekind wrote:
> Hi,
>   I am working on a compact library [1] for JIT compilation of array
> operations. It only runs on AMD64 processors. Currently it supports
> array operations using booleans, integers, and integer RGB and
> integer complex numbers.

Sorry for this "metoo" post. This is absolutely exciting.

This is one of the times I cry that my $DAYJOB is eating me alive.
I wish I had the time to play with this. As things stand, I gotta
limit myself to cheer from the peanut gallery.

Thanks!
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAldZMLgACgkQBcgs9XrR2kYCJgCeLIPEFAszCPSQj9cNiIG/a3xN
Ns4An3vKUvg72/zDVVSy4QiNXV2RSbZv
=kcC7
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-09  9:02 ` tomas
@ 2016-06-09 11:48   ` Jan Wedekind
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Wedekind @ 2016-06-09 11:48 UTC (permalink / raw
  To: tomas; +Cc: guile-user

On Thu, 9 Jun 2016, tomas@tuxteam.de wrote:
> Hash: SHA1
>
> On Wed, Jun 08, 2016 at 10:16:04PM +0100, Jan Wedekind wrote:
>> Hi,
>>   I am working on a compact library [1] for JIT compilation of array
>> operations. It only runs on AMD64 processors. Currently it supports
>> array operations using booleans, integers, and integer RGB and
>> integer complex numbers.
>
> Sorry for this "metoo" post. This is absolutely exciting.
>
> This is one of the times I cry that my $DAYJOB is eating me alive.
> I wish I had the time to play with this. As things stand, I gotta
> limit myself to cheer from the peanut gallery.
>
> Thanks!

   Thanks for the positive feedback. Same here with day job and all. 
Considering how little spare time I have, it is a credit to GNU Guile 
(and Scheme and GOOPS), how far I was able to take this nonetheless.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-08 21:16 "AIscm" array JIT Jan Wedekind
  2016-06-09  9:02 ` tomas
@ 2016-06-10 13:33 ` Ludovic Courtès
  2016-06-10 16:03   ` Jan Wedekind
  2016-06-10 17:38 ` Nala Ginrut
  2016-06-11  1:42 ` Basa Centro
  3 siblings, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2016-06-10 13:33 UTC (permalink / raw
  To: guile-user

Jan Wedekind <jan@wedesoft.de> skribis:

>   Here is an example adding an integer to each element of a 2D array
> and returning the result:
>
>     scheme@(guile-user)> (use-modules (oop goops) (aiscm jit) (aiscm int)
>                                       (aiscm pointer) (aiscm sequence))
>     scheme@(guile-user)> (+ (arr (2 3 5) (7 11 13)) 3)
>     $1 = #<sequence<sequence<int<8,unsigned>>>>:
>     ((5 6 8)
>      (10 14 16))
>
>   The fallback method for the GOOPS generic "+" adds a JIT compiled
> plus operation for the specific array types to the generic and then
> calls "+" again.

Woow, exciting stuff!  It can surely make a different for number
crunching applications.

Ludo’.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-10 13:33 ` Ludovic Courtès
@ 2016-06-10 16:03   ` Jan Wedekind
  2016-06-10 21:48     ` Arne Babenhauserheide
  0 siblings, 1 reply; 10+ messages in thread
From: Jan Wedekind @ 2016-06-10 16:03 UTC (permalink / raw
  To: Ludovic Courtès; +Cc: guile-user

On Fri, 10 Jun 2016, Ludovic Courtès wrote:

> Jan Wedekind <jan@wedesoft.de> skribis:
>
>>   Here is an example adding an integer to each element of a 2D array
>> and returning the result:
>>
>>     scheme@(guile-user)> (use-modules (oop goops) (aiscm jit) (aiscm int)
>>                                       (aiscm pointer) (aiscm sequence))
>>     scheme@(guile-user)> (+ (arr (2 3 5) (7 11 13)) 3)
>>     $1 = #<sequence<sequence<int<8,unsigned>>>>:
>>     ((5 6 8)
>>      (10 14 16))
>>
>>   The fallback method for the GOOPS generic "+" adds a JIT compiled
>> plus operation for the specific array types to the generic and then
>> calls "+" again.
>
> Woow, exciting stuff!  It can surely make a different for number
> crunching applications.
>
> Ludo’.

Yes, here are some examples with empty arrays and arrays with 250,000 
elements. I hope that the upcoming Guile version 2.2 will help increase 
performance as well.

     $ make bench
     Making bench in bench
     make[1]: Entering directory '/home/jan/test/aiscm/bench'
     LD_LIBRARY_PATH=./.libs:/usr/local/lib GC_INITIAL_HEAP_SIZE=1G GC_USE_ENTIRE_HEAP=Y /usr/bin/guile bench.scm
                                            user     system      total        real
     Guile GOOPS method dispatch        0.000040   0.000000   0.000040 (  0.000040)
     Guile make empty sequence          0.000150   0.000000   0.000150 (  0.000140)
     Guile allocate memory              0.000190   0.000000   0.000190 (  0.000200)
     Guile negate empty sequence        0.001580   0.000110   0.001690 (  0.001690)
     Guile make sequence                0.000230   0.000010   0.000240 (  0.000240)
     Guile negate sequence              0.002400   0.000930   0.003330 (  0.003350)
     C allocate memory                  0.000060   0.000000   0.000060 (  0.000060)
     C negate empty sequence            0.000030   0.000000   0.000030 (  0.000030)
     C negate sequence                  0.000730   0.000000   0.000730 (  0.000720)
     make[1]: Leaving directory '/home/jan/test/aiscm/bench'

Regards
Jan


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-08 21:16 "AIscm" array JIT Jan Wedekind
  2016-06-09  9:02 ` tomas
  2016-06-10 13:33 ` Ludovic Courtès
@ 2016-06-10 17:38 ` Nala Ginrut
  2016-06-11  1:42 ` Basa Centro
  3 siblings, 0 replies; 10+ messages in thread
From: Nala Ginrut @ 2016-06-10 17:38 UTC (permalink / raw
  To: Jan Wedekind, guile-user

I've installed from debian repo and tried all the example code, very
cool and impressive! Thanks for the work!
Last months I tried matrix operations in Guile and ChezScheme, it's too
slow. I expect to do some machine learning things to control robot car
with the camera. And I found AIscm has the basic things what I want.
Please continue the work, it's useful. ;-)


On Wed, 2016-06-08 at 22:16 +0100, Jan Wedekind wrote:
> Hi,
>    I am working on a compact library [1] for JIT compilation of
> array 
> operations. It only runs on AMD64 processors. Currently it supports
> array 
> operations using booleans, integers, and integer RGB and integer
> complex 
> numbers.
>    There are still important things missing: floating point numbers, 
> compiling calls to C methods (e.g. sin, cos, ...), tensor
> operations, 
> convolutions, ... I would like to eventually do numerical processing 
> similar to Python's NumPy (but more generic), Theano (but more
> compact 
> syntax as facilitated by macros), and OpenCV.
>    Here is an example adding an integer to each element of a 2D array
> and 
> returning the result:
> 
>      scheme@(guile-user)> (use-modules (oop goops) (aiscm jit) (aiscm
> int)
>                                        (aiscm pointer) (aiscm
> sequence))
>      scheme@(guile-user)> (+ (arr (2 3 5) (7 11 13)) 3)
>      $1 = #<sequence<sequence<int<8,unsigned>>>>:
>      ((5 6 8)
>       (10 14 16))
> 
>    The fallback method for the GOOPS generic "+" adds a JIT compiled
> plus 
> operation for the specific array types to the generic and then calls
> "+" 
> again.
>    The corresponding machine code to produce the unsigned byte array
> is 
> shown below:
> 
>       0:   4c 89 64 24 f0          mov    QWORD PTR [rsp-0x10],r12
>       5:   48 89 6c 24 e8          mov    QWORD PTR [rsp-0x18],rbp
>       a:   4c 89 7c 24 e0          mov    QWORD PTR [rsp-0x20],r15
>       f:   4c 89 74 24 d8          mov    QWORD PTR [rsp-0x28],r14
>      14:   4c 89 6c 24 d0          mov    QWORD PTR [rsp-0x30],r13
>      19:   48 89 5c 24 c8          mov    QWORD PTR [rsp-0x38],rbx
>      1e:   48 89 7c 24 f8          mov    QWORD PTR [rsp-0x8],rdi
>      23:   4c 8b 64 24 08          mov    r12,QWORD PTR [rsp+0x8]
>      28:   48 8b 7c 24 18          mov    rdi,QWORD PTR [rsp+0x18]
>      2d:   48 8b 6c 24 20          mov    rbp,QWORD PTR [rsp+0x20]
>      32:   8a 44 24 28             mov    al,BYTE PTR [rsp+0x28]
>      36:   48 6b de 01             imul   rbx,rsi,0x1
>      3a:   49 8b f0                mov    rsi,r8
>      3d:   4d 6b cc 01             imul   r9,r12,0x1
>      41:   4c 8b fd                mov    r15,rbp
>      44:   49 be 00 00 00 00 00    movabs r14,0x0
>      4b:   00 00 00
>      4e:   4c 8b 44 24 f8          mov    r8,QWORD PTR [rsp-0x8]
>      53:   4d 3b f0                cmp    r14,r8
>      56:   74 3e                   je     0x96
>      58:   49 ff c6                inc    r14
>      5b:   4c 6b d9 01             imul   r11,rcx,0x1
>      5f:   4c 8b ee                mov    r13,rsi
>      62:   4c 6b d7 01             imul   r10,rdi,0x1
>      66:   4d 8b e7                mov    r12,r15
>      69:   48 bd 00 00 00 00 00    movabs rbp,0x0
>      70:   00 00 00
>      73:   48 3b ea                cmp    rbp,rdx
>      76:   74 16                   je     0x8e
>      78:   48 ff c5                inc    rbp
>      7b:   45 8a 04 24             mov    r8b,BYTE PTR [r12]
>      7f:   44 02 c0                add    r8b,al
>      82:   45 88 45 00             mov    BYTE PTR [r13+0x0],r8b
>      86:   4d 03 eb                add    r13,r11
>      89:   4d 03 e2                add    r12,r10
>      8c:   eb e5                   jmp    0x73
>      8e:   48 03 f3                add    rsi,rbx
>      91:   4d 03 f9                add    r15,r9
>      94:   eb b8                   jmp    0x4e
>      96:   4c 8b 64 24 f0          mov    r12,QWORD PTR [rsp-0x10]
>      9b:   48 8b 6c 24 e8          mov    rbp,QWORD PTR [rsp-0x18]
>      a0:   4c 8b 7c 24 e0          mov    r15,QWORD PTR [rsp-0x20]
>      a5:   4c 8b 74 24 d8          mov    r14,QWORD PTR [rsp-0x28]
>      aa:   4c 8b 6c 24 d0          mov    r13,QWORD PTR [rsp-0x30]
>      af:   48 8b 5c 24 c8          mov    rbx,QWORD PTR [rsp-0x38]
>      b4:   c3                      ret
> 
> 
> 
>    Any comments,suggestions, and feedback are welcome!
> 
> Regards
> Jan
> 
> [1] https://github.com/wedesoft/aiscm
> 




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-10 16:03   ` Jan Wedekind
@ 2016-06-10 21:48     ` Arne Babenhauserheide
  2016-06-11  7:32       ` Jan Wedekind
  0 siblings, 1 reply; 10+ messages in thread
From: Arne Babenhauserheide @ 2016-06-10 21:48 UTC (permalink / raw
  To: Jan Wedekind; +Cc: Ludovic Courtès, guile-user

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]

Hi Jan,

Jan Wedekind writes:

> Yes, here are some examples with empty arrays and arrays with 250,000 
> elements. I hope that the upcoming Guile version 2.2 will help increase 
> performance as well.
>
>      $ make bench
>      Making bench in bench
>      make[1]: Entering directory '/home/jan/test/aiscm/bench'
>      LD_LIBRARY_PATH=./.libs:/usr/local/lib GC_INITIAL_HEAP_SIZE=1G GC_USE_ENTIRE_HEAP=Y /usr/bin/guile bench.scm
>                                             user     system      total        real
>      Guile GOOPS method dispatch        0.000040   0.000000   0.000040 (  0.000040)
>      Guile make empty sequence          0.000150   0.000000   0.000150 (  0.000140)
>      Guile allocate memory              0.000190   0.000000   0.000190 (  0.000200)
>      Guile negate empty sequence        0.001580   0.000110   0.001690 (  0.001690)
>      Guile make sequence                0.000230   0.000010   0.000240 (  0.000240)
>      Guile negate sequence              0.002400   0.000930   0.003330 (  0.003350)
>      C allocate memory                  0.000060   0.000000   0.000060 (  0.000060)
>      C negate empty sequence            0.000030   0.000000   0.000030 (  0.000030)
>      C negate sequence                  0.000730   0.000000   0.000730 (  0.000720)
>      make[1]: Leaving directory '/home/jan/test/aiscm/bench'

Do you have a comparison to the same tasks without compilation?

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-08 21:16 "AIscm" array JIT Jan Wedekind
                   ` (2 preceding siblings ...)
  2016-06-10 17:38 ` Nala Ginrut
@ 2016-06-11  1:42 ` Basa Centro
  2016-06-11 12:22   ` Jan Wedekind
  3 siblings, 1 reply; 10+ messages in thread
From: Basa Centro @ 2016-06-11  1:42 UTC (permalink / raw
  To: Jan Wedekind; +Cc: guile-user

I've had the AIscm code on my laptop for months, I was looking at how
to do something with GOOPS.  Nice work, and I hope you continue on it.
Another "me too".



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-10 21:48     ` Arne Babenhauserheide
@ 2016-06-11  7:32       ` Jan Wedekind
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Wedekind @ 2016-06-11  7:32 UTC (permalink / raw
  To: Arne Babenhauserheide; +Cc: Ludovic Courtès, guile-user

On 10. Juni 2016 22:48:56 GMT+01:00, Arne Babenhauserheide <arne_bab@web.de> wrote:
>Hi Jan,
>
>Jan Wedekind writes:
>
>> Yes, here are some examples with empty arrays and arrays with 250,000
>
>> elements. I hope that the upcoming Guile version 2.2 will help
>increase 
>> performance as well.
>>
>>      $ make bench
>>      Making bench in bench
>>      make[1]: Entering directory '/home/jan/test/aiscm/bench'
>>      LD_LIBRARY_PATH=./.libs:/usr/local/lib GC_INITIAL_HEAP_SIZE=1G
>GC_USE_ENTIRE_HEAP=Y /usr/bin/guile bench.scm
>>                                             user     system     
>total        real
>>      Guile GOOPS method dispatch        0.000040   0.000000  
>0.000040 (  0.000040)
>>      Guile make empty sequence          0.000150   0.000000  
>0.000150 (  0.000140)
>>      Guile allocate memory              0.000190   0.000000  
>0.000190 (  0.000200)
>>      Guile negate empty sequence        0.001580   0.000110  
>0.001690 (  0.001690)
>>      Guile make sequence                0.000230   0.000010  
>0.000240 (  0.000240)
>>      Guile negate sequence              0.002400   0.000930  
>0.003330 (  0.003350)
>>      C allocate memory                  0.000060   0.000000  
>0.000060 (  0.000060)
>>      C negate empty sequence            0.000030   0.000000  
>0.000030 (  0.000030)
>>      C negate sequence                  0.000730   0.000000  
>0.000730 (  0.000720)
>>      make[1]: Leaving directory '/home/jan/test/aiscm/bench'
>
>Do you have a comparison to the same tasks without compilation?
>
>Best wishes,
>Arne

Hi Arne,
The benchmark does not include compilation times.

Regards
Jan
-- 
Jan Wedekind
http://www.wedesoft.de/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "AIscm" array JIT
  2016-06-11  1:42 ` Basa Centro
@ 2016-06-11 12:22   ` Jan Wedekind
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Wedekind @ 2016-06-11 12:22 UTC (permalink / raw
  To: Basa Centro; +Cc: guile-user

On 11. Juni 2016 02:42:19 GMT+01:00, Basa Centro <basa.centro@gmail.com> wrote:
>I've had the AIscm code on my laptop for months, I was looking at how
>to do something with GOOPS.  Nice work, and I hope you continue on it.
>Another "me too".

Yes, one can use GOOPS objects without mutating. Unlike Clojure, Scheme does not enforce immutability but one can decide to not use the mutating features anyway.
-- 
Jan Wedekind
http://www.wedesoft.de/



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-06-11 12:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-08 21:16 "AIscm" array JIT Jan Wedekind
2016-06-09  9:02 ` tomas
2016-06-09 11:48   ` Jan Wedekind
2016-06-10 13:33 ` Ludovic Courtès
2016-06-10 16:03   ` Jan Wedekind
2016-06-10 21:48     ` Arne Babenhauserheide
2016-06-11  7:32       ` Jan Wedekind
2016-06-10 17:38 ` Nala Ginrut
2016-06-11  1:42 ` Basa Centro
2016-06-11 12:22   ` Jan Wedekind

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).