[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[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/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/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 - Using division inside cores crashes the program

Using division inside cores crashes the program

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

Using division inside cores crashes the program

Postby Nightingale » Tue Oct 28, 2014 1:18 pm

I have a variable:
volatile float *tfv = static_cast<float*>((void*)0x3990);

I have an issue. This code works:
(*tfv) = 1234.5f;
(*tfv) = (*tfv) * 0.0025f;
This also works:
(*tfv) = 1234.5f;
(*tfv) = (*tfv) / 2.0f;

But this causes cores to crash:
(*tfv) = 1234.5f;
(*tfv) = (*tfv) / 400.0f;

In fact performing division crashes the execution inside the cores. The only exception is division by 2 or division by power of twos. The program itself is big, but essentially it stops crashing only after I take out all the places where division is made (square root also crashes).

Does anybody have any ideas why this could be happening? Or how can I replace this line so that it doesn't use division and square root:
b = 1 / (sqrt(a));
Nightingale
 
Posts: 11
Joined: Fri Sep 19, 2014 11:38 am

Re: Using division inside cores crashes the program

Postby jeremybennett » Tue Oct 28, 2014 1:24 pm

Hi nightingale,

This seems surprising. Given this is a floating point processor, you would think division crashing the processor would have been noticed by now!

Could you provide this as an actual test case. Then post the test case, along with the complete command lines which you use to trigger the problem. The intention is that someone else can reproduce the problem.

Jeremy
User avatar
jeremybennett
 
Posts: 61
Joined: Mon Dec 17, 2012 9:06 am

Re: Using division inside cores crashes the program

Postby Nightingale » Tue Oct 28, 2014 2:58 pm

After removing as much code as I could, it seems that the bug was caused by writing the data in the beginning of shared memory. :oops:
Nightingale
 
Posts: 11
Joined: Fri Sep 19, 2014 11:38 am

Re: Using division inside cores crashes the program

Postby jeremybennett » Tue Oct 28, 2014 3:14 pm

User avatar
jeremybennett
 
Posts: 61
Joined: Mon Dec 17, 2012 9:06 am

Re: Using division inside cores crashes the program

Postby Nightingale » Wed Oct 29, 2014 1:03 pm

Follow up question:
It seems that the division problem is caused by writing a picture into shared memory with this code:
e_mem_t emem;
void* dst = 0x00000000;
if ( E_OK != e_alloc(&emem, dst, sz_sum) ) {
fprintf(stderr, "Failed to allocate shared memory. Error is %s\n",strerror(errno));
return EXIT_FAILURE;
}
for (int scale = 2; scale <= 5; scale++)
{
int sz = static_cast<int>(((512 / scale) + 1) * (512 / scale + 1) * 2);
e_write(&emem,0,0, (off_t) dst, sat[scale-1],sz * sizeof(float));
dst += sz * sizeof(float);
}

This executes properly, but division in cores stops working properly. The size of the picture (checked by printing dst) is 980320.
object dump on e_core program shows this:
Idx Name Size VMA LMA File off Algn
0 .sec1 00000004 00000000 00000000 0000002e 2**0
CONTENTS, ALLOC, LOAD
1 .sec2 00000060 00000028 00000028 00000046 2**0
CONTENTS, ALLOC, LOAD
2 .sec3 000009d2 00000090 00000090 00000186 2**0
CONTENTS, ALLOC, LOAD
3 .sec4 00000038 00000a64 00000a64 00001f0a 2**0
CONTENTS, ALLOC, LOAD
4 .sec5 00000068 00000aa0 00000aa0 00001fda 2**0
CONTENTS, ALLOC, LOAD
5 .sec6 00000696 8e000000 8e000000 0000211a 2**0
CONTENTS, ALLOC, LOAD

Am I correct to assume that the writing 9 megabytes of data into shared memory at the location 0 will overwrite the data that is at 8e000000? If so, how can avoid that?
Nightingale
 
Posts: 11
Joined: Fri Sep 19, 2014 11:38 am

Re: Using division inside cores crashes the program

Postby sebraa » Wed Oct 29, 2014 2:33 pm

In the default linker script, the first 16 MB of shared memory is used for the C library and helper functions. My guess is that you overwrote the division function located there. (The other cases, like division by powers-of-two might work because the compiler never actually calls that function, being able to optimize better.)

Try to use the shared memory from 0x8f000000 instead. This section (".shared_dram" in the linker scripts) is free to use (as long as you avoid malloc() and friends).
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Using division inside cores crashes the program

Postby Nightingale » Wed Oct 29, 2014 2:52 pm

Nightingale
 
Posts: 11
Joined: Fri Sep 19, 2014 11:38 am

Re: Using division inside cores crashes the program

Postby notzed » Wed Oct 29, 2014 10:30 pm

There's 32MB of shared memory, the value you pass to e_"alloc" is the offset into the shared memory. Just pass 16MB, i.e. 0x01000000 instead of 0.

In ezesdk it's a lot simpler and mostly automatic, but i don't support C++. I'm only showing this here in the hope that adapteva pull their finger out and improve the sdk beyond it's current primitive state (i'm unaware of what the apparently-imminent 'new sdk' will include, it may have addressed this already).

epiphany code:
float sat[MAX_SAT] EZ_SECTION(.bss.shared);

host code;
float *e_sat = ez_addr(wg, 0, 0, "_sat", NULL);

It also has a dynamic memory allocator if that is desirable (host-side control).
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Re: Using division inside cores crashes the program

Postby Nightingale » Thu Oct 30, 2014 8:03 am

Well, that was my first idea, but when I do that I get an error. Here is the host side code:
void* dst = 0x01000000;
array<float *, 5> sat;
//populate sat
size_t sz_sum = 980320;
e_mem_t emem;
if ( E_OK != e_alloc(&emem, dst, sz_sum) ) {
fprintf(stderr, "Failed to allocate shared memory. Error is %s\n",strerror(errno));
return EXIT_FAILURE;
}
for (int scale = 2; scale <= 5; scale++)
{
int sz = static_cast<int>(((512/ scale) + 1) * (512/ scale + 1) * 2);
e_write(&emem,0,0, (off_t) dst, sat[scale-1],sz * sizeof(float));
dst += sz * sizeof(float);
}

but when I run this code it prints "ee_mwrite_buf(): Buffer range is out of bounds" four times (when it tries to execute e_write). What am I doing wrong here?

P.S. what does this function actually do: ez_addr(wg, 0, 0, "_sat", NULL)?
Nightingale
 
Posts: 11
Joined: Fri Sep 19, 2014 11:38 am

Re: Using division inside cores crashes the program

Postby sebraa » Thu Oct 30, 2014 2:14 pm

sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Next

Return to Programming Q & A

Who is online

Users browsing this forum: No registered users and 10 guests

cron