From 5c6b254e8b3f8c0104ffb5ef6c1e800f5ee04323 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Dec 2013 23:14:43 +0100 Subject: [PATCH] dol: add support for iterated ports and processes --- .../dol/visitor/epiphany/EpiphanyVisitor.java | 60 ++++++++++++++++--- .../dol/visitor/epiphany/template/Makefile | 27 +++++---- .../epiphany/template/process_Wrapper.c | 2 +- 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/dol/src/dol/visitor/epiphany/EpiphanyVisitor.java b/dol/src/dol/visitor/epiphany/EpiphanyVisitor.java index 5a053ca..7564796 100644 --- a/dol/src/dol/visitor/epiphany/EpiphanyVisitor.java +++ b/dol/src/dol/visitor/epiphany/EpiphanyVisitor.java @@ -97,9 +97,9 @@ public class EpiphanyVisitor extends PNVisitor { // dst.getBasename().equals(_epiphanyHostName)) { /* this is an SHM buffer */ System.out.println("\tBuffer: " + - src.getBasename() + ":" + srcP.getBasename() + + src.getName() + ":" + srcP.getName() + " ==> " + - dst.getBasename() + ":" + dstP.getBasename() + + dst.getName() + ":" + dstP.getName() + " (size " + ch.getSize() + ")" + " as SHM:" + _numShmBufs); @@ -194,11 +194,11 @@ public class EpiphanyVisitor extends PNVisitor { private void createProcessWrapper(Process p) throws Exception { System.out.println("\tcreateProcessWrapper(): " + - p.getBasename()); + p.getName()); /* copy template file */ String filename = _packageName + _delimiter + "esrc" + - _delimiter + p.getBasename() + "_Wrapper.c"; + _delimiter + p.getName() + "_Wrapper.c"; String template = _ui.getMySystemCLib() + _delimiter + "process_Wrapper.c"; template = template.replaceAll("systemC", "epiphany"); @@ -208,6 +208,34 @@ public class EpiphanyVisitor extends PNVisitor { File fTemplate = new File(template); copyFile(fTemplate, fFilename); + /* handle this process' iterators */ + String instance = ""; + Vector indices = p.getIteratorIndices(); + switch(indices.size()) { + case 0: instance = + "0,0,0,0"; break; + case 1: instance = + indices.elementAt(0) + + ",0,0,0"; break; + case 2: instance = + indices.elementAt(0) + + indices.elementAt(1) + + ",0,0"; break; + case 3: instance = + indices.elementAt(0) + + "," + indices.elementAt(1) + + "," + indices.elementAt(2) + + ",0"; break; + case 4: instance = + indices.elementAt(0) + + "," + indices.elementAt(1) + + "," + indices.elementAt(2) + + "," + indices.elementAt(3); break; + default: + throw new Exception("Unsupported iterator dimension"); + } + + /* handle this process' ports */ Integer portNum = 0; String portMapping = ""; @@ -216,7 +244,7 @@ public class EpiphanyVisitor extends PNVisitor { EpiphanyBuffer buf = getBuffer(p, port); /* port mapping */ - portMapping += "\t{ \"" + port.getBasename() + "\", size_" + portNum + ", level_" + portNum + ", "; + portMapping += "\t{ \"" + port.getName() + "\", size_" + portNum + ", level_" + portNum + ", "; portMapping += port.isInPort() ? "read_" + portNum + ", " : "NULL, "; portMapping += port.isOutPort() ? "write_" + portNum + ", " : "NULL, "; portMapping += "},\n"; @@ -244,6 +272,7 @@ public class EpiphanyVisitor extends PNVisitor { /* replace information */ Sed sed = new Sed(); sed.sed(filename, "@@PROCESSNAME@@", p.getBasename()); + sed.sed(filename, "@@INSTANCE@@", instance); sed.sed(filename, "@@NUM_PORTS@@", portNum.toString()); sed.sed(filename, "@@PORTMAPPING@@", portMapping); sed.sed(filename, "@@PORTFUNCTIONS@@", portFunctions); @@ -309,6 +338,7 @@ public class EpiphanyVisitor extends PNVisitor { String srecFiles = ""; Integer srecNum = 0; for(Process p : pn.getProcessList()) { + /* TODO: fix _epiphanyHostName */ if(!_epiphanyHostName.equals(p.getBasename())) { srecFiles += "\t\"bin/" + p.getBasename() + ".srec\",\n"; srecNum++; @@ -354,15 +384,31 @@ public class EpiphanyVisitor extends PNVisitor { /* generate srec filenames */ String srecFiles = ""; for(Process p : pn.getProcessList()) { + /* TODO: fix _epiphanyHostName */ if(!_epiphanyHostName.equals(p.getBasename())) { srecFiles += "\\$(DEST)/" + - p.getBasename() + ".srec "; + p.getName() + ".srec "; } } + /* generate .elf rules, because wrapper file names are + non-obvious with iterated processes... */ + String elfRules = ""; + for(Process p : pn.getProcessList()) { + elfRules += + "\\$(EDEST)/" + p.getName() + ".elf: " + + "\\$(EDEST)/" + p.getBasename() + ".o " + + "\\$(EDEST)/" + p.getName() + "_Wrapper.o " + + "\\$(ECOMMON)\n"; + elfRules += + "\t@\\$(ECHO) \"\\\\t(EPIPHANY) LINK\\\\t\\\\t\\$@\"\n" + + "\t@\\$(CC) -o \\$@ \\$^ \\$(LFLAGS)\n\n"; + } + /* do the replace */ Sed sed = new Sed(); - sed.sed(filename, "@@SREC_FILES@@", srecFiles); + sed.sed(filename, "@@SREC_FILES@@", srecFiles); + sed.sed(filename, "@@ELF_RULES@@", elfRules); System.out.println("done!"); } } diff --git a/dol/src/dol/visitor/epiphany/template/Makefile b/dol/src/dol/visitor/epiphany/template/Makefile index 90cc3bf..bfafbde 100644 --- a/dol/src/dol/visitor/epiphany/template/Makefile +++ b/dol/src/dol/visitor/epiphany/template/Makefile @@ -18,7 +18,6 @@ HOBJS = $(HDEST)/main.o # Epiphany applications and common objects EPAPPS = @@SREC_FILES@@ -EWRAPPERS = $(patsubst $(DEST)%,$(EDEST)%,$(EPAPPS:.srec=_Wrapper.o)) ECOMMON = $(EDEST)/dol.o $(EDEST)/ports.o $(EDEST)/index.o # Epiphany build flags @@ -33,48 +32,50 @@ HOSTCC = gcc HCFLAGS = -O2 -std=c99 -I$(EPIPHANY_HOME)/tools/host/include -Wall HLFLAGS = -L$(EPIPHANY_HOME)/tools/host/lib -le-hal -# Global rules +# =========================================================================== +ECHO = /bin/echo -e .SECONDARY: .PHONY: all run host cores clean all: run host: $(HOSTAPP) -cores: $(ECOMMON) $(EWRAPPERS) $(EPAPPS) +cores: $(ECOMMON) $(EPAPPS) run: host cores - @echo -e "\tRUN" + @$(ECHO) "\tRUN" @sudo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) \ EPIPHANY_HDF=$(EPIPHANY_HDF) \ $(HOSTAPP) clean: - @echo -e "\tCLEAN" + @$(ECHO) "\tCLEAN" @rm -v -f $(HOSTAPP) $(EPAPPS) $(EDEST)/* $(HDEST)/* # Host rules $(HOSTAPP): $(HOBJS) - @echo -e "\t(HOST) LINK\t$@" + @$(ECHO) "\t(HOST) LINK\t$@" @$(HOSTCC) -o $@ $^ $(HLFLAGS) $(HDEST)/%.o: $(HSRC)/%.c - @echo -e "\t(HOST) CC\t$@" + @$(ECHO) "\t(HOST) CC\t$@" @$(HOSTCC) $(HCFLAGS) -c -o $@ $^ # Epiphany rules $(DEST)/%.srec: $(EDEST)/%.elf - @echo -e "\t(EPIPHANY) OBJCOPY $@" + @$(ECHO) "\t(EPIPHANY) OBJCOPY\t$@" @$(OBJCOPY) $(OCFLAGS) --output-target srec --srec-forceS3 $^ $@ -$(EDEST)/%.elf: $(EDEST)/%.o $(EDEST)/%_Wrapper.o $(ECOMMON) - @echo -e "\t(EPIPHANY) LINK\t$@" - @$(CC) -o $@ $^ $(LFLAGS) +@@ELF_RULES@@ +#$(EDEST)/%.elf: $(EDEST)/%.o $(ECOMMON) +# @$(ECHO) "\t(EPIPHANY) LINK\t$@" +# @$(CC) -o $@ $^ $(LFLAGS) $(EDEST)/%.o: $(ESRC)/%.c - @echo -e "\t(EPIPHANY) CC\t$@" + @$(ECHO) "\t(EPIPHANY) CC\t\t$@" @$(CC) $(CFLAGS) -c -o $@ $^ $(EDEST)/%.o: $(ELIB)/%.c - @echo -e "\t(EPIPHANY) CC\t$@" + @$(ECHO) "\t(EPIPHANY) CC\t\t$@" @$(CC) $(CFLAGS) -c -o $@ $^ diff --git a/dol/src/dol/visitor/epiphany/template/process_Wrapper.c b/dol/src/dol/visitor/epiphany/template/process_Wrapper.c index def5887..12ae882 100644 --- a/dol/src/dol/visitor/epiphany/template/process_Wrapper.c +++ b/dol/src/dol/visitor/epiphany/template/process_Wrapper.c @@ -13,7 +13,7 @@ shm_t shm SECTION(".shared_dram"); * ===================================================================== */ struct _DOL_wptr @@PROCESSNAME@@_wptr = { 1, /* active */ - {0,0,0,0} /* instance */ + {@@INSTANCE@@} /* instance */ }; @@PROCESSNAME@@_State @@PROCESSNAME@@_local; -- 2.30.2