Eric Holk

You wouldn't like me when I'm not coding.

Announcing the Release of Harlan

I am happy to announce that after about two years of work, I have made the code for Harlan available to the public.

https://github.com/eholk/harlan

Harlan is a new programming language for GPU computing. Harlan aims to push the expressiveness of languages available for the GPU further than has been done before. Harlan already has native support for rich data structures, including trees and ragged arrays. Very soon the language will support higher order procedures.

To give an example of the look and feel of a Harlan program, below is a simple N-Body Simulation program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(module

  (extern nanotime () -> u64)
  
  (define-datatype point3_t
    (point3 float float float))

  (define (make-points N)
    (kernel ((i (iota N)))
      (point3 (int->float i)
              (int->float i)
              (int->float i))))

  (define (point-diff x y)
    (match x
      ((point3 a b c)
       (match y
         ((point3 d e f)
          (point3 (- a d) (- b e) (- c f)))))))

  (define (point-add x y)
    (match x
      ((point3 a b c)
       (match y
         ((point3 x y z)
          (point3 (+ a x) (+ b y) (+ c z)))))))
  
  (define (point-div a y)
    (match a
      ((point3 a b c)
       (point3 (/ a y) (/ b y) (/ c y)))))

  (define (point-mag p)
    (match p
      ((point3 a b c)
       (sqrt (+ (* a a) (+ (* b b) (* c c)))))))

  (define (nbody bodies)
    (kernel ((i bodies))
      (reduce point-add
        (kernel ((j bodies))
          (let* ((diff (point-diff i j))
                 (d (point-mag diff)))
            (if (< 0 d)
                (point-div diff (* (* d d) d))
                (point3 0 0 0)))))))
  
  (define (main)
    (let* ((bodies (make-points 1000))
           (start (nanotime))
           (forces (nbody bodies))
           (stop (nanotime)))
      (print "Computed ")
      (print (length forces))
      (print " forces in ")
      (print (/ (- stop start) 1000000))
      (println "ms"))
    (return 0)))

The language is still research quality, but I have worked hard to keep it fairly usable. I’d encourage you to try it out and let me know how it works for you!

This is work that I’ve done with my advisor, Andrew Lumsdaine of CREST, with significant contributions from Claire Alvis, Will Byrd, Ryan Newton, and Arun Chauhan.

Comments