Quantcast
Channel: ARM Mali Graphics
Viewing all articles
Browse latest Browse all 266

Installing OpenCL on Chromebook in 30 minutes

$
0
0

I am interrupting my blog series to share what I think is a rather elegant way to quickly get up and running with OpenCL on the ARM® Mali-T604 GPU powered Chromebook. Please bear in mind that this is not ARM's "official guide" (which can be found here). However, it's a useful alternative to the official guide if, for example, you don't have a Linux PC or just want to use Chrome OS day in and day out.

 

You will need:

 

How fast you will complete the installation will depend on how fast you can copy-and-paste instructions from this guide, how fast your Internet connection is and how fast your memory cardis (I will give an approximate time for each step measured when using 30 MB/s and 45 MB/s cards). The basic OpenCL installation should take up to half an hour; PyOpenCL and NumPy about an hour; further SciPy libraries about 3-4 hours. Most of the time, however, you will be able to leave the Chromebook unattended, beavering away while compiling packages from source.

 

Finally, the instructions are provided "as is", you use them at your own risk, and so on, and so forth... (The official guide also contains an important disclaimer.)

 

Installing OpenCL

Enabling Developer Mode

NB: Enabling Developer Mode erases all user data - do a back up first.

 

Enter Recovery Mode by holding the ESC and REFRESH (↻ or F3) buttons, and pressing the POWER button. In Recovery Mode, press Ctrl+D and ENTER to confirm and enable Developer Mode.

 

Entering developer shell (1 min)

Open the Chrome browser and press Ctrl-Alt-T.

Welcome to crosh, the Chrome OS developer shell.

If you got here by mistake, don't panic!  Just close this tab and carry on.

Type 'help' for a list of commands.

Don't panic, keep the tab opened and carry on to enter the shell:

crosh> shellchronos@localhost / $ uname -a
Linux localhost 3.8.11 #1 SMP Mon Sep 22 22:27:45 PDT 2014 armv7l SAMSUNG EXYNOS5 (Flattened Device Tree) GNU/Linux

 

Preparing an SD card (5 min)

Insert a blank SD card (denoted as /dev/mmcblk1 in what follows):

chronos@localhost / $ sudo parted -a optimal /dev/mmcblk1
GNU Parted 3.1
Using /dev/mmcblk1
Welcome to GNU Parted! Type 'help' to view a lit of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/mmcblk1 will be destroyed 
and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
(parted) unit mib
(parted) mkpart primary 1 -1
(parted) name 1 root
(parted) print
Model: SD SU08G (sd/mmc)
Disk /dev/mmcblk1: 7580MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start    End      Size      File system  Name  Flags
 1      1.00MiB  7579MiB  7578MiB                root

(parted) quit

Make sure the card is not mounted, then format it e.g.:

chronos@localhost / $ sudo mkfs.ext3 /dev/mmcblk1p1

NB: If you use a card that is less than 8 GB, you may need to reserve enough inodes when you format the card e.g.:

chronos@localhost / $ sudo mkfs.ext3 /dev/mmcblk1p1 -j -T small

Mount the card and check that it's ready:

chronos@localhost / $ sudo mkdir -p ~/gentoochronos@localhost / $ sudo mount -o rw,exec -t ext3 /dev/mmcblk1p1 ~/gentoochronos@localhost / $ df -h ~/gentoo
/dev/mmcblk1p1  7.2G   17M  6.8G   1% /home/chronos/user/gentoochronos@localhost / $ df -hi ~/gentoo
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/mmcblk1p1   475K    11  475K    1% /home/chronos/user/gentoo

Installing Gentoo Linux (10-15 min)

chronos@localhost / $ cd ~/gentoochronos@localhost ~/gentoo $ ls -la
total 36
drwxr-xr-x  3 root    root            4096 Oct  7 21:37 .
drwx--x--- 33 chronos chronos-access 16384 Oct  7 21:43 ..
drwx------  2 root    root           16384 Oct  7 21:37 lost+found

Download the latest stage 3 archive for armv7a_hardfp:

chronos@localhost ~/gentoo $ sudo wget http://distfiles.gentoo.org/releases/arm/autobuilds/latest-stage3-armv7a_hardfp.txtchronos@localhost ~/gentoo $ sudo wget http://distfiles.gentoo.org/releases/arm/autobuilds/`cat latest-stage3-armv7a_hardfp.txt | grep stage3-armv7a_hardfp`

Extract the downloaded archive right onto the card e.g.:

chronos@localhost ~/gentoo $ sudo tar xjpf stage3-armv7a_hardfp-20140819.tar.bz2

Clean up:

chronos@localhost ~/gentoo $ sudo rm stage3-armv7a_hardfp-20140819.tar.bz2chronos@localhost ~/gentoo $ sudo rm latest-stage3-armv7a_hardfp.txtchronos@localhost ~/gentoo $ ls -la
total 92
drwxr-xr-x  21 root root  4096 Oct  9 19:12 .
drwxr-xr-x  21 root root  4096 Oct  9 19:12 ..
drwxr-xr-x   2 root root  4096 Aug 20 14:44 bin
drwxr-xr-x   2 root root  4096 Aug 20 07:16 boot
drwxr-xr-x  17 root root  3760 Oct  9 18:59 dev
-rwxr--r--   1 root root    85 Oct  7 21:38 enter.sh
drwxr-xr-x  33 root root  4096 Oct  9 19:12 etc
drwxr-xr-x   2 root root  4096 Oct  7 22:14 fbdev
drwxr-xr-x   2 root root  4096 Aug 20 07:16 home
drwxr-xr-x   8 root root  4096 Oct  9 19:08 lib
drwx------   2 root root 16384 Oct  7 20:37 lost+found
drwxr-xr-x   2 root root  4096 Aug 20 07:16 media
drwxr-xr-x   2 root root  4096 Aug 20 07:16 mnt
drwxr-xr-x   2 root root  4096 Aug 20 07:16 opt
dr-xr-xr-x 195 root root     0 Jan  1  1970 proc
drwx------   5 root root  4096 Oct  8 20:46 root
drwxr-xr-x   3 root root  4096 Aug 20 14:43 run
drwxr-xr-x   2 root root  4096 Aug 20 14:54 sbin
-rwxr--r--   1 root root   192 Oct  7 21:38 setup.sh
dr-xr-xr-x  12 root root     0 Oct  9 18:58 sys
drwxrwxrwt   5 root root  4096 Oct  9 19:11 tmp
drwxr-xr-x  12 root root  4096 Oct  7 22:20 usr
drwxr-xr-x   9 root root  4096 Aug 20 07:16 var

 

Downloading OpenCL drivers (4 min)

Go to the page listing Mali-T6xx Linux drivers and download mali-t604_r4p0-02rel0_linux_1+fbdev.tar.gz. Make sure you carefully read and accept the associated licence terms.

chronos@localhost ~/gentoo $ sudo tar xvzf ~/Downloads/mali-t604_r4p0-02rel0_linux_1+fbdev.tar.gz

This will create ~/gentoo/fbdev which we will use later.

 

Entering Gentoo Linux (2 min)

Similar to crouton, we will use chroot to enter our Linux environment.

 

Create two scripts and make them executable:

chronos@localhost ~/gentoo $ sudo vim ~/gentoo/setup.sh
#!/bin/sh
GENTOO_DIR=/home/chronos/user/gentoo
mount -t proc /proc $GENTOO_DIR/proc
mount --rbind /sys  $GENTOO_DIR/sys
mount --rbind /dev  $GENTOO_DIR/dev
cp /etc/resolv.conf $GENTOO_DIR/etcchronos@localhost ~/gentoo $ sudo vim ~/gentoo/enter.sh
#!/bin/sh
GENTOO_DIR=/home/chronos/user/gentoo
LC_ALL=C chroot $GENTOO_DIR /bin/bashchronos@localhost ~/gentoo $ sudo chmod u+x ~/gentoo/setup.sh ~/gentoo/enter.sh

Execute the scripts:

chronos@localhost ~/gentoo $ sudo ~/gentoo/setup.shchronos@localhost ~/gentoo $ sudo ~/gentoo/enter.sh

Note that the ~/gentoo directory will become the root (/) directory once we enter our new Linux environment. For example, ~/gentoo/fbdev will become /fbdev inside the Linux environment.

 

Installing OpenCL header files (2 min)

Download OpenCL header files from the Khronos OpenCL registry:

localhost / # mkdir /usr/include/CL && cd /usr/include/CLlocalhost / # wget http://www.khronos.org/registry/cl/api/1.1/opencl.hlocalhost / # wget http://www.khronos.org/registry/cl/api/1.1/cl_platform.hlocalhost / # wget http://www.khronos.org/registry/cl/api/1.1/cl.hlocalhost / # wget http://www.khronos.org/registry/cl/api/1.1/cl_gl.hlocalhost / # wget http://www.khronos.org/registry/cl/api/1.1/cl_ext.h

 

Installing OpenCL driver (2 min)

Change properties on the downloaded OpenCL driver files and copy them to /usr/lib:

localhost / # chown root /fbdev/*localhost / # chgrp root /fbdev/*localhost / # chmod 755 /fbdev/*localhost / # mv /fbdev/* /usr/liblocalhost / # rmdir /fbdev

 

Summary

By now you should have a mint Linux installation complete with the OpenCL drivers and headers, so you can start playing with OpenCL!

When you reboot, you just need to mount the card and execute the setup script again:

chronos@localhost / $ sudo mount -o rw,exec -t ext3 /dev/mmcblk1p1 ~/gentoochronos@localhost / $ sudo ~/gentoo/setup.sh

Then you can pop in and out of the Linux environment with:

chronos@localhost / $ sudo ~/gentoo/enter.shlocalhost / # exitchronos@localhost / $

But the fun just begins here! Follow the instructions below to install PyOpenCL and SciPy libraries for scientific computing.

 

Installing PyOpenCL

Configuring Portage (15 min)

Portage is Gentoo's package management system.

localhost / # echo "MAKEOPTS=\"-j2\"" >> /etc/portage/make.conflocalhost / # echo "ACCEPT_KEYWORDS=\"~arm\"" >> /etc/portage/make.conflocalhost / # mkdir /etc/portage/profilelocalhost / # mkdir /etc/portage/package.uselocalhost / # mkdir /etc/portage/package.unmasklocalhost / # mkdir /etc/portage/package.accept_keywordslocalhost / # mkdir /etc/portage/package.keywordslocalhost / # touch /etc/portage/package.keywords/dependences

Perform an update:

localhost / # emerge --synclocalhost / # emerge --oneshot portagelocalhost / # eselect news read

 

Selecting Python 2.7 (1 min)

localhost / # eselect python set python2.7

 

Installing NumPy (30-40 min)

Install NumPy with LAPACK as follows.

localhost / # echo "dev-python/numpy lapack" >> /etc/portage/package.use/numpylocalhost / # echo "dev-python/numpy -lapack" >> /etc/portage/profile/package.use.masklocalhost / # emerge --autounmask-write dev-python/numpylocalhost / # python -c "import numpy; print numpy.__version__"
1.8.2

 

Installing PyOpenCL (5-10 min)

Install PyOpenCL.

localhost / # cd /tmplocalhost tmp # wget https://pypi.python.org/packages/source/p/pyopencl/pyopencl-2014.1.tar.gzlocalhost tmp # tar xvzf pyopencl-2014.1.tar.gzlocalhost tmp # cd pyopencl-2014.1localhost pyopencl-2014.1 #localhost pyopencl-2014.1 # python configure.pylocalhost pyopencl-2014.1 # make installlocalhost pyopencl-2014.1 # python -c "import pyopencl; print pyopencl.VERSION_TEXT"
2014.1localhost pyopencl-2014.1 # cd examples && python demo.py
(0.0, 241.63054)

 

Installing scientific libraries

If you would like to follow my posts on benchmarking (e.g. see the intro), I recommend you install packages from the SciPy family.

 

Installing IPython (30-45 min)

localhost / # emerge --autounmask-write dev-python/ipythonlocalhost / # ipython --version
1.2.1

 

Installing IPython Notebook (3-7 min)

Install IPython Notebook to enjoy a fun blend of Chrome OS and IPython experience.

 

localhost / # emerge dev-python/jinja dev-python/pyzmq www-servers/tornadolocalhost / # ipython notebook
2014-05-08 06:49:08.424 [NotebookApp] Using existing profile dir: u'/root/.ipython/profile_default'
2014-05-08 06:49:08.440 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-05-08 06:49:08.485 [NotebookApp] Serving notebooks from local directory: /
2014-05-08 06:49:08.485 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2014-05-08 06:49:08.486 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2014-05-08 06:49:08.486 [NotebookApp] WARNING | No web browser found: could not locate runnable browser.

Open http://127.0.0.1:8888/ in a new Chrome tab to start creating your own IPython Notebooks!

 

Installing Matplotlib (35-50 min)

localhost / # emerge --autounmask-write dev-python/matplotliblocalhost / # python -c "import matplotlib; print matplotlib.__version__"
1.4.0

 

Installing SciPy (45-60 min)

localhost / # emerge --autounmask-write sci-libs/scipylocalhost / # python -c "import scipy; print scipy.__version__"
0.14.0

 

Installing Pandas (55-80 min)

localhost / # emerge --autounmask-write dev-python/pandaslocalhost / # etc-update
Scanning Configuration files...
The following is the list of files which need updating, each
configuration file is followed by a list of possible replacement files.
1) /etc/portage/package.keywords/dependences (1)
Please select a file to edit by entering the corresponding number.              (don't use -3, -5, -7 or -9 if you're unsure what to do)              (-1 to exit) (-3 to auto merge all files)                           (-5 to auto-merge AND not use 'mv -i')                           (-7 to discard all updates)                           (-9 to discard all updates AND not use 'rm -i'): -3
Replacing /etc/portage/package.keywords/dependences with /etc/portage/package.keywords/._cfg0000_dependences
mv: overwrite '/etc/portage/package.keywords/dependences'? y
Exiting: Nothing left to do; exiting.localhost / # emerge dev-python/pandaslocalhost / # python -c "import pandas; print pandas.__version__"
0.14.1

Viewing all articles
Browse latest Browse all 266

Trending Articles