changeset 1556:f71632373220 draft

add multiply ppe example.
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Tue, 05 Mar 2013 06:52:55 +0900
parents 096412ad80fb
children 786ab4ad682e e8c9a7099bcc
files example/add/main.cc example/multiply/ChangeLog example/multiply/Func.h example/multiply/Makefile example/multiply/Makefile.cell example/multiply/Makefile.def example/multiply/Makefile.gpu example/multiply/Makefile.linux example/multiply/Makefile.macosx example/multiply/gpu/Multi.cl example/multiply/gpu/task_init.cc example/multiply/main.cc example/multiply/ppe/Multi.cc example/multiply/ppe/Multi.h example/multiply/ppe/task_init.cc
diffstat 15 files changed, 382 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/example/add/main.cc	Mon Mar 04 20:20:58 2013 +0900
+++ b/example/add/main.cc	Tue Mar 05 06:52:55 2013 +0900
@@ -5,8 +5,6 @@
 #include "Func.h"
 
 extern void task_init(void);
-
-static int length = DATA_NUM;
 static int task = 1;
 
 const char *usr_help_str = "Usage: ./add \n";
@@ -52,7 +50,6 @@
      * Set 32bits parameter
      *   add_param(32bit parameter);
      */
-    add->set_param(0,(memaddr)length);
 
     // add Active Queue
     add->spawn();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/ChangeLog	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,6 @@
+2008-05-27  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
+
+	* memo
+	Fifo バージョンでは確認しました。
+	Cell バージョンは、Cerium がまだ未実装なのでそれから
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Func.h	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,6 @@
+enum {
+#include "SysTasks.h"
+    MULTIPLY_TASK,
+};
+
+#define DATA_NUM 100
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,28 @@
+default: macosx
+
+macosx: FORCE
+	@echo "Make for Mac OS X"
+	@$(MAKE) -f Makefile.macosx
+
+fifo64: FORCE
+	@echo "Make for Mac OS X 64bit mode"
+	@$(MAKE) -f Makefile.macosx ABIBIT=64
+
+linux: FORCE
+	@echo "Make for Linux"
+	@$(MAKE) -f Makefile.linux
+
+cell: FORCE
+	@echo "Make for PS3 (Cell)"
+	@$(MAKE) -f Makefile.cell
+
+gpu: FORCE
+	@echo "Make for GPU (open cl)"
+	@$(MAKE) -f Makefile.gpu
+
+FORCE:
+
+clean:
+	@$(MAKE) -f Makefile.macosx clean
+	@$(MAKE) -f Makefile.linux clean
+	@$(MAKE) -f Makefile.gpu clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile.cell	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,39 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ゅ<ゃ吾
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lCellManager -lspe2 -lpthread -Wl,--gc-sections 
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET) speobject
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+speobject:
+	cd spe; $(MAKE)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo ppu-gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	cd spe; $(MAKE) clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile.def	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,15 @@
+TARGET = multiply
+
+# include/library path
+# ex  macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex  linux/ps3
+CERIUM = ../../../Cerium
+
+CC      = clang++
+OPT = -g
+CFLAGS  = $(OPT) -Wall 
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile.gpu	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,35 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ゅ<ゃ吾
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = gpu
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += `sdl-config --libs` -lGpuManager -framework opencl
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET) 
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo ppu-gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f gpu/*~ gpu/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile.linux	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,36 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ゅ<ゃ吾
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager -lrt
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/Makefile.macosx	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,38 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ゅ<ゃ吾
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+ABIBIT=64
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager `sdl-config --libs`
+CC += -m$(ABIBIT)
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/gpu/Multi.cl	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,5 @@
+__kernel void
+add(__global const void *params,__global const float *A, __global const float*B, __global float *C)
+{
+    *C=*A+*B;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/gpu/task_init.cc	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,16 @@
+#include "Func.h"
+#include "GpuScheduler.h"
+
+/* 綽篏臀吾 */
+
+/**
+ * ∽違 ../spe/spe-main c
+ * у若喝冴違∽違
+ * 絅純∽医сk (SchedRegisterTask 綽)
+ */
+
+void
+task_init(void)
+{
+    GpuSchedRegister(MULTI_TASK, "gpu/Multi.cl","multi");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/main.cc	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "TaskManager.h"
+#include "Func.h"
+
+typedef struct nd_range {
+    int dimension;
+    size_t gws[3];
+    size_t lws[3];
+} ND_RANGE_T, *ND_RANGE_T_PTR;
+
+extern void task_init(void);
+static int task = 1;
+static int length = DATA_NUM;
+const char *usr_help_str = "Usage: ./multiply \n";
+void TMend(TaskManager *);
+
+float *A,*B,*C;
+
+static void
+print_result()
+{
+    printf("---\n");
+    for (int i =0;i<length;i++) {
+        printf("%f * %f = %f \n",A[i],B[i],C[i]);
+    }
+    printf("---\n");
+}
+
+void
+multi_init(TaskManager *manager)
+{    
+    HTask *multiply;
+    
+    A = new float[length];
+    B = new float[length];
+    C = new float[length];
+
+    for(int i=0; i<length; i++) {
+        A[i]=(float)(i+1000);
+        B[i]=(float)i/10.f;
+    }
+    /**
+     * Create Task
+     *   create_task(Task ID);
+     */
+    multiply = manager->create_task(MULTIPLY_TASK);
+    ND_RANGE_T_PTR ndr = new ND_RANGE_T;
+    ndr->dimension = 1;
+    ndr->gws[0] = sizeof(C)/sizeof(C[0]); ndr->gws[1] = 1; ndr->gws[2] = 1;
+    ndr->lws[0] = 1;ndr->lws[1] = 1; ndr->lws[2] = 1;
+    multiply->set_param(0,(memaddr)ndr);
+    multiply->nd_range();
+    multiply->set_cpu(SPE_ANY);
+
+    /**
+     * Set of Input Data
+     *   add_inData(address of input data, size of input data);
+     */
+    multiply->set_inData(0,(memaddr)A, sizeof(float)*length);
+    multiply->set_inData(1,(memaddr)B, sizeof(float)*length);
+
+    /**
+     * Set of OutPut area
+     *   add_outData(address of output area, size of output area);
+     */
+    multiply->set_outData(0,(memaddr)C, sizeof(float)*length);
+
+    /**
+     * Set 32bits parameter
+     *   add_param(32bit parameter);
+     */
+    multiply->set_param(1,(memaddr)length);
+    
+    // add Active Queue
+    multiply->spawn();
+}
+
+
+int
+TMmain(TaskManager *manager,int argc, char *argv[])
+{
+    // Task Register
+    //   ppe/task_init.cc
+    task_init();
+
+    for (int i = 0; i < task; ++i) {
+        multi_init(manager);
+    }
+
+    manager->set_TMend(TMend);
+
+    return 0;
+}
+
+void
+TMend(TaskManager *manager)
+{
+    print_result();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/ppe/Multi.cc	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Multi.h"
+#include "Func.h"
+
+/* 綽 */
+SchedDefineTask(Multiply);
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    float *A,*B,*C;
+
+    A = (float*)s->get_input(rbuf, 0);
+    B = (float*)s->get_input(rbuf, 1);
+    C = (float*)s->get_output(wbuf, 0);
+    
+    long length = (long)s->get_param(1);
+    for (int i=0; i<length; i++) {
+        C[i]=A[i]*B[i];
+    }
+    
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/ppe/Multi.h	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,16 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+/*
+class Twice : public SchedTask {
+public:
+    SchedConstructor(Twice);
+    
+    int run(void *r, void *w);
+};
+ */
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/multiply/ppe/task_init.cc	Tue Mar 05 06:52:55 2013 +0900
@@ -0,0 +1,17 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+/* 綽篏臀吾 */
+SchedExternTask(Multiply);
+
+/**
+ * ∽違 ../spe/spe-main c
+ * у若喝冴違∽違
+ * 絅純∽医сk (SchedRegisterTask 綽)
+ */
+
+void
+task_init(void)
+{
+  SchedRegisterTask(MULTIPLY_TASK, Multiply);
+}