hello world example

58 views
Skip to first unread message

matthew...@gmail.com

unread,
Dec 23, 2013, 4:38:38 PM12/23/13
to harla...@googlegroups.com
Hi harlan-dev,

I've spent a few hours trying to get up and running with harlan, and wanted to provide some feedback.

The documentation is good as far as installing goes, and the different compiler options are well laid out. One thing that I haven't been able to find however is a nice "hello world" walk-through for actually writing harlan code.

Digging through the test cases has given me some idea of how things work, but I think a quick example that illustrates the following things would be helpful:

1. Which code executes on the host, and which executes on the device
2. How arguments are passed to the kernel, how are work-groups and work-items are mapped (if at all).
3. Transferring data to the device and then accessing it there (and copying data back).

I'm coming from a CUDA/OpenCL background, so I may be asking questions at the wrong level of abstraction, but that's where I feel like the biggest gap in the docs is.

Otherwise, awesome project, thanks!

Matt

Eric Holk

unread,
Dec 23, 2013, 9:25:13 PM12/23/13
to harla...@googlegroups.com, matthew...@gmail.com
Thanks a lot for the feedback! I'm glad to hear you were able to run the tests and fix the compiler.

You're correct that currently the test cases are the best source of documentation, but this is still not quite ideal. Going forward, more of the language documentation should move into the wiki on Github.

I just added a language overview page which describes the absolute basics of writing kernels in Harlan. Hopefully this will help you get started. I'll be happy to fill out more of the details if there are specific things you are interested in knowing about. The page is here: https://github.com/eholk/harlan/wiki/Language-overview

I've said a little about your specific questions down below.

On Monday, December 23, 2013 1:38:38 PM UTC-8, matthew...@gmail.com wrote:
Hi harlan-dev,

I've spent a few hours trying to get up and running with harlan, and wanted to provide some feedback.

The documentation is good as far as installing goes, and the different compiler options are well laid out. One thing that I haven't been able to find however is a nice "hello world" walk-through for actually writing harlan code.

Digging through the test cases has given me some idea of how things work, but I think a quick example that illustrates the following things would be helpful:

1. Which code executes on the host, and which executes on the device

Generally, code that's within a kernel expression executes on the device and code outside of kernel expressions runs on the host. This isn't a hard and fast rule though, since to point of a kernel is not so much to say "this must run on the device," but "here's some code that can be done in parallel. In the future, the Harlan compiler may decide that there's no way running that kernel on the device will overcome the data transfer costs, for example, and run it on the CPU instead.
 

2. How arguments are passed to the kernel, how are work-groups and work-items are mapped (if at all).

Generally, a kernel spawns run thread, or work item, per vector element. Grouping these into work groups is done by Harlan and the underlying OpenCL runtime.
 

3. Transferring data to the device and then accessing it there (and copying data back).

Harlan automatically handles transferring data. If you try to reference data on the kernel, Harlan will make sure the data is on the device before the kernel runs. The same is true when accessing data on the host that was once on the device. Since data movement can be pretty expensive, Harlan does these transfers lazily if it can.
 

I'm coming from a CUDA/OpenCL background, so I may be asking questions at the wrong level of abstraction, but that's where I feel like the biggest gap in the docs is.

Otherwise, awesome project, thanks!

Thanks to you too! Good luck, I hope this is useful for you.

-Eric
 

Matt

Reply all
Reply to author
Forward
0 new messages