diff src/parallel_execution/examples/twice/twice.cbc @ 438:7679093bdd72

Work CUDAtwice
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 06 Nov 2017 00:11:43 +0900
parents b3359544adbb
children 5a737c3df91c
line wrap: on
line diff
--- a/src/parallel_execution/examples/twice/twice.cbc	Sat Nov 04 08:30:25 2017 +0900
+++ b/src/parallel_execution/examples/twice/twice.cbc	Mon Nov 06 00:11:43 2017 +0900
@@ -3,10 +3,11 @@
 #include "../../../context.h"
 
 #ifdef USE_CUDAWorker
-extern void cudaExec(struct Context* context, Array* array);
+extern void cudaLoadFunction(struct Context* context, char* filename, char* function);
 #endif
 
-__code twice(struct Array* array, struct MultiDim* multiDim, __code next(...), struct LoopCounter* loopCounter) {
+__code twice(struct Array* array, struct MultiDim* multiDim, __code next(struct Array* output, ...), struct LoopCounter* loopCounter) {
+    struct Array* output = *O_output;
     int i = loopCounter->i;
     int index = multiDim->x;
     if (i < array->prefix) {
@@ -17,21 +18,38 @@
     }
 
     loopCounter->i = 0;
+    output->array = array->array;
     goto meta(context, context->next);
 }
 
 __code twice_stub(struct Context* context) {
 #ifdef USE_CUDAWorker
-    struct Array* array = &context->data[context->idg]->Array;
     if (context->gpu) {
-        cudaExec(context, array);
+        Array* inputArray  = &context->data[context->idg]->Array;
+        Array* outputArray = &context->data[context->odg]->Array;
+        CUDABuffer* buffer = &ALLOCATE(context, CUDABuffer)->CUDABuffer;
+        buffer->inputData = (union Data**)ALLOCATE_PTR_ARRAY(context, Array, 2);
+        buffer->inputData[0] = (union Data*)inputArray->array;
+        buffer->inputData[1] = (union Data*)inputArray;
+        buffer->outputData = NULL;
+        buffer->inputLen = 2;
+        buffer->outputLen = 0;
         //continuationにそってGPUworkerに戻る
-        goto meta(context, context->next);
+        outputArray->array = inputArray->array;
+        Executor* executor = context->worker->worker->CUDAWorker.executor;
+        executor->executor->CUDAExecutor.buffer = buffer;
+        cudaLoadFunction(context, "c/examples/twice/CUDAtwice.ptx", "twice");
+        Gearef(context, Executor)->executor = (union Data*)executor;
+        Gearef(context, Executor)->task = context;
+        Gearef(context, Executor)->next = context->next;
+        goto meta(context, executor->read);
     }
 #endif
+    Array** O_output = (struct Array **)&context->data[context->odg];
     goto twice(context,
                &context->data[context->idg]->Array,
                &context->data[context->idg+1]->MultiDim,
                context->next,
+               O_output,
                Gearef(context, LoopCounter));
 }