Browse Source

factorize code

Olivier Aumage 8 years ago
parent
commit
408f4d3d98
4 changed files with 37 additions and 1 deletions
  1. 32 0
      src/core/workers.c
  2. 1 0
      src/core/workers.h
  3. 3 0
      src/drivers/cuda/driver_cuda.c
  4. 1 1
      src/drivers/opencl/driver_opencl.c

+ 32 - 0
src/core/workers.c

@@ -2313,3 +2313,35 @@ void starpu_worker_display_names(FILE *output, enum starpu_worker_archtype type)
 		}
 	}
 }
+
+void _starpu_worker_refuse_task(struct _starpu_worker *worker, struct starpu_task *task)
+{
+	if (worker->pipeline_length || worker->arch == STARPU_OPENCL_WORKER)
+	{
+		int j;
+		for (j = 0; j < worker->ntasks; j++)
+		{
+			const int j_mod = (j+worker->first_task)%STARPU_MAX_PIPELINE;
+			if (task == worker->current_tasks[j_mod])
+			{
+				worker->current_tasks[j_mod] = NULL;
+				if (j == 0)
+				{
+					worker->first_task = (worker->first_task + 1) % STARPU_MAX_PIPELINE;
+					worker->current_task = NULL;
+					_starpu_set_current_task(NULL);
+				}
+				break;
+			}
+		}
+		STARPU_ASSERT(j<worker->ntasks);
+	}
+	else
+	{
+		worker->current_task = NULL;
+		_starpu_set_current_task(NULL);
+	}
+	worker->ntasks--;
+	int res = _starpu_push_task_to_workers(task);
+	STARPU_ASSERT_MSG(res == 0, "_starpu_push_task_to_workers() unexpectedly returned = %d\n", res);
+}

+ 1 - 0
src/core/workers.h

@@ -1053,4 +1053,5 @@ static inline int _starpu_wake_worker_relax(int workerid)
 	return ret;
 }
 
+void _starpu_worker_refuse_task(struct _starpu_worker *worker, struct starpu_task *task);
 #endif // __WORKERS_H__

+ 3 - 0
src/drivers/cuda/driver_cuda.c

@@ -900,6 +900,8 @@ int _starpu_cuda_driver_run_once(struct _starpu_worker_set *worker_set)
 		if (!_STARPU_CUDA_MAY_PERFORM(j))
 		{
 			/* this is neither a cuda or a cublas task */
+			_starpu_worker_refuse_task(worker, task);
+#if 0
 			if (worker->pipeline_length)
 			{
 				int j;
@@ -927,6 +929,7 @@ int _starpu_cuda_driver_run_once(struct _starpu_worker_set *worker_set)
 			worker->ntasks--;
 			int res = _starpu_push_task_to_workers(task);
 			STARPU_ASSERT_MSG(res == 0, "_starpu_push_task_to_workers() unexpectedly returned = %d\n", res);
+#endif
 			continue;
 		}
 

+ 1 - 1
src/drivers/opencl/driver_opencl.c

@@ -797,7 +797,7 @@ int _starpu_opencl_driver_run_once(struct _starpu_worker *worker)
 	if (!_STARPU_OPENCL_MAY_PERFORM(j))
 	{
 		/* this is not a OpenCL task */
-		_starpu_push_task_to_workers(task);
+		_starpu_worker_refuse_task(worker, task);
 		return 0;
 	}