OpenCL on Altera SoC FPGA (Linux Host) – Part 4 – Setup of the Runtime Environment

OpenCL on Altera SoC FPGA (Linux Host) – Part 4 – Setup of the Runtime Environment


Hello and welcome to Part 4 of setting up
OpenCL on Altera SoC FPGAs. In this section, we’ll setup the run time environment and
get the example application running on the SoC target. If you’d like to follow along,
this section assumes that you’ve already run through Part 1 and Part 3 of this tutorial.
So let’s open up a terminal to begin. Now first of all we need to get the target up
and running with Linux as well as the device drivers needed for the OpenCL integration.
To do this, we’re going to burn a default SD card image for OpenCL, and then we’ll
add the files that we’ve already created onto that image – so I’m going to make
a directory, and move into there, and we’re going to extract the SD card image that comes
with the installation of OpenCL. So we’ll use tar and then point into the directory
of our Altera installation. So in the board directory, there’s c5soc, and then under
there there’s a linux_sd_card_image tarred gzip file. Now that that file’s been extracted
we’ll go ahead and burn that onto an SD card. So I’m going to take my SD card, and
plug that into my PC. Now it’s very important that we get the correct mount point. It is
possible at this stage to overwrite your hard drive, so please do be careful when you’re
doing this. The way that I like to check that I’ve got the right mount point is to use
the “lsblk” command. So here I can see the block devices that are currently mounted
on my system – so here I can see “sda” – that’s got my boot partition, as well
as my root file system for Linux, so I definitely don’t want to be touching this card here
– this is actually my hard drive. But sdb in this case, this is actually my mounted
SD card. So I can see that I’ve already got a couple of partitions on here. It doesn’t
matter what’s on this card. We just need to know that sdb is our SD card, and that’s
we’re going to overwrite. So now that we’re confident that we’ve
got the correct mount point , in my case sdb, let’s go ahead and burn the SD card image.
Now for that we use “dd”- so I’m going to be running as the super user, and I’ll
type in “dd” and the input file is the Linux sd card image. The output is pointing
to the sdb mount point in my case. Now this will change depending on your target, so do
make sure that you don’t overwrite a hard drive here. I’m going to specify that the
block size for the copy is 1 MegaByte. That will just speed up the entire copy – and
we’ll go ahead and run that. So whilst we’re waiting for the SD card
image to be completed, let’s just take a moment to make sure that the mode pins are
correctly setup on our board. So if we have a look at the “MSEL” pins just above the
SoC FPGA, these need to be set to the following position: so Up, Down, Up, Down, Up, Up. This
will make sure that we can correctly configure the FPGA. So if we look down to the bottom
right of the board, we need to make sure that the clock select as well as boot select pins
are also set correctly with the jumpers – so this should be: right, right, right, right
and left as far as the jumpers are concerned. Ok now that the SD card image has been created,
we now have the runtime environment as well as Linux correctly setup for the target. So
if I go ahead and eject, and then re-enter this card, I’ll be able to see the root
file system for Linux – and this is the file system where I’m going to be putting
the OpenCL kernel and application. So let’s move back to the directory where we created
our application. In the vector_add directory we created a directory called “bin” and
these are the two files we want to copy across to the target. We could do this in a number
of different ways, but as I’ve already got the SD card mounted under Linux, I might as
well just copy those directly onto the card. I’m going to copy this into root’s home
directory, so I’ll need to run as the super user to do this – so I’ll copy all of
these files into the mount point of my SD card. So in my case this is this directory
here, /home/root. And now we can go ahead and removed the card from the target and plug
it into the micro SD adapter on the board. I’ve plugged a USB cable into the SoC development
kit, so that I can run an RS232 terminal on the host, so I’m going to run “minicom”
so that I can see what’s happening as we boot the target. So I’ll turn on the board,
and we can see the bootloader run, and then it will go ahead and launch Linux for us.
So I can login as “root” – so now we can see root’s home directory, as well as
the vector add example that we copied across to the file system. The first command that
we need to run is the “init_opencl” script file. This will make sure that our environment
is setup correctly for OpenCL and that the necessary device drivers are loaded onto the
kernel – so we’ll do this now with the source command, and now we can see that the
necessary device driver has been loaded. We can then use the “aocl” command to
diagnose the board – so I can see that the diagnostic has been successful and the OpenCL
environment is happy with the target. Now by default, the BSP that is being used is
for the Cyclone V SoC. You may recall that we didn’t use that for our example design,
but we’ve used the Cyclone V SoC with shared memory only, so we actually need to reconfigure
the FPGA in order to get to the correct environment. In order to program the FPGA, we use the “aocl”
command with “program”, we point to /dev/acl0, and then we specify the name of the programming
file – so in this case, its vector_add.aocx. We can see that the configuration done pin
blinked quite quickly when we ran that command, indicating that the FPGA had been recompiled.
We can then go ahead and run the “aocl diagnose” command again, and we can see that the platform
is ready to run. So let’s go ahead now and run the Vector
Add application. As we can see the application has now run successfully on the Cyclone V
SoC. Now this example has not been tuned for maximum performance, but we can already see
a massive improvement in performance compared to running without an accelerator.
So that concludes Part 4 of setting up OpenCL on Altera SoC FPGAs using a Linux host. For
more information about OpenCL, please click on the “Products” page and follow the
link to OpenCL. From there you can see overview training, as well as documentation and further
examples. In the documentation section, there are a series of guides including a getting
started guide for OpenCL on Cyclone V SoC. From this guide, you can get information about
installing, setting up the environment and running OpenCL both on Windows and Linux hosts.