void init() { // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); //me.row = me.row - E_FIRST_CORE_ROW; //me.col = me.col - E_FIRST_CORE_COL; me.corenum = me.row * e_group_config.group_cols + me.col; //me.corenum = me.row * E_COLS_IN_CHIP + me.col; //me.coreIDn = me.coreID; //e_neighbor_id((e_coreid_t *) &me.coreIDn, E_NEXT_CORE, E_CHIP_WRAP); // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); #if 0 Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer[0]); Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); #endif Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); // Init the ports init_input_port(&X); // Set the port pointer, the address must be global scale.X = (me.coreID << 20) | (int) &X; #ifdef FULL init_output_port(&Y); scale.Y = (me.coreID << 20) | (int) &Y; #endif scale.coreID = me.coreID; // Set the global actor pointer(don't forget to use global address) actors.scale = (me.coreID << 20) | (int) &scale; me.count = 0; // Coefficients W0[0] = 2048; W0[1] = 2676; W0[2] = 2841; W0[3] = 1609; W1[0] = 2048; W1[1] = 1108; W1[2] = 565; W1[3] = 2408; ww0 = W0[0]; ww1 = 2048; index0 = 0; // Init the host-accelerator sync signals Mailbox.pReady[me.corenum] = &me.mystate; return; }
void init(){ // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); me.row = me.row - E_FIRST_CORE_ROW; me.col = me.col - E_FIRST_CORE_COL; me.corenum = me.row * E_COLS_IN_CHIP + me.col; // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); #if 0 // ## For debugging ## Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer[0]); Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); #endif Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); me.count = 0; // Init the ports init_input_port(&X); init_output_port(&Y); // Set the port pointers of the actor struct final.X = (me.coreID << 20) | (int) &X;
int main(void) { const char ShmName[] = "hello_shm"; const char Msg[] = "Hello World from core 0x%03x!"; char buf[256] = { 0 }; e_coreid_t coreid; e_memseg_t emem; unsigned my_row; unsigned my_col; ///////////////////////////// trace_start_wait_all(); ///////////////////////////// // Who am I? Query the CoreID from hardware. coreid = e_get_coreid(); e_coords_from_coreid(coreid, &my_row, &my_col); if ( E_OK != e_shm_attach(&emem, ShmName) ) { return EXIT_FAILURE; } // Attach to the shm segment snprintf(buf, sizeof(buf), Msg, coreid); if ( emem.size >= strlen(buf) + 1 ) { // Write the message (including the null terminating // character) to shared memory e_write((void*)&emem, buf, my_row, my_col, NULL, strlen(buf) + 1); } else { // Shared memory region is too small for the message return EXIT_FAILURE; } return EXIT_SUCCESS; }
void init() { // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); me.row = me.row - E_FIRST_CORE_ROW; me.col = me.col - E_FIRST_CORE_COL; me.corenum = me.row * E_COLS_IN_CHIP + me.col; me.coreIDh = me.coreID; e_neighbor_id((e_coreid_t *) &me.coreIDh, E_PREV_CORE, E_ROW_WRAP); me.coreIDv = me.coreID; e_neighbor_id((e_coreid_t *) &me.coreIDv, E_PREV_CORE, E_COL_WRAP); me.coreIDn = me.coreID; e_neighbor_id((e_coreid_t *) &me.coreIDn, E_NEXT_CORE, E_CHIP_WRAP); // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) SHARED_DRAM; Mailbox.pA = Mailbox.pBase + offsetof(shared_buf_t, A[0]); Mailbox.pB = Mailbox.pBase + offsetof(shared_buf_t, B[0]); Mailbox.pC = Mailbox.pBase + offsetof(shared_buf_t, C[0]); Mailbox.pCore = Mailbox.pBase + offsetof(shared_buf_t, core); // Initialize per-core parameters - core data structure // Initialize pointers to the operand matrices ping-pong arrays me.bank[_BankA][_PING] = (void *) &(AA[0][0][0]); me.bank[_BankA][_PONG] = (void *) &(AA[1][0][0]); me.bank[_BankB][_PING] = (void *) &(BB[0][0][0]); me.bank[_BankB][_PONG] = (void *) &(BB[1][0][0]); me.bank[_BankC][_PING] = (void *) &(CC [0][0]); // Initialize the pointer addresses of the arrays in the horizontal and vertical target // cores, where the submatrices data will be swapped, and the inter-core sync signals. me.tgt_bk[_BankA][_PING] = _gptr(me.coreIDh, me.bank[_BankA][_PONG]); me.tgt_bk[_BankA][_PONG] = _gptr(me.coreIDh, me.bank[_BankA][_PING]); me.tgt_synch = _gptr(me.coreIDh, (&(me.synch))); me.tgt_bk[_BankB][_PING] = _gptr(me.coreIDv, me.bank[_BankB][_PONG]); me.tgt_bk[_BankB][_PONG] = _gptr(me.coreIDv, me.bank[_BankB][_PING]); me.tgt_syncv = _gptr(me.coreIDv, (&(me.syncv))); me.tgt_go_sync = _gptr(me.coreIDn, (&(me.go_sync))); me.tgt_dma_sync = _gptr(me.coreIDn, (&(me.dma_sync))); me.pingpong = _PING; // Clear the inter-core sync signals me.synch = 0; me.syncv = 0; me.go_sync = 0; me.dma_sync = (me.corenum == 0) ? 1 : 0; // Init the host-accelerator sync signals Mailbox.pCore->go[me.corenum] = 0; if (me.corenum == 0) Mailbox.pCore->ready = 1; me.count = 0; return; }
void init() { // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); //me.row = me.row - E_FIRST_CORE_ROW; //me.col = me.col - E_FIRST_CORE_COL; //me.corenum = me.row * E_COLS_IN_CHIP + me.col; me.corenum = me.row * e_group_config.group_cols + me.col; // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); #if 0 // ## For debugging ## Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer[0]); Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); #endif Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); // Init the ports init_input_port(&X); init_input_port(&Y); // Set the port pointer scale.X = (me.coreID << 20) | (int) &X; scale.Y = (me.coreID << 20) | (int) &Y; scale.coreID = me.coreID; // Set the global actor pointer actors.scaleCol = (me.coreID << 20) | (int) &scale; me.count = 0; // Coefficients W0[0] = 2048; W0[1] = 2676; W0[2] = 2841; W0[3] = 1609; W1[0] = 2048; W1[1] = 1108; W1[2] = 565; W1[3] = 2408; ww0 = W0[0]; ww1 = 2048; index0 = 0; // Init the host-accelerator sync signals Mailbox.pReady[me.corenum] = 1; return; }
int main(int argc, char *argv[]) { e_coreid_t core_id = e_get_coreid(); int row, col; e_coords_from_coreid(core_id, &row, &col); e_write(&e_group_config, &core_id, row, col, (int*) 0x2000, sizeof(int)); return 0; }
int main(void) { e_coreid_t coreid; unsigned row, col, i; coreid = e_get_coreid(); e_coords_from_coreid(coreid, &row, &col); printf("Core id: %x row=%u col=%u\n", (unsigned)coreid, row, col); return 0; }
int main(void) { e_coreid_t coreid = e_get_coreid(); unsigned int row, col; e_coords_from_coreid(coreid, &row, &col); //volatile Mailbox* mailbox = (Mailbox*)e_emem_config.base; mailbox->sync[row][col] = 1; //(int)(row * 10 + col); return 0; }
void init(){ // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); me.row = me.row - E_FIRST_CORE_ROW; me.col = me.col - E_FIRST_CORE_COL; me.corenum = me.row * E_COLS_IN_CHIP + me.col; // corenum 12 is empty because of our structure // hence this core gets num 13 but it should be 12 me.corenum--; // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); Mailbox.pSignedBuffer = Mailbox.pBase + offsetof(mbox_t, signed_buffer[0]); Mailbox.pSignedBufferSize = Mailbox.pBase + offsetof(mbox_t, signed_buffer_size); Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer[0]); Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); me.count = 0; // Init the global variables clip.count = -1; clip.coreID = me.coreID; // Init the ports //init_input_port(&SIGNED); init_input_port(&I); //init_output_port(&O); // Set the port pointers of the actor struct //clip.SIGNED = &SIGNED; clip.I = (me.coreID << 20) | (int) &I; //clip.O = &O; // Set the global actor pointer actors.clip = (me.coreID << 20) | (int) &clip; // Init the host-accelerator sync signals // Let the host know that we are ready (for sync) Mailbox.pReady[me.corenum] = 3; }
void init() { unsigned next_row, next_col; // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); me.corenum = me.row * e_group_config.group_cols + me.col; //e_neighbor_id(E_NEXT_CORE, E_GROUP_WRAP, &next_row, &next_col); //me.coreIDn = next_row * e_group_config.group_cols + next_col; ////e_neighbor_id(E_NEXT_CORE, E_GROUP_WRAP, (e_coreid_t *) &me.coreIDn); // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS;//(void*) SHARED_DRAM; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); Mailbox.pInBuffer = Mailbox.pBase + offsetof(mbox_t, in_buffer[0]); Mailbox.pInBufferSize = Mailbox.pBase + offsetof(mbox_t, in_buffer_size); Mailbox.pConnectActors = Mailbox.pBase + offsetof(mbox_t, connectActors); #if 0 // Debug Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer); #endif Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); // initialize the port init_output_port(&Y); // Set the port pointer rowSort.Y = (me.coreID << 20) | (int) &Y; rowSort.coreID = me.coreID; // Set the global actor pointer actors.rowSort = (me.coreID << 20) | (int) &rowSort; // Init the host-accelerator sync signals Mailbox.pReady[me.corenum] = &me.mystate; return; }
void init(){ // Init core enumerations me.coreID = e_get_coreid(); e_coords_from_coreid(me.coreID, &me.row, &me.col); me.row = me.row - E_FIRST_CORE_ROW; me.col = me.col - E_FIRST_CORE_COL; me.corenum = me.row * E_COLS_IN_CHIP + me.col; // Initialize the mailbox shared buffer pointers Mailbox.pBase = (void *) MAILBOX_ADDRESS; Mailbox.pGo = Mailbox.pBase + offsetof(mbox_t, go[0]); Mailbox.pReady = Mailbox.pBase + offsetof(mbox_t, ready[0]); Mailbox.pClocks = Mailbox.pBase + offsetof(mbox_t, clocks); #if 0 // ## For debugging ## Mailbox.pOutputBuffer = Mailbox.pBase + offsetof(mbox_t, output_buffer[0]); Mailbox.pOutputReady = Mailbox.pBase + offsetof(mbox_t, output_ready); #endif Mailbox.pTimer0 = Mailbox.pBase + offsetof(mbox_t, timer0); Mailbox.pTimer1 = Mailbox.pBase + offsetof(mbox_t, timer1); me.count = 0; // Init the ports init_input_port(&X); init_output_port(&Y); // Set the port pointers of the actor struct shuffle.X = (me.coreID << 20) | (int) &X; shuffle.Y = (me.coreID << 20) | (int) &Y; shuffle.coreID = me.coreID; // Set the global actor pointer actors.shuffleRow = (me.coreID << 20) | (int) &shuffle; // Init the host-accelerator sync signals // Let the host know that we are ready (for sync) Mailbox.pGo[me.corenum] = 0; Mailbox.pReady[me.corenum] = me.corenum; }
/* This function calculates the coreid of the neighboring core, where neighbor can be the next core to north, east, south, or west. It will always calculate the id of another core on the same chip, wrapping on a row, column, or chip boundary as specified by the wrap argument. The return value is the difference between the neighboring coreid and the current one. */ int e_neighbor_id(e_coreid_t *coreid, e_coreid_wrap_t dir, e_coreid_wrap_t wrap) { unsigned row, col; e_coreid_t next; int diff; unsigned chip_mask; /* Indexed by [wrap][dir] */ static const int core_adjust_table[3][2] = { { 1, -1 }, /* CHIP_WRAP */ { 1, -1 }, /* ROW_WRAP */ { 64, -64 } /* COL_WRAP */ }; chip_mask = *coreid & ~INTERNAL_CORE_MASK; next = ((*coreid + core_adjust_table[wrap][dir]) & INTERNAL_CORE_MASK) | chip_mask; if (wrap == E_CHIP_WRAP) { e_coords_from_coreid(next, &row, &col); if (dir == E_NEXT_CORE) { /* if we wrapped back to the first column, we need to advance to the next row. */ /* if (col == e_get_chip_min_col(next)) */ if (col == CHIP_MIN_COL(next)) { next = ((next + 0x40) & INTERNAL_CORE_MASK) | chip_mask; } } else /* dir == E_PREV_CORE */ { /* if we wrapped to the last column, we need to advance to the previous row. */ /* if (col == e_get_chip_max_col(next)) */ if (col == CHIP_MAX_COL(next)) { next = ((next - 0x40) & INTERNAL_CORE_MASK) | chip_mask; } } } diff = next - *coreid; *coreid = next; return diff; }
int main(void) { e_coreid_t id = e_get_coreid(); unsigned row, col; unsigned long number; // Get the row, column coordinates of this core e_coords_from_coreid(id, &row, &col); // Assign the starting value for each core (3,5,7,..33) // Each core starts with a unique odd number (2 is the only even prime number) number = 2 + ((2*row*4) + (2*col+1)); // Initialize this core number starting with (*num) = number; // Initialize this core iteration count for stats (*count) = 0; // Initialize the number of found primes counter (*primes) = 0; // while(*count < *max_tests) while(number < *max_tests) { if(is_prime(number)) (*primes)++; // Skip to the next odd number for this core to test, assuming total of 16 cores // Core (0,0) started with 3 on the first iteration, and next test 35 // Core (0,1) started with 5 on the first iteration, and next test 37 // etc number += (2*16); *num = number; (*count)++; } return EXIT_SUCCESS; }
int main () { e_coreid_t coreid; unsigned int row, col, core, trow, tcol, *ec; volatile msg_block_t *msg = (msg_block_t *) BUF_ADDRESS; e_ctimer_set(E_CTIMER_0, 0xffffffff); e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK); ec = (unsigned int *) 0x4000; *ec = 0; coreid = e_get_coreid(); e_coords_from_coreid(coreid, &row, &col); core = row*e_group_config.group_cols + col; srand(msg->shared_msg[core].seed); msg->shared_msg[core].seed = msg->shared_msg[core].seed + 10; trow = ((core + 1) % E_GROUP_CORES) / e_group_config.group_rows; tcol = (core + 1) % e_group_config.group_cols; ec = e_get_global_address(trow, tcol, ec); e_write(&e_group_config, &coreid, 0, 0, ec, sizeof(e_coreid_t)); /**ec = coreid;*/ msg->shared_msg[core].msg = e_coreid_from_coords(trow, tcol); msg->shared_msg[core].external = *(unsigned int *) 0x4000; /* Sync */ e_wait(E_CTIMER_1, 2000); msg->shared_msg[core].timer = 0xffffffff - e_ctimer_get(E_CTIMER_0); msg->shared_msg[core].coreid = coreid; e_ctimer_stop(E_CTIMER_0); return 0; }
int task_main(int argc, const char *argv[]) { e_coreid_t coreid; unsigned row, col; int wg_rows, wg_cols, my_row, my_col; coreid = e_get_coreid(); e_coords_from_coreid (coreid, &row, &col); x_get_task_environment (&wg_rows, &wg_cols, &my_row, &my_col); x_set_task_status ("Hello from core 0x%03x (%d,%d) taskpos %d %d in %d %d", coreid, col, row, my_col, my_row, wg_cols, wg_rows); if (row == 1 && col == 1) { sync_send_test(X_TO_LEFT); } else if (row == 1 && col == 0) { sync_receive_test(X_FROM_RIGHT); } else { x_sleep(30); x_set_task_status ("Goodbye from core 0x%03x (%d,%d) pid %d", coreid, col, row, my_col, my_row); } return X_SUCCESSFUL_TASK; }
int main(int argc, char **argv) { size_t shm_size = 1024; (void) shm_size; char tmp[17]; unsigned my_row; unsigned my_col; e_coreid_t coreid; coreid = e_get_coreid(); e_coords_from_coreid(coreid, &my_row, &my_col); /* <BARELOG_OVERLOAD> */ barelog_mem_space_t mem_space = { .phy_base = (void *) 0x8f000000, .length = 0x01000000, .alignment = 1, .word_size = 4, .data = 0 }; barelog_platform_t platform = { .name = "PARALLELLA", .mem_space = mem_space, }; barelog_policy_t policy = REPLACE; barelog_init_logger(my_row * 4 + my_col, platform, policy, policy, my_read, my_write, get_clock, init_clock, start_clock); /* </BARELOG_OVERLOAD> */ sync(); barelog_start(); uint32_t clock00 = get_clock(); barelog_log(BARELOG_CRITICAL_LVL, "Program starts at %u.", clock00); uint32_t clock01 = get_clock(); (void) clock01; char buff[50] = {0}; barelog_log(BARELOG_INFO_LVL, "e_read begins."); barelog_flush(2); barelog_clean(2); e_read(&e_emem_config, tmp, 0, 0, (void *)(0x8f000000+BARELOG_SHARED_MEM_MAX), 17); barelog_log(BARELOG_INFO_LVL, "e_read ends.%u", get_clock()); uint32_t clock1 = get_clock(); (void) clock1; // Uncomment to test the fulfillment of the events buffer. /*for (uint8_t k = 0; k < 1; ++k) { for (uint8_t i = 0; i < 200; ++i) { barelog_log("Test %u %u %u", get_clock(), k, i); barelog_flush_buffer(); barelog_clean_buffer(); __asm__ __volatile__ ("nop"); } __asm__ __volatile__ ("nop"); }*/ uint32_t clock2 = get_clock(); (void) clock2; // Uncomment to access various clocks data. /* barelog_log("Results %u %u %u %u", clock00, clock01, clock1, clock2); if (barelog_flush_buffer() != BARELOG_SUCCESS) { exit(EXIT_FAILURE); } barelog_clean_buffer(); */ snprintf(buff, 50, "%s from core %u", tmp, (my_row*4 + my_col)); barelog_log(BARELOG_DEBUG_LVL, "e_write begins."); barelog_flush(1); barelog_clean(1); e_write((void*) &e_emem_config, buff, 0, 0, (void *)(0x8f000000+BARELOG_SHARED_MEM_MAX + (my_row*4+my_col)*50), 50); barelog_immediate_log(BARELOG_DEBUG_LVL, "e_write ends."); barelog_log(BARELOG_CRITICAL_LVL, "Program ends at %u", get_clock()); barelog_flush(6); // Voluntary flushing too many events to check everything went well. exit(EXIT_SUCCESS); }