eholk/harlan

Add a more primitive kernel form

Opened this issue · 1 comments

Since we have macros, the current kernel form might as well be a macro that expands into something that more closely resembles the form used internally by the compiler. This opens up a lot more possibilities for surface syntax in terms of macros.

I'd propose something like range-kernel, which might look like this:

(range-kernel (100 100)
  (+ 1 2))

This would be a 2D kernel, with 100 threads in each direction, each of which computes the number three. The result would be a vector of vectors. The range-kernel form would allow any number of dimensions. Within the kernel, we'd need some way of determining the current thread ID. It could be something like a get-global-id primitive (#30), or perhaps we could change the kernel form to be something like this:

(range-kernel ((i 100) (j 100)) (+ i j))

I don't like this second option as well, because part of the goal is to remove kernel as a primitive binding form. However, to use get-global-id safely, we'd need some care in the type checker to make sure you can only call it from within certain kernel contexts.

One nice thing about adding range-kernel is that it can exist alongside the existing kernel form, and we can migrate over to range-kernel incrementally. Much of the compiler will not need to change after the make-work-size-explicit pass.