Running your own code on the Epiphany in 60 seconds

A forum for documenting the Parallella and Epiphany . (Not Q&A!)

Running your own code on the Epiphany in 60 seconds

Postby polas » Fri Oct 16, 2015 2:23 pm

Programming the Epiphany chip is actually very simple, and in this walk through we will be using an Epiphany version the Python programming language (ePython) as our technology. Using ePython you can go from being a complete novice to writing and running your own code on the Epiphany co-processor in 60 seconds. This walk through is intended as an introductory guide, and we will initially discuss installation & configuration of ePython, before looking at some code examples which you can then modify to further explore the concepts.

Installing ePython
ePython, our version of Python, is open source and available at GitHub. You only need to complete these install commands once, once ePython is installed it can be used as many times as you like. Log into your Parallella board as usual and issue the command

Code: Select all
git clone https://github.com/mesham/epython.git


This will copy ePython onto your machine and a directory called epython will have been created. Next we are going to build this by issuing the make command, from the top level directory (the one you issued the git clone into) issue the following two commands:

Code: Select all
cd epython
make


The build process takes around 20-30 seconds and once complete you will be returned to the bash prompt. The next (and last) step is to install ePython to a central location by issuing the two commands below. You will be promoted for your user's password with the first command. The second command (bash) starts a new bash terminal which has the python paths correctly set and every time bash starts from now on it will be correctly configured for ePython.

Code: Select all
sudo make install
bash


Congratulations! You have installed ePython and are ready to start programming!

Let's get coding!
Open a text editor and enter the following code, then save this file as hello.py

Code: Select all
print "Hello world"


Now issue epython hello.py and each Epiphany core will display the message "Hello world", along with the ID of that specific core. Well done - you have just run your first program on the Epiphany co-processor, so let's start exploring some more! The parallel package provides a number of functions which are useful for parallel codes. We are going to look at the coreid and numcores functions. Using the text editor, put the following code into your source file hello.py and reissue epython hello.py

Code: Select all
import parallel
print "Hello world from core "+coreid()+" out of "+numcores()+" cores"


Line one will import the parallel functions (of which coreid and numcores are members.) Line two then displays a similar message from each core as the first example, but also includes the ID of each core and total number of cores in the output. We don't have to use all Epiphany cores, one can set the number of cores via the -d command line argument, for instance epython -d 5 hello.py will only run over five Epiphany cores (you should not select a number greater than the number of physical cores.)

You're doing great, let's look at something a bit more advanced
We have been printing out information about the cores, but we can also use this in other ways too. The first code example in this section will display an even or odd message depending upon the core's id.

Code: Select all
import parallel
if coreid() % 2 == 0:
  print "Even core"
else:
  print "Odd core"


Now we are going to put this all together and produce a slightly more complex example. In the following code the first core will request a number from the user (this can be an integer or float.) The bcast function is then called (part of the parallel package) to broadcast this number from the root process (in this case 0, the second argument to the bcast call) to all other cores. Each core then displays the number it has just received.

Code: Select all
import parallel
a=0
if coreid()==0:
  a=input("Enter a number: ")
a=bcast(a,0)
print "Number is "+a


This is an example of a collective communication, where each process collectively works together to produce some final value. Collective communications form a major corner stone of parallel programming and broadcasting values between processes (or Epiphany cores in this case) is a fundamental aspect of many parallel codes running on modern supercomputers.

Summary
In this walk through we have installed Epiphany Python and then run a few simple, introductory examples to illustrate running codes on the Epiphany co-processor. We have just scratched the surface here and as you can probably imagine, there is far more to explore. ePython comes with complete documentation (doc folder) along with a number of code examples which you can play with.
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby philipz » Sat Oct 17, 2015 2:14 am

Great!!!
Could EPython combine with Jupyter or IPython ? Thanks.
viewtopic.php?f=26&t=850
philipz
 
Posts: 8
Joined: Tue Nov 12, 2013 2:16 am

Re: Running your own code on the Epiphany in 60 seconds

Postby polas » Sat Oct 17, 2015 3:55 pm

Hi - yes it should be possible especially as the source is available for both. Sounds like it would be an interesting project, let me know how you get on with this and if you have any questions/problems.
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby rviertel » Tue Dec 08, 2015 2:55 am

This is excellent! Exactly what I needed to begin learning how to use the epiphany chip. Will this work with libraries such as numpy scipy etc.?
rviertel
 
Posts: 7
Joined: Mon Aug 17, 2015 10:57 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby leon_heller » Thu May 19, 2016 9:48 am

When I run this on my Kickstarter board I have a problem:

parallella@parallella:~$ epython hello.py
epython-host: ERROR: SREC file support is deprecated. Use elf format.

Error loading Epiphany program

Any ideas what is going wrong?
Leon Heller
G1HSM
leon_heller
 
Posts: 67
Joined: Mon Dec 17, 2012 4:01 am
Location: St. Leonards-on-Sea, E. Sussex, UK.

Re: Running your own code on the Epiphany in 60 seconds

Postby sebraa » Thu May 19, 2016 12:50 pm

Use the 2016.3.1 bugfix release, it should support loading SREC files again. The only long-term solution is to make ePython use ELF files instead.
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby polas » Thu May 19, 2016 4:33 pm

Thanks for the report, I have updated ePython to additionally build an ELF device executable and default to loading this ELF version rather than the SREC so that should fix the issue.

Cheers,
Nick
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby t3chman » Thu May 26, 2016 6:55 am

I'm having some trouble getting the first hello world example to run properly. I've checked that the environment variables are configured correctly and that I haven't made any typo's. Also chmod'd the file to make it executable, although I don't think that's necessary. Here's the error I get:

root@parallella:~/epython# epython hello.py
/usr/bin/epython: line 28: 18620 Bus error $FILE "$@"

The bus number changes each time I execute it. Any ideas?

Thank you for writing a great intro to the Epiphany! :)
-----
Gabe
t3chman
t3chman
 
Posts: 2
Joined: Thu May 26, 2016 6:47 am

Re: Running your own code on the Epiphany in 60 seconds

Postby polas » Thu May 26, 2016 6:34 pm

Hi - sorry to hear you are having issues, I guess this is a "normal" 16 core Epiphany chip? Which image are you using, are you using the latest (March) one? Can you run other (non-ePython) examples OK on your Parallella?
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm

Re: Running your own code on the Epiphany in 60 seconds

Postby t3chman » Fri May 27, 2016 5:48 pm

Yes, I just purchased the 16-core Parallela Micro-server off Amazon this week. I'm using the latest headless image of Ubuntu. I actually haven't attempted any other examples yet, but was planning on it. Do you have any recommendations? I'll start looking :)
-----
Gabe
t3chman
t3chman
 
Posts: 2
Joined: Thu May 26, 2016 6:47 am

Next

Return to Quick Start Guides , Documentation, Examples (Start Here!)

Who is online

Users browsing this forum: No registered users and 1 guest