changeset 313:4addbc7469ee

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 15 Feb 2017 11:36:10 +0900
parents 7dd5a7d52a67
children 1839586f5b41
files src/parallel_execution/CUDAWorker.cbc src/parallel_execution/main.cbc
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CUDAWorker.cbc	Wed Feb 15 11:04:30 2017 +0900
+++ b/src/parallel_execution/CUDAWorker.cbc	Wed Feb 15 11:36:10 2017 +0900
@@ -14,6 +14,8 @@
 
 static void start_CUDAworker(Worker* worker);
 
+static int cuda_initialized = 0;
+
 Worker* createCUDAWorker(struct Context* context, int id, Queue* queue) {
     struct Worker* worker = ALLOC(context, Worker);
     struct CUDAWorker* cudaWorker = new CUDAWorker();
@@ -21,6 +23,13 @@
     worker->tasks = queue;
     cudaWorker->id = id;
 
+    worker->taskReceive = C_taskReceiveCUDAWorker;
+    worker->shutdown = C_shutdownCUDAWorker;
+    pthread_create(&worker->worker->CUDAWorker.thread, NULL, (void*)&start_CUDAworker, worker);
+    return worker;
+}
+
+static void cudaInit(struct CUDAWorker *cudaWorker) {
     // initialize and load kernel
     cudaWorker->num_stream = 1; // number of stream
     cudaWorker->stream = NEWN(cudaWorker->num_stream, CUstream );
@@ -32,11 +41,7 @@
         for (int i=0;i<cudaWorker->num_stream;i++)
             checkCudaErrors(cuStreamCreate(&cudaWorker->stream[i],0));
     }
-
-    worker->taskReceive = C_taskReceiveCUDAWorker;
-    worker->shutdown = C_shutdownCUDAWorker;
-    pthread_create(&worker->worker->CUDAWorker.thread, NULL, (void*)&start_CUDAworker, worker);
-    return worker;
+    cuda_initialized = 1;
 }
 
 static void start_CUDAworker(Worker* worker) {
@@ -49,6 +54,10 @@
 }
 
 __code taskReceiveCUDAWorker(struct Worker* worker,struct Queue* queue) {
+    if (cuda_initialized==0) {
+        CUDAWorker* cudaWorker = (CUDAWorker*)worker->worker;
+        cudaInit(cudaWorker);
+    }
     queue->queue = (union Data*)worker->tasks;
     queue->next = C_getTaskCUDA;
     goto meta(context, worker->tasks->take);
--- a/src/parallel_execution/main.cbc	Wed Feb 15 11:04:30 2017 +0900
+++ b/src/parallel_execution/main.cbc	Wed Feb 15 11:36:10 2017 +0900
@@ -132,9 +132,9 @@
             split = (int)atoi(argv[i+1]);
         else if (strcmp(argv[i], "-cuda") == 0) {
             gpu_num = 1;
+            CPU_CUDA = 0;
         }
     }
-    CPU_CUDA = cpu_num;
 }