Real parallel Hello-World

Hardware related problems and workarounds

Real parallel Hello-World

Postby formoon » Fri Sep 12, 2014 5:41 am

I'm a newbee to this forum, I'm from china.
I get my board last week, and try it 4 days.
I rewrite the Hello-World example to a Parallel version.
Because re compile sdk need download a lot of big dependent libraries, I use the old version that include in the my_backup.img of sd image. I think the big difference is this old version have no e_shm_alloc series function.

the code is here :
hello_world.c
Code: Select all
/*
  hello_world.c

  Copyright (C) 2012 Adapteva, Inc.
  Contributed by Yaniv Sapir <yaniv@adapteva.com>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program, see the file COPYING.  If not, see
  <http://www.gnu.org/licenses/>.
*/

// This is the HOST side of the Hello World example.
// The program initializes the Epiphany system,
// randomly draws an eCore and then loads and launches
// the device program on that eCore. It then reads the
// shared external memory buffer for the core's output
// message.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <e-hal.h>

#define _BufSize   (128)
#define _BufOffset (0x01000000)
//#define _SeqLen    (20)
int hexDump(unsigned char *bytes,int len)
{
   int i;
   printf("\n00000000: ");
   for(i=0;i<len;i++)
   {
//      if ((i % 16) == 0)
//         printf("\n%08X: ",i);
      printf("%02X ",bytes[i]);
      if (((i+1) % 16) == 0)
            printf("\n%08X: ",i+1);
   }
   printf("\n");
}

int main(int argc, char *argv[])
{
   unsigned row, col, coreid, i;
   unsigned rrow,rcol,ri;
   e_platform_t platform;
   e_epiphany_t dev;
   e_mem_t emem;
   char emsg[_BufSize*16];
   int _SeqLen;
   
   //srand(1);

   // initialize system, read platform params from
   // default HDF. Then, reset the platform and
   // get the actual system parameters.
   e_init(NULL);
   e_reset_system();
   e_get_platform_info(&platform);
   printf("System Matrix: %d * %d\n",platform.rows,platform.cols);
   _SeqLen=platform.rows*platform.cols;
   // Allocate a buffer in shared external memory
   // for message passing from eCore to host.
   e_alloc(&emem, _BufOffset, _BufSize*_SeqLen);
   e_open(&dev, 0, 0, platform.rows, platform.cols);

   // Open the single-core workgroup and reset the core, in
   // case a previous process is running. Note that we used
   // core coordinates relative to the workgroup.
   e_reset_group(&dev);

   // Load the device program onto the selected eCore
   // and launch after loading.
   e_load_group("e_hello_world.srec", &dev, 0, 0, platform.rows,platform.cols,E_TRUE);

   // Wait for core program execution to finish, then
   // read message from shared buffer.
//   e_load("e_hello_world.srec", &dev, 0,0,E_TRUE);
//   e_load("e_hello_world.srec", &dev, 1,1,E_TRUE);
//   e_load("e_hello_world.srec", &dev, 3,3,E_TRUE);
//   e_load("e_hello_world.srec", &dev, 2,2,E_TRUE);

   //usleep(10000);
   while(1)
   {
      usleep(100);
      e_read(&emem, 0, 0, 0x0, emsg, _BufSize*16);
      if (emsg[15*_BufSize]=='H')
         break;   //wait while last cpu computing finished.
   }
   //hexDump((unsigned char *)emsg,_BufSize*16);

   for (i=0; i<_SeqLen; i++)
   {
      // Draw a random core
      row = i / platform.rows;
      col = i % platform.rows;
      coreid = (row + platform.row) * 64 + col + platform.col;
//
//      rcol = coreid % 64 - platform.col;
//      rrow = coreid / 64 - platform.row;
//      ri=rcol+rrow*platform.rows;
//      fprintf(stderr, "[%3d %3d %3d] ",rrow,rcol,ri);

      fprintf(stderr, "%3d: Message from eCore 0x%03x (%2d,%2d): ", i, coreid, row, col);

      // Print the message and close the workgroup.
      fprintf(stderr, "\"%s\"\n", emsg+i*_BufSize);
   }
   e_close(&dev);

   // Release the allocated buffer and finalize the
   // e-platform connection.
   e_free(&emem);
   e_finalize();

   return 0;
}


e_hello_world.c
Code: Select all
/*
  e_hello_world.c

  Copyright (C) 2012 Adapteva, Inc.
  Contributed by Yaniv Sapir <yaniv@adapteva.com>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program, see the file COPYING.  If not, see
  <http://www.gnu.org/licenses/>.
*/

// This is the DEVICE side of the Hello World example.
// The host may load this program to any eCore. When
// launched, the program queries the CoreID and prints
// a message identifying itself to the shared external
// memory buffer.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "e_lib.h"

char outbuf[128*16] SECTION("shared_dram");

//void e_coords_from_coreid(e_coreid_t coreid, unsigned *row, unsigned *col);

int main(void) {
   e_coreid_t coreid;
   unsigned row,col,ri;
   
   // Who am I? Query the CoreID from hardware.
   coreid = e_get_coreid();
   e_coords_from_coreid(coreid,&row,&col);
   ri=col+row*e_group_config.group_rows;

   // The PRINTF family of functions do not fit
   // in the internal memory, so we link against
   // the FAST.LDF linker script, where these
   // functions are placed in external memory.
   sprintf(outbuf+128*ri, "Hello World from core 0x%03x! group[%3d %3d]", coreid,row,col);

   return EXIT_SUCCESS;
}


In this code, I use e_load_group to launch parallel sub code, I tried e_load for each core, but I think maybe only 1 shared memory defined, every time e_load will clear its data, so, only last core result can return to main program.
formoon
 
Posts: 8
Joined: Wed Sep 10, 2014 9:10 am

Re: Real parallel Hello-World

Postby sebraa » Fri Sep 12, 2014 1:20 pm

You can use "-R .shared_dram" in your e-objcopy command line, when you generate your SREC file. Then the upper 16 MB of shared memory will not be touched when you use e_load().
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm


Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 3 guests