How do I place the libaplc library in external memory ?

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Sat Jun 08, 2013 5:05 pm

Just to make sure - did you remember to run the e-server? The e-gdb cannot work on a hardware target without an e-server active.

However, if you do try, there is some tricky point with running it that comes from the legacy code in it. It requires both HDF files - the .hdf and the .xml that are found in the BSP. So, to run it, please use the following script:

Code: Select all
#!/bin/bash

set -e

ELIBS="${EPIPHANY_HOME}/tools/host/lib"
EHDF="${EPIPHANY_HOME}/bsps/zed_E16G3_512mb/zed_E16G3_512mb.hdf"
EXML="${EPIPHANY_HOME}/bsps/zed_E16G3_512mb/zed_E16G3_512mb.xml"

sudo -E LD_LIBRARY_PATH=${ELIBS} EPIPHANY_HDF=${EHDF} ${EPIPHANY_HOME}/tools/host/bin/e-server -hdf ${EXML} $@
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Sat Jun 08, 2013 5:17 pm

Ah thanks.
It did seem to be working, but perhaps not fully.
I will do what you say - there is so much to learn !

Ok, I had to add a symbolic link to get libepiphany-hal.so (existing libe-hal.so)
Then a more understandable number of servers started (16).
But otherwise still the same hang when outputting.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Mon Jun 10, 2013 5:04 pm

Dr. Webber,

I think that at this point I am out of idea of helping w/o actually having the software itself. Can you please attach an archive with an minimal version of the failing program? What I need is the minimal program (hist and device sides) that still fails to give the expected result, the linker script used, the build script and the run script.

Thanks.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Mon Jun 10, 2013 8:48 pm

Hi ysapir,
Oh excellent.
I have created a tar file but it is too large to upload here - I will email it to you.

OK, it is called skeleton because it is mainly a build skeleton that is slightly fleshed with an application.
There are three possible build functions.

All three build a host function
HOST=harness_01
This is just reads a simple buffer acting as a std-out replacement.
and a target function
TARGET=target
whose source can be chosen at the top of the build functions.
Currently the source function is vector_sum_ed.c.
This is is the output from applying aplc to
: vector_sum.apl:
Code: Select all
V .is .io 9
# .is V
S .is +/V
# .is S

The output of this when compiled with aplc is vector_sum.c, no problem.
When run this should generate a vector 1 to 9, and then the sum of the vector :
Code: Select all
 1 2 3 4 5 6 7 8 9
 45

vector_sum.c, has been slightly hand edited to add #include "e_lib.h", an output buffer as a std-io replacement, fprntf statements have been changes to sprintf to point to this buffer, and a few test output statements have been inserted :
vector_sum_ed.c (in ./src)
Code: Select all
#include "aplc.h"
#include <setjmp.h>

#include "e_lib.h"

// char outbuf[128] SECTION("shared_dram");
// char outbuf[128] SECTION("buffer_location");
// char outbuf[4096] SECTION("buffer_location");
// char outbuf[4096] SECTION("buffer_space");
char outbuf[4096] SECTION("BUFFER_SPACE");

char* pointer = outbuf ;
char Word[] = "testAplctext";

extern jmp_buf aplc_env;
extern struct trs_struct V;/* global */
extern struct trs_struct S;/* global */
/* ------------- main ------------- */
/* V, class GLOBAL, is_pointer 0 */
/* V info:
 TYPEKNOWN (int) RANKKNOWN ({1}) SHAPEKNOWN ((2) 9 ) size 9 */
/* V: type= {int}, rank= {1} */
int V_shape[1] = { 9} ;
int V_value[9];
struct trs_struct V = {APLC_INT,1,V_shape,9,APLC_ALLOC_NF};
/* S, class GLOBAL, is_pointer 0 */
/* S info:
 ANYRANK SHAPEARB */
/* S: type= {any}, rank= {arbitrary} */
struct trs_struct S;
/* main, class FUNCTION, is_pointer 0 */
/* main info:
 valence MM, optype UNK */
 int i_main[3] = {0, 1, 9};


int
main(int argc, char *argv[]) {
int stmtno;
struct trs_struct trs1;
union mp_struct mp1, mp2, mp3;
union res_struct res0, res1, res2, res3, res4;
int i0 = 0;/* for singleton indices */
int i1, i2, i3, i4, i5, i6, i7, i8, i9,
i10, i11, i12; /* end of declarations */



sprintf(pointer,"some text");
pointer = pointer + 9 ;
sprintf(pointer,"\n");
pointer++ ;
sprintf(pointer,"Q");
pointer++ ;
sprintf(pointer,"some text");
pointer = pointer + 9 ;



aplc_setargs(argc, argv);
trs1.type = APLC_UKTYPE;
trs1.alloc_ind = APLC_UNALLOC;
/* V: GLOBAL, type= {int}, rank= {1} */
/* local var V: type= {int}, rank= {0} */
/* V: type= {int}, rank= {1} */
V.value.ip = V_value;
V.alloc_ind = APLC_ALLOC_NFS;
V.alloc_rank = 0;
V.alloc_size = 0;
/* S: GLOBAL, type= {any}, rank= {arbitrary} */
/* local var S: type= {any}, rank= {arbitrary} */
/* S: type= {any}, rank= {arbitrary} */
S.type = APLC_UKTYPE;
S.alloc_ind = APLC_UNALLOC;
S.alloc_rank = 0;
S.alloc_size = 0;
/* main: FUNCTION, type= {unknown type}, rank= {unknown} */
aplc_trace("main", 1);
/* genassign to V (SHAPE) */
/* lookup */
/* assignment */
/* genassign_named shape */
i3 = aplc_ixorg;
/* genassign_named shape val */
/* typesmatch(node, RIGHT) 1, asgn_pass_trs(node) 0 */
/* type(node) APLC_INT; type(right) APLC_INT*/
for (i2 = 0; i2 < 9; i2++) {
V.value.ip[i2] = i3++ ;
}
/* genassign done */
/* genassign to V (FINISH) */
/* lookup */
/* assignment */
/* genassign_named fin */
/* genassign done */



aplc_trace("main", 2);
 if (V.type == APLC_UKTYPE) aplc_error("undefined value (V) used");
mp1.ip = V.value.ip;
/* gencollect, shape */
/* gencollect, havevalue || havetrs { mp1.ip} right {mp1.ip}*/
 aplc_format(&trs1, &V);
i1 = trs1.size;

for (i3 = 0; i3 < i1; i3++) {
// fprintf(aplcout,"%c",trs1.value.cp[i3]);
   sprintf(pointer++,"%c",trs1.value.cp[i3]);
for (i2=aplc_bmpnl(i3, trs1.rank, trs1.shape); i2>0; i2--)
 // fprintf(aplcout,"\n");
    sprintf(pointer++,"\n");
}


/* -- quad assign finish */
 aplc_detalloc(&trs1);
/* -- */



aplc_trace("main", 3);
/* genassign to S (SHAPE) */
/* lookup */
/* assignment */
/* genassign_late shape, result trs1 */
mp3.ip = V.value.ip;
i5 = 9;
/* genassign_late shape val */
/* typesmatch(node, RIGHT) 1, asgn_pass_trs(node) 0 */
/* type(node) APLC_INT; type(right) APLC_INT*/
/* name S, class GLOBAL */
aplc_settrs(&trs1, APLC_INT, 0, aplc_ivone);
i1 = aplc_talloc(&trs1);
mp1.ip = trs1.value.ip;
{
res2.i = 0;
for (i3 = 0; i3 < i5; i3++) {
res2.i += *mp3.ip++ ;
}
 /* asntchk 1 (dest type known (int) and simple) mkrktype */
(*mp1.ip = res2.i);
}
/* genassign_late shape value code {(*mp1.ip = res2.i)} */
/* genassign done */
/* genassign to S (FINISH) */
/* lookup */
/* assignment */
/* genassign_late fin */
/*aplc_detalloc(&S);*/
aplc_assign(&S, &trs1);
/* genassign done */
aplc_trace("main", 4);
if (S.type == APLC_UKTYPE) aplc_error("undefined value (S) used");
mp1 = S.value;
/* gencollect, shape */
/* gencollect, havevalue || havetrs { mp1} right {mp1}*/
aplc_format(&trs1, &S);
i1 = trs1.size;
for (i3 = 0; i3 < i1; i3++) {
// fprintf(aplcout,"%c",trs1.value.cp[i3]);
sprintf(pointer++,"%c",trs1.value.cp[i3]);


for (i2=aplc_bmpnl(i3, trs1.rank, trs1.shape); i2>0; i2--)
 // fprintf(aplcout,"\n");
   sprintf(pointer++,"\n");
}

/* -- quad assign finish */
aplc_detalloc(&trs1);
/* -- */
/* -- doprog finish */
aplc_detalloc(&V);
aplc_detalloc(&S);
/* -- */
return 0;
}

So build the host and target functions, and .srec code, by :
./buildv5.sh

The .ldf function used is a slightly modified version of legacy.ldf : ./apl_external.ldf
The output is always Debug/target.elf and Debug/target.srec
and run it with
./runv5.sh
What I get is :
Code: Select all
  0: Message from eCore 0x8ca ( 3, 2): "some text
Qsome text"
  1: Message from eCore 0x84b ( 1, 3): "some text
Qsome text"
  2: Message from eCore 0x84b ( 1, 3): "some text
Qsome text"

etc.
Which is good, in that it tells us that the output buffer is working
(from sprintf(pointer,"some text"); etc.)
but it should be followed by the the rest of the apl output.

buildv5.sh builds a version based on a pre-built aplc library
buildv7.sh builds a version that also builds the aplc library from source each time (takes just over 30 sec, a lot to do)
buildv9.sh builds a version (from non-edited .c functions) that is intended to be used with the debugger.

There are various aplc .h functions scattered around, and a copy of the aplc library source functions in the /src directory, to assist with tracing in e-gdb debug mode.

server.sh starts servers for use with e-gdb testing.

Best of luck and thanks indeed !
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Tue Jun 11, 2013 10:51 pm

OK, I extracted the (tidy) archive and examined the code. There's a few comments:

1. Build script is erroneous in line #25, missing "="

2. Compiler can't find "aplc.h" header. Added "-I inc" option to the e-gcc line.

3. The "BUFFER_SPACE" input section was not defined in the LDF. I pointed that out in one of the previous posts on this thread. However, it seems like the object is placed correctly anyway. I could not find a reference to such behaviour in the manual, so I posted a question in a forum.

4. After the changes, the program builds and runs OK. However, it looks like the 10ms sleep time is too aggressive. On my ZedBoard (with E64), I get lines cut after the "8" digit.

5. Changing to 100ms delay, looping for 100 iterations, I get all the expected printouts. All 100 iterations printed the "45" number (sum?).

Code: Select all
 99: Message from eCore 0x84a ( 1, 2): "some text
Qsome text 1 2 3 4 5 6 7 8 9
 45
"


If you don't see this result using the same tidy archive you sent me after increasing the delay, then it is possible that you have a faulty board and we need to further investigate that (by faulty board I also include a broken eSDK installation or firmware).
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Wed Jun 12, 2013 10:06 am

ysapir wrote:OK, I extracted the (tidy) archive and examined the code. There's a few comments:

ysapir wrote:1. Build script is erroneous in line #25, missing "="

Sorry, that was a failed hand edit to produce you a compact tidied version. I did the edits on my lap-top as the network was running extremely slowly at the time.
ysapir wrote:2. Compiler can't find "aplc.h" header. Added "-I inc" option to the e-gcc line.

Sorry, ditto.
ysapir wrote:3. The "BUFFER_SPACE" input section was not defined in the LDF. I pointed that out in one of the previous posts on this thread. However, it seems like the object is placed correctly anyway. I could not find a reference to such behaviour in the manual, so I posted a question in a forum.

Yes thank you, I did not understand what I should put here, can you post or email a corrected version ?
ysapir wrote:4. After the changes, the program builds and runs OK. However, it looks like the 10ms sleep time is too aggressive. On my ZedBoard (with E64), I get lines cut after the "8" digit.

AHHH!. And the E64 is running !! Great !!!
We need to find someone who understands how to build a proper buffer based std-in and std-out with signalling.
ysapir wrote:5. Changing to 100ms delay, looping for 100 iterations, I get all the expected printouts. All 100 iterations printed the "45" number (sum?).

Fantastic, my assumption that sprintf was broken was faulty.
This is excellent news - yes the APL does a +/ reduction of the vector.
I will do this on my version and test it.

Yes I have just increased the delay and indeed it now works fine !
Code: Select all
  0: Message from eCore 0x8ca ( 3, 2): "some text
Qsome text 1 2 3 4 5 6 7 8 9
 45
"

etc.

In this version of the .ldf all the program is in external memory, which is why it is so slow - it we now need to move to an .ldf where the program code is in internal memory (where this forum discussion started)

I will then build a number of examples and put them in the APL section of the forum as examples.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby 9600 » Wed Jun 12, 2013 10:23 am

Dr.BeauWebber wrote:I will then build a number of examples and put them in the APL section of the forum as examples


Do you think we could put these and the rest of the code in a GitHub repository or similar?

Cheers,

Andrew
Andrew Back (a.k.a. 9600 / carrierdetect)
User avatar
9600
 
Posts: 997
Joined: Mon Dec 17, 2012 3:25 am

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Wed Jun 12, 2013 10:58 am

9600 wrote:Do you think we could put these and the rest of the code in a GitHub repository or similar?

Sam Sirlin and I need to update the aplc source to correctly include all the build modifications I have generated over the last few months for a number of recent targets and cross-compiled targets : Altera Nios II, XMOS, Raspberry Pi Linux-armv6, Parallella Linux-armv7 and Epiphany cores.

A remaining point that needs to be sorted is adding proper Std-in Std-out (and generic pipes), based on buffers on the Epiphany chip, with proper synchronisation. Until then I am just about to try and write a .sed script to take the .c output from aplc and add an interface buffer, and convert all fprintf to sprintf.

Then I will ask Sam again about GitHub.
Yes I think it will be time - a number of simple gotchas have been removed from the compiling process, I think these sources are nearly ready.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Wed Jun 12, 2013 11:12 am

May I ask what are the correctly specified 3 or 4 part names for the Parallella and Epiphany, when compiling ?
I.e. for my Windows-Cygwin system it is :
Target: i686-pc-cygwin
/bin/arch = i686
I need to place sensible values in the aplc compiler.
cheers, Beau
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Wed Jun 12, 2013 5:26 pm

3. The "BUFFER_SPACE" input section was not defined in the LDF. I pointed that out in one of the previous posts on this thread. However, it seems like the object is placed correctly anyway. I could not find a reference to such behaviour in the manual, so I posted a question in a forum.


Yes thank you, I did not understand what I should put here, can you post or email a corrected version ?


According to the LD reference (I posted the link earlier), the line should be something like:

Code: Select all
BUFFER_SPACE . : { *.o(BUFFER_SPACE) }  > EXTERNAL_DRAM_1


The first name is the name of the output section. It (the name itself) is not really important to our purpose.

The name inside parentheses is the input section name as it appears in the C program (input). The "*.o" is the list of files, which potentially include this input section, that should be mapped to the output section.

However, as I mentioned, it worked as expected even when the input sections were omitted, but I don't know if this is repeatable.

May I ask what are the correctly specified 3 or 4 part names for the Parallella and Epiphany, when compiling ?


When compiling what? If you need this for the APL to C compiler, then why is this important? If you need it for the C to Epiphany compiler, you use e-gcc, so why is this important?

It is not required for the APL to ARM compiler, I assume, as you use the native ARM backend (what I call a-gcc). Is this correct?
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

PreviousNext

Return to Programming Q & A

Who is online

Users browsing this forum: No registered users and 3 guests

cron