Setting Up HSA

How to setup a HSA machine for testing HSA enabled Aparapi


Now that HSA hardware is generally available I figured it was time to describe how to setup a HSA enabled Linux platform so that it can run Aparapi.

Here is a nice introduction to HSA

But for Aparapi users the main advantage is that we are no longer limited to the GPU memory for running GPU tasks. Also because the CPU and the GPU can both see the same memory (the Java heap) Aparapi code can now access Java objects directly. This removes a number of Aparapi constraints. So more of your code can now run on the GPU.

Hardware Required

These instructions were based on my experience setting up a platform using the following hardware.

Component Suggested
Motherboard ASUS A88X-PRO or A88XM-A
Memory G.SKILL Ripjaws X Series 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2133

Software Required

We also have some software dependencies.

Component Suggested
Java 8 JDK
Ubuntu 13.10 64-bit edition
Ubuntu 13.10 64-bit edition HSA enabled kernel image
OKRA HSA enabled runtime

The hope is that the list of HW/SW support widens, but for early adopters this is the set of HW/SW we have been testing with.

Setting up your System

Configure your BIOS to support IOMMU

Once you have built your AMD A10-7850K APU based system you should make sure that your system is configured to use IOMMU.

Remember HSA allows the GPU and CPU cores to share the same memory. IOMMU needs to be enabled for this.

For the A88X-PRO board

For the recommended ASUS board above you will need to make sure that your BIOS is updated to version 0802. Here is a direct link to the 0802 version of the BIOS from ASUS’s site as of 2/28/2014.

Once you have the latest BIOS you will need to enable IOMMU in the system BIOS. This is done using the “CPU Configuration” screen under “Advanced Mode” and then enabling IOMMU.

For the A88XM-A

You will need the 1102 (or later) version of the BIOS

Once you have the latest BIOS you will need to enable IOMMU in the system BIOS. This is done using the “CPU Configuration” screen under “Advanced Mode” and then enabling IOMMU.

Installing Ubuntu 13.10

Once you have your BIOS setup you need to install Ubuntu

Installing HSA enabled kernel + driver Until all of the HSA drivers and features are available in stock linux and have been pulled down into Ubuntu distro we will need a special HSA enabled kernel image.

A Ubuntu compatible kernel can be pulled from github

$ cd ~ # I put all of this in my home dir
$ sudo apt-get install git
$ git clone

Or you can pull the zip and unzip using curl if you don’t have git

$ cd ~ # I put all of this in my home dir
$ curl -L >
$ unzip

This will create the following subdir on your machine


From here we can install our new image and setup the HSA KFD (the driver for HSA)and reboot to the new kernel.

$ cd ~/Linux-HSA-Drivers-And-Images-AMD
$ echo  "KERNEL==\"kfd\", MODE=\"0666\"" | sudo tee /etc/udev/rules.d/kfd.rules
$ sudo dpkg -i ubuntu13.10-based-alpha1/linux-image-3.13.0-kfd+_3.13.0-kfd+-2_amd64.deb
$ sudo cp ~/Linux-HSA-Drivers-And-Images-AMD/ubuntu13.10-based-alpha1/xorg.conf /etc/X11
$ sudo reboot

Installing OKRA RT

Now we need a runtime for executing HSAIL code. We share common infrastructure used by our sister OpenJDK project called Sumatra. Both Aparapi and Sumatra use OKRA to execute HSAIL code on a HSA enabled platform.

We can get the latest version using of OKRA (Offloadable Kernel Runtime API) from another HSA foundation repository.

$ cd ~ # I put all of this in my home dir
$ git clone

or if you prefer curl/unzip

$ cd ~ # I put all of this in my home dir
$ curl -L >
$ unzip

This will create the following dir structure.



OKRA offers a C API (for those that are so inclined ;) ) as well as a java jar file which contains JNI wrappers.

Sanity check your HSA and OKRA install

So to sanity check your install you can run a small sample app (binary)

$ cd ~/Okra-Interface-to-HSA-Device/okra/samples/
$ sh

If everything is OK this should run the C Squares test app.

Congratulations, you have executed your first HSA enabled app.

Getting OpenCL headers and libraries We need OpenCL headers and libraries to build Aparapi (remember we still support OpenCL).

My recommendation is to download AMD-APP-SDK-v2.9-lnx64.tgz from and extract the libraries and headers.

Note that we have nested zipped jars in this archive.

$ cd ~
$ gunzip ~/Downloads/AMD-APP-SDK-v2.9-lnx64.tgz
$ tar xvf ~/Downloads/AMD-APP-SDK-v2.9-lnx64.tar
$ rm ~/ ~/icd-registration.tgz ~/ ~/ReadMe.txt
$ gunzip ~/AMD-APP-SDK-v2.9-RC-lnx64.tgz
$ tar xvf ~/AMD-APP-SDK-v2.9-RC-lnx64.tar
$ rm ~/AMD-APP-SDK-v2.9-RC-lnx64.tar
$ rm -rf AMD-APP-SDK-v2.9-RC-lnx64/samples

Note where AMD-APP-SDK-v2.9-RC-lnx64 is located, you need this in the following step.

You will need Java 8

Download Java 8 JDK from I chose to download the zipped tar and not install with RPM so I can control the location of the install.

$ cd ~
$ gunzip /home/gfrost/Downloads/jdk-8-fcs-bin-b132-linux-x64-04_mar_2014.tar.gz
$ tar xvf ~/Downloads/jdk-8-fcs-bin-b132-linux-x64-04_mar_2014.tar

I now have ~/jdk1.8.0 as my java 8 install dir.

Alternatively the following will pull from Oracles site using curl

$ cd ~
$ curl > jdk-8-fcs-bin-b132-linux-x64-04_mar_2014.tar.gz
$ gunzip jdk-8-fcs-bin-b132-linux-x64-04_mar_2014.tar.gz
$ tar xvf jdk-8-fcs-bin-b132-linux-x64-04_mar_2014.tar

I now have ~/jdk1.8.0 as my java 8 install dir.

You will need g++

We use g++ to build the JNI side of Aparapi

$ sudo apt-get install g++

Pulling the HSA enabled Aparapi branch and building

Now we can pull the Aparapi lambda/HSA branch from GIT

$ sudo apt-get install git
$ git clone

If you are familiar with Aparapi structure then this tree should not be that much of a surprise but there are a few subtle changes.

Specifically the build system has been changed to support OKRA, Aparapi JNI code is provided as a Java agent and the execution scripts all refer to ${APARAPI_HOME}/ to setup a reasonable execution environment.

You will need to edit and make sure that APARAPIHOME, OKRAHOME, OCLHOME and JAVAHOME correctly.

Here are how I set my vars.

environment variable value
JAVA_HOME /home/${LOGNAME}/jdk1.8.0
OCL_HOME /home/${LOGNAME}/AMD-APP-SDK-v2.9-RC-lnx64
APARAPI_HOME /home/${LOGNAME}/aparapi-lambda
OKRA_HOME /home/${LOGNAME}/Okra-Interface-to-HSA-Device/okra/

It is recommended (thanks notzed ;) ) that you test your using sh until it stops reporting errors. Once you have finished I recommend sourcing it into your current shell before building with ant.

$ cd ~aparapi-lambda
$ .
$ mvn

If you get any problems check the vars first.

If all is well you should be able to run some samples.

$ cd ~/aparapi-lambda/samples/mandel
$ sh