Version française
Home     About     Download     Resources     Contact us    
Browse thread
HLVM?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Re: HLVM?
On Saturday 26 September 2009 21:23:32 Sylvain Le Gall wrote:
> On 26-09-2009, David McClain <dbm@refined-audiometrics.com> wrote:
> > Can you provide some gratis information about what makes HLVM so well
> > suited to scientific computing? Something that might prompt one to
> > actually subscribe to your journal?
>
> If I am not wrong, you can access source code of HLVM from here:
> http://hlvm.forge.ocamlcore.org

That is correct.

> There is some source code that compiles and allows to run something (I
> have not tested myself).

I just checked in a second version of the compiler. If you compile it in 
hlvm/examples/compiler2 and run ./repl then you get a REPL:

$ svn checkout svn://svn.forge.ocamlcore.org/svnroot/hlvm
...
$ cd hlvm
$ ./compile.sh
$ cd examples/compiler2
$ ./compile.sh
57 states, 473 transitions, table size 2234 bytes
$ ./repl
# 1+2*3+4;;
- : `Int = 11
Live: 0
Took 0.076751s
# create(10, 3);;
- : `Array(`Int) = [|3; 3; 3; 3; 3; 3; 3; 3; 3; 3|]
Live: 1
Took 0.029611s

It can run OCaml programs like the following FFT implementation (from 
bench.ml):

let rec zadd(((r1, i1), (r2, i2)) : (float * float) * (float * float)) : float 
* float =
  r1 +. r2, i1 +. i2;;

let rec zmul(((r1, i1), (r2, i2)) : (float * float) * (float * float)) : float 
* float =
  r1 *. r2 -. i1 *. i2, r1 *. i2 +. i1 *. r2;;

let rec aux1((i, n, a, a1, a2) : int * int * (float * float) array * (float * 
float) array * (float * float) array) : unit =
  if i < n/2 then
    begin
      a1.(i) <- a.(2*i);
      a2.(i) <- a.(2*i+1);
      aux1(i+1, n, a, a1, a2)
    end;;

let rec aux2((k, n, a, a1, a2) : int * int * (float * float) array * (float * 
float) array * (float * float) array) : unit =
  if k < n/2 then
    begin
      let t = 4. *. pi *. float_of_int k /. float_of_int n in
      a.(k) <- zadd(a1.(k), zmul(a2.(k), (cos t, -.sin t)));
      aux2(k+1, n, a, a1, a2)
    end;;

let rec aux3((k, n, a, a1, a2) : int * int * (float * float) array * (float * 
float) array * (float * float) array) : unit =
  if k < n then
    begin
      let t = 4. *. pi *. float_of_int k /. float_of_int n in
      a.(k) <- zadd(a1.(k-n/2), zmul(a2.(k-n/2), (cos t, -.sin t)));
      aux3(k+1, n, a, a1, a2)
    end;;

let rec fft(a: (float * float) array) : (float * float) array =
  if length a = 1 then create(1, a.(0)) else
    begin
      let n = length a in
      let a1 = create(n/2, (0., 0.)) in
      let a2 = create(n/2, (0., 0.)) in
      aux1(0, n, a, a1, a2);
      let a1 = fft a1 in
      let a2 = fft a2 in
      aux2(0, n, a, a1, a2);
      aux3(n/2, n, a, a1, a2);
      a
    end;;

let rec test(n: int) : (float * float) array =
  let a = create(n, (0., 0.)) in
  a.(1) <- 1.0, 0.0;
  fft a;;

test 8;;

let rec ignore(a: (float * float) array) : unit = ();;

ignore(fft(create(1048576, (0.0, 0.0))));;

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e