changeset 344:b8be1d51f002

Add CodeGear interface
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Fri, 26 May 2017 07:39:23 +0900
parents 5065d1e4adbb
children 2da00c034fbc
files src/parallel_execution/CodeGear.cbc src/parallel_execution/context.h src/parallel_execution/examples/Add.cbc src/parallel_execution/examples/calc.cbc
diffstat 4 files changed, 49 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CodeGear.cbc	Thu May 25 22:52:54 2017 +0900
+++ b/src/parallel_execution/CodeGear.cbc	Fri May 26 07:39:23 2017 +0900
@@ -1,9 +1,7 @@
 typedef struct CodeGear<Impl>{
         union Data* codeGear;
         enum Code code;
-        __code run(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...));
-        struct Integer* input1;
-        struct Integer* input2;
-        struct Integer* output;
+        __code code(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...));
+        union Data* dataGears[10];
         __code next(...);
 } CodeGear;
--- a/src/parallel_execution/context.h	Thu May 25 22:52:54 2017 +0900
+++ b/src/parallel_execution/context.h	Fri May 26 07:39:23 2017 +0900
@@ -109,13 +109,12 @@
     struct LoopCounter {
         int i;
     } LoopCounter;
-    struct Task {
-        union Data* task;
+    struct CodeGear {
+        union Data* CodeGear;
         enum Code code;
-        int idgCount;
-        int odgCount;
-        enum Code setTaskInfo;
-    } Task;
+        union Data* dataGears[10];
+        enum Code next;
+    } CodeGear;
     struct TaskManager {
 #ifdef USE_CUDA_MAIN_THREAD
         volatile 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/Add.cbc	Fri May 26 07:39:23 2017 +0900
@@ -0,0 +1,34 @@
+#include "../../context.h"
+CodeGear* createAddCodeGear(struct Context* context) {
+    struct CodeGear* codeGear = new CodeGear();
+    struct context* addContext = NEW(struct Context);
+    codeGear->codeGear = (union Data*)addContext;
+    initContext(addContext);
+    codeGear->code = C_add;
+    codeGear->setInfo = C_setAddCodeGearInfo;
+    return codeGear;
+}
+
+CodeGear* setAddCodeGearInfo(struct Context* codeGear, union Data** dataGears) {
+    codeGear->next = C_add;
+    codeGear->idgCount = 2;
+    codeGear->idg = codeGear->datanum;
+    codeGear->data[codeGear->idg] = dataGears[0];
+    codeGear->data[codeGear->idg+1] = dataGears[1];
+    codeGear->maxIdg = codeGear->idg + 2;
+    codeGear->odg = codeGear->maxIdg;
+    codeGear->data[codeGear->odg] = dataGears[2];
+    task->maxOdg = task->odg + 1;
+    goto meta(context, C_setWaitTask)
+}
+
+__code setWaitTask(struct Queue* queue, struct Context* task, Data* data, __code next(...)) {
+    queue->queue = (Data *)GET_WAIT_LIST(data);
+    queue->next = next;
+    queue->data = (Data *)task;
+    goto meta(context, queue->queue->Queue.put);
+}
+
+__code setWaitTask_stub(struct Context* context) {
+    goto setWaitTask(context, Gearef(context, Queue), Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->data, Gearef(context, TaskManager)->next);
+}
--- a/src/parallel_execution/examples/calc.cbc	Thu May 25 22:52:54 2017 +0900
+++ b/src/parallel_execution/examples/calc.cbc	Fri May 26 07:39:23 2017 +0900
@@ -129,29 +129,22 @@
     goto meta(context, taskManager->taskManager->TaskManager.spawn);
 }
 
-__code createTask4(struct TaskManager* taskManager) {
-    taskManager->next = C_createTask5;
-    goto meta(context, taskManager->taskManager->TaskManager.createTask);
-}
-
-__code createTask5(LoopCounter* loopCounter, TaskManager* taskManager, struct Context* task, Integer *integer1, Integer *integer2, Integer *integer3) {
+__code createTask4(LoopCounter* loopCounter, TaskManager* taskManager, struct Context* task, Integer *integer1, Integer *integer2, Integer *integer3) {
     int i = loopCounter->i;
     integer1->value = i;
     integer2->value = i+1;
-    task->next = C_add;
-    task->idgCount = 0;
-    task->data[task->idg] = (union Data*)integer1;
-    task->data[task->idg+1] = (union Data*)integer2;
-    task->maxIdg = task->idg + 2;
-    task->odg = task->maxIdg;
-    task->data[task->odg] = (union Data*)integer3;
-    task->maxOdg = task->odg + 1;
+    codeGear->codeGear= createAdd(context);
+    codeGear->codeGear[0] = (union Data*)integer1;
+    codeGear->codeGear[1] = (union Data*)integer2;
+    codeGear->codeGear[2] = (union Data*)integer3;
+    codeGear->next = C_createTask1
     taskManager->context = task;
     taskManager->next = C_createTask1;
     goto meta(context, taskManager->taskManager->TaskManager.spawn);
+    goto meta(context, codeGear->codeGear->CodeGear.);
 }
 
-__code createTask5_stub(struct Context* context) {
+__code createTask4_stub(struct Context* context) {
     Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
     Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
     goto createTask5(context,