changeset 430:35b37fe8d3a7

Add size member in struct Meta
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 09 Oct 2017 17:46:42 +0900
parents 54352ed97f34
children b3359544adbb
files src/parallel_execution/context.h src/parallel_execution/cuda.c src/parallel_execution/examples/bitonicSort/makeArray.cbc src/parallel_execution/examples/bitonicSort/printArray.cbc src/parallel_execution/examples/bitonicSort/sort.cbc
diffstat 5 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/context.h	Mon Oct 09 14:55:23 2017 +0900
+++ b/src/parallel_execution/context.h	Mon Oct 09 17:46:42 2017 +0900
@@ -14,14 +14,16 @@
 #define ALLOC_DATA(context, dseg) ({\
     struct Meta* meta = (struct Meta*)context->heap;\
     meta->type = D_##dseg;\
-    meta->size = 1;\
+    meta->size = sizeof(struct dseg);\
+    meta->len = 1;\
     context->heap += sizeof(struct Meta);\
     context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; })
 
 #define ALLOC_DATA_TYPE(context, dseg, t) ({\
     struct Meta* meta = (struct Meta*)context->heap;\
     meta->type = D_##t;\
-    meta->size = 1;\
+    meta->size = sizeof(struct t);\
+    meta->len = 1;\
     context->heap += sizeof(struct Meta);\
     context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; })
 
@@ -31,27 +33,28 @@
     union Data* data = context->heap; \
     context->heap += sizeof(struct t); \
     meta->type = D_##t; \
-    meta->size = 1;     \
+    meta->size = sizeof(struct t);     \
+    meta->len = 1;\
     data; })
 
-#define ALLOCATE_ARRAY(context, t, len) ({ \
+#define ALLOCATE_ARRAY(context, t, length) ({ \
     struct Meta* meta = (struct Meta*)context->heap;\
     context->heap += sizeof(struct Meta);\
     union Data* data = context->heap; \
-    context->heap += sizeof(struct t)*len; \
+    context->heap += sizeof(struct t)*length; \
     meta->type = D_##t; \
-    meta->size = len;     \
+    meta->size = sizeof(struct t)*length; \
+    meta->len = length; \
     data;   })
 
-#define ALLOC(context, t) (&ALLOCATE(context, t)->t)
-
-#define ALLOCATE_PTR_ARRAY(context, dseg, len) ({\
+#define ALLOCATE_PTR_ARRAY(context, dseg, length) ({\
     struct Meta* meta = (struct Meta*)context->heap;\
     context->heap += sizeof(struct Meta);\
     union Data* data = context->heap; \
-    context->heap += sizeof(struct dseg *)*len; \
+    context->heap += sizeof(struct dseg *)*length; \
     meta->type = D_##dseg; \
-    meta->size = len; \
+    meta->size = sizeof(struct dseg *)*length; \
+    meta->len = length; \
     data; })
 
 #define ALLOCATE_DATA_GEAR(context, t) ({ \
@@ -60,9 +63,12 @@
         meta->wait = createSingleLinkedQueue(context); \
         data; })
 
+#define ALLOC(context, t) (&ALLOCATE(context, t)->t)
+
 #define GET_META(dseg) ((struct Meta*)(((void*)dseg) - sizeof(struct Meta)))
 #define GET_TYPE(dseg) (GET_META(dseg)->type)
 #define GET_SIZE(dseg) (GET_META(dseg)->size)
+#define GET_LEN(dseg) (GET_META(dseg)->len)
 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
 
 #define Gearef(context, t) (&(context)->data[D_##t]->t)
@@ -116,6 +122,7 @@
     struct Meta {
         enum DataType type;
         long size;
+        long len;
         struct Queue* wait; // tasks waiting this dataGear
     } meta;
     struct Context Context;
--- a/src/parallel_execution/cuda.c	Mon Oct 09 14:55:23 2017 +0900
+++ b/src/parallel_execution/cuda.c	Mon Oct 09 17:46:42 2017 +0900
@@ -95,7 +95,7 @@
     CUdeviceptr devC;
     CUdeviceptr devD;
 
-    checkCudaErrors(cuMemAlloc(&devA, sizeof(struct Integer)*GET_SIZE(inputSortArray->array)));
+    checkCudaErrors(cuMemAlloc(&devA, sizeof(struct Integer)*GET_LEN(inputSortArray->array)));
     checkCudaErrors(cuMemAlloc(&devB, sizeof(int)));
     checkCudaErrors(cuMemAlloc(&devC, sizeof(int)));
     checkCudaErrors(cuMemAlloc(&devD, sizeof(int)));
@@ -106,7 +106,7 @@
 
     //入力のDataGearをGPUにbuffer経由で送る
     // Synchronous data transfer(host to device)
-    checkCudaErrors(cuMemcpyHtoD(devA, inputSortArray->array, sizeof(struct Integer)*GET_SIZE(inputSortArray->array)));
+    checkCudaErrors(cuMemcpyHtoD(devA, inputSortArray->array, sizeof(struct Integer)*GET_LEN(inputSortArray->array)));
     checkCudaErrors(cuMemcpyHtoD(devB, &inputSortArray->block, sizeof(int)));
     checkCudaErrors(cuMemcpyHtoD(devC, &inputSortArray->first, sizeof(int)));
     checkCudaErrors(cuMemcpyHtoD(devD, &inputSortArray->prefix, sizeof(int)));
@@ -129,7 +129,7 @@
     }
     //結果を取ってくるコマンドを入力する
     //コマンドの終了待ちを行う   
-    checkCudaErrors(cuMemcpyDtoH(inputSortArray->array, devA, sizeof(struct Integer)*GET_SIZE(inputSortArray->array)));
+    checkCudaErrors(cuMemcpyDtoH(inputSortArray->array, devA, sizeof(struct Integer)*GET_LEN(inputSortArray->array)));
     outputSortArray->array = inputSortArray->array;
     // wait for stream
     checkCudaErrors(cuCtxSynchronize());
--- a/src/parallel_execution/examples/bitonicSort/makeArray.cbc	Mon Oct 09 14:55:23 2017 +0900
+++ b/src/parallel_execution/examples/bitonicSort/makeArray.cbc	Mon Oct 09 17:46:42 2017 +0900
@@ -8,7 +8,7 @@
         output->array = (Integer*)ALLOCATE_ARRAY(context, Integer, length);
         srand((unsigned) time(NULL));
     }
-    if (output->loopCounter == GET_SIZE(output->array)){
+    if (output->loopCounter == GET_LEN(output->array)){
         printf("created Array\n");
         output->loopCounter = 0;
         Gearef(context, Time)->time = (union Data*)output1;
--- a/src/parallel_execution/examples/bitonicSort/printArray.cbc	Mon Oct 09 14:55:23 2017 +0900
+++ b/src/parallel_execution/examples/bitonicSort/printArray.cbc	Mon Oct 09 17:46:42 2017 +0900
@@ -17,7 +17,7 @@
 __code printArray1(struct SortArray* inputArray, __code next(...)){
     //printf("%d\n", inputArray->array[inputArray->loopCounter].value);
     inputArray->loopCounter++;
-    if (inputArray->loopCounter == GET_SIZE(inputArray->array)){
+    if (inputArray->loopCounter == GET_LEN(inputArray->array)){
         printf("sort completed\n");
         inputArray->loopCounter = 0;
         goto meta(context, next);
--- a/src/parallel_execution/examples/bitonicSort/sort.cbc	Mon Oct 09 14:55:23 2017 +0900
+++ b/src/parallel_execution/examples/bitonicSort/sort.cbc	Mon Oct 09 17:46:42 2017 +0900
@@ -71,7 +71,7 @@
 __code kernel2(struct SortArray* sortArray){//ソートの中身
     int i = sortArray->sortArray->loop_counter3;
 
-    if (i >= GET_SIZE(sortArray->sortArray->array)){//ループの終了→上のループへ
+    if (i >= GET_LEN(sortArray->sortArray->array)){//ループの終了→上のループへ
         sortArray->sortArray->loop_counter2++;
         sortArray->sortArray->loop_counter3 = 0;
         goto meta(context, C_kernel);