From 72e08f31e7589c2901158d3abdb7e116c6c6f83e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 16 Dec 2013 22:46:21 +0100 Subject: [PATCH] square: DOL squaring example (shown in live demo) --- square/Makefile | 93 +++++++++++++++++++++++++++++++++++++++++++++ square/Square.xml | 72 +++++++++++++++++++++++++++++++++++ square/src/Gen.c | 28 ++++++++++++++ square/src/Gen.h | 17 +++++++++ square/src/Square.c | 31 +++++++++++++++ square/src/Square.h | 18 +++++++++ 6 files changed, 259 insertions(+) create mode 100644 square/Makefile create mode 100644 square/Square.xml create mode 100644 square/src/Gen.c create mode 100644 square/src/Gen.h create mode 100644 square/src/Square.c create mode 100644 square/src/Square.h diff --git a/square/Makefile b/square/Makefile new file mode 100644 index 0000000..fc78207 --- /dev/null +++ b/square/Makefile @@ -0,0 +1,93 @@ +# Makefile to generate a DOL program + +# Type 'make help' to get a list of targets. + +# program to generate +PROGRAM = Square + +# code generator to use +# use '-C' (SystemC) or '-H' (HdS) or '-E' (Epiphany) +CODEGEN = -E + +# change according to your system +DOLPATH = $(HOME)/jump/dol/jars +SYSTEMC_INC = $(HOME)/systemc/include +SYSTEMC_LIB = $(HOME)/systemc/lib-linux64/libsystemc.a + +# list of programs +JAVA ?= java +JAVAC ?= javac +DOTTY ?= dotty +ECHO ?= echo +SED ?= sed +CP ?= cp +RM ?= rm + +# don't change anything below +# =========================================================================== + +SRCPATH = generated +CLASSPATH = $(DOLPATH)/dol.jar:$(DOLPATH)/jdom.jar:$(DOLPATH)/xercesImpl.jar +.PHONY : help all run codegen dotty clean + +help: + @$(ECHO) "Target List:\n" \ + "\thelp -- show this help [default]\n" \ + "\tall -- generate '$(PROGRAM)'\n" \ + "\trun -- generate and run '$(PROGRAM)'\n" \ + "\tcodegen -- generate code, but do not compile\n" \ + "\tdotty -- show flattened process network using DOTTY\n" \ + "\tclean -- clean generated files\n" + +all: $(PROGRAM) + +codegen: $(SRCPATH)/Makefile.new + +run: $(PROGRAM) + @$(ECHO) "\t[RUN]\t$^" + @./$(PROGRAM) + +clean: + @$(ECHO) "\t[CLEAN]" + @$(RM) -rf $(PROGRAM) $(SRCPATH)/ $(PROGRAM)_flattened.xml \ + $(PROGRAM)_Generator.java $(PROGRAM)_Generator.class \ + $(PROGRAM).dot profile.txt output.txt + +$(PROGRAM): $(SRCPATH)/src/sc_application + @$(ECHO) "\t[COPY]\t$@" + @$(CP) $^ $@ + +$(SRCPATH)/src/sc_application: $(SRCPATH)/Makefile.new + @$(ECHO) "\t[MAKE]\t$<" + @$(MAKE) -f Makefile.new -C $(SRCPATH)/src + +$(SRCPATH)/Makefile.new: $(SRCPATH)/src/Makefile + @$(ECHO) "\t[GEN]\t$@" + @$(SED) -e 's@^SYSTEMC_INC.*@SYSTEMC_INC = -I$(SYSTEMC_INC)@' \ + -e 's@^SYSTEMC_LIB.*@SYSTEMC_LIB = $(SYSTEMC_LIB)@' \ + -e 's@^MY_LIB_INC.*@& -lpthread@' \ + $(SRCPATH)/src/Makefile > $(SRCPATH)/src/Makefile.new + +$(SRCPATH)/src/Makefile: $(PROGRAM)_flattened.xml + @$(ECHO) "\t[GEN]\t$@" +# @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \ +# $(CODEGEN) $(SRCPATH) -c >/dev/null + @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \ + $(CODEGEN) $(SRCPATH) + +$(PROGRAM)_flattened.xml: $(PROGRAM).xml + @$(ECHO) "\t[FLAT]\t$^" + @$(JAVA) -cp $(CLASSPATH) dol.helper.flattener.XMLFlattener \ + $(PROGRAM).xml $(PROGRAM)_Generator >/dev/null + @$(JAVAC) $(PROGRAM)_Generator.java + @$(JAVA) $(PROGRAM)_Generator > $(PROGRAM)_flattened.xml + +$(PROGRAM).dot: $(PROGRAM)_flattened.xml + @$(ECHO) "\t[GEN]\t$@" + @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \ + -D $(PROGRAM).dot -c >/dev/null + +dotty: $(PROGRAM).dot + @$(ECHO) "\t[RUN]\t$(DOTTY) $(PROGRAM).dot" + @$(DOTTY) $(PROGRAM).dot + diff --git a/square/Square.xml b/square/Square.xml new file mode 100644 index 0000000..27f50a2 --- /dev/null +++ b/square/Square.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/square/src/Gen.c b/square/src/Gen.c new file mode 100644 index 0000000..133e5aa --- /dev/null +++ b/square/src/Gen.c @@ -0,0 +1,28 @@ +#include +#include "Gen.h" + +void Gen_delay(void) +{ + for(volatile int a = 0; a < 50; a++) + for(volatile int b = 0; b < 2000000; b++) + ; +} + +void Gen_init(DOLProcess *p) { + ((Gen_State*)p->local)->index = 0; +} + +int Gen_fire(DOLProcess *p) { + float i; + + if (p->local->index < LENGTH) { +Gen_delay(); + p->local->index++; + i = p->local->index; + DOL_write(PORT_OUTPUT, &i, sizeof(float), p); + } else { + DOL_detach(p); + } + + return 0; +} diff --git a/square/src/Gen.h b/square/src/Gen.h new file mode 100644 index 0000000..9acfcf5 --- /dev/null +++ b/square/src/Gen.h @@ -0,0 +1,17 @@ +#ifndef GEN_H +#define GEN_H + +#include + +#define PORT_OUTPUT "0" + +#define LENGTH 8 + +typedef struct _local_states { + int index; +} Gen_State; + +void Gen_init(DOLProcess *); +int Gen_fire(DOLProcess *); + +#endif diff --git a/square/src/Square.c b/square/src/Square.c new file mode 100644 index 0000000..017f19f --- /dev/null +++ b/square/src/Square.c @@ -0,0 +1,31 @@ +#include +#include "Square.h" + +#include "../shared.h" +extern shm_t shm; + +void Square_delay(void) +{ + for(volatile int a = 0; a < 25; a++) + for(volatile int b = 0; b < 25; b++) + ; +} + +void Square_init(DOLProcess *p) { + ((Square_State*)p->local)->index = 0; +} + +int Square_fire(DOLProcess *p) { + float i; + + if (((Square_State*)p->local)->index < LENGTH) { + DOL_read(PORT_INPUT, &i, sizeof(float), p); + i = i*i; + DOL_write(PORT_OUTPUT, &i, sizeof(float), p); + ((Square_State*)p->local)->index++; + } else { + DOL_detach(p); + } + + return 0; +} diff --git a/square/src/Square.h b/square/src/Square.h new file mode 100644 index 0000000..cb89096 --- /dev/null +++ b/square/src/Square.h @@ -0,0 +1,18 @@ +#ifndef SQUARE_H +#define SQUARE_H + +#include + +#define PORT_INPUT "0" +#define PORT_OUTPUT "1" + +#define LENGTH 8 + +typedef struct _local_states { + int index; +} Square_State; + +void Square_init(DOLProcess *); +int Square_fire(DOLProcess *); + +#endif -- 2.30.2