changeset 450:d3d7a7d6a117

Delete USE_CUDA_MAIN_THREAD
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 04 Dec 2017 04:24:30 +0900
parents 0181b7fa5f53
children dcc42f3e7e97
files src/parallel_execution/CMakeLists.txt src/parallel_execution/CPUWorker.cbc src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/context.h src/parallel_execution/examples/bitonicSort/bitonicSort.cbc src/parallel_execution/examples/calc/calc.cbc src/parallel_execution/examples/twice/main.cbc src/parallel_execution/main.cbc src/parallel_execution/test/multiDimIterator_test.cbc
diffstat 9 files changed, 34 insertions(+), 160 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Mon Dec 04 04:24:30 2017 +0900
@@ -85,7 +85,7 @@
       SOURCES 
           examples/twice/main.cbc examples/twice/twice.cbc examples/twice/CUDAtwice.cu examples/twice/createArray.cbc examples/twice/printArray.cbc CPUWorker.cbc TimeImpl.cbc examples/twice/twice.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc CUDAWorker.cbc cuda.c MultiDimIterator.cbc CUDAExecutor.cbc AtomicReference.cbc
     )
-    set_target_properties(CUDAtwice PROPERTIES COMPILE_FLAGS "-Wall -g -DUSE_CUDAWorker=1") # -DUSE_CUDA_MAIN_THREAD
+    set_target_properties(CUDAtwice PROPERTIES COMPILE_FLAGS "-Wall -g -DUSE_CUDAWorker=1")
 
     GearsCommand(
       TARGET
--- a/src/parallel_execution/CPUWorker.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/CPUWorker.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -64,6 +64,7 @@
 }
 
 __code iterateCommit1_stub(struct Context* context) {
+    // switch worker context
     struct Context* workerContext = context->worker->worker->CPUWorker.context;
     goto iterateCommit1(workerContext, context);
 }
@@ -80,6 +81,7 @@
 }
 
 __code odgCommit_stub(struct Context* context) {
+    // switch worker context
     struct Context* workerContext = context->worker->worker->CPUWorker.context;
     goto odgCommit(workerContext,
                    Gearef(context, LoopCounter),
--- a/src/parallel_execution/TaskManagerImpl.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/TaskManagerImpl.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -40,15 +40,10 @@
         taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
     }
     for (;i<taskManager->cpu;i++) {
+        Queue* queue = createSynchronizedQueue(context);
 #ifdef USE_CUDAWorker
-        Queue* queue = createSynchronizedQueue(context);
-#ifndef USE_CUDA_MAIN_THREAD
         taskManagerImpl->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0);
 #else
-        taskManagerImpl->workers[i] = (Worker*)queue;
-#endif
-#else
-        Queue* queue = createSynchronizedQueue(context);
         taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
 #endif
     }
@@ -66,11 +61,11 @@
 }
 
 __code spawnTasksTaskManagerImpl_stub(struct Context* context) {
-	TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-	Queue* tasks = Gearef(context, TaskManager)->tasks;
-	enum Code next1 = Gearef(context, TaskManager)->next1;
-	Queue* queue = Gearef(context, Queue);
-	goto spawnTasksTaskManagerImpl(context, taskManager, tasks, next1, queue);
+    TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    Queue* tasks = Gearef(context, TaskManager)->tasks;
+    enum Code next1 = Gearef(context, TaskManager)->next1;
+    Queue* queue = Gearef(context, Queue);
+    goto spawnTasksTaskManagerImpl(context, taskManager, tasks, next1, queue);
 } 
 
 __code spawnTasksTaskManagerImpl1(struct TaskManagerImpl* taskManager, struct Queue* tasks, __code next1(...), struct Queue* queue) {
@@ -80,11 +75,11 @@
 }
 
 __code spawnTasksTaskManagerImpl1_stub(struct Context* context) {
-	TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-	Queue* tasks = Gearef(context, TaskManager)->tasks;
-	enum Code next1 = Gearef(context, TaskManager)->next1;
-	Queue* queue = Gearef(context, Queue);
-	goto spawnTasksTaskManagerImpl1(context, taskManager, tasks, next1, queue);
+    TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    Queue* tasks = Gearef(context, TaskManager)->tasks;
+    enum Code next1 = Gearef(context, TaskManager)->next1;
+    Queue* queue = Gearef(context, Queue);
+    goto spawnTasksTaskManagerImpl1(context, taskManager, tasks, next1, queue);
 } 
 
 __code spawnTasksTaskManagerImpl2(struct TaskManagerImpl* taskManagerImpl, struct Context* task, struct TaskManager* taskManager) {
@@ -95,10 +90,10 @@
 }
 
 __code spawnTasksTaskManagerImpl2_stub(struct Context* context) {
-	TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-	Context* task = (struct Context*)Gearef(context, Queue)->data;
-	TaskManager* taskManager = Gearef(context, TaskManager);
-	goto spawnTasksTaskManagerImpl2(context, taskManagerImpl, task, taskManager);
+    TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    Context* task = (struct Context*)Gearef(context, Queue)->data;
+    TaskManager* taskManager = Gearef(context, TaskManager);
+    goto spawnTasksTaskManagerImpl2(context, taskManagerImpl, task, taskManager);
 } 
 
 __code spawnTasksTaskManagerImpl3(struct TaskManagerImpl* taskManager, __code next1(...), struct Queue* queue) {
@@ -121,10 +116,10 @@
 }
 
 __code spawnTasksTaskManagerImpl5_stub(struct Context* context) {
-	TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-	Context* task = (struct Context*)Gearef(context, Queue)->data;
-	TaskManager* taskManager = Gearef(context, TaskManager);
-	goto spawnTasksTaskManagerImpl5(context, taskManagerImpl, task, taskManager);
+    TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    Context* task = (struct Context*)Gearef(context, Queue)->data;
+    TaskManager* taskManager = Gearef(context, TaskManager);
+    goto spawnTasksTaskManagerImpl5(context, taskManagerImpl, task, taskManager);
 } 
 
 __code setWaitTaskTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...), struct Queue* queue) {
@@ -147,10 +142,10 @@
     TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
     struct Context* task = Gearef(context, TaskManager)->context;
     goto setWaitTaskTaskManagerImpl(context,
-                                    taskManager,
-                                    task,
-                                    Gearef(context, TaskManager)->next,
-                                    Gearef(context, Queue));
+            taskManager,
+            task,
+            Gearef(context, TaskManager)->next,
+            Gearef(context, Queue));
 }
 
 __code incrementTaskCountTaskManagerImpl(struct TaskManagerImpl* taskManager, __code next(...)) {
@@ -183,11 +178,11 @@
     TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
     pthread_mutex_lock(&taskManager->mutex);
     goto spawnTaskManagerImpl(context,
-                              taskManager,
-                              Gearef(context, Iterator),
-                              &Gearef(context, TaskManager)->taskManager->TaskManager,
-                              Gearef(context, TaskManager)->context,
-                              Gearef(context, TaskManager)->next);
+            taskManager,
+            Gearef(context, Iterator),
+            &Gearef(context, TaskManager)->taskManager->TaskManager,
+            Gearef(context, TaskManager)->context,
+            Gearef(context, TaskManager)->next);
 }
 
 __code taskSend(struct TaskManagerImpl* taskManagerImpl, struct Queue* queue, struct TaskManager* taskManager, struct Context* task, __code next(...)) {
@@ -242,9 +237,9 @@
 __code shutdownTaskManagerImpl_stub(struct Context* context) {
     TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
     goto shutdownTaskManagerImpl(context,
-                                 taskManagerImpl,
-                                 Gearef(context, TaskManager)->next,
-                                 Gearef(context, Queue));
+            taskManagerImpl,
+            Gearef(context, TaskManager)->next,
+            Gearef(context, Queue));
 }
 
 __code shutdownTaskManagerImpl1(TaskManagerImpl* taskManager) {
--- a/src/parallel_execution/context.h	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/context.h	Mon Dec 04 04:24:30 2017 +0900
@@ -143,9 +143,6 @@
         int i;
     } LoopCounter;
     struct TaskManager {
-#ifdef USE_CUDA_MAIN_THREAD
-        volatile
-#endif
         union Data* taskManager;
         enum Code spawn;      // start NEW context on the worker
         enum Code spawnTasks; // start NEW tasks on the worker
--- a/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -18,42 +18,18 @@
     return 0;
 }
 
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-extern volatile int cuda_initialized;
-#endif
-#endif
-
 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
     // loopCounter->tree = createRedBlackTree(context);
     loopCounter->i = 0;
     taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-    while(! cuda_initialized) {};
-#endif
-#endif
     goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
     struct TaskManager* taskManager =  Gearef(context, TaskManager);
     taskManager->taskManager = 0;
-#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
     struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
     goto initDataGears(context, loopCounter, taskManager);
-#else
-    cuda_initialized = 0;
-    pthread_t thread;
-    pthread_create(&thread, NULL, (void*)&start_taskManager, context);
-    while (taskManager->taskManager == 0);
-    TaskManager *t = (TaskManager*)taskManager->taskManager;
-    TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
-    struct Queue *q = (Queue *)im->workers[0];
-    createCUDAWorker(context,0,q, im);
-    pthread_join(thread,0);
-    exit(0);
-#endif
 }
 
 __code code1(struct Time* time) {
--- a/src/parallel_execution/examples/calc/calc.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/examples/calc/calc.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -17,42 +17,18 @@
     return 0;
 }
 
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-extern volatile int cuda_initialized;
-#endif
-#endif
-
 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
     // loopCounter->tree = createRedBlackTree(context);
     loopCounter->i = 0;
     taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-    while(! cuda_initialized) {};
-#endif
-#endif
     goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
     struct TaskManager* taskManager =  Gearef(context, TaskManager);
     taskManager->taskManager = 0;
-#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
     struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
     goto initDataGears(context, loopCounter, taskManager);
-#else
-    cuda_initialized = 0;
-    pthread_t thread;
-    pthread_create(&thread, NULL, (void*)&start_taskManager, context);
-    while (taskManager->taskManager == 0);
-    TaskManager *t = (TaskManager*)taskManager->taskManager;
-    TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
-    struct Queue *q = (Queue *)im->workers[0];
-    createCUDAWorker(context,0,q, im);
-    pthread_join(thread,0);
-    exit(0);
-#endif
 }
 
 __code code1(struct Time* time) {
--- a/src/parallel_execution/examples/twice/main.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/examples/twice/main.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -18,42 +18,18 @@
     return 0;
 }
 
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-extern volatile int cuda_initialized;
-#endif
-#endif
-
 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
     // loopCounter->tree = createRedBlackTree(context);
     loopCounter->i = 0;
     taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-    while(! cuda_initialized) {};
-#endif
-#endif
     goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
     struct TaskManager* taskManager =  Gearef(context, TaskManager);
     taskManager->taskManager = 0;
-#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
     struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
     goto initDataGears(context, loopCounter, taskManager);
-#else
-    cuda_initialized = 0;
-    pthread_t thread;
-    pthread_create(&thread, NULL, (void*)&start_taskManager, context);
-    while (taskManager->taskManager == 0);
-    TaskManager *t = (TaskManager*)taskManager->taskManager;
-    TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
-    struct Queue *q = (Queue *)im->workers[0];
-    createCUDAWorker(context,0,q, im);
-    pthread_join(thread,0);
-    exit(0);
-#endif
 }
 
 __code code1(struct Time* time) {
--- a/src/parallel_execution/main.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/main.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -18,42 +18,18 @@
     return 0;
 }
 
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-extern volatile int cuda_initialized;
-#endif
-#endif
-
 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
     // loopCounter->tree = createRedBlackTree(context);
     loopCounter->i = 0;
     taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-    while(! cuda_initialized) {};
-#endif
-#endif
     goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
     struct TaskManager* taskManager =  Gearef(context, TaskManager);
     taskManager->taskManager = 0;
-#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
     struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
     goto initDataGears(context, loopCounter, taskManager);
-#else
-    cuda_initialized = 0;
-    pthread_t thread;
-    pthread_create(&thread, NULL, (void*)&start_taskManager, context);
-    while (taskManager->taskManager == 0);
-    TaskManager *t = (TaskManager*)taskManager->taskManager;
-    TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
-    struct Queue *q = (Queue *)im->workers[0];
-    createCUDAWorker(context,0,q, im);
-    pthread_join(thread,0);
-    exit(0);
-#endif
 }
 
 __code code1(struct Time* time) {
--- a/src/parallel_execution/test/multiDimIterator_test.cbc	Fri Dec 01 22:47:26 2017 +0900
+++ b/src/parallel_execution/test/multiDimIterator_test.cbc	Mon Dec 04 04:24:30 2017 +0900
@@ -16,42 +16,18 @@
     return 0;
 }
 
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-extern volatile int cuda_initialized;
-#endif
-#endif
-
 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
     // loopCounter->tree = createRedBlackTree(context);
     loopCounter->i = 0;
     taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
-#ifdef USE_CUDAWorker
-#ifdef USE_CUDA_MAIN_THREAD
-    while(! cuda_initialized) {};
-#endif
-#endif
     goto meta(context, C_code1);
 }
 
 __code initDataGears_stub(struct Context* context) {
     struct TaskManager* taskManager =  Gearef(context, TaskManager);
     taskManager->taskManager = 0;
-#if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD))
     struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
     goto initDataGears(context, loopCounter, taskManager);
-#else
-    cuda_initialized = 0;
-    pthread_t thread;
-    pthread_create(&thread, NULL, (void*)&start_taskManager, context);
-    while (taskManager->taskManager == 0);
-    TaskManager *t = (TaskManager*)taskManager->taskManager;
-    TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager;
-    struct Queue *q = (Queue *)im->workers[0];
-    createCUDAWorker(context,0,q, im);
-    pthread_join(thread,0);
-    exit(0);
-#endif
 }
 
 __code code1(struct Time* time) {