[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Parallella Community • View topic - Is there anything like e_load() which loads from memory?

Is there anything like e_load() which loads from memory?

Any technical questions about the Epiphany chip and Parallella HW Platform.

Moderator: aolofsson

Is there anything like e_load() which loads from memory?

Postby rowan194 » Wed Jan 28, 2015 9:06 pm

I'm planning on using a variation of linear genetic programming which will directly modify Epiphany machine code. The ARM host will prepare the next generation while the cores are evaluating the fitness of the current.

The trouble is that e_load() wants a filename, but it's going to be very inefficient to have to create a new file each time, especially since it's not just a flat bin file. Imagine having to write out 500 SREC files each generation?

Can I roll my own to load (from the host memory) and execute a program (on the Epiphany), using something like e_write then e_start? Or does e_load do a lot more?

(One option may be to e_load a 'blank' program, then in a loop use e_read to save the core, including code/data/IVT, modify machine code in host memory, then e_write back?)
rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby sebraa » Wed Jan 28, 2015 11:19 pm

You could have a small stub program in the first, write-protected half-bank of each core. Then, instead of pushing new code to the cores, you could have that stub program fetch it from host memory, where the host has put it. That code would have to be linked at a different address, probably requiring a different linker script. Running it would then just involve creating a function pointer to the entry point of the loaded binary.

That way, you can get around the SREC files. Since you'll probably call some kind of linker, you might still have intermediate files - it might be worth keeping them on a ram disk on the host. :-)
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Is there anything like e_load() which loads from memory?

Postby rowan194 » Thu Jan 29, 2015 7:02 am

Don't think there will be a need for a linker or intermediate files - the host will be manipulating machine code directly, including calculating branch addresses. If the cores had more memory, I could keep the entire set of candidate programs in the core memory, and just modify that from the host (each generation generally changes a single opcode - one single write!), but unfortunately I need to spend a bit of time copying the Epiphany code back and forth. The other option is to execute from the host's memory, but if I understand correctly that is unbelievably slow, and would be especially painful with all 16 cores fighting for access. In that instance, it would probably be faster to execute on the ARM. :(
rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby piotr5 » Thu Jan 29, 2015 10:07 am

and you'd still need to read from host either way.
why don't you just sacrifice one eCore and let the program run solely on epiphany?
let only 15 cores fight it out, and a write-protected 16th core serves the changes?
then the only data on host will be just intermediate results and maybe some rng-seeds...
piotr5
 
Posts: 230
Joined: Sun Dec 23, 2012 2:48 pm

Re: Is there anything like e_load() which loads from memory?

Postby rowan194 » Thu Jan 29, 2015 10:37 am

There isn't enough memory space in the Ephiphany. There could be 500 or 1000 candidate programs in a generation, and each could have up to 1000 instructions. As well as the program code itself, there is also training and validation data, plus fitness calculation code (these remain static so only need to be transferred in once). It may be possible to squeeze 2 or 3 candidates into a single core each load/run round, in order to improve performance.

I should make it clear that each candidate program is executed multiple times (one for each item of training/validation data), and the multiple runs can all be done on-core, independent of the host. So it's more like transfer from host, run, run, run, run, run, run (etc) rather than transfer, run, transfer, run. The latter would be very inefficient as the Parallella would spend half the time just shifting data between the two chips.

I think I may have a good read of the Ephiphany datasheet, and a peek at the SDK internals, to see if I can roll my own from first principles. Even a 'blank' program int main() {}; ends up as a 6428 byte SREC file. Because the cores are running a simple program that reads input data, does some calculations and conditional branches, then exits, there's no need to use any C library functions.

Anyway, sorry for rambling, it's really just thinking aloud. I'd be curious to know if anyone has bypassed the SREC/e_load() system.
rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby sebraa » Thu Jan 29, 2015 2:07 pm

Then sacrifice one core and have it serve the changes from shared memory, where the host prepared the changes earlier. That core could do some advanced caching, and also take care of the of the results. That way, you limit the fighting for shared memory, while having effectively infinite amounts of memory.

It should be possible to roll your own startup code without the newlib. This reduces code size a lot. Oh, and your test main() function should contain an endless loop: On embedded systems, main() should never end.
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Is there anything like e_load() which loads from memory?

Postby rowan194 » Thu Jan 29, 2015 10:29 pm

Here's what I've come up with so far... but it's not working. I've had two hours sleep so I'm probably missing something obvious, or have made a silly mistake.

The idea is to stuff code directly into the Epiphany by using e_write, rather than e_load. Epiphany code simply increments r1 in an endless loop; host code reports back contents of r1 for each core, once per second.

Is this the correct way to point to the start of code? 0x0 is a vector?

edit: I think I've made some fundamental mistake with reading r1 from the core, because using e_write to set r1, then reading it back, doesn't return that value I've set.

<code deleted - see next msg>
rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby rowan194 » Fri Jan 30, 2015 12:49 pm

rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby rowan194 » Sun Feb 22, 2015 12:08 pm

I've done some benchmarking and have run into a further issue - the time it takes for the host to load and execute a program on the Epiphany.

I wrote a simple program that measures the time taken to e_write() the program from host memory to the core, then begin execution.

Results:

8k program: 0.539ms
16k program: 1.099ms
32k program: 2.146ms

The scaling is fairly linear so it seems most of the time is spent transferring data between the host memory and core.

Because my application needs to execute (literally) millions of different programs in rapid succession, the time taken to load each one becomes a painfully significant part of the total... 1 to 2 milliseconds to load the program, but only around 0.1 milliseconds to execute it.

Unless e_write() is horribly inefficient, and can be greatly improved with a hand rolled version, I don't really see any way to work around this. :(
rowan194
 
Posts: 17
Joined: Wed Jan 14, 2015 1:02 pm

Re: Is there anything like e_load() which loads from memory?

Postby aolofsson » Sun Feb 22, 2015 6:57 pm

rowan194,
Writing directly to the cores is always going to be very slow. The current memcpy() implementation inside e_write() is just using a store in a loop from the registers. It would be faster to program the Epiphany DMA to copy in a block of data from shared memory (or to use the Zynq DMA to move the data. My apologies that we haven't gotten this done yet...
Andreas
User avatar
aolofsson
 
Posts: 1005
Joined: Tue Dec 11, 2012 6:59 pm
Location: Lexington, Massachusetts,USA

Next

Return to Epiphany and Parallella Q & A

Who is online

Users browsing this forum: No registered users and 18 guests

cron