square: DOL squaring example (shown in live demo)
authorSebastian <basti@sraa.de>
Mon, 16 Dec 2013 21:46:21 +0000 (22:46 +0100)
committerSebastian <basti@sraa.de>
Mon, 16 Dec 2013 21:46:21 +0000 (22:46 +0100)
square/Makefile [new file with mode: 0644]
square/Square.xml [new file with mode: 0644]
square/src/Gen.c [new file with mode: 0644]
square/src/Gen.h [new file with mode: 0644]
square/src/Square.c [new file with mode: 0644]
square/src/Square.h [new file with mode: 0644]

diff --git a/square/Makefile b/square/Makefile
new file mode 100644 (file)
index 0000000..fc78207
--- /dev/null
@@ -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 (file)
index 0000000..27f50a2
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<processnetwork 
+xmlns="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK" 
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+xsi:schemaLocation="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK
+    http://www.tik.ee.ethz.ch/~shapes/schema/processnetwork.xsd" name="square"> 
+
+  <!-- HOST -->
+  <process name="EpiphanyHost">
+    <port type="input" name="HP0"/>
+    <source type="c"/>
+  </process>
+
+  <!-- APPLICATION -->
+  <process name="Gen">
+    <port type="output" name="0"/>
+    <source type="c" location="Gen.c"/>
+  </process>
+
+  <process name="Square">
+    <port type="input" name="0"/>
+    <port type="output" name="1"/>
+    <source type="c" location="Square.c"/>
+  </process>
+
+  <sw_channel type="fifo" size="16" name="C1">
+    <port type="input" name="0"/>
+    <port type="output" name="1"/>
+  </sw_channel>
+
+  <sw_channel type="fifo" size="16" name="HC1">
+    <port type="input" name="1"/>
+    <port type="output" name="HP0"/>
+  </sw_channel>
+
+  <!-- CONNECTIONS -->
+  <connection name="Gen-C1">
+    <origin name="Gen">
+      <port name="0"/>
+    </origin>
+    <target name="C1">
+      <port name="0"/>
+    </target>
+  </connection>
+
+  <connection name="C1-Square">
+    <origin name="C1">
+      <port name="1"/>
+    </origin>
+    <target name="Square">
+      <port name="0"/>
+    </target>
+  </connection>
+
+  <connection name="Square-HC1">
+    <origin name="Square">
+      <port name="1"/>
+    </origin>
+    <target name="HC1">
+      <port name="1"/>
+    </target>
+  </connection>
+
+  <connection name="HC1-Host">
+    <origin name="HC1">
+      <port name="HP0"/>
+    </origin>
+    <target name="EpiphanyHost">
+      <port name="HP0"/>
+    </target>
+  </connection>
+</processnetwork>
diff --git a/square/src/Gen.c b/square/src/Gen.c
new file mode 100644 (file)
index 0000000..133e5aa
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#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 (file)
index 0000000..9acfcf5
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef GEN_H
+#define GEN_H
+
+#include <dol.h>
+
+#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 (file)
index 0000000..017f19f
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#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 (file)
index 0000000..cb89096
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef SQUARE_H
+#define SQUARE_H
+
+#include <dol.h>
+
+#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