How to implement MIMD program & memory access

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

How to implement MIMD program & memory access

Postby elysium5290 » Mon Nov 02, 2015 11:48 am

Hi all,
I am not sure about this topic post here is right.

I am newer in programming used epiphany sdk, so maybe I would have some stupid questions.

First, I use an simple example to explain my questions.

I try to do 4x4 Matrix add. A + B = C ((reference the epiphany-examples/apps/dotproduct

Here is code.

host.c
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<e-hal.h>


int main(){

        int i,j;
        e_platform_t platform;
        e_epiphany_t dev;

        int A[4][4] = { {0,1,2,3},
                        {4,5,6,7},
                        {8,9,10,11},
                        {12,13,14,15} };

        int B[4][4] = { {15,14,13,12},
                        {11,10,9,8},
                        {7,6,5,4},
                        {3,2,1,0} };

        int C[4][4]={0};
       
        int all_done=0;
        int done[16];
        unsigned clr = 0;

        e_init(NULL);

        e_reset_system();
        e_get_platform_info(&platform);
        e_open(&dev,0,0,platform.rows,platform.cols);

        /*write data to e-core*/
        for(i=0;i<platform.rows;i++)
        {
                for(j=0;j<platform.cols;j++)
                {
                        e_write(&dev,i,j,0x2000,&A[i][j],sizeof(int));
                        e_write(&dev,i,j,0x2004,&B[i][j],sizeof(int));
                        e_write(&dev,i,j,0x200c,&clr,sizeof(clr));
                }
        }


        e_load_group("e_task.srec", &dev, 0 , 0 , platform.rows, platform.cols , E_TRUE);

       /*check all core is done*/
        while(1)
        {
                all_done=0;
                for(i=0;i<platform.rows;i++)
                {
                        for(j=0;j<platform.cols;j++)
                        {
                                e_read(&dev,i,j,0x200c,&done[i*platform.cols+j],sizeof(clr));
                                all_done+=done[i*platform.cols+j];
                        }
                }
                if(all_done==16)
                {
                        break;
                }
        }

       /*get core data to C Matrix*/
        for(i=0; i<platform.rows;i++)
        {
                for(j=0;j<platform.cols;j++)
                {
                        e_read(&dev,i,j,0x2008,&C[i][j],sizeof(int));
                        printf("C[%d][%d] = %d\n",i,j,C[i][j]);
                }
        }

        e_close(&dev);
        e_finalize();

        return 0;
}


e_task.c
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include"e-lib.h"

int main()
{

        unsigned *a,*b,*c,*d;
       
        a = (unsigned *) 0x2000;        //A[][]
        b = (unsigned *) 0x2004;        //B[][]
        c = (unsigned *) 0x2008;        //result[][]
        d = (unsigned *) 0x200c;        //done flag
         
        (*(c)) =*a + *b;
        *d=1;

        __asm__ __volatile__("idle");
}



It's output will be
Code: Select all
C[0][0] = 15
C[0][1] = 15
C[0][2] = 15
C[0][3] = 15
C[1][0] = 15
C[1][1] = 15
C[1][2] = 15
C[1][3] = 15
C[2][0] = 15
C[2][1] = 15
C[2][2] = 15
C[2][3] = 15
C[3][0] = 15
C[3][1] = 15
C[3][2] = 15
C[3][3] = 15


OK, now I have some questions.
First:

I find this in the epiphany_sdk_ref.pdf

Code: Select all
ssize_t e_read(void *dev, unsigned row, unsigned col, off_t from_addr, void *buf, size_t size);


the off_t from_addr

why this can't set 0x0000?

Second:

this program seems is SIMD, all cores to add local data.
I want to implement MIMD progran . How should I do like core(0,0) do sub , core (0,1) do multiplicate .... simultaneously

I had an idea like this : (I am not sure . if it's wrong, please correct me)

Code: Select all
e_open(&dev,0,0,1,1);
e_load_group("e_task_sub.srec", &dev, 0 , 0 ,1, 1 , E_TRUE);

e_open(&dev,0,1,1,1);
e_load_group("e_task_multiplicate.srec", &dev, 0 , 10 ,1, 1 , E_TRUE);


Third:

I think e_write() and e_read() is host to read/write e-core local memory.
How about communication between e-core and e-core.

if core(0,0) want to access data from core (1,0) like this : (I am not sure . if it's wrong, please correct me)
Code: Select all
In core(0,0)_task.c

int C;
e_epiphany_t dev;
e_read(&dev,1,0,0x2008,&C,sizeof(int));




thanks all

Eric
elysium5290
 
Posts: 8
Joined: Sat Mar 28, 2015 7:12 am

Re: How to implement MIMD program & memory access

Postby sebraa » Tue Nov 03, 2015 4:04 pm

elysium5290 wrote:I find this in the epiphany_sdk_ref.pdf
Code: Select all
ssize_t e_read(void *dev, unsigned row, unsigned col, off_t from_addr, void *buf, size_t size);

the off_t from_addr why this can't set 0x0000?


Either, you pass e_read() a device (off_t is relative to the core's memory) or an emem (off_t is relative to your shared memory allocation). In the first case, using 0x0000 (or any really small number) would overwrite the interrupt vector table of that core, which is probably not what you want to do.

elysium5290 wrote:this program seems is SIMD, all cores to add local data.
I want to implement MIMD progran . How should I do like core(0,0) do sub , core (0,1) do multiplicate .... simultaneously
I think you are missing the point: The Epiphany consists of 16 processors independent processors. Applications are always MIMD, even when they all run the same code.

You can run different programs in the same workgroup. Example:
Code: Select all
e_open(&dev, 0, 0, 4, 4);
e_load("core0.srec", &dev, 0, 0, E_TRUE);
e_load("core1.srec", &dev, 0, 1, E_TRUE);
/* ... */


elysium5290 wrote:I think e_write() and e_read() is host to read/write e-core local memory.
How about communication between e-core and e-core.
In Epiphany code, e_read()/e_write() do not exist. You can just create a pointer and access that. Some helper functions (e.g. e_coords_from_coreid(), e_get_global_address(), ...) help you do this. Note that accesses to other cores (or shared memory) are not coherent.
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm


Return to Programming Q & A

Who is online

Users browsing this forum: No registered users and 7 guests

cron