Skip to content

Commit

Permalink
Merge pull request #37 from futurecore/zigzag
Browse files Browse the repository at this point in the history
Adapteva zigzag tests now working
  • Loading branch information
snim2 committed Jul 31, 2016
2 parents 0a5d8c8 + 7850719 commit a4dea0d
Show file tree
Hide file tree
Showing 18 changed files with 1,019 additions and 43 deletions.
35 changes: 18 additions & 17 deletions revelation/elf_loader.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
from revelation.storage import is_local_address

from pydgin.elf import elf_reader
from pydgin.utils import intmask


def load_program(fp, mem, alignment=0, is_64bit=False,
coreid=0x808, ext_base=0x8e000000, ext_size=32):
"""Load an ELF file into an individual core.
def load_program(elf, mem, coreids, alignment=0, ext_base=0x8e000000,
ext_size=32):
"""Copy the contents of an ELF file into individual cores.
The 'elf' argument should be the result of a call to
pydgin.elf.elf_reader().
"""
elf = elf_reader(fp, is_64bit=is_64bit)
sections = elf.get_sections()
entrypoint = -1
coreid_mask = coreid << 20
for section in sections:
if is_local_address(section.addr):
start_addr = coreid_mask | section.addr
else:
start_addr = section.addr
for index, data in enumerate(section.data):
mem.write(start_addr + index, 1, ord(data), quiet=True)
if section.name == '.text':
entrypoint = intmask(section.addr)
if section.name == '.data':
mem.data_section = section.addr
for coreid in coreids:
coreid_mask = coreid << 20
for section in sections:
if is_local_address(section.addr):
start_addr = coreid_mask | section.addr
else:
start_addr = section.addr
for index, data in enumerate(section.data):
mem.write(start_addr + index, 1, ord(data), quiet=True)
if section.name == '.text':
entrypoint = intmask(section.addr)
if section.name == '.data':
mem.data_section = section.addr
assert entrypoint >= 0
return
34 changes: 22 additions & 12 deletions revelation/sim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydgin.debug import Debug, pad, pad_hex
from pydgin.elf import elf_reader
from pydgin.jit import elidable, hint, JitDriver, set_param, set_user_param
from pydgin.misc import FatalError
from pydgin.sim import Sim, init_sim
Expand All @@ -10,6 +11,7 @@
from revelation.logger import Logger
from revelation.machine import State
from revelation.storage import Memory
from revelation.utils import get_coords_from_coreid, get_coreid_from_coords, zfill

import time

Expand Down Expand Up @@ -265,9 +267,10 @@ def run(self):
end_time = time.time()
print 'Done! Total ticks simulated = %d' % tick_counter
for state in self.states:
print ('Core %s (%d, %d): STATUS=%s, Instructions executed=%d' %
(hex(state.coreid), state.coreid >> 6, state.coreid & 0x7f,
hex(state.rf[reg_map['STATUS']]), state.num_insts))
row, col = get_coords_from_coreid(state.coreid)
print ('Core %s (%s, %s): STATUS=0x%s, Instructions executed=%d' %
(hex(state.coreid), zfill(str(row), 2), zfill(str(col), 2),
pad_hex(state.rf[reg_map['STATUS']]), state.num_insts))
if self.collect_times:
print 'Total execution time: %fs' % (end_time - start_time)
if self.logger:
Expand Down Expand Up @@ -298,15 +301,22 @@ def init_state(self, elf_file, filename, testbin, is_test=False):
timer = time.time()
print 'Memory creation took: %fs' % (timer - self.timer)
self.timer = timer
for ncore in xrange(self.rows * self.cols):
coreid = self.first_core + ncore
print 'Loading program %s on to core %s' % (filename, hex(coreid))
elf_file.seek(0) # Start loading from beginning of ELF.
load_program(elf_file, self.memory, coreid=coreid,
ext_base=self.ext_base, ext_size=self.ext_size)
self.hardware_loops.append(False)
self.states.append(State(self.memory, self.debug,
logger=self.logger, coreid=coreid))
f_row= (self.first_core >> 6) & 0x3f
f_col = self.first_core & 0x3f
elf = elf_reader(elf_file, is_64bit=False)
coreids = []
for row in xrange(self.rows):
for col in xrange(self.cols):
coreid = get_coreid_from_coords(f_row + row, f_col + col)
coreids.append(coreid)
print ('Loading program %s on to core %s (%s, %s)' %
(filename, hex(coreid), zfill(str(f_row + row), 2),
zfill(str(f_col + col), 2)))
self.hardware_loops.append(False)
self.states.append(State(self.memory, self.debug,
logger=self.logger, coreid=coreid))
load_program(elf, self.memory, coreids, ext_base=self.ext_base,
ext_size=self.ext_size)
if self.profile:
timer = time.time()
print 'ELF file loader took: %fs' % (timer - self.timer)
Expand Down
2 changes: 1 addition & 1 deletion revelation/test/test_compiled_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_compiled_c_with_output(elf_file, expected, capfd):
assert not revelation.states[0].running
out, err = capfd.readouterr()
assert err == ''
expected_full = (('Loading program %s on to core 0x808\n' % elf_filename)
expected_full = (('Loading program %s on to core 0x808 (32, 08)\n' % elf_filename)
+ expected)
assert out.startswith(expected_full)

Expand Down
4 changes: 2 additions & 2 deletions revelation/test/test_multicore.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_two_cores_with_output(elf_file, expected, capfd):
assert not revelation.states[1].running
out, err = capfd.readouterr()
assert err == ''
expected_full = (('Loading program %s on to core 0x808\n'
'Loading program %s on to core 0x809\n'
expected_full = (('Loading program %s on to core 0x808 (32, 08)\n'
'Loading program %s on to core 0x809 (32, 09)\n'
% (elf_filename, elf_filename)) + expected)
assert out.startswith(expected_full)
2 changes: 1 addition & 1 deletion revelation/test/test_syscall_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def test_open_close_syscall_layout(capfd):
assert err == ''
expected = ('open() successful.\nRead: 14 bytes.\nHello, world!\n'
'Read: 0 bytes.\nclose() successful.\n')
expected_full = (('Loading program %s on to core 0x808\n' % elf_filename)
expected_full = (('Loading program %s on to core 0x808 (32, 08)\n' % elf_filename)
+ expected)
assert out.startswith(expected_full)
19 changes: 9 additions & 10 deletions revelation/test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from revelation.utils import (get_exponent,
get_mantissa,
bits2float,
float2bits,
is_nan,
is_inf,
is_zero,
sext_3,
sext_11,
sext_24)
from revelation.utils import (get_exponent, get_mantissa, bits2float,
float2bits, is_nan, is_inf, is_zero, sext_3, sext_11, sext_24, zfill)

import math


def test_zfill():
assert '000001' == zfill('1', 6)
assert '+00001' == zfill('+1', 6)
assert '-00001' == zfill('-1', 6)


def test_sign_extend_3bit():
assert sext_3(0b011) == 0b011
assert sext_3(0b111) == 0xffffffff
Expand Down
27 changes: 27 additions & 0 deletions revelation/test/zigzag/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
LDF = ${EPIPHANY_HOME}/bsps/current/fast.ldf

CC = e-gcc
CFLAGS = -g -O0 -Wall -Wno-unused -Werror -ffast-math -falign-functions=8
EXTRA_CFLAGS =

LDFLAGS = -T$(LDF)
LDLIBS = -le-lib

ELFS := zigzag2.elf zigzag4.elf zigzag16.elf zigzag64.elf zigzag120.elf zigzag768.elf zigzag4095.elf

zigzag2.elf: EXTRA_CFLAGS := -DROWS=2 -DCOLS=1 -DFIRST_CORE=0x808
zigzag4.elf: EXTRA_CFLAGS := -DROWS=2 -DCOLS=2 -DFIRST_CORE=0x808
zigzag16.elf: EXTRA_CFLAGS := -DROWS=4 -DCOLS=4 -DFIRST_CORE=0x808
zigzag64.elf: EXTRA_CFLAGS := -DROWS=8 -DCOLS=8 -DFIRST_CORE=0x808
zigzag120.elf: EXTRA_CFLAGS := -DROWS=15 -DCOLS=8 -DFIRST_CORE=0x808
zigzag768.elf: EXTRA_CFLAGS := -DROWS=32 -DCOLS=24 -DFIRST_CORE=0x808
zigzag4095.elf: EXTRA_CFLAGS := -DROWS=64 -DCOLS=64 -DFIRST_CORE=0
zigzag4095.elf: LDFLAGS := -T./extraminternal.ldf

all: ${ELFS}

%.elf: zigzag.c
${CC} -o $@ ${EXTRA_CFLAGS} ${CFLAGS} $< ${LDLIBS} -Wl,${LDFLAGS}

clean:
rm -f ${ELFS}
Loading

0 comments on commit a4dea0d

Please sign in to comment.